81
@symbol_versioning.deprecated_function(symbol_versioning.deprecated_in((2, 3, 0)))
82
def tree_files(file_list, default_branch=u'.', canonicalize=True,
84
return internal_tree_files(file_list, default_branch, canonicalize,
86
def _get_branch_location(control_dir, possible_transports=None):
87
"""Return location of branch for this control dir."""
89
target = control_dir.get_branch_reference()
90
except errors.NotBranchError:
91
return control_dir.root_transport.base
92
if target is not None:
94
this_branch = control_dir.open_branch(
95
possible_transports=possible_transports)
96
# This may be a heavy checkout, where we want the master branch
97
master_location = this_branch.get_bound_location()
98
if master_location is not None:
99
return master_location
100
# If not, use a local sibling
101
return this_branch.base
104
def _is_colocated(control_dir, possible_transports=None):
105
"""Check if the branch in control_dir is colocated.
107
:param control_dir: Control directory
108
:return: Tuple with boolean indicating whether the branch is colocated
109
and the full URL to the actual branch
111
# This path is meant to be relative to the existing branch
112
this_url = _get_branch_location(control_dir,
113
possible_transports=possible_transports)
114
# Perhaps the target control dir supports colocated branches?
116
root = controldir.ControlDir.open(this_url,
117
possible_transports=possible_transports)
118
except errors.NotBranchError:
119
return (False, this_url)
122
wt = control_dir.open_workingtree()
123
except (errors.NoWorkingTree, errors.NotLocalUrl):
124
return (False, this_url)
127
root._format.colocated_branches and
128
control_dir.control_url == root.control_url,
132
def lookup_new_sibling_branch(control_dir, location, possible_transports=None):
133
"""Lookup the location for a new sibling branch.
135
:param control_dir: Control directory to find sibling branches from
136
:param location: Name of the new branch
137
:return: Full location to the new branch
139
location = directory_service.directories.dereference(location)
140
if '/' not in location and '\\' not in location:
141
(colocated, this_url) = _is_colocated(control_dir, possible_transports)
144
return urlutils.join_segment_parameters(this_url,
145
{"branch": urlutils.escape(location)})
147
return urlutils.join(this_url, '..', urlutils.escape(location))
151
def open_sibling_branch(control_dir, location, possible_transports=None):
152
"""Open a branch, possibly a sibling of another.
154
:param control_dir: Control directory relative to which to lookup the
156
:param location: Location to look up
157
:return: branch to open
160
# Perhaps it's a colocated branch?
161
return control_dir.open_branch(location,
162
possible_transports=possible_transports)
163
except (errors.NotBranchError, errors.NoColocatedBranchSupport):
164
this_url = _get_branch_location(control_dir)
167
this_url, '..', urlutils.escape(location)))
170
def open_nearby_branch(near=None, location=None, possible_transports=None):
171
"""Open a nearby branch.
173
:param near: Optional location of container from which to open branch
174
:param location: Location of the branch
175
:return: Branch instance
181
return Branch.open(location,
182
possible_transports=possible_transports)
183
except errors.NotBranchError:
185
cdir = controldir.ControlDir.open(near,
186
possible_transports=possible_transports)
187
return open_sibling_branch(cdir, location,
188
possible_transports=possible_transports)
191
def iter_sibling_branches(control_dir, possible_transports=None):
192
"""Iterate over the siblings of a branch.
194
:param control_dir: Control directory for which to look up the siblings
195
:return: Iterator over tuples with branch name and branch object
199
reference = control_dir.get_branch_reference()
200
except errors.NotBranchError:
201
# There is no active branch, just return the colocated branches.
202
for name, branch in control_dir.get_branches().iteritems():
205
if reference is not None:
206
ref_branch = Branch.open(reference,
207
possible_transports=possible_transports)
210
if ref_branch is None or ref_branch.name:
211
if ref_branch is not None:
212
control_dir = ref_branch.bzrdir
213
for name, branch in control_dir.get_branches().iteritems():
216
repo = ref_branch.bzrdir.find_repository()
217
for branch in repo.find_branches(using=True):
218
name = urlutils.relative_url(repo.user_url,
219
branch.user_url).rstrip("/")
88
223
def tree_files_for_add(file_list):
153
# XXX: Bad function name; should possibly also be a class method of
154
# WorkingTree rather than a function.
155
@symbol_versioning.deprecated_function(symbol_versioning.deprecated_in((2, 3, 0)))
156
def internal_tree_files(file_list, default_branch=u'.', canonicalize=True,
158
"""Convert command-line paths to a WorkingTree and relative paths.
160
Deprecated: use WorkingTree.open_containing_paths instead.
162
This is typically used for command-line processors that take one or
163
more filenames, and infer the workingtree that contains them.
165
The filenames given are not required to exist.
167
:param file_list: Filenames to convert.
169
:param default_branch: Fallback tree path to use if file_list is empty or
172
:param apply_view: if True and a view is set, apply it or check that
173
specified files are within it
175
:return: workingtree, [relative_paths]
177
return WorkingTree.open_containing_paths(
178
file_list, default_directory='.',
183
288
def _get_view_info_for_change_reporter(tree):
184
289
"""Get the view information from a tree for change reporting."""
556
661
_see_also = ['info']
557
662
takes_args = ['location?']
558
663
takes_options = [
559
Option('tree', help='Show revno of working tree'),
664
Option('tree', help='Show revno of working tree.'),
563
def run(self, tree=False, location=u'.'):
669
def run(self, tree=False, location=u'.', revision=None):
670
if revision is not None and tree:
671
raise errors.BzrCommandError(gettext("--tree and --revision can "
672
"not be used together"))
566
676
wt = WorkingTree.open_containing(location)[0]
567
677
self.add_cleanup(wt.lock_read().unlock)
568
678
except (errors.NoWorkingTree, errors.NotLocalUrl):
569
679
raise errors.NoWorkingTree(location)
570
681
revid = wt.last_revision()
572
revno_t = wt.branch.revision_id_to_dotted_revno(revid)
573
except errors.NoSuchRevision:
575
revno = ".".join(str(n) for n in revno_t)
577
683
b = Branch.open_containing(location)[0]
578
684
self.add_cleanup(b.lock_read().unlock)
686
if len(revision) != 1:
687
raise errors.BzrCommandError(gettext(
688
"Revision numbers only make sense for single "
689
"revisions, not ranges"))
690
revid = revision[0].as_revision_id(b)
692
revid = b.last_revision()
694
revno_t = b.revision_id_to_dotted_revno(revid)
695
except errors.NoSuchRevision:
697
revno = ".".join(str(n) for n in revno_t)
580
698
self.cleanup_now()
581
self.outf.write(str(revno) + '\n')
699
self.outf.write(revno + '\n')
584
702
class cmd_revision_info(Command):
740
859
takes_args = ['dir+']
863
help='No error if existing, make parent directories as needed.',
741
867
encoding_type = 'replace'
743
def run(self, dir_list):
745
wt, dd = WorkingTree.open_containing(d)
746
base = os.path.dirname(dd)
747
id = wt.path2id(base)
751
self.outf.write(gettext('added %s\n') % d)
870
def add_file_with_parents(cls, wt, relpath):
871
if wt.path2id(relpath) is not None:
873
cls.add_file_with_parents(wt, osutils.dirname(relpath))
877
def add_file_single(cls, wt, relpath):
880
def run(self, dir_list, parents=False):
882
add_file = self.add_file_with_parents
884
add_file = self.add_file_single
886
wt, relpath = WorkingTree.open_containing(dir)
891
if e.errno != errno.EEXIST:
753
raise errors.NotVersionedError(path=base)
895
add_file(wt, relpath)
897
self.outf.write(gettext('added %s\n') % dir)
756
900
class cmd_relpath(Command):
1156
1322
def run(self, location=None, remember=None, overwrite=False,
1157
1323
create_prefix=False, verbose=False, revision=None,
1158
1324
use_existing_dir=False, directory=None, stacked_on=None,
1159
stacked=False, strict=None, no_tree=False):
1325
stacked=False, strict=None, no_tree=False,
1326
overwrite_tags=False):
1160
1327
from bzrlib.push import _show_push_branch
1330
overwrite = ["history", "tags"]
1331
elif overwrite_tags:
1332
overwrite = ["tags"]
1162
1336
if directory is None:
1163
1337
directory = '.'
1164
1338
# Get the source branch
1165
1339
(tree, br_from,
1166
_unused) = bzrdir.BzrDir.open_containing_tree_or_branch(directory)
1340
_unused) = controldir.ControlDir.open_containing_tree_or_branch(directory)
1167
1341
# Get the tip's revision_id
1168
1342
revision = _get_one_revision('push', revision)
1169
1343
if revision is not None:
1303
1493
except errors.NoSuchFile:
1304
1494
raise errors.BzrCommandError(gettext('Parent of "%s" does not exist.')
1307
# preserve whatever source format we have.
1308
dir = br_from.bzrdir.sprout(to_transport.base, revision_id,
1309
possible_transports=[to_transport],
1310
accelerator_tree=accelerator_tree,
1311
hardlink=hardlink, stacked=stacked,
1312
force_new_repo=standalone,
1313
create_tree_if_local=not no_tree,
1314
source_branch=br_from)
1315
branch = dir.open_branch()
1316
except errors.NoSuchRevision:
1317
to_transport.delete_tree('.')
1318
msg = gettext("The branch {0} has no revision {1}.").format(
1319
from_location, revision)
1320
raise errors.BzrCommandError(msg)
1500
# preserve whatever source format we have.
1501
to_dir = br_from.bzrdir.sprout(to_transport.base, revision_id,
1502
possible_transports=[to_transport],
1503
accelerator_tree=accelerator_tree,
1504
hardlink=hardlink, stacked=stacked,
1505
force_new_repo=standalone,
1506
create_tree_if_local=not no_tree,
1507
source_branch=br_from)
1508
branch = to_dir.open_branch(
1509
possible_transports=[
1510
br_from.bzrdir.root_transport, to_transport])
1511
except errors.NoSuchRevision:
1512
to_transport.delete_tree('.')
1513
msg = gettext("The branch {0} has no revision {1}.").format(
1514
from_location, revision)
1515
raise errors.BzrCommandError(msg)
1518
to_repo = to_dir.open_repository()
1519
except errors.NoRepositoryPresent:
1520
to_repo = to_dir.create_repository()
1521
to_repo.fetch(br_from.repository, revision_id=revision_id)
1522
branch = br_from.sprout(to_dir, revision_id=revision_id)
1321
1523
_merge_tags_if_possible(br_from, branch)
1322
1524
# If the source branch is stacked, the new branch may
1323
1525
# be stacked whether we asked for that explicitly or not.
1360
1562
if not t.listable():
1361
1563
raise errors.BzrCommandError(
1362
1564
"Can't scan this type of location.")
1363
for b in bzrdir.BzrDir.find_branches(t):
1565
for b in controldir.ControlDir.find_branches(t):
1364
1566
self.outf.write("%s\n" % urlutils.unescape_for_display(
1365
1567
urlutils.relative_url(t.base, b.base),
1366
1568
self.outf.encoding).rstrip("/"))
1368
dir = bzrdir.BzrDir.open_containing(location)[0]
1369
for branch in dir.list_branches():
1370
if branch.name is None:
1371
self.outf.write(gettext(" (default)\n"))
1570
dir = controldir.ControlDir.open_containing(location)[0]
1572
active_branch = dir.open_branch(name="")
1573
except errors.NotBranchError:
1574
active_branch = None
1576
for name, branch in iter_sibling_branches(dir):
1579
active = (active_branch is not None and
1580
active_branch.base == branch.base)
1581
names[name] = active
1582
# Only mention the current branch explicitly if it's not
1583
# one of the colocated branches
1584
if not any(names.values()) and active_branch is not None:
1585
self.outf.write("* %s\n" % gettext("(default)"))
1586
for name in sorted(names.keys()):
1587
active = names[name]
1373
self.outf.write(" %s\n" % branch.name.encode(
1374
self.outf.encoding))
1592
self.outf.write("%s %s\n" % (
1593
prefix, name.encode(self.outf.encoding)))
1377
1596
class cmd_checkout(Command):
1481
1698
class cmd_update(Command):
1482
__doc__ = """Update a tree to have the latest code committed to its branch.
1484
This will perform a merge into the working tree, and may generate
1485
conflicts. If you have any local changes, you will still
1486
need to commit them after the update for the update to be complete.
1488
If you want to discard your local changes, you can just do a
1489
'bzr revert' instead of 'bzr commit' after the update.
1491
If you want to restore a file that has been removed locally, use
1492
'bzr revert' instead of 'bzr update'.
1494
If the tree's branch is bound to a master branch, it will also update
1699
__doc__ = """Update a working tree to a new revision.
1701
This will perform a merge of the destination revision (the tip of the
1702
branch, or the specified revision) into the working tree, and then make
1703
that revision the basis revision for the working tree.
1705
You can use this to visit an older revision, or to update a working tree
1706
that is out of date from its branch.
1708
If there are any uncommitted changes in the tree, they will be carried
1709
across and remain as uncommitted changes after the update. To discard
1710
these changes, use 'bzr revert'. The uncommitted changes may conflict
1711
with the changes brought in by the change in basis revision.
1713
If the tree's branch is bound to a master branch, bzr will also update
1495
1714
the branch from the master.
1716
You cannot update just a single file or directory, because each Bazaar
1717
working tree has just a single basis revision. If you want to restore a
1718
file that has been removed locally, use 'bzr revert' instead of 'bzr
1719
update'. If you want to restore a file to its state in a previous
1720
revision, use 'bzr revert' with a '-r' option, or use 'bzr cat' to write
1721
out the old content of that file to a new location.
1723
The 'dir' argument, if given, must be the location of the root of a
1724
working tree to update. By default, the working tree that contains the
1725
current working directory is used.
1498
1728
_see_also = ['pull', 'working-trees', 'status-flags']
1632
1870
title='Deletion Strategy', value_switches=True, enum_switch=False,
1633
1871
safe='Backup changed files (default).',
1634
1872
keep='Delete from bzr but leave the working copy.',
1635
no_backup='Don\'t backup changed files.',
1636
force='Delete all the specified files, even if they can not be '
1637
'recovered and even if they are non-empty directories. '
1638
'(deprecated, use no-backup)')]
1873
no_backup='Don\'t backup changed files.'),
1639
1875
aliases = ['rm', 'del']
1640
1876
encoding_type = 'replace'
1642
1878
def run(self, file_list, verbose=False, new=False,
1643
1879
file_deletion_strategy='safe'):
1644
if file_deletion_strategy == 'force':
1645
note(gettext("(The --force option is deprecated, rather use --no-backup "
1647
file_deletion_strategy = 'no-backup'
1649
1881
tree, file_list = WorkingTree.open_containing_paths(file_list)
1961
2197
def run(self, location, format=None, no_trees=False):
1962
2198
if format is None:
1963
format = bzrdir.format_registry.make_bzrdir('default')
2199
format = controldir.format_registry.make_bzrdir('default')
1965
2201
if location is None:
1968
2204
to_transport = transport.get_transport(location)
1969
to_transport.ensure_base()
1971
newdir = format.initialize_on_transport(to_transport)
1972
repo = newdir.create_repository(shared=True)
1973
repo.set_make_working_trees(not no_trees)
2206
(repo, newdir, require_stacking, repository_policy) = (
2207
format.initialize_on_transport_ex(to_transport,
2208
create_prefix=True, make_working_trees=not no_trees,
2209
shared_repo=True, force_new_repo=True,
2210
use_existing_dir=True,
2211
repo_format_name=format.repository_format.get_format_string()))
1974
2212
if not is_quiet():
1975
2213
from bzrlib.info import show_bzrdir_info
1976
show_bzrdir_info(repo.bzrdir, verbose=0, outfile=self.outf)
2214
show_bzrdir_info(newdir, verbose=0, outfile=self.outf)
1979
2217
class cmd_diff(Command):
3081
3323
Option('per-file-timestamps',
3082
3324
help='Set modification time of files to that of the last '
3083
3325
'revision in which it was changed.'),
3326
Option('uncommitted',
3327
help='Export the working tree contents rather than that of the '
3085
3330
def run(self, dest, branch_or_subdir=None, revision=None, format=None,
3086
root=None, filters=False, per_file_timestamps=False, directory=u'.'):
3331
root=None, filters=False, per_file_timestamps=False, uncommitted=False,
3087
3333
from bzrlib.export import export
3089
3335
if branch_or_subdir is None:
3090
tree = WorkingTree.open_containing(directory)[0]
3336
branch_or_subdir = directory
3338
(tree, b, subdir) = controldir.ControlDir.open_containing_tree_or_branch(
3340
if tree is not None:
3341
self.add_cleanup(tree.lock_read().unlock)
3345
raise errors.BzrCommandError(
3346
gettext("--uncommitted requires a working tree"))
3094
b, subdir = Branch.open_containing(branch_or_subdir)
3097
rev_tree = _get_one_revision_tree('export', revision, branch=b, tree=tree)
3349
export_tree = _get_one_revision_tree('export', revision, branch=b, tree=tree)
3099
export(rev_tree, dest, format, root, subdir, filtered=filters,
3351
export(export_tree, dest, format, root, subdir, filtered=filters,
3100
3352
per_file_timestamps=per_file_timestamps)
3101
3353
except errors.NoSuchExportFormat, e:
3102
raise errors.BzrCommandError(gettext('Unsupported export format: %s') % e.format)
3354
raise errors.BzrCommandError(
3355
gettext('Unsupported export format: %s') % e.format)
3105
3358
class cmd_cat(Command):
3633
3888
# use global config unless --branch given
3635
3890
if directory is None:
3636
c = Branch.open_containing(u'.')[0].get_config()
3891
c = Branch.open_containing(u'.')[0].get_config_stack()
3638
c = Branch.open(directory).get_config()
3893
b = Branch.open(directory)
3894
self.add_cleanup(b.lock_write().unlock)
3895
c = b.get_config_stack()
3640
c = _mod_config.GlobalConfig()
3641
c.set_user_option('email', name)
3897
c = _mod_config.GlobalStack()
3898
c.set('email', name)
3644
3901
class cmd_nick(Command):
3645
3902
__doc__ = """Print or set the branch nickname.
3647
If unset, the tree root directory name is used as the nickname.
3648
To print the current nickname, execute with no argument.
3904
If unset, the colocated branch name is used for colocated branches, and
3905
the branch directory name is used for other branches. To print the
3906
current nickname, execute with no argument.
3650
3908
Bound branches use the nickname of its master branch unless it is set
4479
4747
class cmd_revert(Command):
4480
__doc__ = """Revert files to a previous revision.
4749
Set files in the working tree back to the contents of a previous revision.
4482
4751
Giving a list of files will revert only those files. Otherwise, all files
4483
4752
will be reverted. If the revision is not specified with '--revision', the
4484
last committed revision is used.
4753
working tree basis revision is used. A revert operation affects only the
4754
working tree, not any revision history like the branch and repository or
4755
the working tree basis revision.
4486
4757
To remove only some changes, without reverting to a prior version, use
4487
4758
merge instead. For example, "merge . -r -2..-3" (don't forget the ".")
4488
4759
will remove the changes introduced by the second last commit (-2), without
4489
4760
affecting the changes introduced by the last commit (-1). To remove
4490
4761
certain changes on a hunk-by-hunk basis, see the shelve command.
4762
To update the branch to a specific revision or the latest revision and
4763
update the working tree accordingly while preserving local changes, see the
4492
By default, any files that have been manually changed will be backed up
4493
first. (Files changed only by merge are not backed up.) Backup files have
4494
'.~#~' appended to their name, where # is a number.
4766
Uncommitted changes to files that are reverted will be discarded.
4767
Howver, by default, any files that have been manually changed will be
4768
backed up first. (Files changed only by merge are not backed up.) Backup
4769
files have '.~#~' appended to their name, where # is a number.
4496
4771
When you provide files, you can use their current pathname or the pathname
4497
4772
from the target revision. So you can use revert to "undelete" a file by
5259
5545
help='Override the default idle client timeout (5min).'),
5262
def get_host_and_port(self, port):
5263
"""Return the host and port to run the smart server on.
5265
If 'port' is None, None will be returned for the host and port.
5267
If 'port' has a colon in it, the string before the colon will be
5268
interpreted as the host.
5270
:param port: A string of the port to run the server on.
5271
:return: A tuple of (host, port), where 'host' is a host name or IP,
5272
and port is an integer TCP/IP port.
5275
if port is not None:
5277
host, port = port.split(':')
5281
def run(self, port=None, inet=False, directory=None, allow_writes=False,
5282
protocol=None, client_timeout=None):
5548
def run(self, listen=None, port=None, inet=False, directory=None,
5549
allow_writes=False, protocol=None, client_timeout=None):
5283
5550
from bzrlib import transport
5284
5551
if directory is None:
5285
5552
directory = os.getcwd()
5286
5553
if protocol is None:
5287
5554
protocol = transport.transport_server_registry.get()
5288
host, port = self.get_host_and_port(port)
5289
url = urlutils.local_path_to_url(directory)
5555
url = transport.location_to_url(directory)
5290
5556
if not allow_writes:
5291
5557
url = 'readonly+' + url
5292
t = transport.get_transport(url)
5294
protocol(t, host, port, inet, client_timeout)
5295
except TypeError, e:
5296
# We use symbol_versioning.deprecated_in just so that people
5297
# grepping can find it here.
5298
# symbol_versioning.deprecated_in((2, 5, 0))
5299
symbol_versioning.warn(
5300
'Got TypeError(%s)\ntrying to call protocol: %s.%s\n'
5301
'Most likely it needs to be updated to support a'
5302
' "timeout" parameter (added in bzr 2.5.0)'
5303
% (e, protocol.__module__, protocol),
5305
protocol(t, host, port, inet)
5558
t = transport.get_transport_from_url(url)
5559
protocol(t, listen, port, inet, client_timeout)
5308
5562
class cmd_join(Command):
5976
6232
Option('create-branch', short_name='b',
5977
6233
help='Create the target branch from this one before'
5978
6234
' switching to it.'),
6236
help='Store and restore uncommitted changes in the'
5981
6240
def run(self, to_location=None, force=False, create_branch=False,
5982
revision=None, directory=u'.'):
6241
revision=None, directory=u'.', store=False):
5983
6242
from bzrlib import switch
5984
6243
tree_location = directory
5985
6244
revision = _get_one_revision('switch', revision)
5986
control_dir = bzrdir.BzrDir.open_containing(tree_location)[0]
6245
possible_transports = []
6246
control_dir = controldir.ControlDir.open_containing(tree_location,
6247
possible_transports=possible_transports)[0]
5987
6248
if to_location is None:
5988
6249
if revision is None:
5989
6250
raise errors.BzrCommandError(gettext('You must supply either a'
5990
6251
' revision or a location'))
5991
6252
to_location = tree_location
5993
branch = control_dir.open_branch()
6254
branch = control_dir.open_branch(
6255
possible_transports=possible_transports)
5994
6256
had_explicit_nick = branch.get_config().has_explicit_nickname()
5995
6257
except errors.NotBranchError:
5997
6259
had_explicit_nick = False
5998
6260
if create_branch:
5999
6261
if branch is None:
6000
raise errors.BzrCommandError(gettext('cannot create branch without'
6002
to_location = directory_service.directories.dereference(
6004
if '/' not in to_location and '\\' not in to_location:
6005
# This path is meant to be relative to the existing branch
6006
this_url = self._get_branch_location(control_dir)
6007
to_location = urlutils.join(this_url, '..', to_location)
6262
raise errors.BzrCommandError(
6263
gettext('cannot create branch without source branch'))
6264
to_location = lookup_new_sibling_branch(control_dir, to_location,
6265
possible_transports=possible_transports)
6008
6266
to_branch = branch.bzrdir.sprout(to_location,
6009
possible_transports=[branch.bzrdir.root_transport],
6010
source_branch=branch).open_branch()
6267
possible_transports=possible_transports,
6268
source_branch=branch).open_branch()
6013
to_branch = Branch.open(to_location)
6271
to_branch = Branch.open(to_location,
6272
possible_transports=possible_transports)
6014
6273
except errors.NotBranchError:
6015
this_url = self._get_branch_location(control_dir)
6016
to_branch = Branch.open(
6017
urlutils.join(this_url, '..', to_location))
6274
to_branch = open_sibling_branch(control_dir, to_location,
6275
possible_transports=possible_transports)
6018
6276
if revision is not None:
6019
6277
revision = revision.as_revision_id(to_branch)
6020
switch.switch(control_dir, to_branch, force, revision_id=revision)
6278
switch.switch(control_dir, to_branch, force, revision_id=revision,
6279
store_uncommitted=store)
6021
6280
if had_explicit_nick:
6022
6281
branch = control_dir.open_branch() #get the new branch!
6023
6282
branch.nick = to_branch.nick
6024
6283
note(gettext('Switched to branch: %s'),
6025
6284
urlutils.unescape_for_display(to_branch.base, 'utf-8'))
6027
def _get_branch_location(self, control_dir):
6028
"""Return location of branch for this control dir."""
6030
this_branch = control_dir.open_branch()
6031
# This may be a heavy checkout, where we want the master branch
6032
master_location = this_branch.get_bound_location()
6033
if master_location is not None:
6034
return master_location
6035
# If not, use a local sibling
6036
return this_branch.base
6037
except errors.NotBranchError:
6038
format = control_dir.find_branch_format()
6039
if getattr(format, 'get_reference', None) is not None:
6040
return format.get_reference(control_dir)
6042
return control_dir.root_transport.base
6045
6288
class cmd_view(Command):
6234
6477
takes_args = ["location?"]
6479
takes_options = ['directory',
6480
Option('force', help='Remove branch even if it is the active branch.')]
6236
6482
aliases = ["rmbranch"]
6238
def run(self, location=None):
6239
if location is None:
6241
branch = Branch.open_containing(location)[0]
6242
branch.bzrdir.destroy_branch()
6484
def run(self, directory=None, location=None, force=False):
6485
br = open_nearby_branch(near=directory, location=location)
6486
if not force and br.bzrdir.has_workingtree():
6488
active_branch = br.bzrdir.open_branch(name="")
6489
except errors.NotBranchError:
6490
active_branch = None
6491
if (active_branch is not None and
6492
br.control_url == active_branch.control_url):
6493
raise errors.BzrCommandError(
6494
gettext("Branch is active. Use --force to remove it."))
6495
br.bzrdir.destroy_branch(br.name)
6245
6498
class cmd_shelve(Command):
6466
6727
('cmd_version_info', [], 'bzrlib.cmd_version_info'),
6467
6728
('cmd_resolve', ['resolved'], 'bzrlib.conflicts'),
6468
6729
('cmd_conflicts', [], 'bzrlib.conflicts'),
6730
('cmd_ping', [], 'bzrlib.smart.ping'),
6469
6731
('cmd_sign_my_commits', [], 'bzrlib.commit_signature_commands'),
6470
('cmd_verify_signatures', [],
6471
'bzrlib.commit_signature_commands'),
6732
('cmd_verify_signatures', [], 'bzrlib.commit_signature_commands'),
6472
6733
('cmd_test_script', [], 'bzrlib.cmd_test_script'),
6474
6735
builtin_command_registry.register_lazy(name, aliases, module_name)