~ubuntu-branches/ubuntu/trusty/bzr-xmloutput/trusty

« back to all changes in this revision

Viewing changes to .pc/04_no_revision_history/tests/test_info_xml.py

  • Committer: Package Import Robot
  • Author(s): Jelmer Vernooij
  • Date: 2012-02-21 11:30:46 UTC
  • Revision ID: package-import@ubuntu.com-20120221113046-n854cxkvrn6upq61
Tags: 0.8.8+bzr160-2
* Add patches to improve compatibility with newer versions of bzr:
 + 01_no_inventory: Don't rely on inventories being available
 + 02_elementtree: Use correct location of elementtree. Closes: #660728
 + 03_info_controldir: Fix support for 'bzr xmlinfo' in empty control
   directories.
 + 04_no_revision_history: Avoid using deprecated `Branch.revision_history`
   call.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- encoding: utf-8 -*-
 
2
#
 
3
# Copyright (C) 2006, 2007 Canonical Ltd
 
4
#
 
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.
 
9
#
 
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.
 
14
#
 
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
 
18
 
 
19
 
 
20
"""Tests for the info command of bzr."""
 
21
 
 
22
import sys
 
23
 
 
24
import bzrlib
 
25
from bzrlib import (
 
26
    bzrdir,
 
27
    errors,
 
28
    osutils,
 
29
    tests,
 
30
    urlutils,
 
31
    )
 
32
from bzrlib.tests import blackbox
 
33
import bzrlib.upgrade
 
34
 
 
35
 
 
36
class TestInfoXml(blackbox.ExternalBase):
 
37
 
 
38
    def test_should_normalize_non_ascii_url(self):
 
39
        # we disable isolation because the error we want to catch is triggered
 
40
        # outside of the jail
 
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)
 
47
        self.assertEqual(
 
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)
 
54
 
 
55
    def test_info_non_existing(self):
 
56
        # we disable isolation because the error we want to catch is triggered
 
57
        # outside of the jail
 
58
        self.disable_directory_isolation()
 
59
        if sys.platform == "win32":
 
60
            location = "C:/i/do/not/exist/"
 
61
        else:
 
62
            location = "/i/do/not/exist/"
 
63
        out, err = self.run_bzr('xmlinfo '+location, retcode=3)
 
64
        self.assertEqual(out, '')
 
65
        self.assertEqual(
 
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)
 
73
 
 
74
    def test_info_standalone(self):
 
75
        transport = self.get_transport()
 
76
 
 
77
        # Create initial standalone branch
 
78
        tree1 = self.make_branch_and_tree('standalone', 'weave')
 
79
        self.build_tree(['standalone/a'])
 
80
        tree1.add('a')
 
81
        branch1 = tree1.branch
 
82
 
 
83
        out, err = self.run_bzr('xmlinfo standalone')
 
84
        expected_xml = '''<?xml version="1.0"?>
 
85
<info>
 
86
<layout>Standalone tree</layout>
 
87
<formats>
 
88
<format>weave</format>
 
89
</formats>
 
90
<location>
 
91
<branch_root>standalone</branch_root></location>
 
92
</info>
 
93
 
 
94
'''
 
95
        expected_xml = ''.join(expected_xml.split('\n'))+'\n'
 
96
        self.assertEqualDiff(expected_xml, out)
 
97
        self.assertEqual('', err)
 
98
 
 
99
        out, err = self.run_bzr('xmlinfo standalone -v')
 
100
        expected_xml = '''<?xml version="1.0"?>
 
101
<info>
 
102
<layout>Standalone tree</layout>
 
103
<formats>
 
104
<format>weave</format>
 
105
</formats>
 
106
<location>
 
107
<branch_root>standalone</branch_root></location>
 
108
<format>
 
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>
 
113
</format>
 
114
<working_tree_stats>
 
115
<unchanged>0</unchanged>
 
116
<modified>0</modified>
 
117
<added>1</added>
 
118
<removed>0</removed>
 
119
<renamed>0</renamed>
 
120
<unknown>0</unknown>
 
121
<ignored>0</ignored>
 
122
<versioned_subdirectories>0</versioned_subdirectories>
 
123
</working_tree_stats>
 
124
<branch_history>
 
125
<revisions>0</revisions>
 
126
<committers>0</committers>
 
127
</branch_history>
 
128
<repository_stats>
 
129
<revisions>0</revisions>
 
130
</repository_stats>
 
131
</info>
 
132
 
 
133
'''
 
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)
 
140
 
 
141
        # Branch standalone with push location
 
142
        branch2 = branch1.bzrdir.sprout('branch').open_branch()
 
143
        branch2.set_push_location(branch1.bzrdir.root_transport.base)
 
144
 
 
145
        out, err = self.run_bzr('xmlinfo branch')
 
146
        expected_xml = '''<?xml version="1.0"?>
 
147
<info>
 
148
<layout>Standalone tree</layout>
 
149
<formats>
 
150
<format>weave</format>
 
151
</formats>
 
152
<location>
 
153
<branch_root>branch</branch_root></location>
 
154
<related_branches>
 
155
<push_branch>standalone</push_branch><parent_branch>standalone</parent_branch></related_branches>
 
156
</info>
 
157
 
 
158
'''
 
159
        expected_xml = ''.join(expected_xml.split('\n'))+'\n'
 
160
        self.assertEqualDiff(expected_xml, out)
 
161
        self.assertEqual('', err)
 
162
 
 
163
        out, err = self.run_bzr('xmlinfo branch --verbose')
 
164
        expected_xml = '''<?xml version="1.0"?>
 
165
<info>
 
166
<layout>Standalone tree</layout>
 
167
<formats>
 
168
<format>weave</format>
 
169
</formats>
 
170
<location>
 
171
<branch_root>branch</branch_root></location>
 
172
<related_branches>
 
173
<push_branch>standalone</push_branch><parent_branch>standalone</parent_branch></related_branches>
 
174
<format>
 
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>
 
179
</format>
 
180
<working_tree_stats>
 
181
<unchanged>1</unchanged>
 
182
<modified>0</modified>
 
183
<added>0</added>
 
184
<removed>0</removed>
 
185
<renamed>0</renamed>
 
186
<unknown>0</unknown>
 
187
<ignored>0</ignored>
 
188
<versioned_subdirectories>0</versioned_subdirectories>
 
189
</working_tree_stats>
 
190
<branch_history>
 
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>
 
196
</branch_history>
 
197
<repository_stats>
 
198
<revisions>1</revisions>
 
199
</repository_stats>
 
200
</info>
 
201
 
 
202
''' % (datestring_first, datestring_first,
 
203
       )
 
