threads / patch / 15640

patch, 3 partsgit rebase: Support non-interactive merge-preserving rebase

Subject: [PATCH 2/3] git rebase: Support non-interactive merge-preserving rebase

## tl;dr

One message between Sep 23, 2008 and Sep 23, 2008. Diffs are folded; open one to read it.

replies: 0people: 1as markdown or json

Andreas Ericsson· Sep 23, 2008, 20:58 UTC · lore

Previously, 'git rebase --preserve-merges' would only work in interactive mode. For some workflows, this was quite a limitation.

This patch adds a workaround, invoking the git-rebase--interactive helper with GIT_EDITOR set to : in case the user passes "-p" but not "-i" to the rebase command.

The effect is that the interactive rebase helper is used, but the user won't see an editor.

Since this patch fixes the latter of the two expected testfailures in t3409-rebase-preserve-merges, that test is now set to expect success.

Signed-off-by: Andreas Ericsson <ae@op5.se>
---
 Documentation/git-rebase.txt      |    3 +--
 git-rebase.sh                     |   22 +++++++++++++++++++---
 t/t3409-rebase-preserve-merges.sh |    2 +-
 3 files changed, 21 insertions(+), 6 deletions(-)
Show changes to 3 files +21 −6

Documentation/git-rebase.txt, git-rebase.sh, t/t3409-rebase-preserve-merges.sh

diff --git a/Documentation/git-rebase.txt b/Documentation/git-rebase.txt
index 59c1b02..ddec6a6 100644
--- a/Documentation/git-rebase.txt
+++ b/Documentation/git-rebase.txt
@@ -250,8 +250,7 @@ OPTIONS
 
 -p::
 --preserve-merges::
-	Instead of ignoring merges, try to recreate them.  This option
-	only works in interactive mode.
+	Instead of ignoring merges, try to recreate them.
 
 include::merge-strategies.txt[]
 
diff --git a/git-rebase.sh b/git-rebase.sh
index 528b604..03e5f95 100755
--- a/git-rebase.sh
+++ b/git-rebase.sh
@@ -138,10 +138,26 @@ finish_rb_merge () {
 }
 
 is_interactive () {
-	test -f "$dotest"/interactive ||
-	while :; do case $#,"$1" in 0,|*,-i|*,--interactive) break ;; esac
+	while test $# != 0
+	do
+		case "$1" in
+			-i|--interactive)
+				interactive_rebase=explicit
+				break
+			;;
+			-p|--preserve-merges)
+				interactive_rebase=implied
+			;;
+		esac
 		shift
-	done && test -n "$1"
+	done
+
+	if [ "$interactive_rebase" = implied ]; then
+		GIT_EDITOR=:
+		export GIT_EDITOR
+	fi
+
+	test -n "$interactive_rebase" || test -f "$dotest"/interactive
 }
 
 test -f "$GIT_DIR"/rebase-apply/applying &&
diff --git a/t/t3409-rebase-preserve-merges.sh b/t/t3409-rebase-preserve-merges.sh
index 532b220..21b8c79 100644
--- a/t/t3409-rebase-preserve-merges.sh
+++ b/t/t3409-rebase-preserve-merges.sh
@@ -57,7 +57,7 @@ test_expect_failure 'git pull --rebase -p on moved topic' '
 	test $(git rev-list --all --pretty=oneline | grep "Modify A" | wc -l) = 1
 '
 
-test_expect_failure 'rebase -p merge on moved topic' '
+test_expect_success 'rebase -p merge on moved topic' '
 	cd ../clone2 &&
 	git fetch &&
 	git rebase -p origin/topic &&
-- 
1.6.0.2.307.gc4275.dirty

← back to recent threads