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

[PATCH] rebase: introduce "rebase.preserve" configuration option

From
Ralf Thielow <ralf.thielow@gmail.com>
Date
Aug 5, 2014, 20:48 UTC
Message-ID
<1407271714-1624-1-git-send-email-ralf.thielow@gmail.com>

There are several ways to configure Git to preserve merges. There is "pull.rebase=preserve" for all branches and "branch.<name>.rebase=preserve" for individual branches. However, there is no configuration option to preserve merges for all branches when running git-rebase.

This patch introduces a new configuration variable "rebase.preserve". If set to true, "--preserve-merges" option will be enabled in git-rebase by default.

Signed-off-by: Ralf Thielow <ralf.thielow@gmail.com>
---
 Documentation/config.txt          |  3 +++
 git-rebase.sh                     |  1 +
 t/t3409-rebase-preserve-merges.sh | 20 ++++++++++++++++++++
 3 files changed, 24 insertions(+)
diff --git a/Documentation/config.txt b/Documentation/config.txt
index c08286e..4166be0 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -2031,6 +2031,9 @@ rebase.autostash::
 	successful rebase might result in non-trivial conflicts.
 	Defaults to false.
 
+rebase.preserve::
+	If set to true enable '--preserve-merges' option by default.
+
 receive.autogc::
 	By default, git-receive-pack will run "git-gc --auto" after
 	receiving data from git-push and updating refs.  You can stop
diff --git a/git-rebase.sh b/git-rebase.sh
index 47ca3b9..e0b3e05 100755
--- a/git-rebase.sh
+++ b/git-rebase.sh
@@ -83,6 +83,7 @@ state_dir=
 # One of {'', continue, skip, abort}, as parsed from command line
 action=
 preserve_merges=
+test "$(git config --bool rebase.preserve)" = "true" && preserve_merges=t && interactive_rebase=implied
 autosquash=
 keep_empty=
 test "$(git config --bool rebase.autosquash)" = "true" && autosquash=t
diff --git a/t/t3409-rebase-preserve-merges.sh b/t/t3409-rebase-preserve-merges.sh
index 8c251c5..3a02240 100755
--- a/t/t3409-rebase-preserve-merges.sh
+++ b/t/t3409-rebase-preserve-merges.sh
@@ -76,6 +76,16 @@ test_expect_success 'setup for merge-preserving rebase' \
 		git merge --no-ff topic2
 	) &&
 
+	git clone ./. clone5 &&
+	(
+		cd clone5 &&
+		git checkout -b topic2 origin/topic &&
+		echo Sixth > A &&
+		git commit -a -m "Modify A3" &&
+		git checkout -b topic origin/topic &&
+		git merge --no-ff topic2
+	) &&
+
 	git checkout topic &&
 	echo Fourth >> B &&
 	git commit -a -m "Modify B2"
@@ -119,4 +129,14 @@ test_expect_success 'rebase -p ignores merge.log config' '
 	)
 '
 
+test_expect_success 'config rebase.preserve preserves no-ff merges' '
+	(
+	cd clone5 &&
+	git fetch &&
+	git -c rebase.preserve=true rebase origin/topic &&
+	test 3 = $(git rev-list --all --pretty=oneline | grep "Modify A" | wc -l) &&
+	test 1 = $(git rev-list --all --pretty=oneline | grep "Merge branch" | wc -l)
+	)
+'
+
 test_done
-- 
2.1.0.rc1.205.gf9880d1
Next: Junio C Hamano
Message 1 of 2 in “rebase: introduce "rebase.preserve" configuration option”
  1. rebase: introduce "rebase.preserve" configuration optionRalf Thielow, Aug 5, 2014
  2. Junio C HamanoAug 5, 2014

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.