@gitkraken/core-gitlens 0.33.0 → 0.35.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 (113) hide show
  1. package/CHANGELOG.md +23 -1
  2. package/dist/git/cache.d.ts +31 -0
  3. package/dist/git/cache.js +101 -30
  4. package/dist/git/cache.js.map +1 -1
  5. package/dist/git/context.d.ts +3 -1
  6. package/dist/git/context.js.map +1 -1
  7. package/dist/git/errors.d.ts +3 -1
  8. package/dist/git/errors.js +4 -1
  9. package/dist/git/errors.js.map +1 -1
  10. package/dist/git/models/pullRequest.d.ts +90 -1
  11. package/dist/git/models/pullRequest.js +18 -2
  12. package/dist/git/models/pullRequest.js.map +1 -1
  13. package/dist/git/providers/shared/remotes.js +2 -0
  14. package/dist/git/providers/shared/remotes.js.map +1 -1
  15. package/dist/git/utils/pullRequest.utils.d.ts +72 -1
  16. package/dist/git/utils/pullRequest.utils.js +99 -1
  17. package/dist/git/utils/pullRequest.utils.js.map +1 -1
  18. package/dist/git/utils/repository.utils.d.ts +6 -0
  19. package/dist/git/utils/repository.utils.js +14 -2
  20. package/dist/git/utils/repository.utils.js.map +1 -1
  21. package/dist/git/watching/gitDirPoller.d.ts +10 -1
  22. package/dist/git/watching/gitDirPoller.js +9 -3
  23. package/dist/git/watching/gitDirPoller.js.map +1 -1
  24. package/dist/git/watching/unwatchedCacheValidator.d.ts +144 -0
  25. package/dist/git/watching/unwatchedCacheValidator.js +884 -0
  26. package/dist/git/watching/unwatchedCacheValidator.js.map +1 -0
  27. package/dist/git/watching/watchGroup.d.ts +2 -0
  28. package/dist/git/watching/watchGroup.js +4 -8
  29. package/dist/git/watching/watchGroup.js.map +1 -1
  30. package/dist/git/watching/watchService.d.ts +23 -0
  31. package/dist/git/watching/watchService.js +42 -2
  32. package/dist/git/watching/watchService.js.map +1 -1
  33. package/dist/git/watching/watchSession.d.ts +2 -0
  34. package/dist/git/watching/watchSession.js +3 -2
  35. package/dist/git/watching/watchSession.js.map +1 -1
  36. package/dist/git-cli/cliGitProvider.js +1 -1
  37. package/dist/git-cli/cliGitProvider.js.map +1 -1
  38. package/dist/git-cli/exec/commandClassifier.d.ts +31 -1
  39. package/dist/git-cli/exec/commandClassifier.js +67 -16
  40. package/dist/git-cli/exec/commandClassifier.js.map +1 -1
  41. package/dist/git-cli/exec/git.d.ts +46 -2
  42. package/dist/git-cli/exec/git.js +80 -7
  43. package/dist/git-cli/exec/git.js.map +1 -1
  44. package/dist/git-cli/exec/gitDirResolver.d.ts +11 -0
  45. package/dist/git-cli/exec/gitDirResolver.js +34 -1
  46. package/dist/git-cli/exec/gitDirResolver.js.map +1 -1
  47. package/dist/git-cli/exec/gitQueue.js +2 -28
  48. package/dist/git-cli/exec/gitQueue.js.map +1 -1
  49. package/dist/git-cli/providers/branches.d.ts +1 -0
  50. package/dist/git-cli/providers/branches.js +6 -0
  51. package/dist/git-cli/providers/branches.js.map +1 -1
  52. package/dist/git-cli/providers/config.d.ts +13 -1
  53. package/dist/git-cli/providers/config.js +48 -14
  54. package/dist/git-cli/providers/config.js.map +1 -1
  55. package/dist/git-cli/providers/pausedOperations.d.ts +1 -0
  56. package/dist/git-cli/providers/pausedOperations.js +4 -0
  57. package/dist/git-cli/providers/pausedOperations.js.map +1 -1
  58. package/dist/git-cli/providers/revision.js +2 -0
  59. package/dist/git-cli/providers/revision.js.map +1 -1
  60. package/dist/git-cli/providers/worktrees.js +2 -0
  61. package/dist/git-cli/providers/worktrees.js.map +1 -1
  62. package/dist/git-cli/service.d.ts +25 -1
  63. package/dist/git-cli/service.js +45 -0
  64. package/dist/git-cli/service.js.map +1 -1
  65. package/dist/plus/ai/errors.d.ts +8 -2
  66. package/dist/plus/ai/errors.js +15 -3
  67. package/dist/plus/ai/errors.js.map +1 -1
  68. package/dist/plus/git-github/api/config.d.ts +11 -0
  69. package/dist/plus/git-github/api/config.js.map +1 -1
  70. package/dist/plus/git-github/api/github.d.ts +82 -1
  71. package/dist/plus/git-github/api/github.js +304 -7
  72. package/dist/plus/git-github/api/github.js.map +1 -1
  73. package/dist/plus/git-github/models.d.ts +61 -1
  74. package/dist/plus/git-github/models.js +49 -3
  75. package/dist/plus/git-github/models.js.map +1 -1
  76. package/dist/plus/integrations/context.d.ts +12 -0
  77. package/dist/plus/integrations/fieldPresence.d.ts +16 -1
  78. package/dist/plus/integrations/fieldPresence.js +37 -10
  79. package/dist/plus/integrations/fieldPresence.js.map +1 -1
  80. package/dist/plus/integrations/integrationService.d.ts +12 -0
  81. package/dist/plus/integrations/integrationService.js +4 -0
  82. package/dist/plus/integrations/integrationService.js.map +1 -1
  83. package/dist/plus/integrations/manager.d.ts +38 -0
  84. package/dist/plus/integrations/models/gitHostIntegration.d.ts +41 -1
  85. package/dist/plus/integrations/models/gitHostIntegration.js +51 -0
  86. package/dist/plus/integrations/models/gitHostIntegration.js.map +1 -1
  87. package/dist/plus/integrations/models/integration.d.ts +23 -2
  88. package/dist/plus/integrations/models/integration.js.map +1 -1
  89. package/dist/plus/integrations/providers/github/github.js +2 -1
  90. package/dist/plus/integrations/providers/github/github.js.map +1 -1
  91. package/dist/plus/integrations/providers/github.d.ts +21 -1
  92. package/dist/plus/integrations/providers/github.js +71 -6
  93. package/dist/plus/integrations/providers/github.js.map +1 -1
  94. package/dist/plus/integrations/reads/context.d.ts +7 -0
  95. package/dist/plus/integrations/reads/drains.d.ts +1 -1
  96. package/dist/plus/integrations/reads/drains.js +2 -1
  97. package/dist/plus/integrations/reads/drains.js.map +1 -1
  98. package/dist/plus/integrations/reads/etag.js +13 -0
  99. package/dist/plus/integrations/reads/etag.js.map +1 -1
  100. package/dist/plus/integrations/reads/pullRequestBatch.d.ts +6 -2
  101. package/dist/plus/integrations/reads/pullRequestBatch.js +9 -2
  102. package/dist/plus/integrations/reads/pullRequestBatch.js.map +1 -1
  103. package/dist/plus/integrations/reads/pullRequestBranches.d.ts +2 -0
  104. package/dist/plus/integrations/reads/pullRequestBranches.js +3 -1
  105. package/dist/plus/integrations/reads/pullRequestBranches.js.map +1 -1
  106. package/dist/plus/integrations/reads/pullRequests.d.ts +2 -0
  107. package/dist/plus/integrations/reads/pullRequests.js +2 -1
  108. package/dist/plus/integrations/reads/pullRequests.js.map +1 -1
  109. package/dist/plus/integrations/reads/searchPullRequests.d.ts +2 -0
  110. package/dist/plus/integrations/reads/searchPullRequests.js +2 -1
  111. package/dist/plus/integrations/reads/searchPullRequests.js.map +1 -1
  112. package/docs/integrations.md +77 -15
  113. package/package.json +1 -1
