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 topic_2 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/topic_2 >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 topic_2 >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 topic_2 &&
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 --show-current-patch=raw' '
670 git am --show-current-patch=raw >actual.patch &&
671 test_cmp .git/rebase-apply/0001 actual.patch
674 test_expect_success 'am --show-current-patch=diff' '
675 git am --show-current-patch=diff >actual.patch &&
676 test_cmp .git/rebase-apply/patch actual.patch
679 test_expect_success 'am accepts repeated --show-current-patch' '
680 git am --show-current-patch --show-current-patch=raw >actual.patch &&
681 test_cmp .git/rebase-apply/0001 actual.patch
684 test_expect_success 'am detects incompatible --show-current-patch' '
685 test_must_fail git am --show-current-patch=raw --show-current-patch=diff &&
686 test_must_fail git am --show-current-patch --show-current-patch=diff
689 test_expect_success 'am --skip works' '
690 echo goodbye >expected &&
692 test_path_is_missing .git/rebase-apply &&
693 git diff --exit-code lorem2^^ -- file &&
694 test_cmp expected another
697 test_expect_success 'am --abort removes a stray directory' '
698 mkdir .git/rebase-apply &&
700 test_path_is_missing .git/rebase-apply
703 test_expect_success 'am refuses patches when paused' '
704 rm -fr .git/rebase-apply &&
706 git checkout lorem2^^ &&
708 test_must_fail git am lorem-move.patch &&
709 test_path_is_dir .git/rebase-apply &&
710 test_cmp_rev lorem2^^ HEAD &&
712 test_must_fail git am <lorem-move.patch &&
713 test_path_is_dir .git/rebase-apply &&
714 test_cmp_rev lorem2^^ HEAD
717 test_expect_success 'am --resolved works' '
718 echo goodbye >expected &&
719 rm -fr .git/rebase-apply &&
721 git checkout lorem2^^ &&
722 test_must_fail git am lorem-move.patch &&
723 test -d .git/rebase-apply &&
724 echo resolved >>file &&
727 test_path_is_missing .git/rebase-apply &&
728 test_cmp expected another
731 test_expect_success 'am --resolved fails if index has no changes' '
732 rm -fr .git/rebase-apply &&
734 git checkout lorem2^^ &&
735 test_must_fail git am lorem-move.patch &&
736 test_path_is_dir .git/rebase-apply &&
737 test_cmp_rev lorem2^^ HEAD &&
738 test_must_fail git am --resolved &&
739 test_path_is_dir .git/rebase-apply &&
740 test_cmp_rev lorem2^^ HEAD
743 test_expect_success 'am --resolved fails if index has unmerged entries' '
744 rm -fr .git/rebase-apply &&
746 git checkout second &&
747 test_must_fail git am -3 lorem-move.patch &&
748 test_path_is_dir .git/rebase-apply &&
749 test_cmp_rev second HEAD &&
750 test_must_fail git am --resolved >err &&
751 test_path_is_dir .git/rebase-apply &&
752 test_cmp_rev second HEAD &&
753 test_i18ngrep "still have unmerged paths" err
756 test_expect_success 'am takes patches from a Pine mailbox' '
757 rm -fr .git/rebase-apply &&
759 git checkout first &&
760 cat pine patch1 | git am &&
761 test_path_is_missing .git/rebase-apply &&
762 git diff --exit-code master^..HEAD
765 test_expect_success 'am fails on mail without patch' '
766 rm -fr .git/rebase-apply &&
768 test_must_fail git am <failmail &&
770 test_path_is_missing .git/rebase-apply
773 test_expect_success 'am fails on empty patch' '
774 rm -fr .git/rebase-apply &&
776 echo "---" >>failmail &&
777 test_must_fail git am <failmail &&
779 test_path_is_missing .git/rebase-apply
782 test_expect_success 'am works from stdin in subdirectory' '
784 rm -fr .git/rebase-apply &&
786 git checkout first &&
792 git diff --exit-code second
795 test_expect_success 'am works from file (relative path given) in subdirectory' '
797 rm -fr .git/rebase-apply &&
799 git checkout first &&
805 git diff --exit-code second
808 test_expect_success 'am works from file (absolute path given) in subdirectory' '
810 rm -fr .git/rebase-apply &&
812 git checkout first &&
819 git diff --exit-code second
822 test_expect_success 'am --committer-date-is-author-date' '
823 rm -fr .git/rebase-apply &&
825 git checkout first &&
827 git am --committer-date-is-author-date patch1 &&
828 git cat-file commit HEAD | sed -e "/^\$/q" >head1 &&
829 sed -ne "/^author /s/.*> //p" head1 >at &&
830 sed -ne "/^committer /s/.*> //p" head1 >ct &&
834 test_expect_success 'am without --committer-date-is-author-date' '
835 rm -fr .git/rebase-apply &&
837 git checkout first &&
840 git cat-file commit HEAD | sed -e "/^\$/q" >head1 &&
841 sed -ne "/^author /s/.*> //p" head1 >at &&
842 sed -ne "/^committer /s/.*> //p" head1 >ct &&
846 # This checks for +0000 because TZ is set to UTC and that should
847 # show up when the current time is used. The date in message is set
848 # by test_tick that uses -0700 timezone; if this feature does not
849 # work, we will see that instead of +0000.
850 test_expect_success 'am --ignore-date' '
851 rm -fr .git/rebase-apply &&
853 git checkout first &&
855 git am --ignore-date patch1 &&
856 git cat-file commit HEAD | sed -e "/^\$/q" >head1 &&
857 sed -ne "/^author /s/.*> //p" head1 >at &&
861 test_expect_success 'am into an unborn branch' '
862 git rev-parse first^{tree} >expected &&
863 rm -fr .git/rebase-apply &&
867 git format-patch --numbered-files -o subdir -1 first &&
875 git rev-parse HEAD^{tree} >../actual
877 test_cmp expected actual
880 test_expect_success 'am newline in subject' '
881 rm -fr .git/rebase-apply &&
883 git checkout first &&
885 sed -e "s/second/second \\\n foo/" patch1 >patchnl &&
886 git am <patchnl >output.out 2>&1 &&
887 test_i18ngrep "^Applying: second \\\n foo$" output.out
890 test_expect_success 'am -q is quiet' '
891 rm -fr .git/rebase-apply &&
893 git checkout first &&
895 git am -q <patch1 >output.out 2>&1 &&
896 test_must_be_empty output.out
899 test_expect_success 'am empty-file does not infloop' '
900 rm -fr .git/rebase-apply &&
904 test_must_fail git am empty-file 2>actual &&
905 echo Patch format detection failed. >expected &&
906 test_i18ncmp expected actual
909 test_expect_success 'am --message-id really adds the message id' '
910 rm -fr .git/rebase-apply &&
912 git checkout HEAD^ &&
913 git am --message-id patch1.eml &&
914 test_path_is_missing .git/rebase-apply &&
915 git cat-file commit HEAD | tail -n1 >actual &&
916 grep Message-Id patch1.eml >expected &&
917 test_cmp expected actual
920 test_expect_success 'am.messageid really adds the message id' '
921 rm -fr .git/rebase-apply &&
923 git checkout HEAD^ &&
924 test_config am.messageid true &&
926 test_path_is_missing .git/rebase-apply &&
927 git cat-file commit HEAD | tail -n1 >actual &&
928 grep Message-Id patch1.eml >expected &&
929 test_cmp expected actual
932 test_expect_success 'am --message-id -s signs off after the message id' '
933 rm -fr .git/rebase-apply &&
935 git checkout HEAD^ &&
936 git am -s --message-id patch1.eml &&
937 test_path_is_missing .git/rebase-apply &&
938 git cat-file commit HEAD | tail -n2 | head -n1 >actual &&
939 grep Message-Id patch1.eml >expected &&
940 test_cmp expected actual
943 test_expect_success 'am -3 works with rerere' '
944 rm -fr .git/rebase-apply &&
947 # make patches one->two and two->three...
948 test_commit one file &&
949 test_commit two file &&
950 test_commit three file &&
951 git format-patch -2 --stdout >seq.patch &&
953 # and create a situation that conflicts...
954 git reset --hard one &&
955 test_commit other file &&
958 test_config rerere.enabled true &&
959 test_when_finished "rm -rf .git/rr-cache" &&
961 # ...and apply. Our resolution is to skip the first
962 # patch, and the rerere the second one.
963 test_must_fail git am -3 seq.patch &&
964 test_must_fail git am --skip &&
965 echo resolved >file &&
969 # now apply again, and confirm that rerere engaged (we still
970 # expect failure from am because rerere does not auto-commit
972 git reset --hard other &&
973 test_must_fail git am -3 seq.patch &&
974 test_must_fail git am --skip &&
975 echo resolved >expect &&
979 test_expect_success 'am -s unexpected trailer block' '
980 rm -fr .git/rebase-apply &&
987 Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>
988 [jc: tweaked log message]
989 Signed-off-by: J C H <j@c.h>
992 git cat-file commit HEAD | sed -e "1,/^$/d" >original &&
993 git format-patch --stdout -1 >patch &&
995 git reset --hard HEAD^ &&
999 echo "Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>"
1001 git cat-file commit HEAD | sed -e "1,/^$/d" >actual &&
1002 test_cmp expect actual &&
1007 We make sure that there is a blank line between the log
1008 message proper and Signed-off-by: line added.
1011 git commit -F msg file &&
1012 git cat-file commit HEAD | sed -e "1,/^$/d" >original &&
1013 git format-patch --stdout -1 >patch &&
1015 git reset --hard HEAD^ &&
1021 echo "Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>"
1023 git cat-file commit HEAD | sed -e "1,/^$/d" >actual &&
1024 test_cmp expect actual
1027 test_expect_success 'am --patch-format=mboxrd handles mboxrd' '
1028 rm -fr .git/rebase-apply &&
1029 git checkout -f first &&
1030 echo mboxrd >>file &&
1032 cat >msg <<-\INPUT_END &&
1033 mboxrd should escape the body
1035 From could trip up a loose mbox parser
1036 >From extra escape for reversibility
1038 git commit -F msg &&
1039 git format-patch --pretty=mboxrd --stdout -1 >mboxrd1 &&
1040 grep "^>From could trip up a loose mbox parser" mboxrd1 &&
1041 git checkout -f first &&
1042 git am --patch-format=mboxrd mboxrd1 &&
1043 git cat-file commit HEAD | tail -n4 >out &&
1047 test_expect_success 'am works with multi-line in-body headers' '
1048 FORTY="String that has a length of more than forty characters" &&
1049 LONG="$FORTY $FORTY" &&
1050 rm -fr .git/rebase-apply &&
1051 git checkout -f first &&
1053 git commit -am "$LONG
1055 Body test" --author="$LONG <long@example.com>" &&
1056 git format-patch --stdout -1 >patch &&
1057 # bump from, date, and subject down to in-body header
1060 print \"From: x <x\@example.com>\";
1061 print \"Date: Sat, 1 Jan 2000 00:00:00 +0000\";
1062 print \"Subject: x\n\";
1065 git checkout HEAD^ &&
1067 # Ensure that the author and full message are present
1068 git cat-file commit HEAD | grep "^author.*long@example.com" &&
1069 git cat-file commit HEAD | grep "^$LONG$"
1072 test_expect_success 'am --quit keeps HEAD where it is' '
1073 mkdir .git/rebase-apply &&
1074 >.git/rebase-apply/last &&
1075 >.git/rebase-apply/next &&
1076 git rev-parse HEAD^ >.git/ORIG_HEAD &&
1077 git rev-parse HEAD >expected &&
1079 test_path_is_missing .git/rebase-apply &&
1080 git rev-parse HEAD >actual &&
1081 test_cmp expected actual
1084 test_expect_success 'am and .gitattibutes' '
1085 test_create_repo attributes &&
1089 git config filter.test.clean "sed -e '\''s/smudged/clean/g'\''" &&
1090 git config filter.test.smudge "sed -e '\''s/clean/smudged/g'\''" &&
1092 test_commit second &&
1093 git checkout -b test HEAD^ &&
1095 echo "*.txt filter=test conflict-marker-size=10" >.gitattributes &&
1096 git add .gitattributes &&
1097 test_commit third &&
1099 echo "This text is smudged." >a.txt &&
1101 test_commit fourth &&
1103 git checkout -b removal HEAD^ &&
1104 git rm .gitattributes &&
1106 test_commit fifth &&
1107 git cherry-pick test &&
1109 git checkout -b conflict third &&
1110 echo "This text is different." >a.txt &&
1112 test_commit sixth &&
1114 git checkout test &&
1115 git format-patch --stdout master..HEAD >patches &&
1116 git reset --hard master &&
1118 grep "smudged" a.txt &&
1120 git checkout removal &&
1122 git format-patch --stdout master..HEAD >patches &&
1123 git reset --hard master &&
1125 grep "clean" a.txt &&
1127 git checkout conflict &&
1129 git format-patch --stdout master..HEAD >patches &&
1130 git reset --hard fourth &&
1131 test_must_fail git am -3 patches &&
1132 grep "<<<<<<<<<<" a.txt
1136 test_expect_success 'apply binary blob in partial clone' '
1137 printf "\\000" >binary &&
1139 git commit -m "binary blob" &&
1140 git format-patch --stdout -m HEAD^ >patch &&
1142 test_create_repo server &&
1143 test_config -C server uploadpack.allowfilter 1 &&
1144 test_config -C server uploadpack.allowanysha1inwant 1 &&
1145 git clone --filter=blob:none "file://$(pwd)/server" client &&
1146 test_when_finished "rm -rf client" &&
1148 # Exercise to make sure that it works
1149 git -C client am ../patch