1
# Copyright (C) 2006, 2007 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
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 (
32
from bzrlib.osutils import format_date
33
from bzrlib.tests import TestSkipped
34
from bzrlib.tests.blackbox import ExternalBase
37
class TestInfo(ExternalBase):
32
from bzrlib.transport import memory
35
class TestInfo(tests.TestCaseWithTransport):
38
super(TestInfo, self).setUp()
39
self._repo_strings = "2a"
39
41
def test_info_non_existing(self):
40
if sys.platform == "win32":
41
location = "C:/i/do/not/exist/"
43
location = "/i/do/not/exist/"
42
self.vfs_transport_factory = memory.MemoryServer
43
location = self.get_url()
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
65
66
out, err = self.run_bzr('info standalone -v')
66
67
self.assertEqualDiff(
67
68
"""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
95
126
self.assertEqual('', err)
96
127
tree1.commit('commit one')
97
128
rev = branch1.repository.get_revision(branch1.revision_history()[0])
98
datestring_first = format_date(rev.timestamp, rev.timezone)
129
datestring_first = osutils.format_date(rev.timestamp, rev.timezone)
100
131
# Branch standalone with push location
101
132
branch2 = branch1.bzrdir.sprout('branch').open_branch()
146
176
first revision: %s
147
177
latest revision: %s
152
181
""" % (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
183
self.assertEqual('', err)
161
186
# (creates backup as unknown)
162
187
branch1.bzrdir.sprout('bound')
163
188
knit1_format = bzrdir.format_registry.make_bzrdir('knit')
164
bzrlib.upgrade.upgrade('bound', knit1_format)
165
branch3 = bzrlib.bzrdir.BzrDir.open('bound').open_branch()
189
upgrade.upgrade('bound', knit1_format)
190
branch3 = bzrdir.BzrDir.open('bound').open_branch()
166
191
branch3.bind(branch1)
167
192
bound_tree = branch3.bzrdir.open_workingtree()
168
193
out, err = self.run_bzr('info -v bound')
192
217
0 versioned subdirectories
198
222
first revision: %s
199
223
latest revision: %s
204
227
""" % (bound_tree._format.get_format_description(),
205
228
branch3._format.get_format_description(),
206
229
branch3.repository._format.get_format_description(),
207
230
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
232
self.assertEqual('', err)
215
234
# Checkout standalone (same as above, but does not have parent set)
216
branch4 = bzrlib.bzrdir.BzrDir.create_branch_convenience('checkout',
235
branch4 = bzrdir.BzrDir.create_branch_convenience('checkout',
217
236
format=knit1_format)
218
237
branch4.bind(branch1)
219
238
branch4.bzrdir.open_workingtree().update()
247
265
first revision: %s
248
266
latest revision: %s
253
270
""" % (branch4.repository._format.get_format_description(),
254
271
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,
260
273
self.assertEqual('', err)
264
277
branch5 = tree5.branch
265
278
out, err = self.run_bzr('info -v lightcheckout')
266
279
self.assertEqualDiff(
267
"""Lightweight checkout (format: dirstate or dirstate-tags or \
268
pack-0.92 or rich-root or rich-root-pack)
280
"""Lightweight checkout (format: %s)
270
282
light checkout root: lightcheckout
271
283
checkout of branch: standalone
274
286
control: Meta directory format 1
275
working tree: Working tree format 4
287
working tree: Working tree format 6
276
288
branch: Branch format 4
277
289
repository: Weave repository format 6
293
304
first revision: %s
294
305
latest revision: %s
299
""" % (datestring_first, datestring_first,), out)
309
""" % (self._repo_strings, datestring_first, datestring_first,), out)
300
310
self.assertEqual('', err)
302
312
# Update initial standalone branch
305
315
tree1.commit('commit two')
306
316
rev = branch1.repository.get_revision(branch1.revision_history()[-1])
307
datestring_last = format_date(rev.timestamp, rev.timezone)
317
datestring_last = osutils.format_date(rev.timestamp, rev.timezone)
309
319
# Out of date branched standalone branch will not be detected
310
320
out, err = self.run_bzr('info -v branch')
377
385
0 versioned subdirectories
383
390
first revision: %s
384
391
latest revision: %s
389
395
""" % (branch3.repository._format.get_format_description(),
390
396
datestring_first, datestring_first,
391
# poking at _revision_store isn't all that clean, but neither is
392
# having the ui test dependent on the exact overhead of a given store.
393
branch3.repository._revision_store.total_size(
394
branch3.repository.get_transaction())[1] / 1024,
396
398
self.assertEqual('', err)
428
429
first revision: %s
429
430
latest revision: %s
434
434
""" % (branch4.repository._format.get_format_description(),
435
435
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
437
self.assertEqual('', err)
443
439
# Out of date lightweight checkout
444
440
out, err = self.run_bzr('info lightcheckout --verbose')
445
441
self.assertEqualDiff(
446
"""Lightweight checkout (format: dirstate or dirstate-tags or \
447
pack-0.92 or rich-root or rich-root-pack)
442
"""Lightweight checkout (format: %s)
449
444
light checkout root: lightcheckout
450
445
checkout of branch: standalone
453
448
control: Meta directory format 1
454
working tree: Working tree format 4
449
working tree: Working tree format 6
455
450
branch: Branch format 4
456
451
repository: Weave repository format 6
474
468
first revision: %s
475
469
latest revision: %s
480
""" % (datestring_first, datestring_last,), out)
473
""" % (self._repo_strings, datestring_first, datestring_last,), out)
481
474
self.assertEqual('', err)
483
476
def test_info_standalone_no_tree(self):
506
497
""" % (info.describe_format(repo.bzrdir, repo, branch, None),
507
498
format.get_branch_format().get_format_description(),
508
499
format.repository_format.get_format_description(),
564
552
# Create lightweight checkout
565
553
transport.mkdir('tree')
566
554
transport.mkdir('tree/lightcheckout')
567
tree2 = branch1.create_checkout('tree/lightcheckout',
555
tree2 = branch1.create_checkout('tree/lightcheckout',
568
556
lightweight=True)
569
557
branch2 = tree2.branch
570
558
self.assertCheckoutStatusOutput('-v tree/lightcheckout', tree2,
581
569
tree2.commit('commit one')
582
570
rev = repo.get_revision(branch2.revision_history()[0])
583
datestring_first = format_date(rev.timestamp, rev.timezone)
571
datestring_first = osutils.format_date(rev.timestamp, rev.timezone)
584
572
out, err = self.run_bzr('info tree/lightcheckout --verbose')
585
573
self.assertEqualDiff(
586
"""Lightweight checkout (format: dirstate or dirstate-tags or \
587
pack-0.92 or rich-root or rich-root-pack)
574
"""Lightweight checkout (format: %s)
589
576
light checkout root: tree/lightcheckout
590
577
checkout of branch: repo/branch
613
599
first revision: %s
614
600
latest revision: %s
619
""" % (format.get_branch_format().get_format_description(),
604
""" % (self._repo_strings, format.get_branch_format().get_format_description(),
620
605
format.repository_format.get_format_description(),
621
606
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
608
self.assertEqual('', err)
628
610
# Out of date checkout
629
611
out, err = self.run_bzr('info -v tree/checkout')
630
612
self.assertEqualDiff(
631
"""Checkout (format: dirstate)
613
"""Checkout (format: unnamed)
633
615
checkout root: tree/checkout
634
616
checkout of branch: repo/branch
637
619
control: Meta directory format 1
638
working tree: Working tree format 4
620
working tree: Working tree format 6
670
650
out, err = self.run_bzr('info tree/checkout --verbose')
671
651
self.assertEqualDiff(
672
"""Checkout (format: dirstate)
652
"""Checkout (format: unnamed)
674
654
checkout root: tree/checkout
675
655
checkout of branch: repo/branch
678
658
control: Meta directory format 1
679
working tree: Working tree format 4
659
working tree: Working tree format 6
697
676
first revision: %s
698
677
latest revision: %s
703
681
""" % (format.get_branch_format().get_format_description(),
704
682
format.repository_format.get_format_description(),
705
683
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
685
self.assertEqual('', err)
711
686
tree3.commit('commit two')
713
688
# Out of date lightweight checkout
714
689
rev = repo.get_revision(branch1.revision_history()[-1])
715
datestring_last = format_date(rev.timestamp, rev.timezone)
690
datestring_last = osutils.format_date(rev.timestamp, rev.timezone)
716
691
out, err = self.run_bzr('info tree/lightcheckout --verbose')
717
692
self.assertEqualDiff(
718
"""Lightweight checkout (format: dirstate or dirstate-tags or \
719
pack-0.92 or rich-root or rich-root-pack)
693
"""Lightweight checkout (format: %s)
721
695
light checkout root: tree/lightcheckout
722
696
checkout of branch: repo/branch
747
720
first revision: %s
748
721
latest revision: %s
753
""" % (format.get_branch_format().get_format_description(),
725
""" % (self._repo_strings, format.get_branch_format().get_format_description(),
754
726
format.repository_format.get_format_description(),
755
727
datestring_first, datestring_last,
756
# poking at _revision_store isn't all that clean, but neither is
757
# having the ui test dependent on the exact overhead of a given store.
758
repo._revision_store.total_size(repo.get_transaction())[1] / 1024,
760
729
self.assertEqual('', err)
779
747
first revision: %s
780
748
latest revision: %s
785
752
""" % (format.get_branch_format().get_format_description(),
786
753
format.repository_format.get_format_description(),
787
754
datestring_first, datestring_last,
788
# poking at _revision_store isn't all that clean, but neither is
789
# having the ui test dependent on the exact overhead of a given store.
790
repo._revision_store.total_size(repo.get_transaction())[1] / 1024,
792
756
self.assertEqual('', err)
808
771
""" % (format.repository_format.get_format_description(),
809
# poking at _revision_store isn't all that clean, but neither is
810
# having the ui test dependent on the exact overhead of a given store.
811
repo._revision_store.total_size(repo.get_transaction())[1] / 1024,
813
773
self.assertEqual('', err)
887
844
tree1.commit('commit one')
888
845
rev = repo.get_revision(branch1.revision_history()[0])
889
datestring_first = format_date(rev.timestamp, rev.timezone)
846
datestring_first = osutils.format_date(rev.timestamp, rev.timezone)
890
847
out, err = self.run_bzr('info -v repo/branch1')
891
848
self.assertEqualDiff(
892
849
"""Repository tree (format: knit)
917
873
first revision: %s
918
874
latest revision: %s
923
878
""" % (format.get_branch_format().get_format_description(),
924
879
format.repository_format.get_format_description(),
925
880
datestring_first, datestring_first,
926
# poking at _revision_store isn't all that clean, but neither is
927
# having the ui test dependent on the exact overhead of a given store.
928
repo._revision_store.total_size(repo.get_transaction())[1] / 1024,
930
882
self.assertEqual('', err)
966
916
""" % (format.get_branch_format().get_format_description(),
967
917
format.repository_format.get_format_description(),
968
# poking at _revision_store isn't all that clean, but neither is
969
# having the ui test dependent on the exact overhead of a given store.
970
repo._revision_store.total_size(repo.get_transaction())[1] / 1024,
972
919
self.assertEqual('', err)
1007
953
first revision: %s
1008
954
latest revision: %s
1013
958
""" % (format.get_branch_format().get_format_description(),
1014
959
format.repository_format.get_format_description(),
1015
960
datestring_first, datestring_first,
1016
# poking at _revision_store isn't all that clean, but neither is
1017
# having the ui test dependent on the exact overhead of a given store.
1018
repo._revision_store.total_size(repo.get_transaction())[1] / 1024,
1020
962
self.assertEqual('', err)
1038
979
""" % (format.repository_format.get_format_description(),
1039
# poking at _revision_store isn't all that clean, but neither is
1040
# having the ui test dependent on the exact overhead of a given store.
1041
repo._revision_store.total_size(repo.get_transaction())[1] / 1024,
1044
982
self.assertEqual('', err)
1046
984
def test_info_shared_repository_with_tree_in_root(self):
1047
985
format = bzrdir.format_registry.make_bzrdir('knit')
1048
986
transport = self.get_transport()
1099
1036
Branch history:
1106
1041
""" % (format.get_branch_format().get_format_description(),
1107
1042
format.repository_format.get_format_description(),
1109
1044
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)
1111
1072
def assertCheckoutStatusOutput(self,
1112
1073
command_string, lco_tree, shared_repo=None,
1113
1074
repo_branch=None,
1123
1084
allow us, the test writers, to document what *should* be present in
1124
1085
the output. Removing this separation would remove the value of the
1127
1088
:param path: the path to the light checkout.
1128
1089
:param lco_tree: the tree object for the light checkout.
1129
1090
:param shared_repo: A shared repository is in use, expect that in
1137
1098
actually locked then this parameter is overridden. This is because
1138
1099
pack repositories do not have any public API for obtaining an
1139
1100
exclusive repository wide lock.
1140
:param verbose: If true, expect verbose output
1101
:param verbose: verbosity level: 2 or higher to show committers
1142
1103
def friendly_location(url):
1143
1104
path = urlutils.unescape_for_display(url, 'ascii')
1162
1123
(False, True): 'Lightweight checkout',
1163
1124
(False, False): 'Checkout',
1164
1125
}[(shared_repo is not None, light_checkout)]
1165
format = {True: 'dirstate or dirstate-tags or pack-0.92'
1166
' or rich-root or rich-root-pack',
1167
False: 'dirstate'}[light_checkout]
1126
format = {True: self._repo_strings,
1127
False: 'unnamed'}[light_checkout]
1168
1128
if repo_locked:
1169
1129
repo_locked = lco_tree.branch.repository.get_physical_lock_status()
1170
1130
if repo_locked or branch_locked or tree_locked:
1255
1214
transport = self.get_transport()
1256
1215
# Create shared repository with a branch
1257
1216
repo = self.make_repository('repo', shared=True,
1258
format=bzrlib.bzrdir.BzrDirMetaFormat1())
1217
format=bzrdir.BzrDirMetaFormat1())
1259
1218
repo.set_make_working_trees(False)
1260
1219
repo.bzrdir.root_transport.mkdir('branch')
1261
1220
repo_branch = repo.bzrdir.create_branch_convenience('repo/branch',
1262
format=bzrlib.bzrdir.BzrDirMetaFormat1())
1221
format=bzrdir.BzrDirMetaFormat1())
1263
1222
# Do a heavy checkout
1264
1223
transport.mkdir('tree')
1265
1224
transport.mkdir('tree/checkout')
1266
co_branch = bzrlib.bzrdir.BzrDir.create_branch_convenience('tree/checkout',
1267
format=bzrlib.bzrdir.BzrDirMetaFormat1())
1225
co_branch = bzrdir.BzrDir.create_branch_convenience('tree/checkout',
1226
format=bzrdir.BzrDirMetaFormat1())
1268
1227
co_branch.bind(repo_branch)
1269
1228
# Do a light checkout of the heavy one
1270
1229
transport.mkdir('tree/lightcheckout')
1271
lco_dir = bzrlib.bzrdir.BzrDirMetaFormat1().initialize('tree/lightcheckout')
1272
bzrlib.branch.BranchReferenceFormat().initialize(lco_dir, co_branch)
1230
lco_dir = bzrdir.BzrDirMetaFormat1().initialize('tree/lightcheckout')
1231
branch.BranchReferenceFormat().initialize(lco_dir,
1232
target_branch=co_branch)
1273
1233
lco_dir.create_workingtree()
1274
1234
lco_tree = lco_dir.open_workingtree()
1366
1326
def test_info_locking_oslocks(self):
1367
1327
if sys.platform == "win32":
1368
1328
raise TestSkipped("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()
1370
1335
tree = self.make_branch_and_tree('branch',
1371
format=bzrlib.bzrdir.BzrDirFormat6())
1336
format=bzrdir.BzrDirFormat6())
1373
1338
# Test all permutations of locking the working tree, branch and repository
1374
1339
# XXX: Well not yet, as we can't query oslocks yet. Currently, it's
1436
1399
Branch history:
1443
1404
""" % ('branch', tree.branch.repository._format.get_format_description(),
1445
1406
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)