Skip to content

Commit

Permalink
builtin-mv.c: check for unversionned files before looking at the dest…
Browse files Browse the repository at this point in the history
…ination.

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>
  • Loading branch information
moy authored and gitster committed Feb 4, 2009
1 parent c8ba6b1 commit 5aed3c6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions builtin-mv.c
Expand Up @@ -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) {
/*
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion t/t7001-mv.sh
Expand Up @@ -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
Expand Down

0 comments on commit 5aed3c6

Please sign in to comment.