Browse Source

Make the GitFile context manager discard writes on exceptions

Dan Villiom Podlaski Christiansen 2 years ago
parent
commit
199d7d6d7d
1 changed files with 4 additions and 1 deletions
  1. 4 1
      dulwich/file.py

+ 4 - 1
dulwich/file.py

@@ -209,7 +209,10 @@ class _GitFile(object):
         return self
 
     def __exit__(self, exc_type, exc_val, exc_tb):
-        self.close()
+        if exc_type is not None:
+            self.abort()
+        else:
+            self.close()
 
     def __getattr__(self, name):
         """Proxy property calls to the underlying file."""