← Back to team overview

dulwich-users team mailing list archive

[PATCH 8/9] test_repository: Use GitFile when modifying packed-refs.

 

From: Dave Borowitz <dborowitz@xxxxxxxxxx>

This is a workaround for an issue in shutil.copytree() in Python 2.4
where directory permission bits were not copied correctly. As a result,
the test repo could end up in a state where clobbering the existing
packed-refs file would fail with permission denied.

As a side benefit, this is now more correct as example code, since in
general code modifying packed-refs should be using a locking protocol.

Change-Id: I72671757c660575b0b1faf0a95d298584a6b5f10
---
 NEWS                             |    4 ++++
 dulwich/tests/test_repository.py |    7 +++++--
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/NEWS b/NEWS
index d0e9042..0d35abd 100644
--- a/NEWS
+++ b/NEWS
@@ -12,6 +12,10 @@
 
   * Web server supports streaming progress/pack output. (Dave Borowitz)
 
+ TESTS
+
+  * Use GitFile when modifying packed-refs in tests. (Dave Borowitz)
+
  API CHANGES
 
   * ObjectStore.iter_tree_contents now walks contents in depth-first, sorted
diff --git a/dulwich/tests/test_repository.py b/dulwich/tests/test_repository.py
index 9b34d13..a9bb653 100644
--- a/dulwich/tests/test_repository.py
+++ b/dulwich/tests/test_repository.py
@@ -26,6 +26,9 @@ import tempfile
 import warnings
 
 from dulwich import errors
+from dulwich.file import (
+    GitFile,
+    )
 from dulwich.object_store import (
     tree_lookup_path,
     )
@@ -767,10 +770,10 @@ class DiskRefsContainerTests(RefsContainerTests, TestCase):
 
     def test_remove_packed_without_peeled(self):
         refs_file = os.path.join(self._repo.path, 'packed-refs')
-        f = open(refs_file)
+        f = GitFile(refs_file)
         refs_data = f.read()
         f.close()
-        f = open(refs_file, 'wb')
+        f = GitFile(refs_file, 'wb')
         f.write('\n'.join(l for l in refs_data.split('\n')
                           if not l or l[0] not in '#^'))
         f.close()
-- 
1.7.1




References