720
559
location = stored_loc
722
561
to_transport = transport.get_transport(location)
562
location_url = to_transport.base
724
br_to = repository_to = dir_to = None
726
dir_to = bzrdir.BzrDir.open_from_transport(to_transport)
727
except errors.NotBranchError:
728
pass # Didn't find anything
730
# If we can open a branch, use its direct repository, otherwise see
731
# if there is a repository without a branch.
733
br_to = dir_to.open_branch()
734
except errors.NotBranchError:
735
# Didn't find a branch, can we find a repository?
566
dir_to = bzrdir.BzrDir.open(location_url)
567
br_to = dir_to.open_branch()
568
except NotBranchError:
570
to_transport = to_transport.clone('..')
571
if not create_prefix:
737
repository_to = dir_to.find_repository()
738
except errors.NoRepositoryPresent:
573
relurl = to_transport.relpath(location_url)
574
mutter('creating directory %s => %s', location_url, relurl)
575
to_transport.mkdir(relurl)
577
raise BzrCommandError("Parent directory of %s "
578
"does not exist." % location)
741
# Found a branch, so we must have found a repository
742
repository_to = br_to.repository
747
# The destination doesn't exist; create it.
748
# XXX: Refactor the create_prefix/no_create_prefix code into a
749
# common helper function
751
to_transport.mkdir('.')
752
except errors.FileExists:
753
if not use_existing_dir:
754
raise errors.BzrCommandError("Target directory %s"
755
" already exists, but does not have a valid .bzr"
756
" directory. Supply --use-existing-dir to push"
757
" there anyway." % location)
758
except errors.NoSuchFile:
759
if not create_prefix:
760
raise errors.BzrCommandError("Parent directory of %s"
762
"\nYou may supply --create-prefix to create all"
763
" leading parent directories."
765
_create_prefix(to_transport)
767
# Now the target directory exists, but doesn't have a .bzr
768
# directory. So we need to create it, along with any work to create
769
# all of the dependent branches, etc.
770
dir_to = br_from.bzrdir.clone_on_transport(to_transport,
580
current = to_transport.base
581
needed = [(to_transport, to_transport.relpath(location_url))]
584
to_transport, relpath = needed[-1]
585
to_transport.mkdir(relpath)
588
new_transport = to_transport.clone('..')
589
needed.append((new_transport,
590
new_transport.relpath(to_transport.base)))
591
if new_transport.base == to_transport.base:
592
raise BzrCommandError("Could not create "
594
dir_to = br_from.bzrdir.clone(location_url,
771
595
revision_id=br_from.last_revision())
772
596
br_to = dir_to.open_branch()
773
# TODO: Some more useful message about what was copied
774
note('Created new branch.')
597
count = len(br_to.revision_history())
775
598
# We successfully created the target, remember it
776
599
if br_from.get_push_location() is None or remember:
777
600
br_from.set_push_location(br_to.base)
778
elif repository_to is None:
779
# we have a bzrdir but no branch or repository
780
# XXX: Figure out what to do other than complain.
781
raise errors.BzrCommandError("At %s you have a valid .bzr control"
782
" directory, but not a branch or repository. This is an"
783
" unsupported configuration. Please move the target directory"
784
" out of the way and try again."
787
# We have a repository but no branch, copy the revisions, and then
789
last_revision_id = br_from.last_revision()
790
repository_to.fetch(br_from.repository,
791
revision_id=last_revision_id)
792
br_to = br_from.clone(dir_to, revision_id=last_revision_id)
793
note('Created new branch.')
794
if br_from.get_push_location() is None or remember:
795
br_from.set_push_location(br_to.base)
796
else: # We have a valid to branch
797
602
# We were able to connect to the remote location, so remember it
798
603
# we don't need to successfully push because of possible divergence.
799
604
if br_from.get_push_location() is None or remember:
800
605
br_from.set_push_location(br_to.base)
802
old_rh = br_to.revision_history()
606
old_rh = br_to.revision_history()
805
609
tree_to = dir_to.open_workingtree()
806
610
except errors.NotLocalUrl:
807
warning("This transport does not update the working "
808
"tree of: %s. See 'bzr help working-trees' for "
809
"more information." % br_to.base)
810
push_result = br_from.push(br_to, overwrite)
811
except errors.NoWorkingTree:
812
push_result = br_from.push(br_to, overwrite)
611
warning('This transport does not update the working '
612
'tree of: %s' % (br_to.base,))
613
count = br_to.pull(br_from, overwrite)
614
except NoWorkingTree:
615
count = br_to.pull(br_from, overwrite)
816
push_result = br_from.push(tree_to.branch, overwrite)
820
except errors.DivergedBranches:
821
raise errors.BzrCommandError('These branches have diverged.'
822
' Try using "merge" and then "push".')
823
if push_result is not None:
824
push_result.report(self.outf)
617
count = tree_to.pull(br_from, overwrite)
618
except DivergedBranches:
619
raise BzrCommandError("These branches have diverged."
620
" Try a merge then push with overwrite.")
621
note('%d revision(s) pushed.' % (count,))
826
624
new_rh = br_to.revision_history()
827
625
if old_rh != new_rh:
828
626
# Something changed
829
627
from bzrlib.log import show_changed_revisions
830
628
show_changed_revisions(br_to, old_rh, new_rh,
831
629
to_file=self.outf)
833
# we probably did a clone rather than a push, so a message was
838
632
class cmd_branch(Command):
2688
2084
default, use --remember. The value will only be saved if the remote
2689
2085
location can be accessed.
2691
The results of the merge are placed into the destination working
2692
directory, where they can be reviewed (with bzr diff), tested, and then
2693
committed to record the result of the merge.
2089
To merge the latest revision from bzr.dev
2090
bzr merge ../bzr.dev
2092
To merge changes up to and including revision 82 from bzr.dev
2093
bzr merge -r 82 ../bzr.dev
2095
To merge the changes introduced by 82, without previous changes:
2096
bzr merge -r 81..82 ../bzr.dev
2695
2098
merge refuses to run if there are any uncommitted changes, unless
2696
2099
--force is given.
2699
To merge the latest revision from bzr.dev::
2701
bzr merge ../bzr.dev
2703
To merge changes up to and including revision 82 from bzr.dev::
2705
bzr merge -r 82 ../bzr.dev
2707
To merge the changes introduced by 82, without previous changes::
2709
bzr merge -r 81..82 ../bzr.dev
2101
The following merge types are available:
2712
_see_also = ['update', 'remerge', 'status-flags']
2713
2103
takes_args = ['branch?']
2718
help='Merge even if the destination tree has uncommitted changes.'),
2722
Option('show-base', help="Show base revision text in "
2724
Option('uncommitted', help='Apply uncommitted changes'
2725
' from a working copy, instead of branch changes.'),
2726
Option('pull', help='If the destination is already'
2727
' completely merged into the source, pull from the'
2728
' source rather than merging. When this happens,'
2729
' you do not need to commit the result.'),
2731
help='Branch to merge into, '
2732
'rather than the one containing the working directory.',
2104
takes_options = ['revision', 'force', 'merge-type', 'reprocess', 'remember',
2105
Option('show-base', help="Show base revision text in "
2107
Option('uncommitted', help='Apply uncommitted changes'
2108
' from a working copy, instead of branch changes')]
2111
from merge import merge_type_help
2112
from inspect import getdoc
2113
return getdoc(self) + '\n' + merge_type_help()
2738
2115
def run(self, branch=None, revision=None, force=False, merge_type=None,
2739
show_base=False, reprocess=False, remember=False,
2740
uncommitted=False, pull=False,
2743
# This is actually a branch (or merge-directive) *location*.
2116
show_base=False, reprocess=False, remember=False,
2747
2118
if merge_type is None:
2748
merge_type = _mod_merge.Merge3Merger
2750
if directory is None: directory = u'.'
2751
possible_transports = []
2753
allow_pending = True
2754
verified = 'inapplicable'
2755
tree = WorkingTree.open_containing(directory)[0]
2756
change_reporter = delta._ChangeReporter(
2757
unversioned_filter=tree.is_ignored)
2119
merge_type = Merge3Merger
2121
tree = WorkingTree.open_containing(u'.')[0]
2123
if branch is not None:
2125
reader = bundle.read_bundle_from_url(branch)
2127
pass # Continue on considering this url a Branch
2129
conflicts = merge_bundle(reader, tree, not force, merge_type,
2130
reprocess, show_base)
2136
branch = self._get_remembered_parent(tree, branch, 'Merging from')
2138
if revision is None or len(revision) < 1:
2141
other = [branch, None]
2144
other = [branch, -1]
2145
other_branch, path = Branch.open_containing(branch)
2148
raise BzrCommandError('Cannot use --uncommitted and --revision'
2149
' at the same time.')
2150
if len(revision) == 1:
2152
other_branch, path = Branch.open_containing(branch)
2153
revno = revision[0].in_history(other_branch).revno
2154
other = [branch, revno]
2156
assert len(revision) == 2
2157
if None in revision:
2158
raise BzrCommandError(
2159
"Merge doesn't permit that revision specifier.")
2160
other_branch, path = Branch.open_containing(branch)
2162
base = [branch, revision[0].in_history(other_branch).revno]
2163
other = [branch, revision[1].in_history(other_branch).revno]
2165
if tree.branch.get_parent() is None or remember:
2166
tree.branch.set_parent(other_branch.base)
2169
interesting_files = [path]
2171
interesting_files = None
2172
pb = ui.ui_factory.nested_progress_bar()
2760
pb = ui.ui_factory.nested_progress_bar()
2761
cleanups.append(pb.finished)
2763
cleanups.append(tree.unlock)
2764
if location is not None:
2765
mergeable, other_transport = _get_mergeable_helper(location)
2768
raise errors.BzrCommandError('Cannot use --uncommitted'
2769
' with bundles or merge directives.')
2771
if revision is not None:
2772
raise errors.BzrCommandError(
2773
'Cannot use -r with merge directives or bundles')
2774
merger, verified = _mod_merge.Merger.from_mergeable(tree,
2776
possible_transports.append(other_transport)
2778
if merger is None and uncommitted:
2779
if revision is not None and len(revision) > 0:
2780
raise errors.BzrCommandError('Cannot use --uncommitted and'
2781
' --revision at the same time.')
2782
location = self._select_branch_location(tree, location)[0]
2783
other_tree, other_path = WorkingTree.open_containing(location)
2784
merger = _mod_merge.Merger.from_uncommitted(tree, other_tree,
2786
allow_pending = False
2789
merger, allow_pending = self._get_merger_from_branch(tree,
2790
location, revision, remember, possible_transports, pb)
2792
merger.merge_type = merge_type
2793
merger.reprocess = reprocess
2794
merger.show_base = show_base
2795
merger.change_reporter = change_reporter
2796
self.sanity_check_merger(merger)
2797
if (merger.base_rev_id == merger.other_rev_id and
2798
merger.other_rev_id != None):
2799
note('Nothing to do.')
2802
if merger.interesting_files is not None:
2803
raise errors.BzrCommandError('Cannot pull individual files')
2804
if (merger.base_rev_id == tree.last_revision()):
2805
result = tree.pull(merger.other_branch, False,
2806
merger.other_rev_id)
2807
result.report(self.outf)
2809
merger.check_basis(not force)
2810
conflict_count = merger.do_merge()
2812
merger.set_pending()
2813
if verified == 'failed':
2814
warning('Preview patch does not match changes')
2175
conflict_count = merge(other, base, check_clean=(not force),
2176
merge_type=merge_type,
2177
reprocess=reprocess,
2178
show_base=show_base,
2179
pb=pb, file_list=interesting_files)
2815
2182
if conflict_count != 0:
2820
for cleanup in reversed(cleanups):
2823
def sanity_check_merger(self, merger):
2824
if (merger.show_base and
2825
not merger.merge_type is _mod_merge.Merge3Merger):
2826
raise errors.BzrCommandError("Show-base is not supported for this"
2827
" merge type. %s" % merger.merge_type)
2828
if merger.reprocess and not merger.merge_type.supports_reprocess:
2829
raise errors.BzrCommandError("Conflict reduction is not supported"
2830
" for merge type %s." %
2832
if merger.reprocess and merger.show_base:
2833
raise errors.BzrCommandError("Cannot do conflict reduction and"
2836
def _get_merger_from_branch(self, tree, location, revision, remember,
2837
possible_transports, pb):
2838
"""Produce a merger from a location, assuming it refers to a branch."""
2839
from bzrlib.tag import _merge_tags_if_possible
2840
assert revision is None or len(revision) < 3
2841
# find the branch locations
2842
other_loc, location = self._select_branch_location(tree, location,
2844
if revision is not None and len(revision) == 2:
2845
base_loc, location = self._select_branch_location(tree, location,
2848
base_loc = other_loc
2850
other_branch, other_path = Branch.open_containing(other_loc,
2851
possible_transports)
2852
if base_loc == other_loc:
2853
base_branch = other_branch
2855
base_branch, base_path = Branch.open_containing(base_loc,
2856
possible_transports)
2857
# Find the revision ids
2858
if revision is None or len(revision) < 1 or revision[-1] is None:
2859
other_revision_id = _mod_revision.ensure_null(
2860
other_branch.last_revision())
2862
other_revision_id = \
2863
_mod_revision.ensure_null(
2864
revision[-1].in_history(other_branch).rev_id)
2865
if (revision is not None and len(revision) == 2
2866
and revision[0] is not None):
2867
base_revision_id = \
2868
_mod_revision.ensure_null(
2869
revision[0].in_history(base_branch).rev_id)
2871
base_revision_id = None
2872
# Remember where we merge from
2873
if ((tree.branch.get_parent() is None or remember) and
2874
other_branch is not None):
2875
tree.branch.set_parent(other_branch.base)
2876
_merge_tags_if_possible(other_branch, tree.branch)
2877
merger = _mod_merge.Merger.from_revision_ids(pb, tree,
2878
other_revision_id, base_revision_id, other_branch, base_branch)
2879
if other_path != '':
2880
allow_pending = False
2881
merger.interesting_files = [other_path]
2883
allow_pending = True
2884
return merger, allow_pending
2886
def _select_branch_location(self, tree, location, revision=None,
2888
"""Select a branch location, according to possible inputs.
2890
If provided, branches from ``revision`` are preferred. (Both
2891
``revision`` and ``index`` must be supplied.)
2893
Otherwise, the ``location`` parameter is used. If it is None, then the
2894
``parent`` location is used, and a note is printed.
2896
:param tree: The working tree to select a branch for merging into
2897
:param location: The location entered by the user
2898
:param revision: The revision parameter to the command
2899
:param index: The index to use for the revision parameter. Negative
2900
indices are permitted.
2901
:return: (selected_location, default_location). The default location
2902
will be the user-entered location, if any, or else the remembered
2905
if (revision is not None and index is not None
2906
and revision[index] is not None):
2907
branch = revision[index].get_branch()
2908
if branch is not None:
2909
return branch, location
2910
location = self._get_remembered_parent(tree, location, 'Merging from')
2911
return location, location
2186
except errors.AmbiguousBase, e:
2187
m = ("sorry, bzr can't determine the right merge base yet\n"
2188
"candidates are:\n "
2189
+ "\n ".join(e.bases)
2191
"please specify an explicit base with -r,\n"
2192
"and (if you want) report this to the bzr developers\n")
2913
2195
# TODO: move up to common parent; this isn't merge-specific anymore.
2914
2196
def _get_remembered_parent(self, tree, supplied_location, verb_string):
3580
class cmd_wait_until_signalled(Command):
3581
"""Test helper for test_start_and_stop_bzr_subprocess_send_signal.
3583
This just prints a line to signal when it is ready, then blocks on stdin.
3589
sys.stdout.write("running\n")
3591
sys.stdin.readline()
3594
class cmd_serve(Command):
3595
"""Run the bzr server."""
3597
aliases = ['server']
3601
help='Serve on stdin/out for use from inetd or sshd.'),
3603
help='Listen for connections on nominated port of the form '
3604
'[hostname:]portnumber. Passing 0 as the port number will '
3605
'result in a dynamically allocated port. The default port is '
3609
help='Serve contents of this directory.',
3611
Option('allow-writes',
3612
help='By default the server is a readonly server. Supplying '
3613
'--allow-writes enables write access to the contents of '
3614
'the served directory and below.'
3618
def run(self, port=None, inet=False, directory=None, allow_writes=False):
3619
from bzrlib.smart import medium, server
3620
from bzrlib.transport import get_transport
3621
from bzrlib.transport.chroot import ChrootServer
3622
from bzrlib.transport.remote import BZR_DEFAULT_PORT, BZR_DEFAULT_INTERFACE
3623
if directory is None:
3624
directory = os.getcwd()
3625
url = urlutils.local_path_to_url(directory)
3626
if not allow_writes:
3627
url = 'readonly+' + url
3628
chroot_server = ChrootServer(get_transport(url))
3629
chroot_server.setUp()
3630
t = get_transport(chroot_server.get_url())
3632
smart_server = medium.SmartServerPipeStreamMedium(
3633
sys.stdin, sys.stdout, t)
3635
host = BZR_DEFAULT_INTERFACE
3637
port = BZR_DEFAULT_PORT
3640
host, port = port.split(':')
3642
smart_server = server.SmartTCPServer(t, host=host, port=port)
3643
print 'listening on port: ', smart_server.port
3645
# for the duration of this server, no UI output is permitted.
3646
# note that this may cause problems with blackbox tests. This should
3647
# be changed with care though, as we dont want to use bandwidth sending
3648
# progress over stderr to smart server clients!
3649
old_factory = ui.ui_factory
3651
ui.ui_factory = ui.SilentUIFactory()
3652
smart_server.serve()
3654
ui.ui_factory = old_factory
3657
class cmd_join(Command):
3658
"""Combine a subtree into its containing tree.
3660
This command is for experimental use only. It requires the target tree
3661
to be in dirstate-with-subtree format, which cannot be converted into
3664
The TREE argument should be an independent tree, inside another tree, but
3665
not part of it. (Such trees can be produced by "bzr split", but also by
3666
running "bzr branch" with the target inside a tree.)
3668
The result is a combined tree, with the subtree no longer an independant
3669
part. This is marked as a merge of the subtree into the containing tree,
3670
and all history is preserved.
3672
If --reference is specified, the subtree retains its independence. It can
3673
be branched by itself, and can be part of multiple projects at the same
3674
time. But operations performed in the containing tree, such as commit
3675
and merge, will recurse into the subtree.
3678
_see_also = ['split']
3679
takes_args = ['tree']
3681
Option('reference', help='Join by reference.'),
3685
def run(self, tree, reference=False):
3686
sub_tree = WorkingTree.open(tree)
3687
parent_dir = osutils.dirname(sub_tree.basedir)
3688
containing_tree = WorkingTree.open_containing(parent_dir)[0]
3689
repo = containing_tree.branch.repository
3690
if not repo.supports_rich_root():
3691
raise errors.BzrCommandError(
3692
"Can't join trees because %s doesn't support rich root data.\n"
3693
"You can use bzr upgrade on the repository."
3697
containing_tree.add_reference(sub_tree)
3698
except errors.BadReferenceTarget, e:
3699
# XXX: Would be better to just raise a nicely printable
3700
# exception from the real origin. Also below. mbp 20070306
3701
raise errors.BzrCommandError("Cannot join %s. %s" %
3705
containing_tree.subsume(sub_tree)
3706
except errors.BadSubsumeSource, e:
3707
raise errors.BzrCommandError("Cannot join %s. %s" %
3711
class cmd_split(Command):
3712
"""Split a tree into two trees.
3714
This command is for experimental use only. It requires the target tree
3715
to be in dirstate-with-subtree format, which cannot be converted into
3718
The TREE argument should be a subdirectory of a working tree. That
3719
subdirectory will be converted into an independent tree, with its own
3720
branch. Commits in the top-level tree will not apply to the new subtree.
3721
If you want that behavior, do "bzr join --reference TREE".
3724
_see_also = ['join']
3725
takes_args = ['tree']
3729
def run(self, tree):
3730
containing_tree, subdir = WorkingTree.open_containing(tree)
3731
sub_id = containing_tree.path2id(subdir)
3733
raise errors.NotVersionedError(subdir)
3735
containing_tree.extract(sub_id)
3736
except errors.RootNotRich:
3737
raise errors.UpgradeRequired(containing_tree.branch.base)
3741
class cmd_merge_directive(Command):
3742
"""Generate a merge directive for auto-merge tools.
3744
A directive requests a merge to be performed, and also provides all the
3745
information necessary to do so. This means it must either include a
3746
revision bundle, or the location of a branch containing the desired
3749
A submit branch (the location to merge into) must be supplied the first
3750
time the command is issued. After it has been supplied once, it will
3751
be remembered as the default.
3753
A public branch is optional if a revision bundle is supplied, but required
3754
if --diff or --plain is specified. It will be remembered as the default
3755
after the first use.
3758
takes_args = ['submit_branch?', 'public_branch?']
3762
_see_also = ['send']
3765
RegistryOption.from_kwargs('patch-type',
3766
'The type of patch to include in the directive.',
3768
value_switches=True,
3770
bundle='Bazaar revision bundle (default).',
3771
diff='Normal unified diff.',
3772
plain='No patch, just directive.'),
3773
Option('sign', help='GPG-sign the directive.'), 'revision',
3774
Option('mail-to', type=str,
3775
help='Instead of printing the directive, email to this address.'),
3776
Option('message', type=str, short_name='m',
3777
help='Message to use when committing this merge.')
3780
encoding_type = 'exact'
3782
def run(self, submit_branch=None, public_branch=None, patch_type='bundle',
3783
sign=False, revision=None, mail_to=None, message=None):
3784
from bzrlib.revision import ensure_null, NULL_REVISION
3785
include_patch, include_bundle = {
3786
'plain': (False, False),
3787
'diff': (True, False),
3788
'bundle': (True, True),
3790
branch = Branch.open('.')
3791
stored_submit_branch = branch.get_submit_branch()
3792
if submit_branch is None:
3793
submit_branch = stored_submit_branch
3795
if stored_submit_branch is None:
3796
branch.set_submit_branch(submit_branch)
3797
if submit_branch is None:
3798
submit_branch = branch.get_parent()
3799
if submit_branch is None:
3800
raise errors.BzrCommandError('No submit branch specified or known')
3802
stored_public_branch = branch.get_public_branch()
3803
if public_branch is None:
3804
public_branch = stored_public_branch
3805
elif stored_public_branch is None:
3806
branch.set_public_branch(public_branch)
3807
if not include_bundle and public_branch is None:
3808
raise errors.BzrCommandError('No public branch specified or'
3810
base_revision_id = None
3811
if revision is not None:
3812
if len(revision) > 2:
3813
raise errors.BzrCommandError('bzr merge-directive takes '
3814
'at most two one revision identifiers')
3815
revision_id = revision[-1].in_history(branch).rev_id
3816
if len(revision) == 2:
3817
base_revision_id = revision[0].in_history(branch).rev_id
3818
base_revision_id = ensure_null(base_revision_id)
3820
revision_id = branch.last_revision()
3821
revision_id = ensure_null(revision_id)
3822
if revision_id == NULL_REVISION:
3823
raise errors.BzrCommandError('No revisions to bundle.')
3824
directive = merge_directive.MergeDirective2.from_objects(
3825
branch.repository, revision_id, time.time(),
3826
osutils.local_time_offset(), submit_branch,
3827
public_branch=public_branch, include_patch=include_patch,
3828
include_bundle=include_bundle, message=message,
3829
base_revision_id=base_revision_id)
3832
self.outf.write(directive.to_signed(branch))
3834
self.outf.writelines(directive.to_lines())
3836
message = directive.to_email(mail_to, branch, sign)
3837
s = SMTPConnection(branch.get_config())
3838
s.send_email(message)
3841
class cmd_send(Command):
3842
"""Mail or create a merge-directive for submiting changes.
3844
A merge directive provides many things needed for requesting merges:
3846
* A machine-readable description of the merge to perform
3848
* An optional patch that is a preview of the changes requested
3850
* An optional bundle of revision data, so that the changes can be applied
3851
directly from the merge directive, without retrieving data from a
3854
If --no-bundle is specified, then public_branch is needed (and must be
3855
up-to-date), so that the receiver can perform the merge using the
3856
public_branch. The public_branch is always included if known, so that
3857
people can check it later.
3859
The submit branch defaults to the parent, but can be overridden. Both
3860
submit branch and public branch will be remembered if supplied.
3862
If a public_branch is known for the submit_branch, that public submit
3863
branch is used in the merge instructions. This means that a local mirror
3864
can be used as your actual submit branch, once you have set public_branch
3867
Mail is sent using your preferred mail program. This should be transparent
3868
on Windows (it uses MAPI). On *nix, it requires the xdg-email utility. If
3869
the preferred client can't be found (or used), your editor will be used.
3871
To use a specific mail program, set the mail_client configuration option.
3872
(For Thunderbird 1.5, this works around some bugs.) Supported values for
3873
specific clients are "evolution", "kmail", "mutt", and "thunderbird";
3874
generic options are "default", "editor", "mapi", and "xdg-email".
3876
If mail is being sent, a to address is required. This can be supplied
3877
either on the commandline, or by setting the submit_to configuration
3880
Two formats are currently supported: "4" uses revision bundle format 4 and
3881
merge directive format 2. It is significantly faster and smaller than
3882
older formats. It is compatible with Bazaar 0.19 and later. It is the
3883
default. "0.9" uses revision bundle format 0.9 and merge directive
3884
format 1. It is compatible with Bazaar 0.12 - 0.18.
3887
encoding_type = 'exact'
3889
_see_also = ['merge']
3891
takes_args = ['submit_branch?', 'public_branch?']
3895
help='Do not include a bundle in the merge directive.'),
3896
Option('no-patch', help='Do not include a preview patch in the merge'
3899
help='Remember submit and public branch.'),
3901
help='Branch to generate the submission from, '
3902
'rather than the one containing the working directory.',
3905
Option('output', short_name='o', help='Write directive to this file.',
3907
Option('mail-to', help='Mail the request to this address.',
3911
RegistryOption.from_kwargs('format',
3912
'Use the specified output format.',
3913
**{'4': 'Bundle format 4, Merge Directive 2 (default)',
3914
'0.9': 'Bundle format 0.9, Merge Directive 1',})
3917
def run(self, submit_branch=None, public_branch=None, no_bundle=False,
3918
no_patch=False, revision=None, remember=False, output=None,
3919
format='4', mail_to=None, message=None, **kwargs):
3920
return self._run(submit_branch, revision, public_branch, remember,
3921
format, no_bundle, no_patch, output,
3922
kwargs.get('from', '.'), mail_to, message)
3924
def _run(self, submit_branch, revision, public_branch, remember, format,
3925
no_bundle, no_patch, output, from_, mail_to, message):
3926
from bzrlib.revision import NULL_REVISION
3928
outfile = StringIO()
3932
outfile = open(output, 'wb')
3934
branch = Branch.open_containing(from_)[0]
3936
config = branch.get_config()
3938
mail_to = config.get_user_option('submit_to')
3940
raise errors.BzrCommandError('No mail-to address'
3942
mail_client = config.get_mail_client()
3943
if remember and submit_branch is None:
3944
raise errors.BzrCommandError(
3945
'--remember requires a branch to be specified.')
3946
stored_submit_branch = branch.get_submit_branch()
3947
remembered_submit_branch = False
3948
if submit_branch is None:
3949
submit_branch = stored_submit_branch
3950
remembered_submit_branch = True
3952
if stored_submit_branch is None or remember:
3953
branch.set_submit_branch(submit_branch)
3954
if submit_branch is None:
3955
submit_branch = branch.get_parent()
3956
remembered_submit_branch = True
3957
if submit_branch is None:
3958
raise errors.BzrCommandError('No submit branch known or'
3960
if remembered_submit_branch:
3961
note('Using saved location: %s', submit_branch)
3963
stored_public_branch = branch.get_public_branch()
3964
if public_branch is None:
3965
public_branch = stored_public_branch
3966
elif stored_public_branch is None or remember:
3967
branch.set_public_branch(public_branch)
3968
if no_bundle and public_branch is None:
3969
raise errors.BzrCommandError('No public branch specified or'
3971
base_revision_id = None
3973
if revision is not None:
3974
if len(revision) > 2:
3975
raise errors.BzrCommandError('bzr send takes '
3976
'at most two one revision identifiers')
3977
revision_id = revision[-1].in_history(branch).rev_id
3978
if len(revision) == 2:
3979
base_revision_id = revision[0].in_history(branch).rev_id
3980
if revision_id is None:
3981
revision_id = branch.last_revision()
3982
if revision_id == NULL_REVISION:
3983
raise errors.BzrCommandError('No revisions to submit.')
3985
directive = merge_directive.MergeDirective2.from_objects(
3986
branch.repository, revision_id, time.time(),
3987
osutils.local_time_offset(), submit_branch,
3988
public_branch=public_branch, include_patch=not no_patch,
3989
include_bundle=not no_bundle, message=message,
3990
base_revision_id=base_revision_id)
3991
elif format == '0.9':
3994
patch_type = 'bundle'
3996
raise errors.BzrCommandError('Format 0.9 does not'
3997
' permit bundle with no patch')
4003
directive = merge_directive.MergeDirective.from_objects(
4004
branch.repository, revision_id, time.time(),
4005
osutils.local_time_offset(), submit_branch,
4006
public_branch=public_branch, patch_type=patch_type,
4009
outfile.writelines(directive.to_lines())
4011
subject = '[MERGE] '
4012
if message is not None:
4015
revision = branch.repository.get_revision(revision_id)
4016
subject += revision.get_summary()
4017
mail_client.compose_merge_request(mail_to, subject,
4024
class cmd_bundle_revisions(cmd_send):
4026
"""Create a merge-directive for submiting changes.
4028
A merge directive provides many things needed for requesting merges:
4030
* A machine-readable description of the merge to perform
4032
* An optional patch that is a preview of the changes requested
4034
* An optional bundle of revision data, so that the changes can be applied
4035
directly from the merge directive, without retrieving data from a
4038
If --no-bundle is specified, then public_branch is needed (and must be
4039
up-to-date), so that the receiver can perform the merge using the
4040
public_branch. The public_branch is always included if known, so that
4041
people can check it later.
4043
The submit branch defaults to the parent, but can be overridden. Both
4044
submit branch and public branch will be remembered if supplied.
4046
If a public_branch is known for the submit_branch, that public submit
4047
branch is used in the merge instructions. This means that a local mirror
4048
can be used as your actual submit branch, once you have set public_branch
4051
Two formats are currently supported: "4" uses revision bundle format 4 and
4052
merge directive format 2. It is significantly faster and smaller than
4053
older formats. It is compatible with Bazaar 0.19 and later. It is the
4054
default. "0.9" uses revision bundle format 0.9 and merge directive
4055
format 1. It is compatible with Bazaar 0.12 - 0.18.
4060
help='Do not include a bundle in the merge directive.'),
4061
Option('no-patch', help='Do not include a preview patch in the merge'
4064
help='Remember submit and public branch.'),
4066
help='Branch to generate the submission from, '
4067
'rather than the one containing the working directory.',
4070
Option('output', short_name='o', help='Write directive to this file.',
4073
RegistryOption.from_kwargs('format',
4074
'Use the specified output format.',
4075
**{'4': 'Bundle format 4, Merge Directive 2 (default)',
4076
'0.9': 'Bundle format 0.9, Merge Directive 1',})
4078
aliases = ['bundle']
4080
_see_also = ['send', 'merge']
4084
def run(self, submit_branch=None, public_branch=None, no_bundle=False,
4085
no_patch=False, revision=None, remember=False, output=None,
4086
format='4', **kwargs):
4089
return self._run(submit_branch, revision, public_branch, remember,
4090
format, no_bundle, no_patch, output,
4091
kwargs.get('from', '.'), None, None)
4094
class cmd_tag(Command):
4095
"""Create, remove or modify a tag naming a revision.
4097
Tags give human-meaningful names to revisions. Commands that take a -r
4098
(--revision) option can be given -rtag:X, where X is any previously
4101
Tags are stored in the branch. Tags are copied from one branch to another
4102
along when you branch, push, pull or merge.
4104
It is an error to give a tag name that already exists unless you pass
4105
--force, in which case the tag is moved to point to the new revision.
4108
_see_also = ['commit', 'tags']
4109
takes_args = ['tag_name']
4112
help='Delete this tag rather than placing it.',
4115
help='Branch in which to place the tag.',
4120
help='Replace existing tags.',
4125
def run(self, tag_name,
4131
branch, relpath = Branch.open_containing(directory)
4135
branch.tags.delete_tag(tag_name)
4136
self.outf.write('Deleted tag %s.\n' % tag_name)
4139
if len(revision) != 1:
4140
raise errors.BzrCommandError(
4141
"Tags can only be placed on a single revision, "
4143
revision_id = revision[0].in_history(branch).rev_id
4145
revision_id = branch.last_revision()
4146
if (not force) and branch.tags.has_tag(tag_name):
4147
raise errors.TagAlreadyExists(tag_name)
4148
branch.tags.set_tag(tag_name, revision_id)
4149
self.outf.write('Created tag %s.\n' % tag_name)
4154
class cmd_tags(Command):
4157
This tag shows a table of tag names and the revisions they reference.
4163
help='Branch whose tags should be displayed.',
4173
branch, relpath = Branch.open_containing(directory)
4174
for tag_name, target in sorted(branch.tags.get_tag_dict().items()):
4175
self.outf.write('%-20s %s\n' % (tag_name, target))
4178
class cmd_reconfigure(Command):
4179
"""Reconfigure the type of a bzr directory.
4181
A target configuration must be specified.
4183
For checkouts, the bind-to location will be auto-detected if not specified.
4184
The order of preference is
4185
1. For a lightweight checkout, the current bound location.
4186
2. For branches that used to be checkouts, the previously-bound location.
4187
3. The push location.
4188
4. The parent location.
4189
If none of these is available, --bind-to must be specified.
4192
takes_args = ['location?']
4193
takes_options = [RegistryOption.from_kwargs('target_type',
4194
title='Target type',
4195
help='The type to reconfigure the directory to.',
4196
value_switches=True, enum_switch=False,
4197
branch='Reconfigure to a branch.',
4198
tree='Reconfigure to a tree.',
4199
checkout='Reconfigure to a checkout.'),
4200
Option('bind-to', help='Branch to bind checkout to.',
4203
help='Perform reconfiguration even if local changes'
4207
def run(self, location=None, target_type=None, bind_to=None, force=False):
4208
directory = bzrdir.BzrDir.open(location)
4209
if target_type is None:
4210
raise errors.BzrCommandError('No target configuration specified')
4211
elif target_type == 'branch':
4212
reconfiguration = reconfigure.Reconfigure.to_branch(directory)
4213
elif target_type == 'tree':
4214
reconfiguration = reconfigure.Reconfigure.to_tree(directory)
4215
elif target_type == 'checkout':
4216
reconfiguration = reconfigure.Reconfigure.to_checkout(directory,
4218
reconfiguration.apply(force)
4221
def _create_prefix(cur_transport):
4222
needed = [cur_transport]
4223
# Recurse upwards until we can create a directory successfully
4225
new_transport = cur_transport.clone('..')
4226
if new_transport.base == cur_transport.base:
4227
raise errors.BzrCommandError(
4228
"Failed to create path prefix for %s."
4229
% cur_transport.base)
4231
new_transport.mkdir('.')
4232
except errors.NoSuchFile:
4233
needed.append(new_transport)
4234
cur_transport = new_transport
4237
# Now we only need to create child directories
4239
cur_transport = needed.pop()
4240
cur_transport.ensure_base()
4243
def _get_mergeable_helper(location):
4244
"""Get a merge directive or bundle if 'location' points to one.
4246
Try try to identify a bundle and returns its mergeable form. If it's not,
4247
we return the tried transport anyway so that it can reused to access the
4250
:param location: can point to a bundle or a branch.
4252
:return: mergeable, transport
4255
url = urlutils.normalize_url(location)
4256
url, filename = urlutils.split(url, exclude_trailing_slash=False)
4257
location_transport = transport.get_transport(url)
4260
# There may be redirections but we ignore the intermediate
4261
# and final transports used
4262
read = bundle.read_mergeable_from_transport
4263
mergeable, t = read(location_transport, filename)
4264
except errors.NotABundle:
4265
# Continue on considering this url a Branch but adjust the
4266
# location_transport
4267
location_transport = location_transport.clone(filename)
4268
return mergeable, location_transport
2746
# command-line interpretation helper for merge-related commands
2747
def merge(other_revision, base_revision,
2748
check_clean=True, ignore_zero=False,
2749
this_dir=None, backup_files=False, merge_type=Merge3Merger,
2750
file_list=None, show_base=False, reprocess=False,
2751
pb=DummyProgress()):
2752
"""Merge changes into a tree.
2755
list(path, revno) Base for three-way merge.
2756
If [None, None] then a base will be automatically determined.
2758
list(path, revno) Other revision for three-way merge.
2760
Directory to merge changes into; '.' by default.
2762
If true, this_dir must have no uncommitted changes before the
2764
ignore_zero - If true, suppress the "zero conflicts" message when
2765
there are no conflicts; should be set when doing something we expect
2766
to complete perfectly.
2767
file_list - If supplied, merge only changes to selected files.
2769
All available ancestors of other_revision and base_revision are
2770
automatically pulled into the branch.
2772
The revno may be -1 to indicate the last revision on the branch, which is
2775
This function is intended for use from the command line; programmatic
2776
clients might prefer to call merge.merge_inner(), which has less magic
2779
from bzrlib.merge import Merger
2780
if this_dir is None:
2782
this_tree = WorkingTree.open_containing(this_dir)[0]
2783
if show_base and not merge_type is Merge3Merger:
2784
raise BzrCommandError("Show-base is not supported for this merge"
2785
" type. %s" % merge_type)
2786
if reprocess and not merge_type.supports_reprocess:
2787
raise BzrCommandError("Conflict reduction is not supported for merge"
2788
" type %s." % merge_type)
2789
if reprocess and show_base:
2790
raise BzrCommandError("Cannot do conflict reduction and show base.")
2792
merger = Merger(this_tree.branch, this_tree=this_tree, pb=pb)
2793
merger.pp = ProgressPhase("Merge phase", 5, pb)
2794
merger.pp.next_phase()
2795
merger.check_basis(check_clean)
2796
merger.set_other(other_revision)
2797
merger.pp.next_phase()
2798
merger.set_base(base_revision)
2799
if merger.base_rev_id == merger.other_rev_id:
2800
note('Nothing to do.')
2802
merger.backup_files = backup_files
2803
merger.merge_type = merge_type
2804
merger.set_interesting_files(file_list)
2805
merger.show_base = show_base
2806
merger.reprocess = reprocess
2807
conflicts = merger.do_merge()
2808
if file_list is None:
2809
merger.set_pending()
4271
2815
# these get imported and then picked up by the scan for cmd_*