3 # Copyright (c) 2006 Junio C Hamano
6 test_description='various format-patch tests'
9 . "$TEST_DIRECTORY"/lib-terminal.sh
11 test_expect_success setup '
13 for i in 1 2 3 4 5 6 7 8 9 10; do echo "$i"; done >file &&
17 git commit -m Initial &&
18 git checkout -b side &&
20 for i in 1 2 5 6 A B C 7 8 9 10; do echo "$i"; done >file &&
23 git commit -m "Side changes #1" &&
25 for i in D E F; do echo "$i"; done >>file &&
26 git update-index file &&
28 git commit -m "Side changes #2" &&
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 &&
34 git commit -m "Side changes #3 with \\n backslash-n in it." &&
36 git checkout master &&
37 git diff-tree -p C2 | git apply --index &&
39 git commit -m "Master accepts moral equivalent of #2"
43 test_expect_success "format-patch --ignore-if-in-upstream" '
45 git format-patch --stdout master..side >patch0 &&
46 cnt=`grep "^From " patch0 | wc -l` &&
51 test_expect_success "format-patch --ignore-if-in-upstream" '
53 git format-patch --stdout \
54 --ignore-if-in-upstream master..side >patch1 &&
55 cnt=`grep "^From " patch1 | wc -l` &&
60 test_expect_success "format-patch doesn't consider merge commits" '
62 git checkout -b slave master &&
63 echo "Another line" >>file &&
65 git commit -am "Slave change #1" &&
66 echo "Yet another line" >>file &&
68 git commit -am "Slave change #2" &&
69 git checkout -b merger master &&
71 git merge --no-ff slave &&
72 cnt=`git format-patch -3 --stdout | grep "^From " | wc -l` &&
76 test_expect_success "format-patch result applies" '
78 git checkout -b rebuild-0 master &&
80 cnt=`git rev-list master.. | wc -l` &&
84 test_expect_success "format-patch --ignore-if-in-upstream result applies" '
86 git checkout -b rebuild-1 master &&
88 cnt=`git rev-list master.. | wc -l` &&
92 test_expect_success 'commit did not screw up the log message' '
94 git cat-file commit side | grep "^Side .* with .* backslash-n"
98 test_expect_success 'format-patch did not screw up the log message' '
100 grep "^Subject: .*Side changes #3 with .* backslash-n" patch0 &&
101 grep "^Subject: .*Side changes #3 with .* backslash-n" patch1
105 test_expect_success 'replay did not screw up the log message' '
107 git cat-file commit rebuild-1 | grep "^Side .* with .* backslash-n"
111 test_expect_success 'extra headers' '
113 git config format.headers "To: R E Cipient <rcipient@example.com>
115 git config --add format.headers "Cc: S E Cipient <scipient@example.com>
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
124 test_expect_success 'extra headers without newlines' '
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
135 test_expect_success 'extra headers with multiple To:s' '
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
145 test_expect_success 'additional command line cc (ascii)' '
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
153 test_expect_failure 'additional command line cc (rfc822)' '
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
161 test_expect_success 'command line headers' '
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
168 test_expect_success 'configuration headers and command line headers' '
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
176 test_expect_success 'command line To: header (ascii)' '
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
183 test_expect_failure 'command line To: header (rfc822)' '
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
189 test_expect_failure 'command line To: header (rfc2047)' '
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
195 test_expect_success 'configuration To: header (ascii)' '
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
202 test_expect_failure 'configuration To: header (rfc822)' '
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
209 test_expect_failure 'configuration To: header (rfc2047)' '
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
216 # check_patch <patch>: Verify that <patch> looks like a half-sane
217 # patch email to avoid a false positive with !grep
219 grep -e "^From:" "$1" &&
220 grep -e "^Date:" "$1" &&
221 grep -e "^Subject:" "$1"
224 test_expect_success '--no-to overrides config.to' '
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
234 test_expect_success '--no-to and --to replaces config.to' '
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
246 test_expect_success '--no-cc overrides config.cc' '
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
256 test_expect_success '--no-add-header overrides config.headers' '
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
266 test_expect_success 'multiple files' '
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
277 (git format-patch --stdout "$@"; echo $? > status.out) |
278 # Prints everything between the Message-ID and In-Reply-To,
279 # and replaces all Message-ID-lookalikes by a sequence number
281 if (/^(message-id|references|in-reply-to)/i) {
287 $h{$1}=$i++ if (/<([^>]+)>/ and !exists $h{$1});
288 for $k (keys %h) {s/$k/$h{$k}/};
291 print "---\n" if /^From /i;
293 test 0 = "$(cat status.out)" &&
294 test_cmp "$expect" actual
297 cat >> expect.no-threading <<EOF
303 test_expect_success 'no threading' '
305 check_threading expect.no-threading master
308 cat > expect.thread <<EOF
321 test_expect_success 'thread' '
322 check_threading expect.thread --thread master
325 cat > expect.in-reply-to <<EOF
340 test_expect_success 'thread in-reply-to' '
341 check_threading expect.in-reply-to --in-reply-to="<test.message>" \
345 cat > expect.cover-letter <<EOF
362 test_expect_success 'thread cover-letter' '
363 check_threading expect.cover-letter --cover-letter --thread master
366 cat > expect.cl-irt <<EOF
388 test_expect_success 'thread cover-letter in-reply-to' '
389 check_threading expect.cl-irt --cover-letter \
390 --in-reply-to="<test.message>" --thread master
393 test_expect_success 'thread explicit shallow' '
394 check_threading expect.cl-irt --cover-letter \
395 --in-reply-to="<test.message>" --thread=shallow master
398 cat > expect.deep <<EOF
412 test_expect_success 'thread deep' '
413 check_threading expect.deep --thread=deep master
416 cat > expect.deep-irt <<EOF
434 test_expect_success 'thread deep in-reply-to' '
435 check_threading expect.deep-irt --thread=deep \
436 --in-reply-to="<test.message>" master
439 cat > expect.deep-cl <<EOF
459 test_expect_success 'thread deep cover-letter' '
460 check_threading expect.deep-cl --cover-letter --thread=deep master
463 cat > expect.deep-cl-irt <<EOF
488 test_expect_success 'thread deep cover-letter in-reply-to' '
489 check_threading expect.deep-cl-irt --cover-letter \
490 --in-reply-to="<test.message>" --thread=deep master
493 test_expect_success 'thread via config' '
494 test_config format.thread true &&
495 check_threading expect.thread master
498 test_expect_success 'thread deep via config' '
499 test_config format.thread deep &&
500 check_threading expect.deep master
503 test_expect_success 'thread config + override' '
504 test_config format.thread deep &&
505 check_threading expect.thread --thread master
508 test_expect_success 'thread config + --no-thread' '
509 test_config format.thread deep &&
510 check_threading expect.no-threading --no-thread master
513 test_expect_success 'excessive subject' '
517 for i in 5 6 1 2 3 A 4 B C 7 8 9 10 D E F; do echo "$i"; done >>file &&
518 git update-index file &&
519 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." &&
520 git format-patch -o patches/ master..side &&
521 ls patches/0004-This-is-an-excessively-long-subject-line-for-a-messa.patch
524 test_expect_success 'cover-letter inherits diff options' '
528 git format-patch --cover-letter -1 &&
529 check_patch 0000-cover-letter.patch &&
530 ! grep "file => foo .* 0 *\$" 0000-cover-letter.patch &&
531 git format-patch --cover-letter -1 -M &&
532 grep "file => foo .* 0 *\$" 0000-cover-letter.patch
537 This is an excessively long subject line for a message due to the
538 habit some projects have of not having a short, one-line subject at
539 the start of the commit message, but rather sticking a whole
540 paragraph right at the start as the only thing in the commit
541 message. It had better not become the filename for the patch.
546 test_expect_success 'shortlog of cover-letter wraps overly-long onelines' '
548 git format-patch --cover-letter -2 &&
549 sed -e "1,/A U Thor/d" -e "/^\$/q" < 0000-cover-letter.patch > output &&
550 test_cmp expect output
555 index 40f36c6..2dc5c23 100644
566 test_expect_success 'format-patch respects -U' '
568 git format-patch -U4 -2 &&
569 sed -e "1,/^diff/d" -e "/^+5/q" \
570 <0001-This-is-an-excessively-long-subject-line-for-a-messa.patch \
572 test_cmp expect output
578 diff --git a/file b/file
579 index 40f36c6..2dc5c23 100644
589 test_expect_success 'format-patch -p suppresses stat' '
591 git format-patch -p -2 &&
592 sed -e "1,/^\$/d" -e "/^+5/q" < 0001-This-is-an-excessively-long-subject-line-for-a-messa.patch > output &&
593 test_cmp expect output
597 test_expect_success 'format-patch from a subdirectory (1)' '
608 echo "Oops? $filename"
615 test_expect_success 'format-patch from a subdirectory (2)' '
620 git format-patch -1 -o ..
626 echo "Oops? $filename"
630 basename=$(expr "$filename" : ".*/\(.*\)") &&
631 test -f "sub/$basename"
634 test_expect_success 'format-patch from a subdirectory (3)' '
640 git format-patch -1 -o "$TRASH_DIRECTORY"
642 basename=$(expr "$filename" : ".*/\(.*\)") &&
646 test_expect_success 'format-patch --in-reply-to' '
647 git format-patch -1 --stdout --in-reply-to "baz@foo.bar" > patch8 &&
648 grep "^In-Reply-To: <baz@foo.bar>" patch8 &&
649 grep "^References: <baz@foo.bar>" patch8
652 test_expect_success 'format-patch --signoff' '
653 git format-patch -1 --signoff --stdout >out &&
654 grep "^Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>" out
657 test_expect_success 'format-patch --notes --signoff' '
658 git notes --ref test add -m "test message" HEAD &&
659 git format-patch -1 --signoff --stdout --notes=test >out &&
660 # Three dashes must come after S-o-b
661 ! sed "/^Signed-off-by: /q" out | grep "test message" &&
662 sed "1,/^Signed-off-by: /d" out | grep "test message" &&
663 # Notes message must come after three dashes
664 ! sed "/^---$/q" out | grep "test message" &&
665 sed "1,/^---$/d" out | grep "test message"
668 echo "fatal: --name-only does not make sense" > expect.name-only
669 echo "fatal: --name-status does not make sense" > expect.name-status
670 echo "fatal: --check does not make sense" > expect.check
672 test_expect_success 'options no longer allowed for format-patch' '
673 test_must_fail git format-patch --name-only 2> output &&
674 test_i18ncmp expect.name-only output &&
675 test_must_fail git format-patch --name-status 2> output &&
676 test_i18ncmp expect.name-status output &&
677 test_must_fail git format-patch --check 2> output &&
678 test_i18ncmp expect.check output'
680 test_expect_success 'format-patch --numstat should produce a patch' '
681 git format-patch --numstat --stdout master..side > output &&
682 test 6 = $(grep "^diff --git a/" output | wc -l)'
684 test_expect_success 'format-patch -- <path>' '
685 git format-patch master..side -- file 2>error &&
686 ! grep "Use .--" error
689 test_expect_success 'format-patch --ignore-if-in-upstream HEAD' '
690 git format-patch --ignore-if-in-upstream HEAD
693 test_expect_success 'format-patch --signature' '
694 git format-patch --stdout --signature="my sig" -1 >output &&
698 test_expect_success 'format-patch with format.signature config' '
699 git config format.signature "config sig" &&
700 git format-patch --stdout -1 >output &&
701 grep "config sig" output
704 test_expect_success 'format-patch --signature overrides format.signature' '
705 git config format.signature "config sig" &&
706 git format-patch --stdout --signature="overrides" -1 >output &&
707 ! grep "config sig" output &&
708 grep "overrides" output
711 test_expect_success 'format-patch --no-signature ignores format.signature' '
712 git config format.signature "config sig" &&
713 git format-patch --stdout --signature="my sig" --no-signature \
715 check_patch output &&
716 ! grep "config sig" output &&
717 ! grep "my sig" output &&
718 ! grep "^-- \$" output
721 test_expect_success 'format-patch --signature --cover-letter' '
722 git config --unset-all format.signature &&
723 git format-patch --stdout --signature="my sig" --cover-letter \
725 grep "my sig" output &&
726 test 2 = $(grep "my sig" output | wc -l)
729 test_expect_success 'format.signature="" supresses signatures' '
730 git config format.signature "" &&
731 git format-patch --stdout -1 >output &&
732 check_patch output &&
733 ! grep "^-- \$" output
736 test_expect_success 'format-patch --no-signature supresses signatures' '
737 git config --unset-all format.signature &&
738 git format-patch --stdout --no-signature -1 >output &&
739 check_patch output &&
740 ! grep "^-- \$" output
743 test_expect_success 'format-patch --signature="" supresses signatures' '
744 git format-patch --stdout --signature="" -1 >output &&
745 check_patch output &&
746 ! grep "^-- \$" output
749 test_expect_success TTY 'format-patch --stdout paginates' '
752 GIT_PAGER="wc >pager_used" &&
754 test_terminal git format-patch --stdout --all
756 test_path_is_file pager_used
759 test_expect_success TTY 'format-patch --stdout pagination can be disabled' '
762 GIT_PAGER="wc >pager_used" &&
764 test_terminal git --no-pager format-patch --stdout --all &&
765 test_terminal git -c "pager.format-patch=false" format-patch --stdout --all
767 test_path_is_missing pager_used &&
768 test_path_is_missing .git/pager_used
771 test_expect_success 'format-patch handles multi-line subjects' '
773 echo content >>file &&
774 for i in one two three; do echo $i; done >msg &&
777 git format-patch -o patches -1 &&
778 grep ^Subject: patches/0001-one.patch >actual &&
779 echo "Subject: [PATCH] one two three" >expect &&
780 test_cmp expect actual
783 test_expect_success 'format-patch handles multi-line encoded subjects' '
785 echo content >>file &&
786 for i in en två tre; do echo $i; done >msg &&
789 git format-patch -o patches -1 &&
790 grep ^Subject: patches/0001-en.patch >actual &&
791 echo "Subject: [PATCH] =?UTF-8?q?en=20tv=C3=A5=20tre?=" >expect &&
792 test_cmp expect actual
796 M64=$M8$M8$M8$M8$M8$M8$M8$M8
797 M512=$M64$M64$M64$M64$M64$M64$M64$M64
799 Subject: [PATCH] foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo
800 bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar
801 foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo
802 bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar
803 foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo
804 bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar
805 foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar
807 test_expect_success 'format-patch wraps extremely long subject (ascii)' '
808 echo content >>file &&
810 git commit -m "$M512" &&
811 git format-patch --stdout -1 >patch &&
812 sed -n "/^Subject/p; /^ /p; /^$/q" <patch >subject &&
813 test_cmp expect subject
817 M64=$M8$M8$M8$M8$M8$M8$M8$M8
818 M512=$M64$M64$M64$M64$M64$M64$M64$M64
820 Subject: [PATCH] =?UTF-8?q?f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f?=
821 =?UTF-8?q?=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar?=
822 =?UTF-8?q?=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20?=
823 =?UTF-8?q?bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6?=
824 =?UTF-8?q?=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3?=
825 =?UTF-8?q?=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6?=
826 =?UTF-8?q?=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3?=
827 =?UTF-8?q?=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f?=
828 =?UTF-8?q?=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar?=
829 =?UTF-8?q?=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20?=
830 =?UTF-8?q?bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6?=
831 =?UTF-8?q?=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3?=
832 =?UTF-8?q?=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6?=
833 =?UTF-8?q?=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3?=
834 =?UTF-8?q?=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f?=
835 =?UTF-8?q?=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar?=
836 =?UTF-8?q?=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20?=
837 =?UTF-8?q?bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6?=
838 =?UTF-8?q?=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3?=
839 =?UTF-8?q?=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6?=
840 =?UTF-8?q?=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3?=
841 =?UTF-8?q?=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f?=
842 =?UTF-8?q?=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar?=
844 test_expect_success 'format-patch wraps extremely long subject (rfc2047)' '
846 echo content >>file &&
848 git commit -m "$M512" &&
849 git format-patch --stdout -1 >patch &&
850 sed -n "/^Subject/p; /^ /p; /^$/q" <patch >subject &&
851 test_cmp expect subject
855 echo content >>file &&
857 GIT_AUTHOR_NAME=$1 git commit -m author-check &&
858 git format-patch --stdout -1 >patch &&
859 sed -n "/^From: /p; /^ /p; /^$/q" <patch >actual &&
860 test_cmp expect actual
864 From: "Foo B. Bar" <author@example.com>
866 test_expect_success 'format-patch quotes dot in from-headers' '
867 check_author "Foo B. Bar"
871 From: "Foo \"The Baz\" Bar" <author@example.com>
873 test_expect_success 'format-patch quotes double-quote in from-headers' '
874 check_author "Foo \"The Baz\" Bar"
878 From: =?UTF-8?q?F=C3=B6o=20Bar?= <author@example.com>
880 test_expect_success 'format-patch uses rfc2047-encoded from-headers when necessary' '
881 check_author "Föo Bar"
885 From: =?UTF-8?q?F=C3=B6o=20B=2E=20Bar?= <author@example.com>
887 test_expect_success 'rfc2047-encoded from-headers leave no rfc822 specials' '
888 check_author "Föo B. Bar"
892 From: foo_bar_foo_bar_foo_bar_foo_bar_foo_bar_foo_bar_foo_bar_foo_bar_
895 test_expect_success 'format-patch wraps moderately long from-header (ascii)' '
896 check_author "foo_bar_foo_bar_foo_bar_foo_bar_foo_bar_foo_bar_foo_bar_foo_bar_"
900 From: Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar
901 Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo
902 Bar Foo Bar Foo Bar Foo Bar <author@example.com>
904 test_expect_success 'format-patch wraps extremely long from-header (ascii)' '
905 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"
909 From: "Foo.Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar
910 Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo
911 Bar Foo Bar Foo Bar Foo Bar" <author@example.com>
913 test_expect_success 'format-patch wraps extremely long from-header (rfc822)' '
914 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"
918 From: =?UTF-8?q?Fo=C3=B6=20Bar=20Foo=20Bar=20Foo=20Bar=20Foo=20Bar=20Foo?=
919 =?UTF-8?q?=20Bar=20Foo=20Bar=20Foo=20Bar=20Foo=20Bar=20Foo=20Bar=20Foo=20?=
920 =?UTF-8?q?Bar=20Foo=20Bar=20Foo=20Bar=20Foo=20Bar=20Foo=20Bar=20Foo=20Bar?=
921 =?UTF-8?q?=20Foo=20Bar=20Foo=20Bar=20Foo=20Bar=20Foo=20Bar=20Foo=20Bar=20?=
922 =?UTF-8?q?Foo=20Bar=20Foo=20Bar?= <author@example.com>
924 test_expect_success 'format-patch wraps extremely long from-header (rfc2047)' '
925 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"
929 Subject: header with . in it
931 test_expect_success 'subject lines do not have 822 atom-quoting' '
932 echo content >>file &&
934 git commit -m "header with . in it" &&
935 git format-patch -k -1 --stdout >patch &&
936 grep ^Subject: patch >actual &&
937 test_cmp expect actual
941 Subject: [PREFIX 1/1] header with . in it
943 test_expect_success 'subject prefixes have space prepended' '
944 git format-patch -n -1 --stdout --subject-prefix=PREFIX >patch &&
945 grep ^Subject: patch >actual &&
946 test_cmp expect actual
950 Subject: [1/1] header with . in it
952 test_expect_success 'empty subject prefix does not have extra space' '
953 git format-patch -n -1 --stdout --subject-prefix= >patch &&
954 grep ^Subject: patch >actual &&
955 test_cmp expect actual
958 test_expect_success 'format patch ignores color.ui' '
959 test_unconfig color.ui &&
960 git format-patch --stdout -1 >expect &&
961 test_config color.ui always &&
962 git format-patch --stdout -1 >actual &&
963 test_cmp expect actual
968 C=$(git commit-tree HEAD^^{tree} -p HEAD) &&
969 git format-patch --stdout --signoff $C^..$C >append_signoff.patch &&
970 sed -n -e "1,/^---$/p" append_signoff.patch |
971 egrep -n "^Subject|Sign|^$"
974 test_expect_success 'signoff: commit with no body' '
975 append_signoff </dev/null >actual &&
976 cat <<\EOF | sed "s/EOL$//" >expected &&
977 4:Subject: [PATCH] EOL
979 9:Signed-off-by: C O Mitter <committer@example.com>
981 test_cmp expected actual
984 test_expect_success 'signoff: commit with only subject' '
985 echo subject | append_signoff >actual &&
986 cat >expected <<\EOF &&
987 4:Subject: [PATCH] subject
989 9:Signed-off-by: C O Mitter <committer@example.com>
991 test_cmp expected actual
994 test_expect_success 'signoff: commit with only subject that does not end with NL' '
995 printf subject | append_signoff >actual &&
996 cat >expected <<\EOF &&
997 4:Subject: [PATCH] subject
999 9:Signed-off-by: C O Mitter <committer@example.com>
1001 test_cmp expected actual
1004 test_expect_success 'signoff: no existing signoffs' '
1005 append_signoff <<\EOF >actual &&
1010 cat >expected <<\EOF &&
1011 4:Subject: [PATCH] subject
1014 11:Signed-off-by: C O Mitter <committer@example.com>
1016 test_cmp expected actual
1019 test_expect_success 'signoff: no existing signoffs and no trailing NL' '
1020 printf "subject\n\nbody" | append_signoff >actual &&
1021 cat >expected <<\EOF &&
1022 4:Subject: [PATCH] subject
1025 11:Signed-off-by: C O Mitter <committer@example.com>
1027 test_cmp expected actual
1030 test_expect_success 'signoff: some random signoff' '
1031 append_signoff <<\EOF >actual &&
1036 Signed-off-by: my@house
1038 cat >expected <<\EOF &&
1039 4:Subject: [PATCH] subject
1042 11:Signed-off-by: my@house
1043 12:Signed-off-by: C O Mitter <committer@example.com>
1045 test_cmp expected actual
1048 test_expect_success 'signoff: misc conforming footer elements' '
1049 append_signoff <<\EOF >actual &&
1054 Signed-off-by: my@house
1055 (cherry picked from commit da39a3ee5e6b4b0d3255bfef95601890afd80709)
1056 Tested-by: Some One <someone@example.com>
1059 cat >expected <<\EOF &&
1060 4:Subject: [PATCH] subject
1063 11:Signed-off-by: my@house
1064 15:Signed-off-by: C O Mitter <committer@example.com>
1066 test_cmp expected actual
1069 test_expect_success 'signoff: some random signoff-alike' '
1070 append_signoff <<\EOF >actual &&
1074 Fooled-by-me: my@house
1076 cat >expected <<\EOF &&
1077 4:Subject: [PATCH] subject
1080 12:Signed-off-by: C O Mitter <committer@example.com>
1082 test_cmp expected actual
1085 test_expect_success 'signoff: not really a signoff' '
1086 append_signoff <<\EOF >actual &&
1089 I want to mention about Signed-off-by: here.
1091 cat >expected <<\EOF &&
1092 4:Subject: [PATCH] subject
1094 9:I want to mention about Signed-off-by: here.
1096 11:Signed-off-by: C O Mitter <committer@example.com>
1098 test_cmp expected actual
1101 test_expect_success 'signoff: not really a signoff (2)' '
1102 append_signoff <<\EOF >actual &&
1106 Signed-off-by: example happens to be wrapped here.
1108 cat >expected <<\EOF &&
1109 4:Subject: [PATCH] subject
1111 10:Signed-off-by: example happens to be wrapped here.
1113 12:Signed-off-by: C O Mitter <committer@example.com>
1115 test_cmp expected actual
1118 test_expect_success 'signoff: valid S-o-b paragraph in the middle' '
1119 append_signoff <<\EOF >actual &&
1122 Signed-off-by: my@house
1123 Signed-off-by: your@house
1127 cat >expected <<\EOF &&
1128 4:Subject: [PATCH] subject
1130 9:Signed-off-by: my@house
1131 10:Signed-off-by: your@house
1134 14:Signed-off-by: C O Mitter <committer@example.com>
1136 test_cmp expected actual
1139 test_expect_success 'signoff: the same signoff at the end' '
1140 append_signoff <<\EOF >actual &&
1145 Signed-off-by: C O Mitter <committer@example.com>
1147 cat >expected <<\EOF &&
1148 4:Subject: [PATCH] subject
1151 11:Signed-off-by: C O Mitter <committer@example.com>
1153 test_cmp expected actual
1156 test_expect_success 'signoff: the same signoff at the end, no trailing NL' '
1157 printf "subject\n\nSigned-off-by: C O Mitter <committer@example.com>" |
1158 append_signoff >actual &&
1159 cat >expected <<\EOF &&
1160 4:Subject: [PATCH] subject
1162 9:Signed-off-by: C O Mitter <committer@example.com>
1164 test_cmp expected actual
1167 test_expect_success 'signoff: the same signoff NOT at the end' '
1168 append_signoff <<\EOF >actual &&
1173 Signed-off-by: C O Mitter <committer@example.com>
1174 Signed-off-by: my@house
1176 cat >expected <<\EOF &&
1177 4:Subject: [PATCH] subject
1180 11:Signed-off-by: C O Mitter <committer@example.com>
1181 12:Signed-off-by: my@house
1183 test_cmp expected actual
1186 test_expect_success 'signoff: detect garbage in non-conforming footer' '
1187 append_signoff <<\EOF >actual &&
1194 Signed-off-by: C O Mitter <committer@example.com>
1196 cat >expected <<\EOF &&
1197 4:Subject: [PATCH] subject
1200 13:Signed-off-by: C O Mitter <committer@example.com>
1202 15:Signed-off-by: C O Mitter <committer@example.com>
1204 test_cmp expected actual
1207 test_expect_success 'signoff: footer begins with non-signoff without @ sign' '
1208 append_signoff <<\EOF >actual &&
1215 Change-id: Ideadbeef
1216 Signed-off-by: C O Mitter <committer@example.com>
1219 cat >expected <<\EOF &&
1220 4:Subject: [PATCH] subject
1223 14:Signed-off-by: C O Mitter <committer@example.com>
1225 test_cmp expected actual