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