213
213
ref_branch = None
214
214
if ref_branch is None or ref_branch.name:
215
215
if ref_branch is not None:
216
control_dir = ref_branch.bzrdir
216
control_dir = ref_branch.controldir
217
217
for name, branch in viewitems(control_dir.get_branches()):
218
218
yield name, branch
220
repo = ref_branch.bzrdir.find_repository()
220
repo = ref_branch.controldir.find_repository()
221
221
for branch in repo.find_branches(using=True):
222
222
name = urlutils.relative_url(repo.user_url,
223
223
branch.user_url).rstrip("/")
1501
1501
if to_dir is None:
1503
1503
# preserve whatever source format we have.
1504
to_dir = br_from.bzrdir.sprout(to_transport.base, revision_id,
1505
possible_transports=[to_transport],
1506
accelerator_tree=accelerator_tree,
1507
hardlink=hardlink, stacked=stacked,
1508
force_new_repo=standalone,
1509
create_tree_if_local=not no_tree,
1510
source_branch=br_from)
1504
to_dir = br_from.controldir.sprout(
1505
to_transport.base, revision_id,
1506
possible_transports=[to_transport],
1507
accelerator_tree=accelerator_tree, hardlink=hardlink,
1508
stacked=stacked, force_new_repo=standalone,
1509
create_tree_if_local=not no_tree, source_branch=br_from)
1511
1510
branch = to_dir.open_branch(
1512
1511
possible_transports=[
1513
br_from.bzrdir.root_transport, to_transport])
1512
br_from.controldir.root_transport, to_transport])
1514
1513
except errors.NoSuchRevision:
1515
1514
to_transport.delete_tree('.')
1516
1515
msg = gettext("The branch {0} has no revision {1}.").format(
1543
1542
# Switch to the new branch
1544
1543
wt, _ = WorkingTree.open_containing('.')
1545
_mod_switch.switch(wt.bzrdir, branch)
1544
_mod_switch.switch(wt.controldir, branch)
1546
1545
note(gettext('Switched to branch: %s'),
1547
1546
urlutils.unescape_for_display(branch.base, 'utf-8'))
1663
1662
if (osutils.abspath(to_location) ==
1664
1663
osutils.abspath(branch_location)):
1666
source.bzrdir.open_workingtree()
1665
source.controldir.open_workingtree()
1667
1666
except errors.NoWorkingTree:
1668
source.bzrdir.create_workingtree(revision_id)
1667
source.controldir.create_workingtree(revision_id)
1670
1669
source.create_checkout(to_location, revision_id, lightweight,
1671
1670
accelerator_tree, hardlink)
2071
2070
help='Specify a format for this branch. '
2072
2071
'See "help formats".',
2073
2072
lazy_registry=('breezy.controldir', 'format_registry'),
2074
converter=lambda name: controldir.format_registry.make_bzrdir(name),
2073
converter=lambda name: controldir.format_registry.make_controldir(name),
2075
2074
value_switches=True,
2076
2075
title="Branch format",
2084
2083
def run(self, location=None, format=None, append_revisions_only=False,
2085
2084
create_prefix=False, no_tree=False):
2086
2085
if format is None:
2087
format = controldir.format_registry.make_bzrdir('default')
2086
format = controldir.format_registry.make_controldir('default')
2088
2087
if location is None:
2089
2088
location = u'.'
2107
2106
to_transport.create_prefix()
2110
a_bzrdir = controldir.ControlDir.open_from_transport(to_transport)
2109
a_controldir = controldir.ControlDir.open_from_transport(to_transport)
2111
2110
except errors.NotBranchError:
2112
2111
# really a NotBzrDir error...
2113
2112
create_branch = controldir.ControlDir.create_branch_convenience
2118
2117
branch = create_branch(to_transport.base, format=format,
2119
2118
possible_transports=[to_transport],
2120
2119
force_new_tree=force_new_tree)
2121
a_bzrdir = branch.bzrdir
2120
a_controldir = branch.controldir
2123
2122
from .transport.local import LocalTransport
2124
if a_bzrdir.has_branch():
2123
if a_controldir.has_branch():
2125
2124
if (isinstance(to_transport, LocalTransport)
2126
and not a_bzrdir.has_workingtree()):
2125
and not a_controldir.has_workingtree()):
2127
2126
raise errors.BranchExistsWithoutWorkingTree(location)
2128
2127
raise errors.AlreadyBranchError(location)
2129
branch = a_bzrdir.create_branch()
2130
if not no_tree and not a_bzrdir.has_workingtree():
2131
a_bzrdir.create_workingtree()
2128
branch = a_controldir.create_branch()
2129
if not no_tree and not a_controldir.has_workingtree():
2130
a_controldir.create_workingtree()
2132
2131
if append_revisions_only:
2134
2133
branch.set_append_revisions_only(True)
2138
2137
if not is_quiet():
2139
2138
from .info import describe_layout, describe_format
2141
tree = a_bzrdir.open_workingtree(recommend_upgrade=False)
2140
tree = a_controldir.open_workingtree(recommend_upgrade=False)
2142
2141
except (errors.NoWorkingTree, errors.NotLocalUrl):
2144
2143
repository = branch.repository
2145
2144
layout = describe_layout(repository, branch, tree).lower()
2146
format = describe_format(a_bzrdir, repository, branch, tree)
2145
format = describe_format(a_controldir, repository, branch, tree)
2147
2146
self.outf.write(gettext("Created a {0} (format: {1})\n").format(
2148
2147
layout, format))
2149
2148
if repository.is_shared():
2150
2149
#XXX: maybe this can be refactored into transport.path_or_url()
2151
url = repository.bzrdir.root_transport.external_url()
2150
url = repository.controldir.root_transport.external_url()
2153
2152
url = urlutils.local_path_from_url(url)
2154
2153
except errors.InvalidURL:
2190
2189
help='Specify a format for this repository. See'
2191
2190
' "brz help formats" for details.',
2192
2191
lazy_registry=('breezy.controldir', 'format_registry'),
2193
converter=lambda name: controldir.format_registry.make_bzrdir(name),
2192
converter=lambda name: controldir.format_registry.make_controldir(name),
2194
2193
value_switches=True, title='Repository format'),
2195
2194
Option('no-trees',
2196
2195
help='Branches in the repository will default to'
2201
2200
def run(self, location, format=None, no_trees=False):
2202
2201
if format is None:
2203
format = controldir.format_registry.make_bzrdir('default')
2202
format = controldir.format_registry.make_controldir('default')
2205
2204
if location is None:
3804
3803
help='Upgrade to a specific format. See "brz help'
3805
3804
' formats" for details.',
3806
3805
lazy_registry=('breezy.controldir', 'format_registry'),
3807
converter=lambda name: controldir.format_registry.make_bzrdir(name),
3806
converter=lambda name: controldir.format_registry.make_controldir(name),
3808
3807
value_switches=True, title='Branch format'),
3809
3808
Option('clean',
3810
3809
help='Remove the backup.bzr directory if successful.'),
6238
6237
gettext('cannot create branch without source branch'))
6239
6238
to_location = lookup_new_sibling_branch(control_dir, to_location,
6240
6239
possible_transports=possible_transports)
6241
to_branch = branch.bzrdir.sprout(to_location,
6240
to_branch = branch.controldir.sprout(to_location,
6242
6241
possible_transports=possible_transports,
6243
6242
source_branch=branch).open_branch()
6459
6458
def run(self, directory=None, location=None, force=False):
6460
6459
br = open_nearby_branch(near=directory, location=location)
6461
if not force and br.bzrdir.has_workingtree():
6460
if not force and br.controldir.has_workingtree():
6463
active_branch = br.bzrdir.open_branch(name="")
6462
active_branch = br.controldir.open_branch(name="")
6464
6463
except errors.NotBranchError:
6465
6464
active_branch = None
6466
6465
if (active_branch is not None and
6467
6466
br.control_url == active_branch.control_url):
6468
6467
raise errors.BzrCommandError(
6469
6468
gettext("Branch is active. Use --force to remove it."))
6470
br.bzrdir.destroy_branch(br.name)
6469
br.controldir.destroy_branch(br.name)
6473
6472
class cmd_shelve(Command):