~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/builtins.py

  • Committer: Andrew Bennetts
  • Date: 2010-05-28 08:00:39 UTC
  • mto: (5050.3.16 2.2)
  • mto: This revision was merged to the branch mainline in revision 5365.
  • Revision ID: andrew.bennetts@canonical.com-20100528080039-0sa30to282l6opjk
Very rough first draft of cmd_merge_into from bzr-merge-into.  Passes its blackbox tests.

Show diffs side-by-side

added added

removed removed

Lines of Context:
4039
4039
        return stored_location
4040
4040
 
4041
4041
 
 
4042
class cmd_merge_into(Command):
 
4043
    """Merge a branch into a subdirectory of the current one.
 
4044
 
 
4045
    LOCATION is the branch that will be merged into this one.
 
4046
    SUBDIR is the subdirectory that will be used for merging.
 
4047
      (defaults to basename of LOCATION)
 
4048
 
 
4049
    After running 'bzr merge-into OTHER SUBDIR' all of the files from OTHER will be
 
4050
    present underneath the subdirectory SUBDIR.
 
4051
    """
 
4052
 
 
4053
    takes_args = ['location', 'subdir?', 'only?']
 
4054
    takes_options = []
 
4055
 
 
4056
    def run(self, location, subdir=None, only=None):
 
4057
        # Open and lock the various tree and branch objects
 
4058
        if not subdir: # default to same name as source dir
 
4059
            subdir = os.path.basename(location)
 
4060
        wt, subdir_relpath = WorkingTree.open_containing(subdir)
 
4061
        wt.lock_write()
 
4062
        self.add_cleanup(wt.unlock)
 
4063
        branch_to_merge = Branch.open(location)
 
4064
        branch_to_merge.lock_read()
 
4065
        self.add_cleanup(branch_to_merge.unlock)
 
4066
        other_tree = branch_to_merge.basis_tree()
 
4067
        other_tree.lock_read()
 
4068
        self.add_cleanup(other_tree.unlock)
 
4069
        if only is None:
 
4070
            only = ''
 
4071
        # Perform the merge
 
4072
        merger = _mod_merge.MergeIntoMerger(this_tree=wt,
 
4073
                other_tree=other_tree, other_branch=branch_to_merge,
 
4074
                target_subdir=subdir_relpath, source_subpath=only)
 
4075
        merger.set_base_revision(
 
4076
            _mod_revision.NULL_REVISION, branch_to_merge)
 
4077
        conflicts = merger.do_merge()
 
4078
        merger.set_pending()
 
4079
        # Report the results
 
4080
        if not conflicts:
 
4081
            self.outf.write('merge-into successful\n')
 
4082
        else:
 
4083
            self.outf.write('merge-into conflicts: %s\n' % (conflicts,))
 
4084
            return 1
 
4085
 
 
4086
 
4042
4087
class cmd_remerge(Command):
4043
4088
    __doc__ = """Redo a merge.
4044
4089