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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
18
"""Tests for the info command of bzr."""
24
23
from bzrlib import (
32
from bzrlib.osutils import format_date
33
from bzrlib.tests import TestSkipped
34
from bzrlib.tests.blackbox import ExternalBase
37
class TestInfo(ExternalBase):
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"
39
44
def test_info_non_existing(self):
40
if sys.platform == "win32":
41
location = "C:/i/do/not/exist/"
43
location = "/i/do/not/exist/"
45
self.vfs_transport_factory = memory.MemoryServer
46
location = self.get_url()
44
47
out, err = self.run_bzr('info '+location, retcode=3)
45
48
self.assertEqual(out, '')
46
49
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_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.assertEquals(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')
78
self.assertEquals(out,
79
'Dangling branch reference (format: 2a or pack-0.92)\n'
81
' control directory: from\n'
82
' checkout of branch: target\n')
83
self.assertEquals(err, '')
48
85
def test_info_standalone(self):
49
86
transport = self.get_transport()
51
88
# Create initial standalone branch
52
tree1 = self.make_branch_and_tree('standalone', 'weave')
89
tree1 = self.make_branch_and_tree('standalone', 'knit')
53
90
self.build_tree(['standalone/a'])
55
92
branch1 = tree1.branch
57
94
out, err = self.run_bzr('info standalone')
58
95
self.assertEqualDiff(
59
"""Standalone tree (format: weave)
96
"""Standalone tree (format: knit)
61
98
branch root: standalone
63
100
self.assertEqual('', err)
102
# Standalone branch - verbose mode
65
103
out, err = self.run_bzr('info standalone -v')
66
104
self.assertEqualDiff(
67
"""Standalone tree (format: weave)
69
branch root: standalone
72
control: All-in-one format 6
73
working tree: Working tree format 2
74
branch: Branch format 4
75
repository: Weave repository format 6
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
77
152
In the working tree:
146
222
first revision: %s
147
223
latest revision: %s
152
227
""" % (datestring_first, datestring_first,
153
# poking at _revision_store isn't all that clean, but neither is
154
# having the ui test dependent on the exact overhead of a given store.
155
branch2.repository._revision_store.total_size(
156
branch2.repository.get_transaction())[1] / 1024,
158
229
self.assertEqual('', err)
160
231
# Branch and bind to standalone, needs upgrade to metadir
161
232
# (creates backup as unknown)
162
233
branch1.bzrdir.sprout('bound')
163
knit1_format = bzrdir.format_registry.make_bzrdir('knit')
164
bzrlib.upgrade.upgrade('bound', knit1_format)
165
branch3 = bzrlib.bzrdir.BzrDir.open('bound').open_branch()
234
knit1_format = controldir.format_registry.make_bzrdir('knit')
235
upgrade.upgrade('bound', knit1_format)
236
branch3 = controldir.ControlDir.open('bound').open_branch()
166
237
branch3.bind(branch1)
167
238
bound_tree = branch3.bzrdir.open_workingtree()
168
239
out, err = self.run_bzr('info -v bound')
184
258
In the working tree:
192
266
0 versioned subdirectories
198
271
first revision: %s
199
272
latest revision: %s
204
276
""" % (bound_tree._format.get_format_description(),
205
277
branch3._format.get_format_description(),
206
278
branch3.repository._format.get_format_description(),
207
279
datestring_first, datestring_first,
208
# poking at _revision_store isn't all that clean, but neither is
209
# having the ui test dependent on the exact overhead of a given store.
210
branch3.repository._revision_store.total_size(
211
branch3.repository.get_transaction())[1] / 1024,
213
281
self.assertEqual('', err)
215
283
# Checkout standalone (same as above, but does not have parent set)
216
branch4 = bzrlib.bzrdir.BzrDir.create_branch_convenience('checkout',
284
branch4 = controldir.ControlDir.create_branch_convenience('checkout',
217
285
format=knit1_format)
218
286
branch4.bind(branch1)
219
287
branch4.bzrdir.open_workingtree().update()
293
363
first revision: %s
294
364
latest revision: %s
299
""" % (datestring_first, datestring_first,), out)
368
""" % (format_description, datestring_first, datestring_first,), out)
300
369
self.assertEqual('', err)
302
371
# Update initial standalone branch
303
372
self.build_tree(['standalone/b'])
305
374
tree1.commit('commit two')
306
rev = branch1.repository.get_revision(branch1.revision_history()[-1])
307
datestring_last = format_date(rev.timestamp, rev.timezone)
375
rev = branch1.repository.get_revision(branch1.last_revision())
376
datestring_last = osutils.format_date(rev.timestamp, rev.timezone)
309
378
# Out of date branched standalone branch will not be detected
310
379
out, err = self.run_bzr('info -v branch')
311
380
self.assertEqualDiff(
312
"""Standalone tree (format: weave)
381
"""Standalone tree (format: knit)
314
383
branch root: branch
428
497
first revision: %s
429
498
latest revision: %s
434
502
""" % (branch4.repository._format.get_format_description(),
435
503
datestring_first, datestring_first,
436
# poking at _revision_store isn't all that clean, but neither is
437
# having the ui test dependent on the exact overhead of a given store.
438
branch4.repository._revision_store.total_size(
439
branch4.repository.get_transaction())[1] / 1024,
441
505
self.assertEqual('', err)
443
507
# Out of date lightweight checkout
444
508
out, err = self.run_bzr('info lightcheckout --verbose')
445
509
self.assertEqualDiff(
446
"""Lightweight checkout (format: dirstate or dirstate-tags or \
447
pack-0.92 or rich-root or rich-root-pack)
510
"""Lightweight checkout (format: %s)
449
512
light checkout root: lightcheckout
450
513
checkout of branch: standalone
453
516
control: Meta directory format 1
454
working tree: Working tree format 4
455
branch: Branch format 4
456
repository: Weave repository format 6
517
working tree: Working tree format 3
518
branch: Branch format 5
519
repository: Knit repository format 1
458
524
Working tree is out of date: missing 1 revision.
613
682
first revision: %s
614
683
latest revision: %s
619
""" % (format.get_branch_format().get_format_description(),
687
""" % (self._repo_strings, format.get_branch_format().get_format_description(),
620
688
format.repository_format.get_format_description(),
621
689
datestring_first, datestring_first,
622
# poking at _revision_store isn't all that clean, but neither is
623
# having the ui test dependent on the exact overhead of a given store.
624
repo._revision_store.total_size(repo.get_transaction())[1] / 1024,
626
691
self.assertEqual('', err)
628
693
# Out of date checkout
629
694
out, err = self.run_bzr('info -v tree/checkout')
630
695
self.assertEqualDiff(
631
"""Checkout (format: dirstate)
696
"""Checkout (format: unnamed)
633
698
checkout root: tree/checkout
634
699
checkout of branch: repo/branch
637
702
control: Meta directory format 1
638
working tree: Working tree format 4
703
working tree: Working tree format 6
642
710
Branch is out of date: missing 1 revision.
644
712
In the working tree:
697
765
first revision: %s
698
766
latest revision: %s
703
770
""" % (format.get_branch_format().get_format_description(),
704
771
format.repository_format.get_format_description(),
705
772
datestring_first, datestring_first,
706
# poking at _revision_store isn't all that clean, but neither is
707
# having the ui test dependent on the exact overhead of a given store.
708
repo._revision_store.total_size(repo.get_transaction())[1] / 1024,
710
774
self.assertEqual('', err)
711
775
tree3.commit('commit two')
713
777
# Out of date lightweight checkout
714
rev = repo.get_revision(branch1.revision_history()[-1])
715
datestring_last = format_date(rev.timestamp, rev.timezone)
778
rev = repo.get_revision(branch1.last_revision())
779
datestring_last = osutils.format_date(rev.timestamp, rev.timezone)
716
780
out, err = self.run_bzr('info tree/lightcheckout --verbose')
717
781
self.assertEqualDiff(
718
"""Lightweight checkout (format: dirstate or dirstate-tags or \
719
pack-0.92 or rich-root or rich-root-pack)
782
"""Lightweight checkout (format: %s)
721
784
light checkout root: tree/lightcheckout
722
785
checkout of branch: repo/branch
1099
1158
Branch history:
1106
1163
""" % (format.get_branch_format().get_format_description(),
1107
1164
format.repository_format.get_format_description(),
1109
1166
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)
1111
1213
def assertCheckoutStatusOutput(self,
1112
1214
command_string, lco_tree, shared_repo=None,
1113
1215
repo_branch=None,
1252
1358
transport = self.get_transport()
1253
1359
# Create shared repository with a branch
1254
1360
repo = self.make_repository('repo', shared=True,
1255
format=bzrlib.bzrdir.BzrDirMetaFormat1())
1361
format=bzrdir.BzrDirMetaFormat1())
1256
1362
repo.set_make_working_trees(False)
1257
1363
repo.bzrdir.root_transport.mkdir('branch')
1258
repo_branch = repo.bzrdir.create_branch_convenience('repo/branch',
1259
format=bzrlib.bzrdir.BzrDirMetaFormat1())
1364
repo_branch = controldir.ControlDir.create_branch_convenience(
1365
'repo/branch', format=bzrdir.BzrDirMetaFormat1())
1260
1366
# Do a heavy checkout
1261
1367
transport.mkdir('tree')
1262
1368
transport.mkdir('tree/checkout')
1263
co_branch = bzrlib.bzrdir.BzrDir.create_branch_convenience('tree/checkout',
1264
format=bzrlib.bzrdir.BzrDirMetaFormat1())
1369
co_branch = controldir.ControlDir.create_branch_convenience(
1370
'tree/checkout', format=bzrdir.BzrDirMetaFormat1())
1265
1371
co_branch.bind(repo_branch)
1266
1372
# Do a light checkout of the heavy one
1267
1373
transport.mkdir('tree/lightcheckout')
1268
lco_dir = bzrlib.bzrdir.BzrDirMetaFormat1().initialize('tree/lightcheckout')
1269
bzrlib.branch.BranchReferenceFormat().initialize(lco_dir, co_branch)
1374
lco_dir = bzrdir.BzrDirMetaFormat1().initialize('tree/lightcheckout')
1375
lco_dir.set_branch_reference(co_branch)
1270
1376
lco_dir.create_workingtree()
1271
1377
lco_tree = lco_dir.open_workingtree()
1360
1466
self.knownFailure('Win32 cannot run "bzr info"'
1361
1467
' when the tree is locked.')
1363
def test_info_locking_oslocks(self):
1364
if sys.platform == "win32":
1365
raise TestSkipped("don't use oslocks on win32 in unix manner")
1367
tree = self.make_branch_and_tree('branch',
1368
format=bzrlib.bzrdir.BzrDirFormat6())
1370
# Test all permutations of locking the working tree, branch and repository
1371
# XXX: Well not yet, as we can't query oslocks yet. Currently, it's
1372
# implemented by raising NotImplementedError and get_physical_lock_status()
1373
# always returns false. This makes bzr info hide the lock status. (Olaf)
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
1406
""" % ('branch', tree.branch.repository._format.get_format_description(),
1408
self.assertEqual('', err)
1411
out, err = self.run_bzr('info -v branch')
1412
self.assertEqualDiff(
1413
"""Standalone tree (format: weave)
1418
control: All-in-one format 6
1419
working tree: Working tree format 2
1420
branch: Branch format 4
1423
In the working tree:
1431
0 versioned subdirectories
1440
""" % ('branch', tree.branch.repository._format.get_format_description(),
1442
self.assertEqual('', err)
1469
def test_info_stacked(self):
1470
# We have a mainline
1471
trunk_tree = self.make_branch_and_tree('mainline',
1473
trunk_tree.commit('mainline')
1474
# and a branch from it which is stacked
1475
new_dir = trunk_tree.bzrdir.sprout('newbranch', stacked=True)
1476
out, err = self.run_bzr('info newbranch')
1478
"""Standalone tree (format: 1.6)
1480
branch root: newbranch
1483
parent branch: mainline
1484
stacked on: mainline
1486
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)