3 test_description='git-hook command'
7 test_expect_success 'git hook run -- nonexistent hook' '
8 cat >stderr.expect <<-\EOF &&
9 error: cannot find a hook named test-hook
11 test_expect_code 1 git hook run test-hook 2>stderr.actual &&
12 test_cmp stderr.expect stderr.actual
15 test_expect_success 'git hook run -- nonexistent hook with --ignore-missing' '
16 git hook run --ignore-missing test-hook 2>stderr.actual &&
17 test_must_be_empty stderr.actual
20 test_expect_success 'git hook run -- nonexistent hook with --ignore-missing' '
21 cat >stderr.expect <<-\EOF &&
22 fatal: the hook '"'"'unknown-hook'"'"' is not known to git, should be in hook-list.h via githooks(5)
24 test_expect_code 128 git hook run unknown-hook 2>stderr.actual &&
25 test_cmp stderr.expect stderr.actual
28 test_expect_success 'git hook run -- basic' '
29 write_script .git/hooks/test-hook <<-EOF &&
33 cat >expect <<-\EOF &&
36 git hook run test-hook 2>actual &&
37 test_cmp expect actual
40 test_expect_success 'git hook run -- stdout and stderr handling' '
41 write_script .git/hooks/test-hook <<-EOF &&
42 echo >&1 Will end up on stderr
43 echo >&2 Will end up on stderr
46 cat >stderr.expect <<-\EOF &&
50 git hook run test-hook >stdout.actual 2>stderr.actual &&
51 test_cmp stderr.expect stderr.actual &&
52 test_must_be_empty stdout.actual
55 test_expect_success 'git hook run -- exit codes are passed along' '
56 write_script .git/hooks/test-hook <<-EOF &&
60 test_expect_code 1 git hook run test-hook &&
62 write_script .git/hooks/test-hook <<-EOF &&
66 test_expect_code 2 git hook run test-hook &&
68 write_script .git/hooks/test-hook <<-EOF &&
72 test_expect_code 128 git hook run test-hook &&
74 write_script .git/hooks/test-hook <<-EOF &&
78 test_expect_code 129 git hook run test-hook
81 test_expect_success 'git hook run arg u ments without -- is not allowed' '
82 test_expect_code 129 git hook run test-hook arg u ments
85 test_expect_success 'git hook run -- pass arguments' '
86 write_script .git/hooks/test-hook <<-\EOF &&
96 git hook run test-hook -- arg "u ments" 2>actual &&
97 test_cmp expect actual
100 test_expect_success 'git hook run -- out-of-repo runs excluded' '
101 write_script .git/hooks/test-hook <<-EOF &&
105 nongit test_must_fail git hook run test-hook
108 test_expect_success 'git -c core.hooksPath=<PATH> hook run' '
110 write_script my-hooks/test-hook <<-EOF &&
111 echo Hook ran >>actual
114 cat >expect <<-\EOF &&
122 # Test various ways of specifying the path. See also
123 # t1350-config-hooks-path.sh
125 git hook run test-hook 2>>actual &&
126 git -c core.hooksPath=my-hooks hook run test-hook 2>>actual &&
127 git -c core.hooksPath=my-hooks/ hook run test-hook 2>>actual &&
128 git -c core.hooksPath="$PWD/my-hooks" hook run test-hook 2>>actual &&
129 git -c core.hooksPath="$PWD/my-hooks/" hook run test-hook 2>>actual &&
130 test_cmp expect actual
133 test_expect_success 'set up a pre-commit hook in core.hooksPath' '
135 mkdir -p .git/custom-hooks .git/hooks &&
136 write_script .git/custom-hooks/pre-commit <<-\EOF &&
139 write_script .git/hooks/pre-commit <<-\EOF
144 test_expect_success 'stdin to hooks' '
145 write_script .git/hooks/test-hook <<-\EOF &&
151 cat >expect <<-EOF &&
158 git hook run --to-stdin=input test-hook 2>actual &&
159 test_cmp expect actual