@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,1517 @@
1
+ /**
2
+ * `git submodule init`, `deinit`, `sync`, `set-url`, `set-branch` and `foreach`
3
+ * (builtin/submodule--helper.c), over the submodule model of `submodule-model.ts`.
4
+ *
5
+ * Each command gives what git prints (`stdout`, `stderr`) and its exit status; where git dies
6
+ * (`fatal:`, exit 128; a usage error, 129) the command throws {@link SubmoduleCommandError},
7
+ * whose `result` holds what was printed before.
8
+ */
9
+ import { FileMode, type ObjectId } from "@statewalker/vcs-core";
10
+ import { isGitDirectory } from "@statewalker/vcs-store-files";
11
+ import type { GitTransportRegistry } from "@statewalker/vcs-transport";
12
+ import { decodeGitPath } from "@statewalker/vcs-utils/encoding";
13
+ import { type FilesApi, type PosixFilesApi, readFile } from "@statewalker/vcs-utils/files";
14
+ import { computeObjectId } from "@statewalker/vcs-utils/pack";
15
+ import type { GitHostEnvironment, WorkingCopy } from "@statewalker/vcs-working-tree";
16
+
17
+ import { GitApiError, RmFailedError } from "../errors/index.js";
18
+ import { GitCommand } from "../git-command.js";
19
+ import { RemoteConfigStore } from "../remote-config/index.js";
20
+ import { CloneCommand } from "./clone-command.js";
21
+ import { commonGitFileOf, gitFileOf, hookRunnerOf } from "./git-hooks.js";
22
+ import { hostEnvironmentOf } from "./git-ident.js";
23
+ import { InitCommand } from "./init-command.js";
24
+ import {
25
+ DO_MATCH_DIRECTORY,
26
+ matchPathspecSeen,
27
+ parsePathspec,
28
+ pathspecErrors,
29
+ } from "./pathspec.js";
30
+ import { RmCommand } from "./rm-command.js";
31
+ import {
32
+ defaultRemoteOf,
33
+ isRelativeSubmoduleUrl,
34
+ joinFilesPath,
35
+ lstatKind,
36
+ parentIsDirectory,
37
+ physicalFilesPath,
38
+ relativeFilesPath,
39
+ remoteFromUrl,
40
+ resolveFilesLinks,
41
+ resolveRelativeUrl,
42
+ SubmoduleGitDirError,
43
+ SubmoduleModel,
44
+ type SubmoduleSettings,
45
+ safeCreateLeadingDirectories,
46
+ setInConfigFile,
47
+ submodulePathConfigOf,
48
+ submoduleUpdateTypeName,
49
+ upPathOf,
50
+ urlIsLocalNotSsh,
51
+ validateSubmoduleGitDir,
52
+ validateSubmodulePath,
53
+ worktreeHostPath,
54
+ } from "./submodule-model.js";
55
+
56
+ /** How {@link SubmoduleCommandBase.cloneSubmodule} clones (submodule--helper's `clone`). */
57
+ export interface SubmoduleCloneOptions {
58
+ /** `--depth=<n>` */
59
+ depth?: number;
60
+ /** `--reference <repository>`s */
61
+ references?: string[];
62
+ /** `--require-init`: a non-empty directory at the path is refused */
63
+ requireInit?: boolean;
64
+ /**
65
+ * The transports and timeout the clone reaches its remote with. No credentials or headers
66
+ * are taken: a submodule's URL comes from the repository's content, so they are attached
67
+ * by the transports themselves, per URL and origin (`guardSubmoduleTransports`).
68
+ */
69
+ transports?: GitTransportRegistry;
70
+ timeout?: number;
71
+ }
72
+
73
+ /** What a submodule command printed, and its exit status. */
74
+ export interface SubmoduleCommandResult {
75
+ stdout: string;
76
+ stderr: string;
77
+ /** 0, or 1 where git returns 1 without dying (a pathspec that matched nothing) */
78
+ exitCode: number;
79
+ }
80
+
81
+ /**
82
+ * A submodule command died as git dies: `message` is git's last lines (`fatal: ...`, or
83
+ * `error: ...` and the usage), `result` what it printed before them.
84
+ */
85
+ export class SubmoduleCommandError extends GitApiError {
86
+ constructor(
87
+ message: string,
88
+ readonly result: SubmoduleCommandResult,
89
+ exitCode = 128,
90
+ ) {
91
+ super(message, { exitCode });
92
+ this.name = "SubmoduleCommandError";
93
+ this.result = { ...result, exitCode };
94
+ }
95
+ }
96
+
97
+ /** One gitlink of the index (submodule--helper.c's `module_list` entry). */
98
+ export interface SubmoduleListEntry {
99
+ path: string;
100
+ /** The commit the index records */
101
+ id: ObjectId;
102
+ /** The entry's stage (0 unless the path is unmerged: git lists its first gitlink stage) */
103
+ stage: number;
104
+ }
105
+
106
+ /**
107
+ * The variables git clears for a submodule's child process (`local_repo_env`, config kept).
108
+ *
109
+ * @internal
110
+ */
111
+ export const SUBMODULE_UNSET_ENV = [
112
+ "GIT_ALTERNATE_OBJECT_DIRECTORIES",
113
+ "GIT_CONFIG",
114
+ "GIT_OBJECT_DIRECTORY",
115
+ "GIT_DIR",
116
+ "GIT_WORK_TREE",
117
+ "GIT_IMPLICIT_WORK_TREE",
118
+ "GIT_GRAFT_FILE",
119
+ "GIT_INDEX_FILE",
120
+ "GIT_NO_REPLACE_OBJECTS",
121
+ "GIT_REPLACE_REF_BASE",
122
+ "GIT_PREFIX",
123
+ "GIT_SHALLOW_FILE",
124
+ "GIT_COMMON_DIR",
125
+ ];
126
+
127
+ /** git's `sq_quote_buf`: `'...'`, a `'` or `!` inside written as `'\''` / `'\!'`. */
128
+ export function shellQuote(text: string): string {
129
+ return `'${text.replace(/['!]/g, (c) => `'\\${c}'`)}'`;
130
+ }
131
+
132
+ /** Where `<path>/.git` leads (setup.c's `resolve_gitdir_gently`). */
133
+ interface ResolvedGitdir {
134
+ /**
135
+ * The repository directory as a physical FilesApi path (links followed); null when a gitfile
136
+ * or a `.git` link leads beyond the FilesApi
137
+ */
138
+ gitDir: string | null;
139
+ kind: "directory" | "gitfile";
140
+ }
141
+
142
+ /** How deep absorbgitdirs recurses into nested submodules before it gives up. */
143
+ const MAX_ABSORB_DEPTH = 64;
144
+
145
+ /** setup.c's `READ_GITFILE_ERR_*` codes. */
146
+ type GitfileError =
147
+ | "missing"
148
+ | "stat-failed"
149
+ | "is-a-dir"
150
+ | "not-a-file"
151
+ | "too-large"
152
+ | "read-failed"
153
+ | "invalid-format"
154
+ | "no-path"
155
+ | "not-a-repo";
156
+
157
+ /**
158
+ * The `strerror` text of a `rename(2)` of the directory `source` onto `target` that failed
159
+ * (the FilesApi's `move` answers false without the errno): what is in the way, else what is
160
+ * missing, else a refusal.
161
+ */
162
+ async function renameFailure(
163
+ files: FilesApi,
164
+ source: string | null,
165
+ target: string,
166
+ ): Promise<string> {
167
+ if (source === null) return "Permission denied";
168
+ const there = await files.stats(target).catch(() => undefined);
169
+ if (there?.kind === "directory") {
170
+ for await (const _ of files.list(target)) return "Directory not empty";
171
+ } else if (there) return "Not a directory";
172
+ if (!(await files.stats(source).catch(() => undefined))) return "No such file or directory";
173
+ return "Permission denied";
174
+ }
175
+
176
+ /** Whether resolving the `..` components of a FilesApi path climbs above its root. */
177
+ function climbsAboveRoot(path: string): boolean {
178
+ let depth = 0;
179
+ for (const part of path.split("/")) {
180
+ if (!part || part === ".") continue;
181
+ depth += part === ".." ? -1 : 1;
182
+ if (depth < 0) return true;
183
+ }
184
+ return false;
185
+ }
186
+
187
+ /** `read_gitfile_error_die`'s message prefixes; codes without one are not fatal there. */
188
+ const GITFILE_ERRORS: Partial<Record<GitfileError, string>> = {
189
+ "too-large": "too large to be a .git file: ",
190
+ "read-failed": "error reading ",
191
+ "invalid-format": "invalid gitfile format: ",
192
+ "no-path": "no path in gitfile: ",
193
+ };
194
+
195
+ /**
196
+ * The parts every submodule command shares: output, the index's gitlinks, the model.
197
+ *
198
+ * @internal
199
+ */
200
+ export abstract class SubmoduleCommandBase extends GitCommand<SubmoduleCommandResult> {
201
+ protected quiet = false;
202
+ protected superPrefix = "";
203
+ protected compatibility: "2.43" | "2.56" = "2.56";
204
+ protected out: SubmoduleCommandResult = { stdout: "", stderr: "", exitCode: 0 };
205
+ private modelLoad?: Promise<SubmoduleModel>;
206
+ /** The `.gitmodules` warnings were printed already (by a command run before this one) */
207
+ protected modelWarningsShown = false;
208
+
209
+ /** `-q` / `--quiet`: leave out the progress lines. */
210
+ setQuiet(quiet: boolean): this {
211
+ this.checkCallable();
212
+ this.quiet = quiet;
213
+ return this;
214
+ }
215
+
216
+ /**
217
+ * The git version whose behaviour is reproduced where versions differ (default 2.56):
218
+ * `sync` looks up a submodule's remote by its URL first in 2.5x only.
219
+ */
220
+ setCompatibility(version: "2.43" | "2.56"): this {
221
+ this.checkCallable();
222
+ this.compatibility = version;
223
+ return this;
224
+ }
225
+
226
+ /** @internal git's `--super-prefix`: what nested submodules' display paths start with. */
227
+ setSuperPrefix(prefix: string): this {
228
+ this.superPrefix = prefix;
229
+ return this;
230
+ }
231
+
232
+ /** git's `validate_submodule_path`: dies (its `error:` line, exit 128) on a symlinked path. */
233
+ protected async validatePath(path: string): Promise<void> {
234
+ const refusal = await validateSubmodulePath(this.workingCopy, path);
235
+ if (refusal !== undefined) this.die(refusal);
236
+ }
237
+
238
+ protected displayPath(path: string): string {
239
+ return `${this.superPrefix}${path}`;
240
+ }
241
+
242
+ /** Dies as git does: what was printed so far, then `message`. */
243
+ protected die(message: string, exitCode = 128): never {
244
+ throw new SubmoduleCommandError(message, this.out, exitCode);
245
+ }
246
+
247
+ /** The submodule model, read (and its warnings printed) when first asked for. */
248
+ protected model(): Promise<SubmoduleModel> {
249
+ this.modelLoad ??= SubmoduleModel.load(this.workingCopy).then(
250
+ (model) => {
251
+ if (!this.modelWarningsShown) {
252
+ for (const w of model.gitmodules.warnings) this.out.stderr += `${w}\n`;
253
+ }
254
+ return model;
255
+ },
256
+ (error: unknown) => {
257
+ if (error instanceof GitApiError) this.die(error.message);
258
+ throw error;
259
+ },
260
+ );
261
+ return this.modelLoad;
262
+ }
263
+
264
+ /** Reads `.gitmodules` again on the next {@link model} (`repo_read_gitmodules`). */
265
+ protected forgetModel(): void {
266
+ this.modelLoad = undefined;
267
+ }
268
+
269
+ /**
270
+ * git's `module_list_compute`: the index's gitlinks matching the pathspec, each once, in
271
+ * index order; a pathspec element matching nothing (whatever it matched: files count)
272
+ * gives git's error and exit status 1, and an empty list.
273
+ */
274
+ protected async moduleList(paths: readonly string[]): Promise<SubmoduleListEntry[] | undefined> {
275
+ const items = parsePathspec([...paths]);
276
+ const seen = items.map(() => 0);
277
+ const list: SubmoduleListEntry[] = [];
278
+ let last: string | undefined;
279
+ for await (const entry of this.staging.entries()) {
280
+ if (!matchPathspecSeen(items, entry.path, DO_MATCH_DIRECTORY, seen)) continue;
281
+ if (entry.mode !== FileMode.GITLINK || entry.path === last) continue;
282
+ last = entry.path;
283
+ list.push({ path: entry.path, id: entry.objectId, stage: entry.stage ?? 0 });
284
+ }
285
+ const errors = paths.length > 0 ? pathspecErrors(paths, seen) : [];
286
+ if (errors.length > 0) {
287
+ this.out.stderr += errors.map((e) => `${e}\n`).join("");
288
+ this.out.exitCode = 1;
289
+ return undefined;
290
+ }
291
+ return list;
292
+ }
293
+
294
+ /** `git config <key> <value>` in the repository's own file (`repo_config_set_gently`). */
295
+ protected async setConfig(key: string, value: string): Promise<void> {
296
+ const store = RemoteConfigStore.from(this.workingCopy);
297
+ store.setValue(key, value);
298
+ await store.save();
299
+ }
300
+
301
+ /** The FilesApi path of a worktree path. */
302
+ protected filesPath(path: string): string {
303
+ return joinFilesPath(this.worktreeAccess?.getRoot() ?? "", path);
304
+ }
305
+
306
+ protected async kindOf(path: string): Promise<string | undefined> {
307
+ const files = this.worktreeAccess?.getFiles?.();
308
+ return (await files?.stats(this.filesPath(path)).catch(() => undefined))?.kind;
309
+ }
310
+
311
+ /** git's `stat(2)` kind of a worktree path: symbolic links on the way followed. */
312
+ protected async kindThroughLinks(path: string): Promise<string | undefined> {
313
+ const files = this.worktreeAccess?.getFiles?.();
314
+ if (!files) return undefined;
315
+ const physical = await physicalFilesPath(files, this.filesPath(path)).catch(() => undefined);
316
+ if (physical === undefined) return undefined;
317
+ return (await files.stats(physical).catch(() => undefined))?.kind;
318
+ }
319
+
320
+ /** git's `config_set_in_gitmodules_file_gently` (`value` undefined unsets). */
321
+ protected async setInGitmodules(key: string, value: string | undefined): Promise<boolean> {
322
+ return setInConfigFile(this.workingCopy, this.filesPath(".gitmodules"), key, value);
323
+ }
324
+
325
+ /** The working copy of the populated submodule at `path`, undefined when not populated. */
326
+ protected async openSubmodule(path: string): Promise<WorkingCopy | undefined> {
327
+ return this.worktreeAccess?.openGitlink?.(path).catch(() => undefined);
328
+ }
329
+
330
+ /**
331
+ * submodule--helper.c's `sync_submodule`: an active submodule's URL registered again from
332
+ * `.gitmodules` (resolved against the superproject's remote), and, when it is populated,
333
+ * written to the submodule's default remote (resolved from the submodule's place).
334
+ */
335
+ protected async syncSubmodule(path: string, recursive: boolean): Promise<void> {
336
+ const model = await this.model();
337
+ if (!model.isActive(path)) return;
338
+ await this.validatePath(path);
339
+ const sub = model.fromPath(path) as SubmoduleSettings;
340
+ let subOriginUrl = "";
341
+ let superConfigUrl = "";
342
+ if (sub.url !== undefined) {
343
+ if (isRelativeSubmoduleUrl(sub.url)) {
344
+ subOriginUrl = await resolveRelativeUrl(this.workingCopy, sub.url, upPathOf(path), {
345
+ quiet: true,
346
+ });
347
+ superConfigUrl = await resolveRelativeUrl(this.workingCopy, sub.url, undefined, {
348
+ quiet: true,
349
+ });
350
+ } else {
351
+ subOriginUrl = sub.url;
352
+ superConfigUrl = sub.url;
353
+ }
354
+ }
355
+ const dp = this.displayPath(path);
356
+ if (!this.quiet) this.out.stdout += `Synchronizing submodule url for '${dp}'\n`;
357
+ await this.setConfig(`submodule.${sub.name}.url`, superConfigUrl);
358
+ const inner = await this.openSubmodule(path);
359
+ if (!inner) return;
360
+ const remote = await this.defaultRemoteOfSubmodule(sub, inner);
361
+ const store = RemoteConfigStore.from(inner);
362
+ store.setValue(`remote.${remote}.url`, subOriginUrl);
363
+ await store.save();
364
+ if (recursive) {
365
+ const child = new SubmoduleSyncCommand(inner)
366
+ .setQuiet(this.quiet)
367
+ .setRecursive(true)
368
+ .setCompatibility(this.compatibility)
369
+ .setSuperPrefix(`${dp}/`);
370
+ try {
371
+ this.append(await child.call());
372
+ } catch (error) {
373
+ if (!(error instanceof SubmoduleCommandError)) throw error;
374
+ this.append(error.result);
375
+ this.out.stderr += `${error.message}\n`;
376
+ this.die(`fatal: failed to recurse into submodule '${path}'`);
377
+ }
378
+ }
379
+ }
380
+
381
+ /**
382
+ * submodule--helper.c's `get_default_remote_submodule`: in git 2.5x the submodule's
383
+ * remote whose URL is the one `.gitmodules` gives, else (and always in 2.43) its default
384
+ * remote.
385
+ */
386
+ protected async defaultRemoteOfSubmodule(
387
+ sub: SubmoduleSettings,
388
+ inner: WorkingCopy,
389
+ ): Promise<string> {
390
+ if (this.compatibility !== "2.43" && sub.url !== undefined) {
391
+ const url = isRelativeSubmoduleUrl(sub.url)
392
+ ? await resolveRelativeUrl(this.workingCopy, sub.url, undefined, { quiet: true })
393
+ : sub.url;
394
+ const found = remoteFromUrl(inner, url);
395
+ if (found !== undefined) return found;
396
+ }
397
+ return defaultRemoteOf(inner);
398
+ }
399
+
400
+ /**
401
+ * submodule--helper.c's `create_default_gitdir_config`: the first of git's candidates for
402
+ * the submodule's git directory that no other submodule's `gitdir` names (the plain name,
403
+ * then its RFC 3986 encodings, with a digit appended, then the hash of the name) written to
404
+ * `submodule.<name>.gitdir`, unless that is set.
405
+ */
406
+ protected async createDefaultGitdirConfig(name: string): Promise<void> {
407
+ const modules = await gitFileOf(this.workingCopy, "modules");
408
+ const root = this.worktreeAccess?.getRoot() ?? "";
409
+ if (!modules) return;
410
+ const base = relativeFilesPath(root, modules.path);
411
+ const encode = (upper: boolean) =>
412
+ [...new TextEncoder().encode(name)]
413
+ .map((b) => {
414
+ const c = String.fromCharCode(b);
415
+ const ok = upper ? /[a-z0-9\-._~]/.test(c) : /[A-Za-z0-9\-._~]/.test(c);
416
+ return ok ? c : `%${b.toString(16).padStart(2, "0")}`;
417
+ })
418
+ .join("");
419
+ const candidates = [`${base}/${name}`, `${base}/${encode(false)}`, `${base}/${encode(true)}`];
420
+ for (let d = 0; d <= 9; d++) {
421
+ candidates.push(`${base}/${encode(false)}${d}`, `${base}/${encode(true)}${d}`);
422
+ }
423
+ const hash = await computeObjectId("blob", new TextEncoder().encode(name), this.objectFormat);
424
+ candidates.push(`${base}/${hash}`);
425
+ const key = `submodule.${name}.gitdir`;
426
+ const model = await this.model();
427
+ for (const candidate of candidates) {
428
+ const path = joinFilesPath(root, candidate);
429
+ if (await validateSubmoduleGitDir(this.workingCopy, path, name, { encoded: true })) continue;
430
+ if (typeof model.configText(key) === "string") return;
431
+ await this.setConfig(key, candidate);
432
+ return;
433
+ }
434
+ this.die(
435
+ `fatal: failed to set a valid default config for '${key}'. Please ensure it is set, for example by running something like: 'git config ${key} .git/modules/${name}'`,
436
+ );
437
+ }
438
+
439
+ /**
440
+ * submodule--helper.c's `clone_submodule`: `git clone --no-checkout --separate-git-dir
441
+ * <gitdir> -- <url> <path>` with `GIT_PROTOCOL_FROM_USER=0` (or, with the git directory
442
+ * kept, its index dropped), then `connect_work_tree_and_git_dir`.
443
+ */
444
+ protected async cloneSubmodule(
445
+ path: string,
446
+ realrepo: string,
447
+ gitDir: string,
448
+ gitFiles: FilesApi,
449
+ kept: boolean,
450
+ options: SubmoduleCloneOptions = {},
451
+ ): Promise<void> {
452
+ const worktree = this.worktreeAccess;
453
+ const files = worktree?.getFiles?.();
454
+ if (!worktree || !files) return;
455
+ const top = (await worktreeHostPath(this.workingCopy)) ?? "";
456
+ const hostPath = `${top}/${path}`;
457
+ const parentOf = (p: string) => p.slice(0, Math.max(0, p.lastIndexOf("/")));
458
+ const leadingOk = async (): Promise<boolean> => {
459
+ const parts = path.split("/");
460
+ for (let i = 1; i < parts.length; i++) {
461
+ const kind = await this.kindOf(parts.slice(0, i).join("/"));
462
+ if (kind !== undefined && kind !== "directory") return false;
463
+ }
464
+ return true;
465
+ };
466
+
467
+ const nonEmpty = async (): Promise<boolean> => {
468
+ const kind = await this.kindOf(path);
469
+ if (kind === undefined) return false;
470
+ if (kind !== "directory") return true;
471
+ for await (const _ of files.list(this.filesPath(path))) return true;
472
+ return false;
473
+ };
474
+ if (options.requireInit && (await nonEmpty())) {
475
+ this.die(`fatal: directory not empty: '${hostPath}'`);
476
+ }
477
+ if (!kept) {
478
+ // safe_create_leading_directories of the git directory
479
+ const parent = parentOf(gitDir);
480
+ if (parent) await gitFiles.mkdir(parent);
481
+ if (await nonEmpty()) {
482
+ this.out.stderr += `fatal: destination path '${hostPath}' already exists and is not an empty directory.\n`;
483
+ this.die(`fatal: clone of '${realrepo}' into submodule path '${hostPath}' failed`);
484
+ }
485
+ if (!(await leadingOk())) {
486
+ this.out.stderr += `fatal: could not create leading directories of '${hostPath}': Not a directory\n`;
487
+ this.die(`fatal: clone of '${realrepo}' into submodule path '${hostPath}' failed`);
488
+ }
489
+ // cmd_clone's get_repo_path: a local path names a repository, or the clone dies first
490
+ if (urlIsLocalNotSsh(realrepo) && !/^file:/.test(realrepo)) {
491
+ const opened = await worktree
492
+ .openRepository?.(realrepo, { checkOwnership: false, alternates: false })
493
+ .catch(() => undefined);
494
+ const bundle =
495
+ opened === undefined &&
496
+ (await files.stats(joinFilesPath(worktree.getRoot(), realrepo)).catch(() => undefined))
497
+ ?.kind === "file";
498
+ if (worktree.openRepository && opened === undefined && !bundle) {
499
+ this.out.stderr += `fatal: repository '${realrepo}' does not exist\n`;
500
+ this.die(`fatal: clone of '${realrepo}' into submodule path '${hostPath}' failed`);
501
+ }
502
+ }
503
+ if (!this.quiet) this.out.stderr += `Cloning into '${hostPath}'...\n`;
504
+ const worktreeDir = this.filesPath(path);
505
+ const createdDir = (await this.kindOf(path)) === undefined;
506
+ const cleanup = async () => {
507
+ await gitFiles.remove(gitDir).catch(() => false);
508
+ // clone's remove_junk: the worktree it made, or what it wrote in an existing one
509
+ if (createdDir) await files.remove(worktreeDir).catch(() => false);
510
+ else await files.remove(`${worktreeDir}/.git`).catch(() => false);
511
+ };
512
+ try {
513
+ const environment = hostEnvironmentOf(this.workingCopy);
514
+ // git clone --separate-git-dir: a new repository there
515
+ const init = new InitCommand().setFilesApi(gitFiles).setGitDir(gitDir);
516
+ if (environment) init.setEnvironment(environment);
517
+ await init.call();
518
+ // create_default_files: a repository with a worktree logs its refs
519
+ await setInConfigFile(
520
+ this.workingCopy,
521
+ `${gitDir}/config`,
522
+ "core.logallrefupdates",
523
+ "true",
524
+ );
525
+ await worktree.connectGitlink?.(path, gitDir);
526
+ const inner = await worktree.openGitlink?.(path, {
527
+ // always: git-submodule.sh exports GIT_PROTOCOL_FROM_USER=0 whatever the host
528
+ // (without a host environment: one that reads no host files, as none does)
529
+ environment: notFromUser(environment ?? { readFile: async () => undefined }),
530
+ });
531
+ if (!inner) throw new GitApiError(`fatal: could not open the clone at '${hostPath}'`);
532
+ // the clone runs at the superproject's top: a relative path is read from there
533
+ const cloneUrl = isLocalRelativePath(realrepo) ? `${top}/${realrepo}` : realrepo;
534
+ const clone = new CloneCommand(inner)
535
+ .setURI(cloneUrl)
536
+ .setNoCheckout(true)
537
+ .setDirectory(hostPath);
538
+ if (options.depth !== undefined && options.depth > 0) clone.setDepth(options.depth);
539
+ for (const reference of options.references ?? []) clone.addReference(reference);
540
+ if (options.transports) clone.setTransports(options.transports);
541
+ if (options.timeout !== undefined) clone.setTimeout(options.timeout);
542
+ clone.shareHooksOf(this);
543
+ const result = await clone.call();
544
+ if (!this.quiet) {
545
+ for (const line of result.messages ?? []) this.out.stderr += line;
546
+ const local =
547
+ !/^[A-Za-z][A-Za-z0-9+.-]*:\/\//.test(realrepo) &&
548
+ !(result.messages ?? []).some((m) => m.includes("ignoring --local"));
549
+ if (local) this.out.stderr += "done.\n";
550
+ }
551
+ } catch (error) {
552
+ if (error instanceof SubmoduleCommandError || !(error instanceof Error)) throw error;
553
+ await cleanup();
554
+ this.out.stderr += `${error.message}\n`;
555
+ this.die(`fatal: clone of '${realrepo}' into submodule path '${hostPath}' failed`);
556
+ }
557
+ } else {
558
+ if (!(await leadingOk())) {
559
+ this.die(`fatal: could not create directory '${hostPath}'`);
560
+ }
561
+ const parent = parentOf(path);
562
+ if (parent) await files.mkdir(this.filesPath(parent));
563
+ await gitFiles.remove(`${gitDir}/index`).catch(() => false);
564
+ // connect_work_tree_and_git_dir: the gitfile's directory is the path itself
565
+ const kind = await this.kindOf(path);
566
+ if (kind !== undefined && kind !== "directory") {
567
+ this.die(`fatal: could not create directories for ${hostPath}/.git`);
568
+ }
569
+ }
570
+
571
+ await worktree.connectGitlink?.(path, gitDir);
572
+
573
+ // submodule.alternateLocation and alternateErrorStrategy carried into the submodule
574
+ const store = RemoteConfigStore.from(this.workingCopy);
575
+ for (const key of ["submodule.alternateLocation", "submodule.alternateErrorStrategy"]) {
576
+ const value = store.value(key);
577
+ if (value !== undefined) {
578
+ await setInConfigFile(this.workingCopy, `${gitDir}/config`, key, value);
579
+ }
580
+ }
581
+ }
582
+
583
+ /**
584
+ * submodule.c's `absorb_git_dir_into_superproject`: the submodule at `path` whose
585
+ * repository is a `.git` directory in its worktree gets it moved into the superproject's
586
+ * git directory (`.git/modules/<name>`, or `submodule.<name>.gitdir` under
587
+ * `extensions.submodulePathConfig`) and a gitfile in its place; one whose gitfile names no
588
+ * repository (its superproject's git directory moved under it) is connected again to
589
+ * where the repository now lives; nothing for one not populated. Then the same in its own
590
+ * submodules (`--super-prefix=<path>/`), as git's child `submodule--helper absorbgitdirs`.
591
+ */
592
+ protected async absorbGitDirIntoSuperproject(path: string): Promise<void> {
593
+ await this.validatePath(path);
594
+ const state = await this.resolveGitdirGently(path);
595
+ // where the submodule's repository is once absorbed (physically), for the child run
596
+ let innerGitDir: string | null | undefined;
597
+ if ("error" in state) {
598
+ // 2.43 took a failed stat for an unpopulated submodule too
599
+ if (state.error === "missing") return;
600
+ if (state.error === "stat-failed" && this.compatibility === "2.43") return;
601
+ if (state.error !== "not-a-repo") {
602
+ // read_gitfile_error_die: the fatal codes die, the others go on to connect
603
+ const fatal = GITFILE_ERRORS[state.error];
604
+ if (fatal) this.die(`fatal: ${fatal}${path}`);
605
+ }
606
+ // populated, but its gitfile names no repository: the superproject was absorbed itself
607
+ const sub = (await this.model()).fromPath(path);
608
+ if (!sub) this.die(`fatal: could not lookup name for submodule '${path}'`);
609
+ const gitDir = await this.submoduleGitDir(sub.name, path);
610
+ if (gitDir === undefined) return;
611
+ await this.connectWorkTreeAndGitDir(path, gitDir);
612
+ innerGitDir = (await physicalFilesPath(this.filesOrFail(), gitDir)) ?? gitDir;
613
+ } else if (state.gitDir === null && state.kind === "gitfile") {
614
+ // its repository lies beyond this FilesApi: nothing to move, nothing reachable to recurse
615
+ return;
616
+ } else {
617
+ // already absorbed into the superproject's git directory? (a string prefix, as git's)
618
+ const common = await commonGitFileOf(this.workingCopy, "");
619
+ const realSub = await this.realHostPath(state.gitDir ?? this.filesPath(`${path}/.git`));
620
+ const realCommon = common ? await this.realHostPath(common.path) : undefined;
621
+ innerGitDir = state.gitDir;
622
+ if (realCommon === undefined || !realSub.startsWith(realCommon)) {
623
+ innerGitDir = await this.relocateSingleGitDir(path, state);
624
+ }
625
+ }
626
+ await this.absorbNested(path, innerGitDir ?? undefined);
627
+ }
628
+
629
+ private filesOrFail(): FilesApi {
630
+ const files = this.worktreeAccess?.getFiles?.();
631
+ if (!files) throw new GitApiError("fatal: no worktree");
632
+ return files;
633
+ }
634
+
635
+ /**
636
+ * submodule.c's `relocate_single_git_dir_into_superproject`: the `.git` directory moved
637
+ * (git's `rename`, its result checked before anything else changes) to the submodule's
638
+ * place in the superproject's git directory, then the gitfile written and `core.worktree`
639
+ * set (`connect_work_tree_and_git_dir`). A gitfile needs no migration.
640
+ */
641
+ private async relocateSingleGitDir(
642
+ path: string,
643
+ state: ResolvedGitdir,
644
+ ): Promise<string | null | undefined> {
645
+ const files = this.worktreeAccess?.getFiles?.();
646
+ if (!files) return;
647
+ await this.validatePath(path);
648
+ if (await this.usesWorktrees(files, state.gitDir)) {
649
+ this.die(
650
+ `fatal: relocate_gitdir for submodule '${path}' with more than one worktree not supported`,
651
+ );
652
+ }
653
+ if (state.kind === "gitfile") return state.gitDir;
654
+ // the `.git` directory, a link to one followed (git's real_pathdup): state.gitDir is the
655
+ // physical place, null when a link leads beyond this FilesApi
656
+ const source = state.gitDir;
657
+ const from = await this.realHostPath(this.filesPath(`${path}/.git`));
658
+ const sub = (await this.model()).fromPath(path);
659
+ if (!sub) this.die(`fatal: could not lookup name for submodule '${path}'`);
660
+ const target = await this.submoduleGitDir(sub.name, path, from);
661
+ if (target === undefined) return;
662
+ // safe_create_leading_directories, links followed as git's stat follows them: a dangling
663
+ // link on the way (or one beyond the FilesApi) refuses before anything is created
664
+ const physical = (await safeCreateLeadingDirectories(files, target))
665
+ ? await physicalFilesPath(files, target)
666
+ : undefined;
667
+ if (physical === undefined) {
668
+ this.die(`fatal: could not create directory '${(await this.model()).shownPath(target)}'`);
669
+ }
670
+ const to = await this.realHostPath(target);
671
+ this.out.stderr += `Migrating git directory of '${this.superPrefix}${path}' from\n'${from}' to\n'${to}'\n`;
672
+ // relocate_gitdir: nothing else is changed unless the rename succeeded (the source's data
673
+ // is never removed: a failed move leaves it where it was). rename(2) creates no
674
+ // directory: the place's parent must be there (the FilesApi's move would create it)
675
+ const moved =
676
+ source !== null &&
677
+ (await parentIsDirectory(files, physical)) &&
678
+ (await files.move(source, physical).catch(() => false));
679
+ if (!moved) {
680
+ const reason = await renameFailure(files, source, physical);
681
+ this.die(`fatal: could not migrate git directory from '${from}' to '${to}': ${reason}`);
682
+ }
683
+ await this.connectWorkTreeAndGitDir(path, physical);
684
+ return physical;
685
+ }
686
+
687
+ /** `submodule_name_to_gitdir`, its deaths (and 2.43's refusal to move) as git's. */
688
+ private async submoduleGitDir(
689
+ name: string,
690
+ path: string,
691
+ movedFrom?: string,
692
+ ): Promise<string | undefined> {
693
+ try {
694
+ return await (await this.model()).gitDirOf(name);
695
+ } catch (error) {
696
+ if (error instanceof SubmoduleGitDirError && this.compatibility === "2.43") {
697
+ // 2.43's relocate_single_git_dir_into_superproject checked the place itself
698
+ this.out.stderr += error.refusal.map((l) => `${l}\n`).join("");
699
+ const from = movedFrom ?? (await this.realHostPath(this.filesPath(`${path}/.git`)));
700
+ this.die(`fatal: refusing to move '${from}' into an existing git dir`);
701
+ }
702
+ if (error instanceof GitApiError) this.die(error.message);
703
+ throw error;
704
+ }
705
+ }
706
+
707
+ /**
708
+ * dir.c's `connect_work_tree_and_git_dir` (no nested ones): the gitfile at `<path>/.git`
709
+ * naming `gitDir` relative to the worktree, then `core.worktree` in `<gitDir>/config`
710
+ * naming the worktree relative to it (the directory created when missing, as git's
711
+ * `safe_create_leading_directories` of the config file).
712
+ */
713
+ protected async connectWorkTreeAndGitDir(path: string, gitDir: string): Promise<void> {
714
+ const files = this.worktreeAccess?.getFiles?.();
715
+ if (!files) return;
716
+ const gitfile = `${path}/.git`;
717
+ // the leading directories of the gitfile and of `<gitDir>/config`, as git creates them
718
+ // (never through a dangling link)
719
+ if (!(await safeCreateLeadingDirectories(files, this.filesPath(gitfile)))) {
720
+ this.die(`fatal: could not create directories for ${gitfile}`);
721
+ }
722
+ if (!(await safeCreateLeadingDirectories(files, `${gitDir}/config`))) {
723
+ this.die(
724
+ `fatal: could not create directories for ${(await this.model()).shownPath(gitDir)}/config`,
725
+ );
726
+ }
727
+ // both sides as their real paths name them (git's real_pathdup): links followed
728
+ const realGitDir = await physicalFilesPath(files, gitDir);
729
+ const workTree = (await physicalFilesPath(files, this.filesPath(path))) ?? this.filesPath(path);
730
+ // write_file opens `<path>/.git` following a link there (to where the link points), which
731
+ // creates no directory: the place's parent must be there
732
+ const at = await resolveFilesLinks(files, this.filesPath(gitfile));
733
+ if (at === "loop") {
734
+ this.die(`fatal: could not open '${gitfile}' for writing: Too many levels of symbolic links`);
735
+ }
736
+ if (realGitDir === undefined || at === "outside") {
737
+ this.die(`fatal: could not open '${gitfile}' for writing: Permission denied`);
738
+ }
739
+ if (!(await parentIsDirectory(files, at))) {
740
+ this.die(`fatal: could not open '${gitfile}' for writing: No such file or directory`);
741
+ }
742
+ const relative = relativeFilesPath(workTree, realGitDir);
743
+ // never written over a directory (git's open fails there: EISDIR)
744
+ if ((await files.stats(at).catch(() => undefined))?.kind === "directory") {
745
+ this.die(`fatal: could not open '${gitfile}' for writing: Is a directory`);
746
+ }
747
+ const written = await files.write(at, [new TextEncoder().encode(`gitdir: ${relative}\n`)]).then(
748
+ () => true,
749
+ () => false,
750
+ );
751
+ if (!written) this.die(`fatal: could not open '${gitfile}' for writing: Permission denied`);
752
+ const worktreeValue = relativeFilesPath(realGitDir, workTree);
753
+ const set = await setInConfigFile(
754
+ this.workingCopy,
755
+ `${realGitDir}/config`,
756
+ "core.worktree",
757
+ worktreeValue,
758
+ ).catch(() => false);
759
+ if (!set) this.die(`fatal: could not set 'core.worktree' to '${worktreeValue}'`);
760
+ }
761
+
762
+ /** git's child `submodule--helper absorbgitdirs --super-prefix=<prefix><path>/` there. */
763
+ private async absorbNested(path: string, gitDir: string | undefined): Promise<void> {
764
+ await this.validatePath(path);
765
+ // the child git runs in the submodule finds its repository through `.git`, links and a
766
+ // gitfile naming a place through a link followed: where the worktree cannot read through
767
+ // them, the repository is opened from the physical place found here
768
+ const inner =
769
+ (await this.openSubmodule(path)) ??
770
+ (gitDir === undefined
771
+ ? undefined
772
+ : await this.worktreeAccess?.openGitlink?.(path, { gitDir }).catch(() => undefined));
773
+ // a chain of links cannot make this recurse forever
774
+ const depth = this.superPrefix.split("/").length;
775
+ if (!inner || depth > MAX_ABSORB_DEPTH) {
776
+ this.die(`fatal: could not recurse into submodule '${path}'`);
777
+ }
778
+ const child = new SubmoduleAbsorbGitDirsCommand(inner)
779
+ .setCompatibility(this.compatibility)
780
+ .setSuperPrefix(`${this.superPrefix}${path}/`);
781
+ try {
782
+ this.append(await child.call());
783
+ } catch (error) {
784
+ if (!(error instanceof SubmoduleCommandError)) throw error;
785
+ this.append(error.result);
786
+ this.out.stderr += `${error.message}\n`;
787
+ this.die(`fatal: could not recurse into submodule '${path}'`);
788
+ }
789
+ }
790
+
791
+ /**
792
+ * setup.c's `resolve_gitdir_gently` of `<path>/.git`: a `.git` directory that is a
793
+ * repository, else what `read_gitfile_gently` makes of it (the repository a gitfile names,
794
+ * `gitDir` null when it lies beyond this FilesApi, or git's error code).
795
+ */
796
+ private async resolveGitdirGently(
797
+ path: string,
798
+ ): Promise<ResolvedGitdir | { error: GitfileError }> {
799
+ const files = this.worktreeAccess?.getFiles?.();
800
+ if (!files) return { error: "missing" };
801
+ const dotGit = this.filesPath(`${path}/.git`);
802
+ // stat(2), not lstat: a `.git` link is followed to what it names (physically, since the
803
+ // FilesApi never acts through a link)
804
+ let at: string = dotGit;
805
+ if ((await lstatKind(files, dotGit)) === "symlink") {
806
+ const resolved = await resolveFilesLinks(files, dotGit);
807
+ // a loop: stat(2) fails with ELOOP (READ_GITFILE_ERR_STAT_FAILED)
808
+ if (resolved === "loop") return { error: "stat-failed" };
809
+ if (resolved === "outside") {
810
+ // beyond this FilesApi: git would read (and move) it; refused at the move
811
+ return { gitDir: null, kind: "directory" };
812
+ }
813
+ at = resolved;
814
+ }
815
+ const st = await files.stats(at).catch(() => undefined);
816
+ if (!st) return { error: "missing" };
817
+ if (st.kind === "directory") {
818
+ return (await isGitDirectory(files, at))
819
+ ? { gitDir: at, kind: "directory" }
820
+ : { error: "is-a-dir" };
821
+ }
822
+ if (st.kind !== "file") return { error: "not-a-file" };
823
+ if ((st.size ?? 0) > 1 << 20) return { error: "too-large" };
824
+ let text: string;
825
+ try {
826
+ text = decodeGitPath(await readFile(files, at));
827
+ } catch {
828
+ return { error: "read-failed" };
829
+ }
830
+ if (!text.startsWith("gitdir: ")) return { error: "invalid-format" };
831
+ text = text.replace(/[\r\n]+$/, "");
832
+ if (text.length < 9) return { error: "no-path" };
833
+ const target = text.slice(8);
834
+ let resolved: string | undefined;
835
+ if (target.startsWith("/")) {
836
+ const root = (files as { rootDirectory?: string }).rootDirectory?.replace(/\/+$/, "");
837
+ if (root === undefined) resolved = joinFilesPath("", target);
838
+ else if (target === root || target.startsWith(`${root}/`)) {
839
+ resolved = joinFilesPath("", target.slice(root.length));
840
+ }
841
+ } else if (!climbsAboveRoot(`${this.filesPath(path)}/${target}`)) {
842
+ resolved = joinFilesPath(this.filesPath(path), target);
843
+ }
844
+ if (resolved !== undefined) resolved = await physicalFilesPath(files, resolved);
845
+ // a place beyond this FilesApi: a repository git would find, which it would not move
846
+ if (resolved === undefined) return { gitDir: null, kind: "gitfile" };
847
+ if (!(await isGitDirectory(files, resolved))) return { error: "not-a-repo" };
848
+ return { gitDir: resolved, kind: "gitfile" };
849
+ }
850
+
851
+ /**
852
+ * worktree.c's `submodule_uses_worktrees`: whether the submodule's common git directory
853
+ * (its `commondir`) has anything in `worktrees/`.
854
+ */
855
+ private async usesWorktrees(files: FilesApi, gitDir: string | null): Promise<boolean> {
856
+ if (gitDir === null) return false;
857
+ let common = gitDir;
858
+ const commondir = `${gitDir}/commondir`;
859
+ if ((await files.stats(commondir).catch(() => undefined))?.kind === "file") {
860
+ const value = decodeGitPath(await readFile(files, commondir)).replace(/[\r\n]+$/, "");
861
+ if (value && !value.startsWith("/")) common = joinFilesPath(gitDir, value);
862
+ }
863
+ try {
864
+ for await (const _ of files.list(`${common}/worktrees`)) return true;
865
+ } catch {
866
+ return false;
867
+ }
868
+ return false;
869
+ }
870
+
871
+ /** git's `real_pathdup` of a FilesApi path: its host path, links resolved where possible. */
872
+ private async realHostPath(path: string): Promise<string> {
873
+ const files = this.worktreeAccess?.getFiles?.();
874
+ const root = (files as { rootDirectory?: string } | undefined)?.rootDirectory;
875
+ const clean = joinFilesPath("", path);
876
+ const host = root ? `${root.replace(/\/+$/, "")}/${clean}` : clean;
877
+ const environment = hostEnvironmentOf(this.workingCopy);
878
+ const real = await environment?.realPath?.(host).catch(() => undefined);
879
+ if (real !== undefined) return real;
880
+ // a dangling link resolved to where it points; a missing last component: its parent
881
+ // resolved (`real_pathdup(path, 1)`)
882
+ const physical = files ? await physicalFilesPath(files, clean) : undefined;
883
+ if (physical !== undefined && physical !== clean) return this.realHostPath(physical);
884
+ const slash = host.lastIndexOf("/");
885
+ if (slash > 0) {
886
+ const parent = await environment?.realPath?.(host.slice(0, slash)).catch(() => undefined);
887
+ if (parent !== undefined) return `${parent}${host.slice(slash)}`;
888
+ }
889
+ return host;
890
+ }
891
+
892
+ protected append(result: SubmoduleCommandResult): void {
893
+ this.out.stdout += result.stdout;
894
+ this.out.stderr += result.stderr;
895
+ if (result.exitCode) this.out.exitCode = result.exitCode;
896
+ }
897
+
898
+ protected start(): void {
899
+ this.checkCallable();
900
+ this.setCallable(false);
901
+ }
902
+
903
+ protected finish(): SubmoduleCommandResult {
904
+ return { ...this.out };
905
+ }
906
+ }
907
+
908
+ /**
909
+ * `git submodule init [-q] [<path>...]`: each submodule of the index (matching the paths)
910
+ * registered in `.git/config` from `.gitmodules`: `submodule.<name>.active` unless already
911
+ * active, its URL (a relative one resolved against the superproject's default remote, else
912
+ * its own directory with git's warning) unless one is registered, its update strategy unless
913
+ * one is set, and under `extensions.submodulePathConfig` its `submodule.<name>.gitdir`. With
914
+ * no paths and `submodule.active` set, only the active submodules.
915
+ *
916
+ * @example
917
+ * ```typescript
918
+ * const { stderr } = await git.submoduleInit().call();
919
+ * // "Submodule 'lib' (https://example.com/lib) registered for path 'lib'\n"
920
+ * ```
921
+ */
922
+ export class SubmoduleInitCommand extends SubmoduleCommandBase {
923
+ private readonly paths: string[] = [];
924
+
925
+ /** A path (pathspec element) limiting the submodules. */
926
+ addPath(path: string): this {
927
+ this.checkCallable();
928
+ this.paths.push(path);
929
+ return this;
930
+ }
931
+
932
+ async call(): Promise<SubmoduleCommandResult> {
933
+ this.start();
934
+ let list = await this.moduleList(this.paths);
935
+ if (!list) return this.finish();
936
+ if (
937
+ this.paths.length === 0 &&
938
+ RemoteConfigStore.from(this.workingCopy).valuesWithOrigin("submodule.active").length > 0
939
+ ) {
940
+ const model = await this.model();
941
+ list = list.filter((e) => model.isActive(e.path));
942
+ }
943
+ for (const entry of list) await this.initSubmodule(entry.path);
944
+ return this.finish();
945
+ }
946
+
947
+ private async initSubmodule(path: string): Promise<void> {
948
+ const model = await this.model();
949
+ const dp = this.displayPath(path);
950
+ const sub = model.fromPath(path);
951
+ if (!sub) this.die(`fatal: No url found for submodule path '${dp}' in .gitmodules`);
952
+ if (!model.isActive(path)) await this.setConfig(`submodule.${sub.name}.active`, "true");
953
+ const urlKey = `submodule.${sub.name}.url`;
954
+ if (typeof model.configText(urlKey) !== "string") {
955
+ if (sub.url === undefined) {
956
+ this.die(`fatal: No url found for submodule path '${dp}' in .gitmodules`);
957
+ }
958
+ let url = sub.url;
959
+ if (isRelativeSubmoduleUrl(url)) {
960
+ const warnings: string[] = [];
961
+ try {
962
+ url = await resolveRelativeUrl(this.workingCopy, url, undefined, { warnings });
963
+ } finally {
964
+ for (const w of warnings) this.out.stderr += `${w}\n`;
965
+ }
966
+ }
967
+ await this.setConfig(urlKey, url);
968
+ if (!this.quiet) {
969
+ this.out.stderr += `Submodule '${sub.name}' (${url}) registered for path '${dp}'\n`;
970
+ }
971
+ }
972
+ const updateKey = `submodule.${sub.name}.update`;
973
+ if (typeof model.configText(updateKey) !== "string" && sub.update) {
974
+ let value: string;
975
+ if (sub.update.type === "command") {
976
+ this.out.stderr += `warning: command update mode suggested for submodule '${sub.name}'\n`;
977
+ value = "none";
978
+ } else value = submoduleUpdateTypeName(sub.update);
979
+ await this.setConfig(updateKey, value);
980
+ }
981
+ if (await submodulePathConfigOf(this.workingCopy))
982
+ await this.createDefaultGitdirConfig(sub.name);
983
+ }
984
+ }
985
+
986
+ const DEINIT_USAGE = [
987
+ "usage: git submodule deinit [--quiet] [-f | --force] [--all | [--] [<path>...]]",
988
+ "",
989
+ " -q, --[no-]quiet suppress submodule status output",
990
+ " -f, --[no-]force remove submodule working trees even if they contain local changes",
991
+ " --[no-]all unregister all submodules",
992
+ "",
993
+ ].join("\n");
994
+
995
+ /**
996
+ * `git submodule deinit [-q] [-f] (--all | <path>...)`: each submodule's worktree emptied
997
+ * (a `.git` directory first absorbed into `.git/modules/<name>`, local changes refused
998
+ * without `-f` as `git rm -n` refuses them), its repository's `core.worktree` unset, an empty
999
+ * directory left, and its `submodule.<name>` section removed from `.git/config`.
1000
+ *
1001
+ * @example
1002
+ * ```typescript
1003
+ * const { stdout } = await git.submoduleDeinit().addPath("lib").call();
1004
+ * // "Cleared directory 'lib'\nSubmodule 'lib' (../lib) unregistered for path 'lib'\n"
1005
+ * ```
1006
+ */
1007
+ export class SubmoduleDeinitCommand extends SubmoduleCommandBase {
1008
+ private readonly paths: string[] = [];
1009
+ private force = false;
1010
+ private all = false;
1011
+
1012
+ /** A path (pathspec element) naming the submodules to deinitialize. */
1013
+ addPath(path: string): this {
1014
+ this.checkCallable();
1015
+ this.paths.push(path);
1016
+ return this;
1017
+ }
1018
+
1019
+ /** `-f`: remove the worktrees even with local changes. */
1020
+ setForce(force: boolean): this {
1021
+ this.checkCallable();
1022
+ this.force = force;
1023
+ return this;
1024
+ }
1025
+
1026
+ /** `--all`: every submodule (no path may be given). */
1027
+ setAll(all: boolean): this {
1028
+ this.checkCallable();
1029
+ this.all = all;
1030
+ return this;
1031
+ }
1032
+
1033
+ async call(): Promise<SubmoduleCommandResult> {
1034
+ this.start();
1035
+ if (this.all && this.paths.length > 0) {
1036
+ this.die(`error: pathspec and --all are incompatible\n${DEINIT_USAGE}`, 129);
1037
+ }
1038
+ if (!this.all && this.paths.length === 0) {
1039
+ this.die("fatal: Use '--all' if you really want to deinitialize all submodules");
1040
+ }
1041
+ const list = await this.moduleList(this.paths);
1042
+ if (!list) return this.finish();
1043
+ for (const entry of list) await this.deinitSubmodule(entry.path);
1044
+ return this.finish();
1045
+ }
1046
+
1047
+ private async deinitSubmodule(path: string): Promise<void> {
1048
+ await this.validatePath(path);
1049
+ const model = await this.model();
1050
+ const sub = model.fromPath(path);
1051
+ if (!sub) return;
1052
+ const dp = this.displayPath(path);
1053
+ const files = this.worktreeAccess?.getFiles?.();
1054
+ if (!files) return;
1055
+ if ((await this.kindOf(path)) === "directory") {
1056
+ // stat(2) of `.git`: a link followed; one this FilesApi cannot follow is taken for the
1057
+ // directory git would find (the absorb then refuses rather than leave it behind)
1058
+ const dotGitKind = await this.kindThroughLinks(`${path}/.git`);
1059
+ const unfollowed =
1060
+ dotGitKind === undefined &&
1061
+ (await resolveFilesLinks(files, this.filesPath(`${path}/.git`))) === "outside";
1062
+ if (dotGitKind === "directory" || unfollowed) {
1063
+ if (!this.quiet) {
1064
+ this.out.stderr += `warning: Submodule work tree '${dp}' contains a .git directory. This will be replaced with a .git file by using absorbgitdirs.\n`;
1065
+ }
1066
+ await this.absorbGitDirIntoSuperproject(path);
1067
+ }
1068
+ if (!this.force) {
1069
+ try {
1070
+ await new RmCommand(this.workingCopy).setDryRun(true).addFilepattern(path).call();
1071
+ } catch (error) {
1072
+ if (!(error instanceof RmFailedError)) throw error;
1073
+ this.out.stderr += `${error.message}\n`;
1074
+ this.die(
1075
+ `fatal: Submodule work tree '${dp}' contains local modifications; use '-f' to discard them`,
1076
+ );
1077
+ }
1078
+ }
1079
+ const removed = await files.remove(this.filesPath(path)).catch(() => false);
1080
+ if (!this.quiet) {
1081
+ this.out.stdout += removed
1082
+ ? `Cleared directory '${dp}'\n`
1083
+ : `Could not remove submodule work tree '${dp}'\n`;
1084
+ }
1085
+ await this.unsetCoreWorktree(sub);
1086
+ }
1087
+ // mkdir(path, 0777): its parent must be there, and nothing at the path
1088
+ const parent = path.includes("/") ? path.slice(0, path.lastIndexOf("/")) : "";
1089
+ const parentKind = parent === "" ? "directory" : await this.kindOf(parent);
1090
+ if (parentKind === "directory" && (await this.kindOf(path)) === undefined) {
1091
+ await files.mkdir(this.filesPath(path));
1092
+ } else {
1093
+ this.out.stdout += `could not create empty submodule directory ${dp}`;
1094
+ }
1095
+ // `git config --get-regexp 'submodule.<name>\.'` over the whole configuration
1096
+ const store = RemoteConfigStore.from(this.workingCopy);
1097
+ if (this.registered(store, sub.name)) {
1098
+ store.removeSection(`submodule.${sub.name}`);
1099
+ await store.save();
1100
+ if (!this.quiet) {
1101
+ this.out.stdout += `Submodule '${sub.name}' (${sub.url ?? "(null)"}) unregistered for path '${dp}'\n`;
1102
+ }
1103
+ }
1104
+ }
1105
+
1106
+ /**
1107
+ * Whether the configuration holds a `submodule.<name>.*` variable (git runs `git config
1108
+ * --get-regexp 'submodule.<name>\.'`; the name is compared as a string, never compiled
1109
+ * into a pattern: a name from `.gitmodules` is untrusted).
1110
+ */
1111
+ private registered(store: RemoteConfigStore, name: string): boolean {
1112
+ const entries = store.entriesWithPrefix("submodule.");
1113
+ if (!entries) return store.values(`submodule.${name}.url`).length > 0;
1114
+ const prefix = `submodule.${name}.`;
1115
+ return entries.some((e) => e.key.startsWith(prefix) && e.key.length > prefix.length);
1116
+ }
1117
+
1118
+ /** submodule.c's `submodule_unset_core_worktree`. */
1119
+ private async unsetCoreWorktree(sub: SubmoduleSettings): Promise<void> {
1120
+ const model = await this.model();
1121
+ let gitDir: string | undefined;
1122
+ try {
1123
+ await this.validatePath(sub.path ?? "");
1124
+ gitDir = await model.gitDirOf(sub.name);
1125
+ } catch (error) {
1126
+ if (error instanceof GitApiError && !(error instanceof SubmoduleCommandError)) {
1127
+ this.die(error.message);
1128
+ }
1129
+ throw error;
1130
+ }
1131
+ const files = this.worktreeAccess?.getFiles?.();
1132
+ // the config file as git's lock finds it: its directory through links, or the lock fails
1133
+ const physical =
1134
+ gitDir !== undefined && files ? await physicalFilesPath(files, gitDir) : undefined;
1135
+ const directory =
1136
+ physical !== undefined &&
1137
+ (await files?.stats(physical).catch(() => undefined))?.kind === "directory";
1138
+ if (gitDir !== undefined && !directory) {
1139
+ this.out.stderr += `error: could not lock config file ${model.shownPath(gitDir)}/config: No such file or directory\n`;
1140
+ }
1141
+ const done =
1142
+ directory &&
1143
+ (await setInConfigFile(this.workingCopy, `${physical}/config`, "core.worktree", undefined));
1144
+ if (!done) {
1145
+ this.out.stderr += `warning: Could not unset core.worktree setting in submodule '${sub.path ?? ""}'\n`;
1146
+ }
1147
+ }
1148
+ }
1149
+
1150
+ /**
1151
+ * `git submodule absorbgitdirs [-q] [<path>...]` (submodule--helper's `absorbgitdirs`): each
1152
+ * submodule of the index (matching the paths) whose repository is a `.git` directory in its
1153
+ * worktree gets it moved into the superproject's git directory (`.git/modules/<name>`, or
1154
+ * `submodule.<name>.gitdir` under `extensions.submodulePathConfig`), a gitfile and
1155
+ * `core.worktree` linking the two, then the same for its own submodules, at every depth.
1156
+ * git prints each move on stderr whatever `-q` says.
1157
+ *
1158
+ * @example
1159
+ * ```typescript
1160
+ * const { stderr } = await git.submoduleAbsorbGitDirs().call();
1161
+ * // "Migrating git directory of 'lib' from\n'/w/sup/lib/.git' to\n'/w/sup/.git/modules/lib'\n"
1162
+ * ```
1163
+ */
1164
+ export class SubmoduleAbsorbGitDirsCommand extends SubmoduleCommandBase {
1165
+ private readonly paths: string[] = [];
1166
+
1167
+ /** A path (pathspec element) limiting the submodules. */
1168
+ addPath(path: string): this {
1169
+ this.checkCallable();
1170
+ this.paths.push(path);
1171
+ return this;
1172
+ }
1173
+
1174
+ async call(): Promise<SubmoduleCommandResult> {
1175
+ this.start();
1176
+ const list = await this.moduleList(this.paths);
1177
+ if (!list) return this.finish();
1178
+ for (const entry of list) await this.absorbGitDirIntoSuperproject(entry.path);
1179
+ return this.finish();
1180
+ }
1181
+
1182
+ /**
1183
+ * @internal `absorb_git_dir_into_superproject` of the submodule at `path` alone (no
1184
+ * pathspec, no module list), as `git rm` runs it before removing a submodule.
1185
+ */
1186
+ async callForPath(path: string): Promise<SubmoduleCommandResult> {
1187
+ this.start();
1188
+ await this.absorbGitDirIntoSuperproject(path);
1189
+ return this.finish();
1190
+ }
1191
+ }
1192
+
1193
+ /**
1194
+ * `git submodule sync [-q] [--recursive] [<path>...]`: each active submodule's URL
1195
+ * registered again in `.git/config` from `.gitmodules`, and written to the default remote of
1196
+ * a populated submodule (a relative URL resolved from the submodule's own place; in git 2.5x
1197
+ * the remote already naming that URL first). `--recursive` goes on in each populated
1198
+ * submodule's own submodules.
1199
+ *
1200
+ * @example
1201
+ * ```typescript
1202
+ * const { stdout } = await git.submoduleSync().setRecursive(true).call();
1203
+ * // "Synchronizing submodule url for 'lib'\nSynchronizing submodule url for 'lib/nested'\n"
1204
+ * ```
1205
+ */
1206
+ export class SubmoduleSyncCommand extends SubmoduleCommandBase {
1207
+ private readonly paths: string[] = [];
1208
+ private recursive = false;
1209
+
1210
+ /** A path (pathspec element) limiting the submodules. */
1211
+ addPath(path: string): this {
1212
+ this.checkCallable();
1213
+ this.paths.push(path);
1214
+ return this;
1215
+ }
1216
+
1217
+ /** `--recursive`: sync nested submodules too. */
1218
+ setRecursive(recursive: boolean): this {
1219
+ this.checkCallable();
1220
+ this.recursive = recursive;
1221
+ return this;
1222
+ }
1223
+
1224
+ async call(): Promise<SubmoduleCommandResult> {
1225
+ this.start();
1226
+ const list = await this.moduleList(this.paths);
1227
+ if (!list) return this.finish();
1228
+ for (const entry of list) await this.syncSubmodule(entry.path, this.recursive);
1229
+ return this.finish();
1230
+ }
1231
+ }
1232
+
1233
+ const SET_URL_USAGE = [
1234
+ "usage: git submodule set-url [--quiet] <path> <newurl>",
1235
+ "",
1236
+ " -q, --[no-]quiet suppress output for setting url of a submodule",
1237
+ "",
1238
+ ].join("\n");
1239
+
1240
+ /**
1241
+ * `git submodule set-url [-q] <path> <newurl>`: the submodule's `url` in `.gitmodules` set
1242
+ * (the file is not staged), then synced as `git submodule sync` does.
1243
+ *
1244
+ * @example
1245
+ * ```typescript
1246
+ * await git.submoduleSetUrl().setPath("lib").setUrl("../new-lib").call();
1247
+ * ```
1248
+ */
1249
+ export class SubmoduleSetUrlCommand extends SubmoduleCommandBase {
1250
+ private path?: string;
1251
+ private url?: string;
1252
+
1253
+ setPath(path: string): this {
1254
+ this.checkCallable();
1255
+ this.path = path;
1256
+ return this;
1257
+ }
1258
+
1259
+ setUrl(url: string): this {
1260
+ this.checkCallable();
1261
+ this.url = url;
1262
+ return this;
1263
+ }
1264
+
1265
+ async call(): Promise<SubmoduleCommandResult> {
1266
+ this.start();
1267
+ if (this.path === undefined || this.url === undefined) this.die(SET_URL_USAGE, 129);
1268
+ const model = await this.model();
1269
+ const sub = model.fromPath(this.path);
1270
+ if (!sub) {
1271
+ this.die(`fatal: no submodule mapping found in .gitmodules for path '${this.path}'`);
1272
+ }
1273
+ await this.setInGitmodules(`submodule.${sub.name}.url`, this.url);
1274
+ this.forgetModel();
1275
+ await this.syncSubmodule(sub.path ?? this.path, false);
1276
+ return this.finish();
1277
+ }
1278
+ }
1279
+
1280
+ const SET_BRANCH_USAGE = [
1281
+ "usage: git submodule set-branch [-q|--quiet] (-d|--default) <path>",
1282
+ " or: git submodule set-branch [-q|--quiet] (-b|--branch) <branch> <path>",
1283
+ "",
1284
+ " -d, --[no-]default set the default tracking branch to master",
1285
+ " -b, --[no-]branch <branch>",
1286
+ " set the default tracking branch",
1287
+ "",
1288
+ ].join("\n");
1289
+
1290
+ /**
1291
+ * `git submodule set-branch (-b <branch> | -d) <path>`: the submodule's `branch` in
1292
+ * `.gitmodules` set, or removed with `-d` (exit status 1 when there was none).
1293
+ *
1294
+ * @example
1295
+ * ```typescript
1296
+ * await git.submoduleSetBranch().setPath("lib").setBranch("stable").call();
1297
+ * ```
1298
+ */
1299
+ export class SubmoduleSetBranchCommand extends SubmoduleCommandBase {
1300
+ private path?: string;
1301
+ private branch?: string;
1302
+ private useDefault = false;
1303
+
1304
+ setPath(path: string): this {
1305
+ this.checkCallable();
1306
+ this.path = path;
1307
+ return this;
1308
+ }
1309
+
1310
+ /** `-b <branch>`. */
1311
+ setBranch(branch: string): this {
1312
+ this.checkCallable();
1313
+ this.branch = branch;
1314
+ return this;
1315
+ }
1316
+
1317
+ /** `-d`: back to the default (the setting removed). */
1318
+ setDefault(useDefault: boolean): this {
1319
+ this.checkCallable();
1320
+ this.useDefault = useDefault;
1321
+ return this;
1322
+ }
1323
+
1324
+ async call(): Promise<SubmoduleCommandResult> {
1325
+ this.start();
1326
+ if (this.branch === undefined && !this.useDefault) {
1327
+ this.die("fatal: --branch or --default required");
1328
+ }
1329
+ if (this.branch !== undefined && this.useDefault) {
1330
+ this.die("fatal: options '--branch' and '--default' cannot be used together");
1331
+ }
1332
+ if (this.path === undefined) this.die(SET_BRANCH_USAGE, 129);
1333
+ const model = await this.model();
1334
+ const sub = model.fromPath(this.path);
1335
+ if (!sub) {
1336
+ this.die(`fatal: no submodule mapping found in .gitmodules for path '${this.path}'`);
1337
+ }
1338
+ const done = await this.setInGitmodules(`submodule.${sub.name}.branch`, this.branch);
1339
+ if (!done) this.out.exitCode = 1;
1340
+ return this.finish();
1341
+ }
1342
+ }
1343
+
1344
+ /** What a {@link SubmoduleForeachCommand} callback is given (git's variables). */
1345
+ export interface SubmoduleForeachContext {
1346
+ /** `$name`: the submodule's name in `.gitmodules` */
1347
+ name: string;
1348
+ /** `$sm_path`: its path in the superproject running the command */
1349
+ path: string;
1350
+ /** `$displaypath`: its path from the top superproject */
1351
+ displayPath: string;
1352
+ /** `$sha1`: the commit the superproject's index records */
1353
+ sha1: ObjectId;
1354
+ /** `$toplevel`: the host path of the superproject running the command */
1355
+ toplevel: string | undefined;
1356
+ /** The submodule's working copy */
1357
+ workingCopy: WorkingCopy;
1358
+ }
1359
+
1360
+ /** A callback run in each submodule in place of a command. */
1361
+ export type SubmoduleForeachCallback = (
1362
+ context: SubmoduleForeachContext,
1363
+ // biome-ignore lint/suspicious/noConfusingVoidType: a callback may return nothing
1364
+ ) => Promise<SubmoduleForeachOutcome | undefined | void>;
1365
+
1366
+ /** What a callback reports back: a non-zero `exitCode` stops the walk as git dies. */
1367
+ export interface SubmoduleForeachOutcome {
1368
+ exitCode?: number;
1369
+ stdout?: string;
1370
+ stderr?: string;
1371
+ }
1372
+
1373
+ /**
1374
+ * `git submodule foreach [-q] [--recursive] <command>`: in each populated submodule (index
1375
+ * order), `Entering '<displaypath>'` and the command, run through the host's command runner
1376
+ * (`GitHostEnvironment.hookRunner`) as git runs it: one argument through the shell with
1377
+ * `$name`, `$sm_path`, `$displaypath`, `$sha1`, `$toplevel` (and `$path`) set, several as
1378
+ * an argument list; `GIT_DIR=.git` and the repository variables cleared. A callback may take
1379
+ * the command's place. A command that fails stops the walk (git's "run_command returned
1380
+ * non-zero status"); `--recursive` runs it in nested submodules after their parent.
1381
+ *
1382
+ * @example
1383
+ * ```typescript
1384
+ * await git.submoduleForeach().setCommand(["git pull"]).call();
1385
+ * await git.submoduleForeach().setCallback(async ({ name, sha1 }) => {
1386
+ * console.log(name, sha1);
1387
+ * }).call();
1388
+ * ```
1389
+ */
1390
+ export class SubmoduleForeachCommand extends SubmoduleCommandBase {
1391
+ private command: string[] = [];
1392
+ private callback?: SubmoduleForeachCallback;
1393
+ private recursive = false;
1394
+
1395
+ /** The command and its arguments (git's `<command>...`). */
1396
+ setCommand(command: string[]): this {
1397
+ this.checkCallable();
1398
+ this.command = [...command];
1399
+ return this;
1400
+ }
1401
+
1402
+ /** A callback run in place of a command. */
1403
+ setCallback(callback: SubmoduleForeachCallback): this {
1404
+ this.checkCallable();
1405
+ this.callback = callback;
1406
+ return this;
1407
+ }
1408
+
1409
+ /** `--recursive`: nested submodules too. */
1410
+ setRecursive(recursive: boolean): this {
1411
+ this.checkCallable();
1412
+ this.recursive = recursive;
1413
+ return this;
1414
+ }
1415
+
1416
+ async call(): Promise<SubmoduleCommandResult> {
1417
+ this.start();
1418
+ const list = await this.moduleList([]);
1419
+ if (!list) return this.finish();
1420
+ const toplevel = await worktreeHostPath(this.workingCopy);
1421
+ for (const { path, id } of list) {
1422
+ await this.validatePath(path);
1423
+ const dp = this.displayPath(path);
1424
+ const model = await this.model();
1425
+ const sub = model.fromPath(path);
1426
+ if (!sub) this.die(`fatal: No url found for submodule path '${dp}' in .gitmodules`);
1427
+ const inner = await this.openSubmodule(path);
1428
+ if (!inner) continue;
1429
+ if (!this.quiet) this.out.stdout += `Entering '${dp}'\n`;
1430
+ const context: SubmoduleForeachContext = {
1431
+ name: sub.name,
1432
+ path,
1433
+ displayPath: dp,
1434
+ sha1: id,
1435
+ toplevel,
1436
+ workingCopy: inner,
1437
+ };
1438
+ let exitCode = 0;
1439
+ if (this.callback) {
1440
+ const outcome = (await this.callback(context)) ?? undefined;
1441
+ this.out.stdout += outcome?.stdout ?? "";
1442
+ this.out.stderr += outcome?.stderr ?? "";
1443
+ exitCode = outcome?.exitCode ?? 0;
1444
+ } else if (this.command.length > 0) {
1445
+ exitCode = await this.runCommand(context, inner);
1446
+ }
1447
+ if (exitCode !== 0) this.die(`fatal: run_command returned non-zero status for ${dp}\n.`);
1448
+ if (this.recursive) {
1449
+ const child = new SubmoduleForeachCommand(inner)
1450
+ .setQuiet(this.quiet)
1451
+ .setRecursive(true)
1452
+ .setCommand(this.command)
1453
+ .setSuperPrefix(`${dp}/`);
1454
+ if (this.callback) child.setCallback(this.callback);
1455
+ try {
1456
+ this.append(await child.call());
1457
+ } catch (error) {
1458
+ if (!(error instanceof SubmoduleCommandError)) throw error;
1459
+ this.append(error.result);
1460
+ this.out.stderr += `${error.message}\n`;
1461
+ this.die(
1462
+ `fatal: run_command returned non-zero status while recursing in the nested submodules of ${dp}\n.`,
1463
+ );
1464
+ }
1465
+ }
1466
+ }
1467
+ return this.finish();
1468
+ }
1469
+
1470
+ /** The command in the submodule, through the host's runner; its exit status. */
1471
+ private async runCommand(context: SubmoduleForeachContext, inner: WorkingCopy): Promise<number> {
1472
+ const runner = hookRunnerOf(this.workingCopy);
1473
+ const [first, ...rest] = this.command as [string, ...string[]];
1474
+ if (!runner) {
1475
+ this.die(`fatal: cannot run '${first}': no command runner on this host`);
1476
+ }
1477
+ const single = this.command.length === 1;
1478
+ const command = single ? `path=${shellQuote(context.path)}; ${first}` : first;
1479
+ const env: Record<string, string> = { GIT_DIR: ".git" };
1480
+ if (single) {
1481
+ env.name = context.name;
1482
+ env.sm_path = context.path;
1483
+ env.displaypath = context.displayPath;
1484
+ env.sha1 = context.sha1;
1485
+ if (context.toplevel !== undefined) env.toplevel = context.toplevel;
1486
+ }
1487
+ const hostCwd = await worktreeHostPath(inner);
1488
+ const outcome = await runner.run({
1489
+ name: "submodule-foreach",
1490
+ path: command,
1491
+ command,
1492
+ args: single ? [] : rest,
1493
+ env,
1494
+ unsetEnv: SUBMODULE_UNSET_ENV,
1495
+ cwd: this.filesPath(context.path),
1496
+ ...(hostCwd !== undefined ? { hostCwd } : {}),
1497
+ stdoutToStderr: false,
1498
+ });
1499
+ if (!outcome) return 127;
1500
+ const decoder = new TextDecoder();
1501
+ this.out.stdout += decoder.decode(outcome.stdout);
1502
+ this.out.stderr += decoder.decode(outcome.stderr);
1503
+ return outcome.exitCode;
1504
+ }
1505
+ }
1506
+
1507
+ /** A local path that is not absolute (`../up`, a remote's relative URL resolved). */
1508
+ function isLocalRelativePath(url: string): boolean {
1509
+ return !url.startsWith("/") && urlIsLocalNotSsh(url);
1510
+ }
1511
+
1512
+ /** The environment with `GIT_PROTOCOL_FROM_USER=0` (git-submodule.sh exports it). */
1513
+ export function notFromUser(environment: GitHostEnvironment): GitHostEnvironment {
1514
+ return Object.create(environment, {
1515
+ protocolFromUser: { value: false, enumerable: true },
1516
+ }) as GitHostEnvironment;
1517
+ }