fix(git): auto-configure safe.directory when git detects dubious ownership

This commit is contained in:
Fusion
2026-05-21 10:55:14 +02:00
parent 74ac7b00bb
commit 55c4dc1281
+20 -1
View File
@@ -51,7 +51,26 @@ def _run_git_command(repo_path: str, *args: str) -> str:
text=True,
)
if result.returncode != 0:
raise RuntimeError(f"Git command failed: {result.stderr}")
stderr = result.stderr
# Handle "dubious ownership" security error
if "dubious ownership" in stderr.lower():
logger.warning("Git ownership mismatch for %s, adding to safe.directory", repo_path)
# Add this directory to git's safe.directory list
subprocess.run(
["git", "config", "--global", "--add", "safe.directory", repo_path],
capture_output=True,
)
# Retry the command
result = subprocess.run(
["git", *args],
cwd=repo_path,
capture_output=True,
text=True,
)
if result.returncode == 0:
return result.stdout
stderr = result.stderr
raise RuntimeError(f"Git command failed: {stderr}")
return result.stdout