git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 2/5] rebase -r: do not write MERGE_HEAD unless needed

From
Johannes Schindelin via GitGitGadget <gitgitgadget@gmail.com>
Date
Nov 12, 2018, 23:25 UTC
Message-ID
<8aa3dac3147fdd2483dd530792baf3c575d3d3aa.1542065154.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.75.git.gitgitgadget@gmail.com>
From: Johannes Schindelin <johannes.schindelin@gmx.de>

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>
---
 sequencer.c              | 8 ++++----
 t/t3430-rebase-merges.sh | 2 +-
 2 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/sequencer.c b/sequencer.c
index 9e1ab3a2a7..7a9cd81afb 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -3191,10 +3191,6 @@ static int do_merge(struct commit *commit, const char *arg, int arg_len,
 	}
 
 	merge_commit = to_merge->item;
-	write_message(oid_to_hex(&merge_commit->object.oid), GIT_SHA1_HEXSZ,
-		      git_path_merge_head(the_repository), 0);
-	write_message("no-ff", 5, git_path_merge_mode(the_repository), 0);
-
 	bases = get_merge_bases(head_commit, merge_commit);
 	if (bases && oideq(&merge_commit->object.oid,
 			   &bases->item->object.oid)) {
@@ -3203,6 +3199,10 @@ static int do_merge(struct commit *commit, const char *arg, int arg_len,
 		goto leave_merge;
 	}
 
+	write_message(oid_to_hex(&merge_commit->object.oid), GIT_SHA1_HEXSZ,
+		      git_path_merge_head(the_repository), 0);
+	write_message("no-ff", 5, git_path_merge_mode(the_repository), 0);
+
 	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 1f08a33687..cc5646836f 100755
--- a/t/t3430-rebase-merges.sh
+++ b/t/t3430-rebase-merges.sh
@@ -396,7 +396,7 @@ test_expect_success 'with --autosquash and --exec' '
 	grep "G: +G" actual
 '
 
-test_expect_failure '--continue after resolving conflicts after a merge' '
+test_expect_success '--continue after resolving conflicts after a merge' '
 	git checkout -b already-has-g E &&
 	git cherry-pick E..G &&
 	test_commit H2 &&
-- 
gitgitgadget
Previous: Junio C HamanoNext: Johannes Schindelin via GitGitGadget
Message 8 of 14 in “Assorted fixes revolving around rebase and merges”
  1. 0/5 Assorted fixes revolving around rebase and mergesJohannes Schindelin via GitGitGadget, Nov 12, 2018
  2. 1/5 rebase -r: demonstrate bug with conflicting mergesJohannes Schindelin via GitGitGadget, Nov 12, 2018
  3. Junio C HamanoNov 13, 2018
  4. Johannes SchindelinNov 13, 2018
  5. Junio C HamanoNov 13, 2018
  6. Johannes SchindelinNov 13, 2018
  7. Junio C HamanoNov 13, 2018
  8. 2/5 rebase -r: do not write MERGE_HEAD unless neededJohannes Schindelin via GitGitGadget, Nov 12, 2018
  9. 3/5 rebase -i: include MERGE_HEAD into files to clean upJohannes Schindelin via GitGitGadget, Nov 12, 2018
  10. Junio C HamanoNov 13, 2018
  11. 4/5 built-in rebase --skip/--abort: clean up stale .git/<name> filesJohannes Schindelin via GitGitGadget, Nov 12, 2018
  12. Junio C HamanoNov 13, 2018
  13. Johannes SchindelinNov 13, 2018
  14. 5/5 status: rebase and merge can be in progress at the same timeJohannes Schindelin via GitGitGadget, Nov 12, 2018

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.