git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 07/12] t4150: am with applypatch-msg hook

From
Paul Tan <pyokagan@gmail.com>
Date
Jul 2, 2015, 18:16 UTC
Message-ID
<1435861000-25278-8-git-send-email-pyokagan@gmail.com>
In-Reply-To
<1435861000-25278-1-git-send-email-pyokagan@gmail.com>

Since d1c5f2a (Add git-am, applymbox replacement., 2005-10-07), git-am will invoke the applypatch-msg hooks just after extracting the patch message. If the applypatch-msg hook exits with a non-zero status, git-am abort before even applying the patch to the index.

Add tests for this hook.
Cc: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Paul Tan <pyokagan@gmail.com>
---
 t/t4150-am.sh | 39 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)
diff --git a/t/t4150-am.sh b/t/t4150-am.sh
index 05494e9..24c1b42 100755
--- a/t/t4150-am.sh
+++ b/t/t4150-am.sh
@@ -198,6 +198,45 @@ test_expect_success 'am applies patch e-mail with preceding whitespace' '
 	test "$(git rev-parse second^)" = "$(git rev-parse HEAD^)"
 '
 
+test_expect_success 'am with applypatch-msg hook' '
+	test_when_finished "rm -f .git/hooks/applypatch-msg" &&
+	rm -fr .git/rebase-apply &&
+	git reset --hard &&
+	git checkout first &&
+	mkdir -p .git/hooks &&
+	cat >.git/hooks/applypatch-msg <<-\EOF &&
+	#!/bin/sh
+	cat "$1" >actual-msg &&
+	echo hook-message >"$1"
+	EOF
+	chmod +x .git/hooks/applypatch-msg &&
+	git am patch1 &&
+	test_path_is_missing .git/rebase-apply &&
+	git diff --exit-code second &&
+	echo hook-message >expected &&
+	git log -1 --format=format:%B >actual &&
+	test_cmp expected actual &&
+	git log -1 --format=format:%B second >expected &&
+	test_cmp expected actual-msg
+'
+
+test_expect_success 'am with failing applypatch-msg hook' '
+	test_when_finished "rm -f .git/hooks/applypatch-msg" &&
+	rm -fr .git/rebase-apply &&
+	git reset --hard &&
+	git checkout first &&
+	mkdir -p .git/hooks &&
+	cat >.git/hooks/applypatch-msg <<-\EOF &&
+	#!/bin/sh
+	exit 1
+	EOF
+	chmod +x .git/hooks/applypatch-msg &&
+	test_must_fail git am patch1 &&
+	test_path_is_dir .git/rebase-apply &&
+	git diff --exit-code first &&
+	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
Previous: Paul TanNext: Junio C Hamano
Message 12 of 26 in “Improve git-am test coverage”
  1. 00/12 Improve git-am test coveragePaul Tan, Jul 2, 2015
  2. 01/12 t4150: am.messageid really adds the message idPaul Tan, Jul 2, 2015
  3. Paolo BonziniJul 2, 2015
  4. Junio C HamanoJul 6, 2015
  5. 02/12 t4150: am fails if index is dirtyPaul Tan, Jul 2, 2015
  6. Johannes SchindelinJul 5, 2015
  7. Paul TanJul 7, 2015
  8. 03/12 t4151: am --abort will keep dirty index intactPaul Tan, Jul 2, 2015
  9. 04/12 t4150: am refuses patches when pausedPaul Tan, Jul 2, 2015
  10. 05/12 t4150: am --resolved fails if index has no changesPaul Tan, Jul 2, 2015
  11. 06/12 t4150: am --resolved fails if index has unmerged entriesPaul Tan, Jul 2, 2015
  12. 07/12 t4150: am with applypatch-msg hookPaul Tan, Jul 2, 2015
  13. Junio C HamanoJul 6, 2015
  14. 08/12 t4150: am with pre-applypatch hookPaul Tan, Jul 2, 2015
  15. 09/12 t4150: am with post-applypatch hookPaul Tan, Jul 2, 2015
  16. Johannes SchindelinJul 5, 2015
  17. Paul TanJul 7, 2015
  18. Johannes SchindelinJul 7, 2015
  19. 10/12 t4150: tests for am --[no-]scissorsPaul Tan, Jul 2, 2015
  20. 11/12 t3418: non-interactive rebase --continue with rerere enabledPaul Tan, Jul 2, 2015
  21. 12/12 t3901: test git-am encoding conversionPaul Tan, Jul 2, 2015
  22. Johannes SixtJul 8, 2015
  23. Paul TanJul 14, 2015
  24. Stefan BellerJul 3, 2015
  25. Johannes SchindelinJul 5, 2015
  26. Junio C HamanoJul 6, 2015

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.