@gitkraken/core-gitlens 0.32.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 (109) hide show
  1. package/CHANGELOG.md +42 -1
  2. package/dist/git/cache.d.ts +121 -15
  3. package/dist/git/cache.js +316 -74
  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/models/repositoryIdentities.d.ts +0 -1
  14. package/dist/git/models/repositoryIdentities.js +1 -4
  15. package/dist/git/models/repositoryIdentities.js.map +1 -1
  16. package/dist/git/providers/provider.d.ts +7 -0
  17. package/dist/git/providers/shared/remotes.js +2 -0
  18. package/dist/git/providers/shared/remotes.js.map +1 -1
  19. package/dist/git/remotes/gitlab.js +15 -9
  20. package/dist/git/remotes/gitlab.js.map +1 -1
  21. package/dist/git/service.js +4 -1
  22. package/dist/git/service.js.map +1 -1
  23. package/dist/git/utils/pullRequest.utils.d.ts +72 -1
  24. package/dist/git/utils/pullRequest.utils.js +99 -1
  25. package/dist/git/utils/pullRequest.utils.js.map +1 -1
  26. package/dist/git/utils/repository.utils.d.ts +16 -0
  27. package/dist/git/utils/repository.utils.js +37 -2
  28. package/dist/git/utils/repository.utils.js.map +1 -1
  29. package/dist/git/watching/changeEvent.d.ts +13 -3
  30. package/dist/git/watching/changeEvent.js +19 -4
  31. package/dist/git/watching/changeEvent.js.map +1 -1
  32. package/dist/git/watching/gitDirPoller.d.ts +10 -1
  33. package/dist/git/watching/gitDirPoller.js +9 -3
  34. package/dist/git/watching/gitDirPoller.js.map +1 -1
  35. package/dist/git/watching/unwatchedCacheValidator.d.ts +144 -0
  36. package/dist/git/watching/unwatchedCacheValidator.js +884 -0
  37. package/dist/git/watching/unwatchedCacheValidator.js.map +1 -0
  38. package/dist/git/watching/watchGroup.d.ts +6 -2
  39. package/dist/git/watching/watchGroup.js +35 -24
  40. package/dist/git/watching/watchGroup.js.map +1 -1
  41. package/dist/git/watching/watchService.d.ts +27 -1
  42. package/dist/git/watching/watchService.js +60 -17
  43. package/dist/git/watching/watchService.js.map +1 -1
  44. package/dist/git/watching/watchSession.d.ts +29 -12
  45. package/dist/git/watching/watchSession.js +52 -21
  46. package/dist/git/watching/watchSession.js.map +1 -1
  47. package/dist/git/watching/worktreeSummary.js +7 -7
  48. package/dist/git/watching/worktreeSummary.js.map +1 -1
  49. package/dist/git-cli/cliGitProvider.d.ts +28 -2
  50. package/dist/git-cli/cliGitProvider.js +63 -20
  51. package/dist/git-cli/cliGitProvider.js.map +1 -1
  52. package/dist/git-cli/exec/commandClassifier.d.ts +31 -1
  53. package/dist/git-cli/exec/commandClassifier.js +67 -16
  54. package/dist/git-cli/exec/commandClassifier.js.map +1 -1
  55. package/dist/git-cli/exec/git.d.ts +46 -2
  56. package/dist/git-cli/exec/git.js +87 -9
  57. package/dist/git-cli/exec/git.js.map +1 -1
  58. package/dist/git-cli/exec/gitDirResolver.d.ts +11 -0
  59. package/dist/git-cli/exec/gitDirResolver.js +34 -1
  60. package/dist/git-cli/exec/gitDirResolver.js.map +1 -1
  61. package/dist/git-cli/exec/gitQueue.js +2 -28
  62. package/dist/git-cli/exec/gitQueue.js.map +1 -1
  63. package/dist/git-cli/providers/branches.d.ts +1 -0
  64. package/dist/git-cli/providers/branches.js +21 -10
  65. package/dist/git-cli/providers/branches.js.map +1 -1
  66. package/dist/git-cli/providers/config.d.ts +15 -1
  67. package/dist/git-cli/providers/config.js +67 -22
  68. package/dist/git-cli/providers/config.js.map +1 -1
  69. package/dist/git-cli/providers/pausedOperations.d.ts +1 -0
  70. package/dist/git-cli/providers/pausedOperations.js +4 -0
  71. package/dist/git-cli/providers/pausedOperations.js.map +1 -1
  72. package/dist/git-cli/providers/revision.js +2 -0
  73. package/dist/git-cli/providers/revision.js.map +1 -1
  74. package/dist/git-cli/providers/worktrees.js +36 -10
  75. package/dist/git-cli/providers/worktrees.js.map +1 -1
  76. package/dist/git-cli/service.d.ts +25 -1
  77. package/dist/git-cli/service.js +46 -1
  78. package/dist/git-cli/service.js.map +1 -1
  79. package/dist/plus/ai/errors.d.ts +8 -2
  80. package/dist/plus/ai/errors.js +15 -3
  81. package/dist/plus/ai/errors.js.map +1 -1
  82. package/dist/plus/git-github/api/github.d.ts +51 -1
  83. package/dist/plus/git-github/api/github.js +276 -3
  84. package/dist/plus/git-github/api/github.js.map +1 -1
  85. package/dist/plus/git-github/models.d.ts +54 -1
  86. package/dist/plus/git-github/models.js +48 -3
  87. package/dist/plus/git-github/models.js.map +1 -1
  88. package/dist/plus/integrations/fieldPresence.d.ts +6 -1
  89. package/dist/plus/integrations/fieldPresence.js +19 -9
  90. package/dist/plus/integrations/fieldPresence.js.map +1 -1
  91. package/dist/plus/integrations/models/gitHostIntegration.d.ts +26 -1
  92. package/dist/plus/integrations/models/gitHostIntegration.js +51 -0
  93. package/dist/plus/integrations/models/gitHostIntegration.js.map +1 -1
  94. package/dist/plus/integrations/models/integration.d.ts +15 -2
  95. package/dist/plus/integrations/models/integration.js +1 -1
  96. package/dist/plus/integrations/models/integration.js.map +1 -1
  97. package/dist/plus/integrations/providers/github.d.ts +16 -1
  98. package/dist/plus/integrations/providers/github.js +53 -1
  99. package/dist/plus/integrations/providers/github.js.map +1 -1
  100. package/dist/plus/integrations/providers/gitlab/gitlab.d.ts +10 -0
  101. package/dist/plus/integrations/providers/gitlab/gitlab.js +62 -15
  102. package/dist/plus/integrations/providers/gitlab/gitlab.js.map +1 -1
  103. package/dist/plus/integrations/providers/gitlab/gitlab.utils.d.ts +8 -0
  104. package/dist/plus/integrations/providers/gitlab/gitlab.utils.js +32 -16
  105. package/dist/plus/integrations/providers/gitlab/gitlab.utils.js.map +1 -1
  106. package/dist/plus/integrations/reads/etag.js +11 -0
  107. package/dist/plus/integrations/reads/etag.js.map +1 -1
  108. package/docs/integrations.md +39 -6
  109. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"watchService.js","names":[],"sources":["../../../../git/src/watching/watchService.ts"],"sourcesContent":["import type { UnifiedDisposable } from '@gitlens/utils/disposable.js';\nimport type { Event } from '@gitlens/utils/event.js';\nimport { Emitter } from '@gitlens/utils/event.js';\nimport { isDescendant, relative } from '@gitlens/utils/path.js';\nimport type { ResourceUsage } from '@gitlens/utils/resourceUsage.js';\nimport { getRepositoryKey } from '@gitlens/utils/uri.js';\nimport type { GitDir, RepositoryChange } from '../models/repository.js';\nimport type { WatcherRepoChangeEvent } from './changeEvent.js';\nimport type { PollTarget } from './gitDirPoller.js';\nimport { GitDirPoller } from './gitDirPoller.js';\nimport type { GitIgnoreFilter } from './gitIgnoreFilter.js';\nimport type {\n\tFileWatcher,\n\tFileWatcherOptions,\n\tFileWatcherReliability,\n\tFileWatchEvent,\n\tFileWatchingProvider,\n} from './provider.js';\nimport { shouldIgnoreWorkingTreePath, workingTreeExcludes } from './watcherPatterns.js';\nimport type { WatchGroupHooks } from './watchGroup.js';\nimport { WatchGroup } from './watchGroup.js';\nimport { RepositoryWatchSession } from './watchSession.js';\n\n/**\n * Cap on paths held while the gitignore filter loads. Higher than the session's own cap because these are\n * pre-filter — most of a build's output is typically gitignored and would be discarded on replay, so a\n * tighter bound here would mark batches incomplete when they filter down to almost nothing.\n */\nconst maxBufferedWorkingTreePaths = 5000;\n\n/** Trailing debounce before the git-ignored directory set is re-read after an ignore rule changes */\nconst ignoredDirectoriesRefreshDelayMs = 500;\n\ninterface WorkingTreeWatcherEntry {\n\treadonly session: RepositoryWatchSession;\n\t/** The event handler shared by every watcher this entry has had — a re-created watcher reuses it */\n\treadonly onEvent: (event: FileWatchEvent) => void;\n\treadonly filter?: GitIgnoreFilter;\n\twatcher: FileWatcher;\n\t/** The git-ignored directories the live watcher was created excluding (on top of the static set) */\n\tignoredDirectories: readonly string[];\n\t/** Bumped by every ignore-rule change and by stopping; a read that lands under a different value is stale */\n\tgeneration: number;\n\treading: boolean;\n\t/** A refresh came due while a read was in flight */\n\trereadQueued: boolean;\n\trefreshTimer?: ReturnType<typeof setTimeout>;\n\t/** What the live watcher last reported; a re-created watcher starts over from its own report */\n\treliability: FileWatcherReliability;\n\t/** The live watcher has yet to call the `onDidStart` its provider promised (see `callsOnDidStart`) */\n\tstarting: boolean;\n\t/** Compares the host's working-tree fingerprint while the watcher isn't `reliable` */\n\tpollTarget?: PollTarget;\n\t/**\n\t * Git-ignored directories (repo-relative) whose events reached the post-filter, so the watcher isn't pruning them —\n\t * typically created after the last read (a first build's `dist/`). Each waits for a read that started after it.\n\t */\n\tunpruned?: Set<string>;\n\t/**\n\t * Directories a read showed git won't prune (they hold tracked files, or glob metacharacters in their names);\n\t * cleared when ignore rules change\n\t */\n\tunprunable?: Set<string>;\n}\n\n/**\n * A host whose watchers can report they can't be trusted (see `FileWatcherOptions.onDidChangeReliability`) passes\n * these to have core poll in their place. A `.git` directory is polled by statting the files its watchers read and\n * feeding each one that moved through the same interpretation as a watcher event; a working tree is never walked.\n */\nexport interface WatchPollingOptions {\n\t/**\n\t * Reads a path's modification time (ms) and size; `undefined` when it doesn't exist. A rejection means unknown:\n\t * the last reading stands, so it never counts as a change.\n\t */\n\treadonly stat: (path: string) => Promise<{ readonly mtime: number; readonly size: number } | undefined>;\n\t/** Whether a poll is worth running now. Default: the service isn't suspended (`suspendAll`/`resumeAll`) */\n\treadonly isActive?: () => boolean;\n\t/** How often each untrusted watcher is polled. Default: 60000ms */\n\treadonly intervalMs?: number;\n\t/**\n\t * How often `isActive` is looked at, which bounds how late the first poll after it turns true can be. Only with\n\t * `isActive`: the default gate wakes only for a poll. Default: 5000ms\n\t */\n\treadonly activeCheckMs?: number;\n\t/**\n\t * Refs to poll for a repository beyond its subscribers' `relevantRefs`: one with none (a host listing every branch)\n\t * still needs its checked-out branch's upstream, which a push moves without writing `FETCH_HEAD`\n\t */\n\treadonly getRefs?: (repoPath: string) => Iterable<string>;\n\t/**\n\t * Something that changes whenever the repository's working tree does (e.g. a digest of its status and the\n\t * changed files' stats), compared at each poll while working-tree subscribers are watching a working tree whose\n\t * watcher can't be trusted; a change is reported with no paths. `undefined` or a rejection skips that poll. With or\n\t * without it, a working tree whose watcher is `unwatchable` is reported changed (no paths) whenever its index or\n\t * `HEAD` changes.\n\t */\n\treadonly getWorkingTreeFingerprint?: (repoPath: string) => Promise<string | undefined>;\n}\n\nexport interface WatchServiceOptions {\n\treadonly watchingProvider: FileWatchingProvider;\n\t/** Default debounce for repo changes when subscriber doesn't specify. Default: 250ms */\n\treadonly defaultRepoDelayMs?: number;\n\t/** Default debounce for working tree changes when subscriber doesn't specify. Default: 2500ms */\n\treadonly defaultWorkingTreeDelayMs?: number;\n\t/** Default cap on how long continuous repo activity can defer a flush. `Infinity` disables it. Default: 2000ms */\n\treadonly defaultRepoMaxWaitMs?: number;\n\t/** Default cap on how long continuous working tree activity can defer a flush. `Infinity` disables it. Default: 10000ms */\n\treadonly defaultWorkingTreeMaxWaitMs?: number;\n\t/** Returns a GitIgnoreFilter for a given repo. When absent or returns undefined, gitignore filtering is skipped. */\n\treadonly getIgnoreFilter?: (repoPath: string, gitDirPath: string) => GitIgnoreFilter | undefined;\n\t/**\n\t * Returns the repo-relative directories an ignore rule matches, for a watching provider that prunes\n\t * `excludes` natively (`supportsExcludes`). Never called for one that doesn't. A rejection keeps the static set.\n\t */\n\treadonly getIgnoredDirectories?: (repoPath: string) => Promise<readonly string[]>;\n\t/**\n\t * Returns the absolute, normalized folders whose worktrees are ignored (see `GitProvider.getIgnoredWorktreeRoots`):\n\t * with a `readFile` and a `readDirectory`, the watcher's reports of their admin entries reach no session. Asked\n\t * once per common git dir, when its first session starts watching, and never without both. When absent, empty or\n\t * rejected, no admin entry is read.\n\t */\n\treadonly getIgnoredWorktreeRoots?: (repoPath: string) => Promise<readonly string[]>;\n\t/**\n\t * Returns the folders whose worktrees are ignored, relative to a repository's common git dir (see\n\t * `GitProvider.getIgnoredWorktreeFolders`): the `.git` watchers whose tree holds the common git dir leave\n\t * them unwatched. Asked once per common git dir, when its first session starts watching.\n\t */\n\treadonly getIgnoredWorktreeFolders?: (repoPath: string) => readonly string[];\n\t/** Opts into polling the watchers that report they can't be trusted. When absent, no watcher is asked. */\n\treadonly polling?: WatchPollingOptions;\n\t/**\n\t * Reads a file's bytes; a rejection means it couldn't be read. With it, each report of a repository's shared\n\t * `.git/config` is classified by what changed in the file: a change confined to some branches' `branch.<name>`\n\t * sections reaches only the subscribers following those branches, and carries no `remotes`. Without it, every\n\t * config change concerns everyone, as before.\n\t */\n\treadonly readFile?: (path: string) => Promise<Uint8Array>;\n\t/**\n\t * Returns a directory's entries with their types, as the host file system's `readDirectory` does; only the\n\t * directories count as admin entries (a stray `.DS_Store` is no worktree's). A rejection means it couldn't be\n\t * listed, and one whose `code` is `ENOENT` or `FileNotFound` that the directory isn't there. With it and a\n\t * `readFile`, the admin entries of a repository's worktrees are listed and read once as its first session starts\n\t * watching, so the reports of an ignored worktree's (see `getIgnoredWorktreeRoots`) reach no session, and the others\n\t * aren't held back.\n\t */\n\treadonly readDirectory?: (path: string) => Promise<readonly (readonly [string, number])[]>;\n}\n\nexport interface WatchHooks {\n\t/** Called when FETCH_HEAD changed (for last-fetched tracking) */\n\treadonly onFetchHeadChanged?: (repoPath: string) => void;\n\t/** Called when .git/info/exclude changed */\n\treadonly onIgnoresChanged?: (repoPath: string) => void;\n\t/** Called when .gitignore changed in the working tree (extension watches this separately) */\n\treadonly onGitIgnoreChanged?: (repoPath: string) => void;\n}\n\nexport interface WatchHandle {\n\treadonly session: RepositoryWatchSession;\n\tdispose(): void;\n}\n\ninterface SessionRecord {\n\treadonly session: RepositoryWatchSession;\n\treadonly gitDir: GitDir;\n\t/**\n\t * Hooks contributed by all current `watch()` callers for this repo path. Earlier\n\t * implementations stored just the first caller's hooks (`WatchHooks | undefined`) and\n\t * silently dropped subsequent callers' hooks — that broke the case where a low-level\n\t * subscriber (e.g. the Graph's secondary-worktree WIP watcher) opened the session\n\t * first without hooks, and a later `Repository.watch()` for the same path lost\n\t * its `markFetched` / `onIgnoresChanged` wiring. Each `watch()` call adds its hooks\n\t * to this set and removes them on dispose; fire sites iterate the set.\n\t */\n\treadonly watchHooks: Set<WatchHooks>;\n\trefCount: number;\n\t/** The mode {@link RepositoryWatchService.onDidChangeWatchMode} last announced; `'events'` while unwatched */\n\twatchMode: 'events' | 'poll';\n}\n\n/**\n * Global service that multiplexes repository watching across all repos.\n *\n * Manages:\n * - Session map: one `RepositoryWatchSession` per repo path (ref-counted)\n * - Watch groups: shared `.git` watchers across worktrees\n * - Working tree watchers: per-repo filesystem watchers with gitignore filtering\n *\n * Sessions and watch groups are created lazily on first `subscribe()`\n * within a session, and destroyed when the last subscriber leaves.\n */\nexport class RepositoryWatchService implements UnifiedDisposable {\n\tprivate readonly _onDidChangeRepository = new Emitter<WatcherRepoChangeEvent>();\n\t/** Global multiplexed event for ALL watched repos */\n\tget onDidChangeRepository(): Event<WatcherRepoChangeEvent> {\n\t\treturn this._onDidChangeRepository.event;\n\t}\n\n\tprivate readonly _onDidChangeWorkingTree = new Emitter<string>();\n\t/** Global multiplexed working-tree change event (repo path) for ALL watched repos. Fires once per\n\t * debounced flush per session — the single point that drives the cache's status clock for working-tree edits. */\n\tget onDidChangeWorkingTree(): Event<string> {\n\t\treturn this._onDidChangeWorkingTree.event;\n\t}\n\n\tprivate readonly _onDidChangeFetchHead = new Emitter<string>();\n\t/**\n\t * Global FETCH_HEAD change event (repo path) for ALL watched repos, fired as each change is seen (no debounce).\n\t * FETCH_HEAD maps to no {@link RepositoryChange} on the session, so this is how a host invalidates its cached\n\t * last-fetched time — the standalone service bridges it to the cache's `lastFetched`.\n\t */\n\tget onDidChangeFetchHead(): Event<string> {\n\t\treturn this._onDidChangeFetchHead.event;\n\t}\n\n\tprivate readonly _onDidChangeWatchMode = new Emitter<{ repoPath: string; mode: 'events' | 'poll' }>();\n\t/**\n\t * Fires as a watched repository starts being polled in place of a watcher (see {@link getWatchMode}), and with\n\t * `'events'` as it is watched natively again. Never fires as the repository stops being watched; one watched again\n\t * later starts from `'events'`.\n\t */\n\tget onDidChangeWatchMode(): Event<{ repoPath: string; mode: 'events' | 'poll' }> {\n\t\treturn this._onDidChangeWatchMode.event;\n\t}\n\n\tprivate readonly defaultRepoDelayMs?: number;\n\tprivate readonly defaultWorkingTreeDelayMs?: number;\n\tprivate readonly defaultRepoMaxWaitMs?: number;\n\tprivate readonly defaultWorkingTreeMaxWaitMs?: number;\n\tprivate readonly getIgnoreFilter?: (repoPath: string, gitDirPath: string) => GitIgnoreFilter | undefined;\n\tprivate readonly getIgnoredDirectories?: (repoPath: string) => Promise<readonly string[]>;\n\tprivate readonly getIgnoredWorktreeRoots?: (repoPath: string) => Promise<readonly string[]>;\n\tprivate readonly getIgnoredWorktreeFolders?: (repoPath: string) => readonly string[];\n\tprivate readonly provider: FileWatchingProvider;\n\tprivate readonly poller: GitDirPoller | undefined;\n\tprivate readonly readFile: ((path: string) => Promise<Uint8Array>) | undefined;\n\tprivate readonly readDirectory: ((path: string) => Promise<readonly (readonly [string, number])[]>) | undefined;\n\n\tprivate readonly sessionMap = new Map<string, SessionRecord>();\n\tprivate readonly watchGroups = new Map<string, WatchGroup>();\n\tprivate readonly wtWatchers = new Map<string, WorkingTreeWatcherEntry>();\n\t/**\n\t * The last git-ignored directory read under each filter's current rules, kept across a working-tree watcher's\n\t * stop and start so a restart can skip the read; dropped with the filter\n\t */\n\tprivate readonly keptIgnoredDirectories = new WeakMap<GitIgnoreFilter, readonly string[]>();\n\tprivate _disposed = false;\n\t/** Global suspend state (driven by window focus); inherited by sessions created via {@link watch}. */\n\tprivate _suspended = false;\n\n\tconstructor(options: WatchServiceOptions) {\n\t\tthis.provider = options.watchingProvider;\n\t\tthis.defaultRepoDelayMs = options.defaultRepoDelayMs;\n\t\tthis.defaultWorkingTreeDelayMs = options.defaultWorkingTreeDelayMs;\n\t\tthis.defaultRepoMaxWaitMs = options.defaultRepoMaxWaitMs;\n\t\tthis.defaultWorkingTreeMaxWaitMs = options.defaultWorkingTreeMaxWaitMs;\n\t\tthis.getIgnoreFilter = options.getIgnoreFilter;\n\t\tthis.getIgnoredDirectories = options.getIgnoredDirectories;\n\t\tthis.getIgnoredWorktreeRoots = options.getIgnoredWorktreeRoots;\n\t\tthis.getIgnoredWorktreeFolders = options.getIgnoredWorktreeFolders;\n\t\tthis.readFile = options.readFile;\n\t\tthis.readDirectory = options.readDirectory;\n\t\tif (options.polling != null) {\n\t\t\tthis.poller = new GitDirPoller(options.polling);\n\t\t}\n\t}\n\n\t[Symbol.dispose](): void {\n\t\tthis.dispose();\n\t}\n\n\tdispose(): void {\n\t\tif (this._disposed) return;\n\n\t\tthis._disposed = true;\n\n\t\tfor (const record of this.sessionMap.values()) {\n\t\t\tthis.disposeSessionRecord(record);\n\t\t}\n\t\tthis.sessionMap.clear();\n\n\t\tfor (const group of this.watchGroups.values()) {\n\t\t\tgroup.dispose();\n\t\t}\n\t\tthis.watchGroups.clear();\n\n\t\tfor (const repoPath of [...this.wtWatchers.keys()]) {\n\t\t\tthis.stopWorkingTreeWatcher(repoPath);\n\t\t}\n\n\t\tthis.poller?.dispose();\n\n\t\tthis._onDidChangeRepository.dispose();\n\t\tthis._onDidChangeWorkingTree.dispose();\n\t\tthis._onDidChangeFetchHead.dispose();\n\t\tthis._onDidChangeWatchMode.dispose();\n\t}\n\n\t/**\n\t * Start watching a repository. Reference-counted:\n\t * same repoPath → same session (refCount++).\n\t * Worktrees sharing a .git dir share the WatchGroup.\n\t *\n\t * Returns a handle with the session and a dispose function.\n\t * Disposing the handle decrements the ref count.\n\t *\n\t * `repoPath` is keyed by {@link getRepositoryKey}, and every session, event and hook carries that key — the\n\t * same one the cache fences status reads on — so a host passing `C:\\repo\\` and one passing `c:/repo` share\n\t * a session and advance the same status clock.\n\t */\n\twatch(repoPath: string, gitDir: GitDir, watchHooks?: WatchHooks): WatchHandle | undefined {\n\t\tif (this._disposed) return undefined;\n\n\t\trepoPath = getRepositoryKey(repoPath);\n\n\t\tlet record = this.sessionMap.get(repoPath);\n\t\tif (record != null) {\n\t\t\trecord.refCount++;\n\t\t\tif (watchHooks != null) {\n\t\t\t\trecord.watchHooks.add(watchHooks);\n\t\t\t}\n\t\t} else {\n\t\t\tconst session = new RepositoryWatchSession({\n\t\t\t\trepoPath: repoPath,\n\t\t\t\tdefaultRepoDelayMs: this.defaultRepoDelayMs,\n\t\t\t\tdefaultWorkingTreeDelayMs: this.defaultWorkingTreeDelayMs,\n\t\t\t\tdefaultRepoMaxWaitMs: this.defaultRepoMaxWaitMs,\n\t\t\t\tdefaultWorkingTreeMaxWaitMs: this.defaultWorkingTreeMaxWaitMs,\n\t\t\t\tsuspended: this._suspended,\n\t\t\t\tlifecycle: {\n\t\t\t\t\tonFirstRepoSubscriber: (): void => {\n\t\t\t\t\t\tconst rec = this.sessionMap.get(repoPath);\n\t\t\t\t\t\tif (rec != null) {\n\t\t\t\t\t\t\tthis.connectToWatchGroup(rec);\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t\tonLastRepoSubscriber: (): void => {\n\t\t\t\t\t\tconst rec = this.sessionMap.get(repoPath);\n\t\t\t\t\t\tif (rec != null) {\n\t\t\t\t\t\t\tthis.disconnectFromWatchGroup(rec);\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t\tonFirstWorkingTreeSubscriber: (): void => {\n\t\t\t\t\t\tconst rec = this.sessionMap.get(repoPath);\n\t\t\t\t\t\tif (rec != null) {\n\t\t\t\t\t\t\tthis.startWorkingTreeWatcher(rec);\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t\tonLastWorkingTreeSubscriber: (): void => {\n\t\t\t\t\t\tthis.stopWorkingTreeWatcher(repoPath);\n\t\t\t\t\t\tconst rec = this.sessionMap.get(repoPath);\n\t\t\t\t\t\tif (rec != null) {\n\t\t\t\t\t\t\tthis.updateWatchMode(rec);\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\tonDidFireRepoChange: (event): void => {\n\t\t\t\t\tthis._onDidChangeRepository.fire(event);\n\t\t\t\t},\n\t\t\t\tonDidFireWorkingTreeChange: (repoPath): void => {\n\t\t\t\t\tthis._onDidChangeWorkingTree.fire(repoPath);\n\t\t\t\t},\n\t\t\t});\n\n\t\t\tconst watchHooksSet = new Set<WatchHooks>();\n\t\t\tif (watchHooks != null) {\n\t\t\t\twatchHooksSet.add(watchHooks);\n\t\t\t}\n\n\t\t\trecord = {\n\t\t\t\tsession: session,\n\t\t\t\tgitDir: gitDir,\n\t\t\t\twatchHooks: watchHooksSet,\n\t\t\t\trefCount: 1,\n\t\t\t\twatchMode: 'events',\n\t\t\t};\n\t\t\tthis.sessionMap.set(repoPath, record);\n\t\t}\n\n\t\tconst sessionRef = record.session;\n\t\tlet handleDisposed = false;\n\n\t\treturn {\n\t\t\tsession: sessionRef,\n\t\t\tdispose: (): void => {\n\t\t\t\tif (handleDisposed) return;\n\n\t\t\t\thandleDisposed = true;\n\n\t\t\t\tconst rec = this.sessionMap.get(repoPath);\n\t\t\t\tif (rec == null) return;\n\n\t\t\t\trec.refCount--;\n\t\t\t\tif (watchHooks != null) {\n\t\t\t\t\trec.watchHooks.delete(watchHooks);\n\t\t\t\t}\n\t\t\t\tif (rec.refCount <= 0) {\n\t\t\t\t\tthis.sessionMap.delete(repoPath);\n\t\t\t\t\tthis.disposeSessionRecord(rec);\n\t\t\t\t}\n\t\t\t},\n\t\t};\n\t}\n\n\t/**\n\t * Core announced one of its own writes for `repoPath`; the session watching it fires the announcement in place of\n\t * the write's own `.git` events (see {@link RepositoryWatchSession.noteSelfWrite}); `refs` are the full ref names it\n\t * moved, when it knows them, and `options.configConfinedToRefs` confines its `config` change to the sections of the\n\t * local branches among them (see `GitServiceHooks.repository.onChanged`). A path no session watches is ignored.\n\t */\n\tnoteSelfWrite(\n\t\trepoPath: string,\n\t\tchanges: readonly RepositoryChange[],\n\t\trefs?: readonly string[],\n\t\toptions?: { readonly configConfinedToRefs?: boolean },\n\t): void {\n\t\tif (this._disposed) return;\n\n\t\tthis.sessionMap.get(getRepositoryKey(repoPath))?.session.noteSelfWrite(changes, refs, options);\n\t}\n\n\t/** Get an existing session by repo path */\n\tgetSession(repoPath: string): RepositoryWatchSession | undefined {\n\t\treturn this.sessionMap.get(getRepositoryKey(repoPath))?.session;\n\t}\n\n\t/**\n\t * Whether the working tree's watch has yet to go live, owing a rescan once it does (see\n\t * `FileWatchingProvider.callsOnDidStart`). Not while it's `unwatchable`: it rescans when it comes back.\n\t */\n\tisWorkingTreeStarting(repoPath: string): boolean {\n\t\tconst entry = this.wtWatchers.get(getRepositoryKey(repoPath));\n\t\treturn entry?.starting === true && entry.reliability !== 'unwatchable';\n\t}\n\n\t/**\n\t * `'poll'` while a watcher the repository is watched through — its `.git` watchers or its working tree's — can't\n\t * watch, and is polled instead; `'events'` while it is watched natively (polled beside an `unreliable` watcher\n\t * included); `undefined` when nothing watches it, which {@link onDidChangeWatchMode} doesn't announce.\n\t */\n\tgetWatchMode(repoPath: string): 'events' | 'poll' | undefined {\n\t\tconst record = this.sessionMap.get(getRepositoryKey(repoPath));\n\t\treturn record != null ? this.computeWatchMode(record) : undefined;\n\t}\n\n\t/** Resource usage retained by repository watchers. */\n\tgetResourceUsage(): ResourceUsage {\n\t\tconst usage: ResourceUsage = {\n\t\t\t'watch.sessions.count': this.sessionMap.size,\n\t\t\t'watch.groups.count': this.watchGroups.size,\n\t\t\t'watch.workingTreeWatchers.count': this.wtWatchers.size,\n\t\t};\n\t\tif (this.poller != null) {\n\t\t\tusage['watch.pollTargets.count'] = this.poller.size;\n\t\t}\n\t\treturn usage;\n\t}\n\n\t/** Suspend all sessions and mark the service suspended so late-joining sessions start suspended */\n\tsuspendAll(): void {\n\t\tthis._suspended = true;\n\t\tfor (const record of this.sessionMap.values()) {\n\t\t\trecord.session.suspend();\n\t\t}\n\t\tthis.poller?.suspend();\n\t}\n\n\t/** Resume all sessions (clearing the global suspend state), with optional per-session delay */\n\tresumeAll(getDelay?: (session: RepositoryWatchSession) => number): void {\n\t\tthis._suspended = false;\n\t\tfor (const record of this.sessionMap.values()) {\n\t\t\tconst delayMs = getDelay?.(record.session);\n\t\t\trecord.session.resume(delayMs);\n\t\t}\n\t\tthis.poller?.resume();\n\t}\n\n\tprivate getOrCreateWatchGroup(commonGitDir: string, repoPath: string): WatchGroup {\n\t\tlet group = this.watchGroups.get(commonGitDir);\n\t\tif (group == null) {\n\t\t\tgroup = new WatchGroup(\n\t\t\t\tcommonGitDir,\n\t\t\t\tthis.provider,\n\t\t\t\tthis.poller,\n\t\t\t\tthis.readFile,\n\t\t\t\tthis.readDirectory,\n\t\t\t\t// Only a group that can read the admin entries waits on the folders; asking otherwise reads for nothing,\n\t\t\t\t// and leaves a rejection unhandled\n\t\t\t\tthis.readFile != null && this.readDirectory != null\n\t\t\t\t\t? this.getIgnoredWorktreeRoots?.(repoPath)\n\t\t\t\t\t: undefined,\n\t\t\t\tthis.getIgnoredWorktreeFolders?.(repoPath),\n\t\t\t);\n\t\t\tthis.watchGroups.set(commonGitDir, group);\n\t\t}\n\t\treturn group;\n\t}\n\n\tprivate maybeDisposeWatchGroup(commonGitDir: string): void {\n\t\tconst group = this.watchGroups.get(commonGitDir);\n\t\tif (group == null) return;\n\n\t\tif (group.sessions.size === 0) {\n\t\t\tgroup.dispose();\n\t\t\tthis.watchGroups.delete(commonGitDir);\n\t\t}\n\t}\n\n\tprivate connectToWatchGroup(record: SessionRecord): void {\n\t\tconst { session, gitDir, watchHooks } = record;\n\t\tconst commonGitDir = (gitDir.commonUri ?? gitDir.uri).fsPath;\n\t\tconst group = this.getOrCreateWatchGroup(commonGitDir, session.repoPath);\n\n\t\tconst hooks: WatchGroupHooks = {\n\t\t\tonRepoChanged: (\n\t\t\t\t_repoPath: string,\n\t\t\t\tchanges: RepositoryChange[],\n\t\t\t\tref?: string | false,\n\t\t\t\toverflow?: boolean,\n\t\t\t\tconfigBranches?: ReadonlySet<string>,\n\t\t\t): void => {\n\t\t\t\tif (overflow) {\n\t\t\t\t\tsession.pushUnfencedRepoChanges(changes);\n\t\t\t\t} else {\n\t\t\t\t\tsession.pushRepoChanges(changes, ref, configBranches);\n\t\t\t\t}\n\n\t\t\t\t// A working tree nothing watches is read again whenever the index or HEAD says it may have moved\n\t\t\t\tif (\n\t\t\t\t\tthis.poller != null &&\n\t\t\t\t\t(changes.includes('index') || changes.includes('head')) &&\n\t\t\t\t\tthis.wtWatchers.get(session.repoPath)?.reliability === 'unwatchable'\n\t\t\t\t) {\n\t\t\t\t\tsession.pushWorkingTreeChanges([], true);\n\t\t\t\t}\n\t\t\t},\n\t\t\tonFetchHeadChanged: (repoPath: string): void => {\n\t\t\t\t// Global first, so a host's cache drops its last-fetched time before any hook re-reads it\n\t\t\t\tthis._onDidChangeFetchHead.fire(repoPath);\n\t\t\t\t// Iterate at fire time so callers that joined after the group was wired up\n\t\t\t\t// still receive events (e.g. a `Repository.watch()` whose hooks landed\n\t\t\t\t// after a hookless `GitRepositoryService.watch` registered first).\n\t\t\t\tfor (const h of watchHooks) {\n\t\t\t\t\th.onFetchHeadChanged?.(repoPath);\n\t\t\t\t}\n\t\t\t},\n\t\t\tonIgnoresChanged: (repoPath: string): void => {\n\t\t\t\tthis.refreshWorkingTreeFilter(repoPath);\n\t\t\t\tfor (const h of watchHooks) {\n\t\t\t\t\th.onIgnoresChanged?.(repoPath);\n\t\t\t\t}\n\t\t\t},\n\t\t\tgetProbeRefs: (): Iterable<string> => {\n\t\t\t\tconst refs = session.getRelevantRefs();\n\t\t\t\tfor (const ref of this.poller?.options.getRefs?.(session.repoPath) ?? []) {\n\t\t\t\t\trefs.add(ref);\n\t\t\t\t}\n\t\t\t\treturn refs;\n\t\t\t},\n\t\t\tonUnwatchableChanged: (): void => this.updateWatchMode(record),\n\t\t};\n\n\t\tgroup.addSession(session.repoPath, gitDir, hooks);\n\t\tthis.updateWatchMode(record);\n\t}\n\n\tprivate disconnectFromWatchGroup(record: SessionRecord): void {\n\t\tconst { session, gitDir } = record;\n\t\tconst commonGitDir = (gitDir.commonUri ?? gitDir.uri).fsPath;\n\t\tconst group = this.watchGroups.get(commonGitDir);\n\t\tif (group == null) return;\n\n\t\tgroup.removeSession(session.repoPath);\n\t\tthis.maybeDisposeWatchGroup(commonGitDir);\n\t\tthis.updateWatchMode(record);\n\t}\n\n\tprivate computeWatchMode(record: SessionRecord): 'events' | 'poll' | undefined {\n\t\tconst repoPath = record.session.repoPath;\n\t\tconst group = this.watchGroups.get((record.gitDir.commonUri ?? record.gitDir.uri).fsPath);\n\t\tconst connected = group?.sessions.has(repoPath) ?? false;\n\t\tconst wt = this.wtWatchers.get(repoPath);\n\t\tif (!connected && wt == null) return undefined;\n\n\t\treturn group?.isUnwatchable(repoPath) || wt?.reliability === 'unwatchable' ? 'poll' : 'events';\n\t}\n\n\tprivate updateWatchMode(record: SessionRecord): void {\n\t\tif (this._disposed) return;\n\n\t\tconst mode = this.computeWatchMode(record);\n\t\tif (mode == null) {\n\t\t\trecord.watchMode = 'events';\n\t\t\treturn;\n\t\t}\n\t\tif (mode === record.watchMode) return;\n\n\t\trecord.watchMode = mode;\n\t\tthis._onDidChangeWatchMode.fire({ repoPath: record.session.repoPath, mode: mode });\n\t}\n\n\tprivate startWorkingTreeWatcher(record: SessionRecord): void {\n\t\tconst { session, gitDir, watchHooks } = record;\n\t\tconst repoPath = session.repoPath;\n\t\tif (this.wtWatchers.has(repoPath)) return;\n\n\t\tconst canPrune = this.canPruneIgnoredDirectories();\n\t\t// Assigned once the first watcher exists; read by the handlers below instead of a map lookup per event\n\t\tlet entry: WorkingTreeWatcherEntry | undefined;\n\n\t\tlet filter: GitIgnoreFilter | undefined;\n\t\tif (this.getIgnoreFilter != null) {\n\t\t\tfilter = this.getIgnoreFilter(repoPath, gitDir.uri.fsPath);\n\t\t}\n\n\t\t// Buffer events while the gitignore filter loads, then replay\n\t\tlet filterReady = filter == null;\n\t\tlet buffered: string[] | undefined = filter != null ? [] : undefined;\n\t\tlet bufferIncomplete = false;\n\n\t\t// Ahead of `ready()`, so the replay below waits for rules that may have changed while nothing watched them\n\t\tconst revalidated = filter?.revalidate();\n\t\tif (filter != null) {\n\t\t\tvoid filter\n\t\t\t\t.ready()\n\t\t\t\t.then(() => {\n\t\t\t\t\tfilterReady = true;\n\t\t\t\t\tif (buffered?.length) {\n\t\t\t\t\t\tconst paths = filterWorkingTreePaths(buffered, repoPath, filter);\n\t\t\t\t\t\tif (paths.length > 0 || bufferIncomplete) {\n\t\t\t\t\t\t\tsession.pushWorkingTreeChanges(paths, bufferIncomplete);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tbuffered = undefined;\n\t\t\t\t\tbufferIncomplete = false;\n\t\t\t\t})\n\t\t\t\t.catch(() => {\n\t\t\t\t\tfilterReady = true;\n\t\t\t\t\tbuffered = undefined;\n\t\t\t\t});\n\t\t}\n\n\t\t// An ignore rule changed (or may have): refresh the filter (unless it already reloaded) and the pruned set, and\n\t\t// notify the host\n\t\tconst onIgnoreRulesChanged = (refreshFilter: boolean): void => {\n\t\t\tif (refreshFilter && filter != null) {\n\t\t\t\tvoid filter.refresh();\n\t\t\t}\n\t\t\tif (entry != null) {\n\t\t\t\tthis.scheduleIgnoredDirectoriesRefresh(entry);\n\t\t\t}\n\t\t\t// See `connectToWatchGroup` for the iterate-at-fire-time rationale.\n\t\t\tfor (const h of watchHooks) {\n\t\t\t\th.onGitIgnoreChanged?.(repoPath);\n\t\t\t}\n\t\t\t// Route the ignore-rule change through the repo channel as an `ignores` change (like `info/exclude`),\n\t\t\t// so it reaches EVERY session subscriber — including a closed secondary worktree's `watch()` `repoSub`,\n\t\t\t// which has no `onGitIgnoreChanged` hook and would otherwise keep a stale untracked-file list. Coalesces\n\t\t\t// with any hook-fired `ignores` above, so open repos don't double. Unfenced: it comes from the working tree,\n\t\t\t// which a self-write never holds back.\n\t\t\tsession.pushUnfencedRepoChanges(['ignores']);\n\t\t};\n\n\t\tconst onEvent = (event: FileWatchEvent): void => {\n\t\t\t// Dropped events: nothing to filter or buffer, the whole tree needs a re-read. A `.gitignore` edit may be\n\t\t\t// among them, and a filter left on the old rules would keep dropping changes they used to ignore\n\t\t\tif (event.reason === 'overflow') {\n\t\t\t\tsession.pushWorkingTreeChanges([], true);\n\t\t\t\tonIgnoreRulesChanged(true);\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Fast noise check (node_modules, .git, .watchman-cookie-)\n\t\t\tif (shouldIgnoreWorkingTreePath(event.path)) return;\n\n\t\t\t// Detect .gitignore changes (nested ones too, unless git skips them for sitting in an ignored directory).\n\t\t\t// The root .gitignore is only an ignore change; a nested one is also an ordinary working-tree change.\n\t\t\tconst relativePath = isDescendant(event.path, repoPath) ? relative(repoPath, event.path) : undefined;\n\t\t\tif (relativePath === '.gitignore') {\n\t\t\t\tonIgnoreRulesChanged(true);\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (relativePath?.endsWith('/.gitignore') && !(filterReady && filter?.isIgnored(relativePath))) {\n\t\t\t\tonIgnoreRulesChanged(true);\n\t\t\t}\n\n\t\t\tif (!filterReady) {\n\t\t\t\t// Buffer until the gitignore filter is ready. Capped: `ready()` awaits a `core.excludesFile`\n\t\t\t\t// read, which queues behind every other git command, so this window can stay open for a long\n\t\t\t\t// time — and these paths haven't been gitignore-filtered yet, so a build's output all lands\n\t\t\t\t// here. Past the cap, stop retaining and mark the batch partial rather than growing.\n\t\t\t\tif (buffered != null && buffered.length >= maxBufferedWorkingTreePaths) {\n\t\t\t\t\tbufferIncomplete = true;\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tbuffered?.push(event.path);\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Gitignore filter (sync after ready)\n\t\t\tif (filter != null && relativePath != null && filter.isIgnored(relativePath)) {\n\t\t\t\tif (canPrune && entry != null) {\n\t\t\t\t\tthis.onIgnoredEvent(entry, filter, relativePath);\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tsession.pushWorkingTreeChanges([event.path]);\n\t\t};\n\n\t\t// A read from before the watch last stopped; should the rules have moved since, `revalidate` brings a re-read\n\t\tconst kept = canPrune && filter != null ? this.keptIgnoredDirectories.get(filter) : undefined;\n\t\tconst created = this.createWorkingTreeWatcher(\n\t\t\trepoPath,\n\t\t\tonEvent,\n\t\t\tkept != null ? [...workingTreeExcludes, ...kept] : workingTreeExcludes,\n\t\t);\n\t\tentry = {\n\t\t\tsession: session,\n\t\t\tonEvent: onEvent,\n\t\t\tfilter: filter,\n\t\t\twatcher: created.watcher,\n\t\t\tignoredDirectories: kept ?? [],\n\t\t\tgeneration: 0,\n\t\t\treading: false,\n\t\t\trereadQueued: false,\n\t\t\treliability: 'reliable',\n\t\t\tstarting: created.starting,\n\t\t};\n\t\tthis.wtWatchers.set(repoPath, entry);\n\t\tthis.setWorkingTreeReliability(entry, created.reliability, true);\n\n\t\tif (canPrune && kept == null) {\n\t\t\tvoid this.refreshIgnoredDirectories(entry, repoPath);\n\t\t}\n\n\t\t// The kept read predates the rules either outcome lands on, so it goes even when the watch has stopped meanwhile\n\t\tvoid revalidated?.then(\n\t\t\tchanged => {\n\t\t\t\tif (!changed) return;\n\n\t\t\t\tif (filter != null) {\n\t\t\t\t\tthis.keptIgnoredDirectories.delete(filter);\n\t\t\t\t}\n\t\t\t\tif (this.wtWatchers.get(repoPath) === entry) {\n\t\t\t\t\tonIgnoreRulesChanged(false);\n\t\t\t\t}\n\t\t\t},\n\t\t\t() => {\n\t\t\t\tif (filter != null) {\n\t\t\t\t\tthis.keptIgnoredDirectories.delete(filter);\n\t\t\t\t}\n\t\t\t\tif (this.wtWatchers.get(repoPath) === entry) {\n\t\t\t\t\tonIgnoreRulesChanged(true);\n\t\t\t\t}\n\t\t\t},\n\t\t);\n\t}\n\n\tprivate stopWorkingTreeWatcher(repoPath: string): void {\n\t\tconst entry = this.wtWatchers.get(repoPath);\n\t\tif (entry == null) return;\n\n\t\t// Drops any read still in flight, and any refresh waiting on its debounce\n\t\tentry.generation++;\n\t\tclearTimeout(entry.refreshTimer);\n\t\tentry.refreshTimer = undefined;\n\t\tentry.watcher.dispose();\n\t\tif (entry.pollTarget != null) {\n\t\t\tthis.poller?.delete(entry.pollTarget);\n\t\t\tentry.pollTarget = undefined;\n\t\t}\n\t\tthis.wtWatchers.delete(repoPath);\n\t}\n\n\t/**\n\t * Creates a working-tree watcher, with the reliability it reported before returning, and whether it has yet to call\n\t * the `onDidStart` its provider promised\n\t */\n\tprivate createWorkingTreeWatcher(\n\t\trepoPath: string,\n\t\tonEvent: (event: FileWatchEvent) => void,\n\t\texcludes: readonly string[],\n\t): { watcher: FileWatcher; reliability: FileWatcherReliability; starting: boolean } {\n\t\tlet watcher: FileWatcher | undefined;\n\t\tlet started = false;\n\t\t// Not given to `.git` watchers: a host places one for every checkout at startup, and each would cost a rescan\n\t\tconst onDidStart = (): void => {\n\t\t\tif (started) return;\n\n\t\t\tstarted = true;\n\t\t\t// A watch that was live before `createWatcher` returned missed nothing\n\t\t\tif (watcher == null) return;\n\n\t\t\t// The same rescan as a watch coming back, and only for the live watcher, never one already replaced or stopped\n\t\t\tconst entry = this.wtWatchers.get(repoPath);\n\t\t\tif (entry?.watcher === watcher) {\n\t\t\t\tentry.starting = false;\n\t\t\t\tentry.session.pushWorkingTreeChanges([], true);\n\t\t\t}\n\t\t};\n\n\t\tif (this.poller == null) {\n\t\t\twatcher = this.provider.createWatcher(repoPath, '**', onEvent, {\n\t\t\t\texcludes: excludes,\n\t\t\t\tonDidStart: onDidStart,\n\t\t\t});\n\t\t\treturn {\n\t\t\t\twatcher: watcher,\n\t\t\t\treliability: 'reliable',\n\t\t\t\tstarting: this.provider.callsOnDidStart === true && !started,\n\t\t\t};\n\t\t}\n\n\t\tlet reliability: FileWatcherReliability = 'reliable';\n\t\tconst options: FileWatcherOptions = {\n\t\t\texcludes: excludes,\n\t\t\tonDidStart: onDidStart,\n\t\t\tonDidChangeReliability: state => {\n\t\t\t\tif (watcher == null) {\n\t\t\t\t\treliability = state;\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\t// Only the live watcher speaks for the working tree, never one already replaced\n\t\t\t\tconst entry = this.wtWatchers.get(repoPath);\n\t\t\t\tif (entry?.watcher === watcher) {\n\t\t\t\t\tthis.setWorkingTreeReliability(entry, state);\n\t\t\t\t}\n\t\t\t},\n\t\t};\n\t\twatcher = this.provider.createWatcher(repoPath, '**', onEvent, options);\n\t\treturn {\n\t\t\twatcher: watcher,\n\t\t\treliability: reliability,\n\t\t\tstarting: this.provider.callsOnDidStart === true && !started,\n\t\t};\n\t}\n\n\tprivate setWorkingTreeReliability(\n\t\tentry: WorkingTreeWatcherEntry,\n\t\tstate: FileWatcherReliability,\n\t\tinitial?: boolean,\n\t): void {\n\t\tconst previous = entry.reliability;\n\t\tif (previous === state) return;\n\n\t\tentry.reliability = state;\n\t\tthis.updateWorkingTreePollTarget(entry);\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. This rescan stands in for a start still\n\t\t// owed, which a provider that lost the watch may never report\n\t\tif (!initial) {\n\t\t\tentry.starting = false;\n\t\t\tentry.session.pushWorkingTreeChanges([], true);\n\t\t}\n\t\tconst record = this.sessionMap.get(entry.session.repoPath);\n\t\tif (record != null) {\n\t\t\tthis.updateWatchMode(record);\n\t\t}\n\t}\n\n\t/** Polls the host's working-tree fingerprint, when it gives one, while the watcher isn't `reliable` */\n\tprivate updateWorkingTreePollTarget(entry: WorkingTreeWatcherEntry): void {\n\t\tconst poller = this.poller;\n\t\tconst getFingerprint = poller?.options.getWorkingTreeFingerprint;\n\t\tif (poller == null || getFingerprint == null) return;\n\n\t\tif (entry.reliability === 'reliable') {\n\t\t\tif (entry.pollTarget != null) {\n\t\t\t\tpoller.delete(entry.pollTarget);\n\t\t\t\tentry.pollTarget = undefined;\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\tif (entry.pollTarget != null) return;\n\n\t\tconst repoPath = entry.session.repoPath;\n\t\tlet last: string | undefined;\n\t\tconst target: PollTarget = {\n\t\t\tpoll: async (): Promise<void> => {\n\t\t\t\tlet fingerprint: string | undefined;\n\t\t\t\ttry {\n\t\t\t\t\tfingerprint = await getFingerprint(repoPath);\n\t\t\t\t} catch {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (fingerprint == null || entry.pollTarget !== target) return;\n\n\t\t\t\tconst moved = last != null && last !== fingerprint;\n\t\t\t\tlast = fingerprint;\n\t\t\t\t// A fingerprint says the tree moved, not which files did\n\t\t\t\tif (moved) {\n\t\t\t\t\tentry.session.pushWorkingTreeChanges([], true);\n\t\t\t\t}\n\t\t\t},\n\t\t};\n\t\tentry.pollTarget = target;\n\t\tpoller.add(target);\n\t}\n\n\tprivate canPruneIgnoredDirectories(): boolean {\n\t\treturn this.provider.supportsExcludes === true && this.getIgnoredDirectories != null;\n\t}\n\n\t/**\n\t * An event the gitignore post-filter dropped. When its directory is itself ignored, the watcher is watching an\n\t * ignored directory it could prune (one created after the last read), so the ignored set is read again. An ignored\n\t * file in a watched directory (a root `.env`, `src/debug.log`) triggers nothing.\n\t */\n\tprivate onIgnoredEvent(entry: WorkingTreeWatcherEntry, filter: GitIgnoreFilter, relativePath: string): void {\n\t\t// A refresh is already pending and reads the whole set; keep a flood of these events at two field checks\n\t\tif (entry.refreshTimer != null || entry.rereadQueued) return;\n\n\t\t// The outermost ignored directory above the path — the one a read would prune. Keyed on it (not the immediate\n\t\t// parent), so a directory git won't prune costs one read however many subdirectories it has\n\t\tlet ignoredDir: string | undefined;\n\t\tfor (let slash = relativePath.indexOf('/'); slash !== -1; slash = relativePath.indexOf('/', slash + 1)) {\n\t\t\tconst dir = relativePath.slice(0, slash);\n\t\t\tif (entry.unpruned?.has(dir) || entry.unprunable?.has(dir)) return;\n\t\t\tif (filter.isIgnored(`${dir}/`)) {\n\t\t\t\tignoredDir = dir;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif (ignoredDir == null) return;\n\n\t\tentry.unpruned ??= new Set();\n\t\tentry.unpruned.add(ignoredDir);\n\n\t\t// Ignore rules didn't change, so a read in flight stays valid (no generation bump), but it may predate the\n\t\t// directory\n\t\tif (entry.reading) {\n\t\t\tentry.rereadQueued = true;\n\t\t\treturn;\n\t\t}\n\n\t\tthis.armIgnoredDirectoriesRefresh(entry);\n\t}\n\n\t/** Re-reads the git-ignored directories once ignore rules stop changing (trailing debounce, one timer per repo) */\n\tprivate scheduleIgnoredDirectoriesRefresh(entry: WorkingTreeWatcherEntry): void {\n\t\t// Read under the old rules, so a restart must read again even if the watcher stops before this re-read lands\n\t\tif (entry.filter != null) {\n\t\t\tthis.keptIgnoredDirectories.delete(entry.filter);\n\t\t}\n\t\tif (!this.canPruneIgnoredDirectories()) return;\n\n\t\t// A read already in flight is now stale, and a directory git wouldn't prune may be prunable now\n\t\tentry.generation++;\n\t\tentry.unprunable = undefined;\n\t\tclearTimeout(entry.refreshTimer);\n\t\tthis.armIgnoredDirectoriesRefresh(entry);\n\t}\n\n\tprivate armIgnoredDirectoriesRefresh(entry: WorkingTreeWatcherEntry): void {\n\t\tentry.refreshTimer = setTimeout(() => {\n\t\t\tentry.refreshTimer = undefined;\n\t\t\tconst repoPath = entry.session.repoPath;\n\t\t\tif (this.wtWatchers.get(repoPath) !== entry) return;\n\n\t\t\tif (entry.reading) {\n\t\t\t\tentry.rereadQueued = true;\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tvoid this.refreshIgnoredDirectories(entry, repoPath);\n\t\t}, ignoredDirectoriesRefreshDelayMs);\n\t}\n\n\t/** Single-flight: reads the git-ignored directories and, when they changed, swaps in a watcher excluding them */\n\tprivate async refreshIgnoredDirectories(entry: WorkingTreeWatcherEntry, repoPath: string): Promise<void> {\n\t\tif (this.getIgnoredDirectories == null) return;\n\n\t\tentry.reading = true;\n\t\ttry {\n\t\t\tconst generation = entry.generation;\n\t\t\t// The unpruned directories seen so far; any seen during the read wait for the next one\n\t\t\tconst unpruned = entry.unpruned?.size ? [...entry.unpruned] : undefined;\n\n\t\t\tlet directories: readonly string[] | undefined;\n\t\t\ttry {\n\t\t\t\tdirectories = await this.getIgnoredDirectories(repoPath);\n\t\t\t} catch {\n\t\t\t\t// Keep what the watcher has; the next ignore-rule change reads again\n\t\t\t\tdirectories = undefined;\n\t\t\t}\n\n\t\t\tif (entry.generation === generation) {\n\t\t\t\tif (directories != null) {\n\t\t\t\t\tthis.swapWorkingTreeWatcher(entry, repoPath, directories);\n\t\t\t\t\tif (entry.filter != null) {\n\t\t\t\t\t\tthis.keptIgnoredDirectories.set(entry.filter, directories);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (unpruned != null) {\n\t\t\t\t\tthis.settleUnprunedDirectories(entry, unpruned, directories);\n\t\t\t\t}\n\t\t\t}\n\t\t} finally {\n\t\t\tentry.reading = false;\n\t\t}\n\n\t\tif (entry.rereadQueued) {\n\t\t\tentry.rereadQueued = false;\n\t\t\tif (this.wtWatchers.get(repoPath) === entry) {\n\t\t\t\tvoid this.refreshIgnoredDirectories(entry, repoPath);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * A directory the read left unexcluded is one git won't prune (or the read failed), so it never triggers a read\n\t * again until ignore rules change — otherwise each of its events would spawn git.\n\t */\n\tprivate settleUnprunedDirectories(\n\t\tentry: WorkingTreeWatcherEntry,\n\t\tunpruned: readonly string[],\n\t\tdirectories: readonly string[] | undefined,\n\t): void {\n\t\tfor (const dir of unpruned) {\n\t\t\tentry.unpruned?.delete(dir);\n\t\t\tif (directories?.some(d => d === dir || dir.startsWith(`${d}/`))) continue;\n\n\t\t\tentry.unprunable ??= new Set();\n\t\t\tentry.unprunable.add(dir);\n\t\t}\n\t}\n\n\tprivate swapWorkingTreeWatcher(\n\t\tentry: WorkingTreeWatcherEntry,\n\t\trepoPath: string,\n\t\tdirectories: readonly string[],\n\t): void {\n\t\tconst previous = entry.ignoredDirectories;\n\t\tif (previous.length === directories.length && previous.every(d => directories.includes(d))) return;\n\n\t\t// New first, then the old one: the overlap can repeat an event (the session coalesces them), but never loses one.\n\t\t// A provider that places its watch asynchronously leaves a gap until it goes live, which its `onDidStart` rescans\n\t\tlet created: { watcher: FileWatcher; reliability: FileWatcherReliability; starting: boolean };\n\t\ttry {\n\t\t\tcreated = this.createWorkingTreeWatcher(repoPath, entry.onEvent, [...workingTreeExcludes, ...directories]);\n\t\t} catch {\n\t\t\treturn;\n\t\t}\n\n\t\tconst previousWatcher = entry.watcher;\n\t\tentry.watcher = created.watcher;\n\t\t// The replacement owes its own start\n\t\tentry.starting = created.starting;\n\t\tentry.ignoredDirectories = directories;\n\t\tpreviousWatcher.dispose();\n\t\tthis.setWorkingTreeReliability(entry, created.reliability);\n\n\t\t// Files in a directory that is watched again changed while nothing was looking. A directory still covered by\n\t\t// a surviving ancestor entry isn't watched again.\n\t\tif (previous.some(d => !directories.some(n => n === d || d.startsWith(`${n}/`)))) {\n\t\t\tentry.session.pushWorkingTreeChanges([], true);\n\t\t}\n\t}\n\n\tprivate refreshWorkingTreeFilter(repoPath: string): void {\n\t\tconst entry = this.wtWatchers.get(repoPath);\n\t\tif (entry == null) return;\n\n\t\tif (entry.filter != null) {\n\t\t\tvoid entry.filter.refresh();\n\t\t}\n\t\tthis.scheduleIgnoredDirectoriesRefresh(entry);\n\t}\n\n\tprivate disposeSessionRecord(record: SessionRecord): void {\n\t\t// The working tree first: with it still up, leaving the group would read as a move back to `'events'` and\n\t\t// announce one for a repository that is going away\n\t\tthis.stopWorkingTreeWatcher(record.session.repoPath);\n\t\tthis.disconnectFromWatchGroup(record);\n\t\tthis.updateWatchMode(record);\n\t\trecord.session.dispose();\n\t}\n}\n\nfunction filterWorkingTreePaths(absolutePaths: string[], repoPath: string, filter: GitIgnoreFilter): string[] {\n\tconst result: string[] = [];\n\tfor (const p of absolutePaths) {\n\t\tif (!isDescendant(p, repoPath)) continue;\n\n\t\tconst relativePath = relative(repoPath, p);\n\t\tif (!filter.isIgnored(relativePath)) {\n\t\t\tresult.push(p);\n\t\t}\n\t}\n\treturn result;\n}\n"],"mappings":";;;;;;;;;;;;;AA4BA,MAAM,8BAA8B;;AAGpC,MAAM,mCAAmC;;;;;;;;;;;;AAkKzC,IAAa,yBAAb,MAAiE;CAChE,yBAA0C,IAAI,QAAgC;;CAE9E,IAAI,wBAAuD;EAC1D,OAAO,KAAK,uBAAuB;CACpC;CAEA,0BAA2C,IAAI,QAAgB;;;CAG/D,IAAI,yBAAwC;EAC3C,OAAO,KAAK,wBAAwB;CACrC;CAEA,wBAAyC,IAAI,QAAgB;;;;;;CAM7D,IAAI,uBAAsC;EACzC,OAAO,KAAK,sBAAsB;CACnC;CAEA,wBAAyC,IAAI,QAAuD;;;;;;CAMpG,IAAI,uBAA6E;EAChF,OAAO,KAAK,sBAAsB;CACnC;CAEA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAEA,6BAA8B,IAAI,IAA2B;CAC7D,8BAA+B,IAAI,IAAwB;CAC3D,6BAA8B,IAAI,IAAqC;;;;;CAKvE,yCAA0C,IAAI,QAA4C;CAC1F,YAAoB;;CAEpB,aAAqB;CAErB,YAAY,SAA8B;EACzC,KAAK,WAAW,QAAQ;EACxB,KAAK,qBAAqB,QAAQ;EAClC,KAAK,4BAA4B,QAAQ;EACzC,KAAK,uBAAuB,QAAQ;EACpC,KAAK,8BAA8B,QAAQ;EAC3C,KAAK,kBAAkB,QAAQ;EAC/B,KAAK,wBAAwB,QAAQ;EACrC,KAAK,0BAA0B,QAAQ;EACvC,KAAK,4BAA4B,QAAQ;EACzC,KAAK,WAAW,QAAQ;EACxB,KAAK,gBAAgB,QAAQ;EAC7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,YAAY,SAAS,CAAC,CAAC,GAAG;EAI5F,IAAI;EACJ,IAAI;GACH,UAAU,KAAK,yBAAyB,UAAU,MAAM,SAAS,CAAC,GAAG,qBAAqB,GAAG,WAAW,CAAC;EAC1G,QAAQ;GACP;EACD;EAEA,MAAM,kBAAkB,MAAM;EAC9B,MAAM,UAAU,QAAQ;EAExB,MAAM,WAAW,QAAQ;EACzB,MAAM,qBAAqB;EAC3B,gBAAgB,QAAQ;EACxB,KAAK,0BAA0B,OAAO,QAAQ,WAAW;EAIzD,IAAI,SAAS,MAAK,MAAK,CAAC,YAAY,MAAK,MAAK,MAAM,KAAK,EAAE,WAAW,GAAG,EAAE,EAAE,CAAC,CAAC,GAC9E,MAAM,QAAQ,uBAAuB,CAAC,GAAG,IAAI;CAE/C;CAEA,yBAAiC,UAAwB;EACxD,MAAM,QAAQ,KAAK,WAAW,IAAI,QAAQ;EAC1C,IAAI,SAAS,MAAM;EAEnB,IAAI,MAAM,UAAU,MACnB,MAAW,OAAO,QAAQ;EAE3B,KAAK,kCAAkC,KAAK;CAC7C;CAEA,qBAA6B,QAA6B;EAGzD,KAAK,uBAAuB,OAAO,QAAQ,QAAQ;EACnD,KAAK,yBAAyB,MAAM;EACpC,KAAK,gBAAgB,MAAM;EAC3B,OAAO,QAAQ,QAAQ;CACxB;AACD;AAEA,SAAS,uBAAuB,eAAyB,UAAkB,QAAmC;CAC7G,MAAM,SAAmB,CAAC;CAC1B,KAAK,MAAM,KAAK,eAAe;EAC9B,IAAI,CAAC,aAAa,GAAG,QAAQ,GAAG;EAEhC,MAAM,eAAe,SAAS,UAAU,CAAC;EACzC,IAAI,CAAC,OAAO,UAAU,YAAY,GACjC,OAAO,KAAK,CAAC;CAEf;CACA,OAAO;AACR"}
1
+ {"version":3,"file":"watchService.js","names":[],"sources":["../../../../git/src/watching/watchService.ts"],"sourcesContent":["import type { UnifiedDisposable } from '@gitlens/utils/disposable.js';\nimport type { Event } from '@gitlens/utils/event.js';\nimport { Emitter } from '@gitlens/utils/event.js';\nimport { isDescendant, relative } from '@gitlens/utils/path.js';\nimport type { ResourceUsage } from '@gitlens/utils/resourceUsage.js';\nimport { getRepositoryKey } from '@gitlens/utils/uri.js';\nimport type { GitDir, RepositoryChange } from '../models/repository.js';\nimport type { WatcherRepoChangeEvent } from './changeEvent.js';\nimport type { PollTarget } from './gitDirPoller.js';\nimport { GitDirPoller } from './gitDirPoller.js';\nimport type { GitIgnoreFilter } from './gitIgnoreFilter.js';\nimport type {\n\tFileWatcher,\n\tFileWatcherOptions,\n\tFileWatcherReliability,\n\tFileWatchEvent,\n\tFileWatchingProvider,\n} from './provider.js';\nimport { shouldIgnoreWorkingTreePath, workingTreeExcludes } from './watcherPatterns.js';\nimport type { WatchGroupHooks } from './watchGroup.js';\nimport { WatchGroup } from './watchGroup.js';\nimport { RepositoryWatchSession } from './watchSession.js';\n\n/**\n * Cap on paths held while the gitignore filter loads. Higher than the session's own cap because these are\n * pre-filter — most of a build's output is typically gitignored and would be discarded on replay, so a\n * tighter bound here would mark batches incomplete when they filter down to almost nothing.\n */\nconst maxBufferedWorkingTreePaths = 5000;\n\n/** Trailing debounce before the git-ignored directory set is re-read after an ignore rule changes */\nconst ignoredDirectoriesRefreshDelayMs = 500;\n\ninterface WorkingTreeWatcherEntry {\n\treadonly session: RepositoryWatchSession;\n\t/** The event handler shared by every watcher this entry has had — a re-created watcher reuses it */\n\treadonly onEvent: (event: FileWatchEvent) => void;\n\treadonly filter?: GitIgnoreFilter;\n\twatcher: FileWatcher;\n\t/** The git-ignored directories the live watcher was created excluding (on top of the static set) */\n\tignoredDirectories: readonly string[];\n\t/** Bumped by every ignore-rule change and by stopping; a read that lands under a different value is stale */\n\tgeneration: number;\n\treading: boolean;\n\t/** A refresh came due while a read was in flight */\n\trereadQueued: boolean;\n\trefreshTimer?: ReturnType<typeof setTimeout>;\n\t/** What the live watcher last reported; a re-created watcher starts over from its own report */\n\treliability: FileWatcherReliability;\n\t/** The live watcher has yet to call the `onDidStart` its provider promised (see `callsOnDidStart`) */\n\tstarting: boolean;\n\t/** Compares the host's working-tree fingerprint while the watcher isn't `reliable` */\n\tpollTarget?: PollTarget;\n\t/**\n\t * Git-ignored directories (repo-relative) whose events reached the post-filter, so the watcher isn't pruning them —\n\t * typically created after the last read (a first build's `dist/`). Each waits for a read that started after it.\n\t */\n\tunpruned?: Set<string>;\n\t/**\n\t * Directories a read showed git won't prune (they hold tracked files, or glob metacharacters in their names);\n\t * cleared when ignore rules change\n\t */\n\tunprunable?: Set<string>;\n}\n\n/**\n * A host whose watchers can report they can't be trusted (see `FileWatcherOptions.onDidChangeReliability`) passes\n * these to have core poll in their place. A `.git` directory is polled by statting the files its watchers read and\n * feeding each one that moved through the same interpretation as a watcher event; a working tree is never walked.\n */\nexport interface WatchPollingOptions {\n\t/**\n\t * Reads a path's modification time (ms) and size; `undefined` when it doesn't exist. A rejection means unknown:\n\t * the last reading stands, so it never counts as a change.\n\t */\n\treadonly stat: (path: string) => Promise<{ readonly mtime: number; readonly size: number } | undefined>;\n\t/** Whether a poll is worth running now. Default: the service isn't suspended (`suspendAll`/`resumeAll`) */\n\treadonly isActive?: () => boolean;\n\t/** How often each untrusted watcher is polled. Default: 60000ms */\n\treadonly intervalMs?: number;\n\t/**\n\t * How often `isActive` is looked at, which bounds how late the first poll after it turns true can be. Only with\n\t * `isActive`: the default gate wakes only for a poll. Default: 5000ms\n\t */\n\treadonly activeCheckMs?: number;\n\t/**\n\t * Refs to poll for a repository beyond its subscribers' `relevantRefs`: one with none (a host listing every branch)\n\t * still needs its checked-out branch's upstream, which a push moves without writing `FETCH_HEAD`\n\t */\n\treadonly getRefs?: (repoPath: string) => Iterable<string>;\n\t/**\n\t * Something that changes whenever the repository's working tree does (e.g. a digest of its status and the\n\t * changed files' stats), compared at each poll while working-tree subscribers are watching a working tree whose\n\t * watcher can't be trusted; a change is reported with no paths. `undefined` or a rejection skips that poll. With or\n\t * without it, a working tree whose watcher is `unwatchable` is reported changed (no paths) whenever its index or\n\t * `HEAD` changes.\n\t */\n\treadonly getWorkingTreeFingerprint?: (repoPath: string) => Promise<string | undefined>;\n}\n\nexport interface WatchServiceOptions {\n\treadonly watchingProvider: FileWatchingProvider;\n\t/** Default debounce for repo changes when subscriber doesn't specify. Default: 250ms */\n\treadonly defaultRepoDelayMs?: number;\n\t/** Default debounce for working tree changes when subscriber doesn't specify. Default: 2500ms */\n\treadonly defaultWorkingTreeDelayMs?: number;\n\t/** Default cap on how long continuous repo activity can defer a flush. `Infinity` disables it. Default: 2000ms */\n\treadonly defaultRepoMaxWaitMs?: number;\n\t/** Default cap on how long continuous working tree activity can defer a flush. `Infinity` disables it. Default: 10000ms */\n\treadonly defaultWorkingTreeMaxWaitMs?: number;\n\t/** Returns a GitIgnoreFilter for a given repo. When absent or returns undefined, gitignore filtering is skipped. */\n\treadonly getIgnoreFilter?: (repoPath: string, gitDirPath: string) => GitIgnoreFilter | undefined;\n\t/**\n\t * Returns the repo-relative directories an ignore rule matches, for a watching provider that prunes\n\t * `excludes` natively (`supportsExcludes`). Never called for one that doesn't. A rejection keeps the static set.\n\t */\n\treadonly getIgnoredDirectories?: (repoPath: string) => Promise<readonly string[]>;\n\t/**\n\t * Returns the absolute, normalized folders whose worktrees are ignored (see `GitProvider.getIgnoredWorktreeRoots`):\n\t * with a `readFile` and a `readDirectory`, the watcher's reports of their admin entries reach no session. Asked\n\t * once per common git dir, when its first session starts watching, and never without both. When absent, empty or\n\t * rejected, no admin entry is read.\n\t */\n\treadonly getIgnoredWorktreeRoots?: (repoPath: string) => Promise<readonly string[]>;\n\t/**\n\t * Returns the folders whose worktrees are ignored, relative to a repository's common git dir (see\n\t * `GitProvider.getIgnoredWorktreeFolders`): the `.git` watchers whose tree holds the common git dir leave\n\t * them unwatched. Asked once per common git dir, when its first session starts watching.\n\t */\n\treadonly getIgnoredWorktreeFolders?: (repoPath: string) => readonly string[];\n\t/** Opts into polling the watchers that report they can't be trusted. When absent, no watcher is asked. */\n\treadonly polling?: WatchPollingOptions;\n\t/**\n\t * Reads a file's bytes; a rejection means it couldn't be read. With it, each report of a repository's shared\n\t * `.git/config` is classified by what changed in the file: a change confined to some branches' `branch.<name>`\n\t * sections reaches only the subscribers following those branches, and carries no `remotes`. Without it, every\n\t * config change concerns everyone, as before.\n\t */\n\treadonly readFile?: (path: string) => Promise<Uint8Array>;\n\t/**\n\t * Returns a directory's entries with their types, as the host file system's `readDirectory` does; only the\n\t * directories count as admin entries (a stray `.DS_Store` is no worktree's). A rejection means it couldn't be\n\t * listed, and one whose `code` is `ENOENT` or `FileNotFound` that the directory isn't there. With it and a\n\t * `readFile`, the admin entries of a repository's worktrees are listed and read once as its first session starts\n\t * watching, so the reports of an ignored worktree's (see `getIgnoredWorktreeRoots`) reach no session, and the others\n\t * aren't held back.\n\t */\n\treadonly readDirectory?: (path: string) => Promise<readonly (readonly [string, number])[]>;\n}\n\nexport interface WatchHooks {\n\t/** Called when FETCH_HEAD changed (for last-fetched tracking) */\n\treadonly onFetchHeadChanged?: (repoPath: string) => void;\n\t/** Called when .git/info/exclude changed */\n\treadonly onIgnoresChanged?: (repoPath: string) => void;\n\t/** Called when .gitignore changed in the working tree (extension watches this separately) */\n\treadonly onGitIgnoreChanged?: (repoPath: string) => void;\n}\n\nexport interface WatchHandle {\n\treadonly session: RepositoryWatchSession;\n\tdispose(): void;\n}\n\ninterface SessionRecord {\n\treadonly session: RepositoryWatchSession;\n\treadonly gitDir: GitDir;\n\t/**\n\t * Hooks contributed by all current `watch()` callers for this repo path. Earlier\n\t * implementations stored just the first caller's hooks (`WatchHooks | undefined`) and\n\t * silently dropped subsequent callers' hooks — that broke the case where a low-level\n\t * subscriber (e.g. the Graph's secondary-worktree WIP watcher) opened the session\n\t * first without hooks, and a later `Repository.watch()` for the same path lost\n\t * its `markFetched` / `onIgnoresChanged` wiring. Each `watch()` call adds its hooks\n\t * to this set and removes them on dispose; fire sites iterate the set.\n\t */\n\treadonly watchHooks: Set<WatchHooks>;\n\trefCount: number;\n\t/** The mode {@link RepositoryWatchService.onDidChangeWatchMode} last announced; `'events'` while unwatched */\n\twatchMode: 'events' | 'poll';\n}\n\n/**\n * Global service that multiplexes repository watching across all repos.\n *\n * Manages:\n * - Session map: one `RepositoryWatchSession` per repo path (ref-counted)\n * - Watch groups: shared `.git` watchers across worktrees\n * - Working tree watchers: per-repo filesystem watchers with gitignore filtering\n *\n * Sessions and watch groups are created lazily on first `subscribe()`\n * within a session, and destroyed when the last subscriber leaves.\n */\nexport class RepositoryWatchService implements UnifiedDisposable {\n\tprivate readonly _onDidChangeRepository = new Emitter<WatcherRepoChangeEvent>();\n\t/** Global multiplexed event for ALL watched repos */\n\tget onDidChangeRepository(): Event<WatcherRepoChangeEvent> {\n\t\treturn this._onDidChangeRepository.event;\n\t}\n\n\tprivate readonly _onDidChangeWorkingTree = new Emitter<string>();\n\t/** Global multiplexed working-tree change event (repo path) for ALL watched repos. Fires once per\n\t * debounced flush per session — the single point that drives the cache's status clock for working-tree edits. */\n\tget onDidChangeWorkingTree(): Event<string> {\n\t\treturn this._onDidChangeWorkingTree.event;\n\t}\n\n\tprivate readonly _onDidChangeFetchHead = new Emitter<string>();\n\t/**\n\t * Global FETCH_HEAD change event (repo path) for ALL watched repos, fired as each change is seen (no debounce).\n\t * FETCH_HEAD maps to no {@link RepositoryChange} on the session, so this is how a host invalidates its cached\n\t * last-fetched time — the standalone service bridges it to the cache's `lastFetched`.\n\t */\n\tget onDidChangeFetchHead(): Event<string> {\n\t\treturn this._onDidChangeFetchHead.event;\n\t}\n\n\tprivate readonly _onDidChangeWatchMode = new Emitter<{ repoPath: string; mode: 'events' | 'poll' }>();\n\t/**\n\t * Fires as a watched repository starts being polled in place of a watcher (see {@link getWatchMode}), and with\n\t * `'events'` as it is watched natively again. Never fires as the repository stops being watched; one watched again\n\t * later starts from `'events'`.\n\t */\n\tget onDidChangeWatchMode(): Event<{ repoPath: string; mode: 'events' | 'poll' }> {\n\t\treturn this._onDidChangeWatchMode.event;\n\t}\n\n\tprivate readonly _onDidChangeRepoWatched = new Emitter<{ repoPath: string; watched: boolean }>();\n\t/**\n\t * Fires as a repository's `.git` directory starts being watched (its session's first repo subscriber connected it\n\t * to its watch group) and as it stops (its last one left, or its session was disposed); see {@link isRepoWatched}.\n\t * `repoPath` is the session's key ({@link getRepositoryKey}). Never fires as the service itself is disposed, nor as\n\t * the session suspends or resumes: a suspended session still reports what it held once it resumes, so there is\n\t * nothing to hand off, and {@link isRepoWatched} answers `false` meanwhile without announcing it.\n\t */\n\tget onDidChangeRepoWatched(): Event<{ repoPath: string; watched: boolean }> {\n\t\treturn this._onDidChangeRepoWatched.event;\n\t}\n\n\tprivate readonly defaultRepoDelayMs?: number;\n\tprivate readonly defaultWorkingTreeDelayMs?: number;\n\tprivate readonly defaultRepoMaxWaitMs?: number;\n\tprivate readonly defaultWorkingTreeMaxWaitMs?: number;\n\tprivate readonly getIgnoreFilter?: (repoPath: string, gitDirPath: string) => GitIgnoreFilter | undefined;\n\tprivate readonly getIgnoredDirectories?: (repoPath: string) => Promise<readonly string[]>;\n\tprivate readonly getIgnoredWorktreeRoots?: (repoPath: string) => Promise<readonly string[]>;\n\tprivate readonly getIgnoredWorktreeFolders?: (repoPath: string) => readonly string[];\n\tprivate readonly provider: FileWatchingProvider;\n\tprivate readonly poller: GitDirPoller | undefined;\n\tprivate readonly readFile: ((path: string) => Promise<Uint8Array>) | undefined;\n\tprivate readonly readDirectory: ((path: string) => Promise<readonly (readonly [string, number])[]>) | undefined;\n\n\tprivate readonly sessionMap = new Map<string, SessionRecord>();\n\tprivate readonly watchGroups = new Map<string, WatchGroup>();\n\tprivate readonly wtWatchers = new Map<string, WorkingTreeWatcherEntry>();\n\t/**\n\t * The last git-ignored directory read under each filter's current rules, kept across a working-tree watcher's\n\t * stop and start so a restart can skip the read; dropped with the filter\n\t */\n\tprivate readonly keptIgnoredDirectories = new WeakMap<GitIgnoreFilter, readonly string[]>();\n\tprivate _disposed = false;\n\t/** Global suspend state (driven by window focus); inherited by sessions created via {@link watch}. */\n\tprivate _suspended = false;\n\n\tconstructor(options: WatchServiceOptions) {\n\t\tthis.provider = options.watchingProvider;\n\t\tthis.defaultRepoDelayMs = options.defaultRepoDelayMs;\n\t\tthis.defaultWorkingTreeDelayMs = options.defaultWorkingTreeDelayMs;\n\t\tthis.defaultRepoMaxWaitMs = options.defaultRepoMaxWaitMs;\n\t\tthis.defaultWorkingTreeMaxWaitMs = options.defaultWorkingTreeMaxWaitMs;\n\t\tthis.getIgnoreFilter = options.getIgnoreFilter;\n\t\tthis.getIgnoredDirectories = options.getIgnoredDirectories;\n\t\tthis.getIgnoredWorktreeRoots = options.getIgnoredWorktreeRoots;\n\t\tthis.getIgnoredWorktreeFolders = options.getIgnoredWorktreeFolders;\n\t\tthis.readFile = options.readFile;\n\t\tthis.readDirectory = options.readDirectory;\n\t\tif (options.polling != null) {\n\t\t\tthis.poller = new GitDirPoller(options.polling);\n\t\t}\n\t}\n\n\t[Symbol.dispose](): void {\n\t\tthis.dispose();\n\t}\n\n\tdispose(): void {\n\t\tif (this._disposed) return;\n\n\t\tthis._disposed = true;\n\n\t\tfor (const record of this.sessionMap.values()) {\n\t\t\tthis.disposeSessionRecord(record);\n\t\t}\n\t\tthis.sessionMap.clear();\n\n\t\tfor (const group of this.watchGroups.values()) {\n\t\t\tgroup.dispose();\n\t\t}\n\t\tthis.watchGroups.clear();\n\n\t\tfor (const repoPath of [...this.wtWatchers.keys()]) {\n\t\t\tthis.stopWorkingTreeWatcher(repoPath);\n\t\t}\n\n\t\tthis.poller?.dispose();\n\n\t\tthis._onDidChangeRepository.dispose();\n\t\tthis._onDidChangeWorkingTree.dispose();\n\t\tthis._onDidChangeFetchHead.dispose();\n\t\tthis._onDidChangeWatchMode.dispose();\n\t\tthis._onDidChangeRepoWatched.dispose();\n\t}\n\n\t/**\n\t * Start watching a repository. Reference-counted:\n\t * same repoPath → same session (refCount++).\n\t * Worktrees sharing a .git dir share the WatchGroup.\n\t *\n\t * Returns a handle with the session and a dispose function.\n\t * Disposing the handle decrements the ref count.\n\t *\n\t * `repoPath` is keyed by {@link getRepositoryKey}, and every session, event and hook carries that key — the\n\t * same one the cache fences status reads on — so a host passing `C:\\repo\\` and one passing `c:/repo` share\n\t * a session and advance the same status clock.\n\t */\n\twatch(repoPath: string, gitDir: GitDir, watchHooks?: WatchHooks): WatchHandle | undefined {\n\t\tif (this._disposed) return undefined;\n\n\t\trepoPath = getRepositoryKey(repoPath);\n\n\t\tlet record = this.sessionMap.get(repoPath);\n\t\tif (record != null) {\n\t\t\trecord.refCount++;\n\t\t\tif (watchHooks != null) {\n\t\t\t\trecord.watchHooks.add(watchHooks);\n\t\t\t}\n\t\t} else {\n\t\t\tconst session = new RepositoryWatchSession({\n\t\t\t\trepoPath: repoPath,\n\t\t\t\tdefaultRepoDelayMs: this.defaultRepoDelayMs,\n\t\t\t\tdefaultWorkingTreeDelayMs: this.defaultWorkingTreeDelayMs,\n\t\t\t\tdefaultRepoMaxWaitMs: this.defaultRepoMaxWaitMs,\n\t\t\t\tdefaultWorkingTreeMaxWaitMs: this.defaultWorkingTreeMaxWaitMs,\n\t\t\t\tsuspended: this._suspended,\n\t\t\t\tlifecycle: {\n\t\t\t\t\tonFirstRepoSubscriber: (): void => {\n\t\t\t\t\t\tconst rec = this.sessionMap.get(repoPath);\n\t\t\t\t\t\tif (rec != null) {\n\t\t\t\t\t\t\tthis.connectToWatchGroup(rec);\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t\tonLastRepoSubscriber: (): void => {\n\t\t\t\t\t\tconst rec = this.sessionMap.get(repoPath);\n\t\t\t\t\t\tif (rec != null) {\n\t\t\t\t\t\t\tthis.disconnectFromWatchGroup(rec);\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t\tonFirstWorkingTreeSubscriber: (): void => {\n\t\t\t\t\t\tconst rec = this.sessionMap.get(repoPath);\n\t\t\t\t\t\tif (rec != null) {\n\t\t\t\t\t\t\tthis.startWorkingTreeWatcher(rec);\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t\tonLastWorkingTreeSubscriber: (): void => {\n\t\t\t\t\t\tthis.stopWorkingTreeWatcher(repoPath);\n\t\t\t\t\t\tconst rec = this.sessionMap.get(repoPath);\n\t\t\t\t\t\tif (rec != null) {\n\t\t\t\t\t\t\tthis.updateWatchMode(rec);\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\tonDidFireRepoChange: (event): void => {\n\t\t\t\t\tthis._onDidChangeRepository.fire(event);\n\t\t\t\t},\n\t\t\t\tonDidFireWorkingTreeChange: (repoPath): void => {\n\t\t\t\t\tthis._onDidChangeWorkingTree.fire(repoPath);\n\t\t\t\t},\n\t\t\t});\n\n\t\t\tconst watchHooksSet = new Set<WatchHooks>();\n\t\t\tif (watchHooks != null) {\n\t\t\t\twatchHooksSet.add(watchHooks);\n\t\t\t}\n\n\t\t\trecord = {\n\t\t\t\tsession: session,\n\t\t\t\tgitDir: gitDir,\n\t\t\t\twatchHooks: watchHooksSet,\n\t\t\t\trefCount: 1,\n\t\t\t\twatchMode: 'events',\n\t\t\t};\n\t\t\tthis.sessionMap.set(repoPath, record);\n\t\t}\n\n\t\tconst sessionRef = record.session;\n\t\tlet handleDisposed = false;\n\n\t\treturn {\n\t\t\tsession: sessionRef,\n\t\t\tdispose: (): void => {\n\t\t\t\tif (handleDisposed) return;\n\n\t\t\t\thandleDisposed = true;\n\n\t\t\t\tconst rec = this.sessionMap.get(repoPath);\n\t\t\t\tif (rec == null) return;\n\n\t\t\t\trec.refCount--;\n\t\t\t\tif (watchHooks != null) {\n\t\t\t\t\trec.watchHooks.delete(watchHooks);\n\t\t\t\t}\n\t\t\t\tif (rec.refCount <= 0) {\n\t\t\t\t\tthis.sessionMap.delete(repoPath);\n\t\t\t\t\tthis.disposeSessionRecord(rec);\n\t\t\t\t}\n\t\t\t},\n\t\t};\n\t}\n\n\t/**\n\t * Core announced one of its own writes for `repoPath`; the session watching it fires the announcement in place of\n\t * the write's own `.git` events (see {@link RepositoryWatchSession.noteSelfWrite}); `refs` are the full ref names it\n\t * moved, when it knows them, and `options.configConfinedToRefs` confines its `config` change to the sections of the\n\t * local branches among them (see `GitServiceHooks.repository.onChanged`); `options.movedWorktrees` confines its\n\t * `worktreeHead` change to those linked worktrees (see `AnnouncedRepositoryChanges.movedWorktrees`). A path no session\n\t * watches is ignored.\n\t */\n\tnoteSelfWrite(\n\t\trepoPath: string,\n\t\tchanges: readonly RepositoryChange[],\n\t\trefs?: readonly string[],\n\t\toptions?: { readonly configConfinedToRefs?: boolean; readonly movedWorktrees?: readonly string[] },\n\t): void {\n\t\tif (this._disposed) return;\n\n\t\tthis.sessionMap.get(getRepositoryKey(repoPath))?.session.noteSelfWrite(changes, refs, options);\n\t}\n\n\t/**\n\t * Whether `repoPath`'s `.git` directory is watched: its session has a repo subscriber, so it is connected to its\n\t * watch group (natively, or polled in place of a watcher that can't be trusted). A session with only working-tree\n\t * subscribers, or none, doesn't count, nor does a suspended one: it holds what its watcher hears until it resumes,\n\t * and the poller doesn't poll meanwhile, so a read is served stale. Suspending or resuming announces nothing (see\n\t * {@link onDidChangeRepoWatched}).\n\t */\n\tisRepoWatched(repoPath: string): boolean {\n\t\tconst record = this.sessionMap.get(getRepositoryKey(repoPath));\n\t\treturn record != null && this.isConnected(record) && !record.session.suspended;\n\t}\n\n\t/** Get an existing session by repo path */\n\tgetSession(repoPath: string): RepositoryWatchSession | undefined {\n\t\treturn this.sessionMap.get(getRepositoryKey(repoPath))?.session;\n\t}\n\n\t/**\n\t * Whether the working tree's watch has yet to go live, owing a rescan once it does (see\n\t * `FileWatchingProvider.callsOnDidStart`). Not while it's `unwatchable`: it rescans when it comes back.\n\t */\n\tisWorkingTreeStarting(repoPath: string): boolean {\n\t\tconst entry = this.wtWatchers.get(getRepositoryKey(repoPath));\n\t\treturn entry?.starting === true && entry.reliability !== 'unwatchable';\n\t}\n\n\t/**\n\t * `'poll'` while a watcher the repository is watched through — its `.git` watchers or its working tree's — can't\n\t * watch, and is polled instead; `'events'` while it is watched natively (polled beside an `unreliable` watcher\n\t * included); `undefined` when nothing watches it, which {@link onDidChangeWatchMode} doesn't announce.\n\t */\n\tgetWatchMode(repoPath: string): 'events' | 'poll' | undefined {\n\t\tconst record = this.sessionMap.get(getRepositoryKey(repoPath));\n\t\treturn record != null ? this.computeWatchMode(record) : undefined;\n\t}\n\n\t/** Resource usage retained by repository watchers. */\n\tgetResourceUsage(): ResourceUsage {\n\t\tconst usage: ResourceUsage = {\n\t\t\t'watch.sessions.count': this.sessionMap.size,\n\t\t\t'watch.groups.count': this.watchGroups.size,\n\t\t\t'watch.workingTreeWatchers.count': this.wtWatchers.size,\n\t\t};\n\t\tif (this.poller != null) {\n\t\t\tusage['watch.pollTargets.count'] = this.poller.size;\n\t\t}\n\t\treturn usage;\n\t}\n\n\t/** Suspend all sessions and mark the service suspended so late-joining sessions start suspended */\n\tsuspendAll(): void {\n\t\tthis._suspended = true;\n\t\tfor (const record of this.sessionMap.values()) {\n\t\t\trecord.session.suspend();\n\t\t}\n\t\tthis.poller?.suspend();\n\t}\n\n\t/** Resume all sessions (clearing the global suspend state), with optional per-session delay */\n\tresumeAll(getDelay?: (session: RepositoryWatchSession) => number): void {\n\t\tthis._suspended = false;\n\t\tfor (const record of this.sessionMap.values()) {\n\t\t\tconst delayMs = getDelay?.(record.session);\n\t\t\trecord.session.resume(delayMs);\n\t\t}\n\t\tthis.poller?.resume();\n\t}\n\n\tprivate getOrCreateWatchGroup(commonGitDir: string, repoPath: string): WatchGroup {\n\t\tlet group = this.watchGroups.get(commonGitDir);\n\t\tif (group == null) {\n\t\t\tgroup = new WatchGroup(\n\t\t\t\tcommonGitDir,\n\t\t\t\tthis.provider,\n\t\t\t\tthis.poller,\n\t\t\t\tthis.readFile,\n\t\t\t\tthis.readDirectory,\n\t\t\t\t// Only a group that can read the admin entries waits on the folders; asking otherwise reads for nothing,\n\t\t\t\t// and leaves a rejection unhandled\n\t\t\t\tthis.readFile != null && this.readDirectory != null\n\t\t\t\t\t? this.getIgnoredWorktreeRoots?.(repoPath)\n\t\t\t\t\t: undefined,\n\t\t\t\tthis.getIgnoredWorktreeFolders?.(repoPath),\n\t\t\t);\n\t\t\tthis.watchGroups.set(commonGitDir, group);\n\t\t}\n\t\treturn group;\n\t}\n\n\tprivate maybeDisposeWatchGroup(commonGitDir: string): void {\n\t\tconst group = this.watchGroups.get(commonGitDir);\n\t\tif (group == null) return;\n\n\t\tif (group.sessions.size === 0) {\n\t\t\tgroup.dispose();\n\t\t\tthis.watchGroups.delete(commonGitDir);\n\t\t}\n\t}\n\n\tprivate connectToWatchGroup(record: SessionRecord): void {\n\t\tconst { session, gitDir, watchHooks } = record;\n\t\tconst commonGitDir = (gitDir.commonUri ?? gitDir.uri).fsPath;\n\t\tconst group = this.getOrCreateWatchGroup(commonGitDir, session.repoPath);\n\n\t\tconst hooks: WatchGroupHooks = {\n\t\t\tonRepoChanged: (\n\t\t\t\t_repoPath: string,\n\t\t\t\tchanges: RepositoryChange[],\n\t\t\t\tref?: string | false,\n\t\t\t\toverflow?: boolean,\n\t\t\t\tconfigBranches?: ReadonlySet<string>,\n\t\t\t\tmovedWorktree?: string,\n\t\t\t): void => {\n\t\t\t\tif (overflow) {\n\t\t\t\t\tsession.pushUnfencedRepoChanges(changes);\n\t\t\t\t} else {\n\t\t\t\t\tsession.pushRepoChanges(changes, ref, configBranches, movedWorktree);\n\t\t\t\t}\n\n\t\t\t\t// A working tree nothing watches is read again whenever the index or HEAD says it may have moved\n\t\t\t\tif (\n\t\t\t\t\tthis.poller != null &&\n\t\t\t\t\t(changes.includes('index') || changes.includes('head')) &&\n\t\t\t\t\tthis.wtWatchers.get(session.repoPath)?.reliability === 'unwatchable'\n\t\t\t\t) {\n\t\t\t\t\tsession.pushWorkingTreeChanges([], true);\n\t\t\t\t}\n\t\t\t},\n\t\t\tonFetchHeadChanged: (repoPath: string): void => {\n\t\t\t\t// Global first, so a host's cache drops its last-fetched time before any hook re-reads it\n\t\t\t\tthis._onDidChangeFetchHead.fire(repoPath);\n\t\t\t\t// Iterate at fire time so callers that joined after the group was wired up\n\t\t\t\t// still receive events (e.g. a `Repository.watch()` whose hooks landed\n\t\t\t\t// after a hookless `GitRepositoryService.watch` registered first).\n\t\t\t\tfor (const h of watchHooks) {\n\t\t\t\t\th.onFetchHeadChanged?.(repoPath);\n\t\t\t\t}\n\t\t\t},\n\t\t\tonIgnoresChanged: (repoPath: string): void => {\n\t\t\t\tthis.refreshWorkingTreeFilter(repoPath);\n\t\t\t\tfor (const h of watchHooks) {\n\t\t\t\t\th.onIgnoresChanged?.(repoPath);\n\t\t\t\t}\n\t\t\t},\n\t\t\tgetProbeRefs: (): Iterable<string> => {\n\t\t\t\tconst refs = session.getRelevantRefs();\n\t\t\t\tfor (const ref of this.poller?.options.getRefs?.(session.repoPath) ?? []) {\n\t\t\t\t\trefs.add(ref);\n\t\t\t\t}\n\t\t\t\treturn refs;\n\t\t\t},\n\t\t\tonUnwatchableChanged: (): void => this.updateWatchMode(record),\n\t\t};\n\n\t\tconst wasConnected = group.sessions.has(session.repoPath);\n\t\tgroup.addSession(session.repoPath, gitDir, hooks);\n\t\tthis.updateWatchMode(record);\n\t\tif (!wasConnected) {\n\t\t\tthis.fireRepoWatchedIfConnected(record, true);\n\t\t}\n\t}\n\n\tprivate disconnectFromWatchGroup(record: SessionRecord): void {\n\t\tconst { session, gitDir } = record;\n\t\tconst commonGitDir = (gitDir.commonUri ?? gitDir.uri).fsPath;\n\t\tconst group = this.watchGroups.get(commonGitDir);\n\t\tif (group == null) return;\n\n\t\tconst wasConnected = group.sessions.has(session.repoPath);\n\t\tgroup.removeSession(session.repoPath);\n\t\tthis.maybeDisposeWatchGroup(commonGitDir);\n\t\tthis.updateWatchMode(record);\n\t\tif (wasConnected) {\n\t\t\tthis.fireRepoWatchedIfConnected(record, false);\n\t\t}\n\t}\n\n\tprivate isConnected(record: SessionRecord): boolean {\n\t\tconst group = this.watchGroups.get((record.gitDir.commonUri ?? record.gitDir.uri).fsPath);\n\t\treturn group?.sessions.has(record.session.repoPath) ?? false;\n\t}\n\n\t/** Announces that `record` was just connected (`watched`) or disconnected, once that is what it is */\n\tprivate fireRepoWatchedIfConnected(record: SessionRecord, watched: boolean): void {\n\t\tif (this._disposed || this.isConnected(record) !== watched) return;\n\n\t\tthis._onDidChangeRepoWatched.fire({ repoPath: record.session.repoPath, watched: watched });\n\t}\n\n\tprivate computeWatchMode(record: SessionRecord): 'events' | 'poll' | undefined {\n\t\tconst repoPath = record.session.repoPath;\n\t\tconst group = this.watchGroups.get((record.gitDir.commonUri ?? record.gitDir.uri).fsPath);\n\t\tconst connected = group?.sessions.has(repoPath) ?? false;\n\t\tconst wt = this.wtWatchers.get(repoPath);\n\t\tif (!connected && wt == null) return undefined;\n\n\t\treturn group?.isUnwatchable(repoPath) || wt?.reliability === 'unwatchable' ? 'poll' : 'events';\n\t}\n\n\tprivate updateWatchMode(record: SessionRecord): void {\n\t\tif (this._disposed) return;\n\n\t\tconst mode = this.computeWatchMode(record);\n\t\tif (mode == null) {\n\t\t\trecord.watchMode = 'events';\n\t\t\treturn;\n\t\t}\n\t\tif (mode === record.watchMode) return;\n\n\t\trecord.watchMode = mode;\n\t\tthis._onDidChangeWatchMode.fire({ repoPath: record.session.repoPath, mode: mode });\n\t}\n\n\tprivate startWorkingTreeWatcher(record: SessionRecord): void {\n\t\tconst { session, gitDir, watchHooks } = record;\n\t\tconst repoPath = session.repoPath;\n\t\tif (this.wtWatchers.has(repoPath)) return;\n\n\t\tconst canPrune = this.canPruneIgnoredDirectories();\n\t\t// Assigned once the first watcher exists; read by the handlers below instead of a map lookup per event\n\t\tlet entry: WorkingTreeWatcherEntry | undefined;\n\n\t\tlet filter: GitIgnoreFilter | undefined;\n\t\tif (this.getIgnoreFilter != null) {\n\t\t\tfilter = this.getIgnoreFilter(repoPath, gitDir.uri.fsPath);\n\t\t}\n\n\t\t// Buffer events while the gitignore filter loads, then replay\n\t\tlet filterReady = filter == null;\n\t\tlet buffered: string[] | undefined = filter != null ? [] : undefined;\n\t\tlet bufferIncomplete = false;\n\n\t\t// Ahead of `ready()`, so the replay below waits for rules that may have changed while nothing watched them\n\t\tconst revalidated = filter?.revalidate();\n\t\tif (filter != null) {\n\t\t\tconst replay = (): void => {\n\t\t\t\tconst pending = buffered;\n\t\t\t\tconst incomplete = bufferIncomplete;\n\t\t\t\tfilterReady = true;\n\t\t\t\tbuffered = undefined;\n\t\t\t\tbufferIncomplete = false;\n\n\t\t\t\tif (!pending?.length) return;\n\n\t\t\t\tconst paths = filterWorkingTreePaths(pending, repoPath, filter);\n\t\t\t\tif (paths.length > 0 || incomplete) {\n\t\t\t\t\tsession.pushWorkingTreeChanges(paths, incomplete);\n\t\t\t\t}\n\t\t\t};\n\t\t\t// A failed load still replays: the filter keeps the rules it had (none before its first load) and errs\n\t\t\t// toward \"not ignored\", so an extra refresh is the worst case, where dropping the buffer loses real changes\n\t\t\tvoid filter\n\t\t\t\t.ready()\n\t\t\t\t.then(replay, replay)\n\t\t\t\t.catch(() => {});\n\t\t}\n\n\t\t// An ignore rule changed (or may have): refresh the filter (unless it already reloaded) and the pruned set, and\n\t\t// notify the host\n\t\tconst onIgnoreRulesChanged = (refreshFilter: boolean): void => {\n\t\t\tif (refreshFilter && filter != null) {\n\t\t\t\tvoid filter.refresh();\n\t\t\t}\n\t\t\tif (entry != null) {\n\t\t\t\tthis.scheduleIgnoredDirectoriesRefresh(entry);\n\t\t\t}\n\t\t\t// See `connectToWatchGroup` for the iterate-at-fire-time rationale.\n\t\t\tfor (const h of watchHooks) {\n\t\t\t\th.onGitIgnoreChanged?.(repoPath);\n\t\t\t}\n\t\t\t// Route the ignore-rule change through the repo channel as an `ignores` change (like `info/exclude`),\n\t\t\t// so it reaches EVERY session subscriber — including a closed secondary worktree's `watch()` `repoSub`,\n\t\t\t// which has no `onGitIgnoreChanged` hook and would otherwise keep a stale untracked-file list. Coalesces\n\t\t\t// with any hook-fired `ignores` above, so open repos don't double. Unfenced: it comes from the working tree,\n\t\t\t// which a self-write never holds back.\n\t\t\tsession.pushUnfencedRepoChanges(['ignores']);\n\t\t};\n\n\t\tconst onEvent = (event: FileWatchEvent): void => {\n\t\t\t// Dropped events: nothing to filter or buffer, the whole tree needs a re-read. A `.gitignore` edit may be\n\t\t\t// among them, and a filter left on the old rules would keep dropping changes they used to ignore\n\t\t\tif (event.reason === 'overflow') {\n\t\t\t\tsession.pushWorkingTreeChanges([], true);\n\t\t\t\tonIgnoreRulesChanged(true);\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Fast noise check (node_modules, .git, .watchman-cookie-)\n\t\t\tif (shouldIgnoreWorkingTreePath(event.path)) return;\n\n\t\t\t// Detect .gitignore changes (nested ones too, unless git skips them for sitting in an ignored directory).\n\t\t\t// The root .gitignore is only an ignore change; a nested one is also an ordinary working-tree change.\n\t\t\tconst relativePath = isDescendant(event.path, repoPath) ? relative(repoPath, event.path) : undefined;\n\t\t\tif (relativePath === '.gitignore') {\n\t\t\t\tonIgnoreRulesChanged(true);\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (relativePath?.endsWith('/.gitignore') && !(filterReady && filter?.isIgnored(relativePath))) {\n\t\t\t\tonIgnoreRulesChanged(true);\n\t\t\t}\n\n\t\t\tif (!filterReady) {\n\t\t\t\t// Buffer until the gitignore filter is ready. Capped: `ready()` awaits a `core.excludesFile`\n\t\t\t\t// read, which queues behind every other git command, so this window can stay open for a long\n\t\t\t\t// time — and these paths haven't been gitignore-filtered yet, so a build's output all lands\n\t\t\t\t// here. Past the cap, stop retaining and mark the batch partial rather than growing.\n\t\t\t\tif (buffered != null && buffered.length >= maxBufferedWorkingTreePaths) {\n\t\t\t\t\tbufferIncomplete = true;\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tbuffered?.push(event.path);\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Gitignore filter (sync after ready)\n\t\t\tif (filter != null && relativePath != null && filter.isIgnored(relativePath)) {\n\t\t\t\tif (canPrune && entry != null) {\n\t\t\t\t\tthis.onIgnoredEvent(entry, filter, relativePath);\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tsession.pushWorkingTreeChanges([event.path]);\n\t\t};\n\n\t\t// A read from before the watch last stopped; should the rules have moved since, `revalidate` brings a re-read\n\t\tconst kept = canPrune && filter != null ? this.keptIgnoredDirectories.get(filter) : undefined;\n\t\tconst created = this.createWorkingTreeWatcher(\n\t\t\trepoPath,\n\t\t\tonEvent,\n\t\t\tkept != null ? [...workingTreeExcludes, ...kept] : workingTreeExcludes,\n\t\t);\n\t\tentry = {\n\t\t\tsession: session,\n\t\t\tonEvent: onEvent,\n\t\t\tfilter: filter,\n\t\t\twatcher: created.watcher,\n\t\t\tignoredDirectories: kept ?? [],\n\t\t\tgeneration: 0,\n\t\t\treading: false,\n\t\t\trereadQueued: false,\n\t\t\treliability: 'reliable',\n\t\t\tstarting: created.starting,\n\t\t};\n\t\tthis.wtWatchers.set(repoPath, entry);\n\t\tthis.setWorkingTreeReliability(entry, created.reliability, true);\n\n\t\tif (canPrune && kept == null) {\n\t\t\tvoid this.refreshIgnoredDirectories(entry, repoPath);\n\t\t}\n\n\t\t// The kept read predates the rules either outcome lands on, so it goes even when the watch has stopped meanwhile\n\t\tvoid revalidated?.then(\n\t\t\tchanged => {\n\t\t\t\tif (!changed) return;\n\n\t\t\t\tif (filter != null) {\n\t\t\t\t\tthis.keptIgnoredDirectories.delete(filter);\n\t\t\t\t}\n\t\t\t\tif (this.wtWatchers.get(repoPath) === entry) {\n\t\t\t\t\tonIgnoreRulesChanged(false);\n\t\t\t\t}\n\t\t\t},\n\t\t\t() => {\n\t\t\t\tif (filter != null) {\n\t\t\t\t\tthis.keptIgnoredDirectories.delete(filter);\n\t\t\t\t}\n\t\t\t\tif (this.wtWatchers.get(repoPath) === entry) {\n\t\t\t\t\tonIgnoreRulesChanged(true);\n\t\t\t\t}\n\t\t\t},\n\t\t);\n\t}\n\n\tprivate stopWorkingTreeWatcher(repoPath: string): void {\n\t\tconst entry = this.wtWatchers.get(repoPath);\n\t\tif (entry == null) return;\n\n\t\t// Drops any read still in flight, and any refresh waiting on its debounce\n\t\tentry.generation++;\n\t\tclearTimeout(entry.refreshTimer);\n\t\tentry.refreshTimer = undefined;\n\t\tentry.watcher.dispose();\n\t\tif (entry.pollTarget != null) {\n\t\t\tthis.poller?.delete(entry.pollTarget);\n\t\t\tentry.pollTarget = undefined;\n\t\t}\n\t\tthis.wtWatchers.delete(repoPath);\n\t}\n\n\t/**\n\t * Creates a working-tree watcher, with the reliability it reported before returning, and whether it has yet to call\n\t * the `onDidStart` its provider promised\n\t */\n\tprivate createWorkingTreeWatcher(\n\t\trepoPath: string,\n\t\tonEvent: (event: FileWatchEvent) => void,\n\t\texcludes: readonly string[],\n\t): { watcher: FileWatcher; reliability: FileWatcherReliability; starting: boolean } {\n\t\tlet watcher: FileWatcher | undefined;\n\t\tlet started = false;\n\t\t// Not given to `.git` watchers: a host places one for every checkout at startup, and each would cost a rescan\n\t\tconst onDidStart = (): void => {\n\t\t\tif (started) return;\n\n\t\t\tstarted = true;\n\t\t\t// A watch that was live before `createWatcher` returned missed nothing\n\t\t\tif (watcher == null) return;\n\n\t\t\t// The same rescan as a watch coming back, and only for the live watcher, never one already replaced or stopped\n\t\t\tconst entry = this.wtWatchers.get(repoPath);\n\t\t\tif (entry?.watcher === watcher) {\n\t\t\t\tentry.starting = false;\n\t\t\t\tentry.session.pushWorkingTreeChanges([], true);\n\t\t\t}\n\t\t};\n\n\t\tif (this.poller == null) {\n\t\t\twatcher = this.provider.createWatcher(repoPath, '**', onEvent, {\n\t\t\t\texcludes: excludes,\n\t\t\t\tonDidStart: onDidStart,\n\t\t\t});\n\t\t\treturn {\n\t\t\t\twatcher: watcher,\n\t\t\t\treliability: 'reliable',\n\t\t\t\tstarting: this.provider.callsOnDidStart === true && !started,\n\t\t\t};\n\t\t}\n\n\t\tlet reliability: FileWatcherReliability = 'reliable';\n\t\tconst options: FileWatcherOptions = {\n\t\t\texcludes: excludes,\n\t\t\tonDidStart: onDidStart,\n\t\t\tonDidChangeReliability: state => {\n\t\t\t\tif (watcher == null) {\n\t\t\t\t\treliability = state;\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\t// Only the live watcher speaks for the working tree, never one already replaced\n\t\t\t\tconst entry = this.wtWatchers.get(repoPath);\n\t\t\t\tif (entry?.watcher === watcher) {\n\t\t\t\t\tthis.setWorkingTreeReliability(entry, state);\n\t\t\t\t}\n\t\t\t},\n\t\t};\n\t\twatcher = this.provider.createWatcher(repoPath, '**', onEvent, options);\n\t\treturn {\n\t\t\twatcher: watcher,\n\t\t\treliability: reliability,\n\t\t\tstarting: this.provider.callsOnDidStart === true && !started,\n\t\t};\n\t}\n\n\tprivate setWorkingTreeReliability(\n\t\tentry: WorkingTreeWatcherEntry,\n\t\tstate: FileWatcherReliability,\n\t\tinitial?: boolean,\n\t): void {\n\t\tconst previous = entry.reliability;\n\t\tif (previous === state) return;\n\n\t\tentry.reliability = state;\n\t\tthis.updateWorkingTreePollTarget(entry);\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. This rescan stands in for a start still\n\t\t// owed, which a provider that lost the watch may never report\n\t\tif (!initial) {\n\t\t\tentry.starting = false;\n\t\t\tentry.session.pushWorkingTreeChanges([], true);\n\t\t}\n\t\tconst record = this.sessionMap.get(entry.session.repoPath);\n\t\tif (record != null) {\n\t\t\tthis.updateWatchMode(record);\n\t\t}\n\t}\n\n\t/** Polls the host's working-tree fingerprint, when it gives one, while the watcher isn't `reliable` */\n\tprivate updateWorkingTreePollTarget(entry: WorkingTreeWatcherEntry): void {\n\t\tconst poller = this.poller;\n\t\tconst getFingerprint = poller?.options.getWorkingTreeFingerprint;\n\t\tif (poller == null || getFingerprint == null) return;\n\n\t\tif (entry.reliability === 'reliable') {\n\t\t\tif (entry.pollTarget != null) {\n\t\t\t\tpoller.delete(entry.pollTarget);\n\t\t\t\tentry.pollTarget = undefined;\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\tif (entry.pollTarget != null) return;\n\n\t\tconst repoPath = entry.session.repoPath;\n\t\tlet last: string | undefined;\n\t\tconst target: PollTarget = {\n\t\t\tpoll: async (): Promise<void> => {\n\t\t\t\tlet fingerprint: string | undefined;\n\t\t\t\ttry {\n\t\t\t\t\tfingerprint = await getFingerprint(repoPath);\n\t\t\t\t} catch {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (fingerprint == null || entry.pollTarget !== target) return;\n\n\t\t\t\tconst moved = last != null && last !== fingerprint;\n\t\t\t\tlast = fingerprint;\n\t\t\t\t// A fingerprint says the tree moved, not which files did\n\t\t\t\tif (moved) {\n\t\t\t\t\tentry.session.pushWorkingTreeChanges([], true);\n\t\t\t\t}\n\t\t\t},\n\t\t};\n\t\tentry.pollTarget = target;\n\t\tpoller.add(target);\n\t}\n\n\tprivate canPruneIgnoredDirectories(): boolean {\n\t\treturn this.provider.supportsExcludes === true && this.getIgnoredDirectories != null;\n\t}\n\n\t/**\n\t * An event the gitignore post-filter dropped. When its directory is itself ignored, the watcher is watching an\n\t * ignored directory it could prune (one created after the last read), so the ignored set is read again. An ignored\n\t * file in a watched directory (a root `.env`, `src/debug.log`) triggers nothing.\n\t */\n\tprivate onIgnoredEvent(entry: WorkingTreeWatcherEntry, filter: GitIgnoreFilter, relativePath: string): void {\n\t\t// A refresh is already pending and reads the whole set; keep a flood of these events at two field checks\n\t\tif (entry.refreshTimer != null || entry.rereadQueued) return;\n\n\t\t// The outermost ignored directory above the path — the one a read would prune. Keyed on it (not the immediate\n\t\t// parent), so a directory git won't prune costs one read however many subdirectories it has\n\t\tlet ignoredDir: string | undefined;\n\t\tfor (let slash = relativePath.indexOf('/'); slash !== -1; slash = relativePath.indexOf('/', slash + 1)) {\n\t\t\tconst dir = relativePath.slice(0, slash);\n\t\t\tif (entry.unpruned?.has(dir) || entry.unprunable?.has(dir)) return;\n\t\t\tif (filter.isIgnored(`${dir}/`)) {\n\t\t\t\tignoredDir = dir;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif (ignoredDir == null) return;\n\n\t\tentry.unpruned ??= new Set();\n\t\tentry.unpruned.add(ignoredDir);\n\n\t\t// Ignore rules didn't change, so a read in flight stays valid (no generation bump), but it may predate the\n\t\t// directory\n\t\tif (entry.reading) {\n\t\t\tentry.rereadQueued = true;\n\t\t\treturn;\n\t\t}\n\n\t\tthis.armIgnoredDirectoriesRefresh(entry);\n\t}\n\n\t/** Re-reads the git-ignored directories once ignore rules stop changing (trailing debounce, one timer per repo) */\n\tprivate scheduleIgnoredDirectoriesRefresh(entry: WorkingTreeWatcherEntry): void {\n\t\t// Read under the old rules, so a restart must read again even if the watcher stops before this re-read lands\n\t\tif (entry.filter != null) {\n\t\t\tthis.keptIgnoredDirectories.delete(entry.filter);\n\t\t}\n\t\tif (!this.canPruneIgnoredDirectories()) return;\n\n\t\t// A read already in flight is now stale, and a directory git wouldn't prune may be prunable now\n\t\tentry.generation++;\n\t\tentry.unprunable = undefined;\n\t\tclearTimeout(entry.refreshTimer);\n\t\tthis.armIgnoredDirectoriesRefresh(entry);\n\t}\n\n\tprivate armIgnoredDirectoriesRefresh(entry: WorkingTreeWatcherEntry): void {\n\t\tentry.refreshTimer = setTimeout(() => {\n\t\t\tentry.refreshTimer = undefined;\n\t\t\tconst repoPath = entry.session.repoPath;\n\t\t\tif (this.wtWatchers.get(repoPath) !== entry) return;\n\n\t\t\tif (entry.reading) {\n\t\t\t\tentry.rereadQueued = true;\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tvoid this.refreshIgnoredDirectories(entry, repoPath);\n\t\t}, ignoredDirectoriesRefreshDelayMs);\n\t}\n\n\t/** Single-flight: reads the git-ignored directories and, when they changed, swaps in a watcher excluding them */\n\tprivate async refreshIgnoredDirectories(entry: WorkingTreeWatcherEntry, repoPath: string): Promise<void> {\n\t\tif (this.getIgnoredDirectories == null) return;\n\n\t\tentry.reading = true;\n\t\ttry {\n\t\t\tconst generation = entry.generation;\n\t\t\t// The unpruned directories seen so far; any seen during the read wait for the next one\n\t\t\tconst unpruned = entry.unpruned?.size ? [...entry.unpruned] : undefined;\n\n\t\t\tlet directories: readonly string[] | undefined;\n\t\t\ttry {\n\t\t\t\tdirectories = await this.getIgnoredDirectories(repoPath);\n\t\t\t} catch {\n\t\t\t\t// Keep what the watcher has; the next ignore-rule change reads again\n\t\t\t\tdirectories = undefined;\n\t\t\t}\n\n\t\t\tif (entry.generation === generation) {\n\t\t\t\tif (directories != null) {\n\t\t\t\t\tthis.swapWorkingTreeWatcher(entry, repoPath, directories);\n\t\t\t\t\tif (entry.filter != null) {\n\t\t\t\t\t\tthis.keptIgnoredDirectories.set(entry.filter, directories);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (unpruned != null) {\n\t\t\t\t\tthis.settleUnprunedDirectories(entry, unpruned, directories);\n\t\t\t\t}\n\t\t\t}\n\t\t} finally {\n\t\t\tentry.reading = false;\n\t\t}\n\n\t\tif (entry.rereadQueued) {\n\t\t\tentry.rereadQueued = false;\n\t\t\tif (this.wtWatchers.get(repoPath) === entry) {\n\t\t\t\tvoid this.refreshIgnoredDirectories(entry, repoPath);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * A directory the read left unexcluded is one git won't prune (or the read failed), so it never triggers a read\n\t * again until ignore rules change — otherwise each of its events would spawn git.\n\t */\n\tprivate settleUnprunedDirectories(\n\t\tentry: WorkingTreeWatcherEntry,\n\t\tunpruned: readonly string[],\n\t\tdirectories: readonly string[] | undefined,\n\t): void {\n\t\tfor (const dir of unpruned) {\n\t\t\tentry.unpruned?.delete(dir);\n\t\t\tif (directories?.some(d => d === dir || dir.startsWith(`${d}/`))) continue;\n\n\t\t\tentry.unprunable ??= new Set();\n\t\t\tentry.unprunable.add(dir);\n\t\t}\n\t}\n\n\tprivate swapWorkingTreeWatcher(\n\t\tentry: WorkingTreeWatcherEntry,\n\t\trepoPath: string,\n\t\tdirectories: readonly string[],\n\t): void {\n\t\tconst previous = entry.ignoredDirectories;\n\t\tif (previous.length === directories.length && previous.every(d => directories.includes(d))) return;\n\n\t\t// New first, then the old one: the overlap can repeat an event (the session coalesces them), but never loses one.\n\t\t// A provider that places its watch asynchronously leaves a gap until it goes live, which its `onDidStart` rescans\n\t\tlet created: { watcher: FileWatcher; reliability: FileWatcherReliability; starting: boolean };\n\t\ttry {\n\t\t\tcreated = this.createWorkingTreeWatcher(repoPath, entry.onEvent, [...workingTreeExcludes, ...directories]);\n\t\t} catch {\n\t\t\treturn;\n\t\t}\n\n\t\tconst previousWatcher = entry.watcher;\n\t\tentry.watcher = created.watcher;\n\t\t// The replacement owes its own start\n\t\tentry.starting = created.starting;\n\t\tentry.ignoredDirectories = directories;\n\t\tpreviousWatcher.dispose();\n\t\tthis.setWorkingTreeReliability(entry, created.reliability);\n\n\t\t// Files in a directory that is watched again changed while nothing was looking. A directory still covered by\n\t\t// a surviving ancestor entry isn't watched again.\n\t\tif (previous.some(d => !directories.some(n => n === d || d.startsWith(`${n}/`)))) {\n\t\t\tentry.session.pushWorkingTreeChanges([], true);\n\t\t}\n\t}\n\n\tprivate refreshWorkingTreeFilter(repoPath: string): void {\n\t\tconst entry = this.wtWatchers.get(repoPath);\n\t\tif (entry == null) return;\n\n\t\tif (entry.filter != null) {\n\t\t\tvoid entry.filter.refresh();\n\t\t}\n\t\tthis.scheduleIgnoredDirectoriesRefresh(entry);\n\t}\n\n\tprivate disposeSessionRecord(record: SessionRecord): void {\n\t\t// The working tree first: with it still up, leaving the group would read as a move back to `'events'` and\n\t\t// announce one for a repository that is going away\n\t\tthis.stopWorkingTreeWatcher(record.session.repoPath);\n\t\tthis.disconnectFromWatchGroup(record);\n\t\tthis.updateWatchMode(record);\n\t\trecord.session.dispose();\n\t}\n}\n\nfunction filterWorkingTreePaths(absolutePaths: string[], repoPath: string, filter: GitIgnoreFilter): string[] {\n\tconst result: string[] = [];\n\tfor (const p of absolutePaths) {\n\t\tif (!isDescendant(p, repoPath)) continue;\n\n\t\tconst relativePath = relative(repoPath, p);\n\t\tif (!filter.isIgnored(relativePath)) {\n\t\t\tresult.push(p);\n\t\t}\n\t}\n\treturn result;\n}\n"],"mappings":";;;;;;;;;;;;;AA4BA,MAAM,8BAA8B;;AAGpC,MAAM,mCAAmC;;;;;;;;;;;;AAkKzC,IAAa,yBAAb,MAAiE;CAChE,yBAA0C,IAAI,QAAgC;;CAE9E,IAAI,wBAAuD;EAC1D,OAAO,KAAK,uBAAuB;CACpC;CAEA,0BAA2C,IAAI,QAAgB;;;CAG/D,IAAI,yBAAwC;EAC3C,OAAO,KAAK,wBAAwB;CACrC;CAEA,wBAAyC,IAAI,QAAgB;;;;;;CAM7D,IAAI,uBAAsC;EACzC,OAAO,KAAK,sBAAsB;CACnC;CAEA,wBAAyC,IAAI,QAAuD;;;;;;CAMpG,IAAI,uBAA6E;EAChF,OAAO,KAAK,sBAAsB;CACnC;CAEA,0BAA2C,IAAI,QAAgD;;;;;;;;CAQ/F,IAAI,yBAAwE;EAC3E,OAAO,KAAK,wBAAwB;CACrC;CAEA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAEA,6BAA8B,IAAI,IAA2B;CAC7D,8BAA+B,IAAI,IAAwB;CAC3D,6BAA8B,IAAI,IAAqC;;;;;CAKvE,yCAA0C,IAAI,QAA4C;CAC1F,YAAoB;;CAEpB,aAAqB;CAErB,YAAY,SAA8B;EACzC,KAAK,WAAW,QAAQ;EACxB,KAAK,qBAAqB,QAAQ;EAClC,KAAK,4BAA4B,QAAQ;EACzC,KAAK,uBAAuB,QAAQ;EACpC,KAAK,8BAA8B,QAAQ;EAC3C,KAAK,kBAAkB,QAAQ;EAC/B,KAAK,wBAAwB,QAAQ;EACrC,KAAK,0BAA0B,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SAAS,MAAK,MAAK,CAAC,YAAY,MAAK,MAAK,MAAM,KAAK,EAAE,WAAW,GAAG,EAAE,EAAE,CAAC,CAAC,GAC9E,MAAM,QAAQ,uBAAuB,CAAC,GAAG,IAAI;CAE/C;CAEA,yBAAiC,UAAwB;EACxD,MAAM,QAAQ,KAAK,WAAW,IAAI,QAAQ;EAC1C,IAAI,SAAS,MAAM;EAEnB,IAAI,MAAM,UAAU,MACnB,MAAW,OAAO,QAAQ;EAE3B,KAAK,kCAAkC,KAAK;CAC7C;CAEA,qBAA6B,QAA6B;EAGzD,KAAK,uBAAuB,OAAO,QAAQ,QAAQ;EACnD,KAAK,yBAAyB,MAAM;EACpC,KAAK,gBAAgB,MAAM;EAC3B,OAAO,QAAQ,QAAQ;CACxB;AACD;AAEA,SAAS,uBAAuB,eAAyB,UAAkB,QAAmC;CAC7G,MAAM,SAAmB,CAAC;CAC1B,KAAK,MAAM,KAAK,eAAe;EAC9B,IAAI,CAAC,aAAa,GAAG,QAAQ,GAAG;EAEhC,MAAM,eAAe,SAAS,UAAU,CAAC;EACzC,IAAI,CAAC,OAAO,UAAU,YAAY,GACjC,OAAO,KAAK,CAAC;CAEf;CACA,OAAO;AACR"}
@@ -53,6 +53,8 @@ export interface WatchSessionOptions {
53
53
  */
54
54
  readonly onDidFireWorkingTreeChange?: (repoPath: string) => void;
55
55
  }
56
+ /** The debounce a repo subscriber gets when it names none */
57
+ export declare const defaultRepoDelay = 250;
56
58
  /**
57
59
  * Per-repository session that owns the debounce/coalesce/suspend
58
60
  * pipeline for both repo (.git) and working-tree changes.
@@ -89,6 +91,12 @@ export declare class RepositoryWatchSession implements UnifiedDisposable {
89
91
  * changed; `undefined` once any report may have changed anything else
90
92
  */
91
93
  private pendingRepoConfigBranches;
94
+ /**
95
+ * For a pending `worktreeHead` change, the admin ids of the linked worktrees whose HEAD moved outside core's announced
96
+ * writes, as the reports not taken for a write's own named them; `undefined` once any such report, or an open
97
+ * announcement, may have been any linked worktree's
98
+ */
99
+ private pendingRepoMovedWorktrees;
92
100
  private readonly repoClock;
93
101
  private effectiveRepoMs;
94
102
  private effectiveRepoMaxWaitMs;
@@ -173,9 +181,11 @@ export declare class RepositoryWatchSession implements UnifiedDisposable {
173
181
  * file changed; a ref kind in `changes` is attributed to it when the kinds match, and is otherwise unnamed.
174
182
  * `false` preserves cache invalidations for a config edit without claiming any ref moved. `configBranches`, for a
175
183
  * `config` among `changes`, are the local branches (full ref names) whose `branch.<name>` sections are all that
176
- * changed in `.git/config`; without it, the config change may be anywhere.
184
+ * changed in `.git/config`; without it, the config change may be anywhere. `movedWorktree`, for a `worktreeHead`
185
+ * among `changes`, is the admin id of the linked worktree whose HEAD moved; without it, any linked worktree's may
186
+ * have.
177
187
  */
178
- pushRepoChanges(changes: RepositoryChange[], ref?: string | false, configBranches?: ReadonlySet<string>): void;
188
+ pushRepoChanges(changes: RepositoryChange[], ref?: string | false, configBranches?: ReadonlySet<string>, movedWorktree?: string): void;
179
189
  /**
180
190
  * Push watcher-observed repo changes that no write of core's can account for — an overflow's rescan, or an ignore
181
191
  * rule changed in the working tree — so {@link noteSelfWrite} never replaces them or takes them for its echo. Ref
@@ -190,16 +200,19 @@ export declare class RepositoryWatchSession implements UnifiedDisposable {
190
200
  * them in `announced`. A ref kind is unnamed unless `refs` names refs of that kind (the full ref names the write
191
201
  * moved), in which case it carries those names and no other ref of the kind counts as changed by the write.
192
202
  * `config` is confined to the `branch.<name>` sections of the local branches `refs` names when
193
- * `options.configConfinedToRefs` says so, and the event carries them (`configBranches`);
203
+ * `options.configConfinedToRefs` says so, and the event carries them (`configBranches`). `worktreeHead` is
204
+ * confined to the linked worktrees `options.movedWorktrees` names by admin id (none, for a write that moved only
205
+ * the main checkout's HEAD), and is open without it;
194
206
  * - a raw change of an announced kind is the write's own report of it only when it is provably within what the
195
- * write announced: a ref the write named or a ref directory holding one, or a config change confined to branches
196
- * the write's config was confined to. Pending when the announcement arrives, it is replaced. Arriving later, it
197
- * merges and the kind stays announced only within the repo debounce delay of the announcement; a window can stay
198
- * pending for minutes while the session is suspended, and a later move of the same ref is as likely an outside
199
- * one. Any other report of the kind is an outside change: it stays, and the kind isn't `announced`, since the
200
- * host has not handled the outside part. A write never names `HEAD`, but a commit locks it to write its reflog,
201
- * so under a write that announced `head`, a report of the `HEAD` file within the same delay is the write's echo,
202
- * its `heads` part included;
207
+ * write announced: a ref the write named or a ref directory holding one, a config change confined to branches
208
+ * the write's config was confined to, or a `worktreeHead` report of a worktree the write named, or of none (the
209
+ * `worktrees` folder, a rescan). Pending when the announcement arrives, it is replaced, save the worktrees the
210
+ * write didn't name, which stay as an outside move. Arriving later, it merges and the kind stays announced only
211
+ * within the repo debounce delay of the announcement; a window can stay pending for minutes while the session is
212
+ * suspended, and a later move of the same ref is as likely an outside one. Any other report of the kind is an
213
+ * outside change: it stays, and the kind isn't `announced`, since the host has not handled the outside part. A
214
+ * write never names `HEAD`, but a commit locks it to write its reflog, so under a write that announced `head`, a
215
+ * report of the `HEAD` file within the same delay is the write's echo, its `heads` part included;
203
216
  * - a kind the write announced open (unnamed, or `config` unconfined) covers any change of the kind: raw changes
204
217
  * of it still pending are replaced, since the host evicts everything of the kind after the write. One arriving
205
218
  * within the repo debounce delay of the announcement, before its event fires, is taken for the write's own late
@@ -215,6 +228,7 @@ export declare class RepositoryWatchSession implements UnifiedDisposable {
215
228
  */
216
229
  noteSelfWrite(changes: readonly RepositoryChange[], refs?: readonly string[], options?: {
217
230
  readonly configConfinedToRefs?: boolean;
231
+ readonly movedWorktrees?: readonly string[];
218
232
  }): void;
219
233
  /** Push working tree file changes into the pipeline */
220
234
  /** `incomplete` marks the batch as partial when the caller already dropped paths of its own. */
@@ -230,13 +244,16 @@ export declare class RepositoryWatchSession implements UnifiedDisposable {
230
244
  * {@link pushUnfencedRepoChanges}), or core's announced write. A kind stays announced only while nothing else
231
245
  * reports it in the pending window, save the write's own report of it (see {@link noteSelfWrite}).
232
246
  * `configBranches` confines a `config` among `changes` to those branches' sections; without it, it may be anywhere.
247
+ * `movedWorktrees` names the linked worktrees whose HEAD a `worktreeHead` among `changes` moved; without it, it may
248
+ * be any linked worktree's.
233
249
  */
234
250
  private coalesceRepo;
235
251
  /**
236
252
  * Whether a raw report of `change`, confined to `names` (`undefined`: not confined), is the announced write's own.
237
253
  * It must arrive within the repo debounce delay of the announcement, as it always had to. An open announcement
238
254
  * asks nothing more; one confined to names also needs every name the report carries to be one the write announced,
239
- * save the `heads` part of a `HEAD` report under a write that announced `head` in time, which is a commit's echo.
255
+ * save the `heads` part of a `HEAD` report under a write that announced `head` in time, which is a commit's echo. A
256
+ * `worktreeHead` report naming no worktree (the `worktrees` folder, a rescan) can't be told apart from the write's.
240
257
  */
241
258
  private isOwnReport;
242
259
  /** Whether a raw `heads` report confined to `HEAD` is the echo of a write that announced `head` in time */
@@ -3,6 +3,7 @@ import { Emitter } from "../../utils/event.js";
3
3
  import { allWatchedRepositoryChanges } from "./classifyChange.js";
4
4
  import { WatcherRepoChangeEvent, findCoveringRefName, getRefChangeKind, isRefChangeKind } from "./changeEvent.js";
5
5
  //#region ../git/src/watching/watchSession.ts
6
+ /** The debounce a repo subscriber gets when it names none */
6
7
  const defaultRepoDelay = 250;
7
8
  const defaultWorkingTreeDelay = 2500;
8
9
  const defaultRepoMaxWait = 2e3;
@@ -159,6 +160,12 @@ var RepositoryWatchSession = class RepositoryWatchSession {
159
160
  * changed; `undefined` once any report may have changed anything else
160
161
  */
161
162
  pendingRepoConfigBranches;
163
+ /**
164
+ * For a pending `worktreeHead` change, the admin ids of the linked worktrees whose HEAD moved outside core's announced
165
+ * writes, as the reports not taken for a write's own named them; `undefined` once any such report, or an open
166
+ * announcement, may have been any linked worktree's
167
+ */
168
+ pendingRepoMovedWorktrees;
162
169
  repoClock;
163
170
  effectiveRepoMs;
164
171
  effectiveRepoMaxWaitMs;
@@ -182,7 +189,7 @@ var RepositoryWatchSession = class RepositoryWatchSession {
182
189
  onDidFireWorkingTreeChangeCallback;
183
190
  constructor(options) {
184
191
  this.repoPath = options.repoPath;
185
- this.defaultRepoMs = options.defaultRepoDelayMs ?? defaultRepoDelay;
192
+ this.defaultRepoMs = options.defaultRepoDelayMs ?? 250;
186
193
  this.defaultWorkingTreeMs = options.defaultWorkingTreeDelayMs ?? defaultWorkingTreeDelay;
187
194
  this.defaultRepoMaxWaitMs = options.defaultRepoMaxWaitMs ?? defaultRepoMaxWait;
188
195
  this.defaultWorkingTreeMaxWaitMs = options.defaultWorkingTreeMaxWaitMs ?? defaultWorkingTreeMaxWait;
@@ -354,11 +361,13 @@ var RepositoryWatchSession = class RepositoryWatchSession {
354
361
  * file changed; a ref kind in `changes` is attributed to it when the kinds match, and is otherwise unnamed.
355
362
  * `false` preserves cache invalidations for a config edit without claiming any ref moved. `configBranches`, for a
356
363
  * `config` among `changes`, are the local branches (full ref names) whose `branch.<name>` sections are all that
357
- * changed in `.git/config`; without it, the config change may be anywhere.
364
+ * changed in `.git/config`; without it, the config change may be anywhere. `movedWorktree`, for a `worktreeHead`
365
+ * among `changes`, is the admin id of the linked worktree whose HEAD moved; without it, any linked worktree's may
366
+ * have.
358
367
  */
359
- pushRepoChanges(changes, ref, configBranches) {
368
+ pushRepoChanges(changes, ref, configBranches, movedWorktree) {
360
369
  if (this._disposed) return;
361
- this.coalesceRepo(changes, ref, "raw", configBranches);
370
+ this.coalesceRepo(changes, ref, "raw", configBranches, movedWorktree != null ? /* @__PURE__ */ new Set([movedWorktree]) : void 0);
362
371
  }
363
372
  /**
364
373
  * Push watcher-observed repo changes that no write of core's can account for — an overflow's rescan, or an ignore
@@ -377,16 +386,19 @@ var RepositoryWatchSession = class RepositoryWatchSession {
377
386
  * them in `announced`. A ref kind is unnamed unless `refs` names refs of that kind (the full ref names the write
378
387
  * moved), in which case it carries those names and no other ref of the kind counts as changed by the write.
379
388
  * `config` is confined to the `branch.<name>` sections of the local branches `refs` names when
380
- * `options.configConfinedToRefs` says so, and the event carries them (`configBranches`);
389
+ * `options.configConfinedToRefs` says so, and the event carries them (`configBranches`). `worktreeHead` is
390
+ * confined to the linked worktrees `options.movedWorktrees` names by admin id (none, for a write that moved only
391
+ * the main checkout's HEAD), and is open without it;
381
392
  * - a raw change of an announced kind is the write's own report of it only when it is provably within what the
382
- * write announced: a ref the write named or a ref directory holding one, or a config change confined to branches
383
- * the write's config was confined to. Pending when the announcement arrives, it is replaced. Arriving later, it
384
- * merges and the kind stays announced only within the repo debounce delay of the announcement; a window can stay
385
- * pending for minutes while the session is suspended, and a later move of the same ref is as likely an outside
386
- * one. Any other report of the kind is an outside change: it stays, and the kind isn't `announced`, since the
387
- * host has not handled the outside part. A write never names `HEAD`, but a commit locks it to write its reflog,
388
- * so under a write that announced `head`, a report of the `HEAD` file within the same delay is the write's echo,
389
- * its `heads` part included;
393
+ * write announced: a ref the write named or a ref directory holding one, a config change confined to branches
394
+ * the write's config was confined to, or a `worktreeHead` report of a worktree the write named, or of none (the
395
+ * `worktrees` folder, a rescan). Pending when the announcement arrives, it is replaced, save the worktrees the
396
+ * write didn't name, which stay as an outside move. Arriving later, it merges and the kind stays announced only
397
+ * within the repo debounce delay of the announcement; a window can stay pending for minutes while the session is
398
+ * suspended, and a later move of the same ref is as likely an outside one. Any other report of the kind is an
399
+ * outside change: it stays, and the kind isn't `announced`, since the host has not handled the outside part. A
400
+ * write never names `HEAD`, but a commit locks it to write its reflog, so under a write that announced `head`, a
401
+ * report of the `HEAD` file within the same delay is the write's echo, its `heads` part included;
390
402
  * - a kind the write announced open (unnamed, or `config` unconfined) covers any change of the kind: raw changes
391
403
  * of it still pending are replaced, since the host evicts everything of the kind after the write. One arriving
392
404
  * within the repo debounce delay of the announcement, before its event fires, is taken for the write's own late
@@ -406,12 +418,20 @@ var RepositoryWatchSession = class RepositoryWatchSession {
406
418
  const announced = all ? allWatchedRepositoryChanges : changes.filter((c) => isAnnounceable(c));
407
419
  const named = all ? void 0 : groupNamedRefs(changes, refs);
408
420
  const configBranches = !all && options?.configConfinedToRefs === true && changes.includes("config") ? getBranchRefs(refs) : void 0;
421
+ const movedWorktrees = !all && options?.movedWorktrees != null && changes.includes("worktreeHead") ? new Set(options.movedWorktrees) : void 0;
409
422
  for (const change of this.pendingRepoChanges) {
410
423
  if (this.pendingRepoUnfencedChanges.has(change) || !isAnnounceable(change)) continue;
411
424
  if (!all && !changes.includes(change)) continue;
412
425
  if (change === "config" && configBranches != null) {
413
426
  if (this.pendingRepoAnnounced.has(change)) continue;
414
427
  if (!isSubsetOf(this.pendingRepoConfigBranches, configBranches)) continue;
428
+ } else if (change === "worktreeHead" && movedWorktrees != null) {
429
+ if (this.pendingRepoAnnounced.has(change)) continue;
430
+ const outside = this.pendingRepoMovedWorktrees;
431
+ if (outside != null) {
432
+ for (const id of movedWorktrees) outside.delete(id);
433
+ if (outside.size) continue;
434
+ }
415
435
  }
416
436
  const names = isRefChangeKind(change) ? named?.get(change) : void 0;
417
437
  if (names != null) {
@@ -422,12 +442,13 @@ var RepositoryWatchSession = class RepositoryWatchSession {
422
442
  this.pendingRepoChanges.delete(change);
423
443
  this.pendingRepoAnnounced.delete(change);
424
444
  if (change === "config") this.pendingRepoConfigBranches = void 0;
445
+ else if (change === "worktreeHead") this.pendingRepoMovedWorktrees = void 0;
425
446
  if (!isRefChangeKind(change)) continue;
426
447
  this.pendingRepoUnnamedRefKinds.delete(change);
427
448
  for (const ref of this.pendingRepoRefs) if (getRefChangeKind(ref) === change) this.pendingRepoRefs.delete(ref);
428
449
  }
429
450
  if (announced.length !== 0) {
430
- this.coalesceRepo(named != null ? announced.filter((c) => !isRefChangeKind(c) || !named.has(c)) : announced, void 0, "announced", configBranches);
451
+ this.coalesceRepo(named != null ? announced.filter((c) => !isRefChangeKind(c) || !named.has(c)) : announced, void 0, "announced", configBranches, movedWorktrees);
431
452
  if (named != null) for (const [kind, names] of named) for (const name of names) {
432
453
  this.coalesceRepo([kind], name, "announced");
433
454
  if (this.pendingRepoRefs.has(name)) this.pendingRepoAnnouncedRefs.add(name);
@@ -468,7 +489,7 @@ var RepositoryWatchSession = class RepositoryWatchSession {
468
489
  names: this.pendingRepoRefs,
469
490
  unnamed: this.pendingRepoUnnamedRefKinds,
470
491
  configBranches: this.pendingRepoConfigBranches
471
- }, this.pendingRepoAnnounced.keys());
492
+ }, this.pendingRepoAnnounced.keys(), this.pendingRepoMovedWorktrees);
472
493
  this.clearPendingRepoChanges();
473
494
  this.onDidFireRepoChangeCallback?.(event);
474
495
  this.repoEmitter.fire(event);
@@ -478,8 +499,10 @@ var RepositoryWatchSession = class RepositoryWatchSession {
478
499
  * {@link pushUnfencedRepoChanges}), or core's announced write. A kind stays announced only while nothing else
479
500
  * reports it in the pending window, save the write's own report of it (see {@link noteSelfWrite}).
480
501
  * `configBranches` confines a `config` among `changes` to those branches' sections; without it, it may be anywhere.
502
+ * `movedWorktrees` names the linked worktrees whose HEAD a `worktreeHead` among `changes` moved; without it, it may
503
+ * be any linked worktree's.
481
504
  */
482
- coalesceRepo(changes, ref, origin, configBranches) {
505
+ coalesceRepo(changes, ref, origin, configBranches, movedWorktrees) {
483
506
  if (changes.length === 0) return;
484
507
  const now = performance.now();
485
508
  const refKind = typeof ref === "string" ? getRefChangeKind(ref) : void 0;
@@ -488,9 +511,11 @@ var RepositoryWatchSession = class RepositoryWatchSession {
488
511
  let names;
489
512
  if (origin !== "unfenced") {
490
513
  if (change === "config") names = configBranches;
514
+ else if (change === "worktreeHead") names = movedWorktrees;
491
515
  else if (typeof ref === "string" && refKind === change) names = /* @__PURE__ */ new Set([ref]);
492
516
  }
493
517
  const announcement = this.pendingRepoAnnounced.get(change);
518
+ let own = false;
494
519
  if (origin === "announced") {
495
520
  if (!pending) this.pendingRepoAnnounced.set(change, {
496
521
  at: now,
@@ -501,7 +526,7 @@ var RepositoryWatchSession = class RepositoryWatchSession {
501
526
  else announcement.names = void 0;
502
527
  }
503
528
  } else {
504
- const own = origin === "raw" && announcement != null && this.isOwnReport(change, announcement, names, now);
529
+ own = origin === "raw" && announcement != null && this.isOwnReport(change, announcement, names, now);
505
530
  if (announcement != null && !own) this.pendingRepoAnnounced.delete(change);
506
531
  else if (!pending && origin === "raw" && this.isHeadEcho(change, names, now)) this.pendingRepoAnnounced.set(change, {
507
532
  at: now,
@@ -514,6 +539,10 @@ var RepositoryWatchSession = class RepositoryWatchSession {
514
539
  if (!pending) branches = names != null ? new Set(names) : void 0;
515
540
  else if (this.pendingRepoConfigBranches != null && names != null) branches = /* @__PURE__ */ new Set([...this.pendingRepoConfigBranches, ...names]);
516
541
  this.pendingRepoConfigBranches = branches != null && branches.size <= maxPendingRefNames ? branches : void 0;
542
+ } else if (change === "worktreeHead") {
543
+ if (!pending) this.pendingRepoMovedWorktrees = /* @__PURE__ */ new Set();
544
+ if (names == null && !own) this.pendingRepoMovedWorktrees = void 0;
545
+ else if (names != null && !own && origin !== "announced") for (const id of names) this.pendingRepoMovedWorktrees?.add(id);
517
546
  }
518
547
  this.pendingRepoChanges.add(change);
519
548
  if (ref === false || !isRefChangeKind(change)) continue;
@@ -526,12 +555,13 @@ var RepositoryWatchSession = class RepositoryWatchSession {
526
555
  * Whether a raw report of `change`, confined to `names` (`undefined`: not confined), is the announced write's own.
527
556
  * It must arrive within the repo debounce delay of the announcement, as it always had to. An open announcement
528
557
  * asks nothing more; one confined to names also needs every name the report carries to be one the write announced,
529
- * save the `heads` part of a `HEAD` report under a write that announced `head` in time, which is a commit's echo.
558
+ * save the `heads` part of a `HEAD` report under a write that announced `head` in time, which is a commit's echo. A
559
+ * `worktreeHead` report naming no worktree (the `worktrees` folder, a rescan) can't be told apart from the write's.
530
560
  */
531
561
  isOwnReport(change, announcement, names, now) {
532
562
  if (now - announcement.at > this.effectiveRepoMs) return false;
533
563
  if (announcement.names == null) return true;
534
- if (names == null) return false;
564
+ if (names == null) return change === "worktreeHead";
535
565
  if (isRefChangeKind(change) ? isCoveredBy(names, announcement.names) : isSubsetOf(names, announcement.names)) return true;
536
566
  return this.isHeadEcho(change, names, now);
537
567
  }
@@ -556,6 +586,7 @@ var RepositoryWatchSession = class RepositoryWatchSession {
556
586
  this.pendingRepoAnnounced.clear();
557
587
  this.pendingRepoAnnouncedRefs.clear();
558
588
  this.pendingRepoConfigBranches = void 0;
589
+ this.pendingRepoMovedWorktrees = void 0;
559
590
  }
560
591
  flushWorkingTree() {
561
592
  if (!this.hasPendingWorkingTreeChanges) return;
@@ -704,9 +735,9 @@ function narrowToRelevantRefs(e, relevantRefs) {
704
735
  names: keptNames,
705
736
  unnamed: e.unnamedRefKinds,
706
737
  configBranches
707
- }, e.announced);
738
+ }, e.announced, e.movedWorktrees);
708
739
  }
709
740
  //#endregion
710
- export { RepositoryWatchSession };
741
+ export { RepositoryWatchSession, defaultRepoDelay };
711
742
 
712
743
  //# sourceMappingURL=watchSession.js.map