~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

NEWS section template into a separate file

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006, 2007 Canonical Ltd
 
1
# Copyright (C) 2006, 2007, 2008 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
21
20
import sys
22
21
 
23
 
import bzrlib
24
22
from bzrlib import (
 
23
    branch,
25
24
    bzrdir,
26
25
    errors,
27
26
    info,
28
27
    osutils,
29
 
    repository,
 
28
    upgrade,
30
29
    urlutils,
31
30
    )
32
31
from bzrlib.osutils import format_date
36
35
 
37
36
class TestInfo(ExternalBase):
38
37
 
 
38
    def setUp(self):
 
39
        ExternalBase.setUp(self)
 
40
        self._repo_strings = "2a or development-subtree"
 
41
 
39
42
    def test_info_non_existing(self):
40
43
        if sys.platform == "win32":
41
44
            location = "C:/i/do/not/exist/"
62
65
""", out)
63
66
        self.assertEqual('', err)
64
67
 
 
68
        # Standalone branch - verbose mode
65
69
        out, err = self.run_bzr('info standalone -v')
66
70
        self.assertEqualDiff(
67
71
"""Standalone tree (format: weave)
86
90
 
87
91
Branch history:
88
92
         0 revisions
 
93
 
 
94
Repository:
 
95
         0 revisions
 
96
""", out)
 
97
        self.assertEqual('', err)
 
98
 
 
99
        # Standalone branch - really verbose mode
 
100
        out, err = self.run_bzr('info standalone -vv')
 
101
        self.assertEqualDiff(
 
102
"""Standalone tree (format: weave)
 
103
Location:
 
104
  branch root: standalone
 
105
 
 
106
Format:
 
107
       control: All-in-one format 6
 
108
  working tree: Working tree format 2
 
109
        branch: Branch format 4
 
110
    repository: Weave repository format 6
 
111
 
 
112
In the working tree:
 
113
         0 unchanged
 
114
         0 modified
 
115
         1 added
 
116
         0 removed
 
117
         0 renamed
 
118
         0 unknown
 
119
         0 ignored
 
120
         0 versioned subdirectories
 
121
 
 
122
Branch history:
 
123
         0 revisions
89
124
         0 committers
90
125
 
91
126
Repository:
140
175
 
141
176
Branch history:
142
177
         1 revision
143
 
         1 committer
144
178
         0 days old
145
179
   first revision: %s
146
180
  latest revision: %s
155
189
        # (creates backup as unknown)
156
190
        branch1.bzrdir.sprout('bound')
157
191
        knit1_format = bzrdir.format_registry.make_bzrdir('knit')
158
 
        bzrlib.upgrade.upgrade('bound', knit1_format)
159
 
        branch3 = bzrlib.bzrdir.BzrDir.open('bound').open_branch()
 
192
        upgrade.upgrade('bound', knit1_format)
 
193
        branch3 = bzrdir.BzrDir.open('bound').open_branch()
160
194
        branch3.bind(branch1)
161
195
        bound_tree = branch3.bzrdir.open_workingtree()
162
196
        out, err = self.run_bzr('info -v bound')
187
221
 
188
222
Branch history:
189
223
         1 revision
190
 
         1 committer
191
224
         0 days old
192
225
   first revision: %s
193
226
  latest revision: %s
202
235
        self.assertEqual('', err)
203
236
 
204
237
        # Checkout standalone (same as above, but does not have parent set)
205
 
        branch4 = bzrlib.bzrdir.BzrDir.create_branch_convenience('checkout',
 
238
        branch4 = bzrdir.BzrDir.create_branch_convenience('checkout',
206
239
            format=knit1_format)
207
240
        branch4.bind(branch1)
208
241
        branch4.bzrdir.open_workingtree().update()
231
264
 
232
265
Branch history:
233
266
         1 revision
234
 
         1 committer
235
267
         0 days old
236
268
   first revision: %s
237
269
  latest revision: %s
248
280
        branch5 = tree5.branch
249
281
        out, err = self.run_bzr('info -v lightcheckout')
250
282
        self.assertEqualDiff(
251
 
"""Lightweight checkout (format: dirstate or dirstate-tags or \
252
 
pack-0.92 or rich-root or rich-root-pack)
 
283
"""Lightweight checkout (format: %s)
253
284
Location:
254
285
  light checkout root: lightcheckout
255
286
   checkout of branch: standalone
256
287
 
257
288
Format:
258
289
       control: Meta directory format 1
259
 
  working tree: Working tree format 4
 
290
  working tree: Working tree format 6
260
291
        branch: Branch format 4
261
292
    repository: Weave repository format 6
262
293
 
272
303
 
273
304
Branch history:
274
305
         1 revision
275
 
         1 committer
276
306
         0 days old
277
307
   first revision: %s
278
308
  latest revision: %s
279
309
 
280
310
Repository:
281
311
         1 revision
282
 
""" % (datestring_first, datestring_first,), out)
 
312
""" % (self._repo_strings, datestring_first, datestring_first,), out)
283
313
        self.assertEqual('', err)
284
314
 
285
315
        # Update initial standalone branch
318
348
 
319
349
Branch history:
320
350
         1 revision
321
 
         1 committer
322
351
         0 days old
323
352
   first revision: %s
324
353
  latest revision: %s
360
389
 
361
390
Branch history:
362
391
         1 revision
363
 
         1 committer
364
392
         0 days old
365
393
   first revision: %s
366
394
  latest revision: %s
400
428
 
401
429
Branch history:
402
430
         1 revision
403
 
         1 committer
404
431
         0 days old
405
432
   first revision: %s
406
433
  latest revision: %s
415
442
        # Out of date lightweight checkout
416
443
        out, err = self.run_bzr('info lightcheckout --verbose')
417
444
        self.assertEqualDiff(
418
 
"""Lightweight checkout (format: dirstate or dirstate-tags or \
419
 
pack-0.92 or rich-root or rich-root-pack)
 
445
"""Lightweight checkout (format: %s)
420
446
Location:
421
447
  light checkout root: lightcheckout
422
448
   checkout of branch: standalone
423
449
 
424
450
Format:
425
451
       control: Meta directory format 1
426
 
  working tree: Working tree format 4
 
452
  working tree: Working tree format 6
427
453
        branch: Branch format 4
428
454
    repository: Weave repository format 6
429
455
 
441
467
 
442
468
Branch history:
443
469
         2 revisions
444
 
         1 committer
445
470
         0 days old
446
471
   first revision: %s
447
472
  latest revision: %s
448
473
 
449
474
Repository:
450
475
         2 revisions
451
 
""" % (datestring_first, datestring_last,), out)
 
476
""" % (self._repo_strings, datestring_first, datestring_last,), out)
452
477
        self.assertEqual('', err)
453
478
 
454
479
    def test_info_standalone_no_tree(self):
469
494
 
470
495
Branch history:
471
496
         0 revisions
472
 
         0 committers
473
497
 
474
498
Repository:
475
499
         0 revisions
520
544
 
521
545
Branch history:
522
546
         0 revisions
523
 
         0 committers
524
547
 
525
548
Repository:
526
549
         0 revisions
532
555
        # Create lightweight checkout
533
556
        transport.mkdir('tree')
534
557
        transport.mkdir('tree/lightcheckout')
535
 
        tree2 = branch1.create_checkout('tree/lightcheckout', 
 
558
        tree2 = branch1.create_checkout('tree/lightcheckout',
536
559
            lightweight=True)
537
560
        branch2 = tree2.branch
538
561
        self.assertCheckoutStatusOutput('-v tree/lightcheckout', tree2,
551
574
        datestring_first = format_date(rev.timestamp, rev.timezone)
552
575
        out, err = self.run_bzr('info tree/lightcheckout --verbose')
553
576
        self.assertEqualDiff(
554
 
"""Lightweight checkout (format: dirstate or dirstate-tags or \
555
 
pack-0.92 or rich-root or rich-root-pack)
 
577
"""Lightweight checkout (format: %s)
556
578
Location:
557
579
  light checkout root: tree/lightcheckout
558
580
   checkout of branch: repo/branch
560
582
 
561
583
Format:
562
584
       control: Meta directory format 1
563
 
  working tree: Working tree format 4
 
585
  working tree: Working tree format 6
564
586
        branch: %s
565
587
    repository: %s
566
588
 
576
598
 
577
599
Branch history:
578
600
         1 revision
579
 
         1 committer
580
601
         0 days old
581
602
   first revision: %s
582
603
  latest revision: %s
583
604
 
584
605
Repository:
585
606
         1 revision
586
 
""" % (format.get_branch_format().get_format_description(),
 
607
""" % (self._repo_strings, format.get_branch_format().get_format_description(),
587
608
       format.repository_format.get_format_description(),
588
609
       datestring_first, datestring_first,
589
610
       ), out)
592
613
        # Out of date checkout
593
614
        out, err = self.run_bzr('info -v tree/checkout')
594
615
        self.assertEqualDiff(
595
 
"""Checkout (format: dirstate)
 
616
"""Checkout (format: unnamed)
596
617
Location:
597
618
       checkout root: tree/checkout
598
619
  checkout of branch: repo/branch
599
620
 
600
621
Format:
601
622
       control: Meta directory format 1
602
 
  working tree: Working tree format 4
 
623
  working tree: Working tree format 6
603
624
        branch: %s
604
625
    repository: %s
605
626
 
617
638
 
618
639
Branch history:
619
640
         0 revisions
620
 
         0 committers
621
641
 
622
642
Repository:
623
643
         0 revisions
632
652
        tree3.add('b')
633
653
        out, err = self.run_bzr('info tree/checkout --verbose')
634
654
        self.assertEqualDiff(
635
 
"""Checkout (format: dirstate)
 
655
"""Checkout (format: unnamed)
636
656
Location:
637
657
       checkout root: tree/checkout
638
658
  checkout of branch: repo/branch
639
659
 
640
660
Format:
641
661
       control: Meta directory format 1
642
 
  working tree: Working tree format 4
 
662
  working tree: Working tree format 6
643
663
        branch: %s
644
664
    repository: %s
645
665
 
655
675
 
656
676
Branch history:
657
677
         1 revision
658
 
         1 committer
659
678
         0 days old
660
679
   first revision: %s
661
680
  latest revision: %s
674
693
        datestring_last = format_date(rev.timestamp, rev.timezone)
675
694
        out, err = self.run_bzr('info tree/lightcheckout --verbose')
676
695
        self.assertEqualDiff(
677
 
"""Lightweight checkout (format: dirstate or dirstate-tags or \
678
 
pack-0.92 or rich-root or rich-root-pack)
 
696
"""Lightweight checkout (format: %s)
679
697
Location:
680
698
  light checkout root: tree/lightcheckout
681
699
   checkout of branch: repo/branch
683
701
 
684
702
Format:
685
703
       control: Meta directory format 1
686
 
  working tree: Working tree format 4
 
704
  working tree: Working tree format 6
687
705
        branch: %s
688
706
    repository: %s
689
707
 
701
719
 
702
720
Branch history:
703
721
         2 revisions
704
 
         1 committer
705
722
         0 days old
706
723
   first revision: %s
707
724
  latest revision: %s
708
725
 
709
726
Repository:
710
727
         2 revisions
711
 
""" % (format.get_branch_format().get_format_description(),
 
728
""" % (self._repo_strings, format.get_branch_format().get_format_description(),
712
729
       format.repository_format.get_format_description(),
713
730
       datestring_first, datestring_last,
714
731
       ), out)
729
746
 
730
747
Branch history:
731
748
         2 revisions
732
 
         1 committer
733
749
         0 days old
734
750
   first revision: %s
735
751
  latest revision: %s
816
832
 
817
833
Branch history:
818
834
         0 revisions
819
 
         0 committers
820
835
 
821
836
Repository:
822
837
         0 revisions
857
872
 
858
873
Branch history:
859
874
         1 revision
860
 
         1 committer
861
875
         0 days old
862
876
   first revision: %s
863
877
  latest revision: %s
899
913
 
900
914
Branch history:
901
915
         0 revisions
902
 
         0 committers
903
916
 
904
917
Repository:
905
918
         1 revision
939
952
 
940
953
Branch history:
941
954
         1 revision
942
 
         1 committer
943
955
         0 days old
944
956
   first revision: %s
945
957
  latest revision: %s
971
983
       ),
972
984
       out)
973
985
        self.assertEqual('', err)
974
 
    
 
986
 
975
987
    def test_info_shared_repository_with_tree_in_root(self):
976
988
        format = bzrdir.format_registry.make_bzrdir('knit')
977
989
        transport = self.get_transport()
1026
1038
 
1027
1039
Branch history:
1028
1040
         0 revisions
1029
 
         0 committers
1030
1041
 
1031
1042
Repository:
1032
1043
         0 revisions
1035
1046
       ), out)
1036
1047
        self.assertEqual('', err)
1037
1048
 
 
1049
    def test_info_repository_hook(self):
 
1050
        format = bzrdir.format_registry.make_bzrdir('knit')
 
1051
        def repo_info(repo, stats, outf):
 
1052
            outf.write("more info\n")
 
1053
        info.hooks.install_named_hook('repository', repo_info, None)
 
1054
        # Create shared repository with working trees
 
1055
        repo = self.make_repository('repo', shared=True, format=format)
 
1056
        out, err = self.run_bzr('info -v repo')
 
1057
        self.assertEqualDiff(
 
1058
"""Shared repository with trees (format: dirstate or dirstate-tags or knit)
 
1059
Location:
 
1060
  shared repository: repo
 
1061
 
 
1062
Format:
 
1063
       control: Meta directory format 1
 
1064
    repository: %s
 
1065
 
 
1066
Create working tree for new branches inside the repository.
 
1067
 
 
1068
Repository:
 
1069
         0 revisions
 
1070
more info
 
1071
""" % (format.repository_format.get_format_description(),
 
1072
       ), out)
 
1073
        self.assertEqual('', err)
 
1074
 
1038
1075
    def assertCheckoutStatusOutput(self,
1039
1076
        command_string, lco_tree, shared_repo=None,
1040
1077
        repo_branch=None,
1050
1087
        allow us, the test writers, to document what *should* be present in
1051
1088
        the output. Removing this separation would remove the value of the
1052
1089
        tests.
1053
 
        
 
1090
 
1054
1091
        :param path: the path to the light checkout.
1055
1092
        :param lco_tree: the tree object for the light checkout.
1056
1093
        :param shared_repo: A shared repository is in use, expect that in
1064
1101
            actually locked then this parameter is overridden. This is because
1065
1102
            pack repositories do not have any public API for obtaining an
1066
1103
            exclusive repository wide lock.
1067
 
        :param verbose: If true, expect verbose output
 
1104
        :param verbose: verbosity level: 2 or higher to show committers
1068
1105
        """
1069
1106
        def friendly_location(url):
1070
1107
            path = urlutils.unescape_for_display(url, 'ascii')
1089
1126
            (False, True): 'Lightweight checkout',
1090
1127
            (False, False): 'Checkout',
1091
1128
            }[(shared_repo is not None, light_checkout)]
1092
 
        format = {True: 'dirstate or dirstate-tags or pack-0.92'
1093
 
                        ' or rich-root or rich-root-pack',
1094
 
                  False: 'dirstate'}[light_checkout]
 
1129
        format = {True: self._repo_strings,
 
1130
                  False: 'unnamed'}[light_checkout]
1095
1131
        if repo_locked:
1096
1132
            repo_locked = lco_tree.branch.repository.get_physical_lock_status()
1097
1133
        if repo_locked or branch_locked or tree_locked:
1134
1170
        else:
1135
1171
            branch_data = ("   checkout of branch: %s\n" %
1136
1172
                lco_tree.branch.bzrdir.root_transport.base)
1137
 
        
1138
 
        if verbose:
 
1173
 
 
1174
        if verbose >= 2:
1139
1175
            verbose_info = '         0 committers\n'
1140
1176
        else:
1141
1177
            verbose_info = ''
1142
 
            
 
1178
 
1143
1179
        self.assertEqualDiff(
1144
1180
"""%s (format: %s)
1145
1181
Location:
1181
1217
        transport = self.get_transport()
1182
1218
        # Create shared repository with a branch
1183
1219
        repo = self.make_repository('repo', shared=True,
1184
 
                                    format=bzrlib.bzrdir.BzrDirMetaFormat1())
 
1220
                                    format=bzrdir.BzrDirMetaFormat1())
1185
1221
        repo.set_make_working_trees(False)
1186
1222
        repo.bzrdir.root_transport.mkdir('branch')
1187
1223
        repo_branch = repo.bzrdir.create_branch_convenience('repo/branch',
1188
 
                                    format=bzrlib.bzrdir.BzrDirMetaFormat1())
 
1224
                                    format=bzrdir.BzrDirMetaFormat1())
