Ver Fonte

compat: Set GIT_{COMMITTER,AUTHOR}_{NAME,EMAIL} if not specified.

Jelmer Vernooij há 2 meses atrás
pai
commit
1a0ba270e7
2 ficheiros alterados com 16 adições e 2 exclusões
  1. 3 2
      tests/compat/test_commit_graph.py
  2. 13 0
      tests/compat/utils.py

+ 3 - 2
tests/compat/test_commit_graph.py

@@ -14,7 +14,6 @@ identically to C Git's implementation.
 """
 
 import os
-import shutil
 import tempfile
 
 from dulwich.commit_graph import find_commit_graph_file, read_commit_graph
@@ -42,7 +41,9 @@ class CommitGraphCompatTests(CompatTestCase):
         self.overrideEnv("GIT_AUTHOR_EMAIL", "test@example.com")
 
     def tearDown(self):
-        shutil.rmtree(self.test_dir)
+        from .utils import rmtree_ro
+
+        rmtree_ro(self.test_dir)
 
     def create_test_repo_with_history(self):
         """Create a test repository with some commit history."""

+ 13 - 0
tests/compat/utils.py

@@ -140,6 +140,19 @@ def run_git(
     env["LC_ALL"] = env["LANG"] = "C"
     env["PATH"] = os.getenv("PATH")
 
+    # Preserve Git identity environment variables if they exist, otherwise set dummy values
+    git_env_defaults = {
+        "GIT_AUTHOR_NAME": "Test User",
+        "GIT_AUTHOR_EMAIL": "test@example.com",
+        "GIT_COMMITTER_NAME": "Test User",
+        "GIT_COMMITTER_EMAIL": "test@example.com",
+    }
+
+    for git_env_var, default_value in git_env_defaults.items():
+        if git_env_var not in env:
+            # If the environment variable is not set, use the default value
+            env[git_env_var] = default_value
+
     args = [git_path, *args]
     popen_kwargs["stdin"] = subprocess.PIPE
     if capture_stdout: