t2018: don't lose return code of git commands
authorDenton Liu <redacted>
Tue, 7 Jan 2020 04:53:03 +0000 (23:53 -0500)
committerJunio C Hamano <redacted>
Mon, 27 Jan 2020 20:56:02 +0000 (12:56 -0800)
Fix invocations of git commands so their exit codes are not lost
within non-assignment command substitutions.

Signed-off-by: Denton Liu <redacted>
Signed-off-by: Junio C Hamano <redacted>
t/t2018-checkout-branch.sh

index 687ab6713cf46c5e0e7fbd5306c3cf5c5f24b4d3..caf43571b1489565d51282db0daf2231aa04ab85 100755 (executable)
@@ -41,8 +41,12 @@ do_checkout () {
                test_must_fail git checkout $opts $exp_branch $exp_sha
        else
                git checkout $opts $exp_branch $exp_sha &&
-               test $exp_ref = $(git rev-parse --symbolic-full-name HEAD) &&
-               test $exp_sha = $(git rev-parse --verify HEAD)
+               echo "$exp_ref" >ref.expect &&
+               git rev-parse --symbolic-full-name HEAD >ref.actual &&
+               test_cmp ref.expect ref.actual &&
+               echo "$exp_sha" >sha.expect &&
+               git rev-parse --verify HEAD >sha.actual &&
+               test_cmp sha.expect sha.actual
        fi
 }
 
@@ -162,7 +166,8 @@ 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' '
-       git checkout $(git rev-parse --verify HEAD) &&
+       head=$(git rev-parse --verify HEAD) &&
+       git checkout "$head" &&
 
        do_checkout branch2 "" -B
 '
git clone https://git.99rst.org/PROJECT