@statewalker/vcs-commands 0.7.0 → 0.8.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 (410) hide show
  1. package/dist/commands/add-command.d.ts +38 -0
  2. package/dist/commands/add-command.d.ts.map +1 -1
  3. package/dist/commands/am/am-command.d.ts +55 -1
  4. package/dist/commands/am/am-command.d.ts.map +1 -1
  5. package/dist/commands/am/index.d.ts +1 -0
  6. package/dist/commands/am/index.d.ts.map +1 -1
  7. package/dist/commands/am/mailsplit.d.ts +88 -0
  8. package/dist/commands/am/mailsplit.d.ts.map +1 -0
  9. package/dist/commands/apply/apply-command.d.ts.map +1 -1
  10. package/dist/commands/apply/apply-engine.d.ts.map +1 -1
  11. package/dist/commands/apply/apply-parse.d.ts.map +1 -1
  12. package/dist/commands/bisect/bisect-command.d.ts +2 -0
  13. package/dist/commands/bisect/bisect-command.d.ts.map +1 -1
  14. package/dist/commands/branch-command.d.ts +148 -18
  15. package/dist/commands/branch-command.d.ts.map +1 -1
  16. package/dist/commands/branch-info-command.d.ts +55 -0
  17. package/dist/commands/branch-info-command.d.ts.map +1 -0
  18. package/dist/commands/branch-tracking.d.ts +106 -17
  19. package/dist/commands/branch-tracking.d.ts.map +1 -1
  20. package/dist/commands/branch-upstream-command.d.ts +83 -0
  21. package/dist/commands/branch-upstream-command.d.ts.map +1 -0
  22. package/dist/commands/checkout-command.d.ts +19 -3
  23. package/dist/commands/checkout-command.d.ts.map +1 -1
  24. package/dist/commands/cherry-pick-command.d.ts +59 -0
  25. package/dist/commands/cherry-pick-command.d.ts.map +1 -1
  26. package/dist/commands/clean-command.d.ts +12 -0
  27. package/dist/commands/clean-command.d.ts.map +1 -1
  28. package/dist/commands/clone-command.d.ts.map +1 -1
  29. package/dist/commands/commit-command.d.ts +191 -5
  30. package/dist/commands/commit-command.d.ts.map +1 -1
  31. package/dist/commands/commit-reuse.d.ts +33 -0
  32. package/dist/commands/commit-reuse.d.ts.map +1 -0
  33. package/dist/commands/config-command.d.ts +236 -0
  34. package/dist/commands/config-command.d.ts.map +1 -0
  35. package/dist/commands/config-value-types.d.ts +91 -0
  36. package/dist/commands/config-value-types.d.ts.map +1 -0
  37. package/dist/commands/core-config.d.ts +20 -0
  38. package/dist/commands/core-config.d.ts.map +1 -1
  39. package/dist/commands/diff-color-config.d.ts +73 -0
  40. package/dist/commands/diff-color-config.d.ts.map +1 -0
  41. package/dist/commands/diff-command.d.ts +252 -5
  42. package/dist/commands/diff-command.d.ts.map +1 -1
  43. package/dist/commands/fetch-command.d.ts +20 -0
  44. package/dist/commands/fetch-command.d.ts.map +1 -1
  45. package/dist/commands/fmt-merge-msg-command.d.ts +124 -0
  46. package/dist/commands/fmt-merge-msg-command.d.ts.map +1 -0
  47. package/dist/commands/fork-point.d.ts +38 -0
  48. package/dist/commands/fork-point.d.ts.map +1 -0
  49. package/dist/commands/format-patch-command.d.ts +41 -1
  50. package/dist/commands/format-patch-command.d.ts.map +1 -1
  51. package/dist/commands/fsck/fetch-fsck.d.ts +51 -0
  52. package/dist/commands/fsck/fetch-fsck.d.ts.map +1 -1
  53. package/dist/commands/gc-command.d.ts +8 -0
  54. package/dist/commands/gc-command.d.ts.map +1 -1
  55. package/dist/commands/git-describe.d.ts +4 -0
  56. package/dist/commands/git-describe.d.ts.map +1 -1
  57. package/dist/commands/git-hooks.d.ts +35 -0
  58. package/dist/commands/git-hooks.d.ts.map +1 -1
  59. package/dist/commands/grep/grep-command.d.ts +210 -0
  60. package/dist/commands/grep/grep-command.d.ts.map +1 -0
  61. package/dist/commands/grep/grep-engine.d.ts +218 -0
  62. package/dist/commands/grep/grep-engine.d.ts.map +1 -0
  63. package/dist/commands/grep/index.d.ts +3 -0
  64. package/dist/commands/grep/index.d.ts.map +1 -0
  65. package/dist/commands/index-adder.d.ts +13 -2
  66. package/dist/commands/index-adder.d.ts.map +1 -1
  67. package/dist/commands/index.d.ts +26 -0
  68. package/dist/commands/index.d.ts.map +1 -1
  69. package/dist/commands/index.js +3 -3
  70. package/dist/commands/interpret-trailers-command.d.ts +90 -0
  71. package/dist/commands/interpret-trailers-command.d.ts.map +1 -0
  72. package/dist/commands/local-transport.d.ts +36 -5
  73. package/dist/commands/local-transport.d.ts.map +1 -1
  74. package/dist/commands/log-command.d.ts +296 -11
  75. package/dist/commands/log-command.d.ts.map +1 -1
  76. package/dist/commands/log-graph.d.ts +26 -1
  77. package/dist/commands/log-graph.d.ts.map +1 -1
  78. package/dist/commands/log-output.d.ts +133 -5
  79. package/dist/commands/log-output.d.ts.map +1 -1
  80. package/dist/commands/ls-remote-command.d.ts +2 -0
  81. package/dist/commands/ls-remote-command.d.ts.map +1 -1
  82. package/dist/commands/mailmap.d.ts +30 -0
  83. package/dist/commands/mailmap.d.ts.map +1 -1
  84. package/dist/commands/merge-base-command.d.ts +60 -0
  85. package/dist/commands/merge-base-command.d.ts.map +1 -0
  86. package/dist/commands/merge-bases.d.ts +23 -0
  87. package/dist/commands/merge-bases.d.ts.map +1 -1
  88. package/dist/commands/merge-command.d.ts +96 -9
  89. package/dist/commands/merge-command.d.ts.map +1 -1
  90. package/dist/commands/merge-support.d.ts.map +1 -1
  91. package/dist/commands/mv-command.d.ts +4 -0
  92. package/dist/commands/mv-command.d.ts.map +1 -1
  93. package/dist/commands/name-rev.d.ts +48 -0
  94. package/dist/commands/name-rev.d.ts.map +1 -0
  95. package/dist/commands/notes-command.d.ts.map +1 -1
  96. package/dist/commands/pathspec-file.d.ts +39 -0
  97. package/dist/commands/pathspec-file.d.ts.map +1 -0
  98. package/dist/commands/pathspec.d.ts +3 -0
  99. package/dist/commands/pathspec.d.ts.map +1 -1
  100. package/dist/commands/pretty-format.d.ts +43 -3
  101. package/dist/commands/pretty-format.d.ts.map +1 -1
  102. package/dist/commands/promisor-remote.d.ts.map +1 -1
  103. package/dist/commands/pull-command.d.ts +10 -0
  104. package/dist/commands/pull-command.d.ts.map +1 -1
  105. package/dist/commands/push-command.d.ts +160 -9
  106. package/dist/commands/push-command.d.ts.map +1 -1
  107. package/dist/commands/read-tree-command.d.ts +6 -0
  108. package/dist/commands/read-tree-command.d.ts.map +1 -1
  109. package/dist/commands/rebase-command.d.ts +168 -6
  110. package/dist/commands/rebase-command.d.ts.map +1 -1
  111. package/dist/commands/ref-filter/for-each-ref-command.d.ts +121 -0
  112. package/dist/commands/ref-filter/for-each-ref-command.d.ts.map +1 -0
  113. package/dist/commands/ref-filter/index.d.ts +8 -0
  114. package/dist/commands/ref-filter/index.d.ts.map +1 -0
  115. package/dist/commands/ref-filter/ref-atoms.d.ts +88 -0
  116. package/dist/commands/ref-filter/ref-atoms.d.ts.map +1 -0
  117. package/dist/commands/ref-filter/ref-filter.d.ts +178 -0
  118. package/dist/commands/ref-filter/ref-filter.d.ts.map +1 -0
  119. package/dist/commands/ref-filter/ref-format.d.ts +222 -0
  120. package/dist/commands/ref-filter/ref-format.d.ts.map +1 -0
  121. package/dist/commands/ref-filter/ref-listing-command.d.ts +56 -0
  122. package/dist/commands/ref-filter/ref-listing-command.d.ts.map +1 -0
  123. package/dist/commands/ref-filter/ref-quote.d.ts +20 -0
  124. package/dist/commands/ref-filter/ref-quote.d.ts.map +1 -0
  125. package/dist/commands/ref-filter/version-compare.d.ts +20 -0
  126. package/dist/commands/ref-filter/version-compare.d.ts.map +1 -0
  127. package/dist/commands/reflog-command.d.ts +120 -0
  128. package/dist/commands/reflog-command.d.ts.map +1 -1
  129. package/dist/commands/reflog-walk.d.ts +72 -0
  130. package/dist/commands/reflog-walk.d.ts.map +1 -0
  131. package/dist/commands/remote-command.d.ts +138 -29
  132. package/dist/commands/remote-command.d.ts.map +1 -1
  133. package/dist/commands/remote-transport.d.ts +7 -1
  134. package/dist/commands/remote-transport.d.ts.map +1 -1
  135. package/dist/commands/reset-command.d.ts +2 -3
  136. package/dist/commands/reset-command.d.ts.map +1 -1
  137. package/dist/commands/restore-command.d.ts +2 -3
  138. package/dist/commands/restore-command.d.ts.map +1 -1
  139. package/dist/commands/rev-filter/commit-filter.d.ts +95 -0
  140. package/dist/commands/rev-filter/commit-filter.d.ts.map +1 -0
  141. package/dist/commands/rev-filter/commit-grep.d.ts +91 -0
  142. package/dist/commands/rev-filter/commit-grep.d.ts.map +1 -0
  143. package/dist/commands/rev-filter/index.d.ts +3 -0
  144. package/dist/commands/rev-filter/index.d.ts.map +1 -0
  145. package/dist/commands/rev-list-command.d.ts +154 -2
  146. package/dist/commands/rev-list-command.d.ts.map +1 -1
  147. package/dist/commands/revert-command.d.ts +32 -0
  148. package/dist/commands/revert-command.d.ts.map +1 -1
  149. package/dist/commands/revision-range.d.ts +32 -1
  150. package/dist/commands/revision-range.d.ts.map +1 -1
  151. package/dist/commands/revision-resolver.d.ts +15 -0
  152. package/dist/commands/revision-resolver.d.ts.map +1 -1
  153. package/dist/commands/rm-command.d.ts +70 -2
  154. package/dist/commands/rm-command.d.ts.map +1 -1
  155. package/dist/commands/sequencer-pick.d.ts +84 -4
  156. package/dist/commands/sequencer-pick.d.ts.map +1 -1
  157. package/dist/commands/sequencer-support.d.ts +2 -0
  158. package/dist/commands/sequencer-support.d.ts.map +1 -1
  159. package/dist/commands/serve-repository.d.ts +7 -0
  160. package/dist/commands/serve-repository.d.ts.map +1 -1
  161. package/dist/commands/show-command.d.ts +130 -0
  162. package/dist/commands/show-command.d.ts.map +1 -0
  163. package/dist/commands/show-commit.d.ts +11 -0
  164. package/dist/commands/show-commit.d.ts.map +1 -0
  165. package/dist/commands/signature-check.d.ts +164 -0
  166. package/dist/commands/signature-check.d.ts.map +1 -0
  167. package/dist/commands/signing.d.ts +160 -0
  168. package/dist/commands/signing.d.ts.map +1 -0
  169. package/dist/commands/sparse-checkout-command.d.ts.map +1 -1
  170. package/dist/commands/sparse-index-view.d.ts +45 -0
  171. package/dist/commands/sparse-index-view.d.ts.map +1 -0
  172. package/dist/commands/ssh-signer.d.ts +29 -0
  173. package/dist/commands/ssh-signer.d.ts.map +1 -0
  174. package/dist/commands/ssh-verifier.d.ts +42 -0
  175. package/dist/commands/ssh-verifier.d.ts.map +1 -0
  176. package/dist/commands/stash-apply-command.d.ts +5 -0
  177. package/dist/commands/stash-apply-command.d.ts.map +1 -1
  178. package/dist/commands/stash-branch-command.d.ts +34 -0
  179. package/dist/commands/stash-branch-command.d.ts.map +1 -0
  180. package/dist/commands/stash-create-command.d.ts +17 -0
  181. package/dist/commands/stash-create-command.d.ts.map +1 -1
  182. package/dist/commands/stash-info.d.ts +93 -0
  183. package/dist/commands/stash-info.d.ts.map +1 -0
  184. package/dist/commands/stash-list-command.d.ts +16 -0
  185. package/dist/commands/stash-list-command.d.ts.map +1 -1
  186. package/dist/commands/stash-pop-command.d.ts +39 -0
  187. package/dist/commands/stash-pop-command.d.ts.map +1 -0
  188. package/dist/commands/stash-show-command.d.ts +48 -0
  189. package/dist/commands/stash-show-command.d.ts.map +1 -0
  190. package/dist/commands/stash-store-command.d.ts +29 -0
  191. package/dist/commands/stash-store-command.d.ts.map +1 -0
  192. package/dist/commands/stash-working-tree.d.ts.map +1 -1
  193. package/dist/commands/status-command.d.ts.map +1 -1
  194. package/dist/commands/status-header.d.ts +5 -0
  195. package/dist/commands/status-header.d.ts.map +1 -1
  196. package/dist/commands/submodule-add-command.d.ts +89 -0
  197. package/dist/commands/submodule-add-command.d.ts.map +1 -0
  198. package/dist/commands/submodule-auth.d.ts +90 -0
  199. package/dist/commands/submodule-auth.d.ts.map +1 -0
  200. package/dist/commands/submodule-commands.d.ts +375 -0
  201. package/dist/commands/submodule-commands.d.ts.map +1 -0
  202. package/dist/commands/submodule-model.d.ts +288 -0
  203. package/dist/commands/submodule-model.d.ts.map +1 -0
  204. package/dist/commands/submodule-update-command.d.ts +198 -0
  205. package/dist/commands/submodule-update-command.d.ts.map +1 -0
  206. package/dist/commands/switch-command.d.ts.map +1 -1
  207. package/dist/commands/tag-command.d.ts +259 -10
  208. package/dist/commands/tag-command.d.ts.map +1 -1
  209. package/dist/commands/trailers.d.ts +218 -17
  210. package/dist/commands/trailers.d.ts.map +1 -1
  211. package/dist/commands/tree-restore.d.ts +7 -0
  212. package/dist/commands/tree-restore.d.ts.map +1 -1
  213. package/dist/commands/verify-command.d.ts +92 -0
  214. package/dist/commands/verify-command.d.ts.map +1 -0
  215. package/dist/commands/worktree-add-command.d.ts +79 -7
  216. package/dist/commands/worktree-add-command.d.ts.map +1 -1
  217. package/dist/commands/worktree-path-rules.d.ts +66 -0
  218. package/dist/commands/worktree-path-rules.d.ts.map +1 -0
  219. package/dist/commands/worktree-remove-command.d.ts +10 -3
  220. package/dist/commands/worktree-remove-command.d.ts.map +1 -1
  221. package/dist/commands/worktree-repair-command.d.ts +15 -2
  222. package/dist/commands/worktree-repair-command.d.ts.map +1 -1
  223. package/dist/commands/worktree-support.d.ts +5 -0
  224. package/dist/commands/worktree-support.d.ts.map +1 -1
  225. package/dist/{commands-DIJ91NnD.js → commands-ISM52N0n.js} +70736 -54492
  226. package/dist/errors/checkout-errors.d.ts +19 -0
  227. package/dist/errors/checkout-errors.d.ts.map +1 -1
  228. package/dist/errors/command-errors.d.ts.map +1 -1
  229. package/dist/errors/index.js +57 -3
  230. package/dist/errors/ref-errors.d.ts +19 -0
  231. package/dist/errors/ref-errors.d.ts.map +1 -1
  232. package/dist/errors/worktree-errors.d.ts +6 -1
  233. package/dist/errors/worktree-errors.d.ts.map +1 -1
  234. package/dist/{git-command-BGiOJ8Zk.js → fsck-DLRpbwTj.js} +6230 -71
  235. package/dist/git-command.d.ts +27 -1
  236. package/dist/git-command.d.ts.map +1 -1
  237. package/dist/git.d.ts +267 -1
  238. package/dist/git.d.ts.map +1 -1
  239. package/dist/index.js +5 -5
  240. package/dist/remote-config/index.d.ts +1 -1
  241. package/dist/remote-config/index.d.ts.map +1 -1
  242. package/dist/remote-config/remote-config-store.d.ts +55 -0
  243. package/dist/remote-config/remote-config-store.d.ts.map +1 -1
  244. package/dist/results/combined-diff.d.ts +3 -0
  245. package/dist/results/combined-diff.d.ts.map +1 -1
  246. package/dist/results/diff-check.d.ts +38 -0
  247. package/dist/results/diff-check.d.ts.map +1 -0
  248. package/dist/results/diff-color.d.ts +135 -0
  249. package/dist/results/diff-color.d.ts.map +1 -0
  250. package/dist/results/diff-output.d.ts +85 -1
  251. package/dist/results/diff-output.d.ts.map +1 -1
  252. package/dist/results/diff-pickaxe.d.ts +67 -0
  253. package/dist/results/diff-pickaxe.d.ts.map +1 -0
  254. package/dist/results/diff-words.d.ts +55 -0
  255. package/dist/results/diff-words.d.ts.map +1 -0
  256. package/dist/results/index.d.ts +4 -0
  257. package/dist/results/index.d.ts.map +1 -1
  258. package/dist/results/index.js +2 -2
  259. package/dist/results/push-result.d.ts +7 -0
  260. package/dist/results/push-result.d.ts.map +1 -1
  261. package/dist/results/rebase-result.d.ts +2 -0
  262. package/dist/results/rebase-result.d.ts.map +1 -1
  263. package/dist/results/stash-result.d.ts +6 -0
  264. package/dist/results/stash-result.d.ts.map +1 -1
  265. package/dist/{results-WVlBhVb1.js → results-TB2IJ64h.js} +2168 -403
  266. package/dist/whitespace/index.d.ts +2 -0
  267. package/dist/whitespace/index.d.ts.map +1 -0
  268. package/dist/whitespace/whitespace-rule.d.ts +94 -0
  269. package/dist/whitespace/whitespace-rule.d.ts.map +1 -0
  270. package/package.json +12 -12
  271. package/src/commands/add-command.ts +178 -17
  272. package/src/commands/am/am-command.ts +262 -42
  273. package/src/commands/am/index.ts +1 -0
  274. package/src/commands/am/mailsplit.ts +326 -0
  275. package/src/commands/apply/apply-command.ts +6 -6
  276. package/src/commands/apply/apply-engine.ts +1 -1
  277. package/src/commands/apply/apply-parse.ts +7 -8
  278. package/src/commands/bisect/bisect-command.ts +18 -5
  279. package/src/commands/branch-command.ts +528 -53
  280. package/src/commands/branch-info-command.ts +150 -0
  281. package/src/commands/branch-tracking.ts +335 -60
  282. package/src/commands/branch-upstream-command.ts +218 -0
  283. package/src/commands/checkout-command.ts +69 -43
  284. package/src/commands/cherry-pick-command.ts +143 -0
  285. package/src/commands/clean-command.ts +34 -3
  286. package/src/commands/clone-command.ts +2 -1
  287. package/src/commands/commit-command.ts +782 -64
  288. package/src/commands/commit-reuse.ts +94 -0
  289. package/src/commands/config-command.ts +1256 -0
  290. package/src/commands/config-value-types.ts +358 -0
  291. package/src/commands/core-config.ts +40 -0
  292. package/src/commands/diff-color-config.ts +274 -0
  293. package/src/commands/diff-command.ts +1009 -49
  294. package/src/commands/fetch-command.ts +142 -8
  295. package/src/commands/fmt-merge-msg-command.ts +715 -0
  296. package/src/commands/fork-point.ts +63 -0
  297. package/src/commands/format-patch-command.ts +314 -46
  298. package/src/commands/fsck/fetch-fsck.ts +172 -18
  299. package/src/commands/gc-command.ts +31 -1
  300. package/src/commands/git-describe.ts +31 -11
  301. package/src/commands/git-hooks.ts +81 -0
  302. package/src/commands/grep/grep-command.ts +1077 -0
  303. package/src/commands/grep/grep-engine.ts +1024 -0
  304. package/src/commands/grep/index.ts +2 -0
  305. package/src/commands/index-adder.ts +46 -7
  306. package/src/commands/index.ts +26 -0
  307. package/src/commands/interpret-trailers-command.ts +256 -0
  308. package/src/commands/local-transport.ts +109 -10
  309. package/src/commands/log-command.ts +1246 -210
  310. package/src/commands/log-graph.ts +123 -26
  311. package/src/commands/log-output.ts +280 -21
  312. package/src/commands/ls-remote-command.ts +5 -0
  313. package/src/commands/mailmap.ts +119 -0
  314. package/src/commands/merge-base-command.ts +170 -0
  315. package/src/commands/merge-bases.ts +63 -8
  316. package/src/commands/merge-command.ts +330 -82
  317. package/src/commands/merge-support.ts +14 -1
  318. package/src/commands/mv-command.ts +6 -3
  319. package/src/commands/name-rev.ts +171 -0
  320. package/src/commands/notes-command.ts +11 -1
  321. package/src/commands/pathspec-file.ts +72 -0
  322. package/src/commands/pathspec.ts +14 -2
  323. package/src/commands/pretty-format.ts +103 -19
  324. package/src/commands/promisor-remote.ts +10 -1
  325. package/src/commands/pull-command.ts +26 -7
  326. package/src/commands/push-command.ts +682 -65
  327. package/src/commands/read-tree-command.ts +28 -1
  328. package/src/commands/rebase-command.ts +933 -129
  329. package/src/commands/ref-filter/for-each-ref-command.ts +298 -0
  330. package/src/commands/ref-filter/index.ts +7 -0
  331. package/src/commands/ref-filter/ref-atoms.ts +581 -0
  332. package/src/commands/ref-filter/ref-filter.ts +651 -0
  333. package/src/commands/ref-filter/ref-format.ts +1070 -0
  334. package/src/commands/ref-filter/ref-listing-command.ts +421 -0
  335. package/src/commands/ref-filter/ref-quote.ts +69 -0
  336. package/src/commands/ref-filter/version-compare.ts +177 -0
  337. package/src/commands/reflog-command.ts +492 -2
  338. package/src/commands/reflog-walk.ts +234 -0
  339. package/src/commands/remote-command.ts +449 -69
  340. package/src/commands/remote-transport.ts +9 -1
  341. package/src/commands/reset-command.ts +36 -31
  342. package/src/commands/restore-command.ts +12 -41
  343. package/src/commands/rev-filter/commit-filter.ts +159 -0
  344. package/src/commands/rev-filter/commit-grep.ts +444 -0
  345. package/src/commands/rev-filter/index.ts +2 -0
  346. package/src/commands/rev-list-command.ts +402 -15
  347. package/src/commands/revert-command.ts +82 -0
  348. package/src/commands/revision-range.ts +204 -4
  349. package/src/commands/revision-resolver.ts +23 -8
  350. package/src/commands/rm-command.ts +282 -21
  351. package/src/commands/sequencer-pick.ts +498 -85
  352. package/src/commands/sequencer-support.ts +20 -2
  353. package/src/commands/serve-repository.ts +18 -3
  354. package/src/commands/show-command.ts +490 -0
  355. package/src/commands/show-commit.ts +24 -0
  356. package/src/commands/signature-check.ts +657 -0
  357. package/src/commands/signing.ts +385 -0
  358. package/src/commands/sparse-checkout-command.ts +2 -9
  359. package/src/commands/sparse-checkout-support.ts +2 -2
  360. package/src/commands/sparse-index-view.ts +135 -0
  361. package/src/commands/ssh-signer.ts +199 -0
  362. package/src/commands/ssh-verifier.ts +523 -0
  363. package/src/commands/stash-apply-command.ts +16 -4
  364. package/src/commands/stash-branch-command.ts +88 -0
  365. package/src/commands/stash-create-command.ts +28 -0
  366. package/src/commands/stash-info.ts +243 -0
  367. package/src/commands/stash-list-command.ts +33 -0
  368. package/src/commands/stash-pop-command.ts +83 -0
  369. package/src/commands/stash-show-command.ts +141 -0
  370. package/src/commands/stash-store-command.ts +82 -0
  371. package/src/commands/stash-working-tree.ts +2 -2
  372. package/src/commands/status-command.ts +5 -2
  373. package/src/commands/status-header.ts +41 -7
  374. package/src/commands/submodule-add-command.ts +509 -0
  375. package/src/commands/submodule-auth.ts +276 -0
  376. package/src/commands/submodule-commands.ts +1517 -0
  377. package/src/commands/submodule-model.ts +930 -0
  378. package/src/commands/submodule-update-command.ts +1092 -0
  379. package/src/commands/switch-command.ts +3 -1
  380. package/src/commands/tag-command.ts +876 -64
  381. package/src/commands/trailers.ts +837 -100
  382. package/src/commands/tree-restore.ts +38 -10
  383. package/src/commands/verify-command.ts +235 -0
  384. package/src/commands/worktree-add-command.ts +268 -24
  385. package/src/commands/worktree-path-rules.ts +183 -0
  386. package/src/commands/worktree-remove-command.ts +39 -5
  387. package/src/commands/worktree-repair-command.ts +52 -5
  388. package/src/commands/worktree-support.ts +22 -1
  389. package/src/errors/checkout-errors.ts +29 -0
  390. package/src/errors/command-errors.ts +2 -1
  391. package/src/errors/ref-errors.ts +23 -0
  392. package/src/errors/worktree-errors.ts +8 -1
  393. package/src/git-command.ts +66 -1
  394. package/src/git.ts +404 -1
  395. package/src/remote-config/index.ts +2 -0
  396. package/src/remote-config/remote-config-store.ts +101 -0
  397. package/src/results/combined-diff.ts +38 -18
  398. package/src/results/diff-check.ts +185 -0
  399. package/src/results/diff-color.ts +868 -0
  400. package/src/results/diff-output.ts +195 -30
  401. package/src/results/diff-pickaxe.ts +304 -0
  402. package/src/results/diff-words.ts +395 -0
  403. package/src/results/index.ts +4 -0
  404. package/src/results/push-result.ts +7 -0
  405. package/src/results/rebase-result.ts +3 -0
  406. package/src/results/stash-result.ts +7 -0
  407. package/src/whitespace/index.ts +1 -0
  408. package/src/{commands/apply/whitespace.ts → whitespace/whitespace-rule.ts} +173 -23
  409. package/dist/commands/apply/whitespace.d.ts +0 -58
  410. package/dist/commands/apply/whitespace.d.ts.map +0 -1
