@gitkraken/core-gitlens 0.31.0 → 0.33.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 (61) hide show
  1. package/CHANGELOG.md +41 -1
  2. package/dist/git/cache.d.ts +90 -15
  3. package/dist/git/cache.js +215 -44
  4. package/dist/git/cache.js.map +1 -1
  5. package/dist/git/models/repositoryIdentities.d.ts +0 -1
  6. package/dist/git/models/repositoryIdentities.js +1 -4
  7. package/dist/git/models/repositoryIdentities.js.map +1 -1
  8. package/dist/git/providers/config.d.ts +8 -0
  9. package/dist/git/providers/provider.d.ts +7 -0
  10. package/dist/git/remotes/gitlab.js +15 -9
  11. package/dist/git/remotes/gitlab.js.map +1 -1
  12. package/dist/git/service.d.ts +2 -1
  13. package/dist/git/service.js +6 -2
  14. package/dist/git/service.js.map +1 -1
  15. package/dist/git/utils/repository.utils.d.ts +10 -0
  16. package/dist/git/utils/repository.utils.js +25 -2
  17. package/dist/git/utils/repository.utils.js.map +1 -1
  18. package/dist/git/watching/changeEvent.d.ts +13 -3
  19. package/dist/git/watching/changeEvent.js +19 -4
  20. package/dist/git/watching/changeEvent.js.map +1 -1
  21. package/dist/git/watching/watchGroup.d.ts +4 -2
  22. package/dist/git/watching/watchGroup.js +32 -17
  23. package/dist/git/watching/watchGroup.js.map +1 -1
  24. package/dist/git/watching/watchService.d.ts +4 -1
  25. package/dist/git/watching/watchService.js +18 -15
  26. package/dist/git/watching/watchService.js.map +1 -1
  27. package/dist/git/watching/watchSession.d.ts +27 -12
  28. package/dist/git/watching/watchSession.js +49 -19
  29. package/dist/git/watching/watchSession.js.map +1 -1
  30. package/dist/git/watching/worktreeSummary.d.ts +3 -2
  31. package/dist/git/watching/worktreeSummary.js +11 -10
  32. package/dist/git/watching/worktreeSummary.js.map +1 -1
  33. package/dist/git-cli/cliGitProvider.d.ts +28 -2
  34. package/dist/git-cli/cliGitProvider.js +63 -20
  35. package/dist/git-cli/cliGitProvider.js.map +1 -1
  36. package/dist/git-cli/exec/git.d.ts +17 -1
  37. package/dist/git-cli/exec/git.js +55 -8
  38. package/dist/git-cli/exec/git.js.map +1 -1
  39. package/dist/git-cli/exec/indexLock.d.ts +2 -0
  40. package/dist/git-cli/exec/indexLock.js +2 -2
  41. package/dist/git-cli/exec/indexLock.js.map +1 -1
  42. package/dist/git-cli/providers/branches.js +15 -10
  43. package/dist/git-cli/providers/branches.js.map +1 -1
  44. package/dist/git-cli/providers/config.d.ts +6 -1
  45. package/dist/git-cli/providers/config.js +49 -48
  46. package/dist/git-cli/providers/config.js.map +1 -1
  47. package/dist/git-cli/providers/pausedOperations.js +7 -3
  48. package/dist/git-cli/providers/pausedOperations.js.map +1 -1
  49. package/dist/git-cli/providers/worktrees.js +34 -10
  50. package/dist/git-cli/providers/worktrees.js.map +1 -1
  51. package/dist/git-cli/service.js +1 -1
  52. package/dist/git-cli/service.js.map +1 -1
  53. package/dist/plus/integrations/models/integration.js +1 -1
  54. package/dist/plus/integrations/models/integration.js.map +1 -1
  55. package/dist/plus/integrations/providers/gitlab/gitlab.d.ts +10 -0
  56. package/dist/plus/integrations/providers/gitlab/gitlab.js +62 -15
  57. package/dist/plus/integrations/providers/gitlab/gitlab.js.map +1 -1
  58. package/dist/plus/integrations/providers/gitlab/gitlab.utils.d.ts +8 -0
  59. package/dist/plus/integrations/providers/gitlab/gitlab.utils.js +32 -16
  60. package/dist/plus/integrations/providers/gitlab/gitlab.utils.js.map +1 -1
  61. package/package.json +1 -1
@@ -66,7 +66,7 @@ function isIndexWriteCommand(args) {
66
66
  * prints the same line from its own git command and fails makes the run exit 1, after the hook's work is done.
67
67
  */
68
68
  function isIndexLockHeldError(ex) {
69
- return ex instanceof RunError && !(ex instanceof CancelledRunError) && toExitCode(ex.code) === gitFatalExitCode && indexLockHeldRegex.test(ex.stderr);
69
+ return ex instanceof RunError && !(ex instanceof CancelledRunError) && toExitCode(ex.code) === 128 && indexLockHeldRegex.test(ex.stderr);
70
70
  }
71
71
  /** Resolves after `ms`, or rejects as soon as `signal` aborts. */
72
72
  async function delay(ms, signal) {
@@ -169,6 +169,6 @@ function waitFor(promise, signal) {
169
169
  });
170
170
  }
171
171
  //#endregion
172
- export { KeyedSequencer, indexLockRetryDelays, isConfigCommand, isConfigLockHeldError, isIndexLockHeldError, isIndexWriteCommand, retryWhileConfigLocked, retryWhileIndexLocked, toExitCode };
172
+ export { KeyedSequencer, gitFatalExitCode, indexLockRetryDelays, isConfigCommand, isConfigLockHeldError, isIndexLockHeldError, isIndexWriteCommand, retryWhileConfigLocked, retryWhileIndexLocked, toExitCode };
173
173
 
174
174
  //# 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`. */\nconst 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,MAAM,mBAAmB;;AAGzB,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,qBAAqB,IAAsB;CAC1D,OACC,cAAc,YACd,EAAE,cAAc,sBAChB,WAAW,GAAG,IAAI,MAAM,oBACxB,mBAAmB,KAAK,GAAG,MAAM;AAEnC;;AAGA,eAAe,MAAM,IAAY,QAAgD;CAChF,IAAI;EACH,MAAMA,WAAK,IAAI,KAAA,GAAW,EAAU,OAAO,CAAC;CAC7C,SAAS,IAAI;EACZ,IAAI,QAAQ,SAAS,MAAM,YAAY,MAAM;EAE7C,MAAM;CACP;AACD;;;;;;AAOA,MAAM,yBAAyB;;;;;AAM/B,SAAgB,gBAAgB,MAAkC;CACjE,OAAO,eAAe,IAAI,CAAC,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AW,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/**\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,qBAAqB,IAAsB;CAC1D,OACC,cAAc,YACd,EAAE,cAAc,sBAChB,WAAW,GAAG,IAAI,MAAA,OAClB,mBAAmB,KAAK,GAAG,MAAM;AAEnC;;AAGA,eAAe,MAAM,IAAY,QAAgD;CAChF,IAAI;EACH,MAAMA,WAAK,IAAI,KAAA,GAAW,EAAU,OAAO,CAAC;CAC7C,SAAS,IAAI;EACZ,IAAI,QAAQ,SAAS,MAAM,YAAY,MAAM;EAE7C,MAAM;CACP;AACD;;;;;;AAOA,MAAM,yBAAyB;;;;;AAM/B,SAAgB,gBAAgB,MAAkC;CACjE,OAAO,eAAe,IAAI,CAAC,CAAC,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AY,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"}
@@ -183,17 +183,22 @@ const storedMergeKeys = [
183
183
  * `branch`, from the list shared by a repository's worktrees, as `repoPath` sees it. The copy holds the same metadata
184
184
  * object, which `Cache.patchBranchMetadata` updates in place.
185
185
  *
186
- * A list read before a checkout gives the branch now current `worktree: false`. `keepUnlisted` keeps that, so a reader
187
- * of the whole list (`findStaleBranches`) can tell the list is stale; otherwise the current branch names `repoPath`.
186
+ * A list read before a checkout gives the branch now current `worktree: false`, or the worktree it was checked out in
187
+ * then. `keepUnlisted` keeps those placements, so a reader of the whole list (`findStaleBranches`) can tell the list
188
+ * is stale. Otherwise the current branch names `repoPath`, and a branch that isn't current but that the list places at
189
+ * `repoPath` was left by the checkout, so it gets `worktree: false`. `isCurrent` is `undefined` when `repoPath`'s
190
+ * current branch couldn't be read, so the list's placement stands.
188
191
  */
189
192
  function mapSharedBranch(branch, repoPath, commonPath, isCurrent, defaultWorktreePath, keepUnlisted) {
190
- if (!isCurrent && repoPath === commonPath) return branch;
191
193
  let worktree = branch.worktree;
192
- if (isCurrent && (worktree == null || worktree === false && !keepUnlisted)) worktree = {
193
- path: repoPath,
194
- isDefault: repoPath === defaultWorktreePath
195
- };
196
- return new GitBranch(repoPath, branch.refName, isCurrent, branch.date, branch.metadata, branch.sha, branch.upstream, worktree, false, false);
194
+ if (isCurrent) {
195
+ if (worktree == null || !keepUnlisted && (worktree === false || worktree.path !== repoPath)) worktree = {
196
+ path: repoPath,
197
+ isDefault: repoPath === defaultWorktreePath
198
+ };
199
+ } else if (!keepUnlisted && isCurrent === false && worktree !== false && worktree?.path === repoPath) worktree = false;
200
+ if (!isCurrent && repoPath === commonPath && worktree === branch.worktree) return branch;
201
+ return new GitBranch(repoPath, branch.refName, isCurrent ?? false, branch.date, branch.metadata, branch.sha, branch.upstream, worktree, false, false);
197
202
  }
198
203
  var BranchesGitSubProvider = class {
199
204
  context;
@@ -327,7 +332,7 @@ var BranchesGitSubProvider = class {
327
332
  };
328
333
  const branch = values[index];
329
334
  return {
330
- branch: mapSharedBranch(branch, repoPath, commonPath, isCurrent(branch), defaultWorktreePath, false),
335
+ branch: mapSharedBranch(branch, repoPath, commonPath, currentRef != null ? isCurrent(branch) : void 0, defaultWorktreePath, false),
331
336
  kept
332
337
  };
333
338
  }
@@ -475,7 +480,7 @@ var BranchesGitSubProvider = class {
475
480
  mapperSignal ??= cancellation;
476
481
  const { currentRef, defaultWorktreePath, isDetached } = await this.getCurrentRefAndDefaultWorktreePath(targetRepoPath, commonPath, mapperSignal);
477
482
  const branches = shared.values.map((b) => {
478
- return mapSharedBranch(b, targetRepoPath, commonPath, !b.remote && b.name === currentRef?.name && !isDetached, defaultWorktreePath, true);
483
+ return mapSharedBranch(b, targetRepoPath, commonPath, currentRef != null ? !b.remote && b.name === currentRef.name && !isDetached : void 0, defaultWorktreePath, true);
479
484
  });
480
485
  if (isDetached || currentRef != null && !branches.some((b) => b.current)) {
481
486
  const metadataMap = await this.getBranchMetadataMap(commonPath);