~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: 2012-01-24 13:14:06 UTC
  • mto: (6445.4.5 nested-trees-spec)
  • mto: This revision was merged to the branch mainline in revision 6518.
  • Revision ID: jelmer@samba.org-20120124131406-wedftkorbpv37bm0
Import nested tree doc from devnotes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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.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
 
48
72
    def test_info_standalone(self):
49
73
        transport = self.get_transport()
50
74
 
51
75
        # Create initial standalone branch
52
 
        tree1 = self.make_branch_and_tree('standalone', 'weave')
 
76
        tree1 = self.make_branch_and_tree('standalone', 'knit')
53
77
        self.build_tree(['standalone/a'])
54
78
        tree1.add('a')
55
79
        branch1 = tree1.branch
56
80
 
57
81
        out, err = self.run_bzr('info standalone')
58
82
        self.assertEqualDiff(
59
 
"""Standalone tree (format: weave)
 
83
"""Standalone tree (format: knit)
60
84
Location:
61
85
  branch root: standalone
62
86
""", out)
65
89
        # Standalone branch - verbose mode
66
90
        out, err = self.run_bzr('info standalone -v')
67
91
        self.assertEqualDiff(
68
 
"""Standalone tree (format: weave)
 
92
"""Standalone tree (format: knit)
69
93
Location:
70
94
  branch root: standalone
71
95
 
72
96
Format:
73
 
       control: All-in-one format 6
74
 
  working tree: Working tree format 2
75
 
        branch: Branch format 4
76
 
    repository: Weave repository format 6
 
97
       control: Meta directory format 1
 
98
  working tree: Working tree format 3
 
99
        branch: Branch format 5
 
100
    repository: Knit repository format 1
77
101
 
78
102
In the working tree:
79
103
         0 unchanged
96
120
        # Standalone branch - really verbose mode
97
121
        out, err = self.run_bzr('info standalone -vv')
98
122
        self.assertEqualDiff(
99
 
"""Standalone tree (format: weave)
 
123
"""Standalone tree (format: knit)
100
124
Location:
101
125
  branch root: standalone
102
126
 
103
127
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
 
128
       control: Meta directory format 1
 
129
  working tree: Working tree format 3
 
130
        branch: Branch format 5
 
131
    repository: Knit repository format 1
108
132
 
109
133
In the working tree:
110
134
         0 unchanged
125
149
""", out)
126
150
        self.assertEqual('', err)
127
151
        tree1.commit('commit one')
128
 
        rev = branch1.repository.get_revision(branch1.revision_history()[0])
 
152
        rev = branch1.repository.get_revision(branch1.last_revision())
129
153
        datestring_first = osutils.format_date(rev.timestamp, rev.timezone)
130
154
 
131
155
        # Branch standalone with push location
134
158
 
135
159
        out, err = self.run_bzr('info branch')