204
        expected_xml = ''.join(expected_xml.split('\n'))+'\n'
 
205
        self.assertEqualDiff(expected_xml, out)
 
206
        self.assertEqual('', err)
 
207
 
 
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"?>
 
218
<info>
 
219
<layout>Checkout</layout>
 
220
<formats>
 
221
<format>knit</format>
 
222
</formats>
 
223
<location>
 
224
<checkout_root>bound</checkout_root><checkout_of_branch>standalone</checkout_of_branch></location>
 
225
<related_branches>
 
226
<parent_branch>standalone</parent_branch></related_branches>
 
227
<format>
 
228
<control>Meta directory format 1</control>
 
229
<working_tree>%s</working_tree>
 
230
<branch>%s</branch>
 
231
<repository>%s</repository>
 
232
</format>
 
233
<working_tree_stats>
 
234
<unchanged>1</unchanged>
 
235
<modified>0</modified>
 
236
<added>0</added>
 
237
<removed>0</removed>
 
238
<renamed>0</renamed>
 
239
<unknown>0</unknown>
 
240
<ignored>1</ignored>
 
241
<versioned_subdirectories>0</versioned_subdirectories>
 
242
</working_tree_stats>
 
243
<branch_history>
 
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>
 
249
</branch_history>
 
250
<repository_stats>
 
251
<revisions>1</revisions>
 
252
</repository_stats>
 
253
</info>
 
254
 
 
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,
 
259
       )
 
260
        expected_xml = ''.join(expected_xml.split('\n'))+'\n'
 
261
        self.assertEqualDiff(expected_xml, out)
 
262
        self.assertEqual('', err)
 
263
 
 
264
        # Checkout standalone (same as above, but does not have parent set)
 
265
        branch4 = bzrlib.bzrdir.BzrDir.create_branch_convenience('checkout',
 
266
            format=knit1_format)
 
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"?>
 
271
<info>
 
272
<layout>Checkout</layout>
 
273
<formats>
 
274
<format>knit</format>
 
275
</formats>
 
276
<location>
 
277
<checkout_root>checkout</checkout_root><checkout_of_branch>standalone</checkout_of_branch></location>
 
278
<format>
 
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>
 
283
</format>
 
284
<working_tree_stats>
 
285
<unchanged>1</unchanged>
 
286
<modified>0</modified>
 
287
<added>0</added>
 
288
<removed>0</removed>
 
289
<renamed>0</renamed>
 
290
<unknown>0</unknown>
 
291
<ignored>0</ignored>
 
292
<versioned_subdirectories>0</versioned_subdirectories>
 
293
</working_tree_stats>
 
294
<branch_history>
 
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>
 
300
</branch_history>
 
301
<repository_stats>
 
302
<revisions>1</revisions>
 
303
</repository_stats>
 
304
</info>
 
305
 
 
306
''' % (branch4.repository._format.get_format_description(),
 
307
       datestring_first, datestring_first,
 
308
       )
 
309
        expected_xml = ''.join(expected_xml.split('\n'))+'\n'
 
310
        self.assertEqualDiff(expected_xml , out)
 
311
        self.assertEqual('', err)
 
312
 
 
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"?>
 
318
<info>
 
319
<layout>Lightweight checkout</layout>
 
320
<formats>
 
321
<format>2a</format>
 
322
</formats>
 
323
<location>
 
324
<light_checkout_root>lightcheckout</light_checkout_root><checkout_of_branch>standalone</checkout_of_branch></location>
 
325
<format>
 
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>
 
330
</format>
 
331
<working_tree_stats>
 
332
<unchanged>1</unchanged>
 
333
<modified>0</modified>
 
334
<added>0</added>
 
335
<removed>0</removed>
 
336
<renamed>0</renamed>
 
337
<unknown>0</unknown>
 
338
<ignored>0</ignored>
 
339
<versioned_subdirectories>0</versioned_subdirectories>
 
340
</working_tree_stats>
 
341
<branch_history>
 
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>
 
347
</branch_history>
 
348
<repository_stats>
 
349
<revisions>1</revisions>
 
350
</repository_stats>
 
351
</info>
 
352
 
 
353
''' % (datestring_first, datestring_first)
 
354
        expected_xml = ''.join(expected_xml.split('\n'))+'\n'
 
355
        self.assertEqualDiff(expected_xml, out)
 
356
        self.assertEqual('', err)
 
357
 
 
358
        # Update initial standalone branch
 
359
        self.build_tree(['standalone/b'])
 
