~bzr/ubuntu/maverick/bzr-git/bzr-ppa

« back to all changes in this revision

Viewing changes to commands.py

  • Committer: Jelmer Vernooij
  • Date: 2010-11-06 22:47:45 UTC
  • mfrom: (17.25.368 upstream)
  • Revision ID: jelmer@debian.org-20101106224745-ephery62e224bjup
* New upstream snapshot.
* Run testsuite as part of build.

Show diffs side-by-side

added added

removed removed

Lines of Context:
204
204
    "bzr pull".
205
205
    """
206
206
 
 
207
    takes_options = [
 
208
        Option('signoff', short_name='s', help='Add a Signed-off-by line.'),
 
209
        'force']
207
210
    takes_args = ["patches*"]
208
211
 
209
 
    def _apply_patch(self, wt, f):
 
212
    def _apply_patch(self, wt, f, signoff):
 
213
        """Apply a patch.
 
214
 
 
215
        :param wt: A Bazaar working tree object.
 
216
        :param f: Patch file to read.
 
217
        :param signoff: Add Signed-Off-By flag.
 
218
        """
210
219
        from bzrlib.errors import BzrCommandError
211
220
        from dulwich.patch import git_am_patch_split
212
221
        import subprocess
217
226
        exitcode = p.wait()
218
227
        if exitcode != 0:
219
228
            raise BzrCommandError("error running patch")
220
 
        wt.commit(authors=[c.author], message=c.message)
 
229
        message = c.message
 
230
        if signoff:
 
231
            signed_off_by = wt.branch.get_config().username()
 
232
            message += "Signed-off-by: %s\n" % signed_off_by.encode('utf-8')
 
233
        wt.commit(authors=[c.author], message=message)
221
234
 
222
 
    def run(self, patches_list=None):
 
235
    def run(self, patches_list=None, signoff=False, force=False):
223
236
        from bzrlib.errors import UncommittedChanges
224
237
        from bzrlib.workingtree import WorkingTree
225
238
        if patches_list is None:
226
239
            patches_list = []
227
240
 
228
241
        tree, _ = WorkingTree.open_containing(".")
229
 
        if tree.basis_tree().changes_from(tree).has_changed():
 
242
        if tree.basis_tree().changes_from(tree).has_changed() and not force:
230
243
            raise UncommittedChanges(tree)
231
244
        tree.lock_write()
232
245
        try:
233
246
            for patch in patches_list:
234
247
                f = open(patch, 'r')
235
248
                try:
236
 
                    self._apply_patch(tree, f)
 
249
                    self._apply_patch(tree, f, signoff=signoff)
237
250
                finally:
238
251
                    f.close()
239
252
        finally: