Skip to content

Commit 301573d

Browse files
authored
fix(tests): preserve safe directories in git config fixture (#961)
1 parent 9a368a9 commit 301573d

1 file changed

Lines changed: 18 additions & 2 deletions

File tree

test/conftest.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os
22
import platform
3+
import subprocess
34
import tempfile
45
from pathlib import Path
56

@@ -20,11 +21,26 @@
2021

2122
@pytest.fixture(scope="session", autouse=True)
2223
def git_global_config():
23-
# run-task writes to the global git config, so point it at a real
24-
# (writable) empty file instead of ~/.gitconfig.
24+
# Until https://github.com/taskcluster/taskcluster/issues/6561 we need to
25+
# preserved the safe directories that `run-task` sets to keep tests
26+
# working in CI when workers run subsequent tasks.
27+
existing_safe_dirs = subprocess.run(
28+
["git", "config", "--global", "--get-all", "safe.directory"],
29+
capture_output=True,
30+
text=True,
31+
check=False,
32+
).stdout.splitlines()
33+
2534
fd, path = tempfile.mkstemp(prefix="taskgraph-gitconfig-")
2635
os.close(fd)
2736
os.environ["GIT_CONFIG_GLOBAL"] = path
37+
38+
for entry in existing_safe_dirs:
39+
subprocess.run(
40+
["git", "config", "--global", "--add", "safe.directory", entry],
41+
check=False,
42+
)
43+
2844
yield
2945
del os.environ["GIT_CONFIG_GLOBAL"]
3046
os.unlink(path)

0 commit comments

Comments
 (0)