diff --git a/apps/api/src/utils/git_files.py b/apps/api/src/utils/git_files.py index a78dfbf..c793432 100644 --- a/apps/api/src/utils/git_files.py +++ b/apps/api/src/utils/git_files.py @@ -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