diff options
| author | Junio C Hamano <gitster@pobox.com> | 2025-02-27 15:23:00 -0800 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2025-02-27 15:23:00 -0800 |
| commit | c51a0b47c91106ff50a2a9dca302e80bc7049aba (patch) | |
| tree | a2d4e281d4b84d987d31866bd7b4e8e64b307e48 | |
| parent | Merge branch 'kn/ref-migrate-skip-reflog' (diff) | |
| parent | rebase -i: reword empty commit after fast-forward (diff) | |
| download | git-c51a0b47c91106ff50a2a9dca302e80bc7049aba.tar.gz git-c51a0b47c91106ff50a2a9dca302e80bc7049aba.zip | |
Merge branch 'pw/rebase-i-ff-empty-commit'
"git rebase -i" failed to allow rewording an empty commit that has
been fast-forwarded.
* pw/rebase-i-ff-empty-commit:
rebase -i: reword empty commit after fast-forward
| -rw-r--r-- | sequencer.c | 12 | ||||
| -rwxr-xr-x | t/t3404-rebase-interactive.sh | 14 | ||||
| -rwxr-xr-x | t/t3430-rebase-merges.sh | 20 |
3 files changed, 43 insertions, 3 deletions
diff --git a/sequencer.c b/sequencer.c index 407ee4e90f..ad0ab75c8d 100644 --- a/sequencer.c +++ b/sequencer.c @@ -2510,9 +2510,15 @@ static int do_pick_commit(struct repository *r, *check_todo = !!(flags & EDIT_MSG); if (!res && reword) { fast_forward_edit: - res = run_git_commit(NULL, opts, EDIT_MSG | - VERIFY_MSG | AMEND_MSG | - (flags & ALLOW_EMPTY)); + /* + * To reword we amend the commit we just + * picked or fast-forwarded. As the commit has + * already been picked we want to use the same + * set of commit flags regardless of how we + * got here. + */ + flags = EDIT_MSG | VERIFY_MSG | AMEND_MSG | ALLOW_EMPTY; + res = run_git_commit(NULL, opts, flags); *check_todo = 1; } } diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh index ecfc02062c..2aee9789a2 100755 --- a/t/t3404-rebase-interactive.sh +++ b/t/t3404-rebase-interactive.sh @@ -791,6 +791,20 @@ test_expect_success 'reword' ' grep "C changed" actual ' +test_expect_success 'reword fast-forwarded empty commit' ' + git commit --allow-empty -m "empty commit" --only && + ( + set_fake_editor && + FAKE_COMMIT_AMEND=edited FAKE_LINES="reword 1" \ + git rebase -i HEAD^ + ) && + test_commit_message HEAD <<-\EOF + empty commit + + edited + EOF +' + test_expect_success 'no uncommitted changes when rewording and the todo list is reloaded' ' git checkout E && test_when_finished "git checkout @{-1}" && diff --git a/t/t3430-rebase-merges.sh b/t/t3430-rebase-merges.sh index 2593711fec..b84d68c4b9 100755 --- a/t/t3430-rebase-merges.sh +++ b/t/t3430-rebase-merges.sh @@ -610,4 +610,24 @@ test_expect_success 'truncate label names' ' grep "label 0123456789-$" out ' +test_expect_success 'reword fast-forwarded empty merge commit' ' + oid="$(git commit-tree -m "D1" -p A D^{tree})" && + oid="$(git commit-tree -m "empty merge" -p D -p $oid D^{tree})" && + + write_script sequence-editor.sh <<-\EOF && + sed /^merge/s/-C/-c/ "$1" >"$1.tmp" + mv "$1.tmp" "$1" + EOF + + ( + test_set_sequence_editor "$(pwd)/sequence-editor.sh" && + GIT_EDITOR="echo edited >>" git rebase -i -r D $oid + ) && + test_commit_message HEAD <<-\EOF + empty merge + + edited + EOF +' + test_done |
