keeping the profs at Cambridge happy...
[gitolite.git] / t / repo-specific-hooks.t
blob6cacdb26f8753d897b0c04a20e275c40bc8c5419
1 #!/usr/bin/perl
2 use strict;
3 use warnings;
5 # this is hardcoded; change it if needed
6 use lib "src/lib";
7 use Gitolite::Test;
9 # test script for partial copy feature
10 # ----------------------------------------------------------------------
12 try "plan 128";
13 my $h = $ENV{HOME};
14 my $rb = `gitolite query-rc -n GL_REPO_BASE`;
16 try 'cd tsh_tempdir; mkdir -p local/hooks/repo-specific';
18 foreach my $h (qw/first second/) {
19 put "local/hooks/repo-specific/$h", "#!/bin/sh
20 echo \$0
21 if [ \$# -ne 0 ]; then
22 echo \$0 has args: \$@
23 else
24 echo \$0 has stdin: `cat`
28 try 'chmod +x local/hooks/repo-specific/*';
30 try 'pwd';
31 my $tempdir = join("\n", sort (lines()));
32 try 'cd gitolite-admin';
34 try "# Enable LOCAL_CODE and repo-specific-hooks
35 cat $h/.gitolite.rc
36 perl s/# 'repo-specific-hooks'/'repo-specific-hooks'/
37 perl s%# LOCAL_CODE%LOCAL_CODE => '$tempdir/local', #%
38 put $h/.gitolite.rc
41 confreset;confadd '
42 repo foo
43 RW+ = @all
45 repo bar
46 RW+ = @all
48 repo baz
49 RW+ = @all
51 repo frob
52 RW+ = @all
55 try "ADMIN_PUSH repo-specific-hooks-0; !/FATAL/" or die text();
57 try "
58 /Init.*empty.*foo\\.git/
59 /Init.*empty.*bar\\.git/
60 /Init.*empty.*baz\\.git/
61 /Init.*empty.*frob\\.git/
64 my $failing_hook = "#!/bin/sh
65 exit 1
68 # Place a existing hooks in repos
69 put "$rb/foo.git/hooks/post-recieve", $failing_hook;
70 put "$rb/bar.git/hooks/pre-recieve", $failing_hook;
71 put "$rb/baz.git/hooks/post-update", $failing_hook;
72 put "$rb/frob.git/hooks/post-update", $failing_hook;
74 try "# Verify hooks
75 ls -l $rb/foo.git/hooks/*; ok; !/post-receive -. .*local/hooks/multi-hook-driver/
76 ls -l $rb/bar.git/hooks/*; ok; !/pre-receive -. .*local/hooks/multi-hook-driver/
77 ls -l $rb/baz.git/hooks/*; ok; !/post-update -. .*local/hooks/multi-hook-driver/
78 ls -l $rb/frob.git/hooks/*; ok; !/post-update -. .*local/hooks/multi-hook-driver/
81 confreset;confadd '
82 repo foo
83 RW+ = @all
84 option hook.post-receive = first
86 repo bar
87 RW+ = @all
88 option hook.pre-receive = first second
90 repo baz
91 RW+ = @all
92 option hook.post-receive = first
93 option hook.post-update = first second
95 repo frob
96 RW+ = @all
97 option hook.post-receive.b = first
98 option hook.post-receive.a = second
100 repo gitolite-admin
101 option hook.post-receive = second
105 try "ADMIN_PUSH repo-specific-hooks-1; !/FATAL/" or die text();
107 try "# Verify hooks
108 ls -l $rb/foo.git/hooks/*; ok; /post-receive.h00-first/
109 !/post-receive.h01/
110 /post-receive -. .*local/hooks/multi-hook-driver/
111 ls -l $rb/bar.git/hooks/*; ok; /pre-receive.h00-first/
112 /pre-receive.h01-second/
113 /pre-receive -. .*local/hooks/multi-hook-driver/
114 ls -l $rb/baz.git/hooks/*; ok; /post-receive.h00-first/
115 /post-update.h00-first/
116 /post-update.h01-second/
117 /post-update -. .*local/hooks/multi-hook-driver/
118 ls -l $rb/frob.git/hooks/*; ok; /post-receive.h00-second/
119 /post-receive.h01-first/
120 /post-receive -. .*local/hooks/multi-hook-driver/
121 ls -l $rb/gitolite-admin.git/hooks/*
122 ok; /post-receive.h/
123 /post-receive -. .*local/hooks/multi-hook-driver/
124 !/post-update -. .*local/hooks/multi-hook-driver/
127 try "
128 cd ..
130 # Single hook still works
131 [ -d foo ]; !ok;
132 CLONE admin foo; ok; /empty/; /cloned/
133 cd foo
134 tc a1; ok; /ee47f8b/
135 PUSH admin master; ok; /new.*master -. master/
136 /hooks/post-receive.h00-first/
137 !/post-receive.*has args:/
138 /post-receive.h00-first has stdin: 0000000000000000000000000000000000000000 ee47f8b6be2160ad1a3f69c97a0cb3d488e6657e refs/heads/master/
140 cd ..
142 # Multiple hooks fired
143 [ -d bar ]; !ok;
144 CLONE admin bar; ok; /empty/; /cloned/
145 cd bar
146 tc a2; ok; /cfc8561/
147 PUSH admin master; ok; /new.*master -. master/
148 /hooks/pre-receive.h00-first/
149 !/hooks/pre-recieve.*has args:/
150 /hooks/pre-receive.h00-first has stdin: 0000000000000000000000000000000000000000 cfc8561c7827a8b94df6c5dad156383d4cb210f5 refs/heads/master/
151 /hooks/pre-receive.h01-second/
152 !/hooks/pre-receive.h01.*has args:/
153 /hooks/pre-receive.h01-second has stdin: 0000000000000000000000000000000000000000 cfc8561c7827a8b94df6c5dad156383d4cb210f5 refs/heads/master/
155 cd ..
157 # Post-update has stdin instead of arguments
158 [ -d baz ]; !ok;
159 CLONE admin baz; ok; /empty/; /cloned/
160 cd baz
161 tc a3; ok; /2863617/
162 PUSH admin master; ok; /new.*master -. master/
163 /hooks/post-receive.h00-first/
164 !/hooks/post-receive.h00.*has args:/
165 /hooks/post-receive.h00-first has stdin: 0000000000000000000000000000000000000000 28636171ae703f42fb17c312c6b6a078ed07a2cd refs/heads/master/
166 /hooks/post-update.h00-first/
167 /hooks/post-update.h00-first has args: refs/heads/master/
168 !/hooks/post-update.h00.*has stdin:/
169 /hooks/post-update.h01-second/
170 /hooks/post-update.h01-second has args: refs/heads/master/
171 !/hooks/post-update.h01.*has stdin:/
174 # Verify hooks are removed properly
176 confreset;confadd '
177 repo foo
178 RW+ = @all
179 option hook.post-receive =
181 repo bar
182 RW+ = @all
183 option hook.pre-receive = second
185 repo baz
186 RW+ = @all
187 option hook.post-receive =
188 option hook.post-update = second
191 try "ADMIN_PUSH repo-specific-hooks-02; !/FATAL/" or die text();
193 try "
194 ls $rb/foo.git/hooks/*; ok; !/post-receive/
195 ls $rb/bar.git/hooks/*; ok; !/pre-receive.*first/
196 /pre-receive.h00-second/
197 ls $rb/baz.git/hooks/*; ok; !/post-receive/
198 !/post-update.*first/
199 /post-update.h00-second/
202 try "
203 cd ..
205 # Foo has no hooks
206 cd foo
207 tc b1; ok; /7ef69de/
208 PUSH admin master; ok; /master -. master/
209 !/hooks/post-receive/
211 cd ..
213 # Bar only has the second hook
214 cd bar
215 tc b2; ok; /cc7808f/
216 PUSH admin master; ok; /master -. master/
217 /hooks/pre-receive.h00-second/
218 !/hooks/pre-receive.*has args:/
219 /hooks/pre-receive.h00-second has stdin: 0000000000000000000000000000000000000000 cc7808f77c7c7d705f82dc54dc3152146175768f refs/heads/master/
221 cd ..
223 # Baz has no post-receive and keeps the second hook for post-update
224 cd baz
225 tc b3; ok; /8d20101/
226 PUSH admin master; ok; /master -. master/
227 !/hooks/post-receive.*/
228 /hooks/post-update.h00-second/
229 /hooks/post-update.h00-second has args: refs/heads/master/
230 !/hooks/post-update.*has stdin/