@matheusbsbs / matheus-bagliano / commits / a781cd6fef
Fork 0

t3415: stop losing return codes of git commands

Fix invocations of git commands so their exit codes are not lost within non-assignment command substitutions. Signed-off-by: Denton Liu <liu.denton@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Denton Liu committed Jan 6, 2020 at 23:53 UTC a781cd6fefcb40297cdb52cb02e7cb6b940598f2
1 file changed +82 -31
t/t3415-rebase-autosquash.sh
+82 -31
@@ -37,8 +37,12 @@ test_auto_fixup () {
37 git log --oneline >actual &&
38 test_line_count = 3 actual &&
39 git diff --exit-code $1 &&
40 - test 1 = "$(git cat-file blob HEAD^:file1)" &&
41 - test 1 = $(git cat-file commit HEAD^ | grep first | wc -l)
40 + echo 1 >expect &&
41 + git cat-file blob HEAD^:file1 >actual &&
42 + test_cmp expect actual &&
43 + git cat-file commit HEAD^ >commit &&
44 + grep first commit >actual &&
45 + test_line_count = 1 actual
46 }
47
48 test_expect_success 'auto fixup (option)' '
@@ -66,8 +70,12 @@ test_auto_squash () {
70 git log --oneline >actual &&
71 test_line_count = 3 actual &&
72 git diff --exit-code $1 &&
69 - test 1 = "$(git cat-file blob HEAD^:file1)" &&
70 - test 2 = $(git cat-file commit HEAD^ | grep first | wc -l)
73 + echo 1 >expect &&
74 + git cat-file blob HEAD^:file1 >actual &&
75 + test_cmp expect actual &&
76 + git cat-file commit HEAD^ >commit &&
77 + grep first commit >actual &&
78 + test_line_count = 2 actual
79 }
80
81 test_expect_success 'auto squash (option)' '
@@ -94,7 +102,8 @@ test_expect_success 'misspelled auto squash' '
102 git log --oneline >actual &&
103 test_line_count = 4 actual &&
104 git diff --exit-code final-missquash &&
97 - test 0 = $(git rev-list final-missquash...HEAD | wc -l)
105 + git rev-list final-missquash...HEAD >list &&
106 + test_must_be_empty list
107 '
108
109 test_expect_success 'auto squash that matches 2 commits' '
@@ -113,9 +122,15 @@ test_expect_success 'auto squash that matches 2 commits' '
122 git log --oneline >actual &&
123 test_line_count = 4 actual &&
124 git diff --exit-code final-multisquash &&
116 - test 1 = "$(git cat-file blob HEAD^^:file1)" &&
117 - test 2 = $(git cat-file commit HEAD^^ | grep first | wc -l) &&
118 - test 1 = $(git cat-file commit HEAD | grep first | wc -l)
125 + echo 1 >expect &&
126 + git cat-file blob HEAD^^:file1 >actual &&
127 + test_cmp expect actual &&
128 + git cat-file commit HEAD^^ >commit &&
129 + grep first commit >actual &&
130 + test_line_count = 2 actual &&
131 + git cat-file commit HEAD >commit &&
132 + grep first commit >actual &&
133 + test_line_count = 1 actual
134 '
135
136 test_expect_success 'auto squash that matches a commit after the squash' '
@@ -134,25 +149,38 @@ test_expect_success 'auto squash that matches a commit after the squash' '
149 git log --oneline >actual &&
150 test_line_count = 5 actual &&
151 git diff --exit-code final-presquash &&
137 - test 0 = "$(git cat-file blob HEAD^^:file1)" &&
138 - test 1 = "$(git cat-file blob HEAD^:file1)" &&
139 - test 1 = $(git cat-file commit HEAD | grep third | wc -l) &&
140 - test 1 = $(git cat-file commit HEAD^ | grep third | wc -l)
152 + echo 0 >expect &&
153 + git cat-file blob HEAD^^:file1 >actual &&
154 + test_cmp expect actual &&
155 + echo 1 >expect &&
156 + git cat-file blob HEAD^:file1 >actual &&
157 + test_cmp expect actual &&
158 + git cat-file commit HEAD >commit &&
159 + grep third commit >actual &&
160 + test_line_count = 1 actual &&
161 + git cat-file commit HEAD^ >commit &&
162 + grep third commit >actual &&
163 + test_line_count = 1 actual
164 '
165 test_expect_success 'auto squash that matches a sha1' '
166 git reset --hard base &&
167 echo 1 >file1 &&
168 git add -u &&
169 test_tick &&
147 - git commit -m "squash! $(git rev-parse --short HEAD^)" &&
170 + oid=$(git rev-parse --short HEAD^) &&
171 + git commit -m "squash! $oid" &&
172 git tag final-shasquash &&
173 test_tick &&
174 git rebase --autosquash -i HEAD^^^ &&
175 git log --oneline >actual &&
176 test_line_count = 3 actual &&
177 git diff --exit-code final-shasquash &&
154 - test 1 = "$(git cat-file blob HEAD^:file1)" &&
155 - test 1 = $(git cat-file commit HEAD^ | grep squash | wc -l)
178 + echo 1 >expect &&
179 + git cat-file blob HEAD^:file1 >actual &&
180 + test_cmp expect actual &&
181 + git cat-file commit HEAD^ >commit &&
182 + grep squash commit >actual &&
183 + test_line_count = 1 actual
184 '
185
186 test_expect_success 'auto squash that matches longer sha1' '
@@ -160,15 +188,20 @@ test_expect_success 'auto squash that matches longer sha1' '
188 echo 1 >file1 &&
189 git add -u &&
190 test_tick &&
163 - git commit -m "squash! $(git rev-parse --short=11 HEAD^)" &&
191 + oid=$(git rev-parse --short=11 HEAD^) &&
192 + git commit -m "squash! $oid" &&
193 git tag final-longshasquash &&
194 test_tick &&
195 git rebase --autosquash -i HEAD^^^ &&
196 git log --oneline >actual &&
197 test_line_count = 3 actual &&
198 git diff --exit-code final-longshasquash &&
170 - test 1 = "$(git cat-file blob HEAD^:file1)" &&
171 - test 1 = $(git cat-file commit HEAD^ | grep squash | wc -l)
199 + echo 1 >expect &&
200 + git cat-file blob HEAD^:file1 >actual &&
201 + test_cmp expect actual &&
202 + git cat-file commit HEAD^ >commit &&
203 + grep squash commit >actual &&
204 + test_line_count = 1 actual
205 '
206
207 test_auto_commit_flags () {
@@ -183,8 +216,12 @@ test_auto_commit_flags () {
216 git log --oneline >actual &&
217 test_line_count = 3 actual &&
218 git diff --exit-code final-commit-$1 &&
186 - test 1 = "$(git cat-file blob HEAD^:file1)" &&
187 - test $2 = $(git cat-file commit HEAD^ | grep first | wc -l)
219 + echo 1 >expect &&
220 + git cat-file blob HEAD^:file1 >actual &&
221 + test_cmp expect actual &&
222 + git cat-file commit HEAD^ >commit &&
223 + grep first commit >actual &&
224 + test_line_count = $2 actual
225 }
226
227 test_expect_success 'use commit --fixup' '
@@ -210,11 +247,15 @@ test_auto_fixup_fixup () {
247 (
248 set_cat_todo_editor &&
249 test_must_fail git rebase --autosquash -i HEAD^^^^ >actual &&
250 + head=$(git rev-parse --short HEAD) &&
251 + parent1=$(git rev-parse --short HEAD^) &&
252 + parent2=$(git rev-parse --short HEAD^^) &&
253 + parent3=$(git rev-parse --short HEAD^^^) &&
254 cat >expected <<-EOF &&
214 - pick $(git rev-parse --short HEAD^^^) first commit
215 - $1 $(git rev-parse --short HEAD^) $1! first
216 - $1 $(git rev-parse --short HEAD) $1! $2! first
217 - pick $(git rev-parse --short HEAD^^) second commit
255 + pick $parent3 first commit
256 + $1 $parent1 $1! first
257 + $1 $head $1! $2! first
258 + pick $parent2 second commit
259 EOF
260 test_cmp expected actual
261 ) &&
@@ -222,13 +263,17 @@ test_auto_fixup_fixup () {
263 git log --oneline >actual &&
264 test_line_count = 3 actual
265 git diff --exit-code "final-$1-$2" &&
225 - test 2 = "$(git cat-file blob HEAD^:file1)" &&
266 + echo 2 >expect &&
267 + git cat-file blob HEAD^:file1 >actual &&
268 + test_cmp expect actual &&
269 + git cat-file commit HEAD^ >commit &&
270 + grep first commit >actual &&
271 if test "$1" = "fixup"
272 then
228 - test 1 = $(git cat-file commit HEAD^ | grep first | wc -l)
273 + test_line_count = 1 actual
274 elif test "$1" = "squash"
275 then
231 - test 3 = $(git cat-file commit HEAD^ | grep first | wc -l)
276 + test_line_count = 3 actual
277 else
278 false
279 fi
@@ -256,19 +301,25 @@ test_expect_success C_LOCALE_OUTPUT 'autosquash with custom inst format' '
301 echo 2 >file1 &&
302 git add -u &&
303 test_tick &&
259 - git commit -m "squash! $(git rev-parse --short HEAD^)" &&
304 + oid=$(git rev-parse --short HEAD^) &&
305 + git commit -m "squash! $oid" &&
306 echo 1 >file1 &&
307 git add -u &&
308 test_tick &&
263 - git commit -m "squash! $(git log -n 1 --format=%s HEAD~2)" &&
309 + subject=$(git log -n 1 --format=%s HEAD~2) &&
310 + git commit -m "squash! $subject" &&
311 git tag final-squash-instFmt &&
312 test_tick &&
313 git rebase --autosquash -i HEAD~4 &&
314 git log --oneline >actual &&
315 test_line_count = 3 actual &&
316 git diff --exit-code final-squash-instFmt &&
270 - test 1 = "$(git cat-file blob HEAD^:file1)" &&
271 - test 2 = $(git cat-file commit HEAD^ | grep squash | wc -l)
317 + echo 1 >expect &&
318 + git cat-file blob HEAD^:file1 >actual &&
319 + test_cmp expect actual &&
320 + git cat-file commit HEAD^ >commit &&
321 + grep squash commit >actual &&
322 + test_line_count = 2 actual
323 '
324
325 test_expect_success 'autosquash with empty custom instructionFormat' '