From baf8ec8d3a0327307f79efd31d5717a0c91c4d8c Mon Sep 17 00:00:00 2001 From: Phillip Wood Date: Fri, 20 Aug 2021 15:40:37 +0000 Subject: rebase -r: don't write .git/MERGE_MSG when fast-forwarding MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When fast-forwarding we do not create a new commit so .git/MERGE_MSG is not removed and can end up seeding the message of a commit made after the rebase has finished. Avoid writing .git/MERGE_MSG when we are fast-forwarding by writing the file after the fast-forward checks. Note that there are no changes to the fast-forward code, it is simply moved. Note that the way this change is implemented means we no longer write the author script when fast-forwarding either. I believe this is safe for the reasons below but it is a departure from what we do when fast-forwarding a non-merge commit. If we reword the merge then 'git commit --amend' will keep the authorship of the commit we're rewording as it ignores GIT_AUTHOR_* unless --reset-author is passed. It will also export the correct GIT_AUTHOR_* variables to any hooks and we already test the authorship of the reworded commit. If we are not rewording then we no longer call spilt_ident() which means we are no longer checking the commit author header looks sane. However this is what we already do when fast-forwarding non-merge commits in skip_unnecessary_picks() so I don't think we're breaking any promises by not checking the author here. Reported-by: SZEDER Gábor Signed-off-by: Phillip Wood Signed-off-by: Junio C Hamano --- t/lib-rebase.sh | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 't') diff --git a/t/lib-rebase.sh b/t/lib-rebase.sh index 99d9e7efd2..ec6b9b107d 100644 --- a/t/lib-rebase.sh +++ b/t/lib-rebase.sh @@ -173,10 +173,16 @@ set_reword_editor () { write_script reword-editor.sh <<-EOF && # Save the oid of the first reworded commit so we can check rebase - # fast-forwards to it + # fast-forwards to it. Also check that we do not write .git/MERGE_MSG + # when fast-forwarding if ! test -s reword-oid then - git rev-parse HEAD >reword-oid + git rev-parse HEAD >reword-oid && + if test -f .git/MERGE_MSG + then + echo 1>&2 "error: .git/MERGE_MSG exists" + exit 1 + fi fi && # There should be no uncommited changes git diff --exit-code HEAD && -- cgit v1.2.3