18
18
"""Tests for the info command of bzr."""
23
22
from bzrlib import (
34
from bzrlib.tests.matchers import ContainsNoVfsCalls
35
from bzrlib.transport import memory
38
class TestInfo(tests.TestCaseWithTransport):
31
from bzrlib.osutils import format_date
32
from bzrlib.tests import TestSkipped, MemoryServer
33
from bzrlib.tests.blackbox import ExternalBase
36
class TestInfo(ExternalBase):
41
super(TestInfo, self).setUp()
42
self._repo_strings = "2a"
39
ExternalBase.setUp(self)
40
self._repo_strings = "2a or development-subtree"
44
42
def test_info_non_existing(self):
45
self.vfs_transport_factory = memory.MemoryServer
43
self.vfs_transport_factory = MemoryServer
46
44
location = self.get_url()
47
45
out, err = self.run_bzr('info '+location, retcode=3)
48
46
self.assertEqual(out, '')
49
47
self.assertEqual(err, 'bzr: ERROR: Not a branch: "%s".\n' % location)
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'
57
' control directory: ctrl\n')
58
self.assertEquals(err, '')
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'
68
' control directory: from\n'
69
' checkout of branch: target\n')
70
self.assertEquals(err, '')
72
49
def test_info_standalone(self):
73
50
transport = self.get_transport()
75
52
# Create initial standalone branch
76
tree1 = self.make_branch_and_tree('standalone', 'knit')
53
tree1 = self.make_branch_and_tree('standalone', 'weave')
77
54
self.build_tree(['standalone/a'])
79
56
branch1 = tree1.branch
81
58
out, err = self.run_bzr('info standalone')
82
59
self.assertEqualDiff(
83
"""Standalone tree (format: knit)
60
"""Standalone tree (format: weave)
85
62
branch root: standalone
89
66
# Standalone branch - verbose mode
90
67
out, err = self.run_bzr('info standalone -v')
91
68
self.assertEqualDiff(
92
"""Standalone tree (format: knit)
69
"""Standalone tree (format: weave)
94
71
branch root: standalone
97
control: Meta directory format 1
98
working tree: Working tree format 3
99
branch: Branch format 5
100
repository: Knit repository format 1
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
102
79
In the working tree:
120
97
# Standalone branch - really verbose mode
121
98
out, err = self.run_bzr('info standalone -vv')
122
99
self.assertEqualDiff(
123
"""Standalone tree (format: knit)
100
"""Standalone tree (format: weave)
125
102
branch root: standalone
128
control: Meta directory format 1
129
working tree: Working tree format 3
130
branch: Branch format 5
131
repository: Knit repository format 1
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
133
110
In the working tree:
150
127
self.assertEqual('', err)
151
128
tree1.commit('commit one')
152
rev = branch1.repository.get_revision(branch1.last_revision())
153
datestring_first = osutils.format_date(rev.timestamp, rev.timezone)
129
rev = branch1.repository.get_revision(branch1.revision_history()[0])
130
datestring_first = format_date(rev.timestamp, rev.timezone)
155
132
# Branch standalone with push location
156
133
branch2 = branch1.bzrdir.sprout('branch').open_branch()
337
""" % (format_description, datestring_first, datestring_first,), out)
310
""" % (self._repo_strings, datestring_first, datestring_first,), out)
338
311
self.assertEqual('', err)
340
313
# Update initial standalone branch
341
314
self.build_tree(['standalone/b'])
343
316
tree1.commit('commit two')
344
rev = branch1.repository.get_revision(branch1.last_revision())
345
datestring_last = osutils.format_date(rev.timestamp, rev.timezone)
317
rev = branch1.repository.get_revision(branch1.revision_history()[-1])
318
datestring_last = format_date(rev.timestamp, rev.timezone)
347
320
# Out of date branched standalone branch will not be detected
348
321
out, err = self.run_bzr('info -v branch')
349
322
self.assertEqualDiff(
350
"""Standalone tree (format: knit)
323
"""Standalone tree (format: weave)
352
325
branch root: branch
595
568
self.build_tree(['tree/lightcheckout/a'])
597
570
tree2.commit('commit one')
598
rev = repo.get_revision(branch2.last_revision())
599
datestring_first = osutils.format_date(rev.timestamp, rev.timezone)
571
rev = repo.get_revision(branch2.revision_history()[0])
572
datestring_first = format_date(rev.timestamp, rev.timezone)
600
573
out, err = self.run_bzr('info tree/lightcheckout --verbose')
601
574
self.assertEqualDiff(
602
575
"""Lightweight checkout (format: %s)
714
687
tree3.commit('commit two')
716
689
# Out of date lightweight checkout
717
rev = repo.get_revision(branch1.last_revision())
718
datestring_last = osutils.format_date(rev.timestamp, rev.timezone)
690
rev = repo.get_revision(branch1.revision_history()[-1])
691
datestring_last = format_date(rev.timestamp, rev.timezone)
719
692
out, err = self.run_bzr('info tree/lightcheckout --verbose')
720
693
self.assertEqualDiff(
721
694
"""Lightweight checkout (format: %s)
870
843
tree1 = branch1.bzrdir.open_workingtree()
872
845
tree1.commit('commit one')
873
rev = repo.get_revision(branch1.last_revision())
874
datestring_first = osutils.format_date(rev.timestamp, rev.timezone)
846
rev = repo.get_revision(branch1.revision_history()[0])
847
datestring_first = format_date(rev.timestamp, rev.timezone)
875
848
out, err = self.run_bzr('info -v repo/branch1')
876
849
self.assertEqualDiff(
877
850
"""Repository tree (format: knit)
1245
1218
format=bzrdir.BzrDirMetaFormat1())
1246
1219
repo.set_make_working_trees(False)
1247
1220
repo.bzrdir.root_transport.mkdir('branch')
1248
repo_branch = controldir.ControlDir.create_branch_convenience(
1249
'repo/branch', format=bzrdir.BzrDirMetaFormat1())
1221
repo_branch = repo.bzrdir.create_branch_convenience('repo/branch',
1222
format=bzrdir.BzrDirMetaFormat1())
1250
1223
# Do a heavy checkout
1251
1224
transport.mkdir('tree')
1252
1225
transport.mkdir('tree/checkout')
1253
co_branch = controldir.ControlDir.create_branch_convenience(
1254
'tree/checkout', format=bzrdir.BzrDirMetaFormat1())
1226
co_branch = bzrdir.BzrDir.create_branch_convenience('tree/checkout',
1227
format=bzrdir.BzrDirMetaFormat1())
1255
1228
co_branch.bind(repo_branch)
1256
1229
# Do a light checkout of the heavy one
1257
1230
transport.mkdir('tree/lightcheckout')
1258
1231
lco_dir = bzrdir.BzrDirMetaFormat1().initialize('tree/lightcheckout')
1259
branch.BranchReferenceFormat().initialize(lco_dir,
1260
target_branch=co_branch)
1232
branch.BranchReferenceFormat().initialize(lco_dir, co_branch)
1261
1233
lco_dir.create_workingtree()
1262
1234
lco_tree = lco_dir.open_workingtree()
1351
1323
self.knownFailure('Win32 cannot run "bzr info"'
1352
1324
' when the tree is locked.')
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
1333
self.thisFailsStrictLockCheck()
1335
tree = self.make_branch_and_tree('branch',
1336
format=bzrdir.BzrDirFormat6())
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)
1345
out, err = self.run_bzr('info -v branch')
1346
self.assertEqualDiff(
1347
"""Standalone tree (format: weave)
1352
control: All-in-one format 6
1353
working tree: Working tree format 2
1354
branch: Branch format 4
1357
In the working tree:
1365
0 versioned subdirectories
1372
""" % ('branch', tree.branch.repository._format.get_format_description(),
1374
self.assertEqual('', err)
1377
out, err = self.run_bzr('info -v branch')
1378
self.assertEqualDiff(
1379
"""Standalone tree (format: weave)
1384
control: All-in-one format 6
1385
working tree: Working tree format 2
1386
branch: Branch format 4
1389
In the working tree:
1397
0 versioned subdirectories
1404
""" % ('branch', tree.branch.repository._format.get_format_description(),
1406
self.assertEqual('', err)
1354
1409
def test_info_stacked(self):
1355
1410
# We have a mainline
1356
1411
trunk_tree = self.make_branch_and_tree('mainline',
1369
1424
stacked on: mainline
1371
1426
self.assertEqual("", err)
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)
1378
branch.Branch, "last_revision_info", last_revision_info)
1379
out, err = self.run_bzr('info -v .')
1381
"""Standalone tree (format: 2a)
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
1391
In the working tree:
1399
0 versioned subdirectories
1401
self.assertEqual("", err)
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)
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
1428
self.assertEqual("", err)
1431
class TestSmartServerInfo(tests.TestCaseWithTransport):
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')])
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)
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')])
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)