blob: f6dc83e2aabf69ec51364ae9a5f6d5d50ce8db14 [file] [log] [blame]
Ævar Arnfjörð Bjarmason867ad082016-05-04 22:58:12 +00001#!/bin/sh
2
3test_description='Test the core.hooksPath configuration variable'
4
5. ./test-lib.sh
6
7test_expect_success 'set up a pre-commit hook in core.hooksPath' '
Ævar Arnfjörð Bjarmasonaac57842021-06-14 12:37:35 +02008 >actual &&
Ævar Arnfjörð Bjarmasonbef805b2022-03-17 11:13:14 +01009 mkdir -p .git/custom-hooks &&
Ævar Arnfjörð Bjarmason867ad082016-05-04 22:58:12 +000010 write_script .git/custom-hooks/pre-commit <<-\EOF &&
11 echo CUSTOM >>actual
12 EOF
Ævar Arnfjörð Bjarmasonbef805b2022-03-17 11:13:14 +010013 test_hook --setup pre-commit <<-\EOF
Ævar Arnfjörð Bjarmason867ad082016-05-04 22:58:12 +000014 echo NORMAL >>actual
15 EOF
16'
17
18test_expect_success 'Check that various forms of specifying core.hooksPath work' '
19 test_commit no_custom_hook &&
20 git config core.hooksPath .git/custom-hooks &&
21 test_commit have_custom_hook &&
22 git config core.hooksPath .git/custom-hooks/ &&
23 test_commit have_custom_hook_trailing_slash &&
24 git config core.hooksPath "$PWD/.git/custom-hooks" &&
25 test_commit have_custom_hook_abs_path &&
26 git config core.hooksPath "$PWD/.git/custom-hooks/" &&
27 test_commit have_custom_hook_abs_path_trailing_slash &&
28 cat >expect <<-\EOF &&
29 NORMAL
30 CUSTOM
31 CUSTOM
32 CUSTOM
33 CUSTOM
34 EOF
35 test_cmp expect actual
36'
37
Johannes Schindelin9445b492016-08-16 15:14:27 +020038test_expect_success 'git rev-parse --git-path hooks' '
39 git config core.hooksPath .git/custom-hooks &&
40 git rev-parse --git-path hooks/abc >actual &&
41 test .git/custom-hooks/abc = "$(cat actual)"
42'
43
Ævar Arnfjörð Bjarmason867ad082016-05-04 22:58:12 +000044test_done