rebase -r: always reword merge -c
authorPhillip Wood <phillip.wood@dunelm.org.uk>
Thu, 2 May 2019 10:22:49 +0000 (11:22 +0100)
committerJunio C Hamano <gitster@pobox.com>
Sun, 19 May 2019 01:33:43 +0000 (10:33 +0900)
If a merge can be fast-forwarded then make sure that we still edit the
commit message if the user specifies -c. The implementation follows the
same pattern that is used for ordinary rewords that are fast-forwarded.

Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
sequencer.c
t/t3430-rebase-merges.sh
index f88a97fb10a322c21062ec8c102482677cfd0feb..9acf45863596f3a6ef654f49632052a0e1101fa7 100644 (file)
@@ -3401,6 +3401,10 @@ static int do_merge(struct repository *r,
                rollback_lock_file(&lock);
                ret = fast_forward_to(r, &commit->object.oid,
                                      &head_commit->object.oid, 0, opts);
+               if (flags & TODO_EDIT_MERGE_MSG) {
+                       run_commit_flags |= AMEND_MSG;
+                       goto fast_forward_edit;
+               }
                goto leave_merge;
        }
 
@@ -3504,6 +3508,7 @@ static int do_merge(struct repository *r,
                 * value (a negative one would indicate that the `merge`
                 * command needs to be rescheduled).
                 */
+       fast_forward_edit:
                ret = !!run_git_commit(r, git_path_merge_msg(r), opts,
                                       run_commit_flags);
 
index 42ba5b9f0981b2b7ce98e1c5c55012ef61757bab..2315649f43bdfd3b482e8fb1e0a318ccc17dad86 100755 (executable)
@@ -164,6 +164,19 @@ test_expect_success 'failed `merge <branch>` does not crash' '
        grep "^Merge branch ${SQ}G${SQ}$" .git/rebase-merge/message
 '
 
+test_expect_success 'fast-forward merge -c still rewords' '
+       git checkout -b fast-forward-merge-c H &&
+       (
+               set_fake_editor &&
+               FAKE_COMMIT_MESSAGE=edited \
+                       GIT_SEQUENCE_EDITOR="echo merge -c H G >" \
+                       git rebase -ir @^
+       ) &&
+       echo edited >expected &&
+       git log --pretty=format:%B -1 >actual &&
+       test_cmp expected actual
+'
+
 test_expect_success 'with a branch tip that was cherry-picked already' '
        git checkout -b already-upstream master &&
        base="$(git rev-parse --verify HEAD)" &&