86
def _get_branch_location(control_dir):
87
"""Return location of branch for this control dir."""
89
this_branch = control_dir.open_branch()
90
# This may be a heavy checkout, where we want the master branch
91
master_location = this_branch.get_bound_location()
92
if master_location is not None:
93
return master_location
94
# If not, use a local sibling
95
return this_branch.base
96
except errors.NotBranchError:
97
format = control_dir.find_branch_format()
98
if getattr(format, 'get_reference', None) is not None:
99
return format.get_reference(control_dir)
101
return control_dir.root_transport.base
104
def lookup_new_sibling_branch(control_dir, location):
105
"""Lookup the location for a new sibling branch.
107
:param control_dir: Control directory relative to which to look up
109
:param location: Name of the new branch
110
:return: Full location to the new branch
112
location = directory_service.directories.dereference(location)
113
if '/' not in location and '\\' not in location:
114
# This path is meant to be relative to the existing branch
115
this_url = _get_branch_location(control_dir)
116
# Perhaps the target control dir supports colocated branches?
118
root = controldir.ControlDir.open(this_url,
119
possible_transports=[control_dir.user_transport])
120
except errors.NotBranchError:
123
colocated = root._format.colocated_branches
126
return urlutils.join_segment_parameters(this_url,
127
{"branch": urlutils.escape(location)})
129
return urlutils.join(this_url, '..', urlutils.escape(location))
133
def lookup_sibling_branch(control_dir, location):
134
"""Lookup sibling branch.
136
:param control_dir: Control directory relative to which to lookup the
138
:param location: Location to look up
139
:return: branch to open
142
# Perhaps it's a colocated branch?
143
return control_dir.open_branch(location)
144
except (errors.NotBranchError, errors.NoColocatedBranchSupport):
146
return Branch.open(location)
147
except errors.NotBranchError:
148
this_url = _get_branch_location(control_dir)
151
this_url, '..', urlutils.escape(location)))
86
154
@symbol_versioning.deprecated_function(symbol_versioning.deprecated_in((2, 3, 0)))
87
155
def tree_files(file_list, default_branch=u'.', canonicalize=True,
1393
1461
from_location, revision)
1394
1462
raise errors.BzrCommandError(msg)
1465
to_repo = to_dir.open_repository()
1466
except errors.NoRepositoryPresent:
1467
to_repo = to_dir.create_repository()
1468
to_repo.fetch(br_from.repository, revision_id=revision_id)
1396
1469
branch = br_from.sprout(to_dir, revision_id=revision_id)
1397
1470
_merge_tags_if_possible(br_from, branch)
1398
1471
# If the source branch is stacked, the new branch may
1444
1517
dir = controldir.ControlDir.open_containing(location)[0]
1446
active_branch = dir.open_branch(name=None)
1519
active_branch = dir.open_branch(name="")
1447
1520
except errors.NotBranchError:
1448
1521
active_branch = None
1449
1522
branches = dir.get_branches()
1451
1524
for name, branch in branches.iteritems():
1454
1527
active = (active_branch is not None and
1455
1528
active_branch.base == branch.base)
6141
6214
had_explicit_nick = False
6142
6215
if create_branch:
6143
6216
if branch is None:
6144
raise errors.BzrCommandError(gettext('cannot create branch without'
6146
to_location = directory_service.directories.dereference(
6148
if '/' not in to_location and '\\' not in to_location:
6149
# This path is meant to be relative to the existing branch
6150
this_url = self._get_branch_location(control_dir)
6151
# Perhaps the target control dir supports colocated branches?
6153
root = controldir.ControlDir.open(this_url,
6154
possible_transports=[control_dir.user_transport])
6155
except errors.NotBranchError:
6158
colocated = root._format.colocated_branches
6160
to_location = urlutils.join_segment_parameters(this_url,
6161
{"branch": urlutils.escape(to_location)})
6163
to_location = urlutils.join(
6164
this_url, '..', urlutils.escape(to_location))
6217
raise errors.BzrCommandError(
6218
gettext('cannot create branch without source branch'))
6219
to_location = lookup_new_sibling_branch(control_dir, to_location)
6165
6220
to_branch = branch.bzrdir.sprout(to_location,
6166
possible_transports=[branch.bzrdir.root_transport],
6167
source_branch=branch).open_branch()
6221
possible_transports=[branch.bzrdir.root_transport],
6222
source_branch=branch).open_branch()
6169
# Perhaps it's a colocated branch?
6171
to_branch = control_dir.open_branch(to_location)
6172
except (errors.NotBranchError, errors.NoColocatedBranchSupport):
6174
to_branch = Branch.open(to_location)
6175
except errors.NotBranchError:
6176
this_url = self._get_branch_location(control_dir)
6177
to_branch = Branch.open(
6179
this_url, '..', urlutils.escape(to_location)))
6224
to_branch = lookup_sibling_branch(control_dir, to_location)
6180
6225
if revision is not None:
6181
6226
revision = revision.as_revision_id(to_branch)
6182
6227
switch.switch(control_dir, to_branch, force, revision_id=revision)
6186
6231
note(gettext('Switched to branch: %s'),
6187
6232
urlutils.unescape_for_display(to_branch.base, 'utf-8'))
6189
def _get_branch_location(self, control_dir):
6190
"""Return location of branch for this control dir."""
6192
this_branch = control_dir.open_branch()
6193
# This may be a heavy checkout, where we want the master branch
6194
master_location = this_branch.get_bound_location()
6195
if master_location is not None:
6196
return master_location
6197
# If not, use a local sibling
6198
return this_branch.base
6199
except errors.NotBranchError:
6200
format = control_dir.find_branch_format()
6201
if getattr(format, 'get_reference', None) is not None:
6202
return format.get_reference(control_dir)
6204
return control_dir.root_transport.base
6207
6236
class cmd_view(Command):