@statewalker/vcs-commands 0.8.0 → 0.9.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 (297) hide show
  1. package/dist/commands/add-command.d.ts +32 -0
  2. package/dist/commands/add-command.d.ts.map +1 -1
  3. package/dist/commands/add-patch/add-patch.d.ts +7 -0
  4. package/dist/commands/add-patch/add-patch.d.ts.map +1 -1
  5. package/dist/commands/add-patch/patch-backend.d.ts.map +1 -1
  6. package/dist/commands/am/am-command.d.ts +47 -0
  7. package/dist/commands/am/am-command.d.ts.map +1 -1
  8. package/dist/commands/apply/apply-command.d.ts +2 -0
  9. package/dist/commands/apply/apply-command.d.ts.map +1 -1
  10. package/dist/commands/apply/apply-parse.d.ts +7 -0
  11. package/dist/commands/apply/apply-parse.d.ts.map +1 -1
  12. package/dist/commands/apply/index.d.ts +1 -1
  13. package/dist/commands/apply/index.d.ts.map +1 -1
  14. package/dist/commands/blame-command.d.ts +303 -8
  15. package/dist/commands/blame-command.d.ts.map +1 -1
  16. package/dist/commands/blame-ignore.d.ts +48 -0
  17. package/dist/commands/blame-ignore.d.ts.map +1 -0
  18. package/dist/commands/check-mailmap-command.d.ts +49 -0
  19. package/dist/commands/check-mailmap-command.d.ts.map +1 -0
  20. package/dist/commands/checkout-command.d.ts +7 -0
  21. package/dist/commands/checkout-command.d.ts.map +1 -1
  22. package/dist/commands/checkout-paths.d.ts +4 -0
  23. package/dist/commands/checkout-paths.d.ts.map +1 -1
  24. package/dist/commands/cherry-command.d.ts +61 -0
  25. package/dist/commands/cherry-command.d.ts.map +1 -0
  26. package/dist/commands/cherry-pick-command.d.ts +23 -1
  27. package/dist/commands/cherry-pick-command.d.ts.map +1 -1
  28. package/dist/commands/clean-command.d.ts +32 -0
  29. package/dist/commands/clean-command.d.ts.map +1 -1
  30. package/dist/commands/clean-interactive.d.ts +56 -0
  31. package/dist/commands/clean-interactive.d.ts.map +1 -0
  32. package/dist/commands/clone-command.d.ts +116 -2
  33. package/dist/commands/clone-command.d.ts.map +1 -1
  34. package/dist/commands/commit-command.d.ts +50 -2
  35. package/dist/commands/commit-command.d.ts.map +1 -1
  36. package/dist/commands/describe-command.d.ts +71 -64
  37. package/dist/commands/describe-command.d.ts.map +1 -1
  38. package/dist/commands/diff-command.d.ts +118 -6
  39. package/dist/commands/diff-command.d.ts.map +1 -1
  40. package/dist/commands/fetch-command.d.ts +60 -0
  41. package/dist/commands/fetch-command.d.ts.map +1 -1
  42. package/dist/commands/fetch-multiple-command.d.ts +193 -0
  43. package/dist/commands/fetch-multiple-command.d.ts.map +1 -0
  44. package/dist/commands/format-patch-command.d.ts +28 -2
  45. package/dist/commands/format-patch-command.d.ts.map +1 -1
  46. package/dist/commands/git-describe.d.ts +77 -4
  47. package/dist/commands/git-describe.d.ts.map +1 -1
  48. package/dist/commands/git-hooks.d.ts +15 -1
  49. package/dist/commands/git-hooks.d.ts.map +1 -1
  50. package/dist/commands/index.d.ts +12 -0
  51. package/dist/commands/index.d.ts.map +1 -1
  52. package/dist/commands/index.js +5 -3
  53. package/dist/commands/init-command.d.ts +89 -0
  54. package/dist/commands/init-command.d.ts.map +1 -1
  55. package/dist/commands/line-log.d.ts +161 -0
  56. package/dist/commands/line-log.d.ts.map +1 -0
  57. package/dist/commands/log-command.d.ts +235 -6
  58. package/dist/commands/log-command.d.ts.map +1 -1
  59. package/dist/commands/log-graph.d.ts +4 -2
  60. package/dist/commands/log-graph.d.ts.map +1 -1
  61. package/dist/commands/log-output.d.ts +66 -1
  62. package/dist/commands/log-output.d.ts.map +1 -1
  63. package/dist/commands/mailmap.d.ts +24 -1
  64. package/dist/commands/mailmap.d.ts.map +1 -1
  65. package/dist/commands/merge-command.d.ts +51 -1
  66. package/dist/commands/merge-command.d.ts.map +1 -1
  67. package/dist/commands/merge-drivers.d.ts +2 -0
  68. package/dist/commands/merge-drivers.d.ts.map +1 -1
  69. package/dist/commands/merge-strategy-options.d.ts +69 -0
  70. package/dist/commands/merge-strategy-options.d.ts.map +1 -0
  71. package/dist/commands/merge-support.d.ts +10 -0
  72. package/dist/commands/merge-support.d.ts.map +1 -1
  73. package/dist/commands/message-cleanup.d.ts +2 -0
  74. package/dist/commands/message-cleanup.d.ts.map +1 -1
  75. package/dist/commands/name-rev-command.d.ts +65 -0
  76. package/dist/commands/name-rev-command.d.ts.map +1 -0
  77. package/dist/commands/name-rev.d.ts +110 -22
  78. package/dist/commands/name-rev.d.ts.map +1 -1
  79. package/dist/commands/octopus-merge.d.ts +26 -1
  80. package/dist/commands/octopus-merge.d.ts.map +1 -1
  81. package/dist/commands/ort-merge.d.ts +16 -0
  82. package/dist/commands/ort-merge.d.ts.map +1 -1
  83. package/dist/commands/ort-recursive.d.ts.map +1 -1
  84. package/dist/commands/patch-id.d.ts +58 -0
  85. package/dist/commands/patch-id.d.ts.map +1 -1
  86. package/dist/commands/pull-command.d.ts +182 -38
  87. package/dist/commands/pull-command.d.ts.map +1 -1
  88. package/dist/commands/push-command.d.ts +65 -0
  89. package/dist/commands/push-command.d.ts.map +1 -1
  90. package/dist/commands/range-diff/index.d.ts +4 -0
  91. package/dist/commands/range-diff/index.d.ts.map +1 -0
  92. package/dist/commands/range-diff/linear-assignment.d.ts +27 -0
  93. package/dist/commands/range-diff/linear-assignment.d.ts.map +1 -0
  94. package/dist/commands/range-diff/range-diff-command.d.ts +121 -0
  95. package/dist/commands/range-diff/range-diff-command.d.ts.map +1 -0
  96. package/dist/commands/range-diff/range-diff.d.ts +106 -0
  97. package/dist/commands/range-diff/range-diff.d.ts.map +1 -0
  98. package/dist/commands/read-tree-command.d.ts +14 -0
  99. package/dist/commands/read-tree-command.d.ts.map +1 -1
  100. package/dist/commands/rebase-command.d.ts +21 -2
  101. package/dist/commands/rebase-command.d.ts.map +1 -1
  102. package/dist/commands/remerge-diff.d.ts +59 -0
  103. package/dist/commands/remerge-diff.d.ts.map +1 -0
  104. package/dist/commands/remote-command.d.ts +41 -0
  105. package/dist/commands/remote-command.d.ts.map +1 -1
  106. package/dist/commands/remote-show-command.d.ts +204 -0
  107. package/dist/commands/remote-show-command.d.ts.map +1 -0
  108. package/dist/commands/reset-command.d.ts +19 -1
  109. package/dist/commands/reset-command.d.ts.map +1 -1
  110. package/dist/commands/restore-command.d.ts +7 -0
  111. package/dist/commands/restore-command.d.ts.map +1 -1
  112. package/dist/commands/rev-list-command.d.ts +75 -3
  113. package/dist/commands/rev-list-command.d.ts.map +1 -1
  114. package/dist/commands/revert-command.d.ts +22 -1
  115. package/dist/commands/revert-command.d.ts.map +1 -1
  116. package/dist/commands/revision-range.d.ts +2 -0
  117. package/dist/commands/revision-range.d.ts.map +1 -1
  118. package/dist/commands/sequencer-pick.d.ts +102 -1
  119. package/dist/commands/sequencer-pick.d.ts.map +1 -1
  120. package/dist/commands/sequencer-support.d.ts +10 -1
  121. package/dist/commands/sequencer-support.d.ts.map +1 -1
  122. package/dist/commands/shortlog-command.d.ts +109 -0
  123. package/dist/commands/shortlog-command.d.ts.map +1 -0
  124. package/dist/commands/shortlog.d.ts +151 -0
  125. package/dist/commands/shortlog.d.ts.map +1 -0
  126. package/dist/commands/status-command.d.ts +31 -2
  127. package/dist/commands/status-command.d.ts.map +1 -1
  128. package/dist/commands/submodule-commands.d.ts +90 -2
  129. package/dist/commands/submodule-commands.d.ts.map +1 -1
  130. package/dist/commands/submodule-fetch.d.ts +149 -0
  131. package/dist/commands/submodule-fetch.d.ts.map +1 -0
  132. package/dist/commands/submodule-model.d.ts +8 -0
  133. package/dist/commands/submodule-model.d.ts.map +1 -1
  134. package/dist/commands/submodule-unpack.d.ts +120 -0
  135. package/dist/commands/submodule-unpack.d.ts.map +1 -0
  136. package/dist/commands/submodule-update-command.d.ts +8 -0
  137. package/dist/commands/submodule-update-command.d.ts.map +1 -1
  138. package/dist/commands/subtree-shift.d.ts +27 -0
  139. package/dist/commands/subtree-shift.d.ts.map +1 -0
  140. package/dist/commands/switch-command.d.ts +3 -0
  141. package/dist/commands/switch-command.d.ts.map +1 -1
  142. package/dist/commands/tree-restore.d.ts.map +1 -1
  143. package/dist/commands/worktree-overwrite-checks.d.ts +2 -0
  144. package/dist/commands/worktree-overwrite-checks.d.ts.map +1 -1
  145. package/dist/{commands-ISM52N0n.js → commands-CNvli5bl.js} +39426 -61169
  146. package/dist/errors/command-errors.d.ts +25 -0
  147. package/dist/errors/command-errors.d.ts.map +1 -1
  148. package/dist/errors/index.js +29 -1
  149. package/dist/fsck-CPeDh9fh.js +5138 -0
  150. package/dist/git-command.d.ts +31 -1
  151. package/dist/git-command.d.ts.map +1 -1
  152. package/dist/git.d.ts +97 -1
  153. package/dist/git.d.ts.map +1 -1
  154. package/dist/guarded-transport-command.d.ts +82 -0
  155. package/dist/guarded-transport-command.d.ts.map +1 -0
  156. package/dist/index.d.ts +1 -0
  157. package/dist/index.d.ts.map +1 -1
  158. package/dist/index.js +6 -5
  159. package/dist/remote-transport-CCmBadm-.js +1606 -0
  160. package/dist/rename/detect-renames.d.ts +20 -0
  161. package/dist/rename/detect-renames.d.ts.map +1 -1
  162. package/dist/rename/diffcore-break.d.ts +51 -0
  163. package/dist/rename/diffcore-break.d.ts.map +1 -0
  164. package/dist/rename/index.d.ts +1 -0
  165. package/dist/rename/index.d.ts.map +1 -1
  166. package/dist/results/blame-format.d.ts +62 -1
  167. package/dist/results/blame-format.d.ts.map +1 -1
  168. package/dist/results/clone-result.d.ts +9 -0
  169. package/dist/results/clone-result.d.ts.map +1 -1
  170. package/dist/results/diff-dirstat.d.ts +36 -0
  171. package/dist/results/diff-dirstat.d.ts.map +1 -0
  172. package/dist/results/diff-entry.d.ts +10 -0
  173. package/dist/results/diff-entry.d.ts.map +1 -1
  174. package/dist/results/diff-formatter.d.ts.map +1 -1
  175. package/dist/results/diff-output.d.ts +18 -0
  176. package/dist/results/diff-output.d.ts.map +1 -1
  177. package/dist/results/fetch-result.d.ts +12 -1
  178. package/dist/results/fetch-result.d.ts.map +1 -1
  179. package/dist/results/index.d.ts +2 -0
  180. package/dist/results/index.d.ts.map +1 -1
  181. package/dist/results/index.js +2 -2
  182. package/dist/results/init-result.d.ts +8 -1
  183. package/dist/results/init-result.d.ts.map +1 -1
  184. package/dist/results/line-range-hunks.d.ts +27 -0
  185. package/dist/results/line-range-hunks.d.ts.map +1 -0
  186. package/dist/results/merge-result.d.ts +8 -1
  187. package/dist/results/merge-result.d.ts.map +1 -1
  188. package/dist/results/pull-result.d.ts +11 -0
  189. package/dist/results/pull-result.d.ts.map +1 -1
  190. package/dist/results/push-result.d.ts +5 -0
  191. package/dist/results/push-result.d.ts.map +1 -1
  192. package/dist/results/status-result.d.ts +1 -1
  193. package/dist/results/status-result.d.ts.map +1 -1
  194. package/dist/results-BDuEgdLU.js +46847 -0
  195. package/dist/transport-command.d.ts +14 -0
  196. package/dist/transport-command.d.ts.map +1 -1
  197. package/package.json +12 -12
  198. package/src/commands/add-command.ts +115 -0
  199. package/src/commands/add-patch/add-patch.ts +8 -0
  200. package/src/commands/add-patch/patch-backend.ts +20 -2
  201. package/src/commands/am/am-command.ts +138 -4
  202. package/src/commands/apply/apply-command.ts +52 -9
  203. package/src/commands/apply/apply-parse.ts +10 -0
  204. package/src/commands/apply/index.ts +8 -1
  205. package/src/commands/blame-command.ts +1450 -51
  206. package/src/commands/blame-ignore.ts +307 -0
  207. package/src/commands/check-mailmap-command.ts +129 -0
  208. package/src/commands/checkout-command.ts +97 -12
  209. package/src/commands/checkout-paths.ts +28 -0
  210. package/src/commands/cherry-command.ts +187 -0
  211. package/src/commands/cherry-pick-command.ts +42 -1
  212. package/src/commands/clean-command.ts +92 -12
  213. package/src/commands/clean-interactive.ts +522 -0
  214. package/src/commands/clone-command.ts +596 -44
  215. package/src/commands/commit-command.ts +180 -47
  216. package/src/commands/describe-command.ts +341 -254
  217. package/src/commands/diff-command.ts +616 -56
  218. package/src/commands/fetch-command.ts +353 -6
  219. package/src/commands/fetch-multiple-command.ts +665 -0
  220. package/src/commands/format-patch-command.ts +189 -77
  221. package/src/commands/git-describe.ts +456 -217
  222. package/src/commands/git-hooks.ts +42 -3
  223. package/src/commands/index.ts +17 -0
  224. package/src/commands/init-command.ts +603 -49
  225. package/src/commands/line-log.ts +931 -0
  226. package/src/commands/log-command.ts +1414 -177
  227. package/src/commands/log-graph.ts +6 -3
  228. package/src/commands/log-output.ts +173 -10
  229. package/src/commands/mailmap.ts +41 -5
  230. package/src/commands/merge-command.ts +274 -16
  231. package/src/commands/merge-drivers.ts +3 -0
  232. package/src/commands/merge-strategy-options.ts +224 -0
  233. package/src/commands/merge-support.ts +101 -21
  234. package/src/commands/message-cleanup.ts +1 -1
  235. package/src/commands/name-rev-command.ts +184 -0
  236. package/src/commands/name-rev.ts +700 -109
  237. package/src/commands/octopus-merge.ts +35 -11
  238. package/src/commands/ort-merge.ts +41 -7
  239. package/src/commands/ort-recursive.ts +40 -2
  240. package/src/commands/patch-id.ts +109 -0
  241. package/src/commands/pull-command.ts +718 -224
  242. package/src/commands/push-command.ts +353 -3
  243. package/src/commands/range-diff/index.ts +3 -0
  244. package/src/commands/range-diff/linear-assignment.ts +203 -0
  245. package/src/commands/range-diff/range-diff-command.ts +433 -0
  246. package/src/commands/range-diff/range-diff.ts +617 -0
  247. package/src/commands/read-tree-command.ts +74 -3
  248. package/src/commands/rebase-command.ts +141 -65
  249. package/src/commands/remerge-diff.ts +241 -0
  250. package/src/commands/remote-command.ts +98 -10
  251. package/src/commands/remote-show-command.ts +836 -0
  252. package/src/commands/reset-command.ts +78 -3
  253. package/src/commands/restore-command.ts +15 -0
  254. package/src/commands/rev-list-command.ts +187 -11
  255. package/src/commands/revert-command.ts +41 -1
  256. package/src/commands/revision-range.ts +3 -1
  257. package/src/commands/sequencer-pick.ts +323 -29
  258. package/src/commands/sequencer-support.ts +164 -2
  259. package/src/commands/shortlog-command.ts +354 -0
  260. package/src/commands/shortlog.ts +361 -0
  261. package/src/commands/show-command.ts +2 -1
  262. package/src/commands/status-command.ts +115 -25
  263. package/src/commands/status-format.ts +1 -1
  264. package/src/commands/submodule-commands.ts +321 -3
  265. package/src/commands/submodule-fetch.ts +789 -0
  266. package/src/commands/submodule-model.ts +9 -1
  267. package/src/commands/submodule-unpack.ts +265 -0
  268. package/src/commands/submodule-update-command.ts +39 -5
  269. package/src/commands/subtree-shift.ts +215 -0
  270. package/src/commands/switch-command.ts +9 -0
  271. package/src/commands/tree-restore.ts +6 -1
  272. package/src/commands/worktree-overwrite-checks.ts +5 -0
  273. package/src/errors/command-errors.ts +35 -0
  274. package/src/git-command.ts +87 -1
  275. package/src/git.ts +146 -0
  276. package/src/guarded-transport-command.ts +171 -0
  277. package/src/index.ts +1 -0
  278. package/src/rename/detect-renames.ts +42 -8
  279. package/src/rename/diffcore-break.ts +166 -0
  280. package/src/rename/index.ts +1 -0
  281. package/src/results/blame-format.ts +268 -43
  282. package/src/results/clone-result.ts +6 -0
  283. package/src/results/diff-dirstat.ts +117 -0
  284. package/src/results/diff-entry.ts +12 -0
  285. package/src/results/diff-formatter.ts +1 -0
  286. package/src/results/diff-output.ts +127 -2
  287. package/src/results/fetch-result.ts +12 -1
  288. package/src/results/index.ts +2 -0
  289. package/src/results/init-result.ts +10 -1
  290. package/src/results/line-range-hunks.ts +126 -0
  291. package/src/results/merge-result.ts +9 -0
  292. package/src/results/pull-result.ts +7 -0
  293. package/src/results/push-result.ts +5 -0
  294. package/src/results/status-result.ts +2 -2
  295. package/src/transport-command.ts +34 -3
  296. package/dist/fsck-DLRpbwTj.js +0 -13405
  297. package/dist/results-TB2IJ64h.js +0 -4700
@@ -0,0 +1,307 @@
1
+ /**
2
+ * git's heuristics for the lines of an ignored commit (blame.c): each changed line of the
3
+ * ignored version is matched with a line of its parent's version by fingerprint
4
+ * (`fuzzy_find_matching_lines` within the diff chunk, then `scan_parent_range` over the
5
+ * whole parent), so `git blame --ignore-rev` can blame it on the commit that wrote that line.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * const parentFps = lineFingerprints(parentContent);
10
+ * const targetFps = lineFingerprints(targetContent);
11
+ * // a chunk replacing parent lines [3, 5) by target lines [3, 7)
12
+ * const blames = guessLineBlames(parentFps, targetFps, 3, 0, 7, 2);
13
+ * blames[0]; // { isParent: true, sLno: 3 } or { isParent: false, sLno: 3 }
14
+ * ```
15
+ *
16
+ * @module
17
+ */
18
+
19
+ /**
20
+ * A fingerprint (`struct fingerprint`): the multiset of the lower-cased byte pairs of a line,
21
+ * whitespace (as `\0`) added at both ends, whitespace pairs left out; each pair (`c0 | c1 << 8`)
22
+ * mapped to its count
23
+ */
24
+ export type Fingerprint = Map<number, number>;
25
+
26
+ /** git's isspace: tab, line feed, carriage return and space */
27
+ const isSpace = (c: number) => c === 0x20 || c === 0x09 || c === 0x0a || c === 0x0d;
28
+
29
+ /** git's `find_line_starts`: where each line starts, and the length at the end */
30
+ export function lineStartsOf(content: Uint8Array): Int32Array {
31
+ let num = 0;
32
+ for (let i = 0; i < content.length; i++) if (content[i] === 0x0a) num++;
33
+ if (content.length > 0 && content[content.length - 1] !== 0x0a) num++;
34
+ const starts = new Int32Array(num + 1);
35
+ let n = 1;
36
+ for (let i = 0; i < content.length - 1; i++) if (content[i] === 0x0a) starts[n++] = i + 1;
37
+ starts[num] = content.length;
38
+ return starts;
39
+ }
40
+
41
+ /** git's `get_fingerprint` of `content[begin, end]` (`end` itself read as whitespace) */
42
+ function fingerprint(content: Uint8Array, begin: number, end: number): Fingerprint {
43
+ const map: Fingerprint = new Map();
44
+ let c0 = 0;
45
+ for (let p = begin; p <= end; p++) {
46
+ let c1 = 0;
47
+ if (p !== end) {
48
+ const c = content[p];
49
+ if (!isSpace(c)) c1 = c >= 0x41 && c <= 0x5a ? c + 0x20 : c;
50
+ }
51
+ const hash = c0 | (c1 << 8);
52
+ c0 = c1;
53
+ if (hash === 0) continue;
54
+ map.set(hash, (map.get(hash) ?? 0) + 1);
55
+ }
56
+ return map;
57
+ }
58
+
59
+ /** git's `get_line_fingerprints` over every line (`fill_origin_fingerprints`) */
60
+ export function lineFingerprints(content: Uint8Array): Fingerprint[] {
61
+ const starts = lineStartsOf(content);
62
+ const out: Fingerprint[] = new Array(starts.length - 1);
63
+ for (let i = 0; i < out.length; i++) out[i] = fingerprint(content, starts[i], starts[i + 1]);
64
+ return out;
65
+ }
66
+
67
+ /** git's `fingerprint_similarity`: the size of the multisets' intersection */
68
+ function similarity(a: Fingerprint, b: Fingerprint): number {
69
+ let n = 0;
70
+ for (const [hash, countB] of b) {
71
+ const countA = a.get(hash);
72
+ if (countA !== undefined) n += countA < countB ? countA : countB;
73
+ }
74
+ return n;
75
+ }
76
+
77
+ /** git's `fingerprint_subtract`: `b`'s pairs taken out of `a`, in place */
78
+ function subtract(a: Fingerprint, b: Fingerprint): void {
79
+ for (const [hash, countB] of b) {
80
+ const countA = a.get(hash);
81
+ if (countA === undefined) continue;
82
+ if (countA <= countB) a.delete(hash);
83
+ else a.set(hash, countA - countB);
84
+ }
85
+ }
86
+
87
+ const CERTAIN_NOTHING_MATCHES = -2;
88
+ const CERTAINTY_NOT_CALCULATED = -1;
89
+
90
+ interface Mapping {
91
+ destinationStart: number;
92
+ destinationLength: number;
93
+ sourceStart: number;
94
+ sourceLength: number;
95
+ }
96
+
97
+ /** git's `map_line_number`: a line of B mapped onto the middle of its share of A */
98
+ function mapLineNumber(line: number, m: Mapping): number {
99
+ return (
100
+ Math.trunc((((line - m.sourceStart) * 2 + 1) * m.destinationLength) / (m.sourceLength * 2)) +
101
+ m.destinationStart
102
+ );
103
+ }
104
+
105
+ /**
106
+ * git's `fuzzy_find_matching_lines`: for each target line of `[tlno, same)` the parent line
107
+ * of `[parentSlno, parentSlno + parentLen)` it matches (-1 for none), the line order kept;
108
+ * undefined when the parent chunk is empty. The matched parent fingerprints are reduced by
109
+ * what was matched (`parentFps` changes).
110
+ */
111
+ export function fuzzyFindMatchingLines(
112
+ parentFps: Fingerprint[],
113
+ targetFps: Fingerprint[],
114
+ tlno: number,
115
+ parentSlno: number,
116
+ same: number,
117
+ parentLen: number,
118
+ ): Int32Array | undefined {
119
+ const startA0 = parentSlno;
120
+ const lengthA0 = parentLen;
121
+ const startB0 = tlno;
122
+ const lengthB0 = same - tlno;
123
+ const mapping: Mapping = {
124
+ destinationStart: startA0,
125
+ destinationLength: lengthA0,
126
+ sourceStart: startB0,
127
+ sourceLength: lengthB0,
128
+ };
129
+ if (lengthA0 <= 0) return undefined;
130
+ let maxA = 10;
131
+ if (maxA >= lengthA0) maxA = lengthA0 ? lengthA0 - 1 : 0;
132
+ const maxB = Math.trunc(((2 * maxA + 1) * lengthB0 - 1) / lengthA0);
133
+ const width = maxA * 2 + 1;
134
+ const result = new Int32Array(lengthB0).fill(-1);
135
+ const secondBest = new Int32Array(lengthB0).fill(-1);
136
+ const certainties = new Int32Array(lengthB0).fill(CERTAINTY_NOT_CALCULATED);
137
+ const similarities = new Int32Array(lengthB0 * width).fill(-1);
138
+
139
+ /** `get_similarity`'s index: `lineA` and `closestA` relative to the chunk of A */
140
+ const simAt = (lineA: number, row: number, closestA: number) =>
141
+ lineA - closestA + maxA + row * width;
142
+
143
+ /** `find_best_line_matches` for B's line `row` (`bOff + local`) */
144
+ const findBest = (
145
+ startA: number,
146
+ lengthA: number,
147
+ startB: number,
148
+ local: number,
149
+ row: number,
150
+ ) => {
151
+ if (certainties[row] !== CERTAINTY_NOT_CALCULATED) return;
152
+ const closest = mapLineNumber(local + startB, mapping) - startA;
153
+ const searchStart = Math.max(0, closest - maxA);
154
+ const searchEnd = Math.min(lengthA, closest + maxA + 1);
155
+ let best = 0;
156
+ let secondBestSim = 0;
157
+ let bestIndex = 0;
158
+ let secondBestIndex = 0;
159
+ const fb = targetFps[startB + local];
160
+ for (let i = searchStart; i < searchEnd; i++) {
161
+ const at = simAt(i, row, closest);
162
+ if (similarities[at] === -1) {
163
+ similarities[at] = similarity(parentFps[startA + i], fb) * (1000 - Math.abs(i - closest));
164
+ }
165
+ const sim = similarities[at];
166
+ if (sim > best) {
167
+ secondBestSim = best;
168
+ secondBestIndex = bestIndex;
169
+ best = sim;
170
+ bestIndex = i;
171
+ } else if (sim > secondBestSim) {
172
+ secondBestSim = sim;
173
+ secondBestIndex = i;
174
+ }
175
+ }
176
+ if (best === 0) {
177
+ certainties[row] = CERTAIN_NOTHING_MATCHES;
178
+ result[row] = -1;
179
+ } else {
180
+ certainties[row] = best * 2 - secondBestSim;
181
+ result[row] = startA + bestIndex;
182
+ secondBest[row] = startA + secondBestIndex;
183
+ }
184
+ };
185
+
186
+ // fuzzy_find_matching_lines_recurse, its recursion as a stack (first half first)
187
+ const stack: Array<[number, number, number, number, number]> = [
188
+ [startA0, startB0, lengthA0, lengthB0, 0],
189
+ ];
190
+ while (stack.length > 0) {
191
+ const [startA, startB, lengthA, lengthB, bOff] = stack.pop() as [
192
+ number,
193
+ number,
194
+ number,
195
+ number,
196
+ number,
197
+ ];
198
+ let mostCertainLocalB = -1;
199
+ let mostCertainty = -1;
200
+ for (let i = 0; i < lengthB; i++) {
201
+ findBest(startA, lengthA, startB, i, bOff + i);
202
+ if (certainties[bOff + i] > mostCertainty) {
203
+ mostCertainty = certainties[bOff + i];
204
+ mostCertainLocalB = i;
205
+ }
206
+ }
207
+ if (mostCertainLocalB === -1) continue;
208
+ const mostCertainA = result[bOff + mostCertainLocalB];
209
+ subtract(parentFps[mostCertainA], targetFps[startB + mostCertainLocalB]);
210
+ const invalidateMin = Math.max(0, mostCertainLocalB - maxB);
211
+ const invalidateMax = Math.min(lengthB, mostCertainLocalB + maxB + 1);
212
+ for (let i = invalidateMin; i < invalidateMax; i++) {
213
+ const closest = mapLineNumber(i + startB, mapping) - startA;
214
+ if (Math.abs(mostCertainA - startA - closest) > maxA) continue;
215
+ similarities[simAt(mostCertainA - startA, bOff + i, closest)] = -1;
216
+ }
217
+ for (let i = mostCertainLocalB - 1; i >= invalidateMin; i--) {
218
+ const row = bOff + i;
219
+ if (
220
+ certainties[row] >= 0 &&
221
+ (result[row] >= mostCertainA || secondBest[row] >= mostCertainA)
222
+ ) {
223
+ certainties[row] = CERTAINTY_NOT_CALCULATED;
224
+ }
225
+ }
226
+ for (let i = mostCertainLocalB + 1; i < invalidateMax; i++) {
227
+ const row = bOff + i;
228
+ if (
229
+ certainties[row] >= 0 &&
230
+ (result[row] <= mostCertainA || secondBest[row] <= mostCertainA)
231
+ ) {
232
+ certainties[row] = CERTAINTY_NOT_CALCULATED;
233
+ }
234
+ }
235
+ // pushed second half first: the first half (and all it splits into) runs before it
236
+ if (mostCertainLocalB + 1 < lengthB) {
237
+ const offsetB = mostCertainLocalB + 1;
238
+ stack.push([
239
+ mostCertainA,
240
+ startB + offsetB,
241
+ lengthA + startA - mostCertainA,
242
+ lengthB - offsetB,
243
+ bOff + offsetB,
244
+ ]);
245
+ }
246
+ if (mostCertainLocalB > 0) {
247
+ stack.push([startA, startB, mostCertainA + 1 - startA, mostCertainLocalB, bOff]);
248
+ }
249
+ }
250
+ return result;
251
+ }
252
+
253
+ /** git's `scan_parent_range`: the parent line most like a target line (at least 10 pairs) */
254
+ function scanParentRange(
255
+ parentFps: Fingerprint[],
256
+ targetFps: Fingerprint[],
257
+ tIdx: number,
258
+ from: number,
259
+ count: number,
260
+ ): number {
261
+ let bestSim = 10;
262
+ let bestIdx = -1;
263
+ for (let p = from; p < from + count; p++) {
264
+ const sim = similarity(parentFps[p], targetFps[tIdx]);
265
+ if (sim < bestSim) continue;
266
+ if (sim === bestSim && bestIdx !== -1 && Math.abs(bestIdx - tIdx) < Math.abs(p - tIdx)) {
267
+ continue;
268
+ }
269
+ bestSim = sim;
270
+ bestIdx = p;
271
+ }
272
+ return bestIdx;
273
+ }
274
+
275
+ /** Where a changed line of an ignored commit is blamed (`struct blame_line_tracker`) */
276
+ export interface LineBlame {
277
+ /** Whether it goes to the parent (else it stays with the ignored commit: unblamable) */
278
+ isParent: boolean;
279
+ /** Its line in the parent, or its own line in the target */
280
+ sLno: number;
281
+ }
282
+
283
+ /**
284
+ * git's `guess_line_blames`: for the target lines `[tlno, same)` of a diff chunk whose parent
285
+ * side is `parentLen` lines at `tlno + offset`, the parent line each came from, by the fuzzy
286
+ * match within the chunk, else the best match in the whole parent.
287
+ */
288
+ export function guessLineBlames(
289
+ parentFps: Fingerprint[],
290
+ targetFps: Fingerprint[],
291
+ tlno: number,
292
+ offset: number,
293
+ same: number,
294
+ parentLen: number,
295
+ ): LineBlame[] {
296
+ const fuzzy = fuzzyFindMatchingLines(parentFps, targetFps, tlno, tlno + offset, same, parentLen);
297
+ const out: LineBlame[] = new Array(same - tlno);
298
+ for (let i = 0; i < same - tlno; i++) {
299
+ const targetIdx = tlno + i;
300
+ const best =
301
+ fuzzy && fuzzy[i] >= 0
302
+ ? fuzzy[i]
303
+ : scanParentRange(parentFps, targetFps, targetIdx, 0, parentFps.length);
304
+ out[i] = best >= 0 ? { isParent: true, sLno: best } : { isParent: false, sLno: targetIdx };
305
+ }
306
+ return out;
307
+ }
@@ -0,0 +1,129 @@
1
+ /**
2
+ * `git check-mailmap` (builtin/check-mailmap.c): each contact as the repository's mailmap
3
+ * maps it (`.mailmap`, `mailmap.blob`, `mailmap.file`, plus `--mailmap-blob` and
4
+ * `--mailmap-file`).
5
+ *
6
+ * @example
7
+ * ```typescript
8
+ * // git check-mailmap "nick1 <bugs@company.xx>"
9
+ * await git.checkMailmap().addContact("nick1 <bugs@company.xx>").call();
10
+ * // "Some Dude <some@dude.xx>\n"
11
+ * ```
12
+ */
13
+
14
+ import { decodeGitPath } from "@statewalker/vcs-utils/encoding";
15
+ import { GitApiError } from "../errors/index.js";
16
+ import { GitCommand } from "../git-command.js";
17
+ import { hostEnvironmentOf } from "./git-ident.js";
18
+ import { type Mailmap, readMailmapBlob, readMailmapFile } from "./mailmap.js";
19
+ import { inputLines, splitIdent } from "./shortlog.js";
20
+
21
+ /**
22
+ * The contacts of `git check-mailmap <contact>...` (and `--stdin`'s lines after them), one
23
+ * output line each: `Name <email>`, or `<email>` when the result has no name.
24
+ *
25
+ * git 2.43 (`setCompatibility("2.43")`) takes only `Name <email>` contacts (`fatal: unable
26
+ * to parse contact: <contact>`) and has no `--mailmap-file`/`--mailmap-blob`; 2.47 and later
27
+ * also map a bare address. Where git dies, the error carries what was printed before
28
+ * ({@link getOutput}).
29
+ */
30
+ export class CheckMailmapCommand extends GitCommand<string> {
31
+ private readonly contacts: string[] = [];
32
+ private stdin?: string;
33
+ private mailmapFile?: string;
34
+ private mailmapBlob?: string;
35
+ private compatibility: "2.43" | "2.56" = "2.56";
36
+ private output = "";
37
+ private readonly errors: string[] = [];
38
+
39
+ /** A contact argument. */
40
+ addContact(contact: string): this {
41
+ this.checkCallable();
42
+ this.contacts.push(contact);
43
+ return this;
44
+ }
45
+
46
+ /** `--stdin`: these lines (git's stdin) checked after the arguments. */
47
+ setStdin(text: string): this {
48
+ this.checkCallable();
49
+ this.stdin = text;
50
+ return this;
51
+ }
52
+
53
+ /** `--mailmap-file=<file>` (git 2.47+): more entries from this host file. */
54
+ setMailmapFile(path: string): this {
55
+ this.checkCallable();
56
+ this.mailmapFile = path;
57
+ return this;
58
+ }
59
+
60
+ /** `--mailmap-blob=<blob>` (git 2.47+): more entries from this blob. */
61
+ setMailmapBlob(name: string): this {
62
+ this.checkCallable();
63
+ this.mailmapBlob = name;
64
+ return this;
65
+ }
66
+
67
+ /** The git version whose behaviour to follow (default 2.56). */
68
+ setCompatibility(version: "2.43" | "2.56"): this {
69
+ this.checkCallable();
70
+ this.compatibility = version;
71
+ return this;
72
+ }
73
+
74
+ /** What was printed on stdout (also after a death). */
75
+ getOutput(): string {
76
+ return this.output;
77
+ }
78
+
79
+ /** git's `error:` lines (a mailmap blob that is no blob). */
80
+ getErrors(): string[] {
81
+ return [...this.errors];
82
+ }
83
+
84
+ /** The output. */
85
+ async call(): Promise<string> {
86
+ this.checkCallable();
87
+ this.setCallable(false);
88
+ const legacy = this.compatibility === "2.43";
89
+ if (legacy && (this.mailmapFile !== undefined || this.mailmapBlob !== undefined)) {
90
+ const option = this.mailmapFile !== undefined ? "mailmap-file" : "mailmap-blob";
91
+ throw new GitApiError(
92
+ `error: unknown option \`${option}'\nusage: git check-mailmap [<options>] <contact>...`,
93
+ );
94
+ }
95
+ if (this.contacts.length === 0 && this.stdin === undefined)
96
+ throw new GitApiError("fatal: no contacts specified");
97
+ const onError = (line: string) => this.errors.push(line);
98
+ const mailmap = await this.readMailmap(onError);
99
+ if (this.mailmapBlob !== undefined) {
100
+ const bytes = await readMailmapBlob(
101
+ { readObjectNamed: (name) => this.readObjectNamed(name), onError },
102
+ this.mailmapBlob,
103
+ );
104
+ if (bytes) mailmap.read(decodeGitPath(bytes));
105
+ }
106
+ if (this.mailmapFile !== undefined) {
107
+ const bytes = await readMailmapFile(
108
+ this.mailmapFile,
109
+ hostEnvironmentOf(this._workingCopy),
110
+ this.worktreeAccess,
111
+ );
112
+ if (bytes) mailmap.read(decodeGitPath(bytes));
113
+ }
114
+ for (const contact of this.contacts) this.check(mailmap, contact, legacy);
115
+ if (this.stdin !== undefined)
116
+ for (const line of inputLines(this.stdin)) this.check(mailmap, line, legacy);
117
+ return this.output;
118
+ }
119
+
120
+ private check(mailmap: Mailmap, contact: string, legacy: boolean): void {
121
+ let ident = splitIdent(contact);
122
+ if (!ident) {
123
+ if (legacy) throw new GitApiError(`fatal: unable to parse contact: ${contact}`);
124
+ ident = { name: "", email: contact };
125
+ }
126
+ const mapped = mailmap.map(ident.name, ident.email);
127
+ this.output += `${mapped.name ? `${mapped.name} ` : ""}<${mapped.email}>\n`;
128
+ }
129
+ }
@@ -96,6 +96,7 @@ import { pushSparseWarnings, SparseUnpack } from "./sparse-checkout-support.js";
96
96
  import { StashApplyCommand } from "./stash-apply-command.js";
