# HG changeset patch # User Patrick Mezard # Date 1336745822 -7200 # Node ID b2ca2f40c9c1aa0e528381b3d10920915aaed527 # Parent 0c0c1101e46da30be2a84e371f9b5a41734e245f mq: backup local changes in qpop --force (issue3433) diff -r 0c0c1101e46d -r b2ca2f40c9c1 hgext/mq.py --- a/hgext/mq.py Fri May 11 16:08:49 2012 +0200 +++ b/hgext/mq.py Fri May 11 16:17:02 2012 +0200 @@ -554,6 +554,15 @@ except OSError, inst: self.ui.warn(_('error removing undo: %s\n') % str(inst)) + def backup(self, repo, files): + # backup local changes in --force case + for f in sorted(files): + absf = repo.wjoin(f) + if os.path.lexists(absf): + self.ui.note(_('saving current version of %s as %s\n') % + (f, f + '.orig')) + util.rename(absf, absf + '.orig') + def printdiff(self, repo, diffopts, node1, node2=None, files=None, fp=None, changes=None, opts={}): stat = opts.get('stat') @@ -1313,8 +1322,10 @@ break update = needupdate - if not force and update: - self.checklocalchanges(repo) + tobackup = set() + if update: + m, a, r, d = self.checklocalchanges(repo, force=force) + tobackup.update(m + a) self.applieddirty = True end = len(self.applied) @@ -1344,6 +1355,10 @@ m, a, r, d = repo.status(qp, top)[:4] if d: raise util.Abort(_("deletions found between repo revs")) + + # backup local changes in --force case + self.backup(repo, set(a + m + r) & tobackup) + for f in a: try: util.unlinkpath(repo.wjoin(f)) diff -r 0c0c1101e46d -r b2ca2f40c9c1 tests/test-mq-qpush-fail.t --- a/tests/test-mq-qpush-fail.t Fri May 11 16:08:49 2012 +0200 +++ b/tests/test-mq-qpush-fail.t Fri May 11 16:17:02 2012 +0200 @@ -150,3 +150,41 @@ abort: cannot push to a previous patch: a [255] +test qpop --force and backup files + + $ hg qpop -a + popping b + patch queue now empty + $ hg qq --create force + $ echo a > a + $ echo b > b + $ echo c > c + $ hg ci -Am add a b c + $ echo a >> a + $ hg rm b + $ hg rm c + $ hg qnew p1 + $ echo a >> a + $ echo bb > b + $ hg add b + $ echo cc > c + $ hg add c + $ hg qpop --force --verbose + saving current version of a as a.orig + saving current version of b as b.orig + saving current version of c as c.orig + popping p1 + patch queue now empty + $ hg st + ? a.orig + ? b.orig + ? c.orig + ? untracked-file + $ cat a.orig + a + a + a + $ cat b.orig + bb + $ cat c.orig + cc