@statewalker/vcs-commands 0.13.0 → 0.15.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 (304) hide show
  1. package/dist/commands/add-command.d.ts.map +1 -1
  2. package/dist/commands/add-patch/patch-backend.d.ts +1 -1
  3. package/dist/commands/add-patch/patch-backend.d.ts.map +1 -1
  4. package/dist/commands/archive/archive-command.d.ts +6 -2
  5. package/dist/commands/archive/archive-command.d.ts.map +1 -1
  6. package/dist/commands/archive/remote-archive-command.d.ts +27 -2
  7. package/dist/commands/archive/remote-archive-command.d.ts.map +1 -1
  8. package/dist/commands/archive/upload-archive-writer.d.ts +11 -5
  9. package/dist/commands/archive/upload-archive-writer.d.ts.map +1 -1
  10. package/dist/commands/branch-command.d.ts +14 -2
  11. package/dist/commands/branch-command.d.ts.map +1 -1
  12. package/dist/commands/bundle/bundle-format.d.ts +6 -1
  13. package/dist/commands/bundle/bundle-format.d.ts.map +1 -1
  14. package/dist/commands/bundle/bundle-uri-host.d.ts +12 -1
  15. package/dist/commands/bundle/bundle-uri-host.d.ts.map +1 -1
  16. package/dist/commands/bundle/bundle-uri.d.ts +7 -1
  17. package/dist/commands/bundle/bundle-uri.d.ts.map +1 -1
  18. package/dist/commands/bundle/bundle-verify.d.ts +4 -1
  19. package/dist/commands/bundle/bundle-verify.d.ts.map +1 -1
  20. package/dist/commands/cat-file/batch-format.d.ts +8 -12
  21. package/dist/commands/cat-file/batch-format.d.ts.map +1 -1
  22. package/dist/commands/cat-file/cat-file-command.d.ts +39 -5
  23. package/dist/commands/cat-file/cat-file-command.d.ts.map +1 -1
  24. package/dist/commands/check-ignore-command.d.ts.map +1 -1
  25. package/dist/commands/checkout-command.d.ts +4 -0
  26. package/dist/commands/checkout-command.d.ts.map +1 -1
  27. package/dist/commands/checkout-paths.d.ts +9 -0
  28. package/dist/commands/checkout-paths.d.ts.map +1 -1
  29. package/dist/commands/cherry-pick-command.d.ts +3 -0
  30. package/dist/commands/cherry-pick-command.d.ts.map +1 -1
  31. package/dist/commands/clean-interactive.d.ts +0 -9
  32. package/dist/commands/clean-interactive.d.ts.map +1 -1
  33. package/dist/commands/clone-command.d.ts +17 -0
  34. package/dist/commands/clone-command.d.ts.map +1 -1
  35. package/dist/commands/column/column-config.d.ts +23 -0
  36. package/dist/commands/column/column-config.d.ts.map +1 -0
  37. package/dist/commands/column/column-layout.d.ts +129 -0
  38. package/dist/commands/column/column-layout.d.ts.map +1 -0
  39. package/dist/commands/column/index.d.ts +3 -0
  40. package/dist/commands/column/index.d.ts.map +1 -0
  41. package/dist/commands/column-command.d.ts +59 -0
  42. package/dist/commands/column-command.d.ts.map +1 -0
  43. package/dist/commands/comment-char-config.d.ts +15 -0
  44. package/dist/commands/comment-char-config.d.ts.map +1 -1
  45. package/dist/commands/commit-command.d.ts +30 -2
  46. package/dist/commands/commit-command.d.ts.map +1 -1
  47. package/dist/commands/config-command.d.ts +12 -0
  48. package/dist/commands/config-command.d.ts.map +1 -1
  49. package/dist/commands/credential-helper.d.ts +214 -0
  50. package/dist/commands/credential-helper.d.ts.map +1 -0
  51. package/dist/commands/default-branch.d.ts +33 -3
  52. package/dist/commands/default-branch.d.ts.map +1 -1
  53. package/dist/commands/diff-color-config.d.ts +4 -0
  54. package/dist/commands/diff-color-config.d.ts.map +1 -1
  55. package/dist/commands/diff-command.d.ts +12 -0
  56. package/dist/commands/diff-command.d.ts.map +1 -1
  57. package/dist/commands/fast-export/fast-export-command.d.ts +89 -2
  58. package/dist/commands/fast-export/fast-export-command.d.ts.map +1 -1
  59. package/dist/commands/fast-export/fast-import-command.d.ts +113 -8
  60. package/dist/commands/fast-export/fast-import-command.d.ts.map +1 -1
  61. package/dist/commands/fast-export/fast-stream-support.d.ts +0 -9
  62. package/dist/commands/fast-export/fast-stream-support.d.ts.map +1 -1
  63. package/dist/commands/fetch-command.d.ts +23 -1
  64. package/dist/commands/fetch-command.d.ts.map +1 -1
  65. package/dist/commands/fsck/fsck-object-checks.d.ts.map +1 -1
  66. package/dist/commands/git-hooks.d.ts +31 -3
  67. package/dist/commands/git-hooks.d.ts.map +1 -1
  68. package/dist/commands/history-command.d.ts +173 -7
  69. package/dist/commands/history-command.d.ts.map +1 -1
  70. package/dist/commands/index-host.d.ts +19 -0
  71. package/dist/commands/index-host.d.ts.map +1 -1
  72. package/dist/commands/index-refresh.d.ts +36 -0
  73. package/dist/commands/index-refresh.d.ts.map +1 -0
  74. package/dist/commands/index.d.ts +9 -0
  75. package/dist/commands/index.d.ts.map +1 -1
  76. package/dist/commands/index.js +7 -6
  77. package/dist/commands/init-command.d.ts +20 -0
  78. package/dist/commands/init-command.d.ts.map +1 -1
  79. package/dist/commands/local-transport.d.ts +40 -2
  80. package/dist/commands/local-transport.d.ts.map +1 -1
  81. package/dist/commands/log-command.d.ts +7 -0
  82. package/dist/commands/log-command.d.ts.map +1 -1
  83. package/dist/commands/log-output.d.ts +11 -0
  84. package/dist/commands/log-output.d.ts.map +1 -1
  85. package/dist/commands/ls-tree-command.d.ts +10 -0
  86. package/dist/commands/ls-tree-command.d.ts.map +1 -1
  87. package/dist/commands/maintenance-schedule-command.d.ts +122 -0
  88. package/dist/commands/maintenance-schedule-command.d.ts.map +1 -0
  89. package/dist/commands/merge-command.d.ts +13 -1
  90. package/dist/commands/merge-command.d.ts.map +1 -1
  91. package/dist/commands/merge-index-command.d.ts +42 -0
  92. package/dist/commands/merge-index-command.d.ts.map +1 -0
  93. package/dist/commands/merge-one-file.d.ts +129 -0
  94. package/dist/commands/merge-one-file.d.ts.map +1 -0
  95. package/dist/commands/merge-support.d.ts +40 -4
  96. package/dist/commands/merge-support.d.ts.map +1 -1
  97. package/dist/commands/object-disk-info.d.ts +35 -0
  98. package/dist/commands/object-disk-info.d.ts.map +1 -0
  99. package/dist/commands/octopus-merge.d.ts +3 -3
  100. package/dist/commands/octopus-merge.d.ts.map +1 -1
  101. package/dist/commands/plumbing-input.d.ts.map +1 -1
  102. package/dist/commands/promisor-remote-reply.d.ts +31 -4
  103. package/dist/commands/promisor-remote-reply.d.ts.map +1 -1
  104. package/dist/commands/promisor-remote.d.ts +8 -1
  105. package/dist/commands/promisor-remote.d.ts.map +1 -1
  106. package/dist/commands/pull-command.d.ts +55 -7
  107. package/dist/commands/pull-command.d.ts.map +1 -1
  108. package/dist/commands/push-command.d.ts +18 -1
  109. package/dist/commands/push-command.d.ts.map +1 -1
  110. package/dist/commands/range-diff/range-diff-command.d.ts +37 -1
  111. package/dist/commands/range-diff/range-diff-command.d.ts.map +1 -1
  112. package/dist/commands/rebase-command.d.ts +13 -1
  113. package/dist/commands/rebase-command.d.ts.map +1 -1
  114. package/dist/commands/ref-filter/for-each-ref-command.d.ts +3 -2
  115. package/dist/commands/ref-filter/for-each-ref-command.d.ts.map +1 -1
  116. package/dist/commands/ref-filter/index.d.ts +1 -0
  117. package/dist/commands/ref-filter/index.d.ts.map +1 -1
  118. package/dist/commands/ref-filter/peel-limit.d.ts +8 -0
  119. package/dist/commands/ref-filter/peel-limit.d.ts.map +1 -0
  120. package/dist/commands/ref-filter/ref-filter.d.ts.map +1 -1
  121. package/dist/commands/ref-filter/ref-format.d.ts +26 -1
  122. package/dist/commands/ref-filter/ref-format.d.ts.map +1 -1
  123. package/dist/commands/ref-filter/ref-listing-command.d.ts +9 -0
  124. package/dist/commands/ref-filter/ref-listing-command.d.ts.map +1 -1
  125. package/dist/commands/remote-transport.d.ts +27 -0
  126. package/dist/commands/remote-transport.d.ts.map +1 -1
  127. package/dist/commands/repack-command.d.ts +18 -2
  128. package/dist/commands/repack-command.d.ts.map +1 -1
  129. package/dist/commands/repo-command.d.ts +2 -7
  130. package/dist/commands/repo-command.d.ts.map +1 -1
  131. package/dist/commands/reset-command.d.ts +4 -1
  132. package/dist/commands/reset-command.d.ts.map +1 -1
  133. package/dist/commands/restore-command.d.ts.map +1 -1
  134. package/dist/commands/rev-list-command.d.ts +65 -0
  135. package/dist/commands/rev-list-command.d.ts.map +1 -1
  136. package/dist/commands/revert-command.d.ts +3 -0
  137. package/dist/commands/revert-command.d.ts.map +1 -1
  138. package/dist/commands/revision-filenames.d.ts.map +1 -1
  139. package/dist/commands/revision-range.d.ts +17 -0
  140. package/dist/commands/revision-range.d.ts.map +1 -1
  141. package/dist/commands/revision-resolver.d.ts +12 -0
  142. package/dist/commands/revision-resolver.d.ts.map +1 -1
  143. package/dist/commands/serve-repository.d.ts +21 -4
  144. package/dist/commands/serve-repository.d.ts.map +1 -1
  145. package/dist/commands/served-lazy-fetch.d.ts +61 -0
  146. package/dist/commands/served-lazy-fetch.d.ts.map +1 -0
  147. package/dist/commands/signing.d.ts +37 -4
  148. package/dist/commands/signing.d.ts.map +1 -1
  149. package/dist/commands/split-cmdline.d.ts +6 -0
  150. package/dist/commands/split-cmdline.d.ts.map +1 -0
  151. package/dist/commands/status-color-config.d.ts +33 -0
  152. package/dist/commands/status-color-config.d.ts.map +1 -0
  153. package/dist/commands/status-command.d.ts +15 -0
  154. package/dist/commands/status-command.d.ts.map +1 -1
  155. package/dist/commands/status-format.d.ts +46 -4
  156. package/dist/commands/status-format.d.ts.map +1 -1
  157. package/dist/commands/tag-command.d.ts +15 -1
  158. package/dist/commands/tag-command.d.ts.map +1 -1
  159. package/dist/commands/tree-restore.d.ts +14 -0
  160. package/dist/commands/tree-restore.d.ts.map +1 -1
  161. package/dist/commands/verify-command.d.ts +22 -2
  162. package/dist/commands/verify-command.d.ts.map +1 -1
  163. package/dist/commands/worktree-add-command.d.ts.map +1 -1
  164. package/dist/commands/worktree-overwrite-checks.d.ts +31 -6
  165. package/dist/commands/worktree-overwrite-checks.d.ts.map +1 -1
  166. package/dist/{commands-CPceUCP2.js → commands-DT3VEv50.js} +15168 -16842
  167. package/dist/errors/commit-errors.d.ts +37 -1
  168. package/dist/errors/commit-errors.d.ts.map +1 -1
  169. package/dist/errors/git-api-error.d.ts +6 -0
  170. package/dist/errors/git-api-error.d.ts.map +1 -1
  171. package/dist/errors/index.js +44 -3
  172. package/dist/{fsck-tbrPZX2q.js → fsck-BZ508Elg.js} +2 -2
  173. package/dist/git-command.d.ts +33 -1
  174. package/dist/git-command.d.ts.map +1 -1
  175. package/dist/git.d.ts +104 -1
  176. package/dist/git.d.ts.map +1 -1
  177. package/dist/index.js +8 -7
  178. package/dist/{remote-transport-C0OSJtor.js → local-transport-D98U6p4d.js} +228 -692
  179. package/dist/{maintenance-run-command-UiSIaeP8.js → maintenance-run-command-DZFnbnbo.js} +2366 -108
  180. package/dist/remote-config/remote-config-store.d.ts +6 -0
  181. package/dist/remote-config/remote-config-store.d.ts.map +1 -1
  182. package/dist/remote-transport-zvSqwpOB.js +4865 -0
  183. package/dist/results/cherry-pick-result.d.ts +4 -3
  184. package/dist/results/cherry-pick-result.d.ts.map +1 -1
  185. package/dist/results/diff-output.d.ts +7 -0
  186. package/dist/results/diff-output.d.ts.map +1 -1
  187. package/dist/results/diff-words.d.ts +14 -3
  188. package/dist/results/diff-words.d.ts.map +1 -1
  189. package/dist/results/index.js +1 -1
  190. package/dist/results/line-prefix-sink.d.ts +50 -0
  191. package/dist/results/line-prefix-sink.d.ts.map +1 -0
  192. package/dist/results/merge-result.d.ts +4 -3
  193. package/dist/results/merge-result.d.ts.map +1 -1
  194. package/dist/results/rebase-result.d.ts +5 -0
  195. package/dist/results/rebase-result.d.ts.map +1 -1
  196. package/dist/results/revert-result.d.ts +4 -3
  197. package/dist/results/revert-result.d.ts.map +1 -1
  198. package/dist/{results-CkS1p1CH.js → results-rF81cQse.js} +1788 -247
  199. package/dist/transport-command.d.ts +13 -0
  200. package/dist/transport-command.d.ts.map +1 -1
  201. package/package.json +21 -13
  202. package/src/commands/add-command.ts +15 -2
  203. package/src/commands/add-patch/patch-backend.ts +6 -44
  204. package/src/commands/archive/archive-command.ts +7 -3
  205. package/src/commands/archive/remote-archive-command.ts +45 -4
  206. package/src/commands/archive/upload-archive-writer.ts +34 -22
  207. package/src/commands/branch-command.ts +57 -4
  208. package/src/commands/bundle/bundle-format.ts +10 -2
  209. package/src/commands/bundle/bundle-uri-host.ts +71 -11
  210. package/src/commands/bundle/bundle-uri.ts +11 -4
  211. package/src/commands/bundle/bundle-verify.ts +4 -1
  212. package/src/commands/cat-file/batch-format.ts +17 -18
  213. package/src/commands/cat-file/cat-file-command.ts +182 -48
  214. package/src/commands/check-ignore-command.ts +110 -21
  215. package/src/commands/checkout-command.ts +149 -21
  216. package/src/commands/checkout-index-command.ts +2 -1
  217. package/src/commands/checkout-paths.ts +13 -0
  218. package/src/commands/cherry-pick-command.ts +9 -0
  219. package/src/commands/clean-interactive.ts +20 -74
  220. package/src/commands/clone-command.ts +102 -11
  221. package/src/commands/column/column-config.ts +63 -0
  222. package/src/commands/column/column-layout.ts +396 -0
  223. package/src/commands/column/index.ts +2 -0
  224. package/src/commands/column-command.ts +171 -0
  225. package/src/commands/comment-char-config.ts +42 -0
  226. package/src/commands/commit-command.ts +93 -18
  227. package/src/commands/config-command.ts +28 -0
  228. package/src/commands/credential-helper.ts +807 -0
  229. package/src/commands/default-branch.ts +57 -5
  230. package/src/commands/diff-color-config.ts +23 -10
  231. package/src/commands/diff-command.ts +25 -2
  232. package/src/commands/fast-export/fast-export-command.ts +661 -35
  233. package/src/commands/fast-export/fast-import-command.ts +694 -94
  234. package/src/commands/fast-export/fast-stream-support.ts +18 -1
  235. package/src/commands/fetch-command.ts +116 -16
  236. package/src/commands/fsck/fsck-object-checks.ts +3 -1
  237. package/src/commands/git-hooks.ts +96 -5
  238. package/src/commands/history-command.ts +952 -20
  239. package/src/commands/index-host.ts +51 -0
  240. package/src/commands/index-refresh.ts +121 -0
  241. package/src/commands/index.ts +9 -0
  242. package/src/commands/init-command.ts +57 -4
  243. package/src/commands/legacy-remotes.ts +4 -20
  244. package/src/commands/local-transport.ts +183 -18
  245. package/src/commands/log-command.ts +39 -1
  246. package/src/commands/log-output.ts +31 -4
  247. package/src/commands/ls-tree-command.ts +20 -12
  248. package/src/commands/maintenance-schedule-command.ts +418 -0
  249. package/src/commands/merge-command.ts +42 -8
  250. package/src/commands/merge-index-command.ts +202 -0
  251. package/src/commands/merge-one-file.ts +451 -0
  252. package/src/commands/merge-support.ts +169 -15
  253. package/src/commands/object-disk-info.ts +169 -0
  254. package/src/commands/octopus-merge.ts +37 -128
  255. package/src/commands/plumbing-input.ts +3 -1
  256. package/src/commands/promisor-remote-reply.ts +338 -56
  257. package/src/commands/promisor-remote.ts +39 -6
  258. package/src/commands/pull-command.ts +173 -27
  259. package/src/commands/push-command.ts +55 -6
  260. package/src/commands/range-diff/range-diff-command.ts +86 -3
  261. package/src/commands/read-tree-command.ts +2 -2
  262. package/src/commands/rebase-command.ts +46 -1
  263. package/src/commands/ref-filter/for-each-ref-command.ts +4 -3
  264. package/src/commands/ref-filter/index.ts +1 -0
  265. package/src/commands/ref-filter/peel-limit.ts +7 -0
  266. package/src/commands/ref-filter/ref-filter.ts +68 -7
  267. package/src/commands/ref-filter/ref-format.ts +85 -11
  268. package/src/commands/ref-filter/ref-listing-command.ts +30 -0
  269. package/src/commands/remote-command.ts +2 -2
  270. package/src/commands/remote-transport.ts +66 -3
  271. package/src/commands/repack-command.ts +75 -9
  272. package/src/commands/repo-command.ts +6 -70
  273. package/src/commands/reset-command.ts +11 -1
  274. package/src/commands/restore-command.ts +1 -0
  275. package/src/commands/rev-list-command.ts +205 -3
  276. package/src/commands/revert-command.ts +9 -0
  277. package/src/commands/revision-filenames.ts +32 -4
  278. package/src/commands/revision-range.ts +2 -2
  279. package/src/commands/revision-resolver.ts +21 -1
  280. package/src/commands/serve-repository.ts +42 -11
  281. package/src/commands/served-lazy-fetch.ts +164 -0
  282. package/src/commands/signing.ts +103 -12
  283. package/src/commands/split-cmdline.ts +32 -0
  284. package/src/commands/status-color-config.ts +92 -0
  285. package/src/commands/status-command.ts +50 -2
  286. package/src/commands/status-format.ts +198 -50
  287. package/src/commands/tag-command.ts +57 -2
  288. package/src/commands/tree-restore.ts +17 -0
  289. package/src/commands/verify-command.ts +84 -12
  290. package/src/commands/worktree-add-command.ts +2 -0
  291. package/src/commands/worktree-overwrite-checks.ts +75 -14
  292. package/src/errors/commit-errors.ts +52 -2
  293. package/src/errors/git-api-error.ts +7 -0
  294. package/src/git-command.ts +105 -4
  295. package/src/git.ts +153 -0
  296. package/src/remote-config/remote-config-store.ts +16 -0
  297. package/src/results/cherry-pick-result.ts +4 -3
  298. package/src/results/diff-output.ts +8 -0
  299. package/src/results/diff-words.ts +160 -32
  300. package/src/results/line-prefix-sink.ts +102 -0
  301. package/src/results/merge-result.ts +4 -3
  302. package/src/results/rebase-result.ts +5 -0
  303. package/src/results/revert-result.ts +4 -3
  304. package/src/transport-command.ts +79 -3
