~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Martin Pool
  • Date: 2005-09-02 02:05:26 UTC
  • Revision ID: mbp@sourcefrog.net-20050902020526-0ab28bd5a998df70
- fix off-by-one in 'bzr log -r'

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