@gitkraken/core-gitlens 0.37.1 → 0.38.1

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 (116) hide show
  1. package/CHANGELOG.md +69 -1
  2. package/dist/git/cache.d.ts +128 -8
  3. package/dist/git/cache.js +425 -46
  4. package/dist/git/cache.js.map +1 -1
  5. package/dist/git/features.d.ts +1 -1
  6. package/dist/git/features.js +3 -0
  7. package/dist/git/features.js.map +1 -1
  8. package/dist/git/providers/branches.d.ts +42 -1
  9. package/dist/git/providers/diff.d.ts +17 -0
  10. package/dist/git/providers/provider.d.ts +7 -0
  11. package/dist/git/providers/shared/remotes.js +8 -4
  12. package/dist/git/providers/shared/remotes.js.map +1 -1
  13. package/dist/git/remotes/matcher.js +2 -2
  14. package/dist/git/remotes/matcher.js.map +1 -1
  15. package/dist/git/repositoryService.d.ts +16 -1
  16. package/dist/git/repositoryService.js +51 -3
  17. package/dist/git/repositoryService.js.map +1 -1
  18. package/dist/git/run.types.d.ts +1 -0
  19. package/dist/git/service.js +6 -2
  20. package/dist/git/service.js.map +1 -1
  21. package/dist/git/utils/fileStatus.utils.d.ts +5 -0
  22. package/dist/git/utils/fileStatus.utils.js +18 -1
  23. package/dist/git/utils/fileStatus.utils.js.map +1 -1
  24. package/dist/git/watching/changeEvent.d.ts +13 -3
  25. package/dist/git/watching/changeEvent.js +15 -4
  26. package/dist/git/watching/changeEvent.js.map +1 -1
  27. package/dist/git/watching/changeOrdinal.d.ts +9 -0
  28. package/dist/git/watching/changeOrdinal.js +14 -0
  29. package/dist/git/watching/changeOrdinal.js.map +1 -0
  30. package/dist/git/watching/unwatchedCacheValidator.d.ts +38 -5
  31. package/dist/git/watching/unwatchedCacheValidator.js +180 -36
  32. package/dist/git/watching/unwatchedCacheValidator.js.map +1 -1
  33. package/dist/git/watching/watchGroup.d.ts +63 -14
  34. package/dist/git/watching/watchGroup.js +213 -74
  35. package/dist/git/watching/watchGroup.js.map +1 -1
  36. package/dist/git/watching/watchService.js +4 -3
  37. package/dist/git/watching/watchService.js.map +1 -1
  38. package/dist/git/watching/watchSession.d.ts +10 -2
  39. package/dist/git/watching/watchSession.js +18 -4
  40. package/dist/git/watching/watchSession.js.map +1 -1
  41. package/dist/git/watching/watcherPatterns.d.ts +18 -4
  42. package/dist/git/watching/watcherPatterns.js +39 -8
  43. package/dist/git/watching/watcherPatterns.js.map +1 -1
  44. package/dist/git/watching/worktreeSummary.d.ts +23 -12
  45. package/dist/git/watching/worktreeSummary.js +164 -41
  46. package/dist/git/watching/worktreeSummary.js.map +1 -1
  47. package/dist/git-cli/cliGitProvider.d.ts +1 -0
  48. package/dist/git-cli/cliGitProvider.js +11 -2
  49. package/dist/git-cli/cliGitProvider.js.map +1 -1
  50. package/dist/git-cli/exec/git.d.ts +7 -2
  51. package/dist/git-cli/exec/git.js +46 -10
  52. package/dist/git-cli/exec/git.js.map +1 -1
  53. package/dist/git-cli/exec/headState.d.ts +24 -0
  54. package/dist/git-cli/exec/headState.js +46 -6
  55. package/dist/git-cli/exec/headState.js.map +1 -1
  56. package/dist/git-cli/parsers/logParser.js +6 -3
  57. package/dist/git-cli/parsers/logParser.js.map +1 -1
  58. package/dist/git-cli/providers/branches.d.ts +135 -10
  59. package/dist/git-cli/providers/branches.js +622 -80
  60. package/dist/git-cli/providers/branches.js.map +1 -1
  61. package/dist/git-cli/providers/commits.d.ts +16 -0
  62. package/dist/git-cli/providers/commits.js +80 -28
  63. package/dist/git-cli/providers/commits.js.map +1 -1
  64. package/dist/git-cli/providers/config.d.ts +10 -0
  65. package/dist/git-cli/providers/config.js +50 -12
  66. package/dist/git-cli/providers/config.js.map +1 -1
  67. package/dist/git-cli/providers/contributors.js +11 -7
  68. package/dist/git-cli/providers/contributors.js.map +1 -1
  69. package/dist/git-cli/providers/diff.d.ts +12 -0
  70. package/dist/git-cli/providers/diff.js +107 -15
  71. package/dist/git-cli/providers/diff.js.map +1 -1
  72. package/dist/git-cli/providers/graph.js +32 -25
  73. package/dist/git-cli/providers/graph.js.map +1 -1
  74. package/dist/git-cli/providers/operations.d.ts +37 -3
  75. package/dist/git-cli/providers/operations.js +124 -46
  76. package/dist/git-cli/providers/operations.js.map +1 -1
  77. package/dist/git-cli/providers/patch.js +1 -1
  78. package/dist/git-cli/providers/patch.js.map +1 -1
  79. package/dist/git-cli/providers/refs.d.ts +1 -1
  80. package/dist/git-cli/providers/refs.js +10 -11
  81. package/dist/git-cli/providers/refs.js.map +1 -1
  82. package/dist/git-cli/providers/status.d.ts +4 -5
  83. package/dist/git-cli/providers/status.js +36 -33
  84. package/dist/git-cli/providers/status.js.map +1 -1
  85. package/dist/git-cli/providers/tags.d.ts +8 -0
  86. package/dist/git-cli/providers/tags.js +53 -34
  87. package/dist/git-cli/providers/tags.js.map +1 -1
  88. package/dist/git-cli/service.d.ts +15 -0
  89. package/dist/git-cli/service.js +19 -1
  90. package/dist/git-cli/service.js.map +1 -1
  91. package/dist/plus/git-github/providers/github/diff.d.ts +1 -0
  92. package/dist/plus/git-github/providers/github/diff.js +6 -1
  93. package/dist/plus/git-github/providers/github/diff.js.map +1 -1
  94. package/dist/plus/integrations/integrationService.js +9 -0
  95. package/dist/plus/integrations/integrationService.js.map +1 -1
  96. package/dist/plus/integrations/providers/jira-server.js +1 -1
  97. package/dist/plus/integrations/providers/jira-server.js.map +1 -1
  98. package/dist/plus/integrations/providers/jira.d.ts +20 -9
  99. package/dist/plus/integrations/providers/jira.js +114 -99
  100. package/dist/plus/integrations/providers/jira.js.map +1 -1
  101. package/dist/plus/integrations/providers/linear.d.ts +11 -4
  102. package/dist/plus/integrations/providers/linear.js +75 -32
  103. package/dist/plus/integrations/providers/linear.js.map +1 -1
  104. package/dist/plus/integrations/providers/utils/discoveryCache.d.ts +35 -4
  105. package/dist/plus/integrations/providers/utils/discoveryCache.js +45 -11
  106. package/dist/plus/integrations/providers/utils/discoveryCache.js.map +1 -1
  107. package/dist/utils/env/node/exec.d.ts +8 -4
  108. package/dist/utils/env/node/exec.js +115 -9
  109. package/dist/utils/env/node/exec.js.map +1 -1
  110. package/dist/utils/holdOffMap.d.ts +23 -0
  111. package/dist/utils/holdOffMap.js +43 -0
  112. package/dist/utils/holdOffMap.js.map +1 -0
  113. package/dist/utils/promiseCache.d.ts +15 -2
  114. package/dist/utils/promiseCache.js +34 -4
  115. package/dist/utils/promiseCache.js.map +1 -1
  116. package/package.json +1 -1
@@ -3,7 +3,7 @@ import { isDescendant, joinPaths, normalizePath, relative } from "../../utils/pa
3
3
  import { getWorktreeAdminId, isIgnoredWorktreeEntry, parseWorktreeAdminPath } from "../utils/repository.utils.js";
4
4
  import { FileType } from "../context.js";
5
5
  import { GitDirProbeTarget } from "./gitDirPoller.js";
6
- import { dotGitGlobCombined, dotGitGlobCommon, dotGitGlobRoot, getGitDirRefProbes, getIgnoredWorktreeFolderExcludes, gitDirCommonProbes, gitDirExcludes, gitDirProbesByEmittedPath, gitDirRootProbes, shouldIgnoreRepoPath } from "./watcherPatterns.js";
6
+ import { dotGitGlobCombined, dotGitGlobCommon, dotGitGlobRoot, getGitDirRefProbes, getIgnoredWorktreeFolderExcludes, gitDirCommonProbes, gitDirExcludes, gitDirProbesByEmittedPath, gitDirRootProbes, isGitDirCommonPath, shouldIgnoreRepoPath } from "./watcherPatterns.js";
7
7
  import { allWatchedRepositoryChanges, classifyGitDirChange } from "./classifyChange.js";
8
8
  import { diffGitConfigSections, parseGitConfigBytes } from "./configSections.js";
