瀏覽代碼

Make the GitFile context manager discard writes on exceptions

Dan Villiom Podlaski Christiansen 2 年之前
父節點
當前提交
199d7d6d7d
共有 1 個文件被更改,包括 4 次插入1 次删除
  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."""