1
# Copyright (C) 2006-2010 Canonical Ltd
1
# Copyright (C) 2006, 2007 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
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."""
22
24
from bzrlib import (
32
from bzrlib.transport import memory
35
class TestInfo(tests.TestCaseWithTransport):
38
super(TestInfo, self).setUp()
39
self._repo_strings = "2a"
32
from bzrlib.osutils import format_date
33
from bzrlib.tests import TestSkipped
34
from bzrlib.tests.blackbox import ExternalBase
37
class TestInfo(ExternalBase):
41
39
def test_info_non_existing(self):
42
self.vfs_transport_factory = memory.MemoryServer
43
location = self.get_url()
40
if sys.platform == "win32":
41
location = "C:/i/do/not/exist/"
43
location = "/i/do/not/exist/"
44
44
out, err = self.run_bzr('info '+location, retcode=3)
45
45
self.assertEqual(out, '')
46
46
self.assertEqual(err, 'bzr: ERROR: Not a branch: "%s".\n' % location)
63
63
self.assertEqual('', err)
65
# Standalone branch - verbose mode
66
65
out, err = self.run_bzr('info standalone -v')
67
66
self.assertEqualDiff(
68
67
"""Standalone tree (format: weave)
94
self.assertEqual('', err)
96
# Standalone branch - really verbose mode
97
out, err = self.run_bzr('info standalone -vv')
99
"""Standalone tree (format: weave)
101
branch root: standalone
104
control: All-in-one format 6
105
working tree: Working tree format 2
106
branch: Branch format 4
107
repository: Weave repository format 6
117
0 versioned subdirectories
126
94
self.assertEqual('', err)
127
95
tree1.commit('commit one')
128
96
rev = branch1.repository.get_revision(branch1.revision_history()[0])
129
datestring_first = osutils.format_date(rev.timestamp, rev.timezone)
97
datestring_first = format_date(rev.timestamp, rev.timezone)
131
99
# Branch standalone with push location
132
100
branch2 = branch1.bzrdir.sprout('branch').open_branch()
186
155
# (creates backup as unknown)
187
156
branch1.bzrdir.sprout('bound')
188
157
knit1_format = bzrdir.format_registry.make_bzrdir('knit')
189
upgrade.upgrade('bound', knit1_format)
190
branch3 = bzrdir.BzrDir.open('bound').open_branch()
158
bzrlib.upgrade.upgrade('bound', knit1_format)
159
branch3 = bzrlib.bzrdir.BzrDir.open('bound').open_branch()
191
160
branch3.bind(branch1)
192
161
bound_tree = branch3.bzrdir.open_workingtree()
193
162
out, err = self.run_bzr('info -v bound')
232
202
self.assertEqual('', err)
234
204
# Checkout standalone (same as above, but does not have parent set)
235
branch4 = bzrdir.BzrDir.create_branch_convenience('checkout',
205
branch4 = bzrlib.bzrdir.BzrDir.create_branch_convenience('checkout',
236
206
format=knit1_format)
237
207
branch4.bind(branch1)
238
208
branch4.bzrdir.open_workingtree().update()
277
248
branch5 = tree5.branch
278
249
out, err = self.run_bzr('info -v lightcheckout')
279
250
self.assertEqualDiff(
280
"""Lightweight checkout (format: %s)
251
"""Lightweight checkout (format: dirstate or dirstate-tags or \
252
pack-0.92 or rich-root or rich-root-pack)
282
254
light checkout root: lightcheckout
283
255
checkout of branch: standalone
286
258
control: Meta directory format 1
287
working tree: Working tree format 6
259
working tree: Working tree format 4
288
260
branch: Branch format 4
289
261
repository: Weave repository format 6
304
277
first revision: %s
305
278
latest revision: %s
309
""" % (self._repo_strings, datestring_first, datestring_first,), out)
282
""" % (datestring_first, datestring_first,), out)
310
283
self.assertEqual('', err)
312
285
# Update initial standalone branch
315
288
tree1.commit('commit two')
316
289
rev = branch1.repository.get_revision(branch1.revision_history()[-1])
317
datestring_last = osutils.format_date(rev.timestamp, rev.timezone)
290
datestring_last = format_date(rev.timestamp, rev.timezone)
319
292
# Out of date branched standalone branch will not be detected
320
293
out, err = self.run_bzr('info -v branch')
439
415
# Out of date lightweight checkout
440
416
out, err = self.run_bzr('info lightcheckout --verbose')
441
417
self.assertEqualDiff(
442
"""Lightweight checkout (format: %s)
418
"""Lightweight checkout (format: dirstate or dirstate-tags or \
419
pack-0.92 or rich-root or rich-root-pack)
444
421
light checkout root: lightcheckout
445
422
checkout of branch: standalone
448
425
control: Meta directory format 1
449
working tree: Working tree format 6
426
working tree: Working tree format 4
450
427
branch: Branch format 4
451
428
repository: Weave repository format 6
468
446
first revision: %s
469
447
latest revision: %s
473
""" % (self._repo_strings, datestring_first, datestring_last,), out)
451
""" % (datestring_first, datestring_last,), out)
474
452
self.assertEqual('', err)
476
454
def test_info_standalone_no_tree(self):
552
532
# Create lightweight checkout
553
533
transport.mkdir('tree')
554
534
transport.mkdir('tree/lightcheckout')
555
tree2 = branch1.create_checkout('tree/lightcheckout',
535
tree2 = branch1.create_checkout('tree/lightcheckout',
556
536
lightweight=True)
557
537
branch2 = tree2.branch
558
538
self.assertCheckoutStatusOutput('-v tree/lightcheckout', tree2,
569
549
tree2.commit('commit one')
570
550
rev = repo.get_revision(branch2.revision_history()[0])
571
datestring_first = osutils.format_date(rev.timestamp, rev.timezone)
551
datestring_first = format_date(rev.timestamp, rev.timezone)
572
552
out, err = self.run_bzr('info tree/lightcheckout --verbose')
573
553
self.assertEqualDiff(
574
"""Lightweight checkout (format: %s)
554
"""Lightweight checkout (format: dirstate or dirstate-tags or \
555
pack-0.92 or rich-root or rich-root-pack)
576
557
light checkout root: tree/lightcheckout
577
558
checkout of branch: repo/branch
599
581
first revision: %s
600
582
latest revision: %s
604
""" % (self._repo_strings, format.get_branch_format().get_format_description(),
586
""" % (format.get_branch_format().get_format_description(),
605
587
format.repository_format.get_format_description(),
606
588
datestring_first, datestring_first,
610
592
# Out of date checkout
611
593
out, err = self.run_bzr('info -v tree/checkout')
612
594
self.assertEqualDiff(
613
"""Checkout (format: unnamed)
595
"""Checkout (format: dirstate)
615
597
checkout root: tree/checkout
616
598
checkout of branch: repo/branch
619
601
control: Meta directory format 1
620
working tree: Working tree format 6
602
working tree: Working tree format 4
650
633
out, err = self.run_bzr('info tree/checkout --verbose')
651
634
self.assertEqualDiff(
652
"""Checkout (format: unnamed)
635
"""Checkout (format: dirstate)
654
637
checkout root: tree/checkout
655
638
checkout of branch: repo/branch
658
641
control: Meta directory format 1
659
working tree: Working tree format 6
642
working tree: Working tree format 4
688
672
# Out of date lightweight checkout
689
673
rev = repo.get_revision(branch1.revision_history()[-1])
690
datestring_last = osutils.format_date(rev.timestamp, rev.timezone)
674
datestring_last = format_date(rev.timestamp, rev.timezone)
691
675
out, err = self.run_bzr('info tree/lightcheckout --verbose')
692
676
self.assertEqualDiff(
693
"""Lightweight checkout (format: %s)
677
"""Lightweight checkout (format: dirstate or dirstate-tags or \
678
pack-0.92 or rich-root or rich-root-pack)
695
680
light checkout root: tree/lightcheckout
696
681
checkout of branch: repo/branch
720
706
first revision: %s
721
707
latest revision: %s
725
""" % (self._repo_strings, format.get_branch_format().get_format_description(),
711
""" % (format.get_branch_format().get_format_description(),
726
712
format.repository_format.get_format_description(),
727
713
datestring_first, datestring_last,
844
832
tree1.commit('commit one')
845
833
rev = repo.get_revision(branch1.revision_history()[0])
846
datestring_first = osutils.format_date(rev.timestamp, rev.timezone)
834
datestring_first = format_date(rev.timestamp, rev.timezone)
847
835
out, err = self.run_bzr('info -v repo/branch1')
848
836
self.assertEqualDiff(
849
837
"""Repository tree (format: knit)
982
973
self.assertEqual('', err)
984
975
def test_info_shared_repository_with_tree_in_root(self):
985
976
format = bzrdir.format_registry.make_bzrdir('knit')
986
977
transport = self.get_transport()
1044
1036
self.assertEqual('', err)
1046
def test_info_repository_hook(self):
1047
format = bzrdir.format_registry.make_bzrdir('knit')
1048
def repo_info(repo, stats, outf):
1049
outf.write("more info\n")
1050
info.hooks.install_named_hook('repository', repo_info, None)
1051
# Create shared repository with working trees
1052
repo = self.make_repository('repo', shared=True, format=format)
1053
out, err = self.run_bzr('info -v repo')
1054
self.assertEqualDiff(
1055
"""Shared repository with trees (format: dirstate or dirstate-tags or knit)
1057
shared repository: repo
1060
control: Meta directory format 1
1063
Create working tree for new branches inside the repository.
1068
""" % (format.repository_format.get_format_description(),
1070
self.assertEqual('', err)
1072
1038
def assertCheckoutStatusOutput(self,
1073
1039
command_string, lco_tree, shared_repo=None,
1074
1040
repo_branch=None,
1084
1050
allow us, the test writers, to document what *should* be present in
1085
1051
the output. Removing this separation would remove the value of the
1088
1054
:param path: the path to the light checkout.
1089
1055
:param lco_tree: the tree object for the light checkout.
1090
1056
:param shared_repo: A shared repository is in use, expect that in
1098
1064
actually locked then this parameter is overridden. This is because
1099
1065
pack repositories do not have any public API for obtaining an
1100
1066
exclusive repository wide lock.
1101
:param verbose: verbosity level: 2 or higher to show committers
1067
:param verbose: If true, expect verbose output
1103
1069
def friendly_location(url):
1104
1070
path = urlutils.unescape_for_display(url, 'ascii')
1123
1089
(False, True): 'Lightweight checkout',
1124
1090
(False, False): 'Checkout',
1125
1091
}[(shared_repo is not None, light_checkout)]
1126
format = {True: self._repo_strings,
1127
False: 'unnamed'}[light_checkout]
1092
format = {True: 'dirstate or dirstate-tags or pack-0.92'
1093
' or rich-root or rich-root-pack',
1094
False: 'dirstate'}[light_checkout]
1128
1095
if repo_locked:
1129
1096
repo_locked = lco_tree.branch.repository.get_physical_lock_status()
1130
1097
if repo_locked or branch_locked or tree_locked:
1214
1181
transport = self.get_transport()
1215
1182
# Create shared repository with a branch
1216
1183
repo = self.make_repository('repo', shared=True,
1217
format=bzrdir.BzrDirMetaFormat1())
1184
format=bzrlib.bzrdir.BzrDirMetaFormat1())
1218
1185
repo.set_make_working_trees(False)
1219
1186
repo.bzrdir.root_transport.mkdir('branch')
1220
1187
repo_branch = repo.bzrdir.create_branch_convenience('repo/branch',
1221
format=bzrdir.BzrDirMetaFormat1())
1188
format=bzrlib.bzrdir.BzrDirMetaFormat1())
1222
1189
# Do a heavy checkout
1223
1190
transport.mkdir('tree')
1224
1191
transport.mkdir('tree/checkout')
1225
co_branch = bzrdir.BzrDir.create_branch_convenience('tree/checkout',
1226
format=bzrdir.BzrDirMetaFormat1())
1192
co_branch = bzrlib.bzrdir.BzrDir.create_branch_convenience('tree/checkout',
1193
format=bzrlib.bzrdir.BzrDirMetaFormat1())
1227
1194
co_branch.bind(repo_branch)
1228
1195
# Do a light checkout of the heavy one
1229
1196
transport.mkdir('tree/lightcheckout')
1230
lco_dir = bzrdir.BzrDirMetaFormat1().initialize('tree/lightcheckout')
1231
branch.BranchReferenceFormat().initialize(lco_dir,
1232
target_branch=co_branch)
1197
lco_dir = bzrlib.bzrdir.BzrDirMetaFormat1().initialize('tree/lightcheckout')
1198
bzrlib.branch.BranchReferenceFormat().initialize(lco_dir, co_branch)
1233
1199
lco_dir.create_workingtree()
1234
1200
lco_tree = lco_dir.open_workingtree()
1326
1292
def test_info_locking_oslocks(self):
1327
1293
if sys.platform == "win32":
1328
self.skip("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()
1294
raise TestSkipped("don't use oslocks on win32 in unix manner")
1335
1296
tree = self.make_branch_and_tree('branch',
1336
format=bzrdir.BzrDirFormat6())
1297
format=bzrlib.bzrdir.BzrDirFormat6())
1338
1299
# Test all permutations of locking the working tree, branch and repository
1339
1300
# XXX: Well not yet, as we can't query oslocks yet. Currently, it's
1409
1372
def test_info_stacked(self):
1410
1373
# We have a mainline
1411
1374
trunk_tree = self.make_branch_and_tree('mainline',
1375
format='development1')
1413
1376
trunk_tree.commit('mainline')
1414
1377
# and a branch from it which is stacked
1415
1378
new_dir = trunk_tree.bzrdir.sprout('newbranch', stacked=True)
1416
1379
out, err = self.run_bzr('info newbranch')
1417
1380
self.assertEqual(
1418
"""Standalone tree (format: 1.6)
1381
"""Standalone tree (format: development1)
1420
1383
branch root: newbranch