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

[PATCH 3/3] builtin-mv.c: check for unversionned files before looking at the destination.

From
Matthieu Moy <matthieu.moy@imag.fr>
Date
Feb 4, 2009, 09:32 UTC
Message-ID
<1233739928-19895-3-git-send-email-Matthieu.Moy@imag.fr>
In-Reply-To
<1233739928-19895-2-git-send-email-Matthieu.Moy@imag.fr>

The previous code was failing in the case where one moves an unversionned file to an existing destination, with mv -f: the "existing destination" was checked first, and the error was cancelled by the force flag.

We now check the unrecoverable error first, which fixes the bug.
Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>
---
 builtin-mv.c  |    8 ++++----
 t/t7001-mv.sh |    2 +-
 2 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/builtin-mv.c b/builtin-mv.c
index bce9959..01270fe 100644
--- a/builtin-mv.c
+++ b/builtin-mv.c
@@ -162,7 +162,9 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
 				}
 				argc += last - first;
 			}
-		} else if (lstat(dst, &st) == 0) {
+		} else if (cache_name_pos(src, length) < 0)
+			bad = "not under version control";
+		else if (lstat(dst, &st) == 0) {
 			bad = "destination exists";
 			if (force) {
 				/*
@@ -177,9 +179,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
 				} else
 					bad = "Cannot overwrite";
 			}
-		} else if (cache_name_pos(src, length) < 0)
-			bad = "not under version control";
-		else if (string_list_has_string(&src_for_dst, dst))
+		} else if (string_list_has_string(&src_for_dst, dst))
 			bad = "multiple sources for the same target";
 		else
 			string_list_insert(dst, &src_for_dst);
diff --git a/t/t7001-mv.sh b/t/t7001-mv.sh
index 52a47b5..8fb3a56 100755
--- a/t/t7001-mv.sh
+++ b/t/t7001-mv.sh
@@ -58,7 +58,7 @@ test_expect_success \
      test ! -f path0/untracked1 &&
      test ! -f path0/untracked2'
 
-test_expect_failure \
+test_expect_success \
     'checking -f on untracked file with existing target' \
     'touch path0/untracked1 &&
      git mv -f untracked1 path0
-- 
1.6.1.2.321.g68da9
Previous: Matthieu MoyNext: Junio C Hamano
Message 3 of 4 in “Missing && in t/t7001.sh.”
  1. 1/3 Missing && in t/t7001.sh.Matthieu Moy, Feb 4, 2009
  2. 2/3 [BUG] Add a testcase for "git mv -f" on untracked files.Matthieu Moy, Feb 4, 2009
  3. 3/3 builtin-mv.c: check for unversionned files before looking at the destination.Matthieu Moy, Feb 4, 2009
  4. Junio C HamanoFeb 4, 2009

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.