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