705
604
location can be accessed.
708
_see_also = ['pull', 'update', 'working-trees']
709
takes_options = ['remember', 'overwrite', 'verbose', 'revision',
710
Option('create-prefix',
711
help='Create the path leading up to the branch '
712
'if it does not already exist.'),
714
help='Branch to push from, '
715
'rather than the one containing the working directory.',
719
Option('use-existing-dir',
720
help='By default push will fail if the target'
721
' directory exists, but does not already'
722
' have a control directory. This flag will'
723
' allow push to proceed.'),
725
help='Create a stacked branch that references the public location '
726
'of the parent branch.'),
728
help='Create a stacked branch that refers to another branch '
729
'for the commit history. Only the work not present in the '
730
'referenced branch is included in the branch created.',
607
takes_options = ['remember', 'overwrite', 'verbose',
608
Option('create-prefix',
609
help='Create the path leading up to the branch '
610
'if it does not already exist')]
733
611
takes_args = ['location?']
734
612
encoding_type = 'replace'
736
614
def run(self, location=None, remember=False, overwrite=False,
737
create_prefix=False, verbose=False, revision=None,
738
use_existing_dir=False, directory=None, stacked_on=None,
740
from bzrlib.push import _show_push_branch
742
# Get the source branch and revision_id
743
if directory is None:
745
br_from = Branch.open_containing(directory)[0]
746
if revision is not None:
747
if len(revision) == 1:
748
revision_id = revision[0].in_history(br_from).rev_id
750
raise errors.BzrCommandError(
751
'bzr push --revision takes one value.')
753
revision_id = br_from.last_revision()
755
# Get the stacked_on branch, if any
756
if stacked_on is not None:
757
stacked_on = urlutils.normalize_url(stacked_on)
759
parent_url = br_from.get_parent()
761
parent = Branch.open(parent_url)
762
stacked_on = parent.get_public_branch()
764
# I considered excluding non-http url's here, thus forcing
765
# 'public' branches only, but that only works for some
766
# users, so it's best to just depend on the user spotting an
767
# error by the feedback given to them. RBC 20080227.
768
stacked_on = parent_url
770
raise errors.BzrCommandError(
771
"Could not determine branch to refer to.")
773
# Get the destination location
615
create_prefix=False, verbose=False):
616
# FIXME: Way too big! Put this into a function called from the
619
br_from = Branch.open_containing('.')[0]
620
stored_loc = br_from.get_push_location()
774
621
if location is None:
775
stored_loc = br_from.get_push_location()
776
622
if stored_loc is None:
777
raise errors.BzrCommandError(
778
"No push location known or specified.")
623
raise errors.BzrCommandError("No push location known or specified.")
780
625
display_url = urlutils.unescape_for_display(stored_loc,
781
626
self.outf.encoding)
782
627
self.outf.write("Using saved location: %s\n" % display_url)
783
628
location = stored_loc
785
_show_push_branch(br_from, revision_id, location, self.outf,
786
verbose=verbose, overwrite=overwrite, remember=remember,
787
stacked_on=stacked_on, create_prefix=create_prefix,
788
use_existing_dir=use_existing_dir)
630
to_transport = transport.get_transport(location)
631
location_url = to_transport.base
635
dir_to = bzrdir.BzrDir.open(location_url)
636
br_to = dir_to.open_branch()
637
except errors.NotBranchError:
639
to_transport = to_transport.clone('..')
640
if not create_prefix:
642
relurl = to_transport.relpath(location_url)
643
mutter('creating directory %s => %s', location_url, relurl)
644
to_transport.mkdir(relurl)
645
except errors.NoSuchFile:
646
raise errors.BzrCommandError("Parent directory of %s "
647
"does not exist." % location)
649
current = to_transport.base
650
needed = [(to_transport, to_transport.relpath(location_url))]
653
to_transport, relpath = needed[-1]
654
to_transport.mkdir(relpath)
656
except errors.NoSuchFile:
657
new_transport = to_transport.clone('..')
658
needed.append((new_transport,
659
new_transport.relpath(to_transport.base)))
660
if new_transport.base == to_transport.base:
661
raise errors.BzrCommandError("Could not create "
663
dir_to = br_from.bzrdir.clone(location_url,
664
revision_id=br_from.last_revision())
665
br_to = dir_to.open_branch()
666
count = br_to.last_revision_info()[0]
667
# We successfully created the target, remember it
668
if br_from.get_push_location() is None or remember:
669
br_from.set_push_location(br_to.base)
671
# We were able to connect to the remote location, so remember it
672
# we don't need to successfully push because of possible divergence.
673
if br_from.get_push_location() is None or remember:
674
br_from.set_push_location(br_to.base)
675
old_rh = br_to.revision_history()
678
tree_to = dir_to.open_workingtree()
679
except errors.NotLocalUrl:
680
warning('This transport does not update the working '
681
'tree of: %s' % (br_to.base,))
682
count = br_from.push(br_to, overwrite)
683
except errors.NoWorkingTree:
684
count = br_from.push(br_to, overwrite)
688
count = br_from.push(tree_to.branch, overwrite)
692
except errors.DivergedBranches:
693
raise errors.BzrCommandError('These branches have diverged.'
694
' Try using "merge" and then "push".')
695
note('%d revision(s) pushed.' % (count,))
698
new_rh = br_to.revision_history()
701
from bzrlib.log import show_changed_revisions
702
show_changed_revisions(br_to, old_rh, new_rh,
791
706
class cmd_branch(Command):
2760
2267
default, use --remember. The value will only be saved if the remote
2761
2268
location can be accessed.
2763
The results of the merge are placed into the destination working
2764
directory, where they can be reviewed (with bzr diff), tested, and then
2765
committed to record the result of the merge.
2272
To merge the latest revision from bzr.dev
2273
bzr merge ../bzr.dev
2275
To merge changes up to and including revision 82 from bzr.dev
2276
bzr merge -r 82 ../bzr.dev
2278
To merge the changes introduced by 82, without previous changes:
2279
bzr merge -r 81..82 ../bzr.dev
2767
2281
merge refuses to run if there are any uncommitted changes, unless
2768
2282
--force is given.
2771
To merge the latest revision from bzr.dev::
2773
bzr merge ../bzr.dev
2775
To merge changes up to and including revision 82 from bzr.dev::
2777
bzr merge -r 82 ../bzr.dev
2779
To merge the changes introduced by 82, without previous changes::
2781
bzr merge -r 81..82 ../bzr.dev
2783
To apply a merge directive contained in in /tmp/merge:
2785
bzr merge /tmp/merge
2284
The following merge types are available:
2788
encoding_type = 'exact'
2789
_see_also = ['update', 'remerge', 'status-flags']
2790
takes_args = ['location?']
2795
help='Merge even if the destination tree has uncommitted changes.'),
2799
Option('show-base', help="Show base revision text in "
2801
Option('uncommitted', help='Apply uncommitted changes'
2802
' from a working copy, instead of branch changes.'),
2803
Option('pull', help='If the destination is already'
2804
' completely merged into the source, pull from the'
2805
' source rather than merging. When this happens,'
2806
' you do not need to commit the result.'),
2808
help='Branch to merge into, '
2809
'rather than the one containing the working directory.',
2813
Option('preview', help='Instead of merging, show a diff of the merge.')
2816
def run(self, location=None, revision=None, force=False,
2817
merge_type=None, show_base=False, reprocess=False, remember=False,
2818
uncommitted=False, pull=False,
2286
takes_args = ['branch?']
2287
takes_options = ['revision', 'force', 'merge-type', 'reprocess', 'remember',
2288
Option('show-base', help="Show base revision text in "
2290
Option('uncommitted', help='Apply uncommitted changes'
2291
' from a working copy, instead of branch changes'),
2292
Option('pull', help='If the destination is already'
2293
' completely merged into the source, pull from the'
2294
' source rather than merging. When this happens,'
2295
' you do not need to commit the result.'),
2299
from inspect import getdoc
2300
return getdoc(self) + '\n' + _mod_merge.merge_type_help()
2302
def run(self, branch=None, revision=None, force=False, merge_type=None,
2303
show_base=False, reprocess=False, remember=False,
2304
uncommitted=False, pull=False):
2822
2305
if merge_type is None:
2823
2306
merge_type = _mod_merge.Merge3Merger
2825
if directory is None: directory = u'.'
2826
possible_transports = []
2828
allow_pending = True
2829
verified = 'inapplicable'
2830
tree = WorkingTree.open_containing(directory)[0]
2831
change_reporter = delta._ChangeReporter(
2832
unversioned_filter=tree.is_ignored)
2835
pb = ui.ui_factory.nested_progress_bar()
2836
cleanups.append(pb.finished)
2838
cleanups.append(tree.unlock)
2839
if location is not None:
2841
mergeable = bundle.read_mergeable_from_url(location,
2842
possible_transports=possible_transports)
2843
except errors.NotABundle:
2308
tree = WorkingTree.open_containing(u'.')[0]
2310
if branch is not None:
2312
reader = bundle.read_bundle_from_url(branch)
2313
except errors.NotABundle:
2314
pass # Continue on considering this url a Branch
2316
conflicts = merge_bundle(reader, tree, not force, merge_type,
2317
reprocess, show_base)
2847
raise errors.BzrCommandError('Cannot use --uncommitted'
2848
' with bundles or merge directives.')
2850
if revision is not None:
2851
raise errors.BzrCommandError(
2852
'Cannot use -r with merge directives or bundles')
2853
merger, verified = _mod_merge.Merger.from_mergeable(tree,
2856
if merger is None and uncommitted:
2857
if revision is not None and len(revision) > 0:
2858
raise errors.BzrCommandError('Cannot use --uncommitted and'
2859
' --revision at the same time.')
2860
location = self._select_branch_location(tree, location)[0]
2861
other_tree, other_path = WorkingTree.open_containing(location)
2862
merger = _mod_merge.Merger.from_uncommitted(tree, other_tree,
2864
allow_pending = False
2865
if other_path != '':
2866
merger.interesting_files = [other_path]
2869
merger, allow_pending = self._get_merger_from_branch(tree,
2870
location, revision, remember, possible_transports, pb)
2872
merger.merge_type = merge_type
2873
merger.reprocess = reprocess
2874
merger.show_base = show_base
2875
self.sanity_check_merger(merger)
2876
if (merger.base_rev_id == merger.other_rev_id and
2877
merger.other_rev_id is not None):
2878
note('Nothing to do.')
2323
if revision is None \
2324
or len(revision) < 1 or revision[0].needs_branch():
2325
branch = self._get_remembered_parent(tree, branch, 'Merging from')
2327
if revision is None or len(revision) < 1:
2330
other = [branch, None]
2333
other = [branch, -1]
2334
other_branch, path = Branch.open_containing(branch)
2337
raise errors.BzrCommandError('Cannot use --uncommitted and'
2338
' --revision at the same time.')
2339
branch = revision[0].get_branch() or branch
2340
if len(revision) == 1:
2342
other_branch, path = Branch.open_containing(branch)
2343
revno = revision[0].in_history(other_branch).revno
2344
other = [branch, revno]
2346
assert len(revision) == 2
2347
if None in revision:
2348
raise errors.BzrCommandError(
2349
"Merge doesn't permit empty revision specifier.")
2350
base_branch, path = Branch.open_containing(branch)
2351
branch1 = revision[1].get_branch() or branch
2352
other_branch, path1 = Branch.open_containing(branch1)
2353
if revision[0].get_branch() is not None:
2354
# then path was obtained from it, and is None.
2357
base = [branch, revision[0].in_history(base_branch).revno]
2358
other = [branch1, revision[1].in_history(other_branch).revno]
2360
if tree.branch.get_parent() is None or remember:
2361
tree.branch.set_parent(other_branch.base)
2364
interesting_files = [path]
2366
interesting_files = None
2367
pb = ui.ui_factory.nested_progress_bar()
2370
conflict_count = _merge_helper(
2371
other, base, check_clean=(not force),
2372
merge_type=merge_type,
2373
reprocess=reprocess,
2374
show_base=show_base,
2376
pb=pb, file_list=interesting_files)
2379
if conflict_count != 0:
2881
if merger.interesting_files is not None:
2882
raise errors.BzrCommandError('Cannot pull individual files')
2883
if (merger.base_rev_id == tree.last_revision()):
2884
result = tree.pull(merger.other_branch, False,
2885
merger.other_rev_id)
2886
result.report(self.outf)
2888
merger.check_basis(not force)
2890
return self._do_preview(merger)
2892
return self._do_merge(merger, change_reporter, allow_pending,
2895
for cleanup in reversed(cleanups):
2898
def _do_preview(self, merger):
2899
from bzrlib.diff import show_diff_trees
2900
tree_merger = merger.make_merger()
2901
tt = tree_merger.make_preview_transform()
2903
result_tree = tt.get_preview_tree()
2904
show_diff_trees(merger.this_tree, result_tree, self.outf,
2905
old_label='', new_label='')
2909
def _do_merge(self, merger, change_reporter, allow_pending, verified):
2910
merger.change_reporter = change_reporter
2911
conflict_count = merger.do_merge()
2913
merger.set_pending()
2914
if verified == 'failed':
2915
warning('Preview patch does not match changes')
2916
if conflict_count != 0:
2921
def sanity_check_merger(self, merger):
2922
if (merger.show_base and
2923
not merger.merge_type is _mod_merge.Merge3Merger):
2924
raise errors.BzrCommandError("Show-base is not supported for this"
2925
" merge type. %s" % merger.merge_type)
2926
if merger.reprocess and not merger.merge_type.supports_reprocess:
2927
raise errors.BzrCommandError("Conflict reduction is not supported"
2928
" for merge type %s." %
2930
if merger.reprocess and merger.show_base:
2931
raise errors.BzrCommandError("Cannot do conflict reduction and"
2934
def _get_merger_from_branch(self, tree, location, revision, remember,
2935
possible_transports, pb):
2936
"""Produce a merger from a location, assuming it refers to a branch."""
2937
from bzrlib.tag import _merge_tags_if_possible
2938
# find the branch locations
2939
other_loc, user_location = self._select_branch_location(tree, location,
2941
if revision is not None and len(revision) == 2:
2942
base_loc, _unused = self._select_branch_location(tree,
2943
location, revision, 0)
2945
base_loc = other_loc
2947
other_branch, other_path = Branch.open_containing(other_loc,
2948
possible_transports)
2949
if base_loc == other_loc:
2950
base_branch = other_branch
2952
base_branch, base_path = Branch.open_containing(base_loc,
2953
possible_transports)
2954
# Find the revision ids
2955
if revision is None or len(revision) < 1 or revision[-1] is None:
2956
other_revision_id = _mod_revision.ensure_null(
2957
other_branch.last_revision())
2959
other_revision_id = revision[-1].as_revision_id(other_branch)
2960
if (revision is not None and len(revision) == 2
2961
and revision[0] is not None):
2962
base_revision_id = revision[0].as_revision_id(base_branch)
2964
base_revision_id = None
2965
# Remember where we merge from
2966
if ((remember or tree.branch.get_submit_branch() is None) and
2967
user_location is not None):
2968
tree.branch.set_submit_branch(other_branch.base)
2969
_merge_tags_if_possible(other_branch, tree.branch)
2970
merger = _mod_merge.Merger.from_revision_ids(pb, tree,
2971
other_revision_id, base_revision_id, other_branch, base_branch)
2972
if other_path != '':
2973
allow_pending = False
2974
merger.interesting_files = [other_path]
2976
allow_pending = True
2977
return merger, allow_pending
2979
def _select_branch_location(self, tree, user_location, revision=None,
2981
"""Select a branch location, according to possible inputs.
2983
If provided, branches from ``revision`` are preferred. (Both
2984
``revision`` and ``index`` must be supplied.)
2986
Otherwise, the ``location`` parameter is used. If it is None, then the
2987
``submit`` or ``parent`` location is used, and a note is printed.
2989
:param tree: The working tree to select a branch for merging into
2990
:param location: The location entered by the user
2991
:param revision: The revision parameter to the command
2992
:param index: The index to use for the revision parameter. Negative
2993
indices are permitted.
2994
:return: (selected_location, user_location). The default location
2995
will be the user-entered location.
2997
if (revision is not None and index is not None
2998
and revision[index] is not None):
2999
branch = revision[index].get_branch()
3000
if branch is not None:
3001
return branch, branch
3002
if user_location is None:
3003
location = self._get_remembered(tree, 'Merging from')
3005
location = user_location
3006
return location, user_location
3008
def _get_remembered(self, tree, verb_string):
2383
except errors.AmbiguousBase, e:
2384
m = ("sorry, bzr can't determine the right merge base yet\n"
2385
"candidates are:\n "
2386
+ "\n ".join(e.bases)
2388
"please specify an explicit base with -r,\n"
2389
"and (if you want) report this to the bzr developers\n")
2392
# TODO: move up to common parent; this isn't merge-specific anymore.
2393
def _get_remembered_parent(self, tree, supplied_location, verb_string):
3009
2394
"""Use tree.branch's parent if none was supplied.
3011
2396
Report if the remembered location was used.
3013
stored_location = tree.branch.get_submit_branch()
3014
if stored_location is None:
3015
stored_location = tree.branch.get_parent()
2398
if supplied_location is not None:
2399
return supplied_location
2400
stored_location = tree.branch.get_parent()
3016
2401
mutter("%s", stored_location)
3017
2402
if stored_location is None:
3018
2403
raise errors.BzrCommandError("No location specified or remembered")
3019
display_url = urlutils.unescape_for_display(stored_location, 'utf-8')
3020
note(u"%s remembered location %s", verb_string, display_url)
2404
display_url = urlutils.unescape_for_display(stored_location, self.outf.encoding)
2405
self.outf.write("%s remembered location %s\n" % (verb_string, display_url))
3021
2406
return stored_location
3777
2990
takes_options = [
3779
help='Serve on stdin/out for use from inetd or sshd.'),
2992
help='serve on stdin/out for use from inetd or sshd'),
3781
help='Listen for connections on nominated port of the form '
3782
'[hostname:]portnumber. Passing 0 as the port number will '
3783
'result in a dynamically allocated port. The default port is '
2994
help='listen for connections on nominated port of the form '
2995
'[hostname:]portnumber. Passing 0 as the port number will '
2996
'result in a dynamically allocated port.',
3786
2998
Option('directory',
3787
help='Serve contents of this directory.',
2999
help='serve contents of directory',
3789
3001
Option('allow-writes',
3790
help='By default the server is a readonly server. Supplying '
3002
help='By default the server is a readonly server. Supplying '
3791
3003
'--allow-writes enables write access to the contents of '
3792
'the served directory and below.'
3004
'the served directory and below. '
3796
3008
def run(self, port=None, inet=False, directory=None, allow_writes=False):
3797
from bzrlib import lockdir
3798
from bzrlib.smart import medium, server
3009
from bzrlib.transport import smart
3799
3010
from bzrlib.transport import get_transport
3800
from bzrlib.transport.chroot import ChrootServer
3801
3011
if directory is None:
3802
3012
directory = os.getcwd()
3803
3013
url = urlutils.local_path_to_url(directory)
3804
3014
if not allow_writes:
3805
3015
url = 'readonly+' + url
3806
chroot_server = ChrootServer(get_transport(url))
3807
chroot_server.setUp()
3808
t = get_transport(chroot_server.get_url())
3016
t = get_transport(url)
3810
smart_server = medium.SmartServerPipeStreamMedium(
3811
sys.stdin, sys.stdout, t)
3813
host = medium.BZR_DEFAULT_INTERFACE
3815
port = medium.BZR_DEFAULT_PORT
3018
server = smart.SmartServerPipeStreamMedium(sys.stdin, sys.stdout, t)
3019
elif port is not None:
3021
host, port = port.split(':')
3818
host, port = port.split(':')
3820
smart_server = server.SmartTCPServer(t, host=host, port=port)
3821
print 'listening on port: ', smart_server.port
3024
server = smart.SmartTCPServer(t, host=host, port=int(port))
3025
print 'listening on port: ', server.port
3822
3026
sys.stdout.flush()
3823
# for the duration of this server, no UI output is permitted.
3824
# note that this may cause problems with blackbox tests. This should
3825
# be changed with care though, as we dont want to use bandwidth sending
3826
# progress over stderr to smart server clients!
3827
old_factory = ui.ui_factory
3828
old_lockdir_timeout = lockdir._DEFAULT_TIMEOUT_SECONDS
3830
ui.ui_factory = ui.SilentUIFactory()
3831
lockdir._DEFAULT_TIMEOUT_SECONDS = 0
3832
smart_server.serve()
3834
ui.ui_factory = old_factory
3835
lockdir._DEFAULT_TIMEOUT_SECONDS = old_lockdir_timeout
3838
class cmd_join(Command):
3839
"""Combine a subtree into its containing tree.
3841
This command is for experimental use only. It requires the target tree
3842
to be in dirstate-with-subtree format, which cannot be converted into
3845
The TREE argument should be an independent tree, inside another tree, but
3846
not part of it. (Such trees can be produced by "bzr split", but also by
3847
running "bzr branch" with the target inside a tree.)
3849
The result is a combined tree, with the subtree no longer an independant
3850
part. This is marked as a merge of the subtree into the containing tree,
3851
and all history is preserved.
3853
If --reference is specified, the subtree retains its independence. It can
3854
be branched by itself, and can be part of multiple projects at the same
3855
time. But operations performed in the containing tree, such as commit
3856
and merge, will recurse into the subtree.
3859
_see_also = ['split']
3860
takes_args = ['tree']
3862
Option('reference', help='Join by reference.'),
3866
def run(self, tree, reference=False):
3867
sub_tree = WorkingTree.open(tree)
3868
parent_dir = osutils.dirname(sub_tree.basedir)
3869
containing_tree = WorkingTree.open_containing(parent_dir)[0]
3870
repo = containing_tree.branch.repository
3871
if not repo.supports_rich_root():
3872
raise errors.BzrCommandError(
3873
"Can't join trees because %s doesn't support rich root data.\n"
3874
"You can use bzr upgrade on the repository."
3878
containing_tree.add_reference(sub_tree)
3879
except errors.BadReferenceTarget, e:
3880
# XXX: Would be better to just raise a nicely printable
3881
# exception from the real origin. Also below. mbp 20070306
3882
raise errors.BzrCommandError("Cannot join %s. %s" %
3886
containing_tree.subsume(sub_tree)
3887
except errors.BadSubsumeSource, e:
3888
raise errors.BzrCommandError("Cannot join %s. %s" %
3892
class cmd_split(Command):
3893
"""Split a subdirectory of a tree into a separate tree.
3895
This command will produce a target tree in a format that supports
3896
rich roots, like 'rich-root' or 'rich-root-pack'. These formats cannot be
3897
converted into earlier formats like 'dirstate-tags'.
3899
The TREE argument should be a subdirectory of a working tree. That
3900
subdirectory will be converted into an independent tree, with its own
3901
branch. Commits in the top-level tree will not apply to the new subtree.
3904
# join is not un-hidden yet
3905
#_see_also = ['join']
3906
takes_args = ['tree']
3908
def run(self, tree):
3909
containing_tree, subdir = WorkingTree.open_containing(tree)
3910
sub_id = containing_tree.path2id(subdir)
3912
raise errors.NotVersionedError(subdir)
3914
containing_tree.extract(sub_id)
3915
except errors.RootNotRich:
3916
raise errors.UpgradeRequired(containing_tree.branch.base)
3919
class cmd_merge_directive(Command):
3920
"""Generate a merge directive for auto-merge tools.
3922
A directive requests a merge to be performed, and also provides all the
3923
information necessary to do so. This means it must either include a
3924
revision bundle, or the location of a branch containing the desired
3927
A submit branch (the location to merge into) must be supplied the first
3928
time the command is issued. After it has been supplied once, it will
3929
be remembered as the default.
3931
A public branch is optional if a revision bundle is supplied, but required
3932
if --diff or --plain is specified. It will be remembered as the default
3933
after the first use.
3936
takes_args = ['submit_branch?', 'public_branch?']
3940
_see_also = ['send']
3943
RegistryOption.from_kwargs('patch-type',
3944
'The type of patch to include in the directive.',
3946
value_switches=True,
3948
bundle='Bazaar revision bundle (default).',
3949
diff='Normal unified diff.',
3950
plain='No patch, just directive.'),
3951
Option('sign', help='GPG-sign the directive.'), 'revision',
3952
Option('mail-to', type=str,
3953
help='Instead of printing the directive, email to this address.'),
3954
Option('message', type=str, short_name='m',
3955
help='Message to use when committing this merge.')
3958
encoding_type = 'exact'
3960
def run(self, submit_branch=None, public_branch=None, patch_type='bundle',
3961
sign=False, revision=None, mail_to=None, message=None):
3962
from bzrlib.revision import ensure_null, NULL_REVISION
3963
include_patch, include_bundle = {
3964
'plain': (False, False),
3965
'diff': (True, False),
3966
'bundle': (True, True),
3968
branch = Branch.open('.')
3969
stored_submit_branch = branch.get_submit_branch()
3970
if submit_branch is None:
3971
submit_branch = stored_submit_branch
3973
if stored_submit_branch is None:
3974
branch.set_submit_branch(submit_branch)
3975
if submit_branch is None:
3976
submit_branch = branch.get_parent()
3977
if submit_branch is None:
3978
raise errors.BzrCommandError('No submit branch specified or known')
3980
stored_public_branch = branch.get_public_branch()
3981
if public_branch is None:
3982
public_branch = stored_public_branch
3983
elif stored_public_branch is None:
3984
branch.set_public_branch(public_branch)
3985
if not include_bundle and public_branch is None:
3986
raise errors.BzrCommandError('No public branch specified or'
3988
base_revision_id = None
3989
if revision is not None:
3990
if len(revision) > 2:
3991
raise errors.BzrCommandError('bzr merge-directive takes '
3992
'at most two one revision identifiers')
3993
revision_id = revision[-1].as_revision_id(branch)
3994
if len(revision) == 2:
3995
base_revision_id = revision[0].as_revision_id(branch)
3997
revision_id = branch.last_revision()
3998
revision_id = ensure_null(revision_id)
3999
if revision_id == NULL_REVISION:
4000
raise errors.BzrCommandError('No revisions to bundle.')
4001
directive = merge_directive.MergeDirective2.from_objects(
4002
branch.repository, revision_id, time.time(),
4003
osutils.local_time_offset(), submit_branch,
4004
public_branch=public_branch, include_patch=include_patch,
4005
include_bundle=include_bundle, message=message,
4006
base_revision_id=base_revision_id)
4009
self.outf.write(directive.to_signed(branch))
4011
self.outf.writelines(directive.to_lines())
4013
message = directive.to_email(mail_to, branch, sign)
4014
s = SMTPConnection(branch.get_config())
4015
s.send_email(message)
4018
class cmd_send(Command):
4019
"""Mail or create a merge-directive for submiting changes.
4021
A merge directive provides many things needed for requesting merges:
4023
* A machine-readable description of the merge to perform
4025
* An optional patch that is a preview of the changes requested
4027
* An optional bundle of revision data, so that the changes can be applied
4028
directly from the merge directive, without retrieving data from a
4031
If --no-bundle is specified, then public_branch is needed (and must be
4032
up-to-date), so that the receiver can perform the merge using the
4033
public_branch. The public_branch is always included if known, so that
4034
people can check it later.
4036
The submit branch defaults to the parent, but can be overridden. Both
4037
submit branch and public branch will be remembered if supplied.
4039
If a public_branch is known for the submit_branch, that public submit
4040
branch is used in the merge instructions. This means that a local mirror
4041
can be used as your actual submit branch, once you have set public_branch
4044
Mail is sent using your preferred mail program. This should be transparent
4045
on Windows (it uses MAPI). On Linux, it requires the xdg-email utility.
4046
If the preferred client can't be found (or used), your editor will be used.
4048
To use a specific mail program, set the mail_client configuration option.
4049
(For Thunderbird 1.5, this works around some bugs.) Supported values for
4050
specific clients are "evolution", "kmail", "mutt", and "thunderbird";
4051
generic options are "default", "editor", "emacsclient", "mapi", and
4054
If mail is being sent, a to address is required. This can be supplied
4055
either on the commandline, by setting the submit_to configuration
4056
option in the branch itself or the child_submit_to configuration option
4057
in the submit branch.
4059
Two formats are currently supported: "4" uses revision bundle format 4 and
4060
merge directive format 2. It is significantly faster and smaller than
4061
older formats. It is compatible with Bazaar 0.19 and later. It is the
4062
default. "0.9" uses revision bundle format 0.9 and merge directive
4063
format 1. It is compatible with Bazaar 0.12 - 0.18.
4065
Merge directives are applied using the merge command or the pull command.
4068
encoding_type = 'exact'
4070
_see_also = ['merge', 'pull']
4072
takes_args = ['submit_branch?', 'public_branch?']
4076
help='Do not include a bundle in the merge directive.'),
4077
Option('no-patch', help='Do not include a preview patch in the merge'
4080
help='Remember submit and public branch.'),
4082
help='Branch to generate the submission from, '
4083
'rather than the one containing the working directory.',
4086
Option('output', short_name='o',
4087
help='Write merge directive to this file; '
4088
'use - for stdout.',
4090
Option('mail-to', help='Mail the request to this address.',
4094
RegistryOption.from_kwargs('format',
4095
'Use the specified output format.',
4096
**{'4': 'Bundle format 4, Merge Directive 2 (default)',
4097
'0.9': 'Bundle format 0.9, Merge Directive 1',})
4100
def run(self, submit_branch=None, public_branch=None, no_bundle=False,
4101
no_patch=False, revision=None, remember=False, output=None,
4102
format='4', mail_to=None, message=None, **kwargs):
4103
return self._run(submit_branch, revision, public_branch, remember,
4104
format, no_bundle, no_patch, output,
4105
kwargs.get('from', '.'), mail_to, message)
4107
def _run(self, submit_branch, revision, public_branch, remember, format,
4108
no_bundle, no_patch, output, from_, mail_to, message):
4109
from bzrlib.revision import NULL_REVISION
4110
branch = Branch.open_containing(from_)[0]
4112
outfile = StringIO()
4116
outfile = open(output, 'wb')
4117
# we may need to write data into branch's repository to calculate
4122
config = branch.get_config()
4124
mail_to = config.get_user_option('submit_to')
4125
mail_client = config.get_mail_client()
4126
if remember and submit_branch is None:
4127
raise errors.BzrCommandError(
4128
'--remember requires a branch to be specified.')
4129
stored_submit_branch = branch.get_submit_branch()
4130
remembered_submit_branch = False
4131
if submit_branch is None:
4132
submit_branch = stored_submit_branch
4133
remembered_submit_branch = True
4135
if stored_submit_branch is None or remember:
4136
branch.set_submit_branch(submit_branch)
4137
if submit_branch is None:
4138
submit_branch = branch.get_parent()
4139
remembered_submit_branch = True
4140
if submit_branch is None:
4141
raise errors.BzrCommandError('No submit branch known or'
4143
if remembered_submit_branch:
4144
note('Using saved location "%s" to determine what changes to submit.', submit_branch)
4147
submit_config = Branch.open(submit_branch).get_config()
4148
mail_to = submit_config.get_user_option("child_submit_to")
4150
stored_public_branch = branch.get_public_branch()
4151
if public_branch is None:
4152
public_branch = stored_public_branch
4153
elif stored_public_branch is None or remember:
4154
branch.set_public_branch(public_branch)
4155
if no_bundle and public_branch is None:
4156
raise errors.BzrCommandError('No public branch specified or'
4158
base_revision_id = None
4160
if revision is not None:
4161
if len(revision) > 2:
4162
raise errors.BzrCommandError('bzr send takes '
4163
'at most two one revision identifiers')
4164
revision_id = revision[-1].as_revision_id(branch)
4165
if len(revision) == 2:
4166
base_revision_id = revision[0].as_revision_id(branch)
4167
if revision_id is None:
4168
revision_id = branch.last_revision()
4169
if revision_id == NULL_REVISION:
4170
raise errors.BzrCommandError('No revisions to submit.')
4172
directive = merge_directive.MergeDirective2.from_objects(
4173
branch.repository, revision_id, time.time(),
4174
osutils.local_time_offset(), submit_branch,
4175
public_branch=public_branch, include_patch=not no_patch,
4176
include_bundle=not no_bundle, message=message,
4177
base_revision_id=base_revision_id)
4178
elif format == '0.9':
4181
patch_type = 'bundle'
4183
raise errors.BzrCommandError('Format 0.9 does not'
4184
' permit bundle with no patch')
4190
directive = merge_directive.MergeDirective.from_objects(
4191
branch.repository, revision_id, time.time(),
4192
osutils.local_time_offset(), submit_branch,
4193
public_branch=public_branch, patch_type=patch_type,
4196
outfile.writelines(directive.to_lines())
4198
subject = '[MERGE] '
4199
if message is not None:
4202
revision = branch.repository.get_revision(revision_id)
4203
subject += revision.get_summary()
4204
basename = directive.get_disk_name(branch)
4205
mail_client.compose_merge_request(mail_to, subject,
4206
outfile.getvalue(), basename)
4213
class cmd_bundle_revisions(cmd_send):
4215
"""Create a merge-directive for submiting changes.
4217
A merge directive provides many things needed for requesting merges:
4219
* A machine-readable description of the merge to perform
4221
* An optional patch that is a preview of the changes requested
4223
* An optional bundle of revision data, so that the changes can be applied
4224
directly from the merge directive, without retrieving data from a
4227
If --no-bundle is specified, then public_branch is needed (and must be
4228
up-to-date), so that the receiver can perform the merge using the
4229
public_branch. The public_branch is always included if known, so that
4230
people can check it later.
4232
The submit branch defaults to the parent, but can be overridden. Both
4233
submit branch and public branch will be remembered if supplied.
4235
If a public_branch is known for the submit_branch, that public submit
4236
branch is used in the merge instructions. This means that a local mirror
4237
can be used as your actual submit branch, once you have set public_branch
4240
Two formats are currently supported: "4" uses revision bundle format 4 and
4241
merge directive format 2. It is significantly faster and smaller than
4242
older formats. It is compatible with Bazaar 0.19 and later. It is the
4243
default. "0.9" uses revision bundle format 0.9 and merge directive
4244
format 1. It is compatible with Bazaar 0.12 - 0.18.
4249
help='Do not include a bundle in the merge directive.'),
4250
Option('no-patch', help='Do not include a preview patch in the merge'
4253
help='Remember submit and public branch.'),
4255
help='Branch to generate the submission from, '
4256
'rather than the one containing the working directory.',
4259
Option('output', short_name='o', help='Write directive to this file.',
4262
RegistryOption.from_kwargs('format',
4263
'Use the specified output format.',
4264
**{'4': 'Bundle format 4, Merge Directive 2 (default)',
4265
'0.9': 'Bundle format 0.9, Merge Directive 1',})
4267
aliases = ['bundle']
4269
_see_also = ['send', 'merge']
4273
def run(self, submit_branch=None, public_branch=None, no_bundle=False,
4274
no_patch=False, revision=None, remember=False, output=None,
4275
format='4', **kwargs):
4278
return self._run(submit_branch, revision, public_branch, remember,
4279
format, no_bundle, no_patch, output,
4280
kwargs.get('from', '.'), None, None)
4283
class cmd_tag(Command):
4284
"""Create, remove or modify a tag naming a revision.
4286
Tags give human-meaningful names to revisions. Commands that take a -r
4287
(--revision) option can be given -rtag:X, where X is any previously
4290
Tags are stored in the branch. Tags are copied from one branch to another
4291
along when you branch, push, pull or merge.
4293
It is an error to give a tag name that already exists unless you pass
4294
--force, in which case the tag is moved to point to the new revision.
4297
_see_also = ['commit', 'tags']
4298
takes_args = ['tag_name']
4301
help='Delete this tag rather than placing it.',
4304
help='Branch in which to place the tag.',
4309
help='Replace existing tags.',
4314
def run(self, tag_name,
4320
branch, relpath = Branch.open_containing(directory)
4324
branch.tags.delete_tag(tag_name)
4325
self.outf.write('Deleted tag %s.\n' % tag_name)
4328
if len(revision) != 1:
4329
raise errors.BzrCommandError(
4330
"Tags can only be placed on a single revision, "
4332
revision_id = revision[0].as_revision_id(branch)
4334
revision_id = branch.last_revision()
4335
if (not force) and branch.tags.has_tag(tag_name):
4336
raise errors.TagAlreadyExists(tag_name)
4337
branch.tags.set_tag(tag_name, revision_id)
4338
self.outf.write('Created tag %s.\n' % tag_name)
4343
class cmd_tags(Command):
4346
This command shows a table of tag names and the revisions they reference.
4352
help='Branch whose tags should be displayed.',
4356
RegistryOption.from_kwargs('sort',
4357
'Sort tags by different criteria.', title='Sorting',
4358
alpha='Sort tags lexicographically (default).',
4359
time='Sort tags chronologically.',
4370
branch, relpath = Branch.open_containing(directory)
4371
tags = branch.tags.get_tag_dict().items()
4374
elif sort == 'time':
4376
for tag, revid in tags:
4378
revobj = branch.repository.get_revision(revid)
4379
except errors.NoSuchRevision:
4380
timestamp = sys.maxint # place them at the end
4382
timestamp = revobj.timestamp
4383
timestamps[revid] = timestamp
4384
tags.sort(key=lambda x: timestamps[x[1]])
4386
# [ (tag, revid), ... ] -> [ (tag, dotted_revno), ... ]
4387
revno_map = branch.get_revision_id_to_revno_map()
4388
tags = [ (tag, '.'.join(map(str, revno_map.get(revid, ('?',)))))
4389
for tag, revid in tags ]
4390
for tag, revspec in tags:
4391
self.outf.write('%-20s %s\n' % (tag, revspec))
4394
class cmd_reconfigure(Command):
4395
"""Reconfigure the type of a bzr directory.
4397
A target configuration must be specified.
4399
For checkouts, the bind-to location will be auto-detected if not specified.
4400
The order of preference is
4401
1. For a lightweight checkout, the current bound location.
4402
2. For branches that used to be checkouts, the previously-bound location.
4403
3. The push location.
4404
4. The parent location.
4405
If none of these is available, --bind-to must be specified.
4408
_see_also = ['branches', 'checkouts', 'standalone-trees', 'working-trees']
4409
takes_args = ['location?']
4410
takes_options = [RegistryOption.from_kwargs('target_type',
4411
title='Target type',
4412
help='The type to reconfigure the directory to.',
4413
value_switches=True, enum_switch=False,
4414
branch='Reconfigure to be an unbound branch '
4415
'with no working tree.',
4416
tree='Reconfigure to be an unbound branch '
4417
'with a working tree.',
4418
checkout='Reconfigure to be a bound branch '
4419
'with a working tree.',
4420
lightweight_checkout='Reconfigure to be a lightweight'
4421
' checkout (with no local history).',
4422
standalone='Reconfigure to be a standalone branch '
4423
'(i.e. stop using shared repository).',
4424
use_shared='Reconfigure to use a shared repository.'),
4425
Option('bind-to', help='Branch to bind checkout to.',
4428
help='Perform reconfiguration even if local changes'
4432
def run(self, location=None, target_type=None, bind_to=None, force=False):
4433
directory = bzrdir.BzrDir.open(location)
4434
if target_type is None:
4435
raise errors.BzrCommandError('No target configuration specified')
4436
elif target_type == 'branch':
4437
reconfiguration = reconfigure.Reconfigure.to_branch(directory)
4438
elif target_type == 'tree':
4439
reconfiguration = reconfigure.Reconfigure.to_tree(directory)
4440
elif target_type == 'checkout':
4441
reconfiguration = reconfigure.Reconfigure.to_checkout(directory,
4443
elif target_type == 'lightweight-checkout':
4444
reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
4446
elif target_type == 'use-shared':
4447
reconfiguration = reconfigure.Reconfigure.to_use_shared(directory)
4448
elif target_type == 'standalone':
4449
reconfiguration = reconfigure.Reconfigure.to_standalone(directory)
4450
reconfiguration.apply(force)
4453
class cmd_switch(Command):
4454
"""Set the branch of a checkout and update.
4456
For lightweight checkouts, this changes the branch being referenced.
4457
For heavyweight checkouts, this checks that there are no local commits
4458
versus the current bound branch, then it makes the local branch a mirror
4459
of the new location and binds to it.
4461
In both cases, the working tree is updated and uncommitted changes
4462
are merged. The user can commit or revert these as they desire.
4464
Pending merges need to be committed or reverted before using switch.
4466
The path to the branch to switch to can be specified relative to the parent
4467
directory of the current branch. For example, if you are currently in a
4468
checkout of /path/to/branch, specifying 'newbranch' will find a branch at
4472
takes_args = ['to_location']
4473
takes_options = [Option('force',
4474
help='Switch even if local commits will be lost.')
4477
def run(self, to_location, force=False):
4478
from bzrlib import switch
4480
control_dir = bzrdir.BzrDir.open_containing(tree_location)[0]
4482
to_branch = Branch.open(to_location)
4483
except errors.NotBranchError:
4484
to_branch = Branch.open(
4485
control_dir.open_branch().base + '../' + to_location)
4486
switch.switch(control_dir, to_branch, force)
4487
note('Switched to branch: %s',
4488
urlutils.unescape_for_display(to_branch.base, 'utf-8'))
4491
class cmd_hooks(Command):
4492
"""Show a branch's currently registered hooks.
4496
takes_args = ['path?']
4498
def run(self, path=None):
4501
branch_hooks = Branch.open(path).hooks
4502
for hook_type in branch_hooks:
4503
hooks = branch_hooks[hook_type]
4504
self.outf.write("%s:\n" % (hook_type,))
4507
self.outf.write(" %s\n" %
4508
(branch_hooks.get_hook_name(hook),))
4510
self.outf.write(" <no hooks installed>\n")
4513
def _create_prefix(cur_transport):
4514
needed = [cur_transport]
4515
# Recurse upwards until we can create a directory successfully
4517
new_transport = cur_transport.clone('..')
4518
if new_transport.base == cur_transport.base:
4519
raise errors.BzrCommandError(
4520
"Failed to create path prefix for %s."
4521
% cur_transport.base)
4523
new_transport.mkdir('.')
4524
except errors.NoSuchFile:
4525
needed.append(new_transport)
4526
cur_transport = new_transport
4529
# Now we only need to create child directories
4531
cur_transport = needed.pop()
4532
cur_transport.ensure_base()
3028
raise errors.BzrCommandError("bzr serve requires one of --inet or --port")
3032
# command-line interpretation helper for merge-related commands
3033
def _merge_helper(other_revision, base_revision,
3034
check_clean=True, ignore_zero=False,
3035
this_dir=None, backup_files=False,
3037
file_list=None, show_base=False, reprocess=False,
3039
pb=DummyProgress()):
3040
"""Merge changes into a tree.
3043
list(path, revno) Base for three-way merge.
3044
If [None, None] then a base will be automatically determined.
3046
list(path, revno) Other revision for three-way merge.
3048
Directory to merge changes into; '.' by default.
3050
If true, this_dir must have no uncommitted changes before the
3052
ignore_zero - If true, suppress the "zero conflicts" message when
3053
there are no conflicts; should be set when doing something we expect
3054
to complete perfectly.
3055
file_list - If supplied, merge only changes to selected files.
3057
All available ancestors of other_revision and base_revision are
3058
automatically pulled into the branch.
3060
The revno may be -1 to indicate the last revision on the branch, which is
3063
This function is intended for use from the command line; programmatic
3064
clients might prefer to call merge.merge_inner(), which has less magic
3067
# Loading it late, so that we don't always have to import bzrlib.merge
3068
if merge_type is None:
3069
merge_type = _mod_merge.Merge3Merger
3070
if this_dir is None:
3072
this_tree = WorkingTree.open_containing(this_dir)[0]
3073
if show_base and not merge_type is _mod_merge.Merge3Merger:
3074
raise errors.BzrCommandError("Show-base is not supported for this merge"
3075
" type. %s" % merge_type)
3076
if reprocess and not merge_type.supports_reprocess:
3077
raise errors.BzrCommandError("Conflict reduction is not supported for merge"
3078
" type %s." % merge_type)
3079
if reprocess and show_base:
3080
raise errors.BzrCommandError("Cannot do conflict reduction and show base.")
3082
merger = _mod_merge.Merger(this_tree.branch, this_tree=this_tree,
3084
merger.pp = ProgressPhase("Merge phase", 5, pb)
3085
merger.pp.next_phase()
3086
merger.check_basis(check_clean)
3087
merger.set_other(other_revision)
3088
merger.pp.next_phase()
3089
merger.set_base(base_revision)
3090
if merger.base_rev_id == merger.other_rev_id:
3091
note('Nothing to do.')
3093
if file_list is None:
3094
if pull and merger.base_rev_id == merger.this_rev_id:
3095
count = merger.this_tree.pull(merger.this_branch,
3096
False, merger.other_rev_id)
3097
note('%d revision(s) pulled.' % (count,))
3099
merger.backup_files = backup_files
3100
merger.merge_type = merge_type
3101
merger.set_interesting_files(file_list)
3102
merger.show_base = show_base
3103
merger.reprocess = reprocess
3104
conflicts = merger.do_merge()
3105
if file_list is None:
3106
merger.set_pending()
3113
merge = _merge_helper
4535
3116
# these get imported and then picked up by the scan for cmd_*