~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

Merge bzr.dev and tree-file-ids-as-tuples.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006, 2007 Canonical Ltd
 
1
# Copyright (C) 2006-2010 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
 
18
18
"""Tests for the info command of bzr."""
19
19
 
20
 
import os
 
20
import shutil
21
21
import sys
22
22
 
23
 
import bzrlib
24
23
from bzrlib import (
 
24
    branch,
25
25
    bzrdir,
 
26
    controldir,
 
27
    errors,
 
28
    info,
26
29
    osutils,
27
 
    repository,
 
30
    tests,
 
31
    upgrade,
28
32
    urlutils,
29
33
    )
30
 
from bzrlib.osutils import format_date
31
 
from bzrlib.tests import TestSkipped
32
 
from bzrlib.tests.blackbox import ExternalBase
33
 
 
34
 
 
35
 
class TestInfo(ExternalBase):
 
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"
36
43
 
37
44
    def test_info_non_existing(self):
38
 
        if sys.platform == "win32":
39
 
            location = "C:/i/do/not/exist/"
40
 
        else:
41
 
            location = "/i/do/not/exist/"
 
45
        self.vfs_transport_factory = memory.MemoryServer
 
46
        location = self.get_url()
42
47
        out, err = self.run_bzr('info '+location, retcode=3)
43
48
        self.assertEqual(out, '')
44
49
        self.assertEqual(err, 'bzr: ERROR: Not a branch: "%s".\n' % location)
45
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
 
46
72
    def test_info_standalone(self):
47
73
        transport = self.get_transport()
48
74
 
49
75
        # Create initial standalone branch
50
 
        tree1 = self.make_branch_and_tree('standalone', 'weave')
 
76
        tree1 = self.make_branch_and_tree('standalone', 'knit')
51
77
        self.build_tree(['standalone/a'])
52
78
        tree1.add('a')
53
79
        branch1 = tree1.branch
54
80
 
55
81
        out, err = self.run_bzr('info standalone')
56
82
        self.assertEqualDiff(
57
 
"""Standalone tree (format: weave)
 
83
"""Standalone tree (format: knit)
58
84
Location:
59
85
  branch root: standalone
60
86
""", out)
61
87
        self.assertEqual('', err)
62
88
 
 
89
        # Standalone branch - verbose mode
63
90
        out, err = self.run_bzr('info standalone -v')
64
91
        self.assertEqualDiff(
65
 
"""Standalone tree (format: weave)
66
 
Location:
67
 
  branch root: standalone
68
 
 
69
 
Format:
70
 
       control: All-in-one format 6
71
 
  working tree: Working tree format 2
72
 
        branch: Branch format 4
73
 
    repository: Weave repository format 6
 
92
"""Standalone tree (format: knit)
 
93
Location:
 
94
  branch root: standalone
 
95
 
 
96
Format:
 
97
       control: Meta directory format 1
 
98
  working tree: Working tree format 3
 
99
        branch: Branch format 5
 
100
    repository: Knit repository format 1
 
101
 
 
102
In the working tree:
 
103
         0 unchanged
 
104
         0 modified
 
105
         1 added
 
106
         0 removed
 
107
         0 renamed
 
108
         0 unknown
 
109
         0 ignored
 
110
         0 versioned subdirectories
 
111
 
 
112
Branch history:
 
113
         0 revisions
 
114
 
 
115
Repository:
 
116
         0 revisions
 
117
""", out)
 
118
        self.assertEqual('', err)
 
119
 
 
120
        # Standalone branch - really verbose mode
 
121
        out, err = self.run_bzr('info standalone -vv')
 
122
        self.assertEqualDiff(
 
123
"""Standalone tree (format: knit)
 
124
Location:
 
125
  branch root: standalone
 
126
 
 
127
Format:
 
128
       control: Meta directory format 1
 
129
  working tree: Working tree format 3
 
130
        branch: Branch format 5
 
131
    repository: Knit repository format 1
74
132
 
75
133
In the working tree:
76
134
         0 unchanged
88
146
 
89
147
Repository:
90
148
         0 revisions
91
 
         0 KiB
92
149
""", out)
93
150
        self.assertEqual('', err)
94
151
        tree1.commit('commit one')
95
 
        rev = branch1.repository.get_revision(branch1.revision_history()[0])
96
 
        datestring_first = format_date(rev.timestamp, rev.timezone)
 
152
        rev = branch1.repository.get_revision(branch1.last_revision())
 
153
        datestring_first = osutils.format_date(rev.timestamp, rev.timezone)
97
154
 
98
155
        # Branch standalone with push location
99
156
        branch2 = branch1.bzrdir.sprout('branch').open_branch()
101
158
 
102
159
        out, err = self.run_bzr('info branch')
