~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-04-28 07:24:55 UTC
  • Revision ID: mbp@sourcefrog.net-20050428072453-7b99afa993a1e549
todo

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