(command.CommandList children: [ (command.Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (lhs_expr.LhsName name:test_description spids:[12]) op: Equal rhs: {(SQ <'prepare-commit-msg hook'>)} spids: [12] ) ] spids: [12] ) (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'> ) } ) (command.SimpleCommand words: [{(cat)}] redirects: [ (redir.Redir op:<Redir_Great '>'> fd:16777215 arg_word:{(fake-editor)}) (redir.HereDoc op: <Redir_DLess '<<'> fd: 16777215 here_begin: {(SQ <EOF>)} here_end_span_id: 55 stdin_parts: [('#!/bin/sh\n') ('exit 0\n')] ) ] ) (C {(chmod)} {(Lit_Other '+') (x)} {(fake-editor)}) (command.Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (lhs_expr.LhsName name:FAKE_EDITOR spids:[70]) op: Equal rhs: { (DQ (word_part.CommandSubPart command_list: (command.CommandList children:[(C {(pwd)})]) left_token: <Left_CommandSub '$('> spids: [72 74] ) (/fake-editor) ) } spids: [70] ) ] spids: [70] ) (C {(export)} {(FAKE_EDITOR)}) (command.Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (lhs_expr.LhsName name:HOOKDIR spids:[86]) op: Equal rhs: { (DQ (word_part.CommandSubPart command_list: (command.CommandList children: [(C {(git)} {(rev-parse)} {(--git-dir)})] ) left_token: <Left_CommandSub '$('> spids: [88 94] ) (/hooks) ) } spids: [86] ) ] spids: [86] ) (command.Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (lhs_expr.LhsName name:HOOK spids:[98]) op: Equal rhs: {(DQ ($ VSub_Name '$HOOKDIR') (/prepare-commit-msg))} spids: [98] ) ] spids: [98] ) (C {(mkdir)} {(-p)} {(DQ ($ VSub_Name '$HOOKDIR'))}) (command.SimpleCommand words: [{(echo)} {(DQ ('#!') ($ VSub_Name '$SHELL_PATH'))}] redirects: [(redir.Redir op:<Redir_Great '>'> fd:16777215 arg_word:{(DQ ($ VSub_Name '$HOOK'))})] ) (command.SimpleCommand words: [{(cat)}] redirects: [ (redir.Redir op:<Redir_DGreat '>>'> fd:16777215 arg_word:{(DQ ($ VSub_Name '$HOOK'))}) (redir.HereDoc op: <Redir_DLess '<<'> fd: 16777215 here_begin: {(SQ <EOF>)} here_end_span_id: 151 stdin_parts: [ ('\n') ('if test "$2" = commit; then\n') (' source=$(git rev-parse "$3")\n') ('else\n') (' source=${2-default}\n') ('fi\n') ('if test "$GIT_EDITOR" = :; then\n') (' sed -e "1s/.*/$source (no editor)/" "$1" > msg.tmp\n') ('else\n') (' sed -e "1s/.*/$source/" "$1" > msg.tmp\n') ('fi\n') ('mv msg.tmp "$1"\n') ('exit 0\n') ] ) ] ) (C {(chmod)} {(Lit_Other '+') (x)} {(DQ ($ VSub_Name '$HOOK'))}) (command.SimpleCommand words: [{(echo)} {(dummy)} {(template)}] redirects: [ (redir.Redir op: <Redir_Great '>'> fd: 16777215 arg_word: { (DQ (word_part.CommandSubPart command_list: (command.CommandList children: [(C {(git)} {(rev-parse)} {(--git-dir)})] ) left_token: <Left_CommandSub '$('> spids: [171 177] ) (/template) ) } ) ] ) (C {(test_expect_success)} {(SQ <'with hook (-m)'>)} { (SQ <'\n'> <'\n'> <'\techo "more" >> file &&\n'> <'\tgit add file &&\n'> <'\tgit commit -m "more" &&\n'> <'\ttest "$(git log -1 --pretty=format:%s)" = "message (no editor)"\n'> <'\n'> ) } ) (C {(test_expect_success)} {(SQ <'with hook (-m editor)'>)} { (SQ <'\n'> <'\n'> <'\techo "more" >> file &&\n'> <'\tgit add file &&\n'> <'\tGIT_EDITOR="\\"\\$FAKE_EDITOR\\"" git commit -e -m "more more" &&\n'> <'\ttest "$(git log -1 --pretty=format:%s)" = message\n'> <'\n'> ) } ) (C {(test_expect_success)} {(SQ <'with hook (-t)'>)} { (SQ <'\n'> <'\n'> <'\techo "more" >> file &&\n'> <'\tgit add file &&\n'> <'\tgit commit -t "$(git rev-parse --git-dir)/template" &&\n'> <'\ttest "$(git log -1 --pretty=format:%s)" = template\n'> <'\n'> ) } ) (C {(test_expect_success)} {(SQ <'with hook (-F)'>)} { (SQ <'\n'> <'\n'> <'\techo "more" >> file &&\n'> <'\tgit add file &&\n'> <'\t(echo more | git commit -F -) &&\n'> <'\ttest "$(git log -1 --pretty=format:%s)" = "message (no editor)"\n'> <'\n'> ) } ) (C {(test_expect_success)} {(SQ <'with hook (-F editor)'>)} { (SQ <'\n'> <'\n'> <'\techo "more" >> file &&\n'> <'\tgit add file &&\n'> <'\t(echo more more | GIT_EDITOR="\\"\\$FAKE_EDITOR\\"" git commit -e -F -) &&\n'> <'\ttest "$(git log -1 --pretty=format:%s)" = message\n'> <'\n'> ) } ) (C {(test_expect_success)} {(SQ <'with hook (-C)'>)} { (SQ <'\n'> <'\n'> <'\thead=$(git rev-parse HEAD) &&\n'> <'\techo "more" >> file &&\n'> <'\tgit add file &&\n'> <'\tgit commit -C $head &&\n'> <'\ttest "$(git log -1 --pretty=format:%s)" = "$head (no editor)"\n'> <'\n'> ) } ) (C {(test_expect_success)} {(SQ <'with hook (editor)'>)} { (SQ <'\n'> <'\n'> <'\techo "more more" >> file &&\n'> <'\tgit add file &&\n'> <'\tGIT_EDITOR="\\"\\$FAKE_EDITOR\\"" git commit &&\n'> <'\ttest "$(git log -1 --pretty=format:%s)" = default\n'> <'\n'> ) } ) (C {(test_expect_success)} {(SQ <'with hook (--amend)'>)} { (SQ <'\n'> <'\n'> <'\thead=$(git rev-parse HEAD) &&\n'> <'\techo "more" >> file &&\n'> <'\tgit add file &&\n'> <'\tGIT_EDITOR="\\"\\$FAKE_EDITOR\\"" git commit --amend &&\n'> <'\ttest "$(git log -1 --pretty=format:%s)" = "$head"\n'> <'\n'> ) } ) (C {(test_expect_success)} {(SQ <'with hook (-c)'>)} { (SQ <'\n'> <'\n'> <'\thead=$(git rev-parse HEAD) &&\n'> <'\techo "more" >> file &&\n'> <'\tgit add file &&\n'> <'\tGIT_EDITOR="\\"\\$FAKE_EDITOR\\"" git commit -c $head &&\n'> <'\ttest "$(git log -1 --pretty=format:%s)" = "$head"\n'> <'\n'> ) } ) (C {(test_expect_success)} {(SQ <'with hook (merge)'>)} { (SQ <'\n'> <'\n'> <'\ttest_when_finished "git checkout -f master" &&\n'> <'\tgit checkout -B other HEAD@{1} &&\n'> <'\techo "more" >>file &&\n'> <'\tgit add file &&\n'> <'\tgit commit -m other &&\n'> <'\tgit checkout - &&\n'> <'\tgit merge --no-ff other &&\n'> <'\ttest "$(git log -1 --pretty=format:%s)" = "merge (no editor)"\n'> ) } ) (C {(test_expect_success)} {(SQ <'with hook and editor (merge)'>)} { (SQ <'\n'> <'\n'> <'\ttest_when_finished "git checkout -f master" &&\n'> <'\tgit checkout -B other HEAD@{1} &&\n'> <'\techo "more" >>file &&\n'> <'\tgit add file &&\n'> <'\tgit commit -m other &&\n'> <'\tgit checkout - &&\n'> <'\tenv GIT_EDITOR="\\"\\$FAKE_EDITOR\\"" git merge --no-ff -e other &&\n'> <'\ttest "$(git log -1 --pretty=format:%s)" = "merge"\n'> ) } ) (command.SimpleCommand words: [{(cat)}] redirects: [ (redir.Redir op:<Redir_Great '>'> fd:16777215 arg_word:{(DQ ($ VSub_Name '$HOOK'))}) (redir.HereDoc op: <Redir_DLess '<<'> fd: 16777215 here_begin: {(SQ <EOF>)} here_end_span_id: 393 stdin_parts: [('#!/bin/sh\n') ('exit 1\n')] ) ] ) (C {(test_expect_success)} {(SQ <'with failing hook'>)} { (SQ <'\n'> <'\n'> <'\ttest_when_finished "git checkout -f master" &&\n'> <'\thead=$(git rev-parse HEAD) &&\n'> <'\techo "more" >> file &&\n'> <'\tgit add file &&\n'> <'\ttest_must_fail env GIT_EDITOR="\\"\\$FAKE_EDITOR\\"" git commit -c $head\n'> <'\n'> ) } ) (C {(test_expect_success)} {(SQ <'with failing hook (--no-verify)'>)} { (SQ <'\n'> <'\n'> <'\ttest_when_finished "git checkout -f master" &&\n'> <'\thead=$(git rev-parse HEAD) &&\n'> <'\techo "more" >> file &&\n'> <'\tgit add file &&\n'> < '\ttest_must_fail env GIT_EDITOR="\\"\\$FAKE_EDITOR\\"" git commit --no-verify -c $head\n' > <'\n'> ) } ) (C {(test_expect_success)} {(SQ <'with failing hook (merge)'>)} { (SQ <'\n'> <'\n'> <'\ttest_when_finished "git checkout -f master" &&\n'> <'\tgit checkout -B other HEAD@{1} &&\n'> <'\techo "more" >> file &&\n'> <'\tgit add file &&\n'> <'\trm -f "$HOOK" &&\n'> <'\tgit commit -m other &&\n'> <'\twrite_script "$HOOK" <<-EOF &&\n'> <'\texit 1\n'> <'\tEOF\n'> <'\tgit checkout - &&\n'> <'\ttest_must_fail git merge --no-ff other\n'> <'\n'> ) } ) (C {(test_done)}) ] )