git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [BUG] 'git rebase -i ---rebase-merges' can leave MERGE_MSG behind
@ 2021-07-31  6:23 SZEDER Gábor
  2021-08-01  9:56 ` Phillip Wood
  0 siblings, 1 reply; 3+ messages in thread
From: SZEDER Gábor @ 2021-07-31  6:23 UTC (permalink / raw)
  To: git

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [BUG] 'git rebase -i ---rebase-merges' can leave MERGE_MSG behind
  2021-07-31  6:23 [BUG] 'git rebase -i ---rebase-merges' can leave MERGE_MSG behind SZEDER Gábor
@ 2021-08-01  9:56 ` Phillip Wood
  2021-08-05 12:58   ` Phillip Wood
  0 siblings, 1 reply; 3+ messages in thread
From: Phillip Wood @ 2021-08-01  9:56 UTC (permalink / raw)
  To: SZEDER Gábor, git

On 31/07/2021 07:23, SZEDER Gábor wrote:
> 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 :)

Looking at do_merge() in sequencer.c .git/MERGE_MSG is written before it 
checks if it can fast-forward. If it does fast-forward then 'git commit' 
is not run and .git/MERGE_MSG is not removed. I think the best way to 
fix it would be to move the fast-forward code so it comes before the 
code that writes .git/MERGE_MSG. That way we'll not write the message if 
we can fast-forward.

Best Wishes

Phillip

> 
>    ---  >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
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [BUG] 'git rebase -i ---rebase-merges' can leave MERGE_MSG behind
  2021-08-01  9:56 ` Phillip Wood
@ 2021-08-05 12:58   ` Phillip Wood
  0 siblings, 0 replies; 3+ messages in thread
From: Phillip Wood @ 2021-08-05 12:58 UTC (permalink / raw)
  To: SZEDER Gábor, git

On 01/08/2021 10:56, Phillip Wood wrote:
> On 31/07/2021 07:23, SZEDER Gábor wrote:
>> 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 :)
> 
> Looking at do_merge() in sequencer.c .git/MERGE_MSG is written before it 
> checks if it can fast-forward. If it does fast-forward then 'git commit' 
> is not run and .git/MERGE_MSG is not removed. I think the best way to 
> fix it would be to move the fast-forward code so it comes before the 
> code that writes .git/MERGE_MSG. That way we'll not write the message if 
> we can fast-forward.

I've spotted a couple of other small issues in do_merge(), I'll try and 
post some patches next week.

Best Wishes

Phillip


> Best Wishes
> 
> Phillip
> 
>>
>>    ---  >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
>>


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-08-05 12:58 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-31  6:23 [BUG] 'git rebase -i ---rebase-merges' can leave MERGE_MSG behind SZEDER Gábor
2021-08-01  9:56 ` Phillip Wood
2021-08-05 12:58   ` Phillip Wood

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).