@gitkraken/core-gitlens 0.61.1 → 0.63.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 (72) hide show
  1. package/CHANGELOG.md +22 -1
  2. package/dist/git/cache.d.ts +1 -0
  3. package/dist/git/cache.js +11 -0
  4. package/dist/git/cache.js.map +1 -1
  5. package/dist/git/errors.d.ts +15 -0
  6. package/dist/git/errors.js +9 -1
  7. package/dist/git/errors.js.map +1 -1
  8. package/dist/git/models/pullRequest.d.ts +3 -0
  9. package/dist/git/models/pullRequest.js.map +1 -1
  10. package/dist/git/providers/operations.d.ts +4 -3
  11. package/dist/git/providers/staging.d.ts +16 -8
  12. package/dist/git/run.types.d.ts +6 -0
  13. package/dist/git/service.js +6 -0
  14. package/dist/git/service.js.map +1 -1
  15. package/dist/git/utils/hiddenRefs.utils.d.ts +15 -0
  16. package/dist/git/utils/hiddenRefs.utils.js +68 -2
  17. package/dist/git/utils/hiddenRefs.utils.js.map +1 -1
  18. package/dist/git/utils/pullRequest.utils.d.ts +3 -6
  19. package/dist/git/utils/pullRequest.utils.js +6 -7
  20. package/dist/git/utils/pullRequest.utils.js.map +1 -1
  21. package/dist/git/watching/gitIgnoreFilter.d.ts +12 -5
  22. package/dist/git/watching/gitIgnoreFilter.js +26 -32
  23. package/dist/git/watching/gitIgnoreFilter.js.map +1 -1
  24. package/dist/git/watching/provider.d.ts +18 -3
  25. package/dist/git/watching/watchGroup.d.ts +7 -2
  26. package/dist/git/watching/watchGroup.js +51 -3
  27. package/dist/git/watching/watchGroup.js.map +1 -1
  28. package/dist/git/watching/watchService.d.ts +16 -2
  29. package/dist/git/watching/watchService.js +210 -88
  30. package/dist/git/watching/watchService.js.map +1 -1
  31. package/dist/git/watching/watcherPatterns.d.ts +1 -1
  32. package/dist/git/watching/watcherPatterns.js +11 -5
  33. package/dist/git/watching/watcherPatterns.js.map +1 -1
  34. package/dist/git-cli/cliGitProvider.d.ts +3 -6
  35. package/dist/git-cli/cliGitProvider.js +144 -38
  36. package/dist/git-cli/cliGitProvider.js.map +1 -1
  37. package/dist/git-cli/exec/git.js +4 -4
  38. package/dist/git-cli/exec/git.js.map +1 -1
  39. package/dist/git-cli/exec/indexLock.d.ts +7 -5
  40. package/dist/git-cli/exec/indexLock.js +19 -15
  41. package/dist/git-cli/exec/indexLock.js.map +1 -1
  42. package/dist/git-cli/providers/config.d.ts +1 -0
  43. package/dist/git-cli/providers/config.js +15 -5
  44. package/dist/git-cli/providers/config.js.map +1 -1
  45. package/dist/git-cli/providers/pausedOperations.js +2 -2
  46. package/dist/git-cli/providers/pausedOperations.js.map +1 -1
  47. package/dist/git-cli/providers/staging.d.ts +8 -8
  48. package/dist/git-cli/providers/staging.js +120 -25
  49. package/dist/git-cli/providers/staging.js.map +1 -1
  50. package/dist/ipc/discovery.js +1 -1
  51. package/dist/plus/agents/providers/claudeCodeTranscript.js +6 -6
  52. package/dist/plus/agents/providers/claudeCodeTranscript.js.map +1 -1
  53. package/dist/plus/ai/providers/openAICompatibleProviderBase.js +1 -1
  54. package/dist/plus/git-github/api/config.d.ts +5 -0
  55. package/dist/plus/git-github/api/config.js.map +1 -1
  56. package/dist/plus/git-github/api/github.js +24 -4
  57. package/dist/plus/git-github/api/github.js.map +1 -1
  58. package/dist/plus/git-github/models.d.ts +12 -0
  59. package/dist/plus/git-github/models.js +8 -3
  60. package/dist/plus/git-github/models.js.map +1 -1
  61. package/dist/plus/integrations/context.d.ts +5 -0
  62. package/dist/plus/integrations/providers/azure/azure.js +1 -1
  63. package/dist/plus/integrations/providers/github.js +7 -3
  64. package/dist/plus/integrations/providers/github.js.map +1 -1
  65. package/dist/plus/integrations/reads/etag.d.ts +5 -0
  66. package/dist/plus/integrations/reads/etag.js +2 -0
  67. package/dist/plus/integrations/reads/etag.js.map +1 -1
  68. package/dist/utils/env/node/exec.d.ts +2 -0
  69. package/dist/utils/env/node/exec.js +4 -2
  70. package/dist/utils/env/node/exec.js.map +1 -1
  71. package/docs/integrations.md +9 -9
  72. package/package.json +1 -1
@@ -1,4 +1,5 @@
1
1
  import { Emitter } from "../../utils/event.js";
2
+ import { isLinux, isWindows } from "../../utils/platform.js";
2
3
  import { getRepositoryKey } from "../../utils/uri.js";
3
4
  import { isDescendant, relative } from "../../utils/path.js";
4
5
  import { GitDirPoller } from "./gitDirPoller.js";
@@ -12,6 +13,8 @@ import { RepositoryWatchSession } from "./watchSession.js";
12
13
  * tighter bound here would mark batches incomplete when they filter down to almost nothing.
13
14
  */
14
15
  const maxBufferedWorkingTreePaths = 5e3;
16
+ const maxIgnoreCheckPaths = 1e3;
17
+ const ignoreCheckDelayMs = 100;
15
18
  const ignorePruningRefreshDelayMs = 500;
16
19
  /**
17
20
  * Global service that multiplexes repository watching across all repos.
@@ -70,11 +73,13 @@ var RepositoryWatchService = class {
70
73
  defaultRepoMaxWaitMs;
71
74
  defaultWorkingTreeMaxWaitMs;
72
75
  getIgnoreFilter;
76
+ getIgnorePathChecker;
73
77
  getIgnoredDirectories;
74
78
  getGitIgnoreWatchInputs;
75
79
  getIgnoredWorktreeRoots;
76
80
  getIgnoredWorktreeFolders;
77
81
  provider;
82
+ trackedPruning;
78
83
  poller;
79
84
  readFile;
80
85
  readDirectory;
@@ -91,11 +96,13 @@ var RepositoryWatchService = class {
91
96
  _suspended = false;
92
97
  constructor(options) {
93
98
  this.provider = options.watchingProvider;
99
+ this.trackedPruning = this.provider.supportsTrackedGitIgnorePaths === true;
94
100
  this.defaultRepoDelayMs = options.defaultRepoDelayMs;
95
101
  this.defaultWorkingTreeDelayMs = options.defaultWorkingTreeDelayMs;
96
102
  this.defaultRepoMaxWaitMs = options.defaultRepoMaxWaitMs;
97
103
  this.defaultWorkingTreeMaxWaitMs = options.defaultWorkingTreeMaxWaitMs;
98
104
  this.getIgnoreFilter = options.getIgnoreFilter;
105
+ this.getIgnorePathChecker = options.getIgnorePathChecker;
99
106
  this.getIgnoredDirectories = options.getIgnoredDirectories;
100
107
  this.getGitIgnoreWatchInputs = options.getGitIgnoreWatchInputs;
101
108
  this.getIgnoredWorktreeRoots = options.getIgnoredWorktreeRoots;
@@ -174,7 +181,7 @@ var RepositoryWatchService = class {
174
181
  },
175
182
  onDidFireRepoChange: (event) => {
176
183
  this._onDidChangeRepository.fire(event);
177
- if (this.wtWatchers.get(repoPath)?.delegation == null) return;
184
+ if (this.wtWatchers.get(repoPath)?.delegation == null || this.trackedPruning) return;
178
185
  if (event.changes.has("index") || event.changes.has("head") || event.changes.has("config") && !event.configConfined) this.refreshWorkingTreeFilter(repoPath);
179
186
  },
180
187
  onDidFireWorkingTreeChange: (repoPath) => {
@@ -220,7 +227,13 @@ var RepositoryWatchService = class {
220
227
  */
221
228
  noteSelfWrite(repoPath, changes, refs, options) {
222
229
  if (this._disposed) return;
223
- this.sessionMap.get(getRepositoryKey(repoPath))?.session.noteSelfWrite(changes, refs, options);
230
+ const key = getRepositoryKey(repoPath);
231
+ const entry = this.wtWatchers.get(key);
232
+ if (entry != null && (entry.ignoreCheck != null || this.trackedPruning) && (changes.length === 0 || changes.some((change) => change === "index" || change === "head" || change === "config" || change === "ignores" || change === "unknown"))) {
233
+ if (entry.delegation != null) this.refreshWorkingTreeFilter(key);
234
+ else this.invalidateIgnoreCheck(entry);
235
+ }
236
+ this.sessionMap.get(key)?.session.noteSelfWrite(changes, refs, options);
224
237
  }
