##// END OF EJS Templates
mq: backup local changes in qpush --force...
Patrick Mezard -
r16634:435375cc stable
parent child Browse files
Show More
@@ -554,14 +554,17 b' class queue(object):'
554 554 except OSError, inst:
555 555 self.ui.warn(_('error removing undo: %s\n') % str(inst))
556 556
557 def backup(self, repo, files):
557 def backup(self, repo, files, copy=False):
558 558 # backup local changes in --force case
559 559 for f in sorted(files):
560 560 absf = repo.wjoin(f)
561 561 if os.path.lexists(absf):
562 562 self.ui.note(_('saving current version of %s as %s\n') %
563 563 (f, f + '.orig'))
564 util.rename(absf, absf + '.orig')
564 if copy:
565 util.copyfile(absf, absf + '.orig')
566 else:
567 util.rename(absf, absf + '.orig')
565 568
566 569 def printdiff(self, repo, diffopts, node1, node2=None, files=None,
567 570 fp=None, changes=None, opts={}):
@@ -677,7 +680,8 b' class queue(object):'
677 680 return (False, list(files), False)
678 681
679 682 def apply(self, repo, series, list=False, update_status=True,
680 strict=False, patchdir=None, merge=None, all_files=None):
683 strict=False, patchdir=None, merge=None, all_files=None,
684 tobackup=None):
681 685 wlock = lock = tr = None
682 686 try:
683 687 wlock = repo.wlock()
@@ -685,7 +689,8 b' class queue(object):'
685 689 tr = repo.transaction("qpush")
686 690 try:
687 691 ret = self._apply(repo, series, list, update_status,
688 strict, patchdir, merge, all_files=all_files)
692 strict, patchdir, merge, all_files=all_files,
693 tobackup=tobackup)
689 694 tr.close()
690 695 self.savedirty()
691 696 return ret
@@ -702,9 +707,14 b' class queue(object):'
702 707 self.removeundo(repo)
703 708
704 709 def _apply(self, repo, series, list=False, update_status=True,
705 strict=False, patchdir=None, merge=None, all_files=None):
706 '''returns (error, hash)
707 error = 1 for unable to read, 2 for patch failed, 3 for patch fuzz'''
710 strict=False, patchdir=None, merge=None, all_files=None,
711 tobackup=None):
712 """returns (error, hash)
713
714 error = 1 for unable to read, 2 for patch failed, 3 for patch
715 fuzz. tobackup is None or a set of files to backup before they
716 are modified by a patch.
717 """
708 718 # TODO unify with commands.py
709 719 if not patchdir:
710 720 patchdir = self.path
@@ -736,6 +746,11 b' class queue(object):'
736 746 message = '\n'.join(message)
737 747
738 748 if ph.haspatch:
749 if tobackup:
750 touched = patchmod.changedfiles(self.ui, repo, pf)
751 touched = set(touched) & tobackup
752 self.backup(repo, touched, copy=True)
753 tobackup = tobackup - touched
739 754 (patcherr, files, fuzz) = self.patch(repo, pf)
740 755 if all_files is not None:
741 756 all_files.update(files)
@@ -1241,13 +1256,19 b' class queue(object):'
1241 1256 else:
1242 1257 end = self.series.index(patch, start) + 1
1243 1258
1259 tobackup = set()
1260 if force:
1261 m, a, r, d = self.checklocalchanges(repo, force=True)
1262 tobackup.update(m + a)
1263
1244 1264 s = self.series[start:end]
1245 1265 all_files = set()
1246 1266 try:
1247 1267 if mergeq:
1248 1268 ret = self.mergepatch(repo, mergeq, s, diffopts)
1249 1269 else:
1250 ret = self.apply(repo, s, list, all_files=all_files)
1270 ret = self.apply(repo, s, list, all_files=all_files,
1271 tobackup=tobackup)
1251 1272 except:
1252 1273 self.ui.warn(_('cleaning up working directory...'))
1253 1274 node = repo.dirstate.p1()
@@ -188,3 +188,52 b' test qpop --force and backup files'
188 188 bb
189 189 $ cat c.orig
190 190 cc
191
192 test qpush --force and backup files
193
194 $ echo a >> a
195 $ hg qnew p2
196 $ echo b >> b
197 $ echo d > d
198 $ echo e > e
199 $ hg add d e
200 $ hg rm c
201 $ hg qnew p3
202 $ hg qpop -a
203 popping p3
204 popping p2
205 patch queue now empty
206 $ echo a >> a
207 $ echo b1 >> b
208 $ echo d1 > d
209 $ hg add d
210 $ echo e1 > e
211 $ hg qpush -a --force --verbose
212 applying p2
213 saving current version of a as a.orig
214 patching file a
215 a
216 applying p3
217 saving current version of b as b.orig
218 saving current version of d as d.orig
219 patching file b
220 patching file c
221 patching file d
222 file d already exists
223 1 out of 1 hunks FAILED -- saving rejects to file d.rej
224 patching file e
225 file e already exists
226 1 out of 1 hunks FAILED -- saving rejects to file e.rej
227 patch failed to apply
228 b
229 patch failed, rejects left in working dir
230 errors during apply, please fix and refresh p3
231 [2]
232 $ cat a.orig
233 a
234 a
235 $ cat b.orig
236 b
237 b1
238 $ cat d.orig
239 d1
@@ -1356,11 +1356,15 b' qpush should fail, local changes'
1356 1356
1357 1357 apply force, should discard changes in hello, but not bye
1358 1358
1359 $ hg qpush -f
1359 $ hg qpush -f --verbose
1360 1360 applying empty
1361 saving current version of hello.txt as hello.txt.orig
1362 patching file hello.txt
1363 hello.txt
1361 1364 now at: empty
1362 1365 $ hg st
1363 1366 M bye.txt
1367 ? hello.txt.orig
1364 1368 $ hg diff --config diff.nodates=True
1365 1369 diff -r ba252371dbc1 bye.txt
1366 1370 --- a/bye.txt
General Comments 0
You need to be logged in to leave comments. Login now