97
97
  import { StashCreateCommand } from "./stash-create-command.js";
98
98
  import { STASH_REF } from "./stash-list-command.js";
99
+ import { recursesIntoSubmodules, SubmoduleUnpack } from "./submodule-unpack.js";
99
100
  import { planTreeRestore, restoreCaseOptions, writeTreeRestorePlan } from "./tree-restore.js";
100
101
  import {
101
102
  entryNotUptodate,
@@ -293,6 +294,7 @@ export class CheckoutCommand extends GitCommand<CheckoutResult> {
293
294
  private conflictStyle?: ConflictStyle;
294
295
  private quiet = false;
295
296
  private countCheckoutPaths = false;
297
+ private recurseSubmodules?: boolean;
296
298
  /** `--pathspec-from-file` */
297
299
  private readonly pathspecFile = new PathspecFile();
298
300
  /** Set by a `merge` checkout the two-way merge refused: what the autostash needs */
@@ -642,6 +644,17 @@ export class CheckoutCommand extends GitCommand<CheckoutResult> {
642
644
  return this;
643
645
  }
644
646
 
647
+ /**
648
+ * `--[no-]recurse-submodules` (default `submodule.recurse`): the active submodules' worktrees
649
+ * are switched with the superproject's, their HEADs detached at the recorded commits, and
650
+ * local changes in them refuse the switch as git's unpack-trees refuses them.
651
+ */
652
+ setRecurseSubmodules(recurse: boolean): this {
653
+ this.checkCallable();
654
+ this.recurseSubmodules = recurse;
655
+ return this;
656
+ }
657
+
645
658
  /** `-q`: a path checkout reports no counts and no "path is unmerged" warnings. */
646
659
  setQuiet(quiet: boolean): this {
647
660
  this.checkCallable();
@@ -1021,6 +1034,7 @@ export class CheckoutCommand extends GitCommand<CheckoutResult> {
1021
1034
  if (this.startPoint !== undefined) copy.setStartPoint(this.startPoint);
1022
1035
  if (this.guess !== undefined) copy.setGuess(this.guess);
1023
1036
  if (this.hasReflogAction()) copy.setReflogAction(this.reflogAction("checkout"));
1037
+ if (this.recurseSubmodules !== undefined) copy.setRecurseSubmodules(this.recurseSubmodules);
1024
1038
  return copy;
1025
1039
  }
1026
1040
 
@@ -1059,6 +1073,9 @@ export class CheckoutCommand extends GitCommand<CheckoutResult> {
1059
1073
  quiet: this.quiet,
1060
1074
  countCheckoutPaths: this.countCheckoutPaths,
1061
1075
  globalMagic: this.globalPathspecMagic(),
1076
+ ...(this.recurseSubmodules !== undefined
1077
+ ? { recurseSubmodules: this.recurseSubmodules }
1078
+ : {}),
1062
1079
  });
1063
1080
  return pathCheckoutResult(outcome);
1064
1081
  }
@@ -1171,6 +1188,15 @@ export class CheckoutCommand extends GitCommand<CheckoutResult> {
1171
1188
  });
1172
1189
  const quiet = (path: string) => sparse?.leavesAlone(path) === true;
1173
1190
  const writes = (path: string) => !sparse || sparse.writes(path);
1191
+ // --recurse-submodules: unpack-trees' submodule checks and moves (forced: o->reset)
1192
+ const subs = this.worktreeAccess
1193
+ ? await SubmoduleUnpack.start(this.workingCopy, {
1194
+ recurse: recursesIntoSubmodules(this.workingCopy, this.recurseSubmodules),
1195
+ reset: this.force,
1196
+ })
1197
+ : undefined;
1198
+ /** New submodules whose checks replace the untracked-file checks (verify_absent_1) */
1199
+ const submodulePaths = new Set<string>();
1174
1200
 
1175
1201
  // git's two-way merge (unpack-trees `twoway_merge`, checkout without -f): a path HEAD
1176
1202
  // and the target agree on keeps its index entry and worktree file as they are (local
@@ -1230,6 +1256,11 @@ export class CheckoutCommand extends GitCommand<CheckoutResult> {
1230
1256
  const h = head.get(path);
1231
1257
  const t = target.get(path);
1232
1258
  if (initial && t) {
1259
+ if (subs && !quiet(path)) {
1260
+ const absent = await subs.absentRefuses(path, t);
1261
+ if (absent !== undefined) submodulePaths.add(path);
1262
+ if (!absent) await subs.mergedRefuses(path, index.get(path), t);
1263
+ }
1233
1264
  switched.push(path);
1234
1265
  continue;
1235
1266
  }
@@ -1242,6 +1273,8 @@ export class CheckoutCommand extends GitCommand<CheckoutResult> {
1242
1273
  continue;
1243
1274
  }
1244
1275
  if (quiet(path)) continue;
1276
+ // merged_entry's submodule check (FORCE): the submodule must be able to move
1277
+ if (subs && t && !sameSide(i, t)) await subs.mergedRefuses(path, i, t);
1245
1278
  if (!sameSide(i, t) || t) switched.push(path);
1246
1279
  continue;
1247
1280
  }