360
        tree1.add('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)
 
364
 
 
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"?>
 
368
<info>
 
369
<layout>Standalone tree</layout>
 
370
<formats>
 
371
<format>weave</format>
 
372
</formats>
 
373
<location>
 
374
<branch_root>branch</branch_root></location>
 
375
<related_branches>
 
376
<push_branch>standalone</push_branch><parent_branch>standalone</parent_branch></related_branches>
 
377
<format>
 
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>
 
382
</format>
 
383
<working_tree_stats>
 
384
<unchanged>1</unchanged>
 
385
<modified>0</modified>
 
386
<added>0</added>
 
387
<removed>0</removed>
 
388
<renamed>0</renamed>
 
389
<unknown>0</unknown>
 
390
<ignored>0</ignored>
 
391
<versioned_subdirectories>0</versioned_subdirectories>
 
392
</working_tree_stats>
 
393
<branch_history>
 
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>
 
399
</branch_history>
 
400
<repository_stats>
 
401
<revisions>1</revisions>
 
402
</repository_stats>
 
403
</info>
 
404
 
 
405
''' % (datestring_first, datestring_first,)
 
406
        expected_xml = ''.join(expected_xml.split('\n'))+'\n'
 
407
        self.assertEqualDiff(expected_xml, out)
 
408
        self.assertEqual('', err)
 
409
 
 
410
        # Out of date bound branch
 
411
        out, err = self.run_bzr('xmlinfo -v bound')
 
412
        expected_xml = '''<?xml version="1.0"?>
 
413
<info>
 
414
<layout>Checkout</layout>
 
415
<formats>
 
416
<format>knit</format>
 
417
</formats>
 
418
<location>
 
419
<checkout_root>bound</checkout_root><checkout_of_branch>standalone</checkout_of_branch></location>
 
420
<related_branches>
 
421
<parent_branch>standalone</parent_branch></related_branches>
 
422
<format>
 
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>
 
427
</format>
 
428
<branch_stats>
 
429
<missing_revisions>1<missing_revisions>
 
430
</branch_stats>
 
431
<working_tree_stats>
 
432
<unchanged>1</unchanged>
 
433
<modified>0</modified>
 
434
<added>0</added>
 
435
<removed>0</removed>
 
436
<renamed>0</renamed>
 
437
<unknown>0</unknown>
 
438
<ignored>1</ignored>
 
439
<versioned_subdirectories>0</versioned_subdirectories>
 
440
</working_tree_stats>
 
441
<branch_history>
 
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>
 
447
</branch_history>
 
448
<repository_stats>
 
449
<revisions>1</revisions>
 
450
</repository_stats>
 
451
</info>
 
452
 
 
453
''' % (branch3.repository._format.get_format_description(),
 
454
       datestring_first, datestring_first,
 
455
       )
 
456
        expected_xml = ''.join(expected_xml.split('\n'))+'\n'
 
457
        self.assertEqualDiff(expected_xml, out)
 
458
        self.assertEqual('', err)
 
459
 
 
460
        # Out of date checkout
 
461
        out, err = self.run_bzr('xmlinfo -v checkout')
 
462
        expected_xml = '''<?xml version="1.0"?>
 
463
<info>
 
464
<layout>Checkout</layout>
 
465
<formats>
 
466
<format>knit</format>
 
467
</formats>
 
468
<location>
 
469
<checkout_root>checkout</checkout_root><checkout_of_branch>standalone</checkout_of_branch></location>
 
470
<format>
 
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>
 
475
</format>
 
476
<branch_stats>
 
477
<missing_revisions>1<missing_revisions>
 
478
</branch_stats>
 
479
<working_tree_stats>
 
480
<unchanged>1</unchanged>
 
481
<modified>0</modified>
 
482
<added>0</added>
 
483
<removed>0</removed>
 
484
<renamed>0</renamed>
 
485
<unknown>0</unknown>
 
486
<ignored>0</ignored>
 
487
<versioned_subdirectories>0</versioned_subdirectories>
 
488
</working_tree_stats>
 
489
<branch_history>
 
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>
 
495
</branch_history>
 
496
<repository_stats>
 
497
<revisions>1</revisions>
 
498
</repository_stats>
 
499
</info>
 
500
 
 
501
''' % (branch4.repository._format.get_format_description(),
 
502
       datestring_first, datestring_first,
 
503
       )
 
504
        expected_xml = ''.join(expected_xml.split('\n'))+'\n'
 
505
        self.assertEqualDiff(expected_xml, out)
 
506
        self.assertEqual('', err)
 
507
 
 
508
        # Out of date lightweight checkout
 
509
        out, err = self.run_bzr('xmlinfo lightcheckout --verbose')
 
510
        expected_xml = '''<?xml version="1.0"?>
 
511
<info>
 
512
<layout>Lightweight checkout</layout>
 
513
<formats>
 
514
<format>2a</format>
 
515
</formats>
 
516
<location>
 
517
<light_checkout_root>lightcheckout</light_checkout_root><checkout_of_branch>standalone</checkout_of_branch></location>
 
518
<format>
 
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>
 
523
</format>
 
524
<working_tree_stats>
 
525
<missing_revisions>1</missing_revisions>
 
526
<unchanged>1</unchanged>
 
527
<modified>0</modified>
 
528
<added>0</added>
 
529
<removed>0</removed>
 
530
<renamed>0</renamed>
 
531
<unknown>0</unknown>
 
532
<ignored>0</ignored>
 
533
<versioned_subdirectories>0</versioned_subdirectories>
 
534
</working_tree_stats>
 
535
<branch_history>
 
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>
 
541
</branch_history>
 
542
<repository_stats>
 
543
<revisions>2</revisions>
 
544
</repository_stats>
 
545
</info>
 
546
 
 
547
''' % (datestring_first, datestring_last,)
 
548
        expected_xml = ''.join(expected_xml.split('\n'))+'\n'
 
549
        self.assertEqualDiff(expected_xml, out)
 
550
        self.assertEqual('', err)
 
551
 
 
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"?>
 
559
<info>
 
560
<layout>Standalone branch</layout>
 
561
<formats>
 
562
<format>2a</format>
 
563
</formats>
 
564
<location>
 
565
<branch_root>branch</branch_root></location>
 
566
<format>
 
567
<control>Meta directory format 1</control>
 
568
<branch>%s</branch>
 
569
<repository>%s</repository>
 
570
</format>
 
571
<branch_history>
 
572
<revisions>0</revisions>
 
573
<committers>0</committers>
 
574
</branch_history>
 
575
<repository_stats>
 
576
<revisions>0</revisions>
 
577
</repository_stats>
 
578
</info>
 
579
 
 
580
''' % (format.get_branch_format().get_format_description(),
 
581
       format.repository_format.get_format_description(),
 
582
       )
 
583
        expected_xml = ''.join(expected_xml.split('\n'))+'\n'
 
584
        self.assertEqualDiff(expected_xml, out)
 
585
        self.assertEqual('', err)
 
586
 
 
587
    def test_info_shared_repository(self):
 
588
        format = bzrdir.format_registry.make_bzrdir('knit')
 
589
        transport = self.get_transport()
 
590
 
 
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"?>
 
596
<info>
 
597
<layout>Shared repository</layout>
 
598
<formats>
 
599
<format>dirstate</format>
 
600
<format>dirstate-tags</format>
 
601
<format>knit</format>
 
602
</formats>
 
603
<location>
 
604
<shared_repository>%s</shared_repository></location>
 
605
<format>
 
606
<control>Meta directory format 1</control>
 
607
<repository>%s</repository>
 
608
</format>
 
609
<repository_stats>
 
610
<revisions>0</revisions>
 
611
</repository_stats>
 
612
</info>
 
613
 
 
614
''' % ('repo', format.repository_format.get_format_description(),
 
615
       )
 
616
        expected_xml = ''.join(expected_xml.split('\n'))+'\n'
 
617
        self.assertEqualDiff(expected_xml, out)
 
618
        self.assertEqual('', err)
 
619
 
 
620
        # Create branch inside shared repository
 
621
        repo.bzrdir.root_transport.mkdir('branch')
 
622
        branch1 = bzrdir.BzrDir.create_branch_convenience('repo/branch',
 
623
            format=format)
 
624
        out, err = self.run_bzr('xmlinfo -v repo/branch')
 
625
        expected_xml = '''<?xml version="1.0"?>
 
626
<info>
 
627
<layout>Repository branch</layout>
 
628
<formats>
 
629
<format>dirstate</format>
 
630
<format>knit</format>
 
631
</formats>
 
632
<location>
 
633
<shared_repository>repo</shared_repository><repository_branch>repo/branch</repository_branch></location>
 
634
<format>
 
635
<control>Meta directory format 1</control>
 
636
<branch>%s</branch>
 
637
<repository>%s</repository>
 
638
</format>
 
639
<branch_history>
 
640
<revisions>0</revisions>
 
641
<committers>0</committers>
 
642
</branch_history>
 
643
<repository_stats>
 
644
<revisions>0</revisions>
 
645
</repository_stats>
 
646
</info>
 
647
 
 
648
''' % (format.get_branch_format().get_format_description(),
 
649
       format.repository_format.get_format_description(),
 
650
       )
 
651
        expected_xml = ''.join(expected_xml.split('\n'))+'\n'
 
652
        self.assertEqualDiff(expected_xml, out)
 
653
        self.assertEqual('', err)
 
654
 
 
655
        # Create lightweight checkout
 
656
        transport.mkdir('tree')
 
657
        transport.mkdir('tree/lightcheckout')
 
658
        tree2 = branch1.create_checkout('tree/lightcheckout',
 
659
            lightweight=True)
 
660
        branch2 = tree2.branch
 
661
        self.assertCheckoutStatusOutput('-v tree/lightcheckout', tree2,
 
662
                   shared_repo=repo, repo_branch=branch1, verbose=True)
 
663
 
 
664
        # Create normal checkout
 
665
        tree3 = branch1.create_checkout('tree/checkout')
 
666
        self.assertCheckoutStatusOutput('tree/checkout --verbose', tree3,
 
667
            verbose=True,
 
668
            light_checkout=False, repo_branch=branch1)
 
669
        # Update lightweight checkout
 
670
        self.build_tree(['tree/lightcheckout/a'])
 
671
        tree2.add('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"?>
 
677
<info>
 
678
<layout>Lightweight checkout</layout>
 
679
<formats>
 
680
<format>2a</format>
 
681
</formats>
 
682
<location>
 
683
<light_checkout_root>tree/lightcheckout</light_checkout_root><checkout_of_branch>repo/branch</checkout_of_branch><shared_repository>repo</shared_repository></location>
 
684
<format>
 
685
<control>Meta directory format 1</control>
 
686
<working_tree>Working tree format 6</working_tree>
 
687
<branch>%s</branch>
 
688
<repository>%s</repository>
 
689
</format>
 
690
<working_tree_stats>
 
691
<unchanged>1</unchanged>
 
692
<modified>0</modified>
 
693
<added>0</added>
 
694
<removed>0</removed>
 
695
<renamed>0</renamed>
 
696
<unknown>0</unknown>
 
697
<ignored>0</ignored>
 
698
<versioned_subdirectories>0</versioned_subdirectories>
 
699
</working_tree_stats>
 
700
<branch_history>
 
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>
 
706
</branch_history>
 
707
<repository_stats>
 
708
<revisions>1</revisions>
 
709
</repository_stats>
 
710
</info>
 
711
 
 
712
''' % (format.get_branch_format().get_format_description(),
 
713
       format.repository_format.get_format_description(),
 
714
       datestring_first, datestring_first,
 
715
       )
 
716
        expected_xml = ''.join(expected_xml.split('\n'))+'\n'
 
717
        self.assertEqualDiff(expected_xml, out)
 
718
        self.assertEqual('', err)
 
719
 
 
720
        # Out of date checkout
 
721
        out, err = self.run_bzr('xmlinfo -v tree/checkout')
 
722
        expected_xml = '''<?xml version="1.0"?>
 
723
<info>
 
724
<layout>Checkout</layout>
 
725
<formats>
 
726
<format>unnamed</format>
 
727
</formats>
 
728
<location>
 
729
<checkout_root>tree/checkout</checkout_root><checkout_of_branch>repo/branch</checkout_of_branch></location>
 
730
<format>
 
731
<control>Meta directory format 1</control>
 
732
<working_tree>Working tree format 6</working_tree>
 
733
<branch>%s</branch>
 
734
<repository>%s</repository>
 
735
</format>
 
736
<branch_stats>
 
737
<missing_revisions>1<missing_revisions>
 
738
</branch_stats>
 
739
<working_tree_stats>
 
740
<unchanged>0</unchanged>
 
741
<modified>0</modified>
 
742
<added>0</added>
 
743
<removed>0</removed>
 
744
<renamed>0</renamed>
 
745
<unknown>0</unknown>
 
746
<ignored>0</ignored>
 
747
<versioned_subdirectories>0</versioned_subdirectories>
 
748
</working_tree_stats>
 
749
<branch_history>
 
750
<revisions>0</revisions>
 
751
<committers>0</committers>
 
752
</branch_history>
 
753
<repository_stats>
 
754
<revisions>0</revisions>
 
755
</repository_stats>
 
756
</info>
 
757
 
 
758
''' % (format.get_branch_format().get_format_description(),
 
759
       format.repository_format.get_format_description(),
 
760
       )
 
761
        expected_xml = ''.join(expected_xml.split('\n'))+'\n'
 
762
        self.assertEqualDiff(expected_xml, out)
 
763
        self.assertEqual('', err)
 
764
 
 
765
        # Update checkout
 
766
        tree3.update()
 
767
        self.build_tree(['tree/checkout/b'])
 
768
        tree3.add('b')
 
769
        out, err = self.run_bzr('xmlinfo tree/checkout --verbose')
 
770
        expected_xml = '''<?xml version="1.0"?>
 
771
<info>
 
772
<layout>Checkout</layout>
 
773
<formats>
 
774
<format>unnamed</format>
 
775
</formats>
 
776
<location>
 
777
<checkout_root>tree/checkout</checkout_root><checkout_of_branch>repo/branch</checkout_of_branch></location>
 
778
<format>
 
779
<control>Meta directory format 1</control>
 
780
<working_tree>Working tree format 6</working_tree>
 
781
<branch>%s</branch>
 
782
<repository>%s</repository>
 
783
</format>
 
784
<working_tree_stats>
 
785
<unchanged>1</unchanged>
 
786
<modified>0</modified>
 
787
<added>1</added>
 
788
<removed>0</removed>
 
789
<renamed>0</renamed>
 
790
<unknown>0</unknown>
 
791
<ignored>0</ignored>
 
792
<versioned_subdirectories>0</versioned_subdirectories>
 
793
</working_tree_stats>
 
794
<branch_history>
 
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>
 
800
</branch_history>
 
801
<repository_stats>
 
802
<revisions>1</revisions>
 
803
</repository_stats>
 
804
</info>
 
805
 
 
806
''' % (format.get_branch_format().get_format_description(),
 
807
       format.repository_format.get_format_description(),
 
808
       datestring_first, datestring_first,
 
809
       )
 
810
        expected_xml = ''.join(expected_xml.split('\n'))+'\n'
 
811
        self.assertEqualDiff(expected_xml, out)
 
812
        self.assertEqual('', err)
 
813
        tree3.commit('commit two')
 
814
 
 
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"?>
 
820
<info>
 
821
<layout>Lightweight checkout</layout>
 
822
<formats>
 
823
<format>2a</format>
 
824
</formats>
 
825
<location>
 
826
<light_checkout_root>tree/lightcheckout</light_checkout_root><checkout_of_branch>repo/branch</checkout_of_branch><shared_repository>repo</shared_repository></location>
 
827
<format>
 
828
<control>Meta directory format 1</control>
 
829
<working_tree>Working tree format 6</working_tree>
 
830
<branch>%s</branch>
 
831
<repository>%s</repository>
 
832
</format>
 
833
<working_tree_stats>
 
834
<missing_revisions>1</missing_revisions>
 
835
<unchanged>1</unchanged>
 
836
<modified>0</modified>
 
837
<added>0</added>
 
838
<removed>0</removed>
 
839
<renamed>0</renamed>
 
840
<unknown>0</unknown>
 
841
<ignored>0</ignored>
 
842
<versioned_subdirectories>0</versioned_subdirectories>
 
843
</working_tree_stats>
 
844
<branch_history>
 
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>
 
850
</branch_history>
 
851
<repository_stats>
 
852
<revisions>2</revisions>
 
853
</repository_stats>
 
854
</info>
 
855
 
 
856
''' % (format.get_branch_format().get_format_description(),
 
857
       format.repository_format.get_format_description(),
 
858
       datestring_first, datestring_last,
 
859
       )
 
860
        expected_xml = ''.join(expected_xml.split('\n'))+'\n'
 
861
        self.assertEqualDiff(expected_xml, out)
 
862
        self.assertEqual('', err)
 
863
 
 
864
        # Show info about shared branch
 
865
        out, err = self.run_bzr('xmlinfo repo/branch --verbose')
 
866
        expected_xml = '''<?xml version="1.0"?>
 
867
<info>
 
868
<layout>Repository branch</layout>
 
869
<formats>
 
870
<format>dirstate</format>
 
871
<format>knit</format>
 
872
</formats>
 
873
<location>
 
874
<shared_repository>repo</shared_repository><repository_branch>repo/branch</repository_branch></location>
 
875
<format>
 
876
<control>Meta directory format 1</control>
 
877
<branch>%s</branch>
 
878
<repository>%s</repository>
 
879
</format>
 
880
<branch_history>
 
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>
 
886
</branch_history>
 
887
<repository_stats>
 
888
<revisions>2</revisions>
 
889
</repository_stats>
 
890
</info>
 
891
 
 
892
''' % (format.get_branch_format().get_format_description(),
 
893
       format.repository_format.get_format_description(),
 
894
       datestring_first, datestring_last,
 
895
       )
 
896
        expected_xml = ''.join(expected_xml.split('\n'))+'\n'
 
897
        self.assertEqualDiff(expected_xml, out)
 
898
        self.assertEqual('', err)
 
899
 
 
900
        # Show info about repository with revisions
 
901
        out, err = self.run_bzr('xmlinfo -v repo')
 
902
        expected_xml = '''<?xml version="1.0"?>
 
903
<info>
 
904
<layout>Shared repository</layout>
 
905
<formats>
 
906
<format>dirstate</format>
 
907
<format>dirstate-tags</format>
 
908
<format>knit</format>
 
909
</formats>
 
910
<location>
 
911
<shared_repository>repo</shared_repository></location>
 
912
<format>
 
913
<control>Meta directory format 1</control>
 
914
<repository>%s</repository>
 
915
</format>
 
916
<repository_stats>
 
917
<revisions>2</revisions>
 
918
</repository_stats>
 
919
</info>
 
920
 
 
921
''' % (format.repository_format.get_format_description(),
 
922
       )
 
923
        expected_xml = ''.join(expected_xml.split('\n'))+'\n'
 
924
        self.assertEqualDiff(expected_xml, out)
 
925
        self.assertEqual('', err)
 
926
 
 
927
    def test_info_shared_repository_with_trees(self):
 
928
        format = bzrdir.format_registry.make_bzrdir('knit')
 
929
        transport = self.get_transport()
 
930
 
 
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"?>
 
936
<info>
 
937
<layout>Shared repository with trees</layout>
 
938
<formats>
 
939
<format>dirstate</format>
 
940
<format>dirstate-tags</format>
 
941
<format>knit</format>
 
942
</formats>
 
943
<location>
 
944
<shared_repository>repo</shared_repository></location>
 
945
<format>
 
946
<control>Meta directory format 1</control>
 
947
<repository>%s</repository>
 
948
</format>
 
949
<repository_stats>
 
950
<revisions>0</revisions>
 
951
</repository_stats>
 
952
</info>
 
953
 
 
954
''' % (format.repository_format.get_format_description(),
 
955
       )
 
956
        expected_xml = ''.join(expected_xml.split('\n'))+'\n'
 
957
        self.assertEqualDiff(expected_xml, out)
 
958
        self.assertEqual('', err)
 
959
 
 
960
        # Create two branches
 
961
        repo.bzrdir.root_transport.mkdir('branch1')
 
962
        branch1 = bzrdir.BzrDir.create_branch_convenience('repo/branch1',
 
963
            format=format)
 
964
        branch2 = branch1.bzrdir.sprout('repo/branch2').open_branch()
 
965
 
 
966
        # Empty first branch
 
967
        out, err = self.run_bzr('xmlinfo repo/branch1 --verbose')
 
968
        expected_xml = '''<?xml version="1.0"?>
 
969
<info>
 
970
<layout>Repository tree</layout>
 
971
<formats>
 
972
<format>knit</format>
 
973
</formats>
 
974
<location>
 
975
<shared_repository>repo</shared_repository><repository_branch>repo/branch1</repository_branch></location>
 
976
<format>
 
977
<control>Meta directory format 1</control>
 
978
<working_tree>Working tree format 3</working_tree>
 
979
<branch>%s</branch>
 
980
<repository>%s</repository>
 
981
</format>
 
982
<working_tree_stats>
 
983
<unchanged>0</unchanged>
 
984
<modified>0</modified>
 
985
<added>0</added>
 
986
<removed>0</removed>
 
987
<renamed>0</renamed>
 
988
<unknown>0</unknown>
 
989
<ignored>0</ignored>
 
990
<versioned_subdirectories>0</versioned_subdirectories>
 
991
</working_tree_stats>
 
992
<branch_history>
 
993
<revisions>0</revisions>
 
994
<committers>0</committers>
 
995
</branch_history>
 
996
<repository_stats>
 
997
<revisions>0</revisions>
 
998
</repository_stats>
 
999
</info>
 
1000
 
 
1001
''' % (format.get_branch_format().get_format_description(),
 
1002
       format.repository_format.get_format_description(),
 
1003
       )
 
1004
        expected_xml = ''.join(expected_xml.split('\n'))+'\n'
 
1005
        self.assertEqualDiff(expected_xml, out)
 
1006
        self.assertEqual('', err)
 
1007
 
 
1008
        # Update first branch
 
1009
        self.build_tree(['repo/branch1/a'])
 
1010
        tree1 = branch1.bzrdir.open_workingtree()
 
1011
        tree1.add('a')
 
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"?>
 
1017
<info>
 
1018
<layout>Repository tree</layout>
 
1019
<formats>
 
1020
<format>knit</format>
 
1021
</formats>
 
1022
<location>
 
1023
<shared_repository>repo</shared_repository><repository_branch>repo/branch1</repository_branch></location>
 
1024
<format>
 
1025
<control>Meta directory format 1</control>
 
1026
<working_tree>Working tree format 3</working_tree>
 
1027
<branch>%s</branch>
 
1028
<repository>%s</repository>
 
1029
</format>
 
1030
<working_tree_stats>
 
1031
<unchanged>1</unchanged>
 
1032
<modified>0</modified>
 
1033
<added>0</added>
 
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>
 
1040
<branch_history>
 
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>
 
1046
</branch_history>
 
1047
<repository_stats>
 
1048
<revisions>1</revisions>
 
1049
</repository_stats>
 
1050
</info>
 
1051
 
 
1052
'''  % (format.get_branch_format().get_format_description(),
 
1053
       format.repository_format.get_format_description(),
 
1054
       datestring_first, datestring_first,
 
1055
       )
 
1056
        expected_xml = ''.join(expected_xml.split('\n'))+'\n'
 
1057
        self.assertEqualDiff(expected_xml, out)
 
1058
        self.assertEqual('', err)
 
1059
 
 
1060
        # Out of date second branch
 
1061
        out, err = self.run_bzr('xmlinfo repo/branch2 --verbose')
 
1062
        expected_xml = '''<?xml version="1.0"?>
 
1063
<info>
 
1064
<layout>Repository tree</layout>
 
1065
<formats>
 
1066
<format>knit</format>
 
1067
</formats>
 
1068
<location>
 
1069
<shared_repository>repo</shared_repository><repository_branch>repo/branch2</repository_branch></location>
 
1070
<related_branches>
 
1071
<parent_branch>repo/branch1</parent_branch></related_branches>
 
1072
<format>
 
1073
<control>Meta directory format 1</control>
 
1074
<working_tree>Working tree format 3</working_tree>
 
1075
<branch>%s</branch>
 
1076
<repository>%s</repository>
 
1077
</format>
 
1078
<working_tree_stats>
 
1079
<unchanged>0</unchanged>
 
1080
<modified>0</modified>
 
1081
<added>0</added>
 
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>
 
1088
<branch_history>
 
1089
<revisions>0</revisions>
 
1090
<committers>0</committers>
 
1091
</branch_history>
 
1092
<repository_stats>
 
1093
<revisions>1</revisions>
 
1094
</repository_stats>
 
1095
</info>
 
1096
 
 
1097
''' % (format.get_branch_format().get_format_description(),
 
1098
       format.repository_format.get_format_description(),
 
1099
       )
 
1100
        expected_xml = ''.join(expected_xml.split('\n'))+'\n'
 
1101
        self.assertEqualDiff(expected_xml, out)
 
1102
        self.assertEqual('', err)
 
1103
 
 
1104
        # Update second branch
 
1105
        tree2 = branch2.bzrdir.open_workingtree()
 
1106
        tree2.pull(branch1)
 
1107
        out, err = self.run_bzr('xmlinfo -v repo/branch2')
 
1108
        expected_xml = '''<?xml version="1.0"?>
 
1109
<info>
 
1110
<layout>Repository tree</layout>
 
1111
<formats>
 
1112
<format>knit</format>
 
1113
</formats>
 
1114
<location>
 
1115
<shared_repository>repo</shared_repository><repository_branch>repo/branch2</repository_branch></location>
 
1116
<related_branches>
 
1117
<parent_branch>repo/branch1</parent_branch></related_branches>
 
1118
<format>
 
1119
<control>Meta directory format 1</control>
 
1120
<working_tree>Working tree format 3</working_tree>
 
1121
<branch>%s</branch>
 
1122
<repository>%s</repository>
 
1123
</format>
 
1124
<working_tree_stats>
 
1125
<unchanged>1</unchanged>
 
1126
<modified>0</modified>
 
1127
<added>0</added>
 
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>
 
1134
<branch_history>
 
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>
 
1140
</branch_history>
 
1141
<repository_stats>
 
1142
<revisions>1</revisions>
 
1143
</repository_stats>
 
1144
</info>
 
1145
 
 
1146
''' % (format.get_branch_format().get_format_description(),
 
1147
       format.repository_format.get_format_description(),
 
1148
       datestring_first, datestring_first,
 
1149
       )
 
1150
        expected_xml = ''.join(expected_xml.split('\n'))+'\n'
 
1151
        self.assertEqualDiff(expected_xml, out)
 
1152
        self.assertEqual('', err)
 
1153
 
 
1154
        # Show info about repository with revisions
 
1155
        out, err = self.run_bzr('xmlinfo -v repo')
 
1156
        expected_xml = '''<?xml version="1.0"?>
 
1157
<info>
 
1158
<layout>Shared repository with trees</layout>
 
1159
<formats>
 
1160
<format>dirstate</format>
 
1161
<format>dirstate-tags</format>
 
1162
<format>knit</format>
 
1163
</formats>
 
1164
<location>
 
1165
<shared_repository>repo</shared_repository></location>
 
1166
<format>
 
1167
<control>Meta directory format 1</control>
 
1168
<repository>%s</repository>
 
1169
</format>
 
1170
<repository_stats>
 
1171
<revisions>1</revisions>
 
1172
</repository_stats>
 
1173
</info>
 
1174
 
 
1175
''' % (format.repository_format.get_format_description(),
 
1176
       )
 
1177
        expected_xml = ''.join(expected_xml.split('\n'))+'\n'
 
1178
        self.assertEqualDiff(expected_xml, out)
 
1179
        self.assertEqual('', err)
 
1180
 
 
1181
    def test_info_shared_repository_with_tree_in_root(self):
 
1182
        format = bzrdir.format_registry.make_bzrdir('knit')
 
1183
        transport = self.get_transport()
 
1184
 
 
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"?>
 
1190
<info>
 
1191
<layout>Shared repository with trees</layout>
 
1192
<formats>
 
1193
<format>dirstate</format>
 
1194
<format>dirstate-tags</format>
 
1195
<format>knit</format>
 
1196
</formats>
 
1197
<location>
 
1198
<shared_repository>repo</shared_repository></location>
 
1199
<format>
 
1200
<control>Meta directory format 1</control>
 
1201
<repository>%s</repository>
 
1202
</format>
 
1203
<repository_stats>
 
1204
<revisions>0</revisions>
 
1205
</repository_stats>
 
1206
</info>
 
1207
 
 
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)
 
1212
 
 
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"?>
 
1219
<info>
 
1220
<layout>Repository tree</layout>
 
1221
<formats>
 
1222
<format>knit</format>
 
1223
</formats>
 
1224
<location>
 
1225
<shared_repository>repo</shared_repository><repository_branch>repo</repository_branch></location>
 
1226
<format>
 
1227
<control>Meta directory format 1</control>
 
1228
<working_tree>Working tree format 3</working_tree>
 
1229
<branch>%s</branch>
 
1230
<repository>%s</repository>
 
1231
</format>
 
1232
<working_tree_stats>
 
1233
<unchanged>0</unchanged>
 
1234
<modified>0</modified>
 
1235
<added>0</added>
 
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>
 
1242
<branch_history>
 
1243
<revisions>0</revisions>
 
1244
<committers>0</committers>
 
1245
</branch_history>
 
1246
<repository_stats>
 
1247
<revisions>0</revisions>
 
1248
</repository_stats>
 
1249
</info>
 
1250
 
 
1251
''' % (format.get_branch_format().get_format_description(),
 
1252
       format.repository_format.get_format_description(),
 
1253
       )
 
1254
        expected_xml = ''.join(expected_xml.split('\n'))+'\n'
 
1255
        self.assertEqualDiff(expected_xml, out)
 
1256
        self.assertEqual('', err)
 
1257
 
 
1258
    def assertCheckoutStatusOutput(self,
 
1259
        command_string, lco_tree, shared_repo=None,
 
1260
        repo_branch=None,
 
1261
        tree_locked=False,
 
1262
        branch_locked=False, repo_locked=False,
 
1263
        verbose=False,
 
1264
        light_checkout=True,
 
1265
        checkout_root=None):
 
1266
        """Check the output of info in a checkout.
 
1267
 
 
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
 
1272
        tests.
 
1273
 
 
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
 
1277
            the output.
 
1278
        :param repo_branch: A branch in a shared repository for non light
 
1279
            checkouts.
 
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
 
1284
        """
 
1285
        def friendly_location(url):
 
1286
            path = urlutils.unescape_for_display(url, 'ascii')
 
1287
            try:
 
1288
                return osutils.relpath(osutils.getcwd(), path)
 
1289
            except errors.PathNotChild:
 
1290
                return path
 
1291
 
 
1292
        if tree_locked:
 
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)
 
