606
609
custom_help('directory',
607
610
help='Branch to examine, '
608
611
'rather than the one containing the working directory.'),
609
Option('tree', help='Show revno of working tree'),
612
Option('tree', help='Show revno of working tree.'),
755
758
takes_args = ['dir+']
762
help='No error if existing, make parent directories as needed.',
756
766
encoding_type = 'replace'
758
def run(self, dir_list):
760
wt, dd = WorkingTree.open_containing(d)
761
base = os.path.dirname(dd)
762
id = wt.path2id(base)
767
self.outf.write(gettext('added %s\n') % d)
769
def add_file_with_parents(cls, wt, relpath):
770
if wt.path2id(relpath) is not None:
772
cls.add_file_with_parents(wt, osutils.dirname(relpath))
776
def add_file_single(cls, wt, relpath):
779
def run(self, dir_list, parents=False):
781
add_file = self.add_file_with_parents
783
add_file = self.add_file_single
785
wt, relpath = WorkingTree.open_containing(dir)
790
if e.errno != errno.EEXIST:
769
raise errors.NotVersionedError(path=base)
794
add_file(wt, relpath)
796
self.outf.write(gettext('added %s\n') % dir)
772
799
class cmd_relpath(Command):
1224
1251
if location is None:
1225
1252
stored_loc = br_from.get_push_location()
1226
1253
if stored_loc is None:
1227
raise errors.BzrCommandError(gettext(
1228
"No push location known or specified."))
1254
parent_loc = br_from.get_parent()
1256
raise errors.BzrCommandError(gettext(
1257
"No push location known or specified. To push to the "
1258
"parent branch (at %s), use 'bzr push :parent'." %
1259
urlutils.unescape_for_display(parent_loc,
1260
self.outf.encoding)))
1262
raise errors.BzrCommandError(gettext(
1263
"No push location known or specified."))
1230
1265
display_url = urlutils.unescape_for_display(stored_loc,
1231
1266
self.outf.encoding)
1313
1348
revision_id = br_from.last_revision()
1314
1349
if to_location is None:
1315
to_location = urlutils.derive_to_location(from_location)
1350
to_location = getattr(br_from, "name", None)
1351
if to_location is None:
1352
to_location = urlutils.derive_to_location(from_location)
1316
1353
to_transport = transport.get_transport(to_location)
1318
1355
to_transport.mkdir('.')
1319
1356
except errors.FileExists:
1320
if not use_existing_dir:
1321
raise errors.BzrCommandError(gettext('Target directory "%s" '
1322
'already exists.') % to_location)
1325
to_dir = controldir.ControlDir.open_from_transport(
1327
except errors.NotBranchError:
1358
to_dir = controldir.ControlDir.open_from_transport(
1360
except errors.NotBranchError:
1361
if not use_existing_dir:
1362
raise errors.BzrCommandError(gettext('Target directory "%s" '
1363
'already exists.') % to_location)
1368
to_dir.open_branch()
1369
except errors.NotBranchError:
1331
to_dir.open_branch()
1332
except errors.NotBranchError:
1335
raise errors.AlreadyBranchError(to_location)
1372
raise errors.AlreadyBranchError(to_location)
1336
1373
except errors.NoSuchFile:
1337
1374
raise errors.BzrCommandError(gettext('Parent of "%s" does not exist.')
1348
1385
force_new_repo=standalone,
1349
1386
create_tree_if_local=not no_tree,
1350
1387
source_branch=br_from)
1351
branch = to_dir.open_branch()
1388
branch = to_dir.open_branch(
1389
possible_transports=[
1390
br_from.bzrdir.root_transport, to_transport])
1352
1391
except errors.NoSuchRevision:
1353
1392
to_transport.delete_tree('.')
1354
1393
msg = gettext("The branch {0} has no revision {1}.").format(
1404
1443
self.outf.encoding).rstrip("/"))
1406
1445
dir = controldir.ControlDir.open_containing(location)[0]
1407
for branch in dir.list_branches():
1408
if branch.name is None:
1409
self.outf.write(gettext(" (default)\n"))
1447
active_branch = dir.open_branch(name=None)
1448
except errors.NotBranchError:
1449
active_branch = None
1450
branches = dir.get_branches()
1452
for name, branch in branches.iteritems():
1455
active = (active_branch is not None and
1456
active_branch.base == branch.base)
1457
names[name] = active
1458
# Only mention the current branch explicitly if it's not
1459
# one of the colocated branches
1460
if not any(names.values()) and active_branch is not None:
1461
self.outf.write("* %s\n" % gettext("(default)"))
1462
for name in sorted(names.keys()):
1463
active = names[name]
1411
self.outf.write(" %s\n" % branch.name.encode(
1412
self.outf.encoding))
1468
self.outf.write("%s %s\n" % (
1469
prefix, name.encode(self.outf.encoding)))
1415
1472
class cmd_checkout(Command):
2031
2088
to_transport = transport.get_transport(location)
2032
to_transport.ensure_base()
2034
newdir = format.initialize_on_transport(to_transport)
2035
repo = newdir.create_repository(shared=True)
2036
repo.set_make_working_trees(not no_trees)
2090
(repo, newdir, require_stacking, repository_policy) = (
2091
format.initialize_on_transport_ex(to_transport,
2092
create_prefix=True, make_working_trees=not no_trees,
2093
shared_repo=True, force_new_repo=True,
2094
use_existing_dir=True,
2095
repo_format_name=format.repository_format.get_format_string()))
2037
2096
if not is_quiet():
2038
2097
from bzrlib.info import show_bzrdir_info
2039
show_bzrdir_info(repo.bzrdir, verbose=0, outfile=self.outf)
2098
show_bzrdir_info(newdir, verbose=0, outfile=self.outf)
2042
2101
class cmd_diff(Command):
2512
2571
help='Do not report commits with more than one parent.'),
2513
2572
Option('exclude-common-ancestry',
2514
2573
help='Display only the revisions that are not part'
2515
' of both ancestries (require -rX..Y)'
2574
' of both ancestries (require -rX..Y).'
2517
2576
Option('signatures',
2518
help='Show digital signature validity'),
2577
help='Show digital signature validity.'),
2519
2578
ListOption('match',
2520
2579
short_name='m',
2521
2580
help='Show revisions whose properties match this '
3144
3203
Option('per-file-timestamps',
3145
3204
help='Set modification time of files to that of the last '
3146
3205
'revision in which it was changed.'),
3206
Option('uncommitted',
3207
help='Export the working tree contents rather than that of the '
3148
3210
def run(self, dest, branch_or_subdir=None, revision=None, format=None,
3149
root=None, filters=False, per_file_timestamps=False, directory=u'.'):
3211
root=None, filters=False, per_file_timestamps=False, uncommitted=False,
3150
3213
from bzrlib.export import export
3152
3215
if branch_or_subdir is None:
3153
tree = WorkingTree.open_containing(directory)[0]
3216
branch_or_subdir = directory
3218
(tree, b, subdir) = controldir.ControlDir.open_containing_tree_or_branch(
3220
if tree is not None:
3221
self.add_cleanup(tree.lock_read().unlock)
3225
raise errors.BzrCommandError(
3226
gettext("--uncommitted requires a working tree"))
3157
b, subdir = Branch.open_containing(branch_or_subdir)
3160
rev_tree = _get_one_revision_tree('export', revision, branch=b, tree=tree)
3229
export_tree = _get_one_revision_tree('export', revision, branch=b, tree=tree)
3162
export(rev_tree, dest, format, root, subdir, filtered=filters,
3231
export(export_tree, dest, format, root, subdir, filtered=filters,
3163
3232
per_file_timestamps=per_file_timestamps)
3164
3233
except errors.NoSuchExportFormat, e:
3165
raise errors.BzrCommandError(gettext('Unsupported export format: %s') % e.format)
3234
raise errors.BzrCommandError(
3235
gettext('Unsupported export format: %s') % e.format)
3168
3238
class cmd_cat(Command):
3671
3741
if directory is None:
3672
3742
# use branch if we're inside one; otherwise global config
3674
c = Branch.open_containing(u'.')[0].get_config()
3744
c = Branch.open_containing(u'.')[0].get_config_stack()
3675
3745
except errors.NotBranchError:
3676
c = _mod_config.GlobalConfig()
3746
c = _mod_config.GlobalStack()
3678
c = Branch.open(directory).get_config()
3748
c = Branch.open(directory).get_config_stack()
3749
identity = c.get('email')
3680
self.outf.write(c.user_email() + '\n')
3751
self.outf.write(_mod_config.extract_email_address(identity)
3682
self.outf.write(c.username() + '\n')
3754
self.outf.write(identity + '\n')
3696
3768
# use global config unless --branch given
3698
3770
if directory is None:
3699
c = Branch.open_containing(u'.')[0].get_config()
3771
c = Branch.open_containing(u'.')[0].get_config_stack()
3701
c = Branch.open(directory).get_config()
3773
c = Branch.open(directory).get_config_stack()
3703
c = _mod_config.GlobalConfig()
3704
c.set_user_option('email', name)
3775
c = _mod_config.GlobalStack()
3776
c.set('email', name)
3707
3779
class cmd_nick(Command):
5016
5088
def _run(self, b, revision_id_list, revision):
5017
5089
import bzrlib.gpg as gpg
5018
gpg_strategy = gpg.GPGStrategy(b.get_config())
5090
gpg_strategy = gpg.GPGStrategy(b.get_config_stack())
5019
5091
if revision_id_list is not None:
5020
5092
b.repository.start_write_group()
6068
6140
if '/' not in to_location and '\\' not in to_location:
6069
6141
# This path is meant to be relative to the existing branch
6070
6142
this_url = self._get_branch_location(control_dir)
6071
to_location = urlutils.join(this_url, '..', to_location)
6143
# Perhaps the target control dir supports colocated branches?
6145
root = controldir.ControlDir.open(this_url,
6146
possible_transports=[control_dir.user_transport])
6147
except errors.NotBranchError:
6150
colocated = root._format.colocated_branches
6152
to_location = urlutils.join_segment_parameters(this_url,
6153
{"branch": urlutils.escape(to_location)})
6155
to_location = urlutils.join(
6156
this_url, '..', urlutils.escape(to_location))
6072
6157
to_branch = branch.bzrdir.sprout(to_location,
6073
6158
possible_transports=[branch.bzrdir.root_transport],
6074
6159
source_branch=branch).open_branch()
6161
# Perhaps it's a colocated branch?
6077
to_branch = Branch.open(to_location)
6078
except errors.NotBranchError:
6079
this_url = self._get_branch_location(control_dir)
6080
to_branch = Branch.open(
6081
urlutils.join(this_url, '..', to_location))
6163
to_branch = control_dir.open_branch(to_location)
6164
except (errors.NotBranchError, errors.NoColocatedBranchSupport):
6166
to_branch = Branch.open(to_location)
6167
except errors.NotBranchError:
6168
this_url = self._get_branch_location(control_dir)
6169
to_branch = Branch.open(
6171
this_url, '..', urlutils.escape(to_location)))
6082
6172
if revision is not None:
6083
6173
revision = revision.as_revision_id(to_branch)
6084
6174
switch.switch(control_dir, to_branch, force, revision_id=revision)
6517
6607
takes_options = [Option('plugin',
6518
6608
help='Export help text from named command '\
6519
6609
'(defaults to all built in commands).',
6611
Option('include-duplicates',
6612
help='Output multiple copies of the same msgid '
6613
'string if it appears more than once.'),
6522
def run(self, plugin=None):
6616
def run(self, plugin=None, include_duplicates=False):
6523
6617
from bzrlib.export_pot import export_pot
6524
export_pot(self.outf, plugin)
6618
export_pot(self.outf, plugin, include_duplicates)
6527
6621
def _register_lazy_builtins():