public inbox for git@vger.kernel.org 
 help / color / mirror / Atom feed
From: "Dmitry V. Levin" <ldv@altlinux•org>
To: git@vger•kernel.org
Subject: [PATCH 2/2 v2] checkout: add a test for creating a new branch with regexp as a starting point
Date: Sat, 31 Jul 2010 05:44:49 +0400	[thread overview]
Message-ID: <20100731014449.GA19956@wo.int.altlinux.org> (raw)
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

  reply	other threads:[~2010-07-31  1:44 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-07-29 22:01 [PATCH] checkout: add a test for creating a new branch with regexp as a starting point Dmitry V. Levin
2010-07-29 23:07 ` Ævar Arnfjörð Bjarmason
2010-07-29 23:36   ` Thomas Rast
2010-08-02 21:04     ` Junio C Hamano
2010-07-30  8:44   ` Dmitry V. Levin
2010-07-30 11:54     ` Ævar Arnfjörð Bjarmason
2010-07-30 19:13       ` When to use test_commit (Re: [PATCH] checkout: add a test for creating a new branch with regexp as a starting point) Jonathan Nieder
2010-07-30 20:20         ` Ævar Arnfjörð Bjarmason
2010-07-31  0:18           ` [PATCH 1/2] test-lib.sh: introduce 4th argument to test_commit() specifying a tag name Dmitry V. Levin
2010-07-31  0:39             ` Ævar Arnfjörð Bjarmason
2010-07-31  1:56               ` [PATCH 1/2 v2] " Dmitry V. Levin
2010-07-31 10:23                 ` Ævar Arnfjörð Bjarmason
2010-07-31  0:19           ` [PATCH 2/2] checkout: add a test for creating a new branch with regexp as a starting point Dmitry V. Levin
2010-07-31  0:44             ` Ævar Arnfjörð Bjarmason
2010-07-31  1:44               ` Dmitry V. Levin [this message]
2010-07-31 10:24                 ` [PATCH 2/2 v2] " Ævar Arnfjörð Bjarmason
2010-08-05 21:24                   ` [PATCH 2/2 v3] " Dmitry V. Levin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20100731014449.GA19956@wo.int.altlinux.org \
    --to=ldv@altlinux$(echo .)org \
    --cc=git@vger$(echo .)kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox