Skip to content

fix(snapshot): avoid ENAMETOOLONG error caused by git check-ignore command.#22544

Closed
thisxiangyu wants to merge 1 commit intoanomalyco:devfrom
thisxiangyu:upstream-fix
Closed

fix(snapshot): avoid ENAMETOOLONG error caused by git check-ignore command.#22544
thisxiangyu wants to merge 1 commit intoanomalyco:devfrom
thisxiangyu:upstream-fix

Conversation

@thisxiangyu
Copy link
Copy Markdown

@thisxiangyu thisxiangyu commented Apr 15, 2026

Issue for this PR

Fixes #22538 #22540

Type of change

  • Bug fix

What does this PR do?

When a worktree has many ignored files (e.g., 75,000+), the snapshot add() function fails with ENAMETOOLONG error. This happens because git check-ignore --no-index is called with all file paths as command-line arguments, exceeding the 32KB command-line limit.

The fix replaces calls to git check-ignore --no-index with local ignore library (already used elsewhere in the codebase at src/file/index.ts). This library provides equivalent gitignore pattern matching without command-line length limits.

Changes:

  • Added parseIgnore() helper in packages/opencode/src/snapshot/index.ts to load .gitignore and .ignore files
  • Modified add(), patch(), and diffFull() functions to filter ignored files locally instead of spawning git process
  • Both file patterns and directory patterns (with / suffix) are checked to handle directory rules correctly

How did you verify your code works?

Tested locally on Windows by:

  1. Creating a worktree with 75,000+ ignored files
  2. Running snapshot commands to verify no ENAMETOOLONG error occurs
  3. Verifying ignored files are properly excluded from snapshots

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@github-actions
Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@thisxiangyu
Copy link
Copy Markdown
Author

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

? Fixes #22538 #22540

…o avoid ENAMETOOLONG error on Windows

When a worktree has many ignored files (e.g., 75,000+), calling
'git check-ignore --no-index' with all file paths as command-line
arguments exceeds Windows' 32KB limit, causing ENAMETOOLONG errors.

This replaces the git check-ignore calls in add(), patch(), and
diffFull() functions with the local 'ignore' library (already used
in src/file/index.ts), which provides equivalent gitignore pattern
matching without command-line length limits.

Fixes anomalyco#16336, anomalyco#18072
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.

[Bug]Critical issue : It causes a complete freeze.Opening projects fails with ENAMETOOLONG error.

1 participant