]> git.ipfire.org Git - thirdparty/git.git/commitdiff
git-mv: improve error message for conflicted file
authorChris Torek <chris.torek@gmail.com>
Mon, 20 Jul 2020 06:17:52 +0000 (06:17 +0000)
committerJunio C Hamano <gitster@pobox.com>
Mon, 20 Jul 2020 21:35:43 +0000 (14:35 -0700)
'git mv' has always complained about renaming a conflicted
file, as it cannot handle multiple index entries for one file.
However, the error message it uses has been the same as the
one for an untracked file:

    fatal: not under version control, src=...

which is patently wrong.  Distinguish the two cases and
add a test to make sure we produce the correct message.

Signed-off-by: Chris Torek <chris.torek@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/mv.c
t/t7001-mv.sh

index be15ba7044e0eeeee216a9e6c4615214cd7cdc1e..7dac714af908789c675a158cf44067771dd62ad2 100644 (file)
@@ -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) {
index 36b50d0b4c1255408d57b4e8b583cfcd41ce9c0d..c978b6dee4a2559d5d4e4a8a9329f9288de93231 100755 (executable)
@@ -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 &&