Debian Codegraph @

tests/test-audit-subrepo.t

raw
1 Test illegal name
2 -----------------
3
4 on commit:
5
6 $ hg init hgname
7 $ cd hgname
8 $ mkdir sub
9 $ hg init sub/.hg
10 $ echo 'sub/.hg = sub/.hg' >> .hgsub
11 $ hg ci -qAm 'add subrepo "sub/.hg"'
12 abort: path 'sub/.hg' is inside nested repo 'sub'
13 [10]
14
15 prepare tampered repo (including the commit above):
16
17 $ hg import --bypass -qm 'add subrepo "sub/.hg"' - <<'EOF'
18 > diff --git a/.hgsub b/.hgsub
19 > new file mode 100644
20 > --- /dev/null
21 > +++ b/.hgsub
22 > @@ -0,0 +1,1 @@
23 > +sub/.hg = sub/.hg
24 > diff --git a/.hgsubstate b/.hgsubstate
25 > new file mode 100644
26 > --- /dev/null
27 > +++ b/.hgsubstate
28 > @@ -0,0 +1,1 @@
29 > +0000000000000000000000000000000000000000 sub/.hg
30 > EOF
31 $ cd ..
32
33 on clone (and update):
34
35 $ hg clone -q hgname hgname2
36 abort: path 'sub/.hg' is inside nested repo 'sub'
37 [10]
38
39 Test absolute path
40 ------------------
41
42 on commit:
43
44 $ hg init absolutepath
45 $ cd absolutepath
46 $ hg init sub
47 $ echo '/sub = sub' >> .hgsub
48 $ hg ci -qAm 'add subrepo "/sub"'
49 abort: path contains illegal component: /sub
50 [10]
51
52 prepare tampered repo (including the commit above):
53
54 $ hg import --bypass -qm 'add subrepo "/sub"' - <<'EOF'
55 > diff --git a/.hgsub b/.hgsub
56 > new file mode 100644
57 > --- /dev/null
58 > +++ b/.hgsub
59 > @@ -0,0 +1,1 @@
60 > +/sub = sub
61 > diff --git a/.hgsubstate b/.hgsubstate
62 > new file mode 100644
63 > --- /dev/null
64 > +++ b/.hgsubstate
65 > @@ -0,0 +1,1 @@
66 > +0000000000000000000000000000000000000000 /sub
67 > EOF
68 $ cd ..
69
70 on clone (and update):
71
72 $ hg clone -q absolutepath absolutepath2
73 abort: path contains illegal component: /sub
74 [10]
75
76 Test root path
77 --------------
78
79 on commit:
80
81 $ hg init rootpath
82 $ cd rootpath
83 $ hg init sub
84 $ echo '/ = sub' >> .hgsub
85 $ hg ci -qAm 'add subrepo "/"'
86 abort: path ends in directory separator: /
87 [10]
88
89 prepare tampered repo (including the commit above):
90
91 $ hg import --bypass -qm 'add subrepo "/"' - <<'EOF'
92 > diff --git a/.hgsub b/.hgsub
93 > new file mode 100644
94 > --- /dev/null
95 > +++ b/.hgsub
96 > @@ -0,0 +1,1 @@
97 > +/ = sub
98 > diff --git a/.hgsubstate b/.hgsubstate
99 > new file mode 100644
100 > --- /dev/null
101 > +++ b/.hgsubstate
102 > @@ -0,0 +1,1 @@
103 > +0000000000000000000000000000000000000000 /
104 > EOF
105 $ cd ..
106
107 on clone (and update):
108
109 $ hg clone -q rootpath rootpath2
110 abort: path ends in directory separator: /
111 [10]
112
113 Test empty path
114 ---------------
115
116 on commit:
117
118 $ hg init emptypath
119 $ cd emptypath
120 $ hg init sub
121 $ echo '= sub' >> .hgsub
122 $ hg ci -qAm 'add subrepo ""'
123 config error at .hgsub:1: = sub
124 [30]
125
126 prepare tampered repo (including the commit above):
127
128 $ hg import --bypass -qm 'add subrepo ""' - <<'EOF'
129 > diff --git a/.hgsub b/.hgsub
130 > new file mode 100644
131 > --- /dev/null
132 > +++ b/.hgsub
133 > @@ -0,0 +1,1 @@
134 > += sub
135 > diff --git a/.hgsubstate b/.hgsubstate
136 > new file mode 100644
137 > --- /dev/null
138 > +++ b/.hgsubstate
139 > @@ -0,0 +1,1 @@
140 > +0000000000000000000000000000000000000000
141 > EOF
142 $ cd ..
143
144 on clone (and update):
145
146 $ hg clone -q emptypath emptypath2
147 config error at .hgsub:1: = sub
148 [30]
149
150 Test current path
151 -----------------
152
153 on commit:
154
155 $ hg init currentpath
156 $ cd currentpath
157 $ hg init sub
158 $ echo '. = sub' >> .hgsub
159 $ hg ci -qAm 'add subrepo "."'
160 abort: subrepo path contains illegal component: .
161 [255]
162
163 prepare tampered repo (including the commit above):
164
165 $ hg import --bypass -qm 'add subrepo "."' - <<'EOF'
166 > diff --git a/.hgsub b/.hgsub
167 > new file mode 100644
168 > --- /dev/null
169 > +++ b/.hgsub
170 > @@ -0,0 +1,1 @@
171 > +.= sub
172 > diff --git a/.hgsubstate b/.hgsubstate
173 > new file mode 100644
174 > --- /dev/null
175 > +++ b/.hgsubstate
176 > @@ -0,0 +1,1 @@
177 > +0000000000000000000000000000000000000000 .
178 > EOF
179 $ cd ..
180
181 on clone (and update):
182
183 $ hg clone -q currentpath currentpath2
184 abort: subrepo path contains illegal component: .
185 [255]
186
187 Test outer path
188 ---------------
189
190 on commit:
191
192 $ mkdir outerpath
193 $ cd outerpath
194 $ hg init main
195 $ cd main
196 $ hg init ../sub
197 $ echo '../sub = ../sub' >> .hgsub
198 $ hg ci -qAm 'add subrepo "../sub"'
199 abort: path contains illegal component: ../sub
200 [10]
201
202 prepare tampered repo (including the commit above):
203
204 $ hg import --bypass -qm 'add subrepo "../sub"' - <<'EOF'
205 > diff --git a/.hgsub b/.hgsub
206 > new file mode 100644
207 > --- /dev/null
208 > +++ b/.hgsub
209 > @@ -0,0 +1,1 @@
210 > +../sub = ../sub
211 > diff --git a/.hgsubstate b/.hgsubstate
212 > new file mode 100644
213 > --- /dev/null
214 > +++ b/.hgsubstate
215 > @@ -0,0 +1,1 @@
216 > +0000000000000000000000000000000000000000 ../sub
217 > EOF
218 $ cd ..
219
220 on clone (and update):
221
222 $ hg clone -q main main2
223 abort: path contains illegal component: ../sub
224 [10]
225 $ cd ..
226
227 Test variable expansion
228 -----------------------
229
230 Subrepository paths shouldn't be expanded, but we fail to handle them
231 properly. Any local repository paths are expanded.
232
233 on commit:
234
235 $ mkdir envvar
236 $ cd envvar
237 $ hg init main
238 $ cd main
239 $ hg init sub1
240 $ cat <<'EOF' > sub1/hgrc
241 > [hooks]
242 > log = echo pwned
243 > EOF
244 $ hg -R sub1 ci -qAm 'add sub1 files'
245 $ hg -R sub1 log -r. -T '{node}\n'
246 39eb4b4d3e096527668784893a9280578a8f38b8
247 $ echo '$SUB = sub1' >> .hgsub
248 $ SUB=sub1 hg ci -qAm 'add subrepo "$SUB"'
249 abort: subrepo path contains illegal component: $SUB
250 [255]
251
252 prepare tampered repo (including the changes above as two commits):
253
254 $ hg import --bypass -qm 'add subrepo "$SUB"' - <<'EOF'
255 > diff --git a/.hgsub b/.hgsub
256 > new file mode 100644
257 > --- /dev/null
258 > +++ b/.hgsub
259 > @@ -0,0 +1,1 @@
260 > +$SUB = sub1
261 > diff --git a/.hgsubstate b/.hgsubstate
262 > new file mode 100644
263 > --- /dev/null
264 > +++ b/.hgsubstate
265 > @@ -0,0 +1,1 @@
266 > +0000000000000000000000000000000000000000 $SUB
267 > EOF
268 $ hg debugsetparents 0
269 $ hg import --bypass -qm 'update subrepo "$SUB"' - <<'EOF'
270 > diff --git a/.hgsubstate b/.hgsubstate
271 > --- a/.hgsubstate
272 > +++ b/.hgsubstate
273 > @@ -1,1 +1,1 @@
274 > -0000000000000000000000000000000000000000 $SUB
275 > +39eb4b4d3e096527668784893a9280578a8f38b8 $SUB
276 > EOF
277 $ cd ..
278
279 on clone (and update) with various substitutions:
280
281 $ hg clone -q main main2
282 abort: subrepo path contains illegal component: $SUB
283 [255]
284 $ ls -A main2
285 .hg
286 .hgsub
287 .hgsubstate
288
289 $ SUB=sub1 hg clone -q main main3
290 abort: subrepo path contains illegal component: $SUB
291 [255]
292 $ ls -A main3
293 .hg
294 .hgsub
295 .hgsubstate
296
297 $ SUB=sub2 hg clone -q main main4
298 abort: subrepo path contains illegal component: $SUB
299 [255]
300 $ ls -A main4
301 .hg
302 .hgsub
303 .hgsubstate
304
305 on clone empty subrepo into .hg, then pull (and update), which at least fails:
306
307 $ SUB=.hg hg clone -qr0 main main5
308 abort: subrepo path contains illegal component: $SUB
309 [255]
310 $ ls -A main5
311 .hg
312 .hgsub
313 .hgsubstate
314 $ test -d main5/.hg/.hg
315 [1]
316 $ SUB=.hg hg -R main5 pull -u
317 pulling from $TESTTMP/envvar/main
318 searching for changes
319 adding changesets
320 adding manifests
321 adding file changes
322 added 1 changesets with 1 changes to 1 files
323 new changesets 7a2f0e59146f
324 .hgsubstate: untracked file differs
325 abort: untracked files in working directory differ from files in requested revision
326 [20]
327 $ cat main5/.hg/hgrc | grep pwned
328 [1]
329
330 on clone (and update) into .hg, which at least fails:
331
332 $ SUB=.hg hg clone -q main main6
333 abort: subrepo path contains illegal component: $SUB
334 [255]
335 $ ls -A main6
336 .hg
337 .hgsub
338 .hgsubstate
339 $ cat main6/.hg/hgrc | grep pwned
340 [1]
341
342 on clone (and update) into .hg/* subdir:
343
344 $ SUB=.hg/foo hg clone -q main main7
345 abort: subrepo path contains illegal component: $SUB
346 [255]
347 $ ls -A main7
348 .hg
349 .hgsub
350 .hgsubstate
351 $ test -d main7/.hg/.hg
352 [1]
353
354 on clone (and update) into outer tree:
355
356 $ SUB=../out-of-tree-write hg clone -q main main8
357 abort: subrepo path contains illegal component: $SUB
358 [255]
359 $ ls -A main8
360 .hg
361 .hgsub
362 .hgsubstate
363
364 on clone (and update) into e.g. $HOME, which doesn't work since subrepo paths
365 are concatenated prior to variable expansion:
366
367 $ SUB="$TESTTMP/envvar/fakehome" hg clone -q main main9
368 abort: subrepo path contains illegal component: $SUB
369 [255]
370 $ ls -A main9 | wc -l
371 \s*3 (re)
372
373 $ ls
374 main
375 main2
376 main3
377 main4
378 main5
379 main6
380 main7
381 main8
382 main9
383 $ cd ..
384
385 Test tilde
386 ----------
387
388 The leading tilde may be expanded to $HOME, but it can be a valid subrepo
389 path in theory. However, we want to prohibit it as there might be unsafe
390 handling of such paths.
391
392 on commit:
393
394 $ hg init tilde
395 $ cd tilde
396 $ hg init './~'
397 $ echo '~ = ~' >> .hgsub
398 $ hg ci -qAm 'add subrepo "~"'
399 abort: subrepo path contains illegal component: ~
400 [255]
401
402 prepare tampered repo (including the commit above):
403
404 $ hg import --bypass -qm 'add subrepo "~"' - <<'EOF'
405 > diff --git a/.hgsub b/.hgsub
406 > new file mode 100644
407 > --- /dev/null
408 > +++ b/.hgsub
409 > @@ -0,0 +1,1 @@
410 > +~ = ~
411 > diff --git a/.hgsubstate b/.hgsubstate
412 > new file mode 100644
413 > --- /dev/null
414 > +++ b/.hgsubstate
415 > @@ -0,0 +1,1 @@
416 > +0000000000000000000000000000000000000000 ~
417 > EOF
418 $ cd ..
419
420 on clone (and update):
421
422 $ hg clone -q tilde tilde2
423 abort: subrepo path contains illegal component: ~
424 [255]
425
426 Test direct symlink traversal
427 -----------------------------
428
429 #if symlink
430
431 on commit:
432
433 $ mkdir hgsymdir
434 $ hg init hgsymdir/root
435 $ cd hgsymdir/root
436 $ ln -s ../out
437 $ hg ci -qAm 'add symlink "out"'
438 $ hg init ../out
439 $ echo 'out = out' >> .hgsub
440 $ hg ci -qAm 'add subrepo "out"'
441 abort: subrepo 'out' traverses symbolic link
442 [255]
443
444 prepare tampered repo (including the commit above):
445
446 $ hg import --bypass -qm 'add subrepo "out"' - <<'EOF'
447 > diff --git a/.hgsub b/.hgsub
448 > new file mode 100644
449 > --- /dev/null
450 > +++ b/.hgsub
451 > @@ -0,0 +1,1 @@
452 > +out = out
453 > diff --git a/.hgsubstate b/.hgsubstate
454 > new file mode 100644
455 > --- /dev/null
456 > +++ b/.hgsubstate
457 > @@ -0,0 +1,1 @@
458 > +0000000000000000000000000000000000000000 out
459 > EOF
460 $ cd ../..
461
462 on clone (and update):
463
464 $ mkdir hgsymdir2
465 $ hg clone -q hgsymdir/root hgsymdir2/root
466 abort: subrepo 'out' traverses symbolic link
467 [255]
468 $ ls hgsymdir2
469 root
470
471 #endif
472
473 Test indirect symlink traversal
474 -------------------------------
475
476 #if symlink
477
478 on commit:
479
480 $ mkdir hgsymin
481 $ hg init hgsymin/root
482 $ cd hgsymin/root
483 $ ln -s ../out
484 $ hg ci -qAm 'add symlink "out"'
485 $ mkdir ../out
486 $ hg init ../out/sub
487 $ echo 'out/sub = out/sub' >> .hgsub
488 $ hg ci -qAm 'add subrepo "out/sub"'
489 abort: path 'out/sub' traverses symbolic link 'out'
490 [255]
491
492 prepare tampered repo (including the commit above):
493
494 $ hg import --bypass -qm 'add subrepo "out/sub"' - <<'EOF'
495 > diff --git a/.hgsub b/.hgsub
496 > new file mode 100644
497 > --- /dev/null
498 > +++ b/.hgsub
499 > @@ -0,0 +1,1 @@
500 > +out/sub = out/sub
501 > diff --git a/.hgsubstate b/.hgsubstate
502 > new file mode 100644
503 > --- /dev/null
504 > +++ b/.hgsubstate
505 > @@ -0,0 +1,1 @@
506 > +0000000000000000000000000000000000000000 out/sub
507 > EOF
508 $ cd ../..
509
510 on clone (and update):
511
512 $ mkdir hgsymin2
513 $ hg clone -q hgsymin/root hgsymin2/root
514 abort: path 'out/sub' traverses symbolic link 'out'
515 [255]
516 $ ls hgsymin2
517 root
518
519 #endif
520
521 Test symlink traversal by variable expansion
522 --------------------------------------------
523
524 #if symlink
525
526 $ FAKEHOME="$TESTTMP/envvarsym/fakehome"
527
528 on commit:
529
530 $ mkdir envvarsym
531 $ cd envvarsym
532 $ hg init main
533 $ cd main
534 $ ln -s "`echo "$FAKEHOME" | sed 's|\(.\)/.*|\1|'`"
535 $ hg ci -qAm 'add symlink to top-level system directory'
536
537 $ hg init sub1
538 $ echo pwned > sub1/pwned
539 $ hg -R sub1 ci -qAm 'add sub1 files'
540 $ hg -R sub1 log -r. -T '{node}\n'
541 f40c9134ba1b6961e12f250868823f0092fb68a8
542 $ echo '$SUB = sub1' >> .hgsub
543 $ SUB="$FAKEHOME" hg ci -qAm 'add subrepo "$SUB"'
544 abort: subrepo path contains illegal component: $SUB
545 [255]
546
547 prepare tampered repo (including the changes above as two commits):
548
549 $ hg import --bypass -qm 'add subrepo "$SUB"' - <<'EOF'
550 > diff --git a/.hgsub b/.hgsub
551 > new file mode 100644
552 > --- /dev/null
553 > +++ b/.hgsub
554 > @@ -0,0 +1,1 @@
555 > +$SUB = sub1
556 > diff --git a/.hgsubstate b/.hgsubstate
557 > new file mode 100644
558 > --- /dev/null
559 > +++ b/.hgsubstate
560 > @@ -0,0 +1,1 @@
561 > +0000000000000000000000000000000000000000 $SUB
562 > EOF
563 $ hg debugsetparents 1
564 $ hg import --bypass -qm 'update subrepo "$SUB"' - <<'EOF'
565 > diff --git a/.hgsubstate b/.hgsubstate
566 > --- a/.hgsubstate
567 > +++ b/.hgsubstate
568 > @@ -1,1 +1,1 @@
569 > -0000000000000000000000000000000000000000 $SUB
570 > +f40c9134ba1b6961e12f250868823f0092fb68a8 $SUB
571 > EOF
572 $ cd ..
573
574 on clone (and update) without fakehome directory:
575
576 $ rm -fR "$FAKEHOME"
577 $ SUB="$FAKEHOME" hg clone -q main main2
578 abort: subrepo path contains illegal component: $SUB
579 [255]
580 $ test -d "$FAKEHOME"
581 [1]
582
583 on clone (and update) with empty fakehome directory:
584
585 $ rm -fR "$FAKEHOME"
586 $ mkdir "$FAKEHOME"
587 $ SUB="$FAKEHOME" hg clone -q main main3
588 abort: subrepo path contains illegal component: $SUB
589 [255]
590 $ ls "$FAKEHOME"
591
592 on clone (and update) with non-empty fakehome directory:
593
594 $ rm -fR "$FAKEHOME"
595 $ mkdir "$FAKEHOME"
596 $ touch "$FAKEHOME/a"
597 $ SUB="$FAKEHOME" hg clone -q main main4
598 abort: subrepo path contains illegal component: $SUB
599 [255]
600 $ ls "$FAKEHOME"
601 a
602
603 on clone empty subrepo with non-empty fakehome directory,
604 then pull (and update):
605
606 $ rm -fR "$FAKEHOME"
607 $ mkdir "$FAKEHOME"
608 $ touch "$FAKEHOME/a"
609 $ SUB="$FAKEHOME" hg clone -qr1 main main5
610 abort: subrepo path contains illegal component: $SUB
611 [255]
612 $ ls "$FAKEHOME"
613 a
614 $ test -d "$FAKEHOME/.hg"
615 [1]
616 $ SUB="$FAKEHOME" hg -R main5 pull -u
617 pulling from $TESTTMP/envvarsym/main
618 searching for changes
619 adding changesets
620 adding manifests
621 adding file changes
622 added 1 changesets with 1 changes to 1 files
623 new changesets * (glob)
624 .hgsubstate: untracked file differs
625 abort: untracked files in working directory differ from files in requested revision
626 [20]
627 $ ls "$FAKEHOME"
628 a
629 $ test -d "$FAKEHOME/.hg"
630 [1]
631
632 on clone empty subrepo with hg-managed fakehome directory,
633 then pull (and update):
634
635 $ rm -fR "$FAKEHOME"
636 $ hg init "$FAKEHOME"
637 $ touch "$FAKEHOME/a"
638 $ hg -R "$FAKEHOME" ci -qAm 'add fakehome file'
639 $ SUB="$FAKEHOME" hg clone -qr1 main main6
640 abort: subrepo path contains illegal component: $SUB
641 [255]
642 $ ls -A "$FAKEHOME"
643 .hg
644 a
645 $ SUB="$FAKEHOME" hg -R main6 pull -u
646 pulling from $TESTTMP/envvarsym/main
647 searching for changes
648 adding changesets
649 adding manifests
650 adding file changes
651 added 1 changesets with 1 changes to 1 files
652 new changesets * (glob)
653 .hgsubstate: untracked file differs
654 abort: untracked files in working directory differ from files in requested revision
655 [20]
656 $ ls -A "$FAKEHOME"
657 .hg
658 a
659
660 on clone only symlink with hg-managed fakehome directory,
661 then pull (and update):
662
663 $ rm -fR "$FAKEHOME"
664 $ hg init "$FAKEHOME"
665 $ touch "$FAKEHOME/a"
666 $ hg -R "$FAKEHOME" ci -qAm 'add fakehome file'
667 $ SUB="$FAKEHOME" hg clone -qr0 main main7
668 $ ls -A "$FAKEHOME"
669 .hg
670 a
671 $ SUB="$FAKEHOME" hg -R main7 pull -uf
672 pulling from $TESTTMP/envvarsym/main
673 searching for changes
674 adding changesets
675 adding manifests
676 adding file changes
677 added 2 changesets with 3 changes to 2 files
678 new changesets * (glob)
679 abort: subrepo path contains illegal component: $SUB
680 [255]
681 $ ls -A "$FAKEHOME"
682 .hg
683 a
684
685 $ cd ..
686
687 #endif
688
689 Test drive letter
690 -----------------
691
692 Windows has a weird relative path that can change the drive letter, which
693 should also be prohibited on Windows.
694
695 prepare tampered repo:
696
697 $ hg init driveletter
698 $ cd driveletter
699 $ hg import --bypass -qm 'add subrepo "X:"' - <<'EOF'
700 > diff --git a/.hgsub b/.hgsub
701 > new file mode 100644
702 > --- /dev/null
703 > +++ b/.hgsub
704 > @@ -0,0 +1,1 @@
705 > +X: = foo
706 > diff --git a/.hgsubstate b/.hgsubstate
707 > new file mode 100644
708 > --- /dev/null
709 > +++ b/.hgsubstate
710 > @@ -0,0 +1,1 @@
711 > +0000000000000000000000000000000000000000 X:
712 > EOF
713 $ cd ..
714
715 on clone (and update):
716
717 #if windows
718
719 $ hg clone -q driveletter driveletter2
720 abort: path contains illegal component: X:
721 [10]
722
723 #else
724
725 $ hg clone -q driveletter driveletter2
726 $ ls -A driveletter2
727 .hg
728 .hgsub
729 .hgsubstate
730 X:
731
732 #endif