3 test_description
='test core.hooksPath management'
9 if vcmp
"$git_version" '>=' "2.9"; then
10 test_set_prereq GIT_2_9
15 write_dummy_script
() {
16 write_script
"$@" <<\EOT
22 echo "# dummy file $1" >"$1"
26 eval "case \"$1\" in $2) return 0; esac"
31 test_might_fail tg
-C "$1" update no-such-branch-name
2>&1
34 test_expect_success
'setup' '
35 mkdir _global _global/hooks insidious insidious/_global insidious/_global/hooks &&
36 ln -s _global/hooks globhookdir &&
37 ln -s . insidious/subdir &&
38 git init -q --template "$PWD/_global/hooks" --bare insidious/_global &&
39 write_dummy_script _global/hooks/pre-auto-gc &&
40 write_dummy_script _global/hooks/pre-receive &&
41 write_dummy_script _global/hooks/update &&
42 write_dummy_script _global/hooks/post-commit &&
43 write_dummy_script _global/hooks/post-receive &&
44 write_dummy_file _global/hooks/prepare-commit-msg &&
45 write_dummy_script _global/hooks/commit-msg.sh &&
46 test_create_repo r1 &&
47 test_create_repo r2 &&
48 mkdir r2/.git/hooks &&
49 test_create_repo r3 &&
50 mkdir r3/.git/hooks &&
51 (cd r3/.git/hooks && ln -s ../../../_global/hooks/* ./) &&
52 rm r3/.git/hooks/prepare-commit-msg r3/.git/hooks/commit-msg.sh &&
53 test_create_repo r4 &&
54 mkdir r4/.git/hooks &&
55 cp _global/hooks/* r4/.git/hooks/ &&
56 rm r4/.git/hooks/prepare-commit-msg r4/.git/hooks/commit-msg.sh &&
57 cp r4/.git/hooks/* insidious/_global/hooks/ &&
60 test -d r5/.git/hooks &&
61 rm r5/.git/hooks/update &&
64 test -d r6/.git/hooks &&
65 rm r6/.git/hooks/update &&
68 test -d r7/.git/hooks &&
69 echo different >> r7/.git/hooks/update &&
72 test -d r8/.git/hooks &&
73 echo notexec > r8/.git/hooks/update &&
74 chmod a-x r8/.git/hooks/update
77 test_expect_success GIT_2_9
'relative hookspath' '
78 test_config -C r2 core.hooksPath "" &&
80 for rpath in hooks .git/hooks ../_global/hooks ../../_global/hooks; do
81 git -C r2 config core.hooksPath "$rpath" &&
82 result="$(set +vx && do_mergesetup r2)" &&
83 matches "$result" "*\"ignoring non-absolute core.hooks\"[Pp]\"ath\"*" || {
91 test_expect_success GIT_2_9
'no such hookspath' '
92 test_config -C r2 core.hooksPath "" &&
94 for rpath in hooks .git/hooks ../_global/hooks ../../_global/hooks; do
95 git -C r2 config core.hooksPath "$PWD/ns1/ns2/ns3/ns4/$rpath" &&
96 result="$(set +vx && do_mergesetup r2)" &&
97 matches "$result" "*\"ignoring non-existent core.hooks\"[Pp]\"ath\"*" || {
105 test_expect_success GIT_2_9
'our absolute hooks' '
106 test_config -C r2 core.hooksPath "" &&
108 for rpath in hooks hooks/../hooks ../.git/hooks ../../r2/.git/hooks; do
109 git -C r2 config core.hooksPath "$PWD/r2/.git/$rpath" &&
110 result="$(set +vx && do_mergesetup r2)" &&
111 newcp="$(git -C r2 config core.hooksPath)" &&
112 test "$PWD/r2/.git/$rpath" = "$newcp" &&
113 ! matches "$result" "*\" warning: \"*" || {
121 test_expect_success GIT_2_9
'no gratuitous hookspath' '
124 do_mergesetup $rpath >/dev/null &&
125 test_must_fail git config -C $rpath --get core.hooksPath >/dev/null || {
136 case " $friendly " in *" $repo "*);;*) continue; esac
137 test_expect_success GIT_2_9
'"friendly" hookspath '"$repo" '
138 test_config -C $repo core.hooksPath "" &&
140 for gpath in _global/hooks globhookdir; do
141 rm -f "$gpath/pre-commit" &&
142 git -C $repo config core.hooksPath "$PWD/$gpath" &&
143 result="$(set +vx && do_mergesetup $repo)" &&
144 newcp="$(git -C $repo config core.hooksPath)" &&
145 test "$PWD/$gpath" != "$newcp" &&
146 test "$(cd "$PWD/$repo/.git/hooks" && pwd -P)" = "$(cd "$newcp" && pwd -P)" &&
147 ! matches "$result" "*\" warning: \"*" || {
157 case " $friendly " in *" $repo "*) continue; esac
158 test_expect_success GIT_2_9
'"unfriendly" hookspath '"$repo" '
159 test_config -C $repo core.hooksPath "" &&
161 for gpath in _global/hooks globhookdir; do
162 rm -f "$gpath/pre-commit" &&
163 git -C $repo config core.hooksPath "$PWD/$gpath" &&
164 result="$(set +vx && do_mergesetup $repo)" &&
165 newcp="$(git -C $repo config core.hooksPath)" &&
166 test "$PWD/$gpath" = "$newcp" &&
167 ! matches "$result" "*\" warning: \"*" || {
176 test_expect_success GIT_2_9
'insidious hookspath' '
177 git -C insidious/_global config core.hooksPath "$PWD/insidious/subdir/_global/hooks" &&
178 do_mergesetup insidious/_global >/dev/null &&
179 newcp="$(git -C insidious/_global config core.hooksPath)" &&
180 test "$PWD/insidious/subdir/_global/hooks" = "$newcp"