1296
            return
 
1297
        out, err = self.run_bzr('xmlinfo %s' % command_string)
 
1298
        description = {
 
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]
 
1306
        if repo_locked:
 
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):
 
1310
                if a_bool:
 
1311
                    return 'locked'
 
1312
                else:
 
1313
                    return 'unlocked'
 
1314
            expected_lock_output = (
 
1315
                "\n<lock_status>\n"
 
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)))
 
1323
        else:
 
1324
            expected_lock_output = ''
 
1325
        tree_data = ''
 
1326
        extra_space = ''
 
1327
        if light_checkout:
 
1328
            tree_data = ("<light_checkout_root>%s</light_checkout_root>" %
 
1329
                friendly_location(lco_tree.bzrdir.root_transport.base))
 
1330
            extra_space = ' '
 
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:
 
1335
            branch_data = (
 
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)))
 
1343
        else:
 
1344
            branch_data = ("<checkout_of_branch>%s</checkout_of_branch>" %
 
1345
                lco_tree.branch.bzrdir.root_transport.base)
 
1346
 
 
1347
        if verbose:
 
1348
            verbose_info = '<committers>0</committers>'
 
1349
        else:
 
1350
            verbose_info = ''
 
1351
 
 
1352
        expected_xml = '''<?xml version="1.0"?>
 
1353
<info>
 
1354
<layout>%s</layout>
 
1355
<formats>
 
1356
%s
 
1357
</formats>
 
1358
<location>
 
1359
%s%s</location>
 
1360
<format>
 
1361
<control>Meta directory format 1</control>
 
1362
<working_tree>%s</working_tree>
 
1363
<branch>%s</branch>
 
1364
<repository>%s</repository>
 
1365
</format>%s
 
1366
<working_tree_stats>
 
1367
<unchanged>0</unchanged>
 
1368
<modified>0</modified>
 
1369
<added>0</added>
 
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>
 
1376
<branch_history>
 
1377
<revisions>0</revisions>
 
1378
%s
 
1379
</branch_history>
 
1380
<repository_stats>
 
1381
<revisions>0</revisions>
 
1382
</repository_stats>
 
1383
</info>
 
1384
 
 
1385
'''  %  (description,
 
1386
        format,
 
1387
        tree_data,
 
1388
        branch_data,
 
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,
 
1393
        verbose_info,
 
1394
        )
 
