/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to commands.py

In .testr.conf; run all git-relevant tests.

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
    takes_args = ["src_location", "dest_location?"]
38
38
 
39
39
    def run(self, src_location, dest_location=None):
 
40
        from collections import defaultdict
40
41
        import os
41
42
        from bzrlib import (
42
43
            ui,
58
59
            GitBranch,
59
60
            extract_tags,
60
61
            )
 
62
        from bzrlib.plugins.git.refs import ref_to_branch_name
61
63
        from bzrlib.plugins.git.repository import GitRepository
62
64
 
63
65
        if dest_location is None:
81
83
        interrepo = InterRepository.get(source_repo, target_repo)
82
84
        mapping = source_repo.get_mapping()
83
85
        refs = interrepo.fetch()
 
86
        unpeeled_tags = defaultdict(set)
84
87
        tags = {}
85
 
        for k, v in extract_tags(refs).iteritems():
86
 
            tags[k] = mapping.revision_id_foreign_to_bzr(v)
 
88
        for k, (peeled, unpeeled) in extract_tags(refs).iteritems():
 
89
            tags[k] = mapping.revision_id_foreign_to_bzr(peeled)
 
90
            if unpeeled is not None:
 
91
                unpeeled_tags[peeled].add(unpeeled)
 
92
        # FIXME: Store unpeeled tag map
87
93
        pb = ui.ui_factory.nested_progress_bar()
88
94
        try:
89
95
            for i, (name, ref) in enumerate(refs.iteritems()):
90
 
                if name.startswith("refs/tags/"):
 
96
                try:
 
97
                    ref_to_branch_name(name)
 
98
                except ValueError:
 
99
                    # Not a branch, ignore
91
100
                    continue
92
101
                pb.update("creating branches", i, len(refs))
93
102
                head_loc = os.path.join(dest_location, name)
204
213
    "bzr pull".
205
214
    """
206
215
 
 
216
    takes_options = [
 
217
        Option('signoff', short_name='s', help='Add a Signed-off-by line.'),
 
218
        'force']
207
219
    takes_args = ["patches*"]
208
220
 
209
 
    def _apply_patch(self, wt, f):
 
221
    def _apply_patch(self, wt, f, signoff):
 
222
        """Apply a patch.
 
223
 
 
224
        :param wt: A Bazaar working tree object.
 
225
        :param f: Patch file to read.
 
226
        :param signoff: Add Signed-Off-By flag.
 
227
        """
 
228
        from bzrlib.errors import BzrCommandError
210
229
        from dulwich.patch import git_am_patch_split
 
230
        import subprocess
211
231
        (c, diff, version) = git_am_patch_split(f)
212
 
        # FIXME: Process diff
213
 
        wt.commit(committer=c.committer,
214
 
                  message=c.message)
 
232
        # FIXME: Cope with git-specific bits in patch
 
233
        p = subprocess.Popen(["patch", "-p1"], stdin=subprocess.PIPE, cwd=wt.basedir)
 
234
        p.communicate(diff)
 
235
        exitcode = p.wait()
 
236
        if exitcode != 0:
 
237
            raise BzrCommandError("error running patch")
 
238
        message = c.message
 
239
        if signoff:
 
240
            signed_off_by = wt.branch.get_config().username()
 
241
            message += "Signed-off-by: %s\n" % signed_off_by.encode('utf-8')
 
242
        wt.commit(authors=[c.author], message=message)
215
243
 
216
 
    def run(self, patches_list=None):
 
244
    def run(self, patches_list=None, signoff=False, force=False):
 
245
        from bzrlib.errors import UncommittedChanges
217
246
        from bzrlib.workingtree import WorkingTree
218
247
        if patches_list is None:
219
248
            patches_list = []
220
 
        
 
249
 
221
250
        tree, _ = WorkingTree.open_containing(".")
 
251
        if tree.basis_tree().changes_from(tree).has_changed() and not force:
 
252
            raise UncommittedChanges(tree)
222
253
        tree.lock_write()
223
254
        try:
224
255
            for patch in patches_list:
225
256
                f = open(patch, 'r')
226
257
                try:
227
 
                    self._apply_patch(tree, f)
 
258
                    self._apply_patch(tree, f, signoff=signoff)
228
259
                finally:
229
260
                    f.close()
230
261
        finally: