@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
package/dist/git/cache.js CHANGED
@@ -8,7 +8,7 @@ import { normalizePath } from "../utils/path.js";
8
8
  import { PromiseCache, PromiseMap, RepoPromiseCacheMap } from "../utils/promiseCache.js";
9
9
  import { parseBranchMetadataGkConfigKey, setBranchMetadataValue } from "./utils/branch.utils.js";
10
10
  import { createReference } from "./utils/reference.utils.js";
11
- import { getCommonRepositoryPath, getRepositoryOrWorktreePath } from "./utils/repository.utils.js";
11
+ import { getCommonRepositoryPath, getRepositoryOrWorktreePath, getWorktreeAdminId } from "./utils/repository.utils.js";
12
12
  import __decorate from "../_virtual/@oxc-project+runtime/helpers/esm/decorate.js";
13
13
  //#region ../git/src/cache.ts
14
14
  const uriScopedCachedGitTypes = [
@@ -34,8 +34,9 @@ const baseBranchNameTTL = 3e5;
34
34
  * documents be owned by their active tracked-document snapshot instead of retaining a second long-lived owner.
35
35
  */
36
36
  const maxCachedBlameLines = 5e3;
37
- /** Worktree paths whose last current branch drop is tracked; the oldest beyond this folds into the all-paths floor */
38
- const currentBranchDropsTracked = 128;
37
+ /** Per drop-stamped cache, paths whose last drop is tracked; the oldest beyond this folds into the all-paths floor */
38
+ const dropsTracked = 128;
39
+ const dropStampedCacheKeys = exhaustiveArray()(["currentBranchReference", "currentUser"]);
39
40
  async function shouldEvictBlameCacheEntry(progressive) {
40
41
  if (progressive == null) return false;
41
42
  try {
@@ -151,20 +152,47 @@ var Cache = class Cache {
151
152
  _statusGenerations = /* @__PURE__ */ new Map();
152
153
  /** Monotonic per-path "close clock" — see {@link getCloseGeneration}. */
153
154
  _closeGenerations = /* @__PURE__ */ new Map();
155
+ /** Advanced by {@link reset}, which moves every path's close clock, those it never saw included */
156
+ _resetGeneration = 0;
154
157
  /** Per commonPath, the `mergeTargets` keys a checkout evicts (see {@link CachedMergeTarget.evictOnCheckout}) */
155
158
  _mergeTargetsEvictedOnCheckout = /* @__PURE__ */ new Map();
156
159
  /** Bumped on each checkout eviction, so a merge target resolved across one isn't kept for the next */
157
160
  _mergeTargetCheckoutGeneration = 0;
158
161
  /** Each merge target answer's entry as `mergeTargets` stored it, so dropping a stale answer can't drop its successor */
159
162
  _mergeTargetStored = /* @__PURE__ */ new WeakMap();
160
- /** Advanced each time current branch references are dropped (see {@link setCurrentBranchReferenceIfAbsent}) */
161
- _currentBranchDrops = 0;
162
- /** Per worktree path, the value of {@link _currentBranchDrops} when its current branch reference was last dropped */
163
- _currentBranchDroppedAt = /* @__PURE__ */ new Map();
164
- /** The value of {@link _currentBranchDrops} when every current branch reference was last dropped */
165
- _allCurrentBranchesDroppedAt = 0;
166
- /** Each ref listing's records checked out in a worktree, by the value of {@link _currentBranchDrops} when it started */
167
- _refsReadAt = /* @__PURE__ */ new WeakMap();
163
+ /** Advanced each time a drop-stamped cache's entries are dropped (see {@link getDropStamp}) */
164
+ _drops = 0;
165
+ /**
166
+ * Per drop-stamped cache, the value of {@link _drops} when each path's entry was last dropped (`byPath`) and when
167
+ * every path's entry was (`all`)
168
+ */
169
+ _droppedAt = {
170
+ currentBranchReference: {
171
+ byPath: /* @__PURE__ */ new Map(),
172
+ all: 0
173
+ },
174
+ currentUser: {
175
+ byPath: /* @__PURE__ */ new Map(),
176
+ all: 0
177
+ }
178
+ };
179
+ /**
180
+ * Each ref listing's records checked out in a worktree, with the value of {@link _drops} when the listing started
181
+ * and the common path it listed
182
+ */
183
+ _refsRead = /* @__PURE__ */ new WeakMap();
184
+ /**
185
+ * Unregistered linked worktrees a ref listing reported, whether or not it seeded their current branch, with the
186
+ * common path of the listing (see {@link dropLinkedCurrentBranches})
187
+ */
188
+ _seededWorktrees = /* @__PURE__ */ new Map();
189
+ /** {@link _seededWorktrees} by common path */
190
+ _seededWorktreesByCommonPath = /* @__PURE__ */ new Map();
191
+ /**
192
+ * Registered linked worktrees' admin ids (the `<id>` of `.git/worktrees/<id>`), which name the worktree a
193
+ * `'worktreeHead'` report says moved (see {@link applyRepositoryChanges})
194
+ */
195
+ _worktreeAdminIds = /* @__PURE__ */ new Map();
168
196
  /**
169
197
  * Per-commonPath snapshot of the subset of `.git/gk/config` that derived caches depend on — merge-relevant keys
170
198
  * ({@link branchOverviewGkConfigKeysRegex}) and branch metadata keys ({@link parseBranchMetadataGkConfigKey}) —
@@ -193,13 +221,51 @@ var Cache = class Cache {
193
221
  * falls back to the coarse clear.
194
222
  */
195
223
  _gkConfigReconciler;
224
+ /** Run before each read of a cache with no expiry (see {@link setReadValidator}) */
225
+ _readValidator;
226
+ /** What the read validator reports among {@link getResourceUsage}'s */
227
+ _readValidatorUsage;
196
228
  [Symbol.dispose]() {
197
229
  this.dispose();
198
230
  }
199
231
  dispose() {
200
232
  this.reset();
233
+ this._readValidator = void 0;
234
+ this._readValidatorUsage = void 0;
201
235
  this._onDidChangeMergeTargets.dispose();
202
236
  }
237
+ /**
238
+ * Registers what runs before each read of the caches that only a change report, core's own writes or an explicit
239
+ * clear drop in time (the branches, current branch and its reference, refs and their tips, tags, remotes, worktrees,
240
+ * stashes, gk config, paused operation, and what is derived from them: default and base branch names, merge
241
+ * targets, branch metadata, the initial commit, resolved revisions, commit counts, reachability, branch overviews,
242
+ * contributors, the current user, the ahead-of-base and gitignore config listings, and the cached git runs). It
243
+ * answers `undefined` when the read can go ahead at once, or a promise that settles, never rejecting, once it
244
+ * applied whatever changed (as {@link onRepositoryChanged}), after which the read runs. A host that watches only
245
+ * some repositories registers one that checks the others' git dirs (see `UnwatchedCacheValidator`); `undefined`
246
+ * removes it. Kept across {@link reset}: it is host wiring, not cached state. `getResourceUsage` reports what it
247
+ * costs among {@link getResourceUsage}'s.
248
+ */
249
+ setReadValidator(validator, getResourceUsage) {
250
+ this._readValidator = validator;
251
+ this._readValidatorUsage = validator != null ? getResourceUsage : void 0;
252
+ }
253
+ /**
254
+ * Runs the read validator (see {@link setReadValidator}) for a read of one of its caches made without the wrappers
255
+ * here: `undefined` when the read can go ahead at once, or a promise (that never rejects) to read after
256
+ */
257
+ validateBeforeRead(repoPath) {
258
+ return this._readValidator?.(repoPath);
259
+ }
260
+ /** Runs `read` once the read validator let `repoPath` be read, at once when it has nothing to wait for */
261
+ readValidated(repoPath, read) {
262
+ const validation = this._readValidator?.(repoPath);
263
+ return validation != null ? validation.then(read) : read();
264
+ }
265
+ /** A map read directly by the providers, whose every `getOrCreate` is validated as the cache's own reads are */
266
+ createValidatedRepoPromiseCacheMap(options) {
267
+ return new ValidatedRepoPromiseCacheMap((repoPath) => this._readValidator?.(repoPath), options);
268
+ }
203
269
  /** Resource usage retained by instantiated sub-caches and their bookkeeping maps. */
204
270
  getResourceUsage() {
205
271
  const usage = {};
@@ -210,7 +276,10 @@ var Cache = class Cache {
210
276
  usage["cache.closeGenerations.entries.count"] = this._closeGenerations.size;
211
277
  usage["cache.gkConfigSnapshots.entries.count"] = this._gkConfigSnapshots.size;
212
278
  usage["cache.mergeTargetsEvictedOnCheckout.entries.count"] = this._mergeTargetsEvictedOnCheckout.size;
213
- usage["cache.currentBranchDroppedAt.entries.count"] = this._currentBranchDroppedAt.size;
279
+ usage["cache.currentBranchDroppedAt.entries.count"] = this._droppedAt.currentBranchReference.byPath.size;
280
+ usage["cache.currentUserDroppedAt.entries.count"] = this._droppedAt.currentUser.byPath.size;
281
+ usage["cache.seededWorktrees.entries.count"] = this._seededWorktrees.size;
282
+ if (this._readValidatorUsage != null) Object.assign(usage, this._readValidatorUsage());
214
283
  return usage;
215
284
  }
216
285
  get aheadOfBaseConfigKey() {
@@ -291,22 +360,115 @@ var Cache = class Cache {
291
360
  * that `reference` was read from; any other seeds nothing
292
361
  */
293
362
  setCurrentBranchReferenceIfAbsent(worktreePath, reference, record) {
294
- const readAt = this._refsReadAt.get(record);
295
- if (readAt == null || readAt < this._allCurrentBranchesDroppedAt || readAt < (this._currentBranchDroppedAt.get(worktreePath) ?? 0)) return;
296
- if (this.currentBranchReference.get(worktreePath) == null) this.currentBranchReference.set(worktreePath, Promise.resolve(reference));
363
+ const read = this._refsRead.get(record);
364
+ if (read == null || this.isDroppedSince("currentBranchReference", worktreePath, read.at)) return;
365
+ if (worktreePath !== read.commonPath && !this._commonPathRegistry.has(worktreePath)) this.trackSeededWorktree(worktreePath, read.commonPath);
366
+ if (this.currentBranchReference.get(worktreePath) != null) return;
367
+ this.currentBranchReference.set(worktreePath, Promise.resolve(reference));
368
+ }
369
+ trackSeededWorktree(worktreePath, commonPath) {
370
+ const previous = this._seededWorktrees.get(worktreePath);
371
+ if (previous === commonPath) return;
372
+ if (previous != null) this.untrackSeededWorktree(worktreePath);
373
+ this._seededWorktrees.set(worktreePath, commonPath);
374
+ let paths = this._seededWorktreesByCommonPath.get(commonPath);
375
+ if (paths == null) {
376
+ paths = /* @__PURE__ */ new Set();
377
+ this._seededWorktreesByCommonPath.set(commonPath, paths);
378
+ }
379
+ paths.add(worktreePath);
297
380
  }
298
- onCurrentBranchReferencesDropped(repoPath) {
299
- this._currentBranchDrops++;
300
- if (repoPath == null) {
301
- this._allCurrentBranchesDroppedAt = this._currentBranchDrops;
302
- this._currentBranchDroppedAt.clear();
303
- } else {
304
- this._currentBranchDroppedAt.delete(repoPath);
305
- this._currentBranchDroppedAt.set(repoPath, this._currentBranchDrops);
306
- if (this._currentBranchDroppedAt.size > currentBranchDropsTracked) {
307
- const [oldestPath, oldestAt] = this._currentBranchDroppedAt.entries().next().value;
308
- this._currentBranchDroppedAt.delete(oldestPath);
309
- this._allCurrentBranchesDroppedAt = Math.max(this._allCurrentBranchesDroppedAt, oldestAt);
381
+ untrackSeededWorktree(worktreePath) {
382
+ const commonPath = this._seededWorktrees.get(worktreePath);
383
+ if (commonPath == null) return;
384
+ this._seededWorktrees.delete(worktreePath);
385
+ const paths = this._seededWorktreesByCommonPath.get(commonPath);
386
+ paths?.delete(worktreePath);
387
+ if (paths?.size === 0) this._seededWorktreesByCommonPath.delete(commonPath);
388
+ }
389
+ /**
390
+ * Tracks exactly `reported` for `commonPath`. A path the listing no longer reports isn't tracked any more, so a
391
+ * HEAD change could no longer find it to drop its current branch: it goes with it
392
+ */
393
+ replaceSeededWorktrees(commonPath, reported) {
394
+ for (const path of [...this._seededWorktreesByCommonPath.get(commonPath) ?? []]) {
395
+ if (reported.has(path)) continue;
396
+ this.untrackSeededWorktree(path);
397
+ this.dropCurrentBranch(path);
398
+ }
399
+ for (const path of reported) this.trackSeededWorktree(path, commonPath);
400
+ }
401
+ /**
402
+ * A `'worktreeHead'` report that doesn't say which linked worktree's HEAD moved, so each one but `repoPath` loses its
403
+ * current branch: those registered, and those its repository's ref listings seeded. Never the main checkout: its
404
+ * HEAD is the common `HEAD`, which is reported as `'head'`. With `unidentifiedOnly`, the report named a worktree that
405
+ * isn't registered, so a registered one with an admin id of its own keeps its current branch
406
+ */
407
+ dropLinkedCurrentBranches(repoPath, unidentifiedOnly = false) {
408
+ const commonPath = this.getCommonPath(repoPath);
409
+ const paths = new Set(unidentifiedOnly ? this.getWorktreePaths(commonPath).filter((p) => !this._worktreeAdminIds.has(p)) : this.getWorktreePaths(commonPath));
410
+ for (const path of this._seededWorktreesByCommonPath.get(commonPath) ?? []) paths.add(path);
411
+ paths.delete(repoPath);
412
+ paths.delete(commonPath);
413
+ for (const path of paths) this.dropCurrentBranch(path);
414
+ }
415
+ /**
416
+ * A `'worktreeHead'` report naming, by admin id, the linked worktrees whose HEAD moved: each registered one but
417
+ * `repoPath` is cleared as for its own `'head'` change, and an id no registered worktree has is an unregistered
418
+ * worktree's (see {@link dropLinkedCurrentBranches})
419
+ */
420
+ applyLinkedHeadsMoved(repoPath, ids, inFlight) {
421
+ const found = /* @__PURE__ */ new Set();
422
+ for (const path of this.getWorktreePaths(this.getCommonPath(repoPath))) {
423
+ const id = this._worktreeAdminIds.get(path);
424
+ if (id == null || !ids.has(id)) continue;
425
+ found.add(id);
426
+ if (path === repoPath) continue;
427
+ this.applyRepositoryChanges(path, ["head"], inFlight, { worktreeOnly: true });
428
+ this._caches.branches?.delete(path);
429
+ this._caches.gitResults?.delete(path);
430
+ }
431
+ if (found.size < ids.size) this.dropLinkedCurrentBranches(repoPath, true);
432
+ }
433
+ /** Drops what a `'branch'` eviction of `worktreePath` drops of its current branch, and nothing shared */
434
+ dropCurrentBranch(worktreePath) {
435
+ this.onDropped(worktreePath, ["currentBranchReference"]);
436
+ this._caches.currentBranchReference?.delete(worktreePath);
437
+ this._caches.branch?.delete(worktreePath);
438
+ this._caches.branches?.delete(worktreePath);
439
+ }
440
+ /**
441
+ * A stamp to take before a read, to later ask {@link isDroppedSince} whether the read's entry was dropped mid-flight.
442
+ * With `key` and `repoPath`, the stamp of that entry's last drop, which only a drop of it advances, so it can key a
443
+ * read that calls with no drop between them share
444
+ */
445
+ getDropStamp(key, repoPath) {
446
+ if (key == null || repoPath == null) return this._drops;
447
+ const droppedAt = this._droppedAt[key];
448
+ return Math.max(droppedAt.all, droppedAt.byPath.get(repoPath) ?? 0);
449
+ }
450
+ /** Whether `key`'s entry for `repoPath` was dropped after `stamp` was taken by {@link getDropStamp} */
451
+ isDroppedSince(key, repoPath, stamp) {
452
+ const droppedAt = this._droppedAt[key];
453
+ return stamp < droppedAt.all || stamp < (droppedAt.byPath.get(repoPath) ?? 0);
454
+ }
455
+ /** Stamps a drop of `keys`' entries for `repoPath`, or for every path when `undefined` */
456
+ onDropped(repoPath, keys = dropStampedCacheKeys) {
457
+ if (!keys.length) return;
458
+ this._drops++;
459
+ for (const key of keys) {
460
+ const droppedAt = this._droppedAt[key];
461
+ if (repoPath == null) {
462
+ droppedAt.all = this._drops;
463
+ droppedAt.byPath.clear();
464
+ continue;
465
+ }
466
+ droppedAt.byPath.delete(repoPath);
467
+ droppedAt.byPath.set(repoPath, this._drops);
468
+ if (droppedAt.byPath.size > dropsTracked) {
469
+ const [oldestPath, oldestAt] = droppedAt.byPath.entries().next().value;
470
+ droppedAt.byPath.delete(oldestPath);
471
+ droppedAt.all = Math.max(droppedAt.all, oldestAt);
310
472
  }
311
473
  }
312
474
  }
@@ -338,7 +500,7 @@ var Cache = class Cache {
338
500
  return this._caches.gitIgnore ??= /* @__PURE__ */ new Map();
339
501
  }
340
502
  get gitResults() {
341
- return this._caches.gitResults ??= new RepoPromiseCacheMap({ capacity: 200 });
503
+ return this._caches.gitResults ??= this.createValidatedRepoPromiseCacheMap({ capacity: 200 });
342
504
  }
343
505
  get ignoreConfigListing() {
344
506
  return this._caches.ignoreConfigListing ??= new PromiseMap();
@@ -362,7 +524,7 @@ var Cache = class Cache {
362
524
  });
363
525
  }
364
526
  get commitCount() {
365
- return this._caches.commitCount ??= new RepoPromiseCacheMap({
527
+ return this._caches.commitCount ??= this.createValidatedRepoPromiseCacheMap({
366
528
  accessTTL: 36e5,
367
529
  capacity: 50
368
530
  });
@@ -406,7 +568,7 @@ var Cache = class Cache {
406
568
  return this._caches.refTips ??= new PromiseMap();
407
569
  }
408
570
  get reachability() {
409
- return this._caches.reachability ??= new RepoPromiseCacheMap({
571
+ return this._caches.reachability ??= this.createValidatedRepoPromiseCacheMap({
410
572
  accessTTL: 36e5,
411
573
  capacity: 25
412
574
  });
@@ -557,6 +719,7 @@ var Cache = class Cache {
557
719
  keysToClear.add("resolvedRevisions");
558
720
  keysToClear.add("leftRightCommitCount");
559
721
  keysToClear.add("mergeBase");
722
+ keysToClear.add("reachability");
560
723
  }
561
724
  if (types.includes("tracking")) {
562
725
  keysToClear.add("fileExistence");
@@ -565,7 +728,7 @@ var Cache = class Cache {
565
728
  if (types.includes("worktrees") || types.includes("worktreeList")) keysToClear.add("worktrees");
566
729
  if (types.some((t) => t !== "gitignore" && t !== "gkConfig" && t !== "providers" && t !== "worktreeList")) keysToClear.add("gitResults");
567
730
  }
568
- if (keysToClear.has("currentBranchReference")) this.onCurrentBranchReferencesDropped(repoPath);
731
+ this.onDropped(repoPath, dropStampedCacheKeys.filter((k) => keysToClear.has(k)));
569
732
  for (const key of keysToClear) {
570
733
  const cache = this._caches[key];
571
734
  if (cache == null) continue;
@@ -667,14 +830,21 @@ var Cache = class Cache {
667
830
  return this._commonPathRegistry.has(repoPath);
668
831
  }
669
832
  /**
833
+ * The admin id (the `<id>` of `.git/worktrees/<id>`) of the registered linked worktree at `repoPath`; `undefined`
834
+ * for the main checkout, or a path not registered
835
+ */
836
+ getLinkedWorktreeId(repoPath) {
837
+ return this._worktreeAdminIds.get(repoPath);
838
+ }
839
+ /**
670
840
  * Monotonic per-path counter advanced whenever `repoPath` is unregistered (repo closed, worktree
671
- * removed). Lets an async post-read step — e.g. the gk-config reconcile — detect that its target was
672
- * closed (and possibly reopened) mid-flight and bail. Unlike an `isRegistered` check it doesn't
673
- * require the caller to have registered in the first place, so it stays correct for consumers of
674
- * this package that don't wire up the host's repo lifecycle.
841
+ * removed) or the cache is {@link reset}. Lets an async post-read step — e.g. the gk-config reconcile —
842
+ * detect that its target was closed (and possibly reopened) mid-flight and bail. Unlike an `isRegistered`
843
+ * check it doesn't require the caller to have registered in the first place, so it stays correct for
844
+ * consumers of this package that don't wire up the host's repo lifecycle.
675
845
  */
676
846
  getCloseGeneration(repoPath) {
677
- return this._closeGenerations.get(repoPath) ?? 0;
847
+ return (this._closeGenerations.get(repoPath) ?? 0) + this._resetGeneration;
678
848
  }
679
849
  /** Clears file-scoped caches (blame, diff, fileLog) for a specific path within a repo */
680
850
  clearForPath(repoPath, path, ...types) {
@@ -698,6 +868,10 @@ var Cache = class Cache {
698
868
  }
699
869
  if (previousCommonPath == null && normalizedPath !== commonPath) this.evictReadsBeforeRegistration(normalizedPath);
700
870
  this._commonPathRegistry.set(normalizedPath, commonPath);
871
+ this.untrackSeededWorktree(normalizedPath);
872
+ const adminId = gitDir.commonUri != null && normalizedPath !== commonPath ? getWorktreeAdminId(gitDir.uri.path, gitDir.commonUri.path) : void 0;
873
+ if (adminId != null) this._worktreeAdminIds.set(normalizedPath, adminId);
874
+ else this._worktreeAdminIds.delete(normalizedPath);
701
875
  let worktrees = this._worktreesByCommonPath.get(commonPath);
702
876
  if (worktrees == null) {
703
877
  worktrees = /* @__PURE__ */ new Set();
@@ -744,8 +918,8 @@ var Cache = class Cache {
744
918
  */
745
919
  unregisterRepoPath(repoPath) {
746
920
  this.incrementStatusGeneration(repoPath);
747
- this._closeGenerations.set(repoPath, this.getCloseGeneration(repoPath) + 1);
748
- this.onCurrentBranchReferencesDropped(repoPath);
921
+ this._closeGenerations.set(repoPath, (this._closeGenerations.get(repoPath) ?? 0) + 1);
922
+ this.onDropped(repoPath);
749
923
  const commonPath = this._commonPathRegistry.get(repoPath) ?? repoPath;
750
924
  const worktrees = this._worktreesByCommonPath.get(commonPath);
751
925
  const isLastWorktree = worktrees == null || worktrees.size <= 1;
@@ -775,7 +949,13 @@ var Cache = class Cache {
775
949
  if (isLastWorktree) {
776
950
  this._gkConfigSnapshots.delete(commonPath);
777
951
  this._mergeTargetsEvictedOnCheckout.delete(commonPath);
952
+ for (const path of [...this._seededWorktreesByCommonPath.get(commonPath) ?? []]) {
953
+ this.untrackSeededWorktree(path);
954
+ this.dropCurrentBranch(path);
955
+ }
778
956
  }
957
+ this.untrackSeededWorktree(repoPath);
958
+ this._worktreeAdminIds.delete(repoPath);
779
959
  this._commonPathRegistry.delete(repoPath);
780
960
  if (worktrees != null) {
781
961
  worktrees.delete(repoPath);
@@ -783,24 +963,30 @@ var Cache = class Cache {
783
963
  }
784
964
  }
785
965
  reset() {
786
- for (const path of /* @__PURE__ */ new Set([...this._commonPathRegistry.keys(), ...this._closeGenerations.keys()])) this._closeGenerations.set(path, this.getCloseGeneration(path) + 1);
966
+ this._resetGeneration++;
787
967
  this._commonPathRegistry.clear();
788
968
  this._worktreesByCommonPath.clear();
789
969
  this._statusGenerations.clear();
790
970
  this._gkConfigSnapshots.clear();
791
971
  this._mergeTargetsEvictedOnCheckout.clear();
972
+ this._seededWorktrees.clear();
973
+ this._seededWorktreesByCommonPath.clear();
974
+ this._worktreeAdminIds.clear();
792
975
  this._gkConfigReconciler = void 0;
793
976
  this._caches = createEmptyCaches();
794
- this.onCurrentBranchReferencesDropped(void 0);
977
+ this.onDropped(void 0);
795
978
  }
796
- /** Applies a watcher-observed change, sharing reads still in flight (see {@link applyRepositoryChanges}). */
797
- onRepositoryChanged(repoPath, changes) {
979
+ /**
980
+ * Applies a watcher-observed change, sharing reads still in flight (see {@link applyRepositoryChanges}).
981
+ * `options.movedWorktrees` is the event's `movedWorktrees`.
982
+ */
983
+ onRepositoryChanged(repoPath, changes, options) {
798
984
  const changesSet = new Set(changes);
799
985
  if (changesSet.has("unknown") || changesSet.has("closed")) {
800
986
  this.unregisterRepoPath(repoPath);
801
987
  return;
802
988
  }
803
- this.applyRepositoryChanges(repoPath, changesSet, "share");
989
+ this.applyRepositoryChanges(repoPath, changesSet, "share", { movedWorktrees: options?.movedWorktrees });
804
990
  }
805
991
  /**
806
992
  * Clears what `changes` can have made stale for `repoPath`, advances its status clock, and reconciles a
@@ -811,6 +997,15 @@ var Cache = class Cache {
811
997
  * `options.worktreeOnly` clears only `repoPath`'s own entries and status clock, leaving the shared
812
998
  * (commonPath-keyed) ones alone — for a sibling worktree once the change was applied to the worktree it ran in,
813
999
  * which already cleared them for every worktree of the repository.
1000
+ *
1001
+ * `options.announced` says `changes` are core's announcement of its own write for `repoPath`, whose `'worktreeHead'`
1002
+ * is that write's own: its rewrite of `repoPath`'s HEAD, which its `'head'` clears, or a worktree it added or
1003
+ * removed. Other worktrees' watchers report it, so no other worktree loses its current branch for it.
1004
+ *
1005
+ * `options.movedWorktrees` names, by admin id (the `<id>` of `.git/worktrees/<id>`), the linked worktrees whose HEAD
1006
+ * moved, which are all that a `'worktreeHead'` among `changes` reports: each registered one is cleared as for its
1007
+ * own `'head'` change, and no other registered worktree with an admin id of its own is touched. Without it, any
1008
+ * linked worktree's HEAD may have moved, so each one but `repoPath` loses its current branch.
814
1009
  */
815
1010
  applyRepositoryChanges(repoPath, changes, inFlight, options) {
816
1011
  const worktreeOnly = options?.worktreeOnly ?? false;
@@ -851,8 +1046,13 @@ var Cache = class Cache {
851
1046
  }
852
1047
  if (hasAny("stash")) types.add("stashes");
853
1048
  if (hasAny("tags")) types.add("tags");
854
- if (hasAny("worktreeHead")) types.add("worktrees");
855
- else if (hasAny("worktrees")) types.add("worktreeList");
1049
+ if (hasAny("worktreeHead")) {
1050
+ types.add("worktrees");
1051
+ if (!worktreeOnly && !options?.announced) {
1052
+ if (options?.movedWorktrees != null) this.applyLinkedHeadsMoved(repoPath, options.movedWorktrees, inFlight);
1053
+ else this.dropLinkedCurrentBranches(repoPath);
1054
+ }
1055
+ } else if (hasAny("worktrees")) types.add("worktreeList");
856
1056
  if (types.size) this.clearCachesCore(inFlight, repoPath, [...types], worktreeOnly);
857
1057
  return [...types];
858
1058
  }
@@ -917,6 +1117,9 @@ var Cache = class Cache {
917
1117
  * it needs for `repoPath`; {@link getBranches} keeps a mapped copy per worktree.
918
1118
  */
919
1119
  getSharedBranches(repoPath, factory, cancellation) {
1120
+ return this.readValidated(repoPath, () => this.getSharedBranchesCore(repoPath, factory, cancellation));
1121
+ }
1122
+ getSharedBranchesCore(repoPath, factory, cancellation) {
920
1123
  const commonPath = this.getCommonPath(repoPath);
921
1124
  return this.sharedBranches.getOrCreate(commonPath, (cacheable, signal) => {
922
1125
  const p = Promise.resolve(factory(commonPath, cacheable, signal));
@@ -934,8 +1137,11 @@ var Cache = class Cache {
934
1137
  return this._caches.sharedBranches?.getSettled(this.getCommonPath(repoPath))?.value === result;
935
1138
  }
936
1139
  getBranches(repoPath, factory, mapper, cancellation) {
1140
+ return this.readValidated(repoPath, () => this.getBranchesCore(repoPath, factory, mapper, cancellation));
1141
+ }
1142
+ getBranchesCore(repoPath, factory, mapper, cancellation) {
937
1143
  const commonPath = this.getCommonPath(repoPath);
938
- const registration = this.getSharedBranches(repoPath, factory, cancellation);
1144
+ const registration = this.getSharedBranchesCore(repoPath, factory, cancellation);
939
1145
  registration.catch(() => {});
940
1146
  return this.branches.getOrCreate(repoPath, (_cacheable, mapperSignal) => {
941
1147
  const rawShared = this.sharedBranches.get(commonPath) ?? registration;
@@ -990,12 +1196,12 @@ var Cache = class Cache {
990
1196
  * `reconcileGkConfigMap`; later refreshes of that snapshot are owned by the reconcile itself.
991
1197
  */
992
1198
  getGkConfigMap(repoPath, factory) {
993
- return this.getSharedSimple(this.gkConfigMap, repoPath, async (commonPath, cacheable) => {
1199
+ return this.readValidated(repoPath, () => this.getSharedSimple(this.gkConfigMap, repoPath, async (commonPath, cacheable) => {
994
1200
  const closeGeneration = this.getCloseGeneration(commonPath);
995
1201
  const map = await factory(cacheable);
996
1202
  if (!this._gkConfigSnapshots.has(commonPath) && this.isReadPathCurrent(commonPath, closeGeneration)) this._gkConfigSnapshots.set(commonPath, this.extractReconciledGkConfig(map));
997
1203
  return map;
998
- });
1204
+ }));
999
1205
  }
1000
1206
  /** Whether a read that started under the common path `path` may still seed state for it: not registered or closed since */
1001
1207
  isReadPathCurrent(path, closeGeneration) {
@@ -1162,25 +1368,28 @@ var Cache = class Cache {
1162
1368
  }
1163
1369
  }
1164
1370
  async getBranchOverview(repoPath, cacheKey, factory, options) {
1165
- return this.getSharedOrCreateWithKey(this.branchOverviews, repoPath, cacheKey, factory, (data, newRepoPath) => data == null ? data : {
1371
+ return this.readValidated(repoPath, () => this.getSharedOrCreateWithKey(this.branchOverviews, repoPath, cacheKey, factory, (data, newRepoPath) => data == null ? data : {
1166
1372
  ...data,
1167
1373
  repoPath: newRepoPath,
1168
1374
  contributors: data.contributors.map((c) => c.withRepoPath(newRepoPath))
1169
- }, options);
1375
+ }, options));
1170
1376
  }
1171
1377
  async getContributors(repoPath, cacheKey, factory, options) {
1172
- return this.getSharedOrCreateWithKey(this.contributors, repoPath, cacheKey, factory, (data, newRepoPath) => ({
1378
+ return this.readValidated(repoPath, () => this.getSharedOrCreateWithKey(this.contributors, repoPath, cacheKey, factory, (data, newRepoPath) => ({
1173
1379
  ...data,
1174
1380
  contributors: data.contributors.map((c) => c.withRepoPath(newRepoPath))
1175
- }), options);
1381
+ }), options));
1176
1382
  }
1177
1383
  async getContributorsLite(repoPath, cacheKey, factory, options) {
1178
- return this.getSharedOrCreateWithKey(this.contributorsLite, repoPath, cacheKey, factory, (data, newRepoPath) => data.map((c) => c.withRepoPath(newRepoPath)), options);
1384
+ return this.readValidated(repoPath, () => this.getSharedOrCreateWithKey(this.contributorsLite, repoPath, cacheKey, factory, (data, newRepoPath) => data.map((c) => c.withRepoPath(newRepoPath)), options));
1179
1385
  }
1180
1386
  getContributorsStats(repoPath, cacheKey, factory, options) {
1181
- return this.getSharedSimpleWithKey(this.contributorsStats, repoPath, cacheKey, factory, options);
1387
+ return this.readValidated(repoPath, () => this.getSharedSimpleWithKey(this.contributorsStats, repoPath, cacheKey, factory, options));
1182
1388
  }
1183
1389
  getBaseBranchName(repoPath, ref, factory, cancellation) {
1390
+ return this.readValidated(repoPath, () => this.getBaseBranchNameCore(repoPath, ref, factory, cancellation));
1391
+ }
1392
+ getBaseBranchNameCore(repoPath, ref, factory, cancellation) {
1184
1393
  return this.getSharedSimpleWithKey(this.baseBranchName, repoPath, ref, factory, {
1185
1394
  createTTL: baseBranchNameTTL,
1186
1395
  cancellation
@@ -1283,7 +1492,7 @@ var Cache = class Cache {
1283
1492
  }
1284
1493
  /** Config can differ by checkout through config.worktree and conditional includes. */
1285
1494
  getAheadOfBaseConfigKey(repoPath, factory, cancellation) {
1286
- return this.aheadOfBaseConfigKey.getOrCreate(repoPath, (cacheable, signal) => Promise.resolve(factory(repoPath, cacheable, signal)), cancellation);
1495
+ return this.readValidated(repoPath, () => this.aheadOfBaseConfigKey.getOrCreate(repoPath, (cacheable, signal) => Promise.resolve(factory(repoPath, cacheable, signal)), cancellation));
1287
1496
  }
1288
1497
  /**
1289
1498
  * One listing for every checkout of a repository, which serves a checkout's {@link getAheadOfBaseConfigKey} while
@@ -1291,7 +1500,7 @@ var Cache = class Cache {
1291
1500
  * before it.
1292
1501
  */
1293
1502
  getAheadOfBaseConfigListing(repoPath, factory, cancellation) {
1294
- return this.getSharedSimple(this.aheadOfBaseConfigListing, repoPath, factory, cancellation);
1503
+ return this.readValidated(repoPath, () => this.getSharedSimple(this.aheadOfBaseConfigListing, repoPath, factory, cancellation));
1295
1504
  }
1296
1505
  /**
1297
1506
  * One listing of the gitignore filter's config inputs for every checkout of a repository, which serves a checkout's
@@ -1299,13 +1508,13 @@ var Cache = class Cache {
1299
1508
  * from before it.
1300
1509
  */
1301
1510
  getIgnoreConfigListing(repoPath, factory, cancellation) {
1302
- return this.getSharedSimple(this.ignoreConfigListing, repoPath, factory, cancellation);
1511
+ return this.readValidated(repoPath, () => this.getSharedSimple(this.ignoreConfigListing, repoPath, factory, cancellation));
1303
1512
  }
1304
1513
  getBranchMetadataMap(repoPath, factory) {
1305
- return this.getSharedSimple(this.branchMetadataMap, repoPath, factory);
1514
+ return this.readValidated(repoPath, () => this.getSharedSimple(this.branchMetadataMap, repoPath, factory));
1306
1515
  }
1307
1516
  getDefaultBranchName(repoPath, remote, factory, cancellation) {
1308
- return this.getSharedSimpleWithKey(this.defaultBranchName, repoPath, remote, factory, { cancellation });
1517
+ return this.readValidated(repoPath, () => this.getSharedSimpleWithKey(this.defaultBranchName, repoPath, remote, factory, { cancellation }));
1309
1518
  }
1310
1519
  /** The cached default branch for one `remote` key, without reading it; `undefined` when none is cached */
1311
1520
  peekDefaultBranchName(repoPath, remote) {
@@ -1316,6 +1525,9 @@ var Cache = class Cache {
1316
1525
  * (see {@link CachedMergeTarget}). A checkout evicts only the entries marked `evictOnCheckout`
1317
1526
  */
1318
1527
  getMergeTarget(repoPath, cacheKey, factory, cancellation) {
1528
+ return this.readValidated(repoPath, () => this.getMergeTargetCore(repoPath, cacheKey, factory, cancellation));
1529
+ }
1530
+ getMergeTargetCore(repoPath, cacheKey, factory, cancellation) {
1319
1531
  const pending = this.getSharedSimpleWithKey(this.mergeTargets, repoPath, cacheKey, async (commonPath, cacheable, signal) => {
1320
1532
  const generation = this._mergeTargetCheckoutGeneration;
1321
1533
  const closeGeneration = this.getCloseGeneration(commonPath);
@@ -1366,7 +1578,7 @@ var Cache = class Cache {
1366
1578
  this._caches.defaultBranchName?.delete(this.getCommonPath(repoPath), remote);
1367
1579
  }
1368
1580
  getInitialCommitSha(repoPath, factory) {
1369
- return this.getSharedSimple(this.initialCommitSha, repoPath, factory);
1581
+ return this.readValidated(repoPath, () => this.getSharedSimple(this.initialCommitSha, repoPath, factory));
1370
1582
  }
1371
1583
  /** A rejected factory is never cached (`PromiseMap` evicts on rejection) — a failed read retries next time. */
1372
1584
  getEmptyTreeSha(repoPath, factory) {
@@ -1376,39 +1588,57 @@ var Cache = class Cache {
1376
1588
  return this.getSharedSimple(this.lastFetched, repoPath, factory);
1377
1589
  }
1378
1590
  getRefs(repoPath, factory, cancellation) {
1591
+ return this.readValidated(repoPath, () => this.getRefsCore(repoPath, factory, cancellation));
1592
+ }
1593
+ getRefsCore(repoPath, factory, cancellation) {
1379
1594
  const commonPath = this.getCommonPath(repoPath);
1380
1595
  return this.refs.getOrCreate(commonPath, async (cacheable, signal) => {
1381
- const readAt = this._currentBranchDrops;
1596
+ const read = {
1597
+ at: this.getDropStamp(),
1598
+ commonPath
1599
+ };
1600
+ const closeGeneration = this.getCloseGeneration(commonPath);
1382
1601
  const records = await factory(commonPath, cacheable, signal);
1383
- for (const record of records) if (record.worktreePath) this._refsReadAt.set(record, readAt);
1602
+ const unregistered = /* @__PURE__ */ new Set();
1603
+ for (const record of records) {
1604
+ if (!record.worktreePath) continue;
1605
+ this._refsRead.set(record, read);
1606
+ const worktreePath = normalizePath(record.worktreePath);
1607
+ if (worktreePath !== commonPath && !this._commonPathRegistry.has(worktreePath)) unregistered.add(worktreePath);
1608
+ }
1609
+ if (!cacheable.invalidated && !signal?.aborted && this.getCloseGeneration(commonPath) === closeGeneration) this.replaceSeededWorktrees(commonPath, unregistered);
1384
1610
  return records;
1385
1611
  }, cancellation);
1386
1612
  }
1387
1613
  getRefTips(repoPath, factory, cancellation) {
1388
- const commonPath = this.getCommonPath(repoPath);
1389
- return this.refTips.getOrCreate(commonPath, (cacheable, signal) => Promise.resolve(factory(commonPath, cacheable, signal)), cancellation);
1614
+ return this.readValidated(repoPath, () => {
1615
+ const commonPath = this.getCommonPath(repoPath);
1616
+ return this.refTips.getOrCreate(commonPath, (cacheable, signal) => Promise.resolve(factory(commonPath, cacheable, signal)), cancellation);
1617
+ });
1390
1618
  }
1391
1619
  async getRemotes(repoPath, factory, cancellation) {
1392
- return this.getSharedOrCreate(this.remotes, repoPath, factory, (data, newRepoPath) => data.map((r) => r.withRepoPath(newRepoPath)), cancellation);
1620
+ return this.readValidated(repoPath, () => this.getSharedOrCreate(this.remotes, repoPath, factory, (data, newRepoPath) => data.map((r) => r.withRepoPath(newRepoPath)), cancellation));
1393
1621
  }
1394
1622
  async getStash(repoPath, cacheKey, factory, options) {
1395
- return this.getSharedOrCreateWithKey(this.stashes, repoPath, cacheKey, factory, (data, newRepoPath) => ({
1623
+ return this.readValidated(repoPath, () => this.getSharedOrCreateWithKey(this.stashes, repoPath, cacheKey, factory, (data, newRepoPath) => ({
1396
1624
  repoPath: newRepoPath,
1397
1625
  stashes: new Map(Array.from(data.stashes.entries(), ([sha, s]) => [sha, s.withRepoPath(newRepoPath)]))
1398
- }), options);
1626
+ }), options));
1399
1627
  }
1400
1628
  async getTags(repoPath, factory, cancellation) {
1401
- return this.getSharedOrCreate(this.tags, repoPath, factory, (data, newRepoPath) => ({
1629
+ return this.readValidated(repoPath, () => this.getSharedOrCreate(this.tags, repoPath, factory, (data, newRepoPath) => ({
1402
1630
  ...data,
1403
1631
  values: data.values.map((t) => t.withRepoPath(newRepoPath))
1404
- }), cancellation);
1632
+ }), cancellation));
1405
1633
  }
1406
1634
  async getWorktrees(repoPath, factory, options, cancellation) {
1407
- if (options?.force) {
1408
- if (cancellation?.aborted) throw new CancellationError();
1409
- this.evictCaches(repoPath, "worktreeList");
1410
- }
1411
- return this.getSharedOrCreate(this.worktrees, repoPath, factory, (data, newRepoPath) => data.map((w) => w.withRepoPath(newRepoPath)), cancellation);
1635
+ return this.readValidated(repoPath, () => {
1636
+ if (options?.force) {
1637
+ if (cancellation?.aborted) throw new CancellationError();
1638
+ this.evictCaches(repoPath, "worktreeList");
1639
+ }
1640
+ return this.getSharedOrCreate(this.worktrees, repoPath, factory, (data, newRepoPath) => data.map((w) => w.withRepoPath(newRepoPath)), cancellation);
1641
+ });
1412
1642
  }
1413
1643
  async getSharedOrCreate(cache, repoPath, factory, mapper, cancellation) {
1414
1644
  const commonPath = this.getCommonPath(repoPath);
@@ -1472,6 +1702,18 @@ __decorate([debug({ onlyExit: true })], Cache.prototype, "unregisterRepoPath", n
1472
1702
  __decorate([debug({ onlyExit: true })], Cache.prototype, "reset", null);
1473
1703
  __decorate([debug({ onlyExit: true })], Cache.prototype, "onRepositoryChanged", null);
1474
1704
  __decorate([debug({ onlyExit: true })], Cache.prototype, "applyRepositoryChanges", null);
1705
+ /** A {@link RepoPromiseCacheMap} whose `getOrCreate` waits for `validate` first (see {@link Cache.setReadValidator}) */
1706
+ var ValidatedRepoPromiseCacheMap = class extends RepoPromiseCacheMap {
1707
+ validate;
1708
+ constructor(validate, options) {
1709
+ super(options);
1710
+ this.validate = validate;
1711
+ }
1712
+ getOrCreate(...args) {
1713
+ const validation = this.validate(args[0]);
1714
+ return validation != null ? validation.then(() => super.getOrCreate(...args)) : super.getOrCreate(...args);
1715
+ }
1716
+ };
1475
1717
  //#endregion
1476
1718
  export { Cache, areUriScopedCachedGitTypes, resetDropsPendingRuns, shouldEvictBlameCacheEntry };
1477
1719