(command.CommandList children: [ (command.ShAssignment pairs: [ (assign_pair lhs: (sh_lhs_expr.Name name:test_description) op: assign_op.Equal rhs: {(SQ <'pre-commit hook'>)} 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'> ) } ) (command.ShAssignment pairs: [ (assign_pair lhs: (sh_lhs_expr.Name name:HOOKDIR) op: assign_op.Equal rhs: { (DQ (command_sub left_token: <Id.Left_DollarParen '$('> child: (C {<git>} {<rev-parse>} {<--git-dir>}) ) <'/hooks'> ) } spids: [50] ) ] ) (command.ShAssignment pairs: [ (assign_pair lhs: (sh_lhs_expr.Name name:HOOK) op: assign_op.Equal rhs: {(DQ ($ Id.VSub_DollarName '$HOOKDIR') <'/pre-commit'>)} spids: [62] ) ] ) (C {<mkdir>} {<-p>} {(DQ ($ Id.VSub_DollarName '$HOOKDIR'))}) (command.Simple words: [{<cat>}] redirects: [ (redir op: <Id.Redir_Great '>'> loc: (redir_loc.Fd fd:1) arg: {(DQ ($ Id.VSub_DollarName '$HOOK'))} ) (redir op: <Id.Redir_DLess '<<'> loc: (redir_loc.Fd fd:0) arg: (redir_param.HereDoc here_begin: {<EOF>} here_end_span_id: 90 stdin_parts: [<'#!/bin/sh\n'> <'exit 0\n'>] ) ) ] do_fork: T ) (C {<chmod>} {<Id.Lit_Other '+'> <x>} {(DQ ($ Id.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.Simple words: [{<cat>}] redirects: [ (redir op: <Id.Redir_Great '>'> loc: (redir_loc.Fd fd:1) arg: {(DQ ($ Id.VSub_DollarName '$HOOK'))} ) (redir op: <Id.Redir_DLess '<<'> loc: (redir_loc.Fd fd:0) arg: (redir_param.HereDoc here_begin: {<EOF>} here_end_span_id: 150 stdin_parts: [<'#!/bin/sh\n'> <'exit 1\n'>] ) ) ] do_fork: T ) (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 ($ Id.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>} {<Id.Lit_Other '+'> <x>} {(DQ ($ Id.VSub_DollarName '$HOOK'))}) (command.Simple words: [{<cat>}] redirects: [ (redir op: <Id.Redir_Great '>'> loc: (redir_loc.Fd fd:1) arg: {(DQ ($ Id.VSub_DollarName '$HOOK'))} ) (redir op: <Id.Redir_DLess '<<'> loc: (redir_loc.Fd fd:0) arg: (redir_param.HereDoc here_begin: {<EOF>} here_end_span_id: 259 stdin_parts: [ <'#!/bin/sh\n'> <'test '> (word_part.EscapedLiteral token:<Id.Lit_EscapedChar '\\$'>) <'GIT_PREFIX = success/\n'> ] ) ) ] do_fork: T ) (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>}) ] )