136
160
        self.assertEqualDiff(
137
 
"""Standalone tree (format: weave)
 
161
"""Standalone tree (format: knit)
138
162
Location:
139
163
  branch root: branch
140
164
 
146
170
 
147
171
        out, err = self.run_bzr('info branch --verbose')
148
172
        self.assertEqualDiff(
149
 
"""Standalone tree (format: weave)
 
173
"""Standalone tree (format: knit)
150
174
Location:
151
175
  branch root: branch
152
176
 
155
179
  parent branch: standalone
156
180
 
157
181
Format:
158
 
       control: All-in-one format 6
159
 
  working tree: Working tree format 2
160
 
        branch: Branch format 4
161
 
    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
162
186
 
163
187
In the working tree:
164
188
         1 unchanged
187
211
        branch1.bzrdir.sprout('bound')
188
212
        knit1_format = bzrdir.format_registry.make_bzrdir('knit')
189
213
        upgrade.upgrade('bound', knit1_format)
190
 
        branch3 = bzrdir.BzrDir.open('bound').open_branch()
 
214
        branch3 = controldir.ControlDir.open('bound').open_branch()
191
215
        branch3.bind(branch1)
192
216
        bound_tree = branch3.bzrdir.open_workingtree()
193
217
        out, err = self.run_bzr('info -v bound')
213
237
         0 removed
214
238
         0 renamed
215
239
         0 unknown
216
 
         1 ignored
 
240
         0 ignored
217
241
         0 versioned subdirectories
218
242
 
219
243
Branch history:
232
256
        self.assertEqual('', err)
233
257
 
234
258
        # Checkout standalone (same as above, but does not have parent set)
235
 
        branch4 = bzrdir.BzrDir.create_branch_convenience('checkout',
 
259
        branch4 = controldir.ControlDir.create_branch_convenience('checkout',
236
260
            format=knit1_format)
237
261
        branch4.bind(branch1)
238
262
        branch4.bzrdir.open_workingtree().update()
276
300
        tree5 = branch1.create_checkout('lightcheckout', lightweight=True)
277
301
        branch5 = tree5.branch
278
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"
279
307
        self.assertEqualDiff(
280
308
"""Lightweight checkout (format: %s)
281
309
Location:
284
312
 
285
313
Format:
286
314
       control: Meta directory format 1
287
 
  working tree: Working tree format 6
288
 
        branch: Branch format 4
289
 
    repository: Weave repository format 6
 
315
  working tree: Working tree format 3
 
316
        branch: Branch format 5
 
317
    repository: Knit repository format 1
290
318
 
291
319
In the working tree:
292
320
         1 unchanged
306
334
 
307
335
Repository:
308
336
         1 revision
309
 
""" % (self._repo_strings, datestring_first, datestring_first,), out)
 
337
""" % (format_description, datestring_first, datestring_first,), out)
310
338
        self.assertEqual('', err)
311
339
 
312
340
        # Update initial standalone branch
313
341
        self.build_tree(['standalone/b'])
314
342
        tree1.add('b')
315
343
        tree1.commit('commit two')
316
 
        rev = branch1.repository.get_revision(branch1.revision_history()[-1])
 
344
        rev = branch1.repository.get_revision(branch1.last_revision())
317
345
        datestring_last = osutils.format_date(rev.timestamp, rev.timezone)
318
346
 
319
347
        # Out of date branched standalone branch will not be detected
320
348
        out, err = self.run_bzr('info -v branch')
321
349
        self.assertEqualDiff(
322
 
"""Standalone tree (format: weave)
 
350
"""Standalone tree (format: knit)
323
351
Location:
324
352
  branch root: branch
325
353
 
328
356
  parent branch: standalone
329
357
 
330
358
Format:
331
 
       control: All-in-one format 6
332
 
  working tree: Working tree format 2
333
 
        branch: Branch format 4
334
 
    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
335
363
 
336
364
In the working tree:
337
365
         1 unchanged
381
409
         0 removed
382
410
         0 renamed
383
411
         0 unknown
384
 
         1 ignored
 
412
         0 ignored
385
413
         0 versioned subdirectories
386
414
 
387
415
Branch history:
446
474
 
447
475
Format:
448
476
       control: Meta directory format 1
449
 
  working tree: Working tree format 6
450
 
        branch: Branch format 4
451
 
    repository: Weave repository format 6
 
477
  working tree: Working tree format 3
 
478
        branch: Branch format 5
 
479
    repository: Knit repository format 1
452
480
 
453
481
Working tree is out of date: missing 1 revision.
454
482
 
470
498
 
471
499
Repository:
472
500
         2 revisions
473
 
""" % (self._repo_strings, datestring_first, datestring_last,), out)
 
501
""" % (format_description, datestring_first, datestring_last,), out)
474
502
        self.assertEqual('', err)
475
503
 
476
504
    def test_info_standalone_no_tree(self):
525
553
 
526
554
        # Create branch inside shared repository
527
555
        repo.bzrdir.root_transport.mkdir('branch')
528
 
        branch1 = repo.bzrdir.create_branch_convenience('repo/branch',
529
 
            format=format)
 
556
        branch1 = controldir.ControlDir.create_branch_convenience(
 
557
            'repo/branch', format=format)
530
558
        out, err = self.run_bzr('info -v repo/branch')
531
559
        self.assertEqualDiff(
532
560
"""Repository branch (format: dirstate or knit)
567
595
        self.build_tree(['tree/lightcheckout/a'])
568
596
        tree2.add('a')
569
597
        tree2.commit('commit one')
570
 
        rev = repo.get_revision(branch2.revision_history()[0])
 
598
        rev = repo.get_revision(branch2.last_revision())
571
599
        datestring_first = osutils.format_date(rev.timestamp, rev.timezone)
572
600
        out, err = self.run_bzr('info tree/lightcheckout --verbose')
573
601
        self.assertEqualDiff(
686
714
        tree3.commit('commit two')
687
715
 
688
716
        # Out of date lightweight checkout
689
 
        rev = repo.get_revision(branch1.revision_history()[-1])
 
717
        rev = repo.get_revision(branch1.last_revision())
690
718
        datestring_last = osutils.format_date(rev.timestamp, rev.timezone)
691
719
        out, err = self.run_bzr('info tree/lightcheckout --verbose')
692
720
        self.assertEqualDiff(
799
827
 
800
828
        # Create two branches
801
829
        repo.bzrdir.root_transport.mkdir('branch1')
802
 
        branch1 = repo.bzrdir.create_branch_convenience('repo/branch1',
 
830
        branch1 = controldir.ControlDir.create_branch_convenience('repo/branch1',
803
831
            format=format)
804
832
        branch2 = branch1.bzrdir.sprout('repo/branch2').open_branch()
805
833
 
842
870
        tree1 = branch1.bzrdir.open_workingtree()
843
871
        tree1.add('a')
844
872
        tree1.commit('commit one')
845
 
        rev = repo.get_revision(branch1.revision_history()[0])
 
873
        rev = repo.get_revision(branch1.last_revision())
846
874
        datestring_first = osutils.format_date(rev.timestamp, rev.timezone)
847
875
        out, err = self.run_bzr('info -v repo/branch1')
848
876
        self.assertEqualDiff(
1069
1097
       ), out)
1070
1098
        self.assertEqual('', err)
1071
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
 
1072
1116
    def assertCheckoutStatusOutput(self,
1073
1117
        command_string, lco_tree, shared_repo=None,
1074
1118
        repo_branch=None,
1217
1261
                                    format=bzrdir.BzrDirMetaFormat1())
1218
1262
        repo.set_make_working_trees(False)
1219
1263
        repo.bzrdir.root_transport.mkdir('branch')
1220
 
        repo_branch = repo.bzrdir.create_branch_convenience('repo/branch',
1221
 
                                    format=bzrdir.BzrDirMetaFormat1())
 
1264
        repo_branch = controldir.ControlDir.create_branch_convenience(
 
1265
            'repo/branch', format=bzrdir.BzrDirMetaFormat1())
1222
1266
        # Do a heavy checkout
1223
1267
        transport.mkdir('tree')
1224
1268
        transport.mkdir('tree/checkout')
1225
 
        co_branch = bzrdir.BzrDir.create_branch_convenience('tree/checkout',
1226
 
            format=bzrdir.BzrDirMetaFormat1())
 
1269
        co_branch = controldir.ControlDir.create_branch_convenience(
 
1270
            'tree/checkout', format=bzrdir.BzrDirMetaFormat1())
1227
1271
        co_branch.bind(repo_branch)
1228
1272
        # Do a light checkout of the heavy one
1229
1273
        transport.mkdir('tree/lightcheckout')
1230
1274
        lco_dir = bzrdir.BzrDirMetaFormat1().initialize('tree/lightcheckout')
1231
 
        branch.BranchReferenceFormat().initialize(lco_dir,
1232
 
            target_branch=co_branch)
 
1275
        lco_dir.set_branch_reference(co_branch)
1233
1276
        lco_dir.create_workingtree()
1234
1277
        lco_tree = lco_dir.open_workingtree()
1235
1278
 
1323
1366
            self.knownFailure('Win32 cannot run "bzr info"'
1324
1367
                              ' when the tree is locked.')
1325
1368
 
1326
 
    def test_info_locking_oslocks(self):
1327
 
        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()
1334
 
 
1335
 
        tree = self.make_branch_and_tree('branch',
1336
 
                                         format=bzrdir.BzrDirFormat6())
1337
 
 
1338
 
        # Test all permutations of locking the working tree, branch and repository
1339
 
        # XXX: Well not yet, as we can't query oslocks yet. Currently, it's
1340
 
        # implemented by raising NotImplementedError and get_physical_lock_status()
1341
 
        # always returns false. This makes bzr info hide the lock status.  (Olaf)
1342
 
        # W B R
1343
 
 
1344
 
        # U U U
1345
 
        out, err = self.run_bzr('info -v branch')
1346
 
        self.assertEqualDiff(
1347
 
"""Standalone tree (format: weave)
1348
 
Location:
1349
 
  branch root: %s
1350
 
 
1351
 
Format:
1352
 
       control: All-in-one format 6
1353
 
  working tree: Working tree format 2
1354
 
        branch: Branch format 4
1355
 
    repository: %s
1356
 
 
1357
 
In the working tree:
1358
 
         0 unchanged
1359
 
         0 modified
1360
 
         0 added
1361
 
         0 removed
1362
 
         0 renamed
1363
 
         0 unknown
1364
 
         0 ignored
1365
 
         0 versioned subdirectories
1366
 
 
1367
 
Branch history:
1368
 
         0 revisions
1369
 
 
1370
 
Repository:
1371
 
         0 revisions
1372
 
""" % ('branch', tree.branch.repository._format.get_format_description(),
1373
 
       ), out)
1374
 
        self.assertEqual('', err)
1375
 
        # L L L
1376
 
        tree.lock_write()
1377
 
        out, err = self.run_bzr('info -v branch')
1378
 
        self.assertEqualDiff(
1379
 
"""Standalone tree (format: weave)
1380
 
Location:
1381
 
  branch root: %s
1382
 
 
1383
 
Format:
1384
 
       control: All-in-one format 6
1385
 
  working tree: Working tree format 2
1386
 
        branch: Branch format 4
1387
 
    repository: %s
1388
 
 
1389
 
In the working tree:
1390
 
         0 unchanged
1391
 
         0 modified
1392
 
         0 added
1393
 
         0 removed
1394
 
         0 renamed
1395
 
         0 unknown
1396
 
         0 ignored
1397
 
         0 versioned subdirectories
1398
 
 
1399
 
Branch history:
1400
 
         0 revisions
1401
 
 
1402
 
Repository:
1403
 
         0 revisions
1404
 
""" % ('branch', tree.branch.repository._format.get_format_description(),
1405
 
       ), out)
1406
 
        self.assertEqual('', err)
1407
 
        tree.unlock()
1408
 
 
1409
1369
    def test_info_stacked(self):
1410
1370
        # We have a mainline
1411
1371
        trunk_tree = self.make_branch_and_tree('mainline',
1424
1384
     stacked on: mainline
1425
1385
""", out)
1426
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)