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
35 test_might_fail tg
-C "$1" status
2>&1
38 # Note that the initial branch name in insidious/_global does
39 # not affect these tests in any way
40 test_expect_success
'setup' '
41 mkdir _global _global/hooks insidious insidious/_global insidious/_global/hooks &&
42 ln -s _global/hooks globhookdir &&
43 ln -s . insidious/subdir &&
44 git init -q --template "$PWD/_global/hooks" --bare insidious/_global &&
45 write_dummy_script _global/hooks/pre-auto-gc &&
46 write_dummy_script _global/hooks/pre-receive &&
47 write_dummy_script _global/hooks/update &&
48 write_dummy_script _global/hooks/post-commit &&
49 write_dummy_script _global/hooks/post-receive &&
50 write_dummy_file _global/hooks/prepare-commit-msg &&
51 write_dummy_script _global/hooks/commit-msg.sh &&
52 test_create_repo r1 &&
53 test_create_repo r2 &&
54 mkdir r2/.git/hooks &&
55 test_create_repo r3 &&
56 mkdir r3/.git/hooks &&
57 (cd r3/.git/hooks && ln -s ../../../_global/hooks/* ./) &&
58 rm r3/.git/hooks/prepare-commit-msg r3/.git/hooks/commit-msg.sh &&
59 test_create_repo r4 &&
60 mkdir r4/.git/hooks &&
61 cp _global/hooks/* r4/.git/hooks/ &&
62 rm r4/.git/hooks/prepare-commit-msg r4/.git/hooks/commit-msg.sh &&
63 cp r4/.git/hooks/* insidious/_global/hooks/ &&
66 test -d r5/.git/hooks &&
67 rm r5/.git/hooks/update &&
70 test -d r6/.git/hooks &&
71 rm r6/.git/hooks/update &&
74 test -d r7/.git/hooks &&
75 echo different >> r7/.git/hooks/update &&
78 test -d r8/.git/hooks &&
79 echo notexec > r8/.git/hooks/update &&
80 chmod a-x r8/.git/hooks/update
83 test_expect_success GIT_2_9
'relative hookspath' '
84 test_config -C r2 core.hooksPath "" &&
86 for rpath in hooks .git/hooks ../_global/hooks ../../_global/hooks; do
87 git -C r2 config core.hooksPath "$rpath" &&
88 result="$(set +vx && do_mergesetup r2)" &&
89 matches "$result" "*\"ignoring non-absolute core.hooks\"[Pp]\"ath\"*" || {
97 test_expect_success GIT_2_9
'no such hookspath' '
98 test_config -C r2 core.hooksPath "" &&
100 for rpath in hooks .git/hooks ../_global/hooks ../../_global/hooks; do
101 git -C r2 config core.hooksPath "$PWD/ns1/ns2/ns3/ns4/$rpath" &&
102 result="$(set +vx && do_mergesetup r2)" &&
103 matches "$result" "*\"ignoring non-existent core.hooks\"[Pp]\"ath\"*" || {
111 test_expect_success GIT_2_9
'our absolute hooks' '
112 test_config -C r2 core.hooksPath "" &&
114 for rpath in hooks hooks/../hooks ../.git/hooks ../../r2/.git/hooks; do
115 git -C r2 config core.hooksPath "$PWD/r2/.git/$rpath" &&
116 result="$(set +vx && do_mergesetup r2)" &&
117 newcp="$(git -C r2 config core.hooksPath)" &&
118 test "$PWD/r2/.git/$rpath" = "$newcp" &&
119 ! matches "$result" "*\" warning: \"*" || {
127 test_expect_success GIT_2_9
'no gratuitous hookspath' '
130 do_mergesetup $rpath >/dev/null &&
131 test_must_fail git config -C $rpath --get core.hooksPath >/dev/null || {
142 case " $friendly " in *" $repo "*);;*) continue; esac
143 test_expect_success GIT_2_9
'adjusted "friendly" hookspath '"$repo" '
144 test_config -C $repo core.hooksPath "" &&
146 for gpath in _global/hooks globhookdir; do
147 rm -f "$gpath/pre-commit" &&
148 git -C $repo config core.hooksPath "$PWD/$gpath" &&
149 result="$(set +vx && do_mergesetup $repo)" &&
150 newcp="$(git -C $repo config core.hooksPath)" &&
151 test "$PWD/$gpath" != "$newcp" &&
152 test "$(cd "$PWD/$repo/.git/hooks" && pwd -P)" = "$(cd "$newcp" && pwd -P)" &&
153 ! matches "$result" "*\" warning: \"*" || {
163 case " $friendly " in *" $repo "*);;*) continue; esac
164 test_expect_success GIT_2_9
'unadjusted "friendly" hookspath '"$repo" '
165 test_config -C $repo core.hooksPath "" &&
167 for gpath in _global/hooks globhookdir; do
168 rm -f "$gpath/pre-commit" &&
169 git -C $repo config core.hooksPath "$PWD/$gpath" &&
170 result="$(set +vx && do_status $repo)" &&
171 newcp="$(git -C $repo config core.hooksPath)" &&
172 test "$PWD/$gpath" = "$newcp" &&
173 ! matches "$result" "*\" warning: \"*" || {
183 case " $friendly " in *" $repo "*) continue; esac
184 test_expect_success GIT_2_9
'"unfriendly" hookspath '"$repo" '
185 test_config -C $repo core.hooksPath "" &&
187 for gpath in _global/hooks globhookdir; do
188 rm -f "$gpath/pre-commit" &&
189 git -C $repo config core.hooksPath "$PWD/$gpath" &&
190 result="$(set +vx && do_mergesetup $repo)" &&
191 newcp="$(git -C $repo config core.hooksPath)" &&
192 test "$PWD/$gpath" = "$newcp" &&
193 ! matches "$result" "*\" warning: \"*" || {
202 test_expect_success GIT_2_9
'insidious hookspath' '
203 git -C insidious/_global config core.hooksPath "$PWD/insidious/subdir/_global/hooks" &&
204 do_mergesetup insidious/_global >/dev/null &&
205 newcp="$(git -C insidious/_global config core.hooksPath)" &&
206 test "$PWD/insidious/subdir/_global/hooks" = "$newcp"