fix: replace git add -A with two-step staging to avoid .forge error#128
Merged
Merged
Conversation
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>
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The entrypoint's
git_commit()fallback usesgit 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 -Awith a two-step approach:git add -u— stages changes to tracked files (never encounters.forge/)git ls-files --others --exclude-standard→git add— stages new untracked files, respecting.gitignoreand explicitly filtering out.forge/pathsTest plan
test_git_commit_excludes_forge_directorypasses🤖 Generated with Claude Code