Skip to content

fix(snapshot): preserve subdirectory path handling - #33211

Closed
Aqu1bp wants to merge 1 commit into
anomalyco:devfrom
Aqu1bp:snapshot-subdir
Closed

Aqu1bp wants to merge 1 commit into
anomalyco:devfrom
Aqu1bp:snapshot-subdir

Conversation

@Aqu1bp

@Aqu1bp Aqu1bp commented Jun 21, 2026

Copy link
Copy Markdown

Issue for this PR

Closes #27688

Related: #32935. This PR keeps the snapshot file listing scoped to the launch directory while fixing the pathspec consumers, instead of moving the listing commands to the worktree root.

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

When opencode is launched from a git subdirectory, snapshot candidate paths can be consumed from the wrong cwd. For tracked files, git can report worktree-relative paths such as src/date.txt; feeding those pathspecs to git add from repo/src makes git look for repo/src/src/date.txt and snapshot tracking fails.

This fixes the path handling without broadening snapshot scope:

  • keeps diff-files and ls-files --others scoped to state.directory, so a repo/src instance does not snapshot unrelated repo/root.txt changes
  • adds --full-name to ls-files --others so untracked files are also worktree-relative
  • runs ignore, drop, and stage from state.worktree, where those pathspecs resolve correctly
  • checks large-file size using state.worktree because the candidate paths are worktree-relative

The extra --full-name matters because from a subdirectory, git diff-files --name-only -- . can return src/date.txt, while git ls-files --others -- . can return date.txt unless full-name output is requested.

How did you verify your code works?

From packages/opencode:

  • bun test test/snapshot/snapshot.test.ts
  • bun test test/session/revert-compact.test.ts
  • bun test test/session/snapshot-tool-race.test.ts
  • bun run typecheck

From the repo root / during push:

  • git diff --check
  • PATH=/tmp/opencode-bun-1.3.14:$PATH git push -u fork snapshot-subdir ran the pre-push hook successfully, including root bun turbo typecheck

Manual checks:

  • reproduced the original src/src / pathspec failure before the fix
  • confirmed the committed-file repro no longer logs the snapshot pathspec warning
  • confirmed an untracked file created under repo/src is reported correctly after adding --full-name

Screenshots / recordings

N/A, not a UI change.

Checklist

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

@github-actions

Copy link
Copy Markdown
Contributor

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

Based on the search results, I found one related PR:

Potentially Related PR

PR #32935 - fix(snapshot): handle git subdirectory launches
#32935

Why it's related: The current PR (33211) explicitly mentions this PR as related in the description: "Related: #32935. This PR keeps the snapshot file listing scoped to the launch directory while fixing the pathspec consumers, instead of moving the listing commands to the worktree root."

This appears to be a different approach to handling the same snapshot subdirectory issue—PR #32935 moved listing commands to the worktree root, while PR #33211 takes an alternative approach of keeping the listing scoped to the launch directory while fixing path handling downstream.

These are not duplicates (they're alternative solutions), but they are closely related and should be reviewed together to ensure they don't conflict.

@github-actions

Copy link
Copy Markdown
Contributor

Automated PR Cleanup

Thank you for contributing to opencode.

Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions.

This PR was closed because it matched the following cleanup criteria:

  • The PR was created more than 1 month ago
  • The PR had fewer than 2 positive reactions
  • Positive reactions are counted as thumbs-up, heart, celebration, or rocket reactions on the PR

PRs created within the last month are not affected by this cleanup.

If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate.

Thanks again for taking the time to contribute.

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.

Snapshot fails when opencode is opened in a git subdirectory (snapshot service cwd mismatch)

1 participant