3 test_description
='ref_prepare.awk functionality'
9 ap
="$(tg --awk-path)" && test -n "$ap" && test -d "$ap" || die
10 aprp
="$ap/ref_prepare"
11 test -f "$aprp" && test -r "$aprp" && test -x "$aprp" || die
15 test_expect_success
'ref_prepare runs' '
16 # some stupid awks might not even compile it
17 awk -v topbases="a" -v headbase="b" -f "$aprp" </dev/null
20 test_expect_success
'ref_prepare bad usage' '
22 test_must_fail awk -f "$aprp" &&
23 test_must_fail awk -v topbases="bad" -f "$aprp" &&
24 test_must_fail awk -v topbases="bad" -f "$aprp" &&
25 test_must_fail awk -v topbases="/" -v headbase="x" -f "$aprp" &&
26 test_must_fail awk -v topbases="a" -v headbase="/" -f "$aprp"
29 test_expect_success
'leaves refs file alone' '
30 echo notouchy > list &&
31 awk -v topbases="refs" -v refsfile="list" -f "$aprp" </dev/null &&
32 test z"$(cat list)" = z"notouchy"
35 test_expect_success
'leaves refs file alone without rmrf' '
36 echo notouchy > list &&
37 awk -v topbases="refs" -v refsfile="list" -f "$aprp" </dev/null &&
38 awk -v topbases="refs" -v refsfile="list" -v rmrf=0 -f "$aprp" </dev/null &&
39 test z"$(cat list)" = z"notouchy"
42 test_expect_success
'refs file removed on request' '
43 echo notouchy > list &&
44 echo hi | awk -v topbases="refs" -v refsfile="list" -v rmrf=1 -f "$aprp" &&
48 test_expect_success
'removes refs file on request even if not read' '
49 echo notouchy > list &&
50 awk -v topbases="refs" -v refsfile="list" -v rmrf=1 -f "$aprp" </dev/null &&
54 test_expect_success
'only bases recognized' '
67 printf "%s\n" h/1 h/2 b b/ b/3 c/4 b/0 |
68 awk -v topbases=b -v headbase=h -f "$aprp" > actual &&
69 test_diff expected actual
72 test_expect_success
'chkblob on request' '
81 printf "%s\n" h/1 h/2 b b/ b/3 c/4 |
82 awk -v topbases=b -v headbase=h -v chkblob=0666 -f "$aprp" > actual &&
83 test_diff expected actual
86 test_expect_success
'depsblob on request' '
95 printf "%s\n" h/1 h/2 b b/ b/3 c/4 |
96 awk -v topbases=b -v headbase=h -v depsblob=1 -f "$aprp" > actual &&
97 test_diff expected actual
100 test_expect_success
'msgblob on request' '
109 printf "%s\n" h/1 h/2 b b/ b/3 c/4 |
110 awk -v topbases=b -v headbase=h -v msgblob=1 -f "$aprp" > actual &&
111 test_diff expected actual
114 test_expect_success
'both .top blobs on request' '
124 printf "%s\n" h/1 h/2 b b/ b/3 c/4 |
125 awk -v topbases=b -v headbase=h -v msgblob=1 -v depsblob=1 -f "$aprp" > actual &&
126 test_diff expected actual
129 test_expect_success
'all blobs on request' '
140 printf "%s\n" h/1 h/2 b b/ b/3 c/4 |
141 awk -v topbases=b -v headbase=h -v chkblob=0666 -v msgblob=1 -v depsblob=1 -f "$aprp" > actual &&
142 test_diff expected actual
145 test_expect_success
'sensible default headbase' '
146 printf "%s\n" refs/tb/1/2/3 |
147 awk -v topbases=refs/tb -f "$aprp" >actual &&
148 h="$(sed -n 3p <actual)" &&
149 test z"$h" = z"refs/heads/1/2/3^0" &&
150 printf "%s\n" refs/tb/1/2/3 |
151 awk -v topbases=refs/tb/1 -f "$aprp" >actual &&
152 h="$(sed -n 3p <actual)" &&
153 test z"$h" = z"refs/heads/2/3^0" &&
154 printf "%s\n" refs/tb/1/2/3 |
155 awk -v topbases=refs/tb/1/2 -f "$aprp" >actual &&
156 h="$(sed -n 3p <actual)" &&
157 test z"$h" = z"refs/heads/3^0"
160 test_expect_success
'non-remote remote has no default headbase' '
162 test_must_fail awk -v topbases=refs/remotes/tb -f "$aprp" &&
163 test_must_fail awk -v topbases=refs/remotes -f "$aprp"
166 test_expect_success
'single-level remote names default okay' '
167 printf "%s\n" refs/remotes/o/tb/3 |
168 awk -v topbases=refs/remotes/o/tb -f "$aprp" >actual &&
169 h="$(sed -n 3p <actual)" &&
170 test z"$h" = z"refs/remotes/o/3^0" &&
171 printf "%s\n" refs/remotes/longer/tb/3 |
172 awk -v topbases=refs/remotes/longer/tb -f "$aprp" >actual &&
173 h="$(sed -n 3p <actual)" &&
174 test z"$h" = z"refs/remotes/longer/3^0" &&
175 printf "%s\n" refs/remotes/o/tb/3/4 |
176 awk -v topbases=refs/remotes/o/tb -f "$aprp" >actual &&
177 h="$(sed -n 3p <actual)" &&
178 test z"$h" = z"refs/remotes/o/3/4^0" &&
179 printf "%s\n" refs/remotes/longer/tb/3/4/5 |
180 awk -v topbases=refs/remotes/longer/tb -f "$aprp" >actual &&
181 h="$(sed -n 3p <actual)" &&
182 test z"$h" = z"refs/remotes/longer/3/4/5^0" &&
183 printf "%s\n" refs/remotes/longer/tb/not/bad |
184 awk -v topbases=refs/remotes/longer/tb -f "$aprp" >actual &&
185 h="$(sed -n 3p <actual)" &&
186 test z"$h" = z"refs/remotes/longer/not/bad^0"
189 test_expect_success
'multi-level remote names default okay' '
190 printf "%s\n" refs/remotes/o/there/tb/3 |
191 awk -v topbases=refs/remotes/o/there/tb -f "$aprp" >actual &&
192 h="$(sed -n 3p <actual)" &&
193 test z"$h" = z"refs/remotes/o/there/3^0" &&
194 printf "%s\n" refs/remotes/o/there/tb/3/4/5 |
195 awk -v topbases=refs/remotes/o/there/tb -f "$aprp" >actual &&
196 h="$(sed -n 3p <actual)" &&
197 test z"$h" = z"refs/remotes/o/there/3/4/5^0" &&
198 printf "%s\n" refs/remotes/o/there/somewhere/tb/3 |
199 awk -v topbases=refs/remotes/o/there/somewhere/tb -f "$aprp" >actual &&
200 h="$(sed -n 3p <actual)" &&
201 test z"$h" = z"refs/remotes/o/there/somewhere/3^0" &&
202 printf "%s\n" refs/remotes/o/there/somewhere/tb/3/4 |
203 awk -v topbases=refs/remotes/o/there/somewhere/tb -f "$aprp" >actual &&
204 h="$(sed -n 3p <actual)" &&
205 test z"$h" = z"refs/remotes/o/there/somewhere/3/4^0"
208 test_expect_success
'teeout copy works' '
225 printf "%s\n" h/1 h/2 b b/ b/3 c/4 b/0 |
226 awk -v topbases=b -v headbase=h -v depsblob=1 -v msgblob=1 -v teeout=copy -f "$aprp" > actual &&
227 test_diff expected actual &&
228 test_diff expected copy
231 test_expect_success
'teeout copy works on substs' '
248 printf "%s\n" h/1 h/2 b b/ b/3 c/4 b/0 |
249 awk -v topbases=b -v headbase=h -v depsblob=1 -v msgblob=1 -v teeout=copy \
250 -v topdeps=3:1234 -v topmsg=0:4321 -f "$aprp" > actual &&
251 test_diff expected actual &&
252 test_diff expected copy
255 test_expect_success
'teeout copy works on substs with refsfile' '
258 refs/h/3 f333 just junk here
285 printf "%s\n" refs/h/1 refs/h/2 refs/b refs/b/ refs/b/3 refs/b/not refs/c/4 refs/b/0 |
286 awk -v topbases=refs/b -v headbase=refs/h -v depsblob=1 -v msgblob=1 -v teeout=copy \
287 -v topdeps=3:1234 -v topmsg=0:4321 -v refsfile=refslist -f "$aprp" > actual &&
288 test_diff expected actual &&
289 test_diff expected copy
292 test_expect_success
'teeout copy works on substs with pckdrefs refsfile' '
295 f333 refs/h/3 just junk here
322 printf "%s\n" refs/h/1 refs/h/2 refs/b refs/b/ refs/b/3 refs/b/not refs/c/4 refs/b/0 |
323 awk -v topbases=refs/b -v headbase=refs/h -v depsblob=1 -v msgblob=1 -v teeout=copy \
324 -v topdeps=3:1234 -v topmsg=0:4321 -v refsfile=refslist -v pckdrefs=1 -f "$aprp" > actual &&
325 test_diff expected actual &&
326 test_diff expected copy