@@ -10,14 +10,22 @@
10
10
  * ```
11
11
  */
12
12
 
13
- import { expandUserPath, type IgnoreMatch, xdgConfigPath } from "@statewalker/vcs-working-tree";
13
+ import {
14
+ expandUserPath,
15
+ type IgnoreMatch,
16
+ PrepExcludeError,
17
+ rawPathSteps,
18
+ xdgConfigPath,
19
+ } from "@statewalker/vcs-working-tree";
14
20
 
15
21
  import { GitCommand } from "../git-command.js";
16
22
  import { quotePath } from "../results/quote-path.js";
17
23
  import type { PlumbingTextOutput } from "./check-ref-format-command.js";
18
24
  import { hostEnvironmentOf } from "./git-ident.js";
25
+ import { parseElementMagic, unsupportedPathspecMagic } from "./ls-tree-command.js";
19
26
  import { configBool, configValue } from "./merge-config.js";
20
27
  import { DO_MATCH_DIRECTORY, matchPathspec, parsePathspecItem } from "./pathspec.js";
28
+ import { PlumbingError } from "./plumbing-command.js";
21
29
  import { directoryPrefix, inputRecords, prefixPath } from "./plumbing-input.js";
22
30
  import { worktreeHostPath } from "./submodule-model.js";
23
31
 
@@ -133,31 +141,93 @@ export class CheckIgnoreCommand extends GitCommand<PlumbingTextOutput> {
133
141
  let ignored = 0;
134
142
 
135
143
  const top = await worktreeHostPath(this._workingCopy);
136
- const checkOne = async (original: string): Promise<string | undefined> => {
137
- const full = prefixPath(this.prefix, original, top);
144
+ const EMPTY =
145
+ "empty string is not a valid pathspec. please use . instead if you meant to match all paths";
146
+ /**
147
+ * parse_pathspec of one element with check-ignore's mask (every magic but `:/`
148
+ * refused), PATHSPEC_SYMLINK_LEADING_PATH, then die_path_inside_submodule: the path
149
+ * from the top, or git's death.
150
+ */
151
+ const parse = async (
152
+ original: string,
153
+ ): Promise<{ path: string; asWritten: boolean } | { death: string }> => {
154
+ if (original === "") return { death: EMPTY };
155
+ let parsed: { magic: Set<string>; rest: string };
156
+ try {
157
+ parsed = parseElementMagic(original);
158
+ } catch (error) {
159
+ if (error instanceof PlumbingError) return { death: error.message.replace(/^fatal: /, "") };
160
+ throw error;
161
+ }
162
+ const { magic, rest } = parsed;
163
+ if (magic.has("literal") && magic.has("glob")) {
164
+ return { death: `${original}: 'literal' and 'glob' are incompatible` };
165
+ }
166
+ // init_pathspec_item: a `:/` element is taken as written (`match = xstrdup(copyfrom)`:
167
+ // no prefix_path_gently, so no normalisation and no "outside repository" death)
168
+ const asWritten = magic.has("top");
169
+ const full = asWritten ? rest : prefixPath(this.prefix, rest, top);
138
170
  if (full === undefined) {
139
- return `${original}: '${original}' is outside repository at '${top ?? ""}'`;
171
+ return { death: `${original}: '${rest}' is outside repository at '${top ?? ""}'` };
172
+ }
173
+ const unsupported = unsupportedPathspecMagic(original, magic, ["top"]);
174
+ if (unsupported) return { death: unsupported };
175
+ const beyondLink = { death: `pathspec '${original}' is beyond a symbolic link` };
176
+ // PATHSPEC_SYMLINK_LEADING_PATH: has_symlink_leading_path's lstat of each leading
177
+ // component, stopping at one that is missing or no directory
178
+ if (asWritten) {
179
+ const slash = full.lastIndexOf("/");
180
+ for (const step of rawPathSteps(slash < 0 ? "" : full.slice(0, slash), top)) {
181
+ if (step.name === "." || step.name === ".." || step.name === "") continue;
182
+ if (step.above || step.inside === "") continue;
183
+ if (step.inside === undefined) break;
184
+ const entry = await worktree.getEntry(step.inside).catch(() => undefined);
185
+ if (entry && (entry.mode & S_IFMT) === S_IFLNK) return beyondLink;
186
+ if (!entry?.isDirectory) break;
187
+ }
188
+ return { path: full, asWritten };
140
189
  }
141
190
  const path = full.replace(/\/+$/, "");
142
- // PATHSPEC_SYMLINK_LEADING_PATH
143
191
  const parts = path.split("/");
144
192
  for (let k = 1; k < parts.length; k++) {
145
193
  const entry = await worktree.getEntry(parts.slice(0, k).join("/")).catch(() => undefined);
146
- if (entry && (entry.mode & S_IFMT) === S_IFLNK) {
147
- return `pathspec '${original}' is beyond a symbolic link`;
148
- }
194
+ if (entry && (entry.mode & S_IFMT) === S_IFLNK) return beyondLink;
149
195
  }
150
- if (staging) {
151
- // die_path_inside_submodule
152
- for (const e of index) {
153
- if ((e.mode & S_IFMT) === S_IFGITLINK && path.startsWith(`${e.path}/`)) {
154
- return `Pathspec '${original}' is in submodule '${e.path}'`;
155
- }
196
+ return { path: full, asWritten };
197
+ };
198
+ const insideSubmodule = (original: string, full: string): string | undefined => {
199
+ if (!staging) return undefined;
200
+ // die_path_inside_submodule
201
+ const path = full.replace(/\/+$/, "");
202
+ for (const e of index) {
203
+ if ((e.mode & S_IFMT) === S_IFGITLINK && path.startsWith(`${e.path}/`)) {
204
+ return `Pathspec '${original}' is in submodule '${e.path}'`;
156
205
  }
157
206
  }
207
+ return undefined;
208
+ };
209
+ /** One path of check_ignore's loop; git's death in prep_exclude as its message. */
210
+ const checkOne = async (
211
+ original: string,
212
+ full: string,
213
+ asWritten: boolean,
214
+ ): Promise<string | undefined> => {
158
215
  let match: IgnoreMatch | undefined;
159
- if (!staging || !this.seenInIndex(full, index)) {
160
- match = await worktree.ignoreMatch?.(path);
216
+ // no index entry has a `.` or `..` component (verify_path), so match_pathspec of such
217
+ // an element as written finds none
218
+ const seen =
219
+ !!staging &&
220
+ !(asWritten && full.split("/").some((p) => p === "." || p === "..")) &&
221
+ this.seenInIndex(full, index);
222
+ if (!seen) {
223
+ try {
224
+ match = asWritten
225
+ ? await worktree.ignoreMatch?.(full, false, { asWritten, hostTop: top })
226
+ : await worktree.ignoreMatch?.(full.replace(/\/+$/, ""));
227
+ } catch (error) {
228
+ if (error instanceof PrepExcludeError) return error.message;
229
+ throw error;
230
+ }
161
231
  if (!this.verbose && match?.negated) match = undefined;
162
232
  }
163
233
  if (!this.quiet && (match || this.nonMatching))
@@ -165,17 +235,36 @@ export class CheckIgnoreCommand extends GitCommand<PlumbingTextOutput> {
165
235
  if (match) ignored++;
166
236
  return undefined;
167
237
  };
238
+ /** check_ignore of the paths of one call: every element parsed before any output. */
239
+ const checkAll = async (originals: string[]): Promise<string | undefined> => {
240
+ if (originals.includes("")) return EMPTY;
241
+ const paths: { path: string; asWritten: boolean }[] = [];
242
+ for (const original of originals) {
243
+ const parsed = await parse(original);
244
+ if ("death" in parsed) return parsed.death;
245
+ paths.push(parsed);
246
+ }
247
+ for (let i = 0; i < originals.length; i++) {
248
+ const death = insideSubmodule(originals[i] as string, paths[i]?.path as string);
249
+ if (death) return death;
250
+ }
251
+ for (let i = 0; i < originals.length; i++) {
252
+ const { path, asWritten } = paths[i] as { path: string; asWritten: boolean };
253
+ const death = await checkOne(originals[i] as string, path, asWritten);
254
+ if (death) return death;
255
+ }
256
+ return undefined;
257
+ };
168
258
 
169
259
  const run = async () => {
170
260
  if (this.stdin === undefined) {
171
- for (const path of this.paths) {
172
- const death = await checkOne(path);
173
- if (death) return die(death);
174
- }
261
+ const death = await checkAll(this.paths);
262
+ if (death) return die(death);
175
263
  } else {
264
+ // one check_ignore per record: what came before a death stays on stdout
176
265
  const { records, badlyQuoted } = inputRecords(this.stdin, this.nul);
177
266
  for (const path of records) {
178
- const death = await checkOne(path);
267
+ const death = await checkAll([path]);
179
268
  if (death) return die(death);
180
269
  }
181
270
  if (badlyQuoted) return die("line is badly quoted");
@@ -46,6 +46,7 @@ import {
46
46
  attributesIndexOf,
47
47
  cacheTreeOfTree,
48
48
  entryStatOf,
49
+ type FsmonitorState,
49
50
  isIndexUnborn,
50
51
  type StagingEntry,
51
52
  type Worktree,
@@ -85,6 +86,7 @@ import { type CheckoutPathsOutcome, runPathCheckout } from "./checkout-paths.js"
85
86
  import { coreBool, worktreeModeTrust } from "./core-config.js";
86
87
  import { runPostCheckoutHook } from "./git-hooks.js";
87
88
  import { hostEnvironmentOf } from "./git-ident.js";
89
+ import { applyIndexStatUpdates, refreshIndexEntries } from "./index-refresh.js";
88
90
  import { OperationState, updateIndexCacheTree } from "./merge-support.js";
89
91
  import { globalPathspecMagic } from "./pathspec.js";
90
92
  import { PathspecFile } from "./pathspec-file.js";
@@ -105,11 +107,14 @@ import { STASH_REF } from "./stash-list-command.js";
105
107
  import { recursesIntoSubmodules, SubmoduleUnpack } from "./submodule-unpack.js";
106
108
  import { planTreeRestore, restoreCaseOptions, writeTreeRestorePlan } from "./tree-restore.js";
107
109
  import {
110
+ belowRefused,
108
111
  entryNotUptodate,
109
112
  findInTheWay,
110
113
  flaggedEntryDiffers,
114
+ leadingFileOf,
111
115
  overwriteMessage,
112
116
  pruneEmptyParents,
117
+ takeCleanSubdirectory,
113
118
  } from "./worktree-overwrite-checks.js";
114
119
  import { firstInvalidPath, withTreePathRefusal, worktreePathRules } from "./worktree-path-rules.js";
115
120
  import { refuseIfCheckedOut, shortBranchName } from "./worktree-support.js";
@@ -264,6 +269,15 @@ type SwitchPlan =
264
269
  | { kind: "detach"; targetId: ObjectId; logName: string }
265
270
  | { kind: "stay"; targetId: ObjectId; logName: string };
266
271
 
272
+ /**
273
+ * The revision a switch was given as git's `setup_branch_path` reads it (`@` for HEAD, `-`
274
+ * for `@{-1}`): the start point of a branch created, else the name checked out.
275
+ */
276
+ function switchArgument(plan: SwitchPlan, name: string | undefined): string | undefined {
277
+ const arg = plan.kind === "create" ? plan.startName : name;
278
+ return arg === "@" ? "HEAD" : arg === "-" ? "@{-1}" : arg;
279
+ }
280
+
267
281
  /**
268
282
  * Command to checkout branches, commits, or paths.
269
283
  *
@@ -480,6 +494,12 @@ export class CheckoutCommand extends GitCommand<CheckoutResult> {
480
494
  return this;
481
495
  }
482
496
 
497
+ /** The index's file system monitor state for a refresh, when the monitor is on. */
498
+ private async fsmonitorOf(): Promise<{ fsmonitor?: FsmonitorState }> {
499
+ const run = await this.fsmonitorRefresh(this.staging);
500
+ return run ? { fsmonitor: run.state } : {};
501
+ }
502
+
483
503
  /** Whether this switch skips merge_working_tree (see {@link setOnlyMergeOnSwitchingBranches}). */
484
504
  private skipsMergeWorkingTree(): boolean {
485
505
  if (!this.onlyMergeOnSwitchingBranches || this.orphan) return false;
@@ -999,6 +1019,8 @@ export class CheckoutCommand extends GitCommand<CheckoutResult> {
999
1019
  sparse,
1000
1020
  undefined,
1001
1021
  new Set(fsmKept.keys()),
1022
+ // reset_head's init_checkout_metadata: HEAD's commit, no ref
1023
+ { treeish: headId },
1002
1024
  );
1003
1025
  // check_updates: the entries written carry the stat of their new files
1004
1026
  await recordWrittenStat(this.staging, worktree, written);
@@ -1016,11 +1038,18 @@ export class CheckoutCommand extends GitCommand<CheckoutResult> {
1016
1038
  * checkout do before the write).
1017
1039
  */
1018
1040
  private async writeSwitchedIndex(): Promise<void> {
1019
- await updateIndexCacheTree(this.staging, this.trees, this.objectFormat);
1041
+ // an index no tree can hold: verify_cache's lines, once from unpack-trees' own
1042
+ // cache_tree_update and once from merge_working_tree's, and the switch goes on
1043
+ await updateIndexCacheTree(this.staging, this.trees, this.objectFormat, (lines) =>
1044
+ this.cacheTreeLines.push(...lines, ...lines),
1045
+ );
1020
1046
  markIndexUpdate(this.staging, { workdir: true });
1021
1047
  await this.staging.write();
1022
1048
  }
1023
1049
 
1050
+ /** verify_cache's lines of the switch's index write (stderr, after the sparse lines) */
1051
+ private cacheTreeLines: string[] = [];
1052
+
1024
1053
  /** The switch an autostash switch makes again: its caller runs post-checkout once. */
1025
1054
  private noPostCheckout = false;
1026
1055
  private withoutPostCheckout(): this {
@@ -1103,6 +1132,7 @@ export class CheckoutCommand extends GitCommand<CheckoutResult> {
1103
1132
  worktree: this.worktreeAccess,
1104
1133
  abbreviate: (id: ObjectId) => this.abbreviateObjectId(id),
1105
1134
  resolveTree: (rev: string) => this.resolveSourceTree(rev),
1135
+ checkoutRefOf: (rev: string, id: ObjectId) => this.checkoutRefOf(rev, id),
1106
1136
  };
1107
1137
  }
1108
1138
 
@@ -1248,7 +1278,18 @@ export class CheckoutCommand extends GitCommand<CheckoutResult> {
1248
1278
  // switch --orphan switches to the empty tree)
1249
1279
  const keepAll =
1250
1280
  this.orphan && !this.orphanFromEmptyTree && !orphanCheckout && orphanStart === undefined;
1251
- if (!this.force && !keepAll && unmerged.size > 0) {
1281
+ // merge_working_tree's refresh_index(REFRESH_QUIET) before the two-way merge (orphans
1282
+ // included): an entry whose stat moved but whose content did not takes its file's
1283
+ // current stat; an unmerged path prints `<path>: needs merge` on stdout
1284
+ const refresh =
1285
+ !this.force && worktree
1286
+ ? await refreshIndexEntries(this.staging, worktree, {
1287
+ trust: worktreeModeTrust(this.workingCopy, worktree),
1288
+ ...(await this.fsmonitorOf()),
1289
+ })
1290
+ : undefined;
1291
+ // (checkout --orphan too: git refuses before it keeps index and worktree)
1292
+ if (!this.force && unmerged.size > 0) {
1252
1293
  return {
1253
1294
  status: CheckoutStatus.CONFLICTS,
1254
1295
  updated: [],
@@ -1256,6 +1297,9 @@ export class CheckoutCommand extends GitCommand<CheckoutResult> {
1256
1297
  conflicts: [...unmerged].sort(),
1257
1298
  ref: null,
1258
1299
  message: "error: you need to resolve your current index first",
1300
+ ...(refresh && refresh.unmerged.length > 0
1301
+ ? { output: refresh.unmerged.map((path) => `${path}: needs merge`) }
1302
+ : {}),
1259
1303
  };
1260
1304
  }
1261
1305
 
@@ -1270,6 +1314,47 @@ export class CheckoutCommand extends GitCommand<CheckoutResult> {
1270
1314
  const trust = worktree ? worktreeModeTrust(this.workingCopy, worktree) : undefined;
1271
1315
  const ignoreCase = coreBool(this.workingCopy, "ignorecase", false);
1272
1316
  const initial = unborn && !keepAll;
1317
+ const indexTime = this.staging.getUpdateTime();
1318
+ /**
1319
+ * Index entries verify_clean_subdirectory took out (see {@link takeCleanSubdirectory}):
1320
+ * removed, their own paths merged as if the index lacked them
1321
+ */
1322
+ const consumed = new Set<string>();
1323
+ /** Directories deleted_entry's verify_absent checks for untracked files */
1324
+ const absentDirs: string[] = [];
1325
+ /** Paths whose merge failed: git's traverse_trees enters no subtree of theirs */
1326
+ const refused = new Set<string>();
1327
+ /** The paths each refusal list holds (a path is listed once) */
1328
+ const listed = new Map<string[], Set<string>>();
1329
+ const refuse = (list: string[], path: string, at = path) => {
1330
+ let seen = listed.get(list);
1331
+ if (!seen) {
1332
+ seen = new Set(list);
1333
+ listed.set(list, seen);
1334
+ }
1335
+ if (!seen.has(at)) {
1336
+ seen.add(at);
1337
+ list.push(at);
1338
+ }
1339
+ refused.add(path);
1340
+ };
1341
+ /** `switched` as a set: a path verify_clean_subdirectory took out may come up again */
1342
+ const changing = new Set<string>();
1343
+ const change = (path: string) => {
1344
+ if (changing.has(path)) return;
1345
+ changing.add(path);
1346
+ switched.push(path);
1347
+ };
1348
+ /** Whether the switch so far removes the index entry at `path` (CE_REMOVE in its result) */
1349
+ const removesPath = (path: string) => changing.has(path) && !target.has(path);
1350
+ /** verify_absent's directory check of `path`; whether it passed */
1351
+ const cleanSubdirectory = async (wt: Worktree, path: string) => {
1352
+ const result = await takeCleanSubdirectory(wt, path, index, consumed, trust, indexTime);
1353
+ for (const p of result.taken) change(p);
1354
+ if (result.notUptodate === undefined) return true;
1355
+ refuse(local, path, result.notUptodate);
1356
+ return false;
1357
+ };
1273
1358
  const paths = [...new Set([...head.keys(), ...target.keys()])].sort();
1274
1359
  for (const path of keepAll ? [] : paths) {
1275
1360
  const h = head.get(path);
@@ -1284,7 +1369,8 @@ export class CheckoutCommand extends GitCommand<CheckoutResult> {
1284
1369
  continue;
1285
1370
  }
1286
1371
  if (!this.force && sameSide(h, t)) continue;
1287
- const i = index.get(path);
1372
+ if (!this.force && belowRefused(path, refused)) continue;
1373
+ const i = consumed.has(path) ? undefined : index.get(path);
1288
1374
  if (this.force) {
1289
1375
  // oneway_merge leaves a skip-worktree entry the target keeps (and its file) alone, as
1290
1376
  // the sparse checkout does whatever stays outside it
@@ -1299,16 +1385,35 @@ export class CheckoutCommand extends GitCommand<CheckoutResult> {
1299
1385
  continue;
1300
1386
  }
1301
1387
  if (sameSide(i, t)) {
1302
- // kept; but a staged deletion the target also makes leaves the file untracked in
1303
- // the worktree, and the switch would remove it (git refuses)
1304
- if (h && !i && !t && worktree && (await this.untrackedFileAt(worktree, path))) {
1305
- untrackedRemoved.push(path);
1388
+ // kept; but a staged deletion the target also makes is deleted_entry's verify_absent:
1389
+ // an untracked file there would be removed (git refuses), a directory loses its
1390
+ // entries, a file among the leading directories would be removed too
1391
+ if (h && !i && !t && worktree && !quiet(path)) {
1392
+ const there = await worktree.getEntry(path);
1393
+ if (there?.isDirectory) {
1394
+ if (h.mode !== FileMode.GITLINK && (await cleanSubdirectory(worktree, path))) {
1395
+ absentDirs.push(path);
1396
+ }
1397
+ } else if (there) {
1398
+ if (!consumed.has(path) && (await this.untrackedFileAt(worktree, path))) {
1399
+ refuse(untrackedRemoved, path);
1400
+ }
1401
+ } else {
1402
+ const leading = await leadingFileOf(worktree, path);
1403
+ if (
1404
+ leading !== undefined &&
1405
+ !(index.has(leading) && (consumed.has(leading) || removesPath(leading))) &&
1406
+ !(await worktree.isIgnored(leading))
1407
+ ) {
1408
+ refuse(untrackedRemoved, path, leading);
1409
+ }
1410
+ }
1306
1411
  }
1307
1412
  continue;
1308
1413
  }
1309
1414
  if (!sameSide(i, h)) {
1310
1415
  // staged changes (or a staged deletion) the switch would lose
1311
- if (i !== undefined || t !== undefined) local.push(path);
1416
+ if (i !== undefined || t !== undefined) refuse(local, path);
1312
1417
  continue;
1313
1418
  }
1314
1419
  if (subs && worktree && !quiet(path)) {
@@ -1317,15 +1422,15 @@ export class CheckoutCommand extends GitCommand<CheckoutResult> {
1317
1422
  if (!t && (await subs.isSubmodule(path, i)) && (await subs.exists(path))) {
1318
1423
  await subs.refuses(path, (h ?? i).objectId, null);
1319
1424
  }
1320
- const refused = await subs.notUptodate(path, i);
1321
- if (refused) {
1322
- local.push(path);
1425
+ const notUptodate = await subs.notUptodate(path, i);
1426
+ if (notUptodate) {
1427
+ refuse(local, path);
1323
1428
  continue;
1324
1429
  }
1325
- if (refused === false) {
1430
+ if (notUptodate === false) {
1326
1431
  if (t && t.mode !== FileMode.GITLINK) await subs.fileReplacesRefuses(path, i);
1327
1432
  if (t) await subs.mergedRefuses(path, i, t);
1328
- switched.push(path);
1433
+ change(path);
1329
1434
  continue;
1330
1435
  }
1331
1436
  } else if (i === undefined && t) {
@@ -1338,13 +1443,19 @@ export class CheckoutCommand extends GitCommand<CheckoutResult> {
1338
1443
  i !== undefined &&
1339
1444
  worktree &&
1340
1445
  !quiet(path) &&
1341
- (await entryNotUptodate(worktree, path, i, trust, this.staging.getUpdateTime()))
1446
+ (await entryNotUptodate(worktree, path, i, trust, indexTime))
1342
1447
  ) {
1343
- local.push(path);
1448
+ refuse(local, path);
1344
1449
  continue;
1345
1450
  }
1346
1451
  if (subs && i !== undefined && t && !quiet(path)) await subs.mergedRefuses(path, i, t);
1347
- switched.push(path);
1452
+ // merged_entry's verify_absent of a new file: a directory here loses the index
1453
+ // entries below it
1454
+ if (i === undefined && t && worktree && !quiet(path) && t.mode !== FileMode.GITLINK) {
1455
+ const there = await worktree.getEntry(path);
1456
+ if (there?.isDirectory && !(await cleanSubdirectory(worktree, path))) continue;
1457
+ }
1458
+ change(path);
1348
1459
  }
1349
1460
 
1350
1461
  // what stands where the switch writes (git's verify_absent, check_leading_path and
@@ -1352,8 +1463,12 @@ export class CheckoutCommand extends GitCommand<CheckoutResult> {
1352
1463
  // component, untracked files in a directory a file replaces
1353
1464
  if (worktree && !this.force) {
1354
1465
  const found = await findInTheWay(worktree, {
1355
- writes: switched.filter((p) => target.has(p) && writes(p) && !submodulePaths.has(p)),
1356
- removes: new Set(switched.filter((p) => !target.has(p))),
1466
+ writes: [
1467
+ ...switched.filter((p) => target.has(p) && writes(p) && !submodulePaths.has(p)),
1468
+ // deleted_entry's directories, checked as a file written there would check them
1469
+ ...absentDirs,
1470
+ ],
1471
+ removes: new Set([...switched.filter((p) => !target.has(p)), ...consumed]),
1357
1472
  index,
1358
1473
  ...(await restoreCaseOptions(worktree, ignoreCase)),
1359
1474
  caseVariantsExpendable: true,
@@ -1418,8 +1533,8 @@ export class CheckoutCommand extends GitCommand<CheckoutResult> {
1418
1533
  // git 2.55+ `checkout -m`: a two-way merge that fails (local changes, untracked files
1419
1534
  // in the way) falls back to an autostash, run by call() outside this worktree batch;
1420
1535
  // with nothing to stash the refusal stands
1421
- const refused = local.length + untracked.length + untrackedRemoved.length + lostDirs.length;
1422
- if (this.merge && headId && refused > 0 && this.patchCompatibility === "2.43") {
1536
+ const refusals = local.length + untracked.length + untrackedRemoved.length + lostDirs.length;
1537
+ if (this.merge && headId && refusals > 0 && this.patchCompatibility === "2.43") {
1423
1538
  // git 2.43's merge_working_tree: a failed two-way merge under `-m` dies when the index
1424
1539
  // holds changes against HEAD (repo_index_has_changes), an unborn index's missing
1425
1540
  // entries included (staged deletions of every HEAD file)
@@ -1432,7 +1547,7 @@ export class CheckoutCommand extends GitCommand<CheckoutResult> {
1432
1547
  );
1433
1548
  }
1434
1549
  }
1435
- if (this.merge && headId && refused > 0) {
1550
+ if (this.merge && headId && refusals > 0) {
1436
1551
  const left = await this.getCurrentBranch();
1437
1552
  // the base's label: the branch left, else its commit uniquely abbreviated
1438
1553
  // (strbuf_add_unique_abbrev, DEFAULT_ABBREV)
@@ -1572,6 +1687,10 @@ export class CheckoutCommand extends GitCommand<CheckoutResult> {
1572
1687
  ...(this.force && !this.protectUntracked ? { discardUntracked: true } : {}),
1573
1688
  attributes: { direction: "checkout", index: attributesIndexOf(result) },
1574
1689
  progress,
1690
+ // merge_working_tree's init_checkout_metadata: the name given and its commit
1691
+ ...(targetId
1692
+ ? { metadata: await this.checkoutRefOf(switchArgument(switchTo, this.name), targetId) }
1693
+ : {}),
1575
1694
  });
1576
1695
  updated.push(...only.entries.map((e) => e.path));
1577
1696
  for (const e of [...only.entries, ...only.gitlinks]) written.add(e.path);
@@ -1589,6 +1708,14 @@ export class CheckoutCommand extends GitCommand<CheckoutResult> {
1589
1708
  // entries (with the stat of the files just written), every other path keeps its own.
1590
1709
  // git's switch writes a new index (unpack-trees): no resolve-undo records survive it
1591
1710
  this.staging.clearResolveUndo?.();
1711
+ // the refresh's stats, for the entries the switch keeps (written with this index only:
1712
+ // a refused switch rolls the lock back, as git does)
1713
+ if (refresh) {
1714
+ await applyIndexStatUpdates(
1715
+ this.staging,
1716
+ refresh.updates.filter((update) => !switching.has(update.path)),
1717
+ );
1718
+ }
1592
1719
  if (targetTreeId && this.force) {
1593
1720
  // oneway_merge: an unchanged entry keeps its flags and stat, a changed one its
1594
1721
  // skip-worktree bit
@@ -1644,6 +1771,7 @@ export class CheckoutCommand extends GitCommand<CheckoutResult> {
1644
1771
  );
1645
1772
  pushSparseWarnings(sparseWarnings, sparse, outcome, true);
1646
1773
  }
1774
+ sparseWarnings.push(...this.cacheTreeLines.splice(0));
1647
1775
 
1648
1776
  return this.updateRefsForSwitch(switchTo, updated, removed, sparseWarnings);
1649
1777
  }
@@ -499,7 +499,8 @@ class CheckoutIndexRun {
499
499
  } else if (!link) {
500
500
  // smudged with the entry's own attributes, wherever it is written
501
501
  const conversion = await worktree.contentFilter?.checkout(ce.path);
502
- if (conversion) content = await conversion.apply(blob);
502
+ // checkout_entry's metadata: the blob, for a long-running filter process
503
+ if (conversion) content = await conversion.apply(blob, { metadata: { blob: ce.objectId } });
503
504
  }
504
505
  if (path !== undefined) await this.createDirectories(path);
505
506
  const target = path ?? (await this.tempName(link));
@@ -41,6 +41,7 @@ import {
41
41
  } from "./pathspec.js";
42
42
  import { PathspecAttributes } from "./pathspec-attributes.js";
43
43
  import { recursesIntoSubmodules, SubmoduleUnpack } from "./submodule-unpack.js";
44
+ import type { CheckoutRef } from "./tree-restore.js";
44
45
  import {
45
46
  pruneEmptyParents,
46
47
  removeDirectoryIfEmpty,
@@ -68,6 +69,12 @@ export interface CheckoutPathsOptions {
68
69
  reportUnmatched?: boolean;
69
70
  /** The tree checked out of (`opts->source_tree`); none: the index */
70
71
  sourceTree?: ObjectId;
72
+ /**
73
+ * git's checkout metadata of the source (`checkout_paths`' `init_checkout_metadata`: the
74
+ * ref the tree-ish names and its commit), handed with each file's blob to a long-running
75
+ * filter process
76
+ */
77
+ sourceMetadata?: CheckoutRef;
71
78
  /** Update the index (`checkout_index`) */
72
79
  checkoutIndex: boolean;
73
80
  /** Update the worktree (`checkout_worktree`) */
@@ -157,6 +164,8 @@ export interface PathCheckoutRequest {
157
164
  export async function runPathCheckout(
158
165
  ctx: CheckoutPathsContext & {
159
166
  resolveTree(rev: string): Promise<{ id: ObjectId; tree: ObjectId | undefined }>;
167
+ /** git's checkout metadata of the source `rev` at `id` (see `GitCommand.checkoutRefOf`) */
168
+ checkoutRefOf?(rev: string, id: ObjectId): Promise<CheckoutRef>;
160
169
  },
161
170
  req: PathCheckoutRequest,
162
171
  ): Promise<CheckoutPathsOutcome> {
@@ -199,6 +208,7 @@ export async function runPathCheckout(
199
208
  }
200
209
  // the source tree, resolved before checkout_paths runs
201
210
  let sourceTree: ObjectId | undefined;
211
+ let sourceMetadata: CheckoutRef | undefined;
202
212
  if (from !== undefined) {
203
213
  let resolved: { id: ObjectId; tree: ObjectId | undefined };
204
214
  try {
@@ -218,6 +228,7 @@ export async function runPathCheckout(
218
228
  throw new RefNotFoundError(from, `fatal: unable to read tree (${resolved.id})`);
219
229
  }
220
230
  sourceTree = resolved.tree;
231
+ sourceMetadata = await ctx.checkoutRefOf?.(from === "@" ? "HEAD" : from, resolved.id);
221
232
  }
222
233
  if (ignoreUnmerged && req.merge) {
223
234
  throw fail(
@@ -262,6 +273,7 @@ export async function runPathCheckout(
262
273
  originals,
263
274
  reportUnmatched: !req.allPaths,
264
275
  ...(sourceTree ? { sourceTree } : {}),
276
+ ...(sourceMetadata ? { sourceMetadata } : {}),
265
277
  checkoutIndex,
266
278
  checkoutWorktree,
267
279
  overlay: req.overlay ?? !isRestore,
@@ -668,6 +680,7 @@ async function checkoutWorktree(
668
680
  createParents: true,
669
681
  replaceInTheWay: true,
670
682
  discardUntracked: true,
683
+ metadata: { ...o.sourceMetadata, blob: objectId },
671
684
  });
672
685
  return true;
673
686
  };
@@ -375,6 +375,15 @@ export class CherryPickCommand extends GitCommand<CherryPickResult> {
375
375
  return made.id;
376
376
  }
377
377
 
378
+ /** git sets `warn_on_auto_comment_char`: 2.5x warns of `core.commentChar=auto` here. */
379
+ protected override autoCommentCharWarningEntryPoints(): readonly string[] {
380
+ return ["call"];
381
+ }
382
+
383
+ protected override gitCompatibility(): "2.43" | "2.56" {
384
+ return this.compatibility ?? this.hooks.compatibility;
385
+ }
386
+
378
387
  async call(): Promise<CherryPickResult> {
379
388
  this.checkCallable();
380
389
  this.setCallable(false);