1
# Copyright (C) 2006, 2007 Canonical Ltd
1
# Copyright (C) 2006, 2007, 2008 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., 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
22
from bzrlib import (
30
31
from bzrlib.osutils import format_date
41
42
location = "/i/do/not/exist/"
42
43
out, err = self.run_bzr('info '+location, retcode=3)
43
44
self.assertEqual(out, '')
44
self.assertEqual(err, 'bzr: ERROR: Not a branch: %s\n' % location)
45
self.assertEqual(err, 'bzr: ERROR: Not a branch: "%s".\n' % location)
46
47
def test_info_standalone(self):
47
48
transport = self.get_transport()
61
62
self.assertEqual('', err)
64
# Standalone branch - verbose mode
63
65
out, err = self.run_bzr('info standalone -v')
64
66
self.assertEqualDiff(
65
67
"""Standalone tree (format: weave)
93
self.assertEqual('', err)
95
# Standalone branch - really verbose mode
96
out, err = self.run_bzr('info standalone -vv')
98
"""Standalone tree (format: weave)
100
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
116
0 versioned subdirectories
93
125
self.assertEqual('', err)
94
126
tree1.commit('commit one')
144
175
first revision: %s
145
176
latest revision: %s
150
180
""" % (datestring_first, datestring_first,
151
# poking at _revision_store isn't all that clean, but neither is
152
# having the ui test dependent on the exact overhead of a given store.
153
branch2.repository._revision_store.total_size(
154
branch2.repository.get_transaction())[1] / 1024,
156
182
self.assertEqual('', err)
159
185
# (creates backup as unknown)
160
186
branch1.bzrdir.sprout('bound')
161
187
knit1_format = bzrdir.format_registry.make_bzrdir('knit')
162
bzrlib.upgrade.upgrade('bound', knit1_format)
163
branch3 = bzrlib.bzrdir.BzrDir.open('bound').open_branch()
188
upgrade.upgrade('bound', knit1_format)
189
branch3 = bzrdir.BzrDir.open('bound').open_branch()
164
190
branch3.bind(branch1)
165
191
bound_tree = branch3.bzrdir.open_workingtree()
166
192
out, err = self.run_bzr('info -v bound')
196
221
first revision: %s
197
222
latest revision: %s
202
226
""" % (bound_tree._format.get_format_description(),
203
227
branch3._format.get_format_description(),
204
228
branch3.repository._format.get_format_description(),
205
229
datestring_first, datestring_first,
206
# poking at _revision_store isn't all that clean, but neither is
207
# having the ui test dependent on the exact overhead of a given store.
208
branch3.repository._revision_store.total_size(
209
branch3.repository.get_transaction())[1] / 1024,
211
231
self.assertEqual('', err)
213
233
# Checkout standalone (same as above, but does not have parent set)
214
branch4 = bzrlib.bzrdir.BzrDir.create_branch_convenience('checkout',
234
branch4 = bzrdir.BzrDir.create_branch_convenience('checkout',
215
235
format=knit1_format)
216
236
branch4.bind(branch1)
217
237
branch4.bzrdir.open_workingtree().update()
245
264
first revision: %s
246
265
latest revision: %s
251
269
""" % (branch4.repository._format.get_format_description(),
252
270
datestring_first, datestring_first,
253
# poking at _revision_store isn't all that clean, but neither is
254
# having the ui test dependent on the exact overhead of a given store.
255
branch4.repository._revision_store.total_size(
256
branch4.repository.get_transaction())[1] / 1024,
258
272
self.assertEqual('', err)
262
276
branch5 = tree5.branch
263
277
out, err = self.run_bzr('info -v lightcheckout')
264
278
self.assertEqualDiff(
265
"""Lightweight checkout (format: dirstate or dirstate-tags)
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)
267
284
light checkout root: lightcheckout
268
285
checkout of branch: standalone
380
392
first revision: %s
381
393
latest revision: %s
386
397
""" % (branch3.repository._format.get_format_description(),
387
398
datestring_first, datestring_first,
388
# poking at _revision_store isn't all that clean, but neither is
389
# having the ui test dependent on the exact overhead of a given store.
390
branch3.repository._revision_store.total_size(
391
branch3.repository.get_transaction())[1] / 1024,
393
400
self.assertEqual('', err)
425
431
first revision: %s
426
432
latest revision: %s
431
436
""" % (branch4.repository._format.get_format_description(),
432
437
datestring_first, datestring_first,
433
# poking at _revision_store isn't all that clean, but neither is
434
# having the ui test dependent on the exact overhead of a given store.
435
branch4.repository._revision_store.total_size(
436
branch4.repository.get_transaction())[1] / 1024,
438
439
self.assertEqual('', err)
440
441
# Out of date lightweight checkout
441
442
out, err = self.run_bzr('info lightcheckout --verbose')
442
443
self.assertEqualDiff(
443
"""Lightweight checkout (format: dirstate or dirstate-tags)
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)
445
449
light checkout root: lightcheckout
446
450
checkout of branch: standalone
502
""" % (format.get_branch_format().get_format_description(),
502
""" % (info.describe_format(repo.bzrdir, repo, branch, None),
503
format.get_branch_format().get_format_description(),
503
504
format.repository_format.get_format_description(),
505
506
self.assertEqual('', err)
559
557
# Create lightweight checkout
560
558
transport.mkdir('tree')
561
559
transport.mkdir('tree/lightcheckout')
562
tree2 = branch1.create_checkout('tree/lightcheckout',
560
tree2 = branch1.create_checkout('tree/lightcheckout',
563
561
lightweight=True)
564
562
branch2 = tree2.branch
565
563
self.assertCheckoutStatusOutput('-v tree/lightcheckout', tree2,
578
576
datestring_first = format_date(rev.timestamp, rev.timezone)
579
577
out, err = self.run_bzr('info tree/lightcheckout --verbose')
580
578
self.assertEqualDiff(
581
"""Lightweight checkout (format: dirstate or dirstate-tags)
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)
583
584
light checkout root: tree/lightcheckout
584
585
checkout of branch: repo/branch
607
607
first revision: %s
608
608
latest revision: %s
613
612
""" % (format.get_branch_format().get_format_description(),
614
613
format.repository_format.get_format_description(),
615
614
datestring_first, datestring_first,
616
# poking at _revision_store isn't all that clean, but neither is
617
# having the ui test dependent on the exact overhead of a given store.
618
repo._revision_store.total_size(repo.get_transaction())[1] / 1024,
620
616
self.assertEqual('', err)
691
684
first revision: %s
692
685
latest revision: %s
697
689
""" % (format.get_branch_format().get_format_description(),
698
690
format.repository_format.get_format_description(),
699
691
datestring_first, datestring_first,
700
# poking at _revision_store isn't all that clean, but neither is
701
# having the ui test dependent on the exact overhead of a given store.
702
repo._revision_store.total_size(repo.get_transaction())[1] / 1024,
704
693
self.assertEqual('', err)
705
694
tree3.commit('commit two')
709
698
datestring_last = format_date(rev.timestamp, rev.timezone)
710
699
out, err = self.run_bzr('info tree/lightcheckout --verbose')
711
700
self.assertEqualDiff(
712
"""Lightweight checkout (format: dirstate or dirstate-tags)
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)
714
706
light checkout root: tree/lightcheckout
715
707
checkout of branch: repo/branch
740
731
first revision: %s
741
732
latest revision: %s
746
736
""" % (format.get_branch_format().get_format_description(),
747
737
format.repository_format.get_format_description(),
748
738
datestring_first, datestring_last,
749
# poking at _revision_store isn't all that clean, but neither is
750
# having the ui test dependent on the exact overhead of a given store.
751
repo._revision_store.total_size(repo.get_transaction())[1] / 1024,
753
740
self.assertEqual('', err)
772
758
first revision: %s
773
759
latest revision: %s
778
763
""" % (format.get_branch_format().get_format_description(),
779
764
format.repository_format.get_format_description(),
780
765
datestring_first, datestring_last,
781
# poking at _revision_store isn't all that clean, but neither is
782
# having the ui test dependent on the exact overhead of a given store.
783
repo._revision_store.total_size(repo.get_transaction())[1] / 1024,
785
767
self.assertEqual('', err)
801
782
""" % (format.repository_format.get_format_description(),
802
# poking at _revision_store isn't all that clean, but neither is
803
# having the ui test dependent on the exact overhead of a given store.
804
repo._revision_store.total_size(repo.get_transaction())[1] / 1024,
806
784
self.assertEqual('', err)
910
884
first revision: %s
911
885
latest revision: %s
916
889
""" % (format.get_branch_format().get_format_description(),
917
890
format.repository_format.get_format_description(),
918
891
datestring_first, datestring_first,
919
# poking at _revision_store isn't all that clean, but neither is
920
# having the ui test dependent on the exact overhead of a given store.
921
repo._revision_store.total_size(repo.get_transaction())[1] / 1024,
923
893
self.assertEqual('', err)
959
927
""" % (format.get_branch_format().get_format_description(),
960
928
format.repository_format.get_format_description(),
961
# poking at _revision_store isn't all that clean, but neither is
962
# having the ui test dependent on the exact overhead of a given store.
963
repo._revision_store.total_size(repo.get_transaction())[1] / 1024,
965
930
self.assertEqual('', err)
1000
964
first revision: %s
1001
965
latest revision: %s
1006
969
""" % (format.get_branch_format().get_format_description(),
1007
970
format.repository_format.get_format_description(),
1008
971
datestring_first, datestring_first,
1009
# poking at _revision_store isn't all that clean, but neither is
1010
# having the ui test dependent on the exact overhead of a given store.
1011
repo._revision_store.total_size(repo.get_transaction())[1] / 1024,
1013
973
self.assertEqual('', err)
1031
990
""" % (format.repository_format.get_format_description(),
1032
# poking at _revision_store isn't all that clean, but neither is
1033
# having the ui test dependent on the exact overhead of a given store.
1034
repo._revision_store.total_size(repo.get_transaction())[1] / 1024,
1037
993
self.assertEqual('', err)
1039
995
def test_info_shared_repository_with_tree_in_root(self):
1040
996
format = bzrdir.format_registry.make_bzrdir('knit')
1041
997
transport = self.get_transport()
1092
1047
Branch history:
1099
1052
""" % (format.get_branch_format().get_format_description(),
1100
1053
format.repository_format.get_format_description(),
1102
1055
self.assertEqual('', err)
1104
def assertCheckoutStatusOutput(self,
1057
def test_info_repository_hook(self):
1058
format = bzrdir.format_registry.make_bzrdir('knit')
1059
def repo_info(repo, stats, outf):
1060
outf.write("more info\n")
1061
info.hooks.install_named_hook('repository', repo_info, None)
1062
# Create shared repository with working trees
1063
repo = self.make_repository('repo', shared=True, format=format)
1064
out, err = self.run_bzr('info -v repo')
1065
self.assertEqualDiff(
1066
"""Shared repository with trees (format: dirstate or dirstate-tags or knit)
1068
shared repository: repo
1071
control: Meta directory format 1
1074
Create working tree for new branches inside the repository.
1079
""" % (format.repository_format.get_format_description(),
1081
self.assertEqual('', err)
1083
def assertCheckoutStatusOutput(self,
1105
1084
command_string, lco_tree, shared_repo=None,
1106
1085
repo_branch=None,
1107
1086
tree_locked=False,
1116
1095
allow us, the test writers, to document what *should* be present in
1117
1096
the output. Removing this separation would remove the value of the
1120
1099
:param path: the path to the light checkout.
1121
1100
:param lco_tree: the tree object for the light checkout.
1122
1101
:param shared_repo: A shared repository is in use, expect that in
1126
1105
:param tree_locked: If true, expect the tree to be locked.
1127
1106
:param branch_locked: If true, expect the branch to be locked.
1128
1107
:param repo_locked: If true, expect the repository to be locked.
1129
:param verbose: If true, expect verbose output
1108
Note that the lco_tree.branch.repository is inspected, and if is not
1109
actually locked then this parameter is overridden. This is because
1110
pack repositories do not have any public API for obtaining an
1111
exclusive repository wide lock.
1112
:param verbose: verbosity level: 2 or higher to show committers
1131
1114
def friendly_location(url):
1132
1115
path = urlutils.unescape_for_display(url, 'ascii')
1134
return osutils.relpath(os.getcwd(), path)
1117
return osutils.relpath(osutils.getcwd(), path)
1135
1118
except errors.PathNotChild:
1138
if tree_locked and sys.platform == 'win32':
1139
# We expect this to fail because of locking errors. (A write-locked
1140
# file cannot be read-locked in the same process).
1122
# We expect this to fail because of locking errors.
1123
# (A write-locked file cannot be read-locked
1124
# in the different process -- either on win32 or on linux).
1141
1125
# This should be removed when the locking errors are fixed.
1142
args = command_string.split(' ')
1143
self.run_bzr_error([], 'info', *args)
1126
self.expectFailure('OS locks are exclusive '
1127
'for different processes (Bug #174055)',
1128
self.run_bzr_subprocess,
1129
'info ' + command_string)
1145
1130
out, err = self.run_bzr('info %s' % command_string)
1146
1131
description = {
1147
1132
(True, True): 'Lightweight checkout',
1149
1134
(False, True): 'Lightweight checkout',
1150
1135
(False, False): 'Checkout',
1151
1136
}[(shared_repo is not None, light_checkout)]
1152
format = {True: 'dirstate or dirstate-tags',
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',
1153
1141
False: 'dirstate'}[light_checkout]
1143
repo_locked = lco_tree.branch.repository.get_physical_lock_status()
1154
1144
if repo_locked or branch_locked or tree_locked:
1155
1145
def locked_message(a_bool):
1239
1228
transport = self.get_transport()
1240
1229
# Create shared repository with a branch
1241
1230
repo = self.make_repository('repo', shared=True,
1242
format=bzrlib.bzrdir.BzrDirMetaFormat1())
1231
format=bzrdir.BzrDirMetaFormat1())
1243
1232
repo.set_make_working_trees(False)
1244
1233
repo.bzrdir.root_transport.mkdir('branch')
1245
1234
repo_branch = repo.bzrdir.create_branch_convenience('repo/branch',
1246
format=bzrlib.bzrdir.BzrDirMetaFormat1())
1235
format=bzrdir.BzrDirMetaFormat1())
1247
1236
# Do a heavy checkout
1248
1237
transport.mkdir('tree')
1249
1238
transport.mkdir('tree/checkout')
1250
co_branch = bzrlib.bzrdir.BzrDir.create_branch_convenience('tree/checkout',
1251
format=bzrlib.bzrdir.BzrDirMetaFormat1())
1239
co_branch = bzrdir.BzrDir.create_branch_convenience('tree/checkout',
1240
format=bzrdir.BzrDirMetaFormat1())
1252
1241
co_branch.bind(repo_branch)
1253
1242
# Do a light checkout of the heavy one
1254
1243
transport.mkdir('tree/lightcheckout')
1255
lco_dir = bzrlib.bzrdir.BzrDirMetaFormat1().initialize('tree/lightcheckout')
1256
bzrlib.branch.BranchReferenceFormat().initialize(lco_dir, co_branch)
1244
lco_dir = bzrdir.BzrDirMetaFormat1().initialize('tree/lightcheckout')
1245
branch.BranchReferenceFormat().initialize(lco_dir, co_branch)
1257
1246
lco_dir.create_workingtree()
1258
1247
lco_tree = lco_dir.open_workingtree()
1352
1341
raise TestSkipped("don't use oslocks on win32 in unix manner")
1354
1343
tree = self.make_branch_and_tree('branch',
1355
format=bzrlib.bzrdir.BzrDirFormat6())
1344
format=bzrdir.BzrDirFormat6())
1357
1346
# Test all permutations of locking the working tree, branch and repository
1358
1347
# XXX: Well not yet, as we can't query oslocks yet. Currently, it's
1420
1407
Branch history:
1427
1412
""" % ('branch', tree.branch.repository._format.get_format_description(),
1429
1414
self.assertEqual('', err)
1417
def test_info_stacked(self):
1418
# We have a mainline
1419
trunk_tree = self.make_branch_and_tree('mainline',
1421
trunk_tree.commit('mainline')
1422
# and a branch from it which is stacked
1423
new_dir = trunk_tree.bzrdir.sprout('newbranch', stacked=True)
1424
out, err = self.run_bzr('info newbranch')
1426
"""Standalone tree (format: 1.6)
1428
branch root: newbranch
1431
parent branch: mainline
1432
stacked on: mainline
1434
self.assertEqual("", err)