~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Jelmer Vernooij
  • Date: 2011-12-19 19:15:58 UTC
  • mfrom: (6388 +trunk)
  • mto: This revision was merged to the branch mainline in revision 6404.
  • Revision ID: jelmer@canonical.com-20111219191558-p1k7cvhjq8l6v2gm
Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

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