Skip to content

fix(watcher): stop endless refresh inside a linked worktree - #86

Open
BenLocal wants to merge 1 commit into
the0807:mainfrom
BenLocal:fix/worktree-watcher-endless-refresh
Open

fix(watcher): stop endless refresh inside a linked worktree#86
BenLocal wants to merge 1 commit into
the0807:mainfrom
BenLocal:fix/worktree-watcher-endless-refresh

Conversation

@BenLocal

Copy link
Copy Markdown
  • Narrow the shared-gitdir watcher from worktrees/** to worktrees/*/{HEAD,gitdir,locked}: the broad glob also matched every worktree's private runtime state, and for a linked worktree that state IS our own gitdir. Every refresh runs git status, which takes index.lock, which classified as 'unknown' and forced another full refresh, which ran git status again — observed on a large monorepo worktree as a lock create/delete every ~1.5s (debounce + cooldown) that never stopped. Since any non-'status' change invalidates the history search, an in-flight search restarted from scratch each round and never returned a result. The three entries git worktree list actually reports are the only ones worth watching; from a main repo this also stops a sibling worktree's routine git activity from forcing a full refresh here.
  • Keep the pattern deliberately "complex": per the VS Code API contract a RelativePattern containing path segments still creates a recursive watcher, so this only tightens the filter — it does not downgrade to a non-recursive watcher that would miss worktrees/<name>/HEAD entirely.
  • Pin the registered patterns in a test: the failure mode is silent (no error, just a UI that never settles), so a regression would otherwise only surface as a bug report.

- Narrow the shared-gitdir watcher from `worktrees/**` to
  `worktrees/*/{HEAD,gitdir,locked}`: the broad glob also matched every
  worktree's private runtime state, and for a linked worktree that state IS
  our own gitdir. Every refresh runs `git status`, which takes `index.lock`,
  which classified as 'unknown' and forced another full refresh, which ran
  `git status` again — observed on a large monorepo worktree as a lock
  create/delete every ~1.5s (debounce + cooldown) that never stopped. Since
  any non-'status' change invalidates the history search, an in-flight
  search restarted from scratch each round and never returned a result.
  The three entries `git worktree list` actually reports are the only ones
  worth watching; from a main repo this also stops a sibling worktree's
  routine git activity from forcing a full refresh here.
- Keep the pattern deliberately "complex": per the VS Code API contract a
  RelativePattern containing path segments still creates a recursive
  watcher, so this only tightens the filter — it does not downgrade to a
  non-recursive watcher that would miss `worktrees/<name>/HEAD` entirely.
- Pin the registered patterns in a test: the failure mode is silent (no
  error, just a UI that never settles), so a regression would otherwise
  only surface as a bug report.

Signed-off-by: benshi <807629978@qq.com>
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.

1 participant