Skip to content

Commit 769f8a8

Browse files
committed
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 <[email protected]>
1 parent 54f947e commit 769f8a8

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

sequencer.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3184,10 +3184,6 @@ static int do_merge(struct commit *commit, const char *arg, int arg_len,
31843184
}
31853185

31863186
merge_commit = to_merge->item;
3187-
write_message(oid_to_hex(&merge_commit->object.oid), GIT_SHA1_HEXSZ,
3188-
git_path_merge_head(the_repository), 0);
3189-
write_message("no-ff", 5, git_path_merge_mode(the_repository), 0);
3190-
31913187
bases = get_merge_bases(head_commit, merge_commit);
31923188
if (bases && !oidcmp(&merge_commit->object.oid,
31933189
&bases->item->object.oid)) {
@@ -3196,6 +3192,10 @@ static int do_merge(struct commit *commit, const char *arg, int arg_len,
31963192
goto leave_merge;
31973193
}
31983194

3195+
write_message(oid_to_hex(&merge_commit->object.oid), GIT_SHA1_HEXSZ,
3196+
git_path_merge_head(the_repository), 0);
3197+
write_message("no-ff", 5, git_path_merge_mode(the_repository), 0);
3198+
31993199
for (j = bases; j; j = j->next)
32003200
commit_list_insert(j->item, &reversed);
32013201
free_commit_list(bases);

t/t3430-rebase-merges.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ test_expect_success 'with --autosquash and --exec' '
396396
grep "G: +G" actual
397397
'
398398

399-
test_expect_failure '--continue after resolving conflicts after a merge' '
399+
test_expect_success '--continue after resolving conflicts after a merge' '
400400
git checkout -b already-has-g E &&
401401
git cherry-pick E..G &&
402402
test_commit H2 &&

0 commit comments

Comments
 (0)