diff options
-rw-r--r-- | sequencer.c | 7 | ||||
-rwxr-xr-x | t/t3430-rebase-merges.sh | 8 |
2 files changed, 15 insertions, 0 deletions
diff --git a/sequencer.c b/sequencer.c index 558efc1af6..afa155c282 100644 --- a/sequencer.c +++ b/sequencer.c @@ -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); diff --git a/t/t3430-rebase-merges.sh b/t/t3430-rebase-merges.sh index e9c5dc1cd9..1628c8dcc2 100755 --- a/t/t3430-rebase-merges.sh +++ b/t/t3430-rebase-merges.sh @@ -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 |