1049
1547
# Just using os.mkdir, since I don't
1050
1548
# believe that we want to create a bunch of
1051
1549
# locations if the user supplies an extended path
1052
# TODO: create-prefix
1054
to_transport.mkdir('.')
1055
except errors.FileExists:
1059
existing_bzrdir = bzrdir.BzrDir.open(location)
1060
except NotBranchError:
1551
to_transport.ensure_base()
1552
except errors.NoSuchFile:
1553
if not create_prefix:
1554
raise errors.BzrCommandError("Parent directory of %s"
1556
"\nYou may supply --create-prefix to create all"
1557
" leading parent directories."
1559
_create_prefix(to_transport)
1562
a_bzrdir = bzrdir.BzrDir.open_from_transport(to_transport)
1563
except errors.NotBranchError:
1061
1564
# really a NotBzrDir error...
1062
bzrdir.BzrDir.create_branch_convenience(location, format=format)
1565
create_branch = bzrdir.BzrDir.create_branch_convenience
1566
branch = create_branch(to_transport.base, format=format,
1567
possible_transports=[to_transport])
1568
a_bzrdir = branch.bzrdir
1064
if existing_bzrdir.has_branch():
1570
from bzrlib.transport.local import LocalTransport
1571
if a_bzrdir.has_branch():
1065
1572
if (isinstance(to_transport, LocalTransport)
1066
and not existing_bzrdir.has_workingtree()):
1573
and not a_bzrdir.has_workingtree()):
1067
1574
raise errors.BranchExistsWithoutWorkingTree(location)
1068
1575
raise errors.AlreadyBranchError(location)
1070
existing_bzrdir.create_branch()
1071
existing_bzrdir.create_workingtree()
1576
branch = a_bzrdir.create_branch()
1577
a_bzrdir.create_workingtree()
1578
if append_revisions_only:
1580
branch.set_append_revisions_only(True)
1581
except errors.UpgradeRequired:
1582
raise errors.BzrCommandError('This branch format cannot be set'
1583
' to append-revisions-only. Try --experimental-branch6')
1585
from bzrlib.info import describe_layout, describe_format
1587
tree = a_bzrdir.open_workingtree(recommend_upgrade=False)
1588
except (errors.NoWorkingTree, errors.NotLocalUrl):
1590
repository = branch.repository
1591
layout = describe_layout(repository, branch, tree).lower()
1592
format = describe_format(a_bzrdir, repository, branch, tree)
1593
self.outf.write("Created a %s (format: %s)\n" % (layout, format))
1594
if repository.is_shared():
1595
#XXX: maybe this can be refactored into transport.path_or_url()
1596
url = repository.bzrdir.root_transport.external_url()
1598
url = urlutils.local_path_from_url(url)
1599
except errors.InvalidURL:
1601
self.outf.write("Using shared repository: %s\n" % url)
1074
1604
class cmd_init_repository(Command):
1075
1605
"""Create a shared repository to hold branches.
1077
New branches created under the repository directory will store their revisions
1078
in the repository, not in the branch directory, if the branch format supports
1084
bzr checkout --lightweight repo/trunk trunk-checkout
1607
New branches created under the repository directory will store their
1608
revisions in the repository, not in the branch directory.
1610
If the --no-trees option is used then the branches in the repository
1611
will not have working trees by default.
1614
Create a shared repositories holding just branches::
1616
bzr init-repo --no-trees repo
1619
Make a lightweight checkout elsewhere::
1621
bzr checkout --lightweight repo/trunk trunk-checkout
1088
takes_args = ["location"]
1089
takes_options = [Option('format',
1090
help='Specify a format for this repository.'
1091
' Current formats are: default, knit,'
1092
' metaweave and weave. Default is knit;'
1093
' metaweave and weave are deprecated',
1094
type=get_format_type),
1096
help='Allows branches in repository to have'
1626
_see_also = ['init', 'branch', 'checkout', 'repositories']
1627
takes_args = ["location"]
1628
takes_options = [RegistryOption('format',
1629
help='Specify a format for this repository. See'
1630
' "bzr help formats" for details.',
1631
lazy_registry=('bzrlib.bzrdir', 'format_registry'),
1632
converter=lambda name: bzrdir.format_registry.make_bzrdir(name),
1633
value_switches=True, title='Repository format'),
1635
help='Branches in the repository will default to'
1636
' not having a working tree.'),
1098
1638
aliases = ["init-repo"]
1099
def run(self, location, format=None, trees=False):
1640
def run(self, location, format=None, no_trees=False):
1100
1641
if format is None:
1101
format = get_format_type('default')
1642
format = bzrdir.format_registry.make_bzrdir('default')
1103
1644
if location is None:
1106
1647
to_transport = transport.get_transport(location)
1108
to_transport.mkdir('.')
1109
except errors.FileExists:
1648
to_transport.ensure_base()
1112
1650
newdir = format.initialize_on_transport(to_transport)
1113
1651
repo = newdir.create_repository(shared=True)
1114
repo.set_make_working_trees(trees)
1652
repo.set_make_working_trees(not no_trees)
1654
from bzrlib.info import show_bzrdir_info
1655
show_bzrdir_info(repo.bzrdir, verbose=0, outfile=self.outf)
1117
1658
class cmd_diff(Command):
1118
"""Show differences in the working tree or between revisions.
1120
If files are listed, only the changes in those files are listed.
1121
Otherwise, all changes for the tree are listed.
1659
"""Show differences in the working tree, between revisions or branches.
1661
If no arguments are given, all changes for the current tree are listed.
1662
If files are given, only the changes in those files are listed.
1663
Remote and multiple branches can be compared by using the --old and
1664
--new options. If not provided, the default for both is derived from
1665
the first argument, if any, or the current tree if no arguments are
1123
1668
"bzr diff -p1" is equivalent to "bzr diff --prefix old/:new/", and
1124
1669
produces patches suitable for "patch -p1".
1128
Shows the difference in the working tree versus the last commit
1130
Difference between the working tree and revision 1
1132
Difference between revision 2 and revision 1
1133
bzr diff --diff-prefix old/:new/
1134
Same as 'bzr diff' but prefix paths with old/ and new/
1135
bzr diff bzr.mine bzr.dev
1136
Show the differences between the two working trees
1138
Show just the differences for 'foo.c'
1673
2 - unrepresentable changes
1678
Shows the difference in the working tree versus the last commit::
1682
Difference between the working tree and revision 1::
1686
Difference between revision 2 and revision 1::
1690
Difference between revision 2 and revision 1 for branch xxx::
1694
Show just the differences for file NEWS::
1698
Show the differences in working tree xxx for file NEWS::
1702
Show the differences from branch xxx to this working tree:
1706
Show the differences between two branches for file NEWS::
1708
bzr diff --old xxx --new yyy NEWS
1710
Same as 'bzr diff' but prefix paths with old/ and new/::
1712
bzr diff --prefix old/:new/
1140
# TODO: Option to use external diff command; could be GNU diff, wdiff,
1141
# or a graphical diff.
1143
# TODO: Python difflib is not exactly the same as unidiff; should
1144
# either fix it up or prefer to use an external diff.
1146
# TODO: Selected-file diff is inefficient and doesn't show you
1149
# TODO: This probably handles non-Unix newlines poorly.
1714
_see_also = ['status']
1151
1715
takes_args = ['file*']
1152
takes_options = ['revision', 'diff-options', 'prefix']
1717
Option('diff-options', type=str,
1718
help='Pass these options to the external diff program.'),
1719
Option('prefix', type=str,
1721
help='Set prefixes added to old and new filenames, as '
1722
'two values separated by a colon. (eg "old/:new/").'),
1724
help='Branch/tree to compare from.',
1728
help='Branch/tree to compare to.',
1734
help='Use this command to compare files.',
1153
1738
aliases = ['di', 'dif']
1154
1739
encoding_type = 'exact'
1156
1741
@display_command
1157
1742
def run(self, revision=None, file_list=None, diff_options=None,
1159
from bzrlib.diff import diff_cmd_helper, show_diff_trees
1743
prefix=None, old=None, new=None, using=None):
1744
from bzrlib.diff import _get_trees_to_diff, show_diff_trees
1161
1746
if (prefix is None) or (prefix == '0'):
1162
1747
# diff -p0 format
2101
3341
default, use --remember. The value will only be saved if the remote
2102
3342
location can be accessed.
2106
To merge the latest revision from bzr.dev
2107
bzr merge ../bzr.dev
2109
To merge changes up to and including revision 82 from bzr.dev
2110
bzr merge -r 82 ../bzr.dev
2112
To merge the changes introduced by 82, without previous changes:
2113
bzr merge -r 81..82 ../bzr.dev
3344
The results of the merge are placed into the destination working
3345
directory, where they can be reviewed (with bzr diff), tested, and then
3346
committed to record the result of the merge.
2115
3348
merge refuses to run if there are any uncommitted changes, unless
2116
3349
--force is given.
2118
The following merge types are available:
3352
To merge the latest revision from bzr.dev::
3354
bzr merge ../bzr.dev
3356
To merge changes up to and including revision 82 from bzr.dev::
3358
bzr merge -r 82 ../bzr.dev
3360
To merge the changes introduced by 82, without previous changes::
3362
bzr merge -r 81..82 ../bzr.dev
3364
To apply a merge directive contained in in /tmp/merge:
3366
bzr merge /tmp/merge
2120
takes_args = ['branch?']
2121
takes_options = ['revision', 'force', 'merge-type', 'reprocess', 'remember',
2122
Option('show-base', help="Show base revision text in "
2124
Option('uncommitted', help='Apply uncommitted changes'
2125
' from a working copy, instead of branch changes')]
2128
from merge import merge_type_help
2129
from inspect import getdoc
2130
return getdoc(self) + '\n' + merge_type_help()
2132
def run(self, branch=None, revision=None, force=False, merge_type=None,
2133
show_base=False, reprocess=False, remember=False,
3369
encoding_type = 'exact'
3370
_see_also = ['update', 'remerge', 'status-flags', 'send']
3371
takes_args = ['location?']
3376
help='Merge even if the destination tree has uncommitted changes.'),
3380
Option('show-base', help="Show base revision text in "
3382
Option('uncommitted', help='Apply uncommitted changes'
3383
' from a working copy, instead of branch changes.'),
3384
Option('pull', help='If the destination is already'
3385
' completely merged into the source, pull from the'
3386
' source rather than merging. When this happens,'
3387
' you do not need to commit the result.'),
3389
help='Branch to merge into, '
3390
'rather than the one containing the working directory.',
3394
Option('preview', help='Instead of merging, show a diff of the merge.')
3397
def run(self, location=None, revision=None, force=False,
3398
merge_type=None, show_base=False, reprocess=None, remember=False,
3399
uncommitted=False, pull=False,
2135
3403
if merge_type is None:
2136
merge_type = Merge3Merger
2138
tree = WorkingTree.open_containing(u'.')[0]
2140
if branch is not None:
2142
reader = bundle.read_bundle_from_url(branch)
2144
pass # Continue on considering this url a Branch
2146
conflicts = merge_bundle(reader, tree, not force, merge_type,
2147
reprocess, show_base)
3404
merge_type = _mod_merge.Merge3Merger
3406
if directory is None: directory = u'.'
3407
possible_transports = []
3409
allow_pending = True
3410
verified = 'inapplicable'
3411
tree = WorkingTree.open_containing(directory)[0]
3413
# die as quickly as possible if there are uncommitted changes
3415
basis_tree = tree.revision_tree(tree.last_revision())
3416
except errors.NoSuchRevision:
3417
basis_tree = tree.basis_tree()
3419
changes = tree.changes_from(basis_tree)
3420
if changes.has_changed():
3421
raise errors.UncommittedChanges(tree)
3423
view_info = _get_view_info_for_change_reporter(tree)
3424
change_reporter = delta._ChangeReporter(
3425
unversioned_filter=tree.is_ignored, view_info=view_info)
3428
pb = ui.ui_factory.nested_progress_bar()
3429
cleanups.append(pb.finished)
3431
cleanups.append(tree.unlock)
3432
if location is not None:
3434
mergeable = bundle.read_mergeable_from_url(location,
3435
possible_transports=possible_transports)
3436
except errors.NotABundle:
2153
if revision is None \
2154
or len(revision) < 1 or revision[0].needs_branch():
2155
branch = self._get_remembered_parent(tree, branch, 'Merging from')
2157
if revision is None or len(revision) < 1:
2160
other = [branch, None]
2163
other = [branch, -1]
2164
other_branch, path = Branch.open_containing(branch)
2167
raise BzrCommandError('Cannot use --uncommitted and --revision'
2168
' at the same time.')
2169
branch = revision[0].get_branch() or branch
2170
if len(revision) == 1:
2172
other_branch, path = Branch.open_containing(branch)
2173
revno = revision[0].in_history(other_branch).revno
2174
other = [branch, revno]
2176
assert len(revision) == 2
2177
if None in revision:
2178
raise BzrCommandError(
2179
"Merge doesn't permit empty revision specifier.")
2180
base_branch, path = Branch.open_containing(branch)
2181
branch1 = revision[1].get_branch() or branch
2182
other_branch, path1 = Branch.open_containing(branch1)
2183
if revision[0].get_branch() is not None:
2184
# then path was obtained from it, and is None.
2187
base = [branch, revision[0].in_history(base_branch).revno]
2188
other = [branch1, revision[1].in_history(other_branch).revno]
2190
if tree.branch.get_parent() is None or remember:
2191
tree.branch.set_parent(other_branch.base)
2194
interesting_files = [path]
2196
interesting_files = None
2197
pb = ui.ui_factory.nested_progress_bar()
2200
conflict_count = merge(other, base, check_clean=(not force),
2201
merge_type=merge_type,
2202
reprocess=reprocess,
2203
show_base=show_base,
2204
pb=pb, file_list=interesting_files)
2207
if conflict_count != 0:
3440
raise errors.BzrCommandError('Cannot use --uncommitted'
3441
' with bundles or merge directives.')
3443
if revision is not None:
3444
raise errors.BzrCommandError(
3445
'Cannot use -r with merge directives or bundles')
3446
merger, verified = _mod_merge.Merger.from_mergeable(tree,
3449
if merger is None and uncommitted:
3450
if revision is not None and len(revision) > 0:
3451
raise errors.BzrCommandError('Cannot use --uncommitted and'
3452
' --revision at the same time.')
3453
location = self._select_branch_location(tree, location)[0]
3454
other_tree, other_path = WorkingTree.open_containing(location)
3455
merger = _mod_merge.Merger.from_uncommitted(tree, other_tree,
3457
allow_pending = False
3458
if other_path != '':
3459
merger.interesting_files = [other_path]
3462
merger, allow_pending = self._get_merger_from_branch(tree,
3463
location, revision, remember, possible_transports, pb)
3465
merger.merge_type = merge_type
3466
merger.reprocess = reprocess
3467
merger.show_base = show_base
3468
self.sanity_check_merger(merger)
3469
if (merger.base_rev_id == merger.other_rev_id and
3470
merger.other_rev_id is not None):
3471
note('Nothing to do.')
2211
except errors.AmbiguousBase, e:
2212
m = ("sorry, bzr can't determine the right merge base yet\n"
2213
"candidates are:\n "
2214
+ "\n ".join(e.bases)
2216
"please specify an explicit base with -r,\n"
2217
"and (if you want) report this to the bzr developers\n")
2220
# TODO: move up to common parent; this isn't merge-specific anymore.
2221
def _get_remembered_parent(self, tree, supplied_location, verb_string):
3474
if merger.interesting_files is not None:
3475
raise errors.BzrCommandError('Cannot pull individual files')
3476
if (merger.base_rev_id == tree.last_revision()):
3477
result = tree.pull(merger.other_branch, False,
3478
merger.other_rev_id)
3479
result.report(self.outf)
3481
merger.check_basis(False)
3483
return self._do_preview(merger)
3485
return self._do_merge(merger, change_reporter, allow_pending,
3488
for cleanup in reversed(cleanups):
3491
def _do_preview(self, merger):
3492
from bzrlib.diff import show_diff_trees
3493
tree_merger = merger.make_merger()
3494
tt = tree_merger.make_preview_transform()
3496
result_tree = tt.get_preview_tree()
3497
show_diff_trees(merger.this_tree, result_tree, self.outf,
3498
old_label='', new_label='')
3502
def _do_merge(self, merger, change_reporter, allow_pending, verified):
3503
merger.change_reporter = change_reporter
3504
conflict_count = merger.do_merge()
3506
merger.set_pending()
3507
if verified == 'failed':
3508
warning('Preview patch does not match changes')
3509
if conflict_count != 0:
3514
def sanity_check_merger(self, merger):
3515
if (merger.show_base and
3516
not merger.merge_type is _mod_merge.Merge3Merger):
3517
raise errors.BzrCommandError("Show-base is not supported for this"
3518
" merge type. %s" % merger.merge_type)
3519
if merger.reprocess is None:
3520
if merger.show_base:
3521
merger.reprocess = False
3523
# Use reprocess if the merger supports it
3524
merger.reprocess = merger.merge_type.supports_reprocess
3525
if merger.reprocess and not merger.merge_type.supports_reprocess:
3526
raise errors.BzrCommandError("Conflict reduction is not supported"
3527
" for merge type %s." %
3529
if merger.reprocess and merger.show_base:
3530
raise errors.BzrCommandError("Cannot do conflict reduction and"
3533
def _get_merger_from_branch(self, tree, location, revision, remember,
3534
possible_transports, pb):
3535
"""Produce a merger from a location, assuming it refers to a branch."""
3536
from bzrlib.tag import _merge_tags_if_possible
3537
# find the branch locations
3538
other_loc, user_location = self._select_branch_location(tree, location,
3540
if revision is not None and len(revision) == 2:
3541
base_loc, _unused = self._select_branch_location(tree,
3542
location, revision, 0)
3544
base_loc = other_loc
3546
other_branch, other_path = Branch.open_containing(other_loc,
3547
possible_transports)
3548
if base_loc == other_loc:
3549
base_branch = other_branch
3551
base_branch, base_path = Branch.open_containing(base_loc,
3552
possible_transports)
3553
# Find the revision ids
3554
if revision is None or len(revision) < 1 or revision[-1] is None:
3555
other_revision_id = _mod_revision.ensure_null(
3556
other_branch.last_revision())
3558
other_revision_id = revision[-1].as_revision_id(other_branch)
3559
if (revision is not None and len(revision) == 2
3560
and revision[0] is not None):
3561
base_revision_id = revision[0].as_revision_id(base_branch)
3563
base_revision_id = None
3564
# Remember where we merge from
3565
if ((remember or tree.branch.get_submit_branch() is None) and
3566
user_location is not None):
3567
tree.branch.set_submit_branch(other_branch.base)
3568
_merge_tags_if_possible(other_branch, tree.branch)
3569
merger = _mod_merge.Merger.from_revision_ids(pb, tree,
3570
other_revision_id, base_revision_id, other_branch, base_branch)
3571
if other_path != '':
3572
allow_pending = False
3573
merger.interesting_files = [other_path]
3575
allow_pending = True
3576
return merger, allow_pending
3578
def _select_branch_location(self, tree, user_location, revision=None,
3580
"""Select a branch location, according to possible inputs.
3582
If provided, branches from ``revision`` are preferred. (Both
3583
``revision`` and ``index`` must be supplied.)
3585
Otherwise, the ``location`` parameter is used. If it is None, then the
3586
``submit`` or ``parent`` location is used, and a note is printed.
3588
:param tree: The working tree to select a branch for merging into
3589
:param location: The location entered by the user
3590
:param revision: The revision parameter to the command
3591
:param index: The index to use for the revision parameter. Negative
3592
indices are permitted.
3593
:return: (selected_location, user_location). The default location
3594
will be the user-entered location.
3596
if (revision is not None and index is not None
3597
and revision[index] is not None):
3598
branch = revision[index].get_branch()
3599
if branch is not None:
3600
return branch, branch
3601
if user_location is None:
3602
location = self._get_remembered(tree, 'Merging from')
3604
location = user_location
3605
return location, user_location
3607
def _get_remembered(self, tree, verb_string):
2222
3608
"""Use tree.branch's parent if none was supplied.
2224
3610
Report if the remembered location was used.
2226
if supplied_location is not None:
2227
return supplied_location
2228
stored_location = tree.branch.get_parent()
3612
stored_location = tree.branch.get_submit_branch()
3613
stored_location_type = "submit"
3614
if stored_location is None:
3615
stored_location = tree.branch.get_parent()
3616
stored_location_type = "parent"
2229
3617
mutter("%s", stored_location)
2230
3618
if stored_location is None:
2231
raise BzrCommandError("No location specified or remembered")
2232
display_url = urlutils.unescape_for_display(stored_location, self.outf.encoding)
2233
self.outf.write("%s remembered location %s\n" % (verb_string, display_url))
3619
raise errors.BzrCommandError("No location specified or remembered")
3620
display_url = urlutils.unescape_for_display(stored_location, 'utf-8')
3621
note(u"%s remembered %s location %s", verb_string,
3622
stored_location_type, display_url)
2234
3623
return stored_location
2327
3725
class cmd_revert(Command):
2328
"""Reverse all changes since the last commit.
2330
Only versioned files are affected. Specify filenames to revert only
2331
those files. By default, any files that are changed will be backed up
2332
first. Backup files have a '~' appended to their name.
3726
"""Revert files to a previous revision.
3728
Giving a list of files will revert only those files. Otherwise, all files
3729
will be reverted. If the revision is not specified with '--revision', the
3730
last committed revision is used.
3732
To remove only some changes, without reverting to a prior version, use
3733
merge instead. For example, "merge . --revision -2..-3" will remove the
3734
changes introduced by -2, without affecting the changes introduced by -1.
3735
Or to remove certain changes on a hunk-by-hunk basis, see the Shelf plugin.
3737
By default, any files that have been manually changed will be backed up
3738
first. (Files changed only by merge are not backed up.) Backup files have
3739
'.~#~' appended to their name, where # is a number.
3741
When you provide files, you can use their current pathname or the pathname
3742
from the target revision. So you can use revert to "undelete" a file by
3743
name. If you name a directory, all the contents of that directory will be
3746
Any files that have been newly added since that revision will be deleted,
3747
with a backup kept if appropriate. Directories containing unknown files
3748
will not be deleted.
3750
The working tree contains a list of pending merged revisions, which will
3751
be included as parents in the next commit. Normally, revert clears that
3752
list as well as reverting the files. If any files are specified, revert
3753
leaves the pending merge list alone and reverts only the files. Use "bzr
3754
revert ." in the tree root to revert all files but keep the merge record,
3755
and "bzr revert --forget-merges" to clear the pending merge list without
3756
reverting any files.
2334
takes_options = ['revision', 'no-backup']
3759
_see_also = ['cat', 'export']
3762
Option('no-backup', "Do not save backups of reverted files."),
3763
Option('forget-merges',
3764
'Remove pending merge marker, without changing any files.'),
2335
3766
takes_args = ['file*']
2336
aliases = ['merge-revert']
2338
def run(self, revision=None, no_backup=False, file_list=None):
2339
from bzrlib.commands import parse_spec
2340
if file_list is not None:
2341
if len(file_list) == 0:
2342
raise BzrCommandError("No files specified")
3768
def run(self, revision=None, no_backup=False, file_list=None,
3769
forget_merges=None):
2346
3770
tree, file_list = tree_files(file_list)
2347
if revision is None:
2348
# FIXME should be tree.last_revision
2349
rev_id = tree.last_revision()
2350
elif len(revision) != 1:
2351
raise BzrCommandError('bzr revert --revision takes exactly 1 argument')
2353
rev_id = revision[0].in_history(tree.branch).rev_id
3774
tree.set_parent_ids(tree.get_parent_ids()[:1])
3776
self._revert_tree_to_revision(tree, revision, file_list, no_backup)
3781
def _revert_tree_to_revision(tree, revision, file_list, no_backup):
3782
rev_tree = _get_one_revision_tree('revert', revision, tree=tree)
2354
3783
pb = ui.ui_factory.nested_progress_bar()
2356
tree.revert(file_list,
2357
tree.branch.repository.revision_tree(rev_id),
3785
tree.revert(file_list, rev_tree, not no_backup, pb,
3786
report_changes=True)
2363
3791
class cmd_assert_fail(Command):
2364
3792
"""Test reporting of assertion failures"""
3793
# intended just for use in testing
2367
assert False, "always fails"
3798
raise AssertionError("always fails")
2370
3801
class cmd_help(Command):
2371
3802
"""Show help on a command or other topic.
2373
For a list of all available commands, say 'bzr help commands'."""
2374
takes_options = [Option('long', 'show help on all commands')]
3805
_see_also = ['topics']
3807
Option('long', 'Show help on all commands.'),
2375
3809
takes_args = ['topic?']
2376
3810
aliases = ['?', '--help', '-?', '-h']
2378
3812
@display_command
2379
3813
def run(self, topic=None, long=False):
2381
3815
if topic is None and long:
2382
3816
topic = "commands"
3817
bzrlib.help.help(topic)
2386
3820
class cmd_shell_complete(Command):
2387
3821
"""Show appropriate completions for context.
2389
For a list of all available commands, say 'bzr shell-complete'."""
3823
For a list of all available commands, say 'bzr shell-complete'.
2390
3825
takes_args = ['context?']
2391
3826
aliases = ['s-c']
2394
3829
@display_command
2395
3830
def run(self, context=None):
2396
3831
import shellcomplete
2397
3832
shellcomplete.shellcomplete(context)
2400
class cmd_fetch(Command):
2401
"""Copy in history from another branch but don't merge it.
2403
This is an internal method used for pull and merge."""
2405
takes_args = ['from_branch', 'to_branch']
2406
def run(self, from_branch, to_branch):
2407
from bzrlib.fetch import Fetcher
2408
from_b = Branch.open(from_branch)
2409
to_b = Branch.open(to_branch)
2410
Fetcher(to_b, from_b)
2413
3835
class cmd_missing(Command):
2414
3836
"""Show unmerged/unpulled revisions between two branches.
2416
OTHER_BRANCH may be local or remote."""
3838
OTHER_BRANCH may be local or remote.
3840
To filter on a range of revisions, you can use the command -r begin..end
3841
-r revision requests a specific revision, -r ..end or -r begin.. are
3846
Determine the missing revisions between this and the branch at the
3847
remembered pull location::
3851
Determine the missing revisions between this and another branch::
3853
bzr missing http://server/branch
3855
Determine the missing revisions up to a specific revision on the other
3858
bzr missing -r ..-10
3860
Determine the missing revisions up to a specific revision on this
3863
bzr missing --my-revision ..-10
3866
_see_also = ['merge', 'pull']
2417
3867
takes_args = ['other_branch?']
2418
takes_options = [Option('reverse', 'Reverse the order of revisions'),
2420
'Display changes in the local branch only'),
2421
Option('theirs-only',
2422
'Display changes in the remote branch only'),
3869
Option('reverse', 'Reverse the order of revisions.'),
3871
'Display changes in the local branch only.'),
3872
Option('this' , 'Same as --mine-only.'),
3873
Option('theirs-only',
3874
'Display changes in the remote branch only.'),
3875
Option('other', 'Same as --theirs-only.'),
3879
custom_help('revision',
3880
help='Filter on other branch revisions (inclusive). '
3881
'See "help revisionspec" for details.'),
3882
Option('my-revision',
3883
type=_parse_revision_str,
3884
help='Filter on local branch revisions (inclusive). '
3885
'See "help revisionspec" for details.'),
3886
Option('include-merges', 'Show merged revisions.'),
2430
3888
encoding_type = 'replace'
2432
3890
@display_command
2433
3891
def run(self, other_branch=None, reverse=False, mine_only=False,
2434
theirs_only=False, log_format=None, long=False, short=False, line=False,
2435
show_ids=False, verbose=False):
2436
from bzrlib.missing import find_unmerged, iter_log_data
2437
from bzrlib.log import log_formatter
3893
log_format=None, long=False, short=False, line=False,
3894
show_ids=False, verbose=False, this=False, other=False,
3895
include_merges=False, revision=None, my_revision=None):
3896
from bzrlib.missing import find_unmerged, iter_log_revisions
3905
# TODO: We should probably check that we don't have mine-only and
3906
# theirs-only set, but it gets complicated because we also have
3907
# this and other which could be used.
2438
3914
local_branch = Branch.open_containing(u".")[0]
2439
3915
parent = local_branch.get_parent()
2440
3916
if other_branch is None:
2441
3917
other_branch = parent
2442
3918
if other_branch is None:
2443
raise BzrCommandError("No peer location known or specified.")
2444
print "Using last location: " + local_branch.get_parent()
3919
raise errors.BzrCommandError("No peer location known"
3921
display_url = urlutils.unescape_for_display(parent,
3923
message("Using saved parent location: "
3924
+ display_url + "\n")
2445
3926
remote_branch = Branch.open(other_branch)
2446
3927
if remote_branch.base == local_branch.base:
2447
3928
remote_branch = local_branch
3930
local_revid_range = _revision_range_to_revid_range(
3931
_get_revision_range(my_revision, local_branch,
3934
remote_revid_range = _revision_range_to_revid_range(
3935
_get_revision_range(revision,
3936
remote_branch, self.name()))
2448
3938
local_branch.lock_read()
2450
3940
remote_branch.lock_read()
2452
local_extra, remote_extra = find_unmerged(local_branch, remote_branch)
2453
if (log_format is None):
2454
default = local_branch.get_config().log_format()
2455
log_format = get_log_format(long=long, short=short,
2456
line=line, default=default)
2457
lf = log_formatter(log_format,
2460
show_timezone='original')
2461
if reverse is False:
2462
local_extra.reverse()
2463
remote_extra.reverse()
3942
local_extra, remote_extra = find_unmerged(
3943
local_branch, remote_branch, restrict,
3944
backward=not reverse,
3945
include_merges=include_merges,
3946
local_revid_range=local_revid_range,
3947
remote_revid_range=remote_revid_range)
3949
if log_format is None:
3950
registry = log.log_formatter_registry
3951
log_format = registry.get_default(local_branch)
3952
lf = log_format(to_file=self.outf,
3954
show_timezone='original')
2464
3957
if local_extra and not theirs_only:
2465
print "You have %d extra revision(s):" % len(local_extra)
2466
for data in iter_log_data(local_extra, local_branch.repository,
3958
message("You have %d extra revision(s):\n" %
3960
for revision in iter_log_revisions(local_extra,
3961
local_branch.repository,
3963
lf.log_revision(revision)
2469
3964
printed_local = True
2471
3967
printed_local = False
2472
3969
if remote_extra and not mine_only:
2473
3970
if printed_local is True:
2475
print "You are missing %d revision(s):" % len(remote_extra)
2476
for data in iter_log_data(remote_extra, remote_branch.repository,
2479
if not remote_extra and not local_extra:
2481
print "Branches are up to date."
3972
message("You are missing %d revision(s):\n" %
3974
for revision in iter_log_revisions(remote_extra,
3975
remote_branch.repository,
3977
lf.log_revision(revision)
2483
3978
status_code = 1
3980
if mine_only and not local_extra:
3981
# We checked local, and found nothing extra
3982
message('This branch is up to date.\n')
3983
elif theirs_only and not remote_extra:
3984
# We checked remote, and found nothing extra
3985
message('Other branch is up to date.\n')
3986
elif not (mine_only or theirs_only or local_extra or
3988
# We checked both branches, and neither one had extra
3990
message("Branches are up to date.\n")
2485
3992
remote_branch.unlock()
2765
4410
control.break_lock()
2766
4411
except NotImplementedError:
2771
# command-line interpretation helper for merge-related commands
2772
def merge(other_revision, base_revision,
2773
check_clean=True, ignore_zero=False,
2774
this_dir=None, backup_files=False, merge_type=Merge3Merger,
2775
file_list=None, show_base=False, reprocess=False,
2776
pb=DummyProgress()):
2777
"""Merge changes into a tree.
2780
list(path, revno) Base for three-way merge.
2781
If [None, None] then a base will be automatically determined.
2783
list(path, revno) Other revision for three-way merge.
2785
Directory to merge changes into; '.' by default.
2787
If true, this_dir must have no uncommitted changes before the
2789
ignore_zero - If true, suppress the "zero conflicts" message when
2790
there are no conflicts; should be set when doing something we expect
2791
to complete perfectly.
2792
file_list - If supplied, merge only changes to selected files.
2794
All available ancestors of other_revision and base_revision are
2795
automatically pulled into the branch.
2797
The revno may be -1 to indicate the last revision on the branch, which is
2800
This function is intended for use from the command line; programmatic
2801
clients might prefer to call merge.merge_inner(), which has less magic
2804
from bzrlib.merge import Merger
2805
if this_dir is None:
2807
this_tree = WorkingTree.open_containing(this_dir)[0]
2808
if show_base and not merge_type is Merge3Merger:
2809
raise BzrCommandError("Show-base is not supported for this merge"
2810
" type. %s" % merge_type)
2811
if reprocess and not merge_type.supports_reprocess:
2812
raise BzrCommandError("Conflict reduction is not supported for merge"
2813
" type %s." % merge_type)
2814
if reprocess and show_base:
2815
raise BzrCommandError("Cannot do conflict reduction and show base.")
2817
merger = Merger(this_tree.branch, this_tree=this_tree, pb=pb)
2818
merger.pp = ProgressPhase("Merge phase", 5, pb)
2819
merger.pp.next_phase()
2820
merger.check_basis(check_clean)
2821
merger.set_other(other_revision)
2822
merger.pp.next_phase()
2823
merger.set_base(base_revision)
2824
if merger.base_rev_id == merger.other_rev_id:
2825
note('Nothing to do.')
4415
class cmd_wait_until_signalled(Command):
4416
"""Test helper for test_start_and_stop_bzr_subprocess_send_signal.
4418
This just prints a line to signal when it is ready, then blocks on stdin.
4424
sys.stdout.write("running\n")
4426
sys.stdin.readline()
4429
class cmd_serve(Command):
4430
"""Run the bzr server."""
4432
aliases = ['server']
4436
help='Serve on stdin/out for use from inetd or sshd.'),
4438
help='Listen for connections on nominated port of the form '
4439
'[hostname:]portnumber. Passing 0 as the port number will '
4440
'result in a dynamically allocated port. The default port is '
4444
help='Serve contents of this directory.',
4446
Option('allow-writes',
4447
help='By default the server is a readonly server. Supplying '
4448
'--allow-writes enables write access to the contents of '
4449
'the served directory and below.'
4453
def run_smart_server(self, smart_server):
4454
"""Run 'smart_server' forever, with no UI output at all."""
4455
# For the duration of this server, no UI output is permitted. note
4456
# that this may cause problems with blackbox tests. This should be
4457
# changed with care though, as we dont want to use bandwidth sending
4458
# progress over stderr to smart server clients!
4459
from bzrlib import lockdir
4460
old_factory = ui.ui_factory
4461
old_lockdir_timeout = lockdir._DEFAULT_TIMEOUT_SECONDS
4463
ui.ui_factory = ui.SilentUIFactory()
4464
lockdir._DEFAULT_TIMEOUT_SECONDS = 0
4465
smart_server.serve()
4467
ui.ui_factory = old_factory
4468
lockdir._DEFAULT_TIMEOUT_SECONDS = old_lockdir_timeout
4470
def get_host_and_port(self, port):
4471
"""Return the host and port to run the smart server on.
4473
If 'port' is None, the default host (`medium.BZR_DEFAULT_INTERFACE`)
4474
and port (`medium.BZR_DEFAULT_PORT`) will be used.
4476
If 'port' has a colon in it, the string before the colon will be
4477
interpreted as the host.
4479
:param port: A string of the port to run the server on.
4480
:return: A tuple of (host, port), where 'host' is a host name or IP,
4481
and port is an integer TCP/IP port.
4483
from bzrlib.smart import medium
4484
host = medium.BZR_DEFAULT_INTERFACE
4486
port = medium.BZR_DEFAULT_PORT
4489
host, port = port.split(':')
4493
def get_smart_server(self, transport, inet, port):
4494
"""Construct a smart server.
4496
:param transport: The base transport from which branches will be
4498
:param inet: If True, serve over stdin and stdout. Used for running
4500
:param port: The port to listen on. By default, it's `
4501
medium.BZR_DEFAULT_PORT`. See `get_host_and_port` for more
4503
:return: A smart server.
4505
from bzrlib.smart import medium, server
4507
smart_server = medium.SmartServerPipeStreamMedium(
4508
sys.stdin, sys.stdout, transport)
4510
host, port = self.get_host_and_port(port)
4511
smart_server = server.SmartTCPServer(
4512
transport, host=host, port=port)
4513
note('listening on port: %s' % smart_server.port)
4516
def run(self, port=None, inet=False, directory=None, allow_writes=False):
4517
from bzrlib.transport import get_transport
4518
from bzrlib.transport.chroot import ChrootServer
4519
if directory is None:
4520
directory = os.getcwd()
4521
url = urlutils.local_path_to_url(directory)
4522
if not allow_writes:
4523
url = 'readonly+' + url
4524
chroot_server = ChrootServer(get_transport(url))
4525
chroot_server.setUp()
4526
t = get_transport(chroot_server.get_url())
4527
smart_server = self.get_smart_server(t, inet, port)
4528
self.run_smart_server(smart_server)
4531
class cmd_join(Command):
4532
"""Combine a subtree into its containing tree.
4534
This command is for experimental use only. It requires the target tree
4535
to be in dirstate-with-subtree format, which cannot be converted into
4538
The TREE argument should be an independent tree, inside another tree, but
4539
not part of it. (Such trees can be produced by "bzr split", but also by
4540
running "bzr branch" with the target inside a tree.)
4542
The result is a combined tree, with the subtree no longer an independant
4543
part. This is marked as a merge of the subtree into the containing tree,
4544
and all history is preserved.
4546
If --reference is specified, the subtree retains its independence. It can
4547
be branched by itself, and can be part of multiple projects at the same
4548
time. But operations performed in the containing tree, such as commit
4549
and merge, will recurse into the subtree.
4552
_see_also = ['split']
4553
takes_args = ['tree']
4555
Option('reference', help='Join by reference.'),
4559
def run(self, tree, reference=False):
4560
sub_tree = WorkingTree.open(tree)
4561
parent_dir = osutils.dirname(sub_tree.basedir)
4562
containing_tree = WorkingTree.open_containing(parent_dir)[0]
4563
repo = containing_tree.branch.repository
4564
if not repo.supports_rich_root():
4565
raise errors.BzrCommandError(
4566
"Can't join trees because %s doesn't support rich root data.\n"
4567
"You can use bzr upgrade on the repository."
4571
containing_tree.add_reference(sub_tree)
4572
except errors.BadReferenceTarget, e:
4573
# XXX: Would be better to just raise a nicely printable
4574
# exception from the real origin. Also below. mbp 20070306
4575
raise errors.BzrCommandError("Cannot join %s. %s" %
4579
containing_tree.subsume(sub_tree)
4580
except errors.BadSubsumeSource, e:
4581
raise errors.BzrCommandError("Cannot join %s. %s" %
4585
class cmd_split(Command):
4586
"""Split a subdirectory of a tree into a separate tree.
4588
This command will produce a target tree in a format that supports
4589
rich roots, like 'rich-root' or 'rich-root-pack'. These formats cannot be
4590
converted into earlier formats like 'dirstate-tags'.
4592
The TREE argument should be a subdirectory of a working tree. That
4593
subdirectory will be converted into an independent tree, with its own
4594
branch. Commits in the top-level tree will not apply to the new subtree.
4597
# join is not un-hidden yet
4598
#_see_also = ['join']
4599
takes_args = ['tree']
4601
def run(self, tree):
4602
containing_tree, subdir = WorkingTree.open_containing(tree)
4603
sub_id = containing_tree.path2id(subdir)
4605
raise errors.NotVersionedError(subdir)
4607
containing_tree.extract(sub_id)
4608
except errors.RootNotRich:
4609
raise errors.UpgradeRequired(containing_tree.branch.base)
4612
class cmd_merge_directive(Command):
4613
"""Generate a merge directive for auto-merge tools.
4615
A directive requests a merge to be performed, and also provides all the
4616
information necessary to do so. This means it must either include a
4617
revision bundle, or the location of a branch containing the desired
4620
A submit branch (the location to merge into) must be supplied the first
4621
time the command is issued. After it has been supplied once, it will
4622
be remembered as the default.
4624
A public branch is optional if a revision bundle is supplied, but required
4625
if --diff or --plain is specified. It will be remembered as the default
4626
after the first use.
4629
takes_args = ['submit_branch?', 'public_branch?']
4633
_see_also = ['send']
4636
RegistryOption.from_kwargs('patch-type',
4637
'The type of patch to include in the directive.',
4639
value_switches=True,
4641
bundle='Bazaar revision bundle (default).',
4642
diff='Normal unified diff.',
4643
plain='No patch, just directive.'),
4644
Option('sign', help='GPG-sign the directive.'), 'revision',
4645
Option('mail-to', type=str,
4646
help='Instead of printing the directive, email to this address.'),
4647
Option('message', type=str, short_name='m',
4648
help='Message to use when committing this merge.')
4651
encoding_type = 'exact'
4653
def run(self, submit_branch=None, public_branch=None, patch_type='bundle',
4654
sign=False, revision=None, mail_to=None, message=None):
4655
from bzrlib.revision import ensure_null, NULL_REVISION
4656
include_patch, include_bundle = {
4657
'plain': (False, False),
4658
'diff': (True, False),
4659
'bundle': (True, True),
4661
branch = Branch.open('.')
4662
stored_submit_branch = branch.get_submit_branch()
4663
if submit_branch is None:
4664
submit_branch = stored_submit_branch
4666
if stored_submit_branch is None:
4667
branch.set_submit_branch(submit_branch)
4668
if submit_branch is None:
4669
submit_branch = branch.get_parent()
4670
if submit_branch is None:
4671
raise errors.BzrCommandError('No submit branch specified or known')
4673
stored_public_branch = branch.get_public_branch()
4674
if public_branch is None:
4675
public_branch = stored_public_branch
4676
elif stored_public_branch is None:
4677
branch.set_public_branch(public_branch)
4678
if not include_bundle and public_branch is None:
4679
raise errors.BzrCommandError('No public branch specified or'
4681
base_revision_id = None
4682
if revision is not None:
4683
if len(revision) > 2:
4684
raise errors.BzrCommandError('bzr merge-directive takes '
4685
'at most two one revision identifiers')
4686
revision_id = revision[-1].as_revision_id(branch)
4687
if len(revision) == 2:
4688
base_revision_id = revision[0].as_revision_id(branch)
4690
revision_id = branch.last_revision()
4691
revision_id = ensure_null(revision_id)
4692
if revision_id == NULL_REVISION:
4693
raise errors.BzrCommandError('No revisions to bundle.')
4694
directive = merge_directive.MergeDirective2.from_objects(
4695
branch.repository, revision_id, time.time(),
4696
osutils.local_time_offset(), submit_branch,
4697
public_branch=public_branch, include_patch=include_patch,
4698
include_bundle=include_bundle, message=message,
4699
base_revision_id=base_revision_id)
4702
self.outf.write(directive.to_signed(branch))
4704
self.outf.writelines(directive.to_lines())
4706
message = directive.to_email(mail_to, branch, sign)
4707
s = SMTPConnection(branch.get_config())
4708
s.send_email(message)
4711
class cmd_send(Command):
4712
"""Mail or create a merge-directive for submitting changes.
4714
A merge directive provides many things needed for requesting merges:
4716
* A machine-readable description of the merge to perform
4718
* An optional patch that is a preview of the changes requested
4720
* An optional bundle of revision data, so that the changes can be applied
4721
directly from the merge directive, without retrieving data from a
4724
If --no-bundle is specified, then public_branch is needed (and must be
4725
up-to-date), so that the receiver can perform the merge using the
4726
public_branch. The public_branch is always included if known, so that
4727
people can check it later.
4729
The submit branch defaults to the parent, but can be overridden. Both
4730
submit branch and public branch will be remembered if supplied.
4732
If a public_branch is known for the submit_branch, that public submit
4733
branch is used in the merge instructions. This means that a local mirror
4734
can be used as your actual submit branch, once you have set public_branch
4737
Mail is sent using your preferred mail program. This should be transparent
4738
on Windows (it uses MAPI). On Linux, it requires the xdg-email utility.
4739
If the preferred client can't be found (or used), your editor will be used.
4741
To use a specific mail program, set the mail_client configuration option.
4742
(For Thunderbird 1.5, this works around some bugs.) Supported values for
4743
specific clients are "claws", "evolution", "kmail", "mutt", and
4744
"thunderbird"; generic options are "default", "editor", "emacsclient",
4745
"mapi", and "xdg-email". Plugins may also add supported clients.
4747
If mail is being sent, a to address is required. This can be supplied
4748
either on the commandline, by setting the submit_to configuration
4749
option in the branch itself or the child_submit_to configuration option
4750
in the submit branch.
4752
Two formats are currently supported: "4" uses revision bundle format 4 and
4753
merge directive format 2. It is significantly faster and smaller than
4754
older formats. It is compatible with Bazaar 0.19 and later. It is the
4755
default. "0.9" uses revision bundle format 0.9 and merge directive
4756
format 1. It is compatible with Bazaar 0.12 - 0.18.
4758
The merge directives created by bzr send may be applied using bzr merge or
4759
bzr pull by specifying a file containing a merge directive as the location.
4762
encoding_type = 'exact'
4764
_see_also = ['merge', 'pull']
4766
takes_args = ['submit_branch?', 'public_branch?']
4770
help='Do not include a bundle in the merge directive.'),
4771
Option('no-patch', help='Do not include a preview patch in the merge'
4774
help='Remember submit and public branch.'),
4776
help='Branch to generate the submission from, '
4777
'rather than the one containing the working directory.',
4780
Option('output', short_name='o',
4781
help='Write merge directive to this file; '
4782
'use - for stdout.',
4784
Option('mail-to', help='Mail the request to this address.',
4788
Option('body', help='Body for the email.', type=unicode),
4789
RegistryOption.from_kwargs('format',
4790
'Use the specified output format.',
4791
**{'4': 'Bundle format 4, Merge Directive 2 (default)',
4792
'0.9': 'Bundle format 0.9, Merge Directive 1',})
4795
def run(self, submit_branch=None, public_branch=None, no_bundle=False,
4796
no_patch=False, revision=None, remember=False, output=None,
4797
format='4', mail_to=None, message=None, body=None, **kwargs):
4798
return self._run(submit_branch, revision, public_branch, remember,
4799
format, no_bundle, no_patch, output,
4800
kwargs.get('from', '.'), mail_to, message, body)
4802
def _run(self, submit_branch, revision, public_branch, remember, format,
4803
no_bundle, no_patch, output, from_, mail_to, message, body):
4804
from bzrlib.revision import NULL_REVISION
4805
branch = Branch.open_containing(from_)[0]
4807
outfile = cStringIO.StringIO()
4811
outfile = open(output, 'wb')
4812
# we may need to write data into branch's repository to calculate
4817
config = branch.get_config()
4819
mail_to = config.get_user_option('submit_to')
4820
mail_client = config.get_mail_client()
4821
if (not getattr(mail_client, 'supports_body', False)
4822
and body is not None):
4823
raise errors.BzrCommandError(
4824
'Mail client "%s" does not support specifying body' %
4825
mail_client.__class__.__name__)
4826
if remember and submit_branch is None:
4827
raise errors.BzrCommandError(
4828
'--remember requires a branch to be specified.')
4829
stored_submit_branch = branch.get_submit_branch()
4830
remembered_submit_branch = None
4831
if submit_branch is None:
4832
submit_branch = stored_submit_branch
4833
remembered_submit_branch = "submit"
4835
if stored_submit_branch is None or remember:
4836
branch.set_submit_branch(submit_branch)
4837
if submit_branch is None:
4838
submit_branch = branch.get_parent()
4839
remembered_submit_branch = "parent"
4840
if submit_branch is None:
4841
raise errors.BzrCommandError('No submit branch known or'
4843
if remembered_submit_branch is not None:
4844
note('Using saved %s location "%s" to determine what '
4845
'changes to submit.', remembered_submit_branch,
4849
submit_config = Branch.open(submit_branch).get_config()
4850
mail_to = submit_config.get_user_option("child_submit_to")
4852
stored_public_branch = branch.get_public_branch()
4853
if public_branch is None:
4854
public_branch = stored_public_branch
4855
elif stored_public_branch is None or remember:
4856
branch.set_public_branch(public_branch)
4857
if no_bundle and public_branch is None:
4858
raise errors.BzrCommandError('No public branch specified or'
4860
base_revision_id = None
4862
if revision is not None:
4863
if len(revision) > 2:
4864
raise errors.BzrCommandError('bzr send takes '
4865
'at most two one revision identifiers')
4866
revision_id = revision[-1].as_revision_id(branch)
4867
if len(revision) == 2:
4868
base_revision_id = revision[0].as_revision_id(branch)
4869
if revision_id is None:
4870
revision_id = branch.last_revision()
4871
if revision_id == NULL_REVISION:
4872
raise errors.BzrCommandError('No revisions to submit.')
4874
directive = merge_directive.MergeDirective2.from_objects(
4875
branch.repository, revision_id, time.time(),
4876
osutils.local_time_offset(), submit_branch,
4877
public_branch=public_branch, include_patch=not no_patch,
4878
include_bundle=not no_bundle, message=message,
4879
base_revision_id=base_revision_id)
4880
elif format == '0.9':
4883
patch_type = 'bundle'
4885
raise errors.BzrCommandError('Format 0.9 does not'
4886
' permit bundle with no patch')
4892
directive = merge_directive.MergeDirective.from_objects(
4893
branch.repository, revision_id, time.time(),
4894
osutils.local_time_offset(), submit_branch,
4895
public_branch=public_branch, patch_type=patch_type,
4898
outfile.writelines(directive.to_lines())
4900
subject = '[MERGE] '
4901
if message is not None:
4904
revision = branch.repository.get_revision(revision_id)
4905
subject += revision.get_summary()
4906
basename = directive.get_disk_name(branch)
4907
mail_client.compose_merge_request(mail_to, subject,
4916
class cmd_bundle_revisions(cmd_send):
4918
"""Create a merge-directive for submitting changes.
4920
A merge directive provides many things needed for requesting merges:
4922
* A machine-readable description of the merge to perform
4924
* An optional patch that is a preview of the changes requested
4926
* An optional bundle of revision data, so that the changes can be applied
4927
directly from the merge directive, without retrieving data from a
4930
If --no-bundle is specified, then public_branch is needed (and must be
4931
up-to-date), so that the receiver can perform the merge using the
4932
public_branch. The public_branch is always included if known, so that
4933
people can check it later.
4935
The submit branch defaults to the parent, but can be overridden. Both
4936
submit branch and public branch will be remembered if supplied.
4938
If a public_branch is known for the submit_branch, that public submit
4939
branch is used in the merge instructions. This means that a local mirror
4940
can be used as your actual submit branch, once you have set public_branch
4943
Two formats are currently supported: "4" uses revision bundle format 4 and
4944
merge directive format 2. It is significantly faster and smaller than
4945
older formats. It is compatible with Bazaar 0.19 and later. It is the
4946
default. "0.9" uses revision bundle format 0.9 and merge directive
4947
format 1. It is compatible with Bazaar 0.12 - 0.18.
4952
help='Do not include a bundle in the merge directive.'),
4953
Option('no-patch', help='Do not include a preview patch in the merge'
4956
help='Remember submit and public branch.'),
4958
help='Branch to generate the submission from, '
4959
'rather than the one containing the working directory.',
4962
Option('output', short_name='o', help='Write directive to this file.',
4965
RegistryOption.from_kwargs('format',
4966
'Use the specified output format.',
4967
**{'4': 'Bundle format 4, Merge Directive 2 (default)',
4968
'0.9': 'Bundle format 0.9, Merge Directive 1',})
4970
aliases = ['bundle']
4972
_see_also = ['send', 'merge']
4976
def run(self, submit_branch=None, public_branch=None, no_bundle=False,
4977
no_patch=False, revision=None, remember=False, output=None,
4978
format='4', **kwargs):
4981
return self._run(submit_branch, revision, public_branch, remember,
4982
format, no_bundle, no_patch, output,
4983
kwargs.get('from', '.'), None, None, None)
4986
class cmd_tag(Command):
4987
"""Create, remove or modify a tag naming a revision.
4989
Tags give human-meaningful names to revisions. Commands that take a -r
4990
(--revision) option can be given -rtag:X, where X is any previously
4993
Tags are stored in the branch. Tags are copied from one branch to another
4994
along when you branch, push, pull or merge.
4996
It is an error to give a tag name that already exists unless you pass
4997
--force, in which case the tag is moved to point to the new revision.
4999
To rename a tag (change the name but keep it on the same revsion), run ``bzr
5000
tag new-name -r tag:old-name`` and then ``bzr tag --delete oldname``.
5003
_see_also = ['commit', 'tags']
5004
takes_args = ['tag_name']
5007
help='Delete this tag rather than placing it.',
5010
help='Branch in which to place the tag.',
5015
help='Replace existing tags.',
5020
def run(self, tag_name,
5026
branch, relpath = Branch.open_containing(directory)
5030
branch.tags.delete_tag(tag_name)
5031
self.outf.write('Deleted tag %s.\n' % tag_name)
5034
if len(revision) != 1:
5035
raise errors.BzrCommandError(
5036
"Tags can only be placed on a single revision, "
5038
revision_id = revision[0].as_revision_id(branch)
5040
revision_id = branch.last_revision()
5041
if (not force) and branch.tags.has_tag(tag_name):
5042
raise errors.TagAlreadyExists(tag_name)
5043
branch.tags.set_tag(tag_name, revision_id)
5044
self.outf.write('Created tag %s.\n' % tag_name)
5049
class cmd_tags(Command):
5052
This command shows a table of tag names and the revisions they reference.
5058
help='Branch whose tags should be displayed.',
5062
RegistryOption.from_kwargs('sort',
5063
'Sort tags by different criteria.', title='Sorting',
5064
alpha='Sort tags lexicographically (default).',
5065
time='Sort tags chronologically.',
5078
branch, relpath = Branch.open_containing(directory)
5080
tags = branch.tags.get_tag_dict().items()
5087
graph = branch.repository.get_graph()
5088
rev1, rev2 = _get_revision_range(revision, branch, self.name())
5089
revid1, revid2 = rev1.rev_id, rev2.rev_id
5090
# only show revisions between revid1 and revid2 (inclusive)
5091
tags = [(tag, revid) for tag, revid in tags if
5092
graph.is_between(revid, revid1, revid2)]
5097
elif sort == 'time':
5099
for tag, revid in tags:
5101
revobj = branch.repository.get_revision(revid)
5102
except errors.NoSuchRevision:
5103
timestamp = sys.maxint # place them at the end
5105
timestamp = revobj.timestamp
5106
timestamps[revid] = timestamp
5107
tags.sort(key=lambda x: timestamps[x[1]])
5109
# [ (tag, revid), ... ] -> [ (tag, dotted_revno), ... ]
5110
revno_map = branch.get_revision_id_to_revno_map()
5111
tags = [ (tag, '.'.join(map(str, revno_map.get(revid, ('?',)))))
5112
for tag, revid in tags ]
5113
for tag, revspec in tags:
5114
self.outf.write('%-20s %s\n' % (tag, revspec))
5117
class cmd_reconfigure(Command):
5118
"""Reconfigure the type of a bzr directory.
5120
A target configuration must be specified.
5122
For checkouts, the bind-to location will be auto-detected if not specified.
5123
The order of preference is
5124
1. For a lightweight checkout, the current bound location.
5125
2. For branches that used to be checkouts, the previously-bound location.
5126
3. The push location.
5127
4. The parent location.
5128
If none of these is available, --bind-to must be specified.
5131
_see_also = ['branches', 'checkouts', 'standalone-trees', 'working-trees']
5132
takes_args = ['location?']
5134
RegistryOption.from_kwargs(
5136
title='Target type',
5137
help='The type to reconfigure the directory to.',
5138
value_switches=True, enum_switch=False,
5139
branch='Reconfigure to be an unbound branch with no working tree.',
5140
tree='Reconfigure to be an unbound branch with a working tree.',
5141
checkout='Reconfigure to be a bound branch with a working tree.',
5142
lightweight_checkout='Reconfigure to be a lightweight'
5143
' checkout (with no local history).',
5144
standalone='Reconfigure to be a standalone branch '
5145
'(i.e. stop using shared repository).',
5146
use_shared='Reconfigure to use a shared repository.',
5147
with_trees='Reconfigure repository to create '
5148
'working trees on branches by default.',
5149
with_no_trees='Reconfigure repository to not create '
5150
'working trees on branches by default.'
5152
Option('bind-to', help='Branch to bind checkout to.', type=str),
5154
help='Perform reconfiguration even if local changes'
5158
def run(self, location=None, target_type=None, bind_to=None, force=False):
5159
directory = bzrdir.BzrDir.open(location)
5160
if target_type is None:
5161
raise errors.BzrCommandError('No target configuration specified')
5162
elif target_type == 'branch':
5163
reconfiguration = reconfigure.Reconfigure.to_branch(directory)
5164
elif target_type == 'tree':
5165
reconfiguration = reconfigure.Reconfigure.to_tree(directory)
5166
elif target_type == 'checkout':
5167
reconfiguration = reconfigure.Reconfigure.to_checkout(
5169
elif target_type == 'lightweight-checkout':
5170
reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
5172
elif target_type == 'use-shared':
5173
reconfiguration = reconfigure.Reconfigure.to_use_shared(directory)
5174
elif target_type == 'standalone':
5175
reconfiguration = reconfigure.Reconfigure.to_standalone(directory)
5176
elif target_type == 'with-trees':
5177
reconfiguration = reconfigure.Reconfigure.set_repository_trees(
5179
elif target_type == 'with-no-trees':
5180
reconfiguration = reconfigure.Reconfigure.set_repository_trees(
5182
reconfiguration.apply(force)
5185
class cmd_switch(Command):
5186
"""Set the branch of a checkout and update.
5188
For lightweight checkouts, this changes the branch being referenced.
5189
For heavyweight checkouts, this checks that there are no local commits
5190
versus the current bound branch, then it makes the local branch a mirror
5191
of the new location and binds to it.
5193
In both cases, the working tree is updated and uncommitted changes
5194
are merged. The user can commit or revert these as they desire.
5196
Pending merges need to be committed or reverted before using switch.
5198
The path to the branch to switch to can be specified relative to the parent
5199
directory of the current branch. For example, if you are currently in a
5200
checkout of /path/to/branch, specifying 'newbranch' will find a branch at
5203
Bound branches use the nickname of its master branch unless it is set
5204
locally, in which case switching will update the the local nickname to be
5208
takes_args = ['to_location']
5209
takes_options = [Option('force',
5210
help='Switch even if local commits will be lost.')
5213
def run(self, to_location, force=False):
5214
from bzrlib import switch
5216
control_dir = bzrdir.BzrDir.open_containing(tree_location)[0]
5217
branch = control_dir.open_branch()
5219
to_branch = Branch.open(to_location)
5220
except errors.NotBranchError:
5221
this_branch = control_dir.open_branch()
5222
# This may be a heavy checkout, where we want the master branch
5223
this_url = this_branch.get_bound_location()
5224
# If not, use a local sibling
5225
if this_url is None:
5226
this_url = this_branch.base
5227
to_branch = Branch.open(
5228
urlutils.join(this_url, '..', to_location))
5229
switch.switch(control_dir, to_branch, force)
5230
if branch.get_config().has_explicit_nickname():
5231
branch = control_dir.open_branch() #get the new branch!
5232
branch.nick = to_branch.nick
5233
note('Switched to branch: %s',
5234
urlutils.unescape_for_display(to_branch.base, 'utf-8'))
5237
class cmd_guess_renames(Command):
5238
"""Guess which files have been have been renamed, based on their content.
5240
Only versioned files which have been deleted are candidates for rename
5241
detection, and renames to ignored files will not be detected.
5245
work_tree, file_list = tree_files(None, default_branch='.')
5246
work_tree.lock_write()
5248
rename_map.RenameMap.guess_renames(work_tree)
5253
class cmd_view(Command):
5254
"""Manage filtered views.
5256
Views provide a mask over the tree so that users can focus on
5257
a subset of a tree when doing their work. After creating a view,
5258
commands that support a list of files - status, diff, commit, etc -
5259
effectively have that list of files implicitly given each time.
5260
An explicit list of files can still be given but those files
5261
must be within the current view.
5263
In most cases, a view has a short life-span: it is created to make
5264
a selected change and is deleted once that change is committed.
5265
At other times, you may wish to create one or more named views
5266
and switch between them.
5268
To disable the current view without deleting it, you can switch to
5269
the pseudo view called ``off``. This can be useful when you need
5270
to see the whole tree for an operation or two (e.g. merge) but
5271
want to switch back to your view after that.
5274
To define the current view::
5276
bzr view file1 dir1 ...
5278
To list the current view::
5282
To delete the current view::
5286
To disable the current view without deleting it::
5288
bzr view --switch off
5290
To define a named view and switch to it::
5292
bzr view --name view-name file1 dir1 ...
5294
To list a named view::
5296
bzr view --name view-name
5298
To delete a named view::
5300
bzr view --name view-name --delete
5302
To switch to a named view::
5304
bzr view --switch view-name
5306
To list all views defined::
5310
To delete all views::
5312
bzr view --delete --all
5316
takes_args = ['file*']
5319
help='Apply list or delete action to all views.',
5322
help='Delete the view.',
5325
help='Name of the view to define, list or delete.',
5329
help='Name of the view to switch to.',
5334
def run(self, file_list,
5340
tree, file_list = tree_files(file_list, apply_view=False)
5341
current_view, view_dict = tree.views.get_view_info()
5346
raise errors.BzrCommandError(
5347
"Both --delete and a file list specified")
5349
raise errors.BzrCommandError(
5350
"Both --delete and --switch specified")
5352
tree.views.set_view_info(None, {})
5353
self.outf.write("Deleted all views.\n")
5355
raise errors.BzrCommandError("No current view to delete")
5357
tree.views.delete_view(name)
5358
self.outf.write("Deleted '%s' view.\n" % name)
5361
raise errors.BzrCommandError(
5362
"Both --switch and a file list specified")
5364
raise errors.BzrCommandError(
5365
"Both --switch and --all specified")
5366
elif switch == 'off':
5367
if current_view is None:
5368
raise errors.BzrCommandError("No current view to disable")
5369
tree.views.set_view_info(None, view_dict)
5370
self.outf.write("Disabled '%s' view.\n" % (current_view))
5372
tree.views.set_view_info(switch, view_dict)
5373
view_str = views.view_display_str(tree.views.lookup_view())
5374
self.outf.write("Using '%s' view: %s\n" % (switch, view_str))
5377
self.outf.write('Views defined:\n')
5378
for view in sorted(view_dict):
5379
if view == current_view:
5383
view_str = views.view_display_str(view_dict[view])
5384
self.outf.write('%s %-20s %s\n' % (active, view, view_str))
5386
self.outf.write('No views defined.\n')
5389
# No name given and no current view set
5392
raise errors.BzrCommandError(
5393
"Cannot change the 'off' pseudo view")
5394
tree.views.set_view(name, sorted(file_list))
5395
view_str = views.view_display_str(tree.views.lookup_view())
5396
self.outf.write("Using '%s' view: %s\n" % (name, view_str))
5400
# No name given and no current view set
5401
self.outf.write('No current view.\n')
5403
view_str = views.view_display_str(tree.views.lookup_view(name))
5404
self.outf.write("'%s' view is: %s\n" % (name, view_str))
5407
class cmd_hooks(Command):
5413
for hook_key in sorted(hooks.known_hooks.keys()):
5414
some_hooks = hooks.known_hooks_key_to_object(hook_key)
5415
self.outf.write("%s:\n" % type(some_hooks).__name__)
5416
for hook_name, hook_point in sorted(some_hooks.items()):
5417
self.outf.write(" %s:\n" % (hook_name,))
5418
found_hooks = list(hook_point)
5420
for hook in found_hooks:
5421
self.outf.write(" %s\n" %
5422
(some_hooks.get_hook_name(hook),))
5424
self.outf.write(" <no hooks installed>\n")
5427
class cmd_shelve(Command):
5428
"""Temporarily set aside some changes from the current tree.
5430
Shelve allows you to temporarily put changes you've made "on the shelf",
5431
ie. out of the way, until a later time when you can bring them back from
5432
the shelf with the 'unshelve' command. The changes are stored alongside
5433
your working tree, and so they aren't propagated along with your branch nor
5434
will they survive its deletion.
5436
If shelve --list is specified, previously-shelved changes are listed.
5438
Shelve is intended to help separate several sets of changes that have
5439
been inappropriately mingled. If you just want to get rid of all changes
5440
and you don't need to restore them later, use revert. If you want to
5441
shelve all text changes at once, use shelve --all.
5443
If filenames are specified, only the changes to those files will be
5444
shelved. Other files will be left untouched.
5446
If a revision is specified, changes since that revision will be shelved.
5448
You can put multiple items on the shelf, and by default, 'unshelve' will
5449
restore the most recently shelved changes.
5452
takes_args = ['file*']
5456
Option('all', help='Shelve all changes.'),
5458
RegistryOption('writer', 'Method to use for writing diffs.',
5459
bzrlib.option.diff_writer_registry,
5460
value_switches=True, enum_switch=False),
5462
Option('list', help='List shelved changes.'),
5464
help='Destroy removed changes instead of shelving them.'),
5466
_see_also = ['unshelve']
5468
def run(self, revision=None, all=False, file_list=None, message=None,
5469
writer=None, list=False, destroy=False):
5471
return self.run_for_list()
5472
from bzrlib.shelf_ui import Shelver
5474
writer = bzrlib.option.diff_writer_registry.get()
5476
Shelver.from_args(writer(sys.stdout), revision, all, file_list,
5477
message, destroy=destroy).run()
5478
except errors.UserAbort:
2827
merger.backup_files = backup_files
2828
merger.merge_type = merge_type
2829
merger.set_interesting_files(file_list)
2830
merger.show_base = show_base
2831
merger.reprocess = reprocess
2832
conflicts = merger.do_merge()
2833
if file_list is None:
2834
merger.set_pending()
5481
def run_for_list(self):
5482
tree = WorkingTree.open_containing('.')[0]
5485
manager = tree.get_shelf_manager()
5486
shelves = manager.active_shelves()
5487
if len(shelves) == 0:
5488
note('No shelved changes.')
5490
for shelf_id in reversed(shelves):
5491
message = manager.get_metadata(shelf_id).get('message')
5493
message = '<no message>'
5494
self.outf.write('%3d: %s\n' % (shelf_id, message))
5500
class cmd_unshelve(Command):
5501
"""Restore shelved changes.
5503
By default, the most recently shelved changes are restored. However if you
5504
specify a shelf by id those changes will be restored instead. This works
5505
best when the changes don't depend on each other.
5508
takes_args = ['shelf_id?']
5510
RegistryOption.from_kwargs(
5511
'action', help="The action to perform.",
5512
enum_switch=False, value_switches=True,
5513
apply="Apply changes and remove from the shelf.",
5514
dry_run="Show changes, but do not apply or remove them.",
5515
delete_only="Delete changes without applying them."
5518
_see_also = ['shelve']
5520
def run(self, shelf_id=None, action='apply'):
5521
from bzrlib.shelf_ui import Unshelver
5522
Unshelver.from_args(shelf_id, action).run()
5525
class cmd_clean_tree(Command):
5526
"""Remove unwanted files from working tree.
5528
By default, only unknown files, not ignored files, are deleted. Versioned
5529
files are never deleted.
5531
Another class is 'detritus', which includes files emitted by bzr during
5532
normal operations and selftests. (The value of these files decreases with
5535
If no options are specified, unknown files are deleted. Otherwise, option
5536
flags are respected, and may be combined.
5538
To check what clean-tree will do, use --dry-run.
5540
takes_options = [Option('ignored', help='Delete all ignored files.'),
5541
Option('detritus', help='Delete conflict files, merge'
5542
' backups, and failed selftest dirs.'),
5544
help='Delete files unknown to bzr (default).'),
5545
Option('dry-run', help='Show files to delete instead of'
5547
Option('force', help='Do not prompt before deleting.')]
5548
def run(self, unknown=False, ignored=False, detritus=False, dry_run=False,
5550
from bzrlib.clean_tree import clean_tree
5551
if not (unknown or ignored or detritus):
5555
clean_tree('.', unknown=unknown, ignored=ignored, detritus=detritus,
5556
dry_run=dry_run, no_prompt=force)
5559
def _create_prefix(cur_transport):
5560
needed = [cur_transport]
5561
# Recurse upwards until we can create a directory successfully
5563
new_transport = cur_transport.clone('..')
5564
if new_transport.base == cur_transport.base:
5565
raise errors.BzrCommandError(
5566
"Failed to create path prefix for %s."
5567
% cur_transport.base)
5569
new_transport.mkdir('.')
5570
except errors.NoSuchFile:
5571
needed.append(new_transport)
5572
cur_transport = new_transport
5575
# Now we only need to create child directories
5577
cur_transport = needed.pop()
5578
cur_transport.ensure_base()
2840
5581
# these get imported and then picked up by the scan for cmd_*
2841
5582
# TODO: Some more consistent way to split command definitions across files;
2842
# we do need to load at least some information about them to know of
5583
# we do need to load at least some information about them to know of
2843
5584
# aliases. ideally we would avoid loading the implementation until the
2844
5585
# details were needed.
5586
from bzrlib.cmd_version_info import cmd_version_info
2845
5587
from bzrlib.conflicts import cmd_resolve, cmd_conflicts, restore
2846
from bzrlib.bundle.commands import cmd_bundle_revisions
5588
from bzrlib.bundle.commands import (
2847
5591
from bzrlib.sign_my_commits import cmd_sign_my_commits
2848
from bzrlib.weave_commands import cmd_weave_list, cmd_weave_join, \
5592
from bzrlib.weave_commands import cmd_versionedfile_list, \
2849
5593
cmd_weave_plan_merge, cmd_weave_merge_text