1
# Copyright (C) 2006-2012, 2016 Canonical Ltd
1
# Copyright (C) 2006 by Canonical Ltd
2
# -*- coding: utf-8 -*-
3
4
# This program is free software; you can redistribute it and/or modify
4
5
# it under the terms of the GNU General Public License as published by
5
6
# the Free Software Foundation; either version 2 of the License, or
6
7
# (at your option) any later version.
8
9
# This program is distributed in the hope that it will be useful,
9
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
12
# GNU General Public License for more details.
13
14
# You should have received a copy of the GNU General Public License
14
15
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
19
"""Tests for the info command of bzr."""
33
from breezy.bzr import (
36
from breezy.tests.matchers import ContainsNoVfsCalls
37
from breezy.transport import memory
40
class TestInfo(tests.TestCaseWithTransport):
43
super(TestInfo, self).setUp()
44
self._repo_strings = "2a"
46
def test_info_non_existing(self):
47
self.vfs_transport_factory = memory.MemoryServer
48
location = self.get_url()
49
out, err = self.run_bzr('info ' + location, retcode=3)
50
self.assertEqual(out, '')
51
self.assertEqual(err, 'brz: ERROR: Not a branch: "%s".\n' % location)
53
def test_info_empty_controldir(self):
54
self.make_controldir('ctrl')
55
out, err = self.run_bzr('info ctrl')
57
'Empty control directory (format: 2a)\n'
59
' control directory: ctrl\n')
60
self.assertEqual(err, '')
62
def test_info_empty_controldir_verbose(self):
63
self.make_controldir('ctrl')
64
out, err = self.run_bzr('info -v ctrl')
65
self.assertEqualDiff(out,
66
'Empty control directory (format: 2a)\n'
68
' control directory: ctrl\n\n'
70
' control: Meta directory format 1\n\n'
71
'Control directory:\n'
73
self.assertEqual(err, '')
75
def test_info_dangling_branch_reference(self):
76
br = self.make_branch('target')
77
br.create_checkout('from', lightweight=True)
78
shutil.rmtree('target')
79
out, err = self.run_bzr('info from')
81
'Dangling branch reference (format: 2a)\n'
83
' control directory: from\n'
84
' checkout of branch: target\n')
85
self.assertEqual(err, '')
87
def test_info_colocated(self):
88
br = self.make_branch_and_tree('target', format='development-colo')
89
target = br.controldir.create_branch(name='dichtbij')
90
br.controldir.set_branch_reference(target)
91
out, err = self.run_bzr('info target')
93
'Standalone tree (format: development-colo)\n'
95
' light checkout root: target\n'
96
' checkout of co-located branch: dichtbij\n')
97
self.assertEqual(err, '')
25
from bzrlib.osutils import format_date
26
from bzrlib.tests import TestSkipped
27
from bzrlib.tests.blackbox import ExternalBase
30
class TestInfo(ExternalBase):
99
32
def test_info_standalone(self):
100
33
transport = self.get_transport()
102
35
# Create initial standalone branch
103
tree1 = self.make_branch_and_tree('standalone', 'knit')
36
old_format = bzrlib.bzrdir.BzrDirFormat.get_default_format()
37
bzrlib.bzrdir.BzrDirFormat.set_default_format(bzrlib.bzrdir.BzrDirFormat6())
38
tree1 = self.make_branch_and_tree('standalone')
39
bzrlib.bzrdir.BzrDirFormat.set_default_format(old_format)
104
40
self.build_tree(['standalone/a'])
106
42
branch1 = tree1.branch
108
out, err = self.run_bzr('info standalone')
109
self.assertEqualDiff(
110
"""Standalone tree (format: knit)
112
branch root: standalone
114
self.assertEqual('', err)
116
# Standalone branch - verbose mode
117
out, err = self.run_bzr('info standalone -v')
118
self.assertEqualDiff(
119
"""Standalone tree (format: knit)
121
branch root: standalone
124
control: Meta directory format 1
125
working tree: Working tree format 3
126
branch: Branch format 5
127
repository: Knit repository format 1
141
0 versioned subdirectories
149
self.assertEqual('', err)
151
# Standalone branch - really verbose mode
152
out, err = self.run_bzr('info standalone -vv')
153
self.assertEqualDiff(
154
"""Standalone tree (format: knit)
156
branch root: standalone
159
control: Meta directory format 1
160
working tree: Working tree format 3
161
branch: Branch format 5
162
repository: Knit repository format 1
176
0 versioned subdirectories
43
out, err = self.runbzr('info standalone')
49
control: All-in-one format 6
50
working tree: Working tree format 2
51
branch: Branch format 4
52
repository: Weave repository format 6
62
0 versioned subdirectories
70
""" % branch1.bzrdir.root_transport.base, out)
185
71
self.assertEqual('', err)
186
72
tree1.commit('commit one')
187
rev = branch1.repository.get_revision(branch1.last_revision())
188
datestring_first = osutils.format_date(rev.timestamp, rev.timezone)
73
rev = branch1.repository.get_revision(branch1.revision_history()[0])
74
datestring_first = format_date(rev.timestamp, rev.timezone)
190
76
# Branch standalone with push location
191
branch2 = branch1.controldir.sprout('branch').open_branch()
192
branch2.set_push_location(branch1.controldir.root_transport.base)
194
out, err = self.run_bzr('info branch')
195
self.assertEqualDiff(
196
"""Standalone tree (format: knit)
201
push branch: standalone
202
parent branch: standalone
204
self.assertEqual('', err)
206
out, err = self.run_bzr('info branch --verbose')
207
self.assertEqualDiff(
208
"""Standalone tree (format: knit)
213
push branch: standalone
214
parent branch: standalone
77
branch2 = branch1.bzrdir.sprout('branch').open_branch()
78
branch2.set_push_location(branch1.bzrdir.root_transport.base)
79
out, err = self.runbzr('info branch --verbose')
217
control: Meta directory format 1
218
working tree: Working tree format 3
219
branch: Branch format 5
220
repository: Knit repository format 1
87
control: All-in-one format 6
88
working tree: Working tree format 2
89
branch: Branch format 4
90
repository: Weave repository format 6
225
92
In the working tree:
558
421
0 versioned subdirectories
563
427
first revision: %s
564
428
latest revision: %s
568
""" % (format_description, datestring_first, datestring_last,), out)
569
self.assertEqual('', err)
571
def test_info_standalone_no_tree(self):
572
# create standalone branch without a working tree
573
format = controldir.format_registry.make_controldir('default')
574
branch = self.make_branch('branch')
575
repo = branch.repository
576
out, err = self.run_bzr('info branch -v')
577
self.assertEqualDiff(
578
"""Standalone branch (format: %s)
583
control: Meta directory format 1
595
""" % (info.describe_format(repo.controldir, repo, branch, None),
596
format.get_branch_format().get_format_description(),
597
format.repository_format.get_format_description(),
433
""" % (tree5.bzrdir.root_transport.base, branch1.bzrdir.root_transport.base,
434
datestring_first, datestring_last), out)
599
435
self.assertEqual('', err)
601
437
def test_info_shared_repository(self):
602
format = controldir.format_registry.make_controldir('knit')
438
old_format = bzrlib.bzrdir.BzrDirFormat.get_default_format()
439
bzrlib.bzrdir.BzrDirFormat.set_default_format(bzrlib.bzrdir.BzrDirMetaFormat1())
603
440
transport = self.get_transport()
605
442
# Create shared repository
606
repo = self.make_repository('repo', shared=True, format=format)
443
repo = self.make_repository('repo', shared=True)
607
444
repo.set_make_working_trees(False)
608
out, err = self.run_bzr('info -v repo')
445
out, err = self.runbzr('info repo')
609
446
self.assertEqualDiff(
610
"""Shared repository (format: dirstate or dirstate-tags or knit)
612
shared repository: %s
448
shared repository: %s
615
451
control: Meta directory format 1
623
""" % ('repo', format.repository_format.get_format_description(),
457
""" % (repo.bzrdir.root_transport.base, repo._format.get_format_description()),
625
459
self.assertEqual('', err)
627
461
# Create branch inside shared repository
628
repo.controldir.root_transport.mkdir('branch')
629
branch1 = controldir.ControlDir.create_branch_convenience(
630
'repo/branch', format=format)
631
out, err = self.run_bzr('info -v repo/branch')
462
repo.bzrdir.root_transport.mkdir('branch')
463
branch1 = repo.bzrdir.create_branch_convenience('repo/branch')
464
out, err = self.runbzr('info repo/branch')
632
465
self.assertEqualDiff(
633
"""Repository branch (format: dirstate or knit)
635
shared repository: repo
636
repository branch: repo/branch
468
shared repository: %s
639
471
control: Meta directory format 1
472
branch: Branch format 5
651
""" % (format.get_branch_format().get_format_description(),
652
format.repository_format.get_format_description(),
481
""" % (branch1.bzrdir.root_transport.base,
482
repo.bzrdir.root_transport.base,
483
repo._format.get_format_description(),
654
485
self.assertEqual('', err)
656
487
# Create lightweight checkout
657
488
transport.mkdir('tree')
658
489
transport.mkdir('tree/lightcheckout')
659
tree2 = branch1.create_checkout('tree/lightcheckout',
490
dir2 = bzrlib.bzrdir.BzrDirMetaFormat1().initialize('tree/lightcheckout')
491
bzrlib.branch.BranchReferenceFormat().initialize(dir2, branch1)
492
dir2.create_workingtree()
493
tree2 = dir2.open_workingtree()
661
494
branch2 = tree2.branch
662
self.assertCheckoutStatusOutput('-v tree/lightcheckout', tree2,
663
shared_repo=repo, repo_branch=branch1, verbose=True)
495
out, err = self.runbzr('info tree/lightcheckout')
496
self.assertEqualDiff(
499
checkout of branch: %s
500
shared repository: %s
503
control: Meta directory format 1
504
working tree: Working tree format 3
505
branch: Branch format 5
516
0 versioned subdirectories
524
""" % (tree2.bzrdir.root_transport.base,
525
branch1.bzrdir.root_transport.base,
526
repo.bzrdir.root_transport.base,
527
repo._format.get_format_description(),
529
self.assertEqual('', err)
665
531
# Create normal checkout
666
tree3 = branch1.create_checkout('tree/checkout')
667
self.assertCheckoutStatusOutput('tree/checkout --verbose', tree3,
669
light_checkout=False, repo_branch=branch1)
532
branch3 = bzrlib.bzrdir.BzrDir.create_branch_convenience('tree/checkout')
533
branch3.bind(branch1)
534
tree3 = branch3.bzrdir.open_workingtree()
536
out, err = self.runbzr('info tree/checkout --verbose')
537
self.assertEqualDiff(
543
control: Meta directory format 1
544
working tree: Working tree format 3
545
branch: Branch format 5
556
0 versioned subdirectories
565
""" % (branch3.bzrdir.root_transport.base,
566
branch1.bzrdir.root_transport.base,
567
repo._format.get_format_description(),
569
self.assertEqual('', err)
670
571
# Update lightweight checkout
671
572
self.build_tree(['tree/lightcheckout/a'])
673
574
tree2.commit('commit one')
674
rev = repo.get_revision(branch2.last_revision())
675
datestring_first = osutils.format_date(rev.timestamp, rev.timezone)
676
out, err = self.run_bzr('info tree/lightcheckout --verbose')
575
rev = repo.get_revision(branch2.revision_history()[0])
576
datestring_first = format_date(rev.timestamp, rev.timezone)
577
out, err = self.runbzr('info tree/lightcheckout --verbose')
677
578
self.assertEqualDiff(
678
"""Lightweight checkout (format: %s)
680
light checkout root: tree/lightcheckout
681
checkout of branch: repo/branch
682
shared repository: repo
581
checkout of branch: %s
582
shared repository: %s
685
585
control: Meta directory format 1
686
working tree: Working tree format 6
586
working tree: Working tree format 3
587
branch: Branch format 5
693
590
In the working tree:
702
598
0 versioned subdirectories
707
604
first revision: %s
708
605
latest revision: %s
712
""" % (self._repo_strings, format.get_branch_format().get_format_description(),
713
format.repository_format.get_format_description(),
714
datestring_first, datestring_first,
610
""" % (tree2.bzrdir.root_transport.base,
611
branch1.bzrdir.root_transport.base,
612
repo.bzrdir.root_transport.base,
613
repo._format.get_format_description(),
614
datestring_first, datestring_first,
615
# poking at _revision_store isn't all that clean, but neither is
616
# having the ui test dependent on the exact overhead of a given store.
617
repo._revision_store.total_size(repo.get_transaction())[1] / 1024,
716
619
self.assertEqual('', err)
718
621
# Out of date checkout
719
out, err = self.run_bzr('info -v tree/checkout')
622
out, err = self.runbzr('info tree/checkout')
720
623
self.assertEqualDiff(
721
"""Checkout (format: unnamed)
723
checkout root: tree/checkout
724
checkout of branch: repo/branch
727
629
control: Meta directory format 1
728
working tree: Working tree format 6
630
working tree: Working tree format 3
631
branch: Branch format 5
735
634
Branch is out of date: missing 1 revision.
737
636
In the working tree:
835
730
0 versioned subdirectories
840
736
first revision: %s
841
737
latest revision: %s
845
""" % (self._repo_strings, format.get_branch_format().get_format_description(),
846
format.repository_format.get_format_description(),
847
datestring_first, datestring_last,
742
""" % (tree2.bzrdir.root_transport.base,
743
branch1.bzrdir.root_transport.base,
744
repo.bzrdir.root_transport.base,
745
repo._format.get_format_description(),
746
datestring_first, datestring_last,
747
# poking at _revision_store isn't all that clean, but neither is
748
# having the ui test dependent on the exact overhead of a given store.
749
repo._revision_store.total_size(repo.get_transaction())[1] / 1024,
849
751
self.assertEqual('', err)
851
753
# Show info about shared branch
852
out, err = self.run_bzr('info repo/branch --verbose')
754
out, err = self.runbzr('info repo/branch --verbose')
853
755
self.assertEqualDiff(
854
"""Repository branch (format: dirstate or knit)
856
shared repository: repo
857
repository branch: repo/branch
758
shared repository: %s
860
761
control: Meta directory format 1
762
branch: Branch format 5
870
769
first revision: %s
871
770
latest revision: %s
875
""" % (format.get_branch_format().get_format_description(),
876
format.repository_format.get_format_description(),
877
datestring_first, datestring_last,
775
""" % (branch1.bzrdir.root_transport.base,
776
repo.bzrdir.root_transport.base,
777
repo._format.get_format_description(),
778
datestring_first, datestring_last,
779
# poking at _revision_store isn't all that clean, but neither is
780
# having the ui test dependent on the exact overhead of a given store.
781
repo._revision_store.total_size(repo.get_transaction())[1] / 1024,
879
783
self.assertEqual('', err)
881
785
# Show info about repository with revisions
882
out, err = self.run_bzr('info -v repo')
786
out, err = self.runbzr('info repo')
883
787
self.assertEqualDiff(
884
"""Shared repository (format: dirstate or dirstate-tags or knit)
886
shared repository: repo
789
shared repository: %s
889
792
control: Meta directory format 1
897
""" % (format.repository_format.get_format_description(),
798
""" % (repo.bzrdir.root_transport.base,
799
repo._format.get_format_description(),
800
# poking at _revision_store isn't all that clean, but neither is
801
# having the ui test dependent on the exact overhead of a given store.
802
repo._revision_store.total_size(repo.get_transaction())[1] / 1024,
899
805
self.assertEqual('', err)
807
bzrlib.bzrdir.BzrDirFormat.set_default_format(old_format)
901
809
def test_info_shared_repository_with_trees(self):
902
format = controldir.format_registry.make_controldir('knit')
810
old_format = bzrlib.bzrdir.BzrDirFormat.get_default_format()
811
bzrlib.bzrdir.BzrDirFormat.set_default_format(bzrlib.bzrdir.BzrDirMetaFormat1())
903
812
transport = self.get_transport()
905
814
# Create shared repository with working trees
906
repo = self.make_repository('repo', shared=True, format=format)
815
repo = self.make_repository('repo', shared=True)
907
816
repo.set_make_working_trees(True)
908
out, err = self.run_bzr('info -v repo')
817
out, err = self.runbzr('info repo')
909
818
self.assertEqualDiff(
910
"""Shared repository with trees (format: dirstate or dirstate-tags or knit)
912
shared repository: repo
820
shared repository: %s
915
823
control: Meta directory format 1
921
826
Create working tree for new branches inside the repository.
925
""" % (format.repository_format.get_format_description(),
831
""" % (repo.bzrdir.root_transport.base,
832
repo._format.get_format_description(),
927
834
self.assertEqual('', err)
929
836
# Create two branches
930
repo.controldir.root_transport.mkdir('branch1')
931
branch1 = controldir.ControlDir.create_branch_convenience('repo/branch1',
933
branch2 = branch1.controldir.sprout('repo/branch2').open_branch()
837
repo.bzrdir.root_transport.mkdir('branch1')
838
branch1 = repo.bzrdir.create_branch_convenience('repo/branch1')
839
branch2 = branch1.bzrdir.sprout('repo/branch2').open_branch()
935
841
# Empty first branch
936
out, err = self.run_bzr('info repo/branch1 --verbose')
842
out, err = self.runbzr('info repo/branch1 --verbose')
937
843
self.assertEqualDiff(
938
"""Repository tree (format: knit)
940
shared repository: repo
941
repository branch: repo/branch1
846
shared repository: %s
944
849
control: Meta directory format 1
945
850
working tree: Working tree format 3
851
branch: Branch format 5
952
854
In the working tree:
961
862
0 versioned subdirectories
968
""" % (format.get_branch_format().get_format_description(),
969
format.repository_format.get_format_description(),
871
""" % (branch1.bzrdir.root_transport.base,
872
repo.bzrdir.root_transport.base,
873
repo._format.get_format_description(),
971
875
self.assertEqual('', err)
973
877
# Update first branch
974
878
self.build_tree(['repo/branch1/a'])
975
tree1 = branch1.controldir.open_workingtree()
879
tree1 = branch1.bzrdir.open_workingtree()
977
881
tree1.commit('commit one')
978
rev = repo.get_revision(branch1.last_revision())
979
datestring_first = osutils.format_date(rev.timestamp, rev.timezone)
980
out, err = self.run_bzr('info -v repo/branch1')
882
rev = repo.get_revision(branch1.revision_history()[0])
883
datestring_first = format_date(rev.timestamp, rev.timezone)
884
out, err = self.runbzr('info repo/branch1')
981
885
self.assertEqualDiff(
982
"""Repository tree (format: knit)
984
shared repository: repo
985
repository branch: repo/branch1
888
shared repository: %s
988
891
control: Meta directory format 1
989
892
working tree: Working tree format 3
893
branch: Branch format 5
996
896
In the working tree:
1005
904
0 versioned subdirectories
1098
993
first revision: %s
1099
994
latest revision: %s
1103
""" % (format.get_branch_format().get_format_description(),
1104
format.repository_format.get_format_description(),
1105
datestring_first, datestring_first,
999
""" % (branch2.bzrdir.root_transport.base,
1000
repo.bzrdir.root_transport.base,
1001
branch1.bzrdir.root_transport.base,
1002
repo._format.get_format_description(),
1003
datestring_first, datestring_first,
1004
# poking at _revision_store isn't all that clean, but neither is
1005
# having the ui test dependent on the exact overhead of a given store.
1006
repo._revision_store.total_size(repo.get_transaction())[1] / 1024,
1107
1008
self.assertEqual('', err)
1109
1010
# Show info about repository with revisions
1110
out, err = self.run_bzr('info -v repo')
1011
out, err = self.runbzr('info repo')
1111
1012
self.assertEqualDiff(
1112
"""Shared repository with trees (format: dirstate or dirstate-tags or knit)
1114
shared repository: repo
1014
shared repository: %s
1117
1017
control: Meta directory format 1
1123
1020
Create working tree for new branches inside the repository.
1127
""" % (format.repository_format.get_format_description(),
1025
""" % (repo.bzrdir.root_transport.base,
1026
repo._format.get_format_description(),
1027
# poking at _revision_store isn't all that clean, but neither is
1028
# having the ui test dependent on the exact overhead of a given store.
1029
repo._revision_store.total_size(repo.get_transaction())[1] / 1024,
1130
self.assertEqual('', err)
1132
def test_info_shared_repository_with_tree_in_root(self):
1133
format = controldir.format_registry.make_controldir('knit')
1134
transport = self.get_transport()
1136
# Create shared repository with working trees
1137
repo = self.make_repository('repo', shared=True, format=format)
1138
repo.set_make_working_trees(True)
1139
out, err = self.run_bzr('info -v repo')
1140
self.assertEqualDiff(
1141
"""Shared repository with trees (format: dirstate or dirstate-tags or knit)
1143
shared repository: repo
1146
control: Meta directory format 1
1152
Create working tree for new branches inside the repository.
1156
""" % (format.repository_format.get_format_description(),
1158
self.assertEqual('', err)
1160
# Create branch in root of repository
1161
control = repo.controldir
1162
branch = control.create_branch()
1163
control.create_workingtree()
1164
out, err = self.run_bzr('info -v repo')
1165
self.assertEqualDiff(
1166
"""Repository tree (format: knit)
1168
shared repository: repo
1169
repository branch: repo
1172
control: Meta directory format 1
1173
working tree: Working tree format 3
1180
In the working tree:
1189
0 versioned subdirectories
1196
""" % (format.get_branch_format().get_format_description(),
1197
format.repository_format.get_format_description(),
1199
self.assertEqual('', err)
1201
def test_info_repository_hook(self):
1202
format = controldir.format_registry.make_controldir('knit')
1204
def repo_info(repo, stats, outf):
1205
outf.write(u"more info\n")
1206
info.hooks.install_named_hook('repository', repo_info, None)
1207
# Create shared repository with working trees
1208
repo = self.make_repository('repo', shared=True, format=format)
1209
out, err = self.run_bzr('info -v repo')
1210
self.assertEqualDiff(
1211
"""Shared repository with trees (format: dirstate or dirstate-tags or knit)
1213
shared repository: repo
1216
control: Meta directory format 1
1222
Create working tree for new branches inside the repository.
1227
""" % (format.repository_format.get_format_description(),
1229
self.assertEqual('', err)
1231
def test_info_unshared_repository_with_colocated_branches(self):
1232
format = controldir.format_registry.make_controldir('development-colo')
1233
transport = self.get_transport()
1235
# Create unshared repository
1236
repo = self.make_repository('repo', shared=False, format=format)
1237
repo.set_make_working_trees(True)
1238
repo.controldir.create_branch(name='foo')
1239
out, err = self.run_bzr('info repo')
1240
self.assertEqualDiff(
1241
"""Unshared repository with trees and colocated branches (format: development-colo)
1245
self.assertEqual('', err)
1247
def assertCheckoutStatusOutput(self,
1248
command_string, lco_tree, shared_repo=None,
1251
branch_locked=False, repo_locked=False,
1253
light_checkout=True,
1254
checkout_root=None):
1255
"""Check the output of info in a checkout.
1257
This is not quite a mirror of the info code: rather than using the
1258
tree being examined to predict output, it uses a bunch of flags which
1259
allow us, the test writers, to document what *should* be present in
1260
the output. Removing this separation would remove the value of the
1263
:param path: the path to the light checkout.
1264
:param lco_tree: the tree object for the light checkout.
1265
:param shared_repo: A shared repository is in use, expect that in
1267
:param repo_branch: A branch in a shared repository for non light
1269
:param tree_locked: If true, expect the tree to be locked.
1270
:param branch_locked: If true, expect the branch to be locked.
1271
:param repo_locked: If true, expect the repository to be locked.
1272
Note that the lco_tree.branch.repository is inspected, and if is not
1273
actually locked then this parameter is overridden. This is because
1274
pack repositories do not have any public API for obtaining an
1275
exclusive repository wide lock.
1276
:param verbose: verbosity level: 2 or higher to show committers
1278
def friendly_location(url):
1279
path = urlutils.unescape_for_display(url, 'ascii')
1281
return osutils.relpath(osutils.getcwd(), path)
1282
except errors.PathNotChild:
1286
# We expect this to fail because of locking errors.
1287
# (A write-locked file cannot be read-locked
1288
# in the different process -- either on win32 or on linux).
1289
# This should be removed when the locking errors are fixed.
1290
self.expectFailure('OS locks are exclusive '
1291
'for different processes (Bug #174055)',
1292
self.run_bzr_subprocess,
1293
'info ' + command_string)
1294
out, err = self.run_bzr('info %s' % command_string)
1296
(True, True): 'Lightweight checkout',
1297
(True, False): 'Repository checkout',
1298
(False, True): 'Lightweight checkout',
1299
(False, False): 'Checkout',
1300
}[(shared_repo is not None, light_checkout)]
1301
format = {True: self._repo_strings,
1302
False: 'unnamed'}[light_checkout]
1304
repo_locked = lco_tree.branch.repository.get_physical_lock_status()
1305
if repo_locked or branch_locked or tree_locked:
1306
def locked_message(a_bool):
1311
expected_lock_output = (
1314
" working tree: %s\n"
1316
" repository: %s\n" % (
1317
locked_message(tree_locked),
1318
locked_message(branch_locked),
1319
locked_message(repo_locked)))
1321
expected_lock_output = ''
1325
tree_data = (" light checkout root: %s\n" %
1326
friendly_location(lco_tree.controldir.root_transport.base))
1328
if lco_tree.branch.get_bound_location() is not None:
1329
tree_data += ("%s checkout root: %s\n" % (extra_space,
1330
friendly_location(lco_tree.branch.controldir.root_transport.base)))
1331
if shared_repo is not None:
1333
" checkout of branch: %s\n"
1334
" shared repository: %s\n" %
1335
(friendly_location(repo_branch.controldir.root_transport.base),
1336
friendly_location(shared_repo.controldir.root_transport.base)))
1337
elif repo_branch is not None:
1339
"%s checkout of branch: %s\n" %
1341
friendly_location(repo_branch.controldir.root_transport.base)))
1343
branch_data = (" checkout of branch: %s\n" %
1344
lco_tree.branch.controldir.root_transport.base)
1347
verbose_info = ' 0 committers\n'
1351
self.assertEqualDiff(
1356
control: Meta directory format 1
1364
In the working tree:
1373
0 versioned subdirectories
1384
lco_tree._format.get_format_description(),
1385
lco_tree.branch._format.get_format_description(),
1386
lco_tree.branch.repository._format.get_format_description(),
1387
expected_lock_output,
1390
self.assertEqual('', err)
1392
def test_info_locking(self):
1393
transport = self.get_transport()
1394
# Create shared repository with a branch
1395
repo = self.make_repository('repo', shared=True,
1396
format=bzrdir.BzrDirMetaFormat1())
1397
repo.set_make_working_trees(False)
1398
repo.controldir.root_transport.mkdir('branch')
1399
repo_branch = controldir.ControlDir.create_branch_convenience(
1400
'repo/branch', format=bzrdir.BzrDirMetaFormat1())
1401
# Do a heavy checkout
1402
transport.mkdir('tree')
1403
transport.mkdir('tree/checkout')
1404
co_branch = controldir.ControlDir.create_branch_convenience(
1405
'tree/checkout', format=bzrdir.BzrDirMetaFormat1())
1406
co_branch.bind(repo_branch)
1407
# Do a light checkout of the heavy one
1408
transport.mkdir('tree/lightcheckout')
1409
lco_dir = bzrdir.BzrDirMetaFormat1().initialize('tree/lightcheckout')
1410
lco_dir.set_branch_reference(co_branch)
1411
lco_dir.create_workingtree()
1412
lco_tree = lco_dir.open_workingtree()
1414
# Test all permutations of locking the working tree, branch and repository
1418
self.assertCheckoutStatusOutput('-v tree/lightcheckout', lco_tree,
1419
repo_branch=repo_branch,
1420
verbose=True, light_checkout=True)
1422
with lco_tree.branch.repository.lock_write():
1423
self.assertCheckoutStatusOutput('-v tree/lightcheckout',
1424
lco_tree, repo_branch=repo_branch,
1425
repo_locked=True, verbose=True, light_checkout=True)
1427
with lco_tree.branch.lock_write():
1428
self.assertCheckoutStatusOutput('-v tree/lightcheckout',
1432
repo_branch=repo_branch,
1435
with lco_tree.lock_write():
1436
self.assertCheckoutStatusOutput('-v tree/lightcheckout',
1437
lco_tree, repo_branch=repo_branch,
1443
with lco_tree.lock_write(), lco_tree.branch.repository.unlock():
1444
self.assertCheckoutStatusOutput('-v tree/lightcheckout',
1445
lco_tree, repo_branch=repo_branch,
1450
with lco_tree.lock_write(), lco_tree.branch.unlock():
1451
self.assertCheckoutStatusOutput('-v tree/lightcheckout',
1452
lco_tree, repo_branch=repo_branch,
1456
with lco_tree.lock_write(), lco_tree.branch.unlock(), \
1457
lco_tree.branch.repository.lock_write():
1458
self.assertCheckoutStatusOutput('-v tree/lightcheckout',
1459
lco_tree, repo_branch=repo_branch,
1464
with lco_tree.branch.lock_write(), lco_tree.branch.repository.unlock():
1465
self.assertCheckoutStatusOutput('-v tree/lightcheckout',
1466
lco_tree, repo_branch=repo_branch,
1470
if sys.platform == 'win32':
1471
self.knownFailure('Win32 cannot run "brz info"'
1472
' when the tree is locked.')
1474
def test_info_stacked(self):
1475
# We have a mainline
1476
trunk_tree = self.make_branch_and_tree('mainline',
1478
trunk_tree.commit('mainline')
1479
# and a branch from it which is stacked
1480
new_dir = trunk_tree.controldir.sprout('newbranch', stacked=True)
1481
out, err = self.run_bzr('info newbranch')
1483
"""Standalone tree (format: 1.6)
1485
branch root: newbranch
1488
parent branch: mainline
1489
stacked on: mainline
1491
self.assertEqual("", err)
1493
def test_info_revinfo_optional(self):
1494
tree = self.make_branch_and_tree('.')
1496
def last_revision_info(self):
1497
raise errors.UnsupportedOperation(last_revision_info, self)
1499
branch.Branch, "last_revision_info", last_revision_info)
1500
out, err = self.run_bzr('info -v .')
1502
"""Standalone tree (format: 2a)
1507
control: Meta directory format 1
1508
working tree: Working tree format 6
1509
branch: Branch format 7
1510
repository: Repository format 2a - rich roots, group compression and chk inventories
1515
In the working tree:
1524
0 versioned subdirectories
1526
self.assertEqual("", err)
1528
def test_info_shows_colocated_branches(self):
1529
bzrdir = self.make_branch('.', format='development-colo').controldir
1530
bzrdir.create_branch(name="colo1")
1531
bzrdir.create_branch(name="colo2")
1532
bzrdir.create_branch(name="colo3")
1533
out, err = self.run_bzr('info -v .')
1534
self.assertEqualDiff(
1535
"""Standalone branch (format: development-colo)
1540
control: Meta directory format 1 with support for colocated branches
1541
branch: Branch format 7
1542
repository: Repository format 2a - rich roots, group compression and chk inventories
1553
self.assertEqual("", err)
1556
class TestSmartServerInfo(tests.TestCaseWithTransport):
1558
def test_simple_branch_info(self):
1559
self.setup_smart_server_with_call_log()
1560
t = self.make_branch_and_tree('branch')
1561
self.build_tree_contents([('branch/foo', b'thecontents')])
1564
self.reset_smart_call_log()
1565
out, err = self.run_bzr(['info', self.get_url('branch')])
1566
# This figure represent the amount of work to perform this use case. It
1567
# is entirely ok to reduce this number if a test fails due to rpc_count
1568
# being too low. If rpc_count increases, more network roundtrips have
1569
# become necessary for this use case. Please do not adjust this number
1570
# upwards without agreement from bzr's network support maintainers.
1571
self.assertLength(10, self.hpss_calls)
1572
self.assertLength(1, self.hpss_connections)
1573
self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
1575
def test_verbose_branch_info(self):
1576
self.setup_smart_server_with_call_log()
1577
t = self.make_branch_and_tree('branch')
1578
self.build_tree_contents([('branch/foo', b'thecontents')])
1581
self.reset_smart_call_log()
1582
out, err = self.run_bzr(['info', '-v', self.get_url('branch')])
1583
# This figure represent the amount of work to perform this use case. It
1584
# is entirely ok to reduce this number if a test fails due to rpc_count
1585
# being too low. If rpc_count increases, more network roundtrips have
1586
# become necessary for this use case. Please do not adjust this number
1587
# upwards without agreement from bzr's network support maintainers.
1588
self.assertLength(14, self.hpss_calls)
1589
self.assertLength(1, self.hpss_connections)
1590
self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
1032
self.assertEqual('', err)
1034
bzrlib.bzrdir.BzrDirFormat.set_default_format(old_format)