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 &&
15 git commit -m Initial &&
16 git checkout -b side &&
18 for i in 1 2 5 6 A B C 7 8 9 10; do echo "$i"; done >file &&
20 git commit -m "Side changes #1" &&
22 for i in D E F; do echo "$i"; done >>file &&
23 git update-index file &&
24 git commit -m "Side changes #2" &&
27 for i in 5 6 1 2 3 A 4 B C 7 8 9 10 D E F; do echo "$i"; done >file &&
28 git update-index file &&
29 git commit -m "Side changes #3 with \\n backslash-n in it." &&
31 git checkout master &&
32 git diff-tree -p C2 | git apply --index &&
33 git commit -m "Master accepts moral equivalent of #2"
37 test_expect_success
"format-patch --ignore-if-in-upstream" '
39 git format-patch --stdout master..side >patch0 &&
40 cnt=`grep "^From " patch0 | wc -l` &&
45 test_expect_success
"format-patch --ignore-if-in-upstream" '
47 git format-patch --stdout \
48 --ignore-if-in-upstream master..side >patch1 &&
49 cnt=`grep "^From " patch1 | wc -l` &&
54 test_expect_success
"format-patch result applies" '
56 git checkout -b rebuild-0 master &&
58 cnt=`git rev-list master.. | wc -l` &&
62 test_expect_success
"format-patch --ignore-if-in-upstream result applies" '
64 git checkout -b rebuild-1 master &&
66 cnt=`git rev-list master.. | wc -l` &&
70 test_expect_success
'commit did not screw up the log message' '
72 git cat-file commit side | grep "^Side .* with .* backslash-n"
76 test_expect_success
'format-patch did not screw up the log message' '
78 grep "^Subject: .*Side changes #3 with .* backslash-n" patch0 &&
79 grep "^Subject: .*Side changes #3 with .* backslash-n" patch1
83 test_expect_success
'replay did not screw up the log message' '
85 git cat-file commit rebuild-1 | grep "^Side .* with .* backslash-n"
89 test_expect_success
'extra headers' '
91 git config format.headers "To: R. E. Cipient <rcipient@example.com>
93 git config --add format.headers "Cc: S. E. Cipient <scipient@example.com>
95 git format-patch --stdout master..side > patch2 &&
96 sed -e "/^\$/q" patch2 > hdrs2 &&
97 grep "^To: R. E. Cipient <rcipient@example.com>\$" hdrs2 &&
98 grep "^Cc: S. E. Cipient <scipient@example.com>\$" hdrs2
102 test_expect_success
'extra headers without newlines' '
104 git config --replace-all format.headers "To: R. E. Cipient <rcipient@example.com>" &&
105 git config --add format.headers "Cc: S. E. Cipient <scipient@example.com>" &&
106 git format-patch --stdout master..side >patch3 &&
107 sed -e "/^\$/q" patch3 > hdrs3 &&
108 grep "^To: R. E. Cipient <rcipient@example.com>\$" hdrs3 &&
109 grep "^Cc: S. E. Cipient <scipient@example.com>\$" hdrs3
113 test_expect_success
'extra headers with multiple To:s' '
115 git config --replace-all format.headers "To: R. E. Cipient <rcipient@example.com>" &&
116 git config --add format.headers "To: S. E. Cipient <scipient@example.com>" &&
117 git format-patch --stdout master..side > patch4 &&
118 sed -e "/^\$/q" patch4 > hdrs4 &&
119 grep "^To: R. E. Cipient <rcipient@example.com>,\$" hdrs4 &&
120 grep "^ *S. E. Cipient <scipient@example.com>\$" hdrs4
123 test_expect_success
'additional command line cc' '
125 git config --replace-all format.headers "Cc: R. E. Cipient <rcipient@example.com>" &&
126 git format-patch --cc="S. E. Cipient <scipient@example.com>" --stdout master..side | sed -e "/^\$/q" >patch5 &&
127 grep "^Cc: R. E. Cipient <rcipient@example.com>,\$" patch5 &&
128 grep "^ *S. E. Cipient <scipient@example.com>\$" patch5
131 test_expect_success
'command line headers' '
133 git config --unset-all format.headers &&
134 git format-patch --add-header="Cc: R. E. Cipient <rcipient@example.com>" --stdout master..side | sed -e "/^\$/q" >patch6 &&
135 grep "^Cc: R. E. Cipient <rcipient@example.com>\$" patch6
138 test_expect_success
'configuration headers and command line headers' '
140 git config --replace-all format.headers "Cc: R. E. Cipient <rcipient@example.com>" &&
141 git format-patch --add-header="Cc: S. E. Cipient <scipient@example.com>" --stdout master..side | sed -e "/^\$/q" >patch7 &&
142 grep "^Cc: R. E. Cipient <rcipient@example.com>,\$" patch7 &&
143 grep "^ *S. E. Cipient <scipient@example.com>\$" patch7
146 test_expect_success
'command line To: header' '
148 git config --unset-all format.headers &&
149 git format-patch --to="R. E. Cipient <rcipient@example.com>" --stdout master..side | sed -e "/^\$/q" >patch8 &&
150 grep "^To: R. E. Cipient <rcipient@example.com>\$" patch8
153 test_expect_success
'configuration To: header' '
155 git config format.to "R. E. Cipient <rcipient@example.com>" &&
156 git format-patch --stdout master..side | sed -e "/^\$/q" >patch9 &&
157 grep "^To: R. E. Cipient <rcipient@example.com>\$" patch9
160 test_expect_success
'multiple files' '
164 git format-patch -o patches/ master &&
165 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
171 (git format-patch
--stdout "$@"; echo $?
> status.out
) |
172 # Prints everything between the Message-ID and In-Reply-To,
173 # and replaces all Message-ID-lookalikes by a sequence number
175 if (/^(message-id|references|in-reply-to)/i) {
181 $h{$1}=$i++ if (/<([^>]+)>/ and !exists $h{$1});
182 for $k (keys %h) {s/$k/$h{$k}/};
185 print "---\n" if /^From /i;
187 test 0 = "$(cat status.out)" &&
188 test_cmp
"$expect" actual
191 cat >> expect.no-threading
<<EOF
197 test_expect_success
'no threading' '
199 check_threading expect.no-threading master
202 cat > expect.thread
<<EOF
215 test_expect_success
'thread' '
216 check_threading expect.thread --thread master
219 cat > expect.in-reply-to
<<EOF
234 test_expect_success
'thread in-reply-to' '
235 check_threading expect.in-reply-to --in-reply-to="<test.message>" \
239 cat > expect.cover-letter
<<EOF
256 test_expect_success
'thread cover-letter' '
257 check_threading expect.cover-letter --cover-letter --thread master
260 cat > expect.cl-irt
<<EOF
282 test_expect_success
'thread cover-letter in-reply-to' '
283 check_threading expect.cl-irt --cover-letter \
284 --in-reply-to="<test.message>" --thread master
287 test_expect_success
'thread explicit shallow' '
288 check_threading expect.cl-irt --cover-letter \
289 --in-reply-to="<test.message>" --thread=shallow master
292 cat > expect.deep
<<EOF
306 test_expect_success
'thread deep' '
307 check_threading expect.deep --thread=deep master
310 cat > expect.deep-irt
<<EOF
328 test_expect_success
'thread deep in-reply-to' '
329 check_threading expect.deep-irt --thread=deep \
330 --in-reply-to="<test.message>" master
333 cat > expect.deep-cl
<<EOF
353 test_expect_success
'thread deep cover-letter' '
354 check_threading expect.deep-cl --cover-letter --thread=deep master
357 cat > expect.deep-cl-irt
<<EOF
382 test_expect_success
'thread deep cover-letter in-reply-to' '
383 check_threading expect.deep-cl-irt --cover-letter \
384 --in-reply-to="<test.message>" --thread=deep master
387 test_expect_success
'thread via config' '
388 git config format.thread true &&
389 check_threading expect.thread master
392 test_expect_success
'thread deep via config' '
393 git config format.thread deep &&
394 check_threading expect.deep master
397 test_expect_success
'thread config + override' '
398 git config format.thread deep &&
399 check_threading expect.thread --thread master
402 test_expect_success
'thread config + --no-thread' '
403 git config format.thread deep &&
404 check_threading expect.no-threading --no-thread master
407 test_expect_success
'excessive subject' '
411 for i in 5 6 1 2 3 A 4 B C 7 8 9 10 D E F; do echo "$i"; done >>file &&
412 git update-index file &&
413 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." &&
414 git format-patch -o patches/ master..side &&
415 ls patches/0004-This-is-an-excessively-long-subject-line-for-a-messa.patch
418 test_expect_success
'cover-letter inherits diff options' '
422 git format-patch --cover-letter -1 &&
423 ! grep "file => foo .* 0 *\$" 0000-cover-letter.patch &&
424 git format-patch --cover-letter -1 -M &&
425 grep "file => foo .* 0 *\$" 0000-cover-letter.patch
430 This is an excessively long subject line for a message due to the
431 habit some projects have of not having a short, one-line subject at
432 the start of the commit message, but rather sticking a whole
433 paragraph right at the start as the only thing in the commit
434 message. It had better not become the filename for the patch.
439 test_expect_success
'shortlog of cover-letter wraps overly-long onelines' '
441 git format-patch --cover-letter -2 &&
442 sed -e "1,/A U Thor/d" -e "/^\$/q" < 0000-cover-letter.patch > output &&
443 test_cmp expect output
449 file | 16 ++++++++++++++++
450 1 files changed, 16 insertions(+), 0 deletions(-)
452 diff --git a/file b/file
453 index 40f36c6..2dc5c23 100644
464 test_expect_success
'format-patch respects -U' '
466 git format-patch -U4 -2 &&
467 sed -e "1,/^\$/d" -e "/^+5/q" < 0001-This-is-an-excessively-long-subject-line-for-a-messa.patch > output &&
468 test_cmp expect output
474 diff --git a/file b/file
475 index 40f36c6..2dc5c23 100644
485 test_expect_success
'format-patch -p suppresses stat' '
487 git format-patch -p -2 &&
488 sed -e "1,/^\$/d" -e "/^+5/q" < 0001-This-is-an-excessively-long-subject-line-for-a-messa.patch > output &&
489 test_cmp expect output
493 test_expect_success
'format-patch from a subdirectory (1)' '
504 echo "Oops? $filename"
511 test_expect_success
'format-patch from a subdirectory (2)' '
516 git format-patch -1 -o ..
522 echo "Oops? $filename"
526 basename=$(expr "$filename" : ".*/\(.*\)") &&
527 test -f "sub/$basename"
530 test_expect_success
'format-patch from a subdirectory (3)' '
536 git format-patch -1 -o "$TRASH_DIRECTORY"
538 basename=$(expr "$filename" : ".*/\(.*\)") &&
542 test_expect_success
'format-patch --in-reply-to' '
543 git format-patch -1 --stdout --in-reply-to "baz@foo.bar" > patch8 &&
544 grep "^In-Reply-To: <baz@foo.bar>" patch8 &&
545 grep "^References: <baz@foo.bar>" patch8
548 test_expect_success
'format-patch --signoff' '
549 git format-patch -1 --signoff --stdout |
550 grep "^Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>"
553 echo "fatal: --name-only does not make sense" > expect.name-only
554 echo "fatal: --name-status does not make sense" > expect.name-status
555 echo "fatal: --check does not make sense" > expect.check
557 test_expect_success
'options no longer allowed for format-patch' '
558 test_must_fail git format-patch --name-only 2> output &&
559 test_cmp expect.name-only output &&
560 test_must_fail git format-patch --name-status 2> output &&
561 test_cmp expect.name-status output &&
562 test_must_fail git format-patch --check 2> output &&
563 test_cmp expect.check output'
565 test_expect_success
'format-patch --numstat should produce a patch' '
566 git format-patch --numstat --stdout master..side > output &&
567 test 6 = $(grep "^diff --git a/" output | wc -l)'
569 test_expect_success
'format-patch -- <path>' '
570 git format-patch master..side -- file 2>error &&
571 ! grep "Use .--" error