зеркало из https://github.com/microsoft/git.git
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>
This commit is contained in:
Родитель
1abf095063
Коммит
744dacd3f5
|
@ -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)
|
||||
|
|
|
@ -118,4 +118,42 @@ test_expect_success "Sergey Vlasov's test case" '
|
|||
git mv ab a
|
||||
'
|
||||
|
||||
test_expect_success 'absolute pathname' '(
|
||||
|
||||
rm -fr mine &&
|
||||
mkdir mine &&
|
||||
cd mine &&
|
||||
test_create_repo one &&
|
||||
cd one &&
|
||||
mkdir sub &&
|
||||
>sub/file &&
|
||||
git add sub/file &&
|
||||
|
||||
git mv sub "$(pwd)/in" &&
|
||||
! test -d sub &&
|
||||
test -d in &&
|
||||
git ls-files --error-unmatch in/file
|
||||
|
||||
|
||||
)'
|
||||
|
||||
test_expect_success 'absolute pathname outside should fail' '(
|
||||
|
||||
rm -fr mine &&
|
||||
mkdir mine &&
|
||||
cd mine &&
|
||||
out=$(pwd) &&
|
||||
test_create_repo one &&
|
||||
cd one &&
|
||||
mkdir sub &&
|
||||
>sub/file &&
|
||||
git add sub/file &&
|
||||
|
||||
! git mv sub "$out/out" &&
|
||||
test -d sub &&
|
||||
! test -d ../in &&
|
||||
git ls-files --error-unmatch sub/file
|
||||
|
||||
)'
|
||||
|
||||
test_done
|
||||
|
|
Загрузка…
Ссылка в новой задаче