@gitkraken/core-gitlens 0.32.0 → 0.34.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (109) hide show
  1. package/CHANGELOG.md +42 -1
  2. package/dist/git/cache.d.ts +121 -15
  3. package/dist/git/cache.js +316 -74
  4. package/dist/git/cache.js.map +1 -1
  5. package/dist/git/context.d.ts +3 -1
  6. package/dist/git/context.js.map +1 -1
  7. package/dist/git/errors.d.ts +3 -1
  8. package/dist/git/errors.js +4 -1
  9. package/dist/git/errors.js.map +1 -1
  10. package/dist/git/models/pullRequest.d.ts +90 -1
  11. package/dist/git/models/pullRequest.js +18 -2
  12. package/dist/git/models/pullRequest.js.map +1 -1
  13. package/dist/git/models/repositoryIdentities.d.ts +0 -1
  14. package/dist/git/models/repositoryIdentities.js +1 -4
  15. package/dist/git/models/repositoryIdentities.js.map +1 -1
  16. package/dist/git/providers/provider.d.ts +7 -0
  17. package/dist/git/providers/shared/remotes.js +2 -0
  18. package/dist/git/providers/shared/remotes.js.map +1 -1
  19. package/dist/git/remotes/gitlab.js +15 -9
  20. package/dist/git/remotes/gitlab.js.map +1 -1
  21. package/dist/git/service.js +4 -1
  22. package/dist/git/service.js.map +1 -1
  23. package/dist/git/utils/pullRequest.utils.d.ts +72 -1
  24. package/dist/git/utils/pullRequest.utils.js +99 -1
  25. package/dist/git/utils/pullRequest.utils.js.map +1 -1
  26. package/dist/git/utils/repository.utils.d.ts +16 -0
  27. package/dist/git/utils/repository.utils.js +37 -2
  28. package/dist/git/utils/repository.utils.js.map +1 -1
  29. package/dist/git/watching/changeEvent.d.ts +13 -3
  30. package/dist/git/watching/changeEvent.js +19 -4
  31. package/dist/git/watching/changeEvent.js.map +1 -1
  32. package/dist/git/watching/gitDirPoller.d.ts +10 -1
  33. package/dist/git/watching/gitDirPoller.js +9 -3
  34. package/dist/git/watching/gitDirPoller.js.map +1 -1
  35. package/dist/git/watching/unwatchedCacheValidator.d.ts +144 -0
  36. package/dist/git/watching/unwatchedCacheValidator.js +884 -0
  37. package/dist/git/watching/unwatchedCacheValidator.js.map +1 -0
  38. package/dist/git/watching/watchGroup.d.ts +6 -2
  39. package/dist/git/watching/watchGroup.js +35 -24
  40. package/dist/git/watching/watchGroup.js.map +1 -1
  41. package/dist/git/watching/watchService.d.ts +27 -1
  42. package/dist/git/watching/watchService.js +60 -17
  43. package/dist/git/watching/watchService.js.map +1 -1
  44. package/dist/git/watching/watchSession.d.ts +29 -12
  45. package/dist/git/watching/watchSession.js +52 -21
  46. package/dist/git/watching/watchSession.js.map +1 -1
  47. package/dist/git/watching/worktreeSummary.js +7 -7
  48. package/dist/git/watching/worktreeSummary.js.map +1 -1
  49. package/dist/git-cli/cliGitProvider.d.ts +28 -2
  50. package/dist/git-cli/cliGitProvider.js +63 -20
  51. package/dist/git-cli/cliGitProvider.js.map +1 -1
  52. package/dist/git-cli/exec/commandClassifier.d.ts +31 -1
  53. package/dist/git-cli/exec/commandClassifier.js +67 -16
  54. package/dist/git-cli/exec/commandClassifier.js.map +1 -1
  55. package/dist/git-cli/exec/git.d.ts +46 -2
  56. package/dist/git-cli/exec/git.js +87 -9
  57. package/dist/git-cli/exec/git.js.map +1 -1
  58. package/dist/git-cli/exec/gitDirResolver.d.ts +11 -0
  59. package/dist/git-cli/exec/gitDirResolver.js +34 -1
  60. package/dist/git-cli/exec/gitDirResolver.js.map +1 -1
  61. package/dist/git-cli/exec/gitQueue.js +2 -28
  62. package/dist/git-cli/exec/gitQueue.js.map +1 -1
  63. package/dist/git-cli/providers/branches.d.ts +1 -0
  64. package/dist/git-cli/providers/branches.js +21 -10
  65. package/dist/git-cli/providers/branches.js.map +1 -1
  66. package/dist/git-cli/providers/config.d.ts +15 -1
  67. package/dist/git-cli/providers/config.js +67 -22
  68. package/dist/git-cli/providers/config.js.map +1 -1
  69. package/dist/git-cli/providers/pausedOperations.d.ts +1 -0
  70. package/dist/git-cli/providers/pausedOperations.js +4 -0
  71. package/dist/git-cli/providers/pausedOperations.js.map +1 -1
  72. package/dist/git-cli/providers/revision.js +2 -0
  73. package/dist/git-cli/providers/revision.js.map +1 -1
  74. package/dist/git-cli/providers/worktrees.js +36 -10
  75. package/dist/git-cli/providers/worktrees.js.map +1 -1
  76. package/dist/git-cli/service.d.ts +25 -1
  77. package/dist/git-cli/service.js +46 -1
  78. package/dist/git-cli/service.js.map +1 -1
  79. package/dist/plus/ai/errors.d.ts +8 -2
  80. package/dist/plus/ai/errors.js +15 -3
  81. package/dist/plus/ai/errors.js.map +1 -1
  82. package/dist/plus/git-github/api/github.d.ts +51 -1
  83. package/dist/plus/git-github/api/github.js +276 -3
  84. package/dist/plus/git-github/api/github.js.map +1 -1
  85. package/dist/plus/git-github/models.d.ts +54 -1
  86. package/dist/plus/git-github/models.js +48 -3
  87. package/dist/plus/git-github/models.js.map +1 -1
  88. package/dist/plus/integrations/fieldPresence.d.ts +6 -1
  89. package/dist/plus/integrations/fieldPresence.js +19 -9
  90. package/dist/plus/integrations/fieldPresence.js.map +1 -1
  91. package/dist/plus/integrations/models/gitHostIntegration.d.ts +26 -1
  92. package/dist/plus/integrations/models/gitHostIntegration.js +51 -0
  93. package/dist/plus/integrations/models/gitHostIntegration.js.map +1 -1
  94. package/dist/plus/integrations/models/integration.d.ts +15 -2
  95. package/dist/plus/integrations/models/integration.js +1 -1
  96. package/dist/plus/integrations/models/integration.js.map +1 -1
  97. package/dist/plus/integrations/providers/github.d.ts +16 -1
  98. package/dist/plus/integrations/providers/github.js +53 -1
  99. package/dist/plus/integrations/providers/github.js.map +1 -1
  100. package/dist/plus/integrations/providers/gitlab/gitlab.d.ts +10 -0
  101. package/dist/plus/integrations/providers/gitlab/gitlab.js +62 -15
  102. package/dist/plus/integrations/providers/gitlab/gitlab.js.map +1 -1
  103. package/dist/plus/integrations/providers/gitlab/gitlab.utils.d.ts +8 -0
  104. package/dist/plus/integrations/providers/gitlab/gitlab.utils.js +32 -16
  105. package/dist/plus/integrations/providers/gitlab/gitlab.utils.js.map +1 -1
  106. package/dist/plus/integrations/reads/etag.js +11 -0
  107. package/dist/plus/integrations/reads/etag.js.map +1 -1
  108. package/docs/integrations.md +39 -6
  109. package/package.json +1 -1
@@ -176,43 +176,92 @@ function isConfigRead(rest) {
176
176
  if (rest.some((arg) => configReadOptions.has(arg))) return true;
177
177
  return rest.filter((arg) => !arg.startsWith("-")).length === 1;
178
178
  }
179
- /** Global options whose value is the next argument, so the verb scan must skip both. */
179
+ /**
180
+ * Global options whose value is the next argument, so the verb scan must skip both. A missing one makes the scan
181
+ * take its value for the verb and stop there, missing any `-C`, `--git-dir` or `--work-tree` git still reads after it.
182
+ */
180
183
  const globalOptionsWithValue = /* @__PURE__ */ new Set([
181
184
  "-c",
185
+ "--attr-source",
182
186
  "--config-env",
183
- "--exec-path",
184
187
  "--git-dir",
185
188
  "--namespace",
189
+ "--shallow-file",
186
190
  "--super-prefix",
187
191
  "--work-tree"
188
192
  ]);
193
+ /** Shared by every scan that found nothing, so the common run allocates no result */
194
+ const noLeadingOptions = Object.freeze({ verbIndex: -1 });
195
+ /** The index of the first defined token at or after `i` in `first` followed by `second`, or their combined length */
196
+ function nextToken(first, second, i) {
197
+ const firstLength = first?.length ?? 0;
198
+ const total = firstLength + second.length;
199
+ while (i < total && (i < firstLength ? first[i] : second[i - firstLength]) == null) i++;
200
+ return i;
201
+ }
189
202
  /**
190
- * Skips the global options (`-c key=val`, `-C path`) git accepts before the verb to find it, and notes a
191
- * `-C` re-scope so notification targets that tree.
203
+ * Walks the global options (`-c key=val`, `-C path`, `--git-dir`, `--work-tree`) git accepts before the verb,
204
+ * over `first` then `second` as one sequence with `undefined` tokens skipped, and stops at the first non-option
205
+ * token. Git honours these only ahead of the verb, so a later `-C 3` (grep's context) or a pathspec named like an
206
+ * option is never a global option; every consumer shares this one walk so none can drift from how git reads them.
207
+ *
208
+ * With `classify` it also collects the `-c` configs and always returns a result carrying the verb's position;
209
+ * without it the walk allocates nothing unless a global option moves the repository.
192
210
  */
