@gitkraken/core-gitlens 0.33.0 → 0.34.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (88) hide show
  1. package/CHANGELOG.md +16 -1
  2. package/dist/git/cache.d.ts +31 -0
  3. package/dist/git/cache.js +101 -30
  4. package/dist/git/cache.js.map +1 -1
  5. package/dist/git/context.d.ts +3 -1
  6. package/dist/git/context.js.map +1 -1
  7. package/dist/git/errors.d.ts +3 -1
  8. package/dist/git/errors.js +4 -1
  9. package/dist/git/errors.js.map +1 -1
  10. package/dist/git/models/pullRequest.d.ts +90 -1
  11. package/dist/git/models/pullRequest.js +18 -2
  12. package/dist/git/models/pullRequest.js.map +1 -1
  13. package/dist/git/providers/shared/remotes.js +2 -0
  14. package/dist/git/providers/shared/remotes.js.map +1 -1
  15. package/dist/git/utils/pullRequest.utils.d.ts +72 -1
  16. package/dist/git/utils/pullRequest.utils.js +99 -1
  17. package/dist/git/utils/pullRequest.utils.js.map +1 -1
  18. package/dist/git/utils/repository.utils.d.ts +6 -0
  19. package/dist/git/utils/repository.utils.js +14 -2
  20. package/dist/git/utils/repository.utils.js.map +1 -1
  21. package/dist/git/watching/gitDirPoller.d.ts +10 -1
  22. package/dist/git/watching/gitDirPoller.js +9 -3
  23. package/dist/git/watching/gitDirPoller.js.map +1 -1
  24. package/dist/git/watching/unwatchedCacheValidator.d.ts +144 -0
  25. package/dist/git/watching/unwatchedCacheValidator.js +884 -0
  26. package/dist/git/watching/unwatchedCacheValidator.js.map +1 -0
  27. package/dist/git/watching/watchGroup.d.ts +2 -0
  28. package/dist/git/watching/watchGroup.js +4 -8
  29. package/dist/git/watching/watchGroup.js.map +1 -1
  30. package/dist/git/watching/watchService.d.ts +23 -0
  31. package/dist/git/watching/watchService.js +42 -2
  32. package/dist/git/watching/watchService.js.map +1 -1
  33. package/dist/git/watching/watchSession.d.ts +2 -0
  34. package/dist/git/watching/watchSession.js +3 -2
  35. package/dist/git/watching/watchSession.js.map +1 -1
  36. package/dist/git-cli/cliGitProvider.js +1 -1
  37. package/dist/git-cli/cliGitProvider.js.map +1 -1
  38. package/dist/git-cli/exec/commandClassifier.d.ts +31 -1
  39. package/dist/git-cli/exec/commandClassifier.js +67 -16
  40. package/dist/git-cli/exec/commandClassifier.js.map +1 -1
  41. package/dist/git-cli/exec/git.d.ts +46 -2
  42. package/dist/git-cli/exec/git.js +80 -7
  43. package/dist/git-cli/exec/git.js.map +1 -1
  44. package/dist/git-cli/exec/gitDirResolver.d.ts +11 -0
  45. package/dist/git-cli/exec/gitDirResolver.js +34 -1
  46. package/dist/git-cli/exec/gitDirResolver.js.map +1 -1
  47. package/dist/git-cli/exec/gitQueue.js +2 -28
  48. package/dist/git-cli/exec/gitQueue.js.map +1 -1
  49. package/dist/git-cli/providers/branches.d.ts +1 -0
  50. package/dist/git-cli/providers/branches.js +6 -0
  51. package/dist/git-cli/providers/branches.js.map +1 -1
  52. package/dist/git-cli/providers/config.d.ts +13 -1
  53. package/dist/git-cli/providers/config.js +48 -14
  54. package/dist/git-cli/providers/config.js.map +1 -1
  55. package/dist/git-cli/providers/pausedOperations.d.ts +1 -0
  56. package/dist/git-cli/providers/pausedOperations.js +4 -0
  57. package/dist/git-cli/providers/pausedOperations.js.map +1 -1
  58. package/dist/git-cli/providers/revision.js +2 -0
  59. package/dist/git-cli/providers/revision.js.map +1 -1
  60. package/dist/git-cli/providers/worktrees.js +2 -0
  61. package/dist/git-cli/providers/worktrees.js.map +1 -1
  62. package/dist/git-cli/service.d.ts +25 -1
  63. package/dist/git-cli/service.js +45 -0
  64. package/dist/git-cli/service.js.map +1 -1
  65. package/dist/plus/ai/errors.d.ts +8 -2
  66. package/dist/plus/ai/errors.js +15 -3
  67. package/dist/plus/ai/errors.js.map +1 -1
  68. package/dist/plus/git-github/api/github.d.ts +51 -1
  69. package/dist/plus/git-github/api/github.js +276 -3
  70. package/dist/plus/git-github/api/github.js.map +1 -1
  71. package/dist/plus/git-github/models.d.ts +54 -1
  72. package/dist/plus/git-github/models.js +48 -3
  73. package/dist/plus/git-github/models.js.map +1 -1
  74. package/dist/plus/integrations/fieldPresence.d.ts +6 -1
  75. package/dist/plus/integrations/fieldPresence.js +19 -9
  76. package/dist/plus/integrations/fieldPresence.js.map +1 -1
  77. package/dist/plus/integrations/models/gitHostIntegration.d.ts +26 -1
  78. package/dist/plus/integrations/models/gitHostIntegration.js +51 -0
  79. package/dist/plus/integrations/models/gitHostIntegration.js.map +1 -1
  80. package/dist/plus/integrations/models/integration.d.ts +15 -2
  81. package/dist/plus/integrations/models/integration.js.map +1 -1
  82. package/dist/plus/integrations/providers/github.d.ts +16 -1
  83. package/dist/plus/integrations/providers/github.js +53 -1
  84. package/dist/plus/integrations/providers/github.js.map +1 -1
  85. package/dist/plus/integrations/reads/etag.js +11 -0
  86. package/dist/plus/integrations/reads/etag.js.map +1 -1
  87. package/docs/integrations.md +39 -6
  88. package/package.json +1 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unwatchedCacheValidator.js","names":[],"sources":["../../../../git/src/watching/unwatchedCacheValidator.ts"],"sourcesContent":["import { raceWithTimeout } from '@gitlens/utils/cancellation.js';\nimport { joinPaths } from '@gitlens/utils/path.js';\nimport type { ResourceUsage } from '@gitlens/utils/resourceUsage.js';\nimport type { Cache } from '../cache.js';\nimport { FileType } from '../context.js';\nimport type { RepositoryChange } from '../models/repository.js';\nimport { isIgnoredWorktreeEntry, parseWorktreeAdminPath } from '../utils/repository.utils.js';\nimport { allWatchedRepositoryChanges, classifyGitDirChange } from './classifyChange.js';\nimport type { GitDirProbe } from './gitDirPoller.js';\nimport { GitDirProbeTarget } from './gitDirPoller.js';\nimport { gitDirCommonProbes, gitDirRootProbes } from './watcherPatterns.js';\nimport { isNotFound } from './watchGroup.js';\nimport { defaultRepoDelay } from './watchSession.js';\n\ntype ProbeStat = { readonly mtime: number; readonly size: number };\n/** The stats of one validation, by absolute path, shared by every git dir it reads */\ntype StatMemo = Map<string, Promise<ProbeStat | undefined>>;\n/** The reading of a path whose stat failed; never a whole second, so never racy */\nconst unreadable: ProbeStat = { mtime: -1, size: -1 };\n\nexport interface UnwatchedCacheValidatorOptions {\n\treadonly cache: Cache;\n\t/** A path's modification time (ms since the epoch) and size; `undefined` when it doesn't exist */\n\treadonly stat: (path: string) => Promise<ProbeStat | undefined>;\n\t/** A directory's entries with their `FileType`s; a rejection whose `code` is `ENOENT` or `FileNotFound` means it isn't there */\n\treadonly readDirectory: (path: string) => Promise<readonly (readonly [string, number])[]>;\n\t/** A file's bytes; `undefined` when it doesn't exist. Without it, no worktree is ignored */\n\treadonly readFile?: (path: string) => Promise<Uint8Array | undefined>;\n\t/**\n\t * The absolute, normalized folders whose worktrees core ignores (see `GitProvider.getIgnoredWorktreeRoots`), asked\n\t * with a `repoPath` whose git dir the cache holds; a worktree in one is left out of the worktree list, so what moves\n\t * in its admin entry changes nothing cached. A rejection means none is ignored\n\t */\n\treadonly getIgnoredWorktreeRoots?: (repoPath: string) => Promise<readonly string[]>;\n\t/**\n\t * Caches `repoPath`'s git dir without running git, for a repository nothing resolved one for yet (as when only its\n\t * branches, remotes or tags were read); whether one is cached. Without it, or when it answers `false`, such a\n\t * repository isn't validated: a layout git's files alone can't answer for (a bare repository, a submodule, a\n\t * `--separate-git-dir` checkout, a `core.worktree`) stays unvalidated until a read resolves its git dir. A rejection\n\t * is a failure to look, retried soon; `false` is a repository its files can't answer for, tried again rarely\n\t */\n\treadonly resolveGitDir?: (repoPath: string) => Promise<boolean>;\n\t/**\n\t * Whether a `.git` watcher covers `repoPath` and is live (see `RepositoryWatchService.isRepoWatched`): one that is\n\t * suspended holds what it hears until it resumes, so a repository is unwatched meanwhile, without being announced\n\t */\n\treadonly isWatched: (repoPath: string) => boolean;\n\t/** Milliseconds since the epoch, the clock `stat`'s `mtime` is on. Default: `Date.now` */\n\treadonly now?: () => number;\n\t/**\n\t * How long a read waits for a validation before it's served from the cache as is, and how long a hung file-system\n\t * call holds back other repositories' validations. Default: 1000\n\t */\n\treadonly timeoutMs?: number;\n\t/**\n\t * How many of Node's file-system threads (libuv's pool) the validator's calls may hold at once, counting those hung\n\t * past {@link timeoutMs}; at most two run at once. Default: 2, which leaves a host two of the pool's default four\n\t */\n\treadonly maxFsThreads?: number;\n}\n\n/**\n * A target read within this long of its last validation is served as is: a watched repository's read is as stale, as\n * its watch session debounces what its watcher reports by as much\n */\nconst validationWindowMs = defaultRepoDelay;\n/**\n * How long a repository whose files can't show its git dir (a bare repository, a submodule) is left before they are\n * looked at again. Any read that resolves its git dir with git makes the lookup unneeded\n */\nconst unresolvableRetryMs = 30_000;\n/** Targets kept per kind; one dropped just takes a new baseline */\nconst maxTargets = 512;\n/** Polls one validation runs to take the baselines of the directories it finds; the next validation resumes from there */\nconst maxDiscoveryPolls = 16;\n/**\n * How long a reading stays racy on a file system whose timestamps tick by whole seconds (or two, as FAT's): a write in\n * the same second as the stat leaves the same mtime. Counted both from the mtime and from when the validator first saw\n * the reading, as a server whose clock runs ahead of ours stamps writes with a second that ends, on our clock, no later\n * than this long after we first saw it\n */\nconst racyMtimeWindowMs = 2000;\n/** Racy candidates whose first sighting is remembered; the oldest is dropped past it, which only extends its raciness */\nconst maxRacyReadings = maxTargets * 8;\n/** How long a read waits for a validation before it's served from the cache as is */\nconst defaultValidationTimeoutMs = 1000;\n/** The longest delay `setTimeout` keeps; a longer one (`Infinity` included) fires at once */\nconst maxValidationTimeoutMs = 2 ** 31 - 1;\n/**\n * A stat or listing holds one of Node's file-system threads (libuv's pool, 4 by default) until it returns, which on a\n * hung mount is never, as it can't be cancelled. A repository makes one at a time and the validator two, holding no more\n * threads than it's allowed counting those outstanding past the timeout\n */\nconst maxFsCallsPerRepo = 1;\nconst maxFsCalls = 2;\nconst defaultMaxFsThreads = 2;\n\nconst refNamespaces: readonly string[] = ['refs/heads', 'refs/remotes', 'refs/tags'];\nconst reftableProbePath = 'reftable/tables.list';\nconst worktreeHeadRegex = /^worktrees\\/([^/]+)\\/(?:HEAD|reftable\\/tables\\.list)$/;\n\n/**\n * The git dir itself, as the gate of the files in it that git writes by lockfile and rename, or creates and deletes:\n * either moves the directory's mtime, so its reading stands in for theirs, which are read only once it moved. Each\n * gate's files have a probe target of their own, whose readings outlast the validations that skip it; were they left\n * out of a shared target instead, their next reading would be a new baseline, losing what changed meanwhile. What git\n * writes in place (`FETCH_HEAD`, an admin entry's `gitdir`, the rebase and sequencer state `--edit-todo` rewrites) is\n * read every time. This saves stats only while the gate holds still: an index write moves the git dir too, so an\n * active checkout reads as much as ever, and an idle one, as unwatched repositories mostly are, reads just the gate.\n */\nconst gitDirGatePath = '';\nconst rootGatedPaths: ReadonlySet<string> = new Set([\n\t'HEAD',\n\t'ORIG_HEAD',\n\t'MERGE_HEAD',\n\t'CHERRY_PICK_HEAD',\n\t'REVERT_HEAD',\n\t'REBASE_HEAD',\n]);\nconst commonGatedPaths: ReadonlySet<string> = new Set(['packed-refs', 'config', 'shallow']);\n\n// The index is what working-tree status reads, which these caches aren't; `info/exclude` clears only the gitignore filter\nconst rootProbes: readonly GitDirProbe[] = gitDirRootProbes.filter(p => p.path !== 'index');\nconst rootAlwaysProbes: readonly GitDirProbe[] = [\n\t{ path: gitDirGatePath },\n\t...rootProbes.filter(p => !rootGatedPaths.has(p.path)),\n\t{ path: reftableProbePath },\n];\nconst rootGatedProbes: readonly GitDirProbe[] = rootProbes.filter(p => rootGatedPaths.has(p.path));\n/**\n * What a worktree's own git dir can report, which is all its validation without a baseline reports: the shared kinds\n * are the common git dir's to report, from a baseline of its own, or by another worktree's watcher that covers it\n */\nconst rootReportableChanges: readonly RepositoryChange[] = [\n\t...new Set(\n\t\t[...rootAlwaysProbes, ...rootGatedProbes].flatMap((p): RepositoryChange[] => {\n\t\t\tif (p.path === gitDirGatePath) return [];\n\t\t\t// As `classify` reports a worktree's own reftable, which moves with its HEAD\n\t\t\tif (p.path === reftableProbePath) return ['head', 'heads'];\n\n\t\t\treturn (p.emitAs ?? [p.path]).flatMap(path => classifyGitDirChange(path) ?? []);\n\t\t}),\n\t),\n];\nconst commonProbes: readonly GitDirProbe[] = [\n\t...gitDirCommonProbes.filter(p => p.path !== 'info/exclude'),\n\t{ path: reftableProbePath },\n\t// Dropping a stash entry other than the newest rewrites only the stash's reflog, leaving `refs/stash` as it was\n\t{ path: 'logs/refs/stash', emitAs: ['refs/stash'] },\n\t// A replacement (`git replace`) changes ancestry, and the cached ref list holds the replace refs\n\t{ path: 'refs/replace' },\n];\nconst commonAlwaysProbes: readonly GitDirProbe[] = [\n\t{ path: gitDirGatePath },\n\t...commonProbes.filter(p => !commonGatedPaths.has(p.path)),\n];\nconst commonGatedProbes: readonly GitDirProbe[] = commonProbes.filter(p => commonGatedPaths.has(p.path));\n\ninterface ValidationResult {\n\treadonly changes: ReadonlySet<RepositoryChange>;\n\t/** With a `'worktreeHead'` among `changes`, the admin ids of the linked worktrees whose HEAD moved; `undefined` when any may have */\n\treadonly movedWorktrees: ReadonlySet<string> | undefined;\n}\n\n/** Something reads wait for, at most until their timeout */\ninterface Waitable {\n\t/** In flight; settles once what it found was applied */\n\trunning?: Promise<void>;\n\t/** What outlasted a read's wait; while it's still {@link running}, reads don't wait for it */\n\tslow?: Promise<void>;\n\t/** What it started that reads wait for through it, which a wait that outlasts it marks slow too */\n\treadonly started?: (readonly [Waitable, Promise<void>])[];\n\tsettledAt?: number;\n}\n\ninterface TargetState extends Waitable {\n\treadonly dir: ProbedGitDir;\n\truns: number;\n}\n\n/** A resolution of a git dir nothing resolved, then the validation that follows it */\ninterface ResolutionState extends Waitable {\n\treadonly started: (readonly [Waitable, Promise<void>])[];\n\t/** How long after it settled the resolution is tried again: briefly for a failure, longer for a definite \"no\" */\n\tretryAfterMs: number;\n}\n\n/**\n * Keeps the caches that never expire fresh for repositories no `.git` watcher covers: before such a read, stats the\n * files a watcher would have reported (see {@link UnwatchedCacheValidatorOptions.stat}) and applies what moved to the\n * cache as a watcher event would have. Both a worktree's own git dir and the common one are validated while that\n * worktree is unwatched; while another worktree's watcher covers the common one, what moved there clears only the\n * unwatched worktrees' own entries. A repository whose git dir nothing resolved yet is validated once\n * {@link UnwatchedCacheValidatorOptions.resolveGitDir} resolves one; a repository whose files can't show it is looked at\n * again rarely, and one whose resolution failed within the validation window. A read waits at most\n * {@link UnwatchedCacheValidatorOptions.timeoutMs} for a validation (and a resolution before it); one that outlasts it\n * is left to finish on its own, and the reads meanwhile are served as is.\n */\nexport class UnwatchedCacheValidator {\n\tprivate readonly cache: Cache;\n\tprivate readonly isWatched: (repoPath: string) => boolean;\n\tprivate readonly now: () => number;\n\tprivate readonly timeoutMs: number;\n\tprivate readonly resolveGitDir: ((repoPath: string) => Promise<boolean>) | undefined;\n\tprivate readonly gate: FileSystemGate;\n\t/** Since it was created; what {@link getResourceUsage} reports */\n\tprivate readonly counts = { validations: 0, validationsApplied: 0, waitsTimedOut: 0, gitDirLookups: 0 };\n\tprivate readonly dirOptions: ProbedGitDirOptions;\n\t/** Keyed by repo path */\n\tprivate readonly roots = new Map<string, TargetState>();\n\t/** Keyed by common path */\n\tprivate readonly commons = new Map<string, TargetState>();\n\t/** Keyed by absolute path; the readings that may be racy, with when each was first read */\n\tprivate readonly racyReadings = new Map<string, { mtime: number; size: number; firstSeen: number }>();\n\t/**\n\t * Keyed by repo path; one that found nothing is kept, so the reads meanwhile don't retry it: for the window after a\n\t * failure, for {@link unresolvableRetryMs} after a git dir the files can't show\n\t */\n\tprivate readonly resolutions = new Map<string, ResolutionState>();\n\t/** The validation {@link onWatched} ran as a watcher attached, by repo path, which reads wait for while it runs */\n\tprivate readonly handoffs = new Map<string, Promise<void>>();\n\t/** By the repo path of a watched worktree, what moved in its common git dir that its watcher was left to clear */\n\tprivate readonly deferred = new Map<\n\t\tstring,\n\t\t{ readonly commonPath: string; readonly changes: Set<RepositoryChange> }\n\t>();\n\n\tconstructor(options: UnwatchedCacheValidatorOptions) {\n\t\tthis.cache = options.cache;\n\t\tthis.isWatched = options.isWatched;\n\t\tthis.now = options.now ?? ((): number => Date.now());\n\t\tthis.timeoutMs = Math.min(options.timeoutMs ?? defaultValidationTimeoutMs, maxValidationTimeoutMs);\n\t\tthis.resolveGitDir = options.resolveGitDir;\n\t\t// A `NaN` would fail every slot check, so nothing would ever be validated\n\t\tconst maxFsThreads = Math.floor(options.maxFsThreads ?? defaultMaxFsThreads);\n\t\tthis.gate = new FileSystemGate(\n\t\t\tthis.timeoutMs,\n\t\t\tNumber.isNaN(maxFsThreads) ? defaultMaxFsThreads : Math.max(1, maxFsThreads),\n\t\t);\n\t\tthis.dirOptions = {\n\t\t\tgate: this.gate,\n\t\t\tstat: options.stat,\n\t\t\treadDirectory: options.readDirectory,\n\t\t\treadFile: options.readFile,\n\t\t\tgetIgnoredWorktreeRoots: options.getIgnoredWorktreeRoots,\n\t\t\tisRacy: (stat, path) => this.isRacy(stat, path),\n\t\t};\n\t}\n\n\t/**\n\t * Whether `stat` of `path` may still show the same file a write in its own second would leave. Only a whole-second\n\t * mtime can, and only until its second ended: by the mtime's own clock, and by ours since the reading was first\n\t * seen, whichever comes first\n\t */\n\tprivate isRacy(stat: ProbeStat, path: string): boolean {\n\t\tconst now = this.now();\n\t\tif (stat.mtime % 1000 !== 0 || now - stat.mtime >= racyMtimeWindowMs) {\n\t\t\tthis.racyReadings.delete(path);\n\t\t\treturn false;\n\t\t}\n\n\t\tlet reading = this.racyReadings.get(path);\n\t\tif (reading == null || reading.mtime !== stat.mtime || reading.size !== stat.size) {\n\t\t\treading = { mtime: stat.mtime, size: stat.size, firstSeen: now };\n\t\t\tthis.racyReadings.delete(path);\n\t\t\tthis.racyReadings.set(path, reading);\n\t\t\tif (this.racyReadings.size > maxRacyReadings) {\n\t\t\t\tconst oldest = this.racyReadings.keys().next();\n\t\t\t\tif (!oldest.done) {\n\t\t\t\t\tthis.racyReadings.delete(oldest.value);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\t// Kept newest, so the cap drops the reading read longest ago, not one still read\n\t\t\tthis.racyReadings.delete(path);\n\t\t\tthis.racyReadings.set(path, reading);\n\t\t\t// A clock set back since counts from now, or the reading would stay racy until it caught up\n\t\t\tif (now < reading.firstSeen) {\n\t\t\t\treading.firstSeen = now;\n\t\t\t}\n\t\t}\n\n\t\treturn now - reading.firstSeen < racyMtimeWindowMs;\n\t}\n\n\t/**\n\t * Validates what `repoPath`'s reads would be served from, unless a watcher covers it or it was validated within\n\t * the last 250ms. `undefined` when there's nothing to wait for; otherwise settles once what moved was applied to\n\t * the cache, or after {@link UnwatchedCacheValidatorOptions.timeoutMs} with the cache as is, whichever is first.\n\t * Never rejects. A path that can't be read counts as moved as it becomes unreadable and again as it becomes\n\t * readable; a directory that can't be listed is listed again at the next validation, and what changes deeper inside\n\t * it goes unseen until it can be.\n\t */\n\tvalidate(repoPath: string): Promise<void> | undefined {\n\t\treturn this.handoffs.get(repoPath) ?? this.run(repoPath, false);\n\t}\n\n\t/**\n\t * A watcher attached to `repoPath`, so it reports only what changes from now on: validates now what changed since\n\t * the last validation, whatever the window, and has `repoPath`'s reads wait for it.\n\t */\n\tonWatched(repoPath: string): void {\n\t\tconst validation = this.run(repoPath, true);\n\t\tif (validation == null) return;\n\n\t\tconst handoff: Promise<void> = validation.finally(() => {\n\t\t\tif (this.handoffs.get(repoPath) === handoff) {\n\t\t\t\tthis.handoffs.delete(repoPath);\n\t\t\t}\n\t\t});\n\t\tthis.handoffs.set(repoPath, handoff);\n\t}\n\n\t/**\n\t * A watcher left `repoPath`, dropping what it held back unreported. What moved in its common git dir that an\n\t * unwatched sibling's validation left to it is applied now, since that validation took the shared baseline past it;\n\t * whatever else it dropped is still ahead of its own baselines.\n\t */\n\tonUnwatched(repoPath: string): void {\n\t\tconst deferred = this.deferred.get(repoPath);\n\t\tif (deferred == null) return;\n\n\t\tthis.deferred.delete(repoPath);\n\t\t// To the common path, which keys the shared entries, as `repoPath` may already be unregistered\n\t\tthis.cache.onRepositoryChanged(deferred.commonPath, deferred.changes);\n\t\t// And to a linked worktree's own entries while it is still registered, which its watcher would have cleared too\n\t\tif (repoPath !== deferred.commonPath && this.cache.isRegistered(repoPath)) {\n\t\t\tthis.cache.applyRepositoryChanges(repoPath, deferred.changes, 'share', { worktreeOnly: true });\n\t\t}\n\t}\n\n\tprivate run(repoPath: string, force: boolean): Promise<void> | undefined {\n\t\tif (!force && this.isWatched(repoPath)) return undefined;\n\n\t\t// A watcher attaching has no baseline to hand off without a git dir\n\t\tif (this.cache.gitDir.get(repoPath) == null) return force ? undefined : this.resolveThenValidate(repoPath);\n\n\t\tconst waits = this.start(repoPath, force);\n\t\treturn waits?.length ? this.waitAtMost(waits) : undefined;\n\t}\n\n\t/** Starts validating `repoPath`, or joins the validations in flight; what a read waits for */\n\tprivate start(repoPath: string, force: boolean): (readonly [Waitable, Promise<void>])[] | undefined {\n\t\tconst gitDir = this.cache.gitDir.get(repoPath);\n\t\tif (gitDir == null) return undefined;\n\n\t\tconst commonPath = this.cache.getCommonPath(repoPath);\n\t\t// A watcher suspended holds what was left to it until it resumes, and suspending announces nothing\n\t\tfor (const [path, deferred] of this.deferred) {\n\t\t\tif (deferred.commonPath === commonPath && !this.isWatched(path)) {\n\t\t\t\tthis.onUnwatched(path);\n\t\t\t}\n\t\t}\n\n\t\tconst commonGitDir = (gitDir.commonUri ?? gitDir.uri).fsPath;\n\t\tconst root = this.getTarget(this.roots, repoPath, 'root', gitDir.uri.fsPath, commonPath, commonGitDir);\n\t\t// Read even while another worktree's watcher covers it: that watcher clears the shared entries, never this\n\t\t// worktree's own\n\t\tconst common = this.getTarget(this.commons, commonPath, 'common', commonGitDir, commonPath, commonGitDir);\n\n\t\tconst waits: (readonly [Waitable, Promise<void>])[] = [];\n\t\tconst previous: Promise<void>[] = [];\n\t\tconst start = (state: TargetState | undefined): TargetState | undefined => {\n\t\t\tif (state == null) return undefined;\n\n\t\t\tif (state.running != null) {\n\t\t\t\tif (!force) {\n\t\t\t\t\tif (state.slow !== state.running) {\n\t\t\t\t\t\twaits.push([state, state.running]);\n\t\t\t\t\t}\n\t\t\t\t\treturn undefined;\n\t\t\t\t}\n\n\t\t\t\tprevious.push(state.running);\n\t\t\t} else if (!force && state.settledAt != null) {\n\t\t\t\t// A clock set back since counts as outside the window, or nothing would validate until it caught up\n\t\t\t\tconst elapsed = this.now() - state.settledAt;\n\t\t\t\tif (elapsed >= 0 && elapsed < validationWindowMs) return undefined;\n\t\t\t}\n\t\t\treturn state;\n\t\t};\n\t\tconst startedRoot = start(root);\n\t\tconst startedCommon = start(common);\n\n\t\tif (startedRoot != null || startedCommon != null) {\n\t\t\tconst job = this.runTargets(repoPath, commonPath, startedRoot, startedCommon, previous);\n\t\t\tif (startedRoot != null) {\n\t\t\t\tstartedRoot.running = job;\n\t\t\t}\n\t\t\tif (startedCommon != null) {\n\t\t\t\tstartedCommon.running = job;\n\t\t\t}\n\t\t\tfor (const state of [startedRoot, startedCommon]) {\n\t\t\t\tif (state != null) {\n\t\t\t\t\twaits.push([state, job]);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn waits;\n\t}\n\n\t/**\n\t * Resolves the git dir of `repoPath` (through the gate, as one call, keyed by `repoPath` since its common git dir\n\t * isn't known yet), then validates it as usual within the same wait. That first validation has no baseline.\n\t */\n\tprivate resolveThenValidate(repoPath: string): Promise<void> | undefined {\n\t\tconst resolveGitDir = this.resolveGitDir;\n\t\tif (resolveGitDir == null) return undefined;\n\n\t\tlet state = this.resolutions.get(repoPath);\n\t\tlet running = state?.running;\n\t\tif (state != null && running != null) {\n\t\t\tif (state.slow === running) return undefined;\n\t\t} else {\n\t\t\tif (state?.settledAt != null) {\n\t\t\t\tconst elapsed = this.now() - state.settledAt;\n\t\t\t\tif (elapsed >= 0 && elapsed < state.retryAfterMs) return undefined;\n\t\t\t}\n\n\t\t\tstate = { started: [], retryAfterMs: validationWindowMs };\n\t\t\trunning = this.startResolution(repoPath, resolveGitDir, state);\n\t\t}\n\n\t\treturn this.waitAtMost([[state, running]]);\n\t}\n\n\tprivate startResolution(\n\t\trepoPath: string,\n\t\tresolveGitDir: (repoPath: string) => Promise<boolean>,\n\t\tstate: ResolutionState,\n\t): Promise<void> {\n\t\tlet found = false;\n\t\tthis.counts.gitDirLookups++;\n\t\tconst running: Promise<void> = this.gate\n\t\t\t.run(repoPath, () => resolveGitDir(repoPath))\n\t\t\t.catch((): undefined => undefined)\n\t\t\t.then(async resolved => {\n\t\t\t\tfound = resolved === true;\n\t\t\t\t// Only a definite \"no\" waits long: a failure may pass\n\t\t\t\tif (resolved === false) {\n\t\t\t\t\tstate.retryAfterMs = unresolvableRetryMs;\n\t\t\t\t}\n\t\t\t\tif (!found || this.isWatched(repoPath)) return;\n\n\t\t\t\tconst waits = this.start(repoPath, false);\n\t\t\t\tif (waits == null) return;\n\n\t\t\t\tstate.started.push(...waits);\n\t\t\t\tawait Promise.all(waits.map(([, validation]) => validation));\n\t\t\t})\n\t\t\t.finally(() => {\n\t\t\t\tstate.settledAt = this.now();\n\t\t\t\tstate.running = undefined;\n\t\t\t\t// Reads go by the cached git dir from here on\n\t\t\t\tif (found && this.resolutions.get(repoPath) === state) {\n\t\t\t\t\tthis.resolutions.delete(repoPath);\n\t\t\t\t}\n\t\t\t});\n\t\tstate.running = running;\n\n\t\tthis.resolutions.delete(repoPath);\n\t\tthis.resolutions.set(repoPath, state);\n\t\tif (this.resolutions.size > maxTargets) {\n\t\t\tconst oldest = this.resolutions.keys().next();\n\t\t\tif (!oldest.done) {\n\t\t\t\tthis.resolutions.delete(oldest.value);\n\t\t\t}\n\t\t}\n\t\treturn running;\n\t}\n\n\t/**\n\t * Settles once `waits`' validations do, or once the timeout elapses, latching those still running as slow (and what\n\t * they started) so the reads after it don't wait for them again\n\t */\n\tprivate waitAtMost(waits: readonly (readonly [Waitable, Promise<void>])[]): Promise<void> {\n\t\tconst latch = (state: Waitable, running: Promise<void>): void => {\n\t\t\tif (state.running !== running) return;\n\n\t\t\tstate.slow = running;\n\t\t\tfor (const [started, startedRunning] of state.started ?? []) {\n\t\t\t\tlatch(started, startedRunning);\n\t\t\t}\n\t\t};\n\n\t\t// The waits never reject, so only the timeout lands in the rejection handler\n\t\treturn raceWithTimeout(Promise.all(waits.map(([, running]) => running)), this.timeoutMs).then(\n\t\t\t() => undefined,\n\t\t\t() => {\n\t\t\t\tthis.counts.waitsTimedOut++;\n\t\t\t\tfor (const [state, running] of waits) {\n\t\t\t\t\tlatch(state, running);\n\t\t\t\t}\n\t\t\t},\n\t\t);\n\t}\n\n\t/**\n\t * What validating has cost, for a host to weigh against watching: counts since the validator was created of the\n\t * validations run, those that cleared something, the reads served as is after their wait timed out, the git dir\n\t * lookups, and the file-system calls made; and, as of now, the calls stuck on a hung mount and the git dirs kept\n\t */\n\tgetResourceUsage(): ResourceUsage {\n\t\treturn {\n\t\t\t'unwatchedValidation.validations.count': this.counts.validations,\n\t\t\t'unwatchedValidation.validationsApplied.count': this.counts.validationsApplied,\n\t\t\t'unwatchedValidation.waitsTimedOut.count': this.counts.waitsTimedOut,\n\t\t\t'unwatchedValidation.gitDirLookups.count': this.counts.gitDirLookups,\n\t\t\t'unwatchedValidation.fsCalls.count': this.gate.calls,\n\t\t\t'unwatchedValidation.fsCallsStuck.count': this.gate.stuckCalls,\n\t\t\t'unwatchedValidation.gitDirs.count': this.roots.size + this.commons.size,\n\t\t};\n\t}\n\n\t/** The repository's other worktrees whose watchers cover its common git dir */\n\tprivate getCommonWatchers(repoPath: string, commonPath: string): string[] {\n\t\tconst watchers = new Set<string>();\n\t\tif (commonPath !== repoPath && this.isWatched(commonPath)) {\n\t\t\twatchers.add(commonPath);\n\t\t}\n\t\tfor (const path of this.cache.getWorktreePaths(commonPath)) {\n\t\t\tif (path !== repoPath && this.isWatched(path)) {\n\t\t\t\twatchers.add(path);\n\t\t\t}\n\t\t}\n\t\treturn [...watchers];\n\t}\n\n\tprivate getTarget(\n\t\ttargets: Map<string, TargetState>,\n\t\tkey: string,\n\t\tkind: 'root' | 'common',\n\t\tbasePath: string,\n\t\tcommonPath: string,\n\t\tcommonGitDir: string,\n\t): TargetState {\n\t\tlet state = targets.get(key);\n\t\tif (state?.dir.basePath === basePath && state.dir.commonPath === commonPath) {\n\t\t\t// Kept newest, so the cap drops the target read longest ago\n\t\t\ttargets.delete(key);\n\t\t} else {\n\t\t\tstate = { dir: new ProbedGitDir(kind, basePath, commonPath, commonGitDir, this.dirOptions), runs: 0 };\n\t\t}\n\t\ttargets.set(key, state);\n\n\t\tif (targets.size > maxTargets) {\n\t\t\tconst oldest = targets.keys().next();\n\t\t\tif (!oldest.done) {\n\t\t\t\ttargets.delete(oldest.value);\n\t\t\t}\n\t\t}\n\t\treturn state;\n\t}\n\n\tprivate async runTargets(\n\t\trepoPath: string,\n\t\tcommonPath: string,\n\t\troot: TargetState | undefined,\n\t\tcommon: TargetState | undefined,\n\t\tprevious: readonly Promise<void>[],\n\t): Promise<void> {\n\t\tconst rootRun = root != null ? ++root.runs : 0;\n\t\tconst commonRun = common != null ? ++common.runs : 0;\n\t\t// Before anything is awaited: a watcher that attaches from here on reports only what changes after it attached,\n\t\t// and its own validation reads the common git dir after this one, from the baseline this one advances\n\t\tconst watchedAtStart = new Set(this.getCommonWatchers(repoPath, commonPath));\n\t\ttry {\n\t\t\t// A forced validation reads after the one in flight, never beside it\n\t\t\tif (previous.length) {\n\t\t\t\tawait Promise.all(previous);\n\t\t\t}\n\n\t\t\t// The root and common git dirs of one validation can share paths: a main checkout's are the same, and a\n\t\t\t// linked worktree's root is an admin entry of the common one\n\t\t\tconst memo: StatMemo = new Map();\n\t\t\tconst [rootResult, commonResult] = await Promise.all([\n\t\t\t\troot?.dir.validate(memo, repoPath),\n\t\t\t\tcommon?.dir.validate(memo, repoPath),\n\t\t\t]);\n\t\t\tthis.counts.validations++;\n\t\t\tif (rootResult?.changes.size || commonResult?.changes.size) {\n\t\t\t\tthis.counts.validationsApplied++;\n\t\t\t}\n\t\t\tthis.apply(repoPath, commonPath, rootResult, commonResult, watchedAtStart);\n\t\t} catch {\n\t\t\t// `validate` never rejects, so only applying can have thrown; whatever it did apply stands\n\t\t} finally {\n\t\t\t// Before the validation settles, so a read it gated finds the window open and runs no other\n\t\t\tconst settledAt = this.now();\n\t\t\tif (root != null) {\n\t\t\t\troot.settledAt = settledAt;\n\t\t\t\tif (root.runs === rootRun) {\n\t\t\t\t\troot.running = undefined;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (common != null) {\n\t\t\t\tcommon.settledAt = settledAt;\n\t\t\t\tif (common.runs === commonRun) {\n\t\t\t\t\tcommon.running = undefined;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Applies what moved to `repoPath`, and what moved in the common git dir to its other unwatched registered worktrees\n\t * too, as the common watcher would have told each of them. While another worktree's watcher covers the common git\n\t * dir, it already cleared the shared entries, so only the worktrees' own are. A watcher covers it only if it watched\n\t * since before the stats began (`watchedAtStart`)\n\t */\n\tprivate apply(\n\t\trepoPath: string,\n\t\tcommonPath: string,\n\t\troot: ValidationResult | undefined,\n\t\tcommon: ValidationResult | undefined,\n\t\twatchedAtStart: ReadonlySet<string>,\n\t): void {\n\t\tconst watchers = this.getCommonWatchers(repoPath, commonPath).filter(p => watchedAtStart.has(p));\n\t\tconst commonWatched = watchers.length !== 0;\n\t\tconst changes = new Set<RepositoryChange>(root?.changes);\n\t\tif (!commonWatched) {\n\t\t\tfor (const change of common?.changes ?? []) {\n\t\t\t\tchanges.add(change);\n\t\t\t}\n\t\t}\n\n\t\tif (changes.size) {\n\t\t\t// Only the common git dir reports a `'worktreeHead'`\n\t\t\tthis.cache.onRepositoryChanged(repoPath, changes, {\n\t\t\t\tmovedWorktrees: changes.has('worktreeHead') ? common?.movedWorktrees : undefined,\n\t\t\t});\n\t\t}\n\n\t\tif (!common?.changes.size) return;\n\n\t\tif (commonWatched) {\n\t\t\tthis.cache.applyRepositoryChanges(repoPath, common.changes, 'share', { worktreeOnly: true });\n\n\t\t\t// Kept for each watcher until it leaves (see `onUnwatched`), since one that leaves first drops what it held back\n\t\t\tfor (const path of watchers) {\n\t\t\t\tlet deferred = this.deferred.get(path);\n\t\t\t\tif (deferred?.commonPath !== commonPath) {\n\t\t\t\t\tdeferred = { commonPath: commonPath, changes: new Set() };\n\t\t\t\t\tthis.deferred.set(path, deferred);\n\t\t\t\t}\n\t\t\t\tfor (const change of common.changes) {\n\t\t\t\t\tdeferred.changes.add(change);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tfor (const path of this.cache.getWorktreePaths(commonPath)) {\n\t\t\tif (path === repoPath || watchers.includes(path)) continue;\n\n\t\t\tthis.cache.applyRepositoryChanges(path, common.changes, 'share', { worktreeOnly: true });\n\t\t}\n\t}\n}\n\n/**\n * Runs file-system calls at most {@link maxFsCalls} at once, and at most {@link maxFsCallsPerRepo} at once for a key;\n * the calls waiting start in the order they came, skipping those whose key is busy. A call outstanding past the\n * timeout is stuck, as on a hung mount: it stops counting against {@link maxFsCalls}, so other keys' calls go on, but\n * keeps its key busy and holds one of the threads the gate is allowed until it returns\n */\nclass FileSystemGate {\n\t/** The keys with calls in flight, by how many */\n\tprivate readonly busy = new Map<string, number>();\n\tprivate readonly waiting: { readonly key: string; readonly start: () => void }[] = [];\n\tprivate active = 0;\n\tprivate stuck = 0;\n\t/** The calls made since it was created */\n\tcalls = 0;\n\n\tconstructor(\n\t\tprivate readonly timeoutMs: number,\n\t\t/** Calls in flight at most, stuck ones included */\n\t\tprivate readonly maxThreads: number,\n\t) {}\n\n\tasync run<T>(key: string, call: () => Promise<T>): Promise<T> {\n\t\tif (this.canStart(key)) {\n\t\t\tthis.acquire(key);\n\t\t} else {\n\t\t\tawait new Promise<void>(resolve => this.waiting.push({ key: key, start: resolve }));\n\t\t}\n\n\t\tthis.calls++;\n\t\tlet stuck = false;\n\t\tconst timer = setTimeout(() => {\n\t\t\tstuck = true;\n\t\t\tthis.active--;\n\t\t\tthis.stuck++;\n\t\t\tthis.drain();\n\t\t}, this.timeoutMs);\n\t\t// A call alone must not keep a (Node) process alive; in the browser timers are numbers\n\t\tif (typeof timer !== 'number') {\n\t\t\ttimer.unref();\n\t\t}\n\n\t\ttry {\n\t\t\treturn await call();\n\t\t} finally {\n\t\t\tif (stuck) {\n\t\t\t\tthis.stuck--;\n\t\t\t} else {\n\t\t\t\tclearTimeout(timer);\n\t\t\t\tthis.active--;\n\t\t\t}\n\t\t\tthis.release(key);\n\t\t}\n\t}\n\n\t/** The calls outstanding past the timeout */\n\tget stuckCalls(): number {\n\t\treturn this.stuck;\n\t}\n\n\tprivate hasSlot(): boolean {\n\t\treturn this.active < maxFsCalls && this.active + this.stuck < this.maxThreads;\n\t}\n\n\tprivate canStart(key: string): boolean {\n\t\treturn this.hasSlot() && (this.busy.get(key) ?? 0) < maxFsCallsPerRepo;\n\t}\n\n\tprivate acquire(key: string): void {\n\t\tthis.active++;\n\t\tthis.busy.set(key, (this.busy.get(key) ?? 0) + 1);\n\t}\n\n\tprivate release(key: string): void {\n\t\tconst count = (this.busy.get(key) ?? 1) - 1;\n\t\tif (count > 0) {\n\t\t\tthis.busy.set(key, count);\n\t\t} else {\n\t\t\tthis.busy.delete(key);\n\t\t}\n\t\tthis.drain();\n\t}\n\n\tprivate drain(): void {\n\t\tlet i = 0;\n\t\twhile (i < this.waiting.length && this.hasSlot()) {\n\t\t\tconst waiter = this.waiting[i];\n\t\t\tif (!this.canStart(waiter.key)) {\n\t\t\t\ti++;\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tthis.waiting.splice(i, 1);\n\t\t\t// Claimed before it resumes, so no call that comes meanwhile takes its slot\n\t\t\tthis.acquire(waiter.key);\n\t\t\twaiter.start();\n\t\t}\n\t}\n}\n\ninterface ProbedGitDirOptions {\n\t/** Shared by every git dir the validator reads */\n\treadonly gate: FileSystemGate;\n\treadonly stat: (path: string) => Promise<ProbeStat | undefined>;\n\treadonly readDirectory: (path: string) => Promise<readonly (readonly [string, number])[]>;\n\treadonly readFile: ((path: string) => Promise<Uint8Array | undefined>) | undefined;\n\treadonly getIgnoredWorktreeRoots: ((repoPath: string) => Promise<readonly string[]>) | undefined;\n\treadonly isRacy: (stat: ProbeStat, path: string) => boolean;\n}\n\n/** The probes of a gate's files, read only once the gate moved */\ninterface GatedTarget {\n\treadonly target: GitDirProbeTarget;\n\t/** Whether its baseline was taken */\n\tread: boolean;\n}\n\n/**\n * The readings of one git dir: a worktree's own (`root`), or the common one, whose ref directories and worktree admin\n * entries it finds by listing them. A directory is listed only after its reading was recorded, so whatever a listing\n * missed moves the directory again. A path that can't be read counts as moved as it becomes unreadable and again as it\n * becomes readable; a directory that can't be listed keeps what it held and is listed again at the next validation, so\n * what changes deeper inside it goes unseen until it can be. Without a baseline, a worktree's own git dir reports only\n * what its probes can, the common one everything.\n */\nclass ProbedGitDir {\n\t/** The probes read every time, the gates among them */\n\tprivate target: GitDirProbeTarget;\n\t/** By the path of their gate: the git dir's own, and each admin entry's */\n\tprivate readonly gated = new Map<string, GatedTarget>();\n\tprivate baselined = false;\n\t/** The directories found under the ref namespaces, which a ref created or deleted in them moves */\n\tprivate readonly refDirs = new Set<string>();\n\t/** By admin id, whether core ignores the linked worktree, which leaves only its `gitdir` probed */\n\tprivate readonly worktrees = new Map<string, { ignored: boolean }>();\n\t/** The probes that moved during the current validation, by path */\n\tprivate readonly moved = new Map<string, GitDirProbe>();\n\t/** The paths of the probes that moved in the last poll */\n\tprivate readonly movedInPoll = new Set<string>();\n\t/** The gates that moved during the current validation */\n\tprivate readonly movedGates = new Set<string>();\n\t/** The admin ids found during the current validation */\n\tprivate readonly foundWorktrees = new Set<string>();\n\t/** The admin ids removed during the current validation, by whether they were ignored */\n\tprivate readonly removedWorktrees = new Map<string, boolean>();\n\t/** The admin ids whose ignored status flipped during the current validation */\n\tprivate readonly flippedWorktrees = new Set<string>();\n\t/**\n\t * The directories the next validation lists whether they moved or not: those that couldn't be listed, and those\n\t * left at {@link maxDiscoveryPolls}\n\t */\n\tprivate readonly pendingDirs = new Set<string>();\n\t/** The admin ids left at {@link maxDiscoveryPolls}, whose `gitdir` the next validation reads whether it moved or not */\n\tprivate readonly pendingEntries = new Set<string>();\n\t/** The common git dir's own `reftable/tables.list`; only while it's there do the admin entries have their own */\n\tprivate readonly reftablePath: string | undefined;\n\t/** Whether {@link reftablePath} was there at its last reading */\n\tprivate reftable = false;\n\t/** The current validation's */\n\tprivate memo: StatMemo | undefined;\n\t/** The current validation's repository, whose git dir the cache holds */\n\tprivate repoPath: string | undefined;\n\t/** The current validation's, once a worktree needed them */\n\tprivate ignoredRoots: Promise<readonly string[]> | undefined;\n\n\tconstructor(\n\t\treadonly kind: 'root' | 'common',\n\t\treadonly basePath: string,\n\t\t/** The repository's common path as the cache resolved it */\n\t\treadonly commonPath: string,\n\t\t/**\n\t\t * The repository's common git dir, which keys its file-system calls in the gate, shared with its worktrees':\n\t\t * unlike the common path, the same for a worktree the cache never registered\n\t\t */\n\t\tprivate readonly gateKey: string,\n\t\tprivate readonly options: ProbedGitDirOptions,\n\t) {\n\t\tthis.reftablePath = kind === 'common' ? joinPaths(basePath, reftableProbePath) : undefined;\n\t\tthis.target = this.createTarget(() => this.getProbes());\n\t\tthis.addGated(gitDirGatePath, kind === 'root' ? rootGatedProbes : commonGatedProbes);\n\t}\n\n\t/**\n\t * Polls the probes and answers what moved since the last validation; everything it can report when there's no\n\t * baseline. `memo` holds the stats of the validation it's part of\n\t */\n\tasync validate(memo: StatMemo, repoPath: string): Promise<ValidationResult> {\n\t\tthis.moved.clear();\n\t\tthis.movedGates.clear();\n\t\tthis.foundWorktrees.clear();\n\t\tthis.removedWorktrees.clear();\n\t\tthis.flippedWorktrees.clear();\n\t\tthis.memo = memo;\n\t\tthis.repoPath = repoPath;\n\n\t\tlet failed = false;\n\t\ttry {\n\t\t\tawait this.poll();\n\t\t\tif (this.kind === 'common') {\n\t\t\t\tawait this.discover();\n\t\t\t}\n\t\t\tawait this.pollGated();\n\t\t} catch {\n\t\t\tfailed = true;\n\t\t} finally {\n\t\t\tthis.memo = undefined;\n\t\t\tthis.repoPath = undefined;\n\t\t\tthis.ignoredRoots = undefined;\n\t\t}\n\n\t\tif (failed || !this.baselined) {\n\t\t\tif (failed) {\n\t\t\t\tthis.target = this.createTarget(() => this.getProbes());\n\t\t\t\tthis.gated.clear();\n\t\t\t\tthis.addGated(gitDirGatePath, this.kind === 'root' ? rootGatedProbes : commonGatedProbes);\n\t\t\t\tthis.baselined = false;\n\t\t\t\tthis.refDirs.clear();\n\t\t\t\tthis.worktrees.clear();\n\t\t\t\tthis.pendingDirs.clear();\n\t\t\t\tthis.pendingEntries.clear();\n\t\t\t\tthis.reftable = false;\n\t\t\t} else {\n\t\t\t\tthis.baselined = true;\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tchanges: new Set(this.kind === 'root' ? rootReportableChanges : allWatchedRepositoryChanges),\n\t\t\t\tmovedWorktrees: undefined,\n\t\t\t};\n\t\t}\n\n\t\treturn this.classify();\n\t}\n\n\tprivate createTarget(getProbes: () => Iterable<GitDirProbe>): GitDirProbeTarget {\n\t\treturn new GitDirProbeTarget(\n\t\t\tthis.basePath,\n\t\t\t{ stat: path => this.stat(path), invalidate: () => {} },\n\t\t\tgetProbes,\n\t\t\tnew Map(),\n\t\t\t(_event, probe) => {\n\t\t\t\tif (isGatePath(probe.path)) {\n\t\t\t\t\tthis.movedGates.add(probe.path);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tthis.moved.set(probe.path, probe);\n\t\t\t\tthis.movedInPoll.add(probe.path);\n\t\t\t},\n\t\t\t{ isRacy: this.options.isRacy },\n\t\t);\n\t}\n\n\tprivate addGated(gatePath: string, probes: readonly GitDirProbe[]): void {\n\t\tthis.gated.set(gatePath, { target: this.createTarget(() => probes), read: false });\n\t}\n\n\tprivate addWorktreeGated(id: string): void {\n\t\tthis.addGated(`worktrees/${id}`, [{ path: `worktrees/${id}/HEAD` }, { path: `worktrees/${id}/locked` }]);\n\t}\n\n\tprivate async stat(path: string): Promise<ProbeStat | undefined> {\n\t\tlet stat = this.memo?.get(path);\n\t\tif (stat == null) {\n\t\t\t// Mapped before it's shared, so the root and common git dirs read the same\n\t\t\tstat = this.options.gate\n\t\t\t\t.run(this.gateKey, () => this.options.stat(path))\n\t\t\t\t.catch((ex: unknown) => {\n\t\t\t\t\t// A path under one that is now a file (a ref directory replaced by a ref of its name) isn't there\n\t\t\t\t\tif (isNotFound(ex) || isNotADirectory(ex)) return undefined;\n\n\t\t\t\t\t// Read as a reading of its own rather than skipped (as the probe target skips a stat that throws), so\n\t\t\t\t\t// the path moves as it becomes unreadable and as it becomes readable again\n\t\t\t\t\treturn unreadable;\n\t\t\t\t});\n\t\t\tthis.memo?.set(path, stat);\n\t\t}\n\n\t\tconst result = await stat;\n\t\tif (path === this.reftablePath && result !== unreadable) {\n\t\t\tthis.reftable = result != null;\n\t\t}\n\t\treturn result;\n\t}\n\n\tprivate poll(): Promise<void> {\n\t\tthis.movedInPoll.clear();\n\t\treturn this.target.poll();\n\t}\n\n\t/** Polls the files of each gate that moved during this validation, and of each never read */\n\tprivate async pollGated(): Promise<void> {\n\t\tconst due = [...this.gated].filter(([gate, gated]) => !gated.read || this.movedGates.has(gate));\n\t\tawait Promise.all(\n\t\t\tdue.map(async ([, gated]) => {\n\t\t\t\tawait gated.target.poll();\n\t\t\t\tgated.read = true;\n\t\t\t}),\n\t\t);\n\t}\n\n\tprivate getProbes(): GitDirProbe[] {\n\t\tif (this.kind === 'root') return [...rootAlwaysProbes];\n\n\t\tconst probes = [...commonAlwaysProbes];\n\t\tfor (const path of this.refDirs) {\n\t\t\tprobes.push({ path: path });\n\t\t}\n\t\tfor (const [id, { ignored }] of this.worktrees) {\n\t\t\tprobes.push({ path: `worktrees/${id}/gitdir` });\n\t\t\tif (ignored) continue;\n\n\t\t\tprobes.push({ path: `worktrees/${id}` });\n\t\t\tif (this.reftable) {\n\t\t\t\tprobes.push({ path: `worktrees/${id}/${reftableProbePath}` });\n\t\t\t}\n\t\t}\n\t\treturn probes;\n\t}\n\n\t/** The listed directories that moved in the last poll */\n\tprivate getMovedDirs(): string[] {\n\t\treturn [...this.movedInPoll].filter(p => p === 'worktrees' || refNamespaces.includes(p) || this.refDirs.has(p));\n\t}\n\n\t/** The known admin ids whose `gitdir` moved in the last poll */\n\tprivate getMovedGitdirs(): string[] {\n\t\tconst ids: string[] = [];\n\t\tfor (const path of this.movedInPoll) {\n\t\t\tconst entry = parseWorktreeAdminPath(path);\n\t\t\tif (entry?.file === 'gitdir' && this.worktrees.has(entry.id)) {\n\t\t\t\tids.push(entry.id);\n\t\t\t}\n\t\t}\n\t\treturn ids;\n\t}\n\n\t/**\n\t * Lists the directories that moved in the last poll (every one, the first time), and polls again while that finds\n\t * new ones, so they have readings before the caches are read again: the move of the directory they're in already\n\t * reported whatever they hold. Reads whether each admin entry new to it, or whose `gitdir` moved, is ignored, once\n\t * that `gitdir` has a reading. Also lists what an earlier validation left: the directories it couldn't list, and\n\t * what was still to list or read when it reached {@link maxDiscoveryPolls}.\n\t */\n\tprivate async discover(): Promise<void> {\n\t\tlet dirs = this.baselined\n\t\t\t? [...new Set([...this.pendingDirs, ...this.getMovedDirs()])]\n\t\t\t: [...refNamespaces, 'worktrees'];\n\t\tlet entries = this.baselined ? [...new Set([...this.pendingEntries, ...this.getMovedGitdirs()])] : [];\n\t\tthis.pendingEntries.clear();\n\n\t\tfor (let polls = 0; ; polls++) {\n\t\t\tconst found = dirs.length ? await this.list(dirs) : { dirs: [], worktrees: [] };\n\t\t\tconst unignored = entries.length ? await this.readIgnored(entries) : false;\n\t\t\tif (!found.dirs.length && !found.worktrees.length && !unignored) return;\n\n\t\t\t// Even at the cap, so what was just found has a reading before the caches are read again\n\t\t\tawait this.poll();\n\t\t\tdirs = [...found.dirs, ...this.getMovedDirs()];\n\t\t\tentries = [...new Set([...found.worktrees, ...this.getMovedGitdirs()])];\n\n\t\t\tif (polls === maxDiscoveryPolls) {\n\t\t\t\tfor (const dir of dirs) {\n\t\t\t\t\tthis.pendingDirs.add(dir);\n\t\t\t\t}\n\t\t\t\tfor (const id of entries) {\n\t\t\t\t\tthis.pendingEntries.add(id);\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Lists `dirs`, dropping the directories (or admin entries) no longer in them, and answers what's new. One that\n\t * can't be listed keeps what it held, and is left for the next validation to list\n\t */\n\tprivate async list(dirs: readonly string[]): Promise<{ dirs: string[]; worktrees: string[] }> {\n\t\tconst found: { dirs: string[]; worktrees: string[] } = { dirs: [], worktrees: [] };\n\n\t\tawait Promise.all(\n\t\t\tdirs.map(async dir => {\n\t\t\t\tconst names = await this.readDirectories(dir);\n\t\t\t\tif (names == null) {\n\t\t\t\t\tthis.pendingDirs.add(dir);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tthis.pendingDirs.delete(dir);\n\t\t\t\tif (dir === 'worktrees') {\n\t\t\t\t\tfor (const [id, { ignored }] of this.worktrees) {\n\t\t\t\t\t\tif (!names.includes(id)) {\n\t\t\t\t\t\t\tthis.removedWorktrees.set(id, ignored);\n\t\t\t\t\t\t\tthis.worktrees.delete(id);\n\t\t\t\t\t\t\tthis.gated.delete(`worktrees/${id}`);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tfor (const id of names) {\n\t\t\t\t\t\tif (!this.worktrees.has(id)) {\n\t\t\t\t\t\t\t// Probed as not ignored until its `gitdir` is read\n\t\t\t\t\t\t\tthis.worktrees.set(id, { ignored: false });\n\t\t\t\t\t\t\tthis.addWorktreeGated(id);\n\t\t\t\t\t\t\tthis.foundWorktrees.add(id);\n\t\t\t\t\t\t\tfound.worktrees.push(id);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tconst children = new Set(names.map(name => `${dir}/${name}`));\n\t\t\t\tfor (const path of this.refDirs) {\n\t\t\t\t\tif (path.substring(0, path.lastIndexOf('/')) !== dir || children.has(path)) continue;\n\n\t\t\t\t\tfor (const p of this.refDirs) {\n\t\t\t\t\t\tif (p === path || p.startsWith(`${path}/`)) {\n\t\t\t\t\t\t\tthis.refDirs.delete(p);\n\t\t\t\t\t\t\tthis.pendingDirs.delete(p);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tfor (const path of children) {\n\t\t\t\t\tif (!this.refDirs.has(path)) {\n\t\t\t\t\t\tthis.refDirs.add(path);\n\t\t\t\t\t\tfound.dirs.push(path);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}),\n\t\t);\n\t\treturn found;\n\t}\n\n\t/**\n\t * Reads whether core ignores each of the admin entries `ids`, from their `gitdir`; answers whether one known as\n\t * ignored no longer is, whose gate the next poll must take a reading of. A read that fails ignores nothing\n\t */\n\tprivate async readIgnored(ids: readonly string[]): Promise<boolean> {\n\t\tconst { readFile, getIgnoredWorktreeRoots } = this.options;\n\t\tif (readFile == null || getIgnoredWorktreeRoots == null || this.repoPath == null) return false;\n\n\t\tconst repoPath = this.repoPath;\n\t\tconst roots = await (this.ignoredRoots ??= getIgnoredWorktreeRoots(repoPath).catch(() => []));\n\n\t\tlet unignored = false;\n\t\tawait Promise.all(\n\t\t\tids.map(async id => {\n\t\t\t\tlet ignored = false;\n\t\t\t\tif (roots.length) {\n\t\t\t\t\tconst adminDir = joinPaths(this.basePath, 'worktrees', id);\n\t\t\t\t\tlet gitdir: Uint8Array | undefined;\n\t\t\t\t\ttry {\n\t\t\t\t\t\tgitdir = await this.options.gate.run(this.gateKey, () =>\n\t\t\t\t\t\t\treadFile(joinPaths(adminDir, 'gitdir')),\n\t\t\t\t\t\t);\n\t\t\t\t\t} catch {}\n\t\t\t\t\tignored = isIgnoredWorktreeEntry(adminDir, gitdir, roots) === true;\n\t\t\t\t}\n\n\t\t\t\tconst entry = this.worktrees.get(id);\n\t\t\t\tif (entry == null || entry.ignored === ignored) return;\n\n\t\t\t\tentry.ignored = ignored;\n\t\t\t\t// A new entry was reported as the move of the `worktrees` directory it appeared in\n\t\t\t\tif (!this.foundWorktrees.has(id)) {\n\t\t\t\t\tthis.flippedWorktrees.add(id);\n\t\t\t\t}\n\t\t\t\tif (ignored) {\n\t\t\t\t\tthis.gated.delete(`worktrees/${id}`);\n\t\t\t\t} else {\n\t\t\t\t\tthis.addWorktreeGated(id);\n\t\t\t\t\tunignored = true;\n\t\t\t\t}\n\t\t\t}),\n\t\t);\n\t\treturn unignored;\n\t}\n\n\t/** The names of the directories in `dir`; none when it isn't there, and `undefined` when it couldn't be listed */\n\tprivate async readDirectories(dir: string): Promise<string[] | undefined> {\n\t\ttry {\n\t\t\tconst entries = await this.options.gate.run(this.gateKey, () =>\n\t\t\t\tthis.options.readDirectory(joinPaths(this.basePath, dir)),\n\t\t\t);\n\t\t\treturn entries.filter(([, type]) => (type & FileType.Directory) !== 0).map(([name]) => name);\n\t\t} catch (ex) {\n\t\t\tif (isNotFound(ex) || isNotADirectory(ex)) return [];\n\n\t\t\treturn undefined;\n\t\t}\n\t}\n\n\t/**\n\t * The admin ids, not ignored, that the listings of this validation added or removed; none when all were ignored, and\n\t * `undefined` when the listings changed nothing, so what moved the `worktrees` directory is unknown\n\t */\n\tprivate getAddedOrRemovedWorktrees(): string[] | undefined {\n\t\tif (!this.foundWorktrees.size && !this.removedWorktrees.size) return undefined;\n\n\t\tconst ids: string[] = [];\n\t\tfor (const id of this.foundWorktrees) {\n\t\t\tconst entry = this.worktrees.get(id);\n\t\t\tif (entry != null && !entry.ignored) {\n\t\t\t\tids.push(id);\n\t\t\t}\n\t\t}\n\t\tfor (const [id, ignored] of this.removedWorktrees) {\n\t\t\t// One found and gone again within the validation was never reported\n\t\t\tif (!ignored && !this.foundWorktrees.has(id)) {\n\t\t\t\tids.push(id);\n\t\t\t}\n\t\t}\n\t\treturn ids;\n\t}\n\n\tprivate classify(): ValidationResult {\n\t\tconst changes = new Set<RepositoryChange>();\n\t\tconst movedWorktrees = new Set<string>();\n\t\tlet anyWorktreeMoved = false;\n\n\t\tconst add = (...kinds: RepositoryChange[]): void => {\n\t\t\tfor (const kind of kinds) {\n\t\t\t\tchanges.add(kind);\n\t\t\t}\n\t\t};\n\n\t\tfor (const probe of this.moved.values()) {\n\t\t\tif (this.kind === 'common') {\n\t\t\t\t// Nothing in an ignored worktree's admin entry is cached, nor its going\n\t\t\t\tconst entry = parseWorktreeAdminPath(probe.path);\n\t\t\t\tif (entry != null && (this.worktrees.get(entry.id)?.ignored ?? this.removedWorktrees.get(entry.id))) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tfor (const path of probe.emitAs ?? [probe.path]) {\n\t\t\t\tif (path === reftableProbePath) {\n\t\t\t\t\tif (this.kind === 'root') {\n\t\t\t\t\t\tadd('head', 'heads');\n\t\t\t\t\t} else {\n\t\t\t\t\t\tadd('heads', 'remotes', 'tags', 'stash');\n\t\t\t\t\t}\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tif (this.kind === 'common') {\n\t\t\t\t\tif (path === 'FETCH_HEAD') {\n\t\t\t\t\t\tadd('lastFetched');\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\n\t\t\t\t\t// An admin entry added or removed, as its HEAD appearing or going would report to a watcher\n\t\t\t\t\tif (path === 'worktrees') {\n\t\t\t\t\t\tconst ids = this.getAddedOrRemovedWorktrees();\n\t\t\t\t\t\tif (ids == null) {\n\t\t\t\t\t\t\tadd('worktrees', 'worktreeHead');\n\t\t\t\t\t\t\tanyWorktreeMoved = true;\n\t\t\t\t\t\t} else if (ids.length) {\n\t\t\t\t\t\t\tadd('worktrees', 'worktreeHead');\n\t\t\t\t\t\t\tfor (const id of ids) {\n\t\t\t\t\t\t\t\tmovedWorktrees.add(id);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\n\t\t\t\t\tconst match = worktreeHeadRegex.exec(path);\n\t\t\t\t\tif (match != null) {\n\t\t\t\t\t\tadd('worktrees', 'worktreeHead');\n\t\t\t\t\t\tmovedWorktrees.add(match[1]);\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tconst kinds = classifyGitDirChange(path);\n\t\t\t\tif (kinds != null) {\n\t\t\t\t\tadd(...kinds);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// A worktree ignored or no longer: it left the worktree list or joined it, as an entry removed or added would\n\t\tfor (const id of this.flippedWorktrees) {\n\t\t\tadd('worktrees', 'worktreeHead');\n\t\t\tmovedWorktrees.add(id);\n\t\t}\n\n\t\treturn { changes: changes, movedWorktrees: anyWorktreeMoved ? undefined : movedWorktrees };\n\t}\n}\n\n/** A gate's own move reports nothing: the git dir itself, or a linked worktree's admin entry */\nfunction isGatePath(path: string): boolean {\n\tif (path === gitDirGatePath) return true;\n\n\tconst entry = parseWorktreeAdminPath(path);\n\treturn entry != null && entry.file == null;\n}\n\n/** A component of the path is a file: Node's error, or the one VS Code's file system raises */\nfunction isNotADirectory(ex: unknown): boolean {\n\tconst code = (ex as { code?: unknown } | undefined)?.code;\n\treturn code === 'ENOTDIR' || code === 'FileNotADirectory';\n}\n"],"mappings":";;;;;;;;;;;AAkBA,MAAM,aAAwB;CAAE,OAAO;CAAI,MAAM;AAAG;;;;;AA+CpD,MAAM,qBAAA;;;;;AAKN,MAAM,sBAAsB;;AAE5B,MAAM,aAAa;;AAEnB,MAAM,oBAAoB;;;;;;;AAO1B,MAAM,oBAAoB;;AAE1B,MAAM,kBAAkB,aAAa;;AAErC,MAAM,6BAA6B;;AAEnC,MAAM,yBAAyB,KAAK,KAAK;;;;;;AAMzC,MAAM,oBAAoB;AAC1B,MAAM,aAAa;AACnB,MAAM,sBAAsB;AAE5B,MAAM,gBAAmC;CAAC;CAAc;CAAgB;AAAW;AACnF,MAAM,oBAAoB;AAC1B,MAAM,oBAAoB;;;;;;;;;;AAW1B,MAAM,iBAAiB;AACvB,MAAM,iCAAsC,IAAI,IAAI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,aAAa;MACjB;KACD;KAGA,IAAI,SAAS,aAAa;MACzB,MAAM,MAAM,KAAK,2BAA2B;MAC5C,IAAI,OAAO,MAAM;OAChB,IAAI,aAAa,cAAc;OAC/B,mBAAmB;MACpB,OAAO,IAAI,IAAI,QAAQ;OACtB,IAAI,aAAa,cAAc;OAC/B,KAAK,MAAM,MAAM,KAChB,eAAe,IAAI,EAAE;MAEvB;MACA;KACD;KAEA,MAAM,QAAQ,kBAAkB,KAAK,IAAI;KACzC,IAAI,SAAS,MAAM;MAClB,IAAI,aAAa,cAAc;MAC/B,eAAe,IAAI,MAAM,EAAE;MAC3B;KACD;IACD;IAEA,MAAM,QAAQ,qBAAqB,IAAI;IACvC,IAAI,SAAS,MACZ,IAAI,GAAG,KAAK;GAEd;EACD;EAGA,KAAK,MAAM,MAAM,KAAK,kBAAkB;GACvC,IAAI,aAAa,cAAc;GAC/B,eAAe,IAAI,EAAE;EACtB;EAEA,OAAO;GAAW;GAAS,gBAAgB,mBAAmB,KAAA,IAAY;EAAe;CAC1F;AACD;;AAGA,SAAS,WAAW,MAAuB;CAC1C,IAAI,SAAS,gBAAgB,OAAO;CAEpC,MAAM,QAAQ,uBAAuB,IAAI;CACzC,OAAO,SAAS,QAAQ,MAAM,QAAQ;AACvC;;AAGA,SAAS,gBAAgB,IAAsB;CAC9C,MAAM,OAAQ,IAAuC;CACrD,OAAO,SAAS,aAAa,SAAS;AACvC"}
