[PATCH 08/12] t4150: am with pre-applypatch hook

From
Paul Tan <hidden>
Date
2016-06-15 23:05:38
Reply to
Paul Tan, 2016-06-15
Since d1c5f2a (Add git-am, applymbox replacement., 2005-10-07),
git-am.sg will invoke the pre-applypatch hook after applying the patch
to the index, but before a commit is made. Should the hook exit with a
non-zero status, git am will exit.

Add tests for this hook.

Cc: Junio C Hamano <redacted>
Signed-off-by: Paul Tan <redacted>
---
 t/t4150-am.sh | 38 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)
diff --git a/t/t4150-am.sh b/t/t4150-am.sh
index 24c1b42..dd6fe81 100755
--- a/t/t4150-am.sh
+++ b/t/t4150-am.sh
@@ -237,6 +237,44 @@ test_expect_success 'am with failing applypatch-msg hook' '
 	test_cmp_rev first HEAD
 '
 
+test_expect_success 'am with pre-applypatch hook' '
+	test_when_finished "rm -f .git/hooks/pre-applypatch" &&
+	rm -fr .git/rebase-apply &&
+	git reset --hard &&
+	git checkout first &&
+	mkdir -p .git/hooks &&
+	cat >.git/hooks/pre-applypatch <<-\EOF &&
+	#!/bin/sh
+	git diff first >diff.actual
+	exit 0
+	EOF
+	chmod +x .git/hooks/pre-applypatch &&
+	git am patch1 &&
+	test_path_is_missing .git/rebase-apply &&
+	git diff --exit-code second &&
+	test_cmp_rev second HEAD &&
+	test_cmp_rev second^ HEAD^ &&
+	git diff first..second >diff.expected &&
+	test_cmp diff.expected diff.actual
+'
+
+test_expect_success 'am with failing pre-applypatch hook' '
+	test_when_finished "rm -f .git/hooks/pre-applypatch" &&
+	rm -fr .git/rebase-apply &&
+	git reset --hard &&
+	git checkout first &&
+	mkdir -p .git/hooks &&
+	cat >.git/hooks/pre-applypatch <<-\EOF &&
+	#!/bin/sh
+	exit 1
+	EOF
+	chmod +x .git/hooks/pre-applypatch &&
+	test_must_fail git am patch1 &&
+	test_path_is_dir .git/rebase-apply &&
+	git diff --exit-code second &&
+	test_cmp_rev first HEAD
+'
+
 test_expect_success 'setup: new author and committer' '
 	GIT_AUTHOR_NAME="Another Thor" &&
 	GIT_AUTHOR_EMAIL="a.thor@example.com" &&
-- 
2.5.0.rc1.81.gfe77482
Thread (23 messages) 23 messages, 5 authors, 2016-06-15
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help