Since d1c5f2a (Add git-am, applymbox replacement., 2005-10-07),
git-am.sh will invoke the post-applypatch hook after the patch is
applied and a commit is made. The exit code of the hook is ignored.

Add tests for this hook.

Cc: Junio C Hamano <gits...@pobox.com>
Signed-off-by: Paul Tan <pyoka...@gmail.com>
---
 t/t4150-am.sh | 42 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)

diff --git a/t/t4150-am.sh b/t/t4150-am.sh
index dd6fe81..62b678c 100755
--- a/t/t4150-am.sh
+++ b/t/t4150-am.sh
@@ -275,6 +275,48 @@ test_expect_success 'am with failing pre-applypatch hook' '
        test_cmp_rev first HEAD
 '
 
+test_expect_success 'am with post-applypatch hook' '
+       test_when_finished "rm -f .git/hooks/post-applypatch" &&
+       rm -fr .git/rebase-apply &&
+       git reset --hard &&
+       git checkout first &&
+       mkdir -p .git/hooks &&
+       cat >.git/hooks/post-applypatch <<-\EOF &&
+       #!/bin/sh
+       git rev-parse HEAD >head.actual
+       git diff second >diff.actual
+       exit 0
+       EOF
+       chmod +x .git/hooks/post-applypatch &&
+       git am patch1 &&
+       test_path_is_missing .git/rebase-apply &&
+       test_cmp_rev second HEAD &&
+       git rev-parse second >head.expected &&
+       test_cmp head.expected head.actual &&
+       git diff second >diff.expected &&
+       test_cmp diff.expected diff.actual
+'
+
+test_expect_success 'am with failing post-applypatch hook' '
+       test_when_finished "rm -f .git/hooks/post-applypatch" &&
+       rm -fr .git/rebase-apply &&
+       git reset --hard &&
+       git checkout first &&
+       mkdir -p .git/hooks &&
+       cat >.git/hooks/post-applypatch <<-\EOF &&
+       #!/bin/sh
+       git rev-parse HEAD >head.actual
+       exit 1
+       EOF
+       chmod +x .git/hooks/post-applypatch &&
+       git am patch1 &&
+       test_path_is_missing .git/rebase-apply &&
+       git diff --exit-code second &&
+       test_cmp_rev second HEAD &&
+       git rev-parse second >head.expected &&
+       test_cmp head.expected head.actual
+'
+
 test_expect_success 'setup: new author and committer' '
        GIT_AUTHOR_NAME="Another Thor" &&
        GIT_AUTHOR_EMAIL="a.t...@example.com" &&
-- 
2.5.0.rc1.81.gfe77482

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to