@@ -1258,6 +1291,29 @@ export class CheckoutCommand extends GitCommand<CheckoutResult> {
1258
1291
  if (i !== undefined || t !== undefined) local.push(path);
1259
1292
  continue;
1260
1293
  }
1294
+ if (subs && worktree && !quiet(path)) {
1295
+ if (i !== undefined && i.mode === FileMode.GITLINK) {
1296
+ // deleted_entry's verify_absent_if_directory of the submodule going away
1297
+ if (!t && (await subs.isSubmodule(path, i)) && (await subs.exists(path))) {
1298
+ await subs.refuses(path, (h ?? i).objectId, null);
1299
+ }
1300
+ const refused = await subs.notUptodate(path, i);
1301
+ if (refused) {
1302
+ local.push(path);
1303
+ continue;
1304
+ }
1305
+ if (refused === false) {
1306
+ if (t && t.mode !== FileMode.GITLINK) await subs.fileReplacesRefuses(path, i);
1307
+ if (t) await subs.mergedRefuses(path, i, t);
1308
+ switched.push(path);
1309
+ continue;
1310
+ }
1311
+ } else if (i === undefined && t) {
1312
+ const absent = await subs.absentRefuses(path, t);
1313
+ if (absent !== undefined) submodulePaths.add(path);
1314
+ if (!absent) await subs.mergedRefuses(path, undefined, t);
1315
+ }
1316
+ }
1261
1317
  if (
1262
1318
  i !== undefined &&
1263
1319
  worktree &&
@@ -1267,6 +1323,7 @@ export class CheckoutCommand extends GitCommand<CheckoutResult> {
1267
1323
  local.push(path);
1268
1324
  continue;
1269
1325
  }
1326
+ if (subs && i !== undefined && t && !quiet(path)) await subs.mergedRefuses(path, i, t);
1270
1327
  switched.push(path);
1271
1328
  }
