@@ -21,14 +21,20 @@ test_expect_success 'first branch switch' '
21
21
git checkout other
22
22
'
23
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
+
24
30
test_expect_success ' "checkout -" switches back' '
25
31
git checkout - &&
26
- test "z$(git symbolic-ref HEAD)" = "zrefs/heads/ main"
32
+ test_cmp_symbolic_HEAD_ref main
27
33
'
28
34
29
35
test_expect_success ' "checkout -" switches forth' '
30
36
git checkout - &&
31
- test "z$(git symbolic-ref HEAD)" = "zrefs/heads/ other"
37
+ test_cmp_symbolic_HEAD_ref other
32
38
'
33
39
34
40
test_expect_success ' detach HEAD' '
@@ -37,12 +43,16 @@ test_expect_success 'detach HEAD' '
37
43
38
44
test_expect_success ' "checkout -" attaches again' '
39
45
git checkout - &&
40
- test "z$(git symbolic-ref HEAD)" = "zrefs/heads/ other"
46
+ test_cmp_symbolic_HEAD_ref other
41
47
'
42
48
43
49
test_expect_success ' "checkout -" detaches again' '
44
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
+
46
56
test_must_fail git symbolic-ref HEAD
47
57
'
48
58
@@ -63,31 +73,31 @@ more_switches () {
63
73
test_expect_success ' switch to the last' '
64
74
more_switches &&
65
75
git checkout @{-1} &&
66
- test "z$(git symbolic-ref HEAD)" = "zrefs/heads/ branch2"
76
+ test_cmp_symbolic_HEAD_ref branch2
67
77
'
68
78
69
79
test_expect_success ' switch to second from the last' '
70
80
more_switches &&
71
81
git checkout @{-2} &&
72
- test "z$(git symbolic-ref HEAD)" = "zrefs/heads/ branch3"
82
+ test_cmp_symbolic_HEAD_ref branch3
73
83
'
74
84
75
85
test_expect_success ' switch to third from the last' '
76
86
more_switches &&
77
87
git checkout @{-3} &&
78
- test "z$(git symbolic-ref HEAD)" = "zrefs/heads/ branch4"
88
+ test_cmp_symbolic_HEAD_ref branch4
79
89
'
80
90
81
91
test_expect_success ' switch to fourth from the last' '
82
92
more_switches &&
83
93
git checkout @{-4} &&
84
- test "z$(git symbolic-ref HEAD)" = "zrefs/heads/ branch5"
94
+ test_cmp_symbolic_HEAD_ref branch5
85
95
'
86
96
87
97
test_expect_success ' switch to twelfth from the last' '
88
98
more_switches &&
89
99
git checkout @{-12} &&
90
- test "z$(git symbolic-ref HEAD)" = "zrefs/heads/ branch13"
100
+ test_cmp_symbolic_HEAD_ref branch13
91
101
'
92
102
93
103
test_expect_success ' merge base test setup' '
@@ -98,27 +108,36 @@ test_expect_success 'merge base test setup' '
98
108
test_expect_success ' another...main' '
99
109
git checkout another &&
100
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
102
115
'
103
116
104
117
test_expect_success ' ...main' '
105
118
git checkout another &&
106
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
108
124
'
109
125
110
126
test_expect_success ' main...' '
111
127
git checkout another &&
112
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
114
133
'
115
134
116
135
test_expect_success ' "checkout -" works after a rebase A' '
117
136
git checkout main &&
118
137
git checkout other &&
119
138
git rebase main &&
120
139
git checkout - &&
121
- test "z$(git symbolic-ref HEAD)" = "zrefs/heads/ main"
140
+ test_cmp_symbolic_HEAD_ref main
122
141
'
123
142
124
143
test_expect_success ' "checkout -" works after a rebase A B' '
@@ -127,15 +146,15 @@ test_expect_success '"checkout -" works after a rebase A B' '
127
146
git checkout other &&
128
147
git rebase main moodle &&
129
148
git checkout - &&
130
- test "z$(git symbolic-ref HEAD)" = "zrefs/heads/ main"
149
+ test_cmp_symbolic_HEAD_ref main
131
150
'
132
151
133
152
test_expect_success ' "checkout -" works after a rebase -i A' '
134
153
git checkout main &&
135
154
git checkout other &&
136
155
git rebase -i main &&
137
156
git checkout - &&
138
- test "z$(git symbolic-ref HEAD)" = "zrefs/heads/ main"
157
+ test_cmp_symbolic_HEAD_ref main
139
158
'
140
159
141
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' '
144
163
git checkout other &&
145
164
git rebase main foodle &&
146
165
git checkout - &&
147
- test "z$(git symbolic-ref HEAD)" = "zrefs/heads/ main"
166
+ test_cmp_symbolic_HEAD_ref main
148
167
'
149
168
150
169
test_done
0 commit comments