1
# -*- encoding: utf-8 -*-
3
# Copyright (C) 2006, 2007 Canonical Ltd
5
# This program is free software; you can redistribute it and/or modify
6
# it under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 2 of the License, or
8
# (at your option) any later version.
10
# This program is distributed in the hope that it will be useful,
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
15
# You should have received a copy of the GNU General Public License
16
# along with this program; if not, write to the Free Software
17
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
"""Tests for the info command of bzr."""
32
from bzrlib.tests import blackbox
36
class TestInfoXml(blackbox.ExternalBase):
38
def test_should_normalize_non_ascii_url(self):
39
# we disable isolation because the error we want to catch is triggered
41
self.disable_directory_isolation()
42
root = '/C:' if sys.platform == 'win32' else ''
43
url = u'file://%s/Maçã/does/not/exist' % root
44
out, err = self.run_bzr(['xmlinfo', url], retcode=3)
45
from bzrlib.urlutils import normalize_url
46
nurl = normalize_url(url)
48
'<?xml version="1.0" encoding="%s"?>'
49
'<error><class>NotBranchError</class><dict><key>path</key>'
50
'<value>%s/</value><key>extra</key><value></value>'
51
'<key>detail</key><value></value></dict>'
52
'<message>Not a branch: "%s/".</message>'
53
'</error>' % (osutils.get_user_encoding(), nurl, nurl), err)
55
def test_info_non_existing(self):
56
# we disable isolation because the error we want to catch is triggered
58
self.disable_directory_isolation()
59
if sys.platform == "win32":
60
location = "C:/i/do/not/exist/"
62
location = "/i/do/not/exist/"
63
out, err = self.run_bzr('xmlinfo '+location, retcode=3)
64
self.assertEqual(out, '')
66
'<?xml version="1.0" encoding="%s"?><error>'
67
'<class>NotBranchError</class><dict><key>path</key><value>'
68
'%s</value><key>extra</key><value></value>'
69
'<key>detail</key><value></value></dict>'
70
'<message>Not a branch: "%s".</message>'
71
'</error>' % (osutils.get_user_encoding(),
72
location, location), err)
74
def test_info_standalone(self):
75
transport = self.get_transport()
77
# Create initial standalone branch
78
tree1 = self.make_branch_and_tree('standalone', 'weave')
79
self.build_tree(['standalone/a'])
81
branch1 = tree1.branch
83
out, err = self.run_bzr('xmlinfo standalone')
84
expected_xml = '''<?xml version="1.0"?>
86
<layout>Standalone tree</layout>
88
<format>weave</format>
91
<branch_root>standalone</branch_root></location>
95
expected_xml = ''.join(expected_xml.split('\n'))+'\n'
96
self.assertEqualDiff(expected_xml, out)
97
self.assertEqual('', err)
99
out, err = self.run_bzr('xmlinfo standalone -v')
100
expected_xml = '''<?xml version="1.0"?>
102
<layout>Standalone tree</layout>
104
<format>weave</format>
107
<branch_root>standalone</branch_root></location>
109
<control>All-in-one format 6</control>
110
<working_tree>Working tree format 2</working_tree>
111
<branch>Branch format 4</branch>
112
<repository>Weave repository format 6</repository>
115
<unchanged>0</unchanged>
116
<modified>0</modified>
122
<versioned_subdirectories>0</versioned_subdirectories>
123
</working_tree_stats>
125
<revisions>0</revisions>
126
<committers>0</committers>
129
<revisions>0</revisions>
134
expected_xml = ''.join(expected_xml.split('\n'))+'\n'
135
self.assertEqualDiff(expected_xml, out)
136
self.assertEqual('', err)
137
tree1.commit('commit one')
138
rev = branch1.repository.get_revision(branch1.revision_history()[0])
139
datestring_first = osutils.format_date(rev.timestamp, rev.timezone)
141
# Branch standalone with push location
142
branch2 = branch1.bzrdir.sprout('branch').open_branch()
143
branch2.set_push_location(branch1.bzrdir.root_transport.base)
145
out, err = self.run_bzr('xmlinfo branch')
146
expected_xml = '''<?xml version="1.0"?>
148
<layout>Standalone tree</layout>
150
<format>weave</format>
153
<branch_root>branch</branch_root></location>
155
<push_branch>standalone</push_branch><parent_branch>standalone</parent_branch></related_branches>
159
expected_xml = ''.join(expected_xml.split('\n'))+'\n'
160
self.assertEqualDiff(expected_xml, out)
161
self.assertEqual('', err)
163
out, err = self.run_bzr('xmlinfo branch --verbose')
164
expected_xml = '''<?xml version="1.0"?>
166
<layout>Standalone tree</layout>
168
<format>weave</format>
171
<branch_root>branch</branch_root></location>
173
<push_branch>standalone</push_branch><parent_branch>standalone</parent_branch></related_branches>
175
<control>All-in-one format 6</control>
176
<working_tree>Working tree format 2</working_tree>
177
<branch>Branch format 4</branch>
178
<repository>Weave repository format 6</repository>
181
<unchanged>1</unchanged>
182
<modified>0</modified>
188
<versioned_subdirectories>0</versioned_subdirectories>
189
</working_tree_stats>
191
<revisions>1</revisions>
192
<committers>1</committers>
193
<days_old>0</days_old>
194
<first_revision>%s</first_revision>
195
<latest_revision>%s</latest_revision>
198
<revisions>1</revisions>
202
''' % (datestring_first, datestring_first,
204
expected_xml = ''.join(expected_xml.split('\n'))+'\n'
205
self.assertEqualDiff(expected_xml, out)
206
self.assertEqual('', err)
208
# Branch and bind to standalone, needs upgrade to metadir
209
# (creates backup as unknown)
210
branch1.bzrdir.sprout('bound')
211
knit1_format = bzrdir.format_registry.make_bzrdir('knit')
212
bzrlib.upgrade.upgrade('bound', knit1_format)
213
branch3 = bzrlib.bzrdir.BzrDir.open('bound').open_branch()
214
branch3.bind(branch1)
215
bound_tree = branch3.bzrdir.open_workingtree()
216
out, err = self.run_bzr('xmlinfo -v bound')
217
expected_xml = '''<?xml version="1.0"?>
219
<layout>Checkout</layout>
221
<format>knit</format>
224
<checkout_root>bound</checkout_root><checkout_of_branch>standalone</checkout_of_branch></location>
226
<parent_branch>standalone</parent_branch></related_branches>
228
<control>Meta directory format 1</control>
229
<working_tree>%s</working_tree>
231
<repository>%s</repository>
234
<unchanged>1</unchanged>
235
<modified>0</modified>
241
<versioned_subdirectories>0</versioned_subdirectories>
242
</working_tree_stats>
244
<revisions>1</revisions>
245
<committers>1</committers>
246
<days_old>0</days_old>
247
<first_revision>%s</first_revision>
248
<latest_revision>%s</latest_revision>
251
<revisions>1</revisions>
255
''' % (bound_tree._format.get_format_description(),
256
branch3._format.get_format_description(),
257
branch3.repository._format.get_format_description(),
258
datestring_first, datestring_first,
260
expected_xml = ''.join(expected_xml.split('\n'))+'\n'
261
self.assertEqualDiff(expected_xml, out)
262
self.assertEqual('', err)
264
# Checkout standalone (same as above, but does not have parent set)
265
branch4 = bzrlib.bzrdir.BzrDir.create_branch_convenience('checkout',
267
branch4.bind(branch1)
268
branch4.bzrdir.open_workingtree().update()
269
out, err = self.run_bzr('xmlinfo checkout --verbose')
270
expected_xml = '''<?xml version="1.0"?>
272
<layout>Checkout</layout>
274
<format>knit</format>
277
<checkout_root>checkout</checkout_root><checkout_of_branch>standalone</checkout_of_branch></location>
279
<control>Meta directory format 1</control>
280
<working_tree>Working tree format 3</working_tree>
281
<branch>Branch format 5</branch>
282
<repository>%s</repository>
285
<unchanged>1</unchanged>
286
<modified>0</modified>
292
<versioned_subdirectories>0</versioned_subdirectories>
293
</working_tree_stats>
295
<revisions>1</revisions>
296
<committers>1</committers>
297
<days_old>0</days_old>
298
<first_revision>%s</first_revision>
299
<latest_revision>%s</latest_revision>
302
<revisions>1</revisions>
306
''' % (branch4.repository._format.get_format_description(),
307
datestring_first, datestring_first,
309
expected_xml = ''.join(expected_xml.split('\n'))+'\n'
310
self.assertEqualDiff(expected_xml , out)
311
self.assertEqual('', err)
313
# Lightweight checkout (same as above, different branch and repository)
314
tree5 = branch1.create_checkout('lightcheckout', lightweight=True)
315
branch5 = tree5.branch
316
out, err = self.run_bzr('xmlinfo -v lightcheckout')
317
expected_xml = '''<?xml version="1.0"?>
319
<layout>Lightweight checkout</layout>
324
<light_checkout_root>lightcheckout</light_checkout_root><checkout_of_branch>standalone</checkout_of_branch></location>
326
<control>Meta directory format 1</control>
327
<working_tree>Working tree format 6</working_tree>
328
<branch>Branch format 4</branch>
329
<repository>Weave repository format 6</repository>
332
<unchanged>1</unchanged>
333
<modified>0</modified>
339
<versioned_subdirectories>0</versioned_subdirectories>
340
</working_tree_stats>
342
<revisions>1</revisions>
343
<committers>1</committers>
344
<days_old>0</days_old>
345
<first_revision>%s</first_revision>
346
<latest_revision>%s</latest_revision>
349
<revisions>1</revisions>
353
''' % (datestring_first, datestring_first)
354
expected_xml = ''.join(expected_xml.split('\n'))+'\n'
355
self.assertEqualDiff(expected_xml, out)
356
self.assertEqual('', err)
358
# Update initial standalone branch
359
self.build_tree(['standalone/b'])
361
tree1.commit('commit two')
362
rev = branch1.repository.get_revision(branch1.last_revision())
363
datestring_last = osutils.format_date(rev.timestamp, rev.timezone)
365
# Out of date branched standalone branch will not be detected
366
out, err = self.run_bzr('xmlinfo -v branch')
367
expected_xml = '''<?xml version="1.0"?>
369
<layout>Standalone tree</layout>
371
<format>weave</format>
374
<branch_root>branch</branch_root></location>
376
<push_branch>standalone</push_branch><parent_branch>standalone</parent_branch></related_branches>
378
<control>All-in-one format 6</control>
379
<working_tree>Working tree format 2</working_tree>
380
<branch>Branch format 4</branch>
381
<repository>Weave repository format 6</repository>
384
<unchanged>1</unchanged>
385
<modified>0</modified>
391
<versioned_subdirectories>0</versioned_subdirectories>
392
</working_tree_stats>
394
<revisions>1</revisions>
395
<committers>1</committers>
396
<days_old>0</days_old>
397
<first_revision>%s</first_revision>
398
<latest_revision>%s</latest_revision>
401
<revisions>1</revisions>
405
''' % (datestring_first, datestring_first,)
406
expected_xml = ''.join(expected_xml.split('\n'))+'\n'
407
self.assertEqualDiff(expected_xml, out)
408
self.assertEqual('', err)
410
# Out of date bound branch
411
out, err = self.run_bzr('xmlinfo -v bound')
412
expected_xml = '''<?xml version="1.0"?>
414
<layout>Checkout</layout>
416
<format>knit</format>
419
<checkout_root>bound</checkout_root><checkout_of_branch>standalone</checkout_of_branch></location>
421
<parent_branch>standalone</parent_branch></related_branches>
423
<control>Meta directory format 1</control>
424
<working_tree>Working tree format 3</working_tree>
425
<branch>Branch format 5</branch>
426
<repository>%s</repository>
429
<missing_revisions>1<missing_revisions>
432
<unchanged>1</unchanged>
433
<modified>0</modified>
439
<versioned_subdirectories>0</versioned_subdirectories>
440
</working_tree_stats>
442
<revisions>1</revisions>
443
<committers>1</committers>
444
<days_old>0</days_old>
445
<first_revision>%s</first_revision>
446
<latest_revision>%s</latest_revision>
449
<revisions>1</revisions>
453
''' % (branch3.repository._format.get_format_description(),
454
datestring_first, datestring_first,
456
expected_xml = ''.join(expected_xml.split('\n'))+'\n'
457
self.assertEqualDiff(expected_xml, out)
458
self.assertEqual('', err)
460
# Out of date checkout
461
out, err = self.run_bzr('xmlinfo -v checkout')
462
expected_xml = '''<?xml version="1.0"?>
464
<layout>Checkout</layout>
466
<format>knit</format>
469
<checkout_root>checkout</checkout_root><checkout_of_branch>standalone</checkout_of_branch></location>
471
<control>Meta directory format 1</control>
472
<working_tree>Working tree format 3</working_tree>
473
<branch>Branch format 5</branch>
474
<repository>%s</repository>
477
<missing_revisions>1<missing_revisions>
480
<unchanged>1</unchanged>
481
<modified>0</modified>
487
<versioned_subdirectories>0</versioned_subdirectories>
488
</working_tree_stats>
490
<revisions>1</revisions>
491
<committers>1</committers>
492
<days_old>0</days_old>
493
<first_revision>%s</first_revision>
494
<latest_revision>%s</latest_revision>
497
<revisions>1</revisions>
501
''' % (branch4.repository._format.get_format_description(),
502
datestring_first, datestring_first,
504
expected_xml = ''.join(expected_xml.split('\n'))+'\n'
505
self.assertEqualDiff(expected_xml, out)
506
self.assertEqual('', err)
508
# Out of date lightweight checkout
509
out, err = self.run_bzr('xmlinfo lightcheckout --verbose')
510
expected_xml = '''<?xml version="1.0"?>
512
<layout>Lightweight checkout</layout>
517
<light_checkout_root>lightcheckout</light_checkout_root><checkout_of_branch>standalone</checkout_of_branch></location>
519
<control>Meta directory format 1</control>
520
<working_tree>Working tree format 6</working_tree>
521
<branch>Branch format 4</branch>
522
<repository>Weave repository format 6</repository>
525
<missing_revisions>1</missing_revisions>
526
<unchanged>1</unchanged>
527
<modified>0</modified>
533
<versioned_subdirectories>0</versioned_subdirectories>
534
</working_tree_stats>
536
<revisions>2</revisions>
537
<committers>1</committers>
538
<days_old>0</days_old>
539
<first_revision>%s</first_revision>
540
<latest_revision>%s</latest_revision>
543
<revisions>2</revisions>
547
''' % (datestring_first, datestring_last,)
548
expected_xml = ''.join(expected_xml.split('\n'))+'\n'
549
self.assertEqualDiff(expected_xml, out)
550
self.assertEqual('', err)
552
def test_info_standalone_no_tree(self):
553
# create standalone branch without a working tree
554
format = bzrdir.format_registry.make_bzrdir('default')
555
branch = self.make_branch('branch')
556
repo = branch.repository
557
out, err = self.run_bzr('xmlinfo branch -v')
558
expected_xml = '''<?xml version="1.0"?>
560
<layout>Standalone branch</layout>
565
<branch_root>branch</branch_root></location>
567
<control>Meta directory format 1</control>
569
<repository>%s</repository>
572
<revisions>0</revisions>
573
<committers>0</committers>
576
<revisions>0</revisions>
580
''' % (format.get_branch_format().get_format_description(),
581
format.repository_format.get_format_description(),
583
expected_xml = ''.join(expected_xml.split('\n'))+'\n'
584
self.assertEqualDiff(expected_xml, out)
585
self.assertEqual('', err)
587
def test_info_shared_repository(self):
588
format = bzrdir.format_registry.make_bzrdir('knit')
589
transport = self.get_transport()
591
# Create shared repository
592
repo = self.make_repository('repo', shared=True, format=format)
593
repo.set_make_working_trees(False)
594
out, err = self.run_bzr('xmlinfo -v repo')
595
expected_xml = '''<?xml version="1.0"?>
597
<layout>Shared repository</layout>
599
<format>dirstate</format>
600
<format>dirstate-tags</format>
601
<format>knit</format>
604
<shared_repository>%s</shared_repository></location>
606
<control>Meta directory format 1</control>
607
<repository>%s</repository>
610
<revisions>0</revisions>
614
''' % ('repo', format.repository_format.get_format_description(),
616
expected_xml = ''.join(expected_xml.split('\n'))+'\n'
617
self.assertEqualDiff(expected_xml, out)
618
self.assertEqual('', err)
620
# Create branch inside shared repository
621
repo.bzrdir.root_transport.mkdir('branch')
622
branch1 = bzrdir.BzrDir.create_branch_convenience('repo/branch',
624
out, err = self.run_bzr('xmlinfo -v repo/branch')
625
expected_xml = '''<?xml version="1.0"?>
627
<layout>Repository branch</layout>
629
<format>dirstate</format>
630
<format>knit</format>
633
<shared_repository>repo</shared_repository><repository_branch>repo/branch</repository_branch></location>
635
<control>Meta directory format 1</control>
637
<repository>%s</repository>
640
<revisions>0</revisions>
641
<committers>0</committers>
644
<revisions>0</revisions>
648
''' % (format.get_branch_format().get_format_description(),
649
format.repository_format.get_format_description(),
651
expected_xml = ''.join(expected_xml.split('\n'))+'\n'
652
self.assertEqualDiff(expected_xml, out)
653
self.assertEqual('', err)
655
# Create lightweight checkout
656
transport.mkdir('tree')
657
transport.mkdir('tree/lightcheckout')
658
tree2 = branch1.create_checkout('tree/lightcheckout',
660
branch2 = tree2.branch
661
self.assertCheckoutStatusOutput('-v tree/lightcheckout', tree2,
662
shared_repo=repo, repo_branch=branch1, verbose=True)
664
# Create normal checkout
665
tree3 = branch1.create_checkout('tree/checkout')
666
self.assertCheckoutStatusOutput('tree/checkout --verbose', tree3,
668
light_checkout=False, repo_branch=branch1)
669
# Update lightweight checkout
670
self.build_tree(['tree/lightcheckout/a'])
672
tree2.commit('commit one')
673
rev = repo.get_revision(branch2.revision_history()[0])
674
datestring_first = osutils.format_date(rev.timestamp, rev.timezone)
675
out, err = self.run_bzr('xmlinfo tree/lightcheckout --verbose')
676
expected_xml = '''<?xml version="1.0"?>
678
<layout>Lightweight checkout</layout>
683
<light_checkout_root>tree/lightcheckout</light_checkout_root><checkout_of_branch>repo/branch</checkout_of_branch><shared_repository>repo</shared_repository></location>
685
<control>Meta directory format 1</control>
686
<working_tree>Working tree format 6</working_tree>
688
<repository>%s</repository>
691
<unchanged>1</unchanged>
692
<modified>0</modified>
698
<versioned_subdirectories>0</versioned_subdirectories>
699
</working_tree_stats>
701
<revisions>1</revisions>
702
<committers>1</committers>
703
<days_old>0</days_old>
704
<first_revision>%s</first_revision>
705
<latest_revision>%s</latest_revision>
708
<revisions>1</revisions>
712
''' % (format.get_branch_format().get_format_description(),
713
format.repository_format.get_format_description(),
714
datestring_first, datestring_first,
716
expected_xml = ''.join(expected_xml.split('\n'))+'\n'
717
self.assertEqualDiff(expected_xml, out)
718
self.assertEqual('', err)
720
# Out of date checkout
721
out, err = self.run_bzr('xmlinfo -v tree/checkout')
722
expected_xml = '''<?xml version="1.0"?>
724
<layout>Checkout</layout>
726
<format>unnamed</format>
729
<checkout_root>tree/checkout</checkout_root><checkout_of_branch>repo/branch</checkout_of_branch></location>
731
<control>Meta directory format 1</control>
732
<working_tree>Working tree format 6</working_tree>
734
<repository>%s</repository>
737
<missing_revisions>1<missing_revisions>
740
<unchanged>0</unchanged>
741
<modified>0</modified>
747
<versioned_subdirectories>0</versioned_subdirectories>
748
</working_tree_stats>
750
<revisions>0</revisions>
751
<committers>0</committers>
754
<revisions>0</revisions>
758
''' % (format.get_branch_format().get_format_description(),
759
format.repository_format.get_format_description(),
761
expected_xml = ''.join(expected_xml.split('\n'))+'\n'
762
self.assertEqualDiff(expected_xml, out)
763
self.assertEqual('', err)
767
self.build_tree(['tree/checkout/b'])
769
out, err = self.run_bzr('xmlinfo tree/checkout --verbose')
770
expected_xml = '''<?xml version="1.0"?>
772
<layout>Checkout</layout>
774
<format>unnamed</format>
777
<checkout_root>tree/checkout</checkout_root><checkout_of_branch>repo/branch</checkout_of_branch></location>
779
<control>Meta directory format 1</control>
780
<working_tree>Working tree format 6</working_tree>
782
<repository>%s</repository>
785
<unchanged>1</unchanged>
786
<modified>0</modified>
792
<versioned_subdirectories>0</versioned_subdirectories>
793
</working_tree_stats>
795
<revisions>1</revisions>
796
<committers>1</committers>
797
<days_old>0</days_old>
798
<first_revision>%s</first_revision>
799
<latest_revision>%s</latest_revision>
802
<revisions>1</revisions>
806
''' % (format.get_branch_format().get_format_description(),
807
format.repository_format.get_format_description(),
808
datestring_first, datestring_first,
810
expected_xml = ''.join(expected_xml.split('\n'))+'\n'
811
self.assertEqualDiff(expected_xml, out)
812
self.assertEqual('', err)
813
tree3.commit('commit two')
815
# Out of date lightweight checkout
816
rev = repo.get_revision(branch1.last_revision())
817
datestring_last = osutils.format_date(rev.timestamp, rev.timezone)
818
out, err = self.run_bzr('xmlinfo tree/lightcheckout --verbose')
819
expected_xml = '''<?xml version="1.0"?>
821
<layout>Lightweight checkout</layout>
826
<light_checkout_root>tree/lightcheckout</light_checkout_root><checkout_of_branch>repo/branch</checkout_of_branch><shared_repository>repo</shared_repository></location>
828
<control>Meta directory format 1</control>
829
<working_tree>Working tree format 6</working_tree>
831
<repository>%s</repository>
834
<missing_revisions>1</missing_revisions>
835
<unchanged>1</unchanged>
836
<modified>0</modified>
842
<versioned_subdirectories>0</versioned_subdirectories>
843
</working_tree_stats>
845
<revisions>2</revisions>
846
<committers>1</committers>
847
<days_old>0</days_old>
848
<first_revision>%s</first_revision>
849
<latest_revision>%s</latest_revision>
852
<revisions>2</revisions>
856
''' % (format.get_branch_format().get_format_description(),
857
format.repository_format.get_format_description(),
858
datestring_first, datestring_last,
860
expected_xml = ''.join(expected_xml.split('\n'))+'\n'
861
self.assertEqualDiff(expected_xml, out)
862
self.assertEqual('', err)
864
# Show info about shared branch
865
out, err = self.run_bzr('xmlinfo repo/branch --verbose')
866
expected_xml = '''<?xml version="1.0"?>
868
<layout>Repository branch</layout>
870
<format>dirstate</format>
871
<format>knit</format>
874
<shared_repository>repo</shared_repository><repository_branch>repo/branch</repository_branch></location>
876
<control>Meta directory format 1</control>
878
<repository>%s</repository>
881
<revisions>2</revisions>
882
<committers>1</committers>
883
<days_old>0</days_old>
884
<first_revision>%s</first_revision>
885
<latest_revision>%s</latest_revision>
888
<revisions>2</revisions>
892
''' % (format.get_branch_format().get_format_description(),
893
format.repository_format.get_format_description(),
894
datestring_first, datestring_last,
896
expected_xml = ''.join(expected_xml.split('\n'))+'\n'
897
self.assertEqualDiff(expected_xml, out)
898
self.assertEqual('', err)
900
# Show info about repository with revisions
901
out, err = self.run_bzr('xmlinfo -v repo')
902
expected_xml = '''<?xml version="1.0"?>
904
<layout>Shared repository</layout>
906
<format>dirstate</format>
907
<format>dirstate-tags</format>
908
<format>knit</format>
911
<shared_repository>repo</shared_repository></location>
913
<control>Meta directory format 1</control>
914
<repository>%s</repository>
917
<revisions>2</revisions>
921
''' % (format.repository_format.get_format_description(),
923
expected_xml = ''.join(expected_xml.split('\n'))+'\n'
924
self.assertEqualDiff(expected_xml, out)
925
self.assertEqual('', err)
927
def test_info_shared_repository_with_trees(self):
928
format = bzrdir.format_registry.make_bzrdir('knit')
929
transport = self.get_transport()
931
# Create shared repository with working trees
932
repo = self.make_repository('repo', shared=True, format=format)
933
repo.set_make_working_trees(True)
934
out, err = self.run_bzr('xmlinfo -v repo')
935
expected_xml = '''<?xml version="1.0"?>
937
<layout>Shared repository with trees</layout>
939
<format>dirstate</format>
940
<format>dirstate-tags</format>
941
<format>knit</format>
944
<shared_repository>repo</shared_repository></location>
946
<control>Meta directory format 1</control>
947
<repository>%s</repository>
950
<revisions>0</revisions>
954
''' % (format.repository_format.get_format_description(),
956
expected_xml = ''.join(expected_xml.split('\n'))+'\n'
957
self.assertEqualDiff(expected_xml, out)
958
self.assertEqual('', err)
960
# Create two branches
961
repo.bzrdir.root_transport.mkdir('branch1')
962
branch1 = bzrdir.BzrDir.create_branch_convenience('repo/branch1',
964
branch2 = branch1.bzrdir.sprout('repo/branch2').open_branch()
967
out, err = self.run_bzr('xmlinfo repo/branch1 --verbose')
968
expected_xml = '''<?xml version="1.0"?>
970
<layout>Repository tree</layout>
972
<format>knit</format>
975
<shared_repository>repo</shared_repository><repository_branch>repo/branch1</repository_branch></location>
977
<control>Meta directory format 1</control>
978
<working_tree>Working tree format 3</working_tree>
980
<repository>%s</repository>
983
<unchanged>0</unchanged>
984
<modified>0</modified>
990
<versioned_subdirectories>0</versioned_subdirectories>
991
</working_tree_stats>
993
<revisions>0</revisions>
994
<committers>0</committers>
997
<revisions>0</revisions>
1001
''' % (format.get_branch_format().get_format_description(),
1002
format.repository_format.get_format_description(),
1004
expected_xml = ''.join(expected_xml.split('\n'))+'\n'
1005
self.assertEqualDiff(expected_xml, out)
1006
self.assertEqual('', err)
1008
# Update first branch
1009
self.build_tree(['repo/branch1/a'])
1010
tree1 = branch1.bzrdir.open_workingtree()
1012
tree1.commit('commit one')
1013
rev = repo.get_revision(branch1.revision_history()[0])
1014
datestring_first = osutils.format_date(rev.timestamp, rev.timezone)
1015
out, err = self.run_bzr('xmlinfo -v repo/branch1')
1016
expected_xml = '''<?xml version="1.0"?>
1018
<layout>Repository tree</layout>
1020
<format>knit</format>
1023
<shared_repository>repo</shared_repository><repository_branch>repo/branch1</repository_branch></location>
1025
<control>Meta directory format 1</control>
1026
<working_tree>Working tree format 3</working_tree>
1028
<repository>%s</repository>
1030
<working_tree_stats>
1031
<unchanged>1</unchanged>
1032
<modified>0</modified>
1034
<removed>0</removed>
1035
<renamed>0</renamed>
1036
<unknown>0</unknown>
1037
<ignored>0</ignored>
1038
<versioned_subdirectories>0</versioned_subdirectories>
1039
</working_tree_stats>
1041
<revisions>1</revisions>
1042
<committers>1</committers>
1043
<days_old>0</days_old>
1044
<first_revision>%s</first_revision>
1045
<latest_revision>%s</latest_revision>
1048
<revisions>1</revisions>
1052
''' % (format.get_branch_format().get_format_description(),
1053
format.repository_format.get_format_description(),
1054
datestring_first, datestring_first,
1056
expected_xml = ''.join(expected_xml.split('\n'))+'\n'
1057
self.assertEqualDiff(expected_xml, out)
1058
self.assertEqual('', err)
1060
# Out of date second branch
1061
out, err = self.run_bzr('xmlinfo repo/branch2 --verbose')
1062
expected_xml = '''<?xml version="1.0"?>
1064
<layout>Repository tree</layout>
1066
<format>knit</format>
1069
<shared_repository>repo</shared_repository><repository_branch>repo/branch2</repository_branch></location>
1071
<parent_branch>repo/branch1</parent_branch></related_branches>
1073
<control>Meta directory format 1</control>
1074
<working_tree>Working tree format 3</working_tree>
1076
<repository>%s</repository>
1078
<working_tree_stats>
1079
<unchanged>0</unchanged>
1080
<modified>0</modified>
1082
<removed>0</removed>
1083
<renamed>0</renamed>
1084
<unknown>0</unknown>
1085
<ignored>0</ignored>
1086
<versioned_subdirectories>0</versioned_subdirectories>
1087
</working_tree_stats>
1089
<revisions>0</revisions>
1090
<committers>0</committers>
1093
<revisions>1</revisions>
1097
''' % (format.get_branch_format().get_format_description(),
1098
format.repository_format.get_format_description(),
1100
expected_xml = ''.join(expected_xml.split('\n'))+'\n'
1101
self.assertEqualDiff(expected_xml, out)
1102
self.assertEqual('', err)
1104
# Update second branch
1105
tree2 = branch2.bzrdir.open_workingtree()
1107
out, err = self.run_bzr('xmlinfo -v repo/branch2')
1108
expected_xml = '''<?xml version="1.0"?>
1110
<layout>Repository tree</layout>
1112
<format>knit</format>
1115
<shared_repository>repo</shared_repository><repository_branch>repo/branch2</repository_branch></location>
1117
<parent_branch>repo/branch1</parent_branch></related_branches>
1119
<control>Meta directory format 1</control>
1120
<working_tree>Working tree format 3</working_tree>
1122
<repository>%s</repository>
1124
<working_tree_stats>
1125
<unchanged>1</unchanged>
1126
<modified>0</modified>
1128
<removed>0</removed>
1129
<renamed>0</renamed>
1130
<unknown>0</unknown>
1131
<ignored>0</ignored>
1132
<versioned_subdirectories>0</versioned_subdirectories>
1133
</working_tree_stats>
1135
<revisions>1</revisions>
1136
<committers>1</committers>
1137
<days_old>0</days_old>
1138
<first_revision>%s</first_revision>
1139
<latest_revision>%s</latest_revision>
1142
<revisions>1</revisions>
1146
''' % (format.get_branch_format().get_format_description(),
1147
format.repository_format.get_format_description(),
1148
datestring_first, datestring_first,
1150
expected_xml = ''.join(expected_xml.split('\n'))+'\n'
1151
self.assertEqualDiff(expected_xml, out)
1152
self.assertEqual('', err)
1154
# Show info about repository with revisions
1155
out, err = self.run_bzr('xmlinfo -v repo')
1156
expected_xml = '''<?xml version="1.0"?>
1158
<layout>Shared repository with trees</layout>
1160
<format>dirstate</format>
1161
<format>dirstate-tags</format>
1162
<format>knit</format>
1165
<shared_repository>repo</shared_repository></location>
1167
<control>Meta directory format 1</control>
1168
<repository>%s</repository>
1171
<revisions>1</revisions>
1175
''' % (format.repository_format.get_format_description(),
1177
expected_xml = ''.join(expected_xml.split('\n'))+'\n'
1178
self.assertEqualDiff(expected_xml, out)
1179
self.assertEqual('', err)
1181
def test_info_shared_repository_with_tree_in_root(self):
1182
format = bzrdir.format_registry.make_bzrdir('knit')
1183
transport = self.get_transport()
1185
# Create shared repository with working trees
1186
repo = self.make_repository('repo', shared=True, format=format)
1187
repo.set_make_working_trees(True)
1188
out, err = self.run_bzr('xmlinfo -v repo')
1189
expected_xml = '''<?xml version="1.0"?>
1191
<layout>Shared repository with trees</layout>
1193
<format>dirstate</format>
1194
<format>dirstate-tags</format>
1195
<format>knit</format>
1198
<shared_repository>repo</shared_repository></location>
1200
<control>Meta directory format 1</control>
1201
<repository>%s</repository>
1204
<revisions>0</revisions>
1208
''' % (format.repository_format.get_format_description(),)
1209
expected_xml = ''.join(expected_xml.split('\n'))+'\n'
1210
self.assertEqualDiff(expected_xml, out)
1211
self.assertEqual('', err)
1213
# Create branch in root of repository
1214
control = repo.bzrdir
1215
branch = control.create_branch()
1216
control.create_workingtree()
1217
out, err = self.run_bzr('xmlinfo -v repo')
1218
expected_xml = '''<?xml version="1.0"?>
1220
<layout>Repository tree</layout>
1222
<format>knit</format>
1225
<shared_repository>repo</shared_repository><repository_branch>repo</repository_branch></location>
1227
<control>Meta directory format 1</control>
1228
<working_tree>Working tree format 3</working_tree>
1230
<repository>%s</repository>
1232
<working_tree_stats>
1233
<unchanged>0</unchanged>
1234
<modified>0</modified>
1236
<removed>0</removed>
1237
<renamed>0</renamed>
1238
<unknown>0</unknown>
1239
<ignored>0</ignored>
1240
<versioned_subdirectories>0</versioned_subdirectories>
1241
</working_tree_stats>
1243
<revisions>0</revisions>
1244
<committers>0</committers>
1247
<revisions>0</revisions>
1251
''' % (format.get_branch_format().get_format_description(),
1252
format.repository_format.get_format_description(),
1254
expected_xml = ''.join(expected_xml.split('\n'))+'\n'
1255
self.assertEqualDiff(expected_xml, out)
1256
self.assertEqual('', err)
1258
def assertCheckoutStatusOutput(self,
1259
command_string, lco_tree, shared_repo=None,
1262
branch_locked=False, repo_locked=False,
1264
light_checkout=True,
1265
checkout_root=None):
1266
"""Check the output of info in a checkout.
1268
This is not quite a mirror of the info code: rather than using the
1269
tree being examined to predict output, it uses a bunch of flags which
1270
allow us, the test writers, to document what *should* be present in
1271
the output. Removing this separation would remove the value of the
1274
:param path: the path to the light checkout.
1275
:param lco_tree: the tree object for the light checkout.
1276
:param shared_repo: A shared repository is in use, expect that in
1278
:param repo_branch: A branch in a shared repository for non light
1280
:param tree_locked: If true, expect the tree to be locked.
1281
:param branch_locked: If true, expect the branch to be locked.
1282
:param repo_locked: If true, expect the repository to be locked.
1283
:param verbose: If true, expect verbose output
1285
def friendly_location(url):
1286
path = urlutils.unescape_for_display(url, 'ascii')
1288
return osutils.relpath(osutils.getcwd(), path)
1289
except errors.PathNotChild:
1293
# We expect this to fail because of locking errors, dirstate
1294
# can't be read locked while a write lock is open.
1295
self.run_bzr_error([], 'xmlinfo ' + command_string)
1297
out, err = self.run_bzr('xmlinfo %s' % command_string)
1299
(True, True): 'Lightweight checkout',
1300
(True, False): 'Repository checkout',
1301
(False, True): 'Lightweight checkout',
1302
(False, False): 'Checkout',
1303
}[(shared_repo is not None, light_checkout)]
1304
format = {True: '<format>2a</format>\n',
1305
False: '<format>unnamed</format>'}[light_checkout]
1307
repo_locked = lco_tree.branch.repository.get_physical_lock_status()
1308
if repo_locked or branch_locked or tree_locked:
1309
def locked_message(a_bool):
1314
expected_lock_output = (
1316
"<working_tree>%s</<working_tree>\n"
1317
"<branch>%s</branch>\n"
1318
"<repository>%s</repository>\n"
1319
"</lock_status>" % (
1320
locked_message(tree_locked),
1321
locked_message(branch_locked),
1322
locked_message(repo_locked)))
1324
expected_lock_output = ''
1328
tree_data = ("<light_checkout_root>%s</light_checkout_root>" %
1329
friendly_location(lco_tree.bzrdir.root_transport.base))
1331
if lco_tree.branch.get_bound_location() is not None:
1332
tree_data += ("<checkout_root>%s</checkout_root>" % (
1333
friendly_location(lco_tree.branch.bzrdir.root_transport.base)))
1334
if shared_repo is not None:
1336
"<checkout_of_branch>%s</checkout_of_branch>"
1337
"<shared_repository>%s</shared_repository>" %
1338
(friendly_location(repo_branch.bzrdir.root_transport.base),
1339
friendly_location(shared_repo.bzrdir.root_transport.base)))
1340
elif repo_branch is not None:
1341
branch_data = ("<checkout_of_branch>%s</checkout_of_branch>" %
1342
(friendly_location(repo_branch.bzrdir.root_transport.base)))
1344
branch_data = ("<checkout_of_branch>%s</checkout_of_branch>" %
1345
lco_tree.branch.bzrdir.root_transport.base)
1348
verbose_info = '<committers>0</committers>'
1352
expected_xml = '''<?xml version="1.0"?>
1361
<control>Meta directory format 1</control>
1362
<working_tree>%s</working_tree>
1364
<repository>%s</repository>
1366
<working_tree_stats>
1367
<unchanged>0</unchanged>
1368
<modified>0</modified>
1370
<removed>0</removed>
1371
<renamed>0</renamed>
1372
<unknown>0</unknown>
1373
<ignored>0</ignored>
1374
<versioned_subdirectories>0</versioned_subdirectories>
1375
</working_tree_stats>
1377
<revisions>0</revisions>
1381
<revisions>0</revisions>
1389
lco_tree._format.get_format_description(),
1390
lco_tree.branch._format.get_format_description(),
1391
lco_tree.branch.repository._format.get_format_description(),
1392
expected_lock_output,
1395
expected_xml = ''.join(expected_xml.split('\n'))+'\n'
1396
self.assertEqualDiff(expected_xml, out)
1397
self.assertEqual('', err)
1399
def test_info_locking(self):
1400
transport = self.get_transport()
1401
# Create shared repository with a branch
1402
repo = self.make_repository('repo', shared=True,
1403
format=bzrlib.bzrdir.BzrDirMetaFormat1())
1404
repo.set_make_working_trees(False)
1405
repo.bzrdir.root_transport.mkdir('branch')
1406
repo_branch = bzrdir.BzrDir.create_branch_convenience(
1407
'repo/branch', format=bzrlib.bzrdir.BzrDirMetaFormat1())
1408
# Do a heavy checkout
1409
transport.mkdir('tree')
1410
transport.mkdir('tree/checkout')
1411
co_branch = bzrlib.bzrdir.BzrDir.create_branch_convenience('tree/checkout',
1412
format=bzrlib.bzrdir.BzrDirMetaFormat1())
1413
co_branch.bind(repo_branch)
1414
# Do a light checkout of the heavy one
1415
transport.mkdir('tree/lightcheckout')
1416
lco_dir = bzrlib.bzrdir.BzrDirMetaFormat1().initialize('tree/lightcheckout')
1417
bzrlib.branch.BranchReferenceFormat().initialize(lco_dir,
1418
target_branch=co_branch)
1419
lco_dir.create_workingtree()
1420
lco_tree = lco_dir.open_workingtree()
1422
# Test all permutations of locking the working tree, branch and repository
1426
self.assertCheckoutStatusOutput('-v tree/lightcheckout', lco_tree,
1427
repo_branch=repo_branch,
1428
verbose=True, light_checkout=True)
1430
lco_tree.branch.repository.lock_write()
1432
self.assertCheckoutStatusOutput('-v tree/lightcheckout',
1433
lco_tree, repo_branch=repo_branch,
1434
repo_locked=True, verbose=True, light_checkout=True)
1436
lco_tree.branch.repository.unlock()
1438
lco_tree.branch.lock_write()
1440
self.assertCheckoutStatusOutput('-v tree/lightcheckout',
1444
repo_branch=repo_branch,
1447
lco_tree.branch.unlock()
1449
lco_tree.lock_write()
1451
self.assertCheckoutStatusOutput('-v tree/lightcheckout',
1452
lco_tree, repo_branch=repo_branch,
1460
lco_tree.lock_write()
1461
lco_tree.branch.repository.unlock()
1463
self.assertCheckoutStatusOutput('-v tree/lightcheckout',
1464
lco_tree, repo_branch=repo_branch,
1469
lco_tree.branch.repository.lock_write()
1472
lco_tree.lock_write()
1473
lco_tree.branch.unlock()
1475
self.assertCheckoutStatusOutput('-v tree/lightcheckout',
1476
lco_tree, repo_branch=repo_branch,
1480
lco_tree.branch.lock_write()
1483
lco_tree.lock_write()
1484
lco_tree.branch.unlock()
1485
lco_tree.branch.repository.lock_write()
1487
self.assertCheckoutStatusOutput('-v tree/lightcheckout',
1488
lco_tree, repo_branch=repo_branch,
1493
lco_tree.branch.repository.unlock()
1494
lco_tree.branch.lock_write()
1497
lco_tree.branch.lock_write()
1498
lco_tree.branch.repository.unlock()
1500
self.assertCheckoutStatusOutput('-v tree/lightcheckout',
1501
lco_tree, repo_branch=repo_branch,
1505
lco_tree.branch.repository.lock_write()
1506
lco_tree.branch.unlock()
1508
if sys.platform == 'win32':
1509
self.knownFailure('Win32 cannot run "bzr info"'
1510
' when the tree is locked.')
1512
def test_info_locking_oslocks(self):
1513
if sys.platform == "win32":
1514
raise tests.TestSkipped("don't use oslocks on win32 in unix manner")
1515
# This test tests old (all-in-one, OS lock using) behaviour which
1516
# simply cannot work on windows (and is indeed why we changed our
1517
# design. As such, don't try to remove the thisFailsStrictLockCheck
1519
self.thisFailsStrictLockCheck()
1521
tree = self.make_branch_and_tree('branch', format='weave')
1523
# Test all permutations of locking the working tree, branch and repository
1524
# XXX: Well not yet, as we can't query oslocks yet. Currently, it's
1525
# implemented by raising NotImplementedError and get_physical_lock_status()
1526
# always returns false. This makes bzr info hide the lock status. (Olaf)
1530
out, err = self.run_bzr('xmlinfo -v branch')
1531
expected_xml = '''<?xml version="1.0"?>
1533
<layout>Standalone tree</layout>
1535
<format>weave</format>
1538
<branch_root>%s</branch_root></location>
1540
<control>All-in-one format 6</control>
1541
<working_tree>Working tree format 2</working_tree>
1542
<branch>Branch format 4</branch>
1543
<repository>%s</repository>
1545
<working_tree_stats>
1546
<unchanged>0</unchanged>
1547
<modified>0</modified>
1549
<removed>0</removed>
1550
<renamed>0</renamed>
1551
<unknown>0</unknown>
1552
<ignored>0</ignored>
1553
<versioned_subdirectories>0</versioned_subdirectories>
1554
</working_tree_stats>
1556
<revisions>0</revisions>
1557
<committers>0</committers>
1560
<revisions>0</revisions>
1564
''' % ('branch', tree.branch.repository._format.get_format_description(),
1566
expected_xml = ''.join(expected_xml.split('\n'))+'\n'
1567
self.assertEqualDiff(expected_xml, out)
1568
self.assertEqual('', err)
1571
out, err = self.run_bzr('xmlinfo -v branch')
1572
expected_xml = '''<?xml version="1.0"?>
1574
<layout>Standalone tree</layout>
1576
<format>weave</format>
1579
<branch_root>%s</branch_root></location>
1581
<control>All-in-one format 6</control>
1582
<working_tree>Working tree format 2</working_tree>
1583
<branch>Branch format 4</branch>
1584
<repository>%s</repository>
1586
<working_tree_stats>
1587
<unchanged>0</unchanged>
1588
<modified>0</modified>
1590
<removed>0</removed>
1591
<renamed>0</renamed>
1592
<unknown>0</unknown>
1593
<ignored>0</ignored>
1594
<versioned_subdirectories>0</versioned_subdirectories>
1595
</working_tree_stats>
1597
<revisions>0</revisions>
1598
<committers>0</committers>
1601
<revisions>0</revisions>
1605
'''% ('branch', tree.branch.repository._format.get_format_description(),
1607
expected_xml = ''.join(expected_xml.split('\n'))+'\n'
1608
self.assertEqualDiff(expected_xml, out)
1609
self.assertEqual('', err)
1612
def test_info_stacked(self):
1613
# We have a mainline
1614
trunk_tree = self.make_branch_and_tree('mainline', format='1.6')
1615
trunk_tree.commit('mainline')
1616
# and a branch from it which is stacked
1617
new_dir = trunk_tree.bzrdir.sprout('newbranch', stacked=True)
1618
out, err = self.run_bzr('xmlinfo newbranch')
1619
expected_xml = '''<?xml version="1.0"?>
1621
<layout>Standalone tree</layout>
1623
<format>1.6</format>
1625
<location><branch_root>newbranch</branch_root></location>
1627
<parent_branch>mainline</parent_branch>
1628
<stacked_on>mainline</stacked_on>
1631
expected_xml = ''.join(expected_xml.split('\n'))+'\n'
1632
self.assertEqual(expected_xml, out)
1633
self.assertEqual("", err)