Skip to content

Commit 854b5cb

Browse files
Denton-Lgitster
authored andcommitted
t4014: stop losing return codes of git commands
Currently, there are two ways where the return codes of Git commands are lost. The first way is when a command is in the upstream of a pipe. In a pipe, only the return code of the last command is used. Thus, all other commands will have their return codes masked. Rewrite pipes so that there are no Git commands upstream. The other way is when a command is in a non-assignment subshell. The return code will be lost in favour of the surrounding command's. Rewrite instances of this such that Git commands output to a file and surrounding commands only call subshells with non-Git commands. Signed-off-by: Denton Liu <liu.denton@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent dd2b6b6 commit 854b5cb

File tree

1 file changed

+120
-77
lines changed

1 file changed

+120
-77
lines changed

t/t4014-format-patch.sh

Lines changed: 120 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ test_expect_success setup '
3333
git commit -m "Side changes #3 with \\n backslash-n in it." &&
3434
3535
git checkout master &&
36-
git diff-tree -p C2 | git apply --index &&
36+
git diff-tree -p C2 >patch &&
37+
git apply --index <patch &&
3738
test_tick &&
3839
git commit -m "Master accepts moral equivalent of #2" &&
3940
@@ -110,7 +111,8 @@ test_expect_success 'format-patch --ignore-if-in-upstream result applies' '
110111
'
111112

112113
test_expect_success 'commit did not screw up the log message' '
113-
git cat-file commit side | grep "^Side .* with .* backslash-n"
114+
git cat-file commit side >actual &&
115+
grep "^Side .* with .* backslash-n" actual
114116
'
115117

116118
test_expect_success 'format-patch did not screw up the log message' '
@@ -119,7 +121,8 @@ test_expect_success 'format-patch did not screw up the log message' '
119121
'
120122

121123
test_expect_success 'replay did not screw up the log message' '
122-
git cat-file commit rebuild-1 | grep "^Side .* with .* backslash-n"
124+
git cat-file commit rebuild-1 >actual &&
125+
grep "^Side .* with .* backslash-n" actual
123126
'
124127

125128
test_expect_success 'extra headers' '
@@ -153,63 +156,73 @@ test_expect_success 'extra headers with multiple To:s' '
153156

154157
test_expect_success 'additional command line cc (ascii)' '
155158
git config --replace-all format.headers "Cc: R E Cipient <rcipient@example.com>" &&
156-
git format-patch --cc="S E Cipient <scipient@example.com>" --stdout master..side | sed -e "/^\$/q" >patch5 &&
157-
grep "^Cc: R E Cipient <rcipient@example.com>,\$" patch5 &&
158-
grep "^ *S E Cipient <scipient@example.com>\$" patch5
159+
git format-patch --cc="S E Cipient <scipient@example.com>" --stdout master..side >patch5 &&
160+
sed -e "/^\$/q" patch5 >hdrs5 &&
161+
grep "^Cc: R E Cipient <rcipient@example.com>,\$" hdrs5 &&
162+
grep "^ *S E Cipient <scipient@example.com>\$" hdrs5
159163
'
160164

161165
test_expect_failure 'additional command line cc (rfc822)' '
162166
git config --replace-all format.headers "Cc: R E Cipient <rcipient@example.com>" &&
163-
git format-patch --cc="S. E. Cipient <scipient@example.com>" --stdout master..side | sed -e "/^\$/q" >patch5 &&
164-
grep "^Cc: R E Cipient <rcipient@example.com>,\$" patch5 &&
165-
grep "^ *\"S. E. Cipient\" <scipient@example.com>\$" patch5
167+
git format-patch --cc="S. E. Cipient <scipient@example.com>" --stdout master..side >patch5 &&
168+
sed -e "/^\$/q" patch5 >hdrs5 &&
169+
grep "^Cc: R E Cipient <rcipient@example.com>,\$" hdrs5 &&
170+
grep "^ *\"S. E. Cipient\" <scipient@example.com>\$" hdrs5
166171
'
167172

168173
test_expect_success 'command line headers' '
169174
git config --unset-all format.headers &&
170-
git format-patch --add-header="Cc: R E Cipient <rcipient@example.com>" --stdout master..side | sed -e "/^\$/q" >patch6 &&
171-
grep "^Cc: R E Cipient <rcipient@example.com>\$" patch6
175+
git format-patch --add-header="Cc: R E Cipient <rcipient@example.com>" --stdout master..side >patch6 &&
176+
sed -e "/^\$/q" patch6 >hdrs6 &&
177+
grep "^Cc: R E Cipient <rcipient@example.com>\$" hdrs6
172178
'
173179

