git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] git-mv: search more precisely for source directory in index

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Dec 3, 2006, 19:42 UTC
Message-ID
<Pine.LNX.4.63.0612032036030.28348@wbgn013.biozentrum.uni-wuerzburg.de>
In-Reply-To
<20061203135725.GA7971@procyon.home>

A move of a directory should find the entries in the index by searching for the name _including_ the slash. Otherwise, the directory can be shadowed by a file when it matches the prefix and is lexicographically smaller, e.g. "ab.c" shadows "ab/".

Noticed by Sergey Vlasov.
Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
---
	Good catch. Thanks!
 builtin-mv.c |   11 +++++++----
 1 files changed, 7 insertions(+), 4 deletions(-)
diff --git a/builtin-mv.c b/builtin-mv.c
index 54dd3bf..d14a4a7 100644
--- a/builtin-mv.c
+++ b/builtin-mv.c
@@ -146,21 +146,24 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
 				&& lstat(dst, &st) == 0)
 			bad = "cannot move directory over file";
 		else if (src_is_dir) {
+			const char *src_w_slash = add_slash(src);
+			int len_w_slash = length + 1;
 			int first, last;
 
 			modes[i] = WORKING_DIRECTORY;
 
-			first = cache_name_pos(src, length);
+			first = cache_name_pos(src_w_slash, len_w_slash);
 			if (first >= 0)
-				die ("Huh? %s/ is in index?", src);
+				die ("Huh? %.*s is in index?",
+						len_w_slash, src_w_slash);
 
 			first = -1 - first;
 			for (last = first; last < active_nr; last++) {
 				const char *path = active_cache[last]->name;
-				if (strncmp(path, src, length)
-						|| path[length] != '/')
+				if (strncmp(path, src_w_slash, len_w_slash))
 					break;
 			}
+			free((char *)src_w_slash);
 
 			if (last - first < 1)
 				bad = "source directory is empty";
-- 
1.4.4.1.g317bd
Previous: Sergey VlasovNext: Sergey Vlasov
Message 2 of 3 in “[BUG] git-mv fails with "source directory is empty" when it should not”
  1. Sergey VlasovDec 3, 2006
  2. git-mv: search more precisely for source directory in indexJohannes Schindelin, Dec 3, 2006
  3. Sergey VlasovDec 3, 2006

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.