1189
1225
        # Do a heavy checkout
1190
1226
        transport.mkdir('tree')
1191
1227
        transport.mkdir('tree/checkout')
1192
 
        co_branch = bzrlib.bzrdir.BzrDir.create_branch_convenience('tree/checkout',
1193
 
            format=bzrlib.bzrdir.BzrDirMetaFormat1())
 
1228
        co_branch = bzrdir.BzrDir.create_branch_convenience('tree/checkout',
 
1229
            format=bzrdir.BzrDirMetaFormat1())
1194
1230
        co_branch.bind(repo_branch)
1195
1231
        # Do a light checkout of the heavy one
1196
1232
        transport.mkdir('tree/lightcheckout')
1197
 
        lco_dir = bzrlib.bzrdir.BzrDirMetaFormat1().initialize('tree/lightcheckout')
1198
 
        bzrlib.branch.BranchReferenceFormat().initialize(lco_dir, co_branch)
 
1233
        lco_dir = bzrdir.BzrDirMetaFormat1().initialize('tree/lightcheckout')
 
1234
        branch.BranchReferenceFormat().initialize(lco_dir, co_branch)
1199
1235
        lco_dir.create_workingtree()
1200
1236
        lco_tree = lco_dir.open_workingtree()
1201
1237
 
1292
1328
    def test_info_locking_oslocks(self):
1293
1329
        if sys.platform == "win32":
1294
1330
            raise TestSkipped("don't use oslocks on win32 in unix manner")
 
1331
        self.thisFailsStrictLockCheck()
1295
1332
 
1296
1333
        tree = self.make_branch_and_tree('branch',
1297
 
                                         format=bzrlib.bzrdir.BzrDirFormat6())
 
1334
                                         format=bzrdir.BzrDirFormat6())
1298
1335
 
1299
1336
        # Test all permutations of locking the working tree, branch and repository
1300
1337
        # XXX: Well not yet, as we can't query oslocks yet. Currently, it's
1327
1364
 
1328
1365
Branch history:
1329
1366
         0 revisions
1330
 
         0 committers
1331
1367
 
1332
1368
Repository:
1333
1369
         0 revisions
1360
1396
 
1361
1397
Branch history:
1362
1398
         0 revisions
1363
 
         0 committers
1364
1399
 
1365
1400
Repository:
1366
1401
         0 revisions
1372
1407
    def test_info_stacked(self):
1373
1408
        # We have a mainline
1374
1409
        trunk_tree = self.make_branch_and_tree('mainline',
1375
 
            format='development1')
 
1410
            format='1.6')
1376
1411
        trunk_tree.commit('mainline')
1377
1412
        # and a branch from it which is stacked
1378
1413
        new_dir = trunk_tree.bzrdir.sprout('newbranch', stacked=True)
1379
1414
        out, err = self.run_bzr('info newbranch')
1380
1415
        self.assertEqual(
1381
 
"""Standalone tree (format: development1)
 
1416
"""Standalone tree (format: 1.6)
1382
1417
Location:
1383
1418
  branch root: newbranch
1384
1419