174180
test_expect_success 'configuration headers and command line headers' '
175181
git config --replace-all format.headers "Cc: R E Cipient <rcipient@example.com>" &&
176-
git format-patch --add-header="Cc: S E Cipient <scipient@example.com>" --stdout master..side | sed -e "/^\$/q" >patch7 &&
177-
grep "^Cc: R E Cipient <rcipient@example.com>,\$" patch7 &&
178-
grep "^ *S E Cipient <scipient@example.com>\$" patch7
182+
git format-patch --add-header="Cc: S E Cipient <scipient@example.com>" --stdout master..side >patch7 &&
183+
sed -e "/^\$/q" patch7 >hdrs7 &&
184+
grep "^Cc: R E Cipient <rcipient@example.com>,\$" hdrs7 &&
185+
grep "^ *S E Cipient <scipient@example.com>\$" hdrs7
179186
'
180187

181188
test_expect_success 'command line To: header (ascii)' '
182189
git config --unset-all format.headers &&
183-
git format-patch --to="R E Cipient <rcipient@example.com>" --stdout master..side | sed -e "/^\$/q" >patch8 &&
184-
grep "^To: R E Cipient <rcipient@example.com>\$" patch8
190+
git format-patch --to="R E Cipient <rcipient@example.com>" --stdout master..side >patch8 &&
191+
sed -e "/^\$/q" patch8 >hdrs8 &&
192+
grep "^To: R E Cipient <rcipient@example.com>\$" hdrs8
185193
'
186194

187195
test_expect_failure 'command line To: header (rfc822)' '
188-
git format-patch --to="R. E. Cipient <rcipient@example.com>" --stdout master..side | sed -e "/^\$/q" >patch8 &&
189-
grep "^To: \"R. E. Cipient\" <rcipient@example.com>\$" patch8
196+
git format-patch --to="R. E. Cipient <rcipient@example.com>" --stdout master..side >patch8 &&
197+
sed -e "/^\$/q" patch8 >hdrs8 &&
198+
grep "^To: \"R. E. Cipient\" <rcipient@example.com>\$" hdrs8
190199
'
191200

192201
test_expect_failure 'command line To: header (rfc2047)' '
193-
git format-patch --to="R Ä Cipient <rcipient@example.com>" --stdout master..side | sed -e "/^\$/q" >patch8 &&
194-
grep "^To: =?UTF-8?q?R=20=C3=84=20Cipient?= <rcipient@example.com>\$" patch8
202+
git format-patch --to="R Ä Cipient <rcipient@example.com>" --stdout master..side >patch8 &&
203+
sed -e "/^\$/q" patch8 >hdrs8 &&
204+
grep "^To: =?UTF-8?q?R=20=C3=84=20Cipient?= <rcipient@example.com>\$" hdrs8
195205
'
196206

197207
test_expect_success 'configuration To: header (ascii)' '
198208
git config format.to "R E Cipient <rcipient@example.com>" &&
199-
git format-patch --stdout master..side | sed -e "/^\$/q" >patch9 &&
200-
grep "^To: R E Cipient <rcipient@example.com>\$" patch9
209+
git format-patch --stdout master..side >patch9 &&
210+
sed -e "/^\$/q" patch9 >hdrs9 &&
211+
grep "^To: R E Cipient <rcipient@example.com>\$" hdrs9
201212
'
202213

203214
test_expect_failure 'configuration To: header (rfc822)' '
204215
git config format.to "R. E. Cipient <rcipient@example.com>" &&
205-
git format-patch --stdout master..side | sed -e "/^\$/q" >patch9 &&
206-
grep "^To: \"R. E. Cipient\" <rcipient@example.com>\$" patch9
216+
git format-patch --stdout master..side >patch9 &&
217+
sed -e "/^\$/q" patch9 >hdrs9 &&
218+
grep "^To: \"R. E. Cipient\" <rcipient@example.com>\$" hdrs9
207219
'
208220

