[PR #9715] fix(snapshot): handle git add failures with --ignore-errors fallback #13207

Open
opened 2026-02-16 18:18:04 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/9715

State: open
Merged: No


Problem

When git add . fails during snapshot initialization (e.g., due to Windows reserved filenames like nul, con, aux, prn), the snapshot silently returns the empty tree hash (4b825dc642cb6eb9a060e54bf8d69288fbee4904).

This causes:

  • All diff calculations to be based on empty tree
  • undo command only reverts conversation, not code changes
  • revert functionality completely non-functional
  • No error message shown to user

Reproduction Steps

  1. Create a file named nul in a project directory (Windows)
  2. Start opencode and make code changes
  3. Try to undo - conversation reverts but files remain unchanged

Log Evidence

INFO service=snapshot hash=4b825dc642cb6eb9a060e54bf8d69288fbee4904 cwd=E:\project git=...

The hash 4b825dc642cb6eb9a060e54bf8d69288fbee4904 is Git's well-known empty tree hash.

Solution

  • Check git add exit code and log warnings on failure
  • Retry with --ignore-errors flag to skip problematic files
  • This allows snapshot tracking to work for all other files even when some files can't be added

Changes

  • packages/opencode/src/snapshot/index.ts: Modified track() function to handle git add failures gracefully

Testing

Tested on Windows with a file named nul that previously broke snapshot initialization. After the fix, snapshot correctly tracks all other files and undo/revert works as expected.

**Original Pull Request:** https://github.com/anomalyco/opencode/pull/9715 **State:** open **Merged:** No --- ## Problem When `git add .` fails during snapshot initialization (e.g., due to Windows reserved filenames like `nul`, `con`, `aux`, `prn`), the snapshot silently returns the **empty tree hash** (`4b825dc642cb6eb9a060e54bf8d69288fbee4904`). This causes: - All diff calculations to be based on empty tree - `undo` command only reverts conversation, **not code changes** - `revert` functionality completely non-functional - No error message shown to user ### Reproduction Steps 1. Create a file named `nul` in a project directory (Windows) 2. Start opencode and make code changes 3. Try to undo - conversation reverts but files remain unchanged ### Log Evidence ``` INFO service=snapshot hash=4b825dc642cb6eb9a060e54bf8d69288fbee4904 cwd=E:\project git=... ``` The hash `4b825dc642cb6eb9a060e54bf8d69288fbee4904` is Git's well-known empty tree hash. ## Solution - Check `git add` exit code and log warnings on failure - Retry with `--ignore-errors` flag to skip problematic files - This allows snapshot tracking to work for all other files even when some files can't be added ## Changes - `packages/opencode/src/snapshot/index.ts`: Modified `track()` function to handle `git add` failures gracefully ## Testing Tested on Windows with a file named `nul` that previously broke snapshot initialization. After the fix, snapshot correctly tracks all other files and undo/revert works as expected.
yindo added the pull-request label 2026-02-16 18:18:04 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#13207