Skip to content

Conversation

@yimingll
Copy link

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.

When git add fails (e.g., due to Windows reserved filenames like 'nul'),
the snapshot initialization silently returns empty tree hash, making
undo/revert completely non-functional.

This fix:
- Checks git add exit code and logs warnings on failure
- Retries with --ignore-errors to skip problematic files
- Allows snapshot tracking to work even with some problematic files

Fixes issue where undo command only reverts conversation but not code changes.
@github-actions
Copy link
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.

@github-actions
Copy link
Contributor

The following comment was made by an LLM, it may be inaccurate:

No duplicate PRs found

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant