1
# Copyright (C) 2006, 2007, 2008 Canonical Ltd
1
# Copyright (C) 2006-2010 Canonical Ltd
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
22
22
from bzrlib import (
31
from bzrlib.osutils import format_date
32
from bzrlib.tests import TestSkipped
33
from bzrlib.tests.blackbox import ExternalBase
36
class TestInfo(ExternalBase):
33
from bzrlib.transport import memory
36
class TestInfo(tests.TestCaseWithTransport):
39
super(TestInfo, self).setUp()
40
self._repo_strings = "2a"
38
42
def test_info_non_existing(self):
39
if sys.platform == "win32":
40
location = "C:/i/do/not/exist/"
42
location = "/i/do/not/exist/"
43
self.vfs_transport_factory = memory.MemoryServer
44
location = self.get_url()
43
45
out, err = self.run_bzr('info '+location, retcode=3)
44
46
self.assertEqual(out, '')
45
47
self.assertEqual(err, 'bzr: ERROR: Not a branch: "%s".\n' % location)
48
50
transport = self.get_transport()
50
52
# Create initial standalone branch
51
tree1 = self.make_branch_and_tree('standalone', 'weave')
53
tree1 = self.make_branch_and_tree('standalone', 'knit')
52
54
self.build_tree(['standalone/a'])
54
56
branch1 = tree1.branch
56
58
out, err = self.run_bzr('info standalone')
57
59
self.assertEqualDiff(
58
"""Standalone tree (format: weave)
60
"""Standalone tree (format: knit)
60
62
branch root: standalone
64
66
# Standalone branch - verbose mode
65
67
out, err = self.run_bzr('info standalone -v')
66
68
self.assertEqualDiff(
67
"""Standalone tree (format: weave)
69
"""Standalone tree (format: knit)
69
71
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
74
control: Meta directory format 1
75
working tree: Working tree format 3
76
branch: Branch format 5
77
repository: Knit repository format 1
77
79
In the working tree:
95
97
# Standalone branch - really verbose mode
96
98
out, err = self.run_bzr('info standalone -vv')
97
99
self.assertEqualDiff(
98
"""Standalone tree (format: weave)
100
"""Standalone tree (format: knit)
100
102
branch root: standalone
103
control: All-in-one format 6
104
working tree: Working tree format 2
105
branch: Branch format 4
106
repository: Weave repository format 6
105
control: Meta directory format 1
106
working tree: Working tree format 3
107
branch: Branch format 5
108
repository: Knit repository format 1
108
110
In the working tree:
125
127
self.assertEqual('', err)
126
128
tree1.commit('commit one')
127
rev = branch1.repository.get_revision(branch1.revision_history()[0])
128
datestring_first = format_date(rev.timestamp, rev.timezone)
129
rev = branch1.repository.get_revision(branch1.last_revision())
130
datestring_first = osutils.format_date(rev.timestamp, rev.timezone)
130
132
# Branch standalone with push location
131
133
branch2 = branch1.bzrdir.sprout('branch').open_branch()
154
156
parent branch: standalone
157
control: All-in-one format 6
158
working tree: Working tree format 2
159
branch: Branch format 4
160
repository: Weave repository format 6
159
control: Meta directory format 1
160
working tree: Working tree format 3
161
branch: Branch format 5
162
repository: Knit repository format 1
162
164
In the working tree:
186
188
branch1.bzrdir.sprout('bound')
187
189
knit1_format = bzrdir.format_registry.make_bzrdir('knit')
188
190
upgrade.upgrade('bound', knit1_format)
189
branch3 = bzrdir.BzrDir.open('bound').open_branch()
191
branch3 = controldir.ControlDir.open('bound').open_branch()
190
192
branch3.bind(branch1)
191
193
bound_tree = branch3.bzrdir.open_workingtree()
192
194
out, err = self.run_bzr('info -v bound')
231
233
self.assertEqual('', err)
233
235
# Checkout standalone (same as above, but does not have parent set)
234
branch4 = bzrdir.BzrDir.create_branch_convenience('checkout',
236
branch4 = controldir.ControlDir.create_branch_convenience('checkout',
235
237
format=knit1_format)
236
238
branch4.bind(branch1)
237
239
branch4.bzrdir.open_workingtree().update()
275
277
tree5 = branch1.create_checkout('lightcheckout', lightweight=True)
276
278
branch5 = tree5.branch
277
279
out, err = self.run_bzr('info -v lightcheckout')
280
if "metaweave" in bzrdir.format_registry:
281
format_description = "knit or metaweave"
283
format_description = "knit"
278
284
self.assertEqualDiff(
279
"""Lightweight checkout (format: 1.6 or 1.6.1-rich-root \
280
or 1.9 or 1.9-rich-root \
281
or dirstate or dirstate-tags or \
282
pack-0.92 or rich-root or rich-root-pack)
285
"""Lightweight checkout (format: %s)
284
287
light checkout root: lightcheckout
285
288
checkout of branch: standalone
288
291
control: Meta directory format 1
289
working tree: Working tree format 4
290
branch: Branch format 4
291
repository: Weave repository format 6
292
working tree: Working tree format 3
293
branch: Branch format 5
294
repository: Knit repository format 1
293
296
In the working tree:
311
""" % (datestring_first, datestring_first,), out)
314
""" % (format_description, datestring_first, datestring_first,), out)
312
315
self.assertEqual('', err)
314
317
# Update initial standalone branch
315
318
self.build_tree(['standalone/b'])
317
320
tree1.commit('commit two')
318
rev = branch1.repository.get_revision(branch1.revision_history()[-1])
319
datestring_last = format_date(rev.timestamp, rev.timezone)
321
rev = branch1.repository.get_revision(branch1.last_revision())
322
datestring_last = osutils.format_date(rev.timestamp, rev.timezone)
321
324
# Out of date branched standalone branch will not be detected
322
325
out, err = self.run_bzr('info -v branch')
323
326
self.assertEqualDiff(
324
"""Standalone tree (format: weave)
327
"""Standalone tree (format: knit)
326
329
branch root: branch
330
333
parent branch: standalone
333
control: All-in-one format 6
334
working tree: Working tree format 2
335
branch: Branch format 4
336
repository: Weave repository format 6
336
control: Meta directory format 1
337
working tree: Working tree format 3
338
branch: Branch format 5
339
repository: Knit repository format 1
338
341
In the working tree:
441
444
# Out of date lightweight checkout
442
445
out, err = self.run_bzr('info lightcheckout --verbose')
443
446
self.assertEqualDiff(
444
"""Lightweight checkout (format: 1.6 or 1.6.1-rich-root or \
445
1.9 or 1.9-rich-root or \
446
dirstate or dirstate-tags or \
447
pack-0.92 or rich-root or rich-root-pack)
447
"""Lightweight checkout (format: %s)
449
449
light checkout root: lightcheckout
450
450
checkout of branch: standalone
453
453
control: Meta directory format 1
454
working tree: Working tree format 4
455
branch: Branch format 4
456
repository: Weave repository format 6
454
working tree: Working tree format 3
455
branch: Branch format 5
456
repository: Knit repository format 1
458
458
Working tree is out of date: missing 1 revision.
478
""" % (datestring_first, datestring_last,), out)
478
""" % (format_description, datestring_first, datestring_last,), out)
479
479
self.assertEqual('', err)
481
481
def test_info_standalone_no_tree(self):
531
531
# Create branch inside shared repository
532
532
repo.bzrdir.root_transport.mkdir('branch')
533
branch1 = repo.bzrdir.create_branch_convenience('repo/branch',
533
branch1 = controldir.ControlDir.create_branch_convenience(
534
'repo/branch', format=format)
535
535
out, err = self.run_bzr('info -v repo/branch')
536
536
self.assertEqualDiff(
537
537
"""Repository branch (format: dirstate or knit)
572
572
self.build_tree(['tree/lightcheckout/a'])
574
574
tree2.commit('commit one')
575
rev = repo.get_revision(branch2.revision_history()[0])
576
datestring_first = format_date(rev.timestamp, rev.timezone)
575
rev = repo.get_revision(branch2.last_revision())
576
datestring_first = osutils.format_date(rev.timestamp, rev.timezone)
577
577
out, err = self.run_bzr('info tree/lightcheckout --verbose')
578
578
self.assertEqualDiff(
579
"""Lightweight checkout (format: 1.6 or 1.6.1-rich-root or \
580
1.9 or 1.9-rich-root or \
581
dirstate or dirstate-tags or \
582
pack-0.92 or rich-root or rich-root-pack)
579
"""Lightweight checkout (format: %s)
584
581
light checkout root: tree/lightcheckout
585
582
checkout of branch: repo/branch
612
""" % (format.get_branch_format().get_format_description(),
609
""" % (self._repo_strings, format.get_branch_format().get_format_description(),
613
610
format.repository_format.get_format_description(),
614
611
datestring_first, datestring_first,
618
615
# Out of date checkout
619
616
out, err = self.run_bzr('info -v tree/checkout')
620
617
self.assertEqualDiff(
621
"""Checkout (format: dirstate)
618
"""Checkout (format: unnamed)
623
620
checkout root: tree/checkout
624
621
checkout of branch: repo/branch
627
624
control: Meta directory format 1
628
working tree: Working tree format 4
625
working tree: Working tree format 6
658
655
out, err = self.run_bzr('info tree/checkout --verbose')
659
656
self.assertEqualDiff(
660
"""Checkout (format: dirstate)
657
"""Checkout (format: unnamed)
662
659
checkout root: tree/checkout
663
660
checkout of branch: repo/branch
666
663
control: Meta directory format 1
667
working tree: Working tree format 4
664
working tree: Working tree format 6
694
691
tree3.commit('commit two')
696
693
# Out of date lightweight checkout
697
rev = repo.get_revision(branch1.revision_history()[-1])
698
datestring_last = format_date(rev.timestamp, rev.timezone)
694
rev = repo.get_revision(branch1.last_revision())
695
datestring_last = osutils.format_date(rev.timestamp, rev.timezone)
699
696
out, err = self.run_bzr('info tree/lightcheckout --verbose')
700
697
self.assertEqualDiff(
701
"""Lightweight checkout (format: 1.6 or 1.6.1-rich-root or \
702
1.9 or 1.9-rich-root or \
703
dirstate or dirstate-tags or \
704
pack-0.92 or rich-root or rich-root-pack)
698
"""Lightweight checkout (format: %s)
706
700
light checkout root: tree/lightcheckout
707
701
checkout of branch: repo/branch
736
""" % (format.get_branch_format().get_format_description(),
730
""" % (self._repo_strings, format.get_branch_format().get_format_description(),
737
731
format.repository_format.get_format_description(),
738
732
datestring_first, datestring_last,
811
805
# Create two branches
812
806
repo.bzrdir.root_transport.mkdir('branch1')
813
branch1 = repo.bzrdir.create_branch_convenience('repo/branch1',
807
branch1 = controldir.ControlDir.create_branch_convenience('repo/branch1',
815
809
branch2 = branch1.bzrdir.sprout('repo/branch2').open_branch()
853
847
tree1 = branch1.bzrdir.open_workingtree()
855
849
tree1.commit('commit one')
856
rev = repo.get_revision(branch1.revision_history()[0])
857
datestring_first = format_date(rev.timestamp, rev.timezone)
850
rev = repo.get_revision(branch1.last_revision())
851
datestring_first = osutils.format_date(rev.timestamp, rev.timezone)
858
852
out, err = self.run_bzr('info -v repo/branch1')
859
853
self.assertEqualDiff(
860
854
"""Repository tree (format: knit)
1134
1128
(False, True): 'Lightweight checkout',
1135
1129
(False, False): 'Checkout',
1136
1130
}[(shared_repo is not None, light_checkout)]
1137
format = {True: '1.6 or 1.6.1-rich-root'
1138
' or 1.9 or 1.9-rich-root'
1139
' or dirstate or dirstate-tags or pack-0.92'
1140
' or rich-root or rich-root-pack',
1141
False: 'dirstate'}[light_checkout]
1131
format = {True: self._repo_strings,
1132
False: 'unnamed'}[light_checkout]
1142
1133
if repo_locked:
1143
1134
repo_locked = lco_tree.branch.repository.get_physical_lock_status()
1144
1135
if repo_locked or branch_locked or tree_locked:
1231
1222
format=bzrdir.BzrDirMetaFormat1())
1232
1223
repo.set_make_working_trees(False)
1233
1224
repo.bzrdir.root_transport.mkdir('branch')
1234
repo_branch = repo.bzrdir.create_branch_convenience('repo/branch',
1235
format=bzrdir.BzrDirMetaFormat1())
1225
repo_branch = controldir.ControlDir.create_branch_convenience(
1226
'repo/branch', format=bzrdir.BzrDirMetaFormat1())
1236
1227
# Do a heavy checkout
1237
1228
transport.mkdir('tree')
1238
1229
transport.mkdir('tree/checkout')
1239
co_branch = bzrdir.BzrDir.create_branch_convenience('tree/checkout',
1240
format=bzrdir.BzrDirMetaFormat1())
1230
co_branch = controldir.ControlDir.create_branch_convenience(
1231
'tree/checkout', format=bzrdir.BzrDirMetaFormat1())
1241
1232
co_branch.bind(repo_branch)
1242
1233
# Do a light checkout of the heavy one
1243
1234
transport.mkdir('tree/lightcheckout')
1244
1235
lco_dir = bzrdir.BzrDirMetaFormat1().initialize('tree/lightcheckout')
1245
branch.BranchReferenceFormat().initialize(lco_dir, co_branch)
1236
branch.BranchReferenceFormat().initialize(lco_dir,
1237
target_branch=co_branch)
1246
1238
lco_dir.create_workingtree()
1247
1239
lco_tree = lco_dir.open_workingtree()
1336
1328
self.knownFailure('Win32 cannot run "bzr info"'
1337
1329
' when the tree is locked.')
1339
def test_info_locking_oslocks(self):
1340
if sys.platform == "win32":
1341
raise TestSkipped("don't use oslocks on win32 in unix manner")
1343
tree = self.make_branch_and_tree('branch',
1344
format=bzrdir.BzrDirFormat6())
1346
# Test all permutations of locking the working tree, branch and repository
1347
# XXX: Well not yet, as we can't query oslocks yet. Currently, it's
1348
# implemented by raising NotImplementedError and get_physical_lock_status()
1349
# always returns false. This makes bzr info hide the lock status. (Olaf)
1353
out, err = self.run_bzr('info -v branch')
1354
self.assertEqualDiff(
1355
"""Standalone tree (format: weave)
1360
control: All-in-one format 6
1361
working tree: Working tree format 2
1362
branch: Branch format 4
1365
In the working tree:
1373
0 versioned subdirectories
1380
""" % ('branch', tree.branch.repository._format.get_format_description(),
1382
self.assertEqual('', err)
1385
out, err = self.run_bzr('info -v branch')
1386
self.assertEqualDiff(
1387
"""Standalone tree (format: weave)
1392
control: All-in-one format 6
1393
working tree: Working tree format 2
1394
branch: Branch format 4
1397
In the working tree:
1405
0 versioned subdirectories
1412
""" % ('branch', tree.branch.repository._format.get_format_description(),
1414
self.assertEqual('', err)
1417
1331
def test_info_stacked(self):
1418
1332
# We have a mainline
1419
1333
trunk_tree = self.make_branch_and_tree('mainline',
1432
1346
stacked on: mainline
1434
1348
self.assertEqual("", err)
1350
def test_info_revinfo_optional(self):
1351
tree = self.make_branch_and_tree('.')
1352
def last_revision_info(self):
1353
raise errors.UnsupportedOperation(last_revision_info, self)
1355
branch.Branch, "last_revision_info", last_revision_info)
1356
out, err = self.run_bzr('info -v .')
1358
"""Standalone tree (format: 2a)
1363
control: Meta directory format 1
1364
working tree: Working tree format 6
1365
branch: Branch format 7
1366
repository: Repository format 2a - rich roots, group compression and chk inventories
1368
In the working tree:
1376
0 versioned subdirectories
1378
self.assertEqual("", err)