3 # Copyright (c) 2006 Junio C Hamano
6 test_description
='various format-patch tests'
10 test_expect_success setup
'
12 for i in 1 2 3 4 5 6 7 8 9 10; do echo "$i"; done >file &&
16 git commit -m Initial &&
17 git checkout -b side &&
19 for i in 1 2 5 6 A B C 7 8 9 10; do echo "$i"; done >file &&
22 git commit -m "Side changes #1" &&
24 for i in D E F; do echo "$i"; done >>file &&
25 git update-index file &&
27 git commit -m "Side changes #2" &&
30 for i in 5 6 1 2 3 A 4 B C 7 8 9 10 D E F; do echo "$i"; done >file &&
31 git update-index file &&
33 git commit -m "Side changes #3 with \\n backslash-n in it." &&
35 git checkout master &&
36 git diff-tree -p C2 | git apply --index &&
38 git commit -m "Master accepts moral equivalent of #2"
42 test_expect_success
"format-patch --ignore-if-in-upstream" '
44 git format-patch --stdout master..side >patch0 &&
45 cnt=`grep "^From " patch0 | wc -l` &&
50 test_expect_success
"format-patch --ignore-if-in-upstream" '
52 git format-patch --stdout \
53 --ignore-if-in-upstream master..side >patch1 &&
54 cnt=`grep "^From " patch1 | wc -l` &&
59 test_expect_success
"format-patch result applies" '
61 git checkout -b rebuild-0 master &&
63 cnt=`git rev-list master.. | wc -l` &&
67 test_expect_success
"format-patch --ignore-if-in-upstream result applies" '
69 git checkout -b rebuild-1 master &&
71 cnt=`git rev-list master.. | wc -l` &&
75 test_expect_success
'commit did not screw up the log message' '
77 git cat-file commit side | grep "^Side .* with .* backslash-n"
81 test_expect_success
'format-patch did not screw up the log message' '
83 grep "^Subject: .*Side changes #3 with .* backslash-n" patch0 &&
84 grep "^Subject: .*Side changes #3 with .* backslash-n" patch1
88 test_expect_success
'replay did not screw up the log message' '
90 git cat-file commit rebuild-1 | grep "^Side .* with .* backslash-n"
94 test_expect_success
'extra headers' '
96 git config format.headers "To: R. E. Cipient <rcipient@example.com>
98 git config --add format.headers "Cc: S. E. Cipient <scipient@example.com>
100 git format-patch --stdout master..side > patch2 &&
101 sed -e "/^\$/q" patch2 > hdrs2 &&
102 grep "^To: R. E. Cipient <rcipient@example.com>\$" hdrs2 &&
103 grep "^Cc: S. E. Cipient <scipient@example.com>\$" hdrs2
107 test_expect_success
'extra headers without newlines' '
109 git config --replace-all format.headers "To: R. E. Cipient <rcipient@example.com>" &&
110 git config --add format.headers "Cc: S. E. Cipient <scipient@example.com>" &&
111 git format-patch --stdout master..side >patch3 &&
112 sed -e "/^\$/q" patch3 > hdrs3 &&
113 grep "^To: R. E. Cipient <rcipient@example.com>\$" hdrs3 &&
114 grep "^Cc: S. E. Cipient <scipient@example.com>\$" hdrs3
118 test_expect_success
'extra headers with multiple To:s' '
120 git config --replace-all format.headers "To: R. E. Cipient <rcipient@example.com>" &&
121 git config --add format.headers "To: S. E. Cipient <scipient@example.com>" &&
122 git format-patch --stdout master..side > patch4 &&
123 sed -e "/^\$/q" patch4 > hdrs4 &&
124 grep "^To: R. E. Cipient <rcipient@example.com>,\$" hdrs4 &&
125 grep "^ *S. E. Cipient <scipient@example.com>\$" hdrs4
128 test_expect_success
'additional command line cc' '
130 git config --replace-all format.headers "Cc: R. E. Cipient <rcipient@example.com>" &&
131 git format-patch --cc="S. E. Cipient <scipient@example.com>" --stdout master..side | sed -e "/^\$/q" >patch5 &&
132 grep "^Cc: R. E. Cipient <rcipient@example.com>,\$" patch5 &&
133 grep "^ *S. E. Cipient <scipient@example.com>\$" patch5
136 test_expect_success
'command line headers' '
138 git config --unset-all format.headers &&
139 git format-patch --add-header="Cc: R. E. Cipient <rcipient@example.com>" --stdout master..side | sed -e "/^\$/q" >patch6 &&
140 grep "^Cc: R. E. Cipient <rcipient@example.com>\$" patch6
143 test_expect_success
'configuration headers and command line headers' '
145 git config --replace-all format.headers "Cc: R. E. Cipient <rcipient@example.com>" &&
146 git format-patch --add-header="Cc: S. E. Cipient <scipient@example.com>" --stdout master..side | sed -e "/^\$/q" >patch7 &&
147 grep "^Cc: R. E. Cipient <rcipient@example.com>,\$" patch7 &&
148 grep "^ *S. E. Cipient <scipient@example.com>\$" patch7
151 test_expect_success
'command line To: header' '
153 git config --unset-all format.headers &&
154 git format-patch --to="R. E. Cipient <rcipient@example.com>" --stdout master..side | sed -e "/^\$/q" >patch8 &&
155 grep "^To: R. E. Cipient <rcipient@example.com>\$" patch8
158 test_expect_success
'configuration To: header' '
160 git config format.to "R. E. Cipient <rcipient@example.com>" &&
161 git format-patch --stdout master..side | sed -e "/^\$/q" >patch9 &&
162 grep "^To: R. E. Cipient <rcipient@example.com>\$" patch9
165 test_expect_success
'--no-to overrides config.to' '
167 git config --replace-all format.to \
168 "R. E. Cipient <rcipient@example.com>" &&
169 git format-patch --no-to --stdout master..side |
170 sed -e "/^\$/q" >patch10 &&
171 ! grep "^To: R. E. Cipient <rcipient@example.com>\$" patch10
174 test_expect_success
'--no-to and --to replaces config.to' '
176 git config --replace-all format.to \
177 "Someone <someone@out.there>" &&
178 git format-patch --no-to --to="Someone Else <else@out.there>" \
179 --stdout master..side |
180 sed -e "/^\$/q" >patch11 &&
181 ! grep "^To: Someone <someone@out.there>\$" patch11 &&
182 grep "^To: Someone Else <else@out.there>\$" patch11
185 test_expect_success
'--no-cc overrides config.cc' '
187 git config --replace-all format.cc \
188 "C. E. Cipient <rcipient@example.com>" &&
189 git format-patch --no-cc --stdout master..side |
190 sed -e "/^\$/q" >patch12 &&
191 ! grep "^Cc: C. E. Cipient <rcipient@example.com>\$" patch12
194 test_expect_success
'--no-add-headers overrides config.headers' '
196 git config --replace-all format.headers \
197 "Header1: B. E. Cipient <rcipient@example.com>" &&
198 git format-patch --no-add-headers --stdout master..side |
199 sed -e "/^\$/q" >patch13 &&
200 ! grep "^Header1: B. E. Cipient <rcipient@example.com>\$" patch13
203 test_expect_success
'multiple files' '
207 git format-patch -o patches/ master &&
208 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
214 (git format-patch
--stdout "$@"; echo $?
> status.out
) |
215 # Prints everything between the Message-ID and In-Reply-To,
216 # and replaces all Message-ID-lookalikes by a sequence number
218 if (/^(message-id|references|in-reply-to)/i) {
224 $h{$1}=$i++ if (/<([^>]+)>/ and !exists $h{$1});
225 for $k (keys %h) {s/$k/$h{$k}/};
228 print "---\n" if /^From /i;
230 test 0 = "$(cat status.out)" &&
231 test_cmp
"$expect" actual
234 cat >> expect.no-threading
<<EOF
240 test_expect_success
'no threading' '
242 check_threading expect.no-threading master
245 cat > expect.thread
<<EOF
258 test_expect_success
'thread' '
259 check_threading expect.thread --thread master
262 cat > expect.in-reply-to
<<EOF
277 test_expect_success
'thread in-reply-to' '
278 check_threading expect.in-reply-to --in-reply-to="<test.message>" \
282 cat > expect.cover-letter
<<EOF
299 test_expect_success
'thread cover-letter' '
300 check_threading expect.cover-letter --cover-letter --thread master
303 cat > expect.cl-irt
<<EOF
325 test_expect_success
'thread cover-letter in-reply-to' '
326 check_threading expect.cl-irt --cover-letter \
327 --in-reply-to="<test.message>" --thread master
330 test_expect_success
'thread explicit shallow' '
331 check_threading expect.cl-irt --cover-letter \
332 --in-reply-to="<test.message>" --thread=shallow master
335 cat > expect.deep
<<EOF
349 test_expect_success
'thread deep' '
350 check_threading expect.deep --thread=deep master
353 cat > expect.deep-irt
<<EOF
371 test_expect_success
'thread deep in-reply-to' '
372 check_threading expect.deep-irt --thread=deep \
373 --in-reply-to="<test.message>" master
376 cat > expect.deep-cl
<<EOF
396 test_expect_success
'thread deep cover-letter' '
397 check_threading expect.deep-cl --cover-letter --thread=deep master
400 cat > expect.deep-cl-irt
<<EOF
425 test_expect_success
'thread deep cover-letter in-reply-to' '
426 check_threading expect.deep-cl-irt --cover-letter \
427 --in-reply-to="<test.message>" --thread=deep master
430 test_expect_success
'thread via config' '
431 git config format.thread true &&
432 check_threading expect.thread master
435 test_expect_success
'thread deep via config' '
436 git config format.thread deep &&
437 check_threading expect.deep master
440 test_expect_success
'thread config + override' '
441 git config format.thread deep &&
442 check_threading expect.thread --thread master
445 test_expect_success
'thread config + --no-thread' '
446 git config format.thread deep &&
447 check_threading expect.no-threading --no-thread master
450 test_expect_success
'excessive subject' '
454 for i in 5 6 1 2 3 A 4 B C 7 8 9 10 D E F; do echo "$i"; done >>file &&
455 git update-index file &&
456 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." &&
457 git format-patch -o patches/ master..side &&
458 ls patches/0004-This-is-an-excessively-long-subject-line-for-a-messa.patch
461 test_expect_success
'cover-letter inherits diff options' '
465 git format-patch --cover-letter -1 &&
466 ! grep "file => foo .* 0 *\$" 0000-cover-letter.patch &&
467 git format-patch --cover-letter -1 -M &&
468 grep "file => foo .* 0 *\$" 0000-cover-letter.patch
473 This is an excessively long subject line for a message due to the
474 habit some projects have of not having a short, one-line subject at
475 the start of the commit message, but rather sticking a whole
476 paragraph right at the start as the only thing in the commit
477 message. It had better not become the filename for the patch.
482 test_expect_success
'shortlog of cover-letter wraps overly-long onelines' '
484 git format-patch --cover-letter -2 &&
485 sed -e "1,/A U Thor/d" -e "/^\$/q" < 0000-cover-letter.patch > output &&
486 test_cmp expect output
492 file | 16 ++++++++++++++++
493 1 files changed, 16 insertions(+), 0 deletions(-)
495 diff --git a/file b/file
496 index 40f36c6..2dc5c23 100644
507 test_expect_success
'format-patch respects -U' '
509 git format-patch -U4 -2 &&
510 sed -e "1,/^\$/d" -e "/^+5/q" < 0001-This-is-an-excessively-long-subject-line-for-a-messa.patch > output &&
511 test_cmp expect output
517 diff --git a/file b/file
518 index 40f36c6..2dc5c23 100644
528 test_expect_success
'format-patch -p suppresses stat' '
530 git format-patch -p -2 &&
531 sed -e "1,/^\$/d" -e "/^+5/q" < 0001-This-is-an-excessively-long-subject-line-for-a-messa.patch > output &&
532 test_cmp expect output
536 test_expect_success
'format-patch from a subdirectory (1)' '
547 echo "Oops? $filename"
554 test_expect_success
'format-patch from a subdirectory (2)' '
559 git format-patch -1 -o ..
565 echo "Oops? $filename"
569 basename=$(expr "$filename" : ".*/\(.*\)") &&
570 test -f "sub/$basename"
573 test_expect_success
'format-patch from a subdirectory (3)' '
579 git format-patch -1 -o "$TRASH_DIRECTORY"
581 basename=$(expr "$filename" : ".*/\(.*\)") &&
585 test_expect_success
'format-patch --in-reply-to' '
586 git format-patch -1 --stdout --in-reply-to "baz@foo.bar" > patch8 &&
587 grep "^In-Reply-To: <baz@foo.bar>" patch8 &&
588 grep "^References: <baz@foo.bar>" patch8
591 test_expect_success
'format-patch --signoff' '
592 git format-patch -1 --signoff --stdout |
593 grep "^Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>"
596 echo "fatal: --name-only does not make sense" > expect.name-only
597 echo "fatal: --name-status does not make sense" > expect.name-status
598 echo "fatal: --check does not make sense" > expect.check
600 test_expect_success
'options no longer allowed for format-patch' '
601 test_must_fail git format-patch --name-only 2> output &&
602 test_cmp expect.name-only output &&
603 test_must_fail git format-patch --name-status 2> output &&
604 test_cmp expect.name-status output &&
605 test_must_fail git format-patch --check 2> output &&
606 test_cmp expect.check output'
608 test_expect_success
'format-patch --numstat should produce a patch' '
609 git format-patch --numstat --stdout master..side > output &&
610 test 6 = $(grep "^diff --git a/" output | wc -l)'
612 test_expect_success
'format-patch -- <path>' '
613 git format-patch master..side -- file 2>error &&
614 ! grep "Use .--" error
617 test_expect_success
'format-patch --ignore-if-in-upstream HEAD' '
618 git format-patch --ignore-if-in-upstream HEAD