@matheusbsbs / matheus-bagliano / commits / 5aed3c6ab8
Fork 0

builtin-mv.c: check for unversionned files before looking at the destination.

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> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Matthieu Moy committed Feb 4, 2009 at 10:32 UTC 5aed3c6ab834367292bd7a9b0894177a07afd910
2 files changed +5 -5
builtin-mv.c
+4 -4
@@ -162,7 +162,9 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
162 }
163 argc += last - first;
164 }
165 - } else if (lstat(dst, &st) == 0) {
165 + } else if (cache_name_pos(src, length) < 0)
166 + bad = "not under version control";
167 + else if (lstat(dst, &st) == 0) {
168 bad = "destination exists";
169 if (force) {
170 /*
@@ -177,9 +179,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
179 } else
180 bad = "Cannot overwrite";
181 }
180 - } else if (cache_name_pos(src, length) < 0)
181 - bad = "not under version control";
182 - else if (string_list_has_string(&src_for_dst, dst))
182 + } else if (string_list_has_string(&src_for_dst, dst))
183 bad = "multiple sources for the same target";
184 else
185 string_list_insert(dst, &src_for_dst);
t/t7001-mv.sh
+1 -1
@@ -58,7 +58,7 @@ test_expect_success \
58 test ! -f path0/untracked1 &&
59 test ! -f path0/untracked2'
60
61 -test_expect_failure \
61 +test_expect_success \
62 'checking -f on untracked file with existing target' \
63 'touch path0/untracked1 &&
64 git mv -f untracked1 path0