[PATCH 2/2 v2] checkout: add a test for creating a new branch with regexp as a starting point
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