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

[PATCH] rebase -m: skip cherry-picked commits more reliably

From
KFKnut Franke <knut.franke@gmx.de>
Date
Nov 22, 2010, 23:09 UTC
Message-ID
<1290467372-6487-1-git-send-email-Knut.Franke@gmx.de>

Unlike ordinary and interactive rebase, rebase -m halts with a conflict if two conflicting patches have been applied to both source and target branch (e.g. by cherry-picking). Fix this by using git rev-list --cherry-pick to generate the list of patches to apply.

Also adapt t3406 a) to catch this case and b) not to expect "Already applied" messages which can't be emitted easily if duplicates are removed already when storing the patches.

Signed-off-by: Knut Franke <Knut.Franke@gmx.de>
---
 git-rebase.sh             |   29 +++++++++++++++++++----------
 t/t3406-rebase-message.sh |   14 +++++++-------
 2 files changed, 26 insertions(+), 17 deletions(-)
diff --git a/git-rebase.sh b/git-rebase.sh
index 10a238a..aa42744 100755
--- a/git-rebase.sh
+++ b/git-rebase.sh
@@ -552,15 +552,14 @@ then
 	exit 0
 fi
 
-if test -n "$rebase_root"
-then
-	revisions="$onto..$orig_head"
-else
-	revisions="$upstream..$orig_head"
-fi
-
 if test -z "$do_merge"
 then
+	if test -n "$rebase_root"
+	then
+		revisions="$onto..$orig_head"
+	else
+		revisions="$upstream..$orig_head"
+	fi
 	git format-patch -k --stdout --full-index --ignore-if-in-upstream \
 		--src-prefix=a/ --dst-prefix=b/ \
 		--no-renames $root_flag "$revisions" |
@@ -587,11 +586,21 @@ echo "$orig_head" > "$dotest/orig-head"
 echo "$head_name" > "$dotest/head-name"
 echo "$GIT_QUIET" > "$dotest/quiet"
 
+if test -n "$rebase_root"
+then
+	revisions="$onto...$orig_head"
+else
+	revisions="$upstream...$orig_head"
+fi
+
 msgnum=0
-for cmt in `git rev-list --reverse --no-merges "$revisions"`
+for cmt in `git rev-list --reverse --no-merges --cherry-pick "$revisions"`
 do
-	msgnum=$(($msgnum + 1))
-	echo "$cmt" > "$dotest/cmt.$msgnum"
+	if test $(git merge-base "$cmt" "$orig_head") = "$cmt"
+	then
+		msgnum=$(($msgnum + 1))
+		echo "$cmt" > "$dotest/cmt.$msgnum"
+	fi
 done
 
 echo 1 >"$dotest/msgnum"
diff --git a/t/t3406-rebase-message.sh b/t/t3406-rebase-message.sh
index 85fc7c4..41cb039 100755
--- a/t/t3406-rebase-message.sh
+++ b/t/t3406-rebase-message.sh
@@ -5,8 +5,10 @@ test_description='messages from rebase operation'
 . ./test-lib.sh
 
 quick_one () {
-	echo "$1" >"file$1" &&
-	git add "file$1" &&
+	fileno=$2
+	test -z "$fileno" && fileno=$1
+	echo "$1" >"file$fileno" &&
+	git add "file$fileno" &&
 	test_tick &&
 	git commit -m "$1"
 }
@@ -16,21 +18,19 @@ test_expect_success setup '
 	git branch topic &&
 	quick_one X &&
 	quick_one A &&
-	quick_one B &&
+	quick_one B A &&
 	quick_one Y &&
 
 	git checkout topic &&
 	quick_one A &&
-	quick_one B &&
+	quick_one B A &&
 	quick_one Z &&
 	git tag start
 
 '
 
 cat >expect <<\EOF
-Already applied: 0001 A
-Already applied: 0002 B
-Committed: 0003 Z
+Committed: 0001 Z
 EOF
 
 test_expect_success 'rebase -m' '
-- 
1.7.3.2
Next: Martin von Zweigbergk
Message 1 of 3 in “rebase -m: skip cherry-picked commits more reliably”
  1. rebase -m: skip cherry-picked commits more reliablyKnut Franke, Nov 22, 2010
  2. Martin von ZweigbergkNov 23, 2010
  3. Martin von ZweigbergkNov 24, 2010

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.