1395
        expected_xml = ''.join(expected_xml.split('\n'))+'\n'
 
1396
        self.assertEqualDiff(expected_xml, out)
 
1397
        self.assertEqual('', err)
 
1398
 
 
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()
 
1421
 
 
1422
        # Test all permutations of locking the working tree, branch and repository
 
1423
        # W B R
 
1424
 
 
1425
        # U U U
 
1426
        self.assertCheckoutStatusOutput('-v tree/lightcheckout', lco_tree,
 
1427
                                        repo_branch=repo_branch,
 
1428
                                        verbose=True, light_checkout=True)
 
1429
        # U U L
 
1430
        lco_tree.branch.repository.lock_write()
 
1431
        try:
 
1432
            self.assertCheckoutStatusOutput('-v tree/lightcheckout',
 
1433
            lco_tree, repo_branch=repo_branch,
 
1434
            repo_locked=True, verbose=True, light_checkout=True)
 
1435
        finally:
 
1436
            lco_tree.branch.repository.unlock()
 
1437
        # U L L
 
1438
        lco_tree.branch.lock_write()
 
1439
        try:
 
1440
            self.assertCheckoutStatusOutput('-v tree/lightcheckout',
 
1441
            lco_tree,
 
1442
            branch_locked=True,
 
1443
            repo_locked=True,
 
1444
            repo_branch=repo_branch,
 
1445
            verbose=True)
 
1446
        finally:
 
1447
            lco_tree.branch.unlock()
 
1448
        # L L L
 
1449
        lco_tree.lock_write()
 
1450
        try:
 
1451
            self.assertCheckoutStatusOutput('-v tree/lightcheckout',
 
1452
            lco_tree, repo_branch=repo_branch,
 
1453
            tree_locked=True,
 
1454
            branch_locked=True,
 
1455
            repo_locked=True,
 
1456
            verbose=True)
 
1457
        finally:
 
1458
            lco_tree.unlock()
 
1459
        # L L U
 
1460
        lco_tree.lock_write()
 
1461
        lco_tree.branch.repository.unlock()
 
1462
        try:
 
1463
            self.assertCheckoutStatusOutput('-v tree/lightcheckout',
 
1464
            lco_tree, repo_branch=repo_branch,
 
1465
            tree_locked=True,
 
1466
            branch_locked=True,
 
1467
            verbose=True)
 
1468
        finally:
 
1469
            lco_tree.branch.repository.lock_write()
 
1470
            lco_tree.unlock()
 
1471
        # L U U
 
1472
        lco_tree.lock_write()
 
1473
        lco_tree.branch.unlock()
 
1474
        try:
 
1475
            self.assertCheckoutStatusOutput('-v tree/lightcheckout',
 
1476
            lco_tree, repo_branch=repo_branch,
 
1477
            tree_locked=True,
 
1478
            verbose=True)
 
1479
        finally:
 
1480
            lco_tree.branch.lock_write()
 
1481
            lco_tree.unlock()
 
1482
        # L U L
 
1483
        lco_tree.lock_write()
 
1484
        lco_tree.branch.unlock()
 
1485
        lco_tree.branch.repository.lock_write()
 
1486
        try:
 
1487
            self.assertCheckoutStatusOutput('-v tree/lightcheckout',
 
1488
            lco_tree, repo_branch=repo_branch,
 
1489
            tree_locked=True,
 
1490
            repo_locked=True,
 
1491
            verbose=True)
 
1492
        finally:
 
1493
            lco_tree.branch.repository.unlock()
 
1494
            lco_tree.branch.lock_write()
 
1495
            lco_tree.unlock()
 
1496
        # U L U
 
1497
        lco_tree.branch.lock_write()
 
1498
        lco_tree.branch.repository.unlock()
 
1499
        try:
 
1500
            self.assertCheckoutStatusOutput('-v tree/lightcheckout',
 
1501
            lco_tree, repo_branch=repo_branch,
 
1502
            branch_locked=True,
 
1503
            verbose=True)
 
1504
        finally:
 
1505
            lco_tree.branch.repository.lock_write()
 
1506
            lco_tree.branch.unlock()
 
1507
 
 
1508
        if sys.platform == 'win32':
 
