(command.CommandList children: [ (command.Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (lhs_expr.LhsName name:test_description) op: Equal rhs: {(SQ <'pre-commit hook'>)} ) ] ) (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'> ) } ) (command.Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (lhs_expr.LhsName name:HOOKDIR) op: Equal rhs: { (DQ (word_part.CommandSubPart command_list: (command.CommandList children: [(C {(git)} {(rev-parse)} {(--git-dir)})] ) left_token: <Left_CommandSub '$('> ) (/hooks) ) } ) ] ) (command.Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (lhs_expr.LhsName name:HOOK) op: Equal rhs: {(DQ ($ VSub_DollarName '$HOOKDIR') (/pre-commit))} ) ] ) (C {(mkdir)} {(-p)} {(DQ ($ VSub_DollarName '$HOOKDIR'))}) (command.SimpleCommand words: [{(cat)}] redirects: [ (redir.Redir op: <Redir_Great '>'> fd: 16777215 arg_word: {(DQ ($ VSub_DollarName '$HOOK'))} ) (redir.HereDoc op: <Redir_DLess '<<'> fd: 16777215 here_begin: {(EOF)} here_end_span_id: 90 stdin_parts: [('#!/bin/sh\n') ('exit 0\n')] ) ] ) (C {(chmod)} {(Lit_Other '+') (x)} {(DQ ($ VSub_DollarName '$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'> ) } ) (command.SimpleCommand words: [{(cat)}] redirects: [ (redir.Redir op: <Redir_Great '>'> fd: 16777215 arg_word: {(DQ ($ VSub_DollarName '$HOOK'))} ) (redir.HereDoc op: <Redir_DLess '<<'> fd: 16777215 here_begin: {(EOF)} here_end_span_id: 150 stdin_parts: [('#!/bin/sh\n') ('exit 1\n')] ) ] ) (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_DollarName '$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_DollarName '$HOOK'))}) (command.SimpleCommand words: [{(cat)}] redirects: [ (redir.Redir op: <Redir_Great '>'> fd: 16777215 arg_word: {(DQ ($ VSub_DollarName '$HOOK'))} ) (redir.HereDoc op: <Redir_DLess '<<'> fd: 16777215 here_begin: {(EOF)} here_end_span_id: 259 stdin_parts: [ ('#!/bin/sh\n') ('test ') (word_part.EscapedLiteralPart token:<Lit_EscapedChar '\\$'>) ('GIT_PREFIX = success/\n') ] ) ] ) (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)}) ] )