@gitkraken/core-gitlens 0.62.0 → 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 (67) hide show
  1. package/CHANGELOG.md +15 -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/utils/hiddenRefs.utils.d.ts +15 -0
  14. package/dist/git/utils/hiddenRefs.utils.js +68 -2
  15. package/dist/git/utils/hiddenRefs.utils.js.map +1 -1
  16. package/dist/git/utils/pullRequest.utils.d.ts +3 -6
  17. package/dist/git/utils/pullRequest.utils.js +6 -7
  18. package/dist/git/utils/pullRequest.utils.js.map +1 -1
  19. package/dist/git/watching/gitIgnoreFilter.d.ts +12 -5
  20. package/dist/git/watching/gitIgnoreFilter.js +26 -32
  21. package/dist/git/watching/gitIgnoreFilter.js.map +1 -1
  22. package/dist/git/watching/provider.d.ts +18 -3
  23. package/dist/git/watching/watchGroup.d.ts +7 -2
  24. package/dist/git/watching/watchGroup.js +51 -3
  25. package/dist/git/watching/watchGroup.js.map +1 -1
  26. package/dist/git/watching/watchService.d.ts +6 -3
  27. package/dist/git/watching/watchService.js +94 -64
  28. package/dist/git/watching/watchService.js.map +1 -1
  29. package/dist/git-cli/cliGitProvider.d.ts +2 -0
  30. package/dist/git-cli/cliGitProvider.js +85 -24
  31. package/dist/git-cli/cliGitProvider.js.map +1 -1
  32. package/dist/git-cli/exec/git.js +4 -4
  33. package/dist/git-cli/exec/git.js.map +1 -1
  34. package/dist/git-cli/exec/indexLock.d.ts +7 -5
  35. package/dist/git-cli/exec/indexLock.js +19 -15
  36. package/dist/git-cli/exec/indexLock.js.map +1 -1
  37. package/dist/git-cli/providers/config.d.ts +1 -0
  38. package/dist/git-cli/providers/config.js +15 -5
  39. package/dist/git-cli/providers/config.js.map +1 -1
  40. package/dist/git-cli/providers/pausedOperations.js +2 -2
  41. package/dist/git-cli/providers/pausedOperations.js.map +1 -1
  42. package/dist/git-cli/providers/staging.d.ts +8 -8
  43. package/dist/git-cli/providers/staging.js +120 -25
  44. package/dist/git-cli/providers/staging.js.map +1 -1
  45. package/dist/ipc/discovery.js +1 -1
  46. package/dist/plus/agents/providers/claudeCodeTranscript.js +6 -6
  47. package/dist/plus/agents/providers/claudeCodeTranscript.js.map +1 -1
  48. package/dist/plus/ai/providers/openAICompatibleProviderBase.js +1 -1
  49. package/dist/plus/git-github/api/config.d.ts +5 -0
  50. package/dist/plus/git-github/api/config.js.map +1 -1
  51. package/dist/plus/git-github/api/github.js +24 -4
  52. package/dist/plus/git-github/api/github.js.map +1 -1
  53. package/dist/plus/git-github/models.d.ts +12 -0
  54. package/dist/plus/git-github/models.js +8 -3
  55. package/dist/plus/git-github/models.js.map +1 -1
  56. package/dist/plus/integrations/context.d.ts +5 -0
  57. package/dist/plus/integrations/providers/azure/azure.js +1 -1
  58. package/dist/plus/integrations/providers/github.js +7 -3
  59. package/dist/plus/integrations/providers/github.js.map +1 -1
  60. package/dist/plus/integrations/reads/etag.d.ts +5 -0
  61. package/dist/plus/integrations/reads/etag.js +2 -0
  62. package/dist/plus/integrations/reads/etag.js.map +1 -1
  63. package/dist/utils/env/node/exec.d.ts +2 -0
  64. package/dist/utils/env/node/exec.js +4 -2
  65. package/dist/utils/env/node/exec.js.map +1 -1
  66. package/docs/integrations.md +9 -9
  67. package/package.json +1 -1
@@ -8,6 +8,8 @@ export declare function toExitCode(code: number | string | undefined): number |
8
8
  export declare const gitFatalExitCode = 128;
9
9
  /** How long to wait before each retry of a run that found `index.lock` held; its length is the retry count. */
10
10
  export declare const indexLockRetryDelays: readonly number[];
11
+ /** The longer {@link indexLockRetryDelays} of a run that asks for `indexLockWait: 'extended'`. */
12
+ export declare const extendedIndexLockRetryDelays: readonly number[];
11
13
  /**
12
14
  * Whether the argv is a command that writes the index (`apply` only does with `--index`, `--cached` or `--3way`,
13
15
  * which implies `--index`, and never with `--check`).
@@ -26,14 +28,14 @@ export declare function isConfigCommand(args: readonly string[]): boolean;
26
28
  /** Whether a run failed because another process may hold the config file's `.lock`: the reason is `File exists` or absent. */
27
29
  export declare function isConfigLockHeldError(ex: unknown): boolean;
28
30
  /**
29
- * Runs `attempt`, and runs it again after each of {@link indexLockRetryDelays} while it fails on a held
30
- * `index.lock`. Any other failure, or the last lock failure, is rethrown as is. `beforeRetry` runs after each
31
- * wait, right before the next attempt; whatever it throws ends the retrying and is rethrown.
31
+ * Runs `attempt`, and runs it again after each of `delays` (by default {@link indexLockRetryDelays}) while it fails
32
+ * on a held `index.lock`. Any other failure, or the last lock failure, is rethrown as is. `beforeRetry` runs after
33
+ * each wait, right before the next attempt; whatever it throws ends the retrying and is rethrown.
32
34
  */
33
- export declare function retryWhileIndexLocked<T>(attempt: () => Promise<T>, signal: AbortSignal | undefined, beforeRetry?: (lockError: Error) => void | Promise<void>): Promise<T>;
35
+ export declare function retryWhileIndexLocked<T>(attempt: () => Promise<T>, signal: AbortSignal | undefined, beforeRetry?: (lockError: Error) => void | Promise<void>, delays?: readonly number[]): Promise<T>;
34
36
  /**
35
37
  * Like {@link retryWhileIndexLocked}, for a config write that loses the race for the file's `.lock` to another
36
- * process — git fails at once rather than waiting.
38
+ * process — git fails at once rather than waiting. Always waits {@link indexLockRetryDelays}.
37
39
  */
38
40
  export declare function retryWhileConfigLocked<T>(attempt: () => Promise<T>, signal: AbortSignal | undefined): Promise<T>;
