aboutsummaryrefslogtreecommitdiff
path: root/builtin-mv.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2008-02-03 23:59:17 -0800
committerJunio C Hamano <gitster@pobox.com>2008-02-05 00:44:10 -0800
commit744dacd3f5045240a304e687f3ef7135398e7865 (patch)
tree2f79230a6d792514f78c9344661158f1b6b19b5a /builtin-mv.c
parent1abf0950638d4f3279d059a1365da9c253d5718a (diff)
downloadgit-744dacd3f5045240a304e687f3ef7135398e7865.tar.gz
git-744dacd3f5045240a304e687f3ef7135398e7865.tar.xz
builtin-mv: minimum fix to avoid losing files
An incorrect command "git mv subdir /outer/space" threw the subdirectory to outside of the repository and then noticed that /outer/space/subdir/ would be outside of the repository. The error checking is backwards. This fixes the issue by being careful about use of the return value of get_pathspec(). Since the implementation already has handcrafted loop to munge each path on the command line, we use prefix_path() instead. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin-mv.c')
-rw-r--r--builtin-mv.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/builtin-mv.c b/builtin-mv.c
index 94f6dd2aa..68aa2a68b 100644
--- a/builtin-mv.c
+++ b/builtin-mv.c
@@ -19,6 +19,7 @@ static const char **copy_pathspec(const char *prefix, const char **pathspec,
int count, int base_name)
{
int i;
+ int len = prefix ? strlen(prefix) : 0;
const char **result = xmalloc((count + 1) * sizeof(const char *));
memcpy(result, pathspec, count * sizeof(const char *));
result[count] = NULL;
@@ -32,8 +33,11 @@ static const char **copy_pathspec(const char *prefix, const char **pathspec,
if (last_slash)
result[i] = last_slash + 1;
}
+ result[i] = prefix_path(prefix, len, result[i]);
+ if (!result[i])
+ exit(1); /* error already given */
}
- return get_pathspec(prefix, result);
+ return result;
}
static void show_list(const char *label, struct path_list *list)