103
160
        self.assertEqualDiff(
104
 
"""Standalone tree (format: weave)
 
161
"""Standalone tree (format: knit)
105
162
Location:
106
163
  branch root: branch
107
164
 
113
170
 
114
171
        out, err = self.run_bzr('info branch --verbose')
115
172
        self.assertEqualDiff(
116
 
"""Standalone tree (format: weave)
 
173
"""Standalone tree (format: knit)
117
174
Location:
118
175
  branch root: branch
119
176
 
122
179
  parent branch: standalone
123
180
 
124
181
Format:
125
 
       control: All-in-one format 6
126
 
  working tree: Working tree format 2
127
 
        branch: Branch format 4
128
 
    repository: Weave repository format 6
 
182
       control: Meta directory format 1
 
183
  working tree: Working tree format 3
 
184
        branch: Branch format 5
 
185
    repository: Knit repository format 1
129
186
 
130
187
In the working tree:
131
188
         1 unchanged
139
196
 
140
197
Branch history:
141
198
         1 revision
142
 
         1 committer
143
199
         0 days old
144
200
   first revision: %s
145
201
  latest revision: %s
146
202
 
147
203
Repository:
148
204
         1 revision
149
 
         %d KiB
150
205
""" % (datestring_first, datestring_first,
151
 
       # poking at _revision_store isn't all that clean, but neither is
152
 
       # having the ui test dependent on the exact overhead of a given store.
153
 
       branch2.repository._revision_store.total_size(
154
 
        branch2.repository.get_transaction())[1] / 1024,
155
206
       ), out)
156
207
        self.assertEqual('', err)
157
208
 
159
210
        # (creates backup as unknown)
160
211
        branch1.bzrdir.sprout('bound')
161
212
        knit1_format = bzrdir.format_registry.make_bzrdir('knit')
162
 
        bzrlib.upgrade.upgrade('bound', knit1_format)
163
 
        branch3 = bzrlib.bzrdir.BzrDir.open('bound').open_branch()
 
213
        upgrade.upgrade('bound', knit1_format)
 
214
        branch3 = controldir.ControlDir.open('bound').open_branch()
164
215
        branch3.bind(branch1)
165
216
        bound_tree = branch3.bzrdir.open_workingtree()
166
217
        out, err = self.run_bzr('info -v bound')
185
236
         0 added
186
237
         0 removed
187
238
         0 renamed
188
 
         1 unknown
 
239
         0 unknown
189
240
         0 ignored
190
241
         0 versioned subdirectories
191
242
 
192
243
Branch history:
193
244
         1 revision
194
 
         1 committer
195
245
         0 days old
196
246
   first revision: %s
197
247
  latest revision: %s
198
248
 
199
249
Repository:
200
250
         1 revision
201
 
         %d KiB
202
251
""" % (bound_tree._format.get_format_description(),
203
252
       branch3._format.get_format_description(),
204
253
       branch3.repository._format.get_format_description(),
205
254
       datestring_first, datestring_first,
206
 
       # poking at _revision_store isn't all that clean, but neither is
207
 
       # having the ui test dependent on the exact overhead of a given store.
208
 
       branch3.repository._revision_store.total_size(
209
 
        branch3.repository.get_transaction())[1] / 1024,
210
255
       ), out)
211
256
        self.assertEqual('', err)
212
257
 
213
258
        # Checkout standalone (same as above, but does not have parent set)
214
 
        branch4 = bzrlib.bzrdir.BzrDir.create_branch_convenience('checkout',
 
259
        branch4 = controldir.ControlDir.create_branch_convenience('checkout',
215
260
            format=knit1_format)
216
261
        branch4.bind(branch1)
217
262
        branch4.bzrdir.open_workingtree().update()
240
285
 
241
286
Branch history:
242
287
         1 revision
243
 
         1 committer
244
288
         0 days old
245
289
   first revision: %s
246
290
  latest revision: %s
247
291
 
248
292
Repository:
249
293
         1 revision
250
 
         %d KiB
251
294
""" % (branch4.repository._format.get_format_description(),
252
295
       datestring_first, datestring_first,
253
 
       # poking at _revision_store isn't all that clean, but neither is
254
 
       # having the ui test dependent on the exact overhead of a given store.
255
 
       branch4.repository._revision_store.total_size(
256
 
        branch4.repository.get_transaction())[1] / 1024,
257
296
       ), out)
258
297
        self.assertEqual('', err)
259
298
 
261
300
        tree5 = branch1.create_checkout('lightcheckout', lightweight=True)
262
301
        branch5 = tree5.branch
263
302
        out, err = self.run_bzr('info -v lightcheckout')
 
303
        if "metaweave" in bzrdir.format_registry:
 
304
            format_description = "knit or metaweave"
 
305
        else:
 
306
            format_description = "knit"
264
307
        self.assertEqualDiff(
265
 
"""Lightweight checkout (format: dirstate or dirstate-tags)
 
308
"""Lightweight checkout (format: %s)
266
309
Location:
267
310
  light checkout root: lightcheckout
268
311
   checkout of branch: standalone
269
312
 
270
313
Format:
271
314
       control: Meta directory format 1
272
 
  working tree: Working tree format 4
273
 
        branch: Branch format 4
274
 
    repository: Weave repository format 6
 
315
  working tree: Working tree format 3
 
316
        branch: Branch format 5
 
317
    repository: Knit repository format 1
275
318
 
276
319
In the working tree:
277
320
         1 unchanged
285
328
 
286
329
Branch history:
287
330
         1 revision
288
 
         1 committer
289
331
         0 days old
290
332
   first revision: %s
291
333
  latest revision: %s
292
334
 
293
335
Repository:
294
336
         1 revision
295
 
         0 KiB
296
 
""" % (datestring_first, datestring_first,), out)
 
337
""" % (format_description, datestring_first, datestring_first,), out)
297
338
        self.assertEqual('', err)
298
339
 
299
340
        # Update initial standalone branch
300
341
        self.build_tree(['standalone/b'])
301
342
        tree1.add('b')
302
343
        tree1.commit('commit two')
303
 
        rev = branch1.repository.get_revision(branch1.revision_history()[-1])
304
 
        datestring_last = format_date(rev.timestamp, rev.timezone)
 
344
        rev = branch1.repository.get_revision(branch1.last_revision())
 
345
        datestring_last = osutils.format_date(rev.timestamp, rev.timezone)
305
346
 
306
347
        # Out of date branched standalone branch will not be detected
307
348
        out, err = self.run_bzr('info -v branch')
308
349
        self.assertEqualDiff(
309
 
"""Standalone tree (format: weave)
 
350
"""Standalone tree (format: knit)
310
351
Location:
311
352
  branch root: branch
312
353
 
315
356
  parent branch: standalone
316
357
 
317
358
Format:
318
 
       control: All-in-one format 6
319
 
  working tree: Working tree format 2
320
 
        branch: Branch format 4
321
 
    repository: Weave repository format 6
 
359
       control: Meta directory format 1
 
360
  working tree: Working tree format 3
 
361
        branch: Branch format 5
 
362
    repository: Knit repository format 1
322
363
 
323
364
In the working tree:
324
365
         1 unchanged
332
373
 
333
374
Branch history:
334
375
         1 revision
335
 
         1 committer
336
376
         0 days old
337
377
   first revision: %s
338
378
  latest revision: %s
339
379
 
340
380
Repository:
341
381
         1 revision
342
 
         0 KiB
343
382
""" % (datestring_first, datestring_first,
344
383
       ), out)
345
384
        self.assertEqual('', err)
369
408
         0 added
370
409
         0 removed
371
410
         0 renamed
372
 
         1 unknown
 
411
         0 unknown
373
412
         0 ignored
374
413
         0 versioned subdirectories
375
414
 
376
415
Branch history:
377
416
         1 revision
378
 
         1 committer
379
417
         0 days old
380
418
   first revision: %s
381
419
  latest revision: %s
382
420
 
383
421
Repository:
384
422
         1 revision
385
 
         %d KiB
386
423
""" % (branch3.repository._format.get_format_description(),
387
424
       datestring_first, datestring_first,
388
 
       # poking at _revision_store isn't all that clean, but neither is
389
 
       # having the ui test dependent on the exact overhead of a given store.
390
 
       branch3.repository._revision_store.total_size(
391
 
        branch3.repository.get_transaction())[1] / 1024,
392
425
       ), out)
393
426
        self.assertEqual('', err)
394
427
 
420
453
 
421
454
Branch history:
422
455
         1 revision
423
 
         1 committer
424
456
         0 days old
425
457
   first revision: %s
426
458
  latest revision: %s
427
459
 
428
460
Repository:
429
461
         1 revision
430
 
         %d KiB
431
462
""" % (branch4.repository._format.get_format_description(),
432
463
       datestring_first, datestring_first,
433
 
       # poking at _revision_store isn't all that clean, but neither is
434
 
       # having the ui test dependent on the exact overhead of a given store.
435
 
       branch4.repository._revision_store.total_size(
436
 
        branch4.repository.get_transaction())[1] / 1024,
437
464
       ), out)
438
465
        self.assertEqual('', err)
439
466
 
440
467
        # Out of date lightweight checkout
441
468
        out, err = self.run_bzr('info lightcheckout --verbose')
442
469
        self.assertEqualDiff(
443
 
"""Lightweight checkout (format: dirstate or dirstate-tags)
 
470
"""Lightweight checkout (format: %s)
444
471
Location:
445
472
  light checkout root: lightcheckout
446
473
   checkout of branch: standalone
447
474
 
448
475
Format:
449
476
       control: Meta directory format 1
450
 
  working tree: Working tree format 4
451
 
        branch: Branch format 4
452
 
    repository: Weave repository format 6
 
477
  working tree: Working tree format 3
 
478
        branch: Branch format 5
 
479
    repository: Knit repository format 1
453
480
 
454
481
Working tree is out of date: missing 1 revision.
455
482
 
465
492
 
466
493
Branch history:
467
494
         2 revisions
468
 
         1 committer
469
495
         0 days old
470
496
   first revision: %s
471
497
  latest revision: %s
472
498
 
473
499
Repository:
474
500
         2 revisions
475
 
         0 KiB
476
 
""" % (datestring_first, datestring_last,), out)
 
501
""" % (format_description, datestring_first, datestring_last,), out)
477
502
        self.assertEqual('', err)
478
503
 
479
504
    def test_info_standalone_no_tree(self):
483
508
        repo = branch.repository
484
509
        out, err = self.run_bzr('info branch -v')
485
510
        self.assertEqualDiff(
486
 
"""Standalone branch (format: dirstate-tags)
 
511
"""Standalone branch (format: %s)
487
512
Location:
488
513
  branch root: branch
489
514
 
494
519
 
495
520
Branch history:
496
521
         0 revisions
497
 
         0 committers
498
522
 
499
523
Repository:
500
524
         0 revisions
501
 
         0 KiB
502
 
""" % (format.get_branch_format().get_format_description(),
 
525
""" % (info.describe_format(repo.bzrdir, repo, branch, None),
 
526
       format.get_branch_format().get_format_description(),
503
527
       format.repository_format.get_format_description(),
504
528
       ), out)
505
529
        self.assertEqual('', err)
523
547
 
524
548
Repository:
525
549
         0 revisions
526
 
         0 KiB
527
550
""" % ('repo', format.repository_format.get_format_description(),
528
551
       ), out)
529
552
        self.assertEqual('', err)
530
553
 
531
554
        # Create branch inside shared repository
532
555
        repo.bzrdir.root_transport.mkdir('branch')
533
 
        branch1 = repo.bzrdir.create_branch_convenience('repo/branch',
534
 
            format=format)
 
556
        branch1 = controldir.ControlDir.create_branch_convenience(
 
557
            'repo/branch', format=format)
535
558
        out, err = self.run_bzr('info -v repo/branch')
536
559
        self.assertEqualDiff(
537
560
"""Repository branch (format: dirstate or knit)
546
569
 
547
570
Branch history:
548
571
         0 revisions
549
 
         0 committers
550
572
 
551
573
Repository:
552
574
         0 revisions
553
 
         0 KiB
554
575
""" % (format.get_branch_format().get_format_description(),
555
576
       format.repository_format.get_format_description(),
556
577
       ), out)
559
580
        # Create lightweight checkout
560
581
        transport.mkdir('tree')
561
582
        transport.mkdir('tree/lightcheckout')
562
 
        tree2 = branch1.create_checkout('tree/lightcheckout', 
 
583
        tree2 = branch1.create_checkout('tree/lightcheckout',
563
584
            lightweight=True)
564
585
        branch2 = tree2.branch
565
586
        self.assertCheckoutStatusOutput('-v tree/lightcheckout', tree2,
574
595
        self.build_tree(['tree/lightcheckout/a'])
575
596
        tree2.add('a')
576
597
        tree2.commit('commit one')
577
 
        rev = repo.get_revision(branch2.revision_history()[0])
578
 
        datestring_first = format_date(rev.timestamp, rev.timezone)
 
598
        rev = repo.get_revision(branch2.last_revision())
 
599
        datestring_first = osutils.format_date(rev.timestamp, rev.timezone)
579
600
        out, err = self.run_bzr('info tree/lightcheckout --verbose')
580
601
        self.assertEqualDiff(
581
 
"""Lightweight checkout (format: dirstate or dirstate-tags)
 
602
"""Lightweight checkout (format: %s)
582
603
Location:
583
604
  light checkout root: tree/lightcheckout
584
605
   checkout of branch: repo/branch
586
607
 
587
608
Format:
588
609
       control: Meta directory format 1
589
 
  working tree: Working tree format 4
 
610
  working tree: Working tree format 6
590
611
        branch: %s
591
612
    repository: %s
592
613
 
602
623
 
603
624
Branch history:
604
625
         1 revision
605
 
         1 committer
606
626
         0 days old
607
627
   first revision: %s
608
628
  latest revision: %s
609
629
 
610
630
Repository:
611
631
         1 revision
612
 
         %d KiB
613
 
""" % (format.get_branch_format().get_format_description(),
 
632
""" % (self._repo_strings, format.get_branch_format().get_format_description(),
614
633
       format.repository_format.get_format_description(),
615
634
       datestring_first, datestring_first,
616
 
       # poking at _revision_store isn't all that clean, but neither is
617
 
       # having the ui test dependent on the exact overhead of a given store.
618
 
       repo._revision_store.total_size(repo.get_transaction())[1] / 1024,
619
635
       ), out)
620
636
        self.assertEqual('', err)
621
637
 
622
638
        # Out of date checkout
623
639
        out, err = self.run_bzr('info -v tree/checkout')
624
640
        self.assertEqualDiff(
625
 
"""Checkout (format: dirstate)
 
641
"""Checkout (format: unnamed)
626
642
Location:
627
643
       checkout root: tree/checkout
628
644
  checkout of branch: repo/branch
629
645
 
630
646
Format:
631
647
       control: Meta directory format 1
632
 
  working tree: Working tree format 4
 
648
  working tree: Working tree format 6
633
649
        branch: %s
634
650
    repository: %s
635
651
 
647
663
 
648
664
Branch history:
649
665
         0 revisions
650
 
         0 committers
651
666
 
652
667
Repository:
653
668
         0 revisions
654
 
         0 KiB
655
669
""" % (format.get_branch_format().get_format_description(),
656
670
       format.repository_format.get_format_description(),
657
671
       ), out)
663
677
        tree3.add('b')
664
678
        out, err = self.run_bzr('info tree/checkout --verbose')
665
679
        self.assertEqualDiff(
666
 
"""Checkout (format: dirstate)
 
680
"""Checkout (format: unnamed)
667
681
Location:
668
682
       checkout root: tree/checkout
669
683
  checkout of branch: repo/branch
670
684
 
671
685
Format:
672
686
       control: Meta directory format 1
673
 
  working tree: Working tree format 4
 
687
  working tree: Working tree format 6
674
688
        branch: %s
675
689
    repository: %s
676
690
 
686
700
 
687
701
Branch history:
688
702
         1 revision
689
 
         1 committer
690
703
         0 days old
691
704
   first revision: %s
692
705
  latest revision: %s
693
706
 
694
707
Repository:
695
708
         1 revision
696
 
         %d KiB
697
709
""" % (format.get_branch_format().get_format_description(),
698
710
       format.repository_format.get_format_description(),
699
711
       datestring_first, datestring_first,
700
 
       # poking at _revision_store isn't all that clean, but neither is
701
 
       # having the ui test dependent on the exact overhead of a given store.
702
 
       repo._revision_store.total_size(repo.get_transaction())[1] / 1024,
703
712
       ), out)
704
713
        self.assertEqual('', err)
705
714
        tree3.commit('commit two')
706
715
 
707
716
        # Out of date lightweight checkout
708
 
        rev = repo.get_revision(branch1.revision_history()[-1])
709
 
        datestring_last = format_date(rev.timestamp, rev.timezone)
 
717
        rev = repo.get_revision(branch1.last_revision())
 
718
        datestring_last = osutils.format_date(rev.timestamp, rev.timezone)
710
719
        out, err = self.run_bzr('info tree/lightcheckout --verbose')
711
720
        self.assertEqualDiff(
712
 
"""Lightweight checkout (format: dirstate or dirstate-tags)
 
721
"""Lightweight checkout (format: %s)
713
722
Location:
714
723
  light checkout root: tree/lightcheckout
715
724
   checkout of branch: repo/branch
717
726
 
718
727
Format:
719
728
       control: Meta directory format 1
720
 
  working tree: Working tree format 4
 
729
  working tree: Working tree format 6
721
730
        branch: %s
722
731
    repository: %s
723
732
 
735
744
 
736
745
Branch history:
737
746
         2 revisions
738
 
         1 committer
739
747
         0 days old
740
748
   first revision: %s
741
749
  latest revision: %s
742
750
 
743
751
Repository:
744
752
         2 revisions
745
 
         %d KiB
746
 
""" % (format.get_branch_format().get_format_description(),
 
753
""" % (self._repo_strings, format.get_branch_format().get_format_description(),
747
754
       format.repository_format.get_format_description(),
748
755
       datestring_first, datestring_last,
749
 
       # poking at _revision_store isn't all that clean, but neither is
750
 
       # having the ui test dependent on the exact overhead of a given store.
751
 
       repo._revision_store.total_size(repo.get_transaction())[1] / 1024,
752
756
       ), out)
753
757
        self.assertEqual('', err)
754
758
 
767
771
 
768
772
Branch history:
769
773
         2 revisions
770
 
         1 committer
771
774
         0 days old
772
775
   first revision: %s
773
776
  latest revision: %s
774
777
 
775
778
Repository:
776
779
         2 revisions
777
 
         %d KiB
778
780
""" % (format.get_branch_format().get_format_description(),
779
781
       format.repository_format.get_format_description(),
780
782
       datestring_first, datestring_last,
781
 
       # poking at _revision_store isn't all that clean, but neither is
782
 
       # having the ui test dependent on the exact overhead of a given store.
783
 
       repo._revision_store.total_size(repo.get_transaction())[1] / 1024,
784
783
       ), out)
785
784
        self.assertEqual('', err)
786
785
 
797
796
 
798
797
Repository:
799
798
         2 revisions
800
 
         %d KiB
801
799
""" % (format.repository_format.get_format_description(),
802
 
       # poking at _revision_store isn't all that clean, but neither is
803
 
       # having the ui test dependent on the exact overhead of a given store.
804
 
       repo._revision_store.total_size(repo.get_transaction())[1] / 1024,
805
800
       ), out)
806
801
        self.assertEqual('', err)
807
802
 
826
821
 
827
822
Repository:
828
823
         0 revisions
829
 
         0 KiB
830
824
""" % (format.repository_format.get_format_description(),
831
825
       ), out)