@@ -272,5 +272,7 @@ export declare class WatchGroup implements UnifiedDisposable {
272
272
  */
273
273
  private deliverConfigChange;
274
274
  }
275
+ /** The path doesn't exist: Node's error, or the one VS Code's file system raises */
276
+ export declare function isNotFound(ex: unknown): boolean;
275
277
  //#endregion
276
278
  //# sourceMappingURL=watchGroup.d.ts.map
@@ -1,6 +1,6 @@
1
1
  import { some } from "../../utils/iterable.js";
2
- import { dirname, isAbsolute, isDescendant, joinPaths, normalizePath, relative } from "../../utils/path.js";
3
- import { getWorktreeAdminId, parseWorktreeAdminPath } from "../utils/repository.utils.js";
2
+ import { isDescendant, joinPaths, normalizePath, relative } from "../../utils/path.js";
3
+ import { getWorktreeAdminId, isIgnoredWorktreeEntry, parseWorktreeAdminPath } from "../utils/repository.utils.js";
4
4
  import { FileType } from "../context.js";
5
5
  import { GitDirProbeTarget } from "./gitDirPoller.js";
6
6
  import { dotGitGlobCombined, dotGitGlobCommon, dotGitGlobRoot, getGitDirRefProbes, getIgnoredWorktreeFolderExcludes, gitDirCommonProbes, gitDirExcludes, gitDirProbesByEmittedPath, gitDirRootProbes, shouldIgnoreRepoPath } from "./watcherPatterns.js";
