3 test_description='git am running'
7 test_expect_success 'setup: messages' '
11 Lorem ipsum dolor sit amet, consectetuer sadipscing elitr, sed diam nonumy
12 eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam
13 voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita
14 kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem
15 ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod
16 tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At
17 vero eos et accusam et justo duo dolores et ea rebum.
20 qz_to_tab_space <<-\EOF >>msg &&
21 QDuis autem vel eum iriure dolor in hendrerit in vulputate velit
22 Qesse molestie consequat, vel illum dolore eu feugiat nulla facilisis
23 Qat vero eros et accumsan et iusto odio dignissim qui blandit
24 Qpraesent luptatum zzril delenit augue duis dolore te feugait nulla
29 Lorem ipsum dolor sit amet,
30 consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut
31 laoreet dolore magna aliquam erat volutpat.
37 Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit
38 lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure
39 dolor in hendrerit in vulputate velit esse molestie consequat, vel illum
40 dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio
41 dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te
42 feugait nulla facilisi.
44 Reported-by: A N Other <a.n.other@example.com>
47 cat >failmail <<-\EOF &&
48 From foo@example.com Fri May 23 10:43:49 2008
51 Subject: Re: [RFC/PATCH] git-foo.sh
52 Date: Fri, 23 May 2008 05:23:42 +0200
54 Sometimes we have to find out that there'\''s nothing left.
59 From MAILER-DAEMON Fri May 23 10:43:49 2008
60 Date: 23 May 2008 05:23:42 +0200
61 From: Mail System Internal Data <MAILER-DAEMON@example.com>
62 Subject: DON'\''T DELETE THIS MESSAGE -- FOLDER INTERNAL DATA
63 Message-ID: <foo-0001@example.com>
65 This text is part of the internal format of your mail folder, and is not
66 a real message. It is created automatically by the mail system software.
67 If deleted, important folder data will be lost, and it will be re-created
68 with the data reset to initial values.
72 cat >msg-without-scissors-line <<-\EOF &&
73 Test that git-am --scissors cuts at the scissors line
75 This line should be included in the commit message.
78 printf "Subject: " >subject-prefix &&
80 cat - subject-prefix msg-without-scissors-line >msg-with-scissors-line <<-\EOF
81 This line should not be included in the commit message with --scissors enabled.
83 - - >8 - - remove everything above this line - - >8 - -
88 test_expect_success setup '
92 git commit -m first &&
101 git format-patch --stdout first >patch1 &&
103 echo "Message-Id: <1226501681-24923-1-git-send-email-bda@mnsspb.ru>" &&
104 echo "X-Fake-Field: Line One" &&
105 echo "X-Fake-Field: Line Two" &&
106 echo "X-Fake-Field: Line Three" &&
107 git format-patch --stdout first | sed -e "1d"
110 echo "X-Fake-Field: Line One" &&
111 echo "X-Fake-Field: Line Two" &&
112 echo "X-Fake-Field: Line Three" &&
113 git format-patch --stdout first | sed -e "1d"
114 } | append_cr >patch1-crlf.eml &&
117 echo "X-Fake-Field: Line One" &&
118 echo "X-Fake-Field: Line Two" &&
119 echo "X-Fake-Field: Line Three" &&
120 git format-patch --stdout first | sed -e "1d"
125 echo "From: $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>" &&
126 echo "Date: $GIT_AUTHOR_DATE" &&
130 git diff-tree --no-commit-id --stat -p second
131 } >patch1-stgit.eml &&
132 mkdir stgit-series &&
133 cp patch1-stgit.eml stgit-series/patch &&
135 echo "# This series applies on GIT commit $(git rev-parse first)" &&
137 } >stgit-series/series &&
139 echo "# HG changeset patch" &&
140 echo "# User $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>" &&
141 echo "# Date $test_tick 25200" &&
142 echo "# $(git show --pretty="%aD" -s second)" &&
143 echo "# Node ID $ZERO_OID" &&
144 echo "# Parent $ZERO_OID" &&
147 git diff-tree --no-commit-id -p second
153 git commit -F msg-without-scissors-line &&
154 git tag expected-for-scissors &&
155 git reset --hard HEAD^ &&
159 git commit -F msg-with-scissors-line &&
160 git tag expected-for-no-scissors &&
161 git format-patch --stdout expected-for-no-scissors^ >patch-with-scissors-line.eml &&
162 git reset --hard HEAD^ &&
164 sed -n -e "3,\$p" msg >file &&
167 git commit -m third &&
169 git format-patch --stdout first >patch2 &&
171 git checkout -b lorem &&
172 sed -n -e "11,\$p" msg >file &&
173 head -n 9 msg >>file &&
175 git commit -a -m "moved stuff" &&
177 echo goodbye >another &&
180 git commit -m "added another file" &&
182 git format-patch --stdout master >lorem-move.patch &&
183 git format-patch --no-prefix --stdout master >lorem-zero.patch &&
185 git checkout -b rename &&
186 git mv file renamed &&
187 git commit -m "renamed a file" &&
189 git format-patch -M --stdout lorem >rename.patch &&
191 git reset --soft lorem^ &&
192 git commit -m "renamed a file and added another" &&
194 git format-patch -M --stdout lorem^ >rename-add.patch &&
197 sane_unset test_tick &&
201 test_expect_success 'am applies patch correctly' '
202 rm -fr .git/rebase-apply &&
204 git checkout first &&
207 test_path_is_missing .git/rebase-apply &&
208 git diff --exit-code second &&
209 test "$(git rev-parse second)" = "$(git rev-parse HEAD)" &&
210 test "$(git rev-parse second^)" = "$(git rev-parse HEAD^)"
213 test_expect_success 'am fails if index is dirty' '
214 test_when_finished "rm -f dirtyfile" &&
215 rm -fr .git/rebase-apply &&
217 git checkout first &&
218 echo dirtyfile >dirtyfile &&
220 test_must_fail git am patch1 &&
221 test_path_is_dir .git/rebase-apply &&
222 test_cmp_rev first HEAD
225 test_expect_success 'am applies patch e-mail not in a mbox' '
226 rm -fr .git/rebase-apply &&
228 git checkout first &&
230 test_path_is_missing .git/rebase-apply &&
231 git diff --exit-code second &&
232 test "$(git rev-parse second)" = "$(git rev-parse HEAD)" &&
233 test "$(git rev-parse second^)" = "$(git rev-parse HEAD^)"
236 test_expect_success 'am applies patch e-mail not in a mbox with CRLF' '
237 rm -fr .git/rebase-apply &&
239 git checkout first &&
240 git am patch1-crlf.eml &&
241 test_path_is_missing .git/rebase-apply &&
242 git diff --exit-code second &&
243 test "$(git rev-parse second)" = "$(git rev-parse HEAD)" &&
244 test "$(git rev-parse second^)" = "$(git rev-parse HEAD^)"
247 test_expect_success 'am applies patch e-mail with preceding whitespace' '
248 rm -fr .git/rebase-apply &&
250 git checkout first &&
251 git am patch1-ws.eml &&
252 test_path_is_missing .git/rebase-apply &&
253 git diff --exit-code second &&
254 test "$(git rev-parse second)" = "$(git rev-parse HEAD)" &&
255 test "$(git rev-parse second^)" = "$(git rev-parse HEAD^)"
258 test_expect_success 'am applies stgit patch' '
259 rm -fr .git/rebase-apply &&
260 git checkout -f first &&
261 git am patch1-stgit.eml &&
262 test_path_is_missing .git/rebase-apply &&
263 git diff --exit-code second &&
264 test_cmp_rev second HEAD &&
265 test_cmp_rev second^ HEAD^
268 test_expect_success 'am --patch-format=stgit applies stgit patch' '
269 rm -fr .git/rebase-apply &&
270 git checkout -f first &&
271 git am --patch-format=stgit <patch1-stgit.eml &&
272 test_path_is_missing .git/rebase-apply &&
273 git diff --exit-code second &&
274 test_cmp_rev second HEAD &&
275 test_cmp_rev second^ HEAD^
278 test_expect_success 'am applies stgit series' '
279 rm -fr .git/rebase-apply &&
280 git checkout -f first &&
281 git am stgit-series/series &&
282 test_path_is_missing .git/rebase-apply &&
283 git diff --exit-code second &&
284 test_cmp_rev second HEAD &&
285 test_cmp_rev second^ HEAD^
288 test_expect_success 'am applies hg patch' '
289 rm -fr .git/rebase-apply &&
290 git checkout -f first &&
291 git am patch1-hg.eml &&
292 test_path_is_missing .git/rebase-apply &&
293 git diff --exit-code second &&
294 test_cmp_rev second HEAD &&
295 test_cmp_rev second^ HEAD^
298 test_expect_success 'am --patch-format=hg applies hg patch' '
299 rm -fr .git/rebase-apply &&
300 git checkout -f first &&
301 git am --patch-format=hg <patch1-hg.eml &&
302 test_path_is_missing .git/rebase-apply &&
303 git diff --exit-code second &&
304 test_cmp_rev second HEAD &&
305 test_cmp_rev second^ HEAD^
308 test_expect_success 'am with applypatch-msg hook' '
309 test_when_finished "rm -f .git/hooks/applypatch-msg" &&
310 rm -fr .git/rebase-apply &&
312 git checkout first &&
313 mkdir -p .git/hooks &&
314 write_script .git/hooks/applypatch-msg <<-\EOF &&
315 cat "$1" >actual-msg &&
316 echo hook-message >"$1"
319 test_path_is_missing .git/rebase-apply &&
320 git diff --exit-code second &&
321 echo hook-message >expected &&
322 git log -1 --format=format:%B >actual &&
323 test_cmp expected actual &&
324 git log -1 --format=format:%B second >expected &&
325 test_cmp expected actual-msg
328 test_expect_success 'am with failing applypatch-msg hook' '
329 test_when_finished "rm -f .git/hooks/applypatch-msg" &&
330 rm -fr .git/rebase-apply &&
332 git checkout first &&
333 mkdir -p .git/hooks &&
334 write_script .git/hooks/applypatch-msg <<-\EOF &&
337 test_must_fail git am patch1 &&
338 test_path_is_dir .git/rebase-apply &&
339 git diff --exit-code first &&
340 test_cmp_rev first HEAD
343 test_expect_success 'am with pre-applypatch hook' '
344 test_when_finished "rm -f .git/hooks/pre-applypatch" &&
345 rm -fr .git/rebase-apply &&
347 git checkout first &&
348 mkdir -p .git/hooks &&
349 write_script .git/hooks/pre-applypatch <<-\EOF &&
350 git diff first >diff.actual
354 test_path_is_missing .git/rebase-apply &&
355 git diff --exit-code second &&
356 test_cmp_rev second HEAD &&
357 git diff first..second >diff.expected &&
358 test_cmp diff.expected diff.actual
361 test_expect_success 'am with failing pre-applypatch hook' '
362 test_when_finished "rm -f .git/hooks/pre-applypatch" &&
363 rm -fr .git/rebase-apply &&
365 git checkout first &&
366 mkdir -p .git/hooks &&
367 write_script .git/hooks/pre-applypatch <<-\EOF &&
370 test_must_fail git am patch1 &&
371 test_path_is_dir .git/rebase-apply &&
372 git diff --exit-code second &&
373 test_cmp_rev first HEAD
376 test_expect_success 'am with post-applypatch hook' '
377 test_when_finished "rm -f .git/hooks/post-applypatch" &&
378 rm -fr .git/rebase-apply &&
380 git checkout first &&
381 mkdir -p .git/hooks &&
382 write_script .git/hooks/post-applypatch <<-\EOF &&
383 git rev-parse HEAD >head.actual
384 git diff second >diff.actual
388 test_path_is_missing .git/rebase-apply &&
389 test_cmp_rev second HEAD &&
390 git rev-parse second >head.expected &&
391 test_cmp head.expected head.actual &&
392 git diff second >diff.expected &&
393 test_cmp diff.expected diff.actual
396 test_expect_success 'am with failing post-applypatch hook' '
397 test_when_finished "rm -f .git/hooks/post-applypatch" &&
398 rm -fr .git/rebase-apply &&
400 git checkout first &&
401 mkdir -p .git/hooks &&
402 write_script .git/hooks/post-applypatch <<-\EOF &&
403 git rev-parse HEAD >head.actual
407 test_path_is_missing .git/rebase-apply &&
408 git diff --exit-code second &&
409 test_cmp_rev second HEAD &&
410 git rev-parse second >head.expected &&
411 test_cmp head.expected head.actual
414 test_expect_success 'am --scissors cuts the message at the scissors line' '
415 rm -fr .git/rebase-apply &&
417 git checkout second &&
418 git am --scissors patch-with-scissors-line.eml &&
419 test_path_is_missing .git/rebase-apply &&
420 git diff --exit-code expected-for-scissors &&
421 test_cmp_rev expected-for-scissors HEAD
424 test_expect_success 'am --no-scissors overrides mailinfo.scissors' '
425 rm -fr .git/rebase-apply &&
427 git checkout second &&
428 test_config mailinfo.scissors true &&
429 git am --no-scissors patch-with-scissors-line.eml &&
430 test_path_is_missing .git/rebase-apply &&
431 git diff --exit-code expected-for-no-scissors &&
432 test_cmp_rev expected-for-no-scissors HEAD
435 test_expect_success 'setup: new author and committer' '
436 GIT_AUTHOR_NAME="Another Thor" &&
437 GIT_AUTHOR_EMAIL="a.thor@example.com" &&
438 GIT_COMMITTER_NAME="Co M Miter" &&
439 GIT_COMMITTER_EMAIL="c.miter@example.com" &&
440 export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL GIT_COMMITTER_NAME GIT_COMMITTER_EMAIL
444 a=$(git cat-file commit "$2" | grep "^$1 ") &&
445 b=$(git cat-file commit "$3" | grep "^$1 ") &&
449 test_expect_success 'am changes committer and keeps author' '
451 rm -fr .git/rebase-apply &&
453 git checkout first &&
455 test_path_is_missing .git/rebase-apply &&
456 test "$(git rev-parse master^^)" = "$(git rev-parse HEAD^^)" &&
457 git diff --exit-code master..HEAD &&
458 git diff --exit-code master^..HEAD^ &&
459 compare author master HEAD &&
460 compare author master^ HEAD^ &&
461 test "$GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>" = \
462 "$(git log -1 --pretty=format:"%cn <%ce>" HEAD)"
465 test_expect_success 'am --signoff adds Signed-off-by: line' '
466 rm -fr .git/rebase-apply &&
468 git checkout -b master2 first &&
469 git am --signoff <patch2 &&
471 printf "third\n\nSigned-off-by: %s <%s>\n\n" \
472 "$GIT_COMMITTER_NAME" "$GIT_COMMITTER_EMAIL" &&
474 printf "Signed-off-by: %s <%s>\n\n" \
475 "$GIT_COMMITTER_NAME" "$GIT_COMMITTER_EMAIL"
477 git log --pretty=%B -2 HEAD >actual &&
478 test_cmp expected-log actual
481 test_expect_success 'am stays in branch' '
482 echo refs/heads/master2 >expected &&
483 git symbolic-ref HEAD >actual &&
484 test_cmp expected actual
487 test_expect_success 'am --signoff does not add Signed-off-by: line if already there' '
488 git format-patch --stdout first >patch3 &&
489 git reset --hard first &&
490 git am --signoff <patch3 &&
491 git log --pretty=%B -2 HEAD >actual &&
492 test_cmp expected-log actual
495 test_expect_success 'am --signoff adds Signed-off-by: if another author is preset' '
497 EMAIL="a.n.other@example.com" &&
499 printf "third\n\nSigned-off-by: %s <%s>\nSigned-off-by: %s <%s>\n\n" \
500 "$GIT_COMMITTER_NAME" "$GIT_COMMITTER_EMAIL" \
503 printf "Signed-off-by: %s <%s>\nSigned-off-by: %s <%s>\n\n" \
504 "$GIT_COMMITTER_NAME" "$GIT_COMMITTER_EMAIL" \
507 git reset --hard first &&
508 GIT_COMMITTER_NAME="$NAME" GIT_COMMITTER_EMAIL="$EMAIL" \
509 git am --signoff <patch3 &&
510 git log --pretty=%B -2 HEAD >actual &&
511 test_cmp expected-log actual
514 test_expect_success 'am --signoff duplicates Signed-off-by: if it is not the last one' '
516 EMAIL="a.n.other@example.com" &&
518 printf "third\n\nSigned-off-by: %s <%s>\n\
519 Signed-off-by: %s <%s>\nSigned-off-by: %s <%s>\n\n" \
520 "$GIT_COMMITTER_NAME" "$GIT_COMMITTER_EMAIL" \
522 "$GIT_COMMITTER_NAME" "$GIT_COMMITTER_EMAIL" &&
524 printf "Signed-off-by: %s <%s>\nSigned-off-by: %s <%s>\n\
525 Signed-off-by: %s <%s>\n\n" \
526 "$GIT_COMMITTER_NAME" "$GIT_COMMITTER_EMAIL" \
528 "$GIT_COMMITTER_NAME" "$GIT_COMMITTER_EMAIL"
530 git format-patch --stdout first >patch3 &&
531 git reset --hard first &&
532 git am --signoff <patch3 &&
533 git log --pretty=%B -2 HEAD >actual &&
534 test_cmp expected-log actual
537 test_expect_success 'am without --keep removes Re: and [PATCH] stuff' '
538 git format-patch --stdout HEAD^ >tmp &&
539 sed -e "/^Subject/ s,\[PATCH,Re: Re: Re: & 1/5 v2] [foo," tmp >patch4 &&
540 git reset --hard HEAD^ &&
542 git rev-parse HEAD >expected &&
543 git rev-parse master2 >actual &&
544 test_cmp expected actual
547 test_expect_success 'am --keep really keeps the subject' '
548 rm -fr .git/rebase-apply &&
550 git checkout HEAD^ &&
551 git am --keep patch4 &&
552 test_path_is_missing .git/rebase-apply &&
553 git cat-file commit HEAD >actual &&
554 grep "Re: Re: Re: \[PATCH 1/5 v2\] \[foo\] third" actual
557 test_expect_success 'am --keep-non-patch really keeps the non-patch part' '
558 rm -fr .git/rebase-apply &&
560 git checkout HEAD^ &&
561 git am --keep-non-patch patch4 &&
562 test_path_is_missing .git/rebase-apply &&
563 git cat-file commit HEAD >actual &&
564 grep "^\[foo\] third" actual
567 test_expect_success 'setup am -3' '
568 rm -fr .git/rebase-apply &&
570 git checkout -b base3way master2 &&
571 sed -n -e "3,\$p" msg >file &&
572 head -n 9 msg >>file &&
575 git commit -m "copied stuff"
578 test_expect_success 'am -3 falls back to 3-way merge' '
579 rm -fr .git/rebase-apply &&
581 git checkout -b lorem2 base3way &&
582 git am -3 lorem-move.patch &&
583 test_path_is_missing .git/rebase-apply &&
584 git diff --exit-code lorem
587 test_expect_success 'am -3 -p0 can read --no-prefix patch' '
588 rm -fr .git/rebase-apply &&
590 git checkout -b lorem3 base3way &&
591 git am -3 -p0 lorem-zero.patch &&
592 test_path_is_missing .git/rebase-apply &&
593 git diff --exit-code lorem
596 test_expect_success 'am with config am.threeWay falls back to 3-way merge' '
597 rm -fr .git/rebase-apply &&
599 git checkout -b lorem4 base3way &&
600 test_config am.threeWay 1 &&
601 git am lorem-move.patch &&
602 test_path_is_missing .git/rebase-apply &&
603 git diff --exit-code lorem
606 test_expect_success 'am with config am.threeWay overridden by --no-3way' '
607 rm -fr .git/rebase-apply &&
609 git checkout -b lorem5 base3way &&
610 test_config am.threeWay 1 &&
611 test_must_fail git am --no-3way lorem-move.patch &&
612 test_path_is_dir .git/rebase-apply
615 test_expect_success 'am can rename a file' '
616 grep "^rename from" rename.patch &&
617 rm -fr .git/rebase-apply &&
619 git checkout lorem^0 &&
620 git am rename.patch &&
621 test_path_is_missing .git/rebase-apply &&
622 git update-index --refresh &&
623 git diff --exit-code rename
626 test_expect_success 'am -3 can rename a file' '
627 grep "^rename from" rename.patch &&
628 rm -fr .git/rebase-apply &&
630 git checkout lorem^0 &&
631 git am -3 rename.patch &&
632 test_path_is_missing .git/rebase-apply &&
633 git update-index --refresh &&
634 git diff --exit-code rename
637 test_expect_success 'am -3 can rename a file after falling back to 3-way merge' '
638 grep "^rename from" rename-add.patch &&
639 rm -fr .git/rebase-apply &&
641 git checkout lorem^0 &&
642 git am -3 rename-add.patch &&
643 test_path_is_missing .git/rebase-apply &&
644 git update-index --refresh &&
645 git diff --exit-code rename
648 test_expect_success 'am -3 -q is quiet' '
649 rm -fr .git/rebase-apply &&
650 git checkout -f lorem2 &&
651 git reset base3way --hard &&
652 git am -3 -q lorem-move.patch >output.out 2>&1 &&
653 test_must_be_empty output.out
656 test_expect_success 'am pauses on conflict' '
657 rm -fr .git/rebase-apply &&
659 git checkout lorem2^^ &&
660 test_must_fail git am lorem-move.patch &&
661 test -d .git/rebase-apply
664 test_expect_success 'am --show-current-patch' '
665 git am --show-current-patch >actual.patch &&
666 test_cmp .git/rebase-apply/0001 actual.patch
669 test_expect_success 'am --skip works' '
670 echo goodbye >expected &&
672 test_path_is_missing .git/rebase-apply &&
673 git diff --exit-code lorem2^^ -- file &&
674 test_cmp expected another
677 test_expect_success 'am --abort removes a stray directory' '
678 mkdir .git/rebase-apply &&
680 test_path_is_missing .git/rebase-apply
683 test_expect_success 'am refuses patches when paused' '
684 rm -fr .git/rebase-apply &&
686 git checkout lorem2^^ &&
688 test_must_fail git am lorem-move.patch &&
689 test_path_is_dir .git/rebase-apply &&
690 test_cmp_rev lorem2^^ HEAD &&
692 test_must_fail git am <lorem-move.patch &&
693 test_path_is_dir .git/rebase-apply &&
694 test_cmp_rev lorem2^^ HEAD
697 test_expect_success 'am --resolved works' '
698 echo goodbye >expected &&
699 rm -fr .git/rebase-apply &&
701 git checkout lorem2^^ &&
702 test_must_fail git am lorem-move.patch &&
703 test -d .git/rebase-apply &&
704 echo resolved >>file &&
707 test_path_is_missing .git/rebase-apply &&
708 test_cmp expected another
711 test_expect_success 'am --resolved fails if index has no changes' '
712 rm -fr .git/rebase-apply &&
714 git checkout lorem2^^ &&
715 test_must_fail git am lorem-move.patch &&
716 test_path_is_dir .git/rebase-apply &&
717 test_cmp_rev lorem2^^ HEAD &&
718 test_must_fail git am --resolved &&
719 test_path_is_dir .git/rebase-apply &&
720 test_cmp_rev lorem2^^ HEAD
723 test_expect_success 'am --resolved fails if index has unmerged entries' '
724 rm -fr .git/rebase-apply &&
726 git checkout second &&
727 test_must_fail git am -3 lorem-move.patch &&
728 test_path_is_dir .git/rebase-apply &&
729 test_cmp_rev second HEAD &&
730 test_must_fail git am --resolved >err &&
731 test_path_is_dir .git/rebase-apply &&
732 test_cmp_rev second HEAD &&
733 test_i18ngrep "still have unmerged paths" err
736 test_expect_success 'am takes patches from a Pine mailbox' '
737 rm -fr .git/rebase-apply &&
739 git checkout first &&
740 cat pine patch1 | git am &&
741 test_path_is_missing .git/rebase-apply &&
742 git diff --exit-code master^..HEAD
745 test_expect_success 'am fails on mail without patch' '
746 rm -fr .git/rebase-apply &&
748 test_must_fail git am <failmail &&
750 test_path_is_missing .git/rebase-apply
753 test_expect_success 'am fails on empty patch' '
754 rm -fr .git/rebase-apply &&
756 echo "---" >>failmail &&
757 test_must_fail git am <failmail &&
759 test_path_is_missing .git/rebase-apply
762 test_expect_success 'am works from stdin in subdirectory' '
764 rm -fr .git/rebase-apply &&
766 git checkout first &&
772 git diff --exit-code second
775 test_expect_success 'am works from file (relative path given) in subdirectory' '
777 rm -fr .git/rebase-apply &&
779 git checkout first &&
785 git diff --exit-code second
788 test_expect_success 'am works from file (absolute path given) in subdirectory' '
790 rm -fr .git/rebase-apply &&
792 git checkout first &&
799 git diff --exit-code second
802 test_expect_success 'am --committer-date-is-author-date' '
803 rm -fr .git/rebase-apply &&
805 git checkout first &&
807 git am --committer-date-is-author-date patch1 &&
808 git cat-file commit HEAD | sed -e "/^\$/q" >head1 &&
809 sed -ne "/^author /s/.*> //p" head1 >at &&
810 sed -ne "/^committer /s/.*> //p" head1 >ct &&
814 test_expect_success 'am without --committer-date-is-author-date' '
815 rm -fr .git/rebase-apply &&
817 git checkout first &&
820 git cat-file commit HEAD | sed -e "/^\$/q" >head1 &&
821 sed -ne "/^author /s/.*> //p" head1 >at &&
822 sed -ne "/^committer /s/.*> //p" head1 >ct &&
826 # This checks for +0000 because TZ is set to UTC and that should
827 # show up when the current time is used. The date in message is set
828 # by test_tick that uses -0700 timezone; if this feature does not
829 # work, we will see that instead of +0000.
830 test_expect_success 'am --ignore-date' '
831 rm -fr .git/rebase-apply &&
833 git checkout first &&
835 git am --ignore-date patch1 &&
836 git cat-file commit HEAD | sed -e "/^\$/q" >head1 &&
837 sed -ne "/^author /s/.*> //p" head1 >at &&
841 test_expect_success 'am into an unborn branch' '
842 git rev-parse first^{tree} >expected &&
843 rm -fr .git/rebase-apply &&
847 git format-patch --numbered-files -o subdir -1 first &&
855 git rev-parse HEAD^{tree} >../actual
857 test_cmp expected actual
860 test_expect_success 'am newline in subject' '
861 rm -fr .git/rebase-apply &&
863 git checkout first &&
865 sed -e "s/second/second \\\n foo/" patch1 >patchnl &&
866 git am <patchnl >output.out 2>&1 &&
867 test_i18ngrep "^Applying: second \\\n foo$" output.out
870 test_expect_success 'am -q is quiet' '
871 rm -fr .git/rebase-apply &&
873 git checkout first &&
875 git am -q <patch1 >output.out 2>&1 &&
876 test_must_be_empty output.out
879 test_expect_success 'am empty-file does not infloop' '
880 rm -fr .git/rebase-apply &&
884 test_must_fail git am empty-file 2>actual &&
885 echo Patch format detection failed. >expected &&
886 test_i18ncmp expected actual
889 test_expect_success 'am --message-id really adds the message id' '
890 rm -fr .git/rebase-apply &&
892 git checkout HEAD^ &&
893 git am --message-id patch1.eml &&
894 test_path_is_missing .git/rebase-apply &&
895 git cat-file commit HEAD | tail -n1 >actual &&
896 grep Message-Id patch1.eml >expected &&
897 test_cmp expected actual
900 test_expect_success 'am.messageid really adds the message id' '
901 rm -fr .git/rebase-apply &&
903 git checkout HEAD^ &&
904 test_config am.messageid true &&
906 test_path_is_missing .git/rebase-apply &&
907 git cat-file commit HEAD | tail -n1 >actual &&
908 grep Message-Id patch1.eml >expected &&
909 test_cmp expected actual
912 test_expect_success 'am --message-id -s signs off after the message id' '
913 rm -fr .git/rebase-apply &&
915 git checkout HEAD^ &&
916 git am -s --message-id patch1.eml &&
917 test_path_is_missing .git/rebase-apply &&
918 git cat-file commit HEAD | tail -n2 | head -n1 >actual &&
919 grep Message-Id patch1.eml >expected &&
920 test_cmp expected actual
923 test_expect_success 'am -3 works with rerere' '
924 rm -fr .git/rebase-apply &&
927 # make patches one->two and two->three...
928 test_commit one file &&
929 test_commit two file &&
930 test_commit three file &&
931 git format-patch -2 --stdout >seq.patch &&
933 # and create a situation that conflicts...
934 git reset --hard one &&
935 test_commit other file &&
938 test_config rerere.enabled true &&
939 test_when_finished "rm -rf .git/rr-cache" &&
941 # ...and apply. Our resolution is to skip the first
942 # patch, and the rerere the second one.
943 test_must_fail git am -3 seq.patch &&
944 test_must_fail git am --skip &&
945 echo resolved >file &&
949 # now apply again, and confirm that rerere engaged (we still
950 # expect failure from am because rerere does not auto-commit
952 git reset --hard other &&
953 test_must_fail git am -3 seq.patch &&
954 test_must_fail git am --skip &&
955 echo resolved >expect &&
959 test_expect_success 'am -s unexpected trailer block' '
960 rm -fr .git/rebase-apply &&
967 Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>
968 [jc: tweaked log message]
969 Signed-off-by: J C H <j@c.h>
972 git cat-file commit HEAD | sed -e '1,/^$/d' >original &&
973 git format-patch --stdout -1 >patch &&
975 git reset --hard HEAD^ &&
979 echo "Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>"
981 git cat-file commit HEAD | sed -e '1,/^$/d' >actual &&
982 test_cmp expect actual &&
987 We make sure that there is a blank line between the log
988 message proper and Signed-off-by: line added.
991 git commit -F msg file &&
992 git cat-file commit HEAD | sed -e '1,/^$/d' >original &&
993 git format-patch --stdout -1 >patch &&
995 git reset --hard HEAD^ &&
1001 echo "Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>"
1003 git cat-file commit HEAD | sed -e '1,/^$/d' >actual &&
1004 test_cmp expect actual
1007 test_expect_success 'am --patch-format=mboxrd handles mboxrd' '
1008 rm -fr .git/rebase-apply &&
1009 git checkout -f first &&
1010 echo mboxrd >>file &&
1012 cat >msg <<-\INPUT_END &&
1013 mboxrd should escape the body
1015 From could trip up a loose mbox parser
1016 >From extra escape for reversibility
1018 git commit -F msg &&
1019 git format-patch --pretty=mboxrd --stdout -1 >mboxrd1 &&
1020 grep "^>From could trip up a loose mbox parser" mboxrd1 &&
1021 git checkout -f first &&
1022 git am --patch-format=mboxrd mboxrd1 &&
1023 git cat-file commit HEAD | tail -n4 >out &&
1027 test_expect_success 'am works with multi-line in-body headers' '
1028 FORTY="String that has a length of more than forty characters" &&
1029 LONG="$FORTY $FORTY" &&
1030 rm -fr .git/rebase-apply &&
1031 git checkout -f first &&
1033 git commit -am "$LONG
1035 Body test" --author="$LONG <long@example.com>" &&
1036 git format-patch --stdout -1 >patch &&
1037 # bump from, date, and subject down to in-body header
1040 print \"From: x <x\@example.com>\";
1041 print \"Date: Sat, 1 Jan 2000 00:00:00 +0000\";
1042 print \"Subject: x\n\";
1045 git checkout HEAD^ &&
1047 # Ensure that the author and full message are present
1048 git cat-file commit HEAD | grep "^author.*long@example.com" &&
1049 git cat-file commit HEAD | grep "^$LONG$"
1052 test_expect_success 'am --quit keeps HEAD where it is' '
1053 mkdir .git/rebase-apply &&
1054 >.git/rebase-apply/last &&
1055 >.git/rebase-apply/next &&
1056 git rev-parse HEAD^ >.git/ORIG_HEAD &&
1057 git rev-parse HEAD >expected &&
1059 test_path_is_missing .git/rebase-apply &&
1060 git rev-parse HEAD >actual &&
1061 test_cmp expected actual