(CommandList children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:test_description) op: Equal rhs: {(SQ <"pre-commit hook">)} spids: [4] ) ] spids: [4] ) (C {(.)} {(./test-lib.sh)}) (C {(test_expect_success)} {(SQ <"with no hook">)} { (SQ <"\n"> <"\n"> <"\techo \"foo\" > file &&\n"> <"\tgit add file &&\n"> <"\tgit commit -m \"first\"\n"> <"\n"> ) } ) (C {(test_expect_success)} {(SQ <"--no-verify with no hook">)} { (SQ <"\n"> <"\n"> <"\techo \"bar\" > file &&\n"> <"\tgit add file &&\n"> <"\tgit commit --no-verify -m \"bar\"\n"> <"\n"> ) } ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:HOOKDIR) op: Equal rhs: { (DQ (CommandSubPart command_list: (CommandList children:[(C {(git)} {(rev-parse)} {(--git-dir)})]) left_token: <Left_CommandSub "$("> spids: [52 58] ) (/hooks) ) } spids: [50] ) ] spids: [50] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:HOOK) op: Equal rhs: {(DQ ($ VSub_Name "$HOOKDIR") (/pre-commit))} spids: [62] ) ] spids: [62] ) (C {(mkdir)} {(-p)} {(DQ ($ VSub_Name "$HOOKDIR"))}) (SimpleCommand words: [{(cat)}] redirects: [ (Redir op_id:Redir_Great fd:-1 arg_word:{(DQ ($ VSub_Name "$HOOK"))} spids:[78]) (HereDoc op_id: Redir_DLess fd: -1 body: {(DQ ("#!/bin/sh\n") ("exit 0\n"))} do_expansion: True here_end: EOF was_filled: True spids: [84] ) ] ) (C {(chmod)} {(Lit_Other "+") (x)} {(DQ ($ VSub_Name "$HOOK"))}) (C {(test_expect_success)} {(SQ <"with succeeding hook">)} { (SQ <"\n"> <"\n"> <"\techo \"more\" >> file &&\n"> <"\tgit add file &&\n"> <"\tgit commit -m \"more\"\n"> <"\n"> ) } ) (C {(test_expect_success)} {(SQ <"--no-verify with succeeding hook">)} { (SQ <"\n"> <"\n"> <"\techo \"even more\" >> file &&\n"> <"\tgit add file &&\n"> <"\tgit commit --no-verify -m \"even more\"\n"> <"\n"> ) } ) (SimpleCommand words: [{(cat)}] redirects: [ (Redir op_id:Redir_Great fd:-1 arg_word:{(DQ ($ VSub_Name "$HOOK"))} spids:[136]) (HereDoc op_id: Redir_DLess fd: -1 body: {(DQ ("#!/bin/sh\n") ("exit 1\n"))} do_expansion: True here_end: EOF was_filled: True spids: [142] ) ] ) (C {(test_expect_success)} {(SQ <"with failing hook">)} { (SQ <"\n"> <"\n"> <"\techo \"another\" >> file &&\n"> <"\tgit add file &&\n"> <"\ttest_must_fail git commit -m \"another\"\n"> <"\n"> ) } ) (C {(test_expect_success)} {(SQ <"--no-verify with failing hook">)} { (SQ <"\n"> <"\n"> <"\techo \"stuff\" >> file &&\n"> <"\tgit add file &&\n"> <"\tgit commit --no-verify -m \"stuff\"\n"> <"\n"> ) } ) (C {(chmod)} {(-x)} {(DQ ($ VSub_Name "$HOOK"))}) (C {(test_expect_success)} {(POSIXPERM)} {(SQ <"with non-executable hook">)} { (SQ <"\n"> <"\n"> <"\techo \"content\" >> file &&\n"> <"\tgit add file &&\n"> <"\tgit commit -m \"content\"\n"> <"\n"> ) } ) (C {(test_expect_success)} {(POSIXPERM)} {(SQ <"--no-verify with non-executable hook">)} { (SQ <"\n"> <"\n"> <"\techo \"more content\" >> file &&\n"> <"\tgit add file &&\n"> <"\tgit commit --no-verify -m \"more content\"\n"> <"\n"> ) } ) (C {(chmod)} {(Lit_Other "+") (x)} {(DQ ($ VSub_Name "$HOOK"))}) (SimpleCommand words: [{(cat)}] redirects: [ (Redir op_id:Redir_Great fd:-1 arg_word:{(DQ ($ VSub_Name "$HOOK"))} spids:[241]) (HereDoc op_id: Redir_DLess fd: -1 body: { (DQ ("#!/bin/sh\n") ("test ") (EscapedLiteralPart token:<Lit_EscapedChar "\\$">) ("GIT_PREFIX = success/\n") ) } do_expansion: True here_end: EOF was_filled: True spids: [247] ) ] ) (C {(test_expect_success)} {(SQ <"with hook requiring GIT_PREFIX">)} { (SQ <"\n"> <"\n"> <"\techo \"more content\" >> file &&\n"> <"\tgit add file &&\n"> <"\tmkdir success &&\n"> <"\t(\n"> <"\t\tcd success &&\n"> <"\t\tgit commit -m \"hook requires GIT_PREFIX = success/\"\n"> <"\t) &&\n"> <"\trmdir success\n"> ) } ) (C {(test_expect_success)} {(SQ <"with failing hook requiring GIT_PREFIX">)} { (SQ <"\n"> <"\n"> <"\techo \"more content\" >> file &&\n"> <"\tgit add file &&\n"> <"\tmkdir fail &&\n"> <"\t(\n"> <"\t\tcd fail &&\n"> <"\t\ttest_must_fail git commit -m \"hook must fail\"\n"> <"\t) &&\n"> <"\trmdir fail &&\n"> <"\tgit checkout -- file\n"> ) } ) (C {(test_expect_success)} {(SQ <"check the author in hook">)} { (SQ <"\n"> <"\twrite_script \"$HOOK\" <<-\\EOF &&\n"> <"\ttest \"$GIT_AUTHOR_NAME\" = \"New Author\" &&\n"> <"\ttest \"$GIT_AUTHOR_EMAIL\" = \"newauthor@example.com\"\n"> <"\tEOF\n"> <"\ttest_must_fail git commit --allow-empty -m \"by a.u.thor\" &&\n"> <"\t(\n"> <"\t\tGIT_AUTHOR_NAME=\"New Author\" &&\n"> <"\t\tGIT_AUTHOR_EMAIL=\"newauthor@example.com\" &&\n"> <"\t\texport GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL &&\n"> <"\t\tgit commit --allow-empty -m \"by new.author via env\" &&\n"> <"\t\tgit show -s\n"> <"\t) &&\n"> <"\tgit commit --author=\"New Author <newauthor@example.com>\" \\\n"> <"\t\t--allow-empty -m \"by new.author via command line\" &&\n"> <"\tgit show -s\n"> ) } ) (C {(test_done)}) ] )