@@ -21,14 +21,20 @@ test_expect_success 'first branch switch' '
2121 git checkout other
2222'
2323
24+ test_cmp_symbolic_HEAD_ref () {
25+ echo refs/heads/" $1 " > expect &&
26+ git symbolic-ref HEAD > actual &&
27+ test_cmp expect actual
28+ }
29+
2430test_expect_success ' "checkout -" switches back' '
2531 git checkout - &&
26- test "z$(git symbolic-ref HEAD)" = "zrefs/heads/ main"
32+ test_cmp_symbolic_HEAD_ref main
2733'
2834
2935test_expect_success ' "checkout -" switches forth' '
3036 git checkout - &&
31- test "z$(git symbolic-ref HEAD)" = "zrefs/heads/ other"
37+ test_cmp_symbolic_HEAD_ref other
3238'
3339
3440test_expect_success ' detach HEAD' '
@@ -37,12 +43,16 @@ test_expect_success 'detach HEAD' '
3743
3844test_expect_success ' "checkout -" attaches again' '
3945 git checkout - &&
40- test "z$(git symbolic-ref HEAD)" = "zrefs/heads/ other"
46+ test_cmp_symbolic_HEAD_ref other
4147'
4248
4349test_expect_success ' "checkout -" detaches again' '
4450 git checkout - &&
45- test "z$(git rev-parse HEAD)" = "z$(git rev-parse other)" &&
51+
52+ git rev-parse other >expect &&
53+ git rev-parse HEAD >actual &&
54+ test_cmp expect actual &&
55+
4656 test_must_fail git symbolic-ref HEAD
4757'
4858
@@ -63,31 +73,31 @@ more_switches () {
6373test_expect_success ' switch to the last' '
6474 more_switches &&
6575 git checkout @{-1} &&
66- test "z$(git symbolic-ref HEAD)" = "zrefs/heads/ branch2"
76+ test_cmp_symbolic_HEAD_ref branch2
6777'
6878
6979test_expect_success ' switch to second from the last' '
7080 more_switches &&
7181 git checkout @{-2} &&
72- test "z$(git symbolic-ref HEAD)" = "zrefs/heads/ branch3"
82+ test_cmp_symbolic_HEAD_ref branch3
7383'
7484
7585test_expect_success ' switch to third from the last' '
7686 more_switches &&
7787 git checkout @{-3} &&
78- test "z$(git symbolic-ref HEAD)" = "zrefs/heads/ branch4"
88+ test_cmp_symbolic_HEAD_ref branch4
7989'
8090
8191test_expect_success ' switch to fourth from the last' '
8292 more_switches &&
8393 git checkout @{-4} &&
84- test "z$(git symbolic-ref HEAD)" = "zrefs/heads/ branch5"
94+ test_cmp_symbolic_HEAD_ref branch5
8595'
8696
8797test_expect_success ' switch to twelfth from the last' '
8898 more_switches &&
8999 git checkout @{-12} &&
90- test "z$(git symbolic-ref HEAD)" = "zrefs/heads/ branch13"
100+ test_cmp_symbolic_HEAD_ref branch13
91101'
92102
93103test_expect_success ' merge base test setup' '
@@ -98,27 +108,36 @@ test_expect_success 'merge base test setup' '
98108test_expect_success ' another...main' '
99109 git checkout another &&
100110 git checkout another...main &&
101- test "z$(git rev-parse --verify HEAD)" = "z$(git rev-parse --verify main^)"
111+
112+ git rev-parse --verify main^ >expect &&
113+ git rev-parse --verify HEAD >actual &&
114+ test_cmp expect actual
102115'
103116
104117test_expect_success ' ...main' '
105118 git checkout another &&
106119 git checkout ...main &&
107- test "z$(git rev-parse --verify HEAD)" = "z$(git rev-parse --verify main^)"
120+
121+ git rev-parse --verify main^ >expect &&
122+ git rev-parse --verify HEAD >actual &&
123+ test_cmp expect actual
108124'
109125
110126test_expect_success ' main...' '
111127 git checkout another &&
112128 git checkout main... &&
113- test "z$(git rev-parse --verify HEAD)" = "z$(git rev-parse --verify main^)"
129+
130+ git rev-parse --verify main^ >expect &&
131+ git rev-parse --verify HEAD >actual &&
132+ test_cmp expect actual
114133'
115134
116135test_expect_success ' "checkout -" works after a rebase A' '
117136 git checkout main &&
118137 git checkout other &&
119138 git rebase main &&
120139 git checkout - &&
121- test "z$(git symbolic-ref HEAD)" = "zrefs/heads/ main"
140+ test_cmp_symbolic_HEAD_ref main
122141'
123142
124143test_expect_success ' "checkout -" works after a rebase A B' '
@@ -127,15 +146,15 @@ test_expect_success '"checkout -" works after a rebase A B' '
127146 git checkout other &&
128147 git rebase main moodle &&
129148 git checkout - &&
130- test "z$(git symbolic-ref HEAD)" = "zrefs/heads/ main"
149+ test_cmp_symbolic_HEAD_ref main
131150'
132151
133152test_expect_success ' "checkout -" works after a rebase -i A' '
134153 git checkout main &&
135154 git checkout other &&
136155 git rebase -i main &&
137156 git checkout - &&
138- test "z$(git symbolic-ref HEAD)" = "zrefs/heads/ main"
157+ test_cmp_symbolic_HEAD_ref main
139158'
140159
141160test_expect_success ' "checkout -" works after a rebase -i A B' '
@@ -144,7 +163,7 @@ test_expect_success '"checkout -" works after a rebase -i A B' '
144163 git checkout other &&
145164 git rebase main foodle &&
146165 git checkout - &&
147- test "z$(git symbolic-ref HEAD)" = "zrefs/heads/ main"
166+ test_cmp_symbolic_HEAD_ref main
148167'
149168
150169test_done
0 commit comments