]> git.ipfire.org Git - thirdparty/git.git/blame - t/t4014-format-patch.sh
config: improve error message for boolean config
[thirdparty/git.git] / t / t4014-format-patch.sh
CommitLineData
ece3c67f
JH
1#!/bin/sh
2#
3# Copyright (c) 2006 Junio C Hamano
4#
5
9800a754 6test_description='various format-patch tests'
ece3c67f
JH
7
8. ./test-lib.sh
38a94bb6 9. "$TEST_DIRECTORY"/lib-terminal.sh
ece3c67f
JH
10
11test_expect_success setup '
ece3c67f 12 for i in 1 2 3 4 5 6 7 8 9 10; do echo "$i"; done >file &&
cd894ee9
JH
13 cat file >elif &&
14 git add file elif &&
6426f2d2 15 test_tick &&
ece3c67f
JH
16 git commit -m Initial &&
17 git checkout -b side &&
18
19 for i in 1 2 5 6 A B C 7 8 9 10; do echo "$i"; done >file &&
1f553918 20 test_chmod +x elif &&
6426f2d2 21 test_tick &&
816366e2 22 git commit -m "Side changes #1" &&
ece3c67f
JH
23
24 for i in D E F; do echo "$i"; done >>file &&
25 git update-index file &&
6426f2d2 26 test_tick &&
816366e2 27 git commit -m "Side changes #2" &&
982b64e4 28 git tag C2 &&
ece3c67f
JH
29
30 for i in 5 6 1 2 3 A 4 B C 7 8 9 10 D E F; do echo "$i"; done >file &&
31 git update-index file &&
6426f2d2 32 test_tick &&
816366e2 33 git commit -m "Side changes #3 with \\n backslash-n in it." &&
ece3c67f
JH
34
35 git checkout master &&
854b5cb4
DL
36 git diff-tree -p C2 >patch &&
37 git apply --index <patch &&
6426f2d2 38 test_tick &&
6f93d261 39 git commit -m "Master accepts moral equivalent of #2" &&
ece3c67f 40
6f93d261
SB
41 git checkout side &&
42 git checkout -b patchid &&
43 for i in 5 6 1 2 3 A 4 B C 7 8 9 10 D E F; do echo "$i"; done >file2 &&
44 for i in 1 2 3 A 4 B C 7 8 9 10 D E F 5 6; do echo "$i"; done >file3 &&
45 for i in 8 9 10; do echo "$i"; done >file &&
46 git add file file2 file3 &&
47 test_tick &&
48 git commit -m "patchid 1" &&
49 for i in 4 A B 7 8 9 10; do echo "$i"; done >file2 &&
50 for i in 8 9 10 5 6; do echo "$i"; done >file3 &&
51 git add file2 file3 &&
52 test_tick &&
53 git commit -m "patchid 2" &&
54 for i in 10 5 6; do echo "$i"; done >file &&
55 git add file &&
56 test_tick &&
57 git commit -m "patchid 3" &&
58
59 git checkout master
ece3c67f
JH
60'
61
0ab74e97 62test_expect_success 'format-patch --ignore-if-in-upstream' '
ece3c67f 63 git format-patch --stdout master..side >patch0 &&
6bd26f58
DL
64 grep "^From " patch0 >from0 &&
65 test_line_count = 3 from0
ece3c67f
JH
66'
67
0ab74e97 68test_expect_success 'format-patch --ignore-if-in-upstream' '
ece3c67f
JH
69 git format-patch --stdout \
70 --ignore-if-in-upstream master..side >patch1 &&
6bd26f58
DL
71 grep "^From " patch1 >from1 &&
72 test_line_count = 2 from1
ece3c67f
JH
73'
74
0ab74e97 75test_expect_success 'format-patch --ignore-if-in-upstream handles tags' '
9b7a61d7
JH
76 git tag -a v1 -m tag side &&
77 git tag -a v2 -m tag master &&
78 git format-patch --stdout --ignore-if-in-upstream v2..v1 >patch1 &&
6bd26f58
DL
79 grep "^From " patch1 >from1 &&
80 test_line_count = 2 from1
9b7a61d7
JH
81'
82
2c642ed8 83test_expect_success "format-patch doesn't consider merge commits" '
08dc2606 84 git checkout -b feature master &&
2c642ed8
RR
85 echo "Another line" >>file &&
86 test_tick &&
08dc2606 87 git commit -am "Feature branch change #1" &&
2c642ed8
RR
88 echo "Yet another line" >>file &&
89 test_tick &&
08dc2606 90 git commit -am "Feature branch change #2" &&
2c642ed8
RR
91 git checkout -b merger master &&
92 test_tick &&
08dc2606 93 git merge --no-ff feature &&
6bd26f58
DL
94 git format-patch -3 --stdout >patch &&
95 grep "^From " patch >from &&
96 test_line_count = 3 from
2c642ed8
RR
97'
98
0ab74e97 99test_expect_success 'format-patch result applies' '
ece3c67f
JH
100 git checkout -b rebuild-0 master &&
101 git am -3 patch0 &&
6bd26f58
DL
102 git rev-list master.. >list &&
103 test_line_count = 2 list
ece3c67f
JH
104'
105
0ab74e97 106test_expect_success 'format-patch --ignore-if-in-upstream result applies' '
ece3c67f
JH
107 git checkout -b rebuild-1 master &&
108 git am -3 patch1 &&
6bd26f58
DL
109 git rev-list master.. >list &&
110 test_line_count = 2 list
ece3c67f
JH
111'
112
816366e2 113test_expect_success 'commit did not screw up the log message' '
854b5cb4
DL
114 git cat-file commit side >actual &&
115 grep "^Side .* with .* backslash-n" actual
816366e2
JH
116'
117
118test_expect_success 'format-patch did not screw up the log message' '
816366e2
JH
119 grep "^Subject: .*Side changes #3 with .* backslash-n" patch0 &&
120 grep "^Subject: .*Side changes #3 with .* backslash-n" patch1
816366e2
JH
121'
122
123test_expect_success 'replay did not screw up the log message' '
854b5cb4
DL
124 git cat-file commit rebuild-1 >actual &&
125 grep "^Side .* with .* backslash-n" actual
816366e2
JH
126'
127
a8d8173e 128test_expect_success 'extra headers' '
25dc8dad 129 git config format.headers "To: R E Cipient <rcipient@example.com>
a8d8173e 130" &&
25dc8dad 131 git config --add format.headers "Cc: S E Cipient <scipient@example.com>
a8d8173e 132" &&
92014b69
DL
133 git format-patch --stdout master..side >patch2 &&
134 sed -e "/^\$/q" patch2 >hdrs2 &&
25dc8dad
JS
135 grep "^To: R E Cipient <rcipient@example.com>\$" hdrs2 &&
136 grep "^Cc: S E Cipient <scipient@example.com>\$" hdrs2
a8d8173e
DB
137'
138
7d22708b 139test_expect_success 'extra headers without newlines' '
25dc8dad
JS
140 git config --replace-all format.headers "To: R E Cipient <rcipient@example.com>" &&
141 git config --add format.headers "Cc: S E Cipient <scipient@example.com>" &&
a8d8173e 142 git format-patch --stdout master..side >patch3 &&
92014b69 143 sed -e "/^\$/q" patch3 >hdrs3 &&
25dc8dad
JS
144 grep "^To: R E Cipient <rcipient@example.com>\$" hdrs3 &&
145 grep "^Cc: S E Cipient <scipient@example.com>\$" hdrs3
a8d8173e
DB
146'
147
3ee79d9f 148test_expect_success 'extra headers with multiple To:s' '
25dc8dad
JS
149 git config --replace-all format.headers "To: R E Cipient <rcipient@example.com>" &&
150 git config --add format.headers "To: S E Cipient <scipient@example.com>" &&
92014b69
DL
151 git format-patch --stdout master..side >patch4 &&
152 sed -e "/^\$/q" patch4 >hdrs4 &&
25dc8dad
JS
153 grep "^To: R E Cipient <rcipient@example.com>,\$" hdrs4 &&
154 grep "^ *S E Cipient <scipient@example.com>\$" hdrs4
a8d8173e
DB
155'
156
25dc8dad 157test_expect_success 'additional command line cc (ascii)' '
25dc8dad 158 git config --replace-all format.headers "Cc: R E Cipient <rcipient@example.com>" &&
854b5cb4
DL
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
25dc8dad
JS
163'
164
165test_expect_failure 'additional command line cc (rfc822)' '
25dc8dad 166 git config --replace-all format.headers "Cc: R E Cipient <rcipient@example.com>" &&
854b5cb4
DL
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
736cc67d
DB
171'
172
d7d9c2d0 173test_expect_success 'command line headers' '
d7d9c2d0 174 git config --unset-all format.headers &&
854b5cb4
DL
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
d7d9c2d0
MH
178'
179
180test_expect_success 'configuration headers and command line headers' '
25dc8dad 181 git config --replace-all format.headers "Cc: R E Cipient <rcipient@example.com>" &&
854b5cb4
DL
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
d7d9c2d0
MH
186'
187
25dc8dad 188test_expect_success 'command line To: header (ascii)' '
ae6c098f 189 git config --unset-all format.headers &&
854b5cb4
DL
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
25dc8dad
JS
193'
194
195test_expect_failure 'command line To: header (rfc822)' '
854b5cb4
DL
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
25dc8dad
JS
199'
200
201test_expect_failure 'command line To: header (rfc2047)' '
854b5cb4
DL
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
ae6c098f
SD
205'
206
25dc8dad 207test_expect_success 'configuration To: header (ascii)' '
25dc8dad 208 git config format.to "R E Cipient <rcipient@example.com>" &&
854b5cb4
DL
209 git format-patch --stdout master..side >patch9 &&
210 sed -e "/^\$/q" patch9 >hdrs9 &&
211 grep "^To: R E Cipient <rcipient@example.com>\$" hdrs9
25dc8dad
JS
212'
213
214test_expect_failure 'configuration To: header (rfc822)' '
ae6c098f 215 git config format.to "R. E. Cipient <rcipient@example.com>" &&
854b5cb4
DL
216 git format-patch --stdout master..side >patch9 &&
217 sed -e "/^\$/q" patch9 >hdrs9 &&
218 grep "^To: \"R. E. Cipient\" <rcipient@example.com>\$" hdrs9
25dc8dad
JS
219'
220
221test_expect_failure 'configuration To: header (rfc2047)' '
25dc8dad 222 git config format.to "R Ä Cipient <rcipient@example.com>" &&
854b5cb4
DL
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
ae6c098f
SD
226'
227
cc663d14
TR
228# check_patch <patch>: Verify that <patch> looks like a half-sane
229# patch email to avoid a false positive with !grep
230check_patch () {
231 grep -e "^From:" "$1" &&
232 grep -e "^Date:" "$1" &&
233 grep -e "^Subject:" "$1"
234}
235
6bc6b6c0 236test_expect_success 'format.from=false' '
854b5cb4
DL
237 git -c format.from=false format-patch --stdout master..side >patch &&
238 sed -e "/^\$/q" patch >hdrs &&
6bc6b6c0 239 check_patch patch &&
854b5cb4 240 ! grep "^From: C O Mitter <committer@example.com>\$" hdrs
6bc6b6c0
JT
241'
242
243test_expect_success 'format.from=true' '
854b5cb4
DL
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
6bc6b6c0
JT
248'
249
250test_expect_success 'format.from with address' '
854b5cb4
DL
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
6bc6b6c0
JT
255'
256
257test_expect_success '--no-from overrides format.from' '
854b5cb4
DL
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
6bc6b6c0
JT
262'
263
264test_expect_success '--from overrides format.from' '
854b5cb4
DL
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
6bc6b6c0
JT
269'
270
c4260034 271test_expect_success '--no-to overrides config.to' '
c4260034 272 git config --replace-all format.to \
25dc8dad 273 "R E Cipient <rcipient@example.com>" &&
854b5cb4
DL
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
c4260034
SB
278'
279
280test_expect_success '--no-to and --to replaces config.to' '
c4260034
SB
281 git config --replace-all format.to \
282 "Someone <someone@out.there>" &&
283 git format-patch --no-to --to="Someone Else <else@out.there>" \
854b5cb4
DL
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
c4260034
SB
289'
290
291test_expect_success '--no-cc overrides config.cc' '
c4260034 292 git config --replace-all format.cc \
25dc8dad 293 "C E Cipient <rcipient@example.com>" &&
854b5cb4
DL
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
c4260034
SB
298'
299
688f4f2f 300test_expect_success '--no-add-header overrides config.headers' '
c4260034 301 git config --replace-all format.headers \
25dc8dad 302 "Header1: B E Cipient <rcipient@example.com>" &&
854b5cb4
DL
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
c4260034
SB
307'
308
7d812145 309test_expect_success 'multiple files' '
7d812145
DB
310 rm -rf patches/ &&
311 git checkout side &&
312 git format-patch -o patches/ master &&
313 ls patches/0001-Side-changes-1.patch patches/0002-Side-changes-2.patch patches/0003-Side-changes-3-with-n-backslash-n-in-it.patch
314'
315
3baf58bf
JH
316test_expect_success 'filename length limit' '
317 test_when_finished "rm -f 000*" &&
318 rm -rf 000[1-9]-*.patch &&
319 for len in 15 25 35
320 do
321 git format-patch --filename-max-length=$len -3 side &&
322 max=$(
323 for patch in 000[1-9]-*.patch
324 do
325 echo "$patch" | wc -c
326 done |
327 sort -nr |
328 head -n 1
329 ) &&
330 test $max -le $len || return 1
331 done
332'
333
334test_expect_success 'filename length limit from config' '
335 test_when_finished "rm -f 000*" &&
336 rm -rf 000[1-9]-*.patch &&
337 for len in 15 25 35
338 do
339 git -c format.filenameMaxLength=$len format-patch -3 side &&
340 max=$(
341 for patch in 000[1-9]-*.patch
342 do
343 echo "$patch" | wc -c
344 done |
345 sort -nr |
346 head -n 1
347 ) &&
348 test $max -le $len || return 1
349 done
350'
351
352test_expect_success 'filename limit applies only to basename' '
353 test_when_finished "rm -rf patches/" &&
354 rm -rf patches/ &&
355 for len in 15 25 35
356 do
357 git format-patch -o patches --filename-max-length=$len -3 side &&
358 max=$(
359 for patch in patches/000[1-9]-*.patch
360 do
361 echo "${patch#patches/}" | wc -c
362 done |
363 sort -nr |
364 head -n 1
365 ) &&
366 test $max -le $len || return 1
367 done
368'
369
4aad08e0
JH
370test_expect_success 'reroll count' '
371 rm -fr patches &&
372 git format-patch -o patches --cover-letter --reroll-count 4 master..side >list &&
373 ! grep -v "^patches/v4-000[0-3]-" list &&
374 sed -n -e "/^Subject: /p" $(cat list) >subjects &&
375 ! grep -v "^Subject: \[PATCH v4 [0-3]/3\] " subjects
376'
377
7952ea66
JH
378test_expect_success 'reroll count (-v)' '
379 rm -fr patches &&
380 git format-patch -o patches --cover-letter -v4 master..side >list &&
381 ! grep -v "^patches/v4-000[0-3]-" list &&
382 sed -n -e "/^Subject: /p" $(cat list) >subjects &&
383 ! grep -v "^Subject: \[PATCH v4 [0-3]/3\] " subjects
384'
385
484cf6c3
TR
386check_threading () {
387 expect="$1" &&
388 shift &&
dd2b6b68 389 git format-patch --stdout "$@" >patch &&
484cf6c3
TR
390 # Prints everything between the Message-ID and In-Reply-To,
391 # and replaces all Message-ID-lookalikes by a sequence number
94221d22 392 perl -ne '
484cf6c3
TR
393 if (/^(message-id|references|in-reply-to)/i) {
394 $printing = 1;
395 } elsif (/^\S/) {
396 $printing = 0;
397 }
398 if ($printing) {
399 $h{$1}=$i++ if (/<([^>]+)>/ and !exists $h{$1});
400 for $k (keys %h) {s/$k/$h{$k}/};
401 print;
402 }
403 print "---\n" if /^From /i;
dd2b6b68 404 ' <patch >actual &&
484cf6c3
TR
405 test_cmp "$expect" actual
406}
407
92014b69 408cat >>expect.no-threading <<EOF
484cf6c3
TR
409---
410---
411---
412EOF
413
414test_expect_success 'no threading' '
7d812145 415 git checkout side &&
484cf6c3 416 check_threading expect.no-threading master
7d812145
DB
417'
418
92014b69 419cat >expect.thread <<EOF
484cf6c3
TR
420---
421Message-Id: <0>
422---
423Message-Id: <1>
424In-Reply-To: <0>
425References: <0>
426---
427Message-Id: <2>
428In-Reply-To: <0>
429References: <0>
430EOF
7d812145 431
484cf6c3
TR
432test_expect_success 'thread' '
433 check_threading expect.thread --thread master
7d812145
DB
434'
435
92014b69 436cat >expect.in-reply-to <<EOF
484cf6c3
TR
437---
438Message-Id: <0>
439In-Reply-To: <1>
440References: <1>
441---
442Message-Id: <2>
443In-Reply-To: <1>
444References: <1>
445---
446Message-Id: <3>
447In-Reply-To: <1>
448References: <1>
449EOF
a5a27c79 450
484cf6c3
TR
451test_expect_success 'thread in-reply-to' '
452 check_threading expect.in-reply-to --in-reply-to="<test.message>" \
453 --thread master
a5a27c79
DB
454'
455
92014b69 456cat >expect.cover-letter <<EOF
484cf6c3
TR
457---
458Message-Id: <0>
459---
460Message-Id: <1>
461In-Reply-To: <0>
462References: <0>
463---
464Message-Id: <2>
465In-Reply-To: <0>
466References: <0>
467---
468Message-Id: <3>
469In-Reply-To: <0>
470References: <0>
471EOF
a5a27c79 472
484cf6c3
TR
473test_expect_success 'thread cover-letter' '
474 check_threading expect.cover-letter --cover-letter --thread master
475'
476
92014b69 477cat >expect.cl-irt <<EOF
484cf6c3
TR
478---
479Message-Id: <0>
480In-Reply-To: <1>
481References: <1>
482---
483Message-Id: <2>
2175c10d 484In-Reply-To: <0>
484cf6c3 485References: <1>
2175c10d 486 <0>
484cf6c3
TR
487---
488Message-Id: <3>
2175c10d 489In-Reply-To: <0>
484cf6c3 490References: <1>
2175c10d 491 <0>
484cf6c3
TR
492---
493Message-Id: <4>
2175c10d 494In-Reply-To: <0>
484cf6c3 495References: <1>
2175c10d 496 <0>
484cf6c3
TR
497EOF
498
499test_expect_success 'thread cover-letter in-reply-to' '
500 check_threading expect.cl-irt --cover-letter \
501 --in-reply-to="<test.message>" --thread master
a5a27c79
DB
502'
503
30984ed2
TR
504test_expect_success 'thread explicit shallow' '
505 check_threading expect.cl-irt --cover-letter \
506 --in-reply-to="<test.message>" --thread=shallow master
507'
508
92014b69 509cat >expect.deep <<EOF
30984ed2
TR
510---
511Message-Id: <0>
512---
513Message-Id: <1>
514In-Reply-To: <0>
515References: <0>
516---
517Message-Id: <2>
518In-Reply-To: <1>
519References: <0>
520 <1>
521EOF
522
523test_expect_success 'thread deep' '
524 check_threading expect.deep --thread=deep master
525'
526
92014b69 527cat >expect.deep-irt <<EOF
30984ed2
TR
528---
529Message-Id: <0>
530In-Reply-To: <1>
531References: <1>
532---
533Message-Id: <2>
534In-Reply-To: <0>
535References: <1>
536 <0>
537---
538Message-Id: <3>
539In-Reply-To: <2>
540References: <1>
541 <0>
542 <2>
543EOF
544
545test_expect_success 'thread deep in-reply-to' '
546 check_threading expect.deep-irt --thread=deep \
547 --in-reply-to="<test.message>" master
548'
549
92014b69 550cat >expect.deep-cl <<EOF
30984ed2
TR
551---
552Message-Id: <0>
553---
554Message-Id: <1>
555In-Reply-To: <0>
556References: <0>
557---
558Message-Id: <2>
559In-Reply-To: <1>
560References: <0>
561 <1>
562---
563Message-Id: <3>
564In-Reply-To: <2>
565References: <0>
566 <1>
567 <2>
568EOF
569
570test_expect_success 'thread deep cover-letter' '
571 check_threading expect.deep-cl --cover-letter --thread=deep master
572'
573
92014b69 574cat >expect.deep-cl-irt <<EOF
30984ed2
TR
575---
576Message-Id: <0>
577In-Reply-To: <1>
578References: <1>
579---
580Message-Id: <2>
581In-Reply-To: <0>
582References: <1>
583 <0>
584---
585Message-Id: <3>
586In-Reply-To: <2>
587References: <1>
588 <0>
589 <2>
590---
591Message-Id: <4>
592In-Reply-To: <3>
593References: <1>
594 <0>
595 <2>
596 <3>
597EOF
598
599test_expect_success 'thread deep cover-letter in-reply-to' '
600 check_threading expect.deep-cl-irt --cover-letter \
601 --in-reply-to="<test.message>" --thread=deep master
602'
603
604test_expect_success 'thread via config' '
e8107155 605 test_config format.thread true &&
30984ed2
TR
606 check_threading expect.thread master
607'
608
609test_expect_success 'thread deep via config' '
e8107155 610 test_config format.thread deep &&
30984ed2
TR
611 check_threading expect.deep master
612'
613
614test_expect_success 'thread config + override' '
e8107155 615 test_config format.thread deep &&
30984ed2
TR
616 check_threading expect.thread --thread master
617'
618
619test_expect_success 'thread config + --no-thread' '
e8107155 620 test_config format.thread deep &&
30984ed2
TR
621 check_threading expect.no-threading --no-thread master
622'
623
7d812145 624test_expect_success 'excessive subject' '
7d812145
DB
625 rm -rf patches/ &&
626 git checkout side &&
bdee9cd6 627 before=$(git hash-object file) &&
628 before=$(git rev-parse --short $before) &&
7d812145 629 for i in 5 6 1 2 3 A 4 B C 7 8 9 10 D E F; do echo "$i"; done >>file &&
bdee9cd6 630 after=$(git hash-object file) &&
631 after=$(git rev-parse --short $after) &&
7d812145
DB
632 git update-index file &&
633 git commit -m "This is an excessively long subject line for a message due to the habit some projects have of not having a short, one-line subject at the start of the commit message, but rather sticking a whole paragraph right at the start as the only thing in the commit message. It had better not become the filename for the patch." &&
634 git format-patch -o patches/ master..side &&
635 ls patches/0004-This-is-an-excessively-long-subject-line-for-a-messa.patch
636'
637
2fe95f49
JH
638test_expect_success 'failure to write cover-letter aborts gracefully' '
639 test_when_finished "rmdir 0000-cover-letter.patch" &&
640 mkdir 0000-cover-letter.patch &&
641 test_must_fail git format-patch --no-renames --cover-letter -1
642'
643
5d02294c 644test_expect_success 'cover-letter inherits diff options' '
5d02294c
JS
645 git mv file foo &&
646 git commit -m foo &&
5404c116 647 git format-patch --no-renames --cover-letter -1 &&
cc663d14 648 check_patch 0000-cover-letter.patch &&
9524cf29 649 ! grep "file => foo .* 0 *\$" 0000-cover-letter.patch &&
5d02294c 650 git format-patch --cover-letter -1 -M &&
9524cf29 651 grep "file => foo .* 0 *\$" 0000-cover-letter.patch
5d02294c 652'
859c4fbe 653
92014b69 654cat >expect <<EOF
859c4fbe
JS
655 This is an excessively long subject line for a message due to the
656 habit some projects have of not having a short, one-line subject at
657 the start of the commit message, but rather sticking a whole
658 paragraph right at the start as the only thing in the commit
659 message. It had better not become the filename for the patch.
660 foo
661
662EOF
663
664test_expect_success 'shortlog of cover-letter wraps overly-long onelines' '
859c4fbe 665 git format-patch --cover-letter -2 &&
c6ec6dad 666 sed -e "1,/A U Thor/d" -e "/^\$/q" 0000-cover-letter.patch >output &&
3af82863 667 test_cmp expect output
859c4fbe
JS
668'
669
92014b69 670cat >expect <<EOF
bdee9cd6 671index $before..$after 100644
68daa64d
JK
672--- a/file
673+++ b/file
674@@ -13,4 +13,20 @@ C
675 10
676 D
677 E
678 F
679+5
680EOF
681
682test_expect_success 'format-patch respects -U' '
68daa64d 683 git format-patch -U4 -2 &&
6dd88832
JN
684 sed -e "1,/^diff/d" -e "/^+5/q" \
685 <0001-This-is-an-excessively-long-subject-line-for-a-messa.patch \
686 >output &&
68daa64d 687 test_cmp expect output
68daa64d
JK
688'
689
92014b69 690cat >expect <<EOF
1d46f2ea
JK
691
692diff --git a/file b/file
bdee9cd6 693index $before..$after 100644
1d46f2ea
JK
694--- a/file
695+++ b/file
696@@ -14,3 +14,19 @@ C
697 D
698 E
699 F
700+5
701EOF
702
703test_expect_success 'format-patch -p suppresses stat' '
1d46f2ea 704 git format-patch -p -2 &&
c6ec6dad 705 sed -e "1,/^\$/d" -e "/^+5/q" 0001-This-is-an-excessively-long-subject-line-for-a-messa.patch >output &&
1d46f2ea 706 test_cmp expect output
1d46f2ea
JK
707'
708
9800a754
JH
709test_expect_success 'format-patch from a subdirectory (1)' '
710 filename=$(
711 rm -rf sub &&
712 mkdir -p sub/dir &&
713 cd sub/dir &&
714 git format-patch -1
715 ) &&
716 case "$filename" in
717 0*)
718 ;; # ok
719 *)
720 echo "Oops? $filename"
721 false
722 ;;
723 esac &&
724 test -f "$filename"
725'
726
727test_expect_success 'format-patch from a subdirectory (2)' '
728 filename=$(
729 rm -rf sub &&
730 mkdir -p sub/dir &&
731 cd sub/dir &&
732 git format-patch -1 -o ..
733 ) &&
734 case "$filename" in
735 ../0*)
736 ;; # ok
737 *)
738 echo "Oops? $filename"
739 false
740 ;;
741 esac &&
742 basename=$(expr "$filename" : ".*/\(.*\)") &&
743 test -f "sub/$basename"
744'
745
746test_expect_success 'format-patch from a subdirectory (3)' '
9800a754
JH
747 rm -f 0* &&
748 filename=$(
749 rm -rf sub &&
750 mkdir -p sub/dir &&
751 cd sub/dir &&
91c8b825 752 git format-patch -1 -o "$TRASH_DIRECTORY"
9800a754
JH
753 ) &&
754 basename=$(expr "$filename" : ".*/\(.*\)") &&
755 test -f "$basename"
756'
757
f044fe2d 758test_expect_success 'format-patch --in-reply-to' '
92014b69 759 git format-patch -1 --stdout --in-reply-to "baz@foo.bar" >patch8 &&
f044fe2d
SB
760 grep "^In-Reply-To: <baz@foo.bar>" patch8 &&
761 grep "^References: <baz@foo.bar>" patch8
762'
763
764test_expect_success 'format-patch --signoff' '
212620fe
JH
765 git format-patch -1 --signoff --stdout >out &&
766 grep "^Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>" out
767'
768
769test_expect_success 'format-patch --notes --signoff' '
770 git notes --ref test add -m "test message" HEAD &&
771 git format-patch -1 --signoff --stdout --notes=test >out &&
bd1470b8 772 # Three dashes must come after S-o-b
212620fe 773 ! sed "/^Signed-off-by: /q" out | grep "test message" &&
bd1470b8
JH
774 sed "1,/^Signed-off-by: /d" out | grep "test message" &&
775 # Notes message must come after three dashes
776 ! sed "/^---$/q" out | grep "test message" &&
777 sed "1,/^---$/d" out | grep "test message"
f044fe2d
SB
778'
779
13cdf780
DL
780test_expect_success 'format-patch notes output control' '
781 git notes add -m "notes config message" HEAD &&
782 test_when_finished git notes remove HEAD &&
783
784 git format-patch -1 --stdout >out &&
785 ! grep "notes config message" out &&
786 git format-patch -1 --stdout --notes >out &&
787 grep "notes config message" out &&
788 git format-patch -1 --stdout --no-notes >out &&
789 ! grep "notes config message" out &&
790 git format-patch -1 --stdout --notes --no-notes >out &&
791 ! grep "notes config message" out &&
792 git format-patch -1 --stdout --no-notes --notes >out &&
793 grep "notes config message" out &&
794
795 test_config format.notes true &&
796 git format-patch -1 --stdout >out &&
797 grep "notes config message" out &&
798 git format-patch -1 --stdout --notes >out &&
799 grep "notes config message" out &&
800 git format-patch -1 --stdout --no-notes >out &&
801 ! grep "notes config message" out &&
802 git format-patch -1 --stdout --notes --no-notes >out &&
803 ! grep "notes config message" out &&
804 git format-patch -1 --stdout --no-notes --notes >out &&
805 grep "notes config message" out
806'
807
808test_expect_success 'format-patch with multiple notes refs' '
809 git notes --ref note1 add -m "this is note 1" HEAD &&
810 test_when_finished git notes --ref note1 remove HEAD &&
811 git notes --ref note2 add -m "this is note 2" HEAD &&
812 test_when_finished git notes --ref note2 remove HEAD &&
813
814 git format-patch -1 --stdout >out &&
815 ! grep "this is note 1" out &&
816 ! grep "this is note 2" out &&
817 git format-patch -1 --stdout --notes=note1 >out &&
818 grep "this is note 1" out &&
819 ! grep "this is note 2" out &&
820 git format-patch -1 --stdout --notes=note2 >out &&
821 ! grep "this is note 1" out &&
822 grep "this is note 2" out &&
823 git format-patch -1 --stdout --notes=note1 --notes=note2 >out &&
824 grep "this is note 1" out &&
825 grep "this is note 2" out &&
826
827 test_config format.notes note1 &&
828 git format-patch -1 --stdout >out &&
829 grep "this is note 1" out &&
830 ! grep "this is note 2" out &&
831 git format-patch -1 --stdout --no-notes >out &&
832 ! grep "this is note 1" out &&
833 ! grep "this is note 2" out &&
834 git format-patch -1 --stdout --notes=note2 >out &&
835 grep "this is note 1" out &&
836 grep "this is note 2" out &&
837 git format-patch -1 --stdout --no-notes --notes=note2 >out &&
838 ! grep "this is note 1" out &&
839 grep "this is note 2" out &&
840
841 git config --add format.notes note2 &&
842 git format-patch -1 --stdout >out &&
843 grep "this is note 1" out &&
844 grep "this is note 2" out &&
845 git format-patch -1 --stdout --no-notes >out &&
846 ! grep "this is note 1" out &&
847 ! grep "this is note 2" out
848'
849
8164c961
DL
850test_expect_success 'format-patch with multiple notes refs in config' '
851 test_when_finished "test_unconfig format.notes" &&
852
853 git notes --ref note1 add -m "this is note 1" HEAD &&
854 test_when_finished git notes --ref note1 remove HEAD &&
855 git notes --ref note2 add -m "this is note 2" HEAD &&
856 test_when_finished git notes --ref note2 remove HEAD &&
857
858 git config format.notes note1 &&
859 git format-patch -1 --stdout >out &&
860 grep "this is note 1" out &&
861 ! grep "this is note 2" out &&
862 git config format.notes note2 &&
863 git format-patch -1 --stdout >out &&
864 ! grep "this is note 1" out &&
865 grep "this is note 2" out &&
866 git config --add format.notes note1 &&
867 git format-patch -1 --stdout >out &&
868 grep "this is note 1" out &&
869 grep "this is note 2" out &&
870
871 git config --replace-all format.notes note1 &&
872 git config --add format.notes false &&
873 git format-patch -1 --stdout >out &&
874 ! grep "this is note 1" out &&
875 ! grep "this is note 2" out &&
876 git config --add format.notes note2 &&
877 git format-patch -1 --stdout >out &&
878 ! grep "this is note 1" out &&
879 grep "this is note 2" out
880'
881
92014b69
DL
882echo "fatal: --name-only does not make sense" >expect.name-only
883echo "fatal: --name-status does not make sense" >expect.name-status
884echo "fatal: --check does not make sense" >expect.check
02bc5b03 885
68b2a005 886test_expect_success 'options no longer allowed for format-patch' '
92014b69 887 test_must_fail git format-patch --name-only 2>output &&
68b2a005 888 test_i18ncmp expect.name-only output &&
92014b69 889 test_must_fail git format-patch --name-status 2>output &&
68b2a005 890 test_i18ncmp expect.name-status output &&
92014b69 891 test_must_fail git format-patch --check 2>output &&
cb46c406
DL
892 test_i18ncmp expect.check output
893'
02bc5b03
BG
894
895test_expect_success 'format-patch --numstat should produce a patch' '
92014b69 896 git format-patch --numstat --stdout master..side >output &&
6bd26f58
DL
897 grep "^diff --git a/" output >diff &&
898 test_line_count = 5 diff
cb46c406 899'
02bc5b03 900
7e93d3b9
FC
901test_expect_success 'format-patch -- <path>' '
902 git format-patch master..side -- file 2>error &&
903 ! grep "Use .--" error
904'
905
657ab61e
KB
906test_expect_success 'format-patch --ignore-if-in-upstream HEAD' '
907 git format-patch --ignore-if-in-upstream HEAD
908'
909
854b5cb4
DL
910test_expect_success 'get git version' '
911 git_version=$(git --version) &&
912 git_version=${git_version##* }
913'
480871e0
JT
914
915signature() {
916 printf "%s\n%s\n\n" "-- " "${1:-$git_version}"
917}
918
919test_expect_success 'format-patch default signature' '
854b5cb4
DL
920 git format-patch --stdout -1 >patch &&
921 tail -n 3 patch >output &&
480871e0
JT
922 signature >expect &&
923 test_cmp expect output
924'
925
6622d9c7 926test_expect_success 'format-patch --signature' '
854b5cb4
DL
927 git format-patch --stdout --signature="my sig" -1 >patch &&
928 tail -n 3 patch >output &&
480871e0
JT
929 signature "my sig" >expect &&
930 test_cmp expect output
6622d9c7
SB
931'
932
933test_expect_success 'format-patch with format.signature config' '
934 git config format.signature "config sig" &&
935 git format-patch --stdout -1 >output &&
936 grep "config sig" output
937'
938
939test_expect_success 'format-patch --signature overrides format.signature' '
940 git config format.signature "config sig" &&
941 git format-patch --stdout --signature="overrides" -1 >output &&
942 ! grep "config sig" output &&
943 grep "overrides" output
944'
945
946test_expect_success 'format-patch --no-signature ignores format.signature' '
947 git config format.signature "config sig" &&
948 git format-patch --stdout --signature="my sig" --no-signature \
949 -1 >output &&
cc663d14 950 check_patch output &&
6622d9c7
SB
951 ! grep "config sig" output &&
952 ! grep "my sig" output &&
953 ! grep "^-- \$" output
954'
955
956test_expect_success 'format-patch --signature --cover-letter' '
957 git config --unset-all format.signature &&
958 git format-patch --stdout --signature="my sig" --cover-letter \
959 -1 >output &&
6bd26f58
DL
960 grep "my sig" output >sig &&
961 test_line_count = 2 sig
6622d9c7
SB
962'
963
41ccfdd9 964test_expect_success 'format.signature="" suppresses signatures' '
6622d9c7
SB
965 git config format.signature "" &&
966 git format-patch --stdout -1 >output &&
cc663d14 967 check_patch output &&
6622d9c7
SB
968 ! grep "^-- \$" output
969'
970
41ccfdd9 971test_expect_success 'format-patch --no-signature suppresses signatures' '
6622d9c7
SB
972 git config --unset-all format.signature &&
973 git format-patch --stdout --no-signature -1 >output &&
cc663d14 974 check_patch output &&
6622d9c7
SB
975 ! grep "^-- \$" output
976'
977
41ccfdd9 978test_expect_success 'format-patch --signature="" suppresses signatures' '
2fdb5c62 979 git format-patch --stdout --signature="" -1 >output &&
cc663d14 980 check_patch output &&
6622d9c7
SB
981 ! grep "^-- \$" output
982'
983
7022650f
JM
984test_expect_success 'prepare mail-signature input' '
985 cat >mail-signature <<-\EOF
986
987 Test User <test.email@kernel.org>
988 http://git.kernel.org/cgit/git/git.git
989
990 git.kernel.org/?p=git/git.git;a=summary
991
992 EOF
993'
994
995test_expect_success '--signature-file=file works' '
996 git format-patch --stdout --signature-file=mail-signature -1 >output &&
997 check_patch output &&
c6ec6dad 998 sed -e "1,/^-- \$/d" output >actual &&
7022650f
JM
999 {
1000 cat mail-signature && echo
1001 } >expect &&
1002 test_cmp expect actual
1003'
1004
1005test_expect_success 'format.signaturefile works' '
1006 test_config format.signaturefile mail-signature &&
1007 git format-patch --stdout -1 >output &&
1008 check_patch output &&
c6ec6dad 1009 sed -e "1,/^-- \$/d" output >actual &&
7022650f
JM
1010 {
1011 cat mail-signature && echo
1012 } >expect &&
1013 test_cmp expect actual
1014'
1015
1016test_expect_success '--no-signature suppresses format.signaturefile ' '
1017 test_config format.signaturefile mail-signature &&
1018 git format-patch --stdout --no-signature -1 >output &&
1019 check_patch output &&
1020 ! grep "^-- \$" output
1021'
1022
1023test_expect_success '--signature-file overrides format.signaturefile' '
99094a7a 1024 cat >other-mail-signature <<-\EOF &&
7022650f
JM
1025 Use this other signature instead of mail-signature.
1026 EOF
1027 test_config format.signaturefile mail-signature &&
1028 git format-patch --stdout \
1029 --signature-file=other-mail-signature -1 >output &&
1030 check_patch output &&
c6ec6dad 1031 sed -e "1,/^-- \$/d" output >actual &&
7022650f
JM
1032 {
1033 cat other-mail-signature && echo
1034 } >expect &&
1035 test_cmp expect actual
1036'
1037
1038test_expect_success '--signature overrides format.signaturefile' '
1039 test_config format.signaturefile mail-signature &&
1040 git format-patch --stdout --signature="my sig" -1 >output &&
1041 check_patch output &&
1042 grep "my sig" output
1043'
1044
38a94bb6
TRC
1045test_expect_success TTY 'format-patch --stdout paginates' '
1046 rm -f pager_used &&
512477b1 1047 test_terminal env GIT_PAGER="wc >pager_used" git format-patch --stdout --all &&
38a94bb6
TRC
1048 test_path_is_file pager_used
1049'
1050
1051 test_expect_success TTY 'format-patch --stdout pagination can be disabled' '
1052 rm -f pager_used &&
512477b1
DT
1053 test_terminal env GIT_PAGER="wc >pager_used" git --no-pager format-patch --stdout --all &&
1054 test_terminal env GIT_PAGER="wc >pager_used" git -c "pager.format-patch=false" format-patch --stdout --all &&
38a94bb6
TRC
1055 test_path_is_missing pager_used &&
1056 test_path_is_missing .git/pager_used
1057'
1058
a1f6baa5
JK
1059test_expect_success 'format-patch handles multi-line subjects' '
1060 rm -rf patches/ &&
1061 echo content >>file &&
1062 for i in one two three; do echo $i; done >msg &&
1063 git add file &&
1064 git commit -F msg &&
1065 git format-patch -o patches -1 &&
1066 grep ^Subject: patches/0001-one.patch >actual &&
1067 echo "Subject: [PATCH] one two three" >expect &&
1068 test_cmp expect actual
1069'
1070
1071test_expect_success 'format-patch handles multi-line encoded subjects' '
1072 rm -rf patches/ &&
1073 echo content >>file &&
1074 for i in en två tre; do echo $i; done >msg &&
1075 git add file &&
1076 git commit -F msg &&
1077 git format-patch -o patches -1 &&
1078 grep ^Subject: patches/0001-en.patch >actual &&
1079 echo "Subject: [PATCH] =?UTF-8?q?en=20tv=C3=A5=20tre?=" >expect &&
1080 test_cmp expect actual
1081'
1082
1083M8="foo bar "
1084M64=$M8$M8$M8$M8$M8$M8$M8$M8
1085M512=$M64$M64$M64$M64$M64$M64$M64$M64
1086cat >expect <<'EOF'
1087Subject: [PATCH] foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo
7a76e68a
JS
1088 bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar
1089 foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo
1090 bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar
1091 foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo
1092 bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar
1093 foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar
a1f6baa5 1094EOF
7a76e68a 1095test_expect_success 'format-patch wraps extremely long subject (ascii)' '
a1f6baa5
JK
1096 echo content >>file &&
1097 git add file &&
1098 git commit -m "$M512" &&
1099 git format-patch --stdout -1 >patch &&
c6ec6dad 1100 sed -n "/^Subject/p; /^ /p; /^$/q" patch >subject &&
a1f6baa5
JK
1101 test_cmp expect subject
1102'
1103
1104M8="föö bar "
1105M64=$M8$M8$M8$M8$M8$M8$M8$M8
1106M512=$M64$M64$M64$M64$M64$M64$M64$M64
1107cat >expect <<'EOF'
94f6cdf6
JS
1108Subject: [PATCH] =?UTF-8?q?f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f?=
1109 =?UTF-8?q?=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar?=
1110 =?UTF-8?q?=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20?=
1111 =?UTF-8?q?bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6?=
6cd3c053
KS
1112 =?UTF-8?q?=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6?=
1113 =?UTF-8?q?=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f?=
94f6cdf6
JS
1114 =?UTF-8?q?=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar?=
1115 =?UTF-8?q?=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20?=
1116 =?UTF-8?q?bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6?=
6cd3c053
KS
1117 =?UTF-8?q?=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6?=
1118 =?UTF-8?q?=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f?=
94f6cdf6
JS
1119 =?UTF-8?q?=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar?=
1120 =?UTF-8?q?=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20?=
1121 =?UTF-8?q?bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6?=
6cd3c053
KS
1122 =?UTF-8?q?=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6?=
1123 =?UTF-8?q?=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f?=
1124 =?UTF-8?q?=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar?=
1125 =?UTF-8?q?=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20?=
1126 =?UTF-8?q?bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6?=
1127 =?UTF-8?q?=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6?=
1128 =?UTF-8?q?=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f?=
1129 =?UTF-8?q?=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar?=
1130 =?UTF-8?q?=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20?=
1131 =?UTF-8?q?bar?=
a1f6baa5 1132EOF
94f6cdf6 1133test_expect_success 'format-patch wraps extremely long subject (rfc2047)' '
a1f6baa5
JK
1134 rm -rf patches/ &&
1135 echo content >>file &&
1136 git add file &&
1137 git commit -m "$M512" &&
1138 git format-patch --stdout -1 >patch &&
c6ec6dad 1139 sed -n "/^Subject/p; /^ /p; /^$/q" patch >subject &&
a1f6baa5
JK
1140 test_cmp expect subject
1141'
1142
4d03c18a
JK
1143check_author() {
1144 echo content >>file &&
1145 git add file &&
1146 GIT_AUTHOR_NAME=$1 git commit -m author-check &&
1147 git format-patch --stdout -1 >patch &&
c6ec6dad 1148 sed -n "/^From: /p; /^ /p; /^$/q" patch >actual &&
4d03c18a
JK
1149 test_cmp expect actual
1150}
1151
1152cat >expect <<'EOF'
1153From: "Foo B. Bar" <author@example.com>
1154EOF
0fcec2ce 1155test_expect_success 'format-patch quotes dot in from-headers' '
4d03c18a
JK
1156 check_author "Foo B. Bar"
1157'
1158
1159cat >expect <<'EOF'
1160From: "Foo \"The Baz\" Bar" <author@example.com>
1161EOF
0fcec2ce 1162test_expect_success 'format-patch quotes double-quote in from-headers' '
4d03c18a
JK
1163 check_author "Foo \"The Baz\" Bar"
1164'
1165
1166cat >expect <<'EOF'
0fcec2ce 1167From: =?UTF-8?q?F=C3=B6o=20Bar?= <author@example.com>
4d03c18a 1168EOF
0fcec2ce
JS
1169test_expect_success 'format-patch uses rfc2047-encoded from-headers when necessary' '
1170 check_author "Föo Bar"
1171'
1172
1173cat >expect <<'EOF'
1174From: =?UTF-8?q?F=C3=B6o=20B=2E=20Bar?= <author@example.com>
1175EOF
41dd00ba 1176test_expect_success 'rfc2047-encoded from-headers leave no rfc822 specials' '
4d03c18a
JK
1177 check_author "Föo B. Bar"
1178'
1179
7a76e68a
JS
1180cat >expect <<EOF
1181From: foo_bar_foo_bar_foo_bar_foo_bar_foo_bar_foo_bar_foo_bar_foo_bar_
1182 <author@example.com>
1183EOF
1184test_expect_success 'format-patch wraps moderately long from-header (ascii)' '
1185 check_author "foo_bar_foo_bar_foo_bar_foo_bar_foo_bar_foo_bar_foo_bar_foo_bar_"
1186'
1187
1188cat >expect <<'EOF'
1189From: Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar
1190 Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo
1191 Bar Foo Bar Foo Bar Foo Bar <author@example.com>
1192EOF
1193test_expect_success 'format-patch wraps extremely long from-header (ascii)' '
1194 check_author "Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar"
1195'
1196
1197cat >expect <<'EOF'
1198From: "Foo.Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar
1199 Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo
1200 Bar Foo Bar Foo Bar Foo Bar" <author@example.com>
1201EOF
1202test_expect_success 'format-patch wraps extremely long from-header (rfc822)' '
1203 check_author "Foo.Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar"
1204'
1205
4d03c18a 1206cat >expect <<'EOF'
94f6cdf6
JS
1207From: =?UTF-8?q?Fo=C3=B6=20Bar=20Foo=20Bar=20Foo=20Bar=20Foo=20Bar=20Foo?=
1208 =?UTF-8?q?=20Bar=20Foo=20Bar=20Foo=20Bar=20Foo=20Bar=20Foo=20Bar=20Foo=20?=
1209 =?UTF-8?q?Bar=20Foo=20Bar=20Foo=20Bar=20Foo=20Bar=20Foo=20Bar=20Foo=20Bar?=
1210 =?UTF-8?q?=20Foo=20Bar=20Foo=20Bar=20Foo=20Bar=20Foo=20Bar=20Foo=20Bar=20?=
1211 =?UTF-8?q?Foo=20Bar=20Foo=20Bar?= <author@example.com>
1212EOF
1213test_expect_success 'format-patch wraps extremely long from-header (rfc2047)' '
1214 check_author "Foö Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar"
1215'
1216
19d097e3
EB
1217cat >expect <<'EOF'
1218From: Foö Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar
1219 Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo
1220 Bar Foo Bar Foo Bar Foo Bar <author@example.com>
1221EOF
1222test_expect_success 'format-patch wraps extremely long from-header (non-ASCII without Q-encoding)' '
1223 echo content >>file &&
1224 git add file &&
1225 GIT_AUTHOR_NAME="Foö Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar" \
1226 git commit -m author-check &&
1227 git format-patch --no-encode-email-headers --stdout -1 >patch &&
1228 sed -n "/^From: /p; /^ /p; /^$/q" patch >actual &&
1229 test_cmp expect actual
1230'
1231
1232cat >expect <<'EOF'
1233Subject: [PATCH] Foö
1234EOF
1235test_expect_success 'subject lines are unencoded with --no-encode-email-headers' '
1236 echo content >>file &&
1237 git add file &&
1238 git commit -m "Foö" &&
1239 git format-patch --no-encode-email-headers -1 --stdout >patch &&
1240 grep ^Subject: patch >actual &&
1241 test_cmp expect actual
1242'
1243
1244cat >expect <<'EOF'
1245Subject: [PATCH] Foö
1246EOF
1247test_expect_success 'subject lines are unencoded with format.encodeEmailHeaders=false' '
1248 echo content >>file &&
1249 git add file &&
1250 git commit -m "Foö" &&
1251 git config format.encodeEmailHeaders false &&
1252 git format-patch -1 --stdout >patch &&
1253 grep ^Subject: patch >actual &&
1254 test_cmp expect actual
1255'
1256
1257cat >expect <<'EOF'
1258Subject: [PATCH] =?UTF-8?q?Fo=C3=B6?=
1259EOF
1260test_expect_success '--encode-email-headers overrides format.encodeEmailHeaders' '
1261 echo content >>file &&
1262 git add file &&
1263 git commit -m "Foö" &&
1264 git config format.encodeEmailHeaders false &&
1265 git format-patch --encode-email-headers -1 --stdout >patch &&
1266 grep ^Subject: patch >actual &&
1267 test_cmp expect actual
1268'
1269
94f6cdf6 1270cat >expect <<'EOF'
4d03c18a
JK
1271Subject: header with . in it
1272EOF
1273test_expect_success 'subject lines do not have 822 atom-quoting' '
1274 echo content >>file &&
1275 git add file &&
1276 git commit -m "header with . in it" &&
1277 git format-patch -k -1 --stdout >patch &&
1278 grep ^Subject: patch >actual &&
1279 test_cmp expect actual
1280'
1281
e7af8e49
JK
1282cat >expect <<'EOF'
1283Subject: [PREFIX 1/1] header with . in it
1284EOF
1285test_expect_success 'subject prefixes have space prepended' '
1286 git format-patch -n -1 --stdout --subject-prefix=PREFIX >patch &&
1287 grep ^Subject: patch >actual &&
1288 test_cmp expect actual
1289'
1290
1291cat >expect <<'EOF'
1292Subject: [1/1] header with . in it
1293EOF
1294test_expect_success 'empty subject prefix does not have extra space' '
1295 git format-patch -n -1 --stdout --subject-prefix= >patch &&
1296 grep ^Subject: patch >actual &&
1297 test_cmp expect actual
1298'
1299
68e83a5b
JT
1300test_expect_success '--rfc' '
1301 cat >expect <<-\EOF &&
1302 Subject: [RFC PATCH 1/1] header with . in it
1303 EOF
1304 git format-patch -n -1 --stdout --rfc >patch &&
1305 grep ^Subject: patch >actual &&
1306 test_cmp expect actual
1307'
1308
a9080475
JK
1309test_expect_success '--from=ident notices bogus ident' '
1310 test_must_fail git format-patch -1 --stdout --from=foo >patch
1311'
1312
1313test_expect_success '--from=ident replaces author' '
1314 git format-patch -1 --stdout --from="Me <me@example.com>" >patch &&
1315 cat >expect <<-\EOF &&
1316 From: Me <me@example.com>
1317
1318 From: A U Thor <author@example.com>
1319
1320 EOF
c6ec6dad 1321 sed -ne "/^From:/p; /^$/p; /^---$/q" patch >patch.head &&
a9080475
JK
1322 test_cmp expect patch.head
1323'
1324
1325test_expect_success '--from uses committer ident' '
1326 git format-patch -1 --stdout --from >patch &&
1327 cat >expect <<-\EOF &&
1328 From: C O Mitter <committer@example.com>
1329
1330 From: A U Thor <author@example.com>
1331
1332 EOF
c6ec6dad 1333 sed -ne "/^From:/p; /^$/p; /^---$/q" patch >patch.head &&
a9080475
JK
1334 test_cmp expect patch.head
1335'
1336
662cc30c
JK
1337test_expect_success '--from omits redundant in-body header' '
1338 git format-patch -1 --stdout --from="A U Thor <author@example.com>" >patch &&
1339 cat >expect <<-\EOF &&
1340 From: A U Thor <author@example.com>
1341
1342 EOF
c6ec6dad 1343 sed -ne "/^From:/p; /^$/p; /^---$/q" patch >patch.head &&
662cc30c
JK
1344 test_cmp expect patch.head
1345'
1346
a9080475 1347test_expect_success 'in-body headers trigger content encoding' '
d2554c72 1348 test_env GIT_AUTHOR_NAME="éxötìc" test_commit exotic &&
a9080475
JK
1349 test_when_finished "git reset --hard HEAD^" &&
1350 git format-patch -1 --stdout --from >patch &&
1351 cat >expect <<-\EOF &&
1352 From: C O Mitter <committer@example.com>
1353 Content-Type: text/plain; charset=UTF-8
1354
1355 From: éxötìc <author@example.com>
1356
1357 EOF
c6ec6dad 1358 sed -ne "/^From:/p; /^$/p; /^Content-Type/p; /^---$/q" patch >patch.head &&
a9080475
JK
1359 test_cmp expect patch.head
1360'
1361
79133a66
NTND
1362append_signoff()
1363{
1364 C=$(git commit-tree HEAD^^{tree} -p HEAD) &&
1365 git format-patch --stdout --signoff $C^..$C >append_signoff.patch &&
1366 sed -n -e "1,/^---$/p" append_signoff.patch |
1367 egrep -n "^Subject|Sign|^$"
1368}
1369
1370test_expect_success 'signoff: commit with no body' '
1371 append_signoff </dev/null >actual &&
460609cb
DL
1372 cat <<-\EOF | sed "s/EOL$//" >expect &&
1373 4:Subject: [PATCH] EOL
1374 8:
1375 9:Signed-off-by: C O Mitter <committer@example.com>
1376 EOF
b562a54c 1377 test_cmp expect actual
79133a66
NTND
1378'
1379
1380test_expect_success 'signoff: commit with only subject' '
1381 echo subject | append_signoff >actual &&
460609cb
DL
1382 cat >expect <<-\EOF &&
1383 4:Subject: [PATCH] subject
1384 8:
1385 9:Signed-off-by: C O Mitter <committer@example.com>
1386 EOF
b562a54c 1387 test_cmp expect actual
79133a66
NTND
1388'
1389
1390test_expect_success 'signoff: commit with only subject that does not end with NL' '
1391 printf subject | append_signoff >actual &&
460609cb
DL
1392 cat >expect <<-\EOF &&
1393 4:Subject: [PATCH] subject
1394 8:
1395 9:Signed-off-by: C O Mitter <committer@example.com>
1396 EOF
b562a54c 1397 test_cmp expect actual
79133a66
NTND
1398'
1399
1400test_expect_success 'signoff: no existing signoffs' '
460609cb
DL
1401 append_signoff <<-\EOF >actual &&
1402 subject
79133a66 1403
460609cb
DL
1404 body
1405 EOF
1406 cat >expect <<-\EOF &&
1407 4:Subject: [PATCH] subject
1408 8:
1409 10:
1410 11:Signed-off-by: C O Mitter <committer@example.com>
1411 EOF
b562a54c 1412 test_cmp expect actual
79133a66
NTND
1413'
1414
1415test_expect_success 'signoff: no existing signoffs and no trailing NL' '
1416 printf "subject\n\nbody" | append_signoff >actual &&
460609cb
DL
1417 cat >expect <<-\EOF &&
1418 4:Subject: [PATCH] subject
1419 8:
1420 10:
1421 11:Signed-off-by: C O Mitter <committer@example.com>
1422 EOF
b562a54c 1423 test_cmp expect actual
79133a66
NTND
1424'
1425
1426test_expect_success 'signoff: some random signoff' '
460609cb
DL
1427 append_signoff <<-\EOF >actual &&
1428 subject
79133a66 1429
460609cb 1430 body
79133a66 1431
460609cb
DL
1432 Signed-off-by: my@house
1433 EOF
1434 cat >expect <<-\EOF &&
1435 4:Subject: [PATCH] subject
1436 8:
1437 10:
1438 11:Signed-off-by: my@house
1439 12:Signed-off-by: C O Mitter <committer@example.com>
1440 EOF
b562a54c 1441 test_cmp expect actual
79133a66
NTND
1442'
1443
959a2623 1444test_expect_success 'signoff: misc conforming footer elements' '
460609cb
DL
1445 append_signoff <<-\EOF >actual &&
1446 subject
959a2623 1447
460609cb 1448 body
959a2623 1449
460609cb
DL
1450 Signed-off-by: my@house
1451 (cherry picked from commit da39a3ee5e6b4b0d3255bfef95601890afd80709)
1452 Tested-by: Some One <someone@example.com>
1453 Bug: 1234
1454 EOF
1455 cat >expect <<-\EOF &&
1456 4:Subject: [PATCH] subject
1457 8:
1458 10:
1459 11:Signed-off-by: my@house
1460 15:Signed-off-by: C O Mitter <committer@example.com>
1461 EOF
b562a54c 1462 test_cmp expect actual
959a2623
BC
1463'
1464
1465test_expect_success 'signoff: some random signoff-alike' '
460609cb
DL
1466 append_signoff <<-\EOF >actual &&
1467 subject
79133a66 1468
460609cb
DL
1469 body
1470 Fooled-by-me: my@house
1471 EOF
1472 cat >expect <<-\EOF &&
1473 4:Subject: [PATCH] subject
1474 8:
1475 11:
1476 12:Signed-off-by: C O Mitter <committer@example.com>
1477 EOF
b562a54c 1478 test_cmp expect actual
79133a66
NTND
1479'
1480
959a2623 1481test_expect_success 'signoff: not really a signoff' '
460609cb
DL
1482 append_signoff <<-\EOF >actual &&
1483 subject
79133a66 1484
460609cb
DL
1485 I want to mention about Signed-off-by: here.
1486 EOF
1487 cat >expect <<-\EOF &&
1488 4:Subject: [PATCH] subject
1489 8:
1490 9:I want to mention about Signed-off-by: here.
1491 10:
1492 11:Signed-off-by: C O Mitter <committer@example.com>
1493 EOF
b562a54c 1494 test_cmp expect actual
79133a66
NTND
1495'
1496
959a2623 1497test_expect_success 'signoff: not really a signoff (2)' '
460609cb
DL
1498 append_signoff <<-\EOF >actual &&
1499 subject
79133a66 1500
460609cb
DL
1501 My unfortunate
1502 Signed-off-by: example happens to be wrapped here.
1503 EOF
1504 cat >expect <<-\EOF &&
1505 4:Subject: [PATCH] subject
1506 8:
1507 10:Signed-off-by: example happens to be wrapped here.
1508 11:Signed-off-by: C O Mitter <committer@example.com>
1509 EOF
b562a54c 1510 test_cmp expect actual
79133a66
NTND
1511'
1512
959a2623 1513test_expect_success 'signoff: valid S-o-b paragraph in the middle' '
460609cb
DL
1514 append_signoff <<-\EOF >actual &&
1515 subject
79133a66 1516
460609cb
DL
1517 Signed-off-by: my@house
1518 Signed-off-by: your@house
79133a66 1519
460609cb
DL
1520 A lot of houses.
1521 EOF
1522 cat >expect <<-\EOF &&
1523 4:Subject: [PATCH] subject
1524 8:
1525 9:Signed-off-by: my@house
1526 10:Signed-off-by: your@house
1527 11:
1528 13:
1529 14:Signed-off-by: C O Mitter <committer@example.com>
1530 EOF
b562a54c 1531 test_cmp expect actual
79133a66
NTND
1532'
1533
1534test_expect_success 'signoff: the same signoff at the end' '
460609cb
DL
1535 append_signoff <<-\EOF >actual &&
1536 subject
79133a66 1537
460609cb 1538 body
79133a66 1539
460609cb
DL
1540 Signed-off-by: C O Mitter <committer@example.com>
1541 EOF
1542 cat >expect <<-\EOF &&
1543 4:Subject: [PATCH] subject
1544 8:
1545 10:
1546 11:Signed-off-by: C O Mitter <committer@example.com>
1547 EOF
b562a54c 1548 test_cmp expect actual
79133a66
NTND
1549'
1550
1551test_expect_success 'signoff: the same signoff at the end, no trailing NL' '
1552 printf "subject\n\nSigned-off-by: C O Mitter <committer@example.com>" |
1553 append_signoff >actual &&
460609cb
DL
1554 cat >expect <<-\EOF &&
1555 4:Subject: [PATCH] subject
1556 8:
1557 9:Signed-off-by: C O Mitter <committer@example.com>
1558 EOF
b562a54c 1559 test_cmp expect actual
79133a66
NTND
1560'
1561
1562test_expect_success 'signoff: the same signoff NOT at the end' '
460609cb
DL
1563 append_signoff <<-\EOF >actual &&
1564 subject
79133a66 1565
460609cb 1566 body
79133a66 1567
460609cb
DL
1568 Signed-off-by: C O Mitter <committer@example.com>
1569 Signed-off-by: my@house
1570 EOF
1571 cat >expect <<-\EOF &&
1572 4:Subject: [PATCH] subject
1573 8:
1574 10:
1575 11:Signed-off-by: C O Mitter <committer@example.com>
1576 12:Signed-off-by: my@house
1577 EOF
b562a54c 1578 test_cmp expect actual
79133a66
NTND
1579'
1580
967dfd4d 1581test_expect_success 'signoff: tolerate garbage in conforming footer' '
460609cb
DL
1582 append_signoff <<-\EOF >actual &&
1583 subject
79133a66 1584
460609cb 1585 body
79133a66 1586
460609cb
DL
1587 Tested-by: my@house
1588 Some Trash
1589 Signed-off-by: C O Mitter <committer@example.com>
1590 EOF
1591 cat >expect <<-\EOF &&
1592 4:Subject: [PATCH] subject
1593 8:
1594 10:
1595 13:Signed-off-by: C O Mitter <committer@example.com>
1596 EOF
b562a54c 1597 test_cmp expect actual
967dfd4d
JT
1598'
1599
1600test_expect_success 'signoff: respect trailer config' '
460609cb
DL
1601 append_signoff <<-\EOF >actual &&
1602 subject
967dfd4d 1603
460609cb
DL
1604 Myfooter: x
1605 Some Trash
1606 EOF
1607 cat >expect <<-\EOF &&
1608 4:Subject: [PATCH] subject
1609 8:
1610 11:
1611 12:Signed-off-by: C O Mitter <committer@example.com>
1612 EOF
b562a54c 1613 test_cmp expect actual &&
967dfd4d
JT
1614
1615 test_config trailer.Myfooter.ifexists add &&
460609cb
DL
1616 append_signoff <<-\EOF >actual &&
1617 subject
967dfd4d 1618
460609cb
DL
1619 Myfooter: x
1620 Some Trash
1621 EOF
1622 cat >expect <<-\EOF &&
1623 4:Subject: [PATCH] subject
1624 8:
1625 11:Signed-off-by: C O Mitter <committer@example.com>
1626 EOF
b562a54c 1627 test_cmp expect actual
79133a66
NTND
1628'
1629
1630test_expect_success 'signoff: footer begins with non-signoff without @ sign' '
460609cb
DL
1631 append_signoff <<-\EOF >actual &&
1632 subject
79133a66 1633
460609cb 1634 body
79133a66 1635
460609cb
DL
1636 Reviewed-id: Noone
1637 Tested-by: my@house
1638 Change-id: Ideadbeef
1639 Signed-off-by: C O Mitter <committer@example.com>
1640 Bug: 1234
1641 EOF
1642 cat >expect <<-\EOF &&
1643 4:Subject: [PATCH] subject
1644 8:
1645 10:
1646 14:Signed-off-by: C O Mitter <committer@example.com>
1647 EOF
b562a54c 1648 test_cmp expect actual
79133a66
NTND
1649'
1650
787570c7
PYH
1651test_expect_success 'format patch ignores color.ui' '
1652 test_unconfig color.ui &&
1653 git format-patch --stdout -1 >expect &&
1654 test_config color.ui always &&
1655 git format-patch --stdout -1 >actual &&
1656 test_cmp expect actual
1657'
1658
c28ded83
LA
1659test_expect_success 'format patch respects diff.relative' '
1660 rm -rf subdir &&
1661 mkdir subdir &&
1662 echo other content >subdir/file2 &&
1663 git add subdir/file2 &&
1664 git commit -F msg &&
1665 test_unconfig diff.relative &&
1666 git format-patch --relative=subdir --stdout -1 >expect &&
1667 test_config diff.relative true &&
1668 git -C subdir format-patch --stdout -1 >actual &&
1669 test_cmp expect actual
1670'
1671
bf8e65b3
DL
1672test_expect_success 'cover letter with invalid --cover-from-description and config' '
1673 test_config branch.rebuild-1.description "config subject
1674
1675body" &&
1676 test_must_fail git format-patch --cover-letter --cover-from-description garbage master &&
1677 test_config format.coverFromDescription garbage &&
1678 test_must_fail git format-patch --cover-letter master
1679'
1680
1681test_expect_success 'cover letter with format.coverFromDescription = default' '
1682 test_config branch.rebuild-1.description "config subject
1683
1684body" &&
1685 test_config format.coverFromDescription default &&
1686 git checkout rebuild-1 &&
1687 git format-patch --stdout --cover-letter master >actual &&
1688 grep "^Subject: \[PATCH 0/2\] \*\*\* SUBJECT HERE \*\*\*$" actual &&
1689 ! grep "^\*\*\* BLURB HERE \*\*\*$" actual &&
1690 grep "^config subject$" actual &&
1691 grep "^body$" actual
1692'
1693
1694test_expect_success 'cover letter with --cover-from-description default' '
1695 test_config branch.rebuild-1.description "config subject
1696
1697body" &&
1698 git checkout rebuild-1 &&
1699 git format-patch --stdout --cover-letter --cover-from-description default master >actual &&
1700 grep "^Subject: \[PATCH 0/2\] \*\*\* SUBJECT HERE \*\*\*$" actual &&
1701 ! grep "^\*\*\* BLURB HERE \*\*\*$" actual &&
1702 grep "^config subject$" actual &&
1703 grep "^body$" actual
1704'
1705
1706test_expect_success 'cover letter with format.coverFromDescription = none' '
1707 test_config branch.rebuild-1.description "config subject
1708
1709body" &&
1710 test_config format.coverFromDescription none &&
1711 git checkout rebuild-1 &&
1712 git format-patch --stdout --cover-letter master >actual &&
1713 grep "^Subject: \[PATCH 0/2\] \*\*\* SUBJECT HERE \*\*\*$" actual &&
1714 grep "^\*\*\* BLURB HERE \*\*\*$" actual &&
1715 ! grep "^config subject$" actual &&
1716 ! grep "^body$" actual
1717'
1718
1719test_expect_success 'cover letter with --cover-from-description none' '
1720 test_config branch.rebuild-1.description "config subject
1721
1722body" &&
1723 git checkout rebuild-1 &&
1724 git format-patch --stdout --cover-letter --cover-from-description none master >actual &&
1725 grep "^Subject: \[PATCH 0/2\] \*\*\* SUBJECT HERE \*\*\*$" actual &&
1726 grep "^\*\*\* BLURB HERE \*\*\*$" actual &&
1727 ! grep "^config subject$" actual &&
1728 ! grep "^body$" actual
1729'
1730
1731test_expect_success 'cover letter with format.coverFromDescription = message' '
1732 test_config branch.rebuild-1.description "config subject
1733
1734body" &&
1735 test_config format.coverFromDescription message &&
1736 git checkout rebuild-1 &&
1737 git format-patch --stdout --cover-letter master >actual &&
1738 grep "^Subject: \[PATCH 0/2\] \*\*\* SUBJECT HERE \*\*\*$" actual &&
1739 ! grep "^\*\*\* BLURB HERE \*\*\*$" actual &&
1740 grep "^config subject$" actual &&
1741 grep "^body$" actual
1742'
1743
1744test_expect_success 'cover letter with --cover-from-description message' '
1745 test_config branch.rebuild-1.description "config subject
1746
1747body" &&
1748 git checkout rebuild-1 &&
1749 git format-patch --stdout --cover-letter --cover-from-description message master >actual &&
1750 grep "^Subject: \[PATCH 0/2\] \*\*\* SUBJECT HERE \*\*\*$" actual &&
1751 ! grep "^\*\*\* BLURB HERE \*\*\*$" actual &&
1752 grep "^config subject$" actual &&
1753 grep "^body$" actual
1754'
1755
1756test_expect_success 'cover letter with format.coverFromDescription = subject' '
1757 test_config branch.rebuild-1.description "config subject
1758
1759body" &&
1760 test_config format.coverFromDescription subject &&
1761 git checkout rebuild-1 &&
1762 git format-patch --stdout --cover-letter master >actual &&
1763 grep "^Subject: \[PATCH 0/2\] config subject$" actual &&
1764 ! grep "^\*\*\* BLURB HERE \*\*\*$" actual &&
1765 ! grep "^config subject$" actual &&
1766 grep "^body$" actual
1767'
1768
1769test_expect_success 'cover letter with --cover-from-description subject' '
1770 test_config branch.rebuild-1.description "config subject
1771
1772body" &&
1773 git checkout rebuild-1 &&
1774 git format-patch --stdout --cover-letter --cover-from-description subject master >actual &&
1775 grep "^Subject: \[PATCH 0/2\] config subject$" actual &&
1776 ! grep "^\*\*\* BLURB HERE \*\*\*$" actual &&
1777 ! grep "^config subject$" actual &&
1778 grep "^body$" actual
1779'
1780
1781test_expect_success 'cover letter with format.coverFromDescription = auto (short subject line)' '
1782 test_config branch.rebuild-1.description "config subject
1783
1784body" &&
1785 test_config format.coverFromDescription auto &&
1786 git checkout rebuild-1 &&
1787 git format-patch --stdout --cover-letter master >actual &&
1788 grep "^Subject: \[PATCH 0/2\] config subject$" actual &&
1789 ! grep "^\*\*\* BLURB HERE \*\*\*$" actual &&
1790 ! grep "^config subject$" actual &&
1791 grep "^body$" actual
1792'
1793
1794test_expect_success 'cover letter with --cover-from-description auto (short subject line)' '
1795 test_config branch.rebuild-1.description "config subject
1796
1797body" &&
1798 git checkout rebuild-1 &&
1799 git format-patch --stdout --cover-letter --cover-from-description auto master >actual &&
1800 grep "^Subject: \[PATCH 0/2\] config subject$" actual &&
1801 ! grep "^\*\*\* BLURB HERE \*\*\*$" actual &&
1802 ! grep "^config subject$" actual &&
1803 grep "^body$" actual
1804'
1805
1806test_expect_success 'cover letter with format.coverFromDescription = auto (long subject line)' '
1807 test_config branch.rebuild-1.description "this is a really long first line and it is over 100 characters long which is the threshold for long subjects
1808
1809body" &&
1810 test_config format.coverFromDescription auto &&
1811 git checkout rebuild-1 &&
1812 git format-patch --stdout --cover-letter master >actual &&
1813 grep "^Subject: \[PATCH 0/2\] \*\*\* SUBJECT HERE \*\*\*$" actual &&
1814 ! grep "^\*\*\* BLURB HERE \*\*\*$" actual &&
1815 grep "^this is a really long first line and it is over 100 characters long which is the threshold for long subjects$" actual &&
1816 grep "^body$" actual
1817'
1818
1819test_expect_success 'cover letter with --cover-from-description auto (long subject line)' '
1820 test_config branch.rebuild-1.description "this is a really long first line and it is over 100 characters long which is the threshold for long subjects
1821
1822body" &&
1823 git checkout rebuild-1 &&
1824 git format-patch --stdout --cover-letter --cover-from-description auto master >actual &&
1825 grep "^Subject: \[PATCH 0/2\] \*\*\* SUBJECT HERE \*\*\*$" actual &&
1826 ! grep "^\*\*\* BLURB HERE \*\*\*$" actual &&
1827 grep "^this is a really long first line and it is over 100 characters long which is the threshold for long subjects$" actual &&
1828 grep "^body$" actual
1829'
1830
1831test_expect_success 'cover letter with command-line --cover-from-description overrides config' '
1832 test_config branch.rebuild-1.description "config subject
1833
1834body" &&
1835 test_config format.coverFromDescription none &&
1836 git checkout rebuild-1 &&
1837 git format-patch --stdout --cover-letter --cover-from-description subject master >actual &&
1838 grep "^Subject: \[PATCH 0/2\] config subject$" actual &&
1839 ! grep "^\*\*\* BLURB HERE \*\*\*$" actual &&
1840 ! grep "^config subject$" actual &&
1841 grep "^body$" actual
1842'
1843
e216cc48
NTND
1844test_expect_success 'cover letter using branch description (1)' '
1845 git checkout rebuild-1 &&
1846 test_config branch.rebuild-1.description hello &&
1847 git format-patch --stdout --cover-letter master >actual &&
f2e2fa8f 1848 grep hello actual
e216cc48
NTND
1849'
1850
1851test_expect_success 'cover letter using branch description (2)' '
1852 git checkout rebuild-1 &&
1853 test_config branch.rebuild-1.description hello &&
1854 git format-patch --stdout --cover-letter rebuild-1~2..rebuild-1 >actual &&
f2e2fa8f 1855 grep hello actual
e216cc48
NTND
1856'
1857
1858test_expect_success 'cover letter using branch description (3)' '
1859 git checkout rebuild-1 &&
1860 test_config branch.rebuild-1.description hello &&
1861 git format-patch --stdout --cover-letter ^master rebuild-1 >actual &&
f2e2fa8f 1862 grep hello actual
e216cc48
NTND
1863'
1864
20b630aa
NTND
1865test_expect_success 'cover letter using branch description (4)' '
1866 git checkout rebuild-1 &&
1867 test_config branch.rebuild-1.description hello &&
1868 git format-patch --stdout --cover-letter master.. >actual &&
f2e2fa8f 1869 grep hello actual
20b630aa
NTND
1870'
1871
1872test_expect_success 'cover letter using branch description (5)' '
1873 git checkout rebuild-1 &&
1874 test_config branch.rebuild-1.description hello &&
1875 git format-patch --stdout --cover-letter -2 HEAD >actual &&
f2e2fa8f 1876 grep hello actual
20b630aa
NTND
1877'
1878
5ee29aef
NTND
1879test_expect_success 'cover letter using branch description (6)' '
1880 git checkout rebuild-1 &&
1881 test_config branch.rebuild-1.description hello &&
1882 git format-patch --stdout --cover-letter -2 >actual &&
f2e2fa8f 1883 grep hello actual
5ee29aef
NTND
1884'
1885
80d35ca0
FC
1886test_expect_success 'cover letter with nothing' '
1887 git format-patch --stdout --cover-letter >actual &&
1888 test_line_count = 0 actual
1889'
1890
2a4c2607
FC
1891test_expect_success 'cover letter auto' '
1892 mkdir -p tmp &&
1893 test_when_finished "rm -rf tmp;
1894 git config --unset format.coverletter" &&
1895
1896 git config format.coverletter auto &&
1897 git format-patch -o tmp -1 >list &&
1898 test_line_count = 1 list &&
1899 git format-patch -o tmp -2 >list &&
1900 test_line_count = 3 list
1901'
1902
1903test_expect_success 'cover letter auto user override' '
1904 mkdir -p tmp &&
1905 test_when_finished "rm -rf tmp;
1906 git config --unset format.coverletter" &&
1907
1908 git config format.coverletter auto &&
1909 git format-patch -o tmp --cover-letter -1 >list &&
1910 test_line_count = 2 list &&
1911 git format-patch -o tmp --cover-letter -2 >list &&
1912 test_line_count = 3 list &&
1913 git format-patch -o tmp --no-cover-letter -1 >list &&
1914 test_line_count = 1 list &&
1915 git format-patch -o tmp --no-cover-letter -2 >list &&
1916 test_line_count = 2 list
1917'
1918
3a30aa17 1919test_expect_success 'format-patch --zero-commit' '
1920 git format-patch --zero-commit --stdout v2..v1 >patch2 &&
1921 grep "^From " patch2 | sort | uniq >actual &&
8125a58b 1922 echo "From $ZERO_OID Mon Sep 17 00:00:00 2001" >expect &&
3a30aa17 1923 test_cmp expect actual
1924'
1925
06dfc9eb 1926test_expect_success 'From line has expected format' '
1927 git format-patch --stdout v2..v1 >patch2 &&
1928 grep "^From " patch2 >from &&
2ece6ad2 1929 grep "^From $OID_REGEX Mon Sep 17 00:00:00 2001$" patch2 >filtered &&
06dfc9eb 1930 test_cmp from filtered
1931'
1932
edefc318
BW
1933test_expect_success 'format-patch -o with no leading directories' '
1934 rm -fr patches &&
1935 git format-patch -o patches master..side &&
1936 count=$(git rev-list --count master..side) &&
1937 ls patches >list &&
1938 test_line_count = $count list
1939'
1940
1941test_expect_success 'format-patch -o with leading existing directories' '
19c29e53
BW
1942 rm -rf existing-dir &&
1943 mkdir existing-dir &&
1944 git format-patch -o existing-dir/patches master..side &&
edefc318 1945 count=$(git rev-list --count master..side) &&
19c29e53 1946 ls existing-dir/patches >list &&
edefc318
BW
1947 test_line_count = $count list
1948'
1949
1950test_expect_success 'format-patch -o with leading non-existing directories' '
19c29e53
BW
1951 rm -rf non-existing-dir &&
1952 git format-patch -o non-existing-dir/patches master..side &&
edefc318 1953 count=$(git rev-list --count master..side) &&
19c29e53
BW
1954 test_path_is_dir non-existing-dir &&
1955 ls non-existing-dir/patches >list &&
edefc318
BW
1956 test_line_count = $count list
1957'
1958
bc6bf2d7
AK
1959test_expect_success 'format-patch format.outputDirectory option' '
1960 test_config format.outputDirectory patches &&
1961 rm -fr patches &&
1962 git format-patch master..side &&
756fb0de
DL
1963 count=$(git rev-list --count master..side) &&
1964 ls patches >list &&
1965 test_line_count = $count list
bc6bf2d7
AK
1966'
1967
1968test_expect_success 'format-patch -o overrides format.outputDirectory' '
1969 test_config format.outputDirectory patches &&
1970 rm -fr patches patchset &&
1971 git format-patch master..side -o patchset &&
1972 test_path_is_missing patches &&
1973 test_path_is_dir patchset
1974'
1975
4c6f781f 1976test_expect_success 'format-patch forbids multiple outputs' '
dc1672dd 1977 rm -fr outfile outdir &&
4c6f781f 1978 test_must_fail \
dc1672dd
JK
1979 git format-patch --stdout --output-directory=outdir &&
1980 test_must_fail \
1981 git format-patch --stdout --output=outfile &&
1982 test_must_fail \
1983 git format-patch --output=outfile --output-directory=outdir
4c6f781f
JK
1984'
1985
1986test_expect_success 'configured outdir does not conflict with output options' '
dc1672dd 1987 rm -fr outfile outdir &&
4c6f781f
JK
1988 test_config format.outputDirectory outdir &&
1989 git format-patch --stdout &&
dc1672dd
JK
1990 test_path_is_missing outdir &&
1991 git format-patch --output=outfile &&
4c6f781f
JK
1992 test_path_is_missing outdir
1993'
1994
dc1672dd
JK
1995test_expect_success 'format-patch --output' '
1996 rm -fr outfile &&
1997 git format-patch -3 --stdout HEAD >expect &&
1998 git format-patch -3 --output=outfile HEAD &&
1999 test_cmp expect outfile
2000'
2001
2002test_expect_success 'format-patch --cover-letter --output' '
2003 rm -fr outfile &&
2004 git format-patch --cover-letter -3 --stdout HEAD >expect &&
2005 git format-patch --cover-letter -3 --output=outfile HEAD &&
2006 test_cmp expect outfile
2007'
2008
fa2ab86d 2009test_expect_success 'format-patch --base' '
6f93d261 2010 git checkout patchid &&
854b5cb4
DL
2011
2012 git format-patch --stdout --base=HEAD~3 -1 >patch &&
2013 tail -n 7 patch >actual1 &&
2014
2015 git format-patch --stdout --base=HEAD~3 HEAD~.. >patch &&
2016 tail -n 7 patch >actual2 &&
2017
b562a54c 2018 echo >expect &&
854b5cb4
DL
2019 git rev-parse HEAD~3 >commit-id-base &&
2020 echo "base-commit: $(cat commit-id-base)" >>expect &&
2021
2022 git show --patch HEAD~2 >patch &&
2023 git patch-id --stable <patch >patch.id.raw &&
2024 awk "{print \"prerequisite-patch-id:\", \$1}" <patch.id.raw >>expect &&
2025
2026 git show --patch HEAD~1 >patch &&
2027 git patch-id --stable <patch >patch.id.raw &&
2028 awk "{print \"prerequisite-patch-id:\", \$1}" <patch.id.raw >>expect &&
2029
92014b69 2030 signature >>expect &&
b562a54c
DL
2031 test_cmp expect actual1 &&
2032 test_cmp expect actual2 &&
854b5cb4 2033
6f93d261 2034 echo >fail &&
854b5cb4
DL
2035 echo "base-commit: $(cat commit-id-base)" >>fail &&
2036
2037 git show --patch HEAD~2 >patch &&
2038 git patch-id --unstable <patch >patch.id.raw &&
2039 awk "{print \"prerequisite-patch-id:\", \$1}" <patch.id.raw >>fail &&
2040
2041 git show --patch HEAD~1 >patch &&
2042 git patch-id --unstable <patch >patch.id.raw &&
2043 awk "{print \"prerequisite-patch-id:\", \$1}" <patch.id.raw >>fail &&
2044
92014b69 2045 signature >>fail &&
6f93d261
SB
2046 ! test_cmp fail actual1 &&
2047 ! test_cmp fail actual2
fa2ab86d
XY
2048'
2049
2050test_expect_success 'format-patch --base errors out when base commit is in revision list' '
2051 test_must_fail git format-patch --base=HEAD -2 &&
2052 test_must_fail git format-patch --base=HEAD~1 -2 &&
2053 git format-patch --stdout --base=HEAD~2 -2 >patch &&
2054 grep "^base-commit:" patch >actual &&
854b5cb4
DL
2055 git rev-parse HEAD~2 >commit-id-base &&
2056 echo "base-commit: $(cat commit-id-base)" >expect &&
b562a54c 2057 test_cmp expect actual
fa2ab86d
XY
2058'
2059
2060test_expect_success 'format-patch --base errors out when base commit is not ancestor of revision list' '
2061 # For history as below:
2062 #
2063 # ---Q---P---Z---Y---*---X
2064 # \ /
2065 # ------------W
2066 #
2067 # If "format-patch Z..X" is given, P and Z can not be specified as the base commit
2068 git checkout -b topic1 master &&
2069 git rev-parse HEAD >commit-id-base &&
2070 test_commit P &&
2071 git rev-parse HEAD >commit-id-P &&
2072 test_commit Z &&
2073 git rev-parse HEAD >commit-id-Z &&
2074 test_commit Y &&
2075 git checkout -b topic2 master &&
2076 test_commit W &&
2077 git merge topic1 &&
2078 test_commit X &&
2079 test_must_fail git format-patch --base=$(cat commit-id-P) -3 &&
2080 test_must_fail git format-patch --base=$(cat commit-id-Z) -3 &&
2081 git format-patch --stdout --base=$(cat commit-id-base) -3 >patch &&
2082 grep "^base-commit:" patch >actual &&
b562a54c
DL
2083 echo "base-commit: $(cat commit-id-base)" >expect &&
2084 test_cmp expect actual
fa2ab86d
XY
2085'
2086
3de66517
XY
2087test_expect_success 'format-patch --base=auto' '
2088 git checkout -b upstream master &&
2089 git checkout -b local upstream &&
2090 git branch --set-upstream-to=upstream &&
2091 test_commit N1 &&
2092 test_commit N2 &&
2093 git format-patch --stdout --base=auto -2 >patch &&
2094 grep "^base-commit:" patch >actual &&
854b5cb4
DL
2095 git rev-parse upstream >commit-id-base &&
2096 echo "base-commit: $(cat commit-id-base)" >expect &&
b562a54c 2097 test_cmp expect actual
3de66517
XY
2098'
2099
2100test_expect_success 'format-patch errors out when history involves criss-cross' '
2101 # setup criss-cross history
2102 #
2103 # B---M1---D
2104 # / \ /
2105 # A X
2106 # \ / \
2107 # C---M2---E
2108 #
2109 git checkout master &&
2110 test_commit A &&
2111 git checkout -b xb master &&
2112 test_commit B &&
2113 git checkout -b xc master &&
2114 test_commit C &&
2115 git checkout -b xbc xb -- &&
2116 git merge xc &&
2117 git checkout -b xcb xc -- &&
2118 git branch --set-upstream-to=xbc &&
2119 git merge xb &&
2120 git checkout xbc &&
2121 test_commit D &&
2122 git checkout xcb &&
2123 test_commit E &&
2124 test_must_fail git format-patch --base=auto -1
2125'
2126
7efba5fa
JK
2127test_expect_success 'format-patch format.useAutoBase whenAble history involves criss-cross' '
2128 test_config format.useAutoBase whenAble &&
2129 git format-patch -1 >patch &&
2130 ! grep "^base-commit:" patch
2131'
2132
700e006c 2133test_expect_success 'format-patch format.useAutoBase option' '
bb52995f 2134 git checkout local &&
700e006c 2135 test_config format.useAutoBase true &&
bb52995f
XY
2136 git format-patch --stdout -1 >patch &&
2137 grep "^base-commit:" patch >actual &&
854b5cb4
DL
2138 git rev-parse upstream >commit-id-base &&
2139 echo "base-commit: $(cat commit-id-base)" >expect &&
b562a54c 2140 test_cmp expect actual
bb52995f
XY
2141'
2142
7efba5fa
JK
2143test_expect_success 'format-patch format.useAutoBase option with whenAble' '
2144 git checkout local &&
2145 test_config format.useAutoBase whenAble &&
2146 git format-patch --stdout -1 >patch &&
2147 grep "^base-commit:" patch >actual &&
2148 git rev-parse upstream >commit-id-base &&
2149 echo "base-commit: $(cat commit-id-base)" >expect &&
2150 test_cmp expect actual
2151'
2152
bb52995f 2153test_expect_success 'format-patch --base overrides format.useAutoBase' '
700e006c 2154 test_config format.useAutoBase true &&
bb52995f
XY
2155 git format-patch --stdout --base=HEAD~1 -1 >patch &&
2156 grep "^base-commit:" patch >actual &&
854b5cb4
DL
2157 git rev-parse HEAD~1 >commit-id-base &&
2158 echo "base-commit: $(cat commit-id-base)" >expect &&
b562a54c 2159 test_cmp expect actual
bb52995f
XY
2160'
2161
945dc55d
DL
2162test_expect_success 'format-patch --no-base overrides format.useAutoBase' '
2163 test_config format.useAutoBase true &&
2164 git format-patch --stdout --no-base -1 >patch &&
2165 ! grep "^base-commit:" patch
2166'
2167
7efba5fa
JK
2168test_expect_success 'format-patch --no-base overrides format.useAutoBase whenAble' '
2169 test_config format.useAutoBase whenAble &&
2170 git format-patch --stdout --no-base -1 >patch &&
2171 ! grep "^base-commit:" patch
2172'
2173
480871e0
JT
2174test_expect_success 'format-patch --base with --attach' '
2175 git format-patch --attach=mimemime --stdout --base=HEAD~ -1 >patch &&
2176 sed -n -e "/^base-commit:/s/.*/1/p" -e "/^---*mimemime--$/s/.*/2/p" \
2177 patch >actual &&
2178 test_write_lines 1 2 >expect &&
2179 test_cmp expect actual
2180'
50cd54ef 2181test_expect_success 'format-patch --attach cover-letter only is non-multipart' '
2182 test_when_finished "rm -fr patches" &&
2183 git format-patch -o patches --cover-letter --attach=mimemime --base=HEAD~ -1 &&
2184 ! egrep "^--+mimemime" patches/0000*.patch &&
2185 egrep "^--+mimemime$" patches/0001*.patch >output &&
2186 test_line_count = 2 output &&
2187 egrep "^--+mimemime--$" patches/0001*.patch >output &&
2188 test_line_count = 1 output
2189'
480871e0 2190
9f23e040
EW
2191test_expect_success 'format-patch --pretty=mboxrd' '
2192 sp=" " &&
2193 cat >msg <<-INPUT_END &&
2194 mboxrd should escape the body
2195
2196 From could trip up a loose mbox parser
2197 >From extra escape for reversibility
2198 >>From extra escape for reversibility 2
2199 from lower case not escaped
2200 Fromm bad speling not escaped
2201 From with leading space not escaped
2202
2203 F
2204 From
2205 From$sp
2206 From $sp
2207 From $sp
2208 INPUT_END
2209
2210 cat >expect <<-INPUT_END &&
2211 >From could trip up a loose mbox parser
2212 >>From extra escape for reversibility
2213 >>>From extra escape for reversibility 2
2214 from lower case not escaped
2215 Fromm bad speling not escaped
2216 From with leading space not escaped
2217
2218 F
2219 From
2220 From
2221 From
2222 From
2223 INPUT_END
2224
2225 C=$(git commit-tree HEAD^^{tree} -p HEAD <msg) &&
2226 git format-patch --pretty=mboxrd --stdout -1 $C~1..$C >patch &&
2227 git grep -h --no-index -A11 \
2228 "^>From could trip up a loose mbox parser" patch >actual &&
2229 test_cmp expect actual
2230'
2231
126facf8
ES
2232test_expect_success 'interdiff: setup' '
2233 git checkout -b boop master &&
2234 test_commit fnorp blorp &&
2235 test_commit fleep blorp
2236'
2237
2238test_expect_success 'interdiff: cover-letter' '
2239 sed "y/q/ /" >expect <<-\EOF &&
2240 +fleep
2241 --q
2242 EOF
2243 git format-patch --cover-letter --interdiff=boop~2 -1 boop &&
2244 test_i18ngrep "^Interdiff:$" 0000-cover-letter.patch &&
ee6cbf71 2245 test_i18ngrep ! "^Interdiff:$" 0001-fleep.patch &&
c6ec6dad 2246 sed "1,/^@@ /d; /^-- $/q" 0000-cover-letter.patch >actual &&
126facf8
ES
2247 test_cmp expect actual
2248'
2249
5ac290f9
ES
2250test_expect_success 'interdiff: reroll-count' '
2251 git format-patch --cover-letter --interdiff=boop~2 -v2 -1 boop &&
2252 test_i18ngrep "^Interdiff ..* v1:$" v2-0000-cover-letter.patch
2253'
2254
ee6cbf71
ES
2255test_expect_success 'interdiff: solo-patch' '
2256 cat >expect <<-\EOF &&
2257 +fleep
2258
2259 EOF
2260 git format-patch --interdiff=boop~2 -1 boop &&
2261 test_i18ngrep "^Interdiff:$" 0001-fleep.patch &&
c6ec6dad 2262 sed "1,/^ @@ /d; /^$/q" 0001-fleep.patch >actual &&
ee6cbf71
ES
2263 test_cmp expect actual
2264'
2265
ece3c67f 2266test_done