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

[PATCH 2/2 v2] checkout: add a test for creating a new branch with regexp as a starting point

From
Dmitry V. Levin <ldv@altlinux.org>
Date
Jul 31, 2010, 01:44 UTC
Message-ID
<20100731014449.GA19956@wo.int.altlinux.org>
In-Reply-To
<AANLkTin11hHryAbJiOkiBH5TfpPbKREJK-ekWkd4fDhw@mail.gmail.com>
Reported-by: Ivan Zakharyaschev <imz@altlinux.org>
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
---
 t/t2018-checkout-branch.sh |   25 +++++++++++++++++++++----
 1 files changed, 21 insertions(+), 4 deletions(-)
diff --git a/t/t2018-checkout-branch.sh b/t/t2018-checkout-branch.sh
index 1caffea..6ada870 100755
--- a/t/t2018-checkout-branch.sh
+++ b/t/t2018-checkout-branch.sh
@@ -4,12 +4,13 @@ test_description='checkout '
 
 . ./test-lib.sh
 
-# Arguments: <branch> <sha> [<checkout options>]
+# Arguments: <branch> <start_point> [<checkout options>]
 #
 # Runs "git checkout" to switch to <branch>, testing that
 #
 #   1) we are on the specified branch, <branch>;
-#   2) HEAD is <sha>; if <sha> is not specified, the old HEAD is used.
+#   2) HEAD points to the same commit as <start_point> does;
+#      if <start_point> is not specified, the old HEAD is used.
 #
 # If <checkout options> is not specified, "git checkout" is run with -b.
 do_checkout() {
@@ -17,7 +18,8 @@ do_checkout() {
 	exp_ref="refs/heads/$exp_branch" &&
 
 	# if <sha> is not specified, use HEAD.
-	exp_sha=${2:-$(git rev-parse --verify HEAD)} &&
+	start_point=${2:-HEAD}
+	exp_sha=$(git rev-parse --verify $start_point) &&
 
 	# default options for git checkout: -b
 	if [ -z "$3" ]; then
@@ -26,7 +28,7 @@ do_checkout() {
 		opts="$3"
 	fi
 
-	git checkout $opts $exp_branch $exp_sha &&
+	git checkout $opts $exp_branch $start_point &&
 
 	test $exp_ref = $(git rev-parse --symbolic-full-name HEAD) &&
 	test $exp_sha = $(git rev-parse --verify HEAD)
@@ -118,7 +120,22 @@ test_expect_success 'checkout -b to an existing branch fails' '
 	test_must_fail do_checkout branch2 $HEAD2
 '
 
+test_expect_failure 'checkout -b new_branch :/regexp' '
+	# clean up from previous test
+	git reset --hard &&
+
+	do_checkout old_regexp_branch branch1 &&
+	# The first commit in this test should not be referenced by
+	# other branches or tags.
+	test_commit first a a "" &&
+	test_commit second &&
+
+	do_checkout new_regexp_branch :/first
+'
+
 test_expect_success 'checkout -B to an existing branch resets branch to HEAD' '
+	# clean up from previous test
+	git reset --hard &&
 	git checkout branch1 &&
 
 	do_checkout branch2 "" -B
-- 
1.7.2.1
Previous: Ævar Arnfjörð BjarmasonNext: Ævar Arnfjörð Bjarmason
Message 14 of 17 in “checkout: add a test for creating a new branch with regexp as a starting point”
  1. checkout: add a test for creating a new branch with regexp as a starting pointDmitry V. Levin, Jul 29, 2010
  2. Ævar Arnfjörð BjarmasonJul 29, 2010
  3. Thomas RastJul 29, 2010
  4. Dmitry V. LevinJul 30, 2010
  5. Ævar Arnfjörð BjarmasonJul 30, 2010
  6. When to use test_commit (Re: [PATCH] checkout: add a test for creating a new branch with regexp as a starting point)Jonathan Nieder, Jul 30, 2010
  7. Ævar Arnfjörð BjarmasonJul 30, 2010
  8. 1/2 test-lib.sh: introduce 4th argument to test_commit() specifying a tag nameDmitry V. Levin, Jul 31, 2010
  9. Ævar Arnfjörð BjarmasonJul 31, 2010
  10. 1/2 test-lib.sh: introduce 4th argument to test_commit() specifying a tag nameDmitry V. Levin, Jul 31, 2010
  11. Ævar Arnfjörð BjarmasonJul 31, 2010
  12. 2/2 checkout: add a test for creating a new branch with regexp as a starting pointDmitry V. Levin, Jul 31, 2010
  13. Ævar Arnfjörð BjarmasonJul 31, 2010
  14. 2/2 checkout: add a test for creating a new branch with regexp as a starting pointDmitry V. Levin, Jul 31, 2010
  15. Ævar Arnfjörð BjarmasonJul 31, 2010
  16. Dmitry V. LevinAug 5, 2010
  17. Junio C HamanoAug 2, 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.