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

Re: What's cooking in git.git (Jan 2010, #01; Mon, 04)

From
Nanako Shiraishi <nanako3@lavabit.com>
Date
Jan 6, 2010, 10:18 UTC
Message-ID
<20100106191825.6117@nanako3.lavabit.com>
In-Reply-To
<7vskal5c11.fsf@alter.siamese.dyndns.org>
Quoting Junio C Hamano <gitster@pobox.com> writes:
Show 6 quoted lines
> These need a bit more work to go forward.  Help and follow-up are
> appreciated.
>
>  * jc/checkout-merge-base (2009-11-20) 2 commits
>    Users of "rebase -i" might want to teach this to the command.
>    Volunteers?
Let me try. I'll let others to contribute documentation updates.
-- >8 --
Subject: [PATCH] Fix rebase --onto A...B and teach the same to interactive rebase
Signed-off-by: しらいし ななこ <nanako3@lavabit.com>
---
 git-rebase--interactive.sh       |   21 +++++++++++-
 git-rebase.sh                    |    4 +-
 t/t3415-rebase-onto-threedots.sh |   68 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 90 insertions(+), 3 deletions(-)
 create mode 100755 t/t3415-rebase-onto-threedots.sh
diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index 23ded48..d42cc4f 100755
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -482,6 +482,25 @@ get_saved_options () {
 	test -f "$DOTEST"/rebase-root && REBASE_ROOT=t
 }
 
+LF='
+'
+parse_onto () {
+	if	expr "$1" : '.*\.\.\.' >/dev/null &&
+		left=${1%...*} right=${1#*...} &&
+		: ${left:=HEAD} ${right:=HEAD} &&
+		onto=$(git merge-base "$left" "$right")
+	then
+		case "$onto" in
+		?*"$LF"?* | '')
+			exit 1 ;;
+		esac
+		echo "$onto"
+		exit 0
+	else
+		git rev-parse --verify "$1^0"
+	fi
+}
+
 while test $# != 0
 do
 	case "$1" in
@@ -589,7 +608,7 @@ first and then run 'git rebase --continue' again."
 		;;
 	--onto)
 		shift
-		ONTO=$(git rev-parse --verify "$1") ||
+		ONTO=$(parse_onto "$1") ||
 			die "Does not point to a valid commit: $1"
 		;;
 	--)
diff --git a/git-rebase.sh b/git-rebase.sh
index 6503113..43c62c0 100755
--- a/git-rebase.sh
+++ b/git-rebase.sh
@@ -419,8 +419,8 @@ fi
 
 # Make sure the branch to rebase onto is valid.
 onto_name=${newbase-"$upstream_name"}
-if	left=$(expr "$onto_name" : '\(.*\)\.\.\.') &&
-	right=$(expr "$onto_name" : '\.\.\.\(.*\)$') &&
+if	expr "$onto_name" : '.*\.\.\.' >/dev/null &&
+	left=${onto_name%...*} right=${onto_name#*...} &&
 	: ${left:=HEAD} ${right:=HEAD} &&
 	onto=$(git merge-base "$left" "$right")
 then
diff --git a/t/t3415-rebase-onto-threedots.sh b/t/t3415-rebase-onto-threedots.sh
new file mode 100755
index 0000000..c243243
--- /dev/null
+++ b/t/t3415-rebase-onto-threedots.sh
@@ -0,0 +1,68 @@
+#!/bin/sh
+
+test_description='git rebase --onto A...B'
+
+. ./test-lib.sh
+. "$TEST_DIRECTORY/lib-rebase.sh"
+
+#           F---G                     G'
+#          /          -->            /
+# A---B---C---D---E         A---B---C---D---E
+
+test_expect_success setup '
+	test_commit A &&
+	test_commit B &&
+	test_commit C &&
+	git branch topic &&
+	test_commit D &&
+	test_commit E &&
+	git checkout topic &&
+	test_commit F &&
+	test_commit G
+'
+
+test_expect_success 'rebase --onto A...B' '
+	git reset --hard &&
+	git checkout topic &&
+	git reset --hard G &&
+
+	git rebase --onto master...topic HEAD^ &&
+	git rev-parse HEAD^ >actual &&
+	git rev-parse C^0 >expect &&
+	test_cmp expect actual
+'
+
+test_expect_success 'rebase --onto A...' '
+	git reset --hard &&
+	git checkout topic &&
+	git reset --hard G &&
+
+	git rebase --onto master... HEAD^ &&
+	git rev-parse HEAD^ >actual &&
+	git rev-parse C^0 >expect &&
+	test_cmp expect actual
+'
+
+test_expect_success 'rebase -i --onto A...B' '
+	git reset --hard &&
+	git checkout topic &&
+	git reset --hard G &&
+	set_fake_editor &&
+	EXPECT_COUNT=1 git rebase -i --onto master...topic HEAD^ &&
+	git rev-parse HEAD^ >actual &&
+	git rev-parse C^0 >expect &&
+	test_cmp expect actual
+'
+
+test_expect_success 'rebase -i --onto A...' '
+	git reset --hard &&
+	git checkout topic &&
+	git reset --hard G &&
+	set_fake_editor &&
+	EXPECT_COUNT=1 git rebase -i --onto master... HEAD^ &&
+	git rev-parse HEAD^ >actual &&
+	git rev-parse C^0 >expect &&
+	test_cmp expect actual
+'
+
+test_done
-- 
1.6.6

-- 
Nanako Shiraishi
http://ivory.ap.teacup.com/nanako3/
Previous: Junio C HamanoNext: Johannes Schindelin
Message 19 of 32 in “What's cooking in git.git (Jan 2010, #01; Mon, 04)”
  1. Junio C HamanoJan 4, 2010
  2. Matthieu MoyJan 4, 2010
  3. Junio C HamanoJan 4, 2010
  4. Johannes SixtJan 4, 2010
  5. Junio C HamanoJan 5, 2010
  6. Jeff KingJan 5, 2010
  7. Junio C HamanoJan 5, 2010
  8. Johannes SixtJan 5, 2010
  9. Junio C HamanoJan 6, 2010
  10. Johannes SixtJan 6, 2010
  11. Junio C HamanoJan 6, 2010
  12. Junio C HamanoJan 5, 2010
  13. Jeff KingJan 5, 2010
  14. Tay Ray ChuanJan 5, 2010
  15. Teach --[no-]rerere-autoupdate option to merge, revert and friendsJunio C Hamano, Jan 5, 2010
  16. Johan HerlandJan 5, 2010
  17. Ilari LiusvaaraJan 5, 2010
  18. Junio C HamanoJan 6, 2010
  19. Nanako ShiraishiJan 6, 2010
  20. Johannes SchindelinJan 6, 2010
  21. Junio C HamanoJan 6, 2010
  22. 1/2 rebase: fix --onto A...B parsing and add testsNanako Shiraishi, Jan 7, 2010
  23. 2/2 rebase -i: teach --onto A...B syntaxNanako Shiraishi, Jan 7, 2010
  24. Junio C HamanoJan 7, 2010
  25. Johannes SixtJan 7, 2010
  26. Avery PennarunJan 8, 2010
  27. Sverre RabbelierJan 8, 2010
  28. Avery PennarunJan 8, 2010
  29. Sverre RabbelierJan 8, 2010
  30. A Large Angry SCMJan 8, 2010
  31. Johannes SchindelinJan 9, 2010
  32. Avery PennarunJan 9, 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.