~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

(jelmer) Use the absolute_import feature everywhere in bzrlib,
 and add a source test to make sure it's used everywhere. (Jelmer Vernooij)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006, 2007, 2008 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
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,
 
30
    tests,
28
31
    upgrade,
29
32
    urlutils,
30
33
    )
31
 
from bzrlib.osutils import format_date
32
 
from bzrlib.tests import TestSkipped, MemoryServer
33
 
from bzrlib.tests.blackbox import ExternalBase
34
 
 
35
 
 
36
 
class TestInfo(ExternalBase):
 
34
from bzrlib.tests.matchers import ContainsNoVfsCalls
 
35
from bzrlib.transport import memory
 
36
 
 
37
 
 
38
class TestInfo(tests.TestCaseWithTransport):
37
39
 
38
40
    def setUp(self):
39
 
        ExternalBase.setUp(self)
40
 
        self._repo_strings = "2a or development-subtree"
 
41
        super(TestInfo, self).setUp()
 
42
        self._repo_strings = "2a"
41
43
 
42
44
    def test_info_non_existing(self):
43
 
        self.vfs_transport_factory = MemoryServer
 
45
        self.vfs_transport_factory = memory.MemoryServer
44
46
        location = self.get_url()
45
47
        out, err = self.run_bzr('info '+location, retcode=3)
46
48
        self.assertEqual(out, '')
47
49
        self.assertEqual(err, 'bzr: ERROR: Not a branch: "%s".\n' % location)
48
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
 
49
72
    def test_info_standalone(self):
50
73
        transport = self.get_transport()
51
74
 
52
75
        # Create initial standalone branch
53
 
        tree1 = self.make_branch_and_tree('standalone', 'weave')
 
76
        tree1 = self.make_branch_and_tree('standalone', 'knit')
54
77
        self.build_tree(['standalone/a'])
55
78
        tree1.add('a')
56
79
        branch1 = tree1.branch
57
80
 
58
81
        out, err = self.run_bzr('info standalone')
59
82
        self.assertEqualDiff(
60
 
"""Standalone tree (format: weave)
 
83
"""Standalone tree (format: knit)
61
84
Location:
62
85
  branch root: standalone
63
86
""", out)
66
89
        # Standalone branch - verbose mode
67
90
        out, err = self.run_bzr('info standalone -v')
68
91
        self.assertEqualDiff(
69
 
"""Standalone tree (format: weave)
 
92
"""Standalone tree (format: knit)
70
93
Location:
71
94
  branch root: standalone
72
95
 
73
96
Format:
74
 
       control: All-in-one format 6
75
 
  working tree: Working tree format 2
76
 
        branch: Branch format 4
77
 
    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
78
101
 
79
102
In the working tree:
80
103
         0 unchanged
97
120
        # Standalone branch - really verbose mode
98
121
        out, err = self.run_bzr('info standalone -vv')
99
122
        self.assertEqualDiff(
100
 
"""Standalone tree (format: weave)
 
123
"""Standalone tree (format: knit)
101
124
Location:
102
125
  branch root: standalone
103
126
 
104
127
Format:
105
 
       control: All-in-one format 6
106
 
  working tree: Working tree format 2
107
 
        branch: Branch format 4
108
 
    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
109
132
 
110
133
In the working tree:
111
134
         0 unchanged
126
149
""", out)
127
150
        self.assertEqual('', err)
128
151
        tree1.commit('commit one')
129
 
        rev = branch1.repository.get_revision(branch1.revision_history()[0])
130
 
        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)
131
154
 
132
155
        # Branch standalone with push location
133
156
        branch2 = branch1.bzrdir.sprout('branch').open_branch()
135
158
 
136
159
        out, err = self.run_bzr('info branch')
137
160
        self.assertEqualDiff(
138
 
"""Standalone tree (format: weave)
 
161
"""Standalone tree (format: knit)
139
162
Location:
140
163
  branch root: branch
141
164
 
147
170
 
148
171
        out, err = self.run_bzr('info branch --verbose')
149
172
        self.assertEqualDiff(
150
 
"""Standalone tree (format: weave)
 
173
"""Standalone tree (format: knit)
151
174
Location:
152
175
  branch root: branch
153
176
 
156
179
  parent branch: standalone
157
180
 
158
181
Format:
159
 
       control: All-in-one format 6
160
 
  working tree: Working tree format 2
161
 
        branch: Branch format 4
162
 
    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
163
186
 
164
187
In the working tree:
165
188
         1 unchanged
188
211
        branch1.bzrdir.sprout('bound')
189
212
        knit1_format = bzrdir.format_registry.make_bzrdir('knit')
190
213
        upgrade.upgrade('bound', knit1_format)
191
 
        branch3 = bzrdir.BzrDir.open('bound').open_branch()
 
214
        branch3 = controldir.ControlDir.open('bound').open_branch()
192
215
        branch3.bind(branch1)
193
216
        bound_tree = branch3.bzrdir.open_workingtree()
194
217
        out, err = self.run_bzr('info -v bound')
213
236
         0 added
214
237
         0 removed
215
238
         0 renamed
216
 
         1 unknown
 
239
         0 unknown
217
240
         0 ignored
218
241
         0 versioned subdirectories
219
242
 
233
256
        self.assertEqual('', err)
234
257
 
235
258
        # Checkout standalone (same as above, but does not have parent set)
236
 
        branch4 = bzrdir.BzrDir.create_branch_convenience('checkout',
 
259
        branch4 = controldir.ControlDir.create_branch_convenience('checkout',
237
260
            format=knit1_format)
238
261
        branch4.bind(branch1)
239
262
        branch4.bzrdir.open_workingtree().update()
277
300
        tree5 = branch1.create_checkout('lightcheckout', lightweight=True)
278
301
        branch5 = tree5.branch
279
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"
280
307
        self.assertEqualDiff(
281
308
"""Lightweight checkout (format: %s)
282
309
Location:
285
312
 
286
313
Format:
287
314
       control: Meta directory format 1
288
 
  working tree: Working tree format 6
289
 
        branch: Branch format 4
290
 
    repository: Weave repository format 6
 
315
  working tree: Working tree format 3
 
316
        branch: Branch format 5
 
317
    repository: Knit repository format 1
291
318
 
292
319
In the working tree:
293
320
         1 unchanged
307
334
 
308
335
Repository:
309
336
         1 revision
310
 
""" % (self._repo_strings, datestring_first, datestring_first,), out)
 
337
""" % (format_description, datestring_first, datestring_first,), out)
311
338
        self.assertEqual('', err)
312
339
 
313
340
        # Update initial standalone branch
314
341
        self.build_tree(['standalone/b'])
315
342
        tree1.add('b')
316
343
        tree1.commit('commit two')
317
 
        rev = branch1.repository.get_revision(branch1.revision_history()[-1])
318
 
        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)
319
346
 
320
347
        # Out of date branched standalone branch will not be detected
321
348
        out, err = self.run_bzr('info -v branch')
322
349
        self.assertEqualDiff(
323
 
"""Standalone tree (format: weave)
 
350
"""Standalone tree (format: knit)
324
351
Location:
325
352
  branch root: branch
326
353
 
329
356
  parent branch: standalone
330
357
 
331
358
Format:
332
 
       control: All-in-one format 6
333
 
  working tree: Working tree format 2
334
 
        branch: Branch format 4
335
 
    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
336
363
 
337
364
In the working tree:
338
365
         1 unchanged
381
408
         0 added
382
409
         0 removed
383
410
         0 renamed
384
 
         1 unknown
 
411
         0 unknown
385
412
         0 ignored
386
413
         0 versioned subdirectories
387
414
 
447
474
 
448
475
Format:
449
476
       control: Meta directory format 1
450
 
  working tree: Working tree format 6
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
 
471
498
 
472
499
Repository:
473
500
         2 revisions
474
 
""" % (self._repo_strings, datestring_first, datestring_last,), out)
 
501
""" % (format_description, datestring_first, datestring_last,), out)
475
502
        self.assertEqual('', err)
476
503
 
477
504
    def test_info_standalone_no_tree(self):
526
553
 
527
554
        # Create branch inside shared repository
528
555
        repo.bzrdir.root_transport.mkdir('branch')
529
 
        branch1 = repo.bzrdir.create_branch_convenience('repo/branch',
530
 
            format=format)
 
556
        branch1 = controldir.ControlDir.create_branch_convenience(
 
557
            'repo/branch', format=format)
531
558
        out, err = self.run_bzr('info -v repo/branch')
532
559
        self.assertEqualDiff(
533
560
"""Repository branch (format: dirstate or knit)
568
595
        self.build_tree(['tree/lightcheckout/a'])
569
596
        tree2.add('a')
570
597
        tree2.commit('commit one')
571
 
        rev = repo.get_revision(branch2.revision_history()[0])
572
 
        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)
573
600
        out, err = self.run_bzr('info tree/lightcheckout --verbose')
574
601
        self.assertEqualDiff(
575
602
"""Lightweight checkout (format: %s)
687
714
        tree3.commit('commit two')
688
715
 
689
716
        # Out of date lightweight checkout
690
 
        rev = repo.get_revision(branch1.revision_history()[-1])
691
 
        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)
692
719
        out, err = self.run_bzr('info tree/lightcheckout --verbose')
693
720
        self.assertEqualDiff(
694
721
"""Lightweight checkout (format: %s)
800
827
 
801
828
        # Create two branches
802
829
        repo.bzrdir.root_transport.mkdir('branch1')
803
 
        branch1 = repo.bzrdir.create_branch_convenience('repo/branch1',
 
830
        branch1 = controldir.ControlDir.create_branch_convenience('repo/branch1',
804
831
            format=format)
805
832
        branch2 = branch1.bzrdir.sprout('repo/branch2').open_branch()
806
833
 
843
870
        tree1 = branch1.bzrdir.open_workingtree()
844
871
        tree1.add('a')
845
872
        tree1.commit('commit one')
846
 
        rev = repo.get_revision(branch1.revision_history()[0])
847
 
        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)
848
875
        out, err = self.run_bzr('info -v repo/branch1')
849
876
        self.assertEqualDiff(
850
877
"""Repository tree (format: knit)
1218
1245
                                    format=bzrdir.BzrDirMetaFormat1())
1219
1246
        repo.set_make_working_trees(False)
1220
1247
        repo.bzrdir.root_transport.mkdir('branch')
1221
 
        repo_branch = repo.bzrdir.create_branch_convenience('repo/branch',
1222
 
                                    format=bzrdir.BzrDirMetaFormat1())
 
1248
        repo_branch = controldir.ControlDir.create_branch_convenience(
 
1249
            'repo/branch', format=bzrdir.BzrDirMetaFormat1())
1223
1250
        # Do a heavy checkout
1224
1251
        transport.mkdir('tree')
1225
1252
        transport.mkdir('tree/checkout')
1226
 
        co_branch = bzrdir.BzrDir.create_branch_convenience('tree/checkout',
1227
 
            format=bzrdir.BzrDirMetaFormat1())
 
1253
        co_branch = controldir.ControlDir.create_branch_convenience(
 
1254
            'tree/checkout', format=bzrdir.BzrDirMetaFormat1())
1228
1255
        co_branch.bind(repo_branch)
1229
1256
        # Do a light checkout of the heavy one
1230
1257
        transport.mkdir('tree/lightcheckout')
1231
1258
        lco_dir = bzrdir.BzrDirMetaFormat1().initialize('tree/lightcheckout')
1232
 
        branch.BranchReferenceFormat().initialize(lco_dir, co_branch)
 
1259
        branch.BranchReferenceFormat().initialize(lco_dir,
 
1260
            target_branch=co_branch)
1233
1261
        lco_dir.create_workingtree()
1234
1262
        lco_tree = lco_dir.open_workingtree()
1235
1263
 
1323
1351
            self.knownFailure('Win32 cannot run "bzr info"'
1324
1352
                              ' when the tree is locked.')
1325
1353
 
1326
 
    def test_info_locking_oslocks(self):
1327
 
        if sys.platform == "win32":
1328
 
            raise TestSkipped("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
1354
    def test_info_stacked(self):
1410
1355
        # We have a mainline
1411
1356
        trunk_tree = self.make_branch_and_tree('mainline',
1424
1369
     stacked on: mainline
1425
1370
""", out)
1426
1371
        self.assertEqual("", err)
 
1372
 
 
1373
    def test_info_revinfo_optional(self):
 
1374
        tree = self.make_branch_and_tree('.')
 
1375
        def last_revision_info(self):
 
1376
            raise errors.UnsupportedOperation(last_revision_info, self)
 
1377
        self.overrideAttr(
 
1378
            branch.Branch, "last_revision_info", last_revision_info)
 
1379
        out, err = self.run_bzr('info -v .')
 
1380
        self.assertEqual(
 
1381
"""Standalone tree (format: 2a)
 
1382
Location:
 
1383
  branch root: .
 
1384
 
 
1385
Format:
 
1386
       control: Meta directory format 1
 
1387
  working tree: Working tree format 6
 
1388
        branch: Branch format 7
 
1389
    repository: Repository format 2a - rich roots, group compression and chk inventories
 
1390
 
 
1391
In the working tree:
 
1392
         0 unchanged
 
1393
         0 modified
 
1394
         0 added
 
1395
         0 removed
 
1396
         0 renamed
 
1397
         0 unknown
 
1398
         0 ignored
 
1399
         0 versioned subdirectories
 
1400
""", out)
 
1401
        self.assertEqual("", err)
 
1402
 
 
1403
    def test_info_shows_colocated_branches(self):
 
1404
        bzrdir = self.make_branch('.', format='development-colo').bzrdir
 
1405
        bzrdir.create_branch(name="colo1")
 
1406
        bzrdir.create_branch(name="colo2")
 
1407
        bzrdir.create_branch(name="colo3")
 
1408
        out, err = self.run_bzr('info -v .')
 
1409
        self.assertEqualDiff(
 
1410
"""Standalone branch (format: development-colo)
 
1411
Location:
 
1412
  branch root: .
 
1413
 
 
1414
Format:
 
1415
       control: Meta directory format 1 with support for colocated branches
 
1416
        branch: Branch format 7
 
1417
    repository: Repository format 2a - rich roots, group compression and chk inventories
 
1418
 
 
1419
Control directory:
 
1420
         4 branches
 
1421
 
 
1422
Branch history:
 
1423
         0 revisions
 
1424
 
 
1425
Repository:
 
1426
         0 revisions
 
1427
""", out)
 
1428
        self.assertEqual("", err)
 
1429
 
 
1430
 
 
1431
class TestSmartServerInfo(tests.TestCaseWithTransport):
 
1432
 
 
1433
    def test_simple_branch_info(self):
 
1434
        self.setup_smart_server_with_call_log()
 
1435
        t = self.make_branch_and_tree('branch')
 
1436
        self.build_tree_contents([('branch/foo', 'thecontents')])
 
1437
        t.add("foo")
 
1438
        t.commit("message")
 
1439
        self.reset_smart_call_log()
 
1440
        out, err = self.run_bzr(['info', self.get_url('branch')])
 
1441
        # This figure represent the amount of work to perform this use case. It
 
1442
        # is entirely ok to reduce this number if a test fails due to rpc_count
 
1443
        # being too low. If rpc_count increases, more network roundtrips have
 
1444
        # become necessary for this use case. Please do not adjust this number
 
1445
        # upwards without agreement from bzr's network support maintainers.
 
1446
        self.assertLength(12, self.hpss_calls)
 
1447
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
 
1448
 
 
1449
    def test_verbose_branch_info(self):
 
1450
        self.setup_smart_server_with_call_log()
 
1451
        t = self.make_branch_and_tree('branch')
 
1452
        self.build_tree_contents([('branch/foo', 'thecontents')])
 
1453
        t.add("foo")
 
1454
        t.commit("message")
 
1455
        self.reset_smart_call_log()
 
1456
        out, err = self.run_bzr(['info', '-v', self.get_url('branch')])
 
1457
        # This figure represent the amount of work to perform this use case. It
 
1458
        # is entirely ok to reduce this number if a test fails due to rpc_count
 
1459
        # being too low. If rpc_count increases, more network roundtrips have
 
1460
        # become necessary for this use case. Please do not adjust this number
 
1461
        # upwards without agreement from bzr's network support maintainers.
 
1462
        self.assertLength(16, self.hpss_calls)
 
1463
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)