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 does-not-exist
11 test_expect_code 1 git hook run does-not-exist 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 does-not-exist 2>stderr.actual &&
17 test_must_be_empty stderr.actual
20 test_expect_success 'git hook run -- basic' '
21 write_script .git/hooks/test-hook <<-EOF &&
25 cat >expect <<-\EOF &&
28 git hook run test-hook 2>actual &&
29 test_cmp expect actual
32 test_expect_success 'git hook run -- stdout and stderr handling' '
33 write_script .git/hooks/test-hook <<-EOF &&
34 echo >&1 Will end up on stderr
35 echo >&2 Will end up on stderr
38 cat >stderr.expect <<-\EOF &&
42 git hook run test-hook >stdout.actual 2>stderr.actual &&
43 test_cmp stderr.expect stderr.actual &&
44 test_must_be_empty stdout.actual
47 test_expect_success 'git hook run -- exit codes are passed along' '
48 write_script .git/hooks/test-hook <<-EOF &&
52 test_expect_code 1 git hook run test-hook &&
54 write_script .git/hooks/test-hook <<-EOF &&
58 test_expect_code 2 git hook run test-hook &&
60 write_script .git/hooks/test-hook <<-EOF &&
64 test_expect_code 128 git hook run test-hook &&
66 write_script .git/hooks/test-hook <<-EOF &&
70 test_expect_code 129 git hook run test-hook
73 test_expect_success 'git hook run arg u ments without -- is not allowed' '
74 test_expect_code 129 git hook run test-hook arg u ments
77 test_expect_success 'git hook run -- pass arguments' '
78 write_script .git/hooks/test-hook <<-\EOF &&
88 git hook run test-hook -- arg "u ments" 2>actual &&
89 test_cmp expect actual
92 test_expect_success 'git hook run -- out-of-repo runs excluded' '
93 write_script .git/hooks/test-hook <<-EOF &&
97 nongit test_must_fail git hook run test-hook
100 test_expect_success 'git -c core.hooksPath=<PATH> hook run' '
102 write_script my-hooks/test-hook <<-EOF &&
103 echo Hook ran >>actual
106 cat >expect <<-\EOF &&
114 # Test various ways of specifying the path. See also
115 # t1350-config-hooks-path.sh
117 git hook run test-hook 2>>actual &&
118 git -c core.hooksPath=my-hooks hook run test-hook 2>>actual &&
119 git -c core.hooksPath=my-hooks/ hook run test-hook 2>>actual &&
120 git -c core.hooksPath="$PWD/my-hooks" hook run test-hook 2>>actual &&
121 git -c core.hooksPath="$PWD/my-hooks/" hook run test-hook 2>>actual &&
122 test_cmp expect actual
125 test_expect_success 'set up a pre-commit hook in core.hooksPath' '
127 mkdir -p .git/custom-hooks .git/hooks &&
128 write_script .git/custom-hooks/pre-commit <<-\EOF &&
131 write_script .git/hooks/pre-commit <<-\EOF
136 test_expect_success 'stdin to hooks' '
137 write_script .git/hooks/test-hook <<-\EOF &&
143 cat >expect <<-EOF &&
150 git hook run --to-stdin=input test-hook 2>actual &&
151 test_cmp expect actual