From 1e6be0997d2cfb80173e855c103a4d11eff24238 Mon Sep 17 00:00:00 2001 From: Ben Hearsum Date: Mon, 25 May 2026 11:16:55 -0400 Subject: [PATCH] fix(tests): preserve safe directories in git config fixture --- test/conftest.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/test/conftest.py b/test/conftest.py index ceaf2ebfd..21edf2ff3 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -1,5 +1,6 @@ import os import platform +import subprocess import tempfile from pathlib import Path @@ -20,11 +21,26 @@ @pytest.fixture(scope="session", autouse=True) def git_global_config(): - # run-task writes to the global git config, so point it at a real - # (writable) empty file instead of ~/.gitconfig. + # Until https://github.com/taskcluster/taskcluster/issues/6561 we need to + # preserved the safe directories that `run-task` sets to keep tests + # working in CI when workers run subsequent tasks. + existing_safe_dirs = subprocess.run( + ["git", "config", "--global", "--get-all", "safe.directory"], + capture_output=True, + text=True, + check=False, + ).stdout.splitlines() + fd, path = tempfile.mkstemp(prefix="taskgraph-gitconfig-") os.close(fd) os.environ["GIT_CONFIG_GLOBAL"] = path + + for entry in existing_safe_dirs: + subprocess.run( + ["git", "config", "--global", "--add", "safe.directory", entry], + check=False, + ) + yield del os.environ["GIT_CONFIG_GLOBAL"] os.unlink(path)