##// END OF EJS Templates
hgweb: test the order of archive links
av6 -
r30747:4259df51 default
parent child Browse files
Show More
@@ -1,371 +1,378 b''
1 1 #require serve
2 2
3 3 $ hg init test
4 4 $ cd test
5 5 $ echo foo>foo
6 6 $ hg commit -Am 1 -d '1 0'
7 7 adding foo
8 8 $ echo bar>bar
9 9 $ hg commit -Am 2 -d '2 0'
10 10 adding bar
11 11 $ mkdir baz
12 12 $ echo bletch>baz/bletch
13 13 $ hg commit -Am 3 -d '1000000000 0'
14 14 adding baz/bletch
15 15 $ hg init subrepo
16 16 $ touch subrepo/sub
17 17 $ hg -q -R subrepo ci -Am "init subrepo"
18 18 $ echo "subrepo = subrepo" > .hgsub
19 19 $ hg add .hgsub
20 20 $ hg ci -m "add subrepo"
21 21 $ echo "[web]" >> .hg/hgrc
22 22 $ echo "name = test-archive" >> .hg/hgrc
23 23 $ echo "archivesubrepos = True" >> .hg/hgrc
24 24 $ cp .hg/hgrc .hg/hgrc-base
25 25 > test_archtype() {
26 26 > echo "allow_archive = $1" >> .hg/hgrc
27 27 > hg serve -p $HGPORT -d --pid-file=hg.pid -E errors.log
28 28 > cat hg.pid >> $DAEMON_PIDS
29 29 > echo % $1 allowed should give 200
30 30 > get-with-headers.py localhost:$HGPORT "archive/tip.$2" | head -n 1
31 31 > echo % $3 and $4 disallowed should both give 403
32 32 > get-with-headers.py localhost:$HGPORT "archive/tip.$3" | head -n 1
33 33 > get-with-headers.py localhost:$HGPORT "archive/tip.$4" | head -n 1
34 34 > killdaemons.py
35 35 > cat errors.log
36 36 > cp .hg/hgrc-base .hg/hgrc
37 37 > }
38 38
39 39 check http return codes
40 40
41 41 $ test_archtype gz tar.gz tar.bz2 zip
42 42 % gz allowed should give 200
43 43 200 Script output follows
44 44 % tar.bz2 and zip disallowed should both give 403
45 45 403 Archive type not allowed: bz2
46 46 403 Archive type not allowed: zip
47 47 $ test_archtype bz2 tar.bz2 zip tar.gz
48 48 % bz2 allowed should give 200
49 49 200 Script output follows
50 50 % zip and tar.gz disallowed should both give 403
51 51 403 Archive type not allowed: zip
52 52 403 Archive type not allowed: gz
53 53 $ test_archtype zip zip tar.gz tar.bz2
54 54 % zip allowed should give 200
55 55 200 Script output follows
56 56 % tar.gz and tar.bz2 disallowed should both give 403
57 57 403 Archive type not allowed: gz
58 58 403 Archive type not allowed: bz2
59 59
60 60 $ echo "allow_archive = gz bz2 zip" >> .hg/hgrc
61 61 $ hg serve -p $HGPORT -d --pid-file=hg.pid -E errors.log
62 62 $ cat hg.pid >> $DAEMON_PIDS
63 63
64 check archive links' order
65
66 $ get-with-headers.py localhost:$HGPORT "?revcount=1" | grep '/archive/tip.'
67 <a href="/archive/tip.zip">zip</a>
68 <a href="/archive/tip.tar.gz">gz</a>
69 <a href="/archive/tip.tar.bz2">bz2</a>
70
64 71 invalid arch type should give 404
65 72
66 73 $ get-with-headers.py localhost:$HGPORT "archive/tip.invalid" | head -n 1
67 74 404 Unsupported archive type: None
68 75
69 76 $ TIP=`hg id -v | cut -f1 -d' '`
70 77 $ QTIP=`hg id -q`
71 78 $ cat > getarchive.py <<EOF
72 79 > from __future__ import absolute_import
73 80 > import os
74 81 > import sys
75 82 > from mercurial import (
76 83 > util,
77 84 > )
78 85 > try:
79 86 > # Set stdout to binary mode for win32 platforms
80 87 > import msvcrt
81 88 > msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
82 89 > except ImportError:
83 90 > pass
84 91 > if len(sys.argv) <= 3:
85 92 > node, archive = sys.argv[1:]
86 93 > requeststr = 'cmd=archive;node=%s;type=%s' % (node, archive)
87 94 > else:
88 95 > node, archive, file = sys.argv[1:]
89 96 > requeststr = 'cmd=archive;node=%s;type=%s;file=%s' % (node, archive, file)
90 97 > try:
91 98 > stdout = sys.stdout.buffer
92 99 > except AttributeError:
93 100 > stdout = sys.stdout
94 101 > try:
95 102 > f = util.urlreq.urlopen('http://127.0.0.1:%s/?%s'
96 103 > % (os.environ['HGPORT'], requeststr))
97 104 > stdout.write(f.read())
98 105 > except util.urlerr.httperror as e:
99 106 > sys.stderr.write(str(e) + '\n')
100 107 > EOF
101 108 $ python getarchive.py "$TIP" gz | gunzip | tar tf - 2>/dev/null
102 109 test-archive-1701ef1f1510/.hg_archival.txt
103 110 test-archive-1701ef1f1510/.hgsub
104 111 test-archive-1701ef1f1510/.hgsubstate
105 112 test-archive-1701ef1f1510/bar
106 113 test-archive-1701ef1f1510/baz/bletch
107 114 test-archive-1701ef1f1510/foo
108 115 test-archive-1701ef1f1510/subrepo/sub
109 116 $ python getarchive.py "$TIP" bz2 | bunzip2 | tar tf - 2>/dev/null
110 117 test-archive-1701ef1f1510/.hg_archival.txt
111 118 test-archive-1701ef1f1510/.hgsub
112 119 test-archive-1701ef1f1510/.hgsubstate
113 120 test-archive-1701ef1f1510/bar
114 121 test-archive-1701ef1f1510/baz/bletch
115 122 test-archive-1701ef1f1510/foo
116 123 test-archive-1701ef1f1510/subrepo/sub
117 124 $ python getarchive.py "$TIP" zip > archive.zip
118 125 $ unzip -t archive.zip
119 126 Archive: archive.zip
120 127 testing: test-archive-1701ef1f1510/.hg_archival.txt*OK (glob)
121 128 testing: test-archive-1701ef1f1510/.hgsub*OK (glob)
122 129 testing: test-archive-1701ef1f1510/.hgsubstate*OK (glob)
123 130 testing: test-archive-1701ef1f1510/bar*OK (glob)
124 131 testing: test-archive-1701ef1f1510/baz/bletch*OK (glob)
125 132 testing: test-archive-1701ef1f1510/foo*OK (glob)
126 133 testing: test-archive-1701ef1f1510/subrepo/sub*OK (glob)
127 134 No errors detected in compressed data of archive.zip.
128 135
129 136 test that we can download single directories and files
130 137
131 138 $ python getarchive.py "$TIP" gz baz | gunzip | tar tf - 2>/dev/null
132 139 test-archive-1701ef1f1510/baz/bletch
133 140 $ python getarchive.py "$TIP" gz foo | gunzip | tar tf - 2>/dev/null
134 141 test-archive-1701ef1f1510/foo
135 142
136 143 test that we detect file patterns that match no files
137 144
138 145 $ python getarchive.py "$TIP" gz foobar
139 146 HTTP Error 404: file(s) not found: foobar
140 147
141 148 test that we reject unsafe patterns
142 149
143 150 $ python getarchive.py "$TIP" gz relre:baz
144 151 HTTP Error 404: file(s) not found: relre:baz
145 152
146 153 $ killdaemons.py
147 154
148 155 $ hg archive -t tar test.tar
149 156 $ tar tf test.tar
150 157 test/.hg_archival.txt
151 158 test/.hgsub
152 159 test/.hgsubstate
153 160 test/bar
154 161 test/baz/bletch
155 162 test/foo
156 163
157 164 $ hg archive --debug -t tbz2 -X baz test.tar.bz2 --config progress.debug=true
158 165 archiving: 0/4 files (0.00%)
159 166 archiving: .hgsub 1/4 files (25.00%)
160 167 archiving: .hgsubstate 2/4 files (50.00%)
161 168 archiving: bar 3/4 files (75.00%)
162 169 archiving: foo 4/4 files (100.00%)
163 170 $ bunzip2 -dc test.tar.bz2 | tar tf - 2>/dev/null
164 171 test/.hg_archival.txt
165 172 test/.hgsub
166 173 test/.hgsubstate
167 174 test/bar
168 175 test/foo
169 176
170 177 $ hg archive -t tgz -p %b-%h test-%h.tar.gz
171 178 $ gzip -dc test-$QTIP.tar.gz | tar tf - 2>/dev/null
172 179 test-1701ef1f1510/.hg_archival.txt
173 180 test-1701ef1f1510/.hgsub
174 181 test-1701ef1f1510/.hgsubstate
175 182 test-1701ef1f1510/bar
176 183 test-1701ef1f1510/baz/bletch
177 184 test-1701ef1f1510/foo
178 185
179 186 $ hg archive autodetected_test.tar
180 187 $ tar tf autodetected_test.tar
181 188 autodetected_test/.hg_archival.txt
182 189 autodetected_test/.hgsub
183 190 autodetected_test/.hgsubstate
184 191 autodetected_test/bar
185 192 autodetected_test/baz/bletch
186 193 autodetected_test/foo
187 194
188 195 The '-t' should override autodetection
189 196
190 197 $ hg archive -t tar autodetect_override_test.zip
191 198 $ tar tf autodetect_override_test.zip
192 199 autodetect_override_test.zip/.hg_archival.txt
193 200 autodetect_override_test.zip/.hgsub
194 201 autodetect_override_test.zip/.hgsubstate
195 202 autodetect_override_test.zip/bar
196 203 autodetect_override_test.zip/baz/bletch
197 204 autodetect_override_test.zip/foo
198 205
199 206 $ for ext in tar tar.gz tgz tar.bz2 tbz2 zip; do
200 207 > hg archive auto_test.$ext
201 208 > if [ -d auto_test.$ext ]; then
202 209 > echo "extension $ext was not autodetected."
203 210 > fi
204 211 > done
205 212
206 213 $ cat > md5comp.py <<EOF
207 214 > from __future__ import print_function
208 215 > try:
209 216 > from hashlib import md5
210 217 > except ImportError:
211 218 > from md5 import md5
212 219 > import sys
213 220 > f1, f2 = sys.argv[1:3]
214 221 > h1 = md5(open(f1, 'rb').read()).hexdigest()
215 222 > h2 = md5(open(f2, 'rb').read()).hexdigest()
216 223 > print(h1 == h2 or "md5 differ: " + repr((h1, h2)))
217 224 > EOF
218 225
219 226 archive name is stored in the archive, so create similar archives and
220 227 rename them afterwards.
221 228
222 229 $ hg archive -t tgz tip.tar.gz
223 230 $ mv tip.tar.gz tip1.tar.gz
224 231 $ sleep 1
225 232 $ hg archive -t tgz tip.tar.gz
226 233 $ mv tip.tar.gz tip2.tar.gz
227 234 $ python md5comp.py tip1.tar.gz tip2.tar.gz
228 235 True
229 236
230 237 $ hg archive -t zip -p /illegal test.zip
231 238 abort: archive prefix contains illegal components
232 239 [255]
233 240 $ hg archive -t zip -p very/../bad test.zip
234 241
235 242 $ hg archive --config ui.archivemeta=false -t zip -r 2 test.zip
236 243 $ unzip -t test.zip
237 244 Archive: test.zip
238 245 testing: test/bar*OK (glob)
239 246 testing: test/baz/bletch*OK (glob)
240 247 testing: test/foo*OK (glob)
241 248 No errors detected in compressed data of test.zip.
242 249
243 250 $ hg archive -t tar - | tar tf - 2>/dev/null
244 251 test-1701ef1f1510/.hg_archival.txt
245 252 test-1701ef1f1510/.hgsub
246 253 test-1701ef1f1510/.hgsubstate
247 254 test-1701ef1f1510/bar
248 255 test-1701ef1f1510/baz/bletch
249 256 test-1701ef1f1510/foo
250 257
251 258 $ hg archive -r 0 -t tar rev-%r.tar
252 259 $ [ -f rev-0.tar ]
253 260
254 261 test .hg_archival.txt
255 262
256 263 $ hg archive ../test-tags
257 264 $ cat ../test-tags/.hg_archival.txt
258 265 repo: daa7f7c60e0a224faa4ff77ca41b2760562af264
259 266 node: 1701ef1f151069b8747038e93b5186bb43a47504
260 267 branch: default
261 268 latesttag: null
262 269 latesttagdistance: 4
263 270 changessincelatesttag: 4
264 271 $ hg tag -r 2 mytag
265 272 $ hg tag -r 2 anothertag
266 273 $ hg archive -r 2 ../test-lasttag
267 274 $ cat ../test-lasttag/.hg_archival.txt
268 275 repo: daa7f7c60e0a224faa4ff77ca41b2760562af264
269 276 node: 2c0277f05ed49d1c8328fb9ba92fba7a5ebcb33e
270 277 branch: default
271 278 tag: anothertag
272 279 tag: mytag
273 280
274 281 $ hg archive -t bogus test.bogus
275 282 abort: unknown archive type 'bogus'
276 283 [255]
277 284
278 285 enable progress extension:
279 286
280 287 $ cp $HGRCPATH $HGRCPATH.no-progress
281 288 $ cat >> $HGRCPATH <<EOF
282 289 > [progress]
283 290 > assume-tty = 1
284 291 > format = topic bar number
285 292 > delay = 0
286 293 > refresh = 0
287 294 > width = 60
288 295 > EOF
289 296
290 297 $ hg archive ../with-progress
291 298 \r (no-eol) (esc)
292 299 archiving [ ] 0/6\r (no-eol) (esc)
293 300 archiving [======> ] 1/6\r (no-eol) (esc)
294 301 archiving [=============> ] 2/6\r (no-eol) (esc)
295 302 archiving [====================> ] 3/6\r (no-eol) (esc)
296 303 archiving [===========================> ] 4/6\r (no-eol) (esc)
297 304 archiving [==================================> ] 5/6\r (no-eol) (esc)
298 305 archiving [==========================================>] 6/6\r (no-eol) (esc)
299 306 \r (no-eol) (esc)
300 307
301 308 cleanup after progress extension test:
302 309
303 310 $ cp $HGRCPATH.no-progress $HGRCPATH
304 311
305 312 server errors
306 313
307 314 $ cat errors.log
308 315
309 316 empty repo
310 317
311 318 $ hg init ../empty
312 319 $ cd ../empty
313 320 $ hg archive ../test-empty
314 321 abort: no working directory: please specify a revision
315 322 [255]
316 323
317 324 old file -- date clamped to 1980
318 325
319 326 $ touch -t 197501010000 old
320 327 $ hg add old
321 328 $ hg commit -m old
322 329 $ hg archive ../old.zip
323 330 $ unzip -l ../old.zip
324 331 Archive: ../old.zip
325 332 \s*Length.* (re)
326 333 *-----* (glob)
327 334 *172*80*00:00*old/.hg_archival.txt (glob)
328 335 *0*80*00:00*old/old (glob)
329 336 *-----* (glob)
330 337 \s*172\s+2 files (re)
331 338
332 339 show an error when a provided pattern matches no files
333 340
334 341 $ hg archive -I file_that_does_not_exist.foo ../empty.zip
335 342 abort: no files match the archive pattern
336 343 [255]
337 344
338 345 $ hg archive -X * ../empty.zip
339 346 abort: no files match the archive pattern
340 347 [255]
341 348
342 349 $ cd ..
343 350
344 351 issue3600: check whether "hg archive" can create archive files which
345 352 are extracted with expected timestamp, even though TZ is not
346 353 configured as GMT.
347 354
348 355 $ mkdir issue3600
349 356 $ cd issue3600
350 357
351 358 $ hg init repo
352 359 $ echo a > repo/a
353 360 $ hg -R repo add repo/a
354 361 $ hg -R repo commit -m '#0' -d '456789012 21600'
355 362 $ cat > show_mtime.py <<EOF
356 363 > from __future__ import print_function
357 364 > import sys, os
358 365 > print(int(os.stat(sys.argv[1]).st_mtime))
359 366 > EOF
360 367
361 368 $ hg -R repo archive --prefix tar-extracted archive.tar
362 369 $ (TZ=UTC-3; export TZ; tar xf archive.tar)
363 370 $ python show_mtime.py tar-extracted/a
364 371 456789012
365 372
366 373 $ hg -R repo archive --prefix zip-extracted archive.zip
367 374 $ (TZ=UTC-3; export TZ; unzip -q archive.zip)
368 375 $ python show_mtime.py zip-extracted/a
369 376 456789012
370 377
371 378 $ cd ..
General Comments 0
You need to be logged in to leave comments. Login now