Skip to content

Commit b2b1f61

Browse files
committed
rm: resolving by removal is not a warning-worthy event
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 <[email protected]>
1 parent 0d0ac38 commit b2b1f61

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

builtin/rm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
272272
parse_pathspec(&pathspec, 0,
273273
PATHSPEC_PREFER_CWD,
274274
prefix, argv);
275-
refresh_index(&the_index, REFRESH_QUIET, &pathspec, NULL, NULL);
275+
refresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED, &pathspec, NULL, NULL);
276276

277277
seen = xcalloc(pathspec.nr, 1);
278278

t/t3600-rm.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,19 @@ test_expect_success 'choking "git rm" should not let it die with cruft' '
249249
test_path_is_missing .git/index.lock
250250
'
251251

252+
test_expect_success 'Resolving by removal is not a warning-worthy event' '
253+
git reset -q --hard &&
254+
test_when_finished "rm -f .git/index.lock msg && git reset -q --hard" &&
255+
blob=$(echo blob | git hash-object -w --stdin) &&
256+
for stage in 1 2 3
257+
do
258+
echo "100644 $blob $stage blob"
259+
done | git update-index --index-info &&
260+
git rm blob >msg 2>&1 &&
261+
test_i18ngrep ! "needs merge" msg &&
262+
test_must_fail git ls-files -s --error-unmatch blob
263+
'
264+
252265
test_expect_success 'rm removes subdirectories recursively' '
253266
mkdir -p dir/subdir/subsubdir &&
254267
echo content >dir/subdir/subsubdir/file &&

0 commit comments

Comments
 (0)