/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

Add testr magic.

Show diffs side-by-side

added added

removed removed

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