rebase -r: do not write MERGE_HEAD unless needed
When we detect that a `merge` can be skipped because the merged commit is already an ancestor of HEAD, we do not need to commit, therefore writing the MERGE_HEAD file is useless. It is actually worse than useless: a subsequent `git commit` will pick it up and think that we want to merge that commit, still. To avoid that, move the code that writes the MERGE_HEAD file to a location where we already know that the `merge` cannot be skipped. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Johannes Schindelin committed
Nov 12, 2018 at 15:25 UTC
85f8d9da2182690461e05034a4a697f766bb8eb1
2 files changed
+5
-5
sequencer.c
+4
-4
@@ -3191,10 +3191,6 @@ static int do_merge(struct commit *commit, const char *arg, int arg_len,
3191
}
3192
3193
merge_commit = to_merge->item;
3194
- write_message(oid_to_hex(&merge_commit->object.oid), GIT_SHA1_HEXSZ,
3195
- git_path_merge_head(the_repository), 0);
3196
- write_message("no-ff", 5, git_path_merge_mode(the_repository), 0);
3197
-
3194
bases = get_merge_bases(head_commit, merge_commit);
3195
if (bases && oideq(&merge_commit->object.oid,
3196
&bases->item->object.oid)) {
@@ -3203,6 +3199,10 @@ static int do_merge(struct commit *commit, const char *arg, int arg_len,
3199
goto leave_merge;
3200
}
3201
3202
+ write_message(oid_to_hex(&merge_commit->object.oid), GIT_SHA1_HEXSZ,
3203
+ git_path_merge_head(the_repository), 0);
3204
+ write_message("no-ff", 5, git_path_merge_mode(the_repository), 0);
3205
+
3206
for (j = bases; j; j = j->next)
3207
commit_list_insert(j->item, &reversed);
3208
free_commit_list(bases);
t/t3430-rebase-merges.sh
+1
-1
@@ -396,7 +396,7 @@ test_expect_success 'with --autosquash and --exec' '
396
grep "G: +G" actual
397
'
398
399
-test_expect_failure '--continue after resolving conflicts after a merge' '
399
+test_expect_success '--continue after resolving conflicts after a merge' '
400
git checkout -b already-has-g E &&
401
git cherry-pick E..G &&
402
test_commit H2 &&