diff options
-rw-r--r-- | builtin-mv.c | 5 | ||||
-rwxr-xr-x | t/t7001-mv.sh | 4 |
2 files changed, 8 insertions, 1 deletions
diff --git a/builtin-mv.c b/builtin-mv.c index a731f8d9c..e7b5eb708 100644 --- a/builtin-mv.c +++ b/builtin-mv.c @@ -119,6 +119,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix) /* Checking */ for (i = 0; i < count; i++) { + int length; const char *bad = NULL; if (show_only) @@ -204,7 +205,9 @@ int cmd_mv(int argc, const char **argv, const char *prefix) } 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"; if (!bad && cache_name_pos(source[i], strlen(source[i])) < 0) diff --git a/t/t7001-mv.sh b/t/t7001-mv.sh index 900ca93cd..e5e0bb9d5 100755 --- a/t/t7001-mv.sh +++ b/t/t7001-mv.sh @@ -60,6 +60,10 @@ test_expect_success \ 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 \ 'moving whole subdirectory into subdirectory' \ 'git-mv path2 path1' |