fix(git): auto-configure safe.directory when git detects dubious ownership
This commit is contained in:
@@ -51,7 +51,26 @@ def _run_git_command(repo_path: str, *args: str) -> str:
|
|||||||
text=True,
|
text=True,
|
||||||
)
|
)
|
||||||
if result.returncode != 0:
|
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
|
return result.stdout
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user