3 test_description
='git-hook command'
5 TEST_PASSES_SANITIZE_LEAK
=true
8 test_expect_success
'git hook usage' '
9 test_expect_code 129 git hook &&
10 test_expect_code 129 git hook run &&
11 test_expect_code 129 git hook run -h &&
12 test_expect_code 129 git hook run --unknown 2>err &&
13 grep "unknown option" err
16 test_expect_success
'git hook run: nonexistent hook' '
17 cat >stderr.expect <<-\EOF &&
18 error: cannot find a hook named test-hook
20 test_expect_code 1 git hook run test-hook 2>stderr.actual &&
21 test_cmp stderr.expect stderr.actual
24 test_expect_success
'git hook run: nonexistent hook with --ignore-missing' '
25 git hook run --ignore-missing does-not-exist 2>stderr.actual &&
26 test_must_be_empty stderr.actual
29 test_expect_success
'git hook run: basic' '
30 test_hook test-hook <<-EOF &&
34 cat >expect <<-\EOF &&
37 git hook run test-hook 2>actual &&
38 test_cmp expect actual
41 test_expect_success
'git hook run: stdout and stderr both write to our stderr' '
42 test_hook test-hook <<-EOF &&
43 echo >&1 Will end up on stderr
44 echo >&2 Will end up on stderr
47 cat >stderr.expect <<-\EOF &&
51 git hook run test-hook >stdout.actual 2>stderr.actual &&
52 test_cmp stderr.expect stderr.actual &&
53 test_must_be_empty stdout.actual
56 for code
in 1 2 128 129
58 test_expect_success
"git hook run: exit code $code is passed along" '
59 test_hook test-hook <<-EOF &&
63 test_expect_code $code git hook run test-hook
67 test_expect_success
'git hook run arg u ments without -- is not allowed' '
68 test_expect_code 129 git hook run test-hook arg u ments
71 test_expect_success
'git hook run -- pass arguments' '
72 test_hook test-hook <<-\EOF &&
82 git hook run test-hook -- arg "u ments" 2>actual &&
83 test_cmp expect actual
86 test_expect_success
'git hook run -- out-of-repo runs excluded' '
87 test_hook test-hook <<-EOF &&
91 nongit test_must_fail git hook run test-hook
94 test_expect_success
'git -c core.hooksPath=<PATH> hook run' '
96 write_script my-hooks/test-hook <<-\EOF &&
97 echo Hook ran $1 >>actual
100 cat >expect <<-\EOF &&
108 test_hook test-hook <<-EOF &&
112 # Test various ways of specifying the path. See also
113 # t1350-config-hooks-path.sh
115 git hook run test-hook -- ignored 2>>actual &&
116 git -c core.hooksPath=my-hooks hook run test-hook -- one 2>>actual &&
117 git -c core.hooksPath=my-hooks/ hook run test-hook -- two 2>>actual &&
118 git -c core.hooksPath="$PWD/my-hooks" hook run test-hook -- three 2>>actual &&
119 git -c core.hooksPath="$PWD/my-hooks/" hook run test-hook -- four 2>>actual &&
120 test_cmp expect actual