@@ -67,6 +67,19 @@ test_expect_success 'setup: messages' '
6767
6868 EOF
6969
70+ cat >scissors-msg <<-\EOF &&
71+ Test git-am with scissors line
72+
73+ This line should be included in the commit message.
74+ EOF
75+
76+ cat - scissors-msg >no-scissors-msg <<-\EOF &&
77+ This line should not be included in the commit message with --scissors enabled.
78+
79+ - - >8 - - remove everything above this line - - >8 - -
80+
81+ EOF
82+
7083 signoff="Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>"
7184'
7285
@@ -137,6 +150,20 @@ test_expect_success setup '
137150 } >patch1-hg.eml &&
138151
139152
153+ echo scissors-file >scissors-file &&
154+ git add scissors-file &&
155+ git commit -F scissors-msg &&
156+ git tag scissors &&
157+ git format-patch --stdout scissors^ >scissors-patch.eml &&
158+ git reset --hard HEAD^ &&
159+
160+ echo no-scissors-file >no-scissors-file &&
161+ git add no-scissors-file &&
162+ git commit -F no-scissors-msg &&
163+ git tag no-scissors &&
164+ git format-patch --stdout no-scissors^ >no-scissors-patch.eml &&
165+ git reset --hard HEAD^ &&
166+
140167 sed -n -e "3,\$p" msg >file &&
141168 git add file &&
142169 test_tick &&
@@ -186,6 +213,18 @@ test_expect_success 'am applies patch correctly' '
186213 test "$(git rev-parse second^)" = "$(git rev-parse HEAD^)"
187214'
188215
216+ test_expect_success ' am fails if index is dirty' '
217+ test_when_finished "rm -f dirtyfile" &&
218+ rm -fr .git/rebase-apply &&
219+ git reset --hard &&
220+ git checkout first &&
221+ echo dirtyfile >dirtyfile &&
222+ git add dirtyfile &&
223+ test_must_fail git am patch1 &&
224+ test_path_is_dir .git/rebase-apply &&
225+ test_cmp_rev first HEAD
226+ '
227+
189228test_expect_success ' am applies patch e-mail not in a mbox' '
190229 rm -fr .git/rebase-apply &&
191230 git reset --hard &&
@@ -269,6 +308,133 @@ test_expect_success 'am --patch-format=hg applies hg patch' '
269308 test_cmp_rev second^ HEAD^
270309'
271310
311+ test_expect_success ' am with applypatch-msg hook' '
312+ test_when_finished "rm -f .git/hooks/applypatch-msg" &&
313+ rm -fr .git/rebase-apply &&
314+ git reset --hard &&
315+ git checkout first &&
316+ mkdir -p .git/hooks &&
317+ write_script .git/hooks/applypatch-msg <<-\EOF &&
318+ cat "$1" >actual-msg &&
319+ echo hook-message >"$1"
320+ EOF
321+ git am patch1 &&
322+ test_path_is_missing .git/rebase-apply &&
323+ git diff --exit-code second &&
324+ echo hook-message >expected &&
325+ git log -1 --format=format:%B >actual &&
326+ test_cmp expected actual &&
327+ git log -1 --format=format:%B second >expected &&
328+ test_cmp expected actual-msg
329+ '
330+
331+ test_expect_success ' am with failing applypatch-msg hook' '
332+ test_when_finished "rm -f .git/hooks/applypatch-msg" &&
333+ rm -fr .git/rebase-apply &&
334+ git reset --hard &&
335+ git checkout first &&
336+ mkdir -p .git/hooks &&
337+ write_script .git/hooks/applypatch-msg <<-\EOF &&
338+ exit 1
339+ EOF
340+ test_must_fail git am patch1 &&
341+ test_path_is_dir .git/rebase-apply &&
342+ git diff --exit-code first &&
343+ test_cmp_rev first HEAD
344+ '
345+
346+ test_expect_success ' am with pre-applypatch hook' '
347+ test_when_finished "rm -f .git/hooks/pre-applypatch" &&
348+ rm -fr .git/rebase-apply &&
349+ git reset --hard &&
350+ git checkout first &&
351+ mkdir -p .git/hooks &&
352+ write_script .git/hooks/pre-applypatch <<-\EOF &&
353+ git diff first >diff.actual
354+ exit 0
355+ EOF
356+ git am patch1 &&
357+ test_path_is_missing .git/rebase-apply &&
358+ git diff --exit-code second &&
359+ test_cmp_rev second HEAD &&
360+ git diff first..second >diff.expected &&
361+ test_cmp diff.expected diff.actual
362+ '
363+
364+ test_expect_success ' am with failing pre-applypatch hook' '
365+ test_when_finished "rm -f .git/hooks/pre-applypatch" &&
366+ rm -fr .git/rebase-apply &&
367+ git reset --hard &&
368+ git checkout first &&
369+ mkdir -p .git/hooks &&
370+ write_script .git/hooks/pre-applypatch <<-\EOF &&
371+ exit 1
372+ EOF
373+ test_must_fail git am patch1 &&
374+ test_path_is_dir .git/rebase-apply &&
375+ git diff --exit-code second &&
376+ test_cmp_rev first HEAD
377+ '
378+
379+ test_expect_success ' am with post-applypatch hook' '
380+ test_when_finished "rm -f .git/hooks/post-applypatch" &&
381+ rm -fr .git/rebase-apply &&
382+ git reset --hard &&
383+ git checkout first &&
384+ mkdir -p .git/hooks &&
385+ write_script .git/hooks/post-applypatch <<-\EOF &&
386+ git rev-parse HEAD >head.actual
387+ git diff second >diff.actual
388+ exit 0
389+ EOF
390+ git am patch1 &&
391+ test_path_is_missing .git/rebase-apply &&
392+ test_cmp_rev second HEAD &&
393+ git rev-parse second >head.expected &&
394+ test_cmp head.expected head.actual &&
395+ git diff second >diff.expected &&
396+ test_cmp diff.expected diff.actual
397+ '
398+
399+ test_expect_success ' am with failing post-applypatch hook' '
400+ test_when_finished "rm -f .git/hooks/post-applypatch" &&
401+ rm -fr .git/rebase-apply &&
402+ git reset --hard &&
403+ git checkout first &&
404+ mkdir -p .git/hooks &&
405+ write_script .git/hooks/post-applypatch <<-\EOF &&
406+ git rev-parse HEAD >head.actual
407+ exit 1
408+ EOF
409+ git am patch1 &&
410+ test_path_is_missing .git/rebase-apply &&
411+ git diff --exit-code second &&
412+ test_cmp_rev second HEAD &&
413+ git rev-parse second >head.expected &&
414+ test_cmp head.expected head.actual
415+ '
416+
417+ test_expect_success ' am --scissors cuts the message at the scissors line' '
418+ rm -fr .git/rebase-apply &&
419+ git reset --hard &&
420+ git checkout second &&
421+ git am --scissors scissors-patch.eml &&
422+ test_path_is_missing .git/rebase-apply &&
423+ git diff --exit-code scissors &&
424+ test_cmp_rev scissors HEAD
425+ '
426+
427+ test_expect_success ' am --no-scissors overrides mailinfo.scissors' '
428+ rm -fr .git/rebase-apply &&
429+ git reset --hard &&
430+ git checkout second &&
431+ test_config mailinfo.scissors true &&
432+ git am --no-scissors no-scissors-patch.eml &&
433+ test_path_is_missing .git/rebase-apply &&
434+ git diff --exit-code no-scissors &&
435+ test_cmp_rev no-scissors HEAD
436+ '
437+
272438test_expect_success ' setup: new author and committer' '
273439 GIT_AUTHOR_NAME="Another Thor" &&
274440 GIT_AUTHOR_EMAIL="a.thor@example.com" &&
@@ -448,6 +614,20 @@ test_expect_success 'am --abort removes a stray directory' '
448614 test_path_is_missing .git/rebase-apply
449615'
450616
617+ test_expect_success ' am refuses patches when paused' '
618+ rm -fr .git/rebase-apply &&
619+ git reset --hard &&
620+ git checkout lorem2^^ &&
621+
622+ test_must_fail git am lorem-move.patch &&
623+ test_path_is_dir .git/rebase-apply &&
624+ test_cmp_rev lorem2^^ HEAD &&
625+
626+ test_must_fail git am <lorem-move.patch &&
627+ test_path_is_dir .git/rebase-apply &&
628+ test_cmp_rev lorem2^^ HEAD
629+ '
630+
451631test_expect_success ' am --resolved works' '
452632 echo goodbye >expected &&
453633 rm -fr .git/rebase-apply &&
@@ -462,6 +642,31 @@ test_expect_success 'am --resolved works' '
462642 test_cmp expected another
463643'
464644
645+ test_expect_success ' am --resolved fails if index has no changes' '
646+ rm -fr .git/rebase-apply &&
647+ git reset --hard &&
648+ git checkout lorem2^^ &&
649+ test_must_fail git am lorem-move.patch &&
650+ test_path_is_dir .git/rebase-apply &&
651+ test_cmp_rev lorem2^^ HEAD &&
652+ test_must_fail git am --resolved &&
653+ test_path_is_dir .git/rebase-apply &&
654+ test_cmp_rev lorem2^^ HEAD
655+ '
656+
657+ test_expect_success ' am --resolved fails if index has unmerged entries' '
658+ rm -fr .git/rebase-apply &&
659+ git reset --hard &&
660+ git checkout second &&
661+ test_must_fail git am -3 lorem-move.patch &&
662+ test_path_is_dir .git/rebase-apply &&
663+ test_cmp_rev second HEAD &&
664+ test_must_fail git am --resolved >err &&
665+ test_path_is_dir .git/rebase-apply &&
666+ test_cmp_rev second HEAD &&
667+ test_i18ngrep "still have unmerged paths" err
668+ '
669+
465670test_expect_success ' am takes patches from a Pine mailbox' '
466671 rm -fr .git/rebase-apply &&
467672 git reset --hard &&
@@ -626,6 +831,18 @@ test_expect_success 'am --message-id really adds the message id' '
626831 test_cmp expected actual
627832'
628833
834+ test_expect_success ' am.messageid really adds the message id' '
835+ rm -fr .git/rebase-apply &&
836+ git reset --hard &&
837+ git checkout HEAD^ &&
838+ test_config am.messageid true &&
839+ git am patch1.eml &&
840+ test_path_is_missing .git/rebase-apply &&
841+ git cat-file commit HEAD | tail -n1 >actual &&
842+ grep Message-Id patch1.eml >expected &&
843+ test_cmp expected actual
844+ '
845+
629846test_expect_success ' am --message-id -s signs off after the message id' '
630847 rm -fr .git/rebase-apply &&
631848 git reset --hard &&
0 commit comments