@@ -0,0 +1,1092 @@
1
+ /**
2
+ * `git submodule update` and `git submodule status` (builtin/submodule--helper.c
3
+ * `module_update`, `update_submodules`, `prepare_to_clone_next_submodule`, `update_submodule`,
4
+ * `run_update_procedure`, `run_update_command`; `module_status`, `status_submodule`,
5
+ * `compute_rev_name`), over the submodule model of `submodule-model.ts`, the clone, fetch,
6
+ * checkout, merge and rebase commands.
7
+ */
8
+ import type { ObjectId } from "@statewalker/vcs-core";
9
+ import {
10
+ type Credentials,
11
+ createDefaultTransports,
12
+ type GitTransportRegistry,
13
+ } from "@statewalker/vcs-transport";
14
+ import type { PosixFilesApi } from "@statewalker/vcs-utils/files";
15
+ import type { WorkingCopy } from "@statewalker/vcs-working-tree";
16
+
17
+ import { GitApiError } from "../errors/index.js";
18
+ import { GitCommand } from "../git-command.js";
19
+ import { RemoteConfigStore } from "../remote-config/index.js";
20
+ import { CheckoutCommand, CheckoutStatus } from "./checkout-command.js";
21
+ import { createIdAbbreviator } from "./core-config.js";
22
+ import { DiffCommand } from "./diff-command.js";
23
+ import { FetchCommand } from "./fetch-command.js";
24
+ import { createDescriber } from "./git-describe.js";
25
+ import { gitFileOf, hookRunnerOf } from "./git-hooks.js";
26
+ import { hostEnvironmentOf } from "./git-ident.js";
27
+ import { MergeCommand } from "./merge-command.js";
28
+ import { nameRevByTags } from "./name-rev.js";
29
+ import { RebaseCommand } from "./rebase-command.js";
30
+ import {
31
+ type CredentialsForUrl,
32
+ createSubmoduleAuthPolicy,
33
+ guardSubmoduleTransports,
34
+ type HeadersForUrl,
35
+ type SubmoduleAuthFor,
36
+ strictUrlOrigin,
37
+ } from "./submodule-auth.js";
38
+ import {
39
+ notFromUser,
40
+ SUBMODULE_UNSET_ENV,
41
+ SubmoduleCommandBase,
42
+ SubmoduleCommandError,
43
+ type SubmoduleCommandResult,
44
+ SubmoduleInitCommand,
45
+ type SubmoduleListEntry,
46
+ } from "./submodule-commands.js";
47
+ import {
48
+ defaultRemoteOf,
49
+ joinFilesPath,
50
+ openConfigFile,
51
+ parseSubmoduleUpdateStrategy,
52
+ relativeFilesPath,
53
+ resolveRelativeUrl,
54
+ type SubmoduleSettings,
55
+ type SubmoduleUpdateStrategy,
56
+ setInConfigFile,
57
+ worktreeHostPath,
58
+ } from "./submodule-model.js";
59
+
60
+ /** The update strategies `submodule update` takes on its command line. */
61
+ export type SubmoduleUpdateMode = "checkout" | "merge" | "rebase";
62
+
63
+ /** A submodule `update_submodules` goes on with (git's `update_clone_data`). */
64
+ interface UpdateRecord {
65
+ sub: SubmoduleSettings;
66
+ path: string;
67
+ id: ObjectId;
68
+ justCloned: boolean;
69
+ }
70
+
71
+ /**
72
+ * Questions asked inside a submodule's repository, as git's child processes ask them:
73
+ * `rev-list -n 1 <id> --not --all`, a ref's value, `describe` for `submodule status`.
74
+ */
75
+ class SubmoduleRepository extends GitCommand<never> {
76
+ async call(): Promise<never> {
77
+ throw new Error("not callable");
78
+ }
79
+
80
+ /** submodule--helper.c's `is_tip_reachable`: `id` exists and a ref (or HEAD) reaches it. */
81
+ async isTipReachable(id: ObjectId): Promise<boolean> {
82
+ if (!(await this.loadCommit(id))) return false;
83
+ const tips: ObjectId[] = [];
84
+ const head = await this.refsStore.resolve("HEAD").catch(() => undefined);
85
+ if (head?.objectId) tips.push(head.objectId);
86
+ for await (const ref of this.refsStore.list("refs/")) {
87
+ const direct = ref as { objectId?: ObjectId; target?: string };
88
+ const value =
89
+ direct.objectId && direct.target === undefined
90
+ ? direct.objectId
91
+ : (await this.refsStore.resolve(ref.name).catch(() => undefined))?.objectId;
92
+ if (value) tips.push(value);
93
+ }
94
+ const seen = new Set<ObjectId>();
95
+ const queue: ObjectId[] = [];
96
+ for (const tip of tips) queue.push(await this.peel(tip));
97
+ while (queue.length > 0) {
98
+ const oid = queue.pop() as ObjectId;
99
+ if (oid === id) return true;
100
+ if (seen.has(oid)) continue;
101
+ seen.add(oid);
102
+ const commit = await this.loadCommit(oid);
103
+ for (const parent of commit?.parents ?? []) if (!seen.has(parent)) queue.push(parent);
104
+ }
105
+ return false;
106
+ }
107
+
108
+ /** The id a full ref name holds, undefined when it has none. */
109
+ async refValue(name: string): Promise<ObjectId | undefined> {
110
+ return (await this.refsStore.resolve(name).catch(() => undefined))?.objectId;
111
+ }
112
+
113
+ /** The short name of HEAD's branch (`refs/heads/x`), undefined when detached. */
114
+ async currentBranch(): Promise<string | undefined> {
115
+ const ref = await this.getCurrentBranch().catch(() => undefined);
116
+ return ref?.startsWith("refs/") ? ref : undefined;
117
+ }
118
+
119
+ /**
120
+ * submodule--helper.c's `compute_rev_name`: `describe`, `describe --tags`, `describe
121
+ * --contains`, then `describe --all --always`, the first that answers.
122
+ */
123
+ async revName(id: ObjectId): Promise<string | undefined> {
124
+ // a missing commit: `describe --contains` (name-rev) skips it and succeeds, printing nothing
125
+ if (!(await this.loadCommit(id))) return "";
126
+ const abbreviator = createIdAbbreviator(this._workingCopy);
127
+ const tags = this.tagsStore;
128
+ const source = {
129
+ refs: this.refsStore,
130
+ ...(tags ? { tags } : {}),
131
+ commits: this.commits,
132
+ };
133
+ const describe = createDescriber({
134
+ ...source,
135
+ abbreviate: async (oid, length) => {
136
+ if (length === 0) return oid;
137
+ const lengths = await abbreviator.lengths([oid], length);
138
+ return oid.slice(0, lengths.get(oid) ?? 7);
139
+ },
140
+ });
141
+ const plain = await describe(id, {}).catch(() => "");
142
+ if (plain) return plain;
143
+ const lightweight = await describe(id, { tags: true }).catch(() => "");
144
+ if (lightweight) return lightweight;
145
+ const contains = await nameRevByTags(source, id).catch(() => undefined);
146
+ if (contains) return contains;
147
+ return (await describe(id, { all: true, always: true }).catch(() => "")) || undefined;
148
+ }
149
+
150
+ private async loadCommit(id: ObjectId) {
151
+ return this.commits.load(id).catch(() => undefined);
152
+ }
153
+
154
+ /** The commits a rebase of `head` onto `upstream` picks: non-merges `upstream..head`. */
155
+ async countPicks(upstream: ObjectId, head: ObjectId): Promise<number> {
156
+ const below = new Set<ObjectId>();
157
+ const stack: ObjectId[] = [upstream];
158
+ while (stack.length > 0) {
159
+ const oid = stack.pop() as ObjectId;
160
+ if (below.has(oid)) continue;
161
+ below.add(oid);
162
+ for (const p of (await this.loadCommit(oid))?.parents ?? []) stack.push(p);
163
+ }
164
+ let count = 0;
165
+ const seen = new Set<ObjectId>();
166
+ stack.push(head);
167
+ while (stack.length > 0) {
168
+ const oid = stack.pop() as ObjectId;
169
+ if (seen.has(oid) || below.has(oid)) continue;
170
+ seen.add(oid);
171
+ const parents = (await this.loadCommit(oid))?.parents ?? [];
172
+ if (parents.length < 2) count++;
173
+ stack.push(...parents);
174
+ }
175
+ return count;
176
+ }
177
+
178
+ private async peel(id: ObjectId): Promise<ObjectId> {
179
+ let oid = id;
180
+ const tags = this.tagsStore;
181
+ for (let depth = 0; depth < 32 && tags && (await tags.has(oid).catch(() => false)); depth++) {
182
+ const tag = await tags.load(oid).catch(() => undefined);
183
+ if (!tag) break;
184
+ oid = tag.object;
185
+ }
186
+ return oid;
187
+ }
188
+ }
189
+
190
+ const NULL_ID_CHAR = "0";
191
+
192
+ /**
193
+ * `git submodule update [--init] [--remote] [-N] [-f] [--checkout|--merge|--rebase]
194
+ * [--recursive] [--depth <n>] [--[no-]recommend-shallow] [--reference <repo>] [<path>...]`:
195
+ * each active submodule of the index (matching the paths) brought to the commit the index
196
+ * records. One not yet cloned is cloned into `.git/modules/<name>` first (or its kept git
197
+ * directory reconnected), and is then checked out detached at that commit; one already there
198
+ * is updated by its strategy (the command line's, else `submodule.<name>.update` of the
199
+ * configuration, else of `.gitmodules`, else `checkout`): `checkout -q` (`-f` when just
200
+ * cloned or forced), `rebase`, `merge`, `none` (skipped) or, from the configuration only,
201
+ * `!<command>` run through the host's command runner with the commit appended. A commit the
202
+ * submodule lacks is fetched first (`fetch`, then `fetch <remote> <commit>`).
203
+ *
204
+ * `--remote` takes the commit from the submodule's remote-tracking branch instead
205
+ * (`submodule.<name>.branch`, `.` for the superproject's branch, default `HEAD`), fetched
206
+ * first unless `--no-fetch`. `--init` runs `submodule init` first; `--recursive` goes on in
207
+ * each submodule's own submodules. Fetches and clones go through the transports given here;
208
+ * credentials and headers reach only the URLs they are given for (see {@link setCredentials},
209
+ * {@link setCredentialsForUrl}): `.gitmodules` is repository content, and can name any host.
210
+ *
211
+ * Output, refusals and the exit status are git's (stdout, stderr); where git returns 128
212
+ * the command throws {@link SubmoduleCommandError}.
213
+ *
214
+ * @example
215
+ * ```typescript
216
+ * const { stdout } = await git.submoduleUpdate().setInit(true).setRecursive(true).call();
217
+ * // "Submodule path 'lib': checked out '1a2b...'\n"
218
+ * ```
219
+ */
220
+ export class SubmoduleUpdateCommand extends SubmoduleCommandBase {
221
+ private readonly paths: string[] = [];
222
+ private init = false;
223
+ private remote = false;
224
+ private recursive = false;
225
+ private noFetch = false;
226
+ private force = false;
227
+ private mode?: SubmoduleUpdateMode;
228
+ private depth = 0;
229
+ private recommendShallow?: boolean;
230
+ private references: string[] = [];
231
+ private requireInit = false;
232
+ private transports?: GitTransportRegistry;
233
+ private credentials?: Credentials;
234
+ private headers?: Record<string, string>;
235
+ private readonly credentialOrigins: string[] = [];
236
+ private credentialsFor?: CredentialsForUrl;
237
+ private headersFor?: HeadersForUrl;
238
+ /** Set once at the top superproject, handed to nested updates unchanged */
239
+ private authPolicy?: SubmoduleAuthFor;
240
+ private timeout?: number;
241
+
242
+ /** A path (pathspec element) limiting the submodules; uninitialized ones are then reported. */
243
+ addPath(path: string): this {
244
+ this.checkCallable();
245
+ this.paths.push(path);
246
+ return this;
247
+ }
248
+
249
+ /** `--init`: `submodule init` the submodules first. */
250
+ setInit(init: boolean): this {
251
+ this.checkCallable();
252
+ this.init = init;
253
+ return this;
254
+ }
255
+
256
+ /** `--require-init`: `--init`, refusing to clone into a non-empty directory. */
257
+ setRequireInit(requireInit: boolean): this {
258
+ this.checkCallable();
259
+ this.requireInit = requireInit;
260
+ return this;
261
+ }
262
+
263
+ /** `--remote`: the commit of the submodule's remote-tracking branch. */
264
+ setRemote(remote: boolean): this {
265
+ this.checkCallable();
266
+ this.remote = remote;
267
+ return this;
268
+ }
269
+
270
+ /** `--recursive`: nested submodules too. */
271
+ setRecursive(recursive: boolean): this {
272
+ this.checkCallable();
273
+ this.recursive = recursive;
274
+ return this;
275
+ }
276
+
277
+ /** `-N` / `--no-fetch`: never fetch. */
278
+ setNoFetch(noFetch: boolean): this {
279
+ this.checkCallable();
280
+ this.noFetch = noFetch;
281
+ return this;
282
+ }
283
+
284
+ /** `-f`: run the update even at the recorded commit; checkout with `-f`. */
285
+ setForce(force: boolean): this {
286
+ this.checkCallable();
287
+ this.force = force;
288
+ return this;
289
+ }
290
+
291
+ /** `--checkout`, `--merge` or `--rebase`: the strategy for every submodule. */
292
+ setMode(mode: SubmoduleUpdateMode | undefined): this {
293
+ this.checkCallable();
294
+ this.mode = mode;
295
+ return this;
296
+ }
297
+
298
+ /** `--depth <n>`: shallow clones and fetches. */
299
+ setDepth(depth: number): this {
300
+ this.checkCallable();
301
+ this.depth = depth;
302
+ return this;
303
+ }
304
+
305
+ /**
306
+ * `--[no-]recommend-shallow`: whether a clone honours `submodule.<name>.shallow` (depth 1);
307
+ * by default it does.
308
+ */
309
+ setRecommendShallow(recommend: boolean): this {
310
+ this.checkCallable();
311
+ this.recommendShallow = recommend;
312
+ return this;
313
+ }
314
+
315
+ /** `--reference <repository>`: borrow objects in clones. */
316
+ addReference(reference: string): this {
317
+ this.checkCallable();
318
+ this.references.push(reference);
319
+ return this;
320
+ }
321
+
322
+ /** The transports clones and fetches reach non-local URLs through. */
323
+ setTransports(transports: GitTransportRegistry): this {
324
+ this.checkCallable();
325
+ this.transports = transports;
326
+ return this;
327
+ }
328
+
329
+ /**
330
+ * Credentials for clones and fetches of the trusted origins only: those named with
331
+ * {@link addCredentialOrigin}, or, when none is named, the origin (scheme, host, port) of
332
+ * the superproject's own remote, against which relative submodule URLs resolve. A
333
+ * submodule (at any depth) whose URL names another origin gets none; a local path or
334
+ * `file:` URL has no origin and gets none either. Use {@link setCredentialsForUrl} to
335
+ * decide per URL.
336
+ */
337
+ setCredentials(credentials: Credentials): this {
338
+ this.checkCallable();
339
+ this.credentials = credentials;
340
+ return this;
341
+ }
342
+
343
+ /** HTTP headers for clones and fetches of the trusted origins only (as {@link setCredentials}). */
344
+ setHeaders(headers: Record<string, string>): this {
345
+ this.checkCallable();
346
+ this.headers = headers;
347
+ return this;
348
+ }
349
+
350
+ /**
351
+ * An origin the static credentials and headers are for: a URL whose `<scheme>://<host>[:<port>]`
352
+ * is taken (`https://git.example.com`, or any URL of that host). Once one is named, the
353
+ * superproject's remote is no longer trusted by default.
354
+ */
355
+ addCredentialOrigin(url: string): this {
356
+ this.checkCallable();
357
+ const origin = strictUrlOrigin(url);
358
+ if (origin === undefined) {
359
+ throw new GitApiError(`fatal: '${url}' names no origin (scheme and host) for credentials`);
360
+ }
361
+ this.credentialOrigins.push(origin);
362
+ return this;
363
+ }
364
+
365
+ /**
366
+ * Asked with the URL of each clone and fetch (after `insteadOf`, at any depth, git's
367
+ * credential helpers' per-URL match): its credentials, or undefined for the static ones'
368
+ * rule ({@link setCredentials}).
369
+ */
370
+ setCredentialsForUrl(provider: CredentialsForUrl): this {
371
+ this.checkCallable();
372
+ this.credentialsFor = provider;
373
+ return this;
374
+ }
375
+
376
+ /** Asked with the URL of each clone and fetch: its headers (as {@link setCredentialsForUrl}). */
377
+ setHeadersForUrl(provider: HeadersForUrl): this {
378
+ this.checkCallable();
379
+ this.headersFor = provider;
380
+ return this;
381
+ }
382
+
383
+ /** @internal The top superproject's policy, for a nested update. */
384
+ setAuthPolicy(policy: SubmoduleAuthFor): this {
385
+ this.checkCallable();
386
+ this.authPolicy = policy;
387
+ return this;
388
+ }
389
+
390
+ private guarded?: GitTransportRegistry;
391
+
392
+ /**
393
+ * The transports clones and fetches go through: the given ones (default
394
+ * `createDefaultTransports()`) with every connector attaching the policy's credentials and
395
+ * headers itself, per URL and origin (`guardSubmoduleTransports`); the commands are given
396
+ * none, so nothing else can send them anywhere.
397
+ */
398
+ private async guardedTransports(): Promise<GitTransportRegistry> {
399
+ this.guarded ??= guardSubmoduleTransports(
400
+ this.transports ?? createDefaultTransports(),
401
+ await this.auth(),
402
+ );
403
+ return this.guarded;
404
+ }
405
+
406
+ /** The policy: inherited, else built from the setters and the superproject's remote. */
407
+ private async auth(): Promise<SubmoduleAuthFor> {
408
+ if (this.authPolicy) return this.authPolicy;
409
+ let origins = this.credentialOrigins;
410
+ if (origins.length === 0 && (this.credentials || this.headers)) {
411
+ const store = RemoteConfigStore.from(this.workingCopy);
412
+ const url = store.urlFor(await defaultRemoteOf(this.workingCopy));
413
+ const origin = url !== undefined ? strictUrlOrigin(url) : undefined;
414
+ origins = origin !== undefined ? [origin] : [];
415
+ }
416
+ this.authPolicy = createSubmoduleAuthPolicy({
417
+ ...(this.credentials ? { credentials: this.credentials } : {}),
418
+ ...(this.headers ? { headers: this.headers } : {}),
419
+ origins,
420
+ ...(this.credentialsFor ? { credentialsFor: this.credentialsFor } : {}),
421
+ ...(this.headersFor ? { headersFor: this.headersFor } : {}),
422
+ });
423
+ return this.authPolicy;
424
+ }
425
+
426
+ /** The timeout of clones and fetches, in milliseconds. */
427
+ setTimeout(timeout: number): this {
428
+ this.checkCallable();
429
+ this.timeout = timeout;
430
+ return this;
431
+ }
432
+
433
+ async call(): Promise<SubmoduleCommandResult> {
434
+ this.start();
435
+ if (this.requireInit) this.init = true;
436
+ const list = await this.moduleList(this.paths);
437
+ if (!list) return this.finish();
438
+ if (this.init) await this.runInit();
439
+ const records = await this.cloneAll(list);
440
+ if (!records) {
441
+ this.out.exitCode = 1;
442
+ return this.finish();
443
+ }
444
+ for (const record of records) {
445
+ const code = await this.updateRecord(record);
446
+ if (code === 0) continue;
447
+ this.out.exitCode = code;
448
+ if (code === 128) break;
449
+ }
450
+ if (this.out.exitCode === 128) this.dieWithLastLine();
451
+ return this.finish();
452
+ }
453
+
454
+ /** git returned 128 after its `fatal:` line: thrown as git's death, that line the message. */
455
+ private dieWithLastLine(): never {
456
+ const text = this.out.stderr.replace(/\n$/, "");
457
+ const at = text.lastIndexOf("\n");
458
+ this.out.stderr = at < 0 ? "" : `${text.slice(0, at)}\n`;
459
+ this.die(at < 0 ? text : text.slice(at + 1));
460
+ }
461
+
462
+ /** `module_update`'s `--init`: `submodule init` of the same paths. */
463
+ private async runInit(): Promise<void> {
464
+ const init = new SubmoduleInitCommand(this.workingCopy)
465
+ .setQuiet(this.quiet)
466
+ .setCompatibility(this.compatibility)
467
+ .setSuperPrefix(this.superPrefix);
468
+ for (const path of this.paths) init.addPath(path);
469
+ try {
470
+ this.append(await init.call());
471
+ } catch (error) {
472
+ if (!(error instanceof SubmoduleCommandError)) throw error;
473
+ this.append(error.result);
474
+ this.die(error.message);
475
+ }
476
+ this.forgetModel();
477
+ this.modelWarningsShown = true;
478
+ }
479
+
480
+ private warnMissing(displayPath: string): void {
481
+ if (this.paths.length === 0) return;
482
+ this.out.stderr += `Submodule path '${displayPath}' not initialized\nMaybe you want to use 'update --init'?\n`;
483
+ }
484
+
485
+ /**
486
+ * `update_submodules`' clone pass: each submodule looked at (`prepare_to_clone_next_submodule`),
487
+ * those without a `.git` cloned; a failed clone retried once after the others, undefined
488
+ * when it fails again (git's quickstop).
489
+ */
490
+ private async cloneAll(list: SubmoduleListEntry[]): Promise<UpdateRecord[] | undefined> {
491
+ const records: UpdateRecord[] = [];
492
+ const failed: { record: UpdateRecord; url: string }[] = [];
493
+ for (const entry of list) {
494
+ const prepared = await this.prepare(entry);
495
+ if (!prepared) continue;
496
+ records.push(prepared.record);
497
+ if (!prepared.record.justCloned) continue;
498
+ if (!(await this.clone(prepared.record, prepared.url))) {
499
+ this.out.stderr += `Failed to clone '${entry.path}'. Retry scheduled\n`;
500
+ failed.push(prepared);
501
+ }
502
+ }
503
+ for (const { record, url } of failed) {
504
+ if (!(await this.clone(record, url))) {
505
+ this.out.stderr += `Failed to clone '${record.path}' a second time, aborting\n`;
506
+ return undefined;
507
+ }
508
+ }
509
+ return records;
510
+ }
511
+
512
+ /** git's `prepare_to_clone_next_submodule`: the record and URL, undefined when skipped. */
513
+ private async prepare(
514
+ entry: SubmoduleListEntry,
515
+ ): Promise<{ record: UpdateRecord; url: string } | undefined> {
516
+ const dp = this.displayPath(entry.path);
517
+ if (entry.stage) {
518
+ this.out.stderr += `Skipping unmerged submodule ${dp}\n`;
519
+ return undefined;
520
+ }
521
+ const model = await this.model();
522
+ const sub = model.fromPath(entry.path);
523
+ if (!sub) {
524
+ this.warnMissing(dp);
525
+ return undefined;
526
+ }
527
+ const configured = model.configText(`submodule.${sub.name}.update`);
528
+ const type =
529
+ typeof configured === "string"
530
+ ? parseSubmoduleUpdateStrategy(configured)?.type
531
+ : sub.update?.type;
532
+ if (this.mode === undefined && type === "none") {
533
+ this.out.stderr += `Skipping submodule '${dp}'\n`;
534
+ return undefined;
535
+ }
536
+ if (!model.isActive(entry.path)) {
537
+ this.warnMissing(dp);
538
+ return undefined;
539
+ }
540
+ let url = model.configText(`submodule.${sub.name}.url`) ?? undefined;
541
+ if (url === undefined && sub.url !== undefined) {
542
+ if (/^\.\.?\//.test(sub.url)) {
543
+ const warnings: string[] = [];
544
+ url = await resolveRelativeUrl(this.workingCopy, sub.url, undefined, { warnings });
545
+ for (const w of warnings) this.out.stderr += `${w}\n`;
546
+ } else url = sub.url;
547
+ }
548
+ if (url === undefined) this.die(`fatal: cannot clone submodule '${sub.name}' without a URL`);
549
+ const path = sub.path ?? entry.path;
550
+ // file_exists("<path>/.git"): stat follows symbolic links
551
+ const justCloned = !(await this.existsThroughLinks(`${entry.path}/.git`));
552
+ return { record: { sub, path, id: entry.id, justCloned }, url };
553
+ }
554
+
555
+ /**
556
+ * Whether a worktree path exists as `stat` sees it: symbolic links on the way followed
557
+ * (relative ones, inside the storage; an absolute target counts as missing).
558
+ */
559
+ private async existsThroughLinks(path: string): Promise<boolean> {
560
+ const files = this.worktreeAccess?.getFiles?.() as PosixFilesApi | undefined;
561
+ if (!files?.lstat || !files.readlink) return (await this.kindOf(path)) !== undefined;
562
+ let parts = this.filesPath(path).split("/").filter(Boolean);
563
+ const resolved: string[] = [];
564
+ for (let hops = 0; parts.length > 0; ) {
565
+ const part = parts.shift() as string;
566
+ if (part === ".") continue;
567
+ if (part === "..") {
568
+ resolved.pop();
569
+ continue;
570
+ }
571
+ const at = [...resolved, part].join("/");
572
+ const st = await files.lstat(at).catch(() => undefined);
573
+ if (!st) return false;
574
+ if (st.kind !== "symlink") {
575
+ resolved.push(part);
576
+ continue;
577
+ }
578
+ if (++hops > 40) return false;
579
+ const bytes = await files.readlink(at).catch(() => undefined);
580
+ const target = bytes ? new TextDecoder().decode(bytes) : undefined;
581
+ if (target === undefined || target.startsWith("/")) return false;
582
+ parts = [...target.split("/").filter(Boolean), ...parts];
583
+ }
584
+ return true;
585
+ }
586
+
587
+ /** submodule--helper's `clone` child: false when it failed (its lines printed). */
588
+ private async clone(record: UpdateRecord, url: string): Promise<boolean> {
589
+ const { sub, path } = record;
590
+ try {
591
+ await this.validatePath(path);
592
+ const model = await this.model();
593
+ let gitDir: string | undefined;
594
+ try {
595
+ gitDir = await model.gitDirOf(sub.name);
596
+ } catch (error) {
597
+ if (error instanceof GitApiError) this.die(error.message);
598
+ throw error;
599
+ }
600
+ if (gitDir === undefined) this.die("fatal: no git directory to keep the submodule in");
601
+ const common = await gitFileOf(this.workingCopy, "modules");
602
+ const files = this.worktreeAccess?.getFiles?.();
603
+ const gitFiles = common?.files ?? files;
604
+ if (!gitFiles) this.die("fatal: no worktree to clone a submodule into");
605
+ const kept = (await gitFiles.stats(gitDir).catch(() => undefined)) !== undefined;
606
+ const depth =
607
+ this.recommendShallow !== false && sub.shallow === true ? 1 : this.depth || undefined;
608
+ await this.cloneSubmodule(path, url, gitDir, gitFiles, kept, {
609
+ ...(depth !== undefined ? { depth } : {}),
610
+ references: this.references,
611
+ requireInit: this.requireInit,
612
+ transports: await this.guardedTransports(),
613
+ ...(this.timeout !== undefined ? { timeout: this.timeout } : {}),
614
+ });
615
+ return true;
616
+ } catch (error) {
617
+ if (!(error instanceof SubmoduleCommandError)) throw error;
618
+ this.out.stderr += `${error.message}\n`;
619
+ return false;
620
+ }
621
+ }
622
+
623
+ /** The submodule's working copy, opened as git-submodule.sh runs its children. */
624
+ private async openInner(path: string): Promise<WorkingCopy | undefined> {
625
+ const environment = hostEnvironmentOf(this.workingCopy);
626
+ return this.worktreeAccess
627
+ ?.openGitlink?.(path, {
628
+ environment: notFromUser(environment ?? { readFile: async () => undefined }),
629
+ })
630
+ .catch(() => undefined);
631
+ }
632
+
633
+ /** submodule--helper.c's `ensure_core_worktree`. */
634
+ private async ensureCoreWorktree(path: string): Promise<void> {
635
+ const gitDir = await this.worktreeAccess?.gitlinkRepository?.(path).catch(() => undefined);
636
+ if (!gitDir) return;
637
+ const config = await openConfigFile(this.workingCopy, `${gitDir}/config`).catch(
638
+ () => undefined,
639
+ );
640
+ if (!config || config.getLocal("core.worktree").length === 0) return;
641
+ const relative = relativeFilesPath(gitDir, this.filesPath(path));
642
+ await setInConfigFile(this.workingCopy, `${gitDir}/config`, "core.worktree", relative);
643
+ }
644
+
645
+ /** `update_submodules`' second pass for one submodule: its exit code (0 when done). */
646
+ private async updateRecord(record: UpdateRecord): Promise<number> {
647
+ const { path, sub } = record;
648
+ await this.validatePath(path);
649
+ await this.ensureCoreWorktree(path);
650
+ const dp = this.displayPath(path);
651
+ const model = await this.model();
652
+
653
+ // determine_submodule_update_strategy
654
+ let strategy: SubmoduleUpdateStrategy;
655
+ if (this.mode) strategy = { type: this.mode };
656
+ else {
657
+ const configured = model.configText(`submodule.${sub.name}.update`);
658
+ if (typeof configured === "string") {
659
+ const parsed = parseSubmoduleUpdateStrategy(configured);
660
+ if (!parsed) {
661
+ return this.fatal(
662
+ `Invalid update mode '${configured}' configured for submodule path '${path}'`,
663
+ );
664
+ }
665
+ strategy = parsed;
666
+ } else strategy = sub.update ?? { type: "checkout" };
667
+ }
668
+ if (
669
+ record.justCloned &&
670
+ (strategy.type === "merge" || strategy.type === "rebase" || strategy.type === "none")
671
+ ) {
672
+ strategy = { type: "checkout" };
673
+ }
674
+
675
+ let subId: ObjectId | undefined;
676
+ if (!record.justCloned) {
677
+ subId = await this.worktreeAccess?.readGitlinkHead?.(path).catch(() => undefined);
678
+ if (subId === undefined) {
679
+ return this.fatal(`Unable to find current revision in submodule path '${dp}'`);
680
+ }
681
+ }
682
+ const inner = await this.openInner(path);
683
+ if (!inner) {
684
+ return this.fatal(`could not get a repository handle for submodule '${path}'`);
685
+ }
686
+ let id = record.id;
687
+
688
+ if (this.remote) {
689
+ const remoteName = await this.defaultRemoteOfSubmodule(sub, inner);
690
+ const branch = await this.remoteBranch(sub);
691
+ if (typeof branch === "number") return branch;
692
+ const remoteRef = `refs/remotes/${remoteName}/${branch}`;
693
+ if (!this.noFetch && !(await this.fetchIn(inner, false))) {
694
+ return this.fatal(`Unable to fetch in submodule path '${path}'`);
695
+ }
696
+ const value = await new SubmoduleRepository(inner).refValue(remoteRef);
697
+ if (value === undefined) {
698
+ return this.fatal(`Unable to find ${remoteRef} revision in submodule path '${path}'`);
699
+ }
700
+ id = value;
701
+ }
702
+
703
+ if (id !== subId || this.force) {
704
+ const code = await this.runUpdateProcedure(inner, sub, strategy, id, subId, dp);
705
+ if (code) return code;
706
+ }
707
+
708
+ if (this.recursive) return this.recurse(inner, dp);
709
+ return 0;
710
+ }
711
+
712
+ /** die_message: git's `fatal:` line printed, 128 returned. */
713
+ private fatal(message: string): number {
714
+ this.out.stderr += `fatal: ${message}\n`;
715
+ return 128;
716
+ }
717
+
718
+ /** submodule--helper.c's `remote_submodule_branch`: the branch, or an exit code. */
719
+ private async remoteBranch(sub: SubmoduleSettings): Promise<string | number> {
720
+ const model = await this.model();
721
+ const branch = model.branch(sub.name);
722
+ if (branch === undefined) return "HEAD";
723
+ if (branch !== ".") return branch;
724
+ const head = await this.refsStore.get("HEAD").catch(() => undefined);
725
+ const target = head && "target" in head ? (head.target as string | undefined) : undefined;
726
+ if (!head) return this.fatal("No such ref: HEAD");
727
+ if (!target) {
728
+ return this.fatal(
729
+ `Submodule (${sub.name}) branch configured to inherit branch from superproject, but the superproject is not on any branch`,
730
+ );
731
+ }
732
+ if (!target.startsWith("refs/heads/")) {
733
+ return this.fatal(`Expecting a full ref name, got ${target}`);
734
+ }
735
+ return target.slice("refs/heads/".length);
736
+ }
737
+
738
+ /** submodule--helper.c's `fetch_in_submodule`: `git fetch [--quiet] [--depth] [<remote> <id>]`. */
739
+ private async fetchIn(
740
+ inner: WorkingCopy,
741
+ quiet: boolean,
742
+ target?: { remote: string; id: ObjectId },
743
+ ): Promise<boolean> {
744
+ const fetch = new FetchCommand(inner);
745
+ fetch.setTransports(await this.guardedTransports());
746
+ if (this.timeout !== undefined) fetch.setTimeout(this.timeout);
747
+ if (this.depth) fetch.setDepth(this.depth);
748
+ // the remote named, so its URL is known: `git fetch` alone fetches the default remote
749
+ const remote = target?.remote ?? (await defaultRemoteOf(inner));
750
+ fetch.setRemote(remote);
751
+ if (target) fetch.setRefSpecs(target.id);
752
+ try {
753
+ const result = await fetch.call();
754
+ if (!quiet) {
755
+ for (const line of [...(result.display ?? []), ...result.messages]) {
756
+ this.out.stderr += `${line.replace(/\n$/, "")}\n`;
757
+ }
758
+ }
759
+ for (const line of result.errors ?? []) this.out.stderr += `${line.replace(/\n$/, "")}\n`;
760
+ return (result.errors ?? []).length === 0;
761
+ } catch (error) {
762
+ if (!(error instanceof Error)) throw error;
763
+ this.out.stderr += `${error.message.replace(/\n$/, "")}\n`;
764
+ return false;
765
+ }
766
+ }
767
+
768
+ /** submodule--helper.c's `run_update_procedure`. */
769
+ private async runUpdateProcedure(
770
+ inner: WorkingCopy,
771
+ sub: SubmoduleSettings,
772
+ strategy: SubmoduleUpdateStrategy,
773
+ id: ObjectId,
774
+ subId: ObjectId | undefined,
775
+ dp: string,
776
+ ): Promise<number> {
777
+ const subforce = subId === undefined || this.force;
778
+ if (!this.noFetch) {
779
+ const reachable = () => new SubmoduleRepository(inner).isTipReachable(id);
780
+ if (!(await reachable()) && !(await this.fetchIn(inner, this.quiet)) && !this.quiet) {
781
+ this.out.stderr += `Unable to fetch in submodule path '${dp}'; trying to directly fetch ${id}:\n`;
782
+ }
783
+ if (!(await reachable())) {
784
+ const remote = await this.defaultRemoteOfSubmodule(sub, inner);
785
+ if (!(await this.fetchIn(inner, this.quiet, { remote, id }))) {
786
+ return this.fatal(
787
+ `Fetched in submodule path '${dp}', but it did not contain ${id}. Direct fetching of that commit failed.`,
788
+ );
789
+ }
790
+ }
791
+ }
792
+ return this.runUpdateCommand(inner, strategy, id, subforce, dp);
793
+ }
794
+
795
+ /** submodule--helper.c's `run_update_command`. */
796
+ private async runUpdateCommand(
797
+ inner: WorkingCopy,
798
+ strategy: SubmoduleUpdateStrategy,
799
+ id: ObjectId,
800
+ subforce: boolean,
801
+ dp: string,
802
+ ): Promise<number> {
803
+ let done: string;
804
+ switch (strategy.type) {
805
+ case "checkout": {
806
+ try {
807
+ const result = await new CheckoutCommand(inner)
808
+ .setName(id)
809
+ .setQuiet(true)
810
+ .setForced(subforce)
811
+ .call();
812
+ for (const w of result.warnings ?? []) this.out.stderr += `${w}\n`;
813
+ if (result.status !== CheckoutStatus.OK) {
814
+ // a refused checkout (local changes, untracked files in the way): git checkout's
815
+ // lines, exit 1
816
+ if (result.message) this.out.stderr += `${result.message.replace(/\n$/, "")}\n`;
817
+ this.out.stderr += `fatal: Unable to checkout '${id}' in submodule path '${dp}'\n`;
818
+ return 1;
819
+ }
820
+ } catch (error) {
821
+ if (!(error instanceof GitApiError)) throw error;
822
+ this.out.stderr += `${error.message}\n`;
823
+ this.out.stderr += `fatal: Unable to checkout '${id}' in submodule path '${dp}'\n`;
824
+ return error.exitCode || 1;
825
+ }
826
+ done = `checked out '${id}'`;
827
+ break;
828
+ }
829
+ case "rebase": {
830
+ if (!(await this.rebase(inner, id))) {
831
+ return this.fatal(`Unable to rebase '${id}' in submodule path '${dp}'`);
832
+ }
833
+ done = `rebased into '${id}'`;
834
+ break;
835
+ }
836
+ case "merge": {
837
+ if (!(await this.merge(inner, id))) {
838
+ return this.fatal(`Unable to merge '${id}' in submodule path '${dp}'`);
839
+ }
840
+ done = `merged in '${id}'`;
841
+ break;
842
+ }
843
+ case "command": {
844
+ const command = strategy.command ?? "";
845
+ if (!(await this.runCommand(inner, command, id))) {
846
+ return this.fatal(`Execution of '${command} ${id}' failed in submodule path '${dp}'`);
847
+ }
848
+ done = `'${command} ${id}'`;
849
+ break;
850
+ }
851
+ default:
852
+ return 0;
853
+ }
854
+ if (!this.quiet) this.out.stdout += `Submodule path '${dp}': ${done}\n`;
855
+ return 0;
856
+ }
857
+
858
+ /** `git rebase [--quiet] <id>` in the submodule. */
859
+ private async rebase(inner: WorkingCopy, id: ObjectId): Promise<boolean> {
860
+ const repository = new SubmoduleRepository(inner);
861
+ const branch = await repository.currentBranch();
862
+ const before = await repository.refValue("HEAD");
863
+ const picks = before ? await repository.countPicks(id, before) : 0;
864
+ let result: Awaited<ReturnType<RebaseCommand["call"]>>;
865
+ try {
866
+ result = await new RebaseCommand(inner).setUpstream(id).call();
867
+ } catch (error) {
868
+ if (!(error instanceof GitApiError)) throw error;
869
+ this.out.stderr += `${error.message}\n`;
870
+ return false;
871
+ }
872
+ const ok = ["ok", "fast-forward", "up-to-date"].includes(result.status);
873
+ if (!this.quiet || !ok) {
874
+ for (const line of result.output ?? []) this.out.stdout += `${line}\n`;
875
+ }
876
+ if (result.message) this.out.stderr += `${result.message.replace(/\n$/, "")}\n`;
877
+ if (ok && result.status !== "up-to-date" && !this.quiet) {
878
+ // the sequencer's progress, then term_clear_line (2.43 clears a dumb terminal's line
879
+ // even when stderr is no terminal; 2.5x only on a terminal)
880
+ if (result.status === "ok") {
881
+ for (let i = 1; i <= picks; i++) this.out.stderr += `Rebasing (${i}/${picks})\r`;
882
+ }
883
+ if (this.compatibility === "2.43") this.out.stderr += `\r${" ".repeat(80)}\r`;
884
+ this.out.stderr += `Successfully rebased and updated ${branch ?? "detached HEAD"}.\n`;
885
+ }
886
+ return ok;
887
+ }
888
+
889
+ /** `git merge [--quiet] <id>` in the submodule: its stdout, the diffstat included. */
890
+ private async merge(inner: WorkingCopy, id: ObjectId): Promise<boolean> {
891
+ const before = await new SubmoduleRepository(inner).refValue("HEAD");
892
+ let result: Awaited<ReturnType<MergeCommand["call"]>>;
893
+ try {
894
+ result = await new MergeCommand(inner).include(id).call();
895
+ } catch (error) {
896
+ if (!(error instanceof GitApiError)) throw error;
897
+ this.out.stderr += `${error.message}\n`;
898
+ return false;
899
+ }
900
+ const ok = ["fast-forward", "already-up-to-date", "merged"].includes(result.status);
901
+ if (!this.quiet) {
902
+ for (const line of result.output ?? []) this.out.stdout += `${line}\n`;
903
+ if (result.status === "already-up-to-date" && (result.output ?? []).length === 0) {
904
+ this.out.stdout += "Already up to date.\n";
905
+ }
906
+ if ((result.status === "fast-forward" || result.status === "merged") && before) {
907
+ this.out.stdout += await this.diffstat(inner, before, result.newHead ?? id);
908
+ }
909
+ }
910
+ if (!ok && result.message) this.out.stderr += `${result.message.replace(/\n$/, "")}\n`;
911
+ return ok;
912
+ }
913
+
914
+ /** `git diff --stat --summary <from> <to>`, as git merge prints it after a merge. */
915
+ private async diffstat(inner: WorkingCopy, from: ObjectId, to: ObjectId): Promise<string> {
916
+ const diff = () => new DiffCommand(inner).setOldTree(from).setNewTree(to);
917
+ const stat = await diff()
918
+ .callText("stat")
919
+ .catch(() => "");
920
+ const summary = await diff()
921
+ .callText("summary")
922
+ .catch(() => "");
923
+ return `${stat}${summary}`;
924
+ }
925
+
926
+ /** `!command`: `sh -c '<command> "$@"' <command> <id>` in the submodule. */
927
+ private async runCommand(inner: WorkingCopy, command: string, id: ObjectId): Promise<boolean> {
928
+ const runner = hookRunnerOf(this.workingCopy);
929
+ if (!runner) {
930
+ this.out.stderr += `fatal: cannot run '${command}': no command runner on this host\n`;
931
+ return false;
932
+ }
933
+ const hostCwd = await worktreeHostPath(inner);
934
+ const outcome = await runner.run({
935
+ name: "submodule-update",
936
+ path: command,
937
+ command,
938
+ args: [id],
939
+ env: { GIT_DIR: ".git" },
940
+ unsetEnv: SUBMODULE_UNSET_ENV,
941
+ cwd: joinFilesPath(this.worktreeAccess?.getRoot() ?? "", inner.worktree?.getRoot?.() ?? ""),
942
+ ...(hostCwd !== undefined ? { hostCwd } : {}),
943
+ stdoutToStderr: false,
944
+ });
945
+ if (!outcome) return false;
946
+ const decoder = new TextDecoder();
947
+ this.out.stdout += decoder.decode(outcome.stdout);
948
+ this.out.stderr += decoder.decode(outcome.stderr);
949
+ return outcome.exitCode === 0;
950
+ }
951
+
952
+ /** `submodule--helper update --recursive --super-prefix=<dp>/ ...` in the submodule. */
953
+ private async recurse(inner: WorkingCopy, dp: string): Promise<number> {
954
+ const child = new SubmoduleUpdateCommand(inner)
955
+ .setQuiet(this.quiet)
956
+ .setCompatibility(this.compatibility)
957
+ .setSuperPrefix(`${dp}/`)
958
+ .setRecursive(true)
959
+ .setInit(this.init)
960
+ .setRequireInit(this.requireInit)
961
+ .setRemote(this.remote)
962
+ .setNoFetch(this.noFetch)
963
+ .setForce(this.force)
964
+ .setMode(this.mode)
965
+ .setDepth(this.depth);
966
+ if (this.recommendShallow !== undefined) child.setRecommendShallow(this.recommendShallow);
967
+ for (const reference of this.references) child.addReference(reference);
968
+ if (this.transports) child.setTransports(this.transports);
969
+ // the top superproject's policy: a nested superproject's remote is no trusted origin
970
+ child.setAuthPolicy(await this.auth());
971
+ if (this.timeout !== undefined) child.setTimeout(this.timeout);
972
+ let code: number;
973
+ try {
974
+ const result = await child.call();
975
+ this.append({ ...result, exitCode: 0 });
976
+ code = result.exitCode;
977
+ } catch (error) {
978
+ if (!(error instanceof SubmoduleCommandError)) throw error;
979
+ this.append({ ...error.result, exitCode: 0 });
980
+ this.out.stderr += `${error.message}\n`;
981
+ code = error.exitCode;
982
+ }
983
+ if (code) this.out.stderr += `fatal: Failed to recurse into submodule path '${dp}'\n`;
984
+ return code;
985
+ }
986
+ }
987
+
988
+ /**
989
+ * `git submodule status [-q] [--cached] [--recursive] [<path>...]`: one line per submodule
990
+ * of the index, `<state><commit> <path>[ (<name>)]`: `-` not initialized or not checked out,
991
+ * `+` its HEAD (with `--cached`, the index's commit) is not the commit the index records,
992
+ * `U` unmerged (a null id), else a space; the name is the first of `describe`, `describe
993
+ * --tags`, `describe --contains` and `describe --all --always` that answers in the
994
+ * submodule. `--recursive` lists each checked-out submodule's own submodules after it.
995
+ *
996
+ * @example
997
+ * ```typescript
998
+ * const { stdout } = await git.submoduleStatus().call();
999
+ * // " 1a2b3c... lib (v1.0-2-g1a2b3c4)\n"
1000
+ * ```
1001
+ */
1002
+ export class SubmoduleStatusCommand extends SubmoduleCommandBase {
1003
+ private readonly paths: string[] = [];
1004
+ private cached = false;
1005
+ private recursive = false;
1006
+
1007
+ /** A path (pathspec element) limiting the submodules. */
1008
+ addPath(path: string): this {
1009
+ this.checkCallable();
1010
+ this.paths.push(path);
1011
+ return this;
1012
+ }
1013
+
1014
+ /** `--cached`: the index's commit for a submodule whose HEAD moved. */
1015
+ setCached(cached: boolean): this {
1016
+ this.checkCallable();
1017
+ this.cached = cached;
1018
+ return this;
1019
+ }
1020
+
1021
+ /** `--recursive`: nested submodules too. */
1022
+ setRecursive(recursive: boolean): this {
1023
+ this.checkCallable();
1024
+ this.recursive = recursive;
1025
+ return this;
1026
+ }
1027
+
1028
+ async call(): Promise<SubmoduleCommandResult> {
1029
+ this.start();
1030
+ const list = await this.moduleList(this.paths);
1031
+ if (!list) return this.finish();
1032
+ for (const entry of list) await this.statusOne(entry);
1033
+ return this.finish();
1034
+ }
1035
+
1036
+ private async statusOne(entry: SubmoduleListEntry): Promise<void> {
1037
+ const { path } = entry;
1038
+ await this.validatePath(path);
1039
+ const model = await this.model();
1040
+ if (!model.fromPath(path)) {
1041
+ this.die(`fatal: no submodule mapping found in .gitmodules for path '${path}'`);
1042
+ }
1043
+ const dp = this.displayPath(path);
1044
+ if (entry.stage) {
1045
+ await this.print("U", NULL_ID_CHAR.repeat(entry.id.length), dp);
1046
+ return;
1047
+ }
1048
+ const worktree = this.worktreeAccess;
1049
+ const isRepository = await worktree?.isRepository?.(path).catch(() => false);
1050
+ if (!model.isActive(path) || !isRepository) {
1051
+ await this.print("-", entry.id, dp);
1052
+ return;
1053
+ }
1054
+ const inner = await this.openSubmodule(path);
1055
+ const head = await worktree?.readGitlinkHead?.(path).catch(() => undefined);
1056
+ // diff-files' ce_compare_gitlink: a HEAD that cannot be resolved is no change
1057
+ if (head === entry.id || head === undefined) {
1058
+ await this.print(" ", entry.id, dp, inner);
1059
+ } else if (!this.cached) {
1060
+ await this.print("+", head, dp, inner);
1061
+ } else {
1062
+ await this.print("+", entry.id, dp, inner);
1063
+ }
1064
+ if (this.recursive && inner) {
1065
+ const child = new SubmoduleStatusCommand(inner)
1066
+ .setQuiet(this.quiet)
1067
+ .setCompatibility(this.compatibility)
1068
+ .setCached(this.cached)
1069
+ .setRecursive(true)
1070
+ .setSuperPrefix(`${dp}/`);
1071
+ try {
1072
+ this.append(await child.call());
1073
+ } catch (error) {
1074
+ if (!(error instanceof SubmoduleCommandError)) throw error;
1075
+ this.append(error.result);
1076
+ this.out.stderr += `${error.message}\n`;
1077
+ this.die(`fatal: failed to recurse into submodule '${path}'`);
1078
+ }
1079
+ }
1080
+ }
1081
+
1082
+ /** submodule--helper.c's `print_status`. */
1083
+ private async print(state: string, id: ObjectId, dp: string, inner?: WorkingCopy): Promise<void> {
1084
+ if (this.quiet) return;
1085
+ let line = `${state}${id} ${dp}`;
1086
+ if ((state === " " || state === "+") && inner) {
1087
+ const name = await new SubmoduleRepository(inner).revName(id);
1088
+ if (name !== undefined) line += ` (${name})`;
1089
+ }
1090
+ this.out.stdout += `${line}\n`;
1091
+ }
1092
+ }