9
9
  //#region ../git/src/watching/watchGroup.ts
@@ -14,8 +14,8 @@ import { diffGitConfigSections, parseGitConfigBytes } from "./configSections.js"
14
14
  */
15
15
  const readTimeoutMs = 5e3;
16
16
  /**
17
- * How many removed admin entries are remembered. Each watcher reports a removal once for each file it watched in the
18
- * entry, and two watchers see the common dir beside a main checkout, so its reports outlive any single one of them
17
+ * How many removed admin entries are remembered. A watcher reports a removal once for each file it watched in the entry,
18
+ * and a poll may report it too, so its reports outlive any single one of them
19
19
  */
20
20
  const removedWorktreeIdsLimit = 64;
21
21
  /**
@@ -23,18 +23,26 @@ const removedWorktreeIdsLimit = 64;
23
23
  * git wrote its `gitdir`, and then miss the write itself (a new directory's files go unseen until it is watched)
24
24
  */
25
25
  const worktreeRetryDelayMs = 250;
26
+ /**
27
+ * How long a watcher on the common dir that another takes over from keeps delivering to linked sessions beside it. A
28
+ * host may place a `.git` watch asynchronously, with no signal for when it is live, so the new watcher can miss what
29
+ * changes at first
30
+ */
31
+ const handOverOverlapMs = 5e3;
26
32
  function noop() {}
27
33
  /**
28
34
  * Manages filesystem watchers for a single physical `.git` directory,
29
35
  * shared across all worktrees that reference it.
30
36
  *
31
37
  * Structure:
32
- * - 1 common watcher: config, refs/**, info/exclude, etc. Delivers to linked sessions only; a
33
- * session rooted at the common dir hears the same files from its own combined root watcher.
34
- * - N root watchers: one per worktree (index, HEAD, *_HEAD, etc.)
35
- *
36
- * For a standard (non-worktree) repo, the common and root directories
37
- * are the same, but we still create separate watchers for clean separation.
38
+ * - N root watchers: one per session, on its own `.git` directory (index, HEAD, *_HEAD, etc.). A session rooted at the
39
+ * common dir (a main checkout) watches it with the combined glob, so it sees every common file too (config,
40
+ * refs/**, info/exclude, etc.), and linked sessions hear those through it.
41
+ * - 1 common watcher on the common dir, for the common files only, while there are linked sessions and no session
42
+ * rooted at the common dir for them to hear those through. It delivers to linked sessions only. When one of the two
43
+ * takes the common files over from the other, the old one keeps delivering to linked sessions for a moment beside
44
+ * the new one (see {@link handOverOverlapMs}), however many hand-overs follow within it, so only once each such
45
+ * moment has passed is a single watcher left on the common dir.
38
46
  *
39
47
  * Given a `readFile`, the group keeps the shared `.git/config` as it last read it, section by section. A report of
40
48
  * that file (or its lock), from whichever watcher, is read and compared with it once, and every session hears what
@@ -66,7 +74,7 @@ function noop() {}
66
74
  * when a real entry was added or removed since the last listing, and to none when only ignored ones were. Git removes
67
75
  * the directory with its last entry, so a directory that isn't there is an empty listing, as is a removal of it that
68
76
  * can't be listed. Since a listing (or a worktree moved into or out of a folder) changes what every session shows, it
69
- * is told to all of them; the other watcher's report of the same change then finds nothing left to tell. Where only a
77
+ * is told to all of them; another report of the same change (a poll's) then finds nothing left to tell. Where only a
70
78
  * poll watches the common dir, it sees just the `worktrees` directory, so an entry removed and added again under the
71
79
  * same id between two polls, or an entry's HEAD or lock changed in place, goes untold.
72
80
  *
@@ -84,6 +92,12 @@ var WatchGroup = class {
84
92
  _commonWatcher;
85
93
  _commonReliability = "reliable";
86
94
  _commonTarget;
95
+ /**
96
+ * The watchers on the common dir that were taken over from, each still delivering to linked sessions until its own
97
+ * overlap ends: a common watcher (with its poll, if any), or the root watcher of a session rooted at the common dir
98
+ * that went. A hand-over inside another's overlap leaves the earlier one running, since only it may be live yet
99
+ */
100
+ _retiring = /* @__PURE__ */ new Map();
87
101
  _disposed = false;