209221
test_expect_failure 'configuration To: header (rfc2047)' '
210222
git config format.to "R Ä Cipient <rcipient@example.com>" &&
211-
git format-patch --stdout master..side | sed -e "/^\$/q" >patch9 &&
212-
grep "^To: =?UTF-8?q?R=20=C3=84=20Cipient?= <rcipient@example.com>\$" patch9
223+
git format-patch --stdout master..side >patch9 &&
224+
sed -e "/^\$/q" patch9 >hdrs9 &&
225+
grep "^To: =?UTF-8?q?R=20=C3=84=20Cipient?= <rcipient@example.com>\$" hdrs9
213226
'
214227

215228
# check_patch <patch>: Verify that <patch> looks like a half-sane
@@ -221,76 +234,76 @@ check_patch () {
221234
}
222235

223236
test_expect_success 'format.from=false' '
224-
git -c format.from=false format-patch --stdout master..side |
225-
sed -e "/^\$/q" >patch &&
237+
git -c format.from=false format-patch --stdout master..side >patch &&
238+
sed -e "/^\$/q" patch >hdrs &&
226239
check_patch patch &&
227-
! grep "^From: C O Mitter <committer@example.com>\$" patch
240+
! grep "^From: C O Mitter <committer@example.com>\$" hdrs
228241
'
229242

230243
test_expect_success 'format.from=true' '
231-
git -c format.from=true format-patch --stdout master..side |
232-
sed -e "/^\$/q" >patch &&
233-
check_patch patch &&
234-
grep "^From: C O Mitter <committer@example.com>\$" patch
244+
git -c format.from=true format-patch --stdout master..side >patch &&
245+
sed -e "/^\$/q" patch >hdrs &&
246+
check_patch hdrs &&
247+
grep "^From: C O Mitter <committer@example.com>\$" hdrs
235248
'
236249

237250
test_expect_success 'format.from with address' '
238-
git -c format.from="F R Om <from@example.com>" format-patch --stdout master..side |
239-
sed -e "/^\$/q" >patch &&
240-
check_patch patch &&
241-
grep "^From: F R Om <from@example.com>\$" patch
251+
git -c format.from="F R Om <from@example.com>" format-patch --stdout master..side >patch &&
252+
sed -e "/^\$/q" patch >hdrs &&
253+
check_patch hdrs &&
254+
grep "^From: F R Om <from@example.com>\$" hdrs
242255
'
243256

244257
test_expect_success '--no-from overrides format.from' '
245-
git -c format.from="F R Om <from@example.com>" format-patch --no-from --stdout master..side |
246-
sed -e "/^\$/q" >patch &&
247-
check_patch patch &&
248-
! grep "^From: F R Om <from@example.com>\$" patch
258+
git -c format.from="F R Om <from@example.com>" format-patch --no-from --stdout master..side >patch &&
259+
sed -e "/^\$/q" patch >hdrs &&
260+
check_patch hdrs &&
261+
! grep "^From: F R Om <from@example.com>\$" hdrs
249262
'
250263

251264
test_expect_success '--from overrides format.from' '
252-
git -c format.from="F R Om <from@example.com>" format-patch --from --stdout master..side |
253-
sed -e "/^\$/q" >patch &&
254-
check_patch patch &&
255-
! grep "^From: F R Om <from@example.com>\$" patch
265+
git -c format.from="F R Om <from@example.com>" format-patch --from --stdout master..side >patch &&
266+
sed -e "/^\$/q" patch >hdrs &&
267+
check_patch hdrs &&
268+
! grep "^From: F R Om <from@example.com>\$" hdrs
256269
'
257270

258271
test_expect_success '--no-to overrides config.to' '
259272
git config --replace-all format.to \
260273
"R E Cipient <rcipient@example.com>" &&
261-
git format-patch --no-to --stdout master..side |
262-
sed -e "/^\$/q" >patch10 &&
263-
check_patch patch10 &&
264-
! grep "^To: R E Cipient <rcipient@example.com>\$" patch10
274+
git format-patch --no-to --stdout master..side >patch10 &&
275+
sed -e "/^\$/q" patch10 >hdrs10 &&
276+
check_patch hdrs10 &&
277+
! grep "^To: R E Cipient <rcipient@example.com>\$" hdrs10
265278
'
266279

