git-rebase--interactive handles empty log messages inconsistently
between enabled and disabled fast-forwards. By default, commits with
empty log messages are rebased successfully like in non-interactive
mode. In contrast, the `--no-ff` option aborts the replay of such
commits.

In line with not verifying rebased commits and behaving like
git-rebase for `pick` lines, use the `--allow-empty-message` option
to replay commits. Root commits are replayed by recreating them in
`do_pick` using git-commit and commits with parents are replayed
using git-cherry-pick in `pick_one`. Apply the option, understood by
both git-commit and git-cherry-pick, at the respective sites.

In case of `reword` and `squash`/`fixup` continue to abort the rebase
if the resulting commit would have no commit message. The rationale
behind this default is that patches and their log messages should be
verified at least once. For unchanged commits this is assumed to have
happened according to the author's standards when she created the
commits the first time. While the empty log message can always be
kept in place by editing and resuming the aborted rebase, a debatable
alternative could be to teach git-rebase--interactive the option
`--allow-empty-message` for disabling complaints about empty log
messages in changed commits. The to-do list command `edit` is handled
just like `pick` for this matter, because git-rebase--interactive
replays the named commit without changes before the rebase is
interrupted and the user can make her changes to the replayed commit.

Add tests.

Signed-off-by: Fabian Ruch <baf...@gmail.com>
---
 git-rebase--interactive.sh    |  4 ++--
 t/t3404-rebase-interactive.sh | 24 ++++++++++++++++++++++++
 t/t3412-rebase-root.sh        | 19 +++++++++++++++++++
 3 files changed, 45 insertions(+), 2 deletions(-)

diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index 4c875d5..6e2c429 100644
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -249,7 +249,7 @@ pick_one () {
 
        test -d "$rewritten" &&
                pick_one_preserving_merges "$@" && return
-       output eval git cherry-pick \
+       output eval git cherry-pick --allow-empty-message \
                        ${gpg_sign_opt:+$(git rev-parse --sq-quote 
"$gpg_sign_opt")} \
                        "$strategy_args" $empty_args $ff "$@"
 }
@@ -363,7 +363,7 @@ pick_one_preserving_merges () {
                        echo "$sha1 $(git rev-parse HEAD^0)" >> 
"$rewritten_list"
                        ;;
                *)
-                       output eval git cherry-pick \
+                       output eval git cherry-pick --allow-empty-message \
                                ${gpg_sign_opt:+$(git rev-parse --sq-quote 
"$gpg_sign_opt")} \
                                "$strategy_args" "$@" ||
                                die_with_patch $sha1 "Could not pick $sha1"
diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh
index 2da4b9c..2e8fa27 100755
--- a/t/t3404-rebase-interactive.sh
+++ b/t/t3404-rebase-interactive.sh
@@ -1085,4 +1085,28 @@ test_expect_success 'short SHA-1 collide' '
        )
 '
 
+test_expect_success 'rebase commits with empty commit log messages' '
+       git checkout -b no-msg-commit &&
+       test_commit no-msg-commit-1 &&
+       git commit --amend --allow-empty-message -m " " &&
+       test_commit no-msg-commit-2 &&
+       git commit --amend --allow-empty-message -m " " &&
+       EDITOR=true git rebase -i HEAD^ &&
+       EDITOR=true git rebase -i --no-ff HEAD^
+'
+
+test_expect_success 'reword commit with empty commit log message' '
+       git checkout no-msg-commit &&
+       test_when_finished reset_rebase &&
+       set_fake_editor &&
+       test_must_fail env FAKE_LINES="reword 1" git rebase -i HEAD^
+'
+
+test_expect_success 'squash commits with empty commit log messages' '
+       git checkout no-msg-commit &&
+       test_when_finished reset_rebase &&
+       set_fake_editor &&
+       test_must_fail env FAKE_LINES="1 squash 2" git rebase -i HEAD^^
+'
+
 test_done
diff --git a/t/t3412-rebase-root.sh b/t/t3412-rebase-root.sh
index 0b52105..798c9f1 100755
--- a/t/t3412-rebase-root.sh
+++ b/t/t3412-rebase-root.sh
@@ -278,4 +278,23 @@ test_expect_success 'rebase -i -p --root with conflict 
(second part)' '
        test_cmp expect-conflict-p out
 '
 
+test_expect_success 'rebase --root with empty root log message' '
+       git checkout --orphan no-msg-root-commit &&
+       test_commit no-msg-root-commit &&
+       git commit --amend -m " " --allow-empty-message &&
+       git rebase --root &&
+       test_path_is_file no-msg-root-commit.t &&
+       git rebase --root --no-ff &&
+       test_path_is_file no-msg-root-commit.t
+'
+
+test_expect_success 'rebase --root with empty child log message' '
+       test_commit no-msg-child-commit &&
+       git commit --amend -m " " --allow-empty-message &&
+       git rebase --root &&
+       test_path_is_file no-msg-child-commit.t &&
+       git rebase --root --no-ff &&
+       test_path_is_file no-msg-child-commit.t
+'
+
 test_done
-- 
2.0.1

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to