tg: improve handling of configured core.hooksPath
[topgit/pro.git] / t / t1062-hookspath.sh
blob79dbe8be9201e588977c1d58733e228b1f7ab0d1
1 #!/bin/sh
3 test_description='test core.hooksPath management'
5 TEST_NO_CREATE_REPO=1
7 . ./test-lib.sh
9 if vcmp "$git_version" '>=' "2.9"; then
10 test_set_prereq GIT_2_9
13 test_plan 14
15 write_dummy_script() {
16 write_script "$@" <<\EOT
17 exit 0
18 EOT
21 write_dummy_file() {
22 echo "# dummy file $1" >"$1"
25 matches() {
26 eval "case \"$1\" in $2) return 0; esac"
27 return 1
30 do_mergesetup() {
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/ &&
58 test ! -d r5 &&
59 cp -R r3 r5 &&
60 test -d r5/.git/hooks &&
61 rm r5/.git/hooks/update &&
62 test ! -d r6 &&
63 cp -R r4 r6 &&
64 test -d r6/.git/hooks &&
65 rm r6/.git/hooks/update &&
66 test ! -d r7 &&
67 cp -R r4 r7 &&
68 test -d r7/.git/hooks &&
69 echo different >> r7/.git/hooks/update &&
70 test ! -d r8 &&
71 cp -R r4 r8 &&
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 "" &&
79 bad= &&
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\"*" || {
84 bad=1 &&
85 break
87 done &&
88 test -z "$bad"
91 test_expect_success GIT_2_9 'no such hookspath' '
92 test_config -C r2 core.hooksPath "" &&
93 bad= &&
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\"*" || {
98 bad=1 &&
99 break
101 done &&
102 test -z "$bad"
105 test_expect_success GIT_2_9 'our absolute hooks' '
106 test_config -C r2 core.hooksPath "" &&
107 bad= &&
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: \"*" || {
114 bad=1 &&
115 break
117 done &&
118 test -z "$bad"
121 test_expect_success GIT_2_9 'no gratuitous hookspath' '
122 bad= &&
123 for rpath in r?; do
124 do_mergesetup $rpath >/dev/null &&
125 test_must_fail git config -C $rpath --get core.hooksPath >/dev/null || {
126 bad=1 &&
127 break
129 done &&
130 test -z "$bad"
133 friendly="r3 r4"
135 for repo in r?; do
136 case " $friendly " in *" $repo "*);;*) continue; esac
137 test_expect_success GIT_2_9 '"friendly" hookspath '"$repo" '
138 test_config -C $repo core.hooksPath "" &&
139 bad= &&
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: \"*" || {
148 bad=1 &&
149 break
151 done &&
152 test -z "$bad"
154 done
156 for repo in r?; do
157 case " $friendly " in *" $repo "*) continue; esac
158 test_expect_success GIT_2_9 '"unfriendly" hookspath '"$repo" '
159 test_config -C $repo core.hooksPath "" &&
160 bad= &&
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: \"*" || {
168 bad=1 &&
169 break
171 done &&
172 test -z "$bad"
174 done
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"
183 test_done