aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2020-07-30 13:20:35 -0700
committerJunio C Hamano <gitster@pobox.com>2020-07-30 13:20:35 -0700
commitbe2dab9c801fe28a6937e8d426f891e610a82a49 (patch)
tree110244fa8330ee5cd0a0ffe30f398a69a83e6aca
parentMerge branch 'bc/push-cas-cquoted-refname' into master (diff)
parentgit-mv: improve error message for conflicted file (diff)
downloadgit-be2dab9c801fe28a6937e8d426f891e610a82a49.tar.gz
git-be2dab9c801fe28a6937e8d426f891e610a82a49.zip
Merge branch 'ct/mv-unmerged-path-error' into master
"git mv src dst", when src is an unmerged path, errored out correctly but with an incorrect error message to claim that src is not tracked, which has been clarified. * ct/mv-unmerged-path-error: git-mv: improve error message for conflicted file
-rw-r--r--builtin/mv.c7
-rwxr-xr-xt/t7001-mv.sh17
2 files changed, 22 insertions, 2 deletions
diff --git a/builtin/mv.c b/builtin/mv.c
index be15ba7044..7dac714af9 100644
--- a/builtin/mv.c
+++ b/builtin/mv.c
@@ -132,6 +132,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
struct stat st;
struct string_list src_for_dst = STRING_LIST_INIT_NODUP;
struct lock_file lock_file = LOCK_INIT;
+ struct cache_entry *ce;
git_config(git_default_config, NULL);
@@ -220,9 +221,11 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
}
argc += last - first;
}
- } else if (cache_name_pos(src, length) < 0)
+ } else if (!(ce = cache_file_exists(src, length, ignore_case))) {
bad = _("not under version control");
- else if (lstat(dst, &st) == 0 &&
+ } else if (ce_stage(ce)) {
+ bad = _("conflicted");
+ } else if (lstat(dst, &st) == 0 &&
(!ignore_case || strcasecmp(src, dst))) {
bad = _("destination exists");
if (force) {
diff --git a/t/t7001-mv.sh b/t/t7001-mv.sh
index 36b50d0b4c..c978b6dee4 100755
--- a/t/t7001-mv.sh
+++ b/t/t7001-mv.sh
@@ -248,6 +248,23 @@ test_expect_success 'git mv should not change sha1 of moved cache entry' '
rm -f dirty dirty2
+# NB: This test is about the error message
+# as well as the failure.
+test_expect_success 'git mv error on conflicted file' '
+ rm -fr .git &&
+ git init &&
+ >conflict &&
+ test_when_finished "rm -f conflict" &&
+ cfhash=$(git hash-object -w conflict) &&
+ q_to_tab <<-EOF | git update-index --index-info &&
+ 0 $cfhash 0Qconflict
+ 100644 $cfhash 1Qconflict
+ EOF
+
+ test_must_fail git mv conflict newname 2>actual &&
+ test_i18ngrep "conflicted" actual
+'
+
test_expect_success 'git mv should overwrite symlink to a file' '
rm -fr .git &&