267280
test_expect_success '--no-to and --to replaces config.to' '
268281
git config --replace-all format.to \
269282
"Someone <someone@out.there>" &&
270283
git format-patch --no-to --to="Someone Else <else@out.there>" \
271-
--stdout master..side |
272-
sed -e "/^\$/q" >patch11 &&
273-
check_patch patch11 &&
274-
! grep "^To: Someone <someone@out.there>\$" patch11 &&
275-
grep "^To: Someone Else <else@out.there>\$" patch11
284+
--stdout master..side >patch11 &&
285+
sed -e "/^\$/q" patch11 >hdrs11 &&
286+
check_patch hdrs11 &&
287+
! grep "^To: Someone <someone@out.there>\$" hdrs11 &&
288+
grep "^To: Someone Else <else@out.there>\$" hdrs11
276289
'
277290

278291
test_expect_success '--no-cc overrides config.cc' '
279292
git config --replace-all format.cc \
280293
"C E Cipient <rcipient@example.com>" &&
281-
git format-patch --no-cc --stdout master..side |
282-
sed -e "/^\$/q" >patch12 &&
283-
check_patch patch12 &&
284-
! grep "^Cc: C E Cipient <rcipient@example.com>\$" patch12
294+
git format-patch --no-cc --stdout master..side >patch12 &&
295+
sed -e "/^\$/q" patch12 >hdrs12 &&
296+
check_patch hdrs12 &&
297+
! grep "^Cc: C E Cipient <rcipient@example.com>\$" hdrs12
285298
'
286299

287300
test_expect_success '--no-add-header overrides config.headers' '
288301
git config --replace-all format.headers \
289302
"Header1: B E Cipient <rcipient@example.com>" &&
290-
git format-patch --no-add-header --stdout master..side |
291-
sed -e "/^\$/q" >patch13 &&
292-
check_patch patch13 &&
293-
! grep "^Header1: B E Cipient <rcipient@example.com>\$" patch13
303+
git format-patch --no-add-header --stdout master..side >patch13 &&
304+
sed -e "/^\$/q" patch13 >hdrs13 &&
305+
check_patch hdrs13 &&
306+
! grep "^Header1: B E Cipient <rcipient@example.com>\$" hdrs13
294307
'
295308

296309
test_expect_success 'multiple files' '
@@ -808,20 +821,25 @@ test_expect_success 'format-patch --ignore-if-in-upstream HEAD' '
808821
git format-patch --ignore-if-in-upstream HEAD
809822
'
810823

