README_DOCS.rst: update tg prev and tg next usage summary
[topgit/pro.git] / t / t1062-hookspath.sh
blob55e05c39cdd13061ecf7505ce8b0e410de725620
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 16
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 do_status() {
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/ &&
64 test ! -d r5 &&
65 cp -R r3 r5 &&
66 test -d r5/.git/hooks &&
67 rm r5/.git/hooks/update &&
68 test ! -d r6 &&
69 cp -R r4 r6 &&
70 test -d r6/.git/hooks &&
71 rm r6/.git/hooks/update &&
72 test ! -d r7 &&
73 cp -R r4 r7 &&
74 test -d r7/.git/hooks &&
75 echo different >> r7/.git/hooks/update &&
76 test ! -d r8 &&
77 cp -R r4 r8 &&
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 "" &&
85 bad= &&
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\"*" || {
90 bad=1 &&
91 break
93 done &&
94 test -z "$bad"
97 test_expect_success GIT_2_9 'no such hookspath' '
98 test_config -C r2 core.hooksPath "" &&
99 bad= &&
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\"*" || {
104 bad=1 &&
105 break
107 done &&
108 test -z "$bad"
111 test_expect_success GIT_2_9 'our absolute hooks' '
112 test_config -C r2 core.hooksPath "" &&
113 bad= &&
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: \"*" || {
120 bad=1 &&
121 break
123 done &&
124 test -z "$bad"
127 test_expect_success GIT_2_9 'no gratuitous hookspath' '
128 bad= &&
129 for rpath in r?; do
130 do_mergesetup $rpath >/dev/null &&
131 test_must_fail git config -C $rpath --get core.hooksPath >/dev/null || {
132 bad=1 &&
133 break
135 done &&
136 test -z "$bad"
139 friendly="r3 r4"
141 for repo in r?; do
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 "" &&
145 bad= &&
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: \"*" || {
154 bad=1 &&
155 break
157 done &&
158 test -z "$bad"
160 done
162 for repo in r?; do
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 "" &&
166 bad= &&
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: \"*" || {
174 bad=1 &&
175 break
177 done &&
178 test -z "$bad"
180 done
182 for repo in r?; do
183 case " $friendly " in *" $repo "*) continue; esac
184 test_expect_success GIT_2_9 '"unfriendly" hookspath '"$repo" '
185 test_config -C $repo core.hooksPath "" &&
186 bad= &&
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: \"*" || {
194 bad=1 &&
195 break
197 done &&
198 test -z "$bad"
200 done
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"
209 test_done