Jelmer Vernooij 2 місяців тому
батько
коміт
46780f4077
2 змінених файлів з 15 додано та 6 видалено
  1. 7 1
      tests/compat/test_commit_graph.py
  2. 8 5
      tests/compat/utils.py

+ 7 - 1
tests/compat/test_commit_graph.py

@@ -310,7 +310,13 @@ class CommitGraphCompatTests(CompatTestCase):
                     self.repo_path, "objects", "info", "commit-graph"
                 )
                 if os.path.exists(graph_path):
-                    os.remove(graph_path)
+                    try:
+                        os.remove(graph_path)
+                    except PermissionError:
+                        # On Windows, handle read-only files
+                        from .utils import remove_ro
+
+                        remove_ro(graph_path)
 
                 if strategy == ["--stdin-commits"]:
                     # For stdin-commits, we need to provide commit IDs

+ 8 - 5
tests/compat/utils.py

@@ -287,12 +287,15 @@ class CompatTestCase(TestCase):
         return repo
 
 
-if sys.platform == "win32":
+def remove_ro(path: str) -> None:
+    """Remove a read-only file."""
+    os.chmod(path, stat.S_IWRITE)
+    os.remove(path)
 
-    def remove_ro(action, name, exc) -> None:
-        os.chmod(name, stat.S_IWRITE)
-        os.remove(name)
 
-    rmtree_ro = functools.partial(shutil.rmtree, onerror=remove_ro)
+if sys.platform == "win32":
+    rmtree_ro = functools.partial(
+        shutil.rmtree, onerror=lambda action, name, exc: remove_ro(name)
+    )
 else:
     rmtree_ro = shutil.rmtree