/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/tests/blackbox/test_info.py

  • Committer: Jelmer Vernooij
  • Date: 2017-06-10 16:40:42 UTC
  • mfrom: (6653.6.7 rename-controldir)
  • mto: This revision was merged to the branch mainline in revision 6690.
  • Revision ID: jelmer@jelmer.uk-20170610164042-zrxqgy2htyduvke2
MergeĀ rename-controldirĀ branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2006-2012, 2016 Canonical Ltd
 
2
#
 
3
# This program is free software; you can redistribute it and/or modify
 
4
# it under the terms of the GNU General Public License as published by
 
5
# the Free Software Foundation; either version 2 of the License, or
 
6
# (at your option) any later version.
 
7
#
 
8
# This program is distributed in the hope that it will be useful,
 
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
# GNU General Public License for more details.
 
12
#
 
13
# You should have received a copy of the GNU General Public License
 
14
# along with this program; if not, write to the Free Software
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
16
 
 
17
 
 
18
"""Tests for the info command of bzr."""
 
19
 
 
20
import shutil
 
21
import sys
 
22
 
 
23
from breezy import (
 
24
    branch,
 
25
    controldir,
 
26
    errors,
 
27
    info,
 
28
    osutils,
 
29
    tests,
 
30
    upgrade,
 
31
    urlutils,
 
32
    )
 
33
from breezy.bzr import (
 
34
    bzrdir,
 
35
    )
 
36
from breezy.tests.matchers import ContainsNoVfsCalls
 
37
from breezy.transport import memory
 
38
 
 
39
 
 
40
class TestInfo(tests.TestCaseWithTransport):
 
41
 
 
42
    def setUp(self):
 
43
        super(TestInfo, self).setUp()
 
44
        self._repo_strings = "2a"
 
45
 
 
46
    def test_info_non_existing(self):
 
47
        self.vfs_transport_factory = memory.MemoryServer
 
48
        location = self.get_url()
 
49
        out, err = self.run_bzr('info '+location, retcode=3)
 
50
        self.assertEqual(out, '')
 
51
        self.assertEqual(err, 'brz: ERROR: Not a branch: "%s".\n' % location)
 
52
 
 
53
    def test_info_empty_controldir(self):
 
54
        self.make_controldir('ctrl')
 
55
        out, err = self.run_bzr('info ctrl')
 
56
        self.assertEqual(out,
 
57
            'Empty control directory (format: 2a or pack-0.92)\n'
 
58
            'Location:\n'
 
59
            '  control directory: ctrl\n')
 
60
        self.assertEqual(err, '')
 
61
 
 
62
    def test_info_empty_controldir_verbose(self):
 
63
        self.make_controldir('ctrl')
 
64
        out, err = self.run_bzr('info -v ctrl')
 
65
        self.assertEqualDiff(out,
 
66
            'Empty control directory (format: 2a or pack-0.92)\n'
 
67
            'Location:\n'
 
68
            '  control directory: ctrl\n\n'
 
69
            'Format:\n'
 
70
            '       control: Meta directory format 1\n\n'
 
71
            'Control directory:\n'
 
72
            '         0 branches\n')
 
73
        self.assertEqual(err, '')
 
74
 
 
75
    def test_info_dangling_branch_reference(self):
 
76
        br = self.make_branch('target')
 
77
        br.create_checkout('from', lightweight=True)
 
78
        shutil.rmtree('target')
 
79
        out, err = self.run_bzr('info from')
 
80
        self.assertEqual(out,
 
81
            'Dangling branch reference (format: 2a or pack-0.92)\n'
 
82
            'Location:\n'
 
83
            '   control directory: from\n'
 
84
            '  checkout of branch: target\n')
 
85
        self.assertEqual(err, '')
 
86
 
 
87
    def test_info_standalone(self):
 
88
        transport = self.get_transport()
 
89
 
 
90
        # Create initial standalone branch
 
91
        tree1 = self.make_branch_and_tree('standalone', 'knit')
 
92
        self.build_tree(['standalone/a'])
 
93
        tree1.add('a')
 
94
        branch1 = tree1.branch
 
95
 
 
96
        out, err = self.run_bzr('info standalone')
 
97
        self.assertEqualDiff(
 
98
"""Standalone tree (format: knit)
 
99
Location:
 
100
  branch root: standalone
 
101
""", out)
 
102
        self.assertEqual('', err)
 
103
 
 
104
        # Standalone branch - verbose mode
 
105
        out, err = self.run_bzr('info standalone -v')
 
106
        self.assertEqualDiff(
 
107
"""Standalone tree (format: knit)
 
108
Location:
 
109
  branch root: standalone
 
110
 
 
111
Format:
 
112
       control: Meta directory format 1
 
113
  working tree: Working tree format 3
 
114
        branch: Branch format 5
 
115
    repository: Knit repository format 1
 
116
 
 
117
Control directory:
 
118
         1 branches
 
119
 
 
120
In the working tree:
 
121
         0 unchanged
 
122
         0 modified
 
123
         1 added
 
124
         0 removed
 
125
         0 renamed
 
126
         0 unknown
 
127
         0 ignored
 
128
         0 versioned subdirectories
 
129
 
 
130
Branch history:
 
131
         0 revisions
 
132
 
 
133
Repository:
 
134
         0 revisions
 
135
""", out)
 
136
        self.assertEqual('', err)
 
137
 
 
138
        # Standalone branch - really verbose mode
 
139
        out, err = self.run_bzr('info standalone -vv')
 
140
        self.assertEqualDiff(
 
141
"""Standalone tree (format: knit)
 
142
Location:
 
143
  branch root: standalone
 
144
 
 
145
Format:
 
146
       control: Meta directory format 1
 
147
  working tree: Working tree format 3
 
148
        branch: Branch format 5
 
149
    repository: Knit repository format 1
 
150
 
 
151
Control directory:
 
152
         1 branches
 
153
 
 
154
In the working tree:
 
155
         0 unchanged
 
156
         0 modified
 
157
         1 added
 
158
         0 removed
 
159
         0 renamed
 
160
         0 unknown
 
161
         0 ignored
 
162
         0 versioned subdirectories
 
163
 
 
164
Branch history:
 
165
         0 revisions
 
166
         0 committers
 
167
 
 
168
Repository:
 
169
         0 revisions
 
170
""", out)
 
171
        self.assertEqual('', err)
 
172
        tree1.commit('commit one')
 
173
        rev = branch1.repository.get_revision(branch1.last_revision())
 
174
        datestring_first = osutils.format_date(rev.timestamp, rev.timezone)
 
175
 
 
176
        # Branch standalone with push location
 
177
        branch2 = branch1.controldir.sprout('branch').open_branch()
 
178
        branch2.set_push_location(branch1.controldir.root_transport.base)
 
179
 
 
180
        out, err = self.run_bzr('info branch')
 
181
        self.assertEqualDiff(
 
182
"""Standalone tree (format: knit)
 
183
Location:
 
184
  branch root: branch
 
185
 
 
186
Related branches:
 
187
    push branch: standalone
 
188
  parent branch: standalone
 
189
""", out)
 
190
        self.assertEqual('', err)
 
191
 
 
192
        out, err = self.run_bzr('info branch --verbose')
 
193
        self.assertEqualDiff(
 
194
"""Standalone tree (format: knit)
 
195
Location:
 
196
  branch root: branch
 
197
 
 
198
Related branches:
 
199
    push branch: standalone
 
200
  parent branch: standalone
 
201
 
 
202
Format:
 
203
       control: Meta directory format 1
 
204
  working tree: Working tree format 3
 
205
        branch: Branch format 5
 
206
    repository: Knit repository format 1
 
207
 
 
208
Control directory:
 
209
         1 branches
 
210
 
 
211
In the working tree:
 
212
         1 unchanged
 
213
         0 modified
 
214
         0 added
 
215
         0 removed
 
216
         0 renamed
 
217
         0 unknown
 
218
         0 ignored
 
219
         0 versioned subdirectories
 
220
 
 
221
Branch history:
 
222
         1 revision
 
223
         0 days old
 
224
   first revision: %s
 
225
  latest revision: %s
 
226
 
 
227
Repository:
 
228
         1 revision
 
229
""" % (datestring_first, datestring_first,
 
230
       ), out)
 
231
        self.assertEqual('', err)
 
232
 
 
233
        # Branch and bind to standalone, needs upgrade to metadir
 
234
        # (creates backup as unknown)
 
235
        branch1.controldir.sprout('bound')
 
236
        knit1_format = controldir.format_registry.make_controldir('knit')
 
237
        upgrade.upgrade('bound', knit1_format)
 
238
        branch3 = controldir.ControlDir.open('bound').open_branch()
 
239
        branch3.bind(branch1)
 
240
        bound_tree = branch3.controldir.open_workingtree()
 
241
        out, err = self.run_bzr('info -v bound')
 
242
        self.assertEqualDiff(
 
243
"""Checkout (format: knit)
 
244
Location:
 
245
       checkout root: bound
 
246
  checkout of branch: standalone
 
247
 
 
248
Related branches:
 
249
  parent branch: standalone
 
250
 
 
251
Format:
 
252
       control: Meta directory format 1
 
253
  working tree: %s
 
254
        branch: %s
 
255
    repository: %s
 
256
 
 
257
Control directory:
 
258
         1 branches
 
259
 
 
260
In the working tree:
 
261
         1 unchanged
 
262
         0 modified
 
263
         0 added
 
264
         0 removed
 
265
         0 renamed
 
266
         0 unknown
 
267
         0 ignored
 
268
         0 versioned subdirectories
 
269
 
 
270
Branch history:
 
271
         1 revision
 
272
         0 days old
 
273
   first revision: %s
 
274
  latest revision: %s
 
275
 
 
276
Repository:
 
277
         1 revision
 
278
""" % (bound_tree._format.get_format_description(),
 
279
       branch3._format.get_format_description(),
 
280
       branch3.repository._format.get_format_description(),
 
281
       datestring_first, datestring_first,
 
282
       ), out)
 
283
        self.assertEqual('', err)
 
284
 
 
285
        # Checkout standalone (same as above, but does not have parent set)
 
286
        branch4 = controldir.ControlDir.create_branch_convenience('checkout',
 
287
            format=knit1_format)
 
288
        branch4.bind(branch1)
 
289
        branch4.controldir.open_workingtree().update()
 
290
        out, err = self.run_bzr('info checkout --verbose')
 
291
        self.assertEqualDiff(
 
292
"""Checkout (format: knit)
 
293
Location:
 
294
       checkout root: checkout
 
295
  checkout of branch: standalone
 
296
 
 
297
Format:
 
298
       control: Meta directory format 1
 
299
  working tree: Working tree format 3
 
300
        branch: Branch format 5
 
301
    repository: %s
 
302
 
 
303
Control directory:
 
304
         1 branches
 
305
 
 
306
In the working tree:
 
307
         1 unchanged
 
308
         0 modified
 
309
         0 added
 
310
         0 removed
 
311
         0 renamed
 
312
         0 unknown
 
313
         0 ignored
 
314
         0 versioned subdirectories
 
315
 
 
316
Branch history:
 
317
         1 revision
 
318
         0 days old
 
319
   first revision: %s
 
320
  latest revision: %s
 
321
 
 
322
Repository:
 
323
         1 revision
 
324
""" % (branch4.repository._format.get_format_description(),
 
325
       datestring_first, datestring_first,
 
326
       ), out)
 
327
        self.assertEqual('', err)
 
328
 
 
329
        # Lightweight checkout (same as above, different branch and repository)
 
330
        tree5 = branch1.create_checkout('lightcheckout', lightweight=True)
 
331
        branch5 = tree5.branch
 
332
        out, err = self.run_bzr('info -v lightcheckout')
 
333
        if "metaweave" in controldir.format_registry:
 
334
            format_description = "knit or metaweave"
 
335
        else:
 
336
            format_description = "knit"
 
337
        self.assertEqualDiff(
 
338
"""Lightweight checkout (format: %s)
 
339
Location:
 
340
  light checkout root: lightcheckout
 
341
   checkout of branch: standalone
 
342
 
 
343
Format:
 
344
       control: Meta directory format 1
 
345
  working tree: Working tree format 3
 
346
        branch: Branch format 5
 
347
    repository: Knit repository format 1
 
348
 
 
349
Control directory:
 
350
         1 branches
 
351
 
 
352
In the working tree:
 
353
         1 unchanged
 
354
         0 modified
 
355
         0 added
 
356
         0 removed
 
357
         0 renamed
 
358
         0 unknown
 
359
         0 ignored
 
360
         0 versioned subdirectories
 
361
 
 
362
Branch history:
 
363
         1 revision
 
364
         0 days old
 
365
   first revision: %s
 
366
  latest revision: %s
 
367
 
 
368
Repository:
 
369
         1 revision
 
370
""" % (format_description, datestring_first, datestring_first,), out)
 
371
        self.assertEqual('', err)
 
372
 
 
373
        # Update initial standalone branch
 
374
        self.build_tree(['standalone/b'])
 
375
        tree1.add('b')
 
376
        tree1.commit('commit two')
 
377
        rev = branch1.repository.get_revision(branch1.last_revision())
 
378
        datestring_last = osutils.format_date(rev.timestamp, rev.timezone)
 
379
 
 
380
        # Out of date branched standalone branch will not be detected
 
381
        out, err = self.run_bzr('info -v branch')
 
382
        self.assertEqualDiff(
 
383
"""Standalone tree (format: knit)
 
384
Location:
 
385
  branch root: branch
 
386
 
 
387
Related branches:
 
388
    push branch: standalone
 
389
  parent branch: standalone
 
390
 
 
391
Format:
 
392
       control: Meta directory format 1
 
393
  working tree: Working tree format 3
 
394
        branch: Branch format 5
 
395
    repository: Knit repository format 1
 
396
 
 
397
Control directory:
 
398
         1 branches
 
399
 
 
400
In the working tree:
 
401
         1 unchanged
 
402
         0 modified
 
403
         0 added
 
404
         0 removed
 
405
         0 renamed
 
406
         0 unknown
 
407
         0 ignored
 
408
         0 versioned subdirectories
 
409
 
 
410
Branch history:
 
411
         1 revision
 
412
         0 days old
 
413
   first revision: %s
 
414
  latest revision: %s
 
415
 
 
416
Repository:
 
417
         1 revision
 
418
""" % (datestring_first, datestring_first,
 
419
       ), out)
 
420
        self.assertEqual('', err)
 
421
 
 
422
        # Out of date bound branch
 
423
        out, err = self.run_bzr('info -v bound')
 
424
        self.assertEqualDiff(
 
425
"""Checkout (format: knit)
 
426
Location:
 
427
       checkout root: bound
 
428
  checkout of branch: standalone
 
429
 
 
430
Related branches:
 
431
  parent branch: standalone
 
432
 
 
433
Format:
 
434
       control: Meta directory format 1
 
435
  working tree: Working tree format 3
 
436
        branch: Branch format 5
 
437
    repository: %s
 
438
 
 
439
Control directory:
 
440
         1 branches
 
441
 
 
442
Branch is out of date: missing 1 revision.
 
443
 
 
444
In the working tree:
 
445
         1 unchanged
 
446
         0 modified
 
447
         0 added
 
448
         0 removed
 
449
         0 renamed
 
450
         0 unknown
 
451
         0 ignored
 
452
         0 versioned subdirectories
 
453
 
 
454
Branch history:
 
455
         1 revision
 
456
         0 days old
 
457
   first revision: %s
 
458
  latest revision: %s
 
459
 
 
460
Repository:
 
461
         1 revision
 
462
""" % (branch3.repository._format.get_format_description(),
 
463
       datestring_first, datestring_first,
 
464
       ), out)
 
465
        self.assertEqual('', err)
 
466
 
 
467
        # Out of date checkout
 
468
        out, err = self.run_bzr('info -v checkout')
 
469
        self.assertEqualDiff(
 
470
"""Checkout (format: knit)
 
471
Location:
 
472
       checkout root: checkout
 
473
  checkout of branch: standalone
 
474
 
 
475
Format:
 
476
       control: Meta directory format 1
 
477
  working tree: Working tree format 3
 
478
        branch: Branch format 5
 
479
    repository: %s
 
480
 
 
481
Control directory:
 
482
         1 branches
 
483
 
 
484
Branch is out of date: missing 1 revision.
 
485
 
 
486
In the working tree:
 
487
         1 unchanged
 
488
         0 modified
 
489
         0 added
 
490
         0 removed
 
491
         0 renamed
 
492
         0 unknown
 
493
         0 ignored
 
494
         0 versioned subdirectories
 
495
 
 
496
Branch history:
 
497
         1 revision
 
498
         0 days old
 
499
   first revision: %s
 
500
  latest revision: %s
 
501
 
 
502
Repository:
 
503
         1 revision
 
504
""" % (branch4.repository._format.get_format_description(),
 
505
       datestring_first, datestring_first,
 
506
       ), out)
 
507
        self.assertEqual('', err)
 
508
 
 
509
        # Out of date lightweight checkout
 
510
        out, err = self.run_bzr('info lightcheckout --verbose')
 
511
        self.assertEqualDiff(
 
512
"""Lightweight checkout (format: %s)
 
513
Location:
 
514
  light checkout root: lightcheckout
 
515
   checkout of branch: standalone
 
516
 
 
517
Format:
 
518
       control: Meta directory format 1
 
519
  working tree: Working tree format 3
 
520
        branch: Branch format 5
 
521
    repository: Knit repository format 1
 
522
 
 
523
Control directory:
 
524
         1 branches
 
525
 
 
526
Working tree is out of date: missing 1 revision.
 
527
 
 
528
In the working tree:
 
529
         1 unchanged
 
530
         0 modified
 
531
         0 added
 
532
         0 removed
 
533
         0 renamed
 
534
         0 unknown
 
535
         0 ignored
 
536
         0 versioned subdirectories
 
537
 
 
538
Branch history:
 
539
         2 revisions
 
540
         0 days old
 
541
   first revision: %s
 
542
  latest revision: %s
 
543
 
 
544
Repository:
 
545
         2 revisions
 
546
""" % (format_description, datestring_first, datestring_last,), out)
 
547
        self.assertEqual('', err)
 
548
 
 
549
    def test_info_standalone_no_tree(self):
 
550
        # create standalone branch without a working tree
 
551
        format = controldir.format_registry.make_controldir('default')
 
552
        branch = self.make_branch('branch')
 
553
        repo = branch.repository
 
554
        out, err = self.run_bzr('info branch -v')
 
555
        self.assertEqualDiff(
 
556
"""Standalone branch (format: %s)
 
557
Location:
 
558
  branch root: branch
 
559
 
 
560
Format:
 
561
       control: Meta directory format 1
 
562
        branch: %s
 
563
    repository: %s
 
564
 
 
565
Control directory:
 
566
         1 branches
 
567
 
 
568
Branch history:
 
569
         0 revisions
 
570
 
 
571
Repository:
 
572
         0 revisions
 
573
""" % (info.describe_format(repo.controldir, repo, branch, None),
 
574
       format.get_branch_format().get_format_description(),
 
575
       format.repository_format.get_format_description(),
 
576
       ), out)
 
577
        self.assertEqual('', err)
 
578
 
 
579
    def test_info_shared_repository(self):
 
580
        format = controldir.format_registry.make_controldir('knit')
 
581
        transport = self.get_transport()
 
582
 
 
583
        # Create shared repository
 
584
        repo = self.make_repository('repo', shared=True, format=format)
 
585
        repo.set_make_working_trees(False)
 
586
        out, err = self.run_bzr('info -v repo')
 
587
        self.assertEqualDiff(
 
588
"""Shared repository (format: dirstate or dirstate-tags or knit)
 
589
Location:
 
590
  shared repository: %s
 
591
 
 
592
Format:
 
593
       control: Meta directory format 1
 
594
    repository: %s
 
595
 
 
596
Control directory:
 
597
         0 branches
 
598
 
 
599
Repository:
 
600
         0 revisions
 
601
""" % ('repo', format.repository_format.get_format_description(),
 
602
       ), out)
 
603
        self.assertEqual('', err)
 
604
 
 
605
        # Create branch inside shared repository
 
606
        repo.controldir.root_transport.mkdir('branch')
 
607
        branch1 = controldir.ControlDir.create_branch_convenience(
 
608
            'repo/branch', format=format)
 
609
        out, err = self.run_bzr('info -v repo/branch')
 
610
        self.assertEqualDiff(
 
611
"""Repository branch (format: dirstate or knit)
 
612
Location:
 
613
  shared repository: repo
 
614
  repository branch: repo/branch
 
615
 
 
616
Format:
 
617
       control: Meta directory format 1
 
618
        branch: %s
 
619
    repository: %s
 
620
 
 
621
Control directory:
 
622
         1 branches
 
623
 
 
624
Branch history:
 
625
         0 revisions
 
626
 
 
627
Repository:
 
628
         0 revisions
 
629
""" % (format.get_branch_format().get_format_description(),
 
630
       format.repository_format.get_format_description(),
 
631
       ), out)
 
632
        self.assertEqual('', err)
 
633
 
 
634
        # Create lightweight checkout
 
635
        transport.mkdir('tree')
 
636
        transport.mkdir('tree/lightcheckout')
 
637
        tree2 = branch1.create_checkout('tree/lightcheckout',
 
638
            lightweight=True)
 
639
        branch2 = tree2.branch
 
640
        self.assertCheckoutStatusOutput('-v tree/lightcheckout', tree2,
 
641
                   shared_repo=repo, repo_branch=branch1, verbose=True)
 
642
 
 
643
        # Create normal checkout
 
644
        tree3 = branch1.create_checkout('tree/checkout')
 
645
        self.assertCheckoutStatusOutput('tree/checkout --verbose', tree3,
 
646
            verbose=True,
 
647
            light_checkout=False, repo_branch=branch1)
 
648
        # Update lightweight checkout
 
649
        self.build_tree(['tree/lightcheckout/a'])
 
650
        tree2.add('a')
 
651
        tree2.commit('commit one')
 
652
        rev = repo.get_revision(branch2.last_revision())
 
653
        datestring_first = osutils.format_date(rev.timestamp, rev.timezone)
 
654
        out, err = self.run_bzr('info tree/lightcheckout --verbose')
 
655
        self.assertEqualDiff(
 
656
"""Lightweight checkout (format: %s)
 
657
Location:
 
658
  light checkout root: tree/lightcheckout
 
659
   checkout of branch: repo/branch
 
660
    shared repository: repo
 
661
 
 
662
Format:
 
663
       control: Meta directory format 1
 
664
  working tree: Working tree format 6
 
665
        branch: %s
 
666
    repository: %s
 
667
 
 
668
Control directory:
 
669
         1 branches
 
670
 
 
671
In the working tree:
 
672
         1 unchanged
 
673
         0 modified
 
674
         0 added
 
675
         0 removed
 
676
         0 renamed
 
677
         0 unknown
 
678
         0 ignored
 
679
         0 versioned subdirectories
 
680
 
 
681
Branch history:
 
682
         1 revision
 
683
         0 days old
 
684
   first revision: %s
 
685
  latest revision: %s
 
686
 
 
687
Repository:
 
688
         1 revision
 
689
""" % (self._repo_strings, format.get_branch_format().get_format_description(),
 
690
       format.repository_format.get_format_description(),
 
691
       datestring_first, datestring_first,
 
692
       ), out)
 
693
        self.assertEqual('', err)
 
694
 
 
695
        # Out of date checkout
 
696
        out, err = self.run_bzr('info -v tree/checkout')
 
697
        self.assertEqualDiff(
 
698
"""Checkout (format: unnamed)
 
699
Location:
 
700
       checkout root: tree/checkout
 
701
  checkout of branch: repo/branch
 
702
 
 
703
Format:
 
704
       control: Meta directory format 1
 
705
  working tree: Working tree format 6
 
706
        branch: %s
 
707
    repository: %s
 
708
 
 
709
Control directory:
 
710
         1 branches
 
711
 
 
712
Branch is out of date: missing 1 revision.
 
713
 
 
714
In the working tree:
 
715
         0 unchanged
 
716
         0 modified
 
717
         0 added
 
718
         0 removed
 
719
         0 renamed
 
720
         0 unknown
 
721
         0 ignored
 
722
         0 versioned subdirectories
 
723
 
 
724
Branch history:
 
725
         0 revisions
 
726
 
 
727
Repository:
 
728
         0 revisions
 
729
""" % (format.get_branch_format().get_format_description(),
 
730
       format.repository_format.get_format_description(),
 
731
       ), out)
 
732
        self.assertEqual('', err)
 
733
 
 
734
        # Update checkout
 
735
        tree3.update()
 
736
        self.build_tree(['tree/checkout/b'])
 
737
        tree3.add('b')
 
738
        out, err = self.run_bzr('info tree/checkout --verbose')
 
739
        self.assertEqualDiff(
 
740
"""Checkout (format: unnamed)
 
741
Location:
 
742
       checkout root: tree/checkout
 
743
  checkout of branch: repo/branch
 
744
 
 
745
Format:
 
746
       control: Meta directory format 1
 
747
  working tree: Working tree format 6
 
748
        branch: %s
 
749
    repository: %s
 
750
 
 
751
Control directory:
 
752
         1 branches
 
753
 
 
754
In the working tree:
 
755
         1 unchanged
 
756
         0 modified
 
757
         1 added
 
758
         0 removed
 
759
         0 renamed
 
760
         0 unknown
 
761
         0 ignored
 
762
         0 versioned subdirectories
 
763
 
 
764
Branch history:
 
765
         1 revision
 
766
         0 days old
 
767
   first revision: %s
 
768
  latest revision: %s
 
769
 
 
770
Repository:
 
771
         1 revision
 
772
""" % (format.get_branch_format().get_format_description(),
 
773
       format.repository_format.get_format_description(),
 
774
       datestring_first, datestring_first,
 
775
       ), out)
 
776
        self.assertEqual('', err)
 
777
        tree3.commit('commit two')
 
778
 
 
779
        # Out of date lightweight checkout
 
780
        rev = repo.get_revision(branch1.last_revision())
 
781
        datestring_last = osutils.format_date(rev.timestamp, rev.timezone)
 
782
        out, err = self.run_bzr('info tree/lightcheckout --verbose')
 
783
        self.assertEqualDiff(
 
784
"""Lightweight checkout (format: %s)
 
785
Location:
 
786
  light checkout root: tree/lightcheckout
 
787
   checkout of branch: repo/branch
 
788
    shared repository: repo
 
789
 
 
790
Format:
 
791
       control: Meta directory format 1
 
792
  working tree: Working tree format 6
 
793
        branch: %s
 
794
    repository: %s
 
795
 
 
796
Control directory:
 
797
         1 branches
 
798
 
 
799
Working tree is out of date: missing 1 revision.
 
800
 
 
801
In the working tree:
 
802
         1 unchanged
 
803
         0 modified
 
804
         0 added
 
805
         0 removed
 
806
         0 renamed
 
807
         0 unknown
 
808
         0 ignored
 
809
         0 versioned subdirectories
 
810
 
 
811
Branch history:
 
812
         2 revisions
 
813
         0 days old
 
814
   first revision: %s
 
815
  latest revision: %s
 
816
 
 
817
Repository:
 
818
         2 revisions
 
819
""" % (self._repo_strings, format.get_branch_format().get_format_description(),
 
820
       format.repository_format.get_format_description(),
 
821
       datestring_first, datestring_last,
 
822
       ), out)
 
823
        self.assertEqual('', err)
 
824
 
 
825
        # Show info about shared branch
 
826
        out, err = self.run_bzr('info repo/branch --verbose')
 
827
        self.assertEqualDiff(
 
828
"""Repository branch (format: dirstate or knit)
 
829
Location:
 
830
  shared repository: repo
 
831
  repository branch: repo/branch
 
832
 
 
833
Format:
 
834
       control: Meta directory format 1
 
835
        branch: %s
 
836
    repository: %s
 
837
 
 
838
Control directory:
 
839
         1 branches
 
840
 
 
841
Branch history:
 
842
         2 revisions
 
843
         0 days old
 
844
   first revision: %s
 
845
  latest revision: %s
 
846
 
 
847
Repository:
 
848
         2 revisions
 
849
""" % (format.get_branch_format().get_format_description(),
 
850
       format.repository_format.get_format_description(),
 
851
       datestring_first, datestring_last,
 
852
       ), out)
 
853
        self.assertEqual('', err)
 
854
 
 
855
        # Show info about repository with revisions
 
856
        out, err = self.run_bzr('info -v repo')
 
857
        self.assertEqualDiff(
 
858
"""Shared repository (format: dirstate or dirstate-tags or knit)
 
859
Location:
 
860
  shared repository: repo
 
861
 
 
862
Format:
 
863
       control: Meta directory format 1
 
864
    repository: %s
 
865
 
 
866
Control directory:
 
867
         0 branches
 
868
 
 
869
Repository:
 
870
         2 revisions
 
871
""" % (format.repository_format.get_format_description(),
 
872
       ), out)
 
873
        self.assertEqual('', err)
 
874
 
 
875
    def test_info_shared_repository_with_trees(self):
 
876
        format = controldir.format_registry.make_controldir('knit')
 
877
        transport = self.get_transport()
 
878
 
 
879
        # Create shared repository with working trees
 
880
        repo = self.make_repository('repo', shared=True, format=format)
 
881
        repo.set_make_working_trees(True)
 
882
        out, err = self.run_bzr('info -v repo')
 
883
        self.assertEqualDiff(
 
884
"""Shared repository with trees (format: dirstate or dirstate-tags or knit)
 
885
Location:
 
886
  shared repository: repo
 
887
 
 
888
Format:
 
889
       control: Meta directory format 1
 
890
    repository: %s
 
891
 
 
892
Control directory:
 
893
         0 branches
 
894
 
 
895
Create working tree for new branches inside the repository.
 
896
 
 
897
Repository:
 
898
         0 revisions
 
899
""" % (format.repository_format.get_format_description(),
 
900
       ), out)
 
901
        self.assertEqual('', err)
 
902
 
 
903
        # Create two branches
 
904
        repo.controldir.root_transport.mkdir('branch1')
 
905
        branch1 = controldir.ControlDir.create_branch_convenience('repo/branch1',
 
906
            format=format)
 
907
        branch2 = branch1.controldir.sprout('repo/branch2').open_branch()
 
908
 
 
909
        # Empty first branch
 
910
        out, err = self.run_bzr('info repo/branch1 --verbose')
 
911
        self.assertEqualDiff(
 
912
"""Repository tree (format: knit)
 
913
Location:
 
914
  shared repository: repo
 
915
  repository branch: repo/branch1
 
916
 
 
917
Format:
 
918
       control: Meta directory format 1
 
919
  working tree: Working tree format 3
 
920
        branch: %s
 
921
    repository: %s
 
922
 
 
923
Control directory:
 
924
         1 branches
 
925
 
 
926
In the working tree:
 
927
         0 unchanged
 
928
         0 modified
 
929
         0 added
 
930
         0 removed
 
931
         0 renamed
 
932
         0 unknown
 
933
         0 ignored
 
934
         0 versioned subdirectories
 
935
 
 
936
Branch history:
 
937
         0 revisions
 
938
 
 
939
Repository:
 
940
         0 revisions
 
941
""" % (format.get_branch_format().get_format_description(),
 
942
       format.repository_format.get_format_description(),
 
943
       ), out)
 
944
        self.assertEqual('', err)
 
945
 
 
946
        # Update first branch
 
947
        self.build_tree(['repo/branch1/a'])
 
948
        tree1 = branch1.controldir.open_workingtree()
 
949
        tree1.add('a')
 
950
        tree1.commit('commit one')
 
951
        rev = repo.get_revision(branch1.last_revision())
 
952
        datestring_first = osutils.format_date(rev.timestamp, rev.timezone)
 
953
        out, err = self.run_bzr('info -v repo/branch1')
 
954
        self.assertEqualDiff(
 
955
"""Repository tree (format: knit)
 
956
Location:
 
957
  shared repository: repo
 
958
  repository branch: repo/branch1
 
959
 
 
960
Format:
 
961
       control: Meta directory format 1
 
962
  working tree: Working tree format 3
 
963
        branch: %s
 
964
    repository: %s
 
965
 
 
966
Control directory:
 
967
         1 branches
 
968
 
 
969
In the working tree:
 
970
         1 unchanged
 
971
         0 modified
 
972
         0 added
 
973
         0 removed
 
974
         0 renamed
 
975
         0 unknown
 
976
         0 ignored
 
977
         0 versioned subdirectories
 
978
 
 
979
Branch history:
 
980
         1 revision
 
981
         0 days old
 
982
   first revision: %s
 
983
  latest revision: %s
 
984
 
 
985
Repository:
 
986
         1 revision
 
987
""" % (format.get_branch_format().get_format_description(),
 
988
       format.repository_format.get_format_description(),
 
989
       datestring_first, datestring_first,
 
990
       ), out)
 
991
        self.assertEqual('', err)
 
992
 
 
993
        # Out of date second branch
 
994
        out, err = self.run_bzr('info repo/branch2 --verbose')
 
995
        self.assertEqualDiff(
 
996
"""Repository tree (format: knit)
 
997
Location:
 
998
  shared repository: repo
 
999
  repository branch: repo/branch2
 
1000
 
 
1001
Related branches:
 
1002
  parent branch: repo/branch1
 
1003
 
 
1004
Format:
 
1005
       control: Meta directory format 1
 
1006
  working tree: Working tree format 3
 
1007
        branch: %s
 
1008
    repository: %s
 
1009
 
 
1010
Control directory:
 
1011
         1 branches
 
1012
 
 
1013
In the working tree:
 
1014
         0 unchanged
 
1015
         0 modified
 
1016
         0 added
 
1017
         0 removed
 
1018
         0 renamed
 
1019
         0 unknown
 
1020
         0 ignored
 
1021
         0 versioned subdirectories
 
1022
 
 
1023
Branch history:
 
1024
         0 revisions
 
1025
 
 
1026
Repository:
 
1027
         1 revision
 
1028
""" % (format.get_branch_format().get_format_description(),
 
1029
       format.repository_format.get_format_description(),
 
1030
       ), out)
 
1031
        self.assertEqual('', err)
 
1032
 
 
1033
        # Update second branch
 
1034
        tree2 = branch2.controldir.open_workingtree()
 
1035
        tree2.pull(branch1)
 
1036
        out, err = self.run_bzr('info -v repo/branch2')
 
1037
        self.assertEqualDiff(
 
1038
"""Repository tree (format: knit)
 
1039
Location:
 
1040
  shared repository: repo
 
1041
  repository branch: repo/branch2
 
1042
 
 
1043
Related branches:
 
1044
  parent branch: repo/branch1
 
1045
 
 
1046
Format:
 
1047
       control: Meta directory format 1
 
1048
  working tree: Working tree format 3
 
1049
        branch: %s
 
1050
    repository: %s
 
1051
 
 
1052
Control directory:
 
1053
         1 branches
 
1054
 
 
1055
In the working tree:
 
1056
         1 unchanged
 
1057
         0 modified
 
1058
         0 added
 
1059
         0 removed
 
1060
         0 renamed
 
1061
         0 unknown
 
1062
         0 ignored
 
1063
         0 versioned subdirectories
 
1064
 
 
1065
Branch history:
 
1066
         1 revision
 
1067
         0 days old
 
1068
   first revision: %s
 
1069
  latest revision: %s
 
1070
 
 
1071
Repository:
 
1072
         1 revision
 
1073
""" % (format.get_branch_format().get_format_description(),
 
1074
       format.repository_format.get_format_description(),
 
1075
       datestring_first, datestring_first,
 
1076
       ), out)
 
1077
        self.assertEqual('', err)
 
1078
 
 
1079
        # Show info about repository with revisions
 
1080
        out, err = self.run_bzr('info -v repo')
 
1081
        self.assertEqualDiff(
 
1082
"""Shared repository with trees (format: dirstate or dirstate-tags or knit)
 
1083
Location:
 
1084
  shared repository: repo
 
1085
 
 
1086
Format:
 
1087
       control: Meta directory format 1
 
1088
    repository: %s
 
1089
 
 
1090
Control directory:
 
1091
         0 branches
 
1092
 
 
1093
Create working tree for new branches inside the repository.
 
1094
 
 
1095
Repository:
 
1096
         1 revision
 
1097
""" % (format.repository_format.get_format_description(),
 
1098
       ),
 
1099
       out)
 
1100
        self.assertEqual('', err)
 
1101
 
 
1102
    def test_info_shared_repository_with_tree_in_root(self):
 
1103
        format = controldir.format_registry.make_controldir('knit')
 
1104
        transport = self.get_transport()
 
1105
 
 
1106
        # Create shared repository with working trees
 
1107
        repo = self.make_repository('repo', shared=True, format=format)
 
1108
        repo.set_make_working_trees(True)
 
1109
        out, err = self.run_bzr('info -v repo')
 
1110
        self.assertEqualDiff(
 
1111
"""Shared repository with trees (format: dirstate or dirstate-tags or knit)
 
1112
Location:
 
1113
  shared repository: repo
 
1114
 
 
1115
Format:
 
1116
       control: Meta directory format 1
 
1117
    repository: %s
 
1118
 
 
1119
Control directory:
 
1120
         0 branches
 
1121
 
 
1122
Create working tree for new branches inside the repository.
 
1123
 
 
1124
Repository:
 
1125
         0 revisions
 
1126
""" % (format.repository_format.get_format_description(),
 
1127
       ), out)
 
1128
        self.assertEqual('', err)
 
1129
 
 
1130
        # Create branch in root of repository
 
1131
        control = repo.controldir
 
1132
        branch = control.create_branch()
 
1133
        control.create_workingtree()
 
1134
        out, err = self.run_bzr('info -v repo')
 
1135
        self.assertEqualDiff(
 
1136
"""Repository tree (format: knit)
 
1137
Location:
 
1138
  shared repository: repo
 
1139
  repository branch: repo
 
1140
 
 
1141
Format:
 
1142
       control: Meta directory format 1
 
1143
  working tree: Working tree format 3
 
1144
        branch: %s
 
1145
    repository: %s
 
1146
 
 
1147
Control directory:
 
1148
         1 branches
 
1149
 
 
1150
In the working tree:
 
1151
         0 unchanged
 
1152
         0 modified
 
1153
         0 added
 
1154
         0 removed
 
1155
         0 renamed
 
1156
         0 unknown
 
1157
         0 ignored
 
1158
         0 versioned subdirectories
 
1159
 
 
1160
Branch history:
 
1161
         0 revisions
 
1162
 
 
1163
Repository:
 
1164
         0 revisions
 
1165
""" % (format.get_branch_format().get_format_description(),
 
1166
       format.repository_format.get_format_description(),
 
1167
       ), out)
 
1168
        self.assertEqual('', err)
 
1169
 
 
1170
    def test_info_repository_hook(self):
 
1171
        format = controldir.format_registry.make_controldir('knit')
 
1172
        def repo_info(repo, stats, outf):
 
1173
            outf.write("more info\n")
 
1174
        info.hooks.install_named_hook('repository', repo_info, None)
 
1175
        # Create shared repository with working trees
 
1176
        repo = self.make_repository('repo', shared=True, format=format)
 
1177
        out, err = self.run_bzr('info -v repo')
 
1178
        self.assertEqualDiff(
 
1179
"""Shared repository with trees (format: dirstate or dirstate-tags or knit)
 
1180
Location:
 
1181
  shared repository: repo
 
1182
 
 
1183
Format:
 
1184
       control: Meta directory format 1
 
1185
    repository: %s
 
1186
 
 
1187
Control directory:
 
1188
         0 branches
 
1189
 
 
1190
Create working tree for new branches inside the repository.
 
1191
 
 
1192
Repository:
 
1193
         0 revisions
 
1194
more info
 
1195
""" % (format.repository_format.get_format_description(),
 
1196
       ), out)
 
1197
        self.assertEqual('', err)
 
1198
 
 
1199
    def test_info_unshared_repository_with_colocated_branches(self):
 
1200
        format = controldir.format_registry.make_controldir('development-colo')
 
1201
        transport = self.get_transport()
 
1202
 
 
1203
        # Create unshared repository
 
1204
        repo = self.make_repository('repo', shared=False, format=format)
 
1205
        repo.set_make_working_trees(True)
 
1206
        repo.controldir.create_branch(name='foo')
 
1207
        out, err = self.run_bzr('info repo')
 
1208
        self.assertEqualDiff(
 
1209
"""Unshared repository with trees and colocated branches (format: development-colo)
 
1210
Location:
 
1211
  repository: repo
 
1212
""", out)
 
1213
        self.assertEqual('', err)
 
1214
 
 
1215
    def assertCheckoutStatusOutput(self,
 
1216
        command_string, lco_tree, shared_repo=None,
 
1217
        repo_branch=None,
 
1218
        tree_locked=False,
 
1219
        branch_locked=False, repo_locked=False,
 
1220
        verbose=False,
 
1221
        light_checkout=True,
 
1222
        checkout_root=None):
 
1223
        """Check the output of info in a checkout.
 
1224
 
 
1225
        This is not quite a mirror of the info code: rather than using the
 
1226
        tree being examined to predict output, it uses a bunch of flags which
 
1227
        allow us, the test writers, to document what *should* be present in
 
1228
        the output. Removing this separation would remove the value of the
 
1229
        tests.
 
1230
 
 
1231
        :param path: the path to the light checkout.
 
1232
        :param lco_tree: the tree object for the light checkout.
 
1233
        :param shared_repo: A shared repository is in use, expect that in
 
1234
            the output.
 
1235
        :param repo_branch: A branch in a shared repository for non light
 
1236
            checkouts.
 
1237
        :param tree_locked: If true, expect the tree to be locked.
 
1238
        :param branch_locked: If true, expect the branch to be locked.
 
1239
        :param repo_locked: If true, expect the repository to be locked.
 
1240
            Note that the lco_tree.branch.repository is inspected, and if is not
 
1241
            actually locked then this parameter is overridden. This is because
 
1242
            pack repositories do not have any public API for obtaining an
 
1243
            exclusive repository wide lock.
 
1244
        :param verbose: verbosity level: 2 or higher to show committers
 
1245
        """
 
1246
        def friendly_location(url):
 
1247
            path = urlutils.unescape_for_display(url, 'ascii')
 
1248
            try:
 
1249
                return osutils.relpath(osutils.getcwd(), path)
 
1250
            except errors.PathNotChild:
 
1251
                return path
 
1252
 
 
1253
        if tree_locked:
 
1254
            # We expect this to fail because of locking errors.
 
1255
            # (A write-locked file cannot be read-locked
 
1256
            # in the different process -- either on win32 or on linux).
 
1257
            # This should be removed when the locking errors are fixed.
 
1258
            self.expectFailure('OS locks are exclusive '
 
1259
                'for different processes (Bug #174055)',
 
1260
                self.run_bzr_subprocess,
 
1261
                'info ' + command_string)
 
1262
        out, err = self.run_bzr('info %s' % command_string)
 
1263
        description = {
 
1264
            (True, True): 'Lightweight checkout',
 
1265
            (True, False): 'Repository checkout',
 
1266
            (False, True): 'Lightweight checkout',
 
1267
            (False, False): 'Checkout',
 
1268
            }[(shared_repo is not None, light_checkout)]
 
1269
        format = {True: self._repo_strings,
 
1270
                  False: 'unnamed'}[light_checkout]
 
1271
        if repo_locked:
 
1272
            repo_locked = lco_tree.branch.repository.get_physical_lock_status()
 
1273
        if repo_locked or branch_locked or tree_locked:
 
1274
            def locked_message(a_bool):
 
1275
                if a_bool:
 
1276
                    return 'locked'
 
1277
                else:
 
1278
                    return 'unlocked'
 
1279
            expected_lock_output = (
 
1280
                "\n"
 
1281
                "Lock status:\n"
 
1282
                "  working tree: %s\n"
 
1283
                "        branch: %s\n"
 
1284
                "    repository: %s\n" % (
 
1285
                    locked_message(tree_locked),
 
1286
                    locked_message(branch_locked),
 
1287
                    locked_message(repo_locked)))
 
1288
        else:
 
1289
            expected_lock_output = ''
 
1290
        tree_data = ''
 
1291
        extra_space = ''
 
1292
        if light_checkout:
 
1293
            tree_data = ("  light checkout root: %s\n" %
 
1294
                friendly_location(lco_tree.controldir.root_transport.base))
 
1295
            extra_space = ' '
 
1296
        if lco_tree.branch.get_bound_location() is not None:
 
1297
            tree_data += ("%s       checkout root: %s\n" % (extra_space,
 
1298
                friendly_location(lco_tree.branch.controldir.root_transport.base)))
 
1299
        if shared_repo is not None:
 
1300
            branch_data = (
 
1301
                "   checkout of branch: %s\n"
 
1302
                "    shared repository: %s\n" %
 
1303
                (friendly_location(repo_branch.controldir.root_transport.base),
 
1304
                 friendly_location(shared_repo.controldir.root_transport.base)))
 
1305
        elif repo_branch is not None:
 
1306
            branch_data = (
 
1307
                "%s  checkout of branch: %s\n" %
 
1308
                (extra_space,
 
1309
                 friendly_location(repo_branch.controldir.root_transport.base)))
 
1310
        else:
 
1311
            branch_data = ("   checkout of branch: %s\n" %
 
1312
                lco_tree.branch.controldir.root_transport.base)
 
1313
 
 
1314
        if verbose >= 2:
 
1315
            verbose_info = '         0 committers\n'
 
1316
        else:
 
1317
            verbose_info = ''
 
1318
 
 
1319
        self.assertEqualDiff(
 
1320
"""%s (format: %s)
 
1321
Location:
 
1322
%s%s
 
1323
Format:
 
1324
       control: Meta directory format 1
 
1325
  working tree: %s
 
1326
        branch: %s
 
1327
    repository: %s
 
1328
%s
 
1329
Control directory:
 
1330
         1 branches
 
1331
 
 
1332
In the working tree:
 
1333
         0 unchanged
 
1334
         0 modified
 
1335
         0 added
 
1336
         0 removed
 
1337
         0 renamed
 
1338
         0 unknown
 
1339
         0 ignored
 
1340
         0 versioned subdirectories
 
1341
 
 
1342
Branch history:
 
1343
         0 revisions
 
1344
%s
 
1345
Repository:
 
1346
         0 revisions
 
1347
""" %  (description,
 
1348
        format,
 
1349
        tree_data,
 
1350
        branch_data,
 
1351
        lco_tree._format.get_format_description(),
 
1352
        lco_tree.branch._format.get_format_description(),
 
1353
        lco_tree.branch.repository._format.get_format_description(),
 
1354
        expected_lock_output,
 
1355
        verbose_info,
 
1356
        ), out)
 
1357
        self.assertEqual('', err)
 
1358
 
 
1359
    def test_info_locking(self):
 
1360
        transport = self.get_transport()
 
1361
        # Create shared repository with a branch
 
1362
        repo = self.make_repository('repo', shared=True,
 
1363
                                    format=bzrdir.BzrDirMetaFormat1())
 
1364
        repo.set_make_working_trees(False)
 
1365
        repo.controldir.root_transport.mkdir('branch')
 
1366
        repo_branch = controldir.ControlDir.create_branch_convenience(
 
1367
            'repo/branch', format=bzrdir.BzrDirMetaFormat1())
 
1368
        # Do a heavy checkout
 
1369
        transport.mkdir('tree')
 
1370
        transport.mkdir('tree/checkout')
 
1371
        co_branch = controldir.ControlDir.create_branch_convenience(
 
1372
            'tree/checkout', format=bzrdir.BzrDirMetaFormat1())
 
1373
        co_branch.bind(repo_branch)
 
1374
        # Do a light checkout of the heavy one
 
1375
        transport.mkdir('tree/lightcheckout')
 
1376
        lco_dir = bzrdir.BzrDirMetaFormat1().initialize('tree/lightcheckout')
 
1377
        lco_dir.set_branch_reference(co_branch)
 
1378
        lco_dir.create_workingtree()
 
1379
        lco_tree = lco_dir.open_workingtree()
 
1380
 
 
1381
        # Test all permutations of locking the working tree, branch and repository
 
1382
        # W B R
 
1383
 
 
1384
        # U U U
 
1385
        self.assertCheckoutStatusOutput('-v tree/lightcheckout', lco_tree,
 
1386
                                        repo_branch=repo_branch,
 
1387
                                        verbose=True, light_checkout=True)
 
1388
        # U U L
 
1389
        lco_tree.branch.repository.lock_write()
 
1390
        try:
 
1391
            self.assertCheckoutStatusOutput('-v tree/lightcheckout',
 
1392
            lco_tree, repo_branch=repo_branch,
 
1393
            repo_locked=True, verbose=True, light_checkout=True)
 
1394
        finally:
 
1395
            lco_tree.branch.repository.unlock()
 
1396
        # U L L
 
1397
        lco_tree.branch.lock_write()
 
1398
        try:
 
1399
            self.assertCheckoutStatusOutput('-v tree/lightcheckout',
 
1400
            lco_tree,
 
1401
            branch_locked=True,
 
1402
            repo_locked=True,
 
1403
            repo_branch=repo_branch,
 
1404
            verbose=True)
 
1405
        finally:
 
1406
            lco_tree.branch.unlock()
 
1407
        # L L L
 
1408
        lco_tree.lock_write()
 
1409
        try:
 
1410
            self.assertCheckoutStatusOutput('-v tree/lightcheckout',
 
1411
            lco_tree, repo_branch=repo_branch,
 
1412
            tree_locked=True,
 
1413
            branch_locked=True,
 
1414
            repo_locked=True,
 
1415
            verbose=True)
 
1416
        finally:
 
1417
            lco_tree.unlock()
 
1418
        # L L U
 
1419
        lco_tree.lock_write()
 
1420
        lco_tree.branch.repository.unlock()
 
1421
        try:
 
1422
            self.assertCheckoutStatusOutput('-v tree/lightcheckout',
 
1423
            lco_tree, repo_branch=repo_branch,
 
1424
            tree_locked=True,
 
1425
            branch_locked=True,
 
1426
            verbose=True)
 
1427
        finally:
 
1428
            lco_tree.branch.repository.lock_write()
 
1429
            lco_tree.unlock()
 
1430
        # L U U
 
1431
        lco_tree.lock_write()
 
1432
        lco_tree.branch.unlock()
 
1433
        try:
 
1434
            self.assertCheckoutStatusOutput('-v tree/lightcheckout',
 
1435
            lco_tree, repo_branch=repo_branch,
 
1436
            tree_locked=True,
 
1437
            verbose=True)
 
1438
        finally:
 
1439
            lco_tree.branch.lock_write()
 
1440
            lco_tree.unlock()
 
1441
        # L U L
 
1442
        lco_tree.lock_write()
 
1443
        lco_tree.branch.unlock()
 
1444
        lco_tree.branch.repository.lock_write()
 
1445
        try:
 
1446
            self.assertCheckoutStatusOutput('-v tree/lightcheckout',
 
1447
            lco_tree, repo_branch=repo_branch,
 
1448
            tree_locked=True,
 
1449
            repo_locked=True,
 
1450
            verbose=True)
 
1451
        finally:
 
1452
            lco_tree.branch.repository.unlock()
 
1453
            lco_tree.branch.lock_write()
 
1454
            lco_tree.unlock()
 
1455
        # U L U
 
1456
        lco_tree.branch.lock_write()
 
1457
        lco_tree.branch.repository.unlock()
 
1458
        try:
 
1459
            self.assertCheckoutStatusOutput('-v tree/lightcheckout',
 
1460
            lco_tree, repo_branch=repo_branch,
 
1461
            branch_locked=True,
 
1462
            verbose=True)
 
1463
        finally:
 
1464
            lco_tree.branch.repository.lock_write()
 
1465
            lco_tree.branch.unlock()
 
1466
 
 
1467
        if sys.platform == 'win32':
 
1468
            self.knownFailure('Win32 cannot run "brz info"'
 
1469
                              ' when the tree is locked.')
 
1470
 
 
1471
    def test_info_stacked(self):
 
1472
        # We have a mainline
 
1473
        trunk_tree = self.make_branch_and_tree('mainline',
 
1474
            format='1.6')
 
1475
        trunk_tree.commit('mainline')
 
1476
        # and a branch from it which is stacked
 
1477
        new_dir = trunk_tree.controldir.sprout('newbranch', stacked=True)
 
1478
        out, err = self.run_bzr('info newbranch')
 
1479
        self.assertEqual(
 
1480
"""Standalone tree (format: 1.6)
 
1481
Location:
 
1482
  branch root: newbranch
 
1483
 
 
1484
Related branches:
 
1485
  parent branch: mainline
 
1486
     stacked on: mainline
 
1487
""", out)
 
1488
        self.assertEqual("", err)
 
1489
 
 
1490
    def test_info_revinfo_optional(self):
 
1491
        tree = self.make_branch_and_tree('.')
 
1492
        def last_revision_info(self):
 
1493
            raise errors.UnsupportedOperation(last_revision_info, self)
 
1494
        self.overrideAttr(
 
1495
            branch.Branch, "last_revision_info", last_revision_info)
 
1496
        out, err = self.run_bzr('info -v .')
 
1497
        self.assertEqual(
 
1498
"""Standalone tree (format: 2a)
 
1499
Location:
 
1500
  branch root: .
 
1501
 
 
1502
Format:
 
1503
       control: Meta directory format 1
 
1504
  working tree: Working tree format 6
 
1505
        branch: Branch format 7
 
1506
    repository: Repository format 2a - rich roots, group compression and chk inventories
 
1507
 
 
1508
Control directory:
 
1509
         1 branches
 
1510
 
 
1511
In the working tree:
 
1512
         0 unchanged
 
1513
         0 modified
 
1514
         0 added
 
1515
         0 removed
 
1516
         0 renamed
 
1517
         0 unknown
 
1518
         0 ignored
 
1519
         0 versioned subdirectories
 
1520
""", out)
 
1521
        self.assertEqual("", err)
 
1522
 
 
1523
    def test_info_shows_colocated_branches(self):
 
1524
        bzrdir = self.make_branch('.', format='development-colo').controldir
 
1525
        bzrdir.create_branch(name="colo1")
 
1526
        bzrdir.create_branch(name="colo2")
 
1527
        bzrdir.create_branch(name="colo3")
 
1528
        out, err = self.run_bzr('info -v .')
 
1529
        self.assertEqualDiff(
 
1530
"""Standalone branch (format: development-colo)
 
1531
Location:
 
1532
  branch root: .
 
1533
 
 
1534
Format:
 
1535
       control: Meta directory format 1 with support for colocated branches
 
1536
        branch: Branch format 7
 
1537
    repository: Repository format 2a - rich roots, group compression and chk inventories
 
1538
 
 
1539
Control directory:
 
1540
         4 branches
 
1541
 
 
1542
Branch history:
 
1543
         0 revisions
 
1544
 
 
1545
Repository:
 
1546
         0 revisions
 
1547
""", out)
 
1548
        self.assertEqual("", err)
 
1549
 
 
1550
 
 
1551
class TestSmartServerInfo(tests.TestCaseWithTransport):
 
1552
 
 
1553
    def test_simple_branch_info(self):
 
1554
        self.setup_smart_server_with_call_log()
 
1555
        t = self.make_branch_and_tree('branch')
 
1556
        self.build_tree_contents([('branch/foo', 'thecontents')])
 
1557
        t.add("foo")
 
1558
        t.commit("message")
 
1559
        self.reset_smart_call_log()
 
1560
        out, err = self.run_bzr(['info', self.get_url('branch')])
 
1561
        # This figure represent the amount of work to perform this use case. It
 
1562
        # is entirely ok to reduce this number if a test fails due to rpc_count
 
1563
        # being too low. If rpc_count increases, more network roundtrips have
 
1564
        # become necessary for this use case. Please do not adjust this number
 
1565
        # upwards without agreement from bzr's network support maintainers.
 
1566
        self.assertLength(10, self.hpss_calls)
 
1567
        self.assertLength(1, self.hpss_connections)
 
1568
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
 
1569
 
 
1570
    def test_verbose_branch_info(self):
 
1571
        self.setup_smart_server_with_call_log()
 
1572
        t = self.make_branch_and_tree('branch')
 
1573
        self.build_tree_contents([('branch/foo', 'thecontents')])
 
1574
        t.add("foo")
 
1575
        t.commit("message")
 
1576
        self.reset_smart_call_log()
 
1577
        out, err = self.run_bzr(['info', '-v', self.get_url('branch')])
 
1578
        # This figure represent the amount of work to perform this use case. It
 
1579
        # is entirely ok to reduce this number if a test fails due to rpc_count
 
1580
        # being too low. If rpc_count increases, more network roundtrips have
 
1581
        # become necessary for this use case. Please do not adjust this number
 
1582
        # upwards without agreement from bzr's network support maintainers.
 
1583
        self.assertLength(14, self.hpss_calls)
 
1584
        self.assertLength(1, self.hpss_connections)
 
1585
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)