Skip to content

fix(opencode): skip nested repositories in snapshots - #44259

Open
opencode-agent[bot] wants to merge 1 commit into
devfrom
v1-nested-repos
Open

fix(opencode): skip nested repositories in snapshots#44259
opencode-agent[bot] wants to merge 1 commit into
devfrom
v1-nested-repos

Conversation

@opencode-agent

Copy link
Copy Markdown
Contributor

Summary

  • exclude directory-shaped untracked entries from legacy snapshot staging
  • continue capturing ordinary untracked files in the same snapshot
  • add coverage for an unborn nested Git repository

Why

Git reports embedded repositories as directory entries such as tui/. Passing one with no checked-out commit to the snapshot repository's git add fails the batch and leaves the snapshot tree stale. Since ls-files --others already expands ordinary directories into files, omitting directory entries avoids the failure without losing regular file changes.

Testing

  • bun test test/snapshot/snapshot.test.ts
  • bun typecheck
  • bun x prettier --check src/snapshot/index.ts test/snapshot/snapshot.test.ts

Requested by: @rekram1-node (Aiden via Slack)

@Enough1122

Copy link
Copy Markdown

AI code review — automated review for reference, author can ignore or act on any point.

Nice targeted fix. In packages/opencode/src/snapshot/index.ts (hunk @@ -257,7, changed line 260), filtering directory-shaped entries out of all before staging addresses a real failure mode: an unborn embedded repository surfaces as tui/ from ls-files --others, and a single failed git add aborts the entire batch, leaving the snapshot stale. Since the list is NUL-split (-z style output), path quoting isn't a concern, and a trailing slash cannot belong to a legitimate file, so the filter is safe when applied to both the tracked and untracked halves of the set.

Two suggestions:

  1. Nested-repo content now disappears silently instead of failing loudly. Consider logging a one-line warning when entries are dropped (count plus names) so users can understand why nothing under tui/ ever appears in a snapshot.
  2. In test/snapshot/snapshot.test.ts (new test, roughly lines 177–195), a sibling case with a committed nested repo would pin down intended behavior there — git add currently accepts it as a gitlink — protecting against regression if the staging strategy changes later.

Also worth a quick audit that no other call site parses status --porcelain/ls-files output into staging candidates with the same latent bug, so snapshot behavior stays consistent across entry points.

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.

2 participants