88
102
  /** The shared `.git/config`, by section, as the last read that could parse it found it */
89
103
  _config;
@@ -149,6 +163,7 @@ var WatchGroup = class {
149
163
  }
150
164
  this._sessions.clear();
151
165
  this.disposeCommonWatcher();
166
+ this.endAllRetiring();
152
167
  for (const retry of this._worktreeRetries.values()) {
153
168
  clearTimeout(retry.timer);
154
169
  retry.resolve(void 0);
@@ -158,11 +173,14 @@ var WatchGroup = class {
158
173
  get sessions() {
159
174
  return this._sessions;
160
175
  }
161
- /** True when a watcher the session hears through — its root watcher, or a linked session's common one — can't watch */
176
+ /**
177
+ * True when a watcher the session hears through — its root watcher, or for a linked session the watch of the common
178
+ * files (see {@link getCommonReliability}) — can't watch
179
+ */
162
180
  isUnwatchable(repoPath) {
163
181
  const entry = this._sessions.get(repoPath);
164
182
  if (entry == null) return false;
165
- return entry.reliability === "unwatchable" || !entry.coversCommon && this._commonReliability === "unwatchable";
183
+ return entry.reliability === "unwatchable" || !entry.coversCommon && this.getCommonReliability() === "unwatchable";
166
184
  }
167
185
  /** Add a session to this group. Creates the root watcher for the session's gitDir. */
168
186
  addSession(repoPath, gitDir, hooks) {
@@ -170,14 +188,15 @@ var WatchGroup = class {
170
188
  if (this._sessions.has(repoPath)) return;
171
189
  const isStandard = gitDir.commonUri == null;
172
190
  const rootPattern = isStandard ? dotGitGlobCombined : dotGitGlobRoot;
191
+ const commonReliability = isStandard ? this.getCommonReliability() : void 0;
173
192
  let entry;
174
193
  let initialReliability = "reliable";
175
194
  const rootWatcher = this.provider.createWatcher(gitDir.uri.fsPath, rootPattern, (event) => {
176
- const e = this._sessions.get(repoPath);
177
- if (e != null) {
178
- if (event.reason !== "overflow") e.target?.forget(event.path);
179
- this.onRootEvent(event, e);
180
- }
195
+ if (entry == null) return;
196
+ if (this._sessions.get(repoPath) === entry) {
197
+ if (event.reason !== "overflow") entry.target?.forget(event.path);
198
+ this.onRootEvent(event, entry);
199
+ } else if (this._retiring.has(entry.rootWatcher)) this.onCommonEvent(event, true);
181
200
  }, this.getWatcherOptions(gitDir.uri.fsPath, (state) => {
182
201
  if (entry == null) initialReliability = state;
183
202
  else if (this._sessions.get(repoPath) === entry) this.setRootReliability(entry, state);
@@ -194,21 +213,35 @@ var WatchGroup = class {
194
213
  };
195
214
  this._sessions.set(repoPath, entry);
196
215
  if (initialReliability !== "reliable") this.setRootReliability(entry, initialReliability, true);
197
- if (!isStandard) this.ensureCommonWatcher();
216
+ if (commonReliability != null) {
217
+ this.retireCommonWatcher();
218
+ this.handOverCommon(commonReliability);
219
+ } else if (!some(this._sessions.values(), (e) => e.coversCommon)) this.ensureCommonWatcher();
198
220
  }
199
221
  /** Remove a session from this group. Disposes its root watcher. */
200
222
  removeSession(repoPath) {
201
223
  const entry = this._sessions.get(repoPath);
202
224
  if (entry == null) return;
203
- entry.rootWatcher.dispose();
204
- this.stopPolling(entry);
225
+ const commonReliability = entry.coversCommon ? this.getCommonReliability() : void 0;
205
226
  this._sessions.delete(repoPath);
206
- if (this._commonWatcher != null && !some(this._sessions.values(), (e) => !e.coversCommon)) this.disposeCommonWatcher();
227
+ const linked = some(this._sessions.values(), (e) => !e.coversCommon);
228
+ if (commonReliability != null && linked && !some(this._sessions.values(), (e) => e.coversCommon)) {
229
+ this.ensureCommonWatcher(true);
230
+ this.retire(entry.rootWatcher, entry.target);
231
+ } else {
232
+ this.stopPolling(entry);
233
+ entry.rootWatcher.dispose();
234
+ }
235
+ if (!linked) {
236
+ this.disposeCommonWatcher();
237
+ this.endAllRetiring();
238
+ } else if (commonReliability != null) this.handOverCommon(commonReliability);
207
239
  }
208
240
  getWorktreeId(gitDirPath) {
209
241
  return getWorktreeAdminId(gitDirPath, this.commonGitDir);
210
242
  }
211
- ensureCommonWatcher() {
243
+ /** `handingOver`: it takes the common files over from a session's root watcher, which tells linked sessions itself */
244
+ ensureCommonWatcher(handingOver) {
212
245
  if (this._commonWatcher != null || this._disposed) return;
213
246
  let watcher;
214
247
  let initialReliability = "reliable";
@@ -221,7 +254,48 @@ var WatchGroup = class {
221
254
  this.onCommonEvent(event);
222
255
  }, options);
223
256
  this._commonWatcher = watcher;
224
- if (initialReliability !== "reliable") this.setCommonReliability(initialReliability, true);
257
+ if (initialReliability !== "reliable") {
258
+ if (handingOver) this.setCommonPolling(initialReliability);
259
+ else this.setCommonReliability(initialReliability, true);
260
+ }
261
+ }
262
+ /** The common watcher keeps delivering to linked sessions until a root watcher's watch on the common dir is live */
263
+ retireCommonWatcher() {
264
+ const watcher = this._commonWatcher;
265
+ if (watcher == null) return;
266
+ const target = this._commonTarget;
267
+ this._commonWatcher = void 0;
268
+ this._commonTarget = void 0;
269
+ this._commonReliability = "reliable";
270
+ this.retire(watcher, target);
271
+ }
272
+ /**
273
+ * Keeps `watcher` (and its poll) delivering to linked sessions for {@link handOverOverlapMs}, beside any earlier one
274
+ * still in its own overlap. A watcher retires once: the group never makes one current again
275
+ */
276
+ retire(watcher, target) {
277
+ const timer = setTimeout(() => {
278
+ if (this._retiring.get(watcher)?.timer === timer) this.endRetiring(watcher);
279
+ }, handOverOverlapMs);
280
+ if (typeof timer !== "number") timer.unref();
281
+ this._retiring.set(watcher, {
282
+ target,
283
+ timer
284
+ });
285
+ }
286
+ endRetiring(watcher) {
287
+ const retiring = this._retiring.get(watcher);
288
+ if (retiring == null) return;
289
+ this._retiring.delete(watcher);
290
+ clearTimeout(retiring.timer);
291
+ watcher.dispose();
292
+ if (retiring.target != null) this.poller?.delete(retiring.target);
293
+ }
294
+ endAllRetiring() {
295
+ for (const watcher of [...this._retiring.keys()]) this.endRetiring(watcher);
296
+ }
297
+ isRetiringTarget(target) {
298
+ return some(this._retiring.values(), (r) => r.target === target);
225
299
  }
226
300
  disposeCommonWatcher() {
227
301
  this._commonWatcher?.dispose();
@@ -252,11 +326,16 @@ var WatchGroup = class {
252
326
  setRootReliability(entry, state, initial) {
253
327
  const previous = entry.reliability;
254
328
  if (previous === state || this.poller == null) return;
329
+ const commonPrevious = entry.coversCommon && !initial ? this.getCommonReliability() : void 0;
255
330
  entry.reliability = state;
256
331
  if (state === "reliable") this.stopPolling(entry);
257
332
  else if (entry.target == null) {
258
333
  const target = new GitDirProbeTarget(entry.gitDirPath, this.poller, () => this.getRootProbes(entry), gitDirProbesByEmittedPath, (event, probe) => {
259
334
  if (entry.target !== target) return;
335
+ if (this._sessions.get(entry.repoPath) !== entry) {
336
+ if (this.isRetiringTarget(target)) this.onCommonEvent(event, true);
337
+ return;
338
+ }
260
339
  this.onRootEvent(event, entry);
261
340
  if (probe.path === "logs/HEAD" && !entry.coversCommon) this.onLinkedHeadMoved();
262
341
  });
@@ -269,24 +348,35 @@ var WatchGroup = class {
269
348
  if (entry.coversCommon) this.rebaselineWorktrees();
270
349
  }
271
350
  entry.hooks.onUnwatchableChanged?.(entry.repoPath);
351
+ if (commonPrevious != null && commonPrevious === "unwatchable" !== (this.getCommonReliability() === "unwatchable")) this.tellLinkedUnwatchableChanged();
272
352
  }
273
353
  setCommonReliability(state, initial) {
274
354
  const previous = this._commonReliability;
275
355
  if (previous === state || this.poller == null) return;
356
+ this.setCommonPolling(state);
357
+ if (state === "unwatchable" === (previous === "unwatchable")) return;
358
+ this.tellLinkedUnwatchableChanged(initial);
359
+ }
360
+ /** Polls the common dir in place of (or beside) the common watcher while it isn't `reliable` */
361
+ setCommonPolling(state) {
362
+ const poller = this.poller;
363
+ if (poller == null) return;
276
364
  this._commonReliability = state;
277
365
  if (state === "reliable") {
278
366
  if (this._commonTarget != null) {
279
- this.poller.delete(this._commonTarget);
367
+ poller.delete(this._commonTarget);
280
368
  this._commonTarget = void 0;
281
369
  }
282
370
  } else if (this._commonTarget == null) {
283
- const target = new GitDirProbeTarget(this.commonGitDir, this.poller, () => this.getCommonProbes(), gitDirProbesByEmittedPath, (event) => {
284
- if (this._commonTarget === target) this.onCommonEvent(event);
371
+ const target = new GitDirProbeTarget(this.commonGitDir, poller, () => this.getCommonProbes(), gitDirProbesByEmittedPath, (event) => {
372
+ if (this._commonTarget === target || this.isRetiringTarget(target)) this.onCommonEvent(event);
285
373
  });
286
374
  this._commonTarget = target;
287
- this.poller.add(target);
375
+ poller.add(target);
288
376
  }
289
- if (state === "unwatchable" === (previous === "unwatchable")) return;
377
+ }
378
+ /** The watch linked sessions hear the common files through went down or came back: whatever changed meanwhile went unseen */
379
+ tellLinkedUnwatchableChanged(initial) {
290
380
  for (const entry of this._sessions.values()) {
291
381
  if (entry.coversCommon) continue;
292
382
  if (!initial) this.deliverOverflow(entry);
@@ -294,6 +384,38 @@ var WatchGroup = class {
294
384
  }
295
385
  if (!initial) this.rebaselineWorktrees();
296
386
  }
387
+ /**
388
+ * How much of the common files linked sessions hear: what the root watcher of a session rooted at the common dir
389
+ * reports while there is one (the most reliable, should there be several), the common watcher's otherwise. A watcher
390
+ * kept delivering beside the one that took over from it doesn't count: it is about to go
391
+ */
392
+ getCommonReliability() {
393
+ let reliability;
394
+ for (const entry of this._sessions.values()) {
395
+ if (!entry.coversCommon) continue;
396
+ if (entry.reliability === "reliable") return "reliable";
397
+ if (reliability !== "unreliable") reliability = entry.reliability;
398
+ }
399
+ return reliability ?? this._commonReliability;
400
+ }
401
+ /**
402
+ * Linked sessions now hear the common files through another watcher than one that was `previous`. Where either isn't
403
+ * `reliable`, what changed between the two may have gone unseen (a poll's first pass only records), so each rescans,
404
+ * and hears whether the watch went down or came back
405
+ */
406
+ handOverCommon(previous) {
407
+ const current = this.getCommonReliability();
408
+ if (previous === "reliable" && current === "reliable") return;
409
+ const unwatchableChanged = previous === "unwatchable" !== (current === "unwatchable");
410
+ let told = false;
411
+ for (const entry of this._sessions.values()) {
412
+ if (entry.coversCommon) continue;
413
+ told = true;
414
+ this.deliverOverflow(entry);
415
+ if (unwatchableChanged) entry.hooks.onUnwatchableChanged?.(entry.repoPath);
416
+ }
417
+ if (told) this.rebaselineWorktrees();
418
+ }
297
419
  stopPolling(entry) {
298
420
  if (entry.target == null) return;
299
421
  this.poller?.delete(entry.target);
@@ -301,8 +423,7 @@ var WatchGroup = class {
301
423
  }
302
424
  /**
303
425
  * A session rooted at the common dir polls the common files too, with the refs of every session in the group: its
304
- * combined watcher would hear them all. While the common dir is polled too, the poller stats each shared file once
305
- * for both, and each keeps its own readings, so what one watcher reported is held back from its own sessions only
426
+ * combined watcher would hear them all, for linked sessions too
306
427
  */
307
428
  getRootProbes(entry) {
308
429
  if (!entry.coversCommon) return gitDirRootProbes;
@@ -333,7 +454,11 @@ var WatchGroup = class {
333
454
  }
334
455
  return [...gitDirCommonProbes, ...getGitDirRefProbes(refs)];
335
456
  }
336
- onCommonEvent(event) {
457
+ /**
458
+ * An event of a watcher on the common dir that delivers to linked sessions only: the common watcher, or a root watcher
459
+ * whose session went (`sharedOnly`, since it watched that session's own files too)
460
+ */
461
+ onCommonEvent(event, sharedOnly) {
337
462
  if (event.reason === "overflow") {
338
463
  for (const entry of this._sessions.values()) {
339
464
  if (entry.coversCommon) continue;
@@ -345,36 +470,8 @@ var WatchGroup = class {
345
470
  if (!isDescendant(event.path, this.commonGitDir)) return;
346
471
  const relativePath = relative(this.commonGitDir, event.path);
347
472
  if (shouldIgnoreRepoPath(relativePath)) return;
348
- if (this.readFile != null && isConfigFile(relativePath)) {
349
- this.onConfigReported();
350
- return;
351
- }
352
- const isFetchHead = relativePath === "FETCH_HEAD";
353
- const isExclude = relativePath === "info/exclude";
354
- const changes = isFetchHead ? void 0 : withWorktreeEntryHead(classifyGitDirChange(relativePath), relativePath, event.reason);
355
- if (changes == null && !isFetchHead && !isExclude) return;
356
- const ref = changes != null ? getChangedRef(relativePath) : void 0;
357
- const ownerId = changes != null ? getMovedWorktreeId(relativePath) : void 0;
358
- const movedWorktree = getReportedWorktreeId(relativePath, changes);
359
- if (changes != null && this.isWorktreesReport(changes)) {
360
- const sessions = [...this._sessions.values()].filter((e) => !e.coversCommon && (ownerId == null || e.worktreeId !== ownerId));
361
- this.onWorktreesReported(relativePath, event.reason, () => {
362
- for (const entry of sessions) {
363
- if (this._disposed || this._sessions.get(entry.repoPath) !== entry) continue;
364
- deliverRepoChanged(entry, changes, ref, movedWorktree);
365
- }
366
- });
367
- return;
368
- }
369
- for (const entry of this._sessions.values()) {
370
- if (entry.coversCommon) continue;
371
- if (isFetchHead) {
372
- entry.hooks.onFetchHeadChanged?.(entry.repoPath);
373
- continue;
374
- }
375
- if (changes != null && (ownerId == null || entry.worktreeId !== ownerId)) deliverRepoChanged(entry, changes, ref, movedWorktree);
376
- if (isExclude) entry.hooks.onIgnoresChanged?.(entry.repoPath);
377
- }
473
+ if (sharedOnly && !isGitDirCommonPath(relativePath)) return;
474
+ this.onGitDirChanged(relativePath, event.reason, void 0, true, true);
378
475
  }
379
476
  deliverOverflow(entry) {
380
477
  entry.hooks.onRepoChanged(entry.repoPath, [...allWatchedRepositoryChanges], void 0, true);
@@ -384,28 +481,69 @@ var WatchGroup = class {
384
481
  onRootEvent(event, entry) {
385
482
  if (event.reason === "overflow") {
386
483
  this.deliverOverflow(entry);
387
- if (entry.coversCommon) this.rebaselineWorktrees();
484
+ if (entry.coversCommon) {
485
+ for (const e of this._sessions.values()) {
486
+ if (e.coversCommon) continue;
487
+ this.deliverOverflow(e);
488
+ }
489
+ this.rebaselineWorktrees();
490
+ }
388
491
  return;
389
492
  }
390
493
  if (!isDescendant(event.path, entry.gitDirPath)) return;
391
494
  const relativePath = relative(entry.gitDirPath, event.path);
392
495
  if (shouldIgnoreRepoPath(relativePath)) return;
496
+ this.onGitDirChanged(relativePath, event.reason, entry, entry.coversCommon && isGitDirCommonPath(relativePath), entry.coversCommon);
497
+ }
498
+ /**
499
+ * Tells `entry`, and the linked sessions when `linked`, of a change at `relativePath`, relative to the `.git`
500
+ * directory whose watcher (or poll) reported it; `common` when that is the common dir
501
+ */
502
+ onGitDirChanged(relativePath, reason, entry, linked, common) {
393
503
  if (relativePath === "FETCH_HEAD") {
394
- entry.hooks.onFetchHeadChanged?.(entry.repoPath);
504
+ this.callHook(entry, linked, "onFetchHeadChanged");
395
505
  return;
396
506
  }
397
- if (entry.coversCommon && this.readFile != null && isConfigFile(relativePath)) {
507
+ if (common && this.readFile != null && isConfigFile(relativePath)) {
398
508
  this.onConfigReported();
399
509
  return;
400
510
  }
401
- const changes = withWorktreeEntryHead(classifyGitDirChange(relativePath), relativePath, event.reason);
402
- const movedWorktree = entry.coversCommon ? getReportedWorktreeId(relativePath, changes) : void 0;
403
- if (changes != null && entry.coversCommon && this.isWorktreesReport(changes)) this.onWorktreesReported(relativePath, event.reason, () => {
404
- if (this._disposed || this._sessions.get(entry.repoPath) !== entry) return;
405
- deliverRepoChanged(entry, changes, getChangedRef(relativePath), movedWorktree);
406
- });
407
- else if (changes != null) deliverRepoChanged(entry, changes, getChangedRef(relativePath), movedWorktree);
408
- if (relativePath === "info/exclude") entry.hooks.onIgnoresChanged?.(entry.repoPath);
511
+ const changes = withWorktreeEntryHead(classifyGitDirChange(relativePath), relativePath, reason);
512
+ if (changes != null) {
513
+ const ref = getChangedRef(relativePath);
514
+ const movedWorktree = common ? getReportedWorktreeId(relativePath, changes) : void 0;
515
+ const ownerId = common ? getMovedWorktreeId(relativePath) : void 0;
516
+ if (common && this.isWorktreesReport(changes)) {
517
+ const reached = [];
518
+ if (entry != null && (ownerId == null || entry.worktreeId !== ownerId)) reached.push(entry);
519
+ if (linked) for (const e of this._sessions.values()) {
520
+ if (e.coversCommon || ownerId != null && e.worktreeId === ownerId) continue;
521
+ reached.push(e);
522
+ }
523
+ this.onWorktreesReported(relativePath, reason, () => {
524
+ for (const e of reached) {
525
+ if (this._disposed || this._sessions.get(e.repoPath) !== e) continue;
526
+ deliverRepoChanged(e, changes, ref, movedWorktree);
527
+ }
528
+ });
529
+ } else {
530
+ if (entry != null && (ownerId == null || entry.worktreeId !== ownerId)) deliverRepoChanged(entry, changes, ref, movedWorktree);
531
+ if (linked) for (const e of this._sessions.values()) {
532
+ if (e.coversCommon || ownerId != null && e.worktreeId === ownerId) continue;
533
+ deliverRepoChanged(e, changes, ref, movedWorktree);
534
+ }
535
+ }
536
+ }
537
+ if (relativePath === "info/exclude") this.callHook(entry, linked, "onIgnoresChanged");
538
+ }
539
+ /** Calls `hook` of `entry`, and of the linked sessions when `linked` */
540
+ callHook(entry, linked, hook) {
541
+ if (entry != null) entry.hooks[hook]?.(entry.repoPath);
542
+ if (!linked) return;
543
+ for (const e of this._sessions.values()) {
544
+ if (e.coversCommon) continue;
545
+ e.hooks[hook]?.(e.repoPath);
546
+ }
409
547
  }
410
548
  /** A report of the `worktrees` directory, an admin entry or a file in it, once the group may tell them apart */
411
549
  isWorktreesReport(changes) {
@@ -523,8 +661,9 @@ var WatchGroup = class {
523
661
  }
524
662
  /**
525
663
  * A report whose read couldn't read the entry waits on the entry's next read, and `deliver` is told then, unless that
526
- * read finds an ignored worktree's; one still unreadable is told. Both watchers report each change of an entry, so
527
- * the reports of one id wait on one read. Resolves with what it found, as {@link settleWorktreeRetry} does
664
+ * read finds an ignored worktree's; one still unreadable is told. One change of an entry can be reported more than
665
+ * once (by a watcher and a poll, or for each file it touched), so the reports of one id wait on one read. Resolves
666
+ * with what it found, as {@link settleWorktreeRetry} does
528
667
  */
529
668
  waitForWorktreeRetry(id, deliver) {
530
669
  const known = this._worktreeIds.get(id);