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