about summary refs log tree commit diff
path: root/third_party/git/t/t2018-checkout-branch.sh
diff options
context:
space:
mode:
authorVincent Ambo <tazjin@google.com>2020-05-25T23·06+0100
committerVincent Ambo <tazjin@google.com>2020-05-25T23·06+0100
commit93ba78d6f4632ef1c5228965e3edc8c0faf88c1e (patch)
tree85730c182a9f5f492ade8e8ccdb1c2356f9900bd /third_party/git/t/t2018-checkout-branch.sh
parent6f8fbf4aa4b1654ab27d4829e114538761817de0 (diff)
revert(3p/git): Revert merge of git upstream at v2.26.2 r/852
This causes cgit to serve error pages, which is undesirable.

This reverts commit 5229c9b232de5bfa959ad6ebbb4c8192ac513352, reversing
changes made to f2b211131f2347342dde63975b09cf603149f1a3.
Diffstat (limited to 'third_party/git/t/t2018-checkout-branch.sh')
-rwxr-xr-xthird_party/git/t/t2018-checkout-branch.sh75
1 files changed, 24 insertions, 51 deletions
diff --git a/third_party/git/t/t2018-checkout-branch.sh b/third_party/git/t/t2018-checkout-branch.sh
index bbca7ef8da6d..822381dd9df6 100755
--- a/third_party/git/t/t2018-checkout-branch.sh
+++ b/third_party/git/t/t2018-checkout-branch.sh
@@ -1,76 +1,50 @@
 #!/bin/sh
 
-test_description='checkout'
+test_description='checkout '
 
 . ./test-lib.sh
 
-# Arguments: [!] <branch> <oid> [<checkout options>]
+# Arguments: <branch> <sha> [<checkout options>]
 #
 # Runs "git checkout" to switch to <branch>, testing that
 #
 #   1) we are on the specified branch, <branch>;
-#   2) HEAD is <oid>; if <oid> is not specified, the old HEAD is used.
+#   2) HEAD is <sha>; if <sha> is not specified, the old HEAD is used.
 #
 # If <checkout options> is not specified, "git checkout" is run with -b.
-#
-# If the first argument is `!`, "git checkout" is expected to fail when
-# it is run.
-do_checkout () {
-	should_fail= &&
-	if test "x$1" = "x!"
-	then
-		should_fail=yes &&
-		shift
-	fi &&
+do_checkout() {
 	exp_branch=$1 &&
 	exp_ref="refs/heads/$exp_branch" &&
 
-	# if <oid> is not specified, use HEAD.
-	exp_oid=${2:-$(git rev-parse --verify HEAD)} &&
+	# if <sha> is not specified, use HEAD.
+	exp_sha=${2:-$(git rev-parse --verify HEAD)} &&
 
 	# default options for git checkout: -b
-	if test -z "$3"
-	then
+	if [ -z "$3" ]; then
 		opts="-b"
 	else
 		opts="$3"
 	fi
 
-	if test -n "$should_fail"
-	then
-		test_must_fail git checkout $opts $exp_branch $exp_oid
-	else
-		git checkout $opts $exp_branch $exp_oid &&
-		echo "$exp_ref" >ref.expect &&
-		git rev-parse --symbolic-full-name HEAD >ref.actual &&
-		test_cmp ref.expect ref.actual &&
-		echo "$exp_oid" >oid.expect &&
-		git rev-parse --verify HEAD >oid.actual &&
-		test_cmp oid.expect oid.actual
-	fi
-}
+	git checkout $opts $exp_branch $exp_sha &&
 
-test_dirty_unmergeable () {
-	test_expect_code 1 git diff --exit-code
+	test $exp_ref = $(git rev-parse --symbolic-full-name HEAD) &&
+	test $exp_sha = $(git rev-parse --verify HEAD)
 }
 
-test_dirty_unmergeable_discards_changes () {
-	git diff --exit-code
+test_dirty_unmergeable() {
+	! git diff --exit-code >/dev/null
 }
 
-setup_dirty_unmergeable () {
+setup_dirty_unmergeable() {
 	echo >>file1 change2
 }
 
-test_dirty_mergeable () {
-	test_expect_code 1 git diff --cached --exit-code
-}
-
-test_dirty_mergeable_discards_changes () {
-	git diff --cached --exit-code
+test_dirty_mergeable() {
+	! git diff --cached --exit-code >/dev/null
 }
 
-setup_dirty_mergeable () {
+setup_dirty_mergeable() {
 	echo >file2 file2 &&
 	git add file2
 }
@@ -108,7 +82,7 @@ test_expect_success 'checkout -b to a new branch, set to an explicit ref' '
 
 test_expect_success 'checkout -b to a new branch with unmergeable changes fails' '
 	setup_dirty_unmergeable &&
-	do_checkout ! branch2 $HEAD1 &&
+	test_must_fail do_checkout branch2 $HEAD1 &&
 	test_dirty_unmergeable
 '
 
@@ -119,7 +93,7 @@ test_expect_success 'checkout -f -b to a new branch with unmergeable changes dis
 
 	# still dirty and on branch1
 	do_checkout branch2 $HEAD1 "-f -b" &&
-	test_dirty_unmergeable_discards_changes
+	test_must_fail test_dirty_unmergeable
 '
 
 test_expect_success 'checkout -b to a new branch preserves mergeable changes' '
@@ -137,12 +111,12 @@ test_expect_success 'checkout -f -b to a new branch with mergeable changes disca
 	test_when_finished git reset --hard HEAD &&
 	setup_dirty_mergeable &&
 	do_checkout branch2 $HEAD1 "-f -b" &&
-	test_dirty_mergeable_discards_changes
+	test_must_fail test_dirty_mergeable
 '
 
 test_expect_success 'checkout -b to an existing branch fails' '
 	test_when_finished git reset --hard HEAD &&
-	do_checkout ! branch2 $HEAD2
+	test_must_fail do_checkout branch2 $HEAD2
 '
 
 test_expect_success 'checkout -b to @{-1} fails with the right branch name' '
@@ -166,8 +140,7 @@ test_expect_success 'checkout -B to a merge base' '
 '
 
 test_expect_success 'checkout -B to an existing branch from detached HEAD resets branch to HEAD' '
-	head=$(git rev-parse --verify HEAD) &&
-	git checkout "$head" &&
+	git checkout $(git rev-parse --verify HEAD) &&
 
 	do_checkout branch2 "" -B
 '
@@ -182,14 +155,14 @@ test_expect_success 'checkout -B to an existing branch with unmergeable changes
 	git checkout branch1 &&
 
 	setup_dirty_unmergeable &&
-	do_checkout ! branch2 $HEAD1 -B &&
+	test_must_fail do_checkout branch2 $HEAD1 -B &&
 	test_dirty_unmergeable
 '
 
 test_expect_success 'checkout -f -B to an existing branch with unmergeable changes discards changes' '
 	# still dirty and on branch1
 	do_checkout branch2 $HEAD1 "-f -B" &&
-	test_dirty_unmergeable_discards_changes
+	test_must_fail test_dirty_unmergeable
 '
 
 test_expect_success 'checkout -B to an existing branch preserves mergeable changes' '
@@ -206,7 +179,7 @@ test_expect_success 'checkout -f -B to an existing branch with mergeable changes
 
 	setup_dirty_mergeable &&
 	do_checkout branch2 $HEAD1 "-f -B" &&
-	test_dirty_mergeable_discards_changes
+	test_must_fail test_dirty_mergeable
 '
 
 test_expect_success 'checkout -b <describe>' '