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
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):
41
super(TestInfo, self).setUp()
42
self._repo_strings = "2a"
31
from bzrlib.osutils import format_date
32
from bzrlib.tests import TestSkipped
33
from bzrlib.tests.blackbox import ExternalBase
36
class TestInfo(ExternalBase):
44
38
def test_info_non_existing(self):
45
self.vfs_transport_factory = memory.MemoryServer
46
location = self.get_url()
39
if sys.platform == "win32":
40
location = "C:/i/do/not/exist/"
42
location = "/i/do/not/exist/"
47
43
out, err = self.run_bzr('info '+location, retcode=3)
48
44
self.assertEqual(out, '')
49
45
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')
55
'Empty control directory (format: 2a or pack-0.92)\n'
57
' control directory: ctrl\n')
58
self.assertEqual(err, '')
60
def test_info_empty_controldir_verbose(self):
61
self.make_bzrdir('ctrl')
62
out, err = self.run_bzr('info -v ctrl')
63
self.assertEqualDiff(out,
64
'Empty control directory (format: 2a or pack-0.92)\n'
66
' control directory: ctrl\n\n'
68
' control: Meta directory format 1\n\n'
69
'Control directory:\n'
71
self.assertEqual(err, '')
73
def test_info_dangling_branch_reference(self):
74
br = self.make_branch('target')
75
br.create_checkout('from', lightweight=True)
76
shutil.rmtree('target')
77
out, err = self.run_bzr('info from')
79
'Dangling branch reference (format: 2a or pack-0.92)\n'
81
' control directory: from\n'
82
' checkout of branch: target\n')
83
self.assertEqual(err, '')
85
47
def test_info_standalone(self):
86
48
transport = self.get_transport()
88
50
# Create initial standalone branch
89
tree1 = self.make_branch_and_tree('standalone', 'knit')
51
tree1 = self.make_branch_and_tree('standalone', 'weave')
90
52
self.build_tree(['standalone/a'])
92
54
branch1 = tree1.branch
94
56
out, err = self.run_bzr('info standalone')
95
57
self.assertEqualDiff(
96
"""Standalone tree (format: knit)
58
"""Standalone tree (format: weave)
98
60
branch root: standalone
100
62
self.assertEqual('', err)
102
# Standalone branch - verbose mode
103
64
out, err = self.run_bzr('info standalone -v')
104
65
self.assertEqualDiff(
105
"""Standalone tree (format: knit)
107
branch root: standalone
110
control: Meta directory format 1
111
working tree: Working tree format 3
112
branch: Branch format 5
113
repository: Knit repository format 1
126
0 versioned subdirectories
134
self.assertEqual('', err)
136
# Standalone branch - really verbose mode
137
out, err = self.run_bzr('info standalone -vv')
138
self.assertEqualDiff(
139
"""Standalone tree (format: knit)
141
branch root: standalone
144
control: Meta directory format 1
145
working tree: Working tree format 3
146
branch: Branch format 5
147
repository: Knit repository format 1
66
"""Standalone tree (format: weave)
68
branch root: standalone
71
control: All-in-one format 6
72
working tree: Working tree format 2
73
branch: Branch format 4
74
repository: Weave repository format 6
152
76
In the working tree:
328
246
tree5 = branch1.create_checkout('lightcheckout', lightweight=True)
329
247
branch5 = tree5.branch
330
248
out, err = self.run_bzr('info -v lightcheckout')
331
if "metaweave" in controldir.format_registry:
332
format_description = "knit or metaweave"
334
format_description = "knit"
335
249
self.assertEqualDiff(
336
"""Lightweight checkout (format: %s)
250
"""Lightweight checkout (format: 1.6 or 1.6.1-rich-root \
251
or 1.9 or 1.9-rich-root \
252
or dirstate or dirstate-tags or \
253
pack-0.92 or rich-root or rich-root-pack)
338
255
light checkout root: lightcheckout
339
256
checkout of branch: standalone
342
259
control: Meta directory format 1
343
working tree: Working tree format 3
344
branch: Branch format 5
345
repository: Knit repository format 1
260
working tree: Working tree format 4
261
branch: Branch format 4
262
repository: Weave repository format 6
350
264
In the working tree:
363
278
first revision: %s
364
279
latest revision: %s
368
""" % (format_description, datestring_first, datestring_first,), out)
283
""" % (datestring_first, datestring_first,), out)
369
284
self.assertEqual('', err)
371
286
# Update initial standalone branch
372
287
self.build_tree(['standalone/b'])
374
289
tree1.commit('commit two')
375
rev = branch1.repository.get_revision(branch1.last_revision())
376
datestring_last = osutils.format_date(rev.timestamp, rev.timezone)
290
rev = branch1.repository.get_revision(branch1.revision_history()[-1])
291
datestring_last = format_date(rev.timestamp, rev.timezone)
378
293
# Out of date branched standalone branch will not be detected
379
294
out, err = self.run_bzr('info -v branch')
380
295
self.assertEqualDiff(
381
"""Standalone tree (format: knit)
296
"""Standalone tree (format: weave)
383
298
branch root: branch
507
416
# Out of date lightweight checkout
508
417
out, err = self.run_bzr('info lightcheckout --verbose')
509
418
self.assertEqualDiff(
510
"""Lightweight checkout (format: %s)
419
"""Lightweight checkout (format: 1.6 or 1.6.1-rich-root or \
420
1.9 or 1.9-rich-root or \
421
dirstate or dirstate-tags or \
422
pack-0.92 or rich-root or rich-root-pack)
512
424
light checkout root: lightcheckout
513
425
checkout of branch: standalone
516
428
control: Meta directory format 1
517
working tree: Working tree format 3
518
branch: Branch format 5
519
repository: Knit repository format 1
429
working tree: Working tree format 4
430
branch: Branch format 4
431
repository: Weave repository format 6
524
433
Working tree is out of date: missing 1 revision.
647
550
self.build_tree(['tree/lightcheckout/a'])
649
552
tree2.commit('commit one')
650
rev = repo.get_revision(branch2.last_revision())
651
datestring_first = osutils.format_date(rev.timestamp, rev.timezone)
553
rev = repo.get_revision(branch2.revision_history()[0])
554
datestring_first = format_date(rev.timestamp, rev.timezone)
652
555
out, err = self.run_bzr('info tree/lightcheckout --verbose')
653
556
self.assertEqualDiff(
654
"""Lightweight checkout (format: %s)
557
"""Lightweight checkout (format: 1.6 or 1.6.1-rich-root or \
558
1.9 or 1.9-rich-root or \
559
dirstate or dirstate-tags or \
560
pack-0.92 or rich-root or rich-root-pack)
656
562
light checkout root: tree/lightcheckout
657
563
checkout of branch: repo/branch
775
675
tree3.commit('commit two')
777
677
# Out of date lightweight checkout
778
rev = repo.get_revision(branch1.last_revision())
779
datestring_last = osutils.format_date(rev.timestamp, rev.timezone)
678
rev = repo.get_revision(branch1.revision_history()[-1])
679
datestring_last = format_date(rev.timestamp, rev.timezone)
780
680
out, err = self.run_bzr('info tree/lightcheckout --verbose')
781
681
self.assertEqualDiff(
782
"""Lightweight checkout (format: %s)
682
"""Lightweight checkout (format: 1.6 or 1.6.1-rich-root or \
683
1.9 or 1.9-rich-root or \
684
dirstate or dirstate-tags or \
685
pack-0.92 or rich-root or rich-root-pack)
784
687
light checkout root: tree/lightcheckout
785
688
checkout of branch: repo/branch
1166
1043
self.assertEqual('', err)
1168
def test_info_repository_hook(self):
1169
format = controldir.format_registry.make_bzrdir('knit')
1170
def repo_info(repo, stats, outf):
1171
outf.write("more info\n")
1172
info.hooks.install_named_hook('repository', repo_info, None)
1173
# Create shared repository with working trees
1174
repo = self.make_repository('repo', shared=True, format=format)
1175
out, err = self.run_bzr('info -v repo')
1176
self.assertEqualDiff(
1177
"""Shared repository with trees (format: dirstate or dirstate-tags or knit)
1179
shared repository: repo
1182
control: Meta directory format 1
1188
Create working tree for new branches inside the repository.
1193
""" % (format.repository_format.get_format_description(),
1195
self.assertEqual('', err)
1197
def test_info_unshared_repository_with_colocated_branches(self):
1198
format = controldir.format_registry.make_bzrdir('development-colo')
1199
transport = self.get_transport()
1201
# Create unshared repository
1202
repo = self.make_repository('repo', shared=False, format=format)
1203
repo.set_make_working_trees(True)
1204
repo.bzrdir.create_branch(name='foo')
1205
out, err = self.run_bzr('info repo')
1206
self.assertEqualDiff(
1207
"""Unshared repository with trees and colocated branches (format: development-colo)
1211
self.assertEqual('', err)
1213
1045
def assertCheckoutStatusOutput(self,
1214
1046
command_string, lco_tree, shared_repo=None,
1215
1047
repo_branch=None,
1264
1096
(False, True): 'Lightweight checkout',
1265
1097
(False, False): 'Checkout',
1266
1098
}[(shared_repo is not None, light_checkout)]
1267
format = {True: self._repo_strings,
1268
False: 'unnamed'}[light_checkout]
1099
format = {True: '1.6 or 1.6.1-rich-root'
1100
' or 1.9 or 1.9-rich-root'
1101
' or dirstate or dirstate-tags or pack-0.92'
1102
' or rich-root or rich-root-pack',
1103
False: 'dirstate'}[light_checkout]
1269
1104
if repo_locked:
1270
1105
repo_locked = lco_tree.branch.repository.get_physical_lock_status()
1271
1106
if repo_locked or branch_locked or tree_locked:
1361
1193
format=bzrdir.BzrDirMetaFormat1())
1362
1194
repo.set_make_working_trees(False)
1363
1195
repo.bzrdir.root_transport.mkdir('branch')
1364
repo_branch = controldir.ControlDir.create_branch_convenience(
1365
'repo/branch', format=bzrdir.BzrDirMetaFormat1())
1196
repo_branch = repo.bzrdir.create_branch_convenience('repo/branch',
1197
format=bzrdir.BzrDirMetaFormat1())
1366
1198
# Do a heavy checkout
1367
1199
transport.mkdir('tree')
1368
1200
transport.mkdir('tree/checkout')
1369
co_branch = controldir.ControlDir.create_branch_convenience(
1370
'tree/checkout', format=bzrdir.BzrDirMetaFormat1())
1201
co_branch = bzrdir.BzrDir.create_branch_convenience('tree/checkout',
1202
format=bzrdir.BzrDirMetaFormat1())
1371
1203
co_branch.bind(repo_branch)
1372
1204
# Do a light checkout of the heavy one
1373
1205
transport.mkdir('tree/lightcheckout')
1374
1206
lco_dir = bzrdir.BzrDirMetaFormat1().initialize('tree/lightcheckout')
1375
lco_dir.set_branch_reference(co_branch)
1207
branch.BranchReferenceFormat().initialize(lco_dir, co_branch)
1376
1208
lco_dir.create_workingtree()
1377
1209
lco_tree = lco_dir.open_workingtree()
1466
1298
self.knownFailure('Win32 cannot run "bzr info"'
1467
1299
' when the tree is locked.')
1301
def test_info_locking_oslocks(self):
1302
if sys.platform == "win32":
1303
raise TestSkipped("don't use oslocks on win32 in unix manner")
1305
tree = self.make_branch_and_tree('branch',
1306
format=bzrdir.BzrDirFormat6())
1308
# Test all permutations of locking the working tree, branch and repository
1309
# XXX: Well not yet, as we can't query oslocks yet. Currently, it's
1310
# implemented by raising NotImplementedError and get_physical_lock_status()
1311
# always returns false. This makes bzr info hide the lock status. (Olaf)
1315
out, err = self.run_bzr('info -v branch')
1316
self.assertEqualDiff(
1317
"""Standalone tree (format: weave)
1322
control: All-in-one format 6
1323
working tree: Working tree format 2
1324
branch: Branch format 4
1327
In the working tree:
1335
0 versioned subdirectories
1343
""" % ('branch', tree.branch.repository._format.get_format_description(),
1345
self.assertEqual('', err)
1348
out, err = self.run_bzr('info -v branch')
1349
self.assertEqualDiff(
1350
"""Standalone tree (format: weave)
1355
control: All-in-one format 6
1356
working tree: Working tree format 2
1357
branch: Branch format 4
1360
In the working tree:
1368
0 versioned subdirectories
1376
""" % ('branch', tree.branch.repository._format.get_format_description(),
1378
self.assertEqual('', err)
1469
1381
def test_info_stacked(self):
1470
1382
# We have a mainline
1471
1383
trunk_tree = self.make_branch_and_tree('mainline',
1484
1396
stacked on: mainline
1486
1398
self.assertEqual("", err)
1488
def test_info_revinfo_optional(self):
1489
tree = self.make_branch_and_tree('.')
1490
def last_revision_info(self):
1491
raise errors.UnsupportedOperation(last_revision_info, self)
1493
branch.Branch, "last_revision_info", last_revision_info)
1494
out, err = self.run_bzr('info -v .')
1496
"""Standalone tree (format: 2a)
1501
control: Meta directory format 1
1502
working tree: Working tree format 6
1503
branch: Branch format 7
1504
repository: Repository format 2a - rich roots, group compression and chk inventories
1509
In the working tree:
1517
0 versioned subdirectories
1519
self.assertEqual("", err)
1521
def test_info_shows_colocated_branches(self):
1522
bzrdir = self.make_branch('.', format='development-colo').bzrdir
1523
bzrdir.create_branch(name="colo1")
1524
bzrdir.create_branch(name="colo2")
1525
bzrdir.create_branch(name="colo3")
1526
out, err = self.run_bzr('info -v .')
1527
self.assertEqualDiff(
1528
"""Standalone branch (format: development-colo)
1533
control: Meta directory format 1 with support for colocated branches
1534
branch: Branch format 7
1535
repository: Repository format 2a - rich roots, group compression and chk inventories
1546
self.assertEqual("", err)
1549
class TestSmartServerInfo(tests.TestCaseWithTransport):
1551
def test_simple_branch_info(self):
1552
self.setup_smart_server_with_call_log()
1553
t = self.make_branch_and_tree('branch')
1554
self.build_tree_contents([('branch/foo', 'thecontents')])
1557
self.reset_smart_call_log()
1558
out, err = self.run_bzr(['info', self.get_url('branch')])
1559
# This figure represent the amount of work to perform this use case. It
1560
# is entirely ok to reduce this number if a test fails due to rpc_count
1561
# being too low. If rpc_count increases, more network roundtrips have
1562
# become necessary for this use case. Please do not adjust this number
1563
# upwards without agreement from bzr's network support maintainers.
1564
self.assertLength(10, self.hpss_calls)
1565
self.assertLength(1, self.hpss_connections)
1566
self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
1568
def test_verbose_branch_info(self):
1569
self.setup_smart_server_with_call_log()
1570
t = self.make_branch_and_tree('branch')
1571
self.build_tree_contents([('branch/foo', 'thecontents')])
1574
self.reset_smart_call_log()
1575
out, err = self.run_bzr(['info', '-v', self.get_url('branch')])
1576
# This figure represent the amount of work to perform this use case. It
1577
# is entirely ok to reduce this number if a test fails due to rpc_count
1578
# being too low. If rpc_count increases, more network roundtrips have
1579
# become necessary for this use case. Please do not adjust this number
1580
# upwards without agreement from bzr's network support maintainers.
1581
self.assertLength(14, self.hpss_calls)
1582
self.assertLength(1, self.hpss_connections)
1583
self.assertThat(self.hpss_calls, ContainsNoVfsCalls)