2666
2668
if revision is not None:
2667
2669
raise errors.BzrCommandError(
2668
2670
'Cannot use -r with merge directives or bundles')
2669
other_revision_id = mergeable.install_revisions(
2670
tree.branch.repository)
2671
revision = [RevisionSpec.from_string(
2672
'revid:' + other_revision_id)]
2674
if revision is None \
2675
or len(revision) < 1 or revision[0].needs_branch():
2676
branch = self._get_remembered_parent(tree, branch, 'Merging from')
2678
if revision is None or len(revision) < 1:
2681
other = [branch, None]
2671
mergeable.install_revisions(tree.branch.repository)
2672
base_revision_id, other_revision_id, verified =\
2673
mergeable.get_merge_request(tree.branch.repository)
2674
if base_revision_id in tree.branch.repository.get_ancestry(
2675
tree.branch.last_revision(), topo_sorted=False):
2676
base_revision_id = None
2682
if other_revision_id is None:
2683
verified = 'inapplicable'
2684
if revision is None \
2685
or len(revision) < 1 or revision[0].needs_branch():
2686
branch = self._get_remembered_parent(tree, branch,
2689
if revision is None or len(revision) < 1:
2692
other = [branch, None]
2695
other = [branch, -1]
2696
other_branch, path = Branch.open_containing(branch)
2684
other = [branch, -1]
2685
other_branch, path = Branch.open_containing(branch)
2688
raise errors.BzrCommandError('Cannot use --uncommitted and'
2689
' --revision at the same time.')
2690
branch = revision[0].get_branch() or branch
2691
if len(revision) == 1:
2693
if other_revision_id is not None:
2699
raise errors.BzrCommandError('Cannot use --uncommitted and'
2700
' --revision at the same time.')
2701
branch = revision[0].get_branch() or branch
2702
if len(revision) == 1:
2698
2704
other_branch, path = Branch.open_containing(branch)
2699
2705
revno = revision[0].in_history(other_branch).revno
2700
2706
other = [branch, revno]
2702
assert len(revision) == 2
2703
if None in revision:
2704
raise errors.BzrCommandError(
2705
"Merge doesn't permit empty revision specifier.")
2706
base_branch, path = Branch.open_containing(branch)
2707
branch1 = revision[1].get_branch() or branch
2708
other_branch, path1 = Branch.open_containing(branch1)
2709
if revision[0].get_branch() is not None:
2710
# then path was obtained from it, and is None.
2708
assert len(revision) == 2
2709
if None in revision:
2710
raise errors.BzrCommandError(
2711
"Merge doesn't permit empty revision specifier.")
2712
base_branch, path = Branch.open_containing(branch)
2713
branch1 = revision[1].get_branch() or branch
2714
other_branch, path1 = Branch.open_containing(branch1)
2715
if revision[0].get_branch() is not None:
2716
# then path was obtained from it, and is None.
2713
base = [branch, revision[0].in_history(base_branch).revno]
2714
other = [branch1, revision[1].in_history(other_branch).revno]
2719
base = [branch, revision[0].in_history(base_branch).revno]
2721
revision[1].in_history(other_branch).revno]
2716
2723
if ((tree.branch.get_parent() is None or remember) and
2717
2724
other_branch is not None):
3614
3631
public_branch = stored_public_branch
3615
3632
elif stored_public_branch is None:
3616
3633
branch.set_public_branch(public_branch)
3617
if patch_type != "bundle" and public_branch is None:
3634
if not include_bundle and public_branch is None:
3618
3635
raise errors.BzrCommandError('No public branch specified or'
3637
base_revision_id = None
3620
3638
if revision is not None:
3621
if len(revision) != 1:
3639
if len(revision) > 2:
3622
3640
raise errors.BzrCommandError('bzr merge-directive takes '
3623
'exactly one revision identifier')
3625
revision_id = revision[0].in_history(branch).rev_id
3641
'at most two one revision identifiers')
3642
revision_id = revision[-1].in_history(branch).rev_id
3643
if len(revision) == 2:
3644
base_revision_id = revision[0].in_history(branch).rev_id
3645
base_revision_id = ensure_null(base_revision_id)
3627
3647
revision_id = branch.last_revision()
3628
3648
revision_id = ensure_null(revision_id)
3629
3649
if revision_id == NULL_REVISION:
3630
3650
raise errors.BzrCommandError('No revisions to bundle.')
3631
directive = merge_directive.MergeDirective.from_objects(
3651
directive = merge_directive.MergeDirective2.from_objects(
3632
3652
branch.repository, revision_id, time.time(),
3633
3653
osutils.local_time_offset(), submit_branch,
3634
public_branch=public_branch, patch_type=patch_type,
3654
public_branch=public_branch, include_patch=include_patch,
3655
include_bundle=include_bundle, message=message,
3656
base_revision_id=base_revision_id)
3636
3657
if mail_to is None:
3638
3659
self.outf.write(directive.to_signed(branch))
3644
3665
s.send_email(message)
3668
class cmd_submit(Command):
3669
"""Create a merge-directive for submiting changes.
3671
A merge directive provides many things needed for requesting merges:
3672
- A machine-readable description of the merge to perform
3673
- An optional patch that is a preview of the changes requested
3674
- An optional bundle of revision data, so that the changes can be applied
3675
directly from the merge directive, without retrieving data from a
3678
If --no-bundle is specified, then public_branch is needed (and must be
3679
up-to-date), so that the receiver can perform the merge using the
3680
public_branch. The public_branch is always included if known, so that
3681
people can check it later.
3683
The submit branch defaults to the parent, but can be overridden. Both
3684
submit branch and public branch will be remembered if supplied.
3686
If a public_branch is known for the submit_branch, that public submit
3687
branch is used in the merge instructions. This means that a local mirror
3688
can be used as your actual submit branch, once you have set public_branch
3692
encoding_type = 'exact'
3694
aliases = ['bundle', 'bundle-revisions']
3696
_see_also = ['merge']
3698
takes_args = ['submit_branch?', 'public_branch?']
3701
help='Do not include a bundle in the merge directive.'),
3702
Option('no-patch', help='Do not include a preview patch in the merge'
3705
help='Remember submit and public branch.'),
3707
help='Branch to generate the submission from, '
3708
'rather than the one containing the working directory.',
3711
Option('output', short_name='o', help='Write directive to this file.',
3716
def run(self, submit_branch=None, public_branch=None, no_bundle=False,
3717
no_patch=False, revision=None, remember=False, output=None,
3719
from bzrlib.revision import ensure_null, NULL_REVISION
3723
outfile = open(output, 'wb')
3725
from_ = kwargs.get('from', '.')
3726
branch = Branch.open_containing(from_)[0]
3727
if remember and submit_branch is None:
3728
raise errors.BzrCommandError(
3729
'--remember requires a branch to be specified.')
3730
stored_submit_branch = branch.get_submit_branch()
3731
remembered_submit_branch = False
3732
if submit_branch is None:
3733
submit_branch = stored_submit_branch
3734
remembered_submit_branch = True
3736
if stored_submit_branch is None or remember:
3737
branch.set_submit_branch(submit_branch)
3738
if submit_branch is None:
3739
submit_branch = branch.get_parent()
3740
remembered_submit_branch = True
3741
if submit_branch is None:
3742
raise errors.BzrCommandError('No submit branch known or'
3744
if remembered_submit_branch:
3745
note('Using saved location: %s', submit_branch)
3747
stored_public_branch = branch.get_public_branch()
3748
if public_branch is None:
3749
public_branch = stored_public_branch
3750
elif stored_public_branch is None or remember:
3751
branch.set_public_branch(public_branch)
3752
if no_bundle and public_branch is None:
3753
raise errors.BzrCommandError('No public branch specified or'
3755
base_revision_id = None
3756
if revision is not None:
3757
if len(revision) > 2:
3758
raise errors.BzrCommandError('bzr submit takes '
3759
'at most two one revision identifiers')
3760
revision_id = revision[-1].in_history(branch).rev_id
3761
if len(revision) == 2:
3762
base_revision_id = revision[0].in_history(branch).rev_id
3763
base_revision_id = ensure_null(base_revision_id)
3765
revision_id = branch.last_revision()
3766
revision_id = ensure_null(revision_id)
3767
if revision_id == NULL_REVISION:
3768
raise errors.BzrCommandError('No revisions to submit.')
3769
directive = merge_directive.MergeDirective2.from_objects(
3770
branch.repository, revision_id, time.time(),
3771
osutils.local_time_offset(), submit_branch,
3772
public_branch=public_branch, include_patch=not no_patch,
3773
include_bundle=not no_bundle, message=None,
3774
base_revision_id=base_revision_id)
3775
outfile.writelines(directive.to_lines())
3777
if output is not None:
3647
3780
class cmd_tag(Command):
3648
3781
"""Create a tag naming a revision.