Skip to content

Commit 5aed3c6

Browse files
moygitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c8ba6b1 commit 5aed3c6

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

builtin-mv.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,9 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
162162
}
163163
argc += last - first;
164164
}
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) {
166168
bad = "destination exists";
167169
if (force) {
168170
/*
@@ -177,9 +179,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
177179
} else
178180
bad = "Cannot overwrite";
179181
}
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))
183183
bad = "multiple sources for the same target";
184184
else
185185
string_list_insert(dst, &src_for_dst);

t/t7001-mv.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ test_expect_success \
5858
test ! -f path0/untracked1 &&
5959
test ! -f path0/untracked2'
6060

61-
test_expect_failure \
61+
test_expect_success \
6262
'checking -f on untracked file with existing target' \
6363
'touch path0/untracked1 &&
6464
git mv -f untracked1 path0

0 commit comments

Comments
 (0)