]> granicus.if.org Git - git/commitdiff
rebase --rebase-merges: avoid "empty merges"
authorJohannes Schindelin <johannes.schindelin@gmx.de>
Wed, 25 Apr 2018 12:29:31 +0000 (14:29 +0200)
committerJunio C Hamano <gitster@pobox.com>
Thu, 26 Apr 2018 03:28:43 +0000 (12:28 +0900)
The `git merge` command does not allow merging commits that are already
reachable from HEAD: `git merge HEAD^`, for example, will report that we
are already up to date and not change a thing.

In an interactive rebase, such a merge could occur previously, e.g. when
competing (or slightly modified) versions of a patch series were applied
upstream, and the user had to `git rebase --skip` all of the local
commits, and the topic branch becomes "empty" as a consequence.

Let's teach the todo command `merge` to behave the same as `git merge`.

Seeing as it requires some low-level trickery to create such merges with
Git's commands in the first place, we do not even have to bother to
introduce an option to force `merge` to create such merge commits.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
sequencer.c
t/t3430-rebase-merges.sh

index 558efc1af6e20e8abfe664d5c647e14216dc127f..afa155c28290ad069e0e2fef64e9447526f8c78f 100644 (file)
@@ -2810,6 +2810,13 @@ static int do_merge(struct commit *commit, const char *arg, int arg_len,
        write_message("no-ff", 5, git_path_merge_mode(), 0);
 
        bases = get_merge_bases(head_commit, merge_commit);
+       if (bases && !oidcmp(&merge_commit->object.oid,
+                            &bases->item->object.oid)) {
+               ret = 0;
+               /* skip merging an ancestor of HEAD */
+               goto leave_merge;
+       }
+
        for (j = bases; j; j = j->next)
                commit_list_insert(j->item, &reversed);
        free_commit_list(bases);
index e9c5dc1cd95a334448efbda43d09a3ab0456f1e2..1628c8dcc20a4df7a5007efae1ca97a03068b948 100755 (executable)
@@ -215,4 +215,12 @@ test_expect_success 'post-rewrite hook and fixups work for merges' '
        test_cmp expect actual
 '
 
+test_expect_success 'refuse to merge ancestors of HEAD' '
+       echo "merge HEAD^" >script-from-scratch &&
+       test_config -C wt sequence.editor \""$PWD"/replace-editor.sh\" &&
+       before="$(git rev-parse HEAD)" &&
+       git rebase -i HEAD &&
+       test_cmp_rev HEAD $before
+'
+
 test_done