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>
Johannes Schindelin committed
Aug 16, 2006 at 02:20 UTC
1d6249e609289940dca179b626fe4ae5433c90cc
2 files changed
+8
-1
builtin-mv.c
+4
-1
@@ -119,6 +119,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
119
120
/* Checking */
121
for (i = 0; i < count; i++) {
122
+ int length;
123
const char *bad = NULL;
124
125
if (show_only)
@@ -204,7 +205,9 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
205
}
206
207
if (!bad &&
207
- !strncmp(destination[i], source[i], strlen(source[i])))
208
+ (length = strlen(source[i])) >= 0 &&
209
+ !strncmp(destination[i], source[i], length) &&
210
+ (destination[i][length] == 0 || destination[i][length] == '/'))
211
bad = "can not move directory into itself";
212
213
if (!bad && cache_name_pos(source[i], strlen(source[i])) < 0)
t/t7001-mv.sh
+4
@@ -59,6 +59,10 @@ test_expect_success \
59
git-diff-tree -r -M --name-status HEAD^ HEAD | \
60
grep -E "^R100.+path0/README.+path2/README"'
61
62
+test_expect_success \
63
+ 'succeed when source is a prefix of destination' \
64
+ 'git-mv path2/COPYING path2/COPYING-renamed'
65
+
66
test_expect_success \
67
'moving whole subdirectory into subdirectory' \
68
'git-mv path2 path1'