1509
            self.knownFailure('Win32 cannot run "bzr info"'
 
1510
                              ' when the tree is locked.')
 
1511
 
 
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
 
1518
        # call here.
 
1519
        self.thisFailsStrictLockCheck()
 
1520
 
 
1521
        tree = self.make_branch_and_tree('branch', format='weave')
 
1522
 
 
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)
 
1527
        # W B R
 
1528
 
 
1529
        # U U U
 
1530
        out, err = self.run_bzr('xmlinfo -v branch')
 
1531
        expected_xml = '''<?xml version="1.0"?>
 
1532
<info>
 
1533
<layout>Standalone tree</layout>
 
1534
<formats>
 
1535
<format>weave</format>
 
1536
</formats>
 
1537
<location>
 
1538
<branch_root>%s</branch_root></location>
 
1539
<format>
 
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>
 
1544
</format>
 
1545
<working_tree_stats>
 
1546
<unchanged>0</unchanged>
 
1547
<modified>0</modified>
 
1548
<added>0</added>
 
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>
 
1555
<branch_history>
 
1556
<revisions>0</revisions>
 
1557
<committers>0</committers>
 
1558
</branch_history>
 
1559
<repository_stats>
 
1560
<revisions>0</revisions>
 
1561
</repository_stats>
 
1562
</info>
 
1563
 
 
1564
''' % ('branch', tree.branch.repository._format.get_format_description(),
 
1565
       )
 
1566
        expected_xml = ''.join(expected_xml.split('\n'))+'\n'
 
1567
        self.assertEqualDiff(expected_xml, out)
 
1568
        self.assertEqual('', err)
 
1569
        # L L L
 
1570
        tree.lock_write()
 
1571
        out, err = self.run_bzr('xmlinfo -v branch')
 
1572
        expected_xml = '''<?xml version="1.0"?>
 
1573
<info>
 
1574
<layout>Standalone tree</layout>
 
1575
<formats>
 
1576
<format>weave</format>
 
1577
</formats>
 
1578
<location>
 
1579
<branch_root>%s</branch_root></location>
 
1580
<format>
 
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>
 
1585
</format>
 
1586
<working_tree_stats>
 
1587
<unchanged>0</unchanged>
 
1588
<modified>0</modified>
 
1589
<added>0</added>
 
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>
 
1596
<branch_history>
 
1597
<revisions>0</revisions>
 
1598
<committers>0</committers>
 
1599
</branch_history>
 
1600
<repository_stats>
 
1601
<revisions>0</revisions>
 
1602
</repository_stats>
 
1603
</info>
 
1604
 
 
1605
'''% ('branch', tree.branch.repository._format.get_format_description(),
 
1606
       )
 
1607
        expected_xml = ''.join(expected_xml.split('\n'))+'\n'
 
1608
        self.assertEqualDiff(expected_xml, out)
 
1609
        self.assertEqual('', err)
 
1610
        tree.unlock()
 
1611
 
 
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"?>
 
1620
<info>
 
1621
<layout>Standalone tree</layout>
 
1622
<formats>
 
1623
<format>1.6</format>
 
1624
</formats>
 
1625
<location><branch_root>newbranch</branch_root></location>
 
1626
<related_branches>
 
1627
<parent_branch>mainline</parent_branch>
 
1628
<stacked_on>mainline</stacked_on>
 
1629
</related_branches>
 
1630
</info>'''
 
1631
        expected_xml = ''.join(expected_xml.split('\n'))+'\n'
 
1632
        self.assertEqual(expected_xml, out)
 
1633
        self.assertEqual("", err)
 
1634