1272
1329
 
@@ -1275,7 +1332,7 @@ export class CheckoutCommand extends GitCommand<CheckoutResult> {
1275
1332
  // component, untracked files in a directory a file replaces
1276
1333
  if (worktree && !this.force) {
1277
1334
  const found = await findInTheWay(worktree, {
1278
- writes: switched.filter((p) => target.has(p) && writes(p)),
1335
+ writes: switched.filter((p) => target.has(p) && writes(p) && !submodulePaths.has(p)),
1279
1336
  removes: new Set(switched.filter((p) => !target.has(p))),
1280
1337
  index,
1281
1338
  ...(await restoreCaseOptions(worktree, ignoreCase)),
@@ -1366,20 +1423,29 @@ export class CheckoutCommand extends GitCommand<CheckoutResult> {
1366
1423
  : await this.abbreviateObjectId(headId),
1367
1424
  };
1368
1425
  }
1369
- if (local.length + untracked.length + untrackedRemoved.length + lostDirs.length > 0) {
1370
- const message = overwriteMessage("checkout", {
1371
- local,
1372
- lostDirs,
1373
- untracked,
1374
- untrackedRemoved,
1375
- });
1426
+ const submodules = subs?.rejected ?? [];
1427
+ if (
1428
+ local.length + untracked.length + untrackedRemoved.length + lostDirs.length > 0 ||
1429
+ submodules.length > 0
1430
+ ) {
1431
+ // a forced switch runs unpack-trees without porcelain messages (reset_tree)
1432
+ const message =
1433
+ this.force && subs
1434
+ ? subs.refusalLines(true).join("\n")
1435
+ : overwriteMessage("checkout", {
1436
+ local,
1437
+ lostDirs,
1438
+ untracked,
1439
+ untrackedRemoved,
1440
+ submodules,
1441
+ });
1376
1442
  return {
1377
1443
  status: CheckoutStatus.CONFLICTS,
1378
1444
  updated: [],
1379
1445
  removed: [],
1380
- conflicts: [...local, ...lostDirs, ...untracked, ...untrackedRemoved],
1446
+ conflicts: [...local, ...lostDirs, ...untracked, ...untrackedRemoved, ...submodules],
1381
1447
  ref: null,
1382
- message,
1448
+ message: `${subs?.printed() ?? ""}${message ?? ""}`,
1383
1449
  };
1384
1450
  }
1385
1451
 
@@ -1411,7 +1477,9 @@ export class CheckoutCommand extends GitCommand<CheckoutResult> {
1411
1477
  }
1412
1478
  for (const path of switched) {
1413
1479
  if (target.has(path) || quiet(path)) continue;
1414
- await worktree.remove(path);
1480
+ const old = index.get(path);
1481
+ if (subs && old?.mode === FileMode.GITLINK) await subs.unlink(worktree, path, old);
1482
+ else await worktree.remove(path);
1415
1483
  await pruneEmptyParents(worktree, path);
1416
1484
  removed.push(path);
1417
1485
  }
@@ -1425,11 +1493,23 @@ export class CheckoutCommand extends GitCommand<CheckoutResult> {
1425
1493
  if (this.force) {
1426
1494
  for (const path of index.keys()) {
1427
1495
  if (!target.has(path) && !switching.has(path) && !quiet(path)) {
1428
- await worktree.remove(path);
1496
+ const old = index.get(path);
1497
+ if (subs && old?.mode === FileMode.GITLINK) await subs.unlink(worktree, path, old);
1498
+ else await worktree.remove(path);
1429
1499
  removed.push(path);
1430
1500
  }
1431
1501
  }
1432
1502
  }
1503
+ // a file replacing a submodule: its directory goes (checkout_entry's remove_subtree)
1504
+ if (subs) {
1505
+ for (const path of switched) {
1506
+ const old = index.get(path);
1507
+ const t = target.get(path);
1508
+ if (old?.mode === FileMode.GITLINK && t && t.mode !== FileMode.GITLINK && writes(path)) {
1509
+ await subs.removeForFile(worktree, path, old);
1510
+ }
1511
+ }
1512
+ }
1433
1513
  // in a sparse checkout, only the paths in its patterns are written
1434
1514
  const only = plan && {
1435
1515
  ...plan,
@@ -1458,6 +1538,11 @@ export class CheckoutCommand extends GitCommand<CheckoutResult> {
1458
1538
  });
1459
1539
  updated.push(...only.entries.map((e) => e.path));
1460
1540
  for (const e of [...only.entries, ...only.gitlinks]) written.add(e.path);
1541
+ if (subs) {
1542
+ // check_updates: `.gitmodules` read again, then the submodules checked out
1543
+ subs.reload();
1544
+ for (const e of only.gitlinks) await subs.checkout(worktree, e.path, e);
1545
+ }
1461
1546
  }
1462
1547
  }
1463
1548