Debian Codegraph @

tests/test-subrepo-svn.t

raw
1 #require svn15
2
3 $ SVNREPOPATH=`pwd`/svn-repo
4 $ SVNREPOURL="`"$PYTHON" $TESTDIR/svnurlof.py \"$SVNREPOPATH\"`"
5
6 $ filter_svn_output () {
7 > grep -E -v 'Committing|Transmitting|Updating|(^$)' || true
8 > }
9
10 create subversion repo
11
12 $ WCROOT="`pwd`/svn-wc"
13 $ svnadmin create svn-repo
14 $ svn co "$SVNREPOURL" svn-wc
15 Checked out revision 0.
16 $ cd svn-wc
17 $ mkdir src
18 $ echo alpha > src/alpha
19 $ svn add src
20 A src
21 A src/alpha
22 $ mkdir externals
23 $ echo other > externals/other
24 $ svn add externals
25 A externals
26 A externals/other
27 $ svn ci -qm 'Add alpha'
28 $ svn up -q
29 $ echo "externals -r1 $SVNREPOURL/externals" > extdef
30 $ svn propset -F extdef svn:externals src
31 property 'svn:externals' set on 'src'
32 $ svn ci -qm 'Setting externals'
33 $ cd ..
34
35 create hg repo
36
37 $ mkdir sub
38 $ cd sub
39 $ hg init t
40 $ cd t
41
42 first revision, no sub
43
44 $ echo a > a
45 $ hg ci -Am0
46 adding a
47
48 add first svn sub with leading whitespaces
49
50 $ echo "s = [svn] $SVNREPOURL/src" >> .hgsub
51 $ echo "subdir/s = [svn] $SVNREPOURL/src" >> .hgsub
52 $ svn co --quiet "$SVNREPOURL"/src s
53 $ mkdir subdir
54 $ svn co --quiet "$SVNREPOURL"/src subdir/s
55 $ hg add .hgsub
56
57 svn subrepo is disabled by default
58
59 $ hg ci -m1
60 abort: svn subrepos not allowed
61 (see 'hg help config.subrepos' for details)
62 [255]
63
64 so enable it
65
66 $ cat >> $HGRCPATH <<EOF
67 > [subrepos]
68 > svn:allowed = true
69 > EOF
70
71 $ hg ci -m1
72
73 make sure we avoid empty commits (issue2445)
74
75 $ hg sum
76 parent: 1:* tip (glob)
77 1
78 branch: default
79 commit: (clean)
80 update: (current)
81 phases: 2 draft
82 $ hg ci -moops
83 nothing changed
84 [1]
85
86 debugsub
87
88 $ hg debugsub
89 path s
90 source file:/*/svn-repo/src (glob) (windows !)
91 source file:/*/$TESTTMP/svn-repo/src (glob) (no-windows !)
92 revision 2
93 path subdir/s
94 source file:/*/svn-repo/src (glob) (windows !)
95 source file:/*/$TESTTMP/svn-repo/src (glob) (no-windows !)
96 revision 2
97
98 change file in svn and hg, commit
99
100 $ echo a >> a
101 $ echo alpha >> s/alpha
102 $ hg sum
103 parent: 1:* tip (glob)
104 1
105 branch: default
106 commit: 1 modified, 1 subrepos
107 update: (current)
108 phases: 2 draft
109 $ hg commit --subrepos -m 'Message!' | filter_svn_output
110 committing subrepository s
111 Sending*s/alpha (glob)
112 Committed revision 3.
113 Fetching external item into '*s/externals'* (glob)
114 External at revision 1.
115 At revision 3.
116 $ hg debugsub
117 path s
118 source file:/*/svn-repo/src (glob) (windows !)
119 source file:/*/$TESTTMP/svn-repo/src (glob) (no-windows !)
120 revision 3
121 path subdir/s
122 source file:/*/svn-repo/src (glob) (windows !)
123 source file:/*/$TESTTMP/svn-repo/src (glob) (no-windows !)
124 revision 2
125
126 missing svn file, commit should fail
127
128 $ rm s/alpha
129 $ hg commit --subrepos -m 'abort on missing file'
130 committing subrepository s
131 abort: cannot commit missing svn entries (in subrepository "s")
132 [255]
133 $ svn revert s/alpha > /dev/null
134
135 add an unrelated revision in svn and update the subrepo to without
136 bringing any changes.
137
138 $ svn mkdir "$SVNREPOURL/unrelated" -qm 'create unrelated'
139 $ svn up -q s
140 $ hg sum
141 parent: 2:* tip (glob)
142 Message!
143 branch: default
144 commit: (clean)
145 update: (current)
146 phases: 3 draft
147
148 $ echo a > s/a
149
150 should be empty despite change to s/a
151
152 $ hg st
153
154 add a commit from svn
155
156 $ cd "$WCROOT/src"
157 $ svn up -q
158 $ echo xyz >> alpha
159 $ svn propset svn:mime-type 'text/xml' alpha
160 property 'svn:mime-type' set on 'alpha'
161 $ svn ci -qm 'amend a from svn'
162 $ cd ../../sub/t
163
164 this commit from hg will fail
165
166 $ echo zzz >> s/alpha
167 $ (hg ci --subrepos -m 'amend alpha from hg' 2>&1; echo "[$?]") | grep -vi 'out of date'
168 committing subrepository s
169 abort: svn:*Commit failed (details follow): (glob)
170 [255]
171 $ svn revert -q s/alpha
172
173 this commit fails because of meta changes
174
175 $ svn propset svn:mime-type 'text/html' s/alpha
176 property 'svn:mime-type' set on 's/alpha'
177 $ (hg ci --subrepos -m 'amend alpha from hg' 2>&1; echo "[$?]") | grep -vi 'out of date'
178 committing subrepository s
179 abort: svn:*Commit failed (details follow): (glob)
180 [255]
181 $ svn revert -q s/alpha
182
183 this commit fails because of externals changes
184
185 $ echo zzz > s/externals/other
186 $ hg ci --subrepos -m 'amend externals from hg'
187 committing subrepository s
188 abort: cannot commit svn externals (in subrepository "s")
189 [255]
190 $ hg diff --subrepos -r 1:2 | grep -v diff
191 --- a/.hgsubstate Thu Jan 01 00:00:00 1970 +0000
192 +++ b/.hgsubstate Thu Jan 01 00:00:00 1970 +0000
193 @@ -1,2 +1,2 @@
194 -2 s
195 +3 s
196 2 subdir/s
197 --- a/a Thu Jan 01 00:00:00 1970 +0000
198 +++ b/a Thu Jan 01 00:00:00 1970 +0000
199 @@ -1,1 +1,2 @@
200 a
201 +a
202 $ svn revert -q s/externals/other
203
204 this commit fails because of externals meta changes
205
206 $ svn propset svn:mime-type 'text/html' s/externals/other
207 property 'svn:mime-type' set on 's/externals/other'
208 $ hg ci --subrepos -m 'amend externals from hg'
209 committing subrepository s
210 abort: cannot commit svn externals (in subrepository "s")
211 [255]
212 $ svn revert -q s/externals/other
213
214 clone
215
216 $ cd ..
217 $ hg clone t tc
218 updating to branch default
219 A tc/s/alpha
220 U tc/s
221
222 Fetching external item into 'tc/s/externals'* (glob)
223 A tc/s/externals/other
224 Checked out external at revision 1.
225
226 Checked out revision 3.
227 A tc/subdir/s/alpha
228 U tc/subdir/s
229
230 Fetching external item into 'tc/subdir/s/externals'* (glob)
231 A tc/subdir/s/externals/other
232 Checked out external at revision 1.
233
234 Checked out revision 2.
235 3 files updated, 0 files merged, 0 files removed, 0 files unresolved
236 $ cd tc
237
238 debugsub in clone
239
240 $ hg debugsub
241 path s
242 source file:/*/svn-repo/src (glob) (windows !)
243 source file:/*/$TESTTMP/svn-repo/src (glob) (no-windows !)
244 revision 3
245 path subdir/s
246 source file:/*/svn-repo/src (glob) (windows !)
247 source file:/*/$TESTTMP/svn-repo/src (glob) (no-windows !)
248 revision 2
249
250 verify subrepo is contained within the repo directory
251
252 $ "$PYTHON" -c "import os.path; print(os.path.exists('s'))"
253 True
254
255 update to nullrev (must delete the subrepo)
256
257 $ hg up null
258 0 files updated, 0 files merged, 3 files removed, 0 files unresolved
259 $ ls
260
261 Check hg update --clean
262 $ cd "$TESTTMP/sub/t"
263 $ cd s
264 $ echo c0 > alpha
265 $ echo c1 > f1
266 $ echo c1 > f2
267 $ svn add f1 -q
268 $ svn status | sort
269
270 ? * a (glob)
271 ? * f2 (glob)
272 A * f1 (glob)
273 M * alpha (glob)
274 Performing status on external item at 'externals'* (glob)
275 X * externals (glob)
276 $ cd ../..
277 $ hg -R t update -C
278
279 Fetching external item into 't/s/externals'* (glob)
280 Checked out external at revision 1.
281
282 Checked out revision 3.
283 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
284 $ cd t/s
285 $ svn status | sort
286
287 ? * a (glob)
288 ? * f1 (glob)
289 ? * f2 (glob)
290 Performing status on external item at 'externals'* (glob)
291 X * externals (glob)
292
293 Sticky subrepositories, no changes
294 $ cd "$TESTTMP/sub/t"
295 $ hg id -n
296 2
297 $ cd s
298 $ svnversion
299 3
300 $ cd ..
301 $ hg update 1
302 U *s/alpha (glob)
303
304 Fetching external item into '*s/externals'* (glob)
305 Checked out external at revision 1.
306
307 Checked out revision 2.
308 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
309 $ hg id -n
310 1
311 $ cd s
312 $ svnversion
313 2
314 $ cd ..
315
316 Sticky subrepositories, file changes
317 $ touch s/f1
318 $ cd s
319 $ svn add f1
320 A f1
321 $ cd ..
322 $ hg id -n
323 1+
324 $ cd s
325 $ svnversion
326 2M
327 $ cd ..
328 $ hg update tip
329 subrepository s diverged (local revision: 2, remote revision: 3)
330 you can (m)erge, keep (l)ocal [working copy] or keep (r)emote [destination].
331 what do you want to do? m
332 subrepository sources for s differ
333 you can use (l)ocal source (2) or (r)emote source (3).
334 what do you want to do? l
335 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
336 $ hg id -n
337 2+
338 $ cd s
339 $ svnversion
340 2M
341 $ cd ..
342 $ hg update --clean tip
343 U *s/alpha (glob)
344
345 Fetching external item into '*s/externals'* (glob)
346 Checked out external at revision 1.
347
348 Checked out revision 3.
349 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
350
351 Sticky subrepository, revision updates
352 $ hg id -n
353 2
354 $ cd s
355 $ svnversion
356 3
357 $ cd ..
358 $ cd s
359 $ svn update -qr 1
360 $ cd ..
361 $ hg update 1
362 subrepository s diverged (local revision: 3, remote revision: 2)
363 you can (m)erge, keep (l)ocal [working copy] or keep (r)emote [destination].
364 what do you want to do? m
365 subrepository sources for s differ (in checked out version)
366 you can use (l)ocal source (1) or (r)emote source (2).
367 what do you want to do? l
368 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
369 $ hg id -n
370 1+
371 $ cd s
372 $ svnversion
373 1
374 $ cd ..
375
376 Sticky subrepository, file changes and revision updates
377 $ touch s/f1
378 $ cd s
379 $ svn add f1
380 A f1
381 $ svnversion
382 1M
383 $ cd ..
384 $ hg id -n
385 1+
386 $ hg update tip
387 subrepository s diverged (local revision: 3, remote revision: 3)
388 you can (m)erge, keep (l)ocal [working copy] or keep (r)emote [destination].
389 what do you want to do? m
390 subrepository sources for s differ
391 you can use (l)ocal source (1) or (r)emote source (3).
392 what do you want to do? l
393 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
394 $ hg id -n
395 2+
396 $ cd s
397 $ svnversion
398 1M
399 $ cd ..
400
401 Sticky repository, update --clean
402 $ hg update --clean tip | grep -v 's[/\]externals[/\]other'
403 U *s/alpha (glob)
404 U *s (glob)
405
406 Fetching external item into '*s/externals'* (glob)
407 Checked out external at revision 1.
408
409 Checked out revision 3.
410 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
411 $ hg id -n
412 2
413 $ cd s
414 $ svnversion
415 3
416 $ cd ..
417
418 Test subrepo already at intended revision:
419 $ cd s
420 $ svn update -qr 2
421 $ cd ..
422 $ hg update 1
423 subrepository s diverged (local revision: 3, remote revision: 2)
424 you can (m)erge, keep (l)ocal [working copy] or keep (r)emote [destination].
425 what do you want to do? m
426 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
427 $ hg id -n
428 1+
429 $ cd s
430 $ svnversion
431 2
432 $ cd ..
433
434 Test case where subversion would fail to update the subrepo because there
435 are unknown directories being replaced by tracked ones (happens with rebase).
436
437 $ cd "$WCROOT/src"
438 $ mkdir dir
439 $ echo epsilon.py > dir/epsilon.py
440 $ svn add dir
441 A dir
442 A dir/epsilon.py
443 $ svn ci -qm 'Add dir/epsilon.py'
444 $ cd ../..
445 $ hg init rebaserepo
446 $ cd rebaserepo
447 $ svn co -r5 --quiet "$SVNREPOURL"/src s
448 $ echo "s = [svn] $SVNREPOURL/src" >> .hgsub
449 $ hg add .hgsub
450 $ hg ci -m addsub
451 $ echo a > a
452 $ hg add .
453 adding a
454 $ hg ci -m adda
455 $ hg up 0
456 0 files updated, 0 files merged, 1 files removed, 0 files unresolved
457 $ svn up -qr6 s
458 $ hg ci -m updatesub
459 created new head
460 $ echo pyc > s/dir/epsilon.pyc
461 $ hg up 1
462 D *s/dir (glob)
463
464 Fetching external item into '*s/externals'* (glob)
465 Checked out external at revision 1.
466
467 Checked out revision 5.
468 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
469 $ hg up -q 2
470
471 Modify one of the externals to point to a different path so we can
472 test having obstructions when switching branches on checkout:
473 $ hg checkout tip
474 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
475 $ echo "obstruct = [svn] $SVNREPOURL/externals" >> .hgsub
476 $ svn co -r5 --quiet "$SVNREPOURL"/externals obstruct
477 $ hg commit -m 'Start making obstructed working copy'
478 $ hg book other
479 $ hg co -r 'p1(tip)'
480 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
481 (leaving bookmark other)
482 $ echo "obstruct = [svn] $SVNREPOURL/src" >> .hgsub
483 $ svn co -r5 --quiet "$SVNREPOURL"/src obstruct
484 $ hg commit -m 'Other branch which will be obstructed'
485 created new head
486
487 Switching back to the head where we have another path mapped to the
488 same subrepo should work if the subrepo is clean.
489 $ hg co other
490 A *obstruct/other (glob)
491 Checked out revision 1.
492 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
493 (activating bookmark other)
494
495 This is surprising, but is also correct based on the current code:
496 $ echo "updating should (maybe) fail" > obstruct/other
497 $ hg co tip
498 abort: uncommitted changes
499 (commit or update --clean to discard changes)
500 [255]
501
502 Point to a Subversion branch which has since been deleted and recreated
503 First, create that condition in the repository.
504
505 $ hg ci --subrepos -m cleanup | filter_svn_output
506 committing subrepository obstruct
507 Sending obstruct/other
508 Committed revision 7.
509 At revision 7.
510 $ svn mkdir -qm "baseline" $SVNREPOURL/trunk
511 $ svn copy -qm "initial branch" $SVNREPOURL/trunk $SVNREPOURL/branch
512 $ svn co --quiet "$SVNREPOURL"/branch tempwc
513 $ cd tempwc
514 $ echo "something old" > somethingold
515 $ svn add somethingold
516 A somethingold
517 $ svn ci -qm 'Something old'
518 $ svn rm -qm "remove branch" $SVNREPOURL/branch
519 $ svn copy -qm "recreate branch" $SVNREPOURL/trunk $SVNREPOURL/branch
520 $ svn up -q
521 $ echo "something new" > somethingnew
522 $ svn add somethingnew
523 A somethingnew
524 $ svn ci -qm 'Something new'
525 $ cd ..
526 $ rm -rf tempwc
527 $ svn co "$SVNREPOURL/branch"@10 recreated
528 A recreated/somethingold
529 Checked out revision 10.
530 $ echo "recreated = [svn] $SVNREPOURL/branch" >> .hgsub
531 $ hg ci -m addsub
532 $ cd recreated
533 $ svn up -q
534 $ cd ..
535 $ hg ci -m updatesub
536 $ hg up -r-2
537 D *recreated/somethingnew (glob)
538 A *recreated/somethingold (glob)
539 Checked out revision 10.
540 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
541 (leaving bookmark other)
542 $ test -f recreated/somethingold
543
544 Test archive
545
546 $ hg archive -S ../archive-all --debug --config progress.debug=true
547 archiving: 0/2 files (0.00%)
548 archiving: .hgsub 1/2 files (50.00%)
549 archiving: .hgsubstate 2/2 files (100.00%)
550 archiving (obstruct): 0/1 files (0.00%)
551 archiving (obstruct): 1/1 files (100.00%)
552 archiving (recreated): 0/1 files (0.00%)
553 archiving (recreated): 1/1 files (100.00%)
554 archiving (s): 0/2 files (0.00%)
555 archiving (s): 1/2 files (50.00%)
556 archiving (s): 2/2 files (100.00%)
557
558 $ hg archive -S ../archive-exclude --debug --config progress.debug=true -X **old
559 archiving: 0/2 files (0.00%)
560 archiving: .hgsub 1/2 files (50.00%)
561 archiving: .hgsubstate 2/2 files (100.00%)
562 archiving (obstruct): 0/1 files (0.00%)
563 archiving (obstruct): 1/1 files (100.00%)
564 archiving (recreated): 0 files
565 archiving (s): 0/2 files (0.00%)
566 archiving (s): 1/2 files (50.00%)
567 archiving (s): 2/2 files (100.00%)
568 $ find ../archive-exclude | sort
569 ../archive-exclude
570 ../archive-exclude/.hg_archival.txt
571 ../archive-exclude/.hgsub
572 ../archive-exclude/.hgsubstate
573 ../archive-exclude/obstruct
574 ../archive-exclude/obstruct/other
575 ../archive-exclude/s
576 ../archive-exclude/s/alpha
577 ../archive-exclude/s/dir
578 ../archive-exclude/s/dir/epsilon.py
579
580 Test forgetting files, not implemented in svn subrepo, used to
581 traceback
582
583 $ hg forget 'notafile'
584 notafile: $ENOENT$
585 [1]
586
587 Test a subrepo referencing a just moved svn path. Last commit rev will
588 be different from the revision, and the path will be different as
589 well.
590
591 $ cd "$WCROOT"
592 $ svn up > /dev/null
593 $ mkdir trunk/subdir branches
594 $ echo foo > trunk/subdir/a
595 $ svn add trunk/subdir branches
596 A trunk/subdir
597 A trunk/subdir/a
598 A branches
599 $ svn ci -qm addsubdir
600 $ svn cp -qm branchtrunk $SVNREPOURL/trunk $SVNREPOURL/branches/somebranch
601 $ cd ..
602
603 $ hg init repo2
604 $ cd repo2
605 $ svn co $SVNREPOURL/branches/somebranch/subdir
606 A subdir/a
607 Checked out revision 15.
608 $ echo "subdir = [svn] $SVNREPOURL/branches/somebranch/subdir" > .hgsub
609 $ hg add .hgsub
610 $ hg ci -m addsub
611 $ hg up null
612 0 files updated, 0 files merged, 2 files removed, 0 files unresolved
613 $ hg up
614 A *subdir/a (glob)
615 Checked out revision 15.
616 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
617 $ cd ..
618
619 Test sanitizing ".hg/hgrc" in subrepo
620
621 $ cd sub/t
622 $ hg update -q -C tip
623 $ cd s
624 $ mkdir .hg
625 $ echo '.hg/hgrc in svn repo' > .hg/hgrc
626 $ mkdir -p sub/.hg
627 $ echo 'sub/.hg/hgrc in svn repo' > sub/.hg/hgrc
628 $ svn add .hg sub
629 A .hg
630 A .hg/hgrc
631 A sub
632 A sub/.hg
633 A sub/.hg/hgrc
634 $ svn ci -qm 'add .hg/hgrc to be sanitized at hg update'
635 $ svn up -q
636 $ cd ..
637 $ hg commit -S -m 'commit with svn revision including .hg/hgrc'
638 $ grep ' s$' .hgsubstate
639 16 s
640 $ cd ..
641
642 $ hg -R tc pull -u -q 2>&1 | sort
643 warning: removing potentially hostile 'hgrc' in '$TESTTMP/sub/tc/s/.hg'
644 warning: removing potentially hostile 'hgrc' in '$TESTTMP/sub/tc/s/sub/.hg'
645 $ cd tc
646 $ grep ' s$' .hgsubstate
647 16 s
648 $ test -f s/.hg/hgrc
649 [1]
650 $ test -f s/sub/.hg/hgrc
651 [1]
652
653 Test that sanitizing is omitted in meta data area:
654
655 $ mkdir s/.svn/.hg
656 $ echo '.hg/hgrc in svn metadata area' > s/.svn/.hg/hgrc
657 $ hg update -q -C '.^1'
658
659 $ cd ../..
660
661 SEC: test for ssh exploit
662
663 $ hg init ssh-vuln
664 $ cd ssh-vuln
665 $ echo "s = [svn]$SVNREPOURL/src" >> .hgsub
666 $ svn co --quiet "$SVNREPOURL"/src s
667 $ hg add .hgsub
668 $ hg ci -m1
669 $ echo "s = [svn]svn+ssh://-oProxyCommand=touch%20owned%20nested" > .hgsub
670 $ hg ci -m2
671 $ cd ..
672 $ hg clone ssh-vuln ssh-vuln-clone
673 updating to branch default
674 abort: potentially unsafe url: 'svn+ssh://-oProxyCommand=touch owned nested' (in subrepository "s")
675 [255]
676
677 also check that a percent encoded '-' (%2D) doesn't work
678
679 $ cd ssh-vuln
680 $ echo "s = [svn]svn+ssh://%2DoProxyCommand=touch%20owned%20nested" > .hgsub
681 $ hg ci -m3
682 $ cd ..
683 $ rm -r ssh-vuln-clone
684 $ hg clone ssh-vuln ssh-vuln-clone
685 updating to branch default
686 abort: potentially unsafe url: 'svn+ssh://-oProxyCommand=touch owned nested' (in subrepository "s")
687 [255]
688
689 also check that hiding the attack in the username doesn't work:
690
691 $ cd ssh-vuln
692 $ echo "s = [svn]svn+ssh://%2DoProxyCommand=touch%20owned%[email protected]/nested" > .hgsub
693 $ hg ci -m3
694 $ cd ..
695 $ rm -r ssh-vuln-clone
696 $ hg clone ssh-vuln ssh-vuln-clone
697 updating to branch default
698 abort: potentially unsafe url: 'svn+ssh://-oProxyCommand=touch owned [email protected]/nested' (in subrepository "s")
699 [255]