git-mv: succeed even if source is a prefix of destination
As noted by Fredrik Kuivinen, without this patch, git-mv fails on git-mv README README-renamed because "README" is a prefix of "README-renamed". Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de> Signed-off-by: Junio C Hamano <junkio@cox.net>
This commit is contained in:
parent
66c4509b73
commit
1d6249e609
@ -119,6 +119,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
|
|||||||
|
|
||||||
/* Checking */
|
/* Checking */
|
||||||
for (i = 0; i < count; i++) {
|
for (i = 0; i < count; i++) {
|
||||||
|
int length;
|
||||||
const char *bad = NULL;
|
const char *bad = NULL;
|
||||||
|
|
||||||
if (show_only)
|
if (show_only)
|
||||||
@ -204,7 +205,9 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!bad &&
|
if (!bad &&
|
||||||
!strncmp(destination[i], source[i], strlen(source[i])))
|
(length = strlen(source[i])) >= 0 &&
|
||||||
|
!strncmp(destination[i], source[i], length) &&
|
||||||
|
(destination[i][length] == 0 || destination[i][length] == '/'))
|
||||||
bad = "can not move directory into itself";
|
bad = "can not move directory into itself";
|
||||||
|
|
||||||
if (!bad && cache_name_pos(source[i], strlen(source[i])) < 0)
|
if (!bad && cache_name_pos(source[i], strlen(source[i])) < 0)
|
||||||
|
@ -59,6 +59,10 @@ test_expect_success \
|
|||||||
git-diff-tree -r -M --name-status HEAD^ HEAD | \
|
git-diff-tree -r -M --name-status HEAD^ HEAD | \
|
||||||
grep -E "^R100.+path0/README.+path2/README"'
|
grep -E "^R100.+path0/README.+path2/README"'
|
||||||
|
|
||||||
|
test_expect_success \
|
||||||
|
'succeed when source is a prefix of destination' \
|
||||||
|
'git-mv path2/COPYING path2/COPYING-renamed'
|
||||||
|
|
||||||
test_expect_success \
|
test_expect_success \
|
||||||
'moving whole subdirectory into subdirectory' \
|
'moving whole subdirectory into subdirectory' \
|
||||||
'git-mv path2 path1'
|
'git-mv path2 path1'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user