193
- function leadingCommand(args) {
211
+ function scanLeadingOptions(first, second, classify) {
212
+ const firstLength = first?.length ?? 0;
213
+ const total = firstLength + second.length;
194
214
  let pathOverride;
195
215
  let configs;
196
- let i = 0;
197
- while (i < args.length) {
198
- const arg = args[i];
216
+ let gitDir;
217
+ let workTree;
218
+ let i = nextToken(first, second, 0);
219
+ while (i < total) {
220
+ const arg = i < firstLength ? first[i] : second[i - firstLength];
199
221
  if (arg === "-C") {
200
- const path = args[i + 1];
201
- if (path != null) pathOverride = pathOverride == null || isAbsolute(path) ? path : join(pathOverride, path);
202
- i += 2;
222
+ const valueIndex = nextToken(first, second, i + 1);
223
+ if (valueIndex < total) {
224
+ const path = valueIndex < firstLength ? first[valueIndex] : second[valueIndex - firstLength];
225
+ pathOverride = pathOverride == null || isAbsolute(path) ? path : join(pathOverride, path);
226
+ }
227
+ i = nextToken(first, second, valueIndex + 1);
203
228
  continue;
204
229
  }
205
230
  if (globalOptionsWithValue.has(arg)) {
206
- if (arg === "-c" && args[i + 1] != null) (configs ??= []).push(args[i + 1]);
207
- i += 2;
231
+ const valueIndex = nextToken(first, second, i + 1);
232
+ if (valueIndex < total) {
233
+ const value = valueIndex < firstLength ? first[valueIndex] : second[valueIndex - firstLength];
234
+ if (arg === "-c") {
235
+ if (classify) (configs ??= []).push(value);
236
+ } else if (arg === "--git-dir") gitDir = value;
237
+ else if (arg === "--work-tree") workTree = value;
238
+ }
239
+ i = nextToken(first, second, valueIndex + 1);
208
240
  continue;
209
241
  }
210
242
  if (arg.startsWith("-")) {
211
- i += 1;
243
+ if (arg.startsWith("--git-dir=")) gitDir = arg.slice(10);
244
+ else if (arg.startsWith("--work-tree=")) workTree = arg.slice(12);
245
+ i = nextToken(first, second, i + 1);
212
246
  continue;
213
247
  }
214
248
  break;
215
249
  }
250
+ if (!classify && pathOverride == null && gitDir == null && workTree == null) return noLeadingOptions;
251
+ return {
252
+ pathOverride,
253
+ gitDir,
254
+ workTree,
255
+ configs,
256
+ verbIndex: i
257
+ };
258
+ }
259
+ /**
260
+ * Skips the global options (`-c key=val`, `-C path`) git accepts before the verb to find it, and notes a
261
+ * `-C` re-scope so notification targets that tree, and any `--git-dir` / `--work-tree` that moves the repository.
262
+ */
263
+ function leadingCommand(args) {
264
+ const { pathOverride, configs, gitDir, workTree, verbIndex: i } = scanLeadingOptions(void 0, args, true);
216
265
  const verb = args[i] ?? "";
217
266
  const rest = args.slice(i + 1);
218
267
  return {
@@ -221,7 +270,9 @@ function leadingCommand(args) {
221
270
  subcommand: rest[0],
222
271
  rest,
223
272
  pathOverride,
224
- configs
273
+ configs,
274
+ gitDir,
275
+ workTree
225
276
  };
226
277
  }
227
278
  /**
@@ -1059,6 +1110,6 @@ function getChangesForCommand(args) {
1059
1110
  return result;
1060
1111
  }
1061
1112
  //#endregion
1062
- export { getChangesForCommand, leadingCommand, mayWriteTracking, worktreeSharedChanges };
1113
+ export { getChangesForCommand, leadingCommand, mayWriteTracking, scanLeadingOptions, worktreeSharedChanges };
1063
1114
 
1064
1115
  //# sourceMappingURL=commandClassifier.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"commandClassifier.js","names":[],"sources":["../../../../git-cli/src/exec/commandClassifier.ts"],"sourcesContent":["import { isAbsolute, join } from 'node:path';\nimport type { RepositoryChange } from '@gitlens/git/models/repository.js';\nimport { getRefChangeKind } from '@gitlens/git/watching/changeEvent.js';\n\n/**\n * Verbs that never move a ref, the index or the working tree, so a raw run needs no notification.\n * Anything not listed is treated as a mutation: a needless notification costs a full cache eviction, a\n * missed one serves stale state. Object-writing plumbing (`hash-object -w`, `mktree`, `commit-tree`,\n * `write-tree`) is listed too: it only adds loose objects nothing cached observes.\n */\nconst readOnlyVerbs = new Set([\n\t'annotate',\n\t'archive',\n\t'blame',\n\t'cat-file',\n\t'check-attr',\n\t'check-ignore',\n\t'check-mailmap',\n\t'check-ref-format',\n\t'cherry',\n\t'commit-tree',\n\t'count-objects',\n\t'describe',\n\t'diff',\n\t'diff-files',\n\t'diff-index',\n\t'diff-tree',\n\t'for-each-ref',\n\t'fsck',\n\t'grep',\n\t'hash-object',\n\t'help',\n\t'log',\n\t'ls-files',\n\t// Asks a remote what it has; nothing local moves.\n\t'ls-remote',\n\t'ls-tree',\n\t'merge-base',\n\t'merge-tree',\n\t'mktree',\n\t'name-rev',\n\t'patch-id',\n\t'range-diff',\n\t'rev-list',\n\t'rev-parse',\n\t'shortlog',\n\t'show',\n\t'show-branch',\n\t'show-ref',\n\t'status',\n\t'var',\n\t'verify-commit',\n\t'verify-pack',\n\t'verify-tag',\n\t'version',\n\t'whatchanged',\n\t'write-tree',\n]);\n\nconst reflogWriteSubcommands: ReadonlySet<string> = new Set(['expire', 'delete', 'drop']);\n\n/**\n * Sub-commands of otherwise-mutating verbs that only list. `''` is the bare verb, which lists for `branch`,\n * `tag`, `remote` and `notes`; `branch -v` and every `tag` filter imply git's own list mode.\n */\nconst readOnlySubcommands: Readonly<Record<string, ReadonlySet<string>>> = {\n\tbranch: new Set([\n\t\t'',\n\t\t'-l',\n\t\t'--list',\n\t\t'--show-current',\n\t\t'-a',\n\t\t'-r',\n\t\t'-v',\n\t\t'-vv',\n\t\t'--verbose',\n\t\t'--contains',\n\t\t'--no-contains',\n\t\t'--merged',\n\t\t'--no-merged',\n\t\t'--points-at',\n\t]),\n\tconfig: new Set(['get', 'list']),\n\tnotes: new Set(['', 'list', 'show', 'get-ref']),\n\t// `stash create` writes a commit object and prints it; no ref moves\n\tstash: new Set(['list', 'show', 'create']),\n\ttag: new Set([\n\t\t'',\n\t\t'-l',\n\t\t'--list',\n\t\t'-n',\n\t\t'-v',\n\t\t'--verify',\n\t\t'--contains',\n\t\t'--no-contains',\n\t\t'--merged',\n\t\t'--no-merged',\n\t\t'--points-at',\n\t]),\n\tworktree: new Set(['list']),\n\tremote: new Set(['', '-v', 'get-url', 'show']),\n};\n\n/**\n * Options that make an argv write whatever else it contains, checked across the whole argv rather than\n * only its first token: `branch -r -d origin/x` leads with a listing flag and still deletes.\n */\nconst writeOptions: Readonly<Record<string, readonly string[]>> = {\n\tbranch: [\n\t\t'-d',\n\t\t'-D',\n\t\t'--delete',\n\t\t'-m',\n\t\t'-M',\n\t\t'--move',\n\t\t'-c',\n\t\t'-C',\n\t\t'--copy',\n\t\t'-f',\n\t\t'--force',\n\t\t'-t',\n\t\t'--track',\n\t\t'--no-track',\n\t\t'-u',\n\t\t'--set-upstream-to',\n\t\t'--unset-upstream',\n\t\t'--edit-description',\n\t],\n\tconfig: [\n\t\t'--add',\n\t\t'--replace-all',\n\t\t'--unset',\n\t\t'--unset-all',\n\t\t'--rename-section',\n\t\t'--remove-section',\n\t\t'-e',\n\t\t'--edit',\n\t],\n};\n\nconst configReadOptions = new Set([\n\t'--get',\n\t'--get-all',\n\t'--get-regexp',\n\t'--get-urlmatch',\n\t'--get-color',\n\t'--get-colorbool',\n\t'--list',\n\t'-l',\n]);\n\nfunction hasWriteOption(verb: string, rest: readonly string[]): boolean {\n\tconst options = writeOptions[verb];\n\tif (options == null) return false;\n\treturn hasOption(rest, options);\n}\n\nfunction hasOption(rest: readonly string[], options: readonly string[]): boolean {\n\treturn rest.some(arg => options.some(opt => arg === opt || arg.startsWith(`${opt}=`)));\n}\n\n/**\n * `config <key>` with nothing after the key is git's own read form, as is any `--get*`/`--list`. `config edit`\n * (git 2.46's subcommand form of `--edit`) also has a single non-flag argument but writes.\n */\nfunction isConfigRead(rest: readonly string[]): boolean {\n\tif (rest[0] === 'edit') return false;\n\tif (rest.some(arg => configReadOptions.has(arg))) return true;\n\n\treturn rest.filter(arg => !arg.startsWith('-')).length === 1;\n}\n\n/** Global options whose value is the next argument, so the verb scan must skip both. */\nconst globalOptionsWithValue = new Set([\n\t'-c',\n\t'--config-env',\n\t'--exec-path',\n\t'--git-dir',\n\t'--namespace',\n\t'--super-prefix',\n\t'--work-tree',\n]);\n\nexport interface LeadingCommand {\n\tverb: string;\n\treadOnly: boolean;\n\t/** The first token after the verb, unresolved — used for subcommand-shaped decisions (`worktree add`). */\n\tsubcommand?: string;\n\t/** Every token after the verb */\n\trest: readonly string[];\n\t/** The `-C <path>` target when the caller re-scopes the command to another working tree. */\n\tpathOverride?: string;\n\t/** Each `-c <key>[=<value>]` given before the verb, in order */\n\tconfigs?: readonly string[];\n}\n\n/**\n * Skips the global options (`-c key=val`, `-C path`) git accepts before the verb to find it, and notes a\n * `-C` re-scope so notification targets that tree.\n */\nexport function leadingCommand(args: readonly string[]): LeadingCommand {\n\tlet pathOverride: string | undefined;\n\tlet configs: string[] | undefined;\n\tlet i = 0;\n\twhile (i < args.length) {\n\t\tconst arg = args[i];\n\t\tif (arg === '-C') {\n\t\t\t// git applies each `-C` relative to the one before it\n\t\t\tconst path = args[i + 1];\n\t\t\tif (path != null) {\n\t\t\t\tpathOverride = pathOverride == null || isAbsolute(path) ? path : join(pathOverride, path);\n\t\t\t}\n\t\t\ti += 2;\n\n\t\t\tcontinue;\n\t\t}\n\t\tif (globalOptionsWithValue.has(arg)) {\n\t\t\tif (arg === '-c' && args[i + 1] != null) {\n\t\t\t\t(configs ??= []).push(args[i + 1]);\n\t\t\t}\n\t\t\ti += 2;\n\n\t\t\tcontinue;\n\t\t}\n\t\tif (arg.startsWith('-')) {\n\t\t\ti += 1;\n\n\t\t\tcontinue;\n\t\t}\n\t\tbreak;\n\t}\n\tconst verb = args[i] ?? '';\n\tconst rest = args.slice(i + 1);\n\tconst readOnly =\n\t\t!hasWriteOption(verb, rest) &&\n\t\t(readOnlyVerbs.has(verb) ||\n\t\t\t(readOnlySubcommands[verb]?.has(rest[0] ?? '') ?? false) ||\n\t\t\t(verb === 'config' && isConfigRead(rest)) ||\n\t\t\t// Every `reflog` form reads (bare, `<ref>`, `show`, `list`, `exists`) except the three that rewrite\n\t\t\t// it. Base-branch detection answers \"none\" unless a branch's reflog has exactly one creation entry,\n\t\t\t// so a rewrite can make a cached \"none\" derivable; no change kind names a reflog, so it resets all.\n\t\t\t(verb === 'reflog' && !reflogWriteSubcommands.has(rest[0] ?? '')) ||\n\t\t\t// A bare `symbolic-ref <name>` reads; a second non-flag argument, or a delete, writes.\n\t\t\t(verb === 'symbolic-ref' &&\n\t\t\t\t!rest.includes('-d') &&\n\t\t\t\t!rest.includes('--delete') &&\n\t\t\t\trest.filter(a => !a.startsWith('-')).length < 2));\n\n\treturn {\n\t\tverb: verb,\n\t\treadOnly: readOnly,\n\t\tsubcommand: rest[0],\n\t\trest: rest,\n\t\tpathOverride: pathOverride,\n\t\tconfigs: configs,\n\t};\n}\n\n/**\n * The change kinds every worktree sharing a `.git` sees: its refs, stash, worktree list, the HEADs of the worktrees\n * it lists (`worktreeHead`, which every other worktree's watcher reports too) and config. The rest a classified verb\n * announces — the tree's own HEAD, the index, a paused operation, FETCH_HEAD — belong to the one tree the command ran\n * in, so a `-C`-scoped write tells the caller's own `cwd` only this subset of what it changed.\n */\nexport const worktreeSharedChanges: ReadonlySet<RepositoryChange> = new Set([\n\t'heads',\n\t'tags',\n\t'stash',\n\t'remotes',\n\t'worktrees',\n\t'worktreeHead',\n\t'config',\n]);\n\n/**\n * Verbs whose effect is confined to the object store that nothing cached observes — repacking or pruning\n * `.git/objects` changes no cached read (branches, refs, status, worktrees, …). `init` and `clone` create a\n * repository rather than mutate a registered one, so there is nothing yet registered to notify.\n */\nconst objectOnlyVerbs = new Set([\n\t'gc',\n\t'repack',\n\t'prune',\n\t'maintenance',\n\t'commit-graph',\n\t'multi-pack-index',\n\t'init',\n\t'clone',\n]);\n\n/**\n * The {@link RepositoryChange} kinds each mutating verb announces. A worktree subcommand other than a\n * listing is handled separately (see {@link getChangesForCommand}), and any verb absent from both this\n * table and {@link objectOnlyVerbs} announces `[]` — the conservative default for an unclassified\n * mutation: the caller still learns something changed, just not what. An entry covers at least what the\n * verb's typed mutator announces; `update-ref` and `symbolic-ref` name every kind their target ref could be.\n * {@link getNamedChanges} narrows the forms whose argv proves what moved, which can announce less: the typed\n * checkout announces `heads` for any target, but a `--detach` or full-SHA checkout moves only this tree's HEAD,\n * no shared ref.\n * The kinds decide which caches the announcement resets, so a verb that can start or end a paused operation\n * names `pausedOp`: `commit` concludes a merge, cherry-pick or revert, `reset` aborts one, and `am` runs in\n * `rebase-apply`.\n */\nconst changesByVerb: Readonly<Record<string, readonly RepositoryChange[]>> = {\n\tcommit: ['head', 'heads', 'index', 'pausedOp'],\n\tam: ['head', 'heads', 'index', 'pausedOp'],\n\tbisect: ['head', 'index', 'worktrees', 'worktreeHead'],\n\tcheckout: ['head', 'heads', 'index', 'worktrees', 'worktreeHead'],\n\tswitch: ['head', 'heads', 'index', 'worktrees', 'worktreeHead'],\n\treset: ['head', 'heads', 'index', 'pausedOp'],\n\tmerge: ['head', 'heads', 'index', 'pausedOp', 'merge'],\n\trebase: ['head', 'heads', 'index', 'pausedOp', 'rebase', 'worktrees', 'worktreeHead'],\n\t'cherry-pick': ['head', 'heads', 'index', 'pausedOp', 'cherryPick'],\n\trevert: ['head', 'heads', 'index', 'pausedOp', 'revert'],\n\tpull: ['head', 'heads', 'index', 'remotes', 'tags', 'lastFetched', 'pausedOp', 'merge', 'rebase'],\n\tadd: ['index'],\n\trm: ['index'],\n\tmv: ['index'],\n\trestore: ['index'],\n\tapply: ['index'],\n\t'read-tree': ['index'],\n\t'update-index': ['index'],\n\tclean: ['index'],\n\tstash: ['stash', 'index'],\n\t'update-ref': ['head', 'heads', 'remotes', 'tags', 'stash'],\n\tbranch: ['heads', 'remotes'],\n\t'symbolic-ref': ['head', 'heads', 'remotes', 'tags'],\n\t'pack-refs': ['heads', 'remotes', 'tags'],\n\ttag: ['tags'],\n\t// A refspec can write a local branch (`fetch origin main:main`), which only the typed fetch parses for\n\tfetch: ['heads', 'remotes', 'tags', 'lastFetched'],\n\tpush: ['remotes'],\n\tremote: ['remotes', 'config'],\n\tconfig: ['config', 'heads', 'remotes'],\n\tnotes: ['heads'],\n};\n\n/**\n * `branch` options that write `.git/config`: a rename, copy or delete moves or drops the branch's section, and the\n * rest set or clear its upstream or description. A plain create (or `-f`) writes tracking only from a remote-tracking\n * start point, which the `.git/config` watcher reports.\n */\nconst branchConfigOptions: readonly string[] = [\n\t'-d',\n\t'-D',\n\t'--delete',\n\t'-m',\n\t'-M',\n\t'--move',\n\t'-c',\n\t'-C',\n\t'--copy',\n\t'-t',\n\t'--track',\n\t'-u',\n\t'--set-upstream-to',\n\t'--unset-upstream',\n\t'--edit-description',\n];\nconst branchConfigChanges: readonly RepositoryChange[] = ['config', 'heads', 'remotes'];\n\n/**\n * Whether creating a branch from `startPoint` may write its tracking to `.git/config`, as git's default\n * `branch.autoSetupMerge=true` does from a remote-tracking start point. Only a name holding a `/` can be one, so a\n * local name with a `/` counts too. The `.git/config` watcher reports what this misses, such as\n * `branch.autoSetupMerge=always`.\n */\nexport function mayWriteTracking(startPoint: string | undefined, noTracking: boolean | undefined): boolean {\n\tif (noTracking || !startPoint) return false;\n\tif (startPoint.startsWith('refs/')) return startPoint.startsWith('refs/remotes/');\n\n\treturn startPoint.includes('/');\n}\n\nconst worktreeChanges: readonly RepositoryChange[] = ['worktrees', 'worktreeHead', 'heads'];\nconst emptyChanges: readonly RepositoryChange[] = [];\n\nexport interface CommandChanges {\n\tchanges: readonly RepositoryChange[];\n\t/** The `-C <path>` target when the caller re-scoped the command to another working tree. */\n\tpathOverride?: string;\n\t/** The subset of {@link changes} every worktree sharing the same `.git` sees, not just the tree the command ran in. */\n\tsharedChanges: readonly RepositoryChange[];\n\t/**\n\t * The full ref names the command creates, moves or deletes, when its argv proves them. A ref kind in\n\t * {@link changes} with a name of its kind here is fully described by those names, as `repository.onChanged`'s\n\t * `refs` are; a ref kind with none stays unnamed.\n\t */\n\trefs?: readonly string[];\n\t/** The command's `config` change touches only the `branch.<name>` sections of the local branches {@link refs} names */\n\tconfigConfinedToRefs?: boolean;\n\t/**\n\t * The command moves only the branch HEAD is on, or no branch when HEAD is detached, so `git.run` reads HEAD\n\t * before and after the run to name it.\n\t */\n\tmovesHeadBranch?: boolean;\n\t/**\n\t * The paths, as argv spells them, of the worktrees a `worktree add`, `remove`, `lock`, `unlock` or `move` acts on: a\n\t * move's source, then its destination. Unset when argv doesn't name them unambiguously.\n\t */\n\tworktreePaths?: readonly string[];\n}\n\ntype NamedChanges = Omit<CommandChanges, 'pathOverride' | 'sharedChanges' | 'worktreePaths'>;\n\nconst configHeadsChanges: readonly RepositoryChange[] = ['config', 'heads'];\nconst headsChanges: readonly RepositoryChange[] = ['heads'];\nconst remotesChanges: readonly RepositoryChange[] = ['remotes'];\nconst tagsChanges: readonly RepositoryChange[] = ['tags'];\nconst stashChanges: readonly RepositoryChange[] = ['stash'];\nconst stashIndexChanges: readonly RepositoryChange[] = ['stash', 'index'];\nconst stashBranchChanges: readonly RepositoryChange[] = [\n\t'head',\n\t'heads',\n\t'index',\n\t'stash',\n\t'worktrees',\n\t'worktreeHead',\n];\nconst indexChanges: readonly RepositoryChange[] = ['index'];\nconst headHeadsChanges: readonly RepositoryChange[] = ['head', 'heads'];\n// A checkout, rebase, bisect or `stash branch` rewrites the tree's HEAD file, which every other worktree's watcher\n// reports as `worktreeHead`: the `worktrees` and `worktreeHead` kinds reach them as shared, so that report is the\n// write's own\nconst headIndexChanges: readonly RepositoryChange[] = ['head', 'index', 'worktrees', 'worktreeHead'];\nconst checkoutChanges: readonly RepositoryChange[] = ['head', 'heads', 'index', 'worktrees', 'worktreeHead'];\nconst checkoutTrackingChanges: readonly RepositoryChange[] = [\n\t'config',\n\t'head',\n\t'heads',\n\t'index',\n\t'worktrees',\n\t'worktreeHead',\n];\nconst worktreeOnlyChanges: readonly RepositoryChange[] = ['worktrees'];\nconst worktreeHeadChanges: readonly RepositoryChange[] = ['worktrees', 'worktreeHead'];\nconst worktreeTrackingChanges: readonly RepositoryChange[] = ['config', 'worktrees', 'worktreeHead', 'heads'];\n\nconst stashRefs: readonly string[] = ['refs/stash'];\n\n/** A full object name, which `checkout` and `worktree add` never DWIM into a new branch */\nconst fullShaRegex = /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/i;\n\n/**\n * Whether a branch name in argv is the branch it names. Git expands `@{-<n>}` (and `@`) wherever it takes a branch\n * name, `branch -d @{-1}` deleting the previous branch, and no ref name can hold `@{` or be `@`\n */\nfunction isLiteralBranchName(name: string): boolean {\n\treturn name !== '@' && !name.includes('@{');\n}\n\ninterface ParsedArgs {\n\t/** Each option in argv order, with its value when it takes one */\n\toptions: readonly (readonly [name: string, value: string | undefined])[];\n\t/** The non-option arguments, including those after `--` */\n\tpositionals: readonly string[];\n\t/** Where `--` fell in {@link positionals}, for the verbs that take pathspecs after it */\n\tdashDash?: number;\n}\n\n/**\n * Splits a verb's arguments by its own option table, since one letter means different things to different verbs\n * (`-m` moves, merges or sets a message). An option outside the table returns `undefined` rather than a guess at\n * whether it takes a value. A valued option accepts `--opt=<v>`, `--opt <v>`, `-o <v>` and `-o<v>`.\n */\nfunction parseArgs(\n\targs: readonly string[],\n\tflags: ReadonlySet<string>,\n\tvalued: ReadonlySet<string>,\n): ParsedArgs | undefined {\n\tconst options: [string, string | undefined][] = [];\n\tconst positionals: string[] = [];\n\tlet dashDash: number | undefined;\n\tlet optionsEnded = false;\n\tfor (let i = 0; i < args.length; i++) {\n\t\tconst arg = args[i];\n\t\t// Still a pathspec separator after `--end-of-options`, as `checkout` and `reset` read it\n\t\tif (arg === '--' && dashDash == null) {\n\t\t\tdashDash = positionals.length;\n\t\t\toptionsEnded = true;\n\t\t\tcontinue;\n\t\t}\n\t\tif (optionsEnded || arg === '-' || !arg.startsWith('-')) {\n\t\t\tpositionals.push(arg);\n\t\t\tcontinue;\n\t\t}\n\t\tif (arg === '--end-of-options') {\n\t\t\toptionsEnded = true;\n\t\t\tcontinue;\n\t\t}\n\t\tif (flags.has(arg)) {\n\t\t\toptions.push([arg, undefined]);\n\t\t\tcontinue;\n\t\t}\n\t\tif (valued.has(arg)) {\n\t\t\tconst value = args[i + 1];\n\t\t\tif (value == null) return undefined;\n\n\t\t\toptions.push([arg, value]);\n\t\t\ti++;\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst long = arg.startsWith('--');\n\t\tconst name = long ? arg.split('=', 1)[0] : arg.slice(0, 2);\n\t\tif (name === arg || !valued.has(name)) return undefined;\n\n\t\toptions.push([name, arg.slice(long ? name.length + 1 : name.length)]);\n\t}\n\treturn { options: options, positionals: positionals, dashDash: dashDash };\n}\n\nfunction hasParsedOption(parsed: ParsedArgs, ...names: string[]): boolean {\n\treturn parsed.options.some(([option]) => names.includes(option));\n}\n\nconst updateRefFlags: ReadonlySet<string> = new Set(['-d', '--delete', '--no-deref', '--create-reflog']);\nconst updateRefValued: ReadonlySet<string> = new Set(['-m', '--message']);\n\n/**\n * `update-ref` moves the one ref it names, or the ref a symbolic one points to without `--no-deref`, so `HEAD` and a\n * remote's `HEAD` stay unnamed. `null` means a ref outside the namespaces core reads, which the typed\n * `updateReference` doesn't announce either. `git log --all` (graph, search, contributors) does walk such a ref when\n * it points at a commit, and argv can't tell that from a blob ref, so a row it adds or drops can stay stale until the\n * next heads change: the trade the typed write makes not to refresh every worktree on each bookkeeping write. A packed\n * ref's delete rewrites `packed-refs`, which the watcher still reports.\n */\nfunction getUpdateRefChanges(args: readonly string[]): NamedChanges | null | undefined {\n\tconst parsed = parseArgs(args, updateRefFlags, updateRefValued);\n\tif (parsed == null) return undefined;\n\n\tconst [ref] = parsed.positionals;\n\tif (!ref) return undefined;\n\tif (ref === 'HEAD') return { changes: headHeadsChanges };\n\tif (!ref.startsWith('refs/')) return undefined;\n\tif (ref.endsWith('/HEAD') && !hasParsedOption(parsed, '--no-deref')) return undefined;\n\n\tconst kind = getRefChangeKind(ref);\n\tif (kind != null) return { changes: [kind], refs: [ref] };\n\t// The watcher reports `refs/replace` as heads, and `notes` announces heads too\n\tif (ref.startsWith('refs/replace/') || ref.startsWith('refs/notes/')) return { changes: headsChanges };\n\n\treturn null;\n}\n\nconst branchFlags: ReadonlySet<string> = new Set([\n\t'-f',\n\t'--force',\n\t'--no-track',\n\t'-d',\n\t'-D',\n\t'--delete',\n\t'-m',\n\t'-M',\n\t'--move',\n\t'-c',\n\t'-C',\n\t'--copy',\n\t'-r',\n\t'--remotes',\n\t'-q',\n\t'--quiet',\n\t'--create-reflog',\n]);\nconst noValuedOptions: ReadonlySet<string> = new Set();\n\n/**\n * The create, delete, rename and copy forms of `branch` name every branch they write. A delete removes a local\n * branch's `branch.<name>` section and a rename or copy moves it; a create writes it only for tracking.\n */\nfunction getBranchChanges(args: readonly string[]): NamedChanges | undefined {\n\tconst parsed = parseArgs(args, branchFlags, noValuedOptions);\n\tif (parsed == null) return undefined;\n\n\tlet mode: 'delete' | 'move' | undefined;\n\tlet remote = false;\n\tlet noTrack = false;\n\tfor (const [option] of parsed.options) {\n\t\tswitch (option) {\n\t\t\tcase '-d':\n\t\t\tcase '-D':\n\t\t\tcase '--delete':\n\t\t\t\tif (mode === 'move') return undefined;\n\n\t\t\t\tmode = 'delete';\n\t\t\t\tbreak;\n\t\t\tcase '-m':\n\t\t\tcase '-M':\n\t\t\tcase '--move':\n\t\t\tcase '-c':\n\t\t\tcase '-C':\n\t\t\tcase '--copy':\n\t\t\t\tif (mode === 'delete') return undefined;\n\n\t\t\t\tmode = 'move';\n\t\t\t\tbreak;\n\t\t\tcase '-r':\n\t\t\tcase '--remotes':\n\t\t\t\tremote = true;\n\t\t\t\tbreak;\n\t\t\tcase '--no-track':\n\t\t\t\tnoTrack = true;\n\t\t\t\tbreak;\n\t\t}\n\t}\n\n\tconst names = parsed.positionals;\n\tif (mode === 'delete') {\n\t\tif (!names.length || !names.every(isLiteralBranchName)) return undefined;\n\t\tif (remote) return { changes: remotesChanges, refs: names.map(n => `refs/remotes/${n}`) };\n\n\t\treturn { changes: configHeadsChanges, refs: names.map(n => `refs/heads/${n}`), configConfinedToRefs: true };\n\t}\n\tif (remote) return undefined;\n\n\tif (mode === 'move') {\n\t\t// With one name, git renames or copies the current branch, which argv doesn't name\n\t\tif (names.length !== 2 || !names.every(isLiteralBranchName)) return undefined;\n\n\t\treturn { changes: configHeadsChanges, refs: names.map(n => `refs/heads/${n}`), configConfinedToRefs: true };\n\t}\n\n\tif ((names.length !== 1 && names.length !== 2) || !isLiteralBranchName(names[0])) return undefined;\n\n\tconst refs = [`refs/heads/${names[0]}`];\n\tif (mayWriteTracking(names[1], noTrack)) {\n\t\treturn { changes: configHeadsChanges, refs: refs, configConfinedToRefs: true };\n\t}\n\treturn { changes: headsChanges, refs: refs };\n}\n\nconst tagFlags: ReadonlySet<string> = new Set([\n\t'-f',\n\t'--force',\n\t'-d',\n\t'--delete',\n\t'-a',\n\t'--annotate',\n\t'-s',\n\t'--sign',\n\t'--no-sign',\n\t'-e',\n\t'--edit',\n\t'--create-reflog',\n]);\nconst tagValued: ReadonlySet<string> = new Set(['-m', '--message', '-F', '--file', '-u', '--local-user', '--cleanup']);\n\nfunction getTagChanges(args: readonly string[]): NamedChanges | undefined {\n\tconst parsed = parseArgs(args, tagFlags, tagValued);\n\tif (parsed == null) return undefined;\n\n\tconst names = parsed.positionals;\n\tif (hasParsedOption(parsed, '-d', '--delete')) {\n\t\tif (!names.length) return undefined;\n\n\t\treturn { changes: tagsChanges, refs: names.map(n => `refs/tags/${n}`) };\n\t}\n\tif (names.length !== 1 && names.length !== 2) return undefined;\n\n\treturn { changes: tagsChanges, refs: [`refs/tags/${names[0]}`] };\n}\n\n/** The `worktree` subcommands besides `add` and `list` (none writes a branch) that delete a worktree's HEAD */\nconst worktreeHeadSubcommands: ReadonlySet<string> = new Set(['remove', 'prune']);\n/** The rest, which touch no worktree's HEAD */\nconst worktreeEditSubcommands: ReadonlySet<string> = new Set(['lock', 'unlock', 'move', 'repair']);\nconst worktreeAddFlags: ReadonlySet<string> = new Set([\n\t'-f',\n\t'--force',\n\t'-d',\n\t'--detach',\n\t'--checkout',\n\t'--no-checkout',\n\t'--lock',\n\t'-q',\n\t'--quiet',\n\t'--track',\n\t'--no-track',\n\t'--guess-remote',\n\t'--no-guess-remote',\n\t'--orphan',\n]);\nconst worktreeAddValued: ReadonlySet<string> = new Set(['-b', '-B', '--reason']);\n\n/**\n * `worktree add` is the only subcommand that can create a branch: the `-b`/`-B` one it names or, without either, one\n * git DWIMs from a short commit-ish (or from the path, given none), which argv can't name. A detached or full-SHA add\n * creates none.\n */\nfunction getWorktreeChanges(args: readonly string[]): NamedChanges | undefined {\n\tconst [subcommand, ...rest] = args;\n\tif (subcommand != null && worktreeEditSubcommands.has(subcommand)) return { changes: worktreeOnlyChanges };\n\tif (subcommand != null && worktreeHeadSubcommands.has(subcommand)) return { changes: worktreeHeadChanges };\n\tif (subcommand !== 'add') return undefined;\n\n\tconst parsed = parseArgs(rest, worktreeAddFlags, worktreeAddValued);\n\tif (parsed == null) return undefined;\n\n\tlet branch: string | undefined;\n\tlet detach = false;\n\tlet orphan = false;\n\tlet track: boolean | undefined;\n\tfor (const [option, value] of parsed.options) {\n\t\tswitch (option) {\n\t\t\tcase '-b':\n\t\t\tcase '-B':\n\t\t\t\tbranch = value;\n\t\t\t\tbreak;\n\t\t\tcase '-d':\n\t\t\tcase '--detach':\n\t\t\t\tdetach = true;\n\t\t\t\tbreak;\n\t\t\tcase '--orphan':\n\t\t\t\torphan = true;\n\t\t\t\tbreak;\n\t\t\tcase '--track':\n\t\t\t\ttrack = true;\n\t\t\t\tbreak;\n\t\t\tcase '--no-track':\n\t\t\t\ttrack = false;\n\t\t\t\tbreak;\n\t\t}\n\t}\n\n\tconst [path, commitish, ...extra] = parsed.positionals;\n\tif (orphan || path == null || extra.length) return undefined;\n\n\tif (branch) {\n\t\tif (!isLiteralBranchName(branch)) return undefined;\n\n\t\tconst refs = [`refs/heads/${branch}`];\n\t\t// An explicit `--track` writes tracking from a local start point too. Git may also write\n\t\t// `extensions.relativeWorktrees` (under `worktree.useRelativePaths`), which nothing a worktree shows reads, so\n\t\t// the change is still claimed confined: unlike the typed add, a raw run can't evict the config cache unannounced\n\t\tif (track === true || mayWriteTracking(commitish, track === false)) {\n\t\t\treturn { changes: worktreeTrackingChanges, refs: refs, configConfinedToRefs: true };\n\t\t}\n\t\treturn { changes: worktreeChanges, refs: refs };\n\t}\n\tif (detach || (commitish != null && fullShaRegex.test(commitish))) return { changes: worktreeHeadChanges };\n\n\treturn undefined;\n}\n\nconst noOptions: ReadonlySet<string> = new Set();\nconst worktreeForceFlags: ReadonlySet<string> = new Set(['-f', '--force']);\nconst worktreeLockValued: ReadonlySet<string> = new Set(['--reason']);\n\n/** The `worktree` subcommands that act on worktrees argv names: their option tables and how many positionals they take */\nconst worktreePathSubcommands: Readonly<\n\tRecord<string, readonly [flags: ReadonlySet<string>, valued: ReadonlySet<string>, min: number, max: number]>\n> = {\n\tadd: [worktreeAddFlags, worktreeAddValued, 1, 2],\n\tremove: [worktreeForceFlags, noOptions, 1, 1],\n\tlock: [noOptions, worktreeLockValued, 1, 1],\n\tunlock: [noOptions, noOptions, 1, 1],\n\tmove: [worktreeForceFlags, noOptions, 2, 2],\n};\n\n/** See {@link CommandChanges.worktreePaths}; an `add`'s second positional is its commit-ish, not a path */\nfunction getWorktreePaths(args: readonly string[]): readonly string[] | undefined {\n\tconst [subcommand, ...rest] = args;\n\tconst spec = subcommand != null ? worktreePathSubcommands[subcommand] : undefined;\n\tif (spec == null) return undefined;\n\n\tconst [flags, valued, min, max] = spec;\n\tconst positionals = parseArgs(rest, flags, valued)?.positionals;\n\tif (positionals == null || positionals.length < min || positionals.length > max) return undefined;\n\n\treturn subcommand === 'move' ? positionals : positionals.slice(0, 1);\n}\n\nconst checkoutFlags: ReadonlySet<string> = new Set([\n\t'-q',\n\t'--quiet',\n\t'-f',\n\t'--force',\n\t'--detach',\n\t'--no-track',\n\t'-m',\n\t'--merge',\n\t'--progress',\n\t'--no-progress',\n\t'--ignore-other-worktrees',\n\t'--overwrite-ignore',\n\t'--no-overwrite-ignore',\n\t'--recurse-submodules',\n\t'--no-recurse-submodules',\n]);\nconst checkoutValued: ReadonlySet<string> = new Set(['-b', '-B']);\nconst switchFlags: ReadonlySet<string> = new Set([...checkoutFlags, '-d', '--discard-changes']);\nconst switchValued: ReadonlySet<string> = new Set(['-c', '-C', '--create', '--force-create']);\n\n/**\n * `checkout`/`switch` moves no existing branch, so the only shared ref it writes is one it creates: the `-b`/`-c` one\n * it names, or the one git DWIMs from a remote branch named like its lone argument. A detached or full-SHA checkout\n * creates none, and a pathspec checkout writes only the index and working tree.\n */\nfunction getCheckoutChanges(verb: 'checkout' | 'switch', args: readonly string[]): NamedChanges | undefined {\n\tconst parsed =\n\t\tverb === 'switch' ? parseArgs(args, switchFlags, switchValued) : parseArgs(args, checkoutFlags, checkoutValued);\n\tif (parsed == null) return undefined;\n\n\tlet branch: string | undefined;\n\tlet detach = false;\n\tlet noTrack = false;\n\tfor (const [option, value] of parsed.options) {\n\t\tif (value != null) {\n\t\t\tbranch = value;\n\t\t} else if (option === '-d' || option === '--detach') {\n\t\t\tdetach = true;\n\t\t} else if (option === '--no-track') {\n\t\t\tnoTrack = true;\n\t\t}\n\t}\n\n\tconst { positionals, dashDash } = parsed;\n\tconst revs = dashDash == null ? positionals : positionals.slice(0, dashDash);\n\tconst hasPaths = dashDash != null && dashDash < positionals.length;\n\tif (branch != null) {\n\t\tif (hasPaths || revs.length > 1 || !isLiteralBranchName(branch)) return undefined;\n\n\t\tconst refs = [`refs/heads/${branch}`];\n\t\tif (mayWriteTracking(revs[0], noTrack)) {\n\t\t\treturn { changes: checkoutTrackingChanges, refs: refs, configConfinedToRefs: true };\n\t\t}\n\t\treturn { changes: checkoutChanges, refs: refs };\n\t}\n\tif (hasPaths) return verb === 'checkout' ? { changes: indexChanges } : undefined;\n\tif (revs.length > 1) return undefined;\n\tif (detach) return { changes: headIndexChanges };\n\n\tconst [rev] = revs;\n\tif (rev == null || rev === '-' || rev.startsWith('@{-')) return undefined;\n\tif (fullShaRegex.test(rev)) return { changes: headIndexChanges };\n\n\t// A path, an existing ref, or a branch git DWIMs from a remote branch, tracking it from its own config section\n\treturn { changes: checkoutTrackingChanges, refs: [`refs/heads/${rev}`], configConfinedToRefs: true };\n}\n\n/**\n * A stash write moves only `refs/stash` (or its reflog, the rest of the list), save `branch`, which also creates the\n * branch it names from a commit and checks it out; `apply` moves no ref\n */\nfunction getStashChanges(subcommand: string | undefined, rest: readonly string[]): NamedChanges | undefined {\n\tswitch (subcommand) {\n\t\tcase 'branch': {\n\t\t\tconst name = rest[1];\n\t\t\tif (!name || name.startsWith('-') || !isLiteralBranchName(name)) return undefined;\n\n\t\t\treturn { changes: stashBranchChanges, refs: [`refs/heads/${name}`, ...stashRefs] };\n\t\t}\n\t\tcase undefined:\n\t\tcase 'push':\n\t\tcase 'save':\n\t\tcase 'pop':\n\t\t\treturn { changes: stashIndexChanges, refs: stashRefs };\n\t\tcase 'drop':\n\t\tcase 'clear':\n\t\tcase 'store':\n\t\t\treturn { changes: stashChanges, refs: stashRefs };\n\t\tcase 'apply':\n\t\t\treturn { changes: indexChanges };\n\t\tdefault:\n\t\t\t// A bare `stash` with options is a push\n\t\t\treturn subcommand.startsWith('-') ? { changes: stashIndexChanges, refs: stashRefs } : undefined;\n\t}\n}\n\n/** A `reset` given paths, or `-p`, restores index entries and moves no ref */\nfunction isPathspecReset(args: readonly string[]): boolean {\n\tconst dashDash = args.indexOf('--');\n\tif (dashDash >= 0 && dashDash < args.length - 1) return true;\n\n\treturn args.some(\n\t\targ =>\n\t\t\targ === '-p' ||\n\t\t\targ === '--patch' ||\n\t\t\targ === '--pathspec-from-file' ||\n\t\t\targ.startsWith('--pathspec-from-file='),\n\t);\n}\n\nconst falseConfigValues: ReadonlySet<string> = new Set(['false', 'no', 'off', '0', '']);\n\n/**\n * The `rebase` options that take the refs it writes out of argv's hands: the update-refs list was fixed when the\n * rebase started, whatever this argv says, an interactive or `--exec` todo list can write any ref, and `--update-refs`\n * spelled any other way than in full turns update-refs on\n */\nconst unprovableRebaseOptions: readonly string[] = [\n\t'--continue',\n\t'--skip',\n\t'--edit-todo',\n\t'--interactive',\n\t'--exec',\n\t'--update-refs',\n];\n\n/**\n * Whether `arg` is one of {@link unprovableRebaseOptions}, `-i` or `-x`, however git lets it be written: any unique\n * prefix of a long option, before any `=<value>` (`--cont`, `--update-ref`, `--exe=make`), and short ones bundled\n * (`-ri`, `-xmake`)\n */\nfunction isUnprovableRebaseOption(arg: string): boolean {\n\tif (arg.startsWith('--')) {\n\t\tconst name = arg.split('=', 1)[0];\n\t\treturn name.length > 2 && unprovableRebaseOptions.some(o => o.startsWith(name));\n\t}\n\treturn arg.length > 1 && arg.startsWith('-') && /[ix]/.test(arg.slice(1));\n}\n\n/**\n * Whether a `rebase` moves only the branch being rebased. Update-refs would rewrite every branch in the rebased range,\n * so it must be provably off: the last of `--update-refs`/`--no-update-refs`, else the last `-c rebase.updateRefs`\n * before the verb. An interactive or `--exec` rebase can write any ref from its todo list. Git writes the listed refs\n * only when the rebase finishes, so an abort or quit moves none.\n */\nfunction isHeadBranchRebase(command: LeadingCommand): boolean {\n\tlet off: boolean | undefined;\n\tfor (const arg of command.rest) {\n\t\tif (arg === '--' || arg === '--end-of-options') break;\n\n\t\tif (arg === '--abort' || arg === '--quit') return true;\n\n\t\tif (arg === '--no-update-refs') {\n\t\t\toff = true;\n\t\t} else if (arg === '--update-refs') {\n\t\t\toff = false;\n\t\t} else if (isUnprovableRebaseOption(arg)) {\n\t\t\treturn false;\n\t\t}\n\t}\n\tif (off != null) return off;\n\n\tfor (const config of command.configs ?? []) {\n\t\tconst separator = config.indexOf('=');\n\t\tconst key = separator < 0 ? config : config.slice(0, separator);\n\t\tif (key.toLowerCase() !== 'rebase.updaterefs') continue;\n\n\t\t// A bare `-c key` is git's `true`\n\t\toff = separator >= 0 && falseConfigValues.has(config.slice(separator + 1).toLowerCase());\n\t}\n\treturn off ?? false;\n}\n\n/** Verbs that move only the branch HEAD is on, or none from a detached HEAD */\nconst headBranchVerbs: ReadonlySet<string> = new Set(['commit', 'merge', 'cherry-pick', 'revert', 'am']);\n\n/**\n * What argv proves more precisely than {@link changesByVerb}: the refs a write moved, or fewer kinds. `undefined`\n * keeps the verb's table entry; `null` means the write moved nothing cached.\n */\nfunction getNamedChanges(command: LeadingCommand): NamedChanges | null | undefined {\n\tswitch (command.verb) {\n\t\tcase 'update-ref':\n\t\t\treturn getUpdateRefChanges(command.rest);\n\t\tcase 'branch':\n\t\t\treturn getBranchChanges(command.rest);\n\t\tcase 'tag':\n\t\t\treturn getTagChanges(command.rest);\n\t\tcase 'worktree':\n\t\t\treturn getWorktreeChanges(command.rest);\n\t\tcase 'checkout':\n\t\tcase 'switch':\n\t\t\treturn getCheckoutChanges(command.verb, command.rest);\n\t\tcase 'stash':\n\t\t\treturn getStashChanges(command.subcommand, command.rest);\n\t\tcase 'reset':\n\t\t\tif (isPathspecReset(command.rest)) return { changes: indexChanges };\n\n\t\t\treturn { changes: changesByVerb.reset, movesHeadBranch: true };\n\t\tcase 'rebase':\n\t\t\tif (!isHeadBranchRebase(command)) return undefined;\n\n\t\t\treturn { changes: changesByVerb.rebase, movesHeadBranch: true };\n\t\tdefault:\n\t\t\tif (!headBranchVerbs.has(command.verb)) return undefined;\n\n\t\t\treturn { changes: changesByVerb[command.verb], movesHeadBranch: true };\n\t}\n}\n\n/**\n * Classifies a raw git argv for the notification `git.run`'s `notify: 'infer'` applies after the run\n * settles. Returns `undefined` for a command with nothing to announce — read-only, object-only, or a write to a\n * ref nothing cached reads — otherwise the {@link RepositoryChange} kinds it announces, the refs it names when argv\n * proves them, the `-C` re-scope target (if any), and which of those kinds every worktree sees.\n */\nexport function getChangesForCommand(args: readonly string[]): CommandChanges | undefined {\n\tconst command = leadingCommand(args);\n\tif (command.readOnly || objectOnlyVerbs.has(command.verb)) return undefined;\n\n\tconst named = getNamedChanges(command);\n\tif (named === null) return undefined;\n\n\tlet changes = named?.changes;\n\tif (changes == null) {\n\t\tif (command.verb === 'worktree') {\n\t\t\tchanges = worktreeChanges;\n\t\t} else if (command.verb === 'branch' && hasOption(command.rest, branchConfigOptions)) {\n\t\t\tchanges = branchConfigChanges;\n\t\t} else {\n\t\t\tchanges = changesByVerb[command.verb] ?? emptyChanges;\n\t\t}\n\t}\n\tconst result: CommandChanges = {\n\t\t...named,\n\t\tchanges: changes,\n\t\tpathOverride: command.pathOverride,\n\t\tsharedChanges: changes.filter(c => worktreeSharedChanges.has(c)),\n\t};\n\tif (command.verb === 'worktree') {\n\t\tconst worktreePaths = getWorktreePaths(command.rest);\n\t\tif (worktreePaths != null) {\n\t\t\tresult.worktreePaths = worktreePaths;\n\t\t}\n\t}\n\treturn result;\n}\n"],"mappings":";;;;;;;;;AAUA,MAAM,gCAAgB,IAAI,IAAI;CAC7B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAEA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACD,CAAC;AAED,MAAM,yCAA8C,IAAI,IAAI;CAAC;CAAU;CAAU;AAAM,CAAC;;;;;AAMxF,MAAM,sBAAqE;CAC1E,wBAAQ,IAAI,IAAI;EACf;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACD,CAAC;CACD,wBAAQ,IAAI,IAAI,CAAC,OAAO,MAAM,CAAC;CAC/B,uBAAO,IAAI,IAAI;EAAC;EAAI;EAAQ;EAAQ;CAAS,CAAC;CAE9C,uBAAO,IAAI,IAAI;EAAC;EAAQ;EAAQ;CAAQ,CAAC;CACzC,qBAAK,IAAI,IAAI;EACZ;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACD,CAAC;CACD,0BAAU,IAAI,IAAI,CAAC,MAAM,CAAC;CAC1B,wBAAQ,IAAI,IAAI;EAAC;EAAI;EAAM;EAAW;CAAM,CAAC;AAC9C;;;;;AAMA,MAAM,eAA4D;CACjE,QAAQ;EACP;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;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IAAI,QAAQ,SAAS,YACpB,UAAU;OACJ,IAAI,QAAQ,SAAS,YAAY,UAAU,QAAQ,MAAM,mBAAmB,GAClF,UAAU;OAEV,UAAU,cAAc,QAAQ,SAAS;CAE3C;CACA,MAAM,SAAyB;EAC9B,GAAG;EACM;EACT,cAAc,QAAQ;EACtB,eAAe,QAAQ,QAAO,MAAK,sBAAsB,IAAI,CAAC,CAAC;CAChE;CACA,IAAI,QAAQ,SAAS,YAAY;EAChC,MAAM,gBAAgB,iBAAiB,QAAQ,IAAI;EACnD,IAAI,iBAAiB,MACpB,OAAO,gBAAgB;CAEzB;CACA,OAAO;AACR"}
1
+ {"version":3,"file":"commandClassifier.js","names":[],"sources":["../../../../git-cli/src/exec/commandClassifier.ts"],"sourcesContent":["import { isAbsolute, join } from 'node:path';\nimport type { RepositoryChange } from '@gitlens/git/models/repository.js';\nimport { getRefChangeKind } from '@gitlens/git/watching/changeEvent.js';\n\n/**\n * Verbs that never move a ref, the index or the working tree, so a raw run needs no notification.\n * Anything not listed is treated as a mutation: a needless notification costs a full cache eviction, a\n * missed one serves stale state. Object-writing plumbing (`hash-object -w`, `mktree`, `commit-tree`,\n * `write-tree`) is listed too: it only adds loose objects nothing cached observes.\n */\nconst readOnlyVerbs = new Set([\n\t'annotate',\n\t'archive',\n\t'blame',\n\t'cat-file',\n\t'check-attr',\n\t'check-ignore',\n\t'check-mailmap',\n\t'check-ref-format',\n\t'cherry',\n\t'commit-tree',\n\t'count-objects',\n\t'describe',\n\t'diff',\n\t'diff-files',\n\t'diff-index',\n\t'diff-tree',\n\t'for-each-ref',\n\t'fsck',\n\t'grep',\n\t'hash-object',\n\t'help',\n\t'log',\n\t'ls-files',\n\t// Asks a remote what it has; nothing local moves.\n\t'ls-remote',\n\t'ls-tree',\n\t'merge-base',\n\t'merge-tree',\n\t'mktree',\n\t'name-rev',\n\t'patch-id',\n\t'range-diff',\n\t'rev-list',\n\t'rev-parse',\n\t'shortlog',\n\t'show',\n\t'show-branch',\n\t'show-ref',\n\t'status',\n\t'var',\n\t'verify-commit',\n\t'verify-pack',\n\t'verify-tag',\n\t'version',\n\t'whatchanged',\n\t'write-tree',\n]);\n\nconst reflogWriteSubcommands: ReadonlySet<string> = new Set(['expire', 'delete', 'drop']);\n\n/**\n * Sub-commands of otherwise-mutating verbs that only list. `''` is the bare verb, which lists for `branch`,\n * `tag`, `remote` and `notes`; `branch -v` and every `tag` filter imply git's own list mode.\n */\nconst readOnlySubcommands: Readonly<Record<string, ReadonlySet<string>>> = {\n\tbranch: new Set([\n\t\t'',\n\t\t'-l',\n\t\t'--list',\n\t\t'--show-current',\n\t\t'-a',\n\t\t'-r',\n\t\t'-v',\n\t\t'-vv',\n\t\t'--verbose',\n\t\t'--contains',\n\t\t'--no-contains',\n\t\t'--merged',\n\t\t'--no-merged',\n\t\t'--points-at',\n\t]),\n\tconfig: new Set(['get', 'list']),\n\tnotes: new Set(['', 'list', 'show', 'get-ref']),\n\t// `stash create` writes a commit object and prints it; no ref moves\n\tstash: new Set(['list', 'show', 'create']),\n\ttag: new Set([\n\t\t'',\n\t\t'-l',\n\t\t'--list',\n\t\t'-n',\n\t\t'-v',\n\t\t'--verify',\n\t\t'--contains',\n\t\t'--no-contains',\n\t\t'--merged',\n\t\t'--no-merged',\n\t\t'--points-at',\n\t]),\n\tworktree: new Set(['list']),\n\tremote: new Set(['', '-v', 'get-url', 'show']),\n};\n\n/**\n * Options that make an argv write whatever else it contains, checked across the whole argv rather than\n * only its first token: `branch -r -d origin/x` leads with a listing flag and still deletes.\n */\nconst writeOptions: Readonly<Record<string, readonly string[]>> = {\n\tbranch: [\n\t\t'-d',\n\t\t'-D',\n\t\t'--delete',\n\t\t'-m',\n\t\t'-M',\n\t\t'--move',\n\t\t'-c',\n\t\t'-C',\n\t\t'--copy',\n\t\t'-f',\n\t\t'--force',\n\t\t'-t',\n\t\t'--track',\n\t\t'--no-track',\n\t\t'-u',\n\t\t'--set-upstream-to',\n\t\t'--unset-upstream',\n\t\t'--edit-description',\n\t],\n\tconfig: [\n\t\t'--add',\n\t\t'--replace-all',\n\t\t'--unset',\n\t\t'--unset-all',\n\t\t'--rename-section',\n\t\t'--remove-section',\n\t\t'-e',\n\t\t'--edit',\n\t],\n};\n\nconst configReadOptions = new Set([\n\t'--get',\n\t'--get-all',\n\t'--get-regexp',\n\t'--get-urlmatch',\n\t'--get-color',\n\t'--get-colorbool',\n\t'--list',\n\t'-l',\n]);\n\nfunction hasWriteOption(verb: string, rest: readonly string[]): boolean {\n\tconst options = writeOptions[verb];\n\tif (options == null) return false;\n\treturn hasOption(rest, options);\n}\n\nfunction hasOption(rest: readonly string[], options: readonly string[]): boolean {\n\treturn rest.some(arg => options.some(opt => arg === opt || arg.startsWith(`${opt}=`)));\n}\n\n/**\n * `config <key>` with nothing after the key is git's own read form, as is any `--get*`/`--list`. `config edit`\n * (git 2.46's subcommand form of `--edit`) also has a single non-flag argument but writes.\n */\nfunction isConfigRead(rest: readonly string[]): boolean {\n\tif (rest[0] === 'edit') return false;\n\tif (rest.some(arg => configReadOptions.has(arg))) return true;\n\n\treturn rest.filter(arg => !arg.startsWith('-')).length === 1;\n}\n\n/**\n * Global options whose value is the next argument, so the verb scan must skip both. A missing one makes the scan\n * take its value for the verb and stop there, missing any `-C`, `--git-dir` or `--work-tree` git still reads after it.\n */\nconst globalOptionsWithValue = new Set([\n\t'-c',\n\t'--attr-source',\n\t'--config-env',\n\t'--git-dir',\n\t'--namespace',\n\t'--shallow-file',\n\t'--super-prefix',\n\t'--work-tree',\n]);\n\nexport interface LeadingCommand {\n\tverb: string;\n\treadOnly: boolean;\n\t/** The first token after the verb, unresolved — used for subcommand-shaped decisions (`worktree add`). */\n\tsubcommand?: string;\n\t/** Every token after the verb */\n\trest: readonly string[];\n\t/** The `-C <path>` target when the caller re-scopes the command to another working tree. */\n\tpathOverride?: string;\n\t/** Each `-c <key>[=<value>]` given before the verb, in order */\n\tconfigs?: readonly string[];\n\t/** The last `--git-dir <path>` / `--git-dir=<path>` given before the verb, unresolved */\n\tgitDir?: string;\n\t/** The last `--work-tree <path>` / `--work-tree=<path>` given before the verb, unresolved */\n\tworkTree?: string;\n}\n\n/** What {@link scanLeadingOptions} found in the global options git accepts before the verb */\nexport interface LeadingOptions {\n\t/** The `-C <path>` target, each `-C` joined onto the one before it */\n\tpathOverride?: string;\n\t/** The last `--git-dir <path>` / `--git-dir=<path>`, unresolved */\n\tgitDir?: string;\n\t/** The last `--work-tree <path>` / `--work-tree=<path>`, unresolved */\n\tworkTree?: string;\n\t/** Each `-c <key>[=<value>]`, in order; collected only for a classifying scan */\n\tconfigs?: readonly string[];\n\t/**\n\t * Where the first non-option token sits in the combined sequence (its length when there is none), except that a\n\t * scan without `classify` that found nothing moving the repository answers -1, so that common run allocates no result\n\t */\n\tverbIndex: number;\n}\n\n/** Shared by every scan that found nothing, so the common run allocates no result */\nconst noLeadingOptions: LeadingOptions = Object.freeze({ verbIndex: -1 });\n\n/** The index of the first defined token at or after `i` in `first` followed by `second`, or their combined length */\nfunction nextToken(\n\tfirst: readonly (string | undefined)[] | undefined,\n\tsecond: readonly (string | undefined)[],\n\ti: number,\n): number {\n\tconst firstLength = first?.length ?? 0;\n\tconst total = firstLength + second.length;\n\twhile (i < total && (i < firstLength ? first![i] : second[i - firstLength]) == null) {\n\t\ti++;\n\t}\n\treturn i;\n}\n\n/**\n * Walks the global options (`-c key=val`, `-C path`, `--git-dir`, `--work-tree`) git accepts before the verb,\n * over `first` then `second` as one sequence with `undefined` tokens skipped, and stops at the first non-option\n * token. Git honours these only ahead of the verb, so a later `-C 3` (grep's context) or a pathspec named like an\n * option is never a global option; every consumer shares this one walk so none can drift from how git reads them.\n *\n * With `classify` it also collects the `-c` configs and always returns a result carrying the verb's position;\n * without it the walk allocates nothing unless a global option moves the repository.\n */\nexport function scanLeadingOptions(\n\tfirst: readonly (string | undefined)[] | undefined,\n\tsecond: readonly (string | undefined)[],\n\tclassify: boolean,\n): LeadingOptions {\n\tconst firstLength = first?.length ?? 0;\n\tconst total = firstLength + second.length;\n\n\tlet pathOverride: string | undefined;\n\tlet configs: string[] | undefined;\n\tlet gitDir: string | undefined;\n\tlet workTree: string | undefined;\n\n\tlet i = nextToken(first, second, 0);\n\twhile (i < total) {\n\t\tconst arg = (i < firstLength ? first![i] : second[i - firstLength])!;\n\t\tif (arg === '-C') {\n\t\t\t// git applies each `-C` relative to the one before it\n\t\t\tconst valueIndex = nextToken(first, second, i + 1);\n\t\t\tif (valueIndex < total) {\n\t\t\t\tconst path = (valueIndex < firstLength ? first![valueIndex] : second[valueIndex - firstLength])!;\n\t\t\t\tpathOverride = pathOverride == null || isAbsolute(path) ? path : join(pathOverride, path);\n\t\t\t}\n\t\t\ti = nextToken(first, second, valueIndex + 1);\n\n\t\t\tcontinue;\n\t\t}\n\t\tif (globalOptionsWithValue.has(arg)) {\n\t\t\tconst valueIndex = nextToken(first, second, i + 1);\n\t\t\tif (valueIndex < total) {\n\t\t\t\tconst value = (valueIndex < firstLength ? first![valueIndex] : second[valueIndex - firstLength])!;\n\t\t\t\tif (arg === '-c') {\n\t\t\t\t\tif (classify) {\n\t\t\t\t\t\t(configs ??= []).push(value);\n\t\t\t\t\t}\n\t\t\t\t} else if (arg === '--git-dir') {\n\t\t\t\t\tgitDir = value;\n\t\t\t\t} else if (arg === '--work-tree') {\n\t\t\t\t\tworkTree = value;\n\t\t\t\t}\n\t\t\t}\n\t\t\ti = nextToken(first, second, valueIndex + 1);\n\n\t\t\tcontinue;\n\t\t}\n\t\tif (arg.startsWith('-')) {\n\t\t\tif (arg.startsWith('--git-dir=')) {\n\t\t\t\tgitDir = arg.slice('--git-dir='.length);\n\t\t\t} else if (arg.startsWith('--work-tree=')) {\n\t\t\t\tworkTree = arg.slice('--work-tree='.length);\n\t\t\t}\n\t\t\ti = nextToken(first, second, i + 1);\n\n\t\t\tcontinue;\n\t\t}\n\t\tbreak;\n\t}\n\n\tif (!classify && pathOverride == null && gitDir == null && workTree == null) return noLeadingOptions;\n\n\treturn { pathOverride: pathOverride, gitDir: gitDir, workTree: workTree, configs: configs, verbIndex: i };\n}\n\n/**\n * Skips the global options (`-c key=val`, `-C path`) git accepts before the verb to find it, and notes a\n * `-C` re-scope so notification targets that tree, and any `--git-dir` / `--work-tree` that moves the repository.\n */\nexport function leadingCommand(args: readonly string[]): LeadingCommand {\n\tconst { pathOverride, configs, gitDir, workTree, verbIndex: i } = scanLeadingOptions(undefined, args, true);\n\tconst verb = args[i] ?? '';\n\tconst rest = args.slice(i + 1);\n\tconst readOnly =\n\t\t!hasWriteOption(verb, rest) &&\n\t\t(readOnlyVerbs.has(verb) ||\n\t\t\t(readOnlySubcommands[verb]?.has(rest[0] ?? '') ?? false) ||\n\t\t\t(verb === 'config' && isConfigRead(rest)) ||\n\t\t\t// Every `reflog` form reads (bare, `<ref>`, `show`, `list`, `exists`) except the three that rewrite\n\t\t\t// it. Base-branch detection answers \"none\" unless a branch's reflog has exactly one creation entry,\n\t\t\t// so a rewrite can make a cached \"none\" derivable; no change kind names a reflog, so it resets all.\n\t\t\t(verb === 'reflog' && !reflogWriteSubcommands.has(rest[0] ?? '')) ||\n\t\t\t// A bare `symbolic-ref <name>` reads; a second non-flag argument, or a delete, writes.\n\t\t\t(verb === 'symbolic-ref' &&\n\t\t\t\t!rest.includes('-d') &&\n\t\t\t\t!rest.includes('--delete') &&\n\t\t\t\trest.filter(a => !a.startsWith('-')).length < 2));\n\n\treturn {\n\t\tverb: verb,\n\t\treadOnly: readOnly,\n\t\tsubcommand: rest[0],\n\t\trest: rest,\n\t\tpathOverride: pathOverride,\n\t\tconfigs: configs,\n\t\tgitDir: gitDir,\n\t\tworkTree: workTree,\n\t};\n}\n\n/**\n * The change kinds every worktree sharing a `.git` sees: its refs, stash, worktree list, the HEADs of the worktrees\n * it lists (`worktreeHead`, which every other worktree's watcher reports too) and config. The rest a classified verb\n * announces — the tree's own HEAD, the index, a paused operation, FETCH_HEAD — belong to the one tree the command ran\n * in, so a `-C`-scoped write tells the caller's own `cwd` only this subset of what it changed.\n */\nexport const worktreeSharedChanges: ReadonlySet<RepositoryChange> = new Set([\n\t'heads',\n\t'tags',\n\t'stash',\n\t'remotes',\n\t'worktrees',\n\t'worktreeHead',\n\t'config',\n]);\n\n/**\n * Verbs whose effect is confined to the object store that nothing cached observes — repacking or pruning\n * `.git/objects` changes no cached read (branches, refs, status, worktrees, …). `init` and `clone` create a\n * repository rather than mutate a registered one, so there is nothing yet registered to notify.\n */\nconst objectOnlyVerbs = new Set([\n\t'gc',\n\t'repack',\n\t'prune',\n\t'maintenance',\n\t'commit-graph',\n\t'multi-pack-index',\n\t'init',\n\t'clone',\n]);\n\n/**\n * The {@link RepositoryChange} kinds each mutating verb announces. A worktree subcommand other than a\n * listing is handled separately (see {@link getChangesForCommand}), and any verb absent from both this\n * table and {@link objectOnlyVerbs} announces `[]` — the conservative default for an unclassified\n * mutation: the caller still learns something changed, just not what. An entry covers at least what the\n * verb's typed mutator announces; `update-ref` and `symbolic-ref` name every kind their target ref could be.\n * {@link getNamedChanges} narrows the forms whose argv proves what moved, which can announce less: the typed\n * checkout announces `heads` for any target, but a `--detach` or full-SHA checkout moves only this tree's HEAD,\n * no shared ref.\n * The kinds decide which caches the announcement resets, so a verb that can start or end a paused operation\n * names `pausedOp`: `commit` concludes a merge, cherry-pick or revert, `reset` aborts one, and `am` runs in\n * `rebase-apply`.\n */\nconst changesByVerb: Readonly<Record<string, readonly RepositoryChange[]>> = {\n\tcommit: ['head', 'heads', 'index', 'pausedOp'],\n\tam: ['head', 'heads', 'index', 'pausedOp'],\n\tbisect: ['head', 'index', 'worktrees', 'worktreeHead'],\n\tcheckout: ['head', 'heads', 'index', 'worktrees', 'worktreeHead'],\n\tswitch: ['head', 'heads', 'index', 'worktrees', 'worktreeHead'],\n\treset: ['head', 'heads', 'index', 'pausedOp'],\n\tmerge: ['head', 'heads', 'index', 'pausedOp', 'merge'],\n\trebase: ['head', 'heads', 'index', 'pausedOp', 'rebase', 'worktrees', 'worktreeHead'],\n\t'cherry-pick': ['head', 'heads', 'index', 'pausedOp', 'cherryPick'],\n\trevert: ['head', 'heads', 'index', 'pausedOp', 'revert'],\n\tpull: ['head', 'heads', 'index', 'remotes', 'tags', 'lastFetched', 'pausedOp', 'merge', 'rebase'],\n\tadd: ['index'],\n\trm: ['index'],\n\tmv: ['index'],\n\trestore: ['index'],\n\tapply: ['index'],\n\t'read-tree': ['index'],\n\t'update-index': ['index'],\n\tclean: ['index'],\n\tstash: ['stash', 'index'],\n\t'update-ref': ['head', 'heads', 'remotes', 'tags', 'stash'],\n\tbranch: ['heads', 'remotes'],\n\t'symbolic-ref': ['head', 'heads', 'remotes', 'tags'],\n\t'pack-refs': ['heads', 'remotes', 'tags'],\n\ttag: ['tags'],\n\t// A refspec can write a local branch (`fetch origin main:main`), which only the typed fetch parses for\n\tfetch: ['heads', 'remotes', 'tags', 'lastFetched'],\n\tpush: ['remotes'],\n\tremote: ['remotes', 'config'],\n\tconfig: ['config', 'heads', 'remotes'],\n\tnotes: ['heads'],\n};\n\n/**\n * `branch` options that write `.git/config`: a rename, copy or delete moves or drops the branch's section, and the\n * rest set or clear its upstream or description. A plain create (or `-f`) writes tracking only from a remote-tracking\n * start point, which the `.git/config` watcher reports.\n */\nconst branchConfigOptions: readonly string[] = [\n\t'-d',\n\t'-D',\n\t'--delete',\n\t'-m',\n\t'-M',\n\t'--move',\n\t'-c',\n\t'-C',\n\t'--copy',\n\t'-t',\n\t'--track',\n\t'-u',\n\t'--set-upstream-to',\n\t'--unset-upstream',\n\t'--edit-description',\n];\nconst branchConfigChanges: readonly RepositoryChange[] = ['config', 'heads', 'remotes'];\n\n/**\n * Whether creating a branch from `startPoint` may write its tracking to `.git/config`, as git's default\n * `branch.autoSetupMerge=true` does from a remote-tracking start point. Only a name holding a `/` can be one, so a\n * local name with a `/` counts too. The `.git/config` watcher reports what this misses, such as\n * `branch.autoSetupMerge=always`.\n */\nexport function mayWriteTracking(startPoint: string | undefined, noTracking: boolean | undefined): boolean {\n\tif (noTracking || !startPoint) return false;\n\tif (startPoint.startsWith('refs/')) return startPoint.startsWith('refs/remotes/');\n\n\treturn startPoint.includes('/');\n}\n\nconst worktreeChanges: readonly RepositoryChange[] = ['worktrees', 'worktreeHead', 'heads'];\nconst emptyChanges: readonly RepositoryChange[] = [];\n\nexport interface CommandChanges {\n\tchanges: readonly RepositoryChange[];\n\t/** The `-C <path>` target when the caller re-scoped the command to another working tree. */\n\tpathOverride?: string;\n\t/** The subset of {@link changes} every worktree sharing the same `.git` sees, not just the tree the command ran in. */\n\tsharedChanges: readonly RepositoryChange[];\n\t/**\n\t * The full ref names the command creates, moves or deletes, when its argv proves them. A ref kind in\n\t * {@link changes} with a name of its kind here is fully described by those names, as `repository.onChanged`'s\n\t * `refs` are; a ref kind with none stays unnamed.\n\t */\n\trefs?: readonly string[];\n\t/** The command's `config` change touches only the `branch.<name>` sections of the local branches {@link refs} names */\n\tconfigConfinedToRefs?: boolean;\n\t/**\n\t * The command moves only the branch HEAD is on, or no branch when HEAD is detached, so `git.run` reads HEAD\n\t * before and after the run to name it.\n\t */\n\tmovesHeadBranch?: boolean;\n\t/**\n\t * The paths, as argv spells them, of the worktrees a `worktree add`, `remove`, `lock`, `unlock` or `move` acts on: a\n\t * move's source, then its destination. Unset when argv doesn't name them unambiguously.\n\t */\n\tworktreePaths?: readonly string[];\n}\n\ntype NamedChanges = Omit<CommandChanges, 'pathOverride' | 'sharedChanges' | 'worktreePaths'>;\n\nconst configHeadsChanges: readonly RepositoryChange[] = ['config', 'heads'];\nconst headsChanges: readonly RepositoryChange[] = ['heads'];\nconst remotesChanges: readonly RepositoryChange[] = ['remotes'];\nconst tagsChanges: readonly RepositoryChange[] = ['tags'];\nconst stashChanges: readonly RepositoryChange[] = ['stash'];\nconst stashIndexChanges: readonly RepositoryChange[] = ['stash', 'index'];\nconst stashBranchChanges: readonly RepositoryChange[] = [\n\t'head',\n\t'heads',\n\t'index',\n\t'stash',\n\t'worktrees',\n\t'worktreeHead',\n];\nconst indexChanges: readonly RepositoryChange[] = ['index'];\nconst headHeadsChanges: readonly RepositoryChange[] = ['head', 'heads'];\n// A checkout, rebase, bisect or `stash branch` rewrites the tree's HEAD file, which every other worktree's watcher\n// reports as `worktreeHead`: the `worktrees` and `worktreeHead` kinds reach them as shared, so that report is the\n// write's own\nconst headIndexChanges: readonly RepositoryChange[] = ['head', 'index', 'worktrees', 'worktreeHead'];\nconst checkoutChanges: readonly RepositoryChange[] = ['head', 'heads', 'index', 'worktrees', 'worktreeHead'];\nconst checkoutTrackingChanges: readonly RepositoryChange[] = [\n\t'config',\n\t'head',\n\t'heads',\n\t'index',\n\t'worktrees',\n\t'worktreeHead',\n];\nconst worktreeOnlyChanges: readonly RepositoryChange[] = ['worktrees'];\nconst worktreeHeadChanges: readonly RepositoryChange[] = ['worktrees', 'worktreeHead'];\nconst worktreeTrackingChanges: readonly RepositoryChange[] = ['config', 'worktrees', 'worktreeHead', 'heads'];\n\nconst stashRefs: readonly string[] = ['refs/stash'];\n\n/** A full object name, which `checkout` and `worktree add` never DWIM into a new branch */\nconst fullShaRegex = /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/i;\n\n/**\n * Whether a branch name in argv is the branch it names. Git expands `@{-<n>}` (and `@`) wherever it takes a branch\n * name, `branch -d @{-1}` deleting the previous branch, and no ref name can hold `@{` or be `@`\n */\nfunction isLiteralBranchName(name: string): boolean {\n\treturn name !== '@' && !name.includes('@{');\n}\n\ninterface ParsedArgs {\n\t/** Each option in argv order, with its value when it takes one */\n\toptions: readonly (readonly [name: string, value: string | undefined])[];\n\t/** The non-option arguments, including those after `--` */\n\tpositionals: readonly string[];\n\t/** Where `--` fell in {@link positionals}, for the verbs that take pathspecs after it */\n\tdashDash?: number;\n}\n\n/**\n * Splits a verb's arguments by its own option table, since one letter means different things to different verbs\n * (`-m` moves, merges or sets a message). An option outside the table returns `undefined` rather than a guess at\n * whether it takes a value. A valued option accepts `--opt=<v>`, `--opt <v>`, `-o <v>` and `-o<v>`.\n */\nfunction parseArgs(\n\targs: readonly string[],\n\tflags: ReadonlySet<string>,\n\tvalued: ReadonlySet<string>,\n): ParsedArgs | undefined {\n\tconst options: [string, string | undefined][] = [];\n\tconst positionals: string[] = [];\n\tlet dashDash: number | undefined;\n\tlet optionsEnded = false;\n\tfor (let i = 0; i < args.length; i++) {\n\t\tconst arg = args[i];\n\t\t// Still a pathspec separator after `--end-of-options`, as `checkout` and `reset` read it\n\t\tif (arg === '--' && dashDash == null) {\n\t\t\tdashDash = positionals.length;\n\t\t\toptionsEnded = true;\n\t\t\tcontinue;\n\t\t}\n\t\tif (optionsEnded || arg === '-' || !arg.startsWith('-')) {\n\t\t\tpositionals.push(arg);\n\t\t\tcontinue;\n\t\t}\n\t\tif (arg === '--end-of-options') {\n\t\t\toptionsEnded = true;\n\t\t\tcontinue;\n\t\t}\n\t\tif (flags.has(arg)) {\n\t\t\toptions.push([arg, undefined]);\n\t\t\tcontinue;\n\t\t}\n\t\tif (valued.has(arg)) {\n\t\t\tconst value = args[i + 1];\n\t\t\tif (value == null) return undefined;\n\n\t\t\toptions.push([arg, value]);\n\t\t\ti++;\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst long = arg.startsWith('--');\n\t\tconst name = long ? arg.split('=', 1)[0] : arg.slice(0, 2);\n\t\tif (name === arg || !valued.has(name)) return undefined;\n\n\t\toptions.push([name, arg.slice(long ? name.length + 1 : name.length)]);\n\t}\n\treturn { options: options, positionals: positionals, dashDash: dashDash };\n}\n\nfunction hasParsedOption(parsed: ParsedArgs, ...names: string[]): boolean {\n\treturn parsed.options.some(([option]) => names.includes(option));\n}\n\nconst updateRefFlags: ReadonlySet<string> = new Set(['-d', '--delete', '--no-deref', '--create-reflog']);\nconst updateRefValued: ReadonlySet<string> = new Set(['-m', '--message']);\n\n/**\n * `update-ref` moves the one ref it names, or the ref a symbolic one points to without `--no-deref`, so `HEAD` and a\n * remote's `HEAD` stay unnamed. `null` means a ref outside the namespaces core reads, which the typed\n * `updateReference` doesn't announce either. `git log --all` (graph, search, contributors) does walk such a ref when\n * it points at a commit, and argv can't tell that from a blob ref, so a row it adds or drops can stay stale until the\n * next heads change: the trade the typed write makes not to refresh every worktree on each bookkeeping write. A packed\n * ref's delete rewrites `packed-refs`, which the watcher still reports.\n */\nfunction getUpdateRefChanges(args: readonly string[]): NamedChanges | null | undefined {\n\tconst parsed = parseArgs(args, updateRefFlags, updateRefValued);\n\tif (parsed == null) return undefined;\n\n\tconst [ref] = parsed.positionals;\n\tif (!ref) return undefined;\n\tif (ref === 'HEAD') return { changes: headHeadsChanges };\n\tif (!ref.startsWith('refs/')) return undefined;\n\tif (ref.endsWith('/HEAD') && !hasParsedOption(parsed, '--no-deref')) return undefined;\n\n\tconst kind = getRefChangeKind(ref);\n\tif (kind != null) return { changes: [kind], refs: [ref] };\n\t// The watcher reports `refs/replace` as heads, and `notes` announces heads too\n\tif (ref.startsWith('refs/replace/') || ref.startsWith('refs/notes/')) return { changes: headsChanges };\n\n\treturn null;\n}\n\nconst branchFlags: ReadonlySet<string> = new Set([\n\t'-f',\n\t'--force',\n\t'--no-track',\n\t'-d',\n\t'-D',\n\t'--delete',\n\t'-m',\n\t'-M',\n\t'--move',\n\t'-c',\n\t'-C',\n\t'--copy',\n\t'-r',\n\t'--remotes',\n\t'-q',\n\t'--quiet',\n\t'--create-reflog',\n]);\nconst noValuedOptions: ReadonlySet<string> = new Set();\n\n/**\n * The create, delete, rename and copy forms of `branch` name every branch they write. A delete removes a local\n * branch's `branch.<name>` section and a rename or copy moves it; a create writes it only for tracking.\n */\nfunction getBranchChanges(args: readonly string[]): NamedChanges | undefined {\n\tconst parsed = parseArgs(args, branchFlags, noValuedOptions);\n\tif (parsed == null) return undefined;\n\n\tlet mode: 'delete' | 'move' | undefined;\n\tlet remote = false;\n\tlet noTrack = false;\n\tfor (const [option] of parsed.options) {\n\t\tswitch (option) {\n\t\t\tcase '-d':\n\t\t\tcase '-D':\n\t\t\tcase '--delete':\n\t\t\t\tif (mode === 'move') return undefined;\n\n\t\t\t\tmode = 'delete';\n\t\t\t\tbreak;\n\t\t\tcase '-m':\n\t\t\tcase '-M':\n\t\t\tcase '--move':\n\t\t\tcase '-c':\n\t\t\tcase '-C':\n\t\t\tcase '--copy':\n\t\t\t\tif (mode === 'delete') return undefined;\n\n\t\t\t\tmode = 'move';\n\t\t\t\tbreak;\n\t\t\tcase '-r':\n\t\t\tcase '--remotes':\n\t\t\t\tremote = true;\n\t\t\t\tbreak;\n\t\t\tcase '--no-track':\n\t\t\t\tnoTrack = true;\n\t\t\t\tbreak;\n\t\t}\n\t}\n\n\tconst names = parsed.positionals;\n\tif (mode === 'delete') {\n\t\tif (!names.length || !names.every(isLiteralBranchName)) return undefined;\n\t\tif (remote) return { changes: remotesChanges, refs: names.map(n => `refs/remotes/${n}`) };\n\n\t\treturn { changes: configHeadsChanges, refs: names.map(n => `refs/heads/${n}`), configConfinedToRefs: true };\n\t}\n\tif (remote) return undefined;\n\n\tif (mode === 'move') {\n\t\t// With one name, git renames or copies the current branch, which argv doesn't name\n\t\tif (names.length !== 2 || !names.every(isLiteralBranchName)) return undefined;\n\n\t\treturn { changes: configHeadsChanges, refs: names.map(n => `refs/heads/${n}`), configConfinedToRefs: true };\n\t}\n\n\tif ((names.length !== 1 && names.length !== 2) || !isLiteralBranchName(names[0])) return undefined;\n\n\tconst refs = [`refs/heads/${names[0]}`];\n\tif (mayWriteTracking(names[1], noTrack)) {\n\t\treturn { changes: configHeadsChanges, refs: refs, configConfinedToRefs: true };\n\t}\n\treturn { changes: headsChanges, refs: refs };\n}\n\nconst tagFlags: ReadonlySet<string> = new Set([\n\t'-f',\n\t'--force',\n\t'-d',\n\t'--delete',\n\t'-a',\n\t'--annotate',\n\t'-s',\n\t'--sign',\n\t'--no-sign',\n\t'-e',\n\t'--edit',\n\t'--create-reflog',\n]);\nconst tagValued: ReadonlySet<string> = new Set(['-m', '--message', '-F', '--file', '-u', '--local-user', '--cleanup']);\n\nfunction getTagChanges(args: readonly string[]): NamedChanges | undefined {\n\tconst parsed = parseArgs(args, tagFlags, tagValued);\n\tif (parsed == null) return undefined;\n\n\tconst names = parsed.positionals;\n\tif (hasParsedOption(parsed, '-d', '--delete')) {\n\t\tif (!names.length) return undefined;\n\n\t\treturn { changes: tagsChanges, refs: names.map(n => `refs/tags/${n}`) };\n\t}\n\tif (names.length !== 1 && names.length !== 2) return undefined;\n\n\treturn { changes: tagsChanges, refs: [`refs/tags/${names[0]}`] };\n}\n\n/** The `worktree` subcommands besides `add` and `list` (none writes a branch) that delete a worktree's HEAD */\nconst worktreeHeadSubcommands: ReadonlySet<string> = new Set(['remove', 'prune']);\n/** The rest, which touch no worktree's HEAD */\nconst worktreeEditSubcommands: ReadonlySet<string> = new Set(['lock', 'unlock', 'move', 'repair']);\nconst worktreeAddFlags: ReadonlySet<string> = new Set([\n\t'-f',\n\t'--force',\n\t'-d',\n\t'--detach',\n\t'--checkout',\n\t'--no-checkout',\n\t'--lock',\n\t'-q',\n\t'--quiet',\n\t'--track',\n\t'--no-track',\n\t'--guess-remote',\n\t'--no-guess-remote',\n\t'--orphan',\n]);\nconst worktreeAddValued: ReadonlySet<string> = new Set(['-b', '-B', '--reason']);\n\n/**\n * `worktree add` is the only subcommand that can create a branch: the `-b`/`-B` one it names or, without either, one\n * git DWIMs from a short commit-ish (or from the path, given none), which argv can't name. A detached or full-SHA add\n * creates none.\n */\nfunction getWorktreeChanges(args: readonly string[]): NamedChanges | undefined {\n\tconst [subcommand, ...rest] = args;\n\tif (subcommand != null && worktreeEditSubcommands.has(subcommand)) return { changes: worktreeOnlyChanges };\n\tif (subcommand != null && worktreeHeadSubcommands.has(subcommand)) return { changes: worktreeHeadChanges };\n\tif (subcommand !== 'add') return undefined;\n\n\tconst parsed = parseArgs(rest, worktreeAddFlags, worktreeAddValued);\n\tif (parsed == null) return undefined;\n\n\tlet branch: string | undefined;\n\tlet detach = false;\n\tlet orphan = false;\n\tlet track: boolean | undefined;\n\tfor (const [option, value] of parsed.options) {\n\t\tswitch (option) {\n\t\t\tcase '-b':\n\t\t\tcase '-B':\n\t\t\t\tbranch = value;\n\t\t\t\tbreak;\n\t\t\tcase '-d':\n\t\t\tcase '--detach':\n\t\t\t\tdetach = true;\n\t\t\t\tbreak;\n\t\t\tcase '--orphan':\n\t\t\t\torphan = true;\n\t\t\t\tbreak;\n\t\t\tcase '--track':\n\t\t\t\ttrack = true;\n\t\t\t\tbreak;\n\t\t\tcase '--no-track':\n\t\t\t\ttrack = false;\n\t\t\t\tbreak;\n\t\t}\n\t}\n\n\tconst [path, commitish, ...extra] = parsed.positionals;\n\tif (orphan || path == null || extra.length) return undefined;\n\n\tif (branch) {\n\t\tif (!isLiteralBranchName(branch)) return undefined;\n\n\t\tconst refs = [`refs/heads/${branch}`];\n\t\t// An explicit `--track` writes tracking from a local start point too. Git may also write\n\t\t// `extensions.relativeWorktrees` (under `worktree.useRelativePaths`), which nothing a worktree shows reads, so\n\t\t// the change is still claimed confined: unlike the typed add, a raw run can't evict the config cache unannounced\n\t\tif (track === true || mayWriteTracking(commitish, track === false)) {\n\t\t\treturn { changes: worktreeTrackingChanges, refs: refs, configConfinedToRefs: true };\n\t\t}\n\t\treturn { changes: worktreeChanges, refs: refs };\n\t}\n\tif (detach || (commitish != null && fullShaRegex.test(commitish))) return { changes: worktreeHeadChanges };\n\n\treturn undefined;\n}\n\nconst noOptions: ReadonlySet<string> = new Set();\nconst worktreeForceFlags: ReadonlySet<string> = new Set(['-f', '--force']);\nconst worktreeLockValued: ReadonlySet<string> = new Set(['--reason']);\n\n/** The `worktree` subcommands that act on worktrees argv names: their option tables and how many positionals they take */\nconst worktreePathSubcommands: Readonly<\n\tRecord<string, readonly [flags: ReadonlySet<string>, valued: ReadonlySet<string>, min: number, max: number]>\n> = {\n\tadd: [worktreeAddFlags, worktreeAddValued, 1, 2],\n\tremove: [worktreeForceFlags, noOptions, 1, 1],\n\tlock: [noOptions, worktreeLockValued, 1, 1],\n\tunlock: [noOptions, noOptions, 1, 1],\n\tmove: [worktreeForceFlags, noOptions, 2, 2],\n};\n\n/** See {@link CommandChanges.worktreePaths}; an `add`'s second positional is its commit-ish, not a path */\nfunction getWorktreePaths(args: readonly string[]): readonly string[] | undefined {\n\tconst [subcommand, ...rest] = args;\n\tconst spec = subcommand != null ? worktreePathSubcommands[subcommand] : undefined;\n\tif (spec == null) return undefined;\n\n\tconst [flags, valued, min, max] = spec;\n\tconst positionals = parseArgs(rest, flags, valued)?.positionals;\n\tif (positionals == null || positionals.length < min || positionals.length > max) return undefined;\n\n\treturn subcommand === 'move' ? positionals : positionals.slice(0, 1);\n}\n\nconst checkoutFlags: ReadonlySet<string> = new Set([\n\t'-q',\n\t'--quiet',\n\t'-f',\n\t'--force',\n\t'--detach',\n\t'--no-track',\n\t'-m',\n\t'--merge',\n\t'--progress',\n\t'--no-progress',\n\t'--ignore-other-worktrees',\n\t'--overwrite-ignore',\n\t'--no-overwrite-ignore',\n\t'--recurse-submodules',\n\t'--no-recurse-submodules',\n]);\nconst checkoutValued: ReadonlySet<string> = new Set(['-b', '-B']);\nconst switchFlags: ReadonlySet<string> = new Set([...checkoutFlags, '-d', '--discard-changes']);\nconst switchValued: ReadonlySet<string> = new Set(['-c', '-C', '--create', '--force-create']);\n\n/**\n * `checkout`/`switch` moves no existing branch, so the only shared ref it writes is one it creates: the `-b`/`-c` one\n * it names, or the one git DWIMs from a remote branch named like its lone argument. A detached or full-SHA checkout\n * creates none, and a pathspec checkout writes only the index and working tree.\n */\nfunction getCheckoutChanges(verb: 'checkout' | 'switch', args: readonly string[]): NamedChanges | undefined {\n\tconst parsed =\n\t\tverb === 'switch' ? parseArgs(args, switchFlags, switchValued) : parseArgs(args, checkoutFlags, checkoutValued);\n\tif (parsed == null) return undefined;\n\n\tlet branch: string | undefined;\n\tlet detach = false;\n\tlet noTrack = false;\n\tfor (const [option, value] of parsed.options) {\n\t\tif (value != null) {\n\t\t\tbranch = value;\n\t\t} else if (option === '-d' || option === '--detach') {\n\t\t\tdetach = true;\n\t\t} else if (option === '--no-track') {\n\t\t\tnoTrack = true;\n\t\t}\n\t}\n\n\tconst { positionals, dashDash } = parsed;\n\tconst revs = dashDash == null ? positionals : positionals.slice(0, dashDash);\n\tconst hasPaths = dashDash != null && dashDash < positionals.length;\n\tif (branch != null) {\n\t\tif (hasPaths || revs.length > 1 || !isLiteralBranchName(branch)) return undefined;\n\n\t\tconst refs = [`refs/heads/${branch}`];\n\t\tif (mayWriteTracking(revs[0], noTrack)) {\n\t\t\treturn { changes: checkoutTrackingChanges, refs: refs, configConfinedToRefs: true };\n\t\t}\n\t\treturn { changes: checkoutChanges, refs: refs };\n\t}\n\tif (hasPaths) return verb === 'checkout' ? { changes: indexChanges } : undefined;\n\tif (revs.length > 1) return undefined;\n\tif (detach) return { changes: headIndexChanges };\n\n\tconst [rev] = revs;\n\tif (rev == null || rev === '-' || rev.startsWith('@{-')) return undefined;\n\tif (fullShaRegex.test(rev)) return { changes: headIndexChanges };\n\n\t// A path, an existing ref, or a branch git DWIMs from a remote branch, tracking it from its own config section\n\treturn { changes: checkoutTrackingChanges, refs: [`refs/heads/${rev}`], configConfinedToRefs: true };\n}\n\n/**\n * A stash write moves only `refs/stash` (or its reflog, the rest of the list), save `branch`, which also creates the\n * branch it names from a commit and checks it out; `apply` moves no ref\n */\nfunction getStashChanges(subcommand: string | undefined, rest: readonly string[]): NamedChanges | undefined {\n\tswitch (subcommand) {\n\t\tcase 'branch': {\n\t\t\tconst name = rest[1];\n\t\t\tif (!name || name.startsWith('-') || !isLiteralBranchName(name)) return undefined;\n\n\t\t\treturn { changes: stashBranchChanges, refs: [`refs/heads/${name}`, ...stashRefs] };\n\t\t}\n\t\tcase undefined:\n\t\tcase 'push':\n\t\tcase 'save':\n\t\tcase 'pop':\n\t\t\treturn { changes: stashIndexChanges, refs: stashRefs };\n\t\tcase 'drop':\n\t\tcase 'clear':\n\t\tcase 'store':\n\t\t\treturn { changes: stashChanges, refs: stashRefs };\n\t\tcase 'apply':\n\t\t\treturn { changes: indexChanges };\n\t\tdefault:\n\t\t\t// A bare `stash` with options is a push\n\t\t\treturn subcommand.startsWith('-') ? { changes: stashIndexChanges, refs: stashRefs } : undefined;\n\t}\n}\n\n/** A `reset` given paths, or `-p`, restores index entries and moves no ref */\nfunction isPathspecReset(args: readonly string[]): boolean {\n\tconst dashDash = args.indexOf('--');\n\tif (dashDash >= 0 && dashDash < args.length - 1) return true;\n\n\treturn args.some(\n\t\targ =>\n\t\t\targ === '-p' ||\n\t\t\targ === '--patch' ||\n\t\t\targ === '--pathspec-from-file' ||\n\t\t\targ.startsWith('--pathspec-from-file='),\n\t);\n}\n\nconst falseConfigValues: ReadonlySet<string> = new Set(['false', 'no', 'off', '0', '']);\n\n/**\n * The `rebase` options that take the refs it writes out of argv's hands: the update-refs list was fixed when the\n * rebase started, whatever this argv says, an interactive or `--exec` todo list can write any ref, and `--update-refs`\n * spelled any other way than in full turns update-refs on\n */\nconst unprovableRebaseOptions: readonly string[] = [\n\t'--continue',\n\t'--skip',\n\t'--edit-todo',\n\t'--interactive',\n\t'--exec',\n\t'--update-refs',\n];\n\n/**\n * Whether `arg` is one of {@link unprovableRebaseOptions}, `-i` or `-x`, however git lets it be written: any unique\n * prefix of a long option, before any `=<value>` (`--cont`, `--update-ref`, `--exe=make`), and short ones bundled\n * (`-ri`, `-xmake`)\n */\nfunction isUnprovableRebaseOption(arg: string): boolean {\n\tif (arg.startsWith('--')) {\n\t\tconst name = arg.split('=', 1)[0];\n\t\treturn name.length > 2 && unprovableRebaseOptions.some(o => o.startsWith(name));\n\t}\n\treturn arg.length > 1 && arg.startsWith('-') && /[ix]/.test(arg.slice(1));\n}\n\n/**\n * Whether a `rebase` moves only the branch being rebased. Update-refs would rewrite every branch in the rebased range,\n * so it must be provably off: the last of `--update-refs`/`--no-update-refs`, else the last `-c rebase.updateRefs`\n * before the verb. An interactive or `--exec` rebase can write any ref from its todo list. Git writes the listed refs\n * only when the rebase finishes, so an abort or quit moves none.\n */\nfunction isHeadBranchRebase(command: LeadingCommand): boolean {\n\tlet off: boolean | undefined;\n\tfor (const arg of command.rest) {\n\t\tif (arg === '--' || arg === '--end-of-options') break;\n\n\t\tif (arg === '--abort' || arg === '--quit') return true;\n\n\t\tif (arg === '--no-update-refs') {\n\t\t\toff = true;\n\t\t} else if (arg === '--update-refs') {\n\t\t\toff = false;\n\t\t} else if (isUnprovableRebaseOption(arg)) {\n\t\t\treturn false;\n\t\t}\n\t}\n\tif (off != null) return off;\n\n\tfor (const config of command.configs ?? []) {\n\t\tconst separator = config.indexOf('=');\n\t\tconst key = separator < 0 ? config : config.slice(0, separator);\n\t\tif (key.toLowerCase() !== 'rebase.updaterefs') continue;\n\n\t\t// A bare `-c key` is git's `true`\n\t\toff = separator >= 0 && falseConfigValues.has(config.slice(separator + 1).toLowerCase());\n\t}\n\treturn off ?? false;\n}\n\n/** Verbs that move only the branch HEAD is on, or none from a detached HEAD */\nconst headBranchVerbs: ReadonlySet<string> = new Set(['commit', 'merge', 'cherry-pick', 'revert', 'am']);\n\n/**\n * What argv proves more precisely than {@link changesByVerb}: the refs a write moved, or fewer kinds. `undefined`\n * keeps the verb's table entry; `null` means the write moved nothing cached.\n */\nfunction getNamedChanges(command: LeadingCommand): NamedChanges | null | undefined {\n\tswitch (command.verb) {\n\t\tcase 'update-ref':\n\t\t\treturn getUpdateRefChanges(command.rest);\n\t\tcase 'branch':\n\t\t\treturn getBranchChanges(command.rest);\n\t\tcase 'tag':\n\t\t\treturn getTagChanges(command.rest);\n\t\tcase 'worktree':\n\t\t\treturn getWorktreeChanges(command.rest);\n\t\tcase 'checkout':\n\t\tcase 'switch':\n\t\t\treturn getCheckoutChanges(command.verb, command.rest);\n\t\tcase 'stash':\n\t\t\treturn getStashChanges(command.subcommand, command.rest);\n\t\tcase 'reset':\n\t\t\tif (isPathspecReset(command.rest)) return { changes: indexChanges };\n\n\t\t\treturn { changes: changesByVerb.reset, movesHeadBranch: true };\n\t\tcase 'rebase':\n\t\t\tif (!isHeadBranchRebase(command)) return undefined;\n\n\t\t\treturn { changes: changesByVerb.rebase, movesHeadBranch: true };\n\t\tdefault:\n\t\t\tif (!headBranchVerbs.has(command.verb)) return undefined;\n\n\t\t\treturn { changes: changesByVerb[command.verb], movesHeadBranch: true };\n\t}\n}\n\n/**\n * Classifies a raw git argv for the notification `git.run`'s `notify: 'infer'` applies after the run\n * settles. Returns `undefined` for a command with nothing to announce — read-only, object-only, or a write to a\n * ref nothing cached reads — otherwise the {@link RepositoryChange} kinds it announces, the refs it names when argv\n * proves them, the `-C` re-scope target (if any), and which of those kinds every worktree sees.\n */\nexport function getChangesForCommand(args: readonly string[]): CommandChanges | undefined {\n\tconst command = leadingCommand(args);\n\tif (command.readOnly || objectOnlyVerbs.has(command.verb)) return undefined;\n\n\tconst named = getNamedChanges(command);\n\tif (named === null) return undefined;\n\n\tlet changes = named?.changes;\n\tif (changes == null) {\n\t\tif (command.verb === 'worktree') {\n\t\t\tchanges = worktreeChanges;\n\t\t} else if (command.verb === 'branch' && hasOption(command.rest, branchConfigOptions)) {\n\t\t\tchanges = branchConfigChanges;\n\t\t} else {\n\t\t\tchanges = changesByVerb[command.verb] ?? emptyChanges;\n\t\t}\n\t}\n\tconst result: CommandChanges = {\n\t\t...named,\n\t\tchanges: changes,\n\t\tpathOverride: command.pathOverride,\n\t\tsharedChanges: changes.filter(c => worktreeSharedChanges.has(c)),\n\t};\n\tif (command.verb === 'worktree') {\n\t\tconst worktreePaths = getWorktreePaths(command.rest);\n\t\tif (worktreePaths != null) {\n\t\t\tresult.worktreePaths = worktreePaths;\n\t\t}\n\t}\n\treturn result;\n}\n"],"mappings":";;;;;;;;;AAUA,MAAM,gCAAgB,IAAI,IAAI;CAC7B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAEA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA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EACxD,KAAK;GACJ,IAAI,gBAAgB,QAAQ,IAAI,GAAG,OAAO,EAAE,SAAS,aAAa;GAElE,OAAO;IAAE,SAAS,cAAc;IAAO,iBAAiB;GAAK;EAC9D,KAAK;GACJ,IAAI,CAAC,mBAAmB,OAAO,GAAG,OAAO,KAAA;GAEzC,OAAO;IAAE,SAAS,cAAc;IAAQ,iBAAiB;GAAK;EAC/D;GACC,IAAI,CAAC,gBAAgB,IAAI,QAAQ,IAAI,GAAG,OAAO,KAAA;GAE/C,OAAO;IAAE,SAAS,cAAc,QAAQ;IAAO,iBAAiB;GAAK;CACvE;AACD;;;;;;;AAQA,SAAgB,qBAAqB,MAAqD;CACzF,MAAM,UAAU,eAAe,IAAI;CACnC,IAAI,QAAQ,YAAY,gBAAgB,IAAI,QAAQ,IAAI,GAAG,OAAO,KAAA;CAElE,MAAM,QAAQ,gBAAgB,OAAO;CACrC,IAAI,UAAU,MAAM,OAAO,KAAA;CAE3B,IAAI,UAAU,OAAO;CACrB,IAAI,WAAW,MAAM;EACpB,IAAI,QAAQ,SAAS,YACpB,UAAU;OACJ,IAAI,QAAQ,SAAS,YAAY,UAAU,QAAQ,MAAM,mBAAmB,GAClF,UAAU;OAEV,UAAU,cAAc,QAAQ,SAAS;CAE3C;CACA,MAAM,SAAyB;EAC9B,GAAG;EACM;EACT,cAAc,QAAQ;EACtB,eAAe,QAAQ,QAAO,MAAK,sBAAsB,IAAI,CAAC,CAAC;CAChE;CACA,IAAI,QAAQ,SAAS,YAAY;EAChC,MAAM,gBAAgB,iBAAiB,QAAQ,IAAI;EACnD,IAAI,iBAAiB,MACpB,OAAO,gBAAgB;CAEzB;CACA,OAAO;AACR"}
@@ -195,8 +195,35 @@ export interface GitOptions {
195
195
  getEnvironment?: () => Record<string, string | undefined> | undefined;
196
196
  /** Git command timeout in milliseconds, for runs that don't set their own. Defaults to 60000. Set to 0 to disable. */
197
197
  gitTimeout?: number;
198
- /** Returns whether the workspace is currently trusted. Defaults to true when not provided. Called on every exec/stream. */
199
- isTrusted?: () => boolean;
198
+ /**
199
+ * Returns whether git may be run in `repoPath`. Defaults to trusted when not provided. Called on every exec/stream,
200
+ * so it must be cheap; a refusal rejects with `WorkspaceUntrustedError` before any process starts.
201
+ *
202
+ * `repoPath` is the run's `cwd` resolved to an absolute path (so a `..` segment can't lead a path that only starts
203
+ * under a trusted folder out of it) and normalized, and, when the run re-scopes itself with `-C`, that target
204
+ * resolved against `cwd` the same way; an absolute `-C` target is asked about alone, as git applies `-C` before it
205
+ * looks at anything, so `cwd` doesn't matter. A run with no (or an empty) `cwd` executes in the process's working
206
+ * directory, so that is the path asked about; when that folder no longer exists the run is refused, with no path.
207
+ * A run that moves the repository without `-C` is asked about where it moves it too: a leading `--git-dir` (the
208
+ * git dir path itself, so a host that trusts `/repo` sees `/repo/.git` as inside it, and a bare repository at
209
+ * `/srv/x.git` is asked as itself) or `--work-tree`, and `GIT_DIR`, `GIT_COMMON_DIR` or `GIT_WORK_TREE` in the
210
+ * run's own `env` (every key spelling one without regard to case), each resolved against the directory the run
211
+ * ends up in. One refused path refuses the run.
212
+ * A single-workspace host (VS Code) answers for the whole workspace and ignores it; a host serving several
213
+ * repositories answers per path (it should compare normalized paths).
214
+ *
215
+ * Git searches upward from a path for a repository, so answer for the repository git would find there (an
216
+ * enclosing repository's mark counts), not by a bare path-prefix match. A run with no `cwd` (global config reads)
217
+ * is asked about the process's working directory because git discovers a repository from there too; trust that
218
+ * folder unless it is inside a refused repository.
219
+ *
220
+ * Only a return of exactly `true` trusts, so a predicate that returns anything else refuses. Without a predicate
221
+ * every path is trusted.
222
+ *
223
+ * Nothing tells core when an answer changes. A host that starts trusting a path should reset that repository's
224
+ * caches (`hooks.cache.onReset`, or unregister and register it again) so nothing read while it was refused is kept.
225
+ */
226
+ isTrusted?: (repoPath: string) => boolean;
200
227
  /** Queue configuration (max concurrent processes, etc.) */
201
228
  queue?: GitQueueConfig;
202
229
  /** Decodes non-UTF-8 git output. Required when repositories use non-UTF-8 encodings. */
@@ -348,8 +375,25 @@ export declare class Git {
348
375
  supported<T extends GitFeatureOrPrefix>(feature: T): FilteredGitFeatures<T>[] | Promise<FilteredGitFeatures<T>[]>;
349
376
  ensureSupports(feature: GitFeatures, prefix: string, suffix: string): Promise<void>;
350
377
  ensureSupports(feature: GitFeatures, message: GitFeatureUnsupportedMessage): Promise<void>;
378
+ /**
379
+ * Whether git may be run in `repoPath`. Trusted when the host gave no {@link GitOptions.isTrusted}; with one,
380
+ * only an answer of exactly `true` trusts, so a predicate that returns nothing (or anything but a boolean)
381
+ * refuses.
382
+ */
383
+ isPathTrusted(repoPath: string): boolean;
384
+ /** Throws {@link WorkspaceUntrustedError}, carrying `path`, when the host refuses it */
385
+ private assertPathTrusted;
386
+ /**
387
+ * Throws {@link WorkspaceUntrustedError} when the host refuses `cwd` (or the process's working directory when
388
+ * there is none) or any other path the run moves git to: a leading `-C`, a leading `--git-dir` or
389
+ * `--work-tree`, or `GIT_DIR` / `GIT_COMMON_DIR` / `GIT_WORK_TREE` in the run's own `env`. Runs before anything
390
+ * is spawned. A working directory that can't be resolved (the process's own was deleted) refuses without a path.
391
+ */
392
+ private assertTrusted;
351
393
  run(options: ExitCodeOnlyGitCommandOptions, ...args: readonly (string | undefined)[]): Promise<GitResult<unknown>>;
352
394
  run<T extends string | Buffer = string>(options: GitRunOptions, ...args: readonly (string | undefined)[]): Promise<GitResult<T>>;
395
+ /** The body of {@link run} once the trust gate has passed, so a re-entry (`notify`) doesn't ask the host again */
396
+ private runTrusted;
353
397
  /**
354
398
  * Works out, before a `notify`-flagged {@link run} spawns, what it announces once it settles — `undefined` unless
355
399
  * both `notify` and a {@link bindChangeNotifier bound} notifier are present, so an unflagged caller pays nothing.
@@ -8,7 +8,7 @@ import { defer } from "../../utils/promise.js";
8
8
  import { arePathsEqual, dirname as dirname$1, isAbsolute as isAbsolute$1, isDescendant, joinPaths, normalizePath } from "../../utils/path.js";
9
9
  import { GitWarnings, WorkspaceUntrustedError, getGitWarning } from "../../git/errors.js";
10
10
  import { gitFeaturesByVersion } from "../../git/features.js";
11
- import { getChangesForCommand, leadingCommand } from "./commandClassifier.js";
11
+ import { getChangesForCommand, leadingCommand, scanLeadingOptions } from "./commandClassifier.js";
12
12
  import { CancelledRunError, RunError, endStdin, fsExists, runSpawn, spawnProcess } from "../../utils/env/node/exec.js";
13
13
  import { compare, fromString } from "../../utils/version.js";
14
14
  import { EventLoopMonitor } from "./eventLoopMonitor.js";
@@ -421,6 +421,24 @@ function classifySearchError(ex) {
421
421
  if (/unknown revision/i.test(stderr)) return { reason: "invalidRef" };
422
422
  }
423
423
  /**
424
+ * Environment variables that point git at another repository's files: its git dir, the common dir its config and
425
+ * hooks are read from, or its working tree. Upper-case, as the names are compared after upper-casing.
426
+ */
427
+ const repositoryEnvKeys = /* @__PURE__ */ new Set([
428
+ "GIT_DIR",
429
+ "GIT_COMMON_DIR",
430
+ "GIT_WORK_TREE"
431
+ ]);
432
+ /** The longest of {@link repositoryEnvKeys}, so keys that can't match are never upper-cased */
433
+ const repositoryEnvKeyMaxLength = Math.max(...Array.from(repositoryEnvKeys, (k) => k.length));
434
+ /**
435
+ * Whether `path` resolves the same wherever it is resolved from. On Windows a rooted path with no drive (`\x`) takes
436
+ * the drive of the directory it is resolved against.
437
+ */
438
+ function isFullyQualified(path) {
439
+ return isAbsolute$1(path) && (process.platform !== "win32" || !/^[\\/](?![\\/])/.test(path));
440
+ }
441
+ /**
424
442
  * Keys dropped from the INHERITED `process.env` before it seeds the base git environment. git hands these
425
443
  * to anything it launches (a hook, `rebase -x`, an editor invoked as `GIT_EDITOR`) to describe the command
426
444
  * it is running; a host started that way would otherwise run every command against THAT repository with
@@ -615,8 +633,13 @@ var Git = class {
615
633
  _gitLocationPromise;
616
634
  async getLocation() {
617
635
  if (this._gitLocation == null) {
618
- this._gitLocationPromise ??= this._locator();
619
- this._gitLocation = await this._gitLocationPromise;
636
+ const promise = this._gitLocationPromise ??= this._locator();
637
+ try {
638
+ this._gitLocation = await promise;
639
+ } catch (ex) {
640
+ if (this._gitLocationPromise === promise) this._gitLocationPromise = void 0;
641
+ throw ex;
642
+ }
620
643
  }
621
644
  return this._gitLocation;
622
645
  }
@@ -646,16 +669,70 @@ var Git = class {
646
669
  const message = typeof prefixOrMessage === "function" ? prefixOrMessage(version, gitVersion) : `${prefixOrMessage} requires a newer version of Git (>= ${version}) than is currently installed (${gitVersion}).${suffix}`;
647
670
  throw new Error(message);
648
671
  }
672
+ /**
673
+ * Whether git may be run in `repoPath`. Trusted when the host gave no {@link GitOptions.isTrusted}; with one,
674
+ * only an answer of exactly `true` trusts, so a predicate that returns nothing (or anything but a boolean)
675
+ * refuses.
676
+ */
677
+ isPathTrusted(repoPath) {
678
+ const isTrusted = this.options.isTrusted;
679
+ return isTrusted == null || isTrusted(repoPath) === true;
680
+ }
681
+ /** Throws {@link WorkspaceUntrustedError}, carrying `path`, when the host refuses it */
682
+ assertPathTrusted(path) {
683
+ if (!this.isPathTrusted(path)) throw new WorkspaceUntrustedError(path);
684
+ }
685
+ /**
686
+ * Throws {@link WorkspaceUntrustedError} when the host refuses `cwd` (or the process's working directory when
687
+ * there is none) or any other path the run moves git to: a leading `-C`, a leading `--git-dir` or
688
+ * `--work-tree`, or `GIT_DIR` / `GIT_COMMON_DIR` / `GIT_WORK_TREE` in the run's own `env`. Runs before anything
689
+ * is spawned. A working directory that can't be resolved (the process's own was deleted) refuses without a path.
690
+ */
691
+ assertTrusted(cwd, configs, args, env) {
692
+ if (this.options.isTrusted == null) return;
693
+ const { pathOverride, gitDir, workTree } = scanLeadingOptions(configs, args, false);
694
+ let where;
695
+ if (pathOverride != null && isFullyQualified(pathOverride)) {
696
+ where = normalizePath(resolve(pathOverride));
697
+ this.assertPathTrusted(where);
698
+ } else {
699
+ let base;
700
+ try {
701
+ base = normalizePath(resolve(cwd || process.cwd()));
702
+ } catch {
703
+ throw new WorkspaceUntrustedError();
704
+ }
705
+ this.assertPathTrusted(base);
706
+ where = base;
707
+ if (pathOverride != null) {
708
+ where = this.resolveNotifyPath(base, pathOverride);
709
+ if (where !== base) this.assertPathTrusted(where);
710
+ }
711
+ }
712
+ if (gitDir) this.assertPathTrusted(this.resolveNotifyPath(where, gitDir));
713
+ if (workTree) this.assertPathTrusted(this.resolveNotifyPath(where, workTree));
714
+ if (env == null) return;
715
+ for (const key of Object.keys(env)) {
716
+ if (key.length > repositoryEnvKeyMaxLength || !repositoryEnvKeys.has(key.toUpperCase())) continue;
717
+ const path = env[key];
718
+ if (!path) continue;
719
+ this.assertPathTrusted(this.resolveNotifyPath(where, path));
720
+ }
721
+ }
649
722
  async run(options, ...args) {
650
- if (this.options.isTrusted?.() === false) throw new WorkspaceUntrustedError();
723
+ this.assertTrusted(options.cwd, options.configs, args, options.env);
724
+ return this.runTrusted(options, args);
725
+ }
726
+ /** The body of {@link run} once the trust gate has passed, so a re-entry (`notify`) doesn't ask the host again */
727
+ async runTrusted(options, args) {
651
728
  const runArgs = args.filter((a) => a != null);
652
729
  if (options.notify != null) {
653
730
  const pending = await this.prepareNotify(options, runArgs);
654
731
  try {
655
- return await this.run({
732
+ return await this.runTrusted({
656
733
  ...options,
657
734
  notify: void 0
658
- }, ...args);
735
+ }, args);
659
736
  } finally {
660
737
  if (pending != null) await this.applyNotify(pending);
661
738
  }
@@ -958,7 +1035,7 @@ var Git = class {
958
1035
  }
959
1036
  }
960
1037
  async *stream(options, ...args) {
961
- if (this.options.isTrusted?.() === false) throw new WorkspaceUntrustedError();
1038
+ this.assertTrusted(options.cwd, options.configs, args, options.env);
962
1039
  const start = hrtime();
963
1040
  const startEpochMs = Date.now();
964
1041
  const streamId = uniqueCounterForStream.next();
@@ -1091,7 +1168,7 @@ var Git = class {
1091
1168
  */
1092
1169
  async rev_parse__show_toplevel(cwd) {
1093
1170
  let result;
1094
- if (this.options.isTrusted?.() === false) {
1171
+ if (!this.isPathTrusted(cwd)) {
1095
1172
  if (await fsExists(joinPaths(cwd, "HEAD"))) try {
1096
1173
  result = await this.run({
1097
1174
  cwd,
@@ -1120,7 +1197,7 @@ var Git = class {
1120
1197
  return [false];
1121
1198
  }
1122
1199
  const inDotGit = GitWarnings.mustRunInWorkTree.test(ex.stderr ?? "");
1123
- if (inDotGit && this.options.isTrusted?.() !== false) {
1200
+ if (inDotGit && this.isPathTrusted(cwd)) {
1124
1201
  result = await this.run({
1125
1202
  cwd,
1126
1203
  errors: "ignore"
@@ -1158,6 +1235,7 @@ var Git = class {
1158
1235
  async rev_parse__work_tree_of_git_dir(gitDir) {
1159
1236
  const parent = dirname$1(gitDir);
1160
1237
  if (parent === gitDir) return void 0;
1238
+ if (!this.isPathTrusted(parent)) return void 0;
1161
1239
  const result = await this.run({
1162
1240
  cwd: parent,
1163
1241
  errors: "ignore"