##// END OF EJS Templates
mq: introduce qpush --check...
Patrick Mezard -
r16654:490ed897 default
parent child Browse files
Show More
@@ -280,6 +280,9 b' def newcommit(repo, phase, *args, **kwar'
280 280 if phase is not None:
281 281 repo.ui.restoreconfig(backup)
282 282
283 class AbortNoCleanup(error.Abort):
284 pass
285
283 286 class queue(object):
284 287 def __init__(self, ui, path, patchdir=None):
285 288 self.basepath = path
@@ -681,7 +684,7 b' class queue(object):'
681 684
682 685 def apply(self, repo, series, list=False, update_status=True,
683 686 strict=False, patchdir=None, merge=None, all_files=None,
684 tobackup=None):
687 tobackup=None, check=False):
685 688 wlock = lock = tr = None
686 689 try:
687 690 wlock = repo.wlock()
@@ -690,10 +693,14 b' class queue(object):'
690 693 try:
691 694 ret = self._apply(repo, series, list, update_status,
692 695 strict, patchdir, merge, all_files=all_files,
693 tobackup=tobackup)
696 tobackup=tobackup, check=check)
694 697 tr.close()
695 698 self.savedirty()
696 699 return ret
700 except AbortNoCleanup:
701 tr.close()
702 self.savedirty()
703 return 2, repo.dirstate.p1()
697 704 except:
698 705 try:
699 706 tr.abort()
@@ -708,7 +715,7 b' class queue(object):'
708 715
709 716 def _apply(self, repo, series, list=False, update_status=True,
710 717 strict=False, patchdir=None, merge=None, all_files=None,
711 tobackup=None):
718 tobackup=None, check=False):
712 719 """returns (error, hash)
713 720
714 721 error = 1 for unable to read, 2 for patch failed, 3 for patch
@@ -749,6 +756,9 b' class queue(object):'
749 756 if tobackup:
750 757 touched = patchmod.changedfiles(self.ui, repo, pf)
751 758 touched = set(touched) & tobackup
759 if touched and check:
760 raise AbortNoCleanup(
761 _("local changes found, refresh first"))
752 762 self.backup(repo, touched, copy=True)
753 763 tobackup = tobackup - touched
754 764 (patcherr, files, fuzz) = self.patch(repo, pf)
@@ -959,6 +969,10 b' class queue(object):'
959 969 else:
960 970 raise util.Abort(_('patch "%s" already exists') % name)
961 971
972 def checkforcecheck(self, check, force):
973 if force and check:
974 raise util.Abort(_('cannot use both --force and --check'))
975
962 976 def new(self, repo, patchfn, *pats, **opts):
963 977 """options:
964 978 msg: a string or a no-argument function returning a string
@@ -1156,8 +1170,9 b' class queue(object):'
1156 1170 return self.series[i + off]
1157 1171 raise util.Abort(_("patch %s not in series") % patch)
1158 1172
1159 def push(self, repo, patch=None, force=False, list=False,
1160 mergeq=None, all=False, move=False, exact=False, nobackup=False):
1173 def push(self, repo, patch=None, force=False, list=False, mergeq=None,
1174 all=False, move=False, exact=False, nobackup=False, check=False):
1175 self.checkforcecheck(check, force)
1161 1176 diffopts = self.diffopts()
1162 1177 wlock = repo.wlock()
1163 1178 try:
@@ -1212,10 +1227,13 b' class queue(object):'
1212 1227 if start == len(self.series):
1213 1228 self.ui.warn(_('patch series already fully applied\n'))
1214 1229 return 1
1215 if not force:
1230 if not force and not check:
1216 1231 self.checklocalchanges(repo, refresh=self.applied)
1217 1232
1218 1233 if exact:
1234 if check:
1235 raise util.Abort(
1236 _("cannot use --exact and --check together"))
1219 1237 if move:
1220 1238 raise util.Abort(_("cannot use --exact and --move together"))
1221 1239 if self.applied:
@@ -1257,8 +1275,11 b' class queue(object):'
1257 1275 end = self.series.index(patch, start) + 1
1258 1276
1259 1277 tobackup = set()
1260 if not nobackup and force:
1278 if (not nobackup and force) or check:
1261 1279 m, a, r, d = self.checklocalchanges(repo, force=True)
1280 if check:
1281 tobackup.update(m + a + r + d)
1282 else:
1262 1283 tobackup.update(m + a)
1263 1284
1264 1285 s = self.series[start:end]
@@ -1268,7 +1289,7 b' class queue(object):'
1268 1289 ret = self.mergepatch(repo, mergeq, s, diffopts)
1269 1290 else:
1270 1291 ret = self.apply(repo, s, list, all_files=all_files,
1271 tobackup=tobackup)
1292 tobackup=tobackup, check=check)
1272 1293 except:
1273 1294 self.ui.warn(_('cleaning up working directory...'))
1274 1295 node = repo.dirstate.p1()
@@ -1300,8 +1321,7 b' class queue(object):'
1300 1321
1301 1322 def pop(self, repo, patch=None, force=False, update=True, all=False,
1302 1323 nobackup=False, check=False):
1303 if force and check:
1304 raise util.Abort(_('cannot use both --force and --check'))
1324 self.checkforcecheck(check, force)
1305 1325 wlock = repo.wlock()
1306 1326 try:
1307 1327 if patch:
@@ -2638,7 +2658,8 b' def savename(path):'
2638 2658 return newpath
2639 2659
2640 2660 @command("^qpush",
2641 [('f', 'force', None, _('apply on top of local changes')),
2661 [('c', 'check', None, _('tolerate non-conflicting local changes')),
2662 ('f', 'force', None, _('apply on top of local changes')),
2642 2663 ('e', 'exact', None, _('apply the target patch to its recorded parent')),
2643 2664 ('l', 'list', None, _('list patch name in commit text')),
2644 2665 ('a', 'all', None, _('apply all patches')),
@@ -2652,8 +2673,10 b' def savename(path):'
2652 2673 def push(ui, repo, patch=None, **opts):
2653 2674 """push the next patch onto the stack
2654 2675
2655 When -f/--force is applied, all local changes in patched files
2656 will be lost.
2676 By default, abort if the working directory contains uncommitted
2677 changes. With -c/--check, abort only if the uncommitted files
2678 overlap with patched files. With -f/--force, backup and patch over
2679 uncommitted changes.
2657 2680
2658 2681 Return 0 on success.
2659 2682 """
@@ -2672,7 +2695,8 b' def push(ui, repo, patch=None, **opts):'
2672 2695 ui.warn(_("merging with queue at: %s\n") % mergeq.path)
2673 2696 ret = q.push(repo, patch, force=opts.get('force'), list=opts.get('list'),
2674 2697 mergeq=mergeq, all=opts.get('all'), move=opts.get('move'),
2675 exact=opts.get('exact'), nobackup=opts.get('no_backup'))
2698 exact=opts.get('exact'), nobackup=opts.get('no_backup'),
2699 check=opts.get('check'))
2676 2700 return ret
2677 2701
2678 2702 @command("^qpop",
@@ -317,3 +317,54 b' test qgoto --force --no-backup'
317 317 now at: p2
318 318 $ test -f a.orig && echo 'error: backup with --no-backup'
319 319 [1]
320
321 test qpush --check
322
323 $ hg qpush --check --force
324 abort: cannot use both --force and --check
325 [255]
326 $ hg qpush --check --exact
327 abort: cannot use --exact and --check together
328 [255]
329 $ echo b >> b
330 $ hg qpush --check
331 applying p3
332 errors during apply, please fix and refresh p2
333 [2]
334 $ rm b
335 $ hg qpush --check
336 applying p3
337 errors during apply, please fix and refresh p2
338 [2]
339 $ hg rm -A b
340 $ hg qpush --check
341 applying p3
342 errors during apply, please fix and refresh p2
343 [2]
344 $ hg revert -aq b
345 $ echo d > d
346 $ hg add d
347 $ hg qpush --check
348 applying p3
349 errors during apply, please fix and refresh p2
350 [2]
351 $ hg forget d
352 $ rm d
353 $ hg qpop
354 popping p2
355 patch queue now empty
356 $ echo b >> b
357 $ hg qpush -a --check
358 applying p2
359 applying p3
360 errors during apply, please fix and refresh p2
361 [2]
362 $ hg qtop
363 p2
364 $ hg parents --template "{rev} {desc}\n"
365 2 imported patch p2
366 $ hg st b
367 M b
368 $ cat b
369 b
370 b
General Comments 0
You need to be logged in to leave comments. Login now