fix(git): handle exit code 1 from git add --dry-run

Git returns exit code 1 (not 128) when some files are ignored.
- Accept both returncode 1 and 128 for ignore detection
- Parse ignored paths per-batch to avoid cross-batch contamination
- Log ignored file count after filtering

Testing showed: exit code 1 = some ignored, 0 = none ignored

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
Lilith 2026-01-11 00:48:07 -08:00
parent 2473220592
commit 9e993181fe
6 changed files with 5 additions and 2 deletions

View file

@ -203,9 +203,11 @@ async def git_check_ignored(repo_path: Path, files: list[str]) -> list[str]:
if returncode == 0:
# All files in batch are safe
safe_files.extend(batch)
elif returncode == 128 and "ignored" in stderr.lower():
elif (returncode == 1 or returncode == 128) and "ignored" in stderr.lower():
# Some files are ignored - parse error message to find which ones
# Git error format: "The following paths are ignored by one of your .gitignore files:\npath1\npath2"
# Exit code 1 = some files ignored, 128 = all files ignored
batch_ignored = []
lines = stderr.split("\n")
for i, line in enumerate(lines):
if "following paths are ignored" in line.lower():
@ -215,10 +217,11 @@ async def git_check_ignored(repo_path: Path, files: list[str]) -> list[str]:
break
ignored_path = ignored_line.strip()
if ignored_path:
batch_ignored.append(ignored_path)
ignored_files.append(ignored_path)
# Files not in ignored list are safe
safe_files.extend([f for f in batch if f not in ignored_files and not any(f.startswith(ig + "/") for ig in ignored_files)])
safe_files.extend([f for f in batch if f not in batch_ignored and not any(f.startswith(ig + "/") for ig in batch_ignored)])
else:
# Unknown error - be conservative and include all files
logger.warning(f"git add --dry-run returned {returncode}: {stderr}, including all files from batch")