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
95
self.assertEqual('', err)
127
96
tree1.commit('commit one')
128
97
rev = branch1.repository.get_revision(branch1.revision_history()[0])
129
datestring_first = osutils.format_date(rev.timestamp, rev.timezone)
98
datestring_first = format_date(rev.timestamp, rev.timezone)
131
100
# Branch standalone with push location
132
101
branch2 = branch1.bzrdir.sprout('branch').open_branch()
176
146
first revision: %s
177
147
latest revision: %s
181
152
""" % (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,
183
158
self.assertEqual('', err)
186
161
# (creates backup as unknown)
187
162
branch1.bzrdir.sprout('bound')
188
163
knit1_format = bzrdir.format_registry.make_bzrdir('knit')
189
upgrade.upgrade('bound', knit1_format)
190
branch3 = bzrdir.BzrDir.open('bound').open_branch()
164
bzrlib.upgrade.upgrade('bound', knit1_format)
165
branch3 = bzrlib.bzrdir.BzrDir.open('bound').open_branch()
191
166
branch3.bind(branch1)
192
167
bound_tree = branch3.bzrdir.open_workingtree()
193
168
out, err = self.run_bzr('info -v bound')
217
192
0 versioned subdirectories
222
198
first revision: %s
223
199
latest revision: %s
227
204
""" % (bound_tree._format.get_format_description(),
228
205
branch3._format.get_format_description(),
229
206
branch3.repository._format.get_format_description(),
230
207
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,
232
213
self.assertEqual('', err)
234
215
# Checkout standalone (same as above, but does not have parent set)
235
branch4 = bzrdir.BzrDir.create_branch_convenience('checkout',
216
branch4 = bzrlib.bzrdir.BzrDir.create_branch_convenience('checkout',
236
217
format=knit1_format)
237
218
branch4.bind(branch1)
238
219
branch4.bzrdir.open_workingtree().update()
265
247
first revision: %s
266
248
latest revision: %s
270
253
""" % (branch4.repository._format.get_format_description(),
271
254
datestring_first, datestring_first,
255
# poking at _revision_store isn't all that clean, but neither is
256
# having the ui test dependent on the exact overhead of a given store.
257
branch4.repository._revision_store.total_size(
258
branch4.repository.get_transaction())[1] / 1024,
273
260
self.assertEqual('', err)
277
264
branch5 = tree5.branch
278
265
out, err = self.run_bzr('info -v lightcheckout')
279
266
self.assertEqualDiff(
280
"""Lightweight checkout (format: %s)
267
"""Lightweight checkout (format: dirstate or dirstate-tags or knitpack-experimental)
282
269
light checkout root: lightcheckout
283
270
checkout of branch: standalone
286
273
control: Meta directory format 1
287
working tree: Working tree format 6
274
working tree: Working tree format 4
288
275
branch: Branch format 4
289
276
repository: Weave repository format 6
304
292
first revision: %s
305
293
latest revision: %s
309
""" % (self._repo_strings, datestring_first, datestring_first,), out)
298
""" % (datestring_first, datestring_first,), out)
310
299
self.assertEqual('', err)
312
301
# Update initial standalone branch
315
304
tree1.commit('commit two')
316
305
rev = branch1.repository.get_revision(branch1.revision_history()[-1])
317
datestring_last = osutils.format_date(rev.timestamp, rev.timezone)
306
datestring_last = format_date(rev.timestamp, rev.timezone)
319
308
# Out of date branched standalone branch will not be detected
320
309
out, err = self.run_bzr('info -v branch')
385
376
0 versioned subdirectories
390
382
first revision: %s
391
383
latest revision: %s
395
388
""" % (branch3.repository._format.get_format_description(),
396
389
datestring_first, datestring_first,
390
# poking at _revision_store isn't all that clean, but neither is
391
# having the ui test dependent on the exact overhead of a given store.
392
branch3.repository._revision_store.total_size(
393
branch3.repository.get_transaction())[1] / 1024,
398
395
self.assertEqual('', err)
429
427
first revision: %s
430
428
latest revision: %s
434
433
""" % (branch4.repository._format.get_format_description(),
435
434
datestring_first, datestring_first,
435
# poking at _revision_store isn't all that clean, but neither is
436
# having the ui test dependent on the exact overhead of a given store.
437
branch4.repository._revision_store.total_size(
438
branch4.repository.get_transaction())[1] / 1024,
437
440
self.assertEqual('', err)
439
442
# Out of date lightweight checkout
440
443
out, err = self.run_bzr('info lightcheckout --verbose')
441
444
self.assertEqualDiff(
442
"""Lightweight checkout (format: %s)
445
"""Lightweight checkout (format: dirstate or dirstate-tags or knitpack-experimental)
444
447
light checkout root: lightcheckout
445
448
checkout of branch: standalone
448
451
control: Meta directory format 1
449
working tree: Working tree format 6
452
working tree: Working tree format 4
450
453
branch: Branch format 4
451
454
repository: Weave repository format 6
468
472
first revision: %s
469
473
latest revision: %s
473
""" % (self._repo_strings, datestring_first, datestring_last,), out)
478
""" % (datestring_first, datestring_last,), out)
474
479
self.assertEqual('', err)
476
481
def test_info_standalone_no_tree(self):
497
504
""" % (info.describe_format(repo.bzrdir, repo, branch, None),
498
505
format.get_branch_format().get_format_description(),
499
506
format.repository_format.get_format_description(),
552
562
# Create lightweight checkout
553
563
transport.mkdir('tree')
554
564
transport.mkdir('tree/lightcheckout')
555
tree2 = branch1.create_checkout('tree/lightcheckout',
565
tree2 = branch1.create_checkout('tree/lightcheckout',
556
566
lightweight=True)
557
567
branch2 = tree2.branch
558
568
self.assertCheckoutStatusOutput('-v tree/lightcheckout', tree2,
569
579
tree2.commit('commit one')
570
580
rev = repo.get_revision(branch2.revision_history()[0])
571
datestring_first = osutils.format_date(rev.timestamp, rev.timezone)
581
datestring_first = format_date(rev.timestamp, rev.timezone)
572
582
out, err = self.run_bzr('info tree/lightcheckout --verbose')
573
583
self.assertEqualDiff(
574
"""Lightweight checkout (format: %s)
584
"""Lightweight checkout (format: dirstate or dirstate-tags or knitpack-experimental)
576
586
light checkout root: tree/lightcheckout
577
587
checkout of branch: repo/branch
599
610
first revision: %s
600
611
latest revision: %s
604
""" % (self._repo_strings, format.get_branch_format().get_format_description(),
616
""" % (format.get_branch_format().get_format_description(),
605
617
format.repository_format.get_format_description(),
606
618
datestring_first, datestring_first,
619
# poking at _revision_store isn't all that clean, but neither is
620
# having the ui test dependent on the exact overhead of a given store.
621
repo._revision_store.total_size(repo.get_transaction())[1] / 1024,
608
623
self.assertEqual('', err)
610
625
# Out of date checkout
611
626
out, err = self.run_bzr('info -v tree/checkout')
612
627
self.assertEqualDiff(
613
"""Checkout (format: unnamed)
628
"""Checkout (format: dirstate)
615
630
checkout root: tree/checkout
616
631
checkout of branch: repo/branch
619
634
control: Meta directory format 1
620
working tree: Working tree format 6
635
working tree: Working tree format 4
650
667
out, err = self.run_bzr('info tree/checkout --verbose')
651
668
self.assertEqualDiff(
652
"""Checkout (format: unnamed)
669
"""Checkout (format: dirstate)
654
671
checkout root: tree/checkout
655
672
checkout of branch: repo/branch
658
675
control: Meta directory format 1
659
working tree: Working tree format 6
676
working tree: Working tree format 4
676
694
first revision: %s
677
695
latest revision: %s
681
700
""" % (format.get_branch_format().get_format_description(),
682
701
format.repository_format.get_format_description(),
683
702
datestring_first, datestring_first,
703
# poking at _revision_store isn't all that clean, but neither is
704
# having the ui test dependent on the exact overhead of a given store.
705
repo._revision_store.total_size(repo.get_transaction())[1] / 1024,
685
707
self.assertEqual('', err)
686
708
tree3.commit('commit two')
688
710
# Out of date lightweight checkout
689
711
rev = repo.get_revision(branch1.revision_history()[-1])
690
datestring_last = osutils.format_date(rev.timestamp, rev.timezone)
712
datestring_last = format_date(rev.timestamp, rev.timezone)
691
713
out, err = self.run_bzr('info tree/lightcheckout --verbose')
692
714
self.assertEqualDiff(
693
"""Lightweight checkout (format: %s)
715
"""Lightweight checkout (format: dirstate or dirstate-tags or knitpack-experimental)
695
717
light checkout root: tree/lightcheckout
696
718
checkout of branch: repo/branch
720
743
first revision: %s
721
744
latest revision: %s
725
""" % (self._repo_strings, format.get_branch_format().get_format_description(),
749
""" % (format.get_branch_format().get_format_description(),
726
750
format.repository_format.get_format_description(),
727
751
datestring_first, datestring_last,
752
# poking at _revision_store isn't all that clean, but neither is
753
# having the ui test dependent on the exact overhead of a given store.
754
repo._revision_store.total_size(repo.get_transaction())[1] / 1024,
729
756
self.assertEqual('', err)
747
775
first revision: %s
748
776
latest revision: %s
752
781
""" % (format.get_branch_format().get_format_description(),
753
782
format.repository_format.get_format_description(),
754
783
datestring_first, datestring_last,
784
# poking at _revision_store isn't all that clean, but neither is
785
# having the ui test dependent on the exact overhead of a given store.
786
repo._revision_store.total_size(repo.get_transaction())[1] / 1024,
756
788
self.assertEqual('', err)
771
804
""" % (format.repository_format.get_format_description(),
805
# poking at _revision_store isn't all that clean, but neither is
806
# having the ui test dependent on the exact overhead of a given store.
807
repo._revision_store.total_size(repo.get_transaction())[1] / 1024,
773
809
self.assertEqual('', err)
844
883
tree1.commit('commit one')
845
884
rev = repo.get_revision(branch1.revision_history()[0])
846
datestring_first = osutils.format_date(rev.timestamp, rev.timezone)
885
datestring_first = format_date(rev.timestamp, rev.timezone)
847
886
out, err = self.run_bzr('info -v repo/branch1')
848
887
self.assertEqualDiff(
849
888
"""Repository tree (format: knit)
873
913
first revision: %s
874
914
latest revision: %s
878
919
""" % (format.get_branch_format().get_format_description(),
879
920
format.repository_format.get_format_description(),
880
921
datestring_first, datestring_first,
922
# poking at _revision_store isn't all that clean, but neither is
923
# having the ui test dependent on the exact overhead of a given store.
924
repo._revision_store.total_size(repo.get_transaction())[1] / 1024,
882
926
self.assertEqual('', err)
916
962
""" % (format.get_branch_format().get_format_description(),
917
963
format.repository_format.get_format_description(),
964
# poking at _revision_store isn't all that clean, but neither is
965
# having the ui test dependent on the exact overhead of a given store.
966
repo._revision_store.total_size(repo.get_transaction())[1] / 1024,
919
968
self.assertEqual('', err)
953
1003
first revision: %s
954
1004
latest revision: %s
958
1009
""" % (format.get_branch_format().get_format_description(),
959
1010
format.repository_format.get_format_description(),
960
1011
datestring_first, datestring_first,
1012
# poking at _revision_store isn't all that clean, but neither is
1013
# having the ui test dependent on the exact overhead of a given store.
1014
repo._revision_store.total_size(repo.get_transaction())[1] / 1024,
962
1016
self.assertEqual('', err)
979
1034
""" % (format.repository_format.get_format_description(),
1035
# poking at _revision_store isn't all that clean, but neither is
1036
# having the ui test dependent on the exact overhead of a given store.
1037
repo._revision_store.total_size(repo.get_transaction())[1] / 1024,
982
1040
self.assertEqual('', err)
984
1042
def test_info_shared_repository_with_tree_in_root(self):
985
1043
format = bzrdir.format_registry.make_bzrdir('knit')
986
1044
transport = self.get_transport()
1036
1095
Branch history:
1041
1102
""" % (format.get_branch_format().get_format_description(),
1042
1103
format.repository_format.get_format_description(),
1044
1105
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
1107
def assertCheckoutStatusOutput(self,
1073
1108
command_string, lco_tree, shared_repo=None,
1074
1109
repo_branch=None,
1084
1119
allow us, the test writers, to document what *should* be present in
1085
1120
the output. Removing this separation would remove the value of the
1088
1123
:param path: the path to the light checkout.
1089
1124
:param lco_tree: the tree object for the light checkout.
1090
1125
:param shared_repo: A shared repository is in use, expect that in
1098
1133
actually locked then this parameter is overridden. This is because
1099
1134
pack repositories do not have any public API for obtaining an
1100
1135
exclusive repository wide lock.
1101
:param verbose: verbosity level: 2 or higher to show committers
1136
:param verbose: If true, expect verbose output
1103
1138
def friendly_location(url):
1104
1139
path = urlutils.unescape_for_display(url, 'ascii')
1107
1142
except errors.PathNotChild:
1111
# We expect this to fail because of locking errors.
1112
# (A write-locked file cannot be read-locked
1113
# in the different process -- either on win32 or on linux).
1145
if tree_locked and sys.platform == 'win32':
1146
# We expect this to fail because of locking errors. (A write-locked
1147
# file cannot be read-locked in the same process).
1114
1148
# This should be removed when the locking errors are fixed.
1115
self.expectFailure('OS locks are exclusive '
1116
'for different processes (Bug #174055)',
1117
self.run_bzr_subprocess,
1118
'info ' + command_string)
1149
self.run_bzr_error([], 'info ' + command_string)
1119
1151
out, err = self.run_bzr('info %s' % command_string)
1120
1152
description = {
1121
1153
(True, True): 'Lightweight checkout',
1123
1155
(False, True): 'Lightweight checkout',
1124
1156
(False, False): 'Checkout',
1125
1157
}[(shared_repo is not None, light_checkout)]
1126
format = {True: self._repo_strings,
1127
False: 'unnamed'}[light_checkout]
1158
format = {True: 'dirstate or dirstate-tags or knitpack-experimental',
1159
False: 'dirstate'}[light_checkout]
1128
1160
if repo_locked:
1129
1161
repo_locked = lco_tree.branch.repository.get_physical_lock_status()
1130
1162
if repo_locked or branch_locked or tree_locked:
1214
1247
transport = self.get_transport()
1215
1248
# Create shared repository with a branch
1216
1249
repo = self.make_repository('repo', shared=True,
1217
format=bzrdir.BzrDirMetaFormat1())
1250
format=bzrlib.bzrdir.BzrDirMetaFormat1())
1218
1251
repo.set_make_working_trees(False)
1219
1252
repo.bzrdir.root_transport.mkdir('branch')
1220
1253
repo_branch = repo.bzrdir.create_branch_convenience('repo/branch',
1221
format=bzrdir.BzrDirMetaFormat1())
1254
format=bzrlib.bzrdir.BzrDirMetaFormat1())
1222
1255
# Do a heavy checkout
1223
1256
transport.mkdir('tree')
1224
1257
transport.mkdir('tree/checkout')
1225
co_branch = bzrdir.BzrDir.create_branch_convenience('tree/checkout',
1226
format=bzrdir.BzrDirMetaFormat1())
1258
co_branch = bzrlib.bzrdir.BzrDir.create_branch_convenience('tree/checkout',
1259
format=bzrlib.bzrdir.BzrDirMetaFormat1())
1227
1260
co_branch.bind(repo_branch)
1228
1261
# Do a light checkout of the heavy one
1229
1262
transport.mkdir('tree/lightcheckout')
1230
lco_dir = bzrdir.BzrDirMetaFormat1().initialize('tree/lightcheckout')
1231
branch.BranchReferenceFormat().initialize(lco_dir,
1232
target_branch=co_branch)
1263
lco_dir = bzrlib.bzrdir.BzrDirMetaFormat1().initialize('tree/lightcheckout')
1264
bzrlib.branch.BranchReferenceFormat().initialize(lco_dir, co_branch)
1233
1265
lco_dir.create_workingtree()
1234
1266
lco_tree = lco_dir.open_workingtree()
1326
1358
def test_info_locking_oslocks(self):
1327
1359
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()
1360
raise TestSkipped("don't use oslocks on win32 in unix manner")
1335
1362
tree = self.make_branch_and_tree('branch',
1336
format=bzrdir.BzrDirFormat6())
1363
format=bzrlib.bzrdir.BzrDirFormat6())
1338
1365
# Test all permutations of locking the working tree, branch and repository
1339
1366
# XXX: Well not yet, as we can't query oslocks yet. Currently, it's
1399
1428
Branch history:
1404
1435
""" % ('branch', tree.branch.repository._format.get_format_description(),
1406
1437
self.assertEqual('', err)
1409
def test_info_stacked(self):
1410
# We have a mainline
1411
trunk_tree = self.make_branch_and_tree('mainline',
1413
trunk_tree.commit('mainline')
1414
# and a branch from it which is stacked
1415
new_dir = trunk_tree.bzrdir.sprout('newbranch', stacked=True)
1416
out, err = self.run_bzr('info newbranch')
1418
"""Standalone tree (format: 1.6)
1420
branch root: newbranch
1423
parent branch: mainline
1424
stacked on: mainline
1426
self.assertEqual("", err)