Skip to content

fix: snapshot history when running from git worktrees#4312

Merged
rekram1-node merged 1 commit into
anomalyco:devfrom
chrisolszewski:fix-snapshot-worktree
Nov 15, 2025
Merged

fix: snapshot history when running from git worktrees#4312
rekram1-node merged 1 commit into
anomalyco:devfrom
chrisolszewski:fix-snapshot-worktree

Conversation

@chrisolszewski
Copy link
Copy Markdown
Contributor

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

Pass --work-tree on all snapshot git invocations to respect the active worktree while preserving shared history.\n\nAdd tests for worktree flows (patch, revert, diff) and align test conventions: move helper near bootstrap, rename tests for clarity, and clean worktree teardown with `git worktree remove --force`. No storage/layout changes.
@rekram1-node
Copy link
Copy Markdown
Collaborator

Great fix thank you

@rekram1-node rekram1-node merged commit 69a45ef into anomalyco:dev Nov 15, 2025
3 checks passed
@chrisolszewski chrisolszewski deleted the fix-snapshot-worktree branch November 28, 2025 17:52
xywsxp pushed a commit to xywsxp/opencode that referenced this pull request Apr 24, 2026
Rwanbt pushed a commit to Rwanbt/opencode that referenced this pull request May 5, 2026
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.

2 participants