@@ -579,11 +579,7 @@ var WatchGroup = class {
579
579
  async readIgnoredWorktree(id) {
580
580
  const adminDir = joinPaths(this.commonGitDir, "worktrees", id);
581
581
  const content = await this.readWithTimeout(joinPaths(adminDir, "gitdir"));
582
- const dotGit = content != null ? new TextDecoder().decode(content).trim() : "";
583
- const dotGitPath = dotGit ? normalizePath(isAbsolute(dotGit) ? dotGit : joinPaths(adminDir, dotGit)) : "";
584
- if (!dotGitPath.endsWith("/.git")) return void 0;
585
- const worktreePath = dirname(dotGitPath);
586
- return this._ignoredWorktreeRoots.some((root) => isDescendant(worktreePath, root));
582
+ return isIgnoredWorktreeEntry(adminDir, content, this._ignoredWorktreeRoots);
587
583
  }
588
584
  queueWorktreesBaseline(take) {
589
585
  this._worktreesBaselining = true;
@@ -801,6 +797,6 @@ function getChangedRef(relativePath) {
801
797
  return ref.startsWith("refs/") || ref === "HEAD" || ref === "ORIG_HEAD" ? ref : void 0;
802
798
  }
803
799
  //#endregion
804
- export { WatchGroup };
800
+ export { WatchGroup, isNotFound };
805
801
 
806
802
  //# sourceMappingURL=watchGroup.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"watchGroup.js","names":[],"sources":["../../../../git/src/watching/watchGroup.ts"],"sourcesContent":["import type { UnifiedDisposable } from '@gitlens/utils/disposable.js';\nimport { some } from '@gitlens/utils/iterable.js';\nimport { dirname, isAbsolute, isDescendant, joinPaths, normalizePath, relative } from '@gitlens/utils/path.js';\nimport { FileType } from '../context.js';\nimport type { GitDir, RepositoryChange } from '../models/repository.js';\nimport { getWorktreeAdminId, parseWorktreeAdminPath } from '../utils/repository.utils.js';\nimport { allWatchedRepositoryChanges, classifyGitDirChange } from './classifyChange.js';\nimport type { GitConfigSections, GitConfigSectionsChange } from './configSections.js';\nimport { diffGitConfigSections, parseGitConfigBytes } from './configSections.js';\nimport type { GitDirPoller, GitDirProbe } from './gitDirPoller.js';\nimport { GitDirProbeTarget } from './gitDirPoller.js';\nimport type {\n\tFileWatcher,\n\tFileWatcherOptions,\n\tFileWatcherReliability,\n\tFileWatchEvent,\n\tFileWatchingProvider,\n} from './provider.js';\nimport {\n\tdotGitGlobCombined,\n\tdotGitGlobCommon,\n\tdotGitGlobRoot,\n\tgetGitDirRefProbes,\n\tgetIgnoredWorktreeFolderExcludes,\n\tgitDirCommonProbes,\n\tgitDirExcludes,\n\tgitDirProbesByEmittedPath,\n\tgitDirRootProbes,\n\tshouldIgnoreRepoPath,\n} from './watcherPatterns.js';\n\n/**\n * How long a read of the shared `.git/config`, or of the worktrees' admin entries, may take before it counts as failed.\n * Reads of each run one at a time, so one that never settles, as on a hung network or WSL mount, would otherwise hold\n * back every later report.\n */\nconst readTimeoutMs = 5000;\n\n/**\n * How many removed admin entries are remembered. Each watcher reports a removal once for each file it watched in the\n * entry, and two watchers see the common dir beside a main checkout, so its reports outlive any single one of them\n */\nconst removedWorktreeIdsLimit = 64;\n\n/**\n * How long after an admin entry's `gitdir` couldn't be read it is read once more. A watcher can report the entry before\n * git wrote its `gitdir`, and then miss the write itself (a new directory's files go unseen until it is watched)\n */\nconst worktreeRetryDelayMs = 250;\n\nfunction noop(): void {}\n\n/**\n * Hooks that the WatchGroup fires when events are interpreted.\n * These are raw, un-debounced events — the session handles debouncing.\n */\nexport interface WatchGroupHooks {\n\t/**\n\t * `ref` is the full ref name (or ref directory) or pseudo-ref (`HEAD`, `ORIG_HEAD`) whose file changed, with a\n\t * trailing `.lock` stripped; `false` when config changed without moving refs, and `undefined` when ref movement\n\t * is unknown. `overflow` marks the every-kind rescan of a watcher that dropped events, which no single write can\n\t * account for. `configBranches`, with a `config` change, are the local branches (full ref names) whose\n\t * `branch.<name>` sections are all that changed in the shared `.git/config`; without it, the config change may be\n\t * anywhere. `movedWorktree`, with a `worktreeHead` change, is the admin id (the `<id>` of `worktrees/<id>`) of the\n\t * linked worktree whose `HEAD` file changed, or whose admin entry was created or removed; without it, any linked\n\t * worktree's HEAD may have moved.\n\t */\n\treadonly onRepoChanged: (\n\t\trepoPath: string,\n\t\tchanges: RepositoryChange[],\n\t\tref?: string | false,\n\t\toverflow?: boolean,\n\t\tconfigBranches?: ReadonlySet<string>,\n\t\tmovedWorktree?: string,\n\t) => void;\n\treadonly onFetchHeadChanged?: (repoPath: string) => void;\n\treadonly onIgnoresChanged?: (repoPath: string) => void;\n\t/** The refs whose loose files a poll stats for this session, read at each poll */\n\treadonly getProbeRefs?: () => Iterable<string>;\n\t/** A watcher this session hears through went `unwatchable`, or stopped being it (see {@link WatchGroup.isUnwatchable}) */\n\treadonly onUnwatchableChanged?: (repoPath: string) => void;\n}\n\n/**\n * Tracks one session's connection to a WatchGroup.\n * Each session has its own root watcher but shares the common watcher.\n */\ninterface SessionEntry {\n\treadonly repoPath: string;\n\treadonly gitDirPath: string;\n\treadonly rootWatcher: FileWatcher;\n\t/** True when the root watcher is on the common dir itself, so it already sees every common file */\n\treadonly coversCommon: boolean;\n\t/** For a linked session, its `<n>` in `<common>/worktrees/<n>`; otherwise `undefined` */\n\treadonly worktreeId: string | undefined;\n\treadonly hooks: WatchGroupHooks;\n\treliability: FileWatcherReliability;\n\t/** Polls in place of (or beside) the root watcher while it isn't `reliable` */\n\ttarget?: GitDirProbeTarget;\n}\n\n/**\n * Manages filesystem watchers for a single physical `.git` directory,\n * shared across all worktrees that reference it.\n *\n * Structure:\n * - 1 common watcher: config, refs/**, info/exclude, etc. Delivers to linked sessions only; a\n * session rooted at the common dir hears the same files from its own combined root watcher.\n * - N root watchers: one per worktree (index, HEAD, *_HEAD, etc.)\n *\n * For a standard (non-worktree) repo, the common and root directories\n * are the same, but we still create separate watchers for clean separation.\n *\n * Given a `readFile`, the group keeps the shared `.git/config` as it last read it, section by section. A report of\n * that file (or its lock), from whichever watcher, is read and compared with it once, and every session hears what\n * changed: only some branches' `branch.<name>` sections (`config`, confined to them), anything else (`config` and\n * `remotes`, unconfined), or nothing at all, when an earlier report's read already delivered the change. Reads run\n * one at a time, so each compares with the one before it and none is skipped. The first read, taken as the group\n * starts, is the baseline and delivers nothing; a report arriving before it completes may describe a change it\n * already holds, so it is delivered unconfined. A read that fails or doesn't settle within a few seconds, or a file\n * git couldn't parse, is unconfined too.\n *\n * Given a `readFile`, a `readDirectory` (a directory's entries with their types, only the directories counting as\n * admin entries) and the folders whose worktrees the host has core ignore (a tool's throwaway worktrees, which no\n * host shows), the group reports no change of an ignored worktree's admin entry\n * (`<common>/worktrees/<id>`) to any session. Only registered folders count, since a user may keep real worktrees\n * anywhere, `.git` included. It lists the entries and reads each one's `gitdir` once as it starts, and again after a\n * watcher dropped events; a report arriving meanwhile is told at once, and decided once the listing settles, so what\n * is known of its entry catches up. From then on it reads an entry only when its `gitdir` may be new (the entry was\n * created, or its `gitdir` written, or it was removed before), so a real worktree's HEAD moves are told at once,\n * unread. Of two reads of one entry, the later decides both reports. An entry it doesn't know whose `gitdir` can't be\n * read (a watcher can report one before git writes it, and miss the write) is read once more a moment later, its\n * reports held until then, and told if it still can't be. Only the entry's directory or its `gitdir` going is a\n * removal; a deleted `HEAD` (a watcher may report git's lock file renamed over it as a delete) or `locked` is told as\n * the entry is known. Removing an entry deletes the `gitdir` a read needs, so a removal is told from what the entry was\n * known to be (before a read that couldn't read it, if one is waiting to read it again), and an entry it never knew is\n * told as real. Any other report of a removed entry but a delete is read, and one that can't be read is the removal's\n * own (a watcher may report the entry's directory changed beside each file it deletes), unless it creates the entry\n * again. A report of the `worktrees` directory itself (a coalesced\n * removal, a parent directory change, a poll, which sees nothing finer) lists it again: it is told to every session\n * when a real entry was added or removed since the last listing, and to none when only ignored ones were. Git removes\n * the directory with its last entry, so a directory that isn't there is an empty listing, as is a removal of it that\n * can't be listed. Since a listing (or a worktree moved into or out of a folder) changes what every session shows, it\n * is told to all of them; the other watcher's report of the same change then finds nothing left to tell. Where only a\n * poll watches the common dir, it sees just the `worktrees` directory, so an entry removed and added again under the\n * same id between two polls, or an entry's HEAD or lock changed in place, goes untold.\n *\n * Given the folders, the watchers over the common dir leave each one unwatched, since a tool's checkout there would\n * otherwise have every directory of it watched; one that shares a top-level directory with what the `.git` watch reads\n * stays watched.\n */\nexport class WatchGroup implements UnifiedDisposable {\n\tprivate readonly _sessions = new Map<string, SessionEntry>();\n\tprivate _commonWatcher: FileWatcher | undefined;\n\tprivate _commonReliability: FileWatcherReliability = 'reliable';\n\tprivate _commonTarget: GitDirProbeTarget | undefined;\n\tprivate _disposed = false;\n\n\t/** The shared `.git/config`, by section, as the last read that could parse it found it */\n\tprivate _config: GitConfigSections | undefined;\n\t/** The baseline read is in flight */\n\tprivate _configBaselining = false;\n\tprivate _configReading = false;\n\tprivate _configRereadQueued = false;\n\n\t/**\n\t * Settles once the latest baseline of the admin entries was taken; `undefined` when the group can't tell an\n\t * ignored worktree's, so every report is told at once\n\t */\n\tprivate _worktreesBaseline: Promise<void> | undefined;\n\t/** A baseline is pending, so a report waits for it */\n\tprivate _worktreesBaselining = false;\n\tprivate _worktreesRebaselineQueued = false;\n\t/** Set by the first baseline; while empty, nothing is ignored and every report is told at once */\n\tprivate _ignoredWorktreeRoots: readonly string[] = [];\n\t/** Listings run one at a time, so each compares with the one before it */\n\tprivate _worktreesQueue: Promise<void> = Promise.resolve();\n\t/** The `worktrees` directory's reports waiting on the queued listing; `undefined` while none is queued */\n\tprivate _worktreesRescanQueued:\n\t\t| {\n\t\t\t\treadonly delivers: (() => void)[];\n\t\t\t\t/** One of them is a removal of the directory */\n\t\t\t\tremoval: boolean;\n\t\t }\n\t\t| undefined;\n\t/** The admin entries the last listing found */\n\tprivate _listedWorktreeIds: ReadonlySet<string> = new Set();\n\t/** Admin entries known to exist, by id: whether each is an ignored worktree's */\n\tprivate readonly _worktreeIds = new Map<string, boolean>();\n\t/** What removed admin entries were, by id, oldest first */\n\tprivate readonly _removedWorktreeIds = new Map<string, boolean>();\n\t/**\n\t * Each id's latest `gitdir` read, settling with what it found and what the id was known to be before it; only it\n\t * may update what is known of the id. A removal of the entry drops it\n\t */\n\tprivate readonly _worktreeReads = new Map<\n\t\tstring,\n\t\tPromise<[ignored: boolean | undefined, previous: boolean | undefined]>\n\t>();\n\t/** Admin entries whose `gitdir` couldn't be read, by id, waiting to be read once more */\n\tprivate readonly _worktreeRetries = new Map<\n\t\tstring,\n\t\t{\n\t\t\treadonly timer: ReturnType<typeof setTimeout>;\n\t\t\t/** The reports waiting on it, told unless the entry turns out to be an ignored worktree's */\n\t\t\treadonly delivers: (() => void)[];\n\t\t\t/**\n\t\t\t * What the entry was known to be before its `gitdir` couldn't be read, so a move or a removal is still told\n\t\t\t * as it was\n\t\t\t */\n\t\t\tprevious: boolean | undefined;\n\t\t\t/**\n\t\t\t * Settles with whether the entry is an ignored worktree's; `undefined` when it still can't tell, or it was\n\t\t\t * removed\n\t\t\t */\n\t\t\treadonly decided: Promise<boolean | undefined>;\n\t\t\treadonly resolve: (ignored: boolean | undefined) => void;\n\t\t}\n\t>();\n\t/** The `.git` excludes of a watcher over the common git dir, with the ignored worktrees' folders it may leave out */\n\tprivate readonly _commonGitDirExcludes: readonly string[];\n\n\tconstructor(\n\t\treadonly commonGitDir: string,\n\t\tprivate readonly provider: FileWatchingProvider,\n\t\t/** When given, a watcher that reports it can't be trusted is polled; otherwise none is asked */\n\t\tprivate readonly poller?: GitDirPoller,\n\t\t/**\n\t\t * When given, reports of the shared `.git/config` are classified by what changed in it, and admin entries are\n\t\t * read to tell an ignored worktree's (see above)\n\t\t */\n\t\tprivate readonly readFile?: (path: string) => Promise<Uint8Array>,\n\t\t/**\n\t\t * Returns a directory's entries with their types; with `readFile`, the admin entries are listed, only the\n\t\t * directories counting (see above)\n\t\t */\n\t\tprivate readonly readDirectory?: (path: string) => Promise<readonly (readonly [string, number])[]>,\n\t\t/** The absolute, normalized folders whose worktrees are ignored; none reads no admin entry */\n\t\tignoredWorktreeRoots?: Promise<readonly string[]>,\n\t\t/** The folders whose worktrees are ignored, relative to the common git dir */\n\t\tignoredWorktreeFolders?: readonly string[],\n\t) {\n\t\tconst folders = getIgnoredWorktreeFolderExcludes(ignoredWorktreeFolders);\n\t\tthis._commonGitDirExcludes = folders.length ? [...gitDirExcludes, ...folders] : gitDirExcludes;\n\t\tif (readFile != null) {\n\t\t\tvoid this.readConfigBaseline();\n\t\t}\n\t\tif (readFile != null && readDirectory != null && ignoredWorktreeRoots != null) {\n\t\t\tthis.queueWorktreesBaseline(async () => {\n\t\t\t\tconst roots = await this.withTimeout(() => Promise.resolve(ignoredWorktreeRoots));\n\t\t\t\tif (this._disposed || !Array.isArray(roots) || !roots.length) return;\n\n\t\t\t\tthis._ignoredWorktreeRoots = roots;\n\t\t\t\tawait this.listWorktrees('baseline');\n\t\t\t});\n\t\t}\n\t}\n\n\t[Symbol.dispose](): void {\n\t\tthis.dispose();\n\t}\n\n\t/** Dispose the entire group (common watcher + all root watchers). */\n\tdispose(): void {\n\t\tif (this._disposed) return;\n\n\t\tthis._disposed = true;\n\n\t\tfor (const entry of this._sessions.values()) {\n\t\t\tentry.rootWatcher.dispose();\n\t\t\tthis.stopPolling(entry);\n\t\t}\n\t\tthis._sessions.clear();\n\n\t\tthis.disposeCommonWatcher();\n\n\t\tfor (const retry of this._worktreeRetries.values()) {\n\t\t\tclearTimeout(retry.timer);\n\t\t\tretry.resolve(undefined);\n\t\t}\n\t\tthis._worktreeRetries.clear();\n\t}\n\n\tget sessions(): ReadonlyMap<string, SessionEntry> {\n\t\treturn this._sessions;\n\t}\n\n\t/** True when a watcher the session hears through — its root watcher, or a linked session's common one — can't watch */\n\tisUnwatchable(repoPath: string): boolean {\n\t\tconst entry = this._sessions.get(repoPath);\n\t\tif (entry == null) return false;\n\n\t\treturn (\n\t\t\tentry.reliability === 'unwatchable' || (!entry.coversCommon && this._commonReliability === 'unwatchable')\n\t\t);\n\t}\n\n\t/** Add a session to this group. Creates the root watcher for the session's gitDir. */\n\taddSession(repoPath: string, gitDir: GitDir, hooks: WatchGroupHooks): void {\n\t\tif (this._disposed) return;\n\t\tif (this._sessions.has(repoPath)) return; // Already tracked\n\n\t\t// Determine the glob pattern for the root watcher\n\t\tconst isStandard = gitDir.commonUri == null;\n\t\tconst rootPattern = isStandard ? dotGitGlobCombined : dotGitGlobRoot;\n\n\t\t// The watcher can report its reliability before `createWatcher` returns, so before the entry exists\n\t\tlet entry: SessionEntry | undefined;\n\t\tlet initialReliability: FileWatcherReliability = 'reliable';\n\n\t\tconst rootWatcher = this.provider.createWatcher(\n\t\t\tgitDir.uri.fsPath,\n\t\t\trootPattern,\n\t\t\t(event: FileWatchEvent) => {\n\t\t\t\tconst e = this._sessions.get(repoPath);\n\t\t\t\tif (e != null) {\n\t\t\t\t\tif (event.reason !== 'overflow') {\n\t\t\t\t\t\te.target?.forget(event.path);\n\t\t\t\t\t}\n\t\t\t\t\tthis.onRootEvent(event, e);\n\t\t\t\t}\n\t\t\t},\n\t\t\tthis.getWatcherOptions(gitDir.uri.fsPath, state => {\n\t\t\t\tif (entry == null) {\n\t\t\t\t\tinitialReliability = state;\n\t\t\t\t} else if (this._sessions.get(repoPath) === entry) {\n\t\t\t\t\tthis.setRootReliability(entry, state);\n\t\t\t\t}\n\t\t\t}),\n\t\t);\n\n\t\tconst entryGitDirPath = gitDir.uri.fsPath;\n\t\tentry = {\n\t\t\trepoPath: repoPath,\n\t\t\tgitDirPath: entryGitDirPath,\n\t\t\trootWatcher: rootWatcher,\n\t\t\tcoversCommon: isStandard,\n\t\t\tworktreeId: isStandard ? undefined : this.getWorktreeId(entryGitDirPath),\n\t\t\thooks: hooks,\n\t\t\treliability: 'reliable',\n\t\t};\n\n\t\tthis._sessions.set(repoPath, entry);\n\t\tif (initialReliability !== 'reliable') {\n\t\t\tthis.setRootReliability(entry, initialReliability, true);\n\t\t}\n\n\t\t// Start the common watcher if this is a worktree repo and we haven't yet.\n\t\t// Standard repos don't need a separate common watcher because their root\n\t\t// watcher uses dotGitGlobCombined which already covers all patterns.\n\t\tif (!isStandard) {\n\t\t\tthis.ensureCommonWatcher();\n\t\t}\n\t}\n\n\t/** Remove a session from this group. Disposes its root watcher. */\n\tremoveSession(repoPath: string): void {\n\t\tconst entry = this._sessions.get(repoPath);\n\t\tif (entry == null) return;\n\n\t\tentry.rootWatcher.dispose();\n\t\tthis.stopPolling(entry);\n\t\tthis._sessions.delete(repoPath);\n\n\t\t// Once no linked session is left, dispose the common watcher — it delivers to linked sessions only\n\t\tif (this._commonWatcher != null && !some(this._sessions.values(), e => !e.coversCommon)) {\n\t\t\tthis.disposeCommonWatcher();\n\t\t}\n\t}\n\n\tprivate getWorktreeId(gitDirPath: string): string | undefined {\n\t\treturn getWorktreeAdminId(gitDirPath, this.commonGitDir);\n\t}\n\n\tprivate ensureCommonWatcher(): void {\n\t\tif (this._commonWatcher != null || this._disposed) return;\n\n\t\t// The watcher can report its reliability before `createWatcher` returns\n\t\tlet watcher: FileWatcher | undefined;\n\t\tlet initialReliability: FileWatcherReliability = 'reliable';\n\t\tconst options = this.getWatcherOptions(this.commonGitDir, state => {\n\t\t\tif (watcher == null) {\n\t\t\t\tinitialReliability = state;\n\t\t\t} else if (this._commonWatcher === watcher) {\n\t\t\t\tthis.setCommonReliability(state);\n\t\t\t}\n\t\t});\n\n\t\twatcher = this.provider.createWatcher(\n\t\t\tthis.commonGitDir,\n\t\t\tdotGitGlobCommon,\n\t\t\t(event: FileWatchEvent) => {\n\t\t\t\tif (event.reason !== 'overflow') {\n\t\t\t\t\tthis._commonTarget?.forget(event.path);\n\t\t\t\t}\n\t\t\t\tthis.onCommonEvent(event);\n\t\t\t},\n\t\t\toptions,\n\t\t);\n\t\tthis._commonWatcher = watcher;\n\t\tif (initialReliability !== 'reliable') {\n\t\t\tthis.setCommonReliability(initialReliability, true);\n\t\t}\n\t}\n\n\tprivate disposeCommonWatcher(): void {\n\t\tthis._commonWatcher?.dispose();\n\t\tthis._commonWatcher = undefined;\n\t\tthis._commonReliability = 'reliable';\n\t\tif (this._commonTarget != null) {\n\t\t\tthis.poller?.delete(this._commonTarget);\n\t\t\tthis._commonTarget = undefined;\n\t\t}\n\t}\n\n\t/** Hosts that didn't opt into polling get exactly the options they always had */\n\tprivate getWatcherOptions(\n\t\tbasePath: string,\n\t\tonDidChangeReliability: (state: FileWatcherReliability) => void,\n\t): FileWatcherOptions {\n\t\tconst excludes = this.getExcludes(basePath);\n\t\treturn this.poller != null\n\t\t\t? { excludes: excludes, onDidChangeReliability: onDidChangeReliability }\n\t\t\t: { excludes: excludes };\n\t}\n\n\t/**\n\t * The ignored worktrees' folders join the `.git` excludes of a watcher over the common git dir: a tool that keeps its\n\t * throwaway checkouts inside the git dir would otherwise have each one's every directory watched, and every file it\n\t * writes reported. Every other watcher sits on a linked worktree's admin entry, which holds none of them\n\t */\n\tprivate getExcludes(basePath: string): readonly string[] {\n\t\tif (this._commonGitDirExcludes === gitDirExcludes) return gitDirExcludes;\n\n\t\treturn normalizePath(basePath) === normalizePath(this.commonGitDir)\n\t\t\t? this._commonGitDirExcludes\n\t\t\t: gitDirExcludes;\n\t}\n\n\tprivate setRootReliability(entry: SessionEntry, state: FileWatcherReliability, initial?: boolean): void {\n\t\tconst previous = entry.reliability;\n\t\tif (previous === state || this.poller == null) return;\n\n\t\tentry.reliability = state;\n\t\tif (state === 'reliable') {\n\t\t\tthis.stopPolling(entry);\n\t\t} else if (entry.target == null) {\n\t\t\tconst target = new GitDirProbeTarget(\n\t\t\t\tentry.gitDirPath,\n\t\t\t\tthis.poller,\n\t\t\t\t() => this.getRootProbes(entry),\n\t\t\t\tgitDirProbesByEmittedPath,\n\t\t\t\t(event, probe) => {\n\t\t\t\t\tif (entry.target !== target) return;\n\n\t\t\t\t\tthis.onRootEvent(event, entry);\n\t\t\t\t\tif (probe.path === 'logs/HEAD' && !entry.coversCommon) {\n\t\t\t\t\t\tthis.onLinkedHeadMoved();\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t);\n\t\t\tentry.target = target;\n\t\t\tthis.poller.add(target);\n\t\t}\n\n\t\tif ((state === 'unwatchable') === (previous === 'unwatchable')) return;\n\n\t\t// The watch went down or came back: whatever changed meanwhile went unseen\n\t\tif (!initial) {\n\t\t\tthis.deliverOverflow(entry);\n\t\t\tif (entry.coversCommon) {\n\t\t\t\tthis.rebaselineWorktrees();\n\t\t\t}\n\t\t}\n\t\tentry.hooks.onUnwatchableChanged?.(entry.repoPath);\n\t}\n\n\tprivate setCommonReliability(state: FileWatcherReliability, initial?: boolean): void {\n\t\tconst previous = this._commonReliability;\n\t\tif (previous === state || this.poller == null) return;\n\n\t\tthis._commonReliability = state;\n\t\tif (state === 'reliable') {\n\t\t\tif (this._commonTarget != null) {\n\t\t\t\tthis.poller.delete(this._commonTarget);\n\t\t\t\tthis._commonTarget = undefined;\n\t\t\t}\n\t\t} else if (this._commonTarget == null) {\n\t\t\tconst target = new GitDirProbeTarget(\n\t\t\t\tthis.commonGitDir,\n\t\t\t\tthis.poller,\n\t\t\t\t() => this.getCommonProbes(),\n\t\t\t\tgitDirProbesByEmittedPath,\n\t\t\t\tevent => {\n\t\t\t\t\tif (this._commonTarget === target) {\n\t\t\t\t\t\tthis.onCommonEvent(event);\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t);\n\t\t\tthis._commonTarget = target;\n\t\t\tthis.poller.add(target);\n\t\t}\n\n\t\tif ((state === 'unwatchable') === (previous === 'unwatchable')) return;\n\n\t\tfor (const entry of this._sessions.values()) {\n\t\t\tif (entry.coversCommon) continue;\n\n\t\t\tif (!initial) {\n\t\t\t\tthis.deliverOverflow(entry);\n\t\t\t}\n\t\t\tentry.hooks.onUnwatchableChanged?.(entry.repoPath);\n\t\t}\n\t\tif (!initial) {\n\t\t\tthis.rebaselineWorktrees();\n\t\t}\n\t}\n\n\tprivate stopPolling(entry: SessionEntry): void {\n\t\tif (entry.target == null) return;\n\n\t\tthis.poller?.delete(entry.target);\n\t\tentry.target = undefined;\n\t}\n\n\t/**\n\t * A session rooted at the common dir polls the common files too, with the refs of every session in the group: its\n\t * combined watcher would hear them all. While the common dir is polled too, the poller stats each shared file once\n\t * for both, and each keeps its own readings, so what one watcher reported is held back from its own sessions only\n\t */\n\tprivate getRootProbes(entry: SessionEntry): readonly GitDirProbe[] {\n\t\tif (!entry.coversCommon) return gitDirRootProbes;\n\n\t\tconst refs = new Set<string>();\n\t\tfor (const e of this._sessions.values()) {\n\t\t\tfor (const ref of e.hooks.getProbeRefs?.() ?? []) {\n\t\t\t\trefs.add(ref);\n\t\t\t}\n\t\t}\n\t\treturn [...gitDirRootProbes, ...gitDirCommonProbes, ...getGitDirRefProbes(refs)];\n\t}\n\n\t/**\n\t * A linked worktree's `logs/HEAD` moved — a commit or reset there, on a branch a polled session rooted at the common\n\t * dir may not probe — so each such session hears a `heads` change its combined watcher would have heard\n\t */\n\tprivate onLinkedHeadMoved(): void {\n\t\tfor (const entry of this._sessions.values()) {\n\t\t\tif (!entry.coversCommon || entry.target == null) continue;\n\n\t\t\tentry.hooks.onRepoChanged(entry.repoPath, ['heads']);\n\t\t}\n\t}\n\n\t/** The common files, with the refs of every linked session (the only ones the common watcher delivers to) */\n\tprivate getCommonProbes(): GitDirProbe[] {\n\t\tconst refs = new Set<string>();\n\t\tfor (const entry of this._sessions.values()) {\n\t\t\tif (entry.coversCommon) continue;\n\n\t\t\tfor (const ref of entry.hooks.getProbeRefs?.() ?? []) {\n\t\t\t\trefs.add(ref);\n\t\t\t}\n\t\t}\n\t\treturn [...gitDirCommonProbes, ...getGitDirRefProbes(refs)];\n\t}\n\n\tprivate onCommonEvent(event: FileWatchEvent): void {\n\t\tif (event.reason === 'overflow') {\n\t\t\tfor (const entry of this._sessions.values()) {\n\t\t\t\tif (entry.coversCommon) continue;\n\n\t\t\t\tthis.deliverOverflow(entry);\n\t\t\t}\n\t\t\tthis.rebaselineWorktrees();\n\t\t\treturn;\n\t\t}\n\n\t\t// Compute relative path from common git dir\n\t\tif (!isDescendant(event.path, this.commonGitDir)) return;\n\n\t\tconst relativePath = relative(this.commonGitDir, event.path);\n\t\tif (shouldIgnoreRepoPath(relativePath)) return;\n\n\t\tif (this.readFile != null && isConfigFile(relativePath)) {\n\t\t\tthis.onConfigReported();\n\t\t\treturn;\n\t\t}\n\n\t\tconst isFetchHead = relativePath === 'FETCH_HEAD';\n\t\tconst isExclude = relativePath === 'info/exclude';\n\t\tconst changes = isFetchHead\n\t\t\t? undefined\n\t\t\t: withWorktreeEntryHead(classifyGitDirChange(relativePath), relativePath, event.reason);\n\t\tif (changes == null && !isFetchHead && !isExclude) return;\n\n\t\tconst ref = changes != null ? getChangedRef(relativePath) : undefined;\n\n\t\t// `worktrees/<n>/HEAD`: the owner hears its own HEAD from its root watcher. Its `locked` and `gitdir` aren't in\n\t\t// the root glob, so the owner hears those only from here\n\t\tconst ownerId = changes != null ? getMovedWorktreeId(relativePath) : undefined;\n\t\tconst movedWorktree = getReportedWorktreeId(relativePath, changes);\n\n\t\tif (changes != null && this.isWorktreesReport(changes)) {\n\t\t\tconst sessions = [...this._sessions.values()].filter(\n\t\t\t\te => !e.coversCommon && (ownerId == null || e.worktreeId !== ownerId),\n\t\t\t);\n\t\t\tthis.onWorktreesReported(relativePath, event.reason, () => {\n\t\t\t\tfor (const entry of sessions) {\n\t\t\t\t\tif (this._disposed || this._sessions.get(entry.repoPath) !== entry) continue;\n\n\t\t\t\t\tdeliverRepoChanged(entry, changes, ref, movedWorktree);\n\t\t\t\t}\n\t\t\t});\n\t\t\treturn;\n\t\t}\n\n\t\tfor (const entry of this._sessions.values()) {\n\t\t\t// A session rooted at the common dir sees every common file (hooks included) through its own\n\t\t\t// combined root watcher, so delivering here too would duplicate it\n\t\t\tif (entry.coversCommon) continue;\n\n\t\t\tif (isFetchHead) {\n\t\t\t\t// FETCH_HEAD lives in the main .git dir; each worktree updates its last-fetched state\n\t\t\t\tentry.hooks.onFetchHeadChanged?.(entry.repoPath);\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tif (changes != null && (ownerId == null || entry.worktreeId !== ownerId)) {\n\t\t\t\tdeliverRepoChanged(entry, changes, ref, movedWorktree);\n\t\t\t}\n\n\t\t\tif (isExclude) {\n\t\t\t\tentry.hooks.onIgnoresChanged?.(entry.repoPath);\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate deliverOverflow(entry: SessionEntry): void {\n\t\t// Every kind, no ref (ref kinds stay unnamed). Never `'unknown'` — the cache would unregister the path\n\t\tentry.hooks.onRepoChanged(entry.repoPath, [...allWatchedRepositoryChanges], undefined, true);\n\t\tentry.hooks.onFetchHeadChanged?.(entry.repoPath);\n\t\tentry.hooks.onIgnoresChanged?.(entry.repoPath);\n\t}\n\n\tprivate onRootEvent(event: FileWatchEvent, entry: SessionEntry): void {\n\t\tif (event.reason === 'overflow') {\n\t\t\tthis.deliverOverflow(entry);\n\t\t\tif (entry.coversCommon) {\n\t\t\t\tthis.rebaselineWorktrees();\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\tif (!isDescendant(event.path, entry.gitDirPath)) return;\n\n\t\tconst relativePath = relative(entry.gitDirPath, event.path);\n\t\tif (shouldIgnoreRepoPath(relativePath)) return;\n\n\t\t// Check for FETCH_HEAD before interpretation\n\t\tif (relativePath === 'FETCH_HEAD') {\n\t\t\tentry.hooks.onFetchHeadChanged?.(entry.repoPath);\n\t\t\treturn;\n\t\t}\n\n\t\t// A linked worktree's git dir isn't the common one, so no file there is the shared config\n\t\tif (entry.coversCommon && this.readFile != null && isConfigFile(relativePath)) {\n\t\t\tthis.onConfigReported();\n\t\t\treturn;\n\t\t}\n\n\t\tconst changes = withWorktreeEntryHead(classifyGitDirChange(relativePath), relativePath, event.reason);\n\t\t// A linked worktree's git dir isn't the common one, so no path there is a worktree's admin entry\n\t\tconst movedWorktree = entry.coversCommon ? getReportedWorktreeId(relativePath, changes) : undefined;\n\t\tif (changes != null && entry.coversCommon && this.isWorktreesReport(changes)) {\n\t\t\tthis.onWorktreesReported(relativePath, event.reason, () => {\n\t\t\t\tif (this._disposed || this._sessions.get(entry.repoPath) !== entry) return;\n\n\t\t\t\tdeliverRepoChanged(entry, changes, getChangedRef(relativePath), movedWorktree);\n\t\t\t});\n\t\t} else if (changes != null) {\n\t\t\tdeliverRepoChanged(entry, changes, getChangedRef(relativePath), movedWorktree);\n\t\t}\n\n\t\tif (relativePath === 'info/exclude') {\n\t\t\tentry.hooks.onIgnoresChanged?.(entry.repoPath);\n\t\t}\n\t}\n\n\t/** A report of the `worktrees` directory, an admin entry or a file in it, once the group may tell them apart */\n\tprivate isWorktreesReport(changes: readonly RepositoryChange[]): boolean {\n\t\treturn (\n\t\t\tthis._worktreesBaseline != null &&\n\t\t\tchanges.includes('worktrees') &&\n\t\t\tchanges.every(c => c === 'worktrees' || c === 'worktreeHead')\n\t\t);\n\t}\n\n\t/** `deliver` tells the sessions the report reaches of it, should the report concern them (see above) */\n\tprivate onWorktreesReported(relativePath: string, reason: FileWatchEvent['reason'], deliver: () => void): void {\n\t\tif (this._worktreesBaselining && this._worktreesBaseline != null) {\n\t\t\t// The baseline may have read the entry before the change reported, so the report is told; it is still decided\n\t\t\t// once the baseline settles, so what is known of the entry catches up with it\n\t\t\tdeliver();\n\t\t\tvoid this._worktreesBaseline.then(() => this.decideWorktreesReport(relativePath, reason, noop));\n\t\t\treturn;\n\t\t}\n\n\t\tthis.decideWorktreesReport(relativePath, reason, deliver);\n\t}\n\n\tprivate decideWorktreesReport(relativePath: string, reason: FileWatchEvent['reason'], deliver: () => void): void {\n\t\tif (this._disposed) return;\n\t\tif (!this._ignoredWorktreeRoots.length) {\n\t\t\tdeliver();\n\t\t\treturn;\n\t\t}\n\n\t\tif (relativePath === 'worktrees') {\n\t\t\tthis.queueWorktreesRescan(reason, deliver);\n\t\t\treturn;\n\t\t}\n\n\t\tconst entry = parseWorktreeAdminPath(relativePath);\n\t\tif (entry == null) {\n\t\t\tdeliver();\n\t\t\treturn;\n\t\t}\n\n\t\tconst { id, file } = entry;\n\n\t\t// Only the entry or its `gitdir` going is a removal: an unlock deletes `locked` from an entry that stays, and a\n\t\t// watcher may report git's lock file renamed over `HEAD` as `HEAD` deleted and created again\n\t\tif (reason === 'delete' && (file == null || file === 'gitdir')) {\n\t\t\tif (this.forgetWorktreeId(id) !== true) {\n\t\t\t\tdeliver();\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\t// What a removed entry was decides the removal's other reports. Any other report of its id is read: one that finds\n\t\t// the entry is of an entry created again, which may be another worktree's. One that can't is the removal's own\n\t\t// unless it creates the entry, since a watcher may report the entry's directory changed beside each file the\n\t\t// removal deletes\n\t\tconst removed = this._worktreeIds.has(id) ? undefined : this._removedWorktreeIds.get(id);\n\t\tconst known = this._worktreeIds.get(id) ?? (reason === 'delete' ? removed : undefined);\n\t\t// Only a new entry or a written `gitdir` can name another worktree; anything else is told as the id is known\n\t\tif (known != null && file !== 'gitdir' && !(file == null && reason === 'create')) {\n\t\t\tif (!known) {\n\t\t\t\tdeliver();\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\tconst retry = removed == null || reason === 'create';\n\t\tvoid this.readWorktreeId(id, retry).then(([ignored, previous]) => {\n\t\t\tif (this._disposed) return;\n\n\t\t\tif (ignored == null) {\n\t\t\t\tif (retry) {\n\t\t\t\t\tvoid this.waitForWorktreeRetry(id, deliver);\n\t\t\t\t} else if (removed === false) {\n\t\t\t\t\tdeliver();\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Moved into or out of an ignored folder: every session's list gained or lost it\n\t\t\tif (previous != null && ignored !== previous) {\n\t\t\t\tthis.deliverWorktreesChange();\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (!ignored) {\n\t\t\t\tdeliver();\n\t\t\t}\n\t\t});\n\t}\n\n\t/**\n\t * Reads the entry's `gitdir`: whether it names an ignored worktree (`undefined` when it can't be read), and what the\n\t * id was known to be when this read replaced it. Reads of one id can settle out of order (a slow one from before the\n\t * worktree moved out of the folder), so only the latest updates what is known of it; an earlier one settles with\n\t * what the latest finds, without what the id was, since the latest tells a move itself, or once the entry was removed\n\t * since, with what the removal found it was. One that can't read the entry forgets what it was known to be, since git\n\t * may be writing its `gitdir` again, and reads it once more a moment later, unless `retry` is false (it then leaves\n\t * what is known as it was); one that can settles that read, if pending.\n\t */\n\tprivate readWorktreeId(\n\t\tid: string,\n\t\tretry: boolean = true,\n\t): Promise<[ignored: boolean | undefined, previous: boolean | undefined]> {\n\t\tconst read: Promise<[ignored: boolean | undefined, previous: boolean | undefined]> = this.readIgnoredWorktree(\n\t\t\tid,\n\t\t).then(ignored => {\n\t\t\tconst latest = this._worktreeReads.get(id);\n\t\t\tif (latest !== read) {\n\t\t\t\tif (latest == null) return [this._removedWorktreeIds.get(id), undefined];\n\n\t\t\t\treturn latest.then(([found]): [boolean | undefined, undefined] => {\n\t\t\t\t\t// A later read that couldn't read the entry may not read it again, but this one's report may be of\n\t\t\t\t\t// the entry created again, unless it was removed since\n\t\t\t\t\tif (found == null && retry && this._worktreeReads.has(id)) {\n\t\t\t\t\t\tthis.scheduleWorktreeRetry(id, undefined);\n\t\t\t\t\t}\n\t\t\t\t\treturn [found, undefined];\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tconst previous = this._worktreeIds.get(id);\n\t\t\tif (ignored == null) {\n\t\t\t\tif (!retry) return [undefined, previous];\n\n\t\t\t\tthis._removedWorktreeIds.delete(id);\n\t\t\t\tthis._worktreeIds.delete(id);\n\t\t\t\tthis.scheduleWorktreeRetry(id, previous);\n\t\t\t\treturn [undefined, previous];\n\t\t\t}\n\n\t\t\tthis._removedWorktreeIds.delete(id);\n\t\t\tthis._worktreeIds.set(id, ignored);\n\t\t\tthis.settleWorktreeRetry(id, ignored);\n\t\t\treturn [ignored, previous];\n\t\t});\n\t\tthis._worktreeReads.set(id, read);\n\t\treturn read;\n\t}\n\n\t/** Reads the entry once more a moment later, unless that is already pending; `previous` is what it was known to be */\n\tprivate scheduleWorktreeRetry(id: string, previous: boolean | undefined): void {\n\t\tif (this._disposed) return;\n\n\t\tconst pending = this._worktreeRetries.get(id);\n\t\tif (pending != null) {\n\t\t\tpending.previous ??= previous;\n\t\t\treturn;\n\t\t}\n\n\t\tlet resolve!: (ignored: boolean | undefined) => void;\n\t\tconst decided = new Promise<boolean | undefined>(r => {\n\t\t\tresolve = r;\n\t\t});\n\t\tconst timer = setTimeout(() => {\n\t\t\tvoid this.readWorktreeId(id).then(([ignored]) => {\n\t\t\t\t// A removal, or a later read that could read the entry, may have settled it meanwhile\n\t\t\t\tif (this._worktreeRetries.get(id)?.decided === decided) {\n\t\t\t\t\tthis.settleWorktreeRetry(id, ignored);\n\t\t\t\t}\n\t\t\t});\n\t\t}, worktreeRetryDelayMs);\n\t\tthis._worktreeRetries.set(id, {\n\t\t\ttimer: timer,\n\t\t\tdelivers: [],\n\t\t\tprevious: previous,\n\t\t\tdecided: decided,\n\t\t\tresolve: resolve,\n\t\t});\n\t}\n\n\t/**\n\t * A report whose read couldn't read the entry waits on the entry's next read, and `deliver` is told then, unless that\n\t * read finds an ignored worktree's; one still unreadable is told. Both watchers report each change of an entry, so\n\t * the reports of one id wait on one read. Resolves with what it found, as {@link settleWorktreeRetry} does\n\t */\n\tprivate waitForWorktreeRetry(id: string, deliver?: () => void): Promise<boolean | undefined> {\n\t\t// A later read may already have found what the entry is\n\t\tconst known = this._worktreeIds.get(id);\n\t\tif (known != null) {\n\t\t\tif (!known) {\n\t\t\t\tdeliver?.();\n\t\t\t}\n\t\t\treturn Promise.resolve(known);\n\t\t}\n\n\t\t// None is pending only when the entry was removed since, and the removal is told itself\n\t\tconst retry = this._worktreeRetries.get(id);\n\t\tif (retry == null) return Promise.resolve(undefined);\n\n\t\tif (deliver != null) {\n\t\t\tretry.delivers.push(deliver);\n\t\t}\n\t\treturn retry.decided;\n\t}\n\n\t/**\n\t * Tells the reports waiting on the id's retry what the entry turned out to be: nothing when an ignored worktree's,\n\t * every session when it moved into or out of an ignored folder, and the reports' own sessions otherwise, `ignored`\n\t * being `undefined` when it still couldn't be read\n\t */\n\tprivate settleWorktreeRetry(id: string, ignored: boolean | undefined): void {\n\t\tconst pending = this._worktreeRetries.get(id);\n\t\tif (pending == null) return;\n\n\t\tthis._worktreeRetries.delete(id);\n\t\tclearTimeout(pending.timer);\n\t\t// Settled before any session is told: a listing waits on it, and a hook that throws would otherwise hold back\n\t\t// every later listing for good\n\t\tpending.resolve(ignored);\n\t\tif (ignored != null && pending.previous != null && ignored !== pending.previous) {\n\t\t\tthis.deliverWorktreesChange();\n\t\t} else if (ignored !== true) {\n\t\t\tfor (const deliver of pending.delivers) {\n\t\t\t\tdeliver();\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Takes `id` as removed, remembering what it was for the removal's other reports; returns that, or `undefined` when\n\t * the id was never known\n\t */\n\tprivate forgetWorktreeId(id: string): boolean | undefined {\n\t\t// A read still in flight read the entry before it went, and would bring the removed id back as known\n\t\tthis._worktreeReads.delete(id);\n\n\t\tlet ignored = this._worktreeIds.get(id);\n\t\t// The reports waiting to read the entry again are dropped: the removal is told for what the id was, which only\n\t\t// the retry still knows once a read couldn't read the entry\n\t\tconst retry = this._worktreeRetries.get(id);\n\t\tif (retry != null) {\n\t\t\tthis._worktreeRetries.delete(id);\n\t\t\tclearTimeout(retry.timer);\n\t\t\tretry.resolve(undefined);\n\t\t\tignored ??= retry.previous;\n\t\t}\n\n\t\tif (ignored == null) return this._removedWorktreeIds.get(id);\n\n\t\tthis._worktreeIds.delete(id);\n\t\tthis._removedWorktreeIds.delete(id);\n\t\tthis._removedWorktreeIds.set(id, ignored);\n\t\tif (this._removedWorktreeIds.size > removedWorktreeIdsLimit) {\n\t\t\tconst [oldest] = this._removedWorktreeIds.keys();\n\t\t\tthis._removedWorktreeIds.delete(oldest);\n\t\t}\n\t\treturn ignored;\n\t}\n\n\t/** Whether the entry's `gitdir` names an ignored worktree, or `undefined` when it can't be read. Never rejects */\n\tprivate async readIgnoredWorktree(id: string): Promise<boolean | undefined> {\n\t\tconst adminDir = joinPaths(this.commonGitDir, 'worktrees', id);\n\t\tconst content = await this.readWithTimeout(joinPaths(adminDir, 'gitdir'));\n\t\t// Git writes the path of the worktree's `.git` file, relative to the entry under `worktree.useRelativePaths`\n\t\tconst dotGit = content != null ? new TextDecoder().decode(content).trim() : '';\n\t\tconst dotGitPath = dotGit ? normalizePath(isAbsolute(dotGit) ? dotGit : joinPaths(adminDir, dotGit)) : '';\n\t\tif (!dotGitPath.endsWith('/.git')) return undefined;\n\n\t\tconst worktreePath = dirname(dotGitPath);\n\t\treturn this._ignoredWorktreeRoots.some(root => isDescendant(worktreePath, root));\n\t}\n\n\tprivate queueWorktreesBaseline(take: () => Promise<void>): void {\n\t\tthis._worktreesBaselining = true;\n\t\tconst baseline: Promise<void> = this._worktreesQueue\n\t\t\t.then(take)\n\t\t\t.catch(() => {})\n\t\t\t.finally(() => {\n\t\t\t\tif (this._worktreesBaseline === baseline) {\n\t\t\t\t\tthis._worktreesBaselining = false;\n\t\t\t\t}\n\t\t\t});\n\t\tthis._worktreesBaseline = baseline;\n\t\tthis._worktreesQueue = baseline;\n\t}\n\n\t/** A watcher of the `worktrees` directory dropped events: whatever changed meanwhile went unseen */\n\tprivate rebaselineWorktrees(): void {\n\t\tif (this._worktreesBaseline == null || this._worktreesRebaselineQueued || this._disposed) return;\n\t\t// The first baseline found no folder to ignore, and none is asked for again, so there is nothing to retake\n\t\tif (!this._worktreesBaselining && !this._ignoredWorktreeRoots.length) return;\n\n\t\tthis._worktreesRebaselineQueued = true;\n\t\tthis.queueWorktreesBaseline(async () => {\n\t\t\tthis._worktreesRebaselineQueued = false;\n\t\t\tif (this._disposed || !this._ignoredWorktreeRoots.length) return;\n\n\t\t\tawait this.listWorktrees('rebaseline');\n\t\t});\n\t}\n\n\t/** The watchers' reports of the directory pile onto one queued listing, which tells them apart */\n\tprivate queueWorktreesRescan(reason: FileWatchEvent['reason'], deliver: () => void): void {\n\t\tconst queued = this._worktreesRescanQueued;\n\t\tif (queued != null) {\n\t\t\tqueued.delivers.push(deliver);\n\t\t\tqueued.removal ||= reason === 'delete';\n\t\t\treturn;\n\t\t}\n\n\t\tconst rescan = { delivers: [deliver], removal: reason === 'delete' };\n\t\tthis._worktreesRescanQueued = rescan;\n\t\tthis._worktreesQueue = this._worktreesQueue\n\t\t\t.then(() => {\n\t\t\t\tthis._worktreesRescanQueued = undefined;\n\t\t\t\treturn this.listWorktrees('rescan', rescan.delivers, rescan.removal);\n\t\t\t})\n\t\t\t.catch(() => {});\n\t}\n\n\t/**\n\t * Lists the admin entries and compares them with the last listing. A baseline (or a rebaseline, after a watcher\n\t * dropped events) reads every entry; a rescan only those it doesn't know, reading one it can't read once more a\n\t * moment later. Git removes the directory with its last entry, so a directory that isn't there is an empty listing,\n\t * whatever the reports said of it (a poll sees its removal as a change). A listing that fails otherwise is a\n\t * baseline's empty directory, and a rescan's too when one of its reports (`delivers`) removed the directory. For any\n\t * other rescan, it is a change it can't rule out, told to the reports' own sessions\n\t */\n\tprivate async listWorktrees(\n\t\tmode: 'baseline' | 'rebaseline' | 'rescan',\n\t\tdelivers?: readonly (() => void)[],\n\t\tremoval?: boolean,\n\t): Promise<void> {\n\t\tconst readDirectory = this.readDirectory;\n\t\tif (readDirectory == null) return;\n\n\t\tconst entries = await this.withTimeout(() =>\n\t\t\treadDirectory(joinPaths(this.commonGitDir, 'worktrees')).catch((ex: unknown) => {\n\t\t\t\tif (isNotFound(ex)) return [];\n\n\t\t\t\tthrow ex;\n\t\t\t}),\n\t\t);\n\t\tif (this._disposed) return;\n\n\t\t// An admin entry is a directory, so a stray file such as `.DS_Store` is none\n\t\tconst names = entries?.filter(([, type]) => type & FileType.Directory).map(([name]) => name);\n\n\t\tif (names == null && mode === 'rescan' && !removal) {\n\t\t\tfor (const deliver of delivers ?? []) {\n\t\t\t\tdeliver();\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\tconst listing = new Set(names);\n\t\tconst previous = this._listedWorktreeIds;\n\t\tthis._listedWorktreeIds = listing;\n\n\t\tlet changed = false;\n\t\tif (mode !== 'baseline') {\n\t\t\t// An entry known only from its own reports since the last listing may be gone too\n\t\t\tfor (const id of new Set([...previous, ...this._worktreeIds.keys()])) {\n\t\t\t\tif (listing.has(id)) continue;\n\n\t\t\t\tif (this.forgetWorktreeId(id) !== true) {\n\t\t\t\t\tchanged = true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tconst reads = await Promise.all(\n\t\t\t[...listing]\n\t\t\t\t.filter(id => mode !== 'rescan' || (!previous.has(id) && !this._worktreeIds.has(id)))\n\t\t\t\t.map(async id => {\n\t\t\t\t\tconst [ignored, known] = await this.readWorktreeId(id);\n\t\t\t\t\tif (ignored != null || mode !== 'rescan' || this._disposed) return [id, [ignored, known]] as const;\n\n\t\t\t\t\t// An entry listed before its `gitdir` is written won't be listed as new again\n\t\t\t\t\treturn [id, [await this.waitForWorktreeRetry(id), undefined]] as const;\n\t\t\t\t}),\n\t\t);\n\t\tif (this._disposed || mode === 'baseline') return;\n\n\t\tconst read = new Map(reads);\n\t\tfor (const id of listing) {\n\t\t\tconst result = read.get(id);\n\t\t\tif (!previous.has(id)) {\n\t\t\t\t// An entry whose `gitdir` still can't be read counts as real\n\t\t\t\tif ((result != null ? result[0] : this._worktreeIds.get(id)) !== true) {\n\t\t\t\t\tchanged = true;\n\t\t\t\t}\n\t\t\t} else if (result?.[0] != null && result[1] != null && result[0] !== result[1]) {\n\t\t\t\tchanged = true;\n\t\t\t}\n\t\t}\n\n\t\tif (changed) {\n\t\t\tthis.deliverWorktreesChange();\n\t\t}\n\t}\n\n\tprivate deliverWorktreesChange(): void {\n\t\tfor (const entry of this._sessions.values()) {\n\t\t\tentry.hooks.onRepoChanged(entry.repoPath, ['worktrees', 'worktreeHead'], undefined);\n\t\t}\n\t}\n\n\tprivate onConfigReported(): void {\n\t\t// The baseline may already hold the change reported, which comparing with it would lose\n\t\tif (this._configBaselining) {\n\t\t\tthis.deliverConfigChange(undefined);\n\t\t\treturn;\n\t\t}\n\t\tif (this._configReading) {\n\t\t\tthis._configRereadQueued = true;\n\t\t\treturn;\n\t\t}\n\n\t\tvoid this.readConfigChanges();\n\t}\n\n\tprivate async readConfigBaseline(): Promise<void> {\n\t\tthis._configBaselining = true;\n\t\tthis._configReading = true;\n\t\ttry {\n\t\t\tconst config = await this.readConfig();\n\t\t\tif (this._disposed) return;\n\n\t\t\tthis._config = config;\n\t\t} finally {\n\t\t\tthis._configBaselining = false;\n\t\t\tthis._configReading = false;\n\t\t}\n\t}\n\n\t/** Reads and compares until no report came in during the last read: it may describe a change the read missed */\n\tprivate async readConfigChanges(): Promise<void> {\n\t\tthis._configReading = true;\n\t\ttry {\n\t\t\tdo {\n\t\t\t\tthis._configRereadQueued = false;\n\t\t\t\tconst config = await this.readConfig();\n\t\t\t\tif (this._disposed) return;\n\n\t\t\t\tconst previous = this._config;\n\t\t\t\tif (config == null || previous == null) {\n\t\t\t\t\t// Unreadable now, or never readable before: the change may be anywhere. A failed read keeps the last\n\t\t\t\t\t// snapshot, so the next read still compares with what every session was told\n\t\t\t\t\tthis._config ??= config;\n\t\t\t\t\tthis.deliverConfigChange(undefined);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tthis._config = config;\n\t\t\t\tconst change = diffGitConfigSections(previous, config);\n\t\t\t\tif (change != null) {\n\t\t\t\t\tthis.deliverConfigChange(change);\n\t\t\t\t}\n\t\t\t} while (this._configRereadQueued);\n\t\t} finally {\n\t\t\tthis._configReading = false;\n\t\t}\n\t}\n\n\t/** `undefined` when the file couldn't be read or parsed, or the read didn't settle in time */\n\tprivate async readConfig(): Promise<GitConfigSections | undefined> {\n\t\tconst data = await this.readWithTimeout(joinPaths(this.commonGitDir, 'config'));\n\t\ttry {\n\t\t\treturn data != null ? parseGitConfigBytes(data) : undefined;\n\t\t} catch {\n\t\t\treturn undefined;\n\t\t}\n\t}\n\n\t/** `undefined` when the file couldn't be read, or the read didn't settle in time */\n\tprivate readWithTimeout(path: string): Promise<Uint8Array | undefined> {\n\t\tconst readFile = this.readFile;\n\t\tif (readFile == null) return Promise.resolve(undefined);\n\n\t\treturn this.withTimeout(() => readFile(path));\n\t}\n\n\t/** `undefined` when `read` rejects, or doesn't settle in time */\n\tprivate async withTimeout<T>(read: () => Promise<T>): Promise<T | undefined> {\n\t\tlet timer: ReturnType<typeof setTimeout> | undefined;\n\t\ttry {\n\t\t\treturn await Promise.race([\n\t\t\t\tread(),\n\t\t\t\tnew Promise<undefined>(resolve => {\n\t\t\t\t\ttimer = setTimeout(resolve, readTimeoutMs, undefined);\n\t\t\t\t}),\n\t\t\t]);\n\t\t} catch {\n\t\t\treturn undefined;\n\t\t} finally {\n\t\t\tclearTimeout(timer);\n\t\t}\n\t}\n\n\t/**\n\t * Tells every session of a change to the shared `.git/config`: confined to some branches' sections, or (`undefined`,\n\t * or a change outside them) anywhere, which may have changed a remote's settings too. Either way no ref moved\n\t */\n\tprivate deliverConfigChange(change: GitConfigSectionsChange | undefined): void {\n\t\tfor (const entry of this._sessions.values()) {\n\t\t\tif (change?.confined) {\n\t\t\t\tentry.hooks.onRepoChanged(entry.repoPath, ['config'], false, false, change.branches);\n\t\t\t} else {\n\t\t\t\tentry.hooks.onRepoChanged(entry.repoPath, ['config', 'remotes'], false);\n\t\t\t}\n\t\t}\n\t}\n}\n\n/**\n * `changes` with `worktreeHead` for a report that can stand for an entry's HEAD created or deleted with it: the\n * `worktrees` directory, an entry created or deleted, or its `gitdir` deleted. A watcher may coalesce the subtree a\n * removal deletes into one report of its parent, so no report of the HEAD comes. An entry's directory merely changed\n * stays `worktrees` alone: a watcher may report it beside each file in it, a lock's `locked` included\n */\nfunction withWorktreeEntryHead(\n\tchanges: RepositoryChange[] | undefined,\n\trelativePath: string,\n\treason: FileWatchEvent['reason'],\n): RepositoryChange[] | undefined {\n\tif (changes?.length !== 1 || changes[0] !== 'worktrees') return changes;\n\tif (relativePath === 'worktrees') return ['worktrees', 'worktreeHead'];\n\n\tconst idEnd = relativePath.indexOf('/', 10);\n\tif (idEnd === -1) return reason === 'create' || reason === 'delete' ? ['worktrees', 'worktreeHead'] : changes;\n\n\treturn reason === 'delete' && relativePath.substring(idEnd + 1) === 'gitdir'\n\t\t? ['worktrees', 'worktreeHead']\n\t\t: changes;\n}\n\n/** The admin id of the linked worktree whose `HEAD` file `relativePath` (relative to the common git dir) is */\nfunction getMovedWorktreeId(relativePath: string): string | undefined {\n\tconst entry = parseWorktreeAdminPath(relativePath);\n\treturn entry?.file === 'HEAD' ? entry.id : undefined;\n}\n\n/**\n * The admin id of the linked worktree a `worktreeHead` among `changes` is for: the entry `relativePath` (relative to the\n * common git dir) is, or is a file of\n */\nfunction getReportedWorktreeId(\n\trelativePath: string,\n\tchanges: readonly RepositoryChange[] | undefined,\n): string | undefined {\n\treturn changes?.includes('worktreeHead') ? parseWorktreeAdminPath(relativePath)?.id : undefined;\n}\n\n/** Tells `entry` of `changes`, naming the linked worktree whose HEAD moved only when the report knows it */\nfunction deliverRepoChanged(\n\tentry: SessionEntry,\n\tchanges: RepositoryChange[],\n\tref: string | false | undefined,\n\tmovedWorktree: string | undefined,\n): void {\n\tif (movedWorktree != null) {\n\t\tentry.hooks.onRepoChanged(entry.repoPath, changes, ref, undefined, undefined, movedWorktree);\n\t} else {\n\t\tentry.hooks.onRepoChanged(entry.repoPath, changes, ref);\n\t}\n}\n\n/** The path doesn't exist: Node's error, or the one VS Code's file system raises */\nfunction isNotFound(ex: unknown): boolean {\n\tconst code = (ex as { code?: unknown } | undefined)?.code;\n\treturn code === 'ENOENT' || code === 'FileNotFound';\n}\n\n/** The shared `.git/config` (or the lock git writes it through), relative to the common git dir */\nfunction isConfigFile(relativePath: string): boolean {\n\treturn relativePath === 'config' || relativePath === 'config.lock';\n}\n\n/**\n * The ref a `.git`-relative path names: a loose ref (or ref directory) under `refs/`, or the `HEAD`/`ORIG_HEAD`\n * pseudo-refs. A lock file names the ref it locks; the only ones classification lets through are the pseudo-refs' and\n * `refs/stash.lock`.\n */\nfunction getChangedRef(relativePath: string): string | false | undefined {\n\tconst ref = relativePath.endsWith('.lock') ? relativePath.substring(0, relativePath.length - 5) : relativePath;\n\t// Remote config still invalidates remote and branch caches, but doesn't itself move any ref.\n\tif (ref === 'config' || ref === 'config.worktree') return false;\n\n\treturn ref.startsWith('refs/') || ref === 'HEAD' || ref === 'ORIG_HEAD' ? ref : undefined;\n}\n"],"mappings":";;;;;;;;;;;;;;AAoCA,MAAM,gBAAgB;;;;;AAMtB,MAAM,0BAA0B;;;;;AAMhC,MAAM,uBAAuB;AAE7B,SAAS,OAAa,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqGvB,IAAa,aAAb,MAAqD;CAwE1C;CACQ;CAEA;CAKA;CAKA;CApFlB,4BAA6B,IAAI,IAA0B;CAC3D;CACA,qBAAqD;CACrD;CACA,YAAoB;;CAGpB;;CAEA,oBAA4B;CAC5B,iBAAyB;CACzB,sBAA8B;;;;;CAM9B;;CAEA,uBAA+B;CAC/B,6BAAqC;;CAErC,wBAAmD,CAAC;;CAEpD,kBAAyC,QAAQ,QAAQ;;CAEzD;;CAQA,qCAAkD,IAAI,IAAI;;CAE1D,+BAAgC,IAAI,IAAqB;;CAEzD,sCAAuC,IAAI,IAAqB;;;;;CAKhE,iCAAkC,IAAI,IAGpC;;CAEF,mCAAoC,IAAI,IAkBtC;;CAEF;CAEA,YACC,cACA,UAEA,QAKA,UAKA,eAEA,sBAEA,wBACC;EAlBQ,KAAA,eAAA;EACQ,KAAA,WAAA;EAEA,KAAA,SAAA;EAKA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AK,EAAE;CAC1C,IAAI,UAAU,IAAI,OAAO,WAAW,YAAY,WAAW,WAAW,CAAC,aAAa,cAAc,IAAI;CAEtG,OAAO,WAAW,YAAY,aAAa,UAAU,QAAQ,CAAC,MAAM,WACjE,CAAC,aAAa,cAAc,IAC5B;AACJ;;AAGA,SAAS,mBAAmB,cAA0C;CACrE,MAAM,QAAQ,uBAAuB,YAAY;CACjD,OAAO,OAAO,SAAS,SAAS,MAAM,KAAK,KAAA;AAC5C;;;;;AAMA,SAAS,sBACR,cACA,SACqB;CACrB,OAAO,SAAS,SAAS,cAAc,IAAI,uBAAuB,YAAY,CAAC,EAAE,KAAK,KAAA;AACvF;;AAGA,SAAS,mBACR,OACA,SACA,KACA,eACO;CACP,IAAI,iBAAiB,MACpB,MAAM,MAAM,cAAc,MAAM,UAAU,SAAS,KAAK,KAAA,GAAW,KAAA,GAAW,aAAa;MAE3F,MAAM,MAAM,cAAc,MAAM,UAAU,SAAS,GAAG;AAExD;;AAGA,SAAS,WAAW,IAAsB;CACzC,MAAM,OAAQ,IAAuC;CACrD,OAAO,SAAS,YAAY,SAAS;AACtC;;AAGA,SAAS,aAAa,cAA+B;CACpD,OAAO,iBAAiB,YAAY,iBAAiB;AACtD;;;;;;AAOA,SAAS,cAAc,cAAkD;CACxE,MAAM,MAAM,aAAa,SAAS,OAAO,IAAI,aAAa,UAAU,GAAG,aAAa,SAAS,CAAC,IAAI;CAElG,IAAI,QAAQ,YAAY,QAAQ,mBAAmB,OAAO;CAE1D,OAAO,IAAI,WAAW,OAAO,KAAK,QAAQ,UAAU,QAAQ,cAAc,MAAM,KAAA;AACjF"}
1
+ {"version":3,"file":"watchGroup.js","names":[],"sources":["../../../../git/src/watching/watchGroup.ts"],"sourcesContent":["import type { UnifiedDisposable } from '@gitlens/utils/disposable.js';\nimport { some } from '@gitlens/utils/iterable.js';\nimport { isDescendant, joinPaths, normalizePath, relative } from '@gitlens/utils/path.js';\nimport { FileType } from '../context.js';\nimport type { GitDir, RepositoryChange } from '../models/repository.js';\nimport { getWorktreeAdminId, isIgnoredWorktreeEntry, parseWorktreeAdminPath } from '../utils/repository.utils.js';\nimport { allWatchedRepositoryChanges, classifyGitDirChange } from './classifyChange.js';\nimport type { GitConfigSections, GitConfigSectionsChange } from './configSections.js';\nimport { diffGitConfigSections, parseGitConfigBytes } from './configSections.js';\nimport type { GitDirPoller, GitDirProbe } from './gitDirPoller.js';\nimport { GitDirProbeTarget } from './gitDirPoller.js';\nimport type {\n\tFileWatcher,\n\tFileWatcherOptions,\n\tFileWatcherReliability,\n\tFileWatchEvent,\n\tFileWatchingProvider,\n} from './provider.js';\nimport {\n\tdotGitGlobCombined,\n\tdotGitGlobCommon,\n\tdotGitGlobRoot,\n\tgetGitDirRefProbes,\n\tgetIgnoredWorktreeFolderExcludes,\n\tgitDirCommonProbes,\n\tgitDirExcludes,\n\tgitDirProbesByEmittedPath,\n\tgitDirRootProbes,\n\tshouldIgnoreRepoPath,\n} from './watcherPatterns.js';\n\n/**\n * How long a read of the shared `.git/config`, or of the worktrees' admin entries, may take before it counts as failed.\n * Reads of each run one at a time, so one that never settles, as on a hung network or WSL mount, would otherwise hold\n * back every later report.\n */\nconst readTimeoutMs = 5000;\n\n/**\n * How many removed admin entries are remembered. Each watcher reports a removal once for each file it watched in the\n * entry, and two watchers see the common dir beside a main checkout, so its reports outlive any single one of them\n */\nconst removedWorktreeIdsLimit = 64;\n\n/**\n * How long after an admin entry's `gitdir` couldn't be read it is read once more. A watcher can report the entry before\n * git wrote its `gitdir`, and then miss the write itself (a new directory's files go unseen until it is watched)\n */\nconst worktreeRetryDelayMs = 250;\n\nfunction noop(): void {}\n\n/**\n * Hooks that the WatchGroup fires when events are interpreted.\n * These are raw, un-debounced events — the session handles debouncing.\n */\nexport interface WatchGroupHooks {\n\t/**\n\t * `ref` is the full ref name (or ref directory) or pseudo-ref (`HEAD`, `ORIG_HEAD`) whose file changed, with a\n\t * trailing `.lock` stripped; `false` when config changed without moving refs, and `undefined` when ref movement\n\t * is unknown. `overflow` marks the every-kind rescan of a watcher that dropped events, which no single write can\n\t * account for. `configBranches`, with a `config` change, are the local branches (full ref names) whose\n\t * `branch.<name>` sections are all that changed in the shared `.git/config`; without it, the config change may be\n\t * anywhere. `movedWorktree`, with a `worktreeHead` change, is the admin id (the `<id>` of `worktrees/<id>`) of the\n\t * linked worktree whose `HEAD` file changed, or whose admin entry was created or removed; without it, any linked\n\t * worktree's HEAD may have moved.\n\t */\n\treadonly onRepoChanged: (\n\t\trepoPath: string,\n\t\tchanges: RepositoryChange[],\n\t\tref?: string | false,\n\t\toverflow?: boolean,\n\t\tconfigBranches?: ReadonlySet<string>,\n\t\tmovedWorktree?: string,\n\t) => void;\n\treadonly onFetchHeadChanged?: (repoPath: string) => void;\n\treadonly onIgnoresChanged?: (repoPath: string) => void;\n\t/** The refs whose loose files a poll stats for this session, read at each poll */\n\treadonly getProbeRefs?: () => Iterable<string>;\n\t/** A watcher this session hears through went `unwatchable`, or stopped being it (see {@link WatchGroup.isUnwatchable}) */\n\treadonly onUnwatchableChanged?: (repoPath: string) => void;\n}\n\n/**\n * Tracks one session's connection to a WatchGroup.\n * Each session has its own root watcher but shares the common watcher.\n */\ninterface SessionEntry {\n\treadonly repoPath: string;\n\treadonly gitDirPath: string;\n\treadonly rootWatcher: FileWatcher;\n\t/** True when the root watcher is on the common dir itself, so it already sees every common file */\n\treadonly coversCommon: boolean;\n\t/** For a linked session, its `<n>` in `<common>/worktrees/<n>`; otherwise `undefined` */\n\treadonly worktreeId: string | undefined;\n\treadonly hooks: WatchGroupHooks;\n\treliability: FileWatcherReliability;\n\t/** Polls in place of (or beside) the root watcher while it isn't `reliable` */\n\ttarget?: GitDirProbeTarget;\n}\n\n/**\n * Manages filesystem watchers for a single physical `.git` directory,\n * shared across all worktrees that reference it.\n *\n * Structure:\n * - 1 common watcher: config, refs/**, info/exclude, etc. Delivers to linked sessions only; a\n * session rooted at the common dir hears the same files from its own combined root watcher.\n * - N root watchers: one per worktree (index, HEAD, *_HEAD, etc.)\n *\n * For a standard (non-worktree) repo, the common and root directories\n * are the same, but we still create separate watchers for clean separation.\n *\n * Given a `readFile`, the group keeps the shared `.git/config` as it last read it, section by section. A report of\n * that file (or its lock), from whichever watcher, is read and compared with it once, and every session hears what\n * changed: only some branches' `branch.<name>` sections (`config`, confined to them), anything else (`config` and\n * `remotes`, unconfined), or nothing at all, when an earlier report's read already delivered the change. Reads run\n * one at a time, so each compares with the one before it and none is skipped. The first read, taken as the group\n * starts, is the baseline and delivers nothing; a report arriving before it completes may describe a change it\n * already holds, so it is delivered unconfined. A read that fails or doesn't settle within a few seconds, or a file\n * git couldn't parse, is unconfined too.\n *\n * Given a `readFile`, a `readDirectory` (a directory's entries with their types, only the directories counting as\n * admin entries) and the folders whose worktrees the host has core ignore (a tool's throwaway worktrees, which no\n * host shows), the group reports no change of an ignored worktree's admin entry\n * (`<common>/worktrees/<id>`) to any session. Only registered folders count, since a user may keep real worktrees\n * anywhere, `.git` included. It lists the entries and reads each one's `gitdir` once as it starts, and again after a\n * watcher dropped events; a report arriving meanwhile is told at once, and decided once the listing settles, so what\n * is known of its entry catches up. From then on it reads an entry only when its `gitdir` may be new (the entry was\n * created, or its `gitdir` written, or it was removed before), so a real worktree's HEAD moves are told at once,\n * unread. Of two reads of one entry, the later decides both reports. An entry it doesn't know whose `gitdir` can't be\n * read (a watcher can report one before git writes it, and miss the write) is read once more a moment later, its\n * reports held until then, and told if it still can't be. Only the entry's directory or its `gitdir` going is a\n * removal; a deleted `HEAD` (a watcher may report git's lock file renamed over it as a delete) or `locked` is told as\n * the entry is known. Removing an entry deletes the `gitdir` a read needs, so a removal is told from what the entry was\n * known to be (before a read that couldn't read it, if one is waiting to read it again), and an entry it never knew is\n * told as real. Any other report of a removed entry but a delete is read, and one that can't be read is the removal's\n * own (a watcher may report the entry's directory changed beside each file it deletes), unless it creates the entry\n * again. A report of the `worktrees` directory itself (a coalesced\n * removal, a parent directory change, a poll, which sees nothing finer) lists it again: it is told to every session\n * when a real entry was added or removed since the last listing, and to none when only ignored ones were. Git removes\n * the directory with its last entry, so a directory that isn't there is an empty listing, as is a removal of it that\n * can't be listed. Since a listing (or a worktree moved into or out of a folder) changes what every session shows, it\n * is told to all of them; the other watcher's report of the same change then finds nothing left to tell. Where only a\n * poll watches the common dir, it sees just the `worktrees` directory, so an entry removed and added again under the\n * same id between two polls, or an entry's HEAD or lock changed in place, goes untold.\n *\n * Given the folders, the watchers over the common dir leave each one unwatched, since a tool's checkout there would\n * otherwise have every directory of it watched; one that shares a top-level directory with what the `.git` watch reads\n * stays watched.\n */\nexport class WatchGroup implements UnifiedDisposable {\n\tprivate readonly _sessions = new Map<string, SessionEntry>();\n\tprivate _commonWatcher: FileWatcher | undefined;\n\tprivate _commonReliability: FileWatcherReliability = 'reliable';\n\tprivate _commonTarget: GitDirProbeTarget | undefined;\n\tprivate _disposed = false;\n\n\t/** The shared `.git/config`, by section, as the last read that could parse it found it */\n\tprivate _config: GitConfigSections | undefined;\n\t/** The baseline read is in flight */\n\tprivate _configBaselining = false;\n\tprivate _configReading = false;\n\tprivate _configRereadQueued = false;\n\n\t/**\n\t * Settles once the latest baseline of the admin entries was taken; `undefined` when the group can't tell an\n\t * ignored worktree's, so every report is told at once\n\t */\n\tprivate _worktreesBaseline: Promise<void> | undefined;\n\t/** A baseline is pending, so a report waits for it */\n\tprivate _worktreesBaselining = false;\n\tprivate _worktreesRebaselineQueued = false;\n\t/** Set by the first baseline; while empty, nothing is ignored and every report is told at once */\n\tprivate _ignoredWorktreeRoots: readonly string[] = [];\n\t/** Listings run one at a time, so each compares with the one before it */\n\tprivate _worktreesQueue: Promise<void> = Promise.resolve();\n\t/** The `worktrees` directory's reports waiting on the queued listing; `undefined` while none is queued */\n\tprivate _worktreesRescanQueued:\n\t\t| {\n\t\t\t\treadonly delivers: (() => void)[];\n\t\t\t\t/** One of them is a removal of the directory */\n\t\t\t\tremoval: boolean;\n\t\t }\n\t\t| undefined;\n\t/** The admin entries the last listing found */\n\tprivate _listedWorktreeIds: ReadonlySet<string> = new Set();\n\t/** Admin entries known to exist, by id: whether each is an ignored worktree's */\n\tprivate readonly _worktreeIds = new Map<string, boolean>();\n\t/** What removed admin entries were, by id, oldest first */\n\tprivate readonly _removedWorktreeIds = new Map<string, boolean>();\n\t/**\n\t * Each id's latest `gitdir` read, settling with what it found and what the id was known to be before it; only it\n\t * may update what is known of the id. A removal of the entry drops it\n\t */\n\tprivate readonly _worktreeReads = new Map<\n\t\tstring,\n\t\tPromise<[ignored: boolean | undefined, previous: boolean | undefined]>\n\t>();\n\t/** Admin entries whose `gitdir` couldn't be read, by id, waiting to be read once more */\n\tprivate readonly _worktreeRetries = new Map<\n\t\tstring,\n\t\t{\n\t\t\treadonly timer: ReturnType<typeof setTimeout>;\n\t\t\t/** The reports waiting on it, told unless the entry turns out to be an ignored worktree's */\n\t\t\treadonly delivers: (() => void)[];\n\t\t\t/**\n\t\t\t * What the entry was known to be before its `gitdir` couldn't be read, so a move or a removal is still told\n\t\t\t * as it was\n\t\t\t */\n\t\t\tprevious: boolean | undefined;\n\t\t\t/**\n\t\t\t * Settles with whether the entry is an ignored worktree's; `undefined` when it still can't tell, or it was\n\t\t\t * removed\n\t\t\t */\n\t\t\treadonly decided: Promise<boolean | undefined>;\n\t\t\treadonly resolve: (ignored: boolean | undefined) => void;\n\t\t}\n\t>();\n\t/** The `.git` excludes of a watcher over the common git dir, with the ignored worktrees' folders it may leave out */\n\tprivate readonly _commonGitDirExcludes: readonly string[];\n\n\tconstructor(\n\t\treadonly commonGitDir: string,\n\t\tprivate readonly provider: FileWatchingProvider,\n\t\t/** When given, a watcher that reports it can't be trusted is polled; otherwise none is asked */\n\t\tprivate readonly poller?: GitDirPoller,\n\t\t/**\n\t\t * When given, reports of the shared `.git/config` are classified by what changed in it, and admin entries are\n\t\t * read to tell an ignored worktree's (see above)\n\t\t */\n\t\tprivate readonly readFile?: (path: string) => Promise<Uint8Array>,\n\t\t/**\n\t\t * Returns a directory's entries with their types; with `readFile`, the admin entries are listed, only the\n\t\t * directories counting (see above)\n\t\t */\n\t\tprivate readonly readDirectory?: (path: string) => Promise<readonly (readonly [string, number])[]>,\n\t\t/** The absolute, normalized folders whose worktrees are ignored; none reads no admin entry */\n\t\tignoredWorktreeRoots?: Promise<readonly string[]>,\n\t\t/** The folders whose worktrees are ignored, relative to the common git dir */\n\t\tignoredWorktreeFolders?: readonly string[],\n\t) {\n\t\tconst folders = getIgnoredWorktreeFolderExcludes(ignoredWorktreeFolders);\n\t\tthis._commonGitDirExcludes = folders.length ? [...gitDirExcludes, ...folders] : gitDirExcludes;\n\t\tif (readFile != null) {\n\t\t\tvoid this.readConfigBaseline();\n\t\t}\n\t\tif (readFile != null && readDirectory != null && ignoredWorktreeRoots != null) {\n\t\t\tthis.queueWorktreesBaseline(async () => {\n\t\t\t\tconst roots = await this.withTimeout(() => Promise.resolve(ignoredWorktreeRoots));\n\t\t\t\tif (this._disposed || !Array.isArray(roots) || !roots.length) return;\n\n\t\t\t\tthis._ignoredWorktreeRoots = roots;\n\t\t\t\tawait this.listWorktrees('baseline');\n\t\t\t});\n\t\t}\n\t}\n\n\t[Symbol.dispose](): void {\n\t\tthis.dispose();\n\t}\n\n\t/** Dispose the entire group (common watcher + all root watchers). */\n\tdispose(): void {\n\t\tif (this._disposed) return;\n\n\t\tthis._disposed = true;\n\n\t\tfor (const entry of this._sessions.values()) {\n\t\t\tentry.rootWatcher.dispose();\n\t\t\tthis.stopPolling(entry);\n\t\t}\n\t\tthis._sessions.clear();\n\n\t\tthis.disposeCommonWatcher();\n\n\t\tfor (const retry of this._worktreeRetries.values()) {\n\t\t\tclearTimeout(retry.timer);\n\t\t\tretry.resolve(undefined);\n\t\t}\n\t\tthis._worktreeRetries.clear();\n\t}\n\n\tget sessions(): ReadonlyMap<string, SessionEntry> {\n\t\treturn this._sessions;\n\t}\n\n\t/** True when a watcher the session hears through — its root watcher, or a linked session's common one — can't watch */\n\tisUnwatchable(repoPath: string): boolean {\n\t\tconst entry = this._sessions.get(repoPath);\n\t\tif (entry == null) return false;\n\n\t\treturn (\n\t\t\tentry.reliability === 'unwatchable' || (!entry.coversCommon && this._commonReliability === 'unwatchable')\n\t\t);\n\t}\n\n\t/** Add a session to this group. Creates the root watcher for the session's gitDir. */\n\taddSession(repoPath: string, gitDir: GitDir, hooks: WatchGroupHooks): void {\n\t\tif (this._disposed) return;\n\t\tif (this._sessions.has(repoPath)) return; // Already tracked\n\n\t\t// Determine the glob pattern for the root watcher\n\t\tconst isStandard = gitDir.commonUri == null;\n\t\tconst rootPattern = isStandard ? dotGitGlobCombined : dotGitGlobRoot;\n\n\t\t// The watcher can report its reliability before `createWatcher` returns, so before the entry exists\n\t\tlet entry: SessionEntry | undefined;\n\t\tlet initialReliability: FileWatcherReliability = 'reliable';\n\n\t\tconst rootWatcher = this.provider.createWatcher(\n\t\t\tgitDir.uri.fsPath,\n\t\t\trootPattern,\n\t\t\t(event: FileWatchEvent) => {\n\t\t\t\tconst e = this._sessions.get(repoPath);\n\t\t\t\tif (e != null) {\n\t\t\t\t\tif (event.reason !== 'overflow') {\n\t\t\t\t\t\te.target?.forget(event.path);\n\t\t\t\t\t}\n\t\t\t\t\tthis.onRootEvent(event, e);\n\t\t\t\t}\n\t\t\t},\n\t\t\tthis.getWatcherOptions(gitDir.uri.fsPath, state => {\n\t\t\t\tif (entry == null) {\n\t\t\t\t\tinitialReliability = state;\n\t\t\t\t} else if (this._sessions.get(repoPath) === entry) {\n\t\t\t\t\tthis.setRootReliability(entry, state);\n\t\t\t\t}\n\t\t\t}),\n\t\t);\n\n\t\tconst entryGitDirPath = gitDir.uri.fsPath;\n\t\tentry = {\n\t\t\trepoPath: repoPath,\n\t\t\tgitDirPath: entryGitDirPath,\n\t\t\trootWatcher: rootWatcher,\n\t\t\tcoversCommon: isStandard,\n\t\t\tworktreeId: isStandard ? undefined : this.getWorktreeId(entryGitDirPath),\n\t\t\thooks: hooks,\n\t\t\treliability: 'reliable',\n\t\t};\n\n\t\tthis._sessions.set(repoPath, entry);\n\t\tif (initialReliability !== 'reliable') {\n\t\t\tthis.setRootReliability(entry, initialReliability, true);\n\t\t}\n\n\t\t// Start the common watcher if this is a worktree repo and we haven't yet.\n\t\t// Standard repos don't need a separate common watcher because their root\n\t\t// watcher uses dotGitGlobCombined which already covers all patterns.\n\t\tif (!isStandard) {\n\t\t\tthis.ensureCommonWatcher();\n\t\t}\n\t}\n\n\t/** Remove a session from this group. Disposes its root watcher. */\n\tremoveSession(repoPath: string): void {\n\t\tconst entry = this._sessions.get(repoPath);\n\t\tif (entry == null) return;\n\n\t\tentry.rootWatcher.dispose();\n\t\tthis.stopPolling(entry);\n\t\tthis._sessions.delete(repoPath);\n\n\t\t// Once no linked session is left, dispose the common watcher — it delivers to linked sessions only\n\t\tif (this._commonWatcher != null && !some(this._sessions.values(), e => !e.coversCommon)) {\n\t\t\tthis.disposeCommonWatcher();\n\t\t}\n\t}\n\n\tprivate getWorktreeId(gitDirPath: string): string | undefined {\n\t\treturn getWorktreeAdminId(gitDirPath, this.commonGitDir);\n\t}\n\n\tprivate ensureCommonWatcher(): void {\n\t\tif (this._commonWatcher != null || this._disposed) return;\n\n\t\t// The watcher can report its reliability before `createWatcher` returns\n\t\tlet watcher: FileWatcher | undefined;\n\t\tlet initialReliability: FileWatcherReliability = 'reliable';\n\t\tconst options = this.getWatcherOptions(this.commonGitDir, state => {\n\t\t\tif (watcher == null) {\n\t\t\t\tinitialReliability = state;\n\t\t\t} else if (this._commonWatcher === watcher) {\n\t\t\t\tthis.setCommonReliability(state);\n\t\t\t}\n\t\t});\n\n\t\twatcher = this.provider.createWatcher(\n\t\t\tthis.commonGitDir,\n\t\t\tdotGitGlobCommon,\n\t\t\t(event: FileWatchEvent) => {\n\t\t\t\tif (event.reason !== 'overflow') {\n\t\t\t\t\tthis._commonTarget?.forget(event.path);\n\t\t\t\t}\n\t\t\t\tthis.onCommonEvent(event);\n\t\t\t},\n\t\t\toptions,\n\t\t);\n\t\tthis._commonWatcher = watcher;\n\t\tif (initialReliability !== 'reliable') {\n\t\t\tthis.setCommonReliability(initialReliability, true);\n\t\t}\n\t}\n\n\tprivate disposeCommonWatcher(): void {\n\t\tthis._commonWatcher?.dispose();\n\t\tthis._commonWatcher = undefined;\n\t\tthis._commonReliability = 'reliable';\n\t\tif (this._commonTarget != null) {\n\t\t\tthis.poller?.delete(this._commonTarget);\n\t\t\tthis._commonTarget = undefined;\n\t\t}\n\t}\n\n\t/** Hosts that didn't opt into polling get exactly the options they always had */\n\tprivate getWatcherOptions(\n\t\tbasePath: string,\n\t\tonDidChangeReliability: (state: FileWatcherReliability) => void,\n\t): FileWatcherOptions {\n\t\tconst excludes = this.getExcludes(basePath);\n\t\treturn this.poller != null\n\t\t\t? { excludes: excludes, onDidChangeReliability: onDidChangeReliability }\n\t\t\t: { excludes: excludes };\n\t}\n\n\t/**\n\t * The ignored worktrees' folders join the `.git` excludes of a watcher over the common git dir: a tool that keeps its\n\t * throwaway checkouts inside the git dir would otherwise have each one's every directory watched, and every file it\n\t * writes reported. Every other watcher sits on a linked worktree's admin entry, which holds none of them\n\t */\n\tprivate getExcludes(basePath: string): readonly string[] {\n\t\tif (this._commonGitDirExcludes === gitDirExcludes) return gitDirExcludes;\n\n\t\treturn normalizePath(basePath) === normalizePath(this.commonGitDir)\n\t\t\t? this._commonGitDirExcludes\n\t\t\t: gitDirExcludes;\n\t}\n\n\tprivate setRootReliability(entry: SessionEntry, state: FileWatcherReliability, initial?: boolean): void {\n\t\tconst previous = entry.reliability;\n\t\tif (previous === state || this.poller == null) return;\n\n\t\tentry.reliability = state;\n\t\tif (state === 'reliable') {\n\t\t\tthis.stopPolling(entry);\n\t\t} else if (entry.target == null) {\n\t\t\tconst target = new GitDirProbeTarget(\n\t\t\t\tentry.gitDirPath,\n\t\t\t\tthis.poller,\n\t\t\t\t() => this.getRootProbes(entry),\n\t\t\t\tgitDirProbesByEmittedPath,\n\t\t\t\t(event, probe) => {\n\t\t\t\t\tif (entry.target !== target) return;\n\n\t\t\t\t\tthis.onRootEvent(event, entry);\n\t\t\t\t\tif (probe.path === 'logs/HEAD' && !entry.coversCommon) {\n\t\t\t\t\t\tthis.onLinkedHeadMoved();\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t);\n\t\t\tentry.target = target;\n\t\t\tthis.poller.add(target);\n\t\t}\n\n\t\tif ((state === 'unwatchable') === (previous === 'unwatchable')) return;\n\n\t\t// The watch went down or came back: whatever changed meanwhile went unseen\n\t\tif (!initial) {\n\t\t\tthis.deliverOverflow(entry);\n\t\t\tif (entry.coversCommon) {\n\t\t\t\tthis.rebaselineWorktrees();\n\t\t\t}\n\t\t}\n\t\tentry.hooks.onUnwatchableChanged?.(entry.repoPath);\n\t}\n\n\tprivate setCommonReliability(state: FileWatcherReliability, initial?: boolean): void {\n\t\tconst previous = this._commonReliability;\n\t\tif (previous === state || this.poller == null) return;\n\n\t\tthis._commonReliability = state;\n\t\tif (state === 'reliable') {\n\t\t\tif (this._commonTarget != null) {\n\t\t\t\tthis.poller.delete(this._commonTarget);\n\t\t\t\tthis._commonTarget = undefined;\n\t\t\t}\n\t\t} else if (this._commonTarget == null) {\n\t\t\tconst target = new GitDirProbeTarget(\n\t\t\t\tthis.commonGitDir,\n\t\t\t\tthis.poller,\n\t\t\t\t() => this.getCommonProbes(),\n\t\t\t\tgitDirProbesByEmittedPath,\n\t\t\t\tevent => {\n\t\t\t\t\tif (this._commonTarget === target) {\n\t\t\t\t\t\tthis.onCommonEvent(event);\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t);\n\t\t\tthis._commonTarget = target;\n\t\t\tthis.poller.add(target);\n\t\t}\n\n\t\tif ((state === 'unwatchable') === (previous === 'unwatchable')) return;\n\n\t\tfor (const entry of this._sessions.values()) {\n\t\t\tif (entry.coversCommon) continue;\n\n\t\t\tif (!initial) {\n\t\t\t\tthis.deliverOverflow(entry);\n\t\t\t}\n\t\t\tentry.hooks.onUnwatchableChanged?.(entry.repoPath);\n\t\t}\n\t\tif (!initial) {\n\t\t\tthis.rebaselineWorktrees();\n\t\t}\n\t}\n\n\tprivate stopPolling(entry: SessionEntry): void {\n\t\tif (entry.target == null) return;\n\n\t\tthis.poller?.delete(entry.target);\n\t\tentry.target = undefined;\n\t}\n\n\t/**\n\t * A session rooted at the common dir polls the common files too, with the refs of every session in the group: its\n\t * combined watcher would hear them all. While the common dir is polled too, the poller stats each shared file once\n\t * for both, and each keeps its own readings, so what one watcher reported is held back from its own sessions only\n\t */\n\tprivate getRootProbes(entry: SessionEntry): readonly GitDirProbe[] {\n\t\tif (!entry.coversCommon) return gitDirRootProbes;\n\n\t\tconst refs = new Set<string>();\n\t\tfor (const e of this._sessions.values()) {\n\t\t\tfor (const ref of e.hooks.getProbeRefs?.() ?? []) {\n\t\t\t\trefs.add(ref);\n\t\t\t}\n\t\t}\n\t\treturn [...gitDirRootProbes, ...gitDirCommonProbes, ...getGitDirRefProbes(refs)];\n\t}\n\n\t/**\n\t * A linked worktree's `logs/HEAD` moved — a commit or reset there, on a branch a polled session rooted at the common\n\t * dir may not probe — so each such session hears a `heads` change its combined watcher would have heard\n\t */\n\tprivate onLinkedHeadMoved(): void {\n\t\tfor (const entry of this._sessions.values()) {\n\t\t\tif (!entry.coversCommon || entry.target == null) continue;\n\n\t\t\tentry.hooks.onRepoChanged(entry.repoPath, ['heads']);\n\t\t}\n\t}\n\n\t/** The common files, with the refs of every linked session (the only ones the common watcher delivers to) */\n\tprivate getCommonProbes(): GitDirProbe[] {\n\t\tconst refs = new Set<string>();\n\t\tfor (const entry of this._sessions.values()) {\n\t\t\tif (entry.coversCommon) continue;\n\n\t\t\tfor (const ref of entry.hooks.getProbeRefs?.() ?? []) {\n\t\t\t\trefs.add(ref);\n\t\t\t}\n\t\t}\n\t\treturn [...gitDirCommonProbes, ...getGitDirRefProbes(refs)];\n\t}\n\n\tprivate onCommonEvent(event: FileWatchEvent): void {\n\t\tif (event.reason === 'overflow') {\n\t\t\tfor (const entry of this._sessions.values()) {\n\t\t\t\tif (entry.coversCommon) continue;\n\n\t\t\t\tthis.deliverOverflow(entry);\n\t\t\t}\n\t\t\tthis.rebaselineWorktrees();\n\t\t\treturn;\n\t\t}\n\n\t\t// Compute relative path from common git dir\n\t\tif (!isDescendant(event.path, this.commonGitDir)) return;\n\n\t\tconst relativePath = relative(this.commonGitDir, event.path);\n\t\tif (shouldIgnoreRepoPath(relativePath)) return;\n\n\t\tif (this.readFile != null && isConfigFile(relativePath)) {\n\t\t\tthis.onConfigReported();\n\t\t\treturn;\n\t\t}\n\n\t\tconst isFetchHead = relativePath === 'FETCH_HEAD';\n\t\tconst isExclude = relativePath === 'info/exclude';\n\t\tconst changes = isFetchHead\n\t\t\t? undefined\n\t\t\t: withWorktreeEntryHead(classifyGitDirChange(relativePath), relativePath, event.reason);\n\t\tif (changes == null && !isFetchHead && !isExclude) return;\n\n\t\tconst ref = changes != null ? getChangedRef(relativePath) : undefined;\n\n\t\t// `worktrees/<n>/HEAD`: the owner hears its own HEAD from its root watcher. Its `locked` and `gitdir` aren't in\n\t\t// the root glob, so the owner hears those only from here\n\t\tconst ownerId = changes != null ? getMovedWorktreeId(relativePath) : undefined;\n\t\tconst movedWorktree = getReportedWorktreeId(relativePath, changes);\n\n\t\tif (changes != null && this.isWorktreesReport(changes)) {\n\t\t\tconst sessions = [...this._sessions.values()].filter(\n\t\t\t\te => !e.coversCommon && (ownerId == null || e.worktreeId !== ownerId),\n\t\t\t);\n\t\t\tthis.onWorktreesReported(relativePath, event.reason, () => {\n\t\t\t\tfor (const entry of sessions) {\n\t\t\t\t\tif (this._disposed || this._sessions.get(entry.repoPath) !== entry) continue;\n\n\t\t\t\t\tdeliverRepoChanged(entry, changes, ref, movedWorktree);\n\t\t\t\t}\n\t\t\t});\n\t\t\treturn;\n\t\t}\n\n\t\tfor (const entry of this._sessions.values()) {\n\t\t\t// A session rooted at the common dir sees every common file (hooks included) through its own\n\t\t\t// combined root watcher, so delivering here too would duplicate it\n\t\t\tif (entry.coversCommon) continue;\n\n\t\t\tif (isFetchHead) {\n\t\t\t\t// FETCH_HEAD lives in the main .git dir; each worktree updates its last-fetched state\n\t\t\t\tentry.hooks.onFetchHeadChanged?.(entry.repoPath);\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tif (changes != null && (ownerId == null || entry.worktreeId !== ownerId)) {\n\t\t\t\tdeliverRepoChanged(entry, changes, ref, movedWorktree);\n\t\t\t}\n\n\t\t\tif (isExclude) {\n\t\t\t\tentry.hooks.onIgnoresChanged?.(entry.repoPath);\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate deliverOverflow(entry: SessionEntry): void {\n\t\t// Every kind, no ref (ref kinds stay unnamed). Never `'unknown'` — the cache would unregister the path\n\t\tentry.hooks.onRepoChanged(entry.repoPath, [...allWatchedRepositoryChanges], undefined, true);\n\t\tentry.hooks.onFetchHeadChanged?.(entry.repoPath);\n\t\tentry.hooks.onIgnoresChanged?.(entry.repoPath);\n\t}\n\n\tprivate onRootEvent(event: FileWatchEvent, entry: SessionEntry): void {\n\t\tif (event.reason === 'overflow') {\n\t\t\tthis.deliverOverflow(entry);\n\t\t\tif (entry.coversCommon) {\n\t\t\t\tthis.rebaselineWorktrees();\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\tif (!isDescendant(event.path, entry.gitDirPath)) return;\n\n\t\tconst relativePath = relative(entry.gitDirPath, event.path);\n\t\tif (shouldIgnoreRepoPath(relativePath)) return;\n\n\t\t// Check for FETCH_HEAD before interpretation\n\t\tif (relativePath === 'FETCH_HEAD') {\n\t\t\tentry.hooks.onFetchHeadChanged?.(entry.repoPath);\n\t\t\treturn;\n\t\t}\n\n\t\t// A linked worktree's git dir isn't the common one, so no file there is the shared config\n\t\tif (entry.coversCommon && this.readFile != null && isConfigFile(relativePath)) {\n\t\t\tthis.onConfigReported();\n\t\t\treturn;\n\t\t}\n\n\t\tconst changes = withWorktreeEntryHead(classifyGitDirChange(relativePath), relativePath, event.reason);\n\t\t// A linked worktree's git dir isn't the common one, so no path there is a worktree's admin entry\n\t\tconst movedWorktree = entry.coversCommon ? getReportedWorktreeId(relativePath, changes) : undefined;\n\t\tif (changes != null && entry.coversCommon && this.isWorktreesReport(changes)) {\n\t\t\tthis.onWorktreesReported(relativePath, event.reason, () => {\n\t\t\t\tif (this._disposed || this._sessions.get(entry.repoPath) !== entry) return;\n\n\t\t\t\tdeliverRepoChanged(entry, changes, getChangedRef(relativePath), movedWorktree);\n\t\t\t});\n\t\t} else if (changes != null) {\n\t\t\tdeliverRepoChanged(entry, changes, getChangedRef(relativePath), movedWorktree);\n\t\t}\n\n\t\tif (relativePath === 'info/exclude') {\n\t\t\tentry.hooks.onIgnoresChanged?.(entry.repoPath);\n\t\t}\n\t}\n\n\t/** A report of the `worktrees` directory, an admin entry or a file in it, once the group may tell them apart */\n\tprivate isWorktreesReport(changes: readonly RepositoryChange[]): boolean {\n\t\treturn (\n\t\t\tthis._worktreesBaseline != null &&\n\t\t\tchanges.includes('worktrees') &&\n\t\t\tchanges.every(c => c === 'worktrees' || c === 'worktreeHead')\n\t\t);\n\t}\n\n\t/** `deliver` tells the sessions the report reaches of it, should the report concern them (see above) */\n\tprivate onWorktreesReported(relativePath: string, reason: FileWatchEvent['reason'], deliver: () => void): void {\n\t\tif (this._worktreesBaselining && this._worktreesBaseline != null) {\n\t\t\t// The baseline may have read the entry before the change reported, so the report is told; it is still decided\n\t\t\t// once the baseline settles, so what is known of the entry catches up with it\n\t\t\tdeliver();\n\t\t\tvoid this._worktreesBaseline.then(() => this.decideWorktreesReport(relativePath, reason, noop));\n\t\t\treturn;\n\t\t}\n\n\t\tthis.decideWorktreesReport(relativePath, reason, deliver);\n\t}\n\n\tprivate decideWorktreesReport(relativePath: string, reason: FileWatchEvent['reason'], deliver: () => void): void {\n\t\tif (this._disposed) return;\n\t\tif (!this._ignoredWorktreeRoots.length) {\n\t\t\tdeliver();\n\t\t\treturn;\n\t\t}\n\n\t\tif (relativePath === 'worktrees') {\n\t\t\tthis.queueWorktreesRescan(reason, deliver);\n\t\t\treturn;\n\t\t}\n\n\t\tconst entry = parseWorktreeAdminPath(relativePath);\n\t\tif (entry == null) {\n\t\t\tdeliver();\n\t\t\treturn;\n\t\t}\n\n\t\tconst { id, file } = entry;\n\n\t\t// Only the entry or its `gitdir` going is a removal: an unlock deletes `locked` from an entry that stays, and a\n\t\t// watcher may report git's lock file renamed over `HEAD` as `HEAD` deleted and created again\n\t\tif (reason === 'delete' && (file == null || file === 'gitdir')) {\n\t\t\tif (this.forgetWorktreeId(id) !== true) {\n\t\t\t\tdeliver();\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\t// What a removed entry was decides the removal's other reports. Any other report of its id is read: one that finds\n\t\t// the entry is of an entry created again, which may be another worktree's. One that can't is the removal's own\n\t\t// unless it creates the entry, since a watcher may report the entry's directory changed beside each file the\n\t\t// removal deletes\n\t\tconst removed = this._worktreeIds.has(id) ? undefined : this._removedWorktreeIds.get(id);\n\t\tconst known = this._worktreeIds.get(id) ?? (reason === 'delete' ? removed : undefined);\n\t\t// Only a new entry or a written `gitdir` can name another worktree; anything else is told as the id is known\n\t\tif (known != null && file !== 'gitdir' && !(file == null && reason === 'create')) {\n\t\t\tif (!known) {\n\t\t\t\tdeliver();\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\tconst retry = removed == null || reason === 'create';\n\t\tvoid this.readWorktreeId(id, retry).then(([ignored, previous]) => {\n\t\t\tif (this._disposed) return;\n\n\t\t\tif (ignored == null) {\n\t\t\t\tif (retry) {\n\t\t\t\t\tvoid this.waitForWorktreeRetry(id, deliver);\n\t\t\t\t} else if (removed === false) {\n\t\t\t\t\tdeliver();\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Moved into or out of an ignored folder: every session's list gained or lost it\n\t\t\tif (previous != null && ignored !== previous) {\n\t\t\t\tthis.deliverWorktreesChange();\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (!ignored) {\n\t\t\t\tdeliver();\n\t\t\t}\n\t\t});\n\t}\n\n\t/**\n\t * Reads the entry's `gitdir`: whether it names an ignored worktree (`undefined` when it can't be read), and what the\n\t * id was known to be when this read replaced it. Reads of one id can settle out of order (a slow one from before the\n\t * worktree moved out of the folder), so only the latest updates what is known of it; an earlier one settles with\n\t * what the latest finds, without what the id was, since the latest tells a move itself, or once the entry was removed\n\t * since, with what the removal found it was. One that can't read the entry forgets what it was known to be, since git\n\t * may be writing its `gitdir` again, and reads it once more a moment later, unless `retry` is false (it then leaves\n\t * what is known as it was); one that can settles that read, if pending.\n\t */\n\tprivate readWorktreeId(\n\t\tid: string,\n\t\tretry: boolean = true,\n\t): Promise<[ignored: boolean | undefined, previous: boolean | undefined]> {\n\t\tconst read: Promise<[ignored: boolean | undefined, previous: boolean | undefined]> = this.readIgnoredWorktree(\n\t\t\tid,\n\t\t).then(ignored => {\n\t\t\tconst latest = this._worktreeReads.get(id);\n\t\t\tif (latest !== read) {\n\t\t\t\tif (latest == null) return [this._removedWorktreeIds.get(id), undefined];\n\n\t\t\t\treturn latest.then(([found]): [boolean | undefined, undefined] => {\n\t\t\t\t\t// A later read that couldn't read the entry may not read it again, but this one's report may be of\n\t\t\t\t\t// the entry created again, unless it was removed since\n\t\t\t\t\tif (found == null && retry && this._worktreeReads.has(id)) {\n\t\t\t\t\t\tthis.scheduleWorktreeRetry(id, undefined);\n\t\t\t\t\t}\n\t\t\t\t\treturn [found, undefined];\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tconst previous = this._worktreeIds.get(id);\n\t\t\tif (ignored == null) {\n\t\t\t\tif (!retry) return [undefined, previous];\n\n\t\t\t\tthis._removedWorktreeIds.delete(id);\n\t\t\t\tthis._worktreeIds.delete(id);\n\t\t\t\tthis.scheduleWorktreeRetry(id, previous);\n\t\t\t\treturn [undefined, previous];\n\t\t\t}\n\n\t\t\tthis._removedWorktreeIds.delete(id);\n\t\t\tthis._worktreeIds.set(id, ignored);\n\t\t\tthis.settleWorktreeRetry(id, ignored);\n\t\t\treturn [ignored, previous];\n\t\t});\n\t\tthis._worktreeReads.set(id, read);\n\t\treturn read;\n\t}\n\n\t/** Reads the entry once more a moment later, unless that is already pending; `previous` is what it was known to be */\n\tprivate scheduleWorktreeRetry(id: string, previous: boolean | undefined): void {\n\t\tif (this._disposed) return;\n\n\t\tconst pending = this._worktreeRetries.get(id);\n\t\tif (pending != null) {\n\t\t\tpending.previous ??= previous;\n\t\t\treturn;\n\t\t}\n\n\t\tlet resolve!: (ignored: boolean | undefined) => void;\n\t\tconst decided = new Promise<boolean | undefined>(r => {\n\t\t\tresolve = r;\n\t\t});\n\t\tconst timer = setTimeout(() => {\n\t\t\tvoid this.readWorktreeId(id).then(([ignored]) => {\n\t\t\t\t// A removal, or a later read that could read the entry, may have settled it meanwhile\n\t\t\t\tif (this._worktreeRetries.get(id)?.decided === decided) {\n\t\t\t\t\tthis.settleWorktreeRetry(id, ignored);\n\t\t\t\t}\n\t\t\t});\n\t\t}, worktreeRetryDelayMs);\n\t\tthis._worktreeRetries.set(id, {\n\t\t\ttimer: timer,\n\t\t\tdelivers: [],\n\t\t\tprevious: previous,\n\t\t\tdecided: decided,\n\t\t\tresolve: resolve,\n\t\t});\n\t}\n\n\t/**\n\t * A report whose read couldn't read the entry waits on the entry's next read, and `deliver` is told then, unless that\n\t * read finds an ignored worktree's; one still unreadable is told. Both watchers report each change of an entry, so\n\t * the reports of one id wait on one read. Resolves with what it found, as {@link settleWorktreeRetry} does\n\t */\n\tprivate waitForWorktreeRetry(id: string, deliver?: () => void): Promise<boolean | undefined> {\n\t\t// A later read may already have found what the entry is\n\t\tconst known = this._worktreeIds.get(id);\n\t\tif (known != null) {\n\t\t\tif (!known) {\n\t\t\t\tdeliver?.();\n\t\t\t}\n\t\t\treturn Promise.resolve(known);\n\t\t}\n\n\t\t// None is pending only when the entry was removed since, and the removal is told itself\n\t\tconst retry = this._worktreeRetries.get(id);\n\t\tif (retry == null) return Promise.resolve(undefined);\n\n\t\tif (deliver != null) {\n\t\t\tretry.delivers.push(deliver);\n\t\t}\n\t\treturn retry.decided;\n\t}\n\n\t/**\n\t * Tells the reports waiting on the id's retry what the entry turned out to be: nothing when an ignored worktree's,\n\t * every session when it moved into or out of an ignored folder, and the reports' own sessions otherwise, `ignored`\n\t * being `undefined` when it still couldn't be read\n\t */\n\tprivate settleWorktreeRetry(id: string, ignored: boolean | undefined): void {\n\t\tconst pending = this._worktreeRetries.get(id);\n\t\tif (pending == null) return;\n\n\t\tthis._worktreeRetries.delete(id);\n\t\tclearTimeout(pending.timer);\n\t\t// Settled before any session is told: a listing waits on it, and a hook that throws would otherwise hold back\n\t\t// every later listing for good\n\t\tpending.resolve(ignored);\n\t\tif (ignored != null && pending.previous != null && ignored !== pending.previous) {\n\t\t\tthis.deliverWorktreesChange();\n\t\t} else if (ignored !== true) {\n\t\t\tfor (const deliver of pending.delivers) {\n\t\t\t\tdeliver();\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Takes `id` as removed, remembering what it was for the removal's other reports; returns that, or `undefined` when\n\t * the id was never known\n\t */\n\tprivate forgetWorktreeId(id: string): boolean | undefined {\n\t\t// A read still in flight read the entry before it went, and would bring the removed id back as known\n\t\tthis._worktreeReads.delete(id);\n\n\t\tlet ignored = this._worktreeIds.get(id);\n\t\t// The reports waiting to read the entry again are dropped: the removal is told for what the id was, which only\n\t\t// the retry still knows once a read couldn't read the entry\n\t\tconst retry = this._worktreeRetries.get(id);\n\t\tif (retry != null) {\n\t\t\tthis._worktreeRetries.delete(id);\n\t\t\tclearTimeout(retry.timer);\n\t\t\tretry.resolve(undefined);\n\t\t\tignored ??= retry.previous;\n\t\t}\n\n\t\tif (ignored == null) return this._removedWorktreeIds.get(id);\n\n\t\tthis._worktreeIds.delete(id);\n\t\tthis._removedWorktreeIds.delete(id);\n\t\tthis._removedWorktreeIds.set(id, ignored);\n\t\tif (this._removedWorktreeIds.size > removedWorktreeIdsLimit) {\n\t\t\tconst [oldest] = this._removedWorktreeIds.keys();\n\t\t\tthis._removedWorktreeIds.delete(oldest);\n\t\t}\n\t\treturn ignored;\n\t}\n\n\t/** Whether the entry's `gitdir` names an ignored worktree, or `undefined` when it can't be read. Never rejects */\n\tprivate async readIgnoredWorktree(id: string): Promise<boolean | undefined> {\n\t\tconst adminDir = joinPaths(this.commonGitDir, 'worktrees', id);\n\t\tconst content = await this.readWithTimeout(joinPaths(adminDir, 'gitdir'));\n\t\treturn isIgnoredWorktreeEntry(adminDir, content, this._ignoredWorktreeRoots);\n\t}\n\n\tprivate queueWorktreesBaseline(take: () => Promise<void>): void {\n\t\tthis._worktreesBaselining = true;\n\t\tconst baseline: Promise<void> = this._worktreesQueue\n\t\t\t.then(take)\n\t\t\t.catch(() => {})\n\t\t\t.finally(() => {\n\t\t\t\tif (this._worktreesBaseline === baseline) {\n\t\t\t\t\tthis._worktreesBaselining = false;\n\t\t\t\t}\n\t\t\t});\n\t\tthis._worktreesBaseline = baseline;\n\t\tthis._worktreesQueue = baseline;\n\t}\n\n\t/** A watcher of the `worktrees` directory dropped events: whatever changed meanwhile went unseen */\n\tprivate rebaselineWorktrees(): void {\n\t\tif (this._worktreesBaseline == null || this._worktreesRebaselineQueued || this._disposed) return;\n\t\t// The first baseline found no folder to ignore, and none is asked for again, so there is nothing to retake\n\t\tif (!this._worktreesBaselining && !this._ignoredWorktreeRoots.length) return;\n\n\t\tthis._worktreesRebaselineQueued = true;\n\t\tthis.queueWorktreesBaseline(async () => {\n\t\t\tthis._worktreesRebaselineQueued = false;\n\t\t\tif (this._disposed || !this._ignoredWorktreeRoots.length) return;\n\n\t\t\tawait this.listWorktrees('rebaseline');\n\t\t});\n\t}\n\n\t/** The watchers' reports of the directory pile onto one queued listing, which tells them apart */\n\tprivate queueWorktreesRescan(reason: FileWatchEvent['reason'], deliver: () => void): void {\n\t\tconst queued = this._worktreesRescanQueued;\n\t\tif (queued != null) {\n\t\t\tqueued.delivers.push(deliver);\n\t\t\tqueued.removal ||= reason === 'delete';\n\t\t\treturn;\n\t\t}\n\n\t\tconst rescan = { delivers: [deliver], removal: reason === 'delete' };\n\t\tthis._worktreesRescanQueued = rescan;\n\t\tthis._worktreesQueue = this._worktreesQueue\n\t\t\t.then(() => {\n\t\t\t\tthis._worktreesRescanQueued = undefined;\n\t\t\t\treturn this.listWorktrees('rescan', rescan.delivers, rescan.removal);\n\t\t\t})\n\t\t\t.catch(() => {});\n\t}\n\n\t/**\n\t * Lists the admin entries and compares them with the last listing. A baseline (or a rebaseline, after a watcher\n\t * dropped events) reads every entry; a rescan only those it doesn't know, reading one it can't read once more a\n\t * moment later. Git removes the directory with its last entry, so a directory that isn't there is an empty listing,\n\t * whatever the reports said of it (a poll sees its removal as a change). A listing that fails otherwise is a\n\t * baseline's empty directory, and a rescan's too when one of its reports (`delivers`) removed the directory. For any\n\t * other rescan, it is a change it can't rule out, told to the reports' own sessions\n\t */\n\tprivate async listWorktrees(\n\t\tmode: 'baseline' | 'rebaseline' | 'rescan',\n\t\tdelivers?: readonly (() => void)[],\n\t\tremoval?: boolean,\n\t): Promise<void> {\n\t\tconst readDirectory = this.readDirectory;\n\t\tif (readDirectory == null) return;\n\n\t\tconst entries = await this.withTimeout(() =>\n\t\t\treadDirectory(joinPaths(this.commonGitDir, 'worktrees')).catch((ex: unknown) => {\n\t\t\t\tif (isNotFound(ex)) return [];\n\n\t\t\t\tthrow ex;\n\t\t\t}),\n\t\t);\n\t\tif (this._disposed) return;\n\n\t\t// An admin entry is a directory, so a stray file such as `.DS_Store` is none\n\t\tconst names = entries?.filter(([, type]) => type & FileType.Directory).map(([name]) => name);\n\n\t\tif (names == null && mode === 'rescan' && !removal) {\n\t\t\tfor (const deliver of delivers ?? []) {\n\t\t\t\tdeliver();\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\tconst listing = new Set(names);\n\t\tconst previous = this._listedWorktreeIds;\n\t\tthis._listedWorktreeIds = listing;\n\n\t\tlet changed = false;\n\t\tif (mode !== 'baseline') {\n\t\t\t// An entry known only from its own reports since the last listing may be gone too\n\t\t\tfor (const id of new Set([...previous, ...this._worktreeIds.keys()])) {\n\t\t\t\tif (listing.has(id)) continue;\n\n\t\t\t\tif (this.forgetWorktreeId(id) !== true) {\n\t\t\t\t\tchanged = true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tconst reads = await Promise.all(\n\t\t\t[...listing]\n\t\t\t\t.filter(id => mode !== 'rescan' || (!previous.has(id) && !this._worktreeIds.has(id)))\n\t\t\t\t.map(async id => {\n\t\t\t\t\tconst [ignored, known] = await this.readWorktreeId(id);\n\t\t\t\t\tif (ignored != null || mode !== 'rescan' || this._disposed) return [id, [ignored, known]] as const;\n\n\t\t\t\t\t// An entry listed before its `gitdir` is written won't be listed as new again\n\t\t\t\t\treturn [id, [await this.waitForWorktreeRetry(id), undefined]] as const;\n\t\t\t\t}),\n\t\t);\n\t\tif (this._disposed || mode === 'baseline') return;\n\n\t\tconst read = new Map(reads);\n\t\tfor (const id of listing) {\n\t\t\tconst result = read.get(id);\n\t\t\tif (!previous.has(id)) {\n\t\t\t\t// An entry whose `gitdir` still can't be read counts as real\n\t\t\t\tif ((result != null ? result[0] : this._worktreeIds.get(id)) !== true) {\n\t\t\t\t\tchanged = true;\n\t\t\t\t}\n\t\t\t} else if (result?.[0] != null && result[1] != null && result[0] !== result[1]) {\n\t\t\t\tchanged = true;\n\t\t\t}\n\t\t}\n\n\t\tif (changed) {\n\t\t\tthis.deliverWorktreesChange();\n\t\t}\n\t}\n\n\tprivate deliverWorktreesChange(): void {\n\t\tfor (const entry of this._sessions.values()) {\n\t\t\tentry.hooks.onRepoChanged(entry.repoPath, ['worktrees', 'worktreeHead'], undefined);\n\t\t}\n\t}\n\n\tprivate onConfigReported(): void {\n\t\t// The baseline may already hold the change reported, which comparing with it would lose\n\t\tif (this._configBaselining) {\n\t\t\tthis.deliverConfigChange(undefined);\n\t\t\treturn;\n\t\t}\n\t\tif (this._configReading) {\n\t\t\tthis._configRereadQueued = true;\n\t\t\treturn;\n\t\t}\n\n\t\tvoid this.readConfigChanges();\n\t}\n\n\tprivate async readConfigBaseline(): Promise<void> {\n\t\tthis._configBaselining = true;\n\t\tthis._configReading = true;\n\t\ttry {\n\t\t\tconst config = await this.readConfig();\n\t\t\tif (this._disposed) return;\n\n\t\t\tthis._config = config;\n\t\t} finally {\n\t\t\tthis._configBaselining = false;\n\t\t\tthis._configReading = false;\n\t\t}\n\t}\n\n\t/** Reads and compares until no report came in during the last read: it may describe a change the read missed */\n\tprivate async readConfigChanges(): Promise<void> {\n\t\tthis._configReading = true;\n\t\ttry {\n\t\t\tdo {\n\t\t\t\tthis._configRereadQueued = false;\n\t\t\t\tconst config = await this.readConfig();\n\t\t\t\tif (this._disposed) return;\n\n\t\t\t\tconst previous = this._config;\n\t\t\t\tif (config == null || previous == null) {\n\t\t\t\t\t// Unreadable now, or never readable before: the change may be anywhere. A failed read keeps the last\n\t\t\t\t\t// snapshot, so the next read still compares with what every session was told\n\t\t\t\t\tthis._config ??= config;\n\t\t\t\t\tthis.deliverConfigChange(undefined);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tthis._config = config;\n\t\t\t\tconst change = diffGitConfigSections(previous, config);\n\t\t\t\tif (change != null) {\n\t\t\t\t\tthis.deliverConfigChange(change);\n\t\t\t\t}\n\t\t\t} while (this._configRereadQueued);\n\t\t} finally {\n\t\t\tthis._configReading = false;\n\t\t}\n\t}\n\n\t/** `undefined` when the file couldn't be read or parsed, or the read didn't settle in time */\n\tprivate async readConfig(): Promise<GitConfigSections | undefined> {\n\t\tconst data = await this.readWithTimeout(joinPaths(this.commonGitDir, 'config'));\n\t\ttry {\n\t\t\treturn data != null ? parseGitConfigBytes(data) : undefined;\n\t\t} catch {\n\t\t\treturn undefined;\n\t\t}\n\t}\n\n\t/** `undefined` when the file couldn't be read, or the read didn't settle in time */\n\tprivate readWithTimeout(path: string): Promise<Uint8Array | undefined> {\n\t\tconst readFile = this.readFile;\n\t\tif (readFile == null) return Promise.resolve(undefined);\n\n\t\treturn this.withTimeout(() => readFile(path));\n\t}\n\n\t/** `undefined` when `read` rejects, or doesn't settle in time */\n\tprivate async withTimeout<T>(read: () => Promise<T>): Promise<T | undefined> {\n\t\tlet timer: ReturnType<typeof setTimeout> | undefined;\n\t\ttry {\n\t\t\treturn await Promise.race([\n\t\t\t\tread(),\n\t\t\t\tnew Promise<undefined>(resolve => {\n\t\t\t\t\ttimer = setTimeout(resolve, readTimeoutMs, undefined);\n\t\t\t\t}),\n\t\t\t]);\n\t\t} catch {\n\t\t\treturn undefined;\n\t\t} finally {\n\t\t\tclearTimeout(timer);\n\t\t}\n\t}\n\n\t/**\n\t * Tells every session of a change to the shared `.git/config`: confined to some branches' sections, or (`undefined`,\n\t * or a change outside them) anywhere, which may have changed a remote's settings too. Either way no ref moved\n\t */\n\tprivate deliverConfigChange(change: GitConfigSectionsChange | undefined): void {\n\t\tfor (const entry of this._sessions.values()) {\n\t\t\tif (change?.confined) {\n\t\t\t\tentry.hooks.onRepoChanged(entry.repoPath, ['config'], false, false, change.branches);\n\t\t\t} else {\n\t\t\t\tentry.hooks.onRepoChanged(entry.repoPath, ['config', 'remotes'], false);\n\t\t\t}\n\t\t}\n\t}\n}\n\n/**\n * `changes` with `worktreeHead` for a report that can stand for an entry's HEAD created or deleted with it: the\n * `worktrees` directory, an entry created or deleted, or its `gitdir` deleted. A watcher may coalesce the subtree a\n * removal deletes into one report of its parent, so no report of the HEAD comes. An entry's directory merely changed\n * stays `worktrees` alone: a watcher may report it beside each file in it, a lock's `locked` included\n */\nfunction withWorktreeEntryHead(\n\tchanges: RepositoryChange[] | undefined,\n\trelativePath: string,\n\treason: FileWatchEvent['reason'],\n): RepositoryChange[] | undefined {\n\tif (changes?.length !== 1 || changes[0] !== 'worktrees') return changes;\n\tif (relativePath === 'worktrees') return ['worktrees', 'worktreeHead'];\n\n\tconst idEnd = relativePath.indexOf('/', 10);\n\tif (idEnd === -1) return reason === 'create' || reason === 'delete' ? ['worktrees', 'worktreeHead'] : changes;\n\n\treturn reason === 'delete' && relativePath.substring(idEnd + 1) === 'gitdir'\n\t\t? ['worktrees', 'worktreeHead']\n\t\t: changes;\n}\n\n/** The admin id of the linked worktree whose `HEAD` file `relativePath` (relative to the common git dir) is */\nfunction getMovedWorktreeId(relativePath: string): string | undefined {\n\tconst entry = parseWorktreeAdminPath(relativePath);\n\treturn entry?.file === 'HEAD' ? entry.id : undefined;\n}\n\n/**\n * The admin id of the linked worktree a `worktreeHead` among `changes` is for: the entry `relativePath` (relative to the\n * common git dir) is, or is a file of\n */\nfunction getReportedWorktreeId(\n\trelativePath: string,\n\tchanges: readonly RepositoryChange[] | undefined,\n): string | undefined {\n\treturn changes?.includes('worktreeHead') ? parseWorktreeAdminPath(relativePath)?.id : undefined;\n}\n\n/** Tells `entry` of `changes`, naming the linked worktree whose HEAD moved only when the report knows it */\nfunction deliverRepoChanged(\n\tentry: SessionEntry,\n\tchanges: RepositoryChange[],\n\tref: string | false | undefined,\n\tmovedWorktree: string | undefined,\n): void {\n\tif (movedWorktree != null) {\n\t\tentry.hooks.onRepoChanged(entry.repoPath, changes, ref, undefined, undefined, movedWorktree);\n\t} else {\n\t\tentry.hooks.onRepoChanged(entry.repoPath, changes, ref);\n\t}\n}\n\n/** The path doesn't exist: Node's error, or the one VS Code's file system raises */\nexport function isNotFound(ex: unknown): boolean {\n\tconst code = (ex as { code?: unknown } | undefined)?.code;\n\treturn code === 'ENOENT' || code === 'FileNotFound';\n}\n\n/** The shared `.git/config` (or the lock git writes it through), relative to the common git dir */\nfunction isConfigFile(relativePath: string): boolean {\n\treturn relativePath === 'config' || relativePath === 'config.lock';\n}\n\n/**\n * The ref a `.git`-relative path names: a loose ref (or ref directory) under `refs/`, or the `HEAD`/`ORIG_HEAD`\n * pseudo-refs. A lock file names the ref it locks; the only ones classification lets through are the pseudo-refs' and\n * `refs/stash.lock`.\n */\nfunction getChangedRef(relativePath: string): string | false | undefined {\n\tconst ref = relativePath.endsWith('.lock') ? relativePath.substring(0, relativePath.length - 5) : relativePath;\n\t// Remote config still invalidates remote and branch caches, but doesn't itself move any ref.\n\tif (ref === 'config' || ref === 'config.worktree') return false;\n\n\treturn ref.startsWith('refs/') || ref === 'HEAD' || ref === 'ORIG_HEAD' ? ref : undefined;\n}\n"],"mappings":";;;;;;;;;;;;;;AAoCA,MAAM,gBAAgB;;;;;AAMtB,MAAM,0BAA0B;;;;;AAMhC,MAAM,uBAAuB;AAE7B,SAAS,OAAa,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqGvB,IAAa,aAAb,MAAqD;CAwE1C;CACQ;CAEA;CAKA;CAKA;CApFlB,4BAA6B,IAAI,IAA0B;CAC3D;CACA,qBAAqD;CACrD;CACA,YAAoB;;CAGpB;;CAEA,oBAA4B;CAC5B,iBAAyB;CACzB,sBAA8B;;;;;CAM9B;;CAEA,uBAA+B;CAC/B,6BAAqC;;CAErC,wBAAmD,CAAC;;CAEpD,kBAAyC,QAAQ,QAAQ;;CAEzD;;CAQA,qCAAkD,IAAI,IAAI;;CAE1D,+BAAgC,IAAI,IAAqB;;CAEzD,sCAAuC,IAAI,IAAqB;;;;;CAKhE,iCAAkC,IAAI,IAGpC;;CAEF,mCAAoC,IAAI,IAkBtC;;CAEF;CAEA,YACC,cACA,UAEA,QAKA,UAKA,eAEA,sBAEA,wBACC;EAlBQ,KAAA,eAAA;EACQ,KAAA,WAAA;EAEA,KAAA,SAAA;EAKA,KAAA,WAAA;EAKA,KAAA,gBAAA;EAMjB,MAAM,UAAU,iCAAiC,sBAAsB;EACvE,KAAK,wBAAwB,QAAQ,SAAS,CAAC,GAAG,gBAAgB,GAAG,OAAO,IAAI;EAChF,IAAI,YAAY,MACf,KAAU,mBAAmB;EAE9B,IAAI,YAAY,QAAQ,iBAAiB,QAAQ,wBAAwB,MACxE,KAAK,uBAAuB,YAAY;GACvC,MAAM,QAAQ,MAAM,KAAK,k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AAM,cAAc,MAAM,UAAU,SAAS,GAAG;AAExD;;AAGA,SAAgB,WAAW,IAAsB;CAChD,MAAM,OAAQ,IAAuC;CACrD,OAAO,SAAS,YAAY,SAAS;AACtC;;AAGA,SAAS,aAAa,cAA+B;CACpD,OAAO,iBAAiB,YAAY,iBAAiB;AACtD;;;;;;AAOA,SAAS,cAAc,cAAkD;CACxE,MAAM,MAAM,aAAa,SAAS,OAAO,IAAI,aAAa,UAAU,GAAG,aAAa,SAAS,CAAC,IAAI;CAElG,IAAI,QAAQ,YAAY,QAAQ,mBAAmB,OAAO;CAE1D,OAAO,IAAI,WAAW,OAAO,KAAK,QAAQ,UAAU,QAAQ,cAAc,MAAM,KAAA;AACjF"}
@@ -141,6 +141,18 @@ export declare class RepositoryWatchService implements UnifiedDisposable {
141
141
  repoPath: string;
142
142
  mode: 'events' | 'poll';
143
143
  }>;
144
+ private readonly _onDidChangeRepoWatched;
145
+ /**
146
+ * Fires as a repository's `.git` directory starts being watched (its session's first repo subscriber connected it
147
+ * to its watch group) and as it stops (its last one left, or its session was disposed); see {@link isRepoWatched}.
148
+ * `repoPath` is the session's key ({@link getRepositoryKey}). Never fires as the service itself is disposed, nor as
149
+ * the session suspends or resumes: a suspended session still reports what it held once it resumes, so there is
150
+ * nothing to hand off, and {@link isRepoWatched} answers `false` meanwhile without announcing it.
151
+ */
152
+ get onDidChangeRepoWatched(): Event<{
153
+ repoPath: string;
154
+ watched: boolean;
155
+ }>;
144
156
  private readonly defaultRepoDelayMs?;
145
157
  private readonly defaultWorkingTreeDelayMs?;
146
158
  private readonly defaultRepoMaxWaitMs?;
@@ -192,6 +204,14 @@ export declare class RepositoryWatchService implements UnifiedDisposable {
192
204
  readonly configConfinedToRefs?: boolean;
193
205
  readonly movedWorktrees?: readonly string[];
194
206
  }): void;
207
+ /**
208
+ * Whether `repoPath`'s `.git` directory is watched: its session has a repo subscriber, so it is connected to its
209
+ * watch group (natively, or polled in place of a watcher that can't be trusted). A session with only working-tree
210
+ * subscribers, or none, doesn't count, nor does a suspended one: it holds what its watcher hears until it resumes,
211
+ * and the poller doesn't poll meanwhile, so a read is served stale. Suspending or resuming announces nothing (see
212
+ * {@link onDidChangeRepoWatched}).
213
+ */
214
+ isRepoWatched(repoPath: string): boolean;
195
215
  /** Get an existing session by repo path */
196
216
  getSession(repoPath: string): RepositoryWatchSession | undefined;
197
217
  /**
@@ -215,6 +235,9 @@ export declare class RepositoryWatchService implements UnifiedDisposable {
215
235
  private maybeDisposeWatchGroup;
216
236
  private connectToWatchGroup;
217
237
  private disconnectFromWatchGroup;
238
+ private isConnected;
239
+ /** Announces that `record` was just connected (`watched`) or disconnected, once that is what it is */
240
+ private fireRepoWatchedIfConnected;
218
241
  private computeWatchMode;
219
242
  private updateWatchMode;
220
243
  private startWorkingTreeWatcher;