@@ -9,6 +9,8 @@ export declare function isGitDirMovedByEnv(env: Readonly<Record<string, string |
9
9
  export declare function parseGitFile(content: string): string | undefined;
10
10
  /** The path a linked worktree's `commondir` file names, as written (absolute, or relative to its git dir) */
11
11
  export declare function parseCommonDir(content: string): string | undefined;
12
+ /** Whether a file-system call failed in a way that may pass if made again soon */
13
+ export declare function isTransientFsError(ex: unknown): boolean;
12
14
  /**
13
15
  * The git dir and common git dir `git rev-parse --git-dir --git-common-dir` reports from the working tree `repoPath`,
14
16
  * read without running git, and only when that working tree has no superproject. `undefined` whenever the layout is
@@ -27,5 +29,14 @@ export declare function readGitDirs(repoPath: string, superprojects?: PromiseCac
27
29
  gitDir: string;
28
30
  commonGitDir: string;
29
31
  } | undefined>;
32
+ /**
33
+ * As {@link readGitDirs}, but rejects when a file it reads fails in a way that may pass (a share that timed out or
34
+ * dropped, too many open files), whose answer may differ once it reads. Any other failure, a file not there or not
35
+ * readable, is the layout's own answer
36
+ */
37
+ export declare function readGitDirsOrReject(repoPath: string, superprojects?: PromiseCache<string, boolean>): Promise<{
38
+ gitDir: string;
39
+ commonGitDir: string;
40
+ } | undefined>;
30
41
  //#endregion
31
42
  //# sourceMappingURL=gitDirResolver.d.ts.map
@@ -45,6 +45,26 @@ function parseGitFile(content) {
45
45
  function parseCommonDir(content) {
46
46
  return content.replace(trailingNewlinesRegex, "") || void 0;
47
47
  }
48
+ const transientFsErrorCodes = /* @__PURE__ */ new Set([
49
+ "EAGAIN",
50
+ "EBUSY",
51
+ "ECONNRESET",
52
+ "EHOSTDOWN",
53
+ "EHOSTUNREACH",
54
+ "EINTR",
55
+ "EIO",
56
+ "EMFILE",
57
+ "ENETUNREACH",
58
+ "ENFILE",
59
+ "ENOTCONN",
60
+ "ESTALE",
61
+ "ETIMEDOUT"
62
+ ]);
63
+ /** Whether a file-system call failed in a way that may pass if made again soon */
64
+ function isTransientFsError(ex) {
65
+ const code = ex?.code;
66
+ return typeof code === "string" && transientFsErrorCodes.has(code);
67
+ }
48
68
  /**
49
69
  * The git dir and common git dir `git rev-parse --git-dir --git-common-dir` reports from the working tree `repoPath`,
50
70
  * read without running git, and only when that working tree has no superproject. `undefined` whenever the layout is
@@ -66,6 +86,19 @@ async function readGitDirs(repoPath, superprojects) {
66
86
  return;
67
87
  }
68
88
  }
89
+ /**
90
+ * As {@link readGitDirs}, but rejects when a file it reads fails in a way that may pass (a share that timed out or
91
+ * dropped, too many open files), whose answer may differ once it reads. Any other failure, a file not there or not
92
+ * readable, is the layout's own answer
93
+ */
94
+ async function readGitDirsOrReject(repoPath, superprojects) {
95
+ try {
96
+ return await readGitDirsCore(repoPath, superprojects);
97
+ } catch (ex) {
98
+ if (isTransientFsError(ex)) throw ex;
99
+ return;
100
+ }
101
+ }
69
102
  async function readGitDirsCore(repoPath, superprojects) {
70
103
  if (!isAbsolute(repoPath)) return void 0;
71
104
  const realRepoPath = await realpath(repoPath);
@@ -181,6 +214,6 @@ async function readFileIfExists(path) {
181
214
  }
182
215
  }
183
216
  //#endregion
184
- export { isGitDirMovedByEnv, parseCommonDir, parseGitFile, readGitDirs };
217
+ export { isGitDirMovedByEnv, isTransientFsError, parseCommonDir, parseGitFile, readGitDirs, readGitDirsOrReject };
185
218
 
186
219
  //# sourceMappingURL=gitDirResolver.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"gitDirResolver.js","names":[],"sources":["../../../../git-cli/src/exec/gitDirResolver.ts"],"sourcesContent":["import type { Stats } from 'node:fs';\nimport { lstat, readFile, realpath, stat } from 'node:fs/promises';\nimport { dirname, isAbsolute, join } from 'node:path';\nimport * as nodeProcess from 'node:process';\nimport { normalizePath } from '@gitlens/utils/path.js';\nimport type { PromiseCache } from '@gitlens/utils/promiseCache.js';\n\n/** Environment variables that change which repository, git dir or working tree git finds from a `cwd` */\nconst locationEnvKeys = [\n\t'GIT_DIR',\n\t'GIT_COMMON_DIR',\n\t'GIT_WORK_TREE',\n\t'GIT_CEILING_DIRECTORIES',\n\t'GIT_DISCOVERY_ACROSS_FILESYSTEM',\n];\n/** `-c` overrides, passed through the environment, that move or remove the working tree */\nconst locationConfigRegex = /core\\.(?:worktree|bare)|include/i;\n\nconst gitFilePrefix = 'gitdir: ';\nconst trailingNewlinesRegex = /[\\r\\n]+$/;\nconst newlineRegex = /[\\r\\n]/;\nconst headRegex = /^(?:ref:\\s*refs\\/|[0-9a-f]{40}(?:[0-9a-f]{24})?\\s*$)/;\n// git reads a key, or another section header, on the rest of a section header's line too (`[core] bare = true`)\nconst worktreeKeyRegex = /^(?:[ \\t]*\\[[^\\]\\r\\n]*\\])?[ \\t]*worktree[ \\t]*=/im;\nconst includeSectionRegex = /^(?:[ \\t]*\\[[^\\]\\r\\n]*\\])?[ \\t]*\\[[ \\t]*include/im;\nconst bareKeyRegex = /^(?:[ \\t]*\\[[^\\]\\r\\n]*\\])?[ \\t]*bare[ \\t]*(?:=[ \\t]*(.*?))?[ \\t\\r]*$/gim;\nconst boolTrueRegex = /^(?:true|yes|on|1)$/i;\nconst boolFalseRegex = /^(?:false|no|off|0)$/i;\n\n/**\n * Whether git run with `env` might find another git dir or working tree than {@link readGitDirs} reads: one set\n * through the environment, or through `-c` overrides passed in it\n */\nexport function isGitDirMovedByEnv(env: Readonly<Record<string, string | undefined>>): boolean {\n\tif (locationEnvKeys.some(k => env[k] != null)) return true;\n\tif (env.GIT_CONFIG_PARAMETERS != null && locationConfigRegex.test(env.GIT_CONFIG_PARAMETERS)) return true;\n\tif (env.GIT_CONFIG_COUNT == null) return false;\n\n\tconst count = Number(env.GIT_CONFIG_COUNT);\n\tif (!Number.isInteger(count)) return true;\n\n\tfor (let i = 0; i < count; i++) {\n\t\tif (locationConfigRegex.test(env[`GIT_CONFIG_KEY_${i}`] ?? '')) return true;\n\t}\n\treturn false;\n}\n\n/** The path a `.git` file names, as written (absolute, or relative to the file's folder); `undefined` when git would reject it */\nexport function parseGitFile(content: string): string | undefined {\n\tif (!content.startsWith(gitFilePrefix)) return undefined;\n\n\tconst path = content.slice(gitFilePrefix.length).replace(trailingNewlinesRegex, '');\n\treturn path && !newlineRegex.test(path) ? path : undefined;\n}\n\n/** The path a linked worktree's `commondir` file names, as written (absolute, or relative to its git dir) */\nexport function parseCommonDir(content: string): string | undefined {\n\treturn content.replace(trailingNewlinesRegex, '') || undefined;\n}\n\n/**\n * The git dir and common git dir `git rev-parse --git-dir --git-common-dir` reports from the working tree `repoPath`,\n * read without running git, and only when that working tree has no superproject. `undefined` whenever the layout is\n * one git might answer differently for: no `.git` at `repoPath` (a subfolder, a bare repository), a git dir a `.git`\n * file names without a `commondir` (a submodule, `--separate-git-dir`), a `core.bare`, `core.worktree` or `include`\n * in its config, a folder owned by another user (git's `safe.directory` check, made only where the process has a\n * uid: Windows has none, so there a folder git would refuse is still read), or a repository above it whose working\n * tree might track it as a submodule. The caller rules out the environment (see {@link isGitDirMovedByEnv}).\n * Never rejects.\n *\n * Sibling checkouts ask the same question of the same folders, so `superprojects`, when given, holds the answers by\n * parent folder. A stale one can't change the git dirs: \"no\" can only miss a superproject created since, and \"maybe\"\n * only asks git.\n */\nexport async function readGitDirs(\n\trepoPath: string,\n\tsuperprojects?: PromiseCache<string, boolean>,\n): Promise<{ gitDir: string; commonGitDir: string } | undefined> {\n\ttry {\n\t\treturn await readGitDirsCore(repoPath, superprojects);\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\nasync function readGitDirsCore(\n\trepoPath: string,\n\tsuperprojects: PromiseCache<string, boolean> | undefined,\n): Promise<{ gitDir: string; commonGitDir: string } | undefined> {\n\tif (!isAbsolute(repoPath)) return undefined;\n\n\t// git searches from the physical `cwd`, so a relative path in a `.git` file resolves against it\n\tconst realRepoPath = await realpath(repoPath);\n\tconst dotGit = join(repoPath, '.git');\n\tconst dotGitStats = await stat(dotGit);\n\n\tlet gitDir: string;\n\tlet commonGitDir: string;\n\tlet linked: boolean;\n\tif (dotGitStats.isDirectory()) {\n\t\tif ((await statIfExists(join(dotGit, 'commondir'))) != null) return undefined;\n\n\t\t// rev-parse prints `.git` relative to the `cwd`, which is how the caller's path reaches it\n\t\tgitDir = commonGitDir = dotGit;\n\t\tlinked = false;\n\t} else if (dotGitStats.isFile()) {\n\t\tconst target = parseGitFile(await readFile(dotGit, 'utf8'));\n\t\tif (target == null) return undefined;\n\n\t\tgitDir = await realpath(isAbsolute(target) ? target : `${realRepoPath}/${target}`);\n\t\tconst common = parseCommonDir(await readFile(join(gitDir, 'commondir'), 'utf8'));\n\t\tif (common == null) return undefined;\n\n\t\tcommonGitDir = await realpath(isAbsolute(common) ? common : `${gitDir}/${common}`);\n\t\t// A submodule's git dir, which its linked worktrees share, is under its superproject's `modules` folder\n\t\tif (normalizePath(gitDir).includes('/modules/') || normalizePath(commonGitDir).includes('/modules/')) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tlinked = true;\n\t} else {\n\t\treturn undefined;\n\t}\n\n\t// What makes a folder a git dir to git; without it, git keeps searching the folders above\n\tif (!headRegex.test(await readFile(join(gitDir, 'HEAD'), 'utf8'))) return undefined;\n\tif (!(await stat(join(commonGitDir, 'objects'))).isDirectory()) return undefined;\n\tif (!(await stat(join(commonGitDir, 'refs'))).isDirectory()) return undefined;\n\n\t// A linked worktree ignores a `core.bare` in the shared config (a bare repository's worktrees), not in its own\n\tif (!isPlainConfig(await readFile(join(commonGitDir, 'config'), 'utf8'), !linked)) return undefined;\n\n\tconst worktreeConfig = await readFileIfExists(join(gitDir, 'config.worktree'));\n\tif (worktreeConfig != null && !isPlainConfig(worktreeConfig, true)) return undefined;\n\n\tconst uid = nodeProcess.geteuid?.();\n\tif (uid != null) {\n\t\tconst owners = [(await stat(repoPath)).uid, (await lstat(dotGit)).uid, (await stat(gitDir)).uid];\n\t\tif (owners.some(o => o !== uid)) return undefined;\n\t}\n\n\t// A checkout at a filesystem root is its own parent folder, but asks about the folders above it, where a\n\t// checkout below it asks about the root too\n\tconst parentFolder = dirname(realRepoPath);\n\tconst mayHave =\n\t\tsuperprojects != null && parentFolder !== realRepoPath\n\t\t\t? superprojects.getOrCreate(parentFolder, () => mayHaveSuperproject(realRepoPath))\n\t\t\t: mayHaveSuperproject(realRepoPath);\n\tif (await mayHave) return undefined;\n\n\treturn { gitDir: gitDir, commonGitDir: commonGitDir };\n}\n\n/**\n * Whether a repository above `realRepoPath` could list it as a submodule. `rev-parse --show-superproject-working-tree`\n * asks the repository git finds from the parent folder; only a bare one, having no index, can't list it. Rejects when\n * a folder above can't be read.\n */\nasync function mayHaveSuperproject(realRepoPath: string): Promise<boolean> {\n\tlet folder = realRepoPath;\n\tfor (;;) {\n\t\tconst parent = dirname(folder);\n\t\tif (parent === folder) return false;\n\n\t\tfolder = parent;\n\n\t\tconst dotGit = join(folder, '.git');\n\t\tconst dotGitStats = await statIfExists(dotGit);\n\t\tif (dotGitStats?.isFile()) {\n\t\t\tconst target = parseGitFile(await readFile(dotGit, 'utf8'));\n\t\t\tif (target == null) return true;\n\n\t\t\tconst gitDir = isAbsolute(target) ? target : `${folder}/${target}`;\n\t\t\tif ((await statIfExists(join(gitDir, 'commondir'))) != null) return true;\n\n\t\t\treturn !isBareConfig(await readFile(join(gitDir, 'config'), 'utf8'));\n\t\t}\n\n\t\t// git passes over a `.git` folder, or a folder, that isn't a git dir\n\t\tif (dotGitStats?.isDirectory() && (await isGitDirectory(dotGit))) {\n\t\t\treturn !isBareConfig(await readFile(join(dotGit, 'config'), 'utf8'));\n\t\t}\n\t\tif (await isGitDirectory(folder)) return !isBareConfig(await readFile(join(folder, 'config'), 'utf8'));\n\t}\n}\n\n/** Whether a folder is a git dir: a valid `HEAD`, and the `objects` and `refs` folders (or a `commondir` to them) */\nasync function isGitDirectory(path: string): Promise<boolean> {\n\tconst head = await readFileIfExists(join(path, 'HEAD'));\n\tif (head == null || !headRegex.test(head)) return false;\n\tif ((await statIfExists(join(path, 'commondir'))) != null) return true;\n\n\treturn (\n\t\t(await statIfExists(join(path, 'objects')))?.isDirectory() === true &&\n\t\t(await statIfExists(join(path, 'refs')))?.isDirectory() === true\n\t);\n}\n\n/** Whether a config sets nothing that moves the working tree; `checkBare` also rules out a `core.bare` not plainly false */\nfunction isPlainConfig(config: string, checkBare: boolean): boolean {\n\tif (worktreeKeyRegex.test(config) || includeSectionRegex.test(config)) return false;\n\tif (!checkBare) return true;\n\n\tconst bare = getBare(config);\n\treturn bare == null || bare === false;\n}\n\n/** Whether a config is plainly a bare repository's, with no working tree set anywhere */\nfunction isBareConfig(config: string): boolean {\n\treturn !worktreeKeyRegex.test(config) && !includeSectionRegex.test(config) && getBare(config) === true;\n}\n\n/** The last `bare` value in a config: `undefined` when unset, `'unknown'` when not a plain boolean */\nfunction getBare(config: string): boolean | 'unknown' | undefined {\n\tlet bare: boolean | 'unknown' | undefined;\n\tfor (const match of config.matchAll(bareKeyRegex)) {\n\t\tconst value = match[1];\n\t\tif (value == null || boolTrueRegex.test(value)) {\n\t\t\tbare = true;\n\t\t} else if (boolFalseRegex.test(value)) {\n\t\t\tbare = false;\n\t\t} else {\n\t\t\tbare = 'unknown';\n\t\t}\n\t}\n\treturn bare;\n}\n\nasync function statIfExists(path: string): Promise<Stats | undefined> {\n\ttry {\n\t\treturn await stat(path);\n\t} catch (ex) {\n\t\tconst code = (ex as NodeJS.ErrnoException).code;\n\t\tif (code === 'ENOENT' || code === 'ENOTDIR') return undefined;\n\n\t\tthrow ex;\n\t}\n}\n\nasync function readFileIfExists(path: string): Promise<string | undefined> {\n\ttry {\n\t\treturn await readFile(path, 'utf8');\n\t} catch (ex) {\n\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W,OAAO,KAAA;EAEpD,MAAM;CACP;AACD;AAEA,eAAe,iBAAiB,MAA2C;CAC1E,IAAI;EACH,OAAO,MAAM,SAAS,MAAM,MAAM;CACnC,SAAS,IAAI;EACZ,MAAM,OAAQ,GAA6B;EAC3C,IAAI,SAAS,YAAY,SAAS,WAAW,OAAO,KAAA;EAEpD,MAAM;CACP;AACD"}
1
+ {"version":3,"file":"gitDirResolver.js","names":[],"sources":["../../../../git-cli/src/exec/gitDirResolver.ts"],"sourcesContent":["import type { Stats } from 'node:fs';\nimport { lstat, readFile, realpath, stat } from 'node:fs/promises';\nimport { dirname, isAbsolute, join } from 'node:path';\nimport * as nodeProcess from 'node:process';\nimport { normalizePath } from '@gitlens/utils/path.js';\nimport type { PromiseCache } from '@gitlens/utils/promiseCache.js';\n\n/** Environment variables that change which repository, git dir or working tree git finds from a `cwd` */\nconst locationEnvKeys = [\n\t'GIT_DIR',\n\t'GIT_COMMON_DIR',\n\t'GIT_WORK_TREE',\n\t'GIT_CEILING_DIRECTORIES',\n\t'GIT_DISCOVERY_ACROSS_FILESYSTEM',\n];\n/** `-c` overrides, passed through the environment, that move or remove the working tree */\nconst locationConfigRegex = /core\\.(?:worktree|bare)|include/i;\n\nconst gitFilePrefix = 'gitdir: ';\nconst trailingNewlinesRegex = /[\\r\\n]+$/;\nconst newlineRegex = /[\\r\\n]/;\nconst headRegex = /^(?:ref:\\s*refs\\/|[0-9a-f]{40}(?:[0-9a-f]{24})?\\s*$)/;\n// git reads a key, or another section header, on the rest of a section header's line too (`[core] bare = true`)\nconst worktreeKeyRegex = /^(?:[ \\t]*\\[[^\\]\\r\\n]*\\])?[ \\t]*worktree[ \\t]*=/im;\nconst includeSectionRegex = /^(?:[ \\t]*\\[[^\\]\\r\\n]*\\])?[ \\t]*\\[[ \\t]*include/im;\nconst bareKeyRegex = /^(?:[ \\t]*\\[[^\\]\\r\\n]*\\])?[ \\t]*bare[ \\t]*(?:=[ \\t]*(.*?))?[ \\t\\r]*$/gim;\nconst boolTrueRegex = /^(?:true|yes|on|1)$/i;\nconst boolFalseRegex = /^(?:false|no|off|0)$/i;\n\n/**\n * Whether git run with `env` might find another git dir or working tree than {@link readGitDirs} reads: one set\n * through the environment, or through `-c` overrides passed in it\n */\nexport function isGitDirMovedByEnv(env: Readonly<Record<string, string | undefined>>): boolean {\n\tif (locationEnvKeys.some(k => env[k] != null)) return true;\n\tif (env.GIT_CONFIG_PARAMETERS != null && locationConfigRegex.test(env.GIT_CONFIG_PARAMETERS)) return true;\n\tif (env.GIT_CONFIG_COUNT == null) return false;\n\n\tconst count = Number(env.GIT_CONFIG_COUNT);\n\tif (!Number.isInteger(count)) return true;\n\n\tfor (let i = 0; i < count; i++) {\n\t\tif (locationConfigRegex.test(env[`GIT_CONFIG_KEY_${i}`] ?? '')) return true;\n\t}\n\treturn false;\n}\n\n/** The path a `.git` file names, as written (absolute, or relative to the file's folder); `undefined` when git would reject it */\nexport function parseGitFile(content: string): string | undefined {\n\tif (!content.startsWith(gitFilePrefix)) return undefined;\n\n\tconst path = content.slice(gitFilePrefix.length).replace(trailingNewlinesRegex, '');\n\treturn path && !newlineRegex.test(path) ? path : undefined;\n}\n\n/** The path a linked worktree's `commondir` file names, as written (absolute, or relative to its git dir) */\nexport function parseCommonDir(content: string): string | undefined {\n\treturn content.replace(trailingNewlinesRegex, '') || undefined;\n}\n\nconst transientFsErrorCodes: ReadonlySet<string> = new Set([\n\t'EAGAIN',\n\t'EBUSY',\n\t'ECONNRESET',\n\t'EHOSTDOWN',\n\t'EHOSTUNREACH',\n\t'EINTR',\n\t'EIO',\n\t'EMFILE',\n\t'ENETUNREACH',\n\t'ENFILE',\n\t// A FUSE mount (sshfs, rclone) whose connection dropped\n\t'ENOTCONN',\n\t'ESTALE',\n\t'ETIMEDOUT',\n]);\n\n/** Whether a file-system call failed in a way that may pass if made again soon */\nexport function isTransientFsError(ex: unknown): boolean {\n\tconst code = (ex as { code?: unknown } | undefined)?.code;\n\treturn typeof code === 'string' && transientFsErrorCodes.has(code);\n}\n\n/**\n * The git dir and common git dir `git rev-parse --git-dir --git-common-dir` reports from the working tree `repoPath`,\n * read without running git, and only when that working tree has no superproject. `undefined` whenever the layout is\n * one git might answer differently for: no `.git` at `repoPath` (a subfolder, a bare repository), a git dir a `.git`\n * file names without a `commondir` (a submodule, `--separate-git-dir`), a `core.bare`, `core.worktree` or `include`\n * in its config, a folder owned by another user (git's `safe.directory` check, made only where the process has a\n * uid: Windows has none, so there a folder git would refuse is still read), or a repository above it whose working\n * tree might track it as a submodule. The caller rules out the environment (see {@link isGitDirMovedByEnv}).\n * Never rejects.\n *\n * Sibling checkouts ask the same question of the same folders, so `superprojects`, when given, holds the answers by\n * parent folder. A stale one can't change the git dirs: \"no\" can only miss a superproject created since, and \"maybe\"\n * only asks git.\n */\nexport async function readGitDirs(\n\trepoPath: string,\n\tsuperprojects?: PromiseCache<string, boolean>,\n): Promise<{ gitDir: string; commonGitDir: string } | undefined> {\n\ttry {\n\t\treturn await readGitDirsCore(repoPath, superprojects);\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\n/**\n * As {@link readGitDirs}, but rejects when a file it reads fails in a way that may pass (a share that timed out or\n * dropped, too many open files), whose answer may differ once it reads. Any other failure, a file not there or not\n * readable, is the layout's own answer\n */\nexport async function readGitDirsOrReject(\n\trepoPath: string,\n\tsuperprojects?: PromiseCache<string, boolean>,\n): Promise<{ gitDir: string; commonGitDir: string } | undefined> {\n\ttry {\n\t\treturn await readGitDirsCore(repoPath, superprojects);\n\t} catch (ex) {\n\t\tif (isTransientFsError(ex)) throw ex;\n\n\t\treturn undefined;\n\t}\n}\n\nasync function readGitDirsCore(\n\trepoPath: string,\n\tsuperprojects: PromiseCache<string, boolean> | undefined,\n): Promise<{ gitDir: string; commonGitDir: string } | undefined> {\n\tif (!isAbsolute(repoPath)) return undefined;\n\n\t// git searches from the physical `cwd`, so a relative path in a `.git` file resolves against it\n\tconst realRepoPath = await realpath(repoPath);\n\tconst dotGit = join(repoPath, '.git');\n\tconst dotGitStats = await stat(dotGit);\n\n\tlet gitDir: string;\n\tlet commonGitDir: string;\n\tlet linked: boolean;\n\tif (dotGitStats.isDirectory()) {\n\t\tif ((await statIfExists(join(dotGit, 'commondir'))) != null) return undefined;\n\n\t\t// rev-parse prints `.git` relative to the `cwd`, which is how the caller's path reaches it\n\t\tgitDir = commonGitDir = dotGit;\n\t\tlinked = false;\n\t} else if (dotGitStats.isFile()) {\n\t\tconst target = parseGitFile(await readFile(dotGit, 'utf8'));\n\t\tif (target == null) return undefined;\n\n\t\tgitDir = await realpath(isAbsolute(target) ? target : `${realRepoPath}/${target}`);\n\t\tconst common = parseCommonDir(await readFile(join(gitDir, 'commondir'), 'utf8'));\n\t\tif (common == null) return undefined;\n\n\t\tcommonGitDir = await realpath(isAbsolute(common) ? common : `${gitDir}/${common}`);\n\t\t// A submodule's git dir, which its linked worktrees share, is under its superproject's `modules` folder\n\t\tif (normalizePath(gitDir).includes('/modules/') || normalizePath(commonGitDir).includes('/modules/')) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tlinked = true;\n\t} else {\n\t\treturn undefined;\n\t}\n\n\t// What makes a folder a git dir to git; without it, git keeps searching the folders above\n\tif (!headRegex.test(await readFile(join(gitDir, 'HEAD'), 'utf8'))) return undefined;\n\tif (!(await stat(join(commonGitDir, 'objects'))).isDirectory()) return undefined;\n\tif (!(await stat(join(commonGitDir, 'refs'))).isDirectory()) return undefined;\n\n\t// A linked worktree ignores a `core.bare` in the shared config (a bare repository's worktrees), not in its own\n\tif (!isPlainConfig(await readFile(join(commonGitDir, 'config'), 'utf8'), !linked)) return undefined;\n\n\tconst worktreeConfig = await readFileIfExists(join(gitDir, 'config.worktree'));\n\tif (worktreeConfig != null && !isPlainConfig(worktreeConfig, true)) return undefined;\n\n\tconst uid = nodeProcess.geteuid?.();\n\tif (uid != null) {\n\t\tconst owners = [(await stat(repoPath)).uid, (await lstat(dotGit)).uid, (await stat(gitDir)).uid];\n\t\tif (owners.some(o => o !== uid)) return undefined;\n\t}\n\n\t// A checkout at a filesystem root is its own parent folder, but asks about the folders above it, where a\n\t// checkout below it asks about the root too\n\tconst parentFolder = dirname(realRepoPath);\n\tconst mayHave =\n\t\tsuperprojects != null && parentFolder !== realRepoPath\n\t\t\t? superprojects.getOrCreate(parentFolder, () => mayHaveSuperproject(realRepoPath))\n\t\t\t: mayHaveSuperproject(realRepoPath);\n\tif (await mayHave) return undefined;\n\n\treturn { gitDir: gitDir, commonGitDir: commonGitDir };\n}\n\n/**\n * Whether a repository above `realRepoPath` could list it as a submodule. `rev-parse --show-superproject-working-tree`\n * asks the repository git finds from the parent folder; only a bare one, having no index, can't list it. Rejects when\n * a folder above can't be read.\n */\nasync function mayHaveSuperproject(realRepoPath: string): Promise<boolean> {\n\tlet folder = realRepoPath;\n\tfor (;;) {\n\t\tconst parent = dirname(folder);\n\t\tif (parent === folder) return false;\n\n\t\tfolder = parent;\n\n\t\tconst dotGit = join(folder, '.git');\n\t\tconst dotGitStats = await statIfExists(dotGit);\n\t\tif (dotGitStats?.isFile()) {\n\t\t\tconst target = parseGitFile(await readFile(dotGit, 'utf8'));\n\t\t\tif (target == null) return true;\n\n\t\t\tconst gitDir = isAbsolute(target) ? target : `${folder}/${target}`;\n\t\t\tif ((await statIfExists(join(gitDir, 'commondir'))) != null) return true;\n\n\t\t\treturn !isBareConfig(await readFile(join(gitDir, 'config'), 'utf8'));\n\t\t}\n\n\t\t// git passes over a `.git` folder, or a folder, that isn't a git dir\n\t\tif (dotGitStats?.isDirectory() && (await isGitDirectory(dotGit))) {\n\t\t\treturn !isBareConfig(await readFile(join(dotGit, 'config'), 'utf8'));\n\t\t}\n\t\tif (await isGitDirectory(folder)) return !isBareConfig(await readFile(join(folder, 'config'), 'utf8'));\n\t}\n}\n\n/** Whether a folder is a git dir: a valid `HEAD`, and the `objects` and `refs` folders (or a `commondir` to them) */\nasync function isGitDirectory(path: string): Promise<boolean> {\n\tconst head = await readFileIfExists(join(path, 'HEAD'));\n\tif (head == null || !headRegex.test(head)) return false;\n\tif ((await statIfExists(join(path, 'commondir'))) != null) return true;\n\n\treturn (\n\t\t(await statIfExists(join(path, 'objects')))?.isDirectory() === true &&\n\t\t(await statIfExists(join(path, 'refs')))?.isDirectory() === true\n\t);\n}\n\n/** Whether a config sets nothing that moves the working tree; `checkBare` also rules out a `core.bare` not plainly false */\nfunction isPlainConfig(config: string, checkBare: boolean): boolean {\n\tif (worktreeKeyRegex.test(config) || includeSectionRegex.test(config)) return false;\n\tif (!checkBare) return true;\n\n\tconst bare = getBare(config);\n\treturn bare == null || bare === false;\n}\n\n/** Whether a config is plainly a bare repository's, with no working tree set anywhere */\nfunction isBareConfig(config: string): boolean {\n\treturn !worktreeKeyRegex.test(config) && !includeSectionRegex.test(config) && getBare(config) === true;\n}\n\n/** The last `bare` value in a config: `undefined` when unset, `'unknown'` when not a plain boolean */\nfunction getBare(config: string): boolean | 'unknown' | undefined {\n\tlet bare: boolean | 'unknown' | undefined;\n\tfor (const match of config.matchAll(bareKeyRegex)) {\n\t\tconst value = match[1];\n\t\tif (value == null || boolTrueRegex.test(value)) {\n\t\t\tbare = true;\n\t\t} else if (boolFalseRegex.test(value)) {\n\t\t\tbare = false;\n\t\t} else {\n\t\t\tbare = 'unknown';\n\t\t}\n\t}\n\treturn bare;\n}\n\nasync function statIfExists(path: string): Promise<Stats | undefined> {\n\ttry {\n\t\treturn await stat(path);\n\t} catch (ex) {\n\t\tconst code = (ex as NodeJS.ErrnoException).code;\n\t\tif (code === 'ENOENT' || code === 'ENOTDIR') return undefined;\n\n\t\tthrow ex;\n\t}\n}\n\nasync function readFileIfExists(path: string): Promise<string | undefined> {\n\ttry {\n\t\treturn await readFile(path, 'utf8');\n\t} catch (ex) {\n\t\tconst code = (ex as NodeJS.ErrnoException).code;\n\t\tif (code === 'ENOENT' || code === 'ENOTDIR') return undefined;\n\n\t\tthrow ex;\n\t}\n}\n"],"mappings":";;;;;;AAQA,MAAM,kBAAkB;CACvB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AAK,GAC5C,OAAO;OACD,IAAI,eAAe,KAAK,KAAK,GACnC,OAAO;OAEP,OAAO;CAET;CACA,OAAO;AACR;AAEA,eAAe,aAAa,MAA0C;CACrE,IAAI;EACH,OAAO,MAAM,KAAK,IAAI;CACvB,SAAS,IAAI;EACZ,MAAM,OAAQ,GAA6B;EAC3C,IAAI,SAAS,YAAY,SAAS,WAAW,OAAO,KAAA;EAEpD,MAAM;CACP;AACD;AAEA,eAAe,iBAAiB,MAA2C;CAC1E,IAAI;EACH,OAAO,MAAM,SAAS,MAAM,MAAM;CACnC,SAAS,IAAI;EACZ,MAAM,OAAQ,GAA6B;EAC3C,IAAI,SAAS,YAAY,SAAS,WAAW,OAAO,KAAA;EAEpD,MAAM;CACP;AACD"}
@@ -1,3 +1,4 @@
1
+ import { scanLeadingOptions } from "./commandClassifier.js";
1
2
  //#region ../git-cli/src/exec/gitQueue.ts
2
3
  /** Priority levels in descending order (highest first) */
3
4
  const priorities = [
@@ -177,36 +178,9 @@ var GitQueue = class {
177
178
  };
178
179
  }
179
180
  };
180
- /**
181
- * Git global options that consume the next positional arg as their value
182
- * (e.g. `--work-tree <path>`). Long-form `--name=value` is already skipped by
183
- * the leading-dash check, so only the separated form needs explicit handling.
184
- */
185
- const optionsTakingValue = /* @__PURE__ */ new Set([
186
- "-c",
187
- "-C",
188
- "--git-dir",
189
- "--work-tree",
190
- "--namespace",
191
- "--exec-path",
192
- "--super-prefix",
193
- "--config-env",
194
- "--attr-source",
195
- "--list-cmds"
196
- ]);
197
181
  /** Extracts the primary git subcommand from an arg list, skipping global options and their values. */
198
182
  function getPrimaryGitCommand(args) {
199
- for (let i = 0; i < args.length; i++) {
200
- const a = args[i];
201
- if (a == null) continue;
202
- if (optionsTakingValue.has(a)) {
203
- const next = args[i + 1];
204
- if (next != null && !next.startsWith("-")) i++;
205
- continue;
206
- }
207
- if (a.startsWith("-")) continue;
208
- return a;
209
- }
183
+ return args[scanLeadingOptions(void 0, args, true).verbIndex];
210
184
  }
211
185
  /**
212
186
  * Infers a queue priority from the git command being invoked.
@@ -1 +1 @@
1
- {"version":3,"file":"gitQueue.js","names":[],"sources":["../../../../git-cli/src/exec/gitQueue.ts"],"sourcesContent":["import type { GitCommandPriority } from './exec.types.js';\n\ninterface QueuedCommand {\n\trun: () => Promise<unknown>;\n\tresolve: (value: unknown) => void;\n\treject: (reason: unknown) => void;\n\tqueuedAt: number;\n\tpriority: GitCommandPriority;\n\tsignal?: AbortSignal;\n\tabortHandler?: () => void;\n}\n\n/** Priority levels in descending order (highest first) */\nconst priorities: GitCommandPriority[] = ['interactive', 'normal', 'background'];\n\n/** How many extra slots interactive commands can use when at capacity */\nconst interactiveBurstCapacity = 2;\n\n/** What a queued run rejects with for an aborted signal; other waits on a run reject the same way */\nexport function abortReason(signal: AbortSignal): Error {\n\treturn signal.reason instanceof Error ? signal.reason : new Error('Aborted');\n}\n\nexport interface GitQueueConfig {\n\t/**\n\t * Maximum number of concurrent git processes. Defaults to 20, the default of GitLens'\n\t * `advanced.git.maxConcurrentProcesses`.\n\t */\n\tmaxConcurrent?: number;\n\t/** Maximum number of queued commands per priority level. Defaults to 500. Set to 0 to disable. */\n\tmaxQueueDepth?: number;\n}\n\nexport interface GitQueueHooks {\n\t/** Called when a queued command waited longer than 1 second before executing */\n\tonSlowQueue?(info: {\n\t\tpriority: GitCommandPriority;\n\t\twaitTime: number;\n\t\tactive: number;\n\t\tqueued: Record<GitCommandPriority, number>;\n\t\tmaxConcurrent: number;\n\t}): void;\n}\n\n/**\n * Priority-based concurrent queue for git command execution.\n *\n * Implements a multi-level feedback queue with:\n * - Configurable max concurrent processes\n * - Strict priority ordering (interactive > normal > background)\n * - Burst capacity for interactive commands under pressure\n *\n * Capacity rules (with limit N, burst B=2):\n * - All priorities share N slots normally\n * - When at capacity, interactive can burst up to N+B total\n *\n * Scheduling rules:\n * - Higher priority preempts: if interactive is waiting, normal/background queue\n * - Lower priority yields: background won't run if normal is waiting\n */\nexport class GitQueue {\n\tprivate readonly _queues = new Map<GitCommandPriority, QueuedCommand[]>([\n\t\t['interactive', []],\n\t\t['normal', []],\n\t\t['background', []],\n\t]);\n\n\tprivate _activeCount = 0;\n\tprivate _disposed = false;\n\n\tconstructor(\n\t\tprivate readonly _config: GitQueueConfig = {},\n\t\tprivate readonly _hooks: GitQueueHooks = {},\n\t) {}\n\n\tdispose(): void {\n\t\tthis._disposed = true;\n\t\tfor (const queue of this._queues.values()) {\n\t\t\tfor (const cmd of queue) {\n\t\t\t\tif (cmd.signal != null && cmd.abortHandler != null) {\n\t\t\t\t\tcmd.signal.removeEventListener('abort', cmd.abortHandler);\n\t\t\t\t}\n\t\t\t\tcmd.reject(new Error('GitQueue disposed'));\n\t\t\t}\n\t\t\tqueue.length = 0;\n\t\t}\n\t}\n\n\t/** Get the configured max concurrent processes */\n\tprivate get maxConcurrent(): number {\n\t\treturn this._config.maxConcurrent ?? 20;\n\t}\n\n\t/** Update configuration (e.g., when user changes settings) */\n\tupdateConfig(config: Partial<GitQueueConfig>): void {\n\t\tif (config.maxConcurrent != null && config.maxConcurrent > 0) {\n\t\t\tthis._config.maxConcurrent = config.maxConcurrent;\n\t\t}\n\t\tif (config.maxQueueDepth != null && config.maxQueueDepth > 0) {\n\t\t\tthis._config.maxQueueDepth = config.maxQueueDepth;\n\t\t}\n\t}\n\n\t/** Check if a command at the given priority can execute immediately */\n\tprivate canRunNow(priority: GitCommandPriority): boolean {\n\t\t// Must yield to higher priority waiting\n\t\tif (this.hasHigherPriorityWaiting(priority)) return false;\n\n\t\tconst max = this.maxConcurrent;\n\n\t\t// Under normal limit - all priorities can run\n\t\tif (this._activeCount < max) return true;\n\n\t\t// At or over normal limit - only interactive can burst\n\t\tif (priority === 'interactive' && this._activeCount < max + interactiveBurstCapacity) {\n\t\t\treturn true;\n\t\t}\n\n\t\treturn false;\n\t}\n\n\t/** Check if any higher-priority commands are waiting */\n\tprivate hasHigherPriorityWaiting(priority: GitCommandPriority): boolean {\n\t\tfor (const p of priorities) {\n\t\t\tif (p === priority) return false;\n\t\t\tif (this._queues.get(p)!.length > 0) return true;\n\t\t}\n\t\treturn false;\n\t}\n\n\t/**\n\t * Execute a git command with the specified priority.\n\t *\n\t * When `signal` is provided:\n\t * - If already aborted, rejects immediately without running.\n\t * - If aborted while queued, the command is removed from the queue and rejected before it ever runs.\n\t * - If aborted while running, the in-flight spawn must honor the same signal separately\n\t * (callers pass it via `runOpts.cancellation`); the queue does not interrupt running work.\n\t */\n\trun<T>(priority: GitCommandPriority, fn: () => Promise<T>, signal?: AbortSignal): Promise<T> {\n\t\tif (this._disposed) {\n\t\t\treturn Promise.reject(new Error('GitQueue disposed'));\n\t\t}\n\n\t\tif (signal?.aborted) {\n\t\t\treturn Promise.reject(abortReason(signal));\n\t\t}\n\n\t\tif (!this.canRunNow(priority)) {\n\t\t\treturn this.enqueue(fn, priority, signal);\n\t\t}\n\n\t\treturn this.runcore(fn);\n\t}\n\n\tprivate async runcore<T>(fn: () => Promise<T>): Promise<T> {\n\t\tthis._activeCount++;\n\t\ttry {\n\t\t\treturn await fn();\n\t\t} finally {\n\t\t\tthis._activeCount--;\n\t\t\tthis.processQueues();\n\t\t}\n\t}\n\n\tprivate enqueue<T>(fn: () => Promise<T>, priority: GitCommandPriority, signal?: AbortSignal): Promise<T> {\n\t\tconst queue = this._queues.get(priority)!;\n\t\tconst maxDepth = this._config.maxQueueDepth ?? 500;\n\t\tif (maxDepth > 0 && queue.length >= maxDepth) {\n\t\t\treturn Promise.reject(new Error(`GitQueue '${priority}' queue is full (${maxDepth} commands pending)`));\n\t\t}\n\n\t\treturn new Promise<T>((resolve, reject) => {\n\t\t\tconst cmd: QueuedCommand = {\n\t\t\t\trun: fn,\n\t\t\t\tresolve: resolve as (value: unknown) => void,\n\t\t\t\treject: reject,\n\t\t\t\tqueuedAt: Date.now(),\n\t\t\t\tpriority: priority,\n\t\t\t\tsignal: signal,\n\t\t\t};\n\n\t\t\tif (signal != null) {\n\t\t\t\tcmd.abortHandler = () => {\n\t\t\t\t\tconst idx = queue.indexOf(cmd);\n\t\t\t\t\t// If still queued, remove and reject so it never runs.\n\t\t\t\t\t// If already dequeued, the running command should honor the signal at its own layer.\n\t\t\t\t\tif (idx !== -1) {\n\t\t\t\t\t\tqueue.splice(idx, 1);\n\t\t\t\t\t\tcmd.reject(abortReason(signal));\n\t\t\t\t\t}\n\t\t\t\t};\n\t\t\t\tsignal.addEventListener('abort', cmd.abortHandler, { once: true });\n\t\t\t}\n\n\t\t\tqueue.push(cmd);\n\t\t});\n\t}\n\n\tprivate processQueues(): void {\n\t\tif (this._disposed) return;\n\n\t\tconst max = this.maxConcurrent;\n\n\t\tfor (const priority of priorities) {\n\t\t\tconst queue = this._queues.get(priority)!;\n\t\t\tconst limit = priority === 'interactive' ? max + interactiveBurstCapacity : max;\n\n\t\t\twhile (queue.length > 0 && this._activeCount < limit && !this.hasHigherPriorityWaiting(priority)) {\n\t\t\t\tthis.runQueued(queue.shift()!);\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate runQueued(cmd: QueuedCommand): void {\n\t\t// Detach the abort listener now that the command has left the queue — any subsequent\n\t\t// abort must be handled by the running spawn itself (via runOpts.cancellation).\n\t\tif (cmd.signal != null && cmd.abortHandler != null) {\n\t\t\tcmd.signal.removeEventListener('abort', cmd.abortHandler);\n\t\t\tcmd.abortHandler = undefined;\n\t\t}\n\n\t\tconst waitTime = Date.now() - cmd.queuedAt;\n\t\tif (waitTime > 1000) {\n\t\t\tthis._hooks.onSlowQueue?.({\n\t\t\t\tpriority: cmd.priority,\n\t\t\t\twaitTime: waitTime,\n\t\t\t\tactive: this._activeCount,\n\t\t\t\tqueued: {\n\t\t\t\t\tinteractive: this._queues.get('interactive')!.length,\n\t\t\t\t\tnormal: this._queues.get('normal')!.length,\n\t\t\t\t\tbackground: this._queues.get('background')!.length,\n\t\t\t\t},\n\t\t\t\tmaxConcurrent: this.maxConcurrent,\n\t\t\t});\n\t\t}\n\n\t\tthis._activeCount++;\n\t\ttry {\n\t\t\tcmd.run()\n\t\t\t\t.then(cmd.resolve, cmd.reject)\n\t\t\t\t.finally(() => {\n\t\t\t\t\tthis._activeCount--;\n\t\t\t\t\tthis.processQueues();\n\t\t\t\t});\n\t\t} catch (ex) {\n\t\t\tthis._activeCount--;\n\t\t\tcmd.reject(ex);\n\t\t\tthis.processQueues();\n\t\t}\n\t}\n\n\t/** Returns current queue statistics for diagnostics */\n\tgetStats(): { active: number; queued: Record<GitCommandPriority, number>; maxConcurrent: number } {\n\t\treturn {\n\t\t\tactive: this._activeCount,\n\t\t\tqueued: {\n\t\t\t\tinteractive: this._queues.get('interactive')!.length,\n\t\t\t\tnormal: this._queues.get('normal')!.length,\n\t\t\t\tbackground: this._queues.get('background')!.length,\n\t\t\t},\n\t\t\tmaxConcurrent: this.maxConcurrent,\n\t\t};\n\t}\n}\n\n/**\n * Git global options that consume the next positional arg as their value\n * (e.g. `--work-tree <path>`). Long-form `--name=value` is already skipped by\n * the leading-dash check, so only the separated form needs explicit handling.\n */\nconst optionsTakingValue = new Set([\n\t'-c',\n\t'-C',\n\t'--git-dir',\n\t'--work-tree',\n\t'--namespace',\n\t'--exec-path',\n\t'--super-prefix',\n\t'--config-env',\n\t'--attr-source',\n\t'--list-cmds',\n]);\n\n/** Extracts the primary git subcommand from an arg list, skipping global options and their values. */\nexport function getPrimaryGitCommand(args: readonly (string | undefined)[]): string | undefined {\n\tfor (let i = 0; i < args.length; i++) {\n\t\tconst a = args[i];\n\t\tif (a == null) continue;\n\t\tif (optionsTakingValue.has(a)) {\n\t\t\tconst next = args[i + 1];\n\t\t\tif (next != null && !next.startsWith('-')) {\n\t\t\t\ti++;\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\t\tif (a.startsWith('-')) continue;\n\n\t\treturn a;\n\t}\n\treturn undefined;\n}\n\n/**\n * Infers a queue priority from the git command being invoked.\n *\n * Intentionally narrow: only returns 'background' for commands that are\n * *always* read-only AND *always* potentially expensive. Polymorphic commands\n * like `log` and `rev-list` (which can be quick bounded lookups or full-history\n * walks) are deliberately omitted — call sites that perform heavy walks must\n * pass `priority: 'background'` explicitly. Never upgrades to 'interactive'.\n *\n * No subcommand awareness (e.g. `stash list`, `branch -l`): the risk of\n * misclassifying a write subcommand as background outweighs the gain.\n */\nexport function inferGitCommandPriority(args: readonly (string | undefined)[]): GitCommandPriority {\n\tswitch (getPrimaryGitCommand(args)) {\n\t\tcase 'for-each-ref':\n\t\tcase 'shortlog':\n\t\tcase 'reflog':\n\t\tcase 'name-rev':\n\t\tcase 'describe':\n\t\tcase 'cherry':\n\t\tcase 'count-objects':\n\t\tcase 'fsck':\n\t\t\treturn 'background';\n\t\tdefault:\n\t\t\treturn 'normal';\n\t}\n}\n"],"mappings":";;AAaA,MAAM,aAAmC;CAAC;CAAe;CAAU;AAAY;;AAG/E,MAAM,2BAA2B;;AAGjC,SAAgB,YAAY,QAA4B;CACvD,OAAO,OAAO,kBAAkB,QAAQ,OAAO,yBAAS,IAAI,MAAM,SAAS;AAC5E;;;;;;;;;;;;;;;;;AAuCA,IAAa,WAAb,MAAsB;CAWH;CACA;CAXlB,0BAA2B,IAAI,IAAyC;EACvE,CAAC,eAAe,CAAC,CAAC;EAClB,CAAC,UAAU,CAAC,CAAC;EACb,CAAC,cAAc,CAAC,CAAC;CAClB,CAAC;CAED,eAAuB;CACvB,YAAoB;CAEpB,YACC,UAA2C,CAAC,GAC5C,SAAyC,CAAC,GACzC;EAFgB,KAAA,UAAA;EACA,KAAA,SAAA;CACf;CAEH,UAAgB;EACf,KAAK,YAAY;EACjB,KAAK,MAAM,SAAS,KAAK,QAAQ,OAAO,GAAG;GAC1C,KAAK,MAAM,OAAO,OAAO;IACxB,IAAI,IAAI,UAAU,QAAQ,IAAI,gBAAgB,MAC7C,IAAI,OAAO,oBAAoB,SAAS,IAAI,YAAY;IAEzD,IAAI,uBAAO,IAAI,MAAM,mBAAmB,CAAC;GAC1C;GACA,MAAM,SAAS;EAChB;CACD;;CAGA,IAAY,gBAA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;EACrB,CAAC;EAGF,KAAK;EACL,IAAI;GACH,IAAI,IAAI,CAAC,CACP,KAAK,IAAI,SAAS,IAAI,MAAM,CAAC,CAC7B,cAAc;IACd,KAAK;IACL,KAAK,cAAc;GACpB,CAAC;EACH,SAAS,IAAI;GACZ,KAAK;GACL,IAAI,OAAO,EAAE;GACb,KAAK,cAAc;EACpB;CACD;;CAGA,WAAkG;EACjG,OAAO;GACN,QAAQ,KAAK;GACb,QAAQ;IACP,aAAa,KAAK,QAAQ,IAAI,aAAa,CAAC,CAAE;IAC9C,QAAQ,KAAK,QAAQ,IAAI,QAAQ,CAAC,CAAE;IACpC,YAAY,KAAK,QAAQ,IAAI,YAAY,CAAC,CAAE;GAC7C;GACA,eAAe,KAAK;EACrB;CACD;AACD;;;;;;AAOA,MAAM,qCAAqB,IAAI,IAAI;CAClC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACD,CAAC;;AAGD,SAAgB,qBAAqB,MAA2D;CAC/F,KAAK,IAAI,IAAI,GAAG,IAAI,KAAK,QAAQ,KAAK;EACrC,MAAM,IAAI,KAAK;EACf,IAAI,KAAK,MAAM;EACf,IAAI,mBAAmB,IAAI,CAAC,GAAG;GAC9B,MAAM,OAAO,KAAK,IAAI;GACtB,IAAI,QAAQ,QAAQ,CAAC,KAAK,WAAW,GAAG,GACvC;GAED;EACD;EACA,IAAI,EAAE,WAAW,GAAG,GAAG;EAEvB,OAAO;CACR;AAED;;;;;;;;;;;;;AAcA,SAAgB,wBAAwB,MAA2D;CAClG,QAAQ,qBAAqB,IAAI,GAAjC;EACC,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK,QACJ,OAAO;EACR,SACC,OAAO;CACT;AACD"}
1
+ {"version":3,"file":"gitQueue.js","names":[],"sources":["../../../../git-cli/src/exec/gitQueue.ts"],"sourcesContent":["import { scanLeadingOptions } from './commandClassifier.js';\nimport type { GitCommandPriority } from './exec.types.js';\n\ninterface QueuedCommand {\n\trun: () => Promise<unknown>;\n\tresolve: (value: unknown) => void;\n\treject: (reason: unknown) => void;\n\tqueuedAt: number;\n\tpriority: GitCommandPriority;\n\tsignal?: AbortSignal;\n\tabortHandler?: () => void;\n}\n\n/** Priority levels in descending order (highest first) */\nconst priorities: GitCommandPriority[] = ['interactive', 'normal', 'background'];\n\n/** How many extra slots interactive commands can use when at capacity */\nconst interactiveBurstCapacity = 2;\n\n/** What a queued run rejects with for an aborted signal; other waits on a run reject the same way */\nexport function abortReason(signal: AbortSignal): Error {\n\treturn signal.reason instanceof Error ? signal.reason : new Error('Aborted');\n}\n\nexport interface GitQueueConfig {\n\t/**\n\t * Maximum number of concurrent git processes. Defaults to 20, the default of GitLens'\n\t * `advanced.git.maxConcurrentProcesses`.\n\t */\n\tmaxConcurrent?: number;\n\t/** Maximum number of queued commands per priority level. Defaults to 500. Set to 0 to disable. */\n\tmaxQueueDepth?: number;\n}\n\nexport interface GitQueueHooks {\n\t/** Called when a queued command waited longer than 1 second before executing */\n\tonSlowQueue?(info: {\n\t\tpriority: GitCommandPriority;\n\t\twaitTime: number;\n\t\tactive: number;\n\t\tqueued: Record<GitCommandPriority, number>;\n\t\tmaxConcurrent: number;\n\t}): void;\n}\n\n/**\n * Priority-based concurrent queue for git command execution.\n *\n * Implements a multi-level feedback queue with:\n * - Configurable max concurrent processes\n * - Strict priority ordering (interactive > normal > background)\n * - Burst capacity for interactive commands under pressure\n *\n * Capacity rules (with limit N, burst B=2):\n * - All priorities share N slots normally\n * - When at capacity, interactive can burst up to N+B total\n *\n * Scheduling rules:\n * - Higher priority preempts: if interactive is waiting, normal/background queue\n * - Lower priority yields: background won't run if normal is waiting\n */\nexport class GitQueue {\n\tprivate readonly _queues = new Map<GitCommandPriority, QueuedCommand[]>([\n\t\t['interactive', []],\n\t\t['normal', []],\n\t\t['background', []],\n\t]);\n\n\tprivate _activeCount = 0;\n\tprivate _disposed = false;\n\n\tconstructor(\n\t\tprivate readonly _config: GitQueueConfig = {},\n\t\tprivate readonly _hooks: GitQueueHooks = {},\n\t) {}\n\n\tdispose(): void {\n\t\tthis._disposed = true;\n\t\tfor (const queue of this._queues.values()) {\n\t\t\tfor (const cmd of queue) {\n\t\t\t\tif (cmd.signal != null && cmd.abortHandler != null) {\n\t\t\t\t\tcmd.signal.removeEventListener('abort', cmd.abortHandler);\n\t\t\t\t}\n\t\t\t\tcmd.reject(new Error('GitQueue disposed'));\n\t\t\t}\n\t\t\tqueue.length = 0;\n\t\t}\n\t}\n\n\t/** Get the configured max concurrent processes */\n\tprivate get maxConcurrent(): number {\n\t\treturn this._config.maxConcurrent ?? 20;\n\t}\n\n\t/** Update configuration (e.g., when user changes settings) */\n\tupdateConfig(config: Partial<GitQueueConfig>): void {\n\t\tif (config.maxConcurrent != null && config.maxConcurrent > 0) {\n\t\t\tthis._config.maxConcurrent = config.maxConcurrent;\n\t\t}\n\t\tif (config.maxQueueDepth != null && config.maxQueueDepth > 0) {\n\t\t\tthis._config.maxQueueDepth = config.maxQueueDepth;\n\t\t}\n\t}\n\n\t/** Check if a command at the given priority can execute immediately */\n\tprivate canRunNow(priority: GitCommandPriority): boolean {\n\t\t// Must yield to higher priority waiting\n\t\tif (this.hasHigherPriorityWaiting(priority)) return false;\n\n\t\tconst max = this.maxConcurrent;\n\n\t\t// Under normal limit - all priorities can run\n\t\tif (this._activeCount < max) return true;\n\n\t\t// At or over normal limit - only interactive can burst\n\t\tif (priority === 'interactive' && this._activeCount < max + interactiveBurstCapacity) {\n\t\t\treturn true;\n\t\t}\n\n\t\treturn false;\n\t}\n\n\t/** Check if any higher-priority commands are waiting */\n\tprivate hasHigherPriorityWaiting(priority: GitCommandPriority): boolean {\n\t\tfor (const p of priorities) {\n\t\t\tif (p === priority) return false;\n\t\t\tif (this._queues.get(p)!.length > 0) return true;\n\t\t}\n\t\treturn false;\n\t}\n\n\t/**\n\t * Execute a git command with the specified priority.\n\t *\n\t * When `signal` is provided:\n\t * - If already aborted, rejects immediately without running.\n\t * - If aborted while queued, the command is removed from the queue and rejected before it ever runs.\n\t * - If aborted while running, the in-flight spawn must honor the same signal separately\n\t * (callers pass it via `runOpts.cancellation`); the queue does not interrupt running work.\n\t */\n\trun<T>(priority: GitCommandPriority, fn: () => Promise<T>, signal?: AbortSignal): Promise<T> {\n\t\tif (this._disposed) {\n\t\t\treturn Promise.reject(new Error('GitQueue disposed'));\n\t\t}\n\n\t\tif (signal?.aborted) {\n\t\t\treturn Promise.reject(abortReason(signal));\n\t\t}\n\n\t\tif (!this.canRunNow(priority)) {\n\t\t\treturn this.enqueue(fn, priority, signal);\n\t\t}\n\n\t\treturn this.runcore(fn);\n\t}\n\n\tprivate async runcore<T>(fn: () => Promise<T>): Promise<T> {\n\t\tthis._activeCount++;\n\t\ttry {\n\t\t\treturn await fn();\n\t\t} finally {\n\t\t\tthis._activeCount--;\n\t\t\tthis.processQueues();\n\t\t}\n\t}\n\n\tprivate enqueue<T>(fn: () => Promise<T>, priority: GitCommandPriority, signal?: AbortSignal): Promise<T> {\n\t\tconst queue = this._queues.get(priority)!;\n\t\tconst maxDepth = this._config.maxQueueDepth ?? 500;\n\t\tif (maxDepth > 0 && queue.length >= maxDepth) {\n\t\t\treturn Promise.reject(new Error(`GitQueue '${priority}' queue is full (${maxDepth} commands pending)`));\n\t\t}\n\n\t\treturn new Promise<T>((resolve, reject) => {\n\t\t\tconst cmd: QueuedCommand = {\n\t\t\t\trun: fn,\n\t\t\t\tresolve: resolve as (value: unknown) => void,\n\t\t\t\treject: reject,\n\t\t\t\tqueuedAt: Date.now(),\n\t\t\t\tpriority: priority,\n\t\t\t\tsignal: signal,\n\t\t\t};\n\n\t\t\tif (signal != null) {\n\t\t\t\tcmd.abortHandler = () => {\n\t\t\t\t\tconst idx = queue.indexOf(cmd);\n\t\t\t\t\t// If still queued, remove and reject so it never runs.\n\t\t\t\t\t// If already dequeued, the running command should honor the signal at its own layer.\n\t\t\t\t\tif (idx !== -1) {\n\t\t\t\t\t\tqueue.splice(idx, 1);\n\t\t\t\t\t\tcmd.reject(abortReason(signal));\n\t\t\t\t\t}\n\t\t\t\t};\n\t\t\t\tsignal.addEventListener('abort', cmd.abortHandler, { once: true });\n\t\t\t}\n\n\t\t\tqueue.push(cmd);\n\t\t});\n\t}\n\n\tprivate processQueues(): void {\n\t\tif (this._disposed) return;\n\n\t\tconst max = this.maxConcurrent;\n\n\t\tfor (const priority of priorities) {\n\t\t\tconst queue = this._queues.get(priority)!;\n\t\t\tconst limit = priority === 'interactive' ? max + interactiveBurstCapacity : max;\n\n\t\t\twhile (queue.length > 0 && this._activeCount < limit && !this.hasHigherPriorityWaiting(priority)) {\n\t\t\t\tthis.runQueued(queue.shift()!);\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate runQueued(cmd: QueuedCommand): void {\n\t\t// Detach the abort listener now that the command has left the queue — any subsequent\n\t\t// abort must be handled by the running spawn itself (via runOpts.cancellation).\n\t\tif (cmd.signal != null && cmd.abortHandler != null) {\n\t\t\tcmd.signal.removeEventListener('abort', cmd.abortHandler);\n\t\t\tcmd.abortHandler = undefined;\n\t\t}\n\n\t\tconst waitTime = Date.now() - cmd.queuedAt;\n\t\tif (waitTime > 1000) {\n\t\t\tthis._hooks.onSlowQueue?.({\n\t\t\t\tpriority: cmd.priority,\n\t\t\t\twaitTime: waitTime,\n\t\t\t\tactive: this._activeCount,\n\t\t\t\tqueued: {\n\t\t\t\t\tinteractive: this._queues.get('interactive')!.length,\n\t\t\t\t\tnormal: this._queues.get('normal')!.length,\n\t\t\t\t\tbackground: this._queues.get('background')!.length,\n\t\t\t\t},\n\t\t\t\tmaxConcurrent: this.maxConcurrent,\n\t\t\t});\n\t\t}\n\n\t\tthis._activeCount++;\n\t\ttry {\n\t\t\tcmd.run()\n\t\t\t\t.then(cmd.resolve, cmd.reject)\n\t\t\t\t.finally(() => {\n\t\t\t\t\tthis._activeCount--;\n\t\t\t\t\tthis.processQueues();\n\t\t\t\t});\n\t\t} catch (ex) {\n\t\t\tthis._activeCount--;\n\t\t\tcmd.reject(ex);\n\t\t\tthis.processQueues();\n\t\t}\n\t}\n\n\t/** Returns current queue statistics for diagnostics */\n\tgetStats(): { active: number; queued: Record<GitCommandPriority, number>; maxConcurrent: number } {\n\t\treturn {\n\t\t\tactive: this._activeCount,\n\t\t\tqueued: {\n\t\t\t\tinteractive: this._queues.get('interactive')!.length,\n\t\t\t\tnormal: this._queues.get('normal')!.length,\n\t\t\t\tbackground: this._queues.get('background')!.length,\n\t\t\t},\n\t\t\tmaxConcurrent: this.maxConcurrent,\n\t\t};\n\t}\n}\n\n/** Extracts the primary git subcommand from an arg list, skipping global options and their values. */\nexport function getPrimaryGitCommand(args: readonly (string | undefined)[]): string | undefined {\n\t// Classifying always answers where the verb sits, which the cheaper scan omits when no option moves the repository\n\treturn args[scanLeadingOptions(undefined, args, true).verbIndex];\n}\n\n/**\n * Infers a queue priority from the git command being invoked.\n *\n * Intentionally narrow: only returns 'background' for commands that are\n * *always* read-only AND *always* potentially expensive. Polymorphic commands\n * like `log` and `rev-list` (which can be quick bounded lookups or full-history\n * walks) are deliberately omitted — call sites that perform heavy walks must\n * pass `priority: 'background'` explicitly. Never upgrades to 'interactive'.\n *\n * No subcommand awareness (e.g. `stash list`, `branch -l`): the risk of\n * misclassifying a write subcommand as background outweighs the gain.\n */\nexport function inferGitCommandPriority(args: readonly (string | undefined)[]): GitCommandPriority {\n\tswitch (getPrimaryGitCommand(args)) {\n\t\tcase 'for-each-ref':\n\t\tcase 'shortlog':\n\t\tcase 'reflog':\n\t\tcase 'name-rev':\n\t\tcase 'describe':\n\t\tcase 'cherry':\n\t\tcase 'count-objects':\n\t\tcase 'fsck':\n\t\t\treturn 'background';\n\t\tdefault:\n\t\t\treturn 'normal';\n\t}\n}\n"],"mappings":";;;AAcA,MAAM,aAAmC;CAAC;CAAe;CAAU;AAAY;;AAG/E,MAAM,2BAA2B;;AAGjC,SAAgB,YAAY,QAA4B;CACvD,OAAO,OAAO,k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AACvD;;;;;;;;;;;;;AAcA,SAAgB,wBAAwB,MAA2D;CAClG,QAAQ,qBAAqB,IAAI,GAAjC;EACC,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK,QACJ,OAAO;EACR,SACC,OAAO;CACT;AACD"}
@@ -123,6 +123,7 @@ export declare class BranchesGitSubProvider implements GitBranchesSubProvider {
123
123
  private branchesContainingCore;
124
124
  getCurrentBranchReference(repoPath: string, cancellation?: AbortSignal): Promise<GitBranchReference | undefined>;
125
125
  private getCurrentBranchReferenceCore;
126
+ private readCurrentBranchReference;
126
127
  getDefaultBranchName(repoPath: string | undefined, remote?: string, options?: {
127
128
  priority?: GitCommandPriority;
128
129
  local?: boolean;
@@ -273,6 +273,8 @@ var BranchesGitSubProvider = class {
273
273
  const scope = getScopedLogger();
274
274
  if (options?.force) this.cache.evictCaches(repoPath, "branches");
275
275
  if (name != null) return (await this.getBranchFromSharedList(repoPath, name, scope, cancellation)).branch;
276
+ const validation = this.cache.validateBeforeRead(repoPath);
277
+ if (validation != null) await validation;
276
278
  return this.cache.branch.getOrCreate(repoPath, async (cacheable, signal) => {
277
279
  const result = await this.getBranchFromSharedList(repoPath, void 0, scope, signal);
278
280
  const branch = result.branch ?? await this.getCurrentBranch(repoPath, void 0, void 0, signal);
@@ -611,6 +613,10 @@ var BranchesGitSubProvider = class {
611
613
  return ref;
612
614
  }
613
615
  getCurrentBranchReferenceCore(repoPath, ordering, cancellation) {
616
+ const validation = this.cache.validateBeforeRead(repoPath);
617
+ return validation != null ? validation.then(() => this.readCurrentBranchReference(repoPath, ordering, cancellation)) : this.readCurrentBranchReference(repoPath, ordering, cancellation);
618
+ }
619
+ readCurrentBranchReference(repoPath, ordering, cancellation) {
614
620
  return this.cache.currentBranchReference.getOrCreate(repoPath, async (_cacheable, signal) => {
615
621
  const commitOrdering = ordering;
616
622
  let data;