Skip to content

fix: replace git add -A with two-step staging to avoid .forge error#128

Merged
eshulman2 merged 3 commits into
forge-sdlc:mainfrom
JoshSalomon:fix/entrypoint-git-add
Jul 7, 2026
Merged

fix: replace git add -A with two-step staging to avoid .forge error#128
eshulman2 merged 3 commits into
forge-sdlc:mainfrom
JoshSalomon:fix/entrypoint-git-add

Conversation

@JoshSalomon

Copy link
Copy Markdown
Contributor

Summary

The entrypoint's git_commit() fallback uses git add -A -- . ':!.forge' which fails with exit code 1 when .forge/ exists on disk and is in .gitignore. The pathspec exclusion prevents staging but does not suppress the error — git still warns about ignored paths during traversal.

Root Cause

Reproduced consistently: git add -A -- . ':!.forge' ':!.forge/**' returns exit code 1 on git 2.52+ whenever the .forge/ directory exists on disk, regardless of pathspec exclusions. The .forge/ directory always exists because the entrypoint creates it for task.json and history files before the agent runs.

The bug is intermittent because: if the agent commits its own changes during execution (staging specific files), the entrypoint's fallback finds nothing to commit and never calls git add -A. It only triggers when the agent leaves uncommitted changes for the fallback.

Fix

Replace the single git add -A with a two-step approach:

  1. git add -u — stages changes to tracked files (never encounters .forge/)
  2. git ls-files --others --exclude-standardgit add — stages new untracked files, respecting .gitignore and explicitly filtering out .forge/ paths

Test plan

  • Existing test test_git_commit_excludes_forge_directory passes
  • Manual test: run a task implementation where the agent doesn't commit → verify fallback commit succeeds

🤖 Generated with Claude Code

JoshSalomon and others added 3 commits July 7, 2026 17:46
git add -A fails with exit code 1 when .forge/ directory exists on
disk and is listed in .gitignore, even with pathspec exclusion.
The error occurs because git warns about ignored paths during
traversal regardless of exclusions.

Replace with: git add -u (tracked changes) + git ls-files --others
--exclude-standard filtered to skip .forge/ (new untracked files).
This avoids the .gitignore conflict entirely.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Use git ls-files -z for null-byte output instead of newline-separated.
Handles non-ASCII filenames, paths with newlines, and Git's
octal-escaped quoting. Skip file staging entirely if ls-files fails.

Add tests for: .forge/ with .gitignore (the bug scenario), and
non-ASCII filenames (café.txt, données.py).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@eshulman2 eshulman2 merged commit 6ef26c6 into forge-sdlc:main Jul 7, 2026
2 checks passed
JoshSalomon added a commit to JoshSalomon/forge that referenced this pull request Jul 8, 2026
Upstream merged our PR forge-sdlc#128 with stricter error handling (hard
failure on ls-files error). Kept our softer version (warning +
continue) since ls-files failure shouldn't prevent committing
tracked file changes.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants