Merge branch 'jk/repack-pack-writebitmaps-config'
[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 . ./test-lib.sh
9 . "$TEST_DIRECTORY"/lib-terminal.sh
10
11 test_expect_success setup '
12
13         for i in 1 2 3 4 5 6 7 8 9 10; do echo "$i"; done >file &&
14         cat file >elif &&
15         git add file elif &&
16         test_tick &&
17         git commit -m Initial &&
18         git checkout -b side &&
19
20         for i in 1 2 5 6 A B C 7 8 9 10; do echo "$i"; done >file &&
21         test_chmod +x elif &&
22         test_tick &&
23         git commit -m "Side changes #1" &&
24
25         for i in D E F; do echo "$i"; done >>file &&
26         git update-index file &&
27         test_tick &&
28         git commit -m "Side changes #2" &&
29         git tag C2 &&
30
31         for i in 5 6 1 2 3 A 4 B C 7 8 9 10 D E F; do echo "$i"; done >file &&
32         git update-index file &&
33         test_tick &&
34         git commit -m "Side changes #3 with \\n backslash-n in it." &&
35
36         git checkout master &&
37         git diff-tree -p C2 | git apply --index &&
38         test_tick &&
39         git commit -m "Master accepts moral equivalent of #2"
40
41 '
42
43 test_expect_success "format-patch --ignore-if-in-upstream" '
44
45         git format-patch --stdout master..side >patch0 &&
46         cnt=$(grep "^From " patch0 | wc -l) &&
47         test $cnt = 3
48
49 '
50
51 test_expect_success "format-patch --ignore-if-in-upstream" '
52
53         git format-patch --stdout \
54                 --ignore-if-in-upstream master..side >patch1 &&
55         cnt=$(grep "^From " patch1 | wc -l) &&
56         test $cnt = 2
57
58 '
59
60 test_expect_success "format-patch doesn't consider merge commits" '
61
62         git checkout -b slave master &&
63         echo "Another line" >>file &&
64         test_tick &&
65         git commit -am "Slave change #1" &&
66         echo "Yet another line" >>file &&
67         test_tick &&
68         git commit -am "Slave change #2" &&
69         git checkout -b merger master &&
70         test_tick &&
71         git merge --no-ff slave &&
72         cnt=$(git format-patch -3 --stdout | grep "^From " | wc -l) &&
73         test $cnt = 3
74 '
75
76 test_expect_success "format-patch result applies" '
77
78         git checkout -b rebuild-0 master &&
79         git am -3 patch0 &&
80         cnt=$(git rev-list master.. | wc -l) &&
81         test $cnt = 2
82 '
83
84 test_expect_success "format-patch --ignore-if-in-upstream result applies" '
85
86         git checkout -b rebuild-1 master &&
87         git am -3 patch1 &&
88         cnt=$(git rev-list master.. | wc -l) &&
89         test $cnt = 2
90 '
91
92 test_expect_success 'commit did not screw up the log message' '
93
94         git cat-file commit side | grep "^Side .* with .* backslash-n"
95
96 '
97
98 test_expect_success 'format-patch did not screw up the log message' '
99
100         grep "^Subject: .*Side changes #3 with .* backslash-n" patch0 &&
101         grep "^Subject: .*Side changes #3 with .* backslash-n" patch1
102
103 '
104
105 test_expect_success 'replay did not screw up the log message' '
106
107         git cat-file commit rebuild-1 | grep "^Side .* with .* backslash-n"
108
109 '
110
111 test_expect_success 'extra headers' '
112
113         git config format.headers "To: R E Cipient <rcipient@example.com>
114 " &&
115         git config --add format.headers "Cc: S E Cipient <scipient@example.com>
116 " &&
117         git format-patch --stdout master..side > patch2 &&
118         sed -e "/^\$/q" patch2 > hdrs2 &&
119         grep "^To: R E Cipient <rcipient@example.com>\$" hdrs2 &&
120         grep "^Cc: S E Cipient <scipient@example.com>\$" hdrs2
121
122 '
123
124 test_expect_success 'extra headers without newlines' '
125
126         git config --replace-all format.headers "To: R E Cipient <rcipient@example.com>" &&
127         git config --add format.headers "Cc: S E Cipient <scipient@example.com>" &&
128         git format-patch --stdout master..side >patch3 &&
129         sed -e "/^\$/q" patch3 > hdrs3 &&
130         grep "^To: R E Cipient <rcipient@example.com>\$" hdrs3 &&
131         grep "^Cc: S E Cipient <scipient@example.com>\$" hdrs3
132
133 '
134
135 test_expect_success 'extra headers with multiple To:s' '
136
137         git config --replace-all format.headers "To: R E Cipient <rcipient@example.com>" &&
138         git config --add format.headers "To: S E Cipient <scipient@example.com>" &&
139         git format-patch --stdout master..side > patch4 &&
140         sed -e "/^\$/q" patch4 > hdrs4 &&
141         grep "^To: R E Cipient <rcipient@example.com>,\$" hdrs4 &&
142         grep "^ *S E Cipient <scipient@example.com>\$" hdrs4
143 '
144
145 test_expect_success 'additional command line cc (ascii)' '
146
147         git config --replace-all format.headers "Cc: R E Cipient <rcipient@example.com>" &&
148         git format-patch --cc="S E Cipient <scipient@example.com>" --stdout master..side | sed -e "/^\$/q" >patch5 &&
149         grep "^Cc: R E Cipient <rcipient@example.com>,\$" patch5 &&
150         grep "^ *S E Cipient <scipient@example.com>\$" patch5
151 '
152
153 test_expect_failure 'additional command line cc (rfc822)' '
154
155         git config --replace-all format.headers "Cc: R E Cipient <rcipient@example.com>" &&
156         git format-patch --cc="S. E. Cipient <scipient@example.com>" --stdout master..side | sed -e "/^\$/q" >patch5 &&
157         grep "^Cc: R E Cipient <rcipient@example.com>,\$" patch5 &&
158         grep "^ *\"S. E. Cipient\" <scipient@example.com>\$" patch5
159 '
160
161 test_expect_success 'command line headers' '
162
163         git config --unset-all format.headers &&
164         git format-patch --add-header="Cc: R E Cipient <rcipient@example.com>" --stdout master..side | sed -e "/^\$/q" >patch6 &&
165         grep "^Cc: R E Cipient <rcipient@example.com>\$" patch6
166 '
167
168 test_expect_success 'configuration headers and command line headers' '
169
170         git config --replace-all format.headers "Cc: R E Cipient <rcipient@example.com>" &&
171         git format-patch --add-header="Cc: S E Cipient <scipient@example.com>" --stdout master..side | sed -e "/^\$/q" >patch7 &&
172         grep "^Cc: R E Cipient <rcipient@example.com>,\$" patch7 &&
173         grep "^ *S E Cipient <scipient@example.com>\$" patch7
174 '
175
176 test_expect_success 'command line To: header (ascii)' '
177
178         git config --unset-all format.headers &&
179         git format-patch --to="R E Cipient <rcipient@example.com>" --stdout master..side | sed -e "/^\$/q" >patch8 &&
180         grep "^To: R E Cipient <rcipient@example.com>\$" patch8
181 '
182
183 test_expect_failure 'command line To: header (rfc822)' '
184
185         git format-patch --to="R. E. Cipient <rcipient@example.com>" --stdout master..side | sed -e "/^\$/q" >patch8 &&
186         grep "^To: \"R. E. Cipient\" <rcipient@example.com>\$" patch8
187 '
188
189 test_expect_failure 'command line To: header (rfc2047)' '
190
191         git format-patch --to="R Ä Cipient <rcipient@example.com>" --stdout master..side | sed -e "/^\$/q" >patch8 &&
192         grep "^To: =?UTF-8?q?R=20=C3=84=20Cipient?= <rcipient@example.com>\$" patch8
193 '
194
195 test_expect_success 'configuration To: header (ascii)' '
196
197         git config format.to "R E Cipient <rcipient@example.com>" &&
198         git format-patch --stdout master..side | sed -e "/^\$/q" >patch9 &&
199         grep "^To: R E Cipient <rcipient@example.com>\$" patch9
200 '
201
202 test_expect_failure 'configuration To: header (rfc822)' '
203
204         git config format.to "R. E. Cipient <rcipient@example.com>" &&
205         git format-patch --stdout master..side | sed -e "/^\$/q" >patch9 &&
206         grep "^To: \"R. E. Cipient\" <rcipient@example.com>\$" patch9
207 '
208
209 test_expect_failure 'configuration To: header (rfc2047)' '
210
211         git config format.to "R Ä Cipient <rcipient@example.com>" &&
212         git format-patch --stdout master..side | sed -e "/^\$/q" >patch9 &&
213         grep "^To: =?UTF-8?q?R=20=C3=84=20Cipient?= <rcipient@example.com>\$" patch9
214 '
215
216 # check_patch <patch>: Verify that <patch> looks like a half-sane
217 # patch email to avoid a false positive with !grep
218 check_patch () {
219         grep -e "^From:" "$1" &&
220         grep -e "^Date:" "$1" &&
221         grep -e "^Subject:" "$1"
222 }
223
224 test_expect_success '--no-to overrides config.to' '
225
226         git config --replace-all format.to \
227                 "R E Cipient <rcipient@example.com>" &&
228         git format-patch --no-to --stdout master..side |
229         sed -e "/^\$/q" >patch10 &&
230         check_patch patch10 &&
231         ! grep "^To: R E Cipient <rcipient@example.com>\$" patch10
232 '
233
234 test_expect_success '--no-to and --to replaces config.to' '
235
236         git config --replace-all format.to \
237                 "Someone <someone@out.there>" &&
238         git format-patch --no-to --to="Someone Else <else@out.there>" \
239                 --stdout master..side |
240         sed -e "/^\$/q" >patch11 &&
241         check_patch patch11 &&
242         ! grep "^To: Someone <someone@out.there>\$" patch11 &&
243         grep "^To: Someone Else <else@out.there>\$" patch11
244 '
245
246 test_expect_success '--no-cc overrides config.cc' '
247
248         git config --replace-all format.cc \
249                 "C E Cipient <rcipient@example.com>" &&
250         git format-patch --no-cc --stdout master..side |
251         sed -e "/^\$/q" >patch12 &&
252         check_patch patch12 &&
253         ! grep "^Cc: C E Cipient <rcipient@example.com>\$" patch12
254 '
255
256 test_expect_success '--no-add-header overrides config.headers' '
257
258         git config --replace-all format.headers \
259                 "Header1: B E Cipient <rcipient@example.com>" &&
260         git format-patch --no-add-header --stdout master..side |
261         sed -e "/^\$/q" >patch13 &&
262         check_patch patch13 &&
263         ! grep "^Header1: B E Cipient <rcipient@example.com>\$" patch13
264 '
265
266 test_expect_success 'multiple files' '
267
268         rm -rf patches/ &&
269         git checkout side &&
270         git format-patch -o patches/ master &&
271         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
272 '
273
274 test_expect_success 'reroll count' '
275         rm -fr patches &&
276         git format-patch -o patches --cover-letter --reroll-count 4 master..side >list &&
277         ! grep -v "^patches/v4-000[0-3]-" list &&
278         sed -n -e "/^Subject: /p" $(cat list) >subjects &&
279         ! grep -v "^Subject: \[PATCH v4 [0-3]/3\] " subjects
280 '
281
282 test_expect_success 'reroll count (-v)' '
283         rm -fr patches &&
284         git format-patch -o patches --cover-letter -v4 master..side >list &&
285         ! grep -v "^patches/v4-000[0-3]-" list &&
286         sed -n -e "/^Subject: /p" $(cat list) >subjects &&
287         ! grep -v "^Subject: \[PATCH v4 [0-3]/3\] " subjects
288 '
289
290 check_threading () {
291         expect="$1" &&
292         shift &&
293         (git format-patch --stdout "$@"; echo $? > status.out) |
294         # Prints everything between the Message-ID and In-Reply-To,
295         # and replaces all Message-ID-lookalikes by a sequence number
296         perl -ne '
297                 if (/^(message-id|references|in-reply-to)/i) {
298                         $printing = 1;
299                 } elsif (/^\S/) {
300                         $printing = 0;
301                 }
302                 if ($printing) {
303                         $h{$1}=$i++ if (/<([^>]+)>/ and !exists $h{$1});
304                         for $k (keys %h) {s/$k/$h{$k}/};
305                         print;
306                 }
307                 print "---\n" if /^From /i;
308         ' > actual &&
309         test 0 = "$(cat status.out)" &&
310         test_cmp "$expect" actual
311 }
312
313 cat >> expect.no-threading <<EOF
314 ---
315 ---
316 ---
317 EOF
318
319 test_expect_success 'no threading' '
320         git checkout side &&
321         check_threading expect.no-threading master
322 '
323
324 cat > expect.thread <<EOF
325 ---
326 Message-Id: <0>
327 ---
328 Message-Id: <1>
329 In-Reply-To: <0>
330 References: <0>
331 ---
332 Message-Id: <2>
333 In-Reply-To: <0>
334 References: <0>
335 EOF
336
337 test_expect_success 'thread' '
338         check_threading expect.thread --thread master
339 '
340
341 cat > expect.in-reply-to <<EOF
342 ---
343 Message-Id: <0>
344 In-Reply-To: <1>
345 References: <1>
346 ---
347 Message-Id: <2>
348 In-Reply-To: <1>
349 References: <1>
350 ---
351 Message-Id: <3>
352 In-Reply-To: <1>
353 References: <1>
354 EOF
355
356 test_expect_success 'thread in-reply-to' '
357         check_threading expect.in-reply-to --in-reply-to="<test.message>" \
358                 --thread master
359 '
360
361 cat > expect.cover-letter <<EOF
362 ---
363 Message-Id: <0>
364 ---
365 Message-Id: <1>
366 In-Reply-To: <0>
367 References: <0>
368 ---
369 Message-Id: <2>
370 In-Reply-To: <0>
371 References: <0>
372 ---
373 Message-Id: <3>
374 In-Reply-To: <0>
375 References: <0>
376 EOF
377
378 test_expect_success 'thread cover-letter' '
379         check_threading expect.cover-letter --cover-letter --thread master
380 '
381
382 cat > expect.cl-irt <<EOF
383 ---
384 Message-Id: <0>
385 In-Reply-To: <1>
386 References: <1>
387 ---
388 Message-Id: <2>
389 In-Reply-To: <0>
390 References: <1>
391         <0>
392 ---
393 Message-Id: <3>
394 In-Reply-To: <0>
395 References: <1>
396         <0>
397 ---
398 Message-Id: <4>
399 In-Reply-To: <0>
400 References: <1>
401         <0>
402 EOF
403
404 test_expect_success 'thread cover-letter in-reply-to' '
405         check_threading expect.cl-irt --cover-letter \
406                 --in-reply-to="<test.message>" --thread master
407 '
408
409 test_expect_success 'thread explicit shallow' '
410         check_threading expect.cl-irt --cover-letter \
411                 --in-reply-to="<test.message>" --thread=shallow master
412 '
413
414 cat > expect.deep <<EOF
415 ---
416 Message-Id: <0>
417 ---
418 Message-Id: <1>
419 In-Reply-To: <0>
420 References: <0>
421 ---
422 Message-Id: <2>
423 In-Reply-To: <1>
424 References: <0>
425         <1>
426 EOF
427
428 test_expect_success 'thread deep' '
429         check_threading expect.deep --thread=deep master
430 '
431
432 cat > expect.deep-irt <<EOF
433 ---
434 Message-Id: <0>
435 In-Reply-To: <1>
436 References: <1>
437 ---
438 Message-Id: <2>
439 In-Reply-To: <0>
440 References: <1>
441         <0>
442 ---
443 Message-Id: <3>
444 In-Reply-To: <2>
445 References: <1>
446         <0>
447         <2>
448 EOF
449
450 test_expect_success 'thread deep in-reply-to' '
451         check_threading expect.deep-irt  --thread=deep \
452                 --in-reply-to="<test.message>" master
453 '
454
455 cat > expect.deep-cl <<EOF
456 ---
457 Message-Id: <0>
458 ---
459 Message-Id: <1>
460 In-Reply-To: <0>
461 References: <0>
462 ---
463 Message-Id: <2>
464 In-Reply-To: <1>
465 References: <0>
466         <1>
467 ---
468 Message-Id: <3>
469 In-Reply-To: <2>
470 References: <0>
471         <1>
472         <2>
473 EOF
474
475 test_expect_success 'thread deep cover-letter' '
476         check_threading expect.deep-cl --cover-letter --thread=deep master
477 '
478
479 cat > expect.deep-cl-irt <<EOF
480 ---
481 Message-Id: <0>
482 In-Reply-To: <1>
483 References: <1>
484 ---
485 Message-Id: <2>
486 In-Reply-To: <0>
487 References: <1>
488         <0>
489 ---
490 Message-Id: <3>
491 In-Reply-To: <2>
492 References: <1>
493         <0>
494         <2>
495 ---
496 Message-Id: <4>
497 In-Reply-To: <3>
498 References: <1>
499         <0>
500         <2>
501         <3>
502 EOF
503
504 test_expect_success 'thread deep cover-letter in-reply-to' '
505         check_threading expect.deep-cl-irt --cover-letter \
506                 --in-reply-to="<test.message>" --thread=deep master
507 '
508
509 test_expect_success 'thread via config' '
510         test_config format.thread true &&
511         check_threading expect.thread master
512 '
513
514 test_expect_success 'thread deep via config' '
515         test_config format.thread deep &&
516         check_threading expect.deep master
517 '
518
519 test_expect_success 'thread config + override' '
520         test_config format.thread deep &&
521         check_threading expect.thread --thread master
522 '
523
524 test_expect_success 'thread config + --no-thread' '
525         test_config format.thread deep &&
526         check_threading expect.no-threading --no-thread master
527 '
528
529 test_expect_success 'excessive subject' '
530
531         rm -rf patches/ &&
532         git checkout side &&
533         for i in 5 6 1 2 3 A 4 B C 7 8 9 10 D E F; do echo "$i"; done >>file &&
534         git update-index file &&
535         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." &&
536         git format-patch -o patches/ master..side &&
537         ls patches/0004-This-is-an-excessively-long-subject-line-for-a-messa.patch
538 '
539
540 test_expect_success 'cover-letter inherits diff options' '
541
542         git mv file foo &&
543         git commit -m foo &&
544         git format-patch --cover-letter -1 &&
545         check_patch 0000-cover-letter.patch &&
546         ! grep "file => foo .* 0 *\$" 0000-cover-letter.patch &&
547         git format-patch --cover-letter -1 -M &&
548         grep "file => foo .* 0 *\$" 0000-cover-letter.patch
549
550 '
551
552 cat > expect << EOF
553   This is an excessively long subject line for a message due to the
554     habit some projects have of not having a short, one-line subject at
555     the start of the commit message, but rather sticking a whole
556     paragraph right at the start as the only thing in the commit
557     message. It had better not become the filename for the patch.
558   foo
559
560 EOF
561
562 test_expect_success 'shortlog of cover-letter wraps overly-long onelines' '
563
564         git format-patch --cover-letter -2 &&
565         sed -e "1,/A U Thor/d" -e "/^\$/q" < 0000-cover-letter.patch > output &&
566         test_cmp expect output
567
568 '
569
570 cat > expect << EOF
571 index 40f36c6..2dc5c23 100644
572 --- a/file
573 +++ b/file
574 @@ -13,4 +13,20 @@ C
575  10
576  D
577  E
578  F
579 +5
580 EOF
581
582 test_expect_success 'format-patch respects -U' '
583
584         git format-patch -U4 -2 &&
585         sed -e "1,/^diff/d" -e "/^+5/q" \
586                 <0001-This-is-an-excessively-long-subject-line-for-a-messa.patch \
587                 >output &&
588         test_cmp expect output
589
590 '
591
592 cat > expect << EOF
593
594 diff --git a/file b/file
595 index 40f36c6..2dc5c23 100644
596 --- a/file
597 +++ b/file
598 @@ -14,3 +14,19 @@ C
599  D
600  E
601  F
602 +5
603 EOF
604
605 test_expect_success 'format-patch -p suppresses stat' '
606
607         git format-patch -p -2 &&
608         sed -e "1,/^\$/d" -e "/^+5/q" < 0001-This-is-an-excessively-long-subject-line-for-a-messa.patch > output &&
609         test_cmp expect output
610
611 '
612
613 test_expect_success 'format-patch from a subdirectory (1)' '
614         filename=$(
615                 rm -rf sub &&
616                 mkdir -p sub/dir &&
617                 cd sub/dir &&
618                 git format-patch -1
619         ) &&
620         case "$filename" in
621         0*)
622                 ;; # ok
623         *)
624                 echo "Oops? $filename"
625                 false
626                 ;;
627         esac &&
628         test -f "$filename"
629 '
630
631 test_expect_success 'format-patch from a subdirectory (2)' '
632         filename=$(
633                 rm -rf sub &&
634                 mkdir -p sub/dir &&
635                 cd sub/dir &&
636                 git format-patch -1 -o ..
637         ) &&
638         case "$filename" in
639         ../0*)
640                 ;; # ok
641         *)
642                 echo "Oops? $filename"
643                 false
644                 ;;
645         esac &&
646         basename=$(expr "$filename" : ".*/\(.*\)") &&
647         test -f "sub/$basename"
648 '
649
650 test_expect_success 'format-patch from a subdirectory (3)' '
651         rm -f 0* &&
652         filename=$(
653                 rm -rf sub &&
654                 mkdir -p sub/dir &&
655                 cd sub/dir &&
656                 git format-patch -1 -o "$TRASH_DIRECTORY"
657         ) &&
658         basename=$(expr "$filename" : ".*/\(.*\)") &&
659         test -f "$basename"
660 '
661
662 test_expect_success 'format-patch --in-reply-to' '
663         git format-patch -1 --stdout --in-reply-to "baz@foo.bar" > patch8 &&
664         grep "^In-Reply-To: <baz@foo.bar>" patch8 &&
665         grep "^References: <baz@foo.bar>" patch8
666 '
667
668 test_expect_success 'format-patch --signoff' '
669         git format-patch -1 --signoff --stdout >out &&
670         grep "^Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>" out
671 '
672
673 test_expect_success 'format-patch --notes --signoff' '
674         git notes --ref test add -m "test message" HEAD &&
675         git format-patch -1 --signoff --stdout --notes=test >out &&
676         # Three dashes must come after S-o-b
677         ! sed "/^Signed-off-by: /q" out | grep "test message" &&
678         sed "1,/^Signed-off-by: /d" out | grep "test message" &&
679         # Notes message must come after three dashes
680         ! sed "/^---$/q" out | grep "test message" &&
681         sed "1,/^---$/d" out | grep "test message"
682 '
683
684 echo "fatal: --name-only does not make sense" > expect.name-only
685 echo "fatal: --name-status does not make sense" > expect.name-status
686 echo "fatal: --check does not make sense" > expect.check
687
688 test_expect_success 'options no longer allowed for format-patch' '
689         test_must_fail git format-patch --name-only 2> output &&
690         test_i18ncmp expect.name-only output &&
691         test_must_fail git format-patch --name-status 2> output &&
692         test_i18ncmp expect.name-status output &&
693         test_must_fail git format-patch --check 2> output &&
694         test_i18ncmp expect.check output'
695
696 test_expect_success 'format-patch --numstat should produce a patch' '
697         git format-patch --numstat --stdout master..side > output &&
698         test 6 = $(grep "^diff --git a/" output | wc -l)'
699
700 test_expect_success 'format-patch -- <path>' '
701         git format-patch master..side -- file 2>error &&
702         ! grep "Use .--" error
703 '
704
705 test_expect_success 'format-patch --ignore-if-in-upstream HEAD' '
706         git format-patch --ignore-if-in-upstream HEAD
707 '
708
709 test_expect_success 'format-patch --signature' '
710         git format-patch --stdout --signature="my sig" -1 >output &&
711         grep "my sig" output
712 '
713
714 test_expect_success 'format-patch with format.signature config' '
715         git config format.signature "config sig" &&
716         git format-patch --stdout -1 >output &&
717         grep "config sig" output
718 '
719
720 test_expect_success 'format-patch --signature overrides format.signature' '
721         git config format.signature "config sig" &&
722         git format-patch --stdout --signature="overrides" -1 >output &&
723         ! grep "config sig" output &&
724         grep "overrides" output
725 '
726
727 test_expect_success 'format-patch --no-signature ignores format.signature' '
728         git config format.signature "config sig" &&
729         git format-patch --stdout --signature="my sig" --no-signature \
730                 -1 >output &&
731         check_patch output &&
732         ! grep "config sig" output &&
733         ! grep "my sig" output &&
734         ! grep "^-- \$" output
735 '
736
737 test_expect_success 'format-patch --signature --cover-letter' '
738         git config --unset-all format.signature &&
739         git format-patch --stdout --signature="my sig" --cover-letter \
740                 -1 >output &&
741         grep "my sig" output &&
742         test 2 = $(grep "my sig" output | wc -l)
743 '
744
745 test_expect_success 'format.signature="" suppresses signatures' '
746         git config format.signature "" &&
747         git format-patch --stdout -1 >output &&
748         check_patch output &&
749         ! grep "^-- \$" output
750 '
751
752 test_expect_success 'format-patch --no-signature suppresses signatures' '
753         git config --unset-all format.signature &&
754         git format-patch --stdout --no-signature -1 >output &&
755         check_patch output &&
756         ! grep "^-- \$" output
757 '
758
759 test_expect_success 'format-patch --signature="" suppresses signatures' '
760         git format-patch --stdout --signature="" -1 >output &&
761         check_patch output &&
762         ! grep "^-- \$" output
763 '
764
765 test_expect_success 'prepare mail-signature input' '
766         cat >mail-signature <<-\EOF
767
768         Test User <test.email@kernel.org>
769         http://git.kernel.org/cgit/git/git.git
770
771         git.kernel.org/?p=git/git.git;a=summary
772
773         EOF
774 '
775
776 test_expect_success '--signature-file=file works' '
777         git format-patch --stdout --signature-file=mail-signature -1 >output &&
778         check_patch output &&
779         sed -e "1,/^-- \$/d" <output >actual &&
780         {
781                 cat mail-signature && echo
782         } >expect &&
783         test_cmp expect actual
784 '
785
786 test_expect_success 'format.signaturefile works' '
787         test_config format.signaturefile mail-signature &&
788         git format-patch --stdout -1 >output &&
789         check_patch output &&
790         sed -e "1,/^-- \$/d" <output >actual &&
791         {
792                 cat mail-signature && echo
793         } >expect &&
794         test_cmp expect actual
795 '
796
797 test_expect_success '--no-signature suppresses format.signaturefile ' '
798         test_config format.signaturefile mail-signature &&
799         git format-patch --stdout --no-signature -1 >output &&
800         check_patch output &&
801         ! grep "^-- \$" output
802 '
803
804 test_expect_success '--signature-file overrides format.signaturefile' '
805         cat >other-mail-signature <<-\EOF
806         Use this other signature instead of mail-signature.
807         EOF
808         test_config format.signaturefile mail-signature &&
809         git format-patch --stdout \
810                         --signature-file=other-mail-signature -1 >output &&
811         check_patch output &&
812         sed -e "1,/^-- \$/d" <output >actual &&
813         {
814                 cat other-mail-signature && echo
815         } >expect &&
816         test_cmp expect actual
817 '
818
819 test_expect_success '--signature overrides format.signaturefile' '
820         test_config format.signaturefile mail-signature &&
821         git format-patch --stdout --signature="my sig" -1 >output &&
822         check_patch output &&
823         grep "my sig" output
824 '
825
826 test_expect_success TTY 'format-patch --stdout paginates' '
827         rm -f pager_used &&
828         test_terminal env GIT_PAGER="wc >pager_used" git format-patch --stdout --all &&
829         test_path_is_file pager_used
830 '
831
832  test_expect_success TTY 'format-patch --stdout pagination can be disabled' '
833         rm -f pager_used &&
834         test_terminal env GIT_PAGER="wc >pager_used" git --no-pager format-patch --stdout --all &&
835         test_terminal env GIT_PAGER="wc >pager_used" git -c "pager.format-patch=false" format-patch --stdout --all &&
836         test_path_is_missing pager_used &&
837         test_path_is_missing .git/pager_used
838 '
839
840 test_expect_success 'format-patch handles multi-line subjects' '
841         rm -rf patches/ &&
842         echo content >>file &&
843         for i in one two three; do echo $i; done >msg &&
844         git add file &&
845         git commit -F msg &&
846         git format-patch -o patches -1 &&
847         grep ^Subject: patches/0001-one.patch >actual &&
848         echo "Subject: [PATCH] one two three" >expect &&
849         test_cmp expect actual
850 '
851
852 test_expect_success 'format-patch handles multi-line encoded subjects' '
853         rm -rf patches/ &&
854         echo content >>file &&
855         for i in en två tre; do echo $i; done >msg &&
856         git add file &&
857         git commit -F msg &&
858         git format-patch -o patches -1 &&
859         grep ^Subject: patches/0001-en.patch >actual &&
860         echo "Subject: [PATCH] =?UTF-8?q?en=20tv=C3=A5=20tre?=" >expect &&
861         test_cmp expect actual
862 '
863
864 M8="foo bar "
865 M64=$M8$M8$M8$M8$M8$M8$M8$M8
866 M512=$M64$M64$M64$M64$M64$M64$M64$M64
867 cat >expect <<'EOF'
868 Subject: [PATCH] foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo
869  bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar
870  foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo
871  bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar
872  foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo
873  bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar
874  foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar
875 EOF
876 test_expect_success 'format-patch wraps extremely long subject (ascii)' '
877         echo content >>file &&
878         git add file &&
879         git commit -m "$M512" &&
880         git format-patch --stdout -1 >patch &&
881         sed -n "/^Subject/p; /^ /p; /^$/q" <patch >subject &&
882         test_cmp expect subject
883 '
884
885 M8="föö bar "
886 M64=$M8$M8$M8$M8$M8$M8$M8$M8
887 M512=$M64$M64$M64$M64$M64$M64$M64$M64
888 cat >expect <<'EOF'
889 Subject: [PATCH] =?UTF-8?q?f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f?=
890  =?UTF-8?q?=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar?=
891  =?UTF-8?q?=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20?=
892  =?UTF-8?q?bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6?=
893  =?UTF-8?q?=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6?=
894  =?UTF-8?q?=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f?=
895  =?UTF-8?q?=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar?=
896  =?UTF-8?q?=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20?=
897  =?UTF-8?q?bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6?=
898  =?UTF-8?q?=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6?=
899  =?UTF-8?q?=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f?=
900  =?UTF-8?q?=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar?=
901  =?UTF-8?q?=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20?=
902  =?UTF-8?q?bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6?=
903  =?UTF-8?q?=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6?=
904  =?UTF-8?q?=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f?=
905  =?UTF-8?q?=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar?=
906  =?UTF-8?q?=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20?=
907  =?UTF-8?q?bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6?=
908  =?UTF-8?q?=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6?=
909  =?UTF-8?q?=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f?=
910  =?UTF-8?q?=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar?=
911  =?UTF-8?q?=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20?=
912  =?UTF-8?q?bar?=
913 EOF
914 test_expect_success 'format-patch wraps extremely long subject (rfc2047)' '
915         rm -rf patches/ &&
916         echo content >>file &&
917         git add file &&
918         git commit -m "$M512" &&
919         git format-patch --stdout -1 >patch &&
920         sed -n "/^Subject/p; /^ /p; /^$/q" <patch >subject &&
921         test_cmp expect subject
922 '
923
924 check_author() {
925         echo content >>file &&
926         git add file &&
927         GIT_AUTHOR_NAME=$1 git commit -m author-check &&
928         git format-patch --stdout -1 >patch &&
929         sed -n "/^From: /p; /^ /p; /^$/q" <patch >actual &&
930         test_cmp expect actual
931 }
932
933 cat >expect <<'EOF'
934 From: "Foo B. Bar" <author@example.com>
935 EOF
936 test_expect_success 'format-patch quotes dot in from-headers' '
937         check_author "Foo B. Bar"
938 '
939
940 cat >expect <<'EOF'
941 From: "Foo \"The Baz\" Bar" <author@example.com>
942 EOF
943 test_expect_success 'format-patch quotes double-quote in from-headers' '
944         check_author "Foo \"The Baz\" Bar"
945 '
946
947 cat >expect <<'EOF'
948 From: =?UTF-8?q?F=C3=B6o=20Bar?= <author@example.com>
949 EOF
950 test_expect_success 'format-patch uses rfc2047-encoded from-headers when necessary' '
951         check_author "Föo Bar"
952 '
953
954 cat >expect <<'EOF'
955 From: =?UTF-8?q?F=C3=B6o=20B=2E=20Bar?= <author@example.com>
956 EOF
957 test_expect_success 'rfc2047-encoded from-headers leave no rfc822 specials' '
958         check_author "Föo B. Bar"
959 '
960
961 cat >expect <<EOF
962 From: foo_bar_foo_bar_foo_bar_foo_bar_foo_bar_foo_bar_foo_bar_foo_bar_
963  <author@example.com>
964 EOF
965 test_expect_success 'format-patch wraps moderately long from-header (ascii)' '
966         check_author "foo_bar_foo_bar_foo_bar_foo_bar_foo_bar_foo_bar_foo_bar_foo_bar_"
967 '
968
969 cat >expect <<'EOF'
970 From: Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar
971  Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo
972  Bar Foo Bar Foo Bar Foo Bar <author@example.com>
973 EOF
974 test_expect_success 'format-patch wraps extremely long from-header (ascii)' '
975         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"
976 '
977
978 cat >expect <<'EOF'
979 From: "Foo.Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar
980  Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo
981  Bar Foo Bar Foo Bar Foo Bar" <author@example.com>
982 EOF
983 test_expect_success 'format-patch wraps extremely long from-header (rfc822)' '
984         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"
985 '
986
987 cat >expect <<'EOF'
988 From: =?UTF-8?q?Fo=C3=B6=20Bar=20Foo=20Bar=20Foo=20Bar=20Foo=20Bar=20Foo?=
989  =?UTF-8?q?=20Bar=20Foo=20Bar=20Foo=20Bar=20Foo=20Bar=20Foo=20Bar=20Foo=20?=
990  =?UTF-8?q?Bar=20Foo=20Bar=20Foo=20Bar=20Foo=20Bar=20Foo=20Bar=20Foo=20Bar?=
991  =?UTF-8?q?=20Foo=20Bar=20Foo=20Bar=20Foo=20Bar=20Foo=20Bar=20Foo=20Bar=20?=
992  =?UTF-8?q?Foo=20Bar=20Foo=20Bar?= <author@example.com>
993 EOF
994 test_expect_success 'format-patch wraps extremely long from-header (rfc2047)' '
995         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"
996 '
997
998 cat >expect <<'EOF'
999 Subject: header with . in it
1000 EOF
1001 test_expect_success 'subject lines do not have 822 atom-quoting' '
1002         echo content >>file &&
1003         git add file &&
1004         git commit -m "header with . in it" &&
1005         git format-patch -k -1 --stdout >patch &&
1006         grep ^Subject: patch >actual &&
1007         test_cmp expect actual
1008 '
1009
1010 cat >expect <<'EOF'
1011 Subject: [PREFIX 1/1] header with . in it
1012 EOF
1013 test_expect_success 'subject prefixes have space prepended' '
1014         git format-patch -n -1 --stdout --subject-prefix=PREFIX >patch &&
1015         grep ^Subject: patch >actual &&
1016         test_cmp expect actual
1017 '
1018
1019 cat >expect <<'EOF'
1020 Subject: [1/1] header with . in it
1021 EOF
1022 test_expect_success 'empty subject prefix does not have extra space' '
1023         git format-patch -n -1 --stdout --subject-prefix= >patch &&
1024         grep ^Subject: patch >actual &&
1025         test_cmp expect actual
1026 '
1027
1028 test_expect_success '--from=ident notices bogus ident' '
1029         test_must_fail git format-patch -1 --stdout --from=foo >patch
1030 '
1031
1032 test_expect_success '--from=ident replaces author' '
1033         git format-patch -1 --stdout --from="Me <me@example.com>" >patch &&
1034         cat >expect <<-\EOF &&
1035         From: Me <me@example.com>
1036
1037         From: A U Thor <author@example.com>
1038
1039         EOF
1040         sed -ne "/^From:/p; /^$/p; /^---$/q" <patch >patch.head &&
1041         test_cmp expect patch.head
1042 '
1043
1044 test_expect_success '--from uses committer ident' '
1045         git format-patch -1 --stdout --from >patch &&
1046         cat >expect <<-\EOF &&
1047         From: C O Mitter <committer@example.com>
1048
1049         From: A U Thor <author@example.com>
1050
1051         EOF
1052         sed -ne "/^From:/p; /^$/p; /^---$/q" <patch >patch.head &&
1053         test_cmp expect patch.head
1054 '
1055
1056 test_expect_success '--from omits redundant in-body header' '
1057         git format-patch -1 --stdout --from="A U Thor <author@example.com>" >patch &&
1058         cat >expect <<-\EOF &&
1059         From: A U Thor <author@example.com>
1060
1061         EOF
1062         sed -ne "/^From:/p; /^$/p; /^---$/q" <patch >patch.head &&
1063         test_cmp expect patch.head
1064 '
1065
1066 test_expect_success 'in-body headers trigger content encoding' '
1067         GIT_AUTHOR_NAME="éxötìc" test_commit exotic &&
1068         test_when_finished "git reset --hard HEAD^" &&
1069         git format-patch -1 --stdout --from >patch &&
1070         cat >expect <<-\EOF &&
1071         From: C O Mitter <committer@example.com>
1072         Content-Type: text/plain; charset=UTF-8
1073
1074         From: éxötìc <author@example.com>
1075
1076         EOF
1077         sed -ne "/^From:/p; /^$/p; /^Content-Type/p; /^---$/q" <patch >patch.head &&
1078         test_cmp expect patch.head
1079 '
1080
1081 append_signoff()
1082 {
1083         C=$(git commit-tree HEAD^^{tree} -p HEAD) &&
1084         git format-patch --stdout --signoff $C^..$C >append_signoff.patch &&
1085         sed -n -e "1,/^---$/p" append_signoff.patch |
1086                 egrep -n "^Subject|Sign|^$"
1087 }
1088
1089 test_expect_success 'signoff: commit with no body' '
1090         append_signoff </dev/null >actual &&
1091         cat <<\EOF | sed "s/EOL$//" >expected &&
1092 4:Subject: [PATCH] EOL
1093 8:
1094 9:Signed-off-by: C O Mitter <committer@example.com>
1095 EOF
1096         test_cmp expected actual
1097 '
1098
1099 test_expect_success 'signoff: commit with only subject' '
1100         echo subject | append_signoff >actual &&
1101         cat >expected <<\EOF &&
1102 4:Subject: [PATCH] subject
1103 8:
1104 9:Signed-off-by: C O Mitter <committer@example.com>
1105 EOF
1106         test_cmp expected actual
1107 '
1108
1109 test_expect_success 'signoff: commit with only subject that does not end with NL' '
1110         printf subject | append_signoff >actual &&
1111         cat >expected <<\EOF &&
1112 4:Subject: [PATCH] subject
1113 8:
1114 9:Signed-off-by: C O Mitter <committer@example.com>
1115 EOF
1116         test_cmp expected actual
1117 '
1118
1119 test_expect_success 'signoff: no existing signoffs' '
1120         append_signoff <<\EOF >actual &&
1121 subject
1122
1123 body
1124 EOF
1125         cat >expected <<\EOF &&
1126 4:Subject: [PATCH] subject
1127 8:
1128 10:
1129 11:Signed-off-by: C O Mitter <committer@example.com>
1130 EOF
1131         test_cmp expected actual
1132 '
1133
1134 test_expect_success 'signoff: no existing signoffs and no trailing NL' '
1135         printf "subject\n\nbody" | append_signoff >actual &&
1136         cat >expected <<\EOF &&
1137 4:Subject: [PATCH] subject
1138 8:
1139 10:
1140 11:Signed-off-by: C O Mitter <committer@example.com>
1141 EOF
1142         test_cmp expected actual
1143 '
1144
1145 test_expect_success 'signoff: some random signoff' '
1146         append_signoff <<\EOF >actual &&
1147 subject
1148
1149 body
1150
1151 Signed-off-by: my@house
1152 EOF
1153         cat >expected <<\EOF &&
1154 4:Subject: [PATCH] subject
1155 8:
1156 10:
1157 11:Signed-off-by: my@house
1158 12:Signed-off-by: C O Mitter <committer@example.com>
1159 EOF
1160         test_cmp expected actual
1161 '
1162
1163 test_expect_success 'signoff: misc conforming footer elements' '
1164         append_signoff <<\EOF >actual &&
1165 subject
1166
1167 body
1168
1169 Signed-off-by: my@house
1170 (cherry picked from commit da39a3ee5e6b4b0d3255bfef95601890afd80709)
1171 Tested-by: Some One <someone@example.com>
1172 Bug: 1234
1173 EOF
1174         cat >expected <<\EOF &&
1175 4:Subject: [PATCH] subject
1176 8:
1177 10:
1178 11:Signed-off-by: my@house
1179 15:Signed-off-by: C O Mitter <committer@example.com>
1180 EOF
1181         test_cmp expected actual
1182 '
1183
1184 test_expect_success 'signoff: some random signoff-alike' '
1185         append_signoff <<\EOF >actual &&
1186 subject
1187
1188 body
1189 Fooled-by-me: my@house
1190 EOF
1191         cat >expected <<\EOF &&
1192 4:Subject: [PATCH] subject
1193 8:
1194 11:
1195 12:Signed-off-by: C O Mitter <committer@example.com>
1196 EOF
1197         test_cmp expected actual
1198 '
1199
1200 test_expect_success 'signoff: not really a signoff' '
1201         append_signoff <<\EOF >actual &&
1202 subject
1203
1204 I want to mention about Signed-off-by: here.
1205 EOF
1206         cat >expected <<\EOF &&
1207 4:Subject: [PATCH] subject
1208 8:
1209 9:I want to mention about Signed-off-by: here.
1210 10:
1211 11:Signed-off-by: C O Mitter <committer@example.com>
1212 EOF
1213         test_cmp expected actual
1214 '
1215
1216 test_expect_success 'signoff: not really a signoff (2)' '
1217         append_signoff <<\EOF >actual &&
1218 subject
1219
1220 My unfortunate
1221 Signed-off-by: example happens to be wrapped here.
1222 EOF
1223         cat >expected <<\EOF &&
1224 4:Subject: [PATCH] subject
1225 8:
1226 10:Signed-off-by: example happens to be wrapped here.
1227 11:
1228 12:Signed-off-by: C O Mitter <committer@example.com>
1229 EOF
1230         test_cmp expected actual
1231 '
1232
1233 test_expect_success 'signoff: valid S-o-b paragraph in the middle' '
1234         append_signoff <<\EOF >actual &&
1235 subject
1236
1237 Signed-off-by: my@house
1238 Signed-off-by: your@house
1239
1240 A lot of houses.
1241 EOF
1242         cat >expected <<\EOF &&
1243 4:Subject: [PATCH] subject
1244 8:
1245 9:Signed-off-by: my@house
1246 10:Signed-off-by: your@house
1247 11:
1248 13:
1249 14:Signed-off-by: C O Mitter <committer@example.com>
1250 EOF
1251         test_cmp expected actual
1252 '
1253
1254 test_expect_success 'signoff: the same signoff at the end' '
1255         append_signoff <<\EOF >actual &&
1256 subject
1257
1258 body
1259
1260 Signed-off-by: C O Mitter <committer@example.com>
1261 EOF
1262         cat >expected <<\EOF &&
1263 4:Subject: [PATCH] subject
1264 8:
1265 10:
1266 11:Signed-off-by: C O Mitter <committer@example.com>
1267 EOF
1268         test_cmp expected actual
1269 '
1270
1271 test_expect_success 'signoff: the same signoff at the end, no trailing NL' '
1272         printf "subject\n\nSigned-off-by: C O Mitter <committer@example.com>" |
1273                 append_signoff >actual &&
1274         cat >expected <<\EOF &&
1275 4:Subject: [PATCH] subject
1276 8:
1277 9:Signed-off-by: C O Mitter <committer@example.com>
1278 EOF
1279         test_cmp expected actual
1280 '
1281
1282 test_expect_success 'signoff: the same signoff NOT at the end' '
1283         append_signoff <<\EOF >actual &&
1284 subject
1285
1286 body
1287
1288 Signed-off-by: C O Mitter <committer@example.com>
1289 Signed-off-by: my@house
1290 EOF
1291         cat >expected <<\EOF &&
1292 4:Subject: [PATCH] subject
1293 8:
1294 10:
1295 11:Signed-off-by: C O Mitter <committer@example.com>
1296 12:Signed-off-by: my@house
1297 EOF
1298         test_cmp expected actual
1299 '
1300
1301 test_expect_success 'signoff: detect garbage in non-conforming footer' '
1302         append_signoff <<\EOF >actual &&
1303 subject
1304
1305 body
1306
1307 Tested-by: my@house
1308 Some Trash
1309 Signed-off-by: C O Mitter <committer@example.com>
1310 EOF
1311         cat >expected <<\EOF &&
1312 4:Subject: [PATCH] subject
1313 8:
1314 10:
1315 13:Signed-off-by: C O Mitter <committer@example.com>
1316 14:
1317 15:Signed-off-by: C O Mitter <committer@example.com>
1318 EOF
1319         test_cmp expected actual
1320 '
1321
1322 test_expect_success 'signoff: footer begins with non-signoff without @ sign' '
1323         append_signoff <<\EOF >actual &&
1324 subject
1325
1326 body
1327
1328 Reviewed-id: Noone
1329 Tested-by: my@house
1330 Change-id: Ideadbeef
1331 Signed-off-by: C O Mitter <committer@example.com>
1332 Bug: 1234
1333 EOF
1334         cat >expected <<\EOF &&
1335 4:Subject: [PATCH] subject
1336 8:
1337 10:
1338 14:Signed-off-by: C O Mitter <committer@example.com>
1339 EOF
1340         test_cmp expected actual
1341 '
1342
1343 test_expect_success 'format patch ignores color.ui' '
1344         test_unconfig color.ui &&
1345         git format-patch --stdout -1 >expect &&
1346         test_config color.ui always &&
1347         git format-patch --stdout -1 >actual &&
1348         test_cmp expect actual
1349 '
1350
1351 test_expect_success 'cover letter using branch description (1)' '
1352         git checkout rebuild-1 &&
1353         test_config branch.rebuild-1.description hello &&
1354         git format-patch --stdout --cover-letter master >actual &&
1355         grep hello actual >/dev/null
1356 '
1357
1358 test_expect_success 'cover letter using branch description (2)' '
1359         git checkout rebuild-1 &&
1360         test_config branch.rebuild-1.description hello &&
1361         git format-patch --stdout --cover-letter rebuild-1~2..rebuild-1 >actual &&
1362         grep hello actual >/dev/null
1363 '
1364
1365 test_expect_success 'cover letter using branch description (3)' '
1366         git checkout rebuild-1 &&
1367         test_config branch.rebuild-1.description hello &&
1368         git format-patch --stdout --cover-letter ^master rebuild-1 >actual &&
1369         grep hello actual >/dev/null
1370 '
1371
1372 test_expect_success 'cover letter using branch description (4)' '
1373         git checkout rebuild-1 &&
1374         test_config branch.rebuild-1.description hello &&
1375         git format-patch --stdout --cover-letter master.. >actual &&
1376         grep hello actual >/dev/null
1377 '
1378
1379 test_expect_success 'cover letter using branch description (5)' '
1380         git checkout rebuild-1 &&
1381         test_config branch.rebuild-1.description hello &&
1382         git format-patch --stdout --cover-letter -2 HEAD >actual &&
1383         grep hello actual >/dev/null
1384 '
1385
1386 test_expect_success 'cover letter using branch description (6)' '
1387         git checkout rebuild-1 &&
1388         test_config branch.rebuild-1.description hello &&
1389         git format-patch --stdout --cover-letter -2 >actual &&
1390         grep hello actual >/dev/null
1391 '
1392
1393 test_expect_success 'cover letter with nothing' '
1394         git format-patch --stdout --cover-letter >actual &&
1395         test_line_count = 0 actual
1396 '
1397
1398 test_expect_success 'cover letter auto' '
1399         mkdir -p tmp &&
1400         test_when_finished "rm -rf tmp;
1401                 git config --unset format.coverletter" &&
1402
1403         git config format.coverletter auto &&
1404         git format-patch -o tmp -1 >list &&
1405         test_line_count = 1 list &&
1406         git format-patch -o tmp -2 >list &&
1407         test_line_count = 3 list
1408 '
1409
1410 test_expect_success 'cover letter auto user override' '
1411         mkdir -p tmp &&
1412         test_when_finished "rm -rf tmp;
1413                 git config --unset format.coverletter" &&
1414
1415         git config format.coverletter auto &&
1416         git format-patch -o tmp --cover-letter -1 >list &&
1417         test_line_count = 2 list &&
1418         git format-patch -o tmp --cover-letter -2 >list &&
1419         test_line_count = 3 list &&
1420         git format-patch -o tmp --no-cover-letter -1 >list &&
1421         test_line_count = 1 list &&
1422         git format-patch -o tmp --no-cover-letter -2 >list &&
1423         test_line_count = 2 list
1424 '
1425
1426 test_done