The to-do list command `reword` replays a commit like `pick` but lets
the user also edit the commit's log message. If `--keep-empty` is
passed as option to git-rebase--interactive, empty commits ought to
be replayed without complaints. However, if the users chooses to
reword an empty commit by changing the respective to-do list entry
from
pick fa1afe1 Empty commit
to
reword fa1afe1 Empty commit
, then git-rebase--interactive suddenly fails to replay the empty
commit. This is especially counterintuitive because `reword` is
thought of as a `pick` that alters the log message in some way but
nothing more and the unchanged to-do list entry would not fail.
Handle `reword` by cherry-picking the named commit and editing the
log message using
git commit --allow-empty --amend
instead of
git commit --amend.
Add test.
Signed-off-by: Fabian Ruch <[email protected]>
---
git-rebase--interactive.sh | 2 +-
t/t3404-rebase-interactive.sh | 24 ++++++++++++++++++++++++
2 files changed, 25 insertions(+), 1 deletion(-)
diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index 8820eac..89ef5e2 100644
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -504,7 +504,7 @@ do_next () {
mark_action_done
do_pick $sha1 "$rest"
- git commit --amend --no-post-rewrite
${gpg_sign_opt:+"$gpg_sign_opt"} || {
+ git commit --allow-empty --amend --no-post-rewrite
${gpg_sign_opt:+"$gpg_sign_opt"} || {
warn "Could not amend commit after successfully picking
$sha1... $rest"
warn "This is most likely due to an empty commit
message, or the pre-commit hook"
warn "failed. If the pre-commit hook failed, you may
need to resolve the issue before"
diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh
index a95cb2a..3e64280 100755
--- a/t/t3404-rebase-interactive.sh
+++ b/t/t3404-rebase-interactive.sh
@@ -75,6 +75,30 @@ test_expect_success 'rebase --keep-empty' '
test_line_count = 6 actual
'
+test_expect_success 'rebase --keep-empty (reword)' '
+ git checkout -b reword-emptybranch emptybranch &&
+ set_fake_editor &&
+ FAKE_LINES="1 reword 2" git rebase --keep-empty -i HEAD~2 &&
+ git log --oneline >actual &&
+ test_line_count = 6 actual
+'
+
+test_expect_success 'rebase --keep-empty (fixup)' '
+ git checkout -b fixup-emptybranch emptybranch &&
+ set_fake_editor &&
+ FAKE_LINES="1 fixup 2" git rebase --keep-empty -i HEAD~2 &&
+ git log --oneline >actual &&
+ test_line_count = 5 actual
+'
+
+test_expect_success 'rebase --keep-empty (squash)' '
+ git checkout -b squash-emptybranch emptybranch &&
+ set_fake_editor &&
+ FAKE_LINES="1 squash 2" git rebase --keep-empty -i HEAD~2 &&
+ git log --oneline >actual &&
+ test_line_count = 5 actual
+'
+
test_expect_success 'rebase -i with the exec command' '
git checkout master &&
(
--
2.0.1
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html