]> git.ipfire.org Git - thirdparty/git.git/blame - t/t4150-am.sh
Merge branch 'da/rhel7-lacks-uncompress2-and-c99'
[thirdparty/git.git] / t / t4150-am.sh
CommitLineData
d3a7b8f5
SB
1#!/bin/sh
2
3test_description='git am running'
4
8f37854b 5GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
334afbc7
JS
6export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7
d3a7b8f5
SB
8. ./test-lib.sh
9
800f1104
JN
10test_expect_success 'setup: messages' '
11 cat >msg <<-\EOF &&
12 second
13
14 Lorem ipsum dolor sit amet, consectetuer sadipscing elitr, sed diam nonumy
15 eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam
16 voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita
17 kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem
18 ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod
19 tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At
20 vero eos et accusam et justo duo dolores et ea rebum.
21
22 EOF
250b3c6c 23 qz_to_tab_space <<-\EOF >>msg &&
800f1104
JN
24 QDuis autem vel eum iriure dolor in hendrerit in vulputate velit
25 Qesse molestie consequat, vel illum dolore eu feugiat nulla facilisis
26 Qat vero eros et accumsan et iusto odio dignissim qui blandit
27 Qpraesent luptatum zzril delenit augue duis dolore te feugait nulla
28 Qfacilisi.
29 EOF
30 cat >>msg <<-\EOF &&
31
32 Lorem ipsum dolor sit amet,
33 consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut
34 laoreet dolore magna aliquam erat volutpat.
35
36 git
37 ---
38 +++
39
40 Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit
41 lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure
42 dolor in hendrerit in vulputate velit esse molestie consequat, vel illum
43 dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio
44 dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te
45 feugait nulla facilisi.
735285b4
PW
46
47 Reported-by: A N Other <a.n.other@example.com>
800f1104
JN
48 EOF
49
50 cat >failmail <<-\EOF &&
51 From foo@example.com Fri May 23 10:43:49 2008
52 From: foo@example.com
53 To: bar@example.com
54 Subject: Re: [RFC/PATCH] git-foo.sh
55 Date: Fri, 23 May 2008 05:23:42 +0200
56
57 Sometimes we have to find out that there'\''s nothing left.
58
59 EOF
60
61 cat >pine <<-\EOF &&
62 From MAILER-DAEMON Fri May 23 10:43:49 2008
63 Date: 23 May 2008 05:23:42 +0200
64 From: Mail System Internal Data <MAILER-DAEMON@example.com>
65 Subject: DON'\''T DELETE THIS MESSAGE -- FOLDER INTERNAL DATA
66 Message-ID: <foo-0001@example.com>
67
68 This text is part of the internal format of your mail folder, and is not
69 a real message. It is created automatically by the mail system software.
70 If deleted, important folder data will be lost, and it will be re-created
71 with the data reset to initial values.
72
73 EOF
74
b7446fcf
AR
75 cat >msg-without-scissors-line <<-\EOF &&
76 Test that git-am --scissors cuts at the scissors line
bf72ac17
PT
77
78 This line should be included in the commit message.
79 EOF
80
b7446fcf
AR
81 printf "Subject: " >subject-prefix &&
82
e041d078 83 cat - subject-prefix msg-without-scissors-line >msg-with-scissors-line <<-\EOF
bf72ac17
PT
84 This line should not be included in the commit message with --scissors enabled.
85
86 - - >8 - - remove everything above this line - - >8 - -
87
88 EOF
800f1104 89'
d3a7b8f5
SB
90
91test_expect_success setup '
92 echo hello >file &&
93 git add file &&
94 test_tick &&
95 git commit -m first &&
96 git tag first &&
800f1104 97
d3a7b8f5
SB
98 echo world >>file &&
99 git add file &&
100 test_tick &&
735285b4 101 git commit -F msg &&
d3a7b8f5 102 git tag second &&
800f1104 103
d3a7b8f5 104 git format-patch --stdout first >patch1 &&
0fcb2caf 105 {
a078f732 106 echo "Message-Id: <1226501681-24923-1-git-send-email-bda@mnsspb.ru>" &&
0fcb2caf
JH
107 echo "X-Fake-Field: Line One" &&
108 echo "X-Fake-Field: Line Two" &&
109 echo "X-Fake-Field: Line Three" &&
110 git format-patch --stdout first | sed -e "1d"
111 } > patch1.eml &&
e3f67d30
SB
112 {
113 echo "X-Fake-Field: Line One" &&
114 echo "X-Fake-Field: Line Two" &&
115 echo "X-Fake-Field: Line Three" &&
116 git format-patch --stdout first | sed -e "1d"
117 } | append_cr >patch1-crlf.eml &&
0e8341f2 118 {
7abcbcb7 119 printf "%255s\\n" "" &&
0e8341f2
DB
120 echo "X-Fake-Field: Line One" &&
121 echo "X-Fake-Field: Line Two" &&
122 echo "X-Fake-Field: Line Three" &&
123 git format-patch --stdout first | sed -e "1d"
124 } > patch1-ws.eml &&
1daaddd1
PT
125 {
126 sed -ne "1p" msg &&
127 echo &&
128 echo "From: $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>" &&
129 echo "Date: $GIT_AUTHOR_DATE" &&
130 echo &&
131 sed -e "1,2d" msg &&
1daaddd1
PT
132 echo "---" &&
133 git diff-tree --no-commit-id --stat -p second
134 } >patch1-stgit.eml &&
fcceef4e
PT
135 mkdir stgit-series &&
136 cp patch1-stgit.eml stgit-series/patch &&
137 {
138 echo "# This series applies on GIT commit $(git rev-parse first)" &&
139 echo "patch"
140 } >stgit-series/series &&
e9dfe253
PT
141 {
142 echo "# HG changeset patch" &&
143 echo "# User $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>" &&
144 echo "# Date $test_tick 25200" &&
145 echo "# $(git show --pretty="%aD" -s second)" &&
8125a58b 146 echo "# Node ID $ZERO_OID" &&
147 echo "# Parent $ZERO_OID" &&
e9dfe253
PT
148 cat msg &&
149 echo &&
e9dfe253
PT
150 git diff-tree --no-commit-id -p second
151 } >patch1-hg.eml &&
fcceef4e 152
800f1104 153
b7446fcf
AR
154 echo file >file &&
155 git add file &&
156 git commit -F msg-without-scissors-line &&
157 git tag expected-for-scissors &&
bf72ac17
PT
158 git reset --hard HEAD^ &&
159
b7446fcf
AR
160 echo file >file &&
161 git add file &&
162 git commit -F msg-with-scissors-line &&
163 git tag expected-for-no-scissors &&
164 git format-patch --stdout expected-for-no-scissors^ >patch-with-scissors-line.eml &&
bf72ac17
PT
165 git reset --hard HEAD^ &&
166
d3a7b8f5
SB
167 sed -n -e "3,\$p" msg >file &&
168 git add file &&
169 test_tick &&
170 git commit -m third &&
800f1104 171
64d1022e 172 git format-patch --stdout first >patch2 &&
800f1104 173
d3a7b8f5
SB
174 git checkout -b lorem &&
175 sed -n -e "11,\$p" msg >file &&
176 head -n 9 msg >>file &&
177 test_tick &&
178 git commit -a -m "moved stuff" &&
800f1104 179
d3a7b8f5
SB
180 echo goodbye >another &&
181 git add another &&
182 test_tick &&
183 git commit -m "added another file" &&
d3a7b8f5 184
8f37854b
JS
185 git format-patch --stdout main >lorem-move.patch &&
186 git format-patch --no-prefix --stdout main >lorem-zero.patch &&
18cdf802
JH
187
188 git checkout -b rename &&
189 git mv file renamed &&
190 git commit -m "renamed a file" &&
191
192 git format-patch -M --stdout lorem >rename.patch &&
193
194 git reset --soft lorem^ &&
195 git commit -m "renamed a file and added another" &&
196
197 git format-patch -M --stdout lorem^ >rename-add.patch &&
198
7c096b8d
A
199 git checkout -b empty-commit &&
200 git commit -m "empty commit" --allow-empty &&
201
202 : >empty.patch &&
203 git format-patch --always --stdout empty-commit^ >empty-commit.patch &&
204
800f1104 205 # reset time
1f5ad6b1 206 sane_unset test_tick &&
800f1104
JN
207 test_tick
208'
d3a7b8f5
SB
209
210test_expect_success 'am applies patch correctly' '
5d274859
JN
211 rm -fr .git/rebase-apply &&
212 git reset --hard &&
d3a7b8f5
SB
213 git checkout first &&
214 test_tick &&
215 git am <patch1 &&
61e0eb9d 216 test_path_is_missing .git/rebase-apply &&
800f1104 217 git diff --exit-code second &&
d3a7b8f5
SB
218 test "$(git rev-parse second)" = "$(git rev-parse HEAD)" &&
219 test "$(git rev-parse second^)" = "$(git rev-parse HEAD^)"
0fcb2caf
JH
220'
221
ab156128
PT
222test_expect_success 'am fails if index is dirty' '
223 test_when_finished "rm -f dirtyfile" &&
224 rm -fr .git/rebase-apply &&
225 git reset --hard &&
226 git checkout first &&
227 echo dirtyfile >dirtyfile &&
228 git add dirtyfile &&
229 test_must_fail git am patch1 &&
230 test_path_is_dir .git/rebase-apply &&
231 test_cmp_rev first HEAD
232'
233
0fcb2caf 234test_expect_success 'am applies patch e-mail not in a mbox' '
5d274859
JN
235 rm -fr .git/rebase-apply &&
236 git reset --hard &&
0fcb2caf
JH
237 git checkout first &&
238 git am patch1.eml &&
61e0eb9d 239 test_path_is_missing .git/rebase-apply &&
800f1104 240 git diff --exit-code second &&
0fcb2caf
JH
241 test "$(git rev-parse second)" = "$(git rev-parse HEAD)" &&
242 test "$(git rev-parse second^)" = "$(git rev-parse HEAD^)"
e3f67d30
SB
243'
244
245test_expect_success 'am applies patch e-mail not in a mbox with CRLF' '
5d274859
JN
246 rm -fr .git/rebase-apply &&
247 git reset --hard &&
e3f67d30
SB
248 git checkout first &&
249 git am patch1-crlf.eml &&
61e0eb9d 250 test_path_is_missing .git/rebase-apply &&
800f1104 251 git diff --exit-code second &&
e3f67d30
SB
252 test "$(git rev-parse second)" = "$(git rev-parse HEAD)" &&
253 test "$(git rev-parse second^)" = "$(git rev-parse HEAD^)"
d3a7b8f5
SB
254'
255
0e8341f2
DB
256test_expect_success 'am applies patch e-mail with preceding whitespace' '
257 rm -fr .git/rebase-apply &&
258 git reset --hard &&
259 git checkout first &&
260 git am patch1-ws.eml &&
61e0eb9d 261 test_path_is_missing .git/rebase-apply &&
0e8341f2
DB
262 git diff --exit-code second &&
263 test "$(git rev-parse second)" = "$(git rev-parse HEAD)" &&
264 test "$(git rev-parse second^)" = "$(git rev-parse HEAD^)"
265'
266
1daaddd1
PT
267test_expect_success 'am applies stgit patch' '
268 rm -fr .git/rebase-apply &&
269 git checkout -f first &&
270 git am patch1-stgit.eml &&
271 test_path_is_missing .git/rebase-apply &&
272 git diff --exit-code second &&
273 test_cmp_rev second HEAD &&
ab680dce
PT
274 test_cmp_rev second^ HEAD^
275'
276
277test_expect_success 'am --patch-format=stgit applies stgit patch' '
278 rm -fr .git/rebase-apply &&
279 git checkout -f first &&
280 git am --patch-format=stgit <patch1-stgit.eml &&
281 test_path_is_missing .git/rebase-apply &&
282 git diff --exit-code second &&
283 test_cmp_rev second HEAD &&
fcceef4e
PT
284 test_cmp_rev second^ HEAD^
285'
286
287test_expect_success 'am applies stgit series' '
288 rm -fr .git/rebase-apply &&
289 git checkout -f first &&
290 git am stgit-series/series &&
291 test_path_is_missing .git/rebase-apply &&
292 git diff --exit-code second &&
293 test_cmp_rev second HEAD &&
e9dfe253
PT
294 test_cmp_rev second^ HEAD^
295'
296
297test_expect_success 'am applies hg patch' '
298 rm -fr .git/rebase-apply &&
299 git checkout -f first &&
300 git am patch1-hg.eml &&
301 test_path_is_missing .git/rebase-apply &&
302 git diff --exit-code second &&
303 test_cmp_rev second HEAD &&
9f0aa6e6
PT
304 test_cmp_rev second^ HEAD^
305'
306
307test_expect_success 'am --patch-format=hg applies hg patch' '
308 rm -fr .git/rebase-apply &&
309 git checkout -f first &&
310 git am --patch-format=hg <patch1-hg.eml &&
311 test_path_is_missing .git/rebase-apply &&
312 git diff --exit-code second &&
313 test_cmp_rev second HEAD &&
1daaddd1
PT
314 test_cmp_rev second^ HEAD^
315'
316
f26bdf2d
PT
317test_expect_success 'am with applypatch-msg hook' '
318 test_when_finished "rm -f .git/hooks/applypatch-msg" &&
319 rm -fr .git/rebase-apply &&
320 git reset --hard &&
321 git checkout first &&
322 mkdir -p .git/hooks &&
323 write_script .git/hooks/applypatch-msg <<-\EOF &&
324 cat "$1" >actual-msg &&
325 echo hook-message >"$1"
326 EOF
327 git am patch1 &&
328 test_path_is_missing .git/rebase-apply &&
329 git diff --exit-code second &&
330 echo hook-message >expected &&
331 git log -1 --format=format:%B >actual &&
332 test_cmp expected actual &&
333 git log -1 --format=format:%B second >expected &&
334 test_cmp expected actual-msg
335'
336
337test_expect_success 'am with failing applypatch-msg hook' '
338 test_when_finished "rm -f .git/hooks/applypatch-msg" &&
339 rm -fr .git/rebase-apply &&
340 git reset --hard &&
341 git checkout first &&
342 mkdir -p .git/hooks &&
343 write_script .git/hooks/applypatch-msg <<-\EOF &&
344 exit 1
345 EOF
346 test_must_fail git am patch1 &&
347 test_path_is_dir .git/rebase-apply &&
348 git diff --exit-code first &&
349 test_cmp_rev first HEAD
350'
351
3bc6686b
PT
352test_expect_success 'am with pre-applypatch hook' '
353 test_when_finished "rm -f .git/hooks/pre-applypatch" &&
354 rm -fr .git/rebase-apply &&
355 git reset --hard &&
356 git checkout first &&
357 mkdir -p .git/hooks &&
358 write_script .git/hooks/pre-applypatch <<-\EOF &&
359 git diff first >diff.actual
360 exit 0
361 EOF
362 git am patch1 &&
363 test_path_is_missing .git/rebase-apply &&
364 git diff --exit-code second &&
365 test_cmp_rev second HEAD &&
366 git diff first..second >diff.expected &&
367 test_cmp diff.expected diff.actual
368'
369
370test_expect_success 'am with failing pre-applypatch hook' '
371 test_when_finished "rm -f .git/hooks/pre-applypatch" &&
372 rm -fr .git/rebase-apply &&
373 git reset --hard &&
374 git checkout first &&
375 mkdir -p .git/hooks &&
376 write_script .git/hooks/pre-applypatch <<-\EOF &&
377 exit 1
378 EOF
379 test_must_fail git am patch1 &&
380 test_path_is_dir .git/rebase-apply &&
381 git diff --exit-code second &&
382 test_cmp_rev first HEAD
383'
384
3ef4446b
PT
385test_expect_success 'am with post-applypatch hook' '
386 test_when_finished "rm -f .git/hooks/post-applypatch" &&
387 rm -fr .git/rebase-apply &&
388 git reset --hard &&
389 git checkout first &&
390 mkdir -p .git/hooks &&
391 write_script .git/hooks/post-applypatch <<-\EOF &&
392 git rev-parse HEAD >head.actual
393 git diff second >diff.actual
394 exit 0
395 EOF
396 git am patch1 &&
397 test_path_is_missing .git/rebase-apply &&
398 test_cmp_rev second HEAD &&
399 git rev-parse second >head.expected &&
400 test_cmp head.expected head.actual &&
401 git diff second >diff.expected &&
402 test_cmp diff.expected diff.actual
403'
404
405test_expect_success 'am with failing post-applypatch hook' '
406 test_when_finished "rm -f .git/hooks/post-applypatch" &&
407 rm -fr .git/rebase-apply &&
408 git reset --hard &&
409 git checkout first &&
410 mkdir -p .git/hooks &&
411 write_script .git/hooks/post-applypatch <<-\EOF &&
412 git rev-parse HEAD >head.actual
413 exit 1
414 EOF
415 git am patch1 &&
416 test_path_is_missing .git/rebase-apply &&
417 git diff --exit-code second &&
418 test_cmp_rev second HEAD &&
419 git rev-parse second >head.expected &&
420 test_cmp head.expected head.actual
421'
422
bf72ac17
PT
423test_expect_success 'am --scissors cuts the message at the scissors line' '
424 rm -fr .git/rebase-apply &&
425 git reset --hard &&
426 git checkout second &&
b7446fcf 427 git am --scissors patch-with-scissors-line.eml &&
bf72ac17 428 test_path_is_missing .git/rebase-apply &&
b7446fcf
AR
429 git diff --exit-code expected-for-scissors &&
430 test_cmp_rev expected-for-scissors HEAD
bf72ac17
PT
431'
432
433test_expect_success 'am --no-scissors overrides mailinfo.scissors' '
434 rm -fr .git/rebase-apply &&
435 git reset --hard &&
436 git checkout second &&
437 test_config mailinfo.scissors true &&
b7446fcf 438 git am --no-scissors patch-with-scissors-line.eml &&
bf72ac17 439 test_path_is_missing .git/rebase-apply &&
b7446fcf
AR
440 git diff --exit-code expected-for-no-scissors &&
441 test_cmp_rev expected-for-no-scissors HEAD
bf72ac17
PT
442'
443
800f1104
JN
444test_expect_success 'setup: new author and committer' '
445 GIT_AUTHOR_NAME="Another Thor" &&
446 GIT_AUTHOR_EMAIL="a.thor@example.com" &&
447 GIT_COMMITTER_NAME="Co M Miter" &&
448 GIT_COMMITTER_EMAIL="c.miter@example.com" &&
449 export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL GIT_COMMITTER_NAME GIT_COMMITTER_EMAIL
450'
d3a7b8f5
SB
451
452compare () {
800f1104
JN
453 a=$(git cat-file commit "$2" | grep "^$1 ") &&
454 b=$(git cat-file commit "$3" | grep "^$1 ") &&
455 test "$a" = "$b"
d3a7b8f5
SB
456}
457
458test_expect_success 'am changes committer and keeps author' '
459 test_tick &&
5d274859
JN
460 rm -fr .git/rebase-apply &&
461 git reset --hard &&
d3a7b8f5
SB
462 git checkout first &&
463 git am patch2 &&
61e0eb9d 464 test_path_is_missing .git/rebase-apply &&
8f37854b
JS
465 test "$(git rev-parse main^^)" = "$(git rev-parse HEAD^^)" &&
466 git diff --exit-code main..HEAD &&
467 git diff --exit-code main^..HEAD^ &&
468 compare author main HEAD &&
469 compare author main^ HEAD^ &&
d3a7b8f5
SB
470 test "$GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>" = \
471 "$(git log -1 --pretty=format:"%cn <%ce>" HEAD)"
472'
473
474test_expect_success 'am --signoff adds Signed-off-by: line' '
5d274859
JN
475 rm -fr .git/rebase-apply &&
476 git reset --hard &&
b6211b89 477 git checkout -b topic_2 first &&
d3a7b8f5 478 git am --signoff <patch2 &&
735285b4
PW
479 {
480 printf "third\n\nSigned-off-by: %s <%s>\n\n" \
481 "$GIT_COMMITTER_NAME" "$GIT_COMMITTER_EMAIL" &&
482 cat msg &&
483 printf "Signed-off-by: %s <%s>\n\n" \
484 "$GIT_COMMITTER_NAME" "$GIT_COMMITTER_EMAIL"
485 } >expected-log &&
486 git log --pretty=%B -2 HEAD >actual &&
487 test_cmp expected-log actual
d3a7b8f5
SB
488'
489
490test_expect_success 'am stays in branch' '
b6211b89 491 echo refs/heads/topic_2 >expected &&
800f1104
JN
492 git symbolic-ref HEAD >actual &&
493 test_cmp expected actual
d3a7b8f5
SB
494'
495
496test_expect_success 'am --signoff does not add Signed-off-by: line if already there' '
735285b4
PW
497 git format-patch --stdout first >patch3 &&
498 git reset --hard first &&
499 git am --signoff <patch3 &&
500 git log --pretty=%B -2 HEAD >actual &&
501 test_cmp expected-log actual
502'
503
504test_expect_success 'am --signoff adds Signed-off-by: if another author is preset' '
505 NAME="A N Other" &&
506 EMAIL="a.n.other@example.com" &&
507 {
508 printf "third\n\nSigned-off-by: %s <%s>\nSigned-off-by: %s <%s>\n\n" \
509 "$GIT_COMMITTER_NAME" "$GIT_COMMITTER_EMAIL" \
510 "$NAME" "$EMAIL" &&
511 cat msg &&
512 printf "Signed-off-by: %s <%s>\nSigned-off-by: %s <%s>\n\n" \
513 "$GIT_COMMITTER_NAME" "$GIT_COMMITTER_EMAIL" \
514 "$NAME" "$EMAIL"
515 } >expected-log &&
516 git reset --hard first &&
517 GIT_COMMITTER_NAME="$NAME" GIT_COMMITTER_EMAIL="$EMAIL" \
518 git am --signoff <patch3 &&
519 git log --pretty=%B -2 HEAD >actual &&
520 test_cmp expected-log actual
521'
522
523test_expect_success 'am --signoff duplicates Signed-off-by: if it is not the last one' '
524 NAME="A N Other" &&
525 EMAIL="a.n.other@example.com" &&
526 {
527 printf "third\n\nSigned-off-by: %s <%s>\n\
528Signed-off-by: %s <%s>\nSigned-off-by: %s <%s>\n\n" \
529 "$GIT_COMMITTER_NAME" "$GIT_COMMITTER_EMAIL" \
530 "$NAME" "$EMAIL" \
531 "$GIT_COMMITTER_NAME" "$GIT_COMMITTER_EMAIL" &&
532 cat msg &&
533 printf "Signed-off-by: %s <%s>\nSigned-off-by: %s <%s>\n\
534Signed-off-by: %s <%s>\n\n" \
535 "$GIT_COMMITTER_NAME" "$GIT_COMMITTER_EMAIL" \
536 "$NAME" "$EMAIL" \
537 "$GIT_COMMITTER_NAME" "$GIT_COMMITTER_EMAIL"
538 } >expected-log &&
539 git format-patch --stdout first >patch3 &&
540 git reset --hard first &&
541 git am --signoff <patch3 &&
542 git log --pretty=%B -2 HEAD >actual &&
543 test_cmp expected-log actual
d3a7b8f5
SB
544'
545
546test_expect_success 'am without --keep removes Re: and [PATCH] stuff' '
735285b4
PW
547 git format-patch --stdout HEAD^ >tmp &&
548 sed -e "/^Subject/ s,\[PATCH,Re: Re: Re: & 1/5 v2] [foo," tmp >patch4 &&
549 git reset --hard HEAD^ &&
550 git am <patch4 &&
800f1104 551 git rev-parse HEAD >expected &&
b6211b89 552 git rev-parse topic_2 >actual &&
800f1104 553 test_cmp expected actual
d3a7b8f5
SB
554'
555
556test_expect_success 'am --keep really keeps the subject' '
5d274859
JN
557 rm -fr .git/rebase-apply &&
558 git reset --hard &&
d3a7b8f5
SB
559 git checkout HEAD^ &&
560 git am --keep patch4 &&
61e0eb9d 561 test_path_is_missing .git/rebase-apply &&
800f1104 562 git cat-file commit HEAD >actual &&
f7e5ea17
TR
563 grep "Re: Re: Re: \[PATCH 1/5 v2\] \[foo\] third" actual
564'
565
ee2d1cb4 566test_expect_success 'am --keep-non-patch really keeps the non-patch part' '
f7e5ea17
TR
567 rm -fr .git/rebase-apply &&
568 git reset --hard &&
569 git checkout HEAD^ &&
570 git am --keep-non-patch patch4 &&
61e0eb9d 571 test_path_is_missing .git/rebase-apply &&
f7e5ea17
TR
572 git cat-file commit HEAD >actual &&
573 grep "^\[foo\] third" actual
d3a7b8f5
SB
574'
575
8c8884ce 576test_expect_success 'setup am -3' '
5d274859
JN
577 rm -fr .git/rebase-apply &&
578 git reset --hard &&
b6211b89 579 git checkout -b base3way topic_2 &&
d3a7b8f5
SB
580 sed -n -e "3,\$p" msg >file &&
581 head -n 9 msg >>file &&
582 git add file &&
583 test_tick &&
8c8884ce
RL
584 git commit -m "copied stuff"
585'
586
587test_expect_success 'am -3 falls back to 3-way merge' '
588 rm -fr .git/rebase-apply &&
589 git reset --hard &&
590 git checkout -b lorem2 base3way &&
d3a7b8f5 591 git am -3 lorem-move.patch &&
61e0eb9d 592 test_path_is_missing .git/rebase-apply &&
800f1104 593 git diff --exit-code lorem
d3a7b8f5
SB
594'
595
a61ba26a
JH
596test_expect_success 'am -3 -p0 can read --no-prefix patch' '
597 rm -fr .git/rebase-apply &&
598 git reset --hard &&
8c8884ce 599 git checkout -b lorem3 base3way &&
a61ba26a 600 git am -3 -p0 lorem-zero.patch &&
61e0eb9d 601 test_path_is_missing .git/rebase-apply &&
a61ba26a
JH
602 git diff --exit-code lorem
603'
604
e97a5e76
RL
605test_expect_success 'am with config am.threeWay falls back to 3-way merge' '
606 rm -fr .git/rebase-apply &&
607 git reset --hard &&
608 git checkout -b lorem4 base3way &&
609 test_config am.threeWay 1 &&
610 git am lorem-move.patch &&
611 test_path_is_missing .git/rebase-apply &&
612 git diff --exit-code lorem
613'
614
615test_expect_success 'am with config am.threeWay overridden by --no-3way' '
616 rm -fr .git/rebase-apply &&
617 git reset --hard &&
618 git checkout -b lorem5 base3way &&
619 test_config am.threeWay 1 &&
620 test_must_fail git am --no-3way lorem-move.patch &&
621 test_path_is_dir .git/rebase-apply
622'
623
18cdf802
JH
624test_expect_success 'am can rename a file' '
625 grep "^rename from" rename.patch &&
626 rm -fr .git/rebase-apply &&
627 git reset --hard &&
628 git checkout lorem^0 &&
629 git am rename.patch &&
61e0eb9d 630 test_path_is_missing .git/rebase-apply &&
18cdf802
JH
631 git update-index --refresh &&
632 git diff --exit-code rename
633'
634
635test_expect_success 'am -3 can rename a file' '
636 grep "^rename from" rename.patch &&
637 rm -fr .git/rebase-apply &&
638 git reset --hard &&
639 git checkout lorem^0 &&
640 git am -3 rename.patch &&
61e0eb9d 641 test_path_is_missing .git/rebase-apply &&
18cdf802
JH
642 git update-index --refresh &&
643 git diff --exit-code rename
644'
645
646test_expect_success 'am -3 can rename a file after falling back to 3-way merge' '
647 grep "^rename from" rename-add.patch &&
648 rm -fr .git/rebase-apply &&
649 git reset --hard &&
650 git checkout lorem^0 &&
651 git am -3 rename-add.patch &&
61e0eb9d 652 test_path_is_missing .git/rebase-apply &&
18cdf802
JH
653 git update-index --refresh &&
654 git diff --exit-code rename
655'
656
0e987a12 657test_expect_success 'am -3 -q is quiet' '
5d274859 658 rm -fr .git/rebase-apply &&
18cdf802 659 git checkout -f lorem2 &&
8c8884ce 660 git reset base3way --hard &&
800f1104 661 git am -3 -q lorem-move.patch >output.out 2>&1 &&
ec10b018 662 test_must_be_empty output.out
0e987a12
SB
663'
664
d3a7b8f5 665test_expect_success 'am pauses on conflict' '
5d274859
JN
666 rm -fr .git/rebase-apply &&
667 git reset --hard &&
d3a7b8f5 668 git checkout lorem2^^ &&
d492b31c 669 test_must_fail git am lorem-move.patch &&
51ef1daa 670 test -d .git/rebase-apply
d3a7b8f5
SB
671'
672
984913a2
NTND
673test_expect_success 'am --show-current-patch' '
674 git am --show-current-patch >actual.patch &&
675 test_cmp .git/rebase-apply/0001 actual.patch
676'
677
f3b48228
PB
678test_expect_success 'am --show-current-patch=raw' '
679 git am --show-current-patch=raw >actual.patch &&
680 test_cmp .git/rebase-apply/0001 actual.patch
681'
682
aa416b22
PB
683test_expect_success 'am --show-current-patch=diff' '
684 git am --show-current-patch=diff >actual.patch &&
685 test_cmp .git/rebase-apply/patch actual.patch
686'
687
f3b48228
PB
688test_expect_success 'am accepts repeated --show-current-patch' '
689 git am --show-current-patch --show-current-patch=raw >actual.patch &&
690 test_cmp .git/rebase-apply/0001 actual.patch
691'
692
aa416b22
PB
693test_expect_success 'am detects incompatible --show-current-patch' '
694 test_must_fail git am --show-current-patch=raw --show-current-patch=diff &&
695 test_must_fail git am --show-current-patch --show-current-patch=diff
696'
697
d3a7b8f5 698test_expect_success 'am --skip works' '
800f1104 699 echo goodbye >expected &&
d3a7b8f5 700 git am --skip &&
61e0eb9d 701 test_path_is_missing .git/rebase-apply &&
800f1104
JN
702 git diff --exit-code lorem2^^ -- file &&
703 test_cmp expected another
d3a7b8f5
SB
704'
705
b141f3c9
RR
706test_expect_success 'am --abort removes a stray directory' '
707 mkdir .git/rebase-apply &&
708 git am --abort &&
709 test_path_is_missing .git/rebase-apply
710'
711
b4967ab4
PT
712test_expect_success 'am refuses patches when paused' '
713 rm -fr .git/rebase-apply &&
714 git reset --hard &&
715 git checkout lorem2^^ &&
716
717 test_must_fail git am lorem-move.patch &&
718 test_path_is_dir .git/rebase-apply &&
719 test_cmp_rev lorem2^^ HEAD &&
720
721 test_must_fail git am <lorem-move.patch &&
722 test_path_is_dir .git/rebase-apply &&
723 test_cmp_rev lorem2^^ HEAD
724'
725
d3a7b8f5 726test_expect_success 'am --resolved works' '
800f1104 727 echo goodbye >expected &&
5d274859
JN
728 rm -fr .git/rebase-apply &&
729 git reset --hard &&
d3a7b8f5 730 git checkout lorem2^^ &&
d492b31c 731 test_must_fail git am lorem-move.patch &&
51ef1daa 732 test -d .git/rebase-apply &&
d3a7b8f5
SB
733 echo resolved >>file &&
734 git add file &&
735 git am --resolved &&
61e0eb9d 736 test_path_is_missing .git/rebase-apply &&
800f1104 737 test_cmp expected another
d3a7b8f5
SB
738'
739
60ff7f9f
PT
740test_expect_success 'am --resolved fails if index has no changes' '
741 rm -fr .git/rebase-apply &&
742 git reset --hard &&
743 git checkout lorem2^^ &&
744 test_must_fail git am lorem-move.patch &&
745 test_path_is_dir .git/rebase-apply &&
746 test_cmp_rev lorem2^^ HEAD &&
747 test_must_fail git am --resolved &&
748 test_path_is_dir .git/rebase-apply &&
749 test_cmp_rev lorem2^^ HEAD
750'
751
9e2a113d
PT
752test_expect_success 'am --resolved fails if index has unmerged entries' '
753 rm -fr .git/rebase-apply &&
754 git reset --hard &&
755 git checkout second &&
756 test_must_fail git am -3 lorem-move.patch &&
757 test_path_is_dir .git/rebase-apply &&
758 test_cmp_rev second HEAD &&
759 test_must_fail git am --resolved >err &&
760 test_path_is_dir .git/rebase-apply &&
761 test_cmp_rev second HEAD &&
762 test_i18ngrep "still have unmerged paths" err
763'
764
d3a7b8f5 765test_expect_success 'am takes patches from a Pine mailbox' '
5d274859
JN
766 rm -fr .git/rebase-apply &&
767 git reset --hard &&
d3a7b8f5
SB
768 git checkout first &&
769 cat pine patch1 | git am &&
61e0eb9d 770 test_path_is_missing .git/rebase-apply &&
8f37854b 771 git diff --exit-code main^..HEAD
d3a7b8f5
SB
772'
773
774test_expect_success 'am fails on mail without patch' '
5d274859
JN
775 rm -fr .git/rebase-apply &&
776 git reset --hard &&
d492b31c 777 test_must_fail git am <failmail &&
5d274859 778 git am --abort &&
61e0eb9d 779 test_path_is_missing .git/rebase-apply
d3a7b8f5
SB
780'
781
782test_expect_success 'am fails on empty patch' '
5d274859
JN
783 rm -fr .git/rebase-apply &&
784 git reset --hard &&
d3a7b8f5 785 echo "---" >>failmail &&
d492b31c 786 test_must_fail git am <failmail &&
d3a7b8f5 787 git am --skip &&
61e0eb9d 788 test_path_is_missing .git/rebase-apply
d3a7b8f5
SB
789'
790
8ec00d05
SB
791test_expect_success 'am works from stdin in subdirectory' '
792 rm -fr subdir &&
5d274859
JN
793 rm -fr .git/rebase-apply &&
794 git reset --hard &&
8ec00d05
SB
795 git checkout first &&
796 (
797 mkdir -p subdir &&
798 cd subdir &&
799 git am <../patch1
800 ) &&
800f1104 801 git diff --exit-code second
8ec00d05
SB
802'
803
804test_expect_success 'am works from file (relative path given) in subdirectory' '
805 rm -fr subdir &&
5d274859
JN
806 rm -fr .git/rebase-apply &&
807 git reset --hard &&
8ec00d05
SB
808 git checkout first &&
809 (
810 mkdir -p subdir &&
811 cd subdir &&
812 git am ../patch1
813 ) &&
800f1104 814 git diff --exit-code second
8ec00d05
SB
815'
816
817test_expect_success 'am works from file (absolute path given) in subdirectory' '
818 rm -fr subdir &&
5d274859
JN
819 rm -fr .git/rebase-apply &&
820 git reset --hard &&
8ec00d05
SB
821 git checkout first &&
822 P=$(pwd) &&
823 (
824 mkdir -p subdir &&
825 cd subdir &&
826 git am "$P/patch1"
827 ) &&
800f1104 828 git diff --exit-code second
8ec00d05
SB
829'
830
3f01ad66 831test_expect_success 'am --committer-date-is-author-date' '
5d274859
JN
832 rm -fr .git/rebase-apply &&
833 git reset --hard &&
3f01ad66
JH
834 git checkout first &&
835 test_tick &&
836 git am --committer-date-is-author-date patch1 &&
9524cf29 837 git cat-file commit HEAD | sed -e "/^\$/q" >head1 &&
800f1104
JN
838 sed -ne "/^author /s/.*> //p" head1 >at &&
839 sed -ne "/^committer /s/.*> //p" head1 >ct &&
840 test_cmp at ct
3f01ad66
JH
841'
842
843test_expect_success 'am without --committer-date-is-author-date' '
5d274859
JN
844 rm -fr .git/rebase-apply &&
845 git reset --hard &&
3f01ad66
JH
846 git checkout first &&
847 test_tick &&
848 git am patch1 &&
9524cf29 849 git cat-file commit HEAD | sed -e "/^\$/q" >head1 &&
800f1104
JN
850 sed -ne "/^author /s/.*> //p" head1 >at &&
851 sed -ne "/^committer /s/.*> //p" head1 >ct &&
852 ! test_cmp at ct
3f01ad66
JH
853'
854
a79ec62d
NS
855# This checks for +0000 because TZ is set to UTC and that should
856# show up when the current time is used. The date in message is set
857# by test_tick that uses -0700 timezone; if this feature does not
858# work, we will see that instead of +0000.
859test_expect_success 'am --ignore-date' '
5d274859
JN
860 rm -fr .git/rebase-apply &&
861 git reset --hard &&
a79ec62d
NS
862 git checkout first &&
863 test_tick &&
864 git am --ignore-date patch1 &&
9524cf29 865 git cat-file commit HEAD | sed -e "/^\$/q" >head1 &&
800f1104
JN
866 sed -ne "/^author /s/.*> //p" head1 >at &&
867 grep "+0000" at
a79ec62d
NS
868'
869
f79d4c8a 870test_expect_success 'am into an unborn branch' '
800f1104 871 git rev-parse first^{tree} >expected &&
5d274859
JN
872 rm -fr .git/rebase-apply &&
873 git reset --hard &&
f79d4c8a 874 rm -fr subdir &&
800f1104 875 mkdir subdir &&
f79d4c8a
NS
876 git format-patch --numbered-files -o subdir -1 first &&
877 (
878 cd subdir &&
879 git init &&
880 git am 1
881 ) &&
800f1104
JN
882 (
883 cd subdir &&
884 git rev-parse HEAD^{tree} >../actual
f79d4c8a 885 ) &&
800f1104 886 test_cmp expected actual
f79d4c8a
NS
887'
888
b3c32ead 889test_expect_success 'am newline in subject' '
5d274859
JN
890 rm -fr .git/rebase-apply &&
891 git reset --hard &&
b3c32ead
SB
892 git checkout first &&
893 test_tick &&
800f1104
JN
894 sed -e "s/second/second \\\n foo/" patch1 >patchnl &&
895 git am <patchnl >output.out 2>&1 &&
dff1a983 896 test_i18ngrep "^Applying: second \\\n foo$" output.out
b3c32ead
SB
897'
898
0e987a12 899test_expect_success 'am -q is quiet' '
5d274859
JN
900 rm -fr .git/rebase-apply &&
901 git reset --hard &&
0e987a12
SB
902 git checkout first &&
903 test_tick &&
800f1104 904 git am -q <patch1 >output.out 2>&1 &&
ec10b018 905 test_must_be_empty output.out
0e987a12
SB
906'
907
f0c5793b
JM
908test_expect_success 'am empty-file does not infloop' '
909 rm -fr .git/rebase-apply &&
910 git reset --hard &&
911 touch empty-file &&
912 test_tick &&
948065a4 913 test_must_fail git am empty-file 2>actual &&
f0c5793b 914 echo Patch format detection failed. >expected &&
1108cea7 915 test_cmp expected actual
f0c5793b
JM
916'
917
a078f732
PB
918test_expect_success 'am --message-id really adds the message id' '
919 rm -fr .git/rebase-apply &&
920 git reset --hard &&
921 git checkout HEAD^ &&
922 git am --message-id patch1.eml &&
923 test_path_is_missing .git/rebase-apply &&
924 git cat-file commit HEAD | tail -n1 >actual &&
925 grep Message-Id patch1.eml >expected &&
926 test_cmp expected actual
927'
928
8528bf4b
PT
929test_expect_success 'am.messageid really adds the message id' '
930 rm -fr .git/rebase-apply &&
931 git reset --hard &&
932 git checkout HEAD^ &&
933 test_config am.messageid true &&
934 git am patch1.eml &&
935 test_path_is_missing .git/rebase-apply &&
936 git cat-file commit HEAD | tail -n1 >actual &&
937 grep Message-Id patch1.eml >expected &&
938 test_cmp expected actual
939'
940
a078f732
PB
941test_expect_success 'am --message-id -s signs off after the message id' '
942 rm -fr .git/rebase-apply &&
943 git reset --hard &&
944 git checkout HEAD^ &&
945 git am -s --message-id patch1.eml &&
946 test_path_is_missing .git/rebase-apply &&
947 git cat-file commit HEAD | tail -n2 | head -n1 >actual &&
948 grep Message-Id patch1.eml >expected &&
949 test_cmp expected actual
950'
951
9dd330e6
JK
952test_expect_success 'am -3 works with rerere' '
953 rm -fr .git/rebase-apply &&
954 git reset --hard &&
955
956 # make patches one->two and two->three...
957 test_commit one file &&
958 test_commit two file &&
959 test_commit three file &&
960 git format-patch -2 --stdout >seq.patch &&
961
962 # and create a situation that conflicts...
963 git reset --hard one &&
964 test_commit other file &&
965
966 # enable rerere...
967 test_config rerere.enabled true &&
968 test_when_finished "rm -rf .git/rr-cache" &&
969
970 # ...and apply. Our resolution is to skip the first
971 # patch, and the rerere the second one.
972 test_must_fail git am -3 seq.patch &&
973 test_must_fail git am --skip &&
974 echo resolved >file &&
975 git add file &&
976 git am --resolved &&
977
978 # now apply again, and confirm that rerere engaged (we still
979 # expect failure from am because rerere does not auto-commit
980 # for us).
981 git reset --hard other &&
982 test_must_fail git am -3 seq.patch &&
983 test_must_fail git am --skip &&
984 echo resolved >expect &&
985 test_cmp expect file
986'
987
aab84542
JH
988test_expect_success 'am -s unexpected trailer block' '
989 rm -fr .git/rebase-apply &&
990 git reset --hard &&
991 echo signed >file &&
992 git add file &&
993 cat >msg <<-EOF &&
994 subject here
995
996 Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>
997 [jc: tweaked log message]
998 Signed-off-by: J C H <j@c.h>
999 EOF
1000 git commit -F msg &&
c76b84a1 1001 git cat-file commit HEAD | sed -e "1,/^$/d" >original &&
aab84542
JH
1002 git format-patch --stdout -1 >patch &&
1003
1004 git reset --hard HEAD^ &&
1005 git am -s patch &&
1006 (
1007 cat original &&
1008 echo "Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>"
1009 ) >expect &&
c76b84a1 1010 git cat-file commit HEAD | sed -e "1,/^$/d" >actual &&
aab84542
JH
1011 test_cmp expect actual &&
1012
1013 cat >msg <<-\EOF &&
1014 subject here
1015
1016 We make sure that there is a blank line between the log
1017 message proper and Signed-off-by: line added.
1018 EOF
1019 git reset HEAD^ &&
1020 git commit -F msg file &&
c76b84a1 1021 git cat-file commit HEAD | sed -e "1,/^$/d" >original &&
aab84542
JH
1022 git format-patch --stdout -1 >patch &&
1023
1024 git reset --hard HEAD^ &&
1025 git am -s patch &&
1026
1027 (
1028 cat original &&
1029 echo &&
1030 echo "Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>"
1031 ) >expect &&
c76b84a1 1032 git cat-file commit HEAD | sed -e "1,/^$/d" >actual &&
aab84542
JH
1033 test_cmp expect actual
1034'
1035
d9925d1a
EW
1036test_expect_success 'am --patch-format=mboxrd handles mboxrd' '
1037 rm -fr .git/rebase-apply &&
1038 git checkout -f first &&
1039 echo mboxrd >>file &&
1040 git add file &&
1041 cat >msg <<-\INPUT_END &&
1042 mboxrd should escape the body
1043
1044 From could trip up a loose mbox parser
1045 >From extra escape for reversibility
1046 INPUT_END
1047 git commit -F msg &&
1048 git format-patch --pretty=mboxrd --stdout -1 >mboxrd1 &&
1049 grep "^>From could trip up a loose mbox parser" mboxrd1 &&
1050 git checkout -f first &&
1051 git am --patch-format=mboxrd mboxrd1 &&
1052 git cat-file commit HEAD | tail -n4 >out &&
1053 test_cmp msg out
1054'
1055
6b4b013f
JT
1056test_expect_success 'am works with multi-line in-body headers' '
1057 FORTY="String that has a length of more than forty characters" &&
1058 LONG="$FORTY $FORTY" &&
1059 rm -fr .git/rebase-apply &&
1060 git checkout -f first &&
1061 echo one >> file &&
fd1062e5
LT
1062 git commit -am "$LONG
1063
1064 Body test" --author="$LONG <long@example.com>" &&
6b4b013f
JT
1065 git format-patch --stdout -1 >patch &&
1066 # bump from, date, and subject down to in-body header
1067 perl -lpe "
1068 if (/^From:/) {
1069 print \"From: x <x\@example.com>\";
1070 print \"Date: Sat, 1 Jan 2000 00:00:00 +0000\";
1071 print \"Subject: x\n\";
1072 }
1073 " patch >msg &&
1074 git checkout HEAD^ &&
1075 git am msg &&
1076 # Ensure that the author and full message are present
1077 git cat-file commit HEAD | grep "^author.*long@example.com" &&
fd1062e5 1078 git cat-file commit HEAD | grep "^$LONG$"
6b4b013f
JT
1079'
1080
65ed8ff3
NTND
1081test_expect_success 'am --quit keeps HEAD where it is' '
1082 mkdir .git/rebase-apply &&
1083 >.git/rebase-apply/last &&
1084 >.git/rebase-apply/next &&
1085 git rev-parse HEAD^ >.git/ORIG_HEAD &&
1086 git rev-parse HEAD >expected &&
1087 git am --quit &&
1088 test_path_is_missing .git/rebase-apply &&
1089 git rev-parse HEAD >actual &&
1090 test_cmp expected actual
1091'
1092
2c65d90f 1093test_expect_success 'am and .gitattibutes' '
1094 test_create_repo attributes &&
1095 (
1096 cd attributes &&
1097 test_commit init &&
1098 git config filter.test.clean "sed -e '\''s/smudged/clean/g'\''" &&
1099 git config filter.test.smudge "sed -e '\''s/clean/smudged/g'\''" &&
1100
1101 test_commit second &&
1102 git checkout -b test HEAD^ &&
1103
1104 echo "*.txt filter=test conflict-marker-size=10" >.gitattributes &&
1105 git add .gitattributes &&
1106 test_commit third &&
1107
1108 echo "This text is smudged." >a.txt &&
1109 git add a.txt &&
1110 test_commit fourth &&
1111
1112 git checkout -b removal HEAD^ &&
1113 git rm .gitattributes &&
1114 git add -u &&
1115 test_commit fifth &&
1116 git cherry-pick test &&
1117
1118 git checkout -b conflict third &&
1119 echo "This text is different." >a.txt &&
1120 git add a.txt &&
1121 test_commit sixth &&
1122
1123 git checkout test &&
8f37854b
JS
1124 git format-patch --stdout main..HEAD >patches &&
1125 git reset --hard main &&
2c65d90f 1126 git am patches &&
1127 grep "smudged" a.txt &&
1128
1129 git checkout removal &&
1130 git reset --hard &&
8f37854b
JS
1131 git format-patch --stdout main..HEAD >patches &&
1132 git reset --hard main &&
2c65d90f 1133 git am patches &&
1134 grep "clean" a.txt &&
1135
1136 git checkout conflict &&
1137 git reset --hard &&
8f37854b 1138 git format-patch --stdout main..HEAD >patches &&
2c65d90f 1139 git reset --hard fourth &&
1140 test_must_fail git am -3 patches &&
1141 grep "<<<<<<<<<<" a.txt
1142 )
1143'
1144
3318238d
JT
1145test_expect_success 'apply binary blob in partial clone' '
1146 printf "\\000" >binary &&
1147 git add binary &&
1148 git commit -m "binary blob" &&
1149 git format-patch --stdout -m HEAD^ >patch &&
1150
1151 test_create_repo server &&
1152 test_config -C server uploadpack.allowfilter 1 &&
1153 test_config -C server uploadpack.allowanysha1inwant 1 &&
1154 git clone --filter=blob:none "file://$(pwd)/server" client &&
1155 test_when_finished "rm -rf client" &&
1156
1157 # Exercise to make sure that it works
1158 git -C client am ../patch
1159'
1160
7c096b8d
A
1161test_expect_success 'an empty input file is error regardless of --empty option' '
1162 test_when_finished "git am --abort || :" &&
1163 test_must_fail git am --empty=drop empty.patch 2>actual &&
1164 echo "Patch format detection failed." >expected &&
1165 test_cmp expected actual
1166'
1167
1168test_expect_success 'invalid when passing the --empty option alone' '
1169 test_when_finished "git am --abort || :" &&
1170 git checkout empty-commit^ &&
1171 test_must_fail git am --empty empty-commit.patch 2>err &&
1172 echo "error: Invalid value for --empty: empty-commit.patch" >expected &&
1173 test_cmp expected err
1174'
1175
1176test_expect_success 'a message without a patch is an error (default)' '
1177 test_when_finished "git am --abort || :" &&
1178 test_must_fail git am empty-commit.patch >err &&
1179 grep "Patch is empty" err
1180'
1181
1182test_expect_success 'a message without a patch is an error where an explicit "--empty=stop" is given' '
1183 test_when_finished "git am --abort || :" &&
1184 test_must_fail git am --empty=stop empty-commit.patch >err &&
1185 grep "Patch is empty." err
1186'
1187
1188test_expect_success 'a message without a patch will be skipped when "--empty=drop" is given' '
1189 git am --empty=drop empty-commit.patch >output &&
1190 git rev-parse empty-commit^ >expected &&
1191 git rev-parse HEAD >actual &&
1192 test_cmp expected actual &&
1193 grep "Skipping: empty commit" output
1194'
1195
1196test_expect_success 'record as an empty commit when meeting e-mail message that lacks a patch' '
1197 git am --empty=keep empty-commit.patch >output &&
1198 test_path_is_missing .git/rebase-apply &&
1199 git show empty-commit --format="%B" >expected &&
1200 git show HEAD --format="%B" >actual &&
1201 grep -f actual expected &&
1202 grep "Creating an empty commit: empty commit" output
1203'
1204
9e7e41bf
A
1205test_expect_success 'skip an empty patch in the middle of an am session' '
1206 git checkout empty-commit^ &&
1207 test_must_fail git am empty-commit.patch >err &&
1208 grep "Patch is empty." err &&
1209 grep "To record the empty patch as an empty commit, run \"git am --allow-empty\"." err &&
1210 git am --skip &&
1211 test_path_is_missing .git/rebase-apply &&
1212 git rev-parse empty-commit^ >expected &&
1213 git rev-parse HEAD >actual &&
1214 test_cmp expected actual
1215'
1216
1217test_expect_success 'record an empty patch as an empty commit in the middle of an am session' '
1218 git checkout empty-commit^ &&
1219 test_must_fail git am empty-commit.patch >err &&
1220 grep "Patch is empty." err &&
1221 grep "To record the empty patch as an empty commit, run \"git am --allow-empty\"." err &&
1222 git am --allow-empty >output &&
1223 grep "No changes - recorded it as an empty commit." output &&
1224 test_path_is_missing .git/rebase-apply &&
1225 git show empty-commit --format="%B" >expected &&
1226 git show HEAD --format="%B" >actual &&
1227 grep -f actual expected
1228'
1229
1230test_expect_success 'create an non-empty commit when the index IS changed though "--allow-empty" is given' '
1231 git checkout empty-commit^ &&
1232 test_must_fail git am empty-commit.patch >err &&
1233 : >empty-file &&
1234 git add empty-file &&
1235 git am --allow-empty &&
1236 git show empty-commit --format="%B" >expected &&
1237 git show HEAD --format="%B" >actual &&
1238 grep -f actual expected &&
1239 git diff HEAD^..HEAD --name-only
1240'
1241
1242test_expect_success 'cannot create empty commits when there is a clean index due to merge conflicts' '
1243 test_when_finished "git am --abort || :" &&
1244 git rev-parse HEAD >expected &&
1245 test_must_fail git am seq.patch &&
1246 test_must_fail git am --allow-empty >err &&
1247 ! grep "To record the empty patch as an empty commit, run \"git am --allow-empty\"." err &&
1248 git rev-parse HEAD >actual &&
1249 test_cmp actual expected
1250'
1251
1252test_expect_success 'cannot create empty commits when there is unmerged index due to merge conflicts' '
1253 test_when_finished "git am --abort || :" &&
1254 git rev-parse HEAD >expected &&
1255 test_must_fail git am -3 seq.patch &&
1256 test_must_fail git am --allow-empty >err &&
1257 ! grep "To record the empty patch as an empty commit, run \"git am --allow-empty\"." err &&
1258 git rev-parse HEAD >actual &&
1259 test_cmp actual expected
1260'
1261
d3a7b8f5 1262test_done