~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Jelmer Vernooij
  • Date: 2016-04-03 16:32:31 UTC
  • mto: This revision was merged to the branch mainline in revision 6617.
  • Revision ID: jelmer@jelmer.uk-20160403163231-h72bo0uyek2gikw0
Don't put French text in doc/en/user-reference when LANGUAGE=fr_CH.UTF_8.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2010 Canonical Ltd
 
1
# Copyright (C) 2006-2012, 2016 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
17
17
 
18
18
"""Tests for the info command of bzr."""
19
19
 
 
20
import shutil
20
21
import sys
21
22
 
22
23
from bzrlib import (
23
24
    branch,
24
25
    bzrdir,
 
26
    controldir,
25
27
    errors,
26
28
    info,
27
29
    osutils,
29
31
    upgrade,
30
32
    urlutils,
31
33
    )
 
34
from bzrlib.tests.matchers import ContainsNoVfsCalls
32
35
from bzrlib.transport import memory
33
36
 
34
37
 
45
48
        self.assertEqual(out, '')
46
49
        self.assertEqual(err, 'bzr: ERROR: Not a branch: "%s".\n' % location)
47
50
 
 
51
    def test_info_empty_controldir(self):
 
52
        self.make_bzrdir('ctrl')
 
53
        out, err = self.run_bzr('info ctrl')
 
54
        self.assertEqual(out,
 
55
            'Empty control directory (format: 2a or pack-0.92)\n'
 
56
            'Location:\n'
 
57
            '  control directory: ctrl\n')
 
58
        self.assertEqual(err, '')
 
59
 
 
60
    def test_info_empty_controldir_verbose(self):
 
61
        self.make_bzrdir('ctrl')
 
62
        out, err = self.run_bzr('info -v ctrl')
 
63
        self.assertEqualDiff(out,
 
64
            'Empty control directory (format: 2a or pack-0.92)\n'
 
65
            'Location:\n'
 
66
            '  control directory: ctrl\n\n'
 
67
            'Format:\n'
 
68
            '       control: Meta directory format 1\n\n'
 
69
            'Control directory:\n'
 
70
            '         0 branches\n')
 
71
        self.assertEqual(err, '')
 
72
 
 
73
    def test_info_dangling_branch_reference(self):
 
74
        br = self.make_branch('target')
 
75
        br.create_checkout('from', lightweight=True)
 
76
        shutil.rmtree('target')
 
77
        out, err = self.run_bzr('info from')
 
78
        self.assertEqual(out,
 
79
            'Dangling branch reference (format: 2a or pack-0.92)\n'
 
80
            'Location:\n'
 
81
            '   control directory: from\n'
 
82
            '  checkout of branch: target\n')
 
83
        self.assertEqual(err, '')
 
84
 
48
85
    def test_info_standalone(self):
49
86
        transport = self.get_transport()
50
87
 
75
112
        branch: Branch format 5
76
113
    repository: Knit repository format 1
77
114
 
 
115
Control directory:
 
116
         1 branches
 
117
 
78
118
In the working tree:
79
119
         0 unchanged
80
120
         0 modified
106
146
        branch: Branch format 5
107
147
    repository: Knit repository format 1
108
148
 
 
149
Control directory:
 
150
         1 branches
 
151
 
109
152
In the working tree:
110
153
         0 unchanged
111
154
         0 modified
125
168
""", out)
126
169
        self.assertEqual('', err)
127
170
        tree1.commit('commit one')
128
 
        rev = branch1.repository.get_revision(branch1.revision_history()[0])
 
171
        rev = branch1.repository.get_revision(branch1.last_revision())
129
172
        datestring_first = osutils.format_date(rev.timestamp, rev.timezone)
130
173
 
131
174
        # Branch standalone with push location
160
203
        branch: Branch format 5
161
204
    repository: Knit repository format 1
162
205
 
 
206
Control directory:
 
207
         1 branches
 
208
 
163
209
In the working tree:
164
210
         1 unchanged
165
211
         0 modified
185
231
        # Branch and bind to standalone, needs upgrade to metadir
186
232
        # (creates backup as unknown)
187
233
        branch1.bzrdir.sprout('bound')
188
 
        knit1_format = bzrdir.format_registry.make_bzrdir('knit')
 
234
        knit1_format = controldir.format_registry.make_bzrdir('knit')
189
235
        upgrade.upgrade('bound', knit1_format)
190
 
        branch3 = bzrdir.BzrDir.open('bound').open_branch()
 
236
        branch3 = controldir.ControlDir.open('bound').open_branch()
191
237
        branch3.bind(branch1)
192
238
        bound_tree = branch3.bzrdir.open_workingtree()
193
239
        out, err = self.run_bzr('info -v bound')
206
252
        branch: %s
207
253
    repository: %s
208
254
 
 
255
Control directory:
 
256
         1 branches
 
257
 
209
258
In the working tree:
210
259
         1 unchanged
211
260
         0 modified
232
281
        self.assertEqual('', err)
233
282
 
234
283
        # Checkout standalone (same as above, but does not have parent set)
235
 
        branch4 = bzrdir.BzrDir.create_branch_convenience('checkout',
 
284
        branch4 = controldir.ControlDir.create_branch_convenience('checkout',
236
285
            format=knit1_format)
237
286
        branch4.bind(branch1)
238
287
        branch4.bzrdir.open_workingtree().update()
249
298
        branch: Branch format 5
250
299
    repository: %s
251
300
 
 
301
Control directory:
 
302
         1 branches
 
303
 
252
304
In the working tree:
253
305
         1 unchanged
254
306
         0 modified
276
328
        tree5 = branch1.create_checkout('lightcheckout', lightweight=True)
277
329
        branch5 = tree5.branch
278
330
        out, err = self.run_bzr('info -v lightcheckout')
279
 
        if "metaweave" in bzrdir.format_registry:
 
331
        if "metaweave" in controldir.format_registry:
280
332
            format_description = "knit or metaweave"
281
333
        else:
282
334
            format_description = "knit"
292
344
        branch: Branch format 5
293
345
    repository: Knit repository format 1
294
346
 
 
347
Control directory:
 
348
         1 branches
 
349
 
295
350
In the working tree:
296
351
         1 unchanged
297
352
         0 modified
317
372
        self.build_tree(['standalone/b'])
318
373
        tree1.add('b')
319
374
        tree1.commit('commit two')
320
 
        rev = branch1.repository.get_revision(branch1.revision_history()[-1])
 
375
        rev = branch1.repository.get_revision(branch1.last_revision())
321
376
        datestring_last = osutils.format_date(rev.timestamp, rev.timezone)
322
377
 
323
378
        # Out of date branched standalone branch will not be detected
337
392
        branch: Branch format 5
338
393
    repository: Knit repository format 1
339
394
 
 
395
Control directory:
 
396
         1 branches
 
397
 
340
398
In the working tree:
341
399
         1 unchanged
342
400
         0 modified
376
434
        branch: Branch format 5
377
435
    repository: %s
378
436
 
 
437
Control directory:
 
438
         1 branches
 
439
 
379
440
Branch is out of date: missing 1 revision.
380
441
 
381
442
In the working tree:
415
476
        branch: Branch format 5
416
477
    repository: %s
417
478
 
 
479
Control directory:
 
480
         1 branches
 
481
 
418
482
Branch is out of date: missing 1 revision.
419
483
 
420
484
In the working tree:
454
518
        branch: Branch format 5
455
519
    repository: Knit repository format 1
456
520
 
 
521
Control directory:
 
522
         1 branches
 
523
 
457
524
Working tree is out of date: missing 1 revision.
458
525
 
459
526
In the working tree:
479
546
 
480
547
    def test_info_standalone_no_tree(self):
481
548
        # create standalone branch without a working tree
482
 
        format = bzrdir.format_registry.make_bzrdir('default')
 
549
        format = controldir.format_registry.make_bzrdir('default')
483
550
        branch = self.make_branch('branch')
484
551
        repo = branch.repository
485
552
        out, err = self.run_bzr('info branch -v')
493
560
        branch: %s
494
561
    repository: %s
495
562
 
 
563
Control directory:
 
564
         1 branches
 
565
 
496
566
Branch history:
497
567
         0 revisions
498
568
 
505
575
        self.assertEqual('', err)
506
576
 
507
577
    def test_info_shared_repository(self):
508
 
        format = bzrdir.format_registry.make_bzrdir('knit')
 
578
        format = controldir.format_registry.make_bzrdir('knit')
509
579
        transport = self.get_transport()
510
580
 
511
581
        # Create shared repository
521
591
       control: Meta directory format 1
522
592
    repository: %s
523
593
 
 
594
Control directory:
 
595
         0 branches
 
596
 
524
597
Repository:
525
598
         0 revisions
526
599
""" % ('repo', format.repository_format.get_format_description(),
529
602
 
530
603
        # Create branch inside shared repository
531
604
        repo.bzrdir.root_transport.mkdir('branch')
532
 
        branch1 = repo.bzrdir.create_branch_convenience('repo/branch',
533
 
            format=format)
 
605
        branch1 = controldir.ControlDir.create_branch_convenience(
 
606
            'repo/branch', format=format)
534
607
        out, err = self.run_bzr('info -v repo/branch')
535
608
        self.assertEqualDiff(
536
609
"""Repository branch (format: dirstate or knit)
543
616
        branch: %s
544
617
    repository: %s
545
618
 
 
619
Control directory:
 
620
         1 branches
 
621
 
546
622
Branch history:
547
623
         0 revisions
548
624
 
571
647
        self.build_tree(['tree/lightcheckout/a'])
572
648
        tree2.add('a')
573
649
        tree2.commit('commit one')
574
 
        rev = repo.get_revision(branch2.revision_history()[0])
 
650
        rev = repo.get_revision(branch2.last_revision())
575
651
        datestring_first = osutils.format_date(rev.timestamp, rev.timezone)
576
652
        out, err = self.run_bzr('info tree/lightcheckout --verbose')
577
653
        self.assertEqualDiff(
587
663
        branch: %s
588
664
    repository: %s
589
665
 
 
666
Control directory:
 
667
         1 branches
 
668
 
590
669
In the working tree:
591
670
         1 unchanged
592
671
         0 modified
625
704
        branch: %s
626
705
    repository: %s
627
706
 
 
707
Control directory:
 
708
         1 branches
 
709
 
628
710
Branch is out of date: missing 1 revision.
629
711
 
630
712
In the working tree:
664
746
        branch: %s
665
747
    repository: %s
666
748
 
 
749
Control directory:
 
750
         1 branches
 
751
 
667
752
In the working tree:
668
753
         1 unchanged
669
754
         0 modified
690
775
        tree3.commit('commit two')
691
776
 
692
777
        # Out of date lightweight checkout
693
 
        rev = repo.get_revision(branch1.revision_history()[-1])
 
778
        rev = repo.get_revision(branch1.last_revision())
694
779
        datestring_last = osutils.format_date(rev.timestamp, rev.timezone)
695
780
        out, err = self.run_bzr('info tree/lightcheckout --verbose')
696
781
        self.assertEqualDiff(
706
791
        branch: %s
707
792
    repository: %s
708
793
 
 
794
Control directory:
 
795
         1 branches
 
796
 
709
797
Working tree is out of date: missing 1 revision.
710
798
 
711
799
In the working tree:
745
833
        branch: %s
746
834
    repository: %s
747
835
 
 
836
Control directory:
 
837
         1 branches
 
838
 
748
839
Branch history:
749
840
         2 revisions
750
841
         0 days old
770
861
       control: Meta directory format 1
771
862
    repository: %s
772
863
 
 
864
Control directory:
 
865
         0 branches
 
866
 
773
867
Repository:
774
868
         2 revisions
775
869
""" % (format.repository_format.get_format_description(),
777
871
        self.assertEqual('', err)
778
872
 
779
873
    def test_info_shared_repository_with_trees(self):
780
 
        format = bzrdir.format_registry.make_bzrdir('knit')
 
874
        format = controldir.format_registry.make_bzrdir('knit')
781
875
        transport = self.get_transport()
782
876
 
783
877
        # Create shared repository with working trees
793
887
       control: Meta directory format 1
794
888
    repository: %s
795
889
 
 
890
Control directory:
 
891
         0 branches
 
892
 
796
893
Create working tree for new branches inside the repository.
797
894
 
798
895
Repository:
803
900
 
804
901
        # Create two branches
805
902
        repo.bzrdir.root_transport.mkdir('branch1')
806
 
        branch1 = repo.bzrdir.create_branch_convenience('repo/branch1',
 
903
        branch1 = controldir.ControlDir.create_branch_convenience('repo/branch1',
807
904
            format=format)
808
905
        branch2 = branch1.bzrdir.sprout('repo/branch2').open_branch()
809
906
 
821
918
        branch: %s
822
919
    repository: %s
823
920
 
 
921
Control directory:
 
922
         1 branches
 
923
 
824
924
In the working tree:
825
925
         0 unchanged
826
926
         0 modified
846
946
        tree1 = branch1.bzrdir.open_workingtree()
847
947
        tree1.add('a')
848
948
        tree1.commit('commit one')
849
 
        rev = repo.get_revision(branch1.revision_history()[0])
 
949
        rev = repo.get_revision(branch1.last_revision())
850
950
        datestring_first = osutils.format_date(rev.timestamp, rev.timezone)
851
951
        out, err = self.run_bzr('info -v repo/branch1')
852
952
        self.assertEqualDiff(
861
961
        branch: %s
862
962
    repository: %s
863
963
 
 
964
Control directory:
 
965
         1 branches
 
966
 
864
967
In the working tree:
865
968
         1 unchanged
866
969
         0 modified
902
1005
        branch: %s
903
1006
    repository: %s
904
1007
 
 
1008
Control directory:
 
1009
         1 branches
 
1010
 
905
1011
In the working tree:
906
1012
         0 unchanged
907
1013
         0 modified
941
1047
        branch: %s
942
1048
    repository: %s
943
1049
 
 
1050
Control directory:
 
1051
         1 branches
 
1052
 
944
1053
In the working tree:
945
1054
         1 unchanged
946
1055
         0 modified
976
1085
       control: Meta directory format 1
977
1086
    repository: %s
978
1087
 
 
1088
Control directory:
 
1089
         0 branches
 
1090
 
979
1091
Create working tree for new branches inside the repository.
980
1092
 
981
1093
Repository:
986
1098
        self.assertEqual('', err)
987
1099
 
988
1100
    def test_info_shared_repository_with_tree_in_root(self):
989
 
        format = bzrdir.format_registry.make_bzrdir('knit')
 
1101
        format = controldir.format_registry.make_bzrdir('knit')
990
1102
        transport = self.get_transport()
991
1103
 
992
1104
        # Create shared repository with working trees
1002
1114
       control: Meta directory format 1
1003
1115
    repository: %s
1004
1116
 
 
1117
Control directory:
 
1118
         0 branches
 
1119
 
1005
1120
Create working tree for new branches inside the repository.
1006
1121
 
1007
1122
Repository:
1027
1142
        branch: %s
1028
1143
    repository: %s
1029
1144
 
 
1145
Control directory:
 
1146
         1 branches
 
1147
 
1030
1148
In the working tree:
1031
1149
         0 unchanged
1032
1150
         0 modified
1048
1166
        self.assertEqual('', err)
1049
1167
 
1050
1168
    def test_info_repository_hook(self):
1051
 
        format = bzrdir.format_registry.make_bzrdir('knit')
 
1169
        format = controldir.format_registry.make_bzrdir('knit')
1052
1170
        def repo_info(repo, stats, outf):
1053
1171
            outf.write("more info\n")
1054
1172
        info.hooks.install_named_hook('repository', repo_info, None)
1064
1182
       control: Meta directory format 1
1065
1183
    repository: %s
1066
1184
 
 
1185
Control directory:
 
1186
         0 branches
 
1187
 
1067
1188
Create working tree for new branches inside the repository.
1068
1189
 
1069
1190
Repository:
1073
1194
       ), out)
1074
1195
        self.assertEqual('', err)
1075
1196
 
 
1197
    def test_info_unshared_repository_with_colocated_branches(self):
 
1198
        format = controldir.format_registry.make_bzrdir('development-colo')
 
1199
        transport = self.get_transport()
 
1200
 
 
1201
        # Create unshared repository
 
1202
        repo = self.make_repository('repo', shared=False, format=format)
 
1203
        repo.set_make_working_trees(True)
 
1204
        repo.bzrdir.create_branch(name='foo')
 
1205
        out, err = self.run_bzr('info repo')
 
1206
        self.assertEqualDiff(
 
1207
"""Unshared repository with trees and colocated branches (format: development-colo)
 
1208
Location:
 
1209
  repository: repo
 
1210
""", out)
 
1211
        self.assertEqual('', err)
 
1212
 
1076
1213
    def assertCheckoutStatusOutput(self,
1077
1214
        command_string, lco_tree, shared_repo=None,
1078
1215
        repo_branch=None,
1187
1324
        branch: %s
1188
1325
    repository: %s
1189
1326
%s
 
1327
Control directory:
 
1328
         1 branches
 
1329
 
1190
1330
In the working tree:
1191
1331
         0 unchanged
1192
1332
         0 modified
1221
1361
                                    format=bzrdir.BzrDirMetaFormat1())
1222
1362
        repo.set_make_working_trees(False)
1223
1363
        repo.bzrdir.root_transport.mkdir('branch')
1224
 
        repo_branch = repo.bzrdir.create_branch_convenience('repo/branch',
1225
 
                                    format=bzrdir.BzrDirMetaFormat1())
 
1364
        repo_branch = controldir.ControlDir.create_branch_convenience(
 
1365
            'repo/branch', format=bzrdir.BzrDirMetaFormat1())
1226
1366
        # Do a heavy checkout
1227
1367
        transport.mkdir('tree')
1228
1368
        transport.mkdir('tree/checkout')
1229
 
        co_branch = bzrdir.BzrDir.create_branch_convenience('tree/checkout',
1230
 
            format=bzrdir.BzrDirMetaFormat1())
 
1369
        co_branch = controldir.ControlDir.create_branch_convenience(
 
1370
            'tree/checkout', format=bzrdir.BzrDirMetaFormat1())
1231
1371
        co_branch.bind(repo_branch)
1232
1372
        # Do a light checkout of the heavy one
1233
1373
        transport.mkdir('tree/lightcheckout')
1234
1374
        lco_dir = bzrdir.BzrDirMetaFormat1().initialize('tree/lightcheckout')
1235
 
        branch.BranchReferenceFormat().initialize(lco_dir,
1236
 
            target_branch=co_branch)
 
1375
        lco_dir.set_branch_reference(co_branch)
1237
1376
        lco_dir.create_workingtree()
1238
1377
        lco_tree = lco_dir.open_workingtree()
1239
1378
 
1345
1484
     stacked on: mainline
1346
1485
""", out)
1347
1486
        self.assertEqual("", err)
 
1487
 
 
1488
    def test_info_revinfo_optional(self):
 
1489
        tree = self.make_branch_and_tree('.')
 
1490
        def last_revision_info(self):
 
1491
            raise errors.UnsupportedOperation(last_revision_info, self)
 
1492
        self.overrideAttr(
 
1493
            branch.Branch, "last_revision_info", last_revision_info)
 
1494
        out, err = self.run_bzr('info -v .')
 
1495
        self.assertEqual(
 
1496
"""Standalone tree (format: 2a)
 
1497
Location:
 
1498
  branch root: .
 
1499
 
 
1500
Format:
 
1501
       control: Meta directory format 1
 
1502
  working tree: Working tree format 6
 
1503
        branch: Branch format 7
 
1504
    repository: Repository format 2a - rich roots, group compression and chk inventories
 
1505
 
 
1506
Control directory:
 
1507
         1 branches
 
1508
 
 
1509
In the working tree:
 
1510
         0 unchanged
 
1511
         0 modified
 
1512
         0 added
 
1513
         0 removed
 
1514
         0 renamed
 
1515
         0 unknown
 
1516
         0 ignored
 
1517
         0 versioned subdirectories
 
1518
""", out)
 
1519
        self.assertEqual("", err)
 
1520
 
 
1521
    def test_info_shows_colocated_branches(self):
 
1522
        bzrdir = self.make_branch('.', format='development-colo').bzrdir
 
1523
        bzrdir.create_branch(name="colo1")
 
1524
        bzrdir.create_branch(name="colo2")
 
1525
        bzrdir.create_branch(name="colo3")
 
1526
        out, err = self.run_bzr('info -v .')
 
1527
        self.assertEqualDiff(
 
1528
"""Standalone branch (format: development-colo)
 
1529
Location:
 
1530
  branch root: .
 
1531
 
 
1532
Format:
 
1533
       control: Meta directory format 1 with support for colocated branches
 
1534
        branch: Branch format 7
 
1535
    repository: Repository format 2a - rich roots, group compression and chk inventories
 
1536
 
 
1537
Control directory:
 
1538
         4 branches
 
1539
 
 
1540
Branch history:
 
1541
         0 revisions
 
1542
 
 
1543
Repository:
 
1544
         0 revisions
 
1545
""", out)
 
1546
        self.assertEqual("", err)
 
1547
 
 
1548
 
 
1549
class TestSmartServerInfo(tests.TestCaseWithTransport):
 
1550
 
 
1551
    def test_simple_branch_info(self):
 
1552
        self.setup_smart_server_with_call_log()
 
1553
        t = self.make_branch_and_tree('branch')
 
1554
        self.build_tree_contents([('branch/foo', 'thecontents')])
 
1555
        t.add("foo")
 
1556
        t.commit("message")
 
1557
        self.reset_smart_call_log()
 
1558
        out, err = self.run_bzr(['info', self.get_url('branch')])
 
1559
        # This figure represent the amount of work to perform this use case. It
 
1560
        # is entirely ok to reduce this number if a test fails due to rpc_count
 
1561
        # being too low. If rpc_count increases, more network roundtrips have
 
1562
        # become necessary for this use case. Please do not adjust this number
 
1563
        # upwards without agreement from bzr's network support maintainers.
 
1564
        self.assertLength(10, self.hpss_calls)
 
1565
        self.assertLength(1, self.hpss_connections)
 
1566
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
 
1567
 
 
1568
    def test_verbose_branch_info(self):
 
1569
        self.setup_smart_server_with_call_log()
 
1570
        t = self.make_branch_and_tree('branch')
 
1571
        self.build_tree_contents([('branch/foo', 'thecontents')])
 
1572
        t.add("foo")
 
1573
        t.commit("message")
 
1574
        self.reset_smart_call_log()
 
1575
        out, err = self.run_bzr(['info', '-v', self.get_url('branch')])
 
1576
        # This figure represent the amount of work to perform this use case. It
 
1577
        # is entirely ok to reduce this number if a test fails due to rpc_count
 
1578
        # being too low. If rpc_count increases, more network roundtrips have
 
1579
        # become necessary for this use case. Please do not adjust this number
 
1580
        # upwards without agreement from bzr's network support maintainers.
 
1581
        self.assertLength(14, self.hpss_calls)
 
1582
        self.assertLength(1, self.hpss_connections)
 
1583
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)