| 12 | |
| 13 | |
| 14 | def _run_git( |
| 15 | args: list[str], |
| 16 | cwd: str | None = None, |
| 17 | timeout: float = 30.0, |
| 18 | ) -> tuple[str, str, int]: |
| 19 | effective_cwd = cwd or os.getcwd() |
| 20 | try: |
| 21 | result = subprocess.run( |
| 22 | ["git", *args], |
| 23 | capture_output=True, |
| 24 | text=True, |
| 25 | cwd=effective_cwd, |
| 26 | timeout=timeout, |
| 27 | ) |
| 28 | return result.stdout.strip(), result.stderr.strip(), result.returncode |
| 29 | except subprocess.TimeoutExpired: |
| 30 | return "", "Command timed out", -1 |
| 31 | except FileNotFoundError: |
| 32 | return "", "git not found", -1 |
| 33 | except Exception as e: |
| 34 | return "", str(e), -1 |
| 35 | |
| 36 | |
| 37 | def _run_git_ok(args: list[str], cwd: str | None = None) -> str: |