mq: avoid silent failure when single patch doesn't apply (issue4604) stable
authorMatt Mackall <mpm@selenic.com>
Mon, 20 Apr 2015 18:13:44 -0500
branchstable
changeset 24826 9b02b678888e
parent 24825 7f9655f37163
child 24827 2f2de8a7f97f
mq: avoid silent failure when single patch doesn't apply (issue4604) The error-handling here is quite byzantine. self._apply raises an AbortNoCleanup, but self.apply was swallowing the exception and returns 2. In self.push, we catch all exceptions.. and cleanup. We try to print a message to clean up.. but that relies on having a top-of-stack. Instead, we re-raise the abort in self.apply, and avoid cleanup on AbortNoCleanup in self.push by adding a trivial new except clause. We also modernize the now-visible abort message.
hgext/mq.py
tests/test-mq-qpush-fail.t
--- a/hgext/mq.py	Mon Apr 20 17:16:05 2015 +0200
+++ b/hgext/mq.py	Mon Apr 20 18:13:44 2015 -0500
@@ -822,7 +822,7 @@
             except AbortNoCleanup:
                 tr.close()
                 self.savedirty()
-                return 2, repo.dirstate.p1()
+                raise
             except: # re-raises
                 try:
                     tr.abort()
@@ -880,7 +880,8 @@
                     touched = set(touched) & tobackup
                     if touched and keepchanges:
                         raise AbortNoCleanup(
-                            _("local changes found, refresh first"))
+                            _("conflicting local changes found"),
+                            hint=_("did you forget to qrefresh?"))
                     self.backup(repo, touched, copy=True)
                     tobackup = tobackup - touched
                 (patcherr, files, fuzz) = self.patch(repo, pf)
@@ -1417,6 +1418,8 @@
                 else:
                     ret = self.apply(repo, s, list, all_files=all_files,
                                      tobackup=tobackup, keepchanges=keepchanges)
+            except AbortNoCleanup:
+                raise
             except: # re-raises
                 self.ui.warn(_('cleaning up working directory...'))
                 node = repo.dirstate.p1()
--- a/tests/test-mq-qpush-fail.t	Mon Apr 20 17:16:05 2015 +0200
+++ b/tests/test-mq-qpush-fail.t	Mon Apr 20 18:13:44 2015 -0500
@@ -344,25 +344,29 @@
   $ echo b >> b
   $ hg qpush --keep-changes
   applying p3
-  errors during apply, please fix and refresh p2
-  [2]
+  abort: conflicting local changes found
+  (did you forget to qrefresh?)
+  [255]
   $ rm b
   $ hg qpush --keep-changes
   applying p3
-  errors during apply, please fix and refresh p2
-  [2]
+  abort: conflicting local changes found
+  (did you forget to qrefresh?)
+  [255]
   $ hg rm -A b
   $ hg qpush --keep-changes
   applying p3
-  errors during apply, please fix and refresh p2
-  [2]
+  abort: conflicting local changes found
+  (did you forget to qrefresh?)
+  [255]
   $ hg revert -aq b
   $ echo d > d
   $ hg add d
   $ hg qpush --keep-changes
   applying p3
-  errors during apply, please fix and refresh p2
-  [2]
+  abort: conflicting local changes found
+  (did you forget to qrefresh?)
+  [255]
   $ hg forget d
   $ rm d
   $ hg qpop
@@ -372,8 +376,9 @@
   $ hg qpush -a --keep-changes
   applying p2
   applying p3
-  errors during apply, please fix and refresh p2
-  [2]
+  abort: conflicting local changes found
+  (did you forget to qrefresh?)
+  [255]
   $ hg qtop
   p2
   $ hg parents --template "{rev} {desc}\n"