39
41
  /**
@@ -52,6 +52,14 @@ const indexLockRetryDelays = [
52
52
  200,
53
53
  400
54
54
  ];
55
+ /** The longer {@link indexLockRetryDelays} of a run that asks for `indexLockWait: 'extended'`. */
56
+ const extendedIndexLockRetryDelays = [
57
+ 100,
58
+ 200,
59
+ 400,
60
+ 800,
61
+ 1600
62
+ ];
55
63
  /**
56
64
  * Whether the argv is a command that writes the index (`apply` only does with `--index`, `--cached` or `--3way`,
57
65
  * which implies `--index`, and never with `--check`).
@@ -97,37 +105,33 @@ function isConfigLockHeldError(ex) {
97
105
  if (rest == null) return false;
98
106
  return /: File exists\s*$/i.test(rest) || !rest.includes(": ");
99
107
  }
100
- /**
101
- * Runs `attempt`, and runs it again after each of {@link indexLockRetryDelays} while it fails with an error
102
- * `isHeldError` accepts. Any other failure, or the last lock failure, is rethrown as is.
103
- */
104
- async function retryWhileHeld(attempt, signal, isHeldError, beforeRetry) {
108
+ async function retryWhileHeld(attempt, signal, isHeldError, delays, beforeRetry) {
105
109
  for (let retry = 0;; retry++) {
106
110
  let lockError;
107
111
  try {
108
112
  return await attempt();
109
113
  } catch (ex) {
110
- if (retry >= indexLockRetryDelays.length || !isHeldError(ex)) throw ex;
114
+ if (retry >= delays.length || !isHeldError(ex)) throw ex;
111
115
  lockError = ex;
112
116
  }
113
- await delay(indexLockRetryDelays[retry], signal);
117
+ await delay(delays[retry], signal);
114
118
  await beforeRetry?.(lockError);
115
119
  }
116
120
  }
117
121
  /**
118
- * Runs `attempt`, and runs it again after each of {@link indexLockRetryDelays} while it fails on a held
119
- * `index.lock`. Any other failure, or the last lock failure, is rethrown as is. `beforeRetry` runs after each
120
- * wait, right before the next attempt; whatever it throws ends the retrying and is rethrown.
122
+ * Runs `attempt`, and runs it again after each of `delays` (by default {@link indexLockRetryDelays}) while it fails
123
+ * on a held `index.lock`. Any other failure, or the last lock failure, is rethrown as is. `beforeRetry` runs after
124
+ * each wait, right before the next attempt; whatever it throws ends the retrying and is rethrown.
121
125
  */
122
- function retryWhileIndexLocked(attempt, signal, beforeRetry) {
123
- return retryWhileHeld(attempt, signal, isIndexLockHeldError, beforeRetry);
126
+ function retryWhileIndexLocked(attempt, signal, beforeRetry, delays = indexLockRetryDelays) {
127
+ return retryWhileHeld(attempt, signal, isIndexLockHeldError, delays, beforeRetry);
124
128
  }
125
129
  /**
126
130
  * Like {@link retryWhileIndexLocked}, for a config write that loses the race for the file's `.lock` to another
127
- * process — git fails at once rather than waiting.
131
+ * process — git fails at once rather than waiting. Always waits {@link indexLockRetryDelays}.
128
132
  */
129
133
  function retryWhileConfigLocked(attempt, signal) {
130
- return retryWhileHeld(attempt, signal, isConfigLockHeldError);
134
+ return retryWhileHeld(attempt, signal, isConfigLockHeldError, indexLockRetryDelays);
131
135
  }
132
136
  /**
133
137
  * Runs the work for each key one at a time, in arrival order. A failing run doesn't hold up the next one, and a
@@ -169,6 +173,6 @@ function waitFor(promise, signal) {
169
173
  });
170
174
  }
171
175
  //#endregion
172
- export { KeyedSequencer, gitFatalExitCode, indexLockRetryDelays, isConfigCommand, isConfigLockHeldError, isIndexLockHeldError, isIndexWriteCommand, retryWhileConfigLocked, retryWhileIndexLocked, toExitCode };
176
+ export { KeyedSequencer, extendedIndexLockRetryDelays, gitFatalExitCode, indexLockRetryDelays, isConfigCommand, isConfigLockHeldError, isIndexLockHeldError, isIndexWriteCommand, retryWhileConfigLocked, retryWhileIndexLocked, toExitCode };
173
177
 
174
178
  //# sourceMappingURL=indexLock.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"indexLock.js","names":["wait"],"sources":["../../../../git-cli/src/exec/indexLock.ts"],"sourcesContent":["import { setTimeout as wait } from 'timers/promises';\nimport { leadingCommand } from './commandClassifier.js';\nimport { CancelledRunError, RunError } from './exec.errors.js';\nimport { abortReason } from './gitQueue.js';\n\n/**\n * Verbs that take `<gitdir>/index.lock` before changing anything, so a run that loses the race fails at once\n * with nothing half-done and is safe to retry. `stash` is left out because it is multi-step and can fail part\n * way, and the long or interactive verbs (`merge`, `rebase`, `cherry-pick`, `revert`, `am`, `pull`) because\n * holding the lock-ordering chain for their whole run would stall every other write to the checkout.\n */\nconst indexWritingVerbs: ReadonlySet<string> = new Set([\n\t'add',\n\t'checkout',\n\t'commit',\n\t'mv',\n\t'read-tree',\n\t'reset',\n\t'restore',\n\t'rm',\n\t'switch',\n\t'update-index',\n]);\n\nconst applyIndexOptions: ReadonlySet<string> = new Set(['--index', '--cached', '--3way', '-3']);\n\n/**\n * Matches git's `fatal: Unable to create '<path>/index.lock': File exists.` — the wording varies a little by version,\n * but git always `die()`s (`fatal:`) on it.\n * Anchored to the start of stderr: git takes the lock before doing anything else, so its own failure is the first\n * thing it prints past any `warning:`/`hint:` lines from parsing its arguments (`checkout` warns of an ambiguous\n * refname first). The same line after other output came from something the run started, such as a hook running its\n * own git command, after the run had already done its work — retrying would run it all again.\n */\nconst indexLockHeldRegex =\n\t/^(?:\\s*(?:warning|hint): [^\\r\\n]*\\r?\\n)*\\s*fatal: Unable to create '[^\\r\\n]*index\\.lock': File exists/i;\n\n/**\n * The exit code in a run error's `code`, or `undefined` when the process never exited normally: a numeric string\n * is a real exit code, but an errno (`'ENOENT'`) means the spawn itself failed, and `undefined` means it was killed.\n */\nexport function toExitCode(code: number | string | undefined): number | undefined {\n\tconst exitCode = typeof code === 'number' ? code : code != null ? parseInt(code, 10) : NaN;\n\treturn Number.isInteger(exitCode) ? exitCode : undefined;\n}\n\n/** Git's exit code when it `die()`s, as it does on a held `index.lock`. */\nexport const gitFatalExitCode = 128;\n\n/** How long to wait before each retry of a run that found `index.lock` held; its length is the retry count. */\nexport const indexLockRetryDelays: readonly number[] = [100, 200, 400];\n\n/**\n * Whether the argv is a command that writes the index (`apply` only does with `--index`, `--cached` or `--3way`,\n * which implies `--index`, and never with `--check`).\n */\nexport function isIndexWriteCommand(args: readonly string[]): boolean {\n\tconst { verb, rest } = leadingCommand(args);\n\tif (verb === 'apply') return !rest.includes('--check') && rest.some(a => applyIndexOptions.has(a));\n\n\treturn indexWritingVerbs.has(verb);\n}\n\n/**\n * Whether a run failed because another process held `index.lock`. The exit code must be 128 too: a hook that\n * prints the same line from its own git command and fails makes the run exit 1, after the hook's work is done.\n */\nexport function isIndexLockHeldError(ex: unknown): boolean {\n\treturn (\n\t\tex instanceof RunError &&\n\t\t!(ex instanceof CancelledRunError) &&\n\t\ttoExitCode(ex.code) === gitFatalExitCode &&\n\t\tindexLockHeldRegex.test(ex.stderr)\n\t);\n}\n\n/** Resolves after `ms`, or rejects as soon as `signal` aborts. */\nasync function delay(ms: number, signal: AbortSignal | undefined): Promise<void> {\n\ttry {\n\t\tawait wait(ms, undefined, { signal: signal });\n\t} catch (ex) {\n\t\tif (signal?.aborted) throw abortReason(signal);\n\n\t\tthrow ex;\n\t}\n}\n\n/**\n * Captures the rest of git's `error: could not lock config file <path>[: <reason>]` line. A held lock reads\n * `: File exists`, except `--remove-section`/`--rename-section` print no reason (for any failure); permanent\n * failures (`Permission denied`, `No such file or directory`, ...) must not be retried.\n */\nconst configLockFailureRegex = /could not lock config file ([^\\r\\n]*)/i;\n\n/**\n * Whether the argv is `git config`. Only that verb: others that write config (`branch -m`, `remote add`) can\n * fail after a partial change, so a blind retry isn't safe.\n */\nexport function isConfigCommand(args: readonly string[]): boolean {\n\treturn leadingCommand(args).verb === 'config';\n}\n\n/** Whether a run failed because another process may hold the config file's `.lock`: the reason is `File exists` or absent. */\nexport function isConfigLockHeldError(ex: unknown): boolean {\n\tif (!(ex instanceof RunError) || ex instanceof CancelledRunError) return false;\n\n\tconst rest = configLockFailureRegex.exec(ex.stderr)?.[1];\n\tif (rest == null) return false;\n\n\treturn /: File exists\\s*$/i.test(rest) || !rest.includes(': ');\n}\n\n/**\n * Runs `attempt`, and runs it again after each of {@link indexLockRetryDelays} while it fails with an error\n * `isHeldError` accepts. Any other failure, or the last lock failure, is rethrown as is.\n */\nasync function retryWhileHeld<T>(\n\tattempt: () => Promise<T>,\n\tsignal: AbortSignal | undefined,\n\tisHeldError: (ex: unknown) => boolean,\n\tbeforeRetry?: (lockError: Error) => void | Promise<void>,\n): Promise<T> {\n\tfor (let retry = 0; ; retry++) {\n\t\tlet lockError: Error;\n\t\ttry {\n\t\t\treturn await attempt();\n\t\t} catch (ex) {\n\t\t\tif (retry >= indexLockRetryDelays.length || !isHeldError(ex)) throw ex;\n\n\t\t\tlockError = ex as Error;\n\t\t}\n\n\t\tawait delay(indexLockRetryDelays[retry], signal);\n\t\tawait beforeRetry?.(lockError);\n\t}\n}\n\n/**\n * Runs `attempt`, and runs it again after each of {@link indexLockRetryDelays} while it fails on a held\n * `index.lock`. Any other failure, or the last lock failure, is rethrown as is. `beforeRetry` runs after each\n * wait, right before the next attempt; whatever it throws ends the retrying and is rethrown.\n */\nexport function retryWhileIndexLocked<T>(\n\tattempt: () => Promise<T>,\n\tsignal: AbortSignal | undefined,\n\tbeforeRetry?: (lockError: Error) => void | Promise<void>,\n): Promise<T> {\n\treturn retryWhileHeld(attempt, signal, isIndexLockHeldError, beforeRetry);\n}\n\n/**\n * Like {@link retryWhileIndexLocked}, for a config write that loses the race for the file's `.lock` to another\n * process — git fails at once rather than waiting.\n */\nexport function retryWhileConfigLocked<T>(attempt: () => Promise<T>, signal: AbortSignal | undefined): Promise<T> {\n\treturn retryWhileHeld(attempt, signal, isConfigLockHeldError);\n}\n\n/**\n * Runs the work for each key one at a time, in arrival order. A failing run doesn't hold up the next one, and a\n * run whose signal aborts while it waits rejects at once without ever starting.\n */\nexport class KeyedSequencer {\n\t/** The tail of each key's chain — settles once everything queued so far has finished or been dropped. */\n\tprivate readonly _tails = new Map<string, Promise<void>>();\n\n\tasync run<T>(key: string, signal: AbortSignal | undefined, fn: () => Promise<T>): Promise<T> {\n\t\tconst previous = this._tails.get(key);\n\n\t\tlet release!: () => void;\n\t\tconst tail = new Promise<void>(resolve => (release = resolve));\n\t\tthis._tails.set(key, tail);\n\n\t\tconst finish = () => {\n\t\t\trelease();\n\t\t\tif (this._tails.get(key) === tail) {\n\t\t\t\tthis._tails.delete(key);\n\t\t\t}\n\t\t};\n\n\t\tlet started = false;\n\t\ttry {\n\t\t\tif (previous != null) {\n\t\t\t\tawait waitFor(previous, signal);\n\t\t\t}\n\n\t\t\tstarted = true;\n\t\t\treturn await fn();\n\t\t} finally {\n\t\t\tif (started || previous == null) {\n\t\t\t\tfinish();\n\t\t\t} else {\n\t\t\t\t// Dropped while waiting: whoever is queued behind still has to wait for the run ahead of us,\n\t\t\t\t// so the chain can only be released once that run is done.\n\t\t\t\tvoid previous.then(finish);\n\t\t\t}\n\t\t}\n\t}\n}\n\nfunction waitFor(promise: Promise<void>, signal: AbortSignal | undefined): Promise<void> {\n\tif (signal == null) return promise;\n\tif (signal.aborted) return Promise.reject(abortReason(signal));\n\n\treturn new Promise<void>((resolve, reject) => {\n\t\tconst onAbort = () => reject(abortReason(signal));\n\t\tsignal.addEventListener('abort', onAbort, { once: true });\n\t\tvoid promise.then(() => {\n\t\t\tsignal.removeEventListener('abort', onAbort);\n\t\t\tresolve();\n\t\t});\n\t});\n}\n"],"mappings":";;;;;;;;;;;AAWA,MAAM,oCAAyC,IAAI,IAAI;CACtD;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACD,CAAC;AAED,MAAM,oCAAyC,IAAI,IAAI;CAAC;CAAW;CAAY;CAAU;AAAI,CAAC;;;;;;;;;AAU9F,MAAM,qBACL;;;;;AAMD,SAAgB,WAAW,MAAuD;CACjF,MAAM,WAAW,OAAO,SAAS,WAAW,OAAO,QAAQ,OAAO,SAAS,MAAM,EAAE,IAAI;CACvF,OAAO,OAAO,UAAU,QAAQ,IAAI,WAAW,KAAA;AAChD;;AAGA,MAAa,mBAAmB;;AAGhC,MAAa,uBAA0C;CAAC;CAAK;CAAK;AAAG;;;;;AAMrE,SAAgB,oBAAoB,MAAkC;CACrE,MAAM,EAAE,MAAM,SAAS,eAAe,IAAI;CAC1C,IAAI,SAAS,SAAS,OAAO,CAAC,KAAK,SAAS,SAAS,KAAK,KAAK,MAAK,MAAK,kBAAkB,IAAI,CAAC,CAAC;CAEjG,OAAO,kBAAkB,IAAI,IAAI;AAClC;;;;;AAMA,SAAgB,qBAA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;EAC5F,MAAM,WAAW,KAAK,OAAO,IAAI,GAAG;EAEpC,IAAI;EACJ,MAAM,OAAO,IAAI,SAAc,YAAY,UAAU,OAAQ;EAC7D,KAAK,OAAO,IAAI,KAAK,IAAI;EAEzB,MAAM,eAAe;GACpB,QAAQ;GACR,IAAI,KAAK,OAAO,IAAI,GAAG,MAAM,MAC5B,KAAK,OAAO,OAAO,GAAG;EAExB;EAEA,IAAI,UAAU;EACd,IAAI;GACH,IAAI,YAAY,MACf,MAAM,QAAQ,UAAU,MAAM;GAG/B,UAAU;GACV,OAAO,MAAM,GAAG;EACjB,UAAU;GACT,IAAI,WAAW,YAAY,MAC1B,OAAO;QAIP,SAAc,KAAK,MAAM;EAE3B;CACD;AACD;AAEA,SAAS,QAAQ,SAAwB,QAAgD;CACxF,IAAI,UAAU,MAAM,OAAO;CAC3B,IAAI,OAAO,SAAS,OAAO,QAAQ,OAAO,YAAY,MAAM,CAAC;CAE7D,OAAO,IAAI,SAAe,SAAS,WAAW;EAC7C,MAAM,gBAAgB,OAAO,YAAY,MAAM,CAAC;EAChD,OAAO,iBAAiB,SAAS,SAAS,EAAE,MAAM,KAAK,CAAC;EACxD,QAAa,WAAW;GACvB,OAAO,oBAAoB,SAAS,OAAO;GAC3C,QAAQ;EACT,CAAC;CACF,CAAC;AACF"}
1
+ {"version":3,"file":"indexLock.js","names":["wait"],"sources":["../../../../git-cli/src/exec/indexLock.ts"],"sourcesContent":["import { setTimeout as wait } from 'timers/promises';\nimport { leadingCommand } from './commandClassifier.js';\nimport { CancelledRunError, RunError } from './exec.errors.js';\nimport { abortReason } from './gitQueue.js';\n\n/**\n * Verbs that take `<gitdir>/index.lock` before changing anything, so a run that loses the race fails at once\n * with nothing half-done and is safe to retry. `stash` is left out because it is multi-step and can fail part\n * way, and the long or interactive verbs (`merge`, `rebase`, `cherry-pick`, `revert`, `am`, `pull`) because\n * holding the lock-ordering chain for their whole run would stall every other write to the checkout.\n */\nconst indexWritingVerbs: ReadonlySet<string> = new Set([\n\t'add',\n\t'checkout',\n\t'commit',\n\t'mv',\n\t'read-tree',\n\t'reset',\n\t'restore',\n\t'rm',\n\t'switch',\n\t'update-index',\n]);\n\nconst applyIndexOptions: ReadonlySet<string> = new Set(['--index', '--cached', '--3way', '-3']);\n\n/**\n * Matches git's `fatal: Unable to create '<path>/index.lock': File exists.` — the wording varies a little by version,\n * but git always `die()`s (`fatal:`) on it.\n * Anchored to the start of stderr: git takes the lock before doing anything else, so its own failure is the first\n * thing it prints past any `warning:`/`hint:` lines from parsing its arguments (`checkout` warns of an ambiguous\n * refname first). The same line after other output came from something the run started, such as a hook running its\n * own git command, after the run had already done its work — retrying would run it all again.\n */\nconst indexLockHeldRegex =\n\t/^(?:\\s*(?:warning|hint): [^\\r\\n]*\\r?\\n)*\\s*fatal: Unable to create '[^\\r\\n]*index\\.lock': File exists/i;\n\n/**\n * The exit code in a run error's `code`, or `undefined` when the process never exited normally: a numeric string\n * is a real exit code, but an errno (`'ENOENT'`) means the spawn itself failed, and `undefined` means it was killed.\n */\nexport function toExitCode(code: number | string | undefined): number | undefined {\n\tconst exitCode = typeof code === 'number' ? code : code != null ? parseInt(code, 10) : NaN;\n\treturn Number.isInteger(exitCode) ? exitCode : undefined;\n}\n\n/** Git's exit code when it `die()`s, as it does on a held `index.lock`. */\nexport const gitFatalExitCode = 128;\n\n/** How long to wait before each retry of a run that found `index.lock` held; its length is the retry count. */\nexport const indexLockRetryDelays: readonly number[] = [100, 200, 400];\n\n/** The longer {@link indexLockRetryDelays} of a run that asks for `indexLockWait: 'extended'`. */\nexport const extendedIndexLockRetryDelays: readonly number[] = [100, 200, 400, 800, 1600];\n\n/**\n * Whether the argv is a command that writes the index (`apply` only does with `--index`, `--cached` or `--3way`,\n * which implies `--index`, and never with `--check`).\n */\nexport function isIndexWriteCommand(args: readonly string[]): boolean {\n\tconst { verb, rest } = leadingCommand(args);\n\tif (verb === 'apply') return !rest.includes('--check') && rest.some(a => applyIndexOptions.has(a));\n\n\treturn indexWritingVerbs.has(verb);\n}\n\n/**\n * Whether a run failed because another process held `index.lock`. The exit code must be 128 too: a hook that\n * prints the same line from its own git command and fails makes the run exit 1, after the hook's work is done.\n */\nexport function isIndexLockHeldError(ex: unknown): boolean {\n\treturn (\n\t\tex instanceof RunError &&\n\t\t!(ex instanceof CancelledRunError) &&\n\t\ttoExitCode(ex.code) === gitFatalExitCode &&\n\t\tindexLockHeldRegex.test(ex.stderr)\n\t);\n}\n\n/** Resolves after `ms`, or rejects as soon as `signal` aborts. */\nasync function delay(ms: number, signal: AbortSignal | undefined): Promise<void> {\n\ttry {\n\t\tawait wait(ms, undefined, { signal: signal });\n\t} catch (ex) {\n\t\tif (signal?.aborted) throw abortReason(signal);\n\n\t\tthrow ex;\n\t}\n}\n\n/**\n * Captures the rest of git's `error: could not lock config file <path>[: <reason>]` line. A held lock reads\n * `: File exists`, except `--remove-section`/`--rename-section` print no reason (for any failure); permanent\n * failures (`Permission denied`, `No such file or directory`, ...) must not be retried.\n */\nconst configLockFailureRegex = /could not lock config file ([^\\r\\n]*)/i;\n\n/**\n * Whether the argv is `git config`. Only that verb: others that write config (`branch -m`, `remote add`) can\n * fail after a partial change, so a blind retry isn't safe.\n */\nexport function isConfigCommand(args: readonly string[]): boolean {\n\treturn leadingCommand(args).verb === 'config';\n}\n\n/** Whether a run failed because another process may hold the config file's `.lock`: the reason is `File exists` or absent. */\nexport function isConfigLockHeldError(ex: unknown): boolean {\n\tif (!(ex instanceof RunError) || ex instanceof CancelledRunError) return false;\n\n\tconst rest = configLockFailureRegex.exec(ex.stderr)?.[1];\n\tif (rest == null) return false;\n\n\treturn /: File exists\\s*$/i.test(rest) || !rest.includes(': ');\n}\n\nasync function retryWhileHeld<T>(\n\tattempt: () => Promise<T>,\n\tsignal: AbortSignal | undefined,\n\tisHeldError: (ex: unknown) => boolean,\n\tdelays: readonly number[],\n\tbeforeRetry?: (lockError: Error) => void | Promise<void>,\n): Promise<T> {\n\tfor (let retry = 0; ; retry++) {\n\t\tlet lockError: Error;\n\t\ttry {\n\t\t\treturn await attempt();\n\t\t} catch (ex) {\n\t\t\tif (retry >= delays.length || !isHeldError(ex)) throw ex;\n\n\t\t\tlockError = ex as Error;\n\t\t}\n\n\t\tawait delay(delays[retry], signal);\n\t\tawait beforeRetry?.(lockError);\n\t}\n}\n\n/**\n * Runs `attempt`, and runs it again after each of `delays` (by default {@link indexLockRetryDelays}) while it fails\n * on a held `index.lock`. Any other failure, or the last lock failure, is rethrown as is. `beforeRetry` runs after\n * each wait, right before the next attempt; whatever it throws ends the retrying and is rethrown.\n */\nexport function retryWhileIndexLocked<T>(\n\tattempt: () => Promise<T>,\n\tsignal: AbortSignal | undefined,\n\tbeforeRetry?: (lockError: Error) => void | Promise<void>,\n\tdelays: readonly number[] = indexLockRetryDelays,\n): Promise<T> {\n\treturn retryWhileHeld(attempt, signal, isIndexLockHeldError, delays, beforeRetry);\n}\n\n/**\n * Like {@link retryWhileIndexLocked}, for a config write that loses the race for the file's `.lock` to another\n * process — git fails at once rather than waiting. Always waits {@link indexLockRetryDelays}.\n */\nexport function retryWhileConfigLocked<T>(attempt: () => Promise<T>, signal: AbortSignal | undefined): Promise<T> {\n\treturn retryWhileHeld(attempt, signal, isConfigLockHeldError, indexLockRetryDelays);\n}\n\n/**\n * Runs the work for each key one at a time, in arrival order. A failing run doesn't hold up the next one, and a\n * run whose signal aborts while it waits rejects at once without ever starting.\n */\nexport class KeyedSequencer {\n\t/** The tail of each key's chain — settles once everything queued so far has finished or been dropped. */\n\tprivate readonly _tails = new Map<string, Promise<void>>();\n\n\tasync run<T>(key: string, signal: AbortSignal | undefined, fn: () => Promise<T>): Promise<T> {\n\t\tconst previous = this._tails.get(key);\n\n\t\tlet release!: () => void;\n\t\tconst tail = new Promise<void>(resolve => (release = resolve));\n\t\tthis._tails.set(key, tail);\n\n\t\tconst finish = () => {\n\t\t\trelease();\n\t\t\tif (this._tails.get(key) === tail) {\n\t\t\t\tthis._tails.delete(key);\n\t\t\t}\n\t\t};\n\n\t\tlet started = false;\n\t\ttry {\n\t\t\tif (previous != null) {\n\t\t\t\tawait waitFor(previous, signal);\n\t\t\t}\n\n\t\t\tstarted = true;\n\t\t\treturn await fn();\n\t\t} finally {\n\t\t\tif (started || previous == null) {\n\t\t\t\tfinish();\n\t\t\t} else {\n\t\t\t\t// Dropped while waiting: whoever is queued behind still has to wait for the run ahead of us,\n\t\t\t\t// so the chain can only be released once that run is done.\n\t\t\t\tvoid previous.then(finish);\n\t\t\t}\n\t\t}\n\t}\n}\n\nfunction waitFor(promise: Promise<void>, signal: AbortSignal | undefined): Promise<void> {\n\tif (signal == null) return promise;\n\tif (signal.aborted) return Promise.reject(abortReason(signal));\n\n\treturn new Promise<void>((resolve, reject) => {\n\t\tconst onAbort = () => reject(abortReason(signal));\n\t\tsignal.addEventListener('abort', onAbort, { once: true });\n\t\tvoid promise.then(() => {\n\t\t\tsignal.removeEventListener('abort', onAbort);\n\t\t\tresolve();\n\t\t});\n\t});\n}\n"],"mappings":";;;;;;;;;;;AAWA,MAAM,oCAAyC,IAAI,IAAI;CACtD;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACD,CAAC;AAED,MAAM,oCAAyC,IAAI,IAAI;CAAC;CAAW;CAAY;CAAU;AAAI,CAAC;;;;;;;;;AAU9F,MAAM,qBACL;;;;;AAMD,SAAgB,WAAW,MAAuD;CACjF,MAAM,WAAW,OAAO,SAAS,WAAW,OAAO,QAAQ,OAAO,SAAS,MAAM,EAAE,IAAI;CACvF,OAAO,OAAO,UAAU,QAAQ,IAAI,WAAW,KAAA;AAChD;;AAGA,MAAa,mBAAmB;;AAGhC,MAAa,uBAA0C;CAAC;CAAK;CAAK;AAAG;;AAGrE,MAAa,+BAAkD;CAAC;CAAK;CAAK;CAAK;CAAK;AAAI;;;;;AAMxF,SAAgB,oBAAoB,MAAkC;CACrE,MAAM,EAAE,MAAM,SAAS,eAAe,IAAI;CAC1C,IAAI,SAAS,SAAS,OAAO,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A6C;CACjH,OAAO,eAAe,SAAS,QAAQ,uBAAuB,oBAAoB;AACnF;;;;;AAMA,IAAa,iBAAb,MAA4B;;CAE3B,yBAA0B,IAAI,IAA2B;CAEzD,MAAM,IAAO,KAAa,QAAiC,IAAkC;EAC5F,MAAM,WAAW,KAAK,OAAO,IAAI,GAAG;EAEpC,IAAI;EACJ,MAAM,OAAO,IAAI,SAAc,YAAY,UAAU,OAAQ;EAC7D,KAAK,OAAO,IAAI,KAAK,IAAI;EAEzB,MAAM,eAAe;GACpB,QAAQ;GACR,IAAI,KAAK,OAAO,IAAI,GAAG,MAAM,MAC5B,KAAK,OAAO,OAAO,GAAG;EAExB;EAEA,IAAI,UAAU;EACd,IAAI;GACH,IAAI,YAAY,MACf,MAAM,QAAQ,UAAU,MAAM;GAG/B,UAAU;GACV,OAAO,MAAM,GAAG;EACjB,UAAU;GACT,IAAI,WAAW,YAAY,MAC1B,OAAO;QAIP,SAAc,KAAK,MAAM;EAE3B;CACD;AACD;AAEA,SAAS,QAAQ,SAAwB,QAAgD;CACxF,IAAI,UAAU,MAAM,OAAO;CAC3B,IAAI,OAAO,SAAS,OAAO,QAAQ,OAAO,YAAY,MAAM,CAAC;CAE7D,OAAO,IAAI,SAAe,SAAS,WAAW;EAC7C,MAAM,gBAAgB,OAAO,YAAY,MAAM,CAAC;EAChD,OAAO,iBAAiB,SAAS,SAAS,EAAE,MAAM,KAAK,CAAC;EACxD,QAAa,WAAW;GACvB,OAAO,oBAAoB,SAAS,OAAO;GAC3C,QAAQ;EACT,CAAC;CACF,CAAC;AACF"}
@@ -86,6 +86,7 @@ export declare class ConfigGitSubProvider implements GitConfigSubProvider {
86
86
  private readonly git;
87
87
  private readonly cache;
88
88
  private readonly provider;
89
+ private ignoreConfigEnvironment?;
89
90
  constructor(context: GitServiceContext, git: Git, cache: Cache, provider: CliGitProviderInternal);
90
91
  /**
91
92
  * Failed reads of the current user by repository path, each with the drop stamp taken before it. Not a cached answer:
@@ -15,9 +15,9 @@ import { KeyedSequencer } from "../exec/indexLock.js";
15
15
  import { isFolder, isGitAnswer, isGitUnanswered, throwIfUnanswered } from "../exec/git.js";
16
16
  import { HoldOffMap } from "../../utils/holdOffMap.js";
17
17
  import { gate } from "../../utils/decorators/gate.js";
18
- import { promises, statSync } from "fs";
19
- import { env } from "process";
20
18
  import { hostname, userInfo } from "os";
19
+ import { env } from "process";
20
+ import { promises, statSync } from "fs";
21
21
  //#region ../git-cli/src/providers/config.ts
22
22
  const mappedAuthorRegex = /(.+)\s<(.+)>/;
23
23
  const emptyArray = Object.freeze([]);
@@ -186,6 +186,7 @@ var ConfigGitSubProvider = class {
186
186
  git;
187
187
  cache;
188
188
  provider;
189
+ ignoreConfigEnvironment;
189
190
  constructor(context, git, cache, provider) {
190
191
  this.context = context;
191
192
  this.git = git;
@@ -224,13 +225,17 @@ var ConfigGitSubProvider = class {
224
225
  args.push(key);
225
226
  return (await this.git.run({
226
227
  cwd: repoPath ?? "",
228
+ env: options?.env,
227
229
  errors: "ignore",
228
230
  runLocally: options?.runGitLocally
229
231
  }, ...args)).stdout.trim() || void 0;
230
232
  }
231
233
  async getIgnoreConfig(repoPath, options) {
234
+ const env = this.git.getRunEnvironment();
235
+ if (this.ignoreConfigEnvironment != null && env !== this.ignoreConfigEnvironment) this.cache.deleteIgnoreConfig();
236
+ this.ignoreConfigEnvironment = env;
232
237
  const commonPath = this.cache.getCommonPath(repoPath);
233
- const listing = await this.cache.getIgnoreConfigListing(repoPath, (path, cacheable, signal) => this.readIgnoreConfigListing(path, cacheable, signal));
238
+ const listing = await this.cache.getIgnoreConfigListing(repoPath, (path, cacheable, signal) => this.readIgnoreConfigListing(path, env, cacheable, signal));
234
239
  if (options?.observableOnly && (listing == null || mayConfigDifferByCheckout(listing))) return void 0;
235
240
  if (listing != null && (repoPath === commonPath || !mayConfigDifferByCheckout(listing))) {
236
241
  let excludesFile;
@@ -247,15 +252,20 @@ var ConfigGitSubProvider = class {
247
252
  ignoreCase
248
253
  };
249
254
  }
250
- const [excludesFileResult, ignoreCaseResult] = await Promise.allSettled([this.getConfig(repoPath, "core.excludesFile"), this.getConfig(repoPath, "core.ignorecase")]);
255
+ const [excludesFileResult, ignoreCaseResult] = await Promise.allSettled([this.getConfigCore(repoPath, "core.excludesFile", { env }), this.getConfigCore(repoPath, "core.ignorecase", { env })]);
251
256
  return {
252
257
  excludesFile: getSettledValue(excludesFileResult),
253
258
  ignoreCase: getSettledValue(ignoreCaseResult)
254
259
  };
255
260
  }
256
- async readIgnoreConfigListing(cwd, cacheable, cancellation) {
261
+ async readIgnoreConfigListing(cwd, env, cacheable, cancellation) {
262
+ if (env !== this.git.getRunEnvironment()) {
263
+ cacheable.invalidate();
264
+ return;
265
+ }
257
266
  const result = await this.git.run({
258
267
  cwd,
268
+ env,
259
269
  cancellation,
260
270
  errors: "ignore"
261
271
  }, "config", "--null", "--get-regexp", "^(core\\.excludesfile|core\\.ignorecase|core\\.worktree|include\\.path|includeif\\..*|extensions\\.worktreeconfig)$");