changeset 27924:24361fb68cba stable

transaction: abort transaction during hook exception The new transaction context did not handle the case where an exception during close should still call release. This cause pretxnclose hooks that failed to cause the transaction to fail without aborting, thus requiring a hg recover. I've added a test.
author Durham Goode <durham@fb.com>
date Tue, 19 Jan 2016 15:18:21 -0800
parents f62dea3f3697
children f6d73c8756e2
files mercurial/transaction.py tests/test-hook.t
diffstat 2 files changed, 27 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/transaction.py	Wed Jan 20 22:39:51 2016 -0600
+++ b/mercurial/transaction.py	Tue Jan 19 15:18:21 2016 -0800
@@ -337,9 +337,11 @@
         return self
 
     def __exit__(self, exc_type, exc_val, exc_tb):
-        if exc_type is None:
-            self.close()
-        self.release()
+        try:
+            if exc_type is None:
+                self.close()
+        finally:
+            self.release()
 
     def running(self):
         return self.count > 0
--- a/tests/test-hook.t	Wed Jan 20 22:39:51 2016 -0600
+++ b/tests/test-hook.t	Tue Jan 19 15:18:21 2016 -0800
@@ -724,3 +724,25 @@
   date:        Thu Jan 01 00:00:00 1970 +0000
   summary:     b
   
+  $ cd ..
+
+pretxnclose hook failure should abort the transaction
+
+  $ hg init txnfailure
+  $ cd txnfailure
+  $ touch a && hg commit -Aqm a
+  $ cat >> .hg/hgrc <<EOF
+  > [hooks]
+  > pretxnclose.error = exit 1
+  > EOF
+  $ hg strip -r 0 --config extensions.strip=
+  0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+  saved backup bundle to * (glob)
+  transaction abort!
+  rollback completed
+  strip failed, full bundle stored in * (glob)
+  abort: pretxnclose.error hook exited with status 1
+  [255]
+  $ hg recover
+  no interrupted transaction available
+  [1]