[PR #4312] fix: snapshot history when running from git worktrees #10937

Closed
opened 2026-02-16 18:15:42 -05:00 by yindo · 0 comments
Owner

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

State: closed
Merged: Yes


When running from a secondary git worktree, snapshot history stops updating. The sidecar snapshot repo under ~/.local/share/opencode/snapshot/<project-id> retains the original worktree path in core.worktree from the first initialization. Subsequent sessions reuse the same snapshot repo but do not override the worktree, so git add/diff/revert operate against the wrong tree. In the TUI, the Modified Files section remains hidden on the sidebar, and undo/redo don’t affect any files in the active worktree.

This patch passes the active worktree to every snapshot git invocation by adding --work-tree alongside the existing --git-dir. Storage layout and initialization stay the same, no migrations or config changes.

Validated locally with v1.0.65 by setting GIT_WORK_TREE to the active worktree. This patch implements the same behavior in code.

Tests cover three worktree scenarios:

  • Patch: detects changes made in a secondary worktree
  • Revert: removes only files in the invoking worktree
  • Diff: shows worktree-only and shared-file edits, ignores primary-only changes
**Original Pull Request:** https://github.com/anomalyco/opencode/pull/4312 **State:** closed **Merged:** Yes --- When running from a secondary git worktree, snapshot history stops updating. The sidecar snapshot repo under `~/.local/share/opencode/snapshot/<project-id>` retains the original worktree path in `core.worktree` from the first initialization. Subsequent sessions reuse the same snapshot repo but do not override the worktree, so git add/diff/revert operate against the wrong tree. In the TUI, the **Modified Files** section remains hidden on the sidebar, and undo/redo don’t affect any files in the active worktree. This patch passes the active worktree to every snapshot git invocation by adding `--work-tree` alongside the existing `--git-dir`. Storage layout and initialization stay the same, no migrations or config changes. Validated locally with **v1.0.65** by setting `GIT_WORK_TREE` to the active worktree. This patch implements the same behavior in code. Tests cover three worktree scenarios: - Patch: detects changes made in a secondary worktree - Revert: removes only files in the invoking worktree - Diff: shows worktree-only and shared-file edits, ignores primary-only changes
yindo added the pull-request label 2026-02-16 18:15:42 -05:00
yindo closed this issue 2026-02-16 18:15:42 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#10937