832
826
        self.assertEqual('', err)
833
827
 
834
828
        # Create two branches
835
829
        repo.bzrdir.root_transport.mkdir('branch1')
836
 
        branch1 = repo.bzrdir.create_branch_convenience('repo/branch1',
 
830
        branch1 = controldir.ControlDir.create_branch_convenience('repo/branch1',
837
831
            format=format)
838
832
        branch2 = branch1.bzrdir.sprout('repo/branch2').open_branch()
839
833
 
863
857
 
864
858
Branch history:
865
859
         0 revisions
866
 
         0 committers
867
860
 
868
861
Repository:
869
862
         0 revisions
870
 
         0 KiB
871
863
""" % (format.get_branch_format().get_format_description(),
872
864
       format.repository_format.get_format_description(),
873
865
       ), out)
878
870
        tree1 = branch1.bzrdir.open_workingtree()
879
871
        tree1.add('a')
880
872
        tree1.commit('commit one')
881
 
        rev = repo.get_revision(branch1.revision_history()[0])
882
 
        datestring_first = format_date(rev.timestamp, rev.timezone)
 
873
        rev = repo.get_revision(branch1.last_revision())
 
874
        datestring_first = osutils.format_date(rev.timestamp, rev.timezone)
883
875
        out, err = self.run_bzr('info -v repo/branch1')
884
876
        self.assertEqualDiff(
885
877
"""Repository tree (format: knit)
905
897
 
906
898
Branch history:
907
899
         1 revision
908
 
         1 committer
909
900
         0 days old
910
901
   first revision: %s
911
902
  latest revision: %s
912
903
 
913
904
Repository:
914
905
         1 revision
915
 
         %d KiB
916
906
""" % (format.get_branch_format().get_format_description(),
917
907
       format.repository_format.get_format_description(),
918
908
       datestring_first, datestring_first,
919
 
       # poking at _revision_store isn't all that clean, but neither is
920
 
       # having the ui test dependent on the exact overhead of a given store.
921
 
       repo._revision_store.total_size(repo.get_transaction())[1] / 1024,
922
909
       ), out)
923
910
        self.assertEqual('', err)
924
911
 
951
938
 
952
939
Branch history:
953
940
         0 revisions
954
 
         0 committers
955
941
 
956
942
Repository:
957
943
         1 revision
958
 
         %d KiB
959
944
""" % (format.get_branch_format().get_format_description(),
960
945
       format.repository_format.get_format_description(),
961
 
       # poking at _revision_store isn't all that clean, but neither is
962
 
       # having the ui test dependent on the exact overhead of a given store.
963
 
       repo._revision_store.total_size(repo.get_transaction())[1] / 1024,
964
946
       ), out)
965
947
        self.assertEqual('', err)
966
948
 
995
977
 
996
978
Branch history:
997
979
         1 revision
998
 
         1 committer
999
980
         0 days old
1000
981
   first revision: %s
1001
982
  latest revision: %s
1002
983
 
1003
984
Repository:
1004
985
         1 revision
1005
 
         %d KiB
1006
986
""" % (format.get_branch_format().get_format_description(),
1007
987
       format.repository_format.get_format_description(),
1008
988
       datestring_first, datestring_first,
1009
 
       # poking at _revision_store isn't all that clean, but neither is
1010
 
       # having the ui test dependent on the exact overhead of a given store.
1011
 
       repo._revision_store.total_size(repo.get_transaction())[1] / 1024,
1012
989
       ), out)
1013
990
        self.assertEqual('', err)
1014
991
 
1027
1004
 
1028
1005
Repository:
1029
1006
         1 revision
1030
 
         %d KiB
1031
1007
""" % (format.repository_format.get_format_description(),
1032
 
       # poking at _revision_store isn't all that clean, but neither is
1033
 
       # having the ui test dependent on the exact overhead of a given store.
1034
 
       repo._revision_store.total_size(repo.get_transaction())[1] / 1024,
1035
1008
       ),
1036
1009
       out)
1037
1010
        self.assertEqual('', err)
1038
 
    
 
1011
 
1039
1012
    def test_info_shared_repository_with_tree_in_root(self):
1040
1013
        format = bzrdir.format_registry.make_bzrdir('knit')
1041
1014
        transport = self.get_transport()
1057
1030
 
1058
1031
Repository:
1059
1032
         0 revisions
1060
 
         0 KiB
1061
1033
""" % (format.repository_format.get_format_description(),
1062
1034
       ), out)
1063
1035
        self.assertEqual('', err)
1091
1063
 
1092
1064
Branch history:
1093
1065
         0 revisions
1094
 
         0 committers
1095
1066
 
1096
1067
Repository:
1097
1068
         0 revisions
1098
 
         0 KiB
1099
1069
""" % (format.get_branch_format().get_format_description(),
1100
1070
       format.repository_format.get_format_description(),
1101
1071
       ), out)
1102
1072
        self.assertEqual('', err)
1103
1073
 
1104
 
    def assertCheckoutStatusOutput(self, 
 
1074
    def test_info_repository_hook(self):
 
1075
        format = bzrdir.format_registry.make_bzrdir('knit')
 
1076
        def repo_info(repo, stats, outf):
 
1077
            outf.write("more info\n")
 
1078
        info.hooks.install_named_hook('repository', repo_info, None)
 
1079
        # Create shared repository with working trees
 
1080
        repo = self.make_repository('repo', shared=True, format=format)
 
1081
        out, err = self.run_bzr('info -v repo')
 
1082
        self.assertEqualDiff(
 
1083
"""Shared repository with trees (format: dirstate or dirstate-tags or knit)
 
1084
Location:
 
1085
  shared repository: repo
 
1086
 
 
1087
Format:
 
1088
       control: Meta directory format 1
 
1089
    repository: %s
 
1090
 
 
1091
Create working tree for new branches inside the repository.
 
1092
 
 
1093
Repository:
 
1094
         0 revisions
 
1095
more info
 
1096
""" % (format.repository_format.get_format_description(),
 
1097
       ), out)
 
1098
        self.assertEqual('', err)
 
1099
 
 
1100
    def test_info_unshared_repository_with_colocated_branches(self):
 
1101
        format = bzrdir.format_registry.make_bzrdir('development-colo')
 
1102
        transport = self.get_transport()
 
1103
 
 
1104
        # Create unshared repository
 
1105
        repo = self.make_repository('repo', shared=False, format=format)
 
1106
        repo.set_make_working_trees(True)
 
1107
        repo.bzrdir.create_branch(name='foo')
 
1108
        out, err = self.run_bzr('info repo')
 
1109
        self.assertEqualDiff(
 
1110
"""Unshared repository with trees and colocated branches (format: development-colo)
 
1111
Location:
 
1112
  repository: repo
 
1113
""", out)
 
1114
        self.assertEqual('', err)
 
1115
 
 
1116
    def assertCheckoutStatusOutput(self,
1105
1117
        command_string, lco_tree, shared_repo=None,
1106
1118
        repo_branch=None,
1107
1119
        tree_locked=False,
1116
1128
        allow us, the test writers, to document what *should* be present in
1117
1129
        the output. Removing this separation would remove the value of the
1118
1130
        tests.
1119
 
        
 
1131
 
1120
1132
        :param path: the path to the light checkout.
1121
1133
        :param lco_tree: the tree object for the light checkout.
1122
1134
        :param shared_repo: A shared repository is in use, expect that in
1126
1138
        :param tree_locked: If true, expect the tree to be locked.
1127
1139
        :param branch_locked: If true, expect the branch to be locked.
1128
1140
        :param repo_locked: If true, expect the repository to be locked.
1129
 
        :param verbose: If true, expect verbose output
 
1141
            Note that the lco_tree.branch.repository is inspected, and if is not
 
1142
            actually locked then this parameter is overridden. This is because
 
1143
            pack repositories do not have any public API for obtaining an
 
1144
            exclusive repository wide lock.
 
1145
        :param verbose: verbosity level: 2 or higher to show committers
1130
1146
        """
1131
1147
        def friendly_location(url):
1132
1148
            path = urlutils.unescape_for_display(url, 'ascii')
1133
1149
            try:
1134
 
                return osutils.relpath(os.getcwd(), path)
 
1150
                return osutils.relpath(osutils.getcwd(), path)
1135
1151
            except errors.PathNotChild:
1136
1152
                return path
1137
1153
 
1138
 
        if tree_locked and sys.platform == 'win32':
1139
 
            # We expect this to fail because of locking errors. (A write-locked
1140
 
            # file cannot be read-locked in the same process).
 
1154
        if tree_locked:
 
1155
            # We expect this to fail because of locking errors.
 
1156
            # (A write-locked file cannot be read-locked
 
1157
            # in the different process -- either on win32 or on linux).
1141
1158
            # This should be removed when the locking errors are fixed.
1142
 
            args = command_string.split(' ')
1143
 
            self.run_bzr_error([], 'info', *args)
1144
 
            return
 
1159
            self.expectFailure('OS locks are exclusive '
 
1160
                'for different processes (Bug #174055)',
 
1161
                self.run_bzr_subprocess,
 
1162
                'info ' + command_string)
1145
1163
        out, err = self.run_bzr('info %s' % command_string)
1146
1164
        description = {
1147
1165
            (True, True): 'Lightweight checkout',
1149
1167
            (False, True): 'Lightweight checkout',
1150
1168
            (False, False): 'Checkout',
1151
1169
            }[(shared_repo is not None, light_checkout)]
1152
 
        format = {True: 'dirstate or dirstate-tags',
1153
 
                  False: 'dirstate'}[light_checkout]
 
1170
        format = {True: self._repo_strings,
 
1171
                  False: 'unnamed'}[light_checkout]
 
1172
        if repo_locked:
 
1173
            repo_locked = lco_tree.branch.repository.get_physical_lock_status()
1154
1174
        if repo_locked or branch_locked or tree_locked:
1155
1175
            def locked_message(a_bool):
1156
1176
                if a_bool:
1191
1211
        else:
1192
1212
            branch_data = ("   checkout of branch: %s\n" %
1193
1213
                lco_tree.branch.bzrdir.root_transport.base)
1194
 
        
1195
 
        if verbose:
 
1214
 
 
1215
        if verbose >= 2:
1196
1216
            verbose_info = '         0 committers\n'
1197
1217
        else:
1198
1218
            verbose_info = ''
1199
 
            
 
1219
 
1200
1220
        self.assertEqualDiff(
1201
1221
"""%s (format: %s)
1202
1222
Location:
1222
1242
%s
1223
1243
Repository:
1224
1244
         0 revisions
1225
 
         0 KiB
1226
1245
""" %  (description,
1227
1246
        format,
1228
1247
        tree_data,
1239
1258
        transport = self.get_transport()
1240
1259
        # Create shared repository with a branch
1241
1260
        repo = self.make_repository('repo', shared=True,
1242
 
                                    format=bzrlib.bzrdir.BzrDirMetaFormat1())
 
1261
                                    format=bzrdir.BzrDirMetaFormat1())
1243
1262
        repo.set_make_working_trees(False)
1244
1263
        repo.bzrdir.root_transport.mkdir('branch')
1245
 
        repo_branch = repo.bzrdir.create_branch_convenience('repo/branch',
1246
 
                                    format=bzrlib.bzrdir.BzrDirMetaFormat1())
 
1264
        repo_branch = controldir.ControlDir.create_branch_convenience(
 
1265
            'repo/branch', format=bzrdir.BzrDirMetaFormat1())
1247
1266
        # Do a heavy checkout
1248
1267
        transport.mkdir('tree')
1249
1268
        transport.mkdir('tree/checkout')
1250
 
        co_branch = bzrlib.bzrdir.BzrDir.create_branch_convenience('tree/checkout',
1251
 
            format=bzrlib.bzrdir.BzrDirMetaFormat1())
 
1269
        co_branch = controldir.ControlDir.create_branch_convenience(
 
1270
            'tree/checkout', format=bzrdir.BzrDirMetaFormat1())
1252
1271
        co_branch.bind(repo_branch)
1253
1272
        # Do a light checkout of the heavy one
1254
1273
        transport.mkdir('tree/lightcheckout')
1255
 
        lco_dir = bzrlib.bzrdir.BzrDirMetaFormat1().initialize('tree/lightcheckout')
1256
 
        bzrlib.branch.BranchReferenceFormat().initialize(lco_dir, co_branch)
 
1274
        lco_dir = bzrdir.BzrDirMetaFormat1().initialize('tree/lightcheckout')
 
1275
        lco_dir.set_branch_reference(co_branch)
1257
1276
        lco_dir.create_workingtree()
1258
1277
        lco_tree = lco_dir.open_workingtree()
1259
1278
 
1347
1366
            self.knownFailure('Win32 cannot run "bzr info"'
1348
1367
                              ' when the tree is locked.')
1349
1368
 
1350
 
    def test_info_locking_oslocks(self):
1351
 
        if sys.platform == "win32":
1352
 
            raise TestSkipped("don't use oslocks on win32 in unix manner")
1353
 
 
1354
 
        tree = self.make_branch_and_tree('branch',
1355
 
                                         format=bzrlib.bzrdir.BzrDirFormat6())
1356
 
 
1357
 
        # Test all permutations of locking the working tree, branch and repository
1358
 
        # XXX: Well not yet, as we can't query oslocks yet. Currently, it's
1359
 
        # implemented by raising NotImplementedError and get_physical_lock_status()
1360
 
        # always returns false. This makes bzr info hide the lock status.  (Olaf)
1361
 
        # W B R
1362
 
 
1363
 
        # U U U
1364
 
        out, err = self.run_bzr('info -v branch')
1365
 
        self.assertEqualDiff(
1366
 
"""Standalone tree (format: weave)
1367
 
Location:
1368
 
  branch root: %s
1369
 
 
1370
 
Format:
1371
 
       control: All-in-one format 6
1372
 
  working tree: Working tree format 2
1373
 
        branch: Branch format 4
1374
 
    repository: %s
1375
 
 
1376
 
In the working tree:
1377
 
         0 unchanged
1378
 
         0 modified
1379
 
         0 added
1380
 
         0 removed
1381
 
         0 renamed
1382
 
         0 unknown
1383
 
         0 ignored
1384
 
         0 versioned subdirectories
1385
 
 
1386
 
Branch history:
1387
 
         0 revisions
1388
 
         0 committers
1389
 
 
1390
 
Repository:
1391
 
         0 revisions
1392
 
         0 KiB
1393
 
""" % ('branch', tree.branch.repository._format.get_format_description(),
1394
 
       ), out)
1395
 
        self.assertEqual('', err)
1396
 
        # L L L
1397
 
        tree.lock_write()
1398
 
        out, err = self.run_bzr('info -v branch')
1399
 
        self.assertEqualDiff(
1400
 
"""Standalone tree (format: weave)
1401
 
Location:
1402
 
  branch root: %s
1403
 
 
1404
 
Format:
1405
 
       control: All-in-one format 6
1406
 
  working tree: Working tree format 2
1407
 
        branch: Branch format 4
1408
 
    repository: %s
1409
 
 
1410
 
In the working tree:
1411
 
         0 unchanged
1412
 
         0 modified
1413
 
         0 added
1414
 
         0 removed
1415
 
         0 renamed
1416
 
         0 unknown
1417
 
         0 ignored
1418
 
         0 versioned subdirectories
1419
 
 
1420
 
Branch history:
1421
 
         0 revisions
1422
 
         0 committers
1423
 
 
1424
 
Repository:
1425
 
         0 revisions
1426
 
         0 KiB
1427
 
""" % ('branch', tree.branch.repository._format.get_format_description(),
1428
 
       ), out)
1429
 
        self.assertEqual('', err)
1430
 
        tree.unlock()
 
1369
    def test_info_stacked(self):
 
1370
        # We have a mainline
 
1371
        trunk_tree = self.make_branch_and_tree('mainline',
 
1372
            format='1.6')
 
1373
        trunk_tree.commit('mainline')
 
1374
        # and a branch from it which is stacked
 
1375
        new_dir = trunk_tree.bzrdir.sprout('newbranch', stacked=True)
 
1376
        out, err = self.run_bzr('info newbranch')
 
1377
        self.assertEqual(
 
1378
"""Standalone tree (format: 1.6)
 
1379
Location:
 
1380
  branch root: newbranch
 
1381
 
 
1382
Related branches:
 
1383
  parent branch: mainline
 
1384
     stacked on: mainline
 
1385
""", out)
 
1386
        self.assertEqual("", err)
 
1387
 
 
1388
    def test_info_revinfo_optional(self):
 
1389
        tree = self.make_branch_and_tree('.')
 
1390
        def last_revision_info(self):
 
1391
            raise errors.UnsupportedOperation(last_revision_info, self)
 
1392
        self.overrideAttr(
 
1393
            branch.Branch, "last_revision_info", last_revision_info)
 
1394
        out, err = self.run_bzr('info -v .')
 
1395
        self.assertEqual(
 
1396
"""Standalone tree (format: 2a)
 
1397
Location:
 
1398
  branch root: .
 
1399
 
 
1400
Format:
 
1401
       control: Meta directory format 1
 
1402
  working tree: Working tree format 6
 
1403
        branch: Branch format 7
 
1404
    repository: Repository format 2a - rich roots, group compression and chk inventories
 
1405
 
 
1406
In the working tree:
 
1407
         0 unchanged
 
1408
         0 modified
 
1409
         0 added
 
1410
         0 removed
 
1411
         0 renamed
 
1412
         0 unknown
 
1413
         0 ignored
 
1414
         0 versioned subdirectories
 
1415
""", out)
 
1416
        self.assertEqual("", err)
 
1417
 
 
1418
    def test_info_shows_colocated_branches(self):
 
1419
        bzrdir = self.make_branch('.', format='development-colo').bzrdir
 
1420
        bzrdir.create_branch(name="colo1")
 
1421
        bzrdir.create_branch(name="colo2")
 
1422
        bzrdir.create_branch(name="colo3")
 
1423
        out, err = self.run_bzr('info -v .')
 
1424
        self.assertEqualDiff(
 
1425
"""Standalone branch (format: development-colo)
 
1426
Location:
 
1427
  branch root: .
 
1428
 
 
1429
Format:
 
1430
       control: Meta directory format 1 with support for colocated branches
 
1431
        branch: Branch format 7
 
1432
    repository: Repository format 2a - rich roots, group compression and chk inventories
 
1433
 
 
1434
Control directory:
 
1435
         4 branches
 
1436
 
 
1437
Branch history:
 
1438
         0 revisions
 
1439
 
 
1440
Repository:
 
1441
         0 revisions
 
1442
""", out)
 
1443
        self.assertEqual("", err)
 
1444
 
 
1445
 
 
1446
class TestSmartServerInfo(tests.TestCaseWithTransport):
 
1447
 
 
1448
    def test_simple_branch_info(self):
 
1449
        self.setup_smart_server_with_call_log()
 
1450
        t = self.make_branch_and_tree('branch')
 
1451
        self.build_tree_contents([('branch/foo', 'thecontents')])
 
1452
        t.add("foo")
 
1453
        t.commit("message")
 
1454
        self.reset_smart_call_log()
 
1455
        out, err = self.run_bzr(['info', self.get_url('branch')])
 
1456
        # This figure represent the amount of work to perform this use case. It
 
1457
        # is entirely ok to reduce this number if a test fails due to rpc_count
 
1458
        # being too low. If rpc_count increases, more network roundtrips have
 
1459
        # become necessary for this use case. Please do not adjust this number
 
1460
        # upwards without agreement from bzr's network support maintainers.
 
1461
        self.assertLength(12, self.hpss_calls)
 
1462
        self.assertLength(1, self.hpss_connections)
 
1463
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
 
1464
 
 
1465
    def test_verbose_branch_info(self):
 
1466
        self.setup_smart_server_with_call_log()
 
1467
        t = self.make_branch_and_tree('branch')
 
1468
        self.build_tree_contents([('branch/foo', 'thecontents')])
 
1469
        t.add("foo")
 
1470
        t.commit("message")
 
1471
        self.reset_smart_call_log()
 
1472
        out, err = self.run_bzr(['info', '-v', self.get_url('branch')])
 
1473
        # This figure represent the amount of work to perform this use case. It
 
1474
        # is entirely ok to reduce this number if a test fails due to rpc_count
 
1475
        # being too low. If rpc_count increases, more network roundtrips have
 
1476
        # become necessary for this use case. Please do not adjust this number
 
1477
        # upwards without agreement from bzr's network support maintainers.
 
1478
        self.assertLength(16, self.hpss_calls)
 
1479
        self.assertLength(1, self.hpss_connections)
 
1480
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)