summaryrefslogtreecommitdiff
path: root/sequencer.c
diff options
context:
space:
mode:
authorPhillip Wood <phillip.wood@dunelm.org.uk>2025-02-11 15:59:08 +0000
committerJunio C Hamano <gitster@pobox.com>2025-02-11 09:50:53 -0800
commitaf8fc7be10fa486c93acfb177af4dd1fa7757deb (patch)
tree4c14cf2c0e780c3ce6d8348f253dcd7302380771 /sequencer.c
parentf93ff170b93a1782659637824b25923245ac9dd1 (diff)
rebase -i: reword empty commit after fast-forward
When rebase rewords a commit it picks the commit and then runs "git commit --amend" to reword it. When the commit is picked the sequencer tries to reuse existing commits by fast-forwarding if the parents are unchanged. Rewording an empty commit that has been fast-forwarded fails because "git commit --amend" is called without "--allow-empty". This happens because when a commit is fast-forwarded the logic that checks whether we should pass "--allow-empty" is skipped. Fix this by always passing "--allow-empty" when rewording a commit. This is safe because we are amending a commit that has already been picked so if it had become empty when it was picked we'd have already returned an error. As "git commit" will happily create empty merge commits without "--allow-empty" we do not need to pass that flag when rewording merge commits. Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'sequencer.c')
-rw-r--r--sequencer.c12
1 files changed, 9 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;
}
}