811-
git_version="$(git --version | sed "s/.* //")"
824+
test_expect_success 'get git version' '
825+
git_version=$(git --version) &&
826+
git_version=${git_version##* }
827+
'
812828

813829
signature() {
814830
printf "%s\n%s\n\n" "-- " "${1:-$git_version}"
815831
}
816832

817833
test_expect_success 'format-patch default signature' '
818-
git format-patch --stdout -1 | tail -n 3 >output &&
834+
git format-patch --stdout -1 >patch &&
835+
tail -n 3 patch >output &&
819836
signature >expect &&
820837
test_cmp expect output
821838
'
822839

823840
test_expect_success 'format-patch --signature' '
824-
git format-patch --stdout --signature="my sig" -1 | tail -n 3 >output &&
841+
git format-patch --stdout --signature="my sig" -1 >patch &&
842+
tail -n 3 patch >output &&
825843
signature "my sig" >expect &&
826844
test_cmp expect output
827845
'
@@ -1606,19 +1624,40 @@ test_expect_success 'format-patch -o overrides format.outputDirectory' '
16061624

16071625
test_expect_success 'format-patch --base' '
16081626
git checkout patchid &&
1609-
git format-patch --stdout --base=HEAD~3 -1 | tail -n 7 >actual1 &&
1610-
git format-patch --stdout --base=HEAD~3 HEAD~.. | tail -n 7 >actual2 &&
1627+
1628+
git format-patch --stdout --base=HEAD~3 -1 >patch &&
1629+
tail -n 7 patch >actual1 &&
1630+
1631+
git format-patch --stdout --base=HEAD~3 HEAD~.. >patch &&
1632+
tail -n 7 patch >actual2 &&
1633+
16111634
echo >expect &&
1612-
echo "base-commit: $(git rev-parse HEAD~3)" >>expect &&
1613-
echo "prerequisite-patch-id: $(git show --patch HEAD~2 | git patch-id --stable | awk "{print \$1}")" >>expect &&
1614-
echo "prerequisite-patch-id: $(git show --patch HEAD~1 | git patch-id --stable | awk "{print \$1}")" >>expect &&
1635+
git rev-parse HEAD~3 >commit-id-base &&
1636+
echo "base-commit: $(cat commit-id-base)" >>expect &&
1637+
1638+
git show --patch HEAD~2 >patch &&
1639+
git patch-id --stable <patch >patch.id.raw &&
1640+
awk "{print \"prerequisite-patch-id:\", \$1}" <patch.id.raw >>expect &&
1641+
1642+
git show --patch HEAD~1 >patch &&
1643+
git patch-id --stable <patch >patch.id.raw &&
1644+
awk "{print \"prerequisite-patch-id:\", \$1}" <patch.id.raw >>expect &&
1645+
16151646
signature >>expect &&
16161647
test_cmp expect actual1 &&
16171648
test_cmp expect actual2 &&
1649+
16181650
echo >fail &&
1619-
echo "base-commit: $(git rev-parse HEAD~3)" >>fail &&
1620-
echo "prerequisite-patch-id: $(git show --patch HEAD~2 | git patch-id --unstable | awk "{print \$1}")" >>fail &&
1621-
echo "prerequisite-patch-id: $(git show --patch HEAD~1 | git patch-id --unstable | awk "{print \$1}")" >>fail &&
1651+
echo "base-commit: $(cat commit-id-base)" >>fail &&
1652+
1653+
git show --patch HEAD~2 >patch &&
1654+
git patch-id --unstable <patch >patch.id.raw &&
1655+
awk "{print \"prerequisite-patch-id:\", \$1}" <patch.id.raw >>fail &&
1656+
1657+
git show --patch HEAD~1 >patch &&
1658+
git patch-id --unstable <patch >patch.id.raw &&
1659+
awk "{print \"prerequisite-patch-id:\", \$1}" <patch.id.raw >>fail &&
1660+
16221661
signature >>fail &&
16231662
! test_cmp fail actual1 &&
16241663
! test_cmp fail actual2
@@ -1629,7 +1668,8 @@ test_expect_success 'format-patch --base errors out when base commit is in revis
16291668
test_must_fail git format-patch --base=HEAD~1 -2 &&
16301669
git format-patch --stdout --base=HEAD~2 -2 >patch &&
16311670
grep "^base-commit:" patch >actual &&
1632-
echo "base-commit: $(git rev-parse HEAD~2)" >expect &&
1671+
git rev-parse HEAD~2 >commit-id-base &&
1672+
echo "base-commit: $(cat commit-id-base)" >expect &&
16331673
test_cmp expect actual
16341674
'
16351675

@@ -1668,7 +1708,8 @@ test_expect_success 'format-patch --base=auto' '
16681708
test_commit N2 &&
16691709
git format-patch --stdout --base=auto -2 >patch &&
16701710
grep "^base-commit:" patch >actual &&
1671-
echo "base-commit: $(git rev-parse upstream)" >expect &&
1711+
git rev-parse upstream >commit-id-base &&
1712+
echo "base-commit: $(cat commit-id-base)" >expect &&
16721713
test_cmp expect actual
16731714
'
16741715

@@ -1705,7 +1746,8 @@ test_expect_success 'format-patch format.useAutoBaseoption' '
17051746
git config format.useAutoBase true &&
17061747
git format-patch --stdout -1 >patch &&
17071748
grep "^base-commit:" patch >actual &&
1708-
echo "base-commit: $(git rev-parse upstream)" >expect &&
1749+
git rev-parse upstream >commit-id-base &&
1750+
echo "base-commit: $(cat commit-id-base)" >expect &&
17091751
test_cmp expect actual
17101752
'
17111753

@@ -1714,7 +1756,8 @@ test_expect_success 'format-patch --base overrides format.useAutoBase' '
17141756
git config format.useAutoBase true &&
17151757
git format-patch --stdout --base=HEAD~1 -1 >patch &&
17161758
grep "^base-commit:" patch >actual &&
1717-
echo "base-commit: $(git rev-parse HEAD~1)" >expect &&
1759+
git rev-parse HEAD~1 >commit-id-base &&
1760+
echo "base-commit: $(cat commit-id-base)" >expect &&
17181761
test_cmp expect actual
17191762
'
17201763

0 commit comments

Comments
 (0)