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

[PATCH 5/6] rebase --rebase-merges: a "merge" into a new root is a fast-forward

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Apr 27, 2018, 22:31 UTC
Message-ID
<0b7379b576be2cee807b8237dc52e5412663a2fd.1524868165.git.johannes.schindelin@gmx.de>
In-Reply-To
<cover.1524868165.git.johannes.schindelin@gmx.de>
When a user provides a todo list containing something like
	reset [new root]
	merge my-branch

let's do the same as if pulling into an orphan branch: simply fast-forward.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
 sequencer.c              | 12 ++++++++++++
 t/t3430-rebase-merges.sh | 13 +++++++++++++
 2 files changed, 25 insertions(+)
diff --git a/sequencer.c b/sequencer.c
index d10ebd62520..ad5ff2709a6 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -2850,6 +2850,18 @@ static int do_merge(struct commit *commit, const char *arg, int arg_len,
 		goto leave_merge;
 	}
 
+	if (opts->have_squash_onto &&
+	    !oidcmp(&head_commit->object.oid, &opts->squash_onto)) {
+		/*
+		 * When the user tells us to "merge" something into a
+		 * "[new root]", let's simply fast-forward to the merge head.
+		 */
+		rollback_lock_file(&lock);
+		ret = fast_forward_to(&merge_commit->object.oid,
+				       &head_commit->object.oid, 0, opts);
+		goto leave_merge;
+	}
+
 	if (commit) {
 		const char *message = get_commit_buffer(commit, NULL);
 		const char *body;
diff --git a/t/t3430-rebase-merges.sh b/t/t3430-rebase-merges.sh
index 35260862fcb..5543f1d5a34 100755
--- a/t/t3430-rebase-merges.sh
+++ b/t/t3430-rebase-merges.sh
@@ -275,4 +275,17 @@ test_expect_success 'root commits' '
 	test_cmp_rev HEAD $before
 '
 
+test_expect_success 'a "merge" into a root commit is a fast-forward' '
+	head=$(git rev-parse HEAD) &&
+	cat >script-from-scratch <<-EOF &&
+	reset [new root]
+	merge $head
+	EOF
+	test_config sequence.editor \""$PWD"/replace-editor.sh\" &&
+	test_tick &&
+	git rebase -i -r HEAD^ &&
+	test_cmp_rev HEAD $head
+'
+
+
 test_done
-- 
2.17.0.windows.1.33.gfcbb1fa0445
Previous: Johannes SchindelinNext: Johannes Schindelin
Message 12 of 22 in “Let the sequencer handle `git rebase -i --root`”
  1. 0/6 Let the sequencer handle `git rebase -i --root`Johannes Schindelin, Apr 27, 2018
  2. 1/6 sequencer: extract helper to update active_cache_treeJohannes Schindelin, Apr 27, 2018
  3. Stefan BellerApr 28, 2018
  4. 2/6 sequencer: learn about the special "fake root commit" handlingJohannes Schindelin, Apr 27, 2018
  5. Stefan BellerApr 28, 2018
  6. Johannes SchindelinApr 29, 2018
  7. Stefan BellerApr 29, 2018
  8. 3/6 rebase -i --root: let the sequencer handle even the initial partJohannes Schindelin, Apr 27, 2018
  9. Stefan BellerApr 28, 2018
  10. Johannes SchindelinApr 29, 2018
  11. 4/6 sequencer: allow introducing new root commitsJohannes Schindelin, Apr 27, 2018
  12. 5/6 rebase --rebase-merges: a "merge" into a new root is a fast-forwardJohannes Schindelin, Apr 27, 2018
  13. 6/6 rebase --rebase-merges: root commits can be cousins, tooJohannes Schindelin, Apr 27, 2018
  14. 0/6 Let the sequencer handle `git rebase -i --root`Johannes Schindelin, May 3, 2018
  15. 1/6 sequencer: extract helper to update active_cache_treeJohannes Schindelin, May 3, 2018
  16. 3/6 rebase -i --root: let the sequencer handle even the initial partJohannes Schindelin, May 3, 2018
  17. 2/6 sequencer: learn about the special "fake root commit" handlingJohannes Schindelin, May 3, 2018
  18. 5/6 rebase --rebase-merges: a "merge" into a new root is a fast-forwardJohannes Schindelin, May 3, 2018
  19. 6/6 rebase --rebase-merges: root commits can be cousins, tooJohannes Schindelin, May 3, 2018
  20. 4/6 sequencer: allow introducing new root commitsJohannes Schindelin, May 3, 2018
  21. Stefan BellerMay 4, 2018
  22. Johannes SchindelinMay 5, 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.