Parcourir la source

Make the GitFile context manager discard writes on exceptions

Dan Villiom Podlaski Christiansen il y a 2 ans
Parent
commit
199d7d6d7d
1 fichiers modifiés avec 4 ajouts et 1 suppressions
  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."""