rm: resolving by removal is not a warning-worthy event
authorJunio C Hamano <gitster@pobox.com>
Wed, 17 Jul 2019 20:28:24 +0000 (13:28 -0700)
committerJunio C Hamano <gitster@pobox.com>
Thu, 18 Jul 2019 21:47:28 +0000 (14:47 -0700)
When resolving a conflict on a path in favor of removing it, using
"git rm" on it is the standard way to do so. The user however is
greeted with a "needs merge" message during that operation:

$ git merge side-branch
$ edit conflicted-path-1
$ git add conflicted-path-1
$ git rm conflicted-path-2
conflicted-path-2: needs merge
rm 'conflicted-path-2'

The removal by "git rm" does get performed, but an uninitiated user
may find it confusing, "needs merge? so I need to resolve conflict
before being able to remove it???"

The message is coming from "update-index --refresh" that is called
internally to make sure "git rm" knows which paths are clean and
which paths are dirty, in order to prevent removal of paths modified
relative to the index without the "-f" option. We somehow ended up
not squelching this message which seeped through to the UI surface.

Use the same mechanism used by "git commit", "git describe", etc. to
squelch the message.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/rm.c
t/t3600-rm.sh
index 17086d3d97c536522720c589ea8f35d366536ea8..3ddce9cf061336223346caca8c1795da9be733ac 100644 (file)
@@ -272,7 +272,7 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
        parse_pathspec(&pathspec, 0,
                       PATHSPEC_PREFER_CWD,
                       prefix, argv);
        parse_pathspec(&pathspec, 0,
                       PATHSPEC_PREFER_CWD,
                       prefix, argv);
-       refresh_index(&the_index, REFRESH_QUIET, &pathspec, NULL, NULL);
+       refresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED, &pathspec, NULL, NULL);
 
        seen = xcalloc(pathspec.nr, 1);
 
 
        seen = xcalloc(pathspec.nr, 1);
 
index 04e5d42bd3b82a7bf683659f6fdd8e20813df770..a4d25c8b083640373efc96c48fcbe5beeffb1835 100755 (executable)
@@ -249,6 +249,19 @@ test_expect_success 'choking "git rm" should not let it die with cruft' '
        test_path_is_missing .git/index.lock
 '
 
        test_path_is_missing .git/index.lock
 '
 
+test_expect_success 'Resolving by removal is not a warning-worthy event' '
+       git reset -q --hard &&
+       test_when_finished "rm -f .git/index.lock msg && git reset -q --hard" &&
+       blob=$(echo blob | git hash-object -w --stdin) &&
+       for stage in 1 2 3
+       do
+               echo "100644 $blob $stage       blob"
+       done | git update-index --index-info &&
+       git rm blob >msg 2>&1 &&
+       test_i18ngrep ! "needs merge" msg &&
+       test_must_fail git ls-files -s --error-unmatch blob
+'
+
 test_expect_success 'rm removes subdirectories recursively' '
        mkdir -p dir/subdir/subsubdir &&
        echo content >dir/subdir/subsubdir/file &&
 test_expect_success 'rm removes subdirectories recursively' '
        mkdir -p dir/subdir/subsubdir &&
        echo content >dir/subdir/subsubdir/file &&