225
238
  /**
226
239
  * Whether `repoPath`'s `.git` directory is watched: its session has a repo subscriber, so it is connected to its
@@ -268,6 +281,7 @@ var RepositoryWatchService = class {
268
281
  suspendAll() {
269
282
  this._suspended = true;
270
283
  for (const record of this.sessionMap.values()) record.session.suspend();
284
+ for (const entry of this.wtWatchers.values()) this.invalidateIgnoreCheck(entry);
271
285
  this.poller?.suspend();
272
286
  }
273
287
  /** Resume all sessions (clearing the global suspend state), with optional per-session delay */
@@ -276,10 +290,10 @@ var RepositoryWatchService = class {
276
290
  for (const record of this.sessionMap.values()) {
277
291
  const delayMs = getDelay?.(record.session);
278
292
  record.session.resume(delayMs);
279
- if (this.poller == null) {
280
- const entry = this.wtWatchers.get(record.session.repoPath);
281
- if (entry != null && entry.watcher == null) this.placeFallbackWorkingTreeWatcher(entry);
282
- }
293
+ const entry = this.wtWatchers.get(record.session.repoPath);
294
+ if (entry == null) continue;
295
+ if (this.poller == null && entry.watcher == null) this.placeFallbackWorkingTreeWatcher(entry);
296
+ if (entry.ignoreCheck != null) this.scheduleIgnoreCheck(entry, entry.ignoreCheck);
283
297
  }
284
298
  this.poller?.resume();
285
299
  }
@@ -305,19 +319,22 @@ var RepositoryWatchService = class {
305
319
  const group = this.getOrCreateWatchGroup(commonGitDir, session.repoPath);
306
320
  const hooks = {
307
321
  onRepoChanged: (_repoPath, changes, ref, overflow, configBranches, movedWorktree) => {
308
- if (overflow) {
309
- session.pushUnfencedRepoChanges(changes);
310
- const entry = this.wtWatchers.get(session.repoPath);
311
- if (entry?.delegation != null) this.scheduleIgnorePruningRefresh(entry, "recovery");
312
- } else session.pushRepoChanges(changes, ref, configBranches, movedWorktree);
322
+ const entry = this.wtWatchers.get(session.repoPath);
323
+ const indexMayHaveChanged = changes.includes("index") || changes.includes("head");
324
+ if (!overflow && entry != null && (indexMayHaveChanged || changes.includes("config"))) {
325
+ if (this.trackedPruning && entry.delegation != null && (indexMayHaveChanged || configBranches == null)) this.refreshWorkingTreeFilter(session.repoPath);
326
+ else this.invalidateIgnoreCheck(entry);
327
+ }
328
+ if (overflow) session.pushUnfencedRepoChanges(changes);
329
+ else session.pushRepoChanges(changes, ref, configBranches, movedWorktree);
313
330
  if (this.poller != null && (changes.includes("index") || changes.includes("head")) && this.wtWatchers.get(session.repoPath)?.reliability === "unwatchable") session.pushWorkingTreeChanges([], true);
314
331
  },
315
332
  onFetchHeadChanged: (repoPath) => {
316
333
  this._onDidChangeFetchHead.fire(repoPath);
317
334
  for (const h of watchHooks) h.onFetchHeadChanged?.(repoPath);
318
335
  },
319
- onIgnoresChanged: (repoPath) => {
320
- this.refreshWorkingTreeFilter(repoPath);
336
+ onIgnoresChanged: (repoPath, overflow) => {
337
+ this.refreshWorkingTreeFilter(repoPath, overflow ? "recovery" : "metadata");
321
338
  for (const h of watchHooks) h.onIgnoresChanged?.(repoPath);
322
339
  },
323
340
  getProbeRefs: () => {
@@ -325,6 +342,12 @@ var RepositoryWatchService = class {
325
342
  for (const ref of this.poller?.options.getRefs?.(session.repoPath) ?? []) refs.add(ref);
326
343
  return refs;
327
344
  },
345
+ onMetadataCoverageChanged: (live) => {
346
+ const entry = this.wtWatchers.get(session.repoPath);
347
+ if (entry == null || !this.trackedPruning) return;
348
+ if (!live) this.relinquishIgnoreDelegation(entry);
349
+ else if (entry.delegation == null && this.provider.createGitIgnoringWatcher != null && this.getGitIgnoreWatchInputs != null) this.replaceWithCoveredWatcher(entry);
350
+ },
328
351
  onUnwatchableChanged: () => this.updateWatchMode(record)
329
352
  };
330
353
  const wasConnected = group.sessions.has(session.repoPath);
@@ -385,26 +408,44 @@ var RepositoryWatchService = class {
385
408
  let entry;
386
409
  let filter;
387
410
  if (this.getIgnoreFilter != null) filter = this.getIgnoreFilter(repoPath, gitDir.uri.fsPath);
388
- let filterReady = filter == null;
389
- let buffered = filter != null ? [] : void 0;
411
+ const check = this.getIgnorePathChecker?.(repoPath);
412
+ const deliverUnchecked = this.trackedPruning && check == null;
413
+ let filterReady = filter == null || deliverUnchecked;
414
+ let buffered = filterReady ? void 0 : [];
390
415
  let bufferIncomplete = false;
416
+ const rootPrefix = repoPath.endsWith("/") ? repoPath : `${repoPath}/`;
417
+ const getRelativeEventPath = (path) => {
418
+ if (!isWindows && path.startsWith("/") && repoPath.startsWith("/")) {
419
+ const prefix = path.slice(0, rootPrefix.length);
420
+ if (prefix !== rootPrefix && (isLinux || prefix.toLowerCase() !== rootPrefix.toLowerCase())) return;
421
+ return path.slice(prefix.length);
422
+ }
423
+ return isDescendant(path, repoPath) ? relative(repoPath, path) : void 0;
424
+ };
391
425
  const revalidated = filter?.revalidate();
392
- if (filter != null) {
426
+ if (!filterReady && filter != null) {
393
427
  const replay = () => {
394
428
  const pending = buffered;
395
429
  const incomplete = bufferIncomplete;
396
430
  filterReady = true;
397
431
  buffered = void 0;
398
432
  bufferIncomplete = false;
399
- if (!pending?.length) return;
400
- const paths = filterWorkingTreePaths(pending, repoPath, filter);
401
- if (paths.length > 0 || incomplete) session.pushWorkingTreeChanges(paths, incomplete);
433
+ if (entry == null || this.wtWatchers.get(repoPath) !== entry) return;
434
+ const deliver = [];
435
+ for (const event of pending ?? []) {
436
+ const relativePath = getRelativeEventPath(event.path);
437
+ if (relativePath != null && this.shouldDeliverWorkingTreePath(entry, event.path, relativePath, event.reason === "delete")) deliver.push(event.path);
438
+ }
439
+ if (deliver.length || incomplete) session.pushWorkingTreeChanges(deliver, incomplete);
402
440
  };
403
441
  filter.ready().then(replay, replay).catch(() => {});
404
442
  }
405
443
  const onIgnoreRulesChanged = (refreshFilter, reason = "worktree") => {
406
- if (refreshFilter && filter != null) filter.refresh();
407
- if (entry != null) this.scheduleIgnorePruningRefresh(entry, reason);
444
+ if (refreshFilter && filter != null) this.reloadIgnoreFilter(filter, reason !== "worktree" && entry?.delegation != null);
445
+ if (entry != null) {
446
+ this.invalidateIgnoreCheck(entry);
447
+ this.scheduleIgnorePruningRefresh(entry, reason);
448
+ }
408
449
  for (const h of watchHooks) h.onGitIgnoreChanged?.(repoPath);
409
450
  session.pushUnfencedRepoChanges(["ignores"]);
410
451
  };
@@ -412,35 +453,37 @@ var RepositoryWatchService = class {
412
453
  const onEvent = (event) => {
413
454
  const startingDelegation = entry?.starting === true && entry.delegation != null;
414
455
  if (event.reason === "overflow") {
415
- session.pushWorkingTreeChanges([], true);
416
456
  onIgnoreRulesChanged(true, "recovery");
457
+ if (entry?.delegation == null || !this.trackedPruning) session.pushWorkingTreeChanges([], true);
417
458
  return;
418
459
  }
419
460
  if (isNoise(event.path)) return;
420
- const relativePath = isDescendant(event.path, repoPath) ? relative(repoPath, event.path) : void 0;
461
+ const relativePath = getRelativeEventPath(event.path);
421
462
  if (relativePath === ".gitignore") {
422
463
  onIgnoreRulesChanged(true);
423
464
  return;
424
465
  }
425
- if (relativePath?.endsWith("/.gitignore") && (entry?.delegation != null || !(filterReady && filter?.isIgnored(relativePath.slice(0, -10))))) onIgnoreRulesChanged(true);
466
+ if (relativePath?.endsWith("/.gitignore") && (deliverUnchecked || entry?.delegation != null || !(filterReady && filter?.isIgnored(relativePath.slice(0, -10))))) onIgnoreRulesChanged(true);
426
467
  if (startingDelegation) return;
427
468
  if (!filterReady) {
428
469
  if (buffered != null && buffered.length >= maxBufferedWorkingTreePaths) {
429
470
  bufferIncomplete = true;
430
471
  return;
431
472
  }
432
- buffered?.push(event.path);
473
+ buffered?.push(event);
433
474
  return;
434
475
  }
435
- if (filter != null && relativePath != null && filter.isIgnored(relativePath)) {
436
- if (canPrune && entry != null && entry.delegation == null) this.onIgnoredEvent(entry, filter, relativePath);
437
- return;
438
- }
439
- session.pushWorkingTreeChanges([event.path]);
476
+ if (entry != null && this.wtWatchers.get(repoPath) !== entry) return;
477
+ if (deliverUnchecked || entry == null || this.shouldDeliverWorkingTreePath(entry, event.path, relativePath, event.reason === "delete")) session.pushWorkingTreeChanges([event.path]);
440
478
  };
441
- const kept = canPrune && filter != null ? this.keptIgnoredDirectories.get(filter) : void 0;
442
- const created = this.createWorkingTreeWatcher(repoPath, onEvent, kept != null ? [...workingTreeExcludes, ...kept] : workingTreeExcludes, this.getGitIgnoreWatchInputs != null && this.isConnected(record));
479
+ const kept = check == null && canPrune && filter != null ? this.keptIgnoredDirectories.get(filter) : void 0;
480
+ const created = (this.getGitIgnoreWatchInputs != null && (this.trackedPruning ? this.watchGroups.get((gitDir.commonUri ?? gitDir.uri).fsPath)?.hasLiveMetadataCoverage(repoPath) : check == null && this.isConnected(record)) ? this.createWorkingTreeWatcher(repoPath, onEvent, workingTreeExcludes, true) : void 0) ?? this.createWorkingTreeWatcher(repoPath, onEvent, kept != null ? [...workingTreeExcludes, ...kept] : workingTreeExcludes);
443
481
  entry = {
482
+ ignoreCheck: check && {
483
+ check,
484
+ paths: /* @__PURE__ */ new Map(),
485
+ incomplete: false
486
+ },
444
487
  session,
445
488
  onEvent,
446
489
  filter,
@@ -466,10 +509,80 @@ var RepositoryWatchService = class {
466
509
  if (this.wtWatchers.get(repoPath) === entry) onIgnoreRulesChanged(true);
467
510
  });
468
511
  }
512
+ shouldDeliverWorkingTreePath(entry, path, relativePath, deleted = false) {
513
+ const filter = entry.filter;
514
+ if (relativePath == null || filter == null) return true;
515
+ const batch = entry.ignoreCheck;
516
+ if (!filter.isIgnored(relativePath) && !(batch != null && filter.isIgnored(`${relativePath}/`))) return true;
517
+ if (batch == null) {
518
+ if (entry.delegation == null && this.canPruneIgnoredDirectories()) this.onIgnoredEvent(entry, filter, relativePath);
519
+ return false;
520
+ }
521
+ if (batch.incomplete) return false;
522
+ const previous = batch.paths.get(path);
523
+ if (this._suspended || batch.paths.size >= maxIgnoreCheckPaths && previous == null) {
524
+ batch.paths.clear();
525
+ batch.incomplete = true;
526
+ } else batch.paths.set(path, {
527
+ relativePath,
528
+ deleted: deleted || previous?.deleted === true
529
+ });
530
+ this.scheduleIgnoreCheck(entry, batch);
531
+ return false;
532
+ }
533
+ invalidateIgnoreCheck(entry) {
534
+ const batch = entry.ignoreCheck;
535
+ if (batch == null) return;
536
+ if (batch.controller != null || batch.paths.size) {
537
+ clearTimeout(batch.timer);
538
+ batch.timer = void 0;
539
+ batch.controller?.abort();
540
+ batch.controller = void 0;
541
+ batch.paths.clear();
542
+ batch.incomplete = true;
543
+ }
544
+ this.scheduleIgnoreCheck(entry, batch);
545
+ }
546
+ scheduleIgnoreCheck(entry, batch) {
547
+ if (this._suspended || batch.controller != null || batch.timer != null || !batch.paths.size && !batch.incomplete) return;
548
+ batch.timer = setTimeout(() => {
549
+ batch.timer = void 0;
550
+ this.flushIgnoreCheck(entry, batch);
551
+ }, ignoreCheckDelayMs);
552
+ }
553
+ async flushIgnoreCheck(entry, batch) {
554
+ if (batch.incomplete) {
555
+ batch.incomplete = false;
556
+ entry.session.pushWorkingTreeChanges([], true);
557
+ return;
558
+ }
559
+ const paths = batch.paths;
560
+ const generation = entry.generation;
561
+ batch.paths = /* @__PURE__ */ new Map();
562
+ const controller = new AbortController();
563
+ batch.controller = controller;
564
+ let ignored;
565
+ try {
566
+ ignored = await batch.check(Array.from(paths.values(), (item) => item.relativePath), controller.signal);
567
+ } catch {}
568
+ if (this.wtWatchers.get(entry.session.repoPath) !== entry || batch.controller !== controller) return;
569
+ batch.controller = void 0;
570
+ if (ignored == null || generation !== entry.generation) entry.session.pushWorkingTreeChanges([], true);
571
+ else {
572
+ const delivered = [];
573
+ let ignoredDeletion = false;
574
+ for (const [path, { relativePath, deleted }] of paths) if (!ignored.has(relativePath)) delivered.push(path);
575
+ else ignoredDeletion ||= deleted;
576
+ if (delivered.length || ignoredDeletion) entry.session.pushWorkingTreeChanges(delivered, ignoredDeletion);
577
+ }
578
+ this.scheduleIgnoreCheck(entry, batch);
579
+ }
469
580
  stopWorkingTreeWatcher(repoPath) {
470
581
  const entry = this.wtWatchers.get(repoPath);
471
582
  if (entry == null) return;
472
583
  entry.generation++;
584
+ clearTimeout(entry.ignoreCheck?.timer);
585
+ entry.ignoreCheck?.controller?.abort();
473
586
  clearTimeout(entry.refreshTimer);
474
587
  entry.refreshTimer = void 0;
475
588
  this.wtWatchers.delete(repoPath);
@@ -489,6 +602,7 @@ var RepositoryWatchService = class {
489
602
  if (watcher != null && entry?.watcher === watcher) {
490
603
  entry.awaitingStartAck = false;
491
604
  this.reconcileWorkingTreeLifecycle(entry, entry.reliability, { rescan: entry.delegation == null });
605
+ if (this.trackedPruning && entry.delegation?.initialApplied && !entry.delegation.verified) this.refreshIgnorePruning(entry);
492
606
  }
493
607
  };
494
608
  let reliability = "reliable";
@@ -503,53 +617,60 @@ var RepositoryWatchService = class {
503
617
  const options = {
504
618
  excludes,
505
619
  onDidStart,
506
- ...this.poller == null ? void 0 : { onDidChangeReliability }
620
+ ...this.poller != null || this.trackedPruning ? { onDidChangeReliability } : void 0
507
621
  };
508
- if (tryDelegation && this.provider.createGitIgnoringWatcher != null) {
509
- let declined = false;
510
- const delegated = this.provider.createGitIgnoringWatcher(repoPath, (event) => {
511
- const entry = this.wtWatchers.get(repoPath);
512
- if (watcher != null && entry?.watcher === watcher && !declined) onEvent(event);
513
- }, {
514
- excludes: workingTreeExcludes,
515
- onDidStart: () => {
516
- if (!declined) onDidStart();
517
- },
518
- ...this.poller == null ? void 0 : { onDidChangeReliability: (state) => {
519
- if (!declined) onDidChangeReliability(state);
520
- } }
521
- });
522
- if (delegated != null) {
523
- watcher = delegated;
524
- return {
525
- watcher,
526
- reliability,
527
- awaitingStartAck: this.provider.callsOnDidStart === true && !started,
528
- delegation: {
529
- watcher: delegated,
530
- initialApplied: false,
531
- refreshing: false,
532
- verified: false
533
- }
534
- };
535
- }
536
- declined = true;
537
- started = false;
538
- reliability = "reliable";
622
+ const emit = (event) => {
623
+ if (watcher == null ? !tryDelegation : this.wtWatchers.get(repoPath)?.watcher === watcher) onEvent(event);
624
+ };
625
+ if (tryDelegation) {
626
+ const delegated = this.provider.createGitIgnoringWatcher?.(repoPath, emit, options);
627
+ if (delegated == null) return void 0;
628
+ watcher = delegated;
629
+ return {
630
+ watcher,
631
+ reliability,
632
+ awaitingStartAck: (this.provider.callsOnDidStart === true || this.trackedPruning) && !started,
633
+ delegation: {
634
+ watcher: delegated,
635
+ initialApplied: false,
636
+ refreshing: false,
637
+ verified: false
638
+ }
639
+ };
539
640
  }
540
- watcher = this.provider.createWatcher(repoPath, "**", onEvent, options);
641
+ watcher = this.provider.createWatcher(repoPath, "**", emit, options);
541
642
  return {
542
643
  watcher,
543
644
  reliability,
544
645
  awaitingStartAck: this.provider.callsOnDidStart === true && !started
545
646
  };
546
647
  }
648
+ replaceWithCoveredWatcher(entry) {
649
+ const previous = entry.watcher;
650
+ let created;
651
+ try {
652
+ created = this.createWorkingTreeWatcher(entry.session.repoPath, entry.onEvent, workingTreeExcludes, true);
653
+ if (created == null) return;
654
+ } catch {
655
+ return;
656
+ }
657
+ entry.watcher = created.watcher;
658
+ entry.delegation = created.delegation;
659
+ entry.awaitingStartAck = created.awaitingStartAck;
660
+ entry.starting = created.awaitingStartAck || created.delegation != null;
661
+ previous?.dispose();
662
+ this.reconcileWorkingTreeLifecycle(entry, created.reliability, {
663
+ initial: true,
664
+ rescan: !entry.starting
665
+ });
666
+ this.refreshIgnorePruning(entry);
667
+ }
547
668
  reconcileWorkingTreeLifecycle(entry, state, options) {
548
669
  const unavailable = state === "unwatchable";
549
670
  const availabilityChanged = !options?.initial && unavailable !== (entry.reliability === "unwatchable");
550
671
  const delegation = entry.delegation;
551
672
  entry.reliability = state;
552
- if (unavailable) entry.awaitingStartAck = false;
673
+ if (unavailable && (delegation == null || !this.trackedPruning)) entry.awaitingStartAck = false;
553
674
  if (availabilityChanged && delegation != null) {
554
675
  if (unavailable) {
555
676
  entry.generation++;
@@ -558,7 +679,7 @@ var RepositoryWatchService = class {
558
679
  }
559
680
  const rulesVerified = delegation?.verified !== false;
560
681
  const startupReady = entry.starting && !unavailable && !entry.awaitingStartAck && rulesVerified;
561
- const reconcileAvailability = availabilityChanged && (unavailable || rulesVerified);
682
+ const reconcileAvailability = availabilityChanged && (unavailable || rulesVerified && !(this.trackedPruning && delegation != null));
562
683
  if (startupReady || availabilityChanged && unavailable && delegation == null) entry.starting = false;
563
684
  this.updateWorkingTreePollTarget(entry);
564
685
  if (startupReady || reconcileAvailability || options?.rescan) entry.session.pushWorkingTreeChanges([], true);
@@ -599,7 +720,7 @@ var RepositoryWatchService = class {
599
720
  poller.add(target);
600
721
  }
601
722
  canPruneIgnoredDirectories() {
602
- return this.provider.supportsExcludes === true && this.getIgnoredDirectories != null;
723
+ return !this.trackedPruning && this.provider.supportsExcludes === true && this.getIgnoredDirectories != null;
603
724
  }
604
725
  /**
605
726
  * An event the gitignore post-filter dropped. When its directory is itself ignored, the watcher is watching an
@@ -628,7 +749,7 @@ var RepositoryWatchService = class {
628
749
  }
629
750
  scheduleIgnorePruningRefresh(entry, reason) {
630
751
  if (entry.filter != null) this.keptIgnoredDirectories.delete(entry.filter);
631
- if (entry.delegation == null && !this.canPruneIgnoredDirectories()) return;
752
+ if (entry.delegation == null && (entry.ignoreCheck != null || !this.canPruneIgnoredDirectories())) return;
632
753
  const delegation = entry.delegation;
633
754
  if (delegation != null) {
634
755
  if (entry.starting) delegation.verified = false;
@@ -651,10 +772,11 @@ var RepositoryWatchService = class {
651
772
  if (this.wtWatchers.get(entry.session.repoPath) !== entry) return;
652
773
  const delegation = entry.delegation;
653
774
  if (delegation != null) {
775
+ if (this.trackedPruning && delegation.initialApplied && entry.awaitingStartAck) return;
654
776
  if (!delegation.refreshing && (!delegation.initialApplied || entry.reliability !== "unwatchable")) this.refreshDelegatedIgnores(entry, delegation);
655
777
  return;
656
778
  }
657
- if (entry.watcher == null || !this.canPruneIgnoredDirectories()) return;
779
+ if (entry.watcher == null || entry.ignoreCheck != null || !this.canPruneIgnoredDirectories()) return;
658
780
  if (entry.reading) {
659
781
  entry.rereadQueued = true;
660
782
  return;
@@ -695,20 +817,22 @@ var RepositoryWatchService = class {
695
817
  const initial = !delegation.initialApplied;
696
818
  const verifyingStartup = !initial && !delegation.verified;
697
819
  const reason = initial ? "initial" : verifyingStartup ? "recovery" : delegation.pendingRefresh ?? "worktree";
698
- delegation.pendingRefresh = void 0;
699
820
  delegation.refreshing = true;
700
821
  try {
701
822
  const record = this.sessionMap.get(repoPath);
702
- const inputs = record == null ? void 0 : await this.getGitIgnoreWatchInputs?.(repoPath, record.gitDir, { refreshConfig: verifyingStartup });
823
+ const refreshConfig = verifyingStartup || this.trackedPruning && reason !== "worktree";
824
+ const reloadAfterRead = refreshConfig && (initial || verifyingStartup || !entry.filter?.canInvalidateConfig);
825
+ let inputs;
826
+ try {
827
+ if (record != null) inputs = await this.getGitIgnoreWatchInputs?.(repoPath, record.gitDir, { refreshConfig: reloadAfterRead });
828
+ } finally {
829
+ if (refreshConfig && entry.generation === generation && entry.delegation === delegation) await (reloadAfterRead ? entry.filter?.refresh() : entry.filter?.ready());
830
+ }
703
831
  if (entry.generation !== generation || entry.delegation !== delegation) return;
704
- if (inputs == null) {
832
+ if (inputs == null || this.trackedPruning && (!Array.isArray(inputs.protectedPaths) || !Array.isArray(inputs.configWatchPaths))) {
705
833
  this.relinquishIgnoreDelegation(entry);
706
834
  return;
707
835
  }
708
- if (verifyingStartup) {
709
- await entry.filter?.refresh();
710
- if (entry.generation !== generation || entry.delegation !== delegation) return;
711
- }
712
836
  await delegation.watcher.refreshGitIgnores(reason, inputs);
713
837
  if (entry.delegation !== delegation || this.wtWatchers.get(repoPath) !== entry) return;
714
838
  if (initial) {
@@ -720,9 +844,10 @@ var RepositoryWatchService = class {
720
844
  delegation.verified = true;
721
845
  this.reconcileWorkingTreeLifecycle(entry, entry.reliability, { rescan: !verifyingStartup && !entry.starting });
722
846
  } catch {
723
- if (this.wtWatchers.get(repoPath) === entry && entry.delegation === delegation) this.relinquishIgnoreDelegation(entry);
847
+ if (entry.generation === generation && this.wtWatchers.get(repoPath) === entry && entry.delegation === delegation) this.relinquishIgnoreDelegation(entry);
724
848
  } finally {
725
849
  delegation.refreshing = false;
850
+ if (entry.generation === generation) delegation.pendingRefresh = void 0;
726
851
  if (entry.delegation === delegation && this.wtWatchers.get(repoPath) === entry && entry.refreshTimer == null && (delegation.pendingRefresh != null || delegation.initialApplied && !delegation.verified)) this.refreshIgnorePruning(entry);
727
852
  }
728
853
  }
@@ -791,9 +916,15 @@ var RepositoryWatchService = class {
791
916
  refreshWorkingTreeFilter(repoPath, reason = "metadata") {
792
917
  const entry = this.wtWatchers.get(repoPath);
793
918
  if (entry == null) return;
794
- if (entry.filter != null) entry.filter.refresh();
919
+ this.invalidateIgnoreCheck(entry);
920
+ if (entry.filter != null) this.reloadIgnoreFilter(entry.filter, entry.delegation != null);
795
921
  this.scheduleIgnorePruningRefresh(entry, reason);
796
922
  }
923
+ reloadIgnoreFilter(filter, delegatedConfigChange) {
924
+ const configChanged = delegatedConfigChange && this.trackedPruning;
925
+ if (configChanged && !filter.canInvalidateConfig) return;
926
+ filter.refresh({ configChanged });
927
+ }
797
928
  disposeSessionRecord(record) {
798
929
  this.stopWorkingTreeWatcher(record.session.repoPath);
799
930
  this.disconnectFromWatchGroup(record);
@@ -801,15 +932,6 @@ var RepositoryWatchService = class {
801
932
  record.session.dispose();
802
933
  }
803
934
  };
804
- function filterWorkingTreePaths(absolutePaths, repoPath, filter) {
805
- const result = [];
806
- for (const p of absolutePaths) {
807
- if (!isDescendant(p, repoPath)) continue;
808
- const relativePath = relative(repoPath, p);
809
- if (!filter.isIgnored(relativePath)) result.push(p);
810
- }
811
- return result;
812
- }
813
935
  //#endregion
814
936
  export { RepositoryWatchService };
815
937