git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[BUG] 'git rebase -i ---rebase-merges' can leave MERGE_MSG behind

From
SZEDER Gábor <szeder.dev@gmail.com>
Date
Jul 31, 2021, 06:23 UTC
Message-ID
<20210731062322.GB23408@szeder.dev>
Hi,

'git rebase -i --rebase-merges' leaves a stray '.git/MERGE_MSG' file behind after it re-created an unchanged merge commit. The test script below demonstrates this issue (it doesn't fail, but look at its verbose output to see what the issue and its consequences are).

This issue is as old as --rebase-merges, I see the same output with v2.18.0, the first release containing this feature.

I suspect that fixing this is merely a matter of adding a missing unlink(".git/MERGE_MSG") to the right place, but I won't dive into the sequencer machinery to figure out where that right place might be :)

  ---  >8  ---
#!/bin/sh
test_description='test'

. ./test-lib.sh . "$TEST_DIRECTORY"/lib-rebase.sh

test_expect_success '--rebase-merges leaves MERGE_MSG behind' '
	# A-B-M-D-E-F
	#  \ /
	#   C
	test_commit A &&
	test_commit B &&
	git checkout -b branch HEAD^ &&
	test_commit C &&
	git checkout master &&
	git merge --log branch &&
	test_commit D &&
	test_commit E &&
	test_commit F &&
	# Rewrite a commit after the merge:
	write_script todo-editor <<-\EOF &&
	sed -i -e "/^pick .* E$/ s/^pick/edit/" "$1"
	EOF
	# No MERGE_MSG present before starting the rebase, good:
	test_path_is_missing .git/MERGE_MSG &&
	# Start rebasing before the merge, so the sequencer has to
	# re-create an identical merge commit.
	GIT_EDITOR=./todo-editor git rebase -i --rebase-merges A &&
	# Just to make sure that the history so far is unchanged:
	test_cmp_rev E HEAD &&
	# BUG: now there is a stray MERGE_MSG file:
	cat .git/MERGE_MSG &&
	# And it interferes with the next "git commit", because its
	# content is included in the commit message template:
	echo foo >>E.t &&
	GIT_EDITOR=cat git commit -a
'
test_done
Next: Phillip Wood
Message 1 of 3 in “[BUG] 'git rebase -i ---rebase-merges' can leave MERGE_MSG behind”
  1. SZEDER GáborJul 31, 2021
  2. Phillip WoodAug 1, 2021
  3. Phillip WoodAug 5, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.