~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to shelf.py

  • Committer: Michael Ellerman
  • Date: 2006-03-12 14:12:00 UTC
  • mto: (325.1.2 bzrtools) (0.3.1 shelf-dev)
  • mto: This revision was merged to the branch mainline in revision 334.
  • Revision ID: michael@ellerman.id.au-20060312141200-0e20055c572dfc23
Add support for unshelving -p0 patches, for backward compatibility.

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
import sys
5
5
import subprocess
6
6
from datetime import datetime
7
 
from errors import CommandError
 
7
from errors import CommandError, PatchFailed
8
8
from hunk_selector import ShelveHunkSelector, UnshelveHunkSelector
9
9
from patchsource import PatchSource, FilePatchSource
10
10
 
157
157
        try:
158
158
            self._run_patch(to_unshelve, dry_run=True)
159
159
            self._run_patch(to_unshelve)
160
 
        except CommandError:
161
 
            raise CommandError("Your shelved patch no " \
 
160
        except PatchFailed:
 
161
            try:
 
162
                self._run_patch(to_unshelve, strip=0, dry_run=True)
 
163
                self._run_patch(to_unshelve, strip=0)
 
164
            except PatchFailed:
 
165
                raise CommandError("Your shelved patch no " \
162
166
                    "longer applies cleanly to the working tree!")
163
167
 
164
168
        # Backup the shelved patch
205
209
 
206
210
        self._run_patch(to_shelve, reverse=True)
207
211
 
208
 
    def _run_patch(self, patches, reverse=False, dry_run=False):
209
 
        args = ['patch', '-d', self.base, '-s', '-p1', '-f']
 
212
    def _run_patch(self, patches, strip=1, reverse=False, dry_run=False):
 
213
        args = ['patch', '-d', self.base, '-s', '-p%d' % strip, '-f']
210
214
        if reverse:
211
215
            args.append('-R')
212
216
        if dry_run:
224
228
 
225
229
        result = process.wait()
226
230
        if result != 0:
227
 
            raise CommandError("Failed applying patches!")
 
231
            raise PatchFailed()
228
232
 
229
233
        return result
230
234