From 1d6249e609289940dca179b626fe4ae5433c90cc Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Wed, 16 Aug 2006 02:20:32 +0200 Subject: 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 Signed-off-by: Junio C Hamano --- builtin-mv.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'builtin-mv.c') diff --git a/builtin-mv.c b/builtin-mv.c index a731f8d9cf..e7b5eb7088 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) -- cgit v1.2.1