/brz/remove-bazaar

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

« back to all changes in this revision

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

  • Committer: Jelmer Vernooij
  • Date: 2018-11-17 00:41:07 UTC
  • mto: This revision was merged to the branch mainline in revision 7183.
  • Revision ID: jelmer@jelmer.uk-20181117004107-908n1zg4j46nhbix
Fix test.

Show diffs side-by-side

added added

removed removed

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