checkout tests: don't ignore "git <cmd>" exit code
Change a fragile pattern introduced in 696acf45f96 (checkout: implement "-" abbreviation, add docs and tests, 2009-01-17) to check the exit code of both "git symbolic-ref" and "git rev-parse". Without this change this test will become flaky e.g. under SANITIZE=leak if some (but not all) memory leaks revealed by these commands are fixed. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Ævar Arnfjörð Bjarmason committed
Mar 7, 2022 at 13:49 UTC
c419562860e3baf1cd3ae1ed9cb7cce6ab06cbd5
1 file changed
+35
-16
t/t2012-checkout-last.sh
+35
-16
@@ -21,14 +21,20 @@ test_expect_success 'first branch switch' '
21
git checkout other
22
'
23
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
+
30
test_expect_success '"checkout -" switches back' '
31
git checkout - &&
26
- test "z$(git symbolic-ref HEAD)" = "zrefs/heads/main"
32
+ test_cmp_symbolic_HEAD_ref main
33
'
34
35
test_expect_success '"checkout -" switches forth' '
36
git checkout - &&
31
- test "z$(git symbolic-ref HEAD)" = "zrefs/heads/other"
37
+ test_cmp_symbolic_HEAD_ref other
38
'
39
40
test_expect_success 'detach HEAD' '
@@ -37,12 +43,16 @@ test_expect_success 'detach HEAD' '
43
44
test_expect_success '"checkout -" attaches again' '
45
git checkout - &&
40
- test "z$(git symbolic-ref HEAD)" = "zrefs/heads/other"
46
+ test_cmp_symbolic_HEAD_ref other
47
'
48
49
test_expect_success '"checkout -" detaches again' '
50
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
+
56
test_must_fail git symbolic-ref HEAD
57
'
58
@@ -63,31 +73,31 @@ more_switches () {
73
test_expect_success 'switch to the last' '
74
more_switches &&
75
git checkout @{-1} &&
66
- test "z$(git symbolic-ref HEAD)" = "zrefs/heads/branch2"
76
+ test_cmp_symbolic_HEAD_ref branch2
77
'
78
79
test_expect_success 'switch to second from the last' '
80
more_switches &&
81
git checkout @{-2} &&
72
- test "z$(git symbolic-ref HEAD)" = "zrefs/heads/branch3"
82
+ test_cmp_symbolic_HEAD_ref branch3
83
'
84
85
test_expect_success 'switch to third from the last' '
86
more_switches &&
87
git checkout @{-3} &&
78
- test "z$(git symbolic-ref HEAD)" = "zrefs/heads/branch4"
88
+ test_cmp_symbolic_HEAD_ref branch4
89
'
90
91
test_expect_success 'switch to fourth from the last' '
92
more_switches &&
93
git checkout @{-4} &&
84
- test "z$(git symbolic-ref HEAD)" = "zrefs/heads/branch5"
94
+ test_cmp_symbolic_HEAD_ref branch5
95
'
96
97
test_expect_success 'switch to twelfth from the last' '
98
more_switches &&
99
git checkout @{-12} &&
90
- test "z$(git symbolic-ref HEAD)" = "zrefs/heads/branch13"
100
+ test_cmp_symbolic_HEAD_ref branch13
101
'
102
103
test_expect_success 'merge base test setup' '
@@ -98,19 +108,28 @@ test_expect_success 'merge base test setup' '
108
test_expect_success 'another...main' '
109
git checkout another &&
110
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
115
'
116
117
test_expect_success '...main' '
118
git checkout another &&
119
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
124
'
125
126
test_expect_success 'main...' '
127
git checkout another &&
128
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
133
'
134
135
test_expect_success '"checkout -" works after a rebase A' '
@@ -118,7 +137,7 @@ test_expect_success '"checkout -" works after a rebase A' '
137
git checkout other &&
138
git rebase main &&
139
git checkout - &&
121
- test "z$(git symbolic-ref HEAD)" = "zrefs/heads/main"
140
+ test_cmp_symbolic_HEAD_ref main
141
'
142
143
test_expect_success '"checkout -" works after a rebase A B' '
@@ -127,7 +146,7 @@ test_expect_success '"checkout -" works after a rebase A B' '
146
git checkout other &&
147
git rebase main moodle &&
148
git checkout - &&
130
- test "z$(git symbolic-ref HEAD)" = "zrefs/heads/main"
149
+ test_cmp_symbolic_HEAD_ref main
150
'
151
152
test_expect_success '"checkout -" works after a rebase -i A' '
@@ -135,7 +154,7 @@ test_expect_success '"checkout -" works after a rebase -i A' '
154
git checkout other &&
155
git rebase -i main &&
156
git checkout - &&
138
- test "z$(git symbolic-ref HEAD)" = "zrefs/heads/main"
157
+ test_cmp_symbolic_HEAD_ref main
158
'
159
160
test_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' '
163
git checkout other &&
164
git rebase main foodle &&
165
git checkout - &&
147
- test "z$(git symbolic-ref HEAD)" = "zrefs/heads/main"
166
+ test_cmp_symbolic_HEAD_ref main
167
'
168
169
test_done