~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2008-07-17 09:40:51 UTC
  • mfrom: (3518.1.2 virtualvf)
  • Revision ID: pqm@pqm.ubuntu.com-20080717094051-cgyo1zagozwcd4mm
(Jelmer) Add VirtualVersionedFiles class.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2010 Canonical Ltd
 
1
# Copyright (C) 2006, 2007 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
 
18
18
"""Tests for the info command of bzr."""
19
19
 
 
20
import os
20
21
import sys
21
22
 
 
23
import bzrlib
22
24
from bzrlib import (
23
 
    branch,
24
25
    bzrdir,
25
26
    errors,
26
27
    info,
27
28
    osutils,
28
 
    tests,
29
 
    upgrade,
 
29
    repository,
30
30
    urlutils,
31
31
    )
32
 
from bzrlib.transport import memory
33
 
 
34
 
 
35
 
class TestInfo(tests.TestCaseWithTransport):
36
 
 
37
 
    def setUp(self):
38
 
        super(TestInfo, self).setUp()
39
 
        self._repo_strings = "2a"
 
32
from bzrlib.osutils import format_date
 
33
from bzrlib.tests import TestSkipped
 
34
from bzrlib.tests.blackbox import ExternalBase
 
35
 
 
36
 
 
37
class TestInfo(ExternalBase):
40
38
 
41
39
    def test_info_non_existing(self):
42
 
        self.vfs_transport_factory = memory.MemoryServer
43
 
        location = self.get_url()
 
40
        if sys.platform == "win32":
 
41
            location = "C:/i/do/not/exist/"
 
42
        else:
 
43
            location = "/i/do/not/exist/"
44
44
        out, err = self.run_bzr('info '+location, retcode=3)
45
45
        self.assertEqual(out, '')
46
46
        self.assertEqual(err, 'bzr: ERROR: Not a branch: "%s".\n' % location)
62
62
""", out)
63
63
        self.assertEqual('', err)
64
64
 
65
 
        # Standalone branch - verbose mode
66
65
        out, err = self.run_bzr('info standalone -v')
67
66
        self.assertEqualDiff(
68
67
"""Standalone tree (format: weave)
87
86
 
88
87
Branch history:
89
88
         0 revisions
90
 
 
91
 
Repository:
92
 
         0 revisions
93
 
""", out)
94
 
        self.assertEqual('', err)
95
 
 
96
 
        # Standalone branch - really verbose mode
97
 
        out, err = self.run_bzr('info standalone -vv')
98
 
        self.assertEqualDiff(
99
 
"""Standalone tree (format: weave)
100
 
Location:
101
 
  branch root: standalone
102
 
 
103
 
Format:
104
 
       control: All-in-one format 6
105
 
  working tree: Working tree format 2
106
 
        branch: Branch format 4
107
 
    repository: Weave repository format 6
108
 
 
109
 
In the working tree:
110
 
         0 unchanged
111
 
         0 modified
112
 
         1 added
113
 
         0 removed
114
 
         0 renamed
115
 
         0 unknown
116
 
         0 ignored
117
 
         0 versioned subdirectories
118
 
 
119
 
Branch history:
120
 
         0 revisions
121
89
         0 committers
122
90
 
123
91
Repository:
126
94
        self.assertEqual('', err)
127
95
        tree1.commit('commit one')
128
96
        rev = branch1.repository.get_revision(branch1.revision_history()[0])
129
 
        datestring_first = osutils.format_date(rev.timestamp, rev.timezone)
 
97
        datestring_first = format_date(rev.timestamp, rev.timezone)
130
98
 
131
99
        # Branch standalone with push location
132
100
        branch2 = branch1.bzrdir.sprout('branch').open_branch()
172
140
 
173
141
Branch history:
174
142
         1 revision
 
143
         1 committer
175
144
         0 days old
176
145
   first revision: %s
177
146
  latest revision: %s
186
155
        # (creates backup as unknown)
187
156
        branch1.bzrdir.sprout('bound')
188
157
        knit1_format = bzrdir.format_registry.make_bzrdir('knit')
189
 
        upgrade.upgrade('bound', knit1_format)
190
 
        branch3 = bzrdir.BzrDir.open('bound').open_branch()
 
158
        bzrlib.upgrade.upgrade('bound', knit1_format)
 
159
        branch3 = bzrlib.bzrdir.BzrDir.open('bound').open_branch()
191
160
        branch3.bind(branch1)
192
161
        bound_tree = branch3.bzrdir.open_workingtree()
193
162
        out, err = self.run_bzr('info -v bound')
212
181
         0 added
213
182
         0 removed
214
183
         0 renamed
215
 
         0 unknown
216
 
         1 ignored
 
184
         1 unknown
 
185
         0 ignored
217
186
         0 versioned subdirectories
218
187
 
219
188
Branch history:
220
189
         1 revision
 
190
         1 committer
221
191
         0 days old
222
192
   first revision: %s
223
193
  latest revision: %s
232
202
        self.assertEqual('', err)
233
203
 
234
204
        # Checkout standalone (same as above, but does not have parent set)
235
 
        branch4 = bzrdir.BzrDir.create_branch_convenience('checkout',
 
205
        branch4 = bzrlib.bzrdir.BzrDir.create_branch_convenience('checkout',
236
206
            format=knit1_format)
237
207
        branch4.bind(branch1)
238
208
        branch4.bzrdir.open_workingtree().update()
261
231
 
262
232
Branch history:
263
233
         1 revision
 
234
         1 committer
264
235
         0 days old
265
236
   first revision: %s
266
237
  latest revision: %s
277
248
        branch5 = tree5.branch
278
249
        out, err = self.run_bzr('info -v lightcheckout')
279
250
        self.assertEqualDiff(
280
 
"""Lightweight checkout (format: %s)
 
251
"""Lightweight checkout (format: dirstate or dirstate-tags or \
 
252
pack-0.92 or rich-root or rich-root-pack)
281
253
Location:
282
254
  light checkout root: lightcheckout
283
255
   checkout of branch: standalone
284
256
 
285
257
Format:
286
258
       control: Meta directory format 1
287
 
  working tree: Working tree format 6
 
259
  working tree: Working tree format 4
288
260
        branch: Branch format 4
289
261
    repository: Weave repository format 6
290
262
 
300
272
 
301
273
Branch history:
302
274
         1 revision
 
275
         1 committer
303
276
         0 days old
304
277
   first revision: %s
305
278
  latest revision: %s
306
279
 
307
280
Repository:
308
281
         1 revision
309
 
""" % (self._repo_strings, datestring_first, datestring_first,), out)
 
282
""" % (datestring_first, datestring_first,), out)
310
283
        self.assertEqual('', err)
311
284
 
312
285
        # Update initial standalone branch
314
287
        tree1.add('b')
315
288
        tree1.commit('commit two')
316
289
        rev = branch1.repository.get_revision(branch1.revision_history()[-1])
317
 
        datestring_last = osutils.format_date(rev.timestamp, rev.timezone)
 
290
        datestring_last = format_date(rev.timestamp, rev.timezone)
318
291
 
319
292
        # Out of date branched standalone branch will not be detected
320
293
        out, err = self.run_bzr('info -v branch')
345
318
 
346
319
Branch history:
347
320
         1 revision
 
321
         1 committer
348
322
         0 days old
349
323
   first revision: %s
350
324
  latest revision: %s
380
354
         0 added
381
355
         0 removed
382
356
         0 renamed
383
 
         0 unknown
384
 
         1 ignored
 
357
         1 unknown
 
358
         0 ignored
385
359
         0 versioned subdirectories
386
360
 
387
361
Branch history:
388
362
         1 revision
 
363
         1 committer
389
364
         0 days old
390
365
   first revision: %s
391
366
  latest revision: %s
425
400
 
426
401
Branch history:
427
402
         1 revision
 
403
         1 committer
428
404
         0 days old
429
405
   first revision: %s
430
406
  latest revision: %s
439
415
        # Out of date lightweight checkout
440
416
        out, err = self.run_bzr('info lightcheckout --verbose')
441
417
        self.assertEqualDiff(
442
 
"""Lightweight checkout (format: %s)
 
418
"""Lightweight checkout (format: dirstate or dirstate-tags or \
 
419
pack-0.92 or rich-root or rich-root-pack)
443
420
Location:
444
421
  light checkout root: lightcheckout
445
422
   checkout of branch: standalone
446
423
 
447
424
Format:
448
425
       control: Meta directory format 1
449
 
  working tree: Working tree format 6
 
426
  working tree: Working tree format 4
450
427
        branch: Branch format 4
451
428
    repository: Weave repository format 6
452
429
 
464
441
 
465
442
Branch history:
466
443
         2 revisions
 
444
         1 committer
467
445
         0 days old
468
446
   first revision: %s
469
447
  latest revision: %s
470
448
 
471
449
Repository:
472
450
         2 revisions
473
 
""" % (self._repo_strings, datestring_first, datestring_last,), out)
 
451
""" % (datestring_first, datestring_last,), out)
474
452
        self.assertEqual('', err)
475
453
 
476
454
    def test_info_standalone_no_tree(self):
491
469
 
492
470
Branch history:
493
471
         0 revisions
 
472
         0 committers
494
473
 
495
474
Repository:
496
475
         0 revisions
541
520
 
542
521
Branch history:
543
522
         0 revisions
 
523
         0 committers
544
524
 
545
525
Repository:
546
526
         0 revisions
552
532
        # Create lightweight checkout
553
533
        transport.mkdir('tree')
554
534
        transport.mkdir('tree/lightcheckout')
555
 
        tree2 = branch1.create_checkout('tree/lightcheckout',
 
535
        tree2 = branch1.create_checkout('tree/lightcheckout', 
556
536
            lightweight=True)
557
537
        branch2 = tree2.branch
558
538
        self.assertCheckoutStatusOutput('-v tree/lightcheckout', tree2,
568
548
        tree2.add('a')
569
549
        tree2.commit('commit one')
570
550
        rev = repo.get_revision(branch2.revision_history()[0])
571
 
        datestring_first = osutils.format_date(rev.timestamp, rev.timezone)
 
551
        datestring_first = format_date(rev.timestamp, rev.timezone)
572
552
        out, err = self.run_bzr('info tree/lightcheckout --verbose')
573
553
        self.assertEqualDiff(
574
 
"""Lightweight checkout (format: %s)
 
554
"""Lightweight checkout (format: dirstate or dirstate-tags or \
 
555
pack-0.92 or rich-root or rich-root-pack)
575
556
Location:
576
557
  light checkout root: tree/lightcheckout
577
558
   checkout of branch: repo/branch
579
560
 
580
561
Format:
581
562
       control: Meta directory format 1
582
 
  working tree: Working tree format 6
 
563
  working tree: Working tree format 4
583
564
        branch: %s
584
565
    repository: %s
585
566
 
595
576
 
596
577
Branch history:
597
578
         1 revision
 
579
         1 committer
598
580
         0 days old
599
581
   first revision: %s
600
582
  latest revision: %s
601
583
 
602
584
Repository:
603
585
         1 revision
604
 
""" % (self._repo_strings, format.get_branch_format().get_format_description(),
 
586
""" % (format.get_branch_format().get_format_description(),
605
587
       format.repository_format.get_format_description(),
606
588
       datestring_first, datestring_first,
607
589
       ), out)
610
592
        # Out of date checkout
611
593
        out, err = self.run_bzr('info -v tree/checkout')
612
594
        self.assertEqualDiff(
613
 
"""Checkout (format: unnamed)
 
595
"""Checkout (format: dirstate)
614
596
Location:
615
597
       checkout root: tree/checkout
616
598
  checkout of branch: repo/branch
617
599
 
618
600
Format:
619
601
       control: Meta directory format 1
620
 
  working tree: Working tree format 6
 
602
  working tree: Working tree format 4
621
603
        branch: %s
622
604
    repository: %s
623
605
 
635
617
 
636
618
Branch history:
637
619
         0 revisions
 
620
         0 committers
638
621
 
639
622
Repository:
640
623
         0 revisions
649
632
        tree3.add('b')
650
633
        out, err = self.run_bzr('info tree/checkout --verbose')
651
634
        self.assertEqualDiff(
652
 
"""Checkout (format: unnamed)
 
635
"""Checkout (format: dirstate)
653
636
Location:
654
637
       checkout root: tree/checkout
655
638
  checkout of branch: repo/branch
656
639
 
657
640
Format:
658
641
       control: Meta directory format 1
659
 
  working tree: Working tree format 6
 
642
  working tree: Working tree format 4
660
643
        branch: %s
661
644
    repository: %s
662
645
 
672
655
 
673
656
Branch history:
674
657
         1 revision
 
658
         1 committer
675
659
         0 days old
676
660
   first revision: %s
677
661
  latest revision: %s
687
671
 
688
672
        # Out of date lightweight checkout
689
673
        rev = repo.get_revision(branch1.revision_history()[-1])
690
 
        datestring_last = osutils.format_date(rev.timestamp, rev.timezone)
 
674
        datestring_last = format_date(rev.timestamp, rev.timezone)
691
675
        out, err = self.run_bzr('info tree/lightcheckout --verbose')
692
676
        self.assertEqualDiff(
693
 
"""Lightweight checkout (format: %s)
 
677
"""Lightweight checkout (format: dirstate or dirstate-tags or \
 
678
pack-0.92 or rich-root or rich-root-pack)
694
679
Location:
695
680
  light checkout root: tree/lightcheckout
696
681
   checkout of branch: repo/branch
698
683
 
699
684
Format:
700
685
       control: Meta directory format 1
701
 
  working tree: Working tree format 6
 
686
  working tree: Working tree format 4
702
687
        branch: %s
703
688
    repository: %s
704
689
 
716
701
 
717
702
Branch history:
718
703
         2 revisions
 
704
         1 committer
719
705
         0 days old
720
706
   first revision: %s
721
707
  latest revision: %s
722
708
 
723
709
Repository:
724
710
         2 revisions
725
 
""" % (self._repo_strings, format.get_branch_format().get_format_description(),
 
711
""" % (format.get_branch_format().get_format_description(),
726
712
       format.repository_format.get_format_description(),
727
713
       datestring_first, datestring_last,
728
714
       ), out)
743
729
 
744
730
Branch history:
745
731
         2 revisions
 
732
         1 committer
746
733
         0 days old
747
734
   first revision: %s
748
735
  latest revision: %s
829
816
 
830
817
Branch history:
831
818
         0 revisions
 
819
         0 committers
832
820
 
833
821
Repository:
834
822
         0 revisions
843
831
        tree1.add('a')
844
832
        tree1.commit('commit one')
845
833
        rev = repo.get_revision(branch1.revision_history()[0])
846
 
        datestring_first = osutils.format_date(rev.timestamp, rev.timezone)
 
834
        datestring_first = format_date(rev.timestamp, rev.timezone)
847
835
        out, err = self.run_bzr('info -v repo/branch1')
848
836
        self.assertEqualDiff(
849
837
"""Repository tree (format: knit)
869
857
 
870
858
Branch history:
871
859
         1 revision
 
860
         1 committer
872
861
         0 days old
873
862
   first revision: %s
874
863
  latest revision: %s
910
899
 
911
900
Branch history:
912
901
         0 revisions
 
902
         0 committers
913
903
 
914
904
Repository:
915
905
         1 revision
949
939
 
950
940
Branch history:
951
941
         1 revision
 
942
         1 committer
952
943
         0 days old
953
944
   first revision: %s
954
945
  latest revision: %s
980
971
       ),
981
972
       out)
982
973
        self.assertEqual('', err)
983
 
 
 
974
    
984
975
    def test_info_shared_repository_with_tree_in_root(self):
985
976
        format = bzrdir.format_registry.make_bzrdir('knit')
986
977
        transport = self.get_transport()
1035
1026
 
1036
1027
Branch history:
1037
1028
         0 revisions
 
1029
         0 committers
1038
1030
 
1039
1031
Repository:
1040
1032
         0 revisions
1043
1035
       ), out)
1044
1036
        self.assertEqual('', err)
1045
1037
 
1046
 
    def test_info_repository_hook(self):
1047
 
        format = bzrdir.format_registry.make_bzrdir('knit')
1048
 
        def repo_info(repo, stats, outf):
1049
 
            outf.write("more info\n")
1050
 
        info.hooks.install_named_hook('repository', repo_info, None)
1051
 
        # Create shared repository with working trees
1052
 
        repo = self.make_repository('repo', shared=True, format=format)
1053
 
        out, err = self.run_bzr('info -v repo')
1054
 
        self.assertEqualDiff(
1055
 
"""Shared repository with trees (format: dirstate or dirstate-tags or knit)
1056
 
Location:
1057
 
  shared repository: repo
1058
 
 
1059
 
Format:
1060
 
       control: Meta directory format 1
1061
 
    repository: %s
1062
 
 
1063
 
Create working tree for new branches inside the repository.
1064
 
 
1065
 
Repository:
1066
 
         0 revisions
1067
 
more info
1068
 
""" % (format.repository_format.get_format_description(),
1069
 
       ), out)
1070
 
        self.assertEqual('', err)
1071
 
 
1072
1038
    def assertCheckoutStatusOutput(self,
1073
1039
        command_string, lco_tree, shared_repo=None,
1074
1040
        repo_branch=None,
1084
1050
        allow us, the test writers, to document what *should* be present in
1085
1051
        the output. Removing this separation would remove the value of the
1086
1052
        tests.
1087
 
 
 
1053
        
1088
1054
        :param path: the path to the light checkout.
1089
1055
        :param lco_tree: the tree object for the light checkout.
1090
1056
        :param shared_repo: A shared repository is in use, expect that in
1098
1064
            actually locked then this parameter is overridden. This is because
1099
1065
            pack repositories do not have any public API for obtaining an
1100
1066
            exclusive repository wide lock.
1101
 
        :param verbose: verbosity level: 2 or higher to show committers
 
1067
        :param verbose: If true, expect verbose output
1102
1068
        """
1103
1069
        def friendly_location(url):
1104
1070
            path = urlutils.unescape_for_display(url, 'ascii')
1123
1089
            (False, True): 'Lightweight checkout',
1124
1090
            (False, False): 'Checkout',
1125
1091
            }[(shared_repo is not None, light_checkout)]
1126
 
        format = {True: self._repo_strings,
1127
 
                  False: 'unnamed'}[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]
1128
1095
        if repo_locked:
1129
1096
            repo_locked = lco_tree.branch.repository.get_physical_lock_status()
1130
1097
        if repo_locked or branch_locked or tree_locked:
1167
1134
        else:
1168
1135
            branch_data = ("   checkout of branch: %s\n" %
1169
1136
                lco_tree.branch.bzrdir.root_transport.base)
1170
 
 
1171
 
        if verbose >= 2:
 
1137
        
 
1138
        if verbose:
1172
1139
            verbose_info = '         0 committers\n'
1173
1140
        else:
1174
1141
            verbose_info = ''
1175
 
 
 
1142
            
1176
1143
        self.assertEqualDiff(
1177
1144
"""%s (format: %s)
1178
1145
Location:
1214
1181
        transport = self.get_transport()
1215
1182
        # Create shared repository with a branch
1216
1183
        repo = self.make_repository('repo', shared=True,
1217
 
                                    format=bzrdir.BzrDirMetaFormat1())
 
1184
                                    format=bzrlib.bzrdir.BzrDirMetaFormat1())
1218
1185
        repo.set_make_working_trees(False)
1219
1186
        repo.bzrdir.root_transport.mkdir('branch')
1220
1187
        repo_branch = repo.bzrdir.create_branch_convenience('repo/branch',
1221
 
                                    format=bzrdir.BzrDirMetaFormat1())
 
1188
                                    format=bzrlib.bzrdir.BzrDirMetaFormat1())
1222
1189
        # Do a heavy checkout
1223
1190
        transport.mkdir('tree')
1224
1191
        transport.mkdir('tree/checkout')
1225
 
        co_branch = bzrdir.BzrDir.create_branch_convenience('tree/checkout',
1226
 
            format=bzrdir.BzrDirMetaFormat1())
 
1192
        co_branch = bzrlib.bzrdir.BzrDir.create_branch_convenience('tree/checkout',
 
1193
            format=bzrlib.bzrdir.BzrDirMetaFormat1())
1227
1194
        co_branch.bind(repo_branch)
1228
1195
        # Do a light checkout of the heavy one
1229
1196
        transport.mkdir('tree/lightcheckout')
1230
 
        lco_dir = bzrdir.BzrDirMetaFormat1().initialize('tree/lightcheckout')
1231
 
        branch.BranchReferenceFormat().initialize(lco_dir,
1232
 
            target_branch=co_branch)
 
1197
        lco_dir = bzrlib.bzrdir.BzrDirMetaFormat1().initialize('tree/lightcheckout')
 
1198
        bzrlib.branch.BranchReferenceFormat().initialize(lco_dir, co_branch)
1233
1199
        lco_dir.create_workingtree()
1234
1200
        lco_tree = lco_dir.open_workingtree()
1235
1201
 
1325
1291
 
1326
1292
    def test_info_locking_oslocks(self):
1327
1293
        if sys.platform == "win32":
1328
 
            self.skip("don't use oslocks on win32 in unix manner")
1329
 
        # This test tests old (all-in-one, OS lock using) behaviour which
1330
 
        # simply cannot work on windows (and is indeed why we changed our
1331
 
        # design. As such, don't try to remove the thisFailsStrictLockCheck
1332
 
        # call here.
1333
 
        self.thisFailsStrictLockCheck()
 
1294
            raise TestSkipped("don't use oslocks on win32 in unix manner")
1334
1295
 
1335
1296
        tree = self.make_branch_and_tree('branch',
1336
 
                                         format=bzrdir.BzrDirFormat6())
 
1297
                                         format=bzrlib.bzrdir.BzrDirFormat6())
1337
1298
 
1338
1299
        # Test all permutations of locking the working tree, branch and repository
1339
1300
        # XXX: Well not yet, as we can't query oslocks yet. Currently, it's
1366
1327
 
1367
1328
Branch history:
1368
1329
         0 revisions
 
1330
         0 committers
1369
1331
 
1370
1332
Repository:
1371
1333
         0 revisions
1398
1360
 
1399
1361
Branch history:
1400
1362
         0 revisions
 
1363
         0 committers
1401
1364
 
1402
1365
Repository:
1403
1366
         0 revisions
1409
1372
    def test_info_stacked(self):
1410
1373
        # We have a mainline
1411
1374
        trunk_tree = self.make_branch_and_tree('mainline',
1412
 
            format='1.6')
 
1375
            format='development1')
1413
1376
        trunk_tree.commit('mainline')
1414
1377
        # and a branch from it which is stacked
1415
1378
        new_dir = trunk_tree.bzrdir.sprout('newbranch', stacked=True)
1416
1379
        out, err = self.run_bzr('info newbranch')
1417
1380
        self.assertEqual(
1418
 
"""Standalone tree (format: 1.6)
 
1381
"""Standalone tree (format: development1)
1419
1382
Location:
1420
1383
  branch root: newbranch
1421
1384