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