@statewalker/vcs-commands 0.8.0 → 0.10.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 (622) hide show
  1. package/README.md +1 -1
  2. package/dist/commands/add-command.d.ts +32 -0
  3. package/dist/commands/add-command.d.ts.map +1 -1
  4. package/dist/commands/add-patch/add-patch.d.ts +7 -0
  5. package/dist/commands/add-patch/add-patch.d.ts.map +1 -1
  6. package/dist/commands/add-patch/patch-backend.d.ts +2 -0
  7. package/dist/commands/add-patch/patch-backend.d.ts.map +1 -1
  8. package/dist/commands/add-patch/patch-modes.d.ts +6 -2
  9. package/dist/commands/add-patch/patch-modes.d.ts.map +1 -1
  10. package/dist/commands/add-patch/patch-session.d.ts +4 -0
  11. package/dist/commands/add-patch/patch-session.d.ts.map +1 -1
  12. package/dist/commands/am/am-command.d.ts +88 -2
  13. package/dist/commands/am/am-command.d.ts.map +1 -1
  14. package/dist/commands/apply/apply-command.d.ts +2 -0
  15. package/dist/commands/apply/apply-command.d.ts.map +1 -1
  16. package/dist/commands/apply/apply-parse.d.ts +7 -0
  17. package/dist/commands/apply/apply-parse.d.ts.map +1 -1
  18. package/dist/commands/apply/index.d.ts +1 -1
  19. package/dist/commands/apply/index.d.ts.map +1 -1
  20. package/dist/commands/archive/archive-command.d.ts +169 -0
  21. package/dist/commands/archive/archive-command.d.ts.map +1 -0
  22. package/dist/commands/archive/archive-entry.d.ts +60 -0
  23. package/dist/commands/archive/archive-entry.d.ts.map +1 -0
  24. package/dist/commands/archive/index.d.ts +8 -0
  25. package/dist/commands/archive/index.d.ts.map +1 -0
  26. package/dist/commands/archive/remote-archive-command.d.ts +56 -0
  27. package/dist/commands/archive/remote-archive-command.d.ts.map +1 -0
  28. package/dist/commands/archive/tar-archive.d.ts +31 -0
  29. package/dist/commands/archive/tar-archive.d.ts.map +1 -0
  30. package/dist/commands/archive/tar-commit-id.d.ts +13 -0
  31. package/dist/commands/archive/tar-commit-id.d.ts.map +1 -0
  32. package/dist/commands/archive/upload-archive-writer.d.ts +48 -0
  33. package/dist/commands/archive/upload-archive-writer.d.ts.map +1 -0
  34. package/dist/commands/archive/zip-archive.d.ts +42 -0
  35. package/dist/commands/archive/zip-archive.d.ts.map +1 -0
  36. package/dist/commands/attributes-source.d.ts +10 -0
  37. package/dist/commands/attributes-source.d.ts.map +1 -1
  38. package/dist/commands/blame-command.d.ts +345 -8
  39. package/dist/commands/blame-command.d.ts.map +1 -1
  40. package/dist/commands/blame-ignore.d.ts +48 -0
  41. package/dist/commands/blame-ignore.d.ts.map +1 -0
  42. package/dist/commands/bundle/bundle-create-command.d.ts +67 -0
  43. package/dist/commands/bundle/bundle-create-command.d.ts.map +1 -0
  44. package/dist/commands/bundle/bundle-format.d.ts +89 -0
  45. package/dist/commands/bundle/bundle-format.d.ts.map +1 -0
  46. package/dist/commands/bundle/bundle-list.d.ts +92 -0
  47. package/dist/commands/bundle/bundle-list.d.ts.map +1 -0
  48. package/dist/commands/bundle/bundle-read-commands.d.ts +81 -0
  49. package/dist/commands/bundle/bundle-read-commands.d.ts.map +1 -0
  50. package/dist/commands/bundle/bundle-support.d.ts +32 -0
  51. package/dist/commands/bundle/bundle-support.d.ts.map +1 -0
  52. package/dist/commands/bundle/bundle-transport.d.ts +38 -0
  53. package/dist/commands/bundle/bundle-transport.d.ts.map +1 -0
  54. package/dist/commands/bundle/bundle-uri-host.d.ts +43 -0
  55. package/dist/commands/bundle/bundle-uri-host.d.ts.map +1 -0
  56. package/dist/commands/bundle/bundle-uri.d.ts +55 -0
  57. package/dist/commands/bundle/bundle-uri.d.ts.map +1 -0
  58. package/dist/commands/bundle/bundle-verify.d.ts +63 -0
  59. package/dist/commands/bundle/bundle-verify.d.ts.map +1 -0
  60. package/dist/commands/bundle/index.d.ts +14 -0
  61. package/dist/commands/bundle/index.d.ts.map +1 -0
  62. package/dist/commands/cat-file/batch-format.d.ts +58 -0
  63. package/dist/commands/cat-file/batch-format.d.ts.map +1 -0
  64. package/dist/commands/cat-file/cat-file-command.d.ts +135 -0
  65. package/dist/commands/cat-file/cat-file-command.d.ts.map +1 -0
  66. package/dist/commands/cat-file/index.d.ts +3 -0
  67. package/dist/commands/cat-file/index.d.ts.map +1 -0
  68. package/dist/commands/check-attr-command.d.ts +66 -0
  69. package/dist/commands/check-attr-command.d.ts.map +1 -0
  70. package/dist/commands/check-ignore-command.d.ts +58 -0
  71. package/dist/commands/check-ignore-command.d.ts.map +1 -0
  72. package/dist/commands/check-mailmap-command.d.ts +49 -0
  73. package/dist/commands/check-mailmap-command.d.ts.map +1 -0
  74. package/dist/commands/check-ref-format-command.d.ts +60 -0
  75. package/dist/commands/check-ref-format-command.d.ts.map +1 -0
  76. package/dist/commands/checkout-command.d.ts +7 -0
  77. package/dist/commands/checkout-command.d.ts.map +1 -1
  78. package/dist/commands/checkout-index-command.d.ts +96 -0
  79. package/dist/commands/checkout-index-command.d.ts.map +1 -0
  80. package/dist/commands/checkout-paths.d.ts +4 -0
  81. package/dist/commands/checkout-paths.d.ts.map +1 -1
  82. package/dist/commands/cherry-command.d.ts +61 -0
  83. package/dist/commands/cherry-command.d.ts.map +1 -0
  84. package/dist/commands/cherry-pick-command.d.ts +33 -1
  85. package/dist/commands/cherry-pick-command.d.ts.map +1 -1
  86. package/dist/commands/clean-command.d.ts +32 -0
  87. package/dist/commands/clean-command.d.ts.map +1 -1
  88. package/dist/commands/clean-interactive.d.ts +56 -0
  89. package/dist/commands/clean-interactive.d.ts.map +1 -0
  90. package/dist/commands/clone-command.d.ts +135 -2
  91. package/dist/commands/clone-command.d.ts.map +1 -1
  92. package/dist/commands/commit-command.d.ts +59 -3
  93. package/dist/commands/commit-command.d.ts.map +1 -1
  94. package/dist/commands/config-command.d.ts +2 -0
  95. package/dist/commands/config-command.d.ts.map +1 -1
  96. package/dist/commands/daemon-access-hook.d.ts +36 -0
  97. package/dist/commands/daemon-access-hook.d.ts.map +1 -0
  98. package/dist/commands/default-branch.d.ts +42 -0
  99. package/dist/commands/default-branch.d.ts.map +1 -1
  100. package/dist/commands/describe-command.d.ts +71 -64
  101. package/dist/commands/describe-command.d.ts.map +1 -1
  102. package/dist/commands/diff-command.d.ts +249 -10
  103. package/dist/commands/diff-command.d.ts.map +1 -1
  104. package/dist/commands/diff-external.d.ts +43 -0
  105. package/dist/commands/diff-external.d.ts.map +1 -0
  106. package/dist/commands/diff-plumbing/diff-pairs-command.d.ts +27 -0
  107. package/dist/commands/diff-plumbing/diff-pairs-command.d.ts.map +1 -0
  108. package/dist/commands/diff-plumbing/diff-plumbing-command.d.ts +129 -0
  109. package/dist/commands/diff-plumbing/diff-plumbing-command.d.ts.map +1 -0
  110. package/dist/commands/diff-plumbing/index.d.ts +3 -0
  111. package/dist/commands/diff-plumbing/index.d.ts.map +1 -0
  112. package/dist/commands/diff-textconv.d.ts +5 -1
  113. package/dist/commands/diff-textconv.d.ts.map +1 -1
  114. package/dist/commands/fast-export/fast-export-command.d.ts +135 -0
  115. package/dist/commands/fast-export/fast-export-command.d.ts.map +1 -0
  116. package/dist/commands/fast-export/fast-import-command.d.ts +182 -0
  117. package/dist/commands/fast-export/fast-import-command.d.ts.map +1 -0
  118. package/dist/commands/fast-export/fast-stream-support.d.ts +64 -0
  119. package/dist/commands/fast-export/fast-stream-support.d.ts.map +1 -0
  120. package/dist/commands/fast-export/index.d.ts +4 -0
  121. package/dist/commands/fast-export/index.d.ts.map +1 -0
  122. package/dist/commands/fetch-command.d.ts +125 -0
  123. package/dist/commands/fetch-command.d.ts.map +1 -1
  124. package/dist/commands/fetch-multiple-command.d.ts +193 -0
  125. package/dist/commands/fetch-multiple-command.d.ts.map +1 -0
  126. package/dist/commands/format-patch-command.d.ts +28 -2
  127. package/dist/commands/format-patch-command.d.ts.map +1 -1
  128. package/dist/commands/format-rev-command.d.ts +58 -0
  129. package/dist/commands/format-rev-command.d.ts.map +1 -0
  130. package/dist/commands/fsck/fsck-command.d.ts.map +1 -1
  131. package/dist/commands/fsck/fsck-msg-ids.d.ts +18 -3
  132. package/dist/commands/fsck/fsck-msg-ids.d.ts.map +1 -1
  133. package/dist/commands/fsmonitor-refresh.d.ts +69 -0
  134. package/dist/commands/fsmonitor-refresh.d.ts.map +1 -0
  135. package/dist/commands/gc-command.d.ts +5 -0
  136. package/dist/commands/gc-command.d.ts.map +1 -1
  137. package/dist/commands/git-describe.d.ts +77 -4
  138. package/dist/commands/git-describe.d.ts.map +1 -1
  139. package/dist/commands/git-hooks.d.ts +47 -1
  140. package/dist/commands/git-hooks.d.ts.map +1 -1
  141. package/dist/commands/git-paths.d.ts +26 -0
  142. package/dist/commands/git-paths.d.ts.map +1 -0
  143. package/dist/commands/grep/grep-command.d.ts +2 -1
  144. package/dist/commands/grep/grep-command.d.ts.map +1 -1
  145. package/dist/commands/history-command.d.ts +156 -0
  146. package/dist/commands/history-command.d.ts.map +1 -0
  147. package/dist/commands/http-config.d.ts +38 -0
  148. package/dist/commands/http-config.d.ts.map +1 -0
  149. package/dist/commands/index-adder.d.ts +12 -1
  150. package/dist/commands/index-adder.d.ts.map +1 -1
  151. package/dist/commands/index-host.d.ts.map +1 -1
  152. package/dist/commands/index.d.ts +56 -1
  153. package/dist/commands/index.d.ts.map +1 -1
  154. package/dist/commands/index.js +6 -3
  155. package/dist/commands/init-command.d.ts +89 -0
  156. package/dist/commands/init-command.d.ts.map +1 -1
  157. package/dist/commands/last-modified-command.d.ts +102 -0
  158. package/dist/commands/last-modified-command.d.ts.map +1 -0
  159. package/dist/commands/lfs/go-url.d.ts +43 -0
  160. package/dist/commands/lfs/go-url.d.ts.map +1 -0
  161. package/dist/commands/lfs/index.d.ts +3 -0
  162. package/dist/commands/lfs/index.d.ts.map +1 -0
  163. package/dist/commands/lfs/lfs-config.d.ts +174 -0
  164. package/dist/commands/lfs/lfs-config.d.ts.map +1 -0
  165. package/dist/commands/lfs/lfs-endpoint-command.d.ts +83 -0
  166. package/dist/commands/lfs/lfs-endpoint-command.d.ts.map +1 -0
  167. package/dist/commands/line-log.d.ts +161 -0
  168. package/dist/commands/line-log.d.ts.map +1 -0
  169. package/dist/commands/local-transport.d.ts.map +1 -1
  170. package/dist/commands/log-command.d.ts +261 -6
  171. package/dist/commands/log-command.d.ts.map +1 -1
  172. package/dist/commands/log-graph.d.ts +4 -2
  173. package/dist/commands/log-graph.d.ts.map +1 -1
  174. package/dist/commands/log-output.d.ts +88 -2
  175. package/dist/commands/log-output.d.ts.map +1 -1
  176. package/dist/commands/ls-files-command.d.ts +153 -0
  177. package/dist/commands/ls-files-command.d.ts.map +1 -0
  178. package/dist/commands/ls-remote-command.d.ts +5 -0
  179. package/dist/commands/ls-remote-command.d.ts.map +1 -1
  180. package/dist/commands/ls-tree-command.d.ts +105 -0
  181. package/dist/commands/ls-tree-command.d.ts.map +1 -0
  182. package/dist/commands/mailmap.d.ts +24 -1
  183. package/dist/commands/mailmap.d.ts.map +1 -1
  184. package/dist/commands/maintenance-run-command.d.ts +122 -0
  185. package/dist/commands/maintenance-run-command.d.ts.map +1 -0
  186. package/dist/commands/merge-command.d.ts +58 -1
  187. package/dist/commands/merge-command.d.ts.map +1 -1
  188. package/dist/commands/merge-config.d.ts +7 -0
  189. package/dist/commands/merge-config.d.ts.map +1 -1
  190. package/dist/commands/merge-drivers.d.ts +69 -5
  191. package/dist/commands/merge-drivers.d.ts.map +1 -1
  192. package/dist/commands/merge-strategy-options.d.ts +69 -0
  193. package/dist/commands/merge-strategy-options.d.ts.map +1 -0
  194. package/dist/commands/merge-support.d.ts +16 -0
  195. package/dist/commands/merge-support.d.ts.map +1 -1
  196. package/dist/commands/merge-tree-command.d.ts +122 -0
  197. package/dist/commands/merge-tree-command.d.ts.map +1 -0
  198. package/dist/commands/message-cleanup.d.ts +2 -0
  199. package/dist/commands/message-cleanup.d.ts.map +1 -1
  200. package/dist/commands/mktag-command.d.ts +51 -0
  201. package/dist/commands/mktag-command.d.ts.map +1 -0
  202. package/dist/commands/name-rev-command.d.ts +65 -0
  203. package/dist/commands/name-rev-command.d.ts.map +1 -0
  204. package/dist/commands/name-rev.d.ts +110 -22
  205. package/dist/commands/name-rev.d.ts.map +1 -1
  206. package/dist/commands/object-store/count-objects-command.d.ts +58 -0
  207. package/dist/commands/object-store/count-objects-command.d.ts.map +1 -0
  208. package/dist/commands/object-store/index.d.ts +5 -0
  209. package/dist/commands/object-store/index.d.ts.map +1 -0
  210. package/dist/commands/object-store/objects-directory.d.ts +12 -0
  211. package/dist/commands/object-store/objects-directory.d.ts.map +1 -0
  212. package/dist/commands/object-store/prune-command.d.ts +38 -0
  213. package/dist/commands/object-store/prune-command.d.ts.map +1 -0
  214. package/dist/commands/object-store/show-index-command.d.ts +23 -0
  215. package/dist/commands/object-store/show-index-command.d.ts.map +1 -0
  216. package/dist/commands/octopus-merge.d.ts +26 -1
  217. package/dist/commands/octopus-merge.d.ts.map +1 -1
  218. package/dist/commands/ort-merge.d.ts +40 -0
  219. package/dist/commands/ort-merge.d.ts.map +1 -1
  220. package/dist/commands/ort-recursive.d.ts.map +1 -1
  221. package/dist/commands/patch-id-command.d.ts +30 -0
  222. package/dist/commands/patch-id-command.d.ts.map +1 -0
  223. package/dist/commands/patch-id.d.ts +82 -0
  224. package/dist/commands/patch-id.d.ts.map +1 -1
  225. package/dist/commands/plumbing-command.d.ts +66 -0
  226. package/dist/commands/plumbing-command.d.ts.map +1 -0
  227. package/dist/commands/plumbing-input.d.ts +38 -0
  228. package/dist/commands/plumbing-input.d.ts.map +1 -0
  229. package/dist/commands/promisor-remote-reply.d.ts +35 -0
  230. package/dist/commands/promisor-remote-reply.d.ts.map +1 -0
  231. package/dist/commands/promisor-remote.d.ts.map +1 -1
  232. package/dist/commands/pull-command.d.ts +182 -38
  233. package/dist/commands/pull-command.d.ts.map +1 -1
  234. package/dist/commands/push-command.d.ts +82 -2
  235. package/dist/commands/push-command.d.ts.map +1 -1
  236. package/dist/commands/range-diff/index.d.ts +4 -0
  237. package/dist/commands/range-diff/index.d.ts.map +1 -0
  238. package/dist/commands/range-diff/linear-assignment.d.ts +27 -0
  239. package/dist/commands/range-diff/linear-assignment.d.ts.map +1 -0
  240. package/dist/commands/range-diff/range-diff-command.d.ts +121 -0
  241. package/dist/commands/range-diff/range-diff-command.d.ts.map +1 -0
  242. package/dist/commands/range-diff/range-diff.d.ts +106 -0
  243. package/dist/commands/range-diff/range-diff.d.ts.map +1 -0
  244. package/dist/commands/read-tree-command.d.ts +14 -0
  245. package/dist/commands/read-tree-command.d.ts.map +1 -1
  246. package/dist/commands/rebase-command.d.ts +129 -4
  247. package/dist/commands/rebase-command.d.ts.map +1 -1
  248. package/dist/commands/refs-command.d.ts +81 -0
  249. package/dist/commands/refs-command.d.ts.map +1 -0
  250. package/dist/commands/remerge-diff.d.ts +59 -0
  251. package/dist/commands/remerge-diff.d.ts.map +1 -0
  252. package/dist/commands/remote-command.d.ts +41 -0
  253. package/dist/commands/remote-command.d.ts.map +1 -1
  254. package/dist/commands/remote-object-info-command.d.ts +55 -0
  255. package/dist/commands/remote-object-info-command.d.ts.map +1 -0
  256. package/dist/commands/remote-show-command.d.ts +204 -0
  257. package/dist/commands/remote-show-command.d.ts.map +1 -0
  258. package/dist/commands/remote-transport.d.ts +40 -3
  259. package/dist/commands/remote-transport.d.ts.map +1 -1
  260. package/dist/commands/repack-command.d.ts +115 -0
  261. package/dist/commands/repack-command.d.ts.map +1 -0
  262. package/dist/commands/replace-command.d.ts +143 -0
  263. package/dist/commands/replace-command.d.ts.map +1 -0
  264. package/dist/commands/replay-command.d.ts +117 -0
  265. package/dist/commands/replay-command.d.ts.map +1 -0
  266. package/dist/commands/repo-command.d.ts +136 -0
  267. package/dist/commands/repo-command.d.ts.map +1 -0
  268. package/dist/commands/request-pull-command.d.ts +82 -0
  269. package/dist/commands/request-pull-command.d.ts.map +1 -0
  270. package/dist/commands/rerere-command.d.ts +36 -0
  271. package/dist/commands/rerere-command.d.ts.map +1 -0
  272. package/dist/commands/rerere.d.ts +102 -0
  273. package/dist/commands/rerere.d.ts.map +1 -0
  274. package/dist/commands/reset-command.d.ts +19 -1
  275. package/dist/commands/reset-command.d.ts.map +1 -1
  276. package/dist/commands/restore-command.d.ts +7 -0
  277. package/dist/commands/restore-command.d.ts.map +1 -1
  278. package/dist/commands/rev-filter/commit-grep.d.ts +3 -1
  279. package/dist/commands/rev-filter/commit-grep.d.ts.map +1 -1
  280. package/dist/commands/rev-list-command.d.ts +78 -3
  281. package/dist/commands/rev-list-command.d.ts.map +1 -1
  282. package/dist/commands/rev-parse-command.d.ts +9 -0
  283. package/dist/commands/rev-parse-command.d.ts.map +1 -1
  284. package/dist/commands/revert-command.d.ts +32 -1
  285. package/dist/commands/revert-command.d.ts.map +1 -1
  286. package/dist/commands/revision-range.d.ts +7 -0
  287. package/dist/commands/revision-range.d.ts.map +1 -1
  288. package/dist/commands/revision-resolver.d.ts +12 -0
  289. package/dist/commands/revision-resolver.d.ts.map +1 -1
  290. package/dist/commands/sequencer-pick.d.ts +120 -1
  291. package/dist/commands/sequencer-pick.d.ts.map +1 -1
  292. package/dist/commands/sequencer-support.d.ts +10 -1
  293. package/dist/commands/sequencer-support.d.ts.map +1 -1
  294. package/dist/commands/serve-repository.d.ts +23 -1
  295. package/dist/commands/serve-repository.d.ts.map +1 -1
  296. package/dist/commands/session-id.d.ts +18 -0
  297. package/dist/commands/session-id.d.ts.map +1 -0
  298. package/dist/commands/shortlog-command.d.ts +109 -0
  299. package/dist/commands/shortlog-command.d.ts.map +1 -0
  300. package/dist/commands/shortlog.d.ts +151 -0
  301. package/dist/commands/shortlog.d.ts.map +1 -0
  302. package/dist/commands/show-branch-command.d.ts +59 -0
  303. package/dist/commands/show-branch-command.d.ts.map +1 -0
  304. package/dist/commands/show-ref-command.d.ts +112 -0
  305. package/dist/commands/show-ref-command.d.ts.map +1 -0
  306. package/dist/commands/signature-check.d.ts +9 -2
  307. package/dist/commands/signature-check.d.ts.map +1 -1
  308. package/dist/commands/signing.d.ts +22 -1
  309. package/dist/commands/signing.d.ts.map +1 -1
  310. package/dist/commands/stash-apply-command.d.ts.map +1 -1
  311. package/dist/commands/stash-export-command.d.ts +115 -0
  312. package/dist/commands/stash-export-command.d.ts.map +1 -0
  313. package/dist/commands/status-command.d.ts +33 -3
  314. package/dist/commands/status-command.d.ts.map +1 -1
  315. package/dist/commands/stripspace-command.d.ts +44 -0
  316. package/dist/commands/stripspace-command.d.ts.map +1 -0
  317. package/dist/commands/submodule-add-command.d.ts +10 -1
  318. package/dist/commands/submodule-add-command.d.ts.map +1 -1
  319. package/dist/commands/submodule-auth.d.ts +3 -1
  320. package/dist/commands/submodule-auth.d.ts.map +1 -1
  321. package/dist/commands/submodule-commands.d.ts +99 -3
  322. package/dist/commands/submodule-commands.d.ts.map +1 -1
  323. package/dist/commands/submodule-fetch.d.ts +149 -0
  324. package/dist/commands/submodule-fetch.d.ts.map +1 -0
  325. package/dist/commands/submodule-model.d.ts +8 -0
  326. package/dist/commands/submodule-model.d.ts.map +1 -1
  327. package/dist/commands/submodule-unpack.d.ts +120 -0
  328. package/dist/commands/submodule-unpack.d.ts.map +1 -0
  329. package/dist/commands/submodule-update-command.d.ts +21 -1
  330. package/dist/commands/submodule-update-command.d.ts.map +1 -1
  331. package/dist/commands/subtree-shift.d.ts +27 -0
  332. package/dist/commands/subtree-shift.d.ts.map +1 -0
  333. package/dist/commands/switch-command.d.ts +3 -0
  334. package/dist/commands/switch-command.d.ts.map +1 -1
  335. package/dist/commands/textconv-cache.d.ts +58 -0
  336. package/dist/commands/textconv-cache.d.ts.map +1 -0
  337. package/dist/commands/tree-restore.d.ts +5 -0
  338. package/dist/commands/tree-restore.d.ts.map +1 -1
  339. package/dist/commands/unpack-objects-command.d.ts +47 -0
  340. package/dist/commands/unpack-objects-command.d.ts.map +1 -0
  341. package/dist/commands/update-index-command.d.ts +110 -0
  342. package/dist/commands/update-index-command.d.ts.map +1 -0
  343. package/dist/commands/uri-protocols.d.ts +13 -0
  344. package/dist/commands/uri-protocols.d.ts.map +1 -0
  345. package/dist/commands/url-parse-command.d.ts +30 -0
  346. package/dist/commands/url-parse-command.d.ts.map +1 -0
  347. package/dist/commands/var-command.d.ts +42 -0
  348. package/dist/commands/var-command.d.ts.map +1 -0
  349. package/dist/commands/worktree-overwrite-checks.d.ts +2 -0
  350. package/dist/commands/worktree-overwrite-checks.d.ts.map +1 -1
  351. package/dist/{commands-ISM52N0n.js → commands-Mlo1dxQN.js} +56133 -70269
  352. package/dist/errors/command-errors.d.ts +58 -0
  353. package/dist/errors/command-errors.d.ts.map +1 -1
  354. package/dist/errors/index.js +67 -1
  355. package/dist/fsck-CrhVMNIH.js +5179 -0
  356. package/dist/git-command.d.ts +89 -3
  357. package/dist/git-command.d.ts.map +1 -1
  358. package/dist/git.d.ts +628 -1
  359. package/dist/git.d.ts.map +1 -1
  360. package/dist/guarded-transport-command.d.ts +84 -0
  361. package/dist/guarded-transport-command.d.ts.map +1 -0
  362. package/dist/index.d.ts +1 -0
  363. package/dist/index.d.ts.map +1 -1
  364. package/dist/index.js +7 -5
  365. package/dist/maintenance-run-command-Bw21HEkH.js +13539 -0
  366. package/dist/remote-transport-Bu4PGSMD.js +2605 -0
  367. package/dist/rename/detect-renames.d.ts +20 -0
  368. package/dist/rename/detect-renames.d.ts.map +1 -1
  369. package/dist/rename/diffcore-break.d.ts +51 -0
  370. package/dist/rename/diffcore-break.d.ts.map +1 -0
  371. package/dist/rename/index.d.ts +1 -0
  372. package/dist/rename/index.d.ts.map +1 -1
  373. package/dist/results/blame-format.d.ts +62 -1
  374. package/dist/results/blame-format.d.ts.map +1 -1
  375. package/dist/results/cherry-pick-result.d.ts +6 -0
  376. package/dist/results/cherry-pick-result.d.ts.map +1 -1
  377. package/dist/results/clone-result.d.ts +9 -0
  378. package/dist/results/clone-result.d.ts.map +1 -1
  379. package/dist/results/diff-dirstat.d.ts +36 -0
  380. package/dist/results/diff-dirstat.d.ts.map +1 -0
  381. package/dist/results/diff-entry.d.ts +20 -0
  382. package/dist/results/diff-entry.d.ts.map +1 -1
  383. package/dist/results/diff-formatter.d.ts.map +1 -1
  384. package/dist/results/diff-output.d.ts +67 -3
  385. package/dist/results/diff-output.d.ts.map +1 -1
  386. package/dist/results/fetch-result.d.ts +24 -1
  387. package/dist/results/fetch-result.d.ts.map +1 -1
  388. package/dist/results/index.d.ts +2 -0
  389. package/dist/results/index.d.ts.map +1 -1
  390. package/dist/results/index.js +2 -2
  391. package/dist/results/init-result.d.ts +8 -1
  392. package/dist/results/init-result.d.ts.map +1 -1
  393. package/dist/results/line-range-hunks.d.ts +27 -0
  394. package/dist/results/line-range-hunks.d.ts.map +1 -0
  395. package/dist/results/merge-result.d.ts +13 -1
  396. package/dist/results/merge-result.d.ts.map +1 -1
  397. package/dist/results/pull-result.d.ts +11 -0
  398. package/dist/results/pull-result.d.ts.map +1 -1
  399. package/dist/results/push-result.d.ts +10 -0
  400. package/dist/results/push-result.d.ts.map +1 -1
  401. package/dist/results/rebase-result.d.ts +7 -0
  402. package/dist/results/rebase-result.d.ts.map +1 -1
  403. package/dist/results/revert-result.d.ts +6 -0
  404. package/dist/results/revert-result.d.ts.map +1 -1
  405. package/dist/results/stash-result.d.ts +5 -0
  406. package/dist/results/stash-result.d.ts.map +1 -1
  407. package/dist/results/status-result.d.ts +1 -1
  408. package/dist/results/status-result.d.ts.map +1 -1
  409. package/dist/results-ERo9vELd.js +49673 -0
  410. package/dist/transport-command.d.ts +93 -1
  411. package/dist/transport-command.d.ts.map +1 -1
  412. package/package.json +12 -12
  413. package/src/commands/add-command.ts +118 -0
  414. package/src/commands/add-patch/add-patch.ts +8 -0
  415. package/src/commands/add-patch/patch-backend.ts +24 -3
  416. package/src/commands/add-patch/patch-modes.ts +26 -2
  417. package/src/commands/add-patch/patch-session.ts +6 -0
  418. package/src/commands/am/am-command.ts +301 -12
  419. package/src/commands/apply/apply-command.ts +52 -9
  420. package/src/commands/apply/apply-parse.ts +10 -0
  421. package/src/commands/apply/index.ts +9 -1
  422. package/src/commands/archive/archive-command.ts +1148 -0
  423. package/src/commands/archive/archive-entry.ts +93 -0
  424. package/src/commands/archive/index.ts +7 -0
  425. package/src/commands/archive/remote-archive-command.ts +140 -0
  426. package/src/commands/archive/tar-archive.ts +207 -0
  427. package/src/commands/archive/tar-commit-id.ts +72 -0
  428. package/src/commands/archive/upload-archive-writer.ts +213 -0
  429. package/src/commands/archive/zip-archive.ts +317 -0
  430. package/src/commands/attributes-source.ts +26 -12
  431. package/src/commands/blame-command.ts +1551 -53
  432. package/src/commands/blame-ignore.ts +307 -0
  433. package/src/commands/bundle/bundle-create-command.ts +405 -0
  434. package/src/commands/bundle/bundle-format.ts +228 -0
  435. package/src/commands/bundle/bundle-list.ts +276 -0
  436. package/src/commands/bundle/bundle-read-commands.ts +157 -0
  437. package/src/commands/bundle/bundle-support.ts +85 -0
  438. package/src/commands/bundle/bundle-transport.ts +107 -0
  439. package/src/commands/bundle/bundle-uri-host.ts +204 -0
  440. package/src/commands/bundle/bundle-uri.ts +236 -0
  441. package/src/commands/bundle/bundle-verify.ts +152 -0
  442. package/src/commands/bundle/index.ts +14 -0
  443. package/src/commands/cat-file/batch-format.ts +193 -0
  444. package/src/commands/cat-file/cat-file-command.ts +857 -0
  445. package/src/commands/cat-file/index.ts +2 -0
  446. package/src/commands/check-attr-command.ts +333 -0
  447. package/src/commands/check-ignore-command.ts +261 -0
  448. package/src/commands/check-mailmap-command.ts +129 -0
  449. package/src/commands/check-ref-format-command.ts +129 -0
  450. package/src/commands/checkout-command.ts +131 -28
  451. package/src/commands/checkout-index-command.ts +568 -0
  452. package/src/commands/checkout-paths.ts +35 -0
  453. package/src/commands/cherry-command.ts +187 -0
  454. package/src/commands/cherry-pick-command.ts +63 -2
  455. package/src/commands/clean-command.ts +92 -12
  456. package/src/commands/clean-interactive.ts +522 -0
  457. package/src/commands/clone-command.ts +803 -50
  458. package/src/commands/commit-command.ts +202 -51
  459. package/src/commands/config-command.ts +9 -0
  460. package/src/commands/daemon-access-hook.ts +78 -0
  461. package/src/commands/default-branch.ts +99 -1
  462. package/src/commands/describe-command.ts +341 -254
  463. package/src/commands/diff-command.ts +1186 -99
  464. package/src/commands/diff-external.ts +131 -0
  465. package/src/commands/diff-plumbing/diff-pairs-command.ts +193 -0
  466. package/src/commands/diff-plumbing/diff-plumbing-command.ts +424 -0
  467. package/src/commands/diff-plumbing/index.ts +2 -0
  468. package/src/commands/diff-textconv.ts +5 -1
  469. package/src/commands/fast-export/fast-export-command.ts +911 -0
  470. package/src/commands/fast-export/fast-import-command.ts +1553 -0
  471. package/src/commands/fast-export/fast-stream-support.ts +162 -0
  472. package/src/commands/fast-export/index.ts +3 -0
  473. package/src/commands/fetch-command.ts +665 -14
  474. package/src/commands/fetch-multiple-command.ts +668 -0
  475. package/src/commands/format-patch-command.ts +189 -77
  476. package/src/commands/format-rev-command.ts +251 -0
  477. package/src/commands/fsck/fsck-command.ts +47 -20
  478. package/src/commands/fsck/fsck-msg-ids.ts +19 -3
  479. package/src/commands/fsck/fsck-pack.ts +2 -2
  480. package/src/commands/fsmonitor-refresh.ts +315 -0
  481. package/src/commands/gc-command.ts +10 -0
  482. package/src/commands/git-describe.ts +456 -217
  483. package/src/commands/git-hooks.ts +165 -9
  484. package/src/commands/git-paths.ts +136 -0
  485. package/src/commands/grep/grep-command.ts +38 -15
  486. package/src/commands/history-command.ts +617 -0
  487. package/src/commands/http-config.ts +139 -0
  488. package/src/commands/index-adder.ts +37 -3
  489. package/src/commands/index-host.ts +6 -1
  490. package/src/commands/index.ts +62 -0
  491. package/src/commands/init-command.ts +617 -49
  492. package/src/commands/last-modified-command.ts +804 -0
  493. package/src/commands/lfs/go-url.ts +370 -0
  494. package/src/commands/lfs/index.ts +2 -0
  495. package/src/commands/lfs/lfs-config.ts +738 -0
  496. package/src/commands/lfs/lfs-endpoint-command.ts +180 -0
  497. package/src/commands/line-log.ts +931 -0
  498. package/src/commands/local-transport.ts +252 -4
  499. package/src/commands/log-command.ts +1518 -182
  500. package/src/commands/log-graph.ts +6 -3
  501. package/src/commands/log-output.ts +228 -15
  502. package/src/commands/ls-files-command.ts +1177 -0
  503. package/src/commands/ls-remote-command.ts +6 -0
  504. package/src/commands/ls-tree-command.ts +684 -0
  505. package/src/commands/mailmap.ts +41 -5
  506. package/src/commands/maintenance-run-command.ts +949 -0
  507. package/src/commands/merge-command.ts +351 -47
  508. package/src/commands/merge-config.ts +23 -1
  509. package/src/commands/merge-drivers.ts +112 -20
  510. package/src/commands/merge-strategy-options.ts +224 -0
  511. package/src/commands/merge-support.ts +130 -26
  512. package/src/commands/merge-tree-command.ts +786 -0
  513. package/src/commands/message-cleanup.ts +1 -1
  514. package/src/commands/mktag-command.ts +149 -0
  515. package/src/commands/name-rev-command.ts +184 -0
  516. package/src/commands/name-rev.ts +700 -109
  517. package/src/commands/object-store/count-objects-command.ts +404 -0
  518. package/src/commands/object-store/index.ts +4 -0
  519. package/src/commands/object-store/objects-directory.ts +24 -0
  520. package/src/commands/object-store/prune-command.ts +129 -0
  521. package/src/commands/object-store/show-index-command.ts +151 -0
  522. package/src/commands/octopus-merge.ts +35 -11
  523. package/src/commands/ort-merge.ts +124 -23
  524. package/src/commands/ort-recursive.ts +40 -2
  525. package/src/commands/patch-id-command.ts +65 -0
  526. package/src/commands/patch-id.ts +327 -0
  527. package/src/commands/plumbing-command.ts +141 -0
  528. package/src/commands/plumbing-input.ts +87 -0
  529. package/src/commands/promisor-remote-reply.ts +276 -0
  530. package/src/commands/promisor-remote.ts +25 -2
  531. package/src/commands/pull-command.ts +720 -224
  532. package/src/commands/push-command.ts +440 -8
  533. package/src/commands/range-diff/index.ts +3 -0
  534. package/src/commands/range-diff/linear-assignment.ts +203 -0
  535. package/src/commands/range-diff/range-diff-command.ts +433 -0
  536. package/src/commands/range-diff/range-diff.ts +617 -0
  537. package/src/commands/read-tree-command.ts +74 -3
  538. package/src/commands/rebase-command.ts +647 -83
  539. package/src/commands/refs-command.ts +274 -0
  540. package/src/commands/remerge-diff.ts +241 -0
  541. package/src/commands/remote-command.ts +98 -10
  542. package/src/commands/remote-object-info-command.ts +109 -0
  543. package/src/commands/remote-show-command.ts +836 -0
  544. package/src/commands/remote-transport.ts +116 -1
  545. package/src/commands/repack-command.ts +383 -0
  546. package/src/commands/replace-command.ts +816 -0
  547. package/src/commands/replay-command.ts +674 -0
  548. package/src/commands/repo-command.ts +967 -0
  549. package/src/commands/request-pull-command.ts +356 -0
  550. package/src/commands/rerere-command.ts +179 -0
  551. package/src/commands/rerere.ts +925 -0
  552. package/src/commands/reset-command.ts +78 -3
  553. package/src/commands/restore-command.ts +15 -0
  554. package/src/commands/rev-filter/commit-grep.ts +7 -2
  555. package/src/commands/rev-list-command.ts +196 -11
  556. package/src/commands/rev-parse-command.ts +62 -4
  557. package/src/commands/revert-command.ts +62 -2
  558. package/src/commands/revision-range.ts +10 -3
  559. package/src/commands/revision-resolver.ts +44 -3
  560. package/src/commands/sequencer-pick.ts +370 -29
  561. package/src/commands/sequencer-support.ts +164 -2
  562. package/src/commands/serve-repository.ts +65 -0
  563. package/src/commands/session-id.ts +31 -0
  564. package/src/commands/shortlog-command.ts +354 -0
  565. package/src/commands/shortlog.ts +361 -0
  566. package/src/commands/show-branch-command.ts +981 -0
  567. package/src/commands/show-command.ts +3 -2
  568. package/src/commands/show-ref-command.ts +439 -0
  569. package/src/commands/signature-check.ts +37 -5
  570. package/src/commands/signing.ts +122 -16
  571. package/src/commands/stash-apply-command.ts +3 -0
  572. package/src/commands/stash-export-command.ts +397 -0
  573. package/src/commands/status-command.ts +158 -31
  574. package/src/commands/status-format.ts +1 -1
  575. package/src/commands/stripspace-command.ts +118 -0
  576. package/src/commands/submodule-add-command.ts +22 -1
  577. package/src/commands/submodule-auth.ts +61 -6
  578. package/src/commands/submodule-commands.ts +333 -5
  579. package/src/commands/submodule-fetch.ts +789 -0
  580. package/src/commands/submodule-model.ts +9 -1
  581. package/src/commands/submodule-unpack.ts +265 -0
  582. package/src/commands/submodule-update-command.ts +68 -5
  583. package/src/commands/subtree-shift.ts +215 -0
  584. package/src/commands/switch-command.ts +9 -0
  585. package/src/commands/textconv-cache.ts +143 -0
  586. package/src/commands/tree-restore.ts +20 -1
  587. package/src/commands/unpack-objects-command.ts +235 -0
  588. package/src/commands/update-index-command.ts +1016 -0
  589. package/src/commands/uri-protocols.ts +13 -0
  590. package/src/commands/url-parse-command.ts +67 -0
  591. package/src/commands/var-command.ts +219 -0
  592. package/src/commands/worktree-overwrite-checks.ts +5 -0
  593. package/src/errors/command-errors.ts +80 -0
  594. package/src/git-command.ts +218 -2
  595. package/src/git.ts +1033 -80
  596. package/src/guarded-transport-command.ts +176 -0
  597. package/src/index.ts +1 -0
  598. package/src/rename/detect-renames.ts +42 -8
  599. package/src/rename/diffcore-break.ts +166 -0
  600. package/src/rename/index.ts +1 -0
  601. package/src/results/blame-format.ts +268 -43
  602. package/src/results/cherry-pick-result.ts +6 -0
  603. package/src/results/clone-result.ts +6 -0
  604. package/src/results/diff-dirstat.ts +117 -0
  605. package/src/results/diff-entry.ts +24 -0
  606. package/src/results/diff-formatter.ts +8 -4
  607. package/src/results/diff-output.ts +239 -8
  608. package/src/results/diff-pickaxe.ts +1 -1
  609. package/src/results/fetch-result.ts +24 -1
  610. package/src/results/index.ts +2 -0
  611. package/src/results/init-result.ts +10 -1
  612. package/src/results/line-range-hunks.ts +126 -0
  613. package/src/results/merge-result.ts +14 -0
  614. package/src/results/pull-result.ts +7 -0
  615. package/src/results/push-result.ts +10 -0
  616. package/src/results/rebase-result.ts +7 -0
  617. package/src/results/revert-result.ts +6 -0
  618. package/src/results/stash-result.ts +6 -0
  619. package/src/results/status-result.ts +2 -2
  620. package/src/transport-command.ts +216 -4
  621. package/dist/fsck-DLRpbwTj.js +0 -13405
  622. package/dist/results-TB2IJ64h.js +0 -4700
@@ -1,25 +1,44 @@
1
1
  import {
2
+ compareRefNames,
2
3
  type FilesApi,
3
4
  historyWithoutLazyFetch,
4
5
  isSymbolicRef,
6
+ isValidRefName,
5
7
  type ObjectId,
6
8
  parseObjectFilter,
7
9
  } from "@statewalker/vcs-core";
8
- import { computeAlternatePath, HostPaths, hostRootOf } from "@statewalker/vcs-store-files";
9
10
  import {
11
+ CONFIG_REGEX_NONE,
12
+ computeAlternatePath,
13
+ GitWorkingCopyConfig,
14
+ HostPaths,
15
+ hostRootOf,
16
+ parseConfigKey,
17
+ setConfigMultivarText,
18
+ } from "@statewalker/vcs-store-files";
19
+ import {
20
+ bundleUriLines,
10
21
  createRepositoryFacade,
11
22
  createTransportRefStore,
12
23
  FetchCheckError,
13
24
  fetchFromConnection,
25
+ mapRefs,
26
+ missingSources,
14
27
  type RefspecResolver,
28
+ type RemoteRef,
29
+ refPrefixes,
30
+ ShallowRemoteRejectedError,
15
31
  type FetchOptions as TransportFetchOptions,
32
+ type UploadPackConnection,
16
33
  } from "@statewalker/vcs-transport";
34
+ import { parseGitBool } from "@statewalker/vcs-utils";
17
35
  import { parseGitInt } from "@statewalker/vcs-utils/encoding";
18
36
  import type { ObjectFormat } from "@statewalker/vcs-utils/hash";
19
37
  import type { OpenedRepository, WorkingCopy, Worktree } from "@statewalker/vcs-working-tree";
20
38
  import {
21
39
  CloneCheckoutError,
22
40
  CloneDestinationError,
41
+ GitApiError,
23
42
  InvalidArgumentError,
24
43
  InvalidRemoteError,
25
44
  RefNotFoundError,
@@ -29,6 +48,13 @@ import { RemoteConfigStore } from "../remote-config/index.js";
29
48
  import type { CloneResult } from "../results/clone-result.js";
30
49
  import type { FetchResult, TrackingRefUpdate } from "../results/fetch-result.js";
31
50
  import { TransportCommand } from "../transport-command.js";
51
+ import {
52
+ BundleList,
53
+ BundlePrerequisitesError,
54
+ fetchBundleList,
55
+ fetchBundleUri,
56
+ parseBundleListLine,
57
+ } from "./bundle/index.js";
32
58
  import { coreBool, worktreeModeTrust } from "./core-config.js";
33
59
  import { defaultInitialBranch } from "./default-branch.js";
34
60
  import { TagOption, toTagMode, toTrackingRefUpdate } from "./fetch-command.js";
@@ -37,12 +63,17 @@ import { runPostCheckoutHook } from "./git-hooks.js";
37
63
  import { hostEnvironmentOf } from "./git-ident.js";
38
64
  import { copyLocalObjects } from "./local-clone.js";
39
65
  import { promisorOf } from "./promisor-remote.js";
66
+ import { promisorRemoteReplyOf } from "./promisor-remote-reply.js";
40
67
  import { reflogMessages } from "./reflog-messages.js";
41
68
  import { isValidRemoteName } from "./remote-command.js";
42
69
  import { withRemoteUploadPack } from "./remote-transport.js";
70
+ import { clientSessionIdOf } from "./session-id.js";
43
71
  import { SparseCheckoutCommand } from "./sparse-checkout-command.js";
44
72
  import { SparseUnpack } from "./sparse-checkout-support.js";
73
+ import { SubmoduleCommandError, type SubmoduleCommandResult } from "./submodule-commands.js";
74
+ import { SubmoduleUpdateCommand } from "./submodule-update-command.js";
45
75
  import { checkoutFreshTree } from "./tree-restore.js";
76
+ import { uriProtocolsOption } from "./uri-protocols.js";
46
77
  import { worktreePathRules } from "./worktree-path-rules.js";
47
78
  import { repositoryPlaceOf, worktreeAdminWorkingCopy } from "./worktree-support.js";
48
79
 
@@ -57,6 +88,11 @@ const CLONE_SETTINGS = [
57
88
  "noCheckout",
58
89
  "sparse",
59
90
  "remoteName",
91
+ "remoteExplicit",
92
+ "revision",
93
+ "rejectShallow",
94
+ "serverOptions",
95
+ "compatibility",
60
96
  "cloneAllBranches",
61
97
  "mirror",
62
98
  "singleBranch",
@@ -69,13 +105,21 @@ const CLONE_SETTINGS = [
69
105
  "local",
70
106
  "dissociate",
71
107
  "references",
108
+ "recurseSubmodules",
109
+ "shallowSubmodules",
110
+ "alsoFilterSubmodules",
111
+ "remoteSubmodules",
72
112
  "credentials",
73
113
  "timeout",
74
114
  "headers",
75
115
  "gzipRequests",
116
+ "credentialHelper",
117
+ "warningCallback",
76
118
  "progressCallback",
77
119
  "progressMessageCallback",
120
+ "progress",
78
121
  "transportRegistry",
122
+ "bundles",
79
123
  "useReplaceRefsOverride",
80
124
  "reflogActionOverride",
81
125
  ];
@@ -159,6 +203,19 @@ export class CloneCommand extends TransportCommand<CloneResult> {
159
203
  private noCheckout = false;
160
204
  private sparse = false;
161
205
  private remoteName = "origin";
206
+ /** `-o`/`--origin` given: `clone.defaultRemoteName` is not read */
207
+ private remoteExplicit = false;
208
+ /** `-c`/`--config` entries (`key=value`, or `key` for true) */
209
+ private configEntries: string[] = [];
210
+ /** `--revision` (git 2.49+) */
211
+ private revision?: string;
212
+ /** `--[no-]reject-shallow`; unset: `clone.rejectShallow` */
213
+ private rejectShallow?: boolean;
214
+ /** `--server-option` values */
215
+ private serverOptions: string[] = [];
216
+ /** The git version reproduced; default the hooks' */
217
+ private compatibility?: "2.43" | "2.56";
218
+ private bundleUri?: string;
162
219
  private cloneAllBranches = true;
163
220
  private mirror = false;
164
221
  private singleBranch?: boolean;
@@ -173,6 +230,12 @@ export class CloneCommand extends TransportCommand<CloneResult> {
173
230
  private dissociate = false;
174
231
  /** `--reference` (required) and `--reference-if-able` paths, in the order given */
175
232
  private references: { path: string; required: boolean }[] = [];
233
+ /** `--recurse-submodules[=<pathspec>]` values, in the order given */
234
+ private recurseSubmodules: string[] = [];
235
+ private shallowSubmodules = false;
236
+ /** `--[no-]also-filter-submodules`; unset: `clone.filterSubmodules` */
237
+ private alsoFilterSubmodules?: boolean;
238
+ private remoteSubmodules = false;
176
239
 
177
240
  /**
178
241
  * The destination directory as `git clone <url> <directory>` names it, for messages only
@@ -225,6 +288,23 @@ export class CloneCommand extends TransportCommand<CloneResult> {
225
288
  return this.branch;
226
289
  }
227
290
 
291
+ /**
292
+ * `git clone --bundle-uri=<uri>`: before fetching from the remote, the bundle (or bundle
293
+ * list) at `uri` is downloaded and applied, its refs written under `refs/bundles/`
294
+ * (bundle-uri.c's `fetch_bundle_uri`), so the fetch asks only for what the bundles lack.
295
+ * `uri` is an `http(s)://` URL, a `file://` URL or a path (relative to the worktree top).
296
+ * A failure only warns (`CloneResult.messages`). A list using the `creationToken`
297
+ * heuristic is remembered as `fetch.bundleURI` (later fetches download its new bundles),
298
+ * with `fetch.bundleCreationToken`. Without it, `transfer.bundleURI=true` asks a protocol
299
+ * v2 server for its bundle list (the `bundle-uri` command). Refused with a shallow clone,
300
+ * as git.
301
+ */
302
+ setBundleUri(uri: string): this {
303
+ this.checkCallable();
304
+ this.bundleUri = uri;
305
+ return this;
306
+ }
307
+
228
308
  /**
229
309
  * Set shallow clone depth.
230
310
  *
@@ -325,15 +405,84 @@ export class CloneCommand extends TransportCommand<CloneResult> {
325
405
  }
326
406
 
327
407
  /**
328
- * Set the remote name.
408
+ * Set the remote name (`-o`/`--origin`).
329
409
  *
330
- * Default is "origin".
410
+ * Default `clone.defaultRemoteName` (the `-c` values included), else "origin".
331
411
  *
332
412
  * @param remoteName Remote name
333
413
  */
334
414
  setRemote(remoteName: string): this {
335
415
  this.checkCallable();
336
416
  this.remoteName = remoteName;
417
+ this.remoteExplicit = true;
418
+ return this;
419
+ }
420
+
421
+ /**
422
+ * `git clone -c <key>=<value>` (repeatable; `<key>` alone is `true`): each value is added
423
+ * to the new repository's config before anything is fetched (clone.c's `write_config`), so
424
+ * the fetch and the checkout use it: `url.<base>.insteadOf`, `protocol.*`,
425
+ * `fetch.fsckObjects`, `remote.<name>.fetch` (fetched with the clone's own refspec, which
426
+ * is added after it), `core.autocrlf`, `clone.defaultRemoteName`, `clone.rejectShallow`.
427
+ * A key git cannot parse fails the clone before any is written.
428
+ *
429
+ * @example
430
+ * ```ts
431
+ * await git.clone().setURI(url).setConfig(["core.autocrlf=true", "remote.origin.fetch=+refs/pull/*:refs/pull/*"]).call();
432
+ * ```
433
+ */
434
+ setConfig(entries: string[]): this {
435
+ this.checkCallable();
436
+ this.configEntries = [...entries];
437
+ return this;
438
+ }
439
+
440
+ /** Adds one `-c <key>=<value>` entry (see {@link setConfig}). */
441
+ addConfig(entry: string): this {
442
+ this.checkCallable();
443
+ this.configEntries.push(entry);
444
+ return this;
445
+ }
446
+
447
+ /**
448
+ * `git clone --revision=<rev>` (git 2.49+): fetch the history of one ref or commit id and
449
+ * detach HEAD at its commit (a tag peeled); no ref is written for it, no
450
+ * `remote.<name>.fetch` is configured and no tag is followed. A ref name is looked up as
451
+ * `git fetch` looks up a refspec's source; a commit id must be complete. Refused with
452
+ * `--branch` and `--mirror`, and as an unknown option under 2.43 compatibility.
453
+ */
454
+ setRevision(revision: string): this {
455
+ this.checkCallable();
456
+ this.revision = revision;
457
+ return this;
458
+ }
459
+
460
+ /**
461
+ * `git clone --[no-]reject-shallow`: refuse a shallow source (local or not) with git's
462
+ * "source repository is shallow, reject to clone."; unset, `clone.rejectShallow` decides.
463
+ */
464
+ setRejectShallow(reject: boolean): this {
465
+ this.checkCallable();
466
+ this.rejectShallow = reject;
467
+ return this;
468
+ }
469
+
470
+ /**
471
+ * `git clone --server-option=<option>` (repeatable): sent to the server with each protocol
472
+ * v2 request; they replace `remote.<name>.serverOption` (git 2.5x), which is used without
473
+ * them. A server speaking v0 fails the clone when options were given here (git's "server
474
+ * options require protocol version 2 or later"); configured ones are then dropped.
475
+ */
476
+ setServerOptions(options: string[]): this {
477
+ this.checkCallable();
478
+ this.serverOptions = [...options];
479
+ return this;
480
+ }
481
+
482
+ /** The git version reproduced (default the hook runner's, else 2.56). */
483
+ setCompatibility(compatibility: "2.43" | "2.56"): this {
484
+ this.checkCallable();
485
+ this.compatibility = compatibility;
337
486
  return this;
338
487
  }
339
488
 
@@ -584,6 +733,50 @@ export class CloneCommand extends TransportCommand<CloneResult> {
584
733
  * @returns Clone result
585
734
  * @throws InvalidRemoteError if URI is not specified
586
735
  */
736
+ /**
737
+ * `--recurse-submodules[=<pathspec>]` (`--recursive`): `true` is `.` (every submodule), a
738
+ * list the pathspecs given (each written as a `submodule.active` value, sorted, duplicates
739
+ * dropped), `false` none (`--no-recurse-submodules`). After the checkout the submodules
740
+ * are cloned and checked out as `git submodule update --init --require-init --recursive`
741
+ * does (see `SubmoduleUpdateCommand`), its output in {@link CloneResult.submodules}.
742
+ * As in git, submodules are cloned with `GIT_PROTOCOL_FROM_USER=0`: a local URL needs
743
+ * `protocol.file.allow=always`. Credentials and headers reach a submodule's URL only as
744
+ * `SubmoduleUpdateCommand.setCredentials` allows (the clone's own origin).
745
+ */
746
+ setRecurseSubmodules(recurse: boolean | string[]): this {
747
+ this.checkCallable();
748
+ this.recurseSubmodules = recurse === true ? ["."] : recurse === false ? [] : [...recurse];
749
+ return this;
750
+ }
751
+
752
+ /** `--shallow-submodules`: the submodules are cloned with a depth of 1. */
753
+ setShallowSubmodules(shallow: boolean): this {
754
+ this.checkCallable();
755
+ this.shallowSubmodules = shallow;
756
+ return this;
757
+ }
758
+
759
+ /**
760
+ * `--[no-]also-filter-submodules`: the submodules are cloned with this clone's filter
761
+ * ({@link setFilter}); unset, `clone.filterSubmodules` decides. Given true, it needs a
762
+ * filter and {@link setRecurseSubmodules}.
763
+ */
764
+ setAlsoFilterSubmodules(filter: boolean): this {
765
+ this.checkCallable();
766
+ this.alsoFilterSubmodules = filter;
767
+ return this;
768
+ }
769
+
770
+ /**
771
+ * `--remote-submodules`: each submodule is checked out at its remote-tracking branch
772
+ * (`submodule update --remote --no-fetch`).
773
+ */
774
+ setRemoteSubmodules(remote: boolean): this {
775
+ this.checkCallable();
776
+ this.remoteSubmodules = remote;
777
+ return this;
778
+ }
779
+
587
780
  async call(): Promise<CloneResult> {
588
781
  this.checkCallable();
589
782
  this.setCallable(false);
@@ -649,11 +842,59 @@ export class CloneCommand extends TransportCommand<CloneResult> {
649
842
  if (!this.uri) {
650
843
  throw new InvalidRemoteError("", "URI must be specified for clone");
651
844
  }
652
- if (!isValidRemoteName(this.remoteName)) {
653
- throw new InvalidArgumentError(
654
- "remote",
655
- this.remoteName,
656
- `'${this.remoteName}' is not a valid remote name`,
845
+ // cmd_clone: what --recurse-submodules adds to the -c values (option_config)
846
+ const submoduleConfig: string[] = [];
847
+ if (this.recurseSubmodules.length > 0) {
848
+ const patterns = [...new Set(this.recurseSubmodules)].sort((a, b) =>
849
+ a < b ? -1 : a > b ? 1 : 0,
850
+ );
851
+ for (const pattern of patterns) submoduleConfig.push(`submodule.active=${pattern}`);
852
+ const sticky = RemoteConfigStore.from(this.workingCopy).value(
853
+ "submodule.stickyRecursiveClone",
854
+ );
855
+ if (sticky !== undefined && parseGitBool(sticky) === true) {
856
+ submoduleConfig.push("submodule.recurse=true");
857
+ }
858
+ const required = this.references.some((r) => r.required);
859
+ const optional = this.references.some((r) => !r.required);
860
+ if (required && optional) {
861
+ throw new GitApiError(
862
+ "fatal: clone --recursive is not compatible with both --reference and --reference-if-able",
863
+ );
864
+ }
865
+ if (required || optional) {
866
+ submoduleConfig.push(
867
+ "submodule.alternateLocation=superproject",
868
+ `submodule.alternateErrorStrategy=${required ? "die" : "info"}`,
869
+ );
870
+ }
871
+ }
872
+ if (this.alsoFilterSubmodules === true && this.filterSpec === undefined) {
873
+ throw new GitApiError("fatal: the option '--also-filter-submodules' requires '--filter'");
874
+ }
875
+ if (this.alsoFilterSubmodules === true && this.recurseSubmodules.length === 0) {
876
+ throw new GitApiError(
877
+ "fatal: the option '--also-filter-submodules' requires '--recurse-submodules'",
878
+ );
879
+ }
880
+ const compatibility = this.compatibility ?? this.hooks.compatibility;
881
+ // parse_options: --revision is unknown to 2.43
882
+ if (this.revision !== undefined && compatibility === "2.43") {
883
+ throw new GitApiError(`error: unknown option \`revision=${this.revision}'`, {
884
+ exitCode: 129,
885
+ });
886
+ }
887
+
888
+ if (
889
+ this.bundleUri !== undefined &&
890
+ (this.depth !== undefined ||
891
+ this.shallowSince !== undefined ||
892
+ this.shallowExcludes.length > 0)
893
+ ) {
894
+ throw new GitApiError(
895
+ compatibility === "2.43"
896
+ ? "fatal: --bundle-uri is incompatible with --depth, --shallow-since, and --shallow-exclude"
897
+ : "fatal: options '--bundle-uri' and '--depth/--shallow-since/--shallow-exclude' cannot be used together",
657
898
  );
658
899
  }
659
900
 
@@ -671,19 +912,78 @@ export class CloneCommand extends TransportCommand<CloneResult> {
671
912
  ?.openRepository?.(uri, { checkOwnership: false, commandLineConfig: false })
672
913
  .then((opened) => opened !== undefined)
673
914
  .catch(() => false);
915
+ // get_repo_path: then a regular file, `<path>.bundle` first (a bundle: the transport reads
916
+ // it there, remote.<name>.url keeps the path as given)
917
+ let bundleFile: string | undefined;
918
+ const givenBundle = this.hasGivenBundle(uri);
919
+ if (givenBundle) {
920
+ // a bundle given as bytes (addBundle): its URL as given
921
+ bundleFile = uri;
922
+ } else if (!isRepositoryPath) {
923
+ for (const suffix of [".bundle", ""]) {
924
+ const bytes = await worktree?.readLocalFile?.(`${uri}${suffix}`).catch(() => undefined);
925
+ if (bytes) {
926
+ bundleFile = absolutePathOf(worktree, `${uri}${suffix}`);
927
+ break;
928
+ }
929
+ }
930
+ }
674
931
  let repo: string;
675
- if (isRepositoryPath) repo = absolutePathOf(worktree, uri);
932
+ if (givenBundle) repo = uri;
933
+ else if (isRepositoryPath || bundleFile !== undefined) repo = absolutePathOf(worktree, uri);
676
934
  else if (uri.includes(":")) repo = uri;
677
935
  else throw new TransportError(`fatal: repository '${uri}' does not exist`);
936
+ // clone.c: a destination that exists and is not empty is refused before anything is
937
+ // written; here the destination is the working copy, empty once `git init` made it
938
+ await this.refuseNonEmptyDestination();
939
+ // write_config: the -c values, after init_db and before anything reads the config (the
940
+ // remote's name, url.*.insteadOf, protocol.*, the fetch and the checkout)
941
+ await this.writeCommandLineConfig(submoduleConfig);
942
+ const store = RemoteConfigStore.from(this.workingCopy);
943
+ // git_clone_config re-read: clone.defaultRemoteName, then --origin over it
944
+ if (!this.remoteExplicit) this.remoteName = store.value("clone.defaultRemoteName") ?? "origin";
945
+ if (!isValidRemoteName(this.remoteName)) {
946
+ throw new InvalidArgumentError(
947
+ "remote",
948
+ this.remoteName,
949
+ `'${this.remoteName}' is not a valid remote name`,
950
+ );
951
+ }
952
+ const rejectShallowConfig = store.value("clone.rejectShallow");
953
+ const rejectShallow =
954
+ this.rejectShallow ??
955
+ (rejectShallowConfig === undefined ? false : (parseGitBool(rejectShallowConfig) ?? false));
956
+ if (this.revision !== undefined) {
957
+ if (this.branch !== undefined) {
958
+ throw new GitApiError("fatal: options '--revision' and '--branch' cannot be used together");
959
+ }
960
+ if (this.mirror) {
961
+ throw new GitApiError("fatal: options '--revision' and '--mirror' cannot be used together");
962
+ }
963
+ if (!isRevisionRefspec(this.revision)) {
964
+ throw new GitApiError(`fatal: invalid refspec '${this.revision}'`);
965
+ }
966
+ }
967
+ // transport.c's handshake: --server-option, else remote.<name>.serverOption (2.5x), an
968
+ // empty value clearing the list
969
+ let serverOptions = this.serverOptions;
970
+ if (serverOptions.length === 0 && compatibility !== "2.43") {
971
+ serverOptions = [];
972
+ for (const value of store.values(`remote.${this.remoteName}.serverOption`)) {
973
+ if (value === "") serverOptions.length = 0;
974
+ else serverOptions.push(value);
975
+ }
976
+ }
977
+
678
978
  this.repoUrl = repo;
679
- const sourceUrl = RemoteConfigStore.from(this.workingCopy).aliasUrl(repo) ?? repo;
680
- const remote = await this.prepareRemote(sourceUrl);
979
+ const sourceUrl = store.aliasUrl(repo) ?? repo;
980
+ const remote = await this.prepareRemote(bundleFile ?? sourceUrl);
981
+ if (remote.kind === "bundle" && remote.remote.bundle.header.filter !== undefined) {
982
+ throw new TransportError("fatal: cannot clone from filtered bundle");
983
+ }
681
984
  const localRemote: OpenedRepository | undefined =
682
985
  remote.kind === "local" ? remote.repository : undefined;
683
-
684
- // clone.c: a destination that exists and is not empty is refused before anything is
685
- // written; here the destination is the working copy, empty once `git init` made it
686
- await this.refuseNonEmptyDestination(localRemote);
986
+ if (localRemote) await this.refuseSourceAsDestination(localRemote);
687
987
 
688
988
  // clone.c's is_local: a local repository path (remote.<name>.url as rewritten; never a
689
989
  // URL, file:// included), unless --no-local or the source is shallow
@@ -713,6 +1013,9 @@ export class CloneCommand extends TransportCommand<CloneResult> {
713
1013
  localWarnings.push("warning: --filter is ignored in local clones; use file:// instead.\n");
714
1014
  }
715
1015
  if (await sourceIsShallow(localRemote, worktree?.getFiles?.())) {
1016
+ if (rejectShallow) {
1017
+ throw new TransportError("fatal: source repository is shallow, reject to clone.");
1018
+ }
716
1019
  if (this.local === true) {
717
1020
  localWarnings.push("warning: source repository is shallow, ignoring --local\n");
718
1021
  }
@@ -747,6 +1050,7 @@ export class CloneCommand extends TransportCommand<CloneResult> {
747
1050
  this.bare ? `refs/heads/${branch}` : `refs/remotes/${this.remoteName}/${branch}`;
748
1051
  // git: a shallow clone is a single-branch clone (of --branch, else the remote HEAD's branch)
749
1052
  const singleBranch =
1053
+ this.revision === undefined &&
750
1054
  !this.mirror &&
751
1055
  (this.singleBranch ??
752
1056
  (branchesToClone.length > 0 ||
@@ -812,11 +1116,58 @@ export class CloneCommand extends TransportCommand<CloneResult> {
812
1116
  } else {
813
1117
  refspecs = [`+refs/heads/*:${tracking("*")}`];
814
1118
  }
815
- // git clone takes every tag, unless one branch is cloned (then tags follow) or --no-tags
1119
+ // --revision: the revision alone, as a refspec without destination (no ref written)
1120
+ let revisionRef: { name: string; oid: string } | undefined;
1121
+ if (this.revision !== undefined) {
1122
+ const rev = this.revision;
1123
+ refspecs = {
1124
+ prefixes: FULL_HEX_ID.test(rev) ? [] : refPrefixes([rev]),
1125
+ resolve: (remoteRefs) => {
1126
+ const found = mapRefs(remoteRefs, [rev])[0];
1127
+ if (!found) {
1128
+ throw new RefNotFoundError(
1129
+ rev,
1130
+ `fatal: Remote revision ${rev} not found in upstream ${this.remoteName}`,
1131
+ );
1132
+ }
1133
+ revisionRef = { name: found.remoteRef, oid: found.oid };
1134
+ return [rev];
1135
+ },
1136
+ };
1137
+ }
1138
+ // remote_get_early: the configured remote.<name>.fetch refspecs (the -c values and the
1139
+ // command line's included) come first; a single-branch clone maps them over its one ref
1140
+ const configuredFetch = store.values(`remote.${this.remoteName}.fetch`);
1141
+ if (configuredFetch.length > 0) {
1142
+ const selected =
1143
+ singleBranch && !this.mirror
1144
+ ? (remoteRefs: readonly RemoteRef[]) => {
1145
+ if (branchToClone !== undefined) {
1146
+ return (
1147
+ remoteRefs.find((r) => r.name === `refs/heads/${branchToClone}` && r.oid) ??
1148
+ remoteRefs.find((r) => r.name === `refs/tags/${branchToClone}` && r.oid)
1149
+ );
1150
+ }
1151
+ const head = remoteRefs.find((r) => r.name === "HEAD")?.symref;
1152
+ return head ? remoteRefs.find((r) => r.name === head && r.oid) : undefined;
1153
+ }
1154
+ : undefined;
1155
+ // (tags: "all" below maps git's TAG_REFSPEC after them)
1156
+ const allTags =
1157
+ this.revision === undefined &&
1158
+ this.tagOption === TagOption.AUTO_FOLLOW &&
1159
+ !singleBranch &&
1160
+ !this.mirror;
1161
+ refspecs = withConfiguredRefspecs(refspecs, configuredFetch, selected, allTags);
1162
+ }
1163
+ // git clone takes every tag, unless one branch is cloned (then tags follow) or --no-tags;
1164
+ // none with --revision
816
1165
  const tags =
817
- this.tagOption === TagOption.AUTO_FOLLOW && !singleBranch && !this.mirror
818
- ? "all"
819
- : toTagMode(this.tagOption);
1166
+ this.revision !== undefined
1167
+ ? "none"
1168
+ : this.tagOption === TagOption.AUTO_FOLLOW && !singleBranch && !this.mirror
1169
+ ? "all"
1170
+ : toTagMode(this.tagOption);
820
1171
 
821
1172
  // fetch.fsckObjects / transfer.fsckObjects (the clone's own config, `-c` settings included)
822
1173
  const environment = hostEnvironmentOf(this.workingCopy);
@@ -832,7 +1183,11 @@ export class CloneCommand extends TransportCommand<CloneResult> {
832
1183
  baseDir: await this.hostWorkingDir(),
833
1184
  });
834
1185
 
1186
+ const sessionId = clientSessionIdOf(this.workingCopy);
835
1187
  const fetchOptions: TransportFetchOptions = {
1188
+ ...(sessionId !== undefined ? { sessionId } : {}),
1189
+ // fetch.uriProtocols: the packs a v2 server offloads to packfile URIs
1190
+ ...uriProtocolsOption(RemoteConfigStore.from(this.workingCopy).value("fetch.uriprotocols")),
836
1191
  url: sourceUrl,
837
1192
  auth: this.credentials,
838
1193
  headers: this.headers,
@@ -846,6 +1201,8 @@ export class CloneCommand extends TransportCommand<CloneResult> {
846
1201
  deepenSince: shallowSince,
847
1202
  deepenNot: shallowExcludes.length > 0 ? shallowExcludes : undefined,
848
1203
  onProgress: this.progressMessageCallback,
1204
+ // index-pack's "Receiving objects" and "Resolving deltas"
1205
+ ...(this.progress ? { progress: this.progress } : {}),
849
1206
  // git's write_remote_refs: one initial transaction (packed-refs), no reflog; the
850
1207
  // followed tags of a single-branch clone each on their own (write_followtags)
851
1208
  skipReflog: true,
@@ -855,10 +1212,14 @@ export class CloneCommand extends TransportCommand<CloneResult> {
855
1212
  // clone.c sets TRANS_OPT_KEEP: the pack is kept whatever its size
856
1213
  keepPack: true,
857
1214
  // --filter (TRANS_OPT_LIST_OBJECTS_FILTER, TRANS_OPT_FROM_PROMISOR); not in a local clone
858
- ...(this.filterSpec !== undefined && !isLocal
859
- ? { filter: this.filterSpec, onWarning: (line: string) => messages.push(`${line}\n`) }
860
- : {}),
1215
+ ...(this.filterSpec !== undefined && !isLocal ? { filter: this.filterSpec } : {}),
1216
+ // the transport's warnings (a filter the server ignores, the dumb walker's alternates)
1217
+ onWarning: (line: string) => messages.push(`${line}\n`),
1218
+ // the server's promisor-remote capability (promisor.acceptFromServer, storeFields)
1219
+ promisorRemote: promisorRemoteReplyOf(this.workingCopy, (line) => messages.push(`${line}\n`)),
861
1220
  ...(fsck ? { fsckObjects: fsck } : {}),
1221
+ ...(serverOptions.length > 0 ? { serverOptions } : {}),
1222
+ ...(rejectShallow ? { rejectShallow: true } : {}),
862
1223
  // git's clone takes the remote's hash: a destination of another one is reopened with it
863
1224
  // before anything is fetched (cloneReopenedAs)
864
1225
  onRemoteObjectFormat: (format) => {
@@ -884,9 +1245,31 @@ export class CloneCommand extends TransportCommand<CloneResult> {
884
1245
  };
885
1246
  // fetch_if_missing = 0 while the fetch runs: its walks read through the history's view
886
1247
  // without lazy fetch (the facade above)
887
- const result = await withRemoteUploadPack(remote, sessionOptions, (connection) =>
888
- fetchFromConnection(connection, fetchOptions),
889
- ).catch((error: unknown) => {
1248
+ const result = await withRemoteUploadPack(remote, sessionOptions, (connection) => {
1249
+ // transport.c's die_if_server_options: command-line options need v2
1250
+ if (connection.version !== 2 && this.serverOptions.length > 0) {
1251
+ throw new TransportError(
1252
+ "hint: see protocol.version in 'git help config' for more details\n" +
1253
+ "fatal: server options require protocol version 2 or later",
1254
+ );
1255
+ }
1256
+ // the bundles come after the ref listing and before anything is fetched (or a local
1257
+ // clone's objects copied)
1258
+ const copy = fetchOptions.beforeFetch;
1259
+ return fetchFromConnection(connection, {
1260
+ ...fetchOptions,
1261
+ beforeFetch: async (remoteRefs, refMap) => {
1262
+ await this.cloneBundles(connection, sourceUrl, compatibility, messages);
1263
+ return copy?.(remoteRefs, refMap);
1264
+ },
1265
+ });
1266
+ }).catch((error: unknown) => {
1267
+ if (error instanceof ShallowRemoteRejectedError) {
1268
+ throw new TransportError(`fatal: ${error.message}`);
1269
+ }
1270
+ if (error instanceof BundlePrerequisitesError) {
1271
+ throw new TransportError(`${error.lines}fatal: remote transport reported error`);
1272
+ }
890
1273
  if (!(error instanceof FetchCheckError)) throw error;
891
1274
  // what was received is refused before any ref is written: index-pack died, or
892
1275
  // update_remote_refs' check of the refs found history missing (git then removes the
@@ -910,7 +1293,24 @@ export class CloneCommand extends TransportCommand<CloneResult> {
910
1293
  // Two forms, deliberately kept apart: the advertised form goes out on
911
1294
  // FetchResult unchanged (it is what the remote said), while the ref work
912
1295
  // below and CloneResult use the bare branch name.
913
- const advertisedDefaultBranch = result.defaultBranch;
1296
+ // guess_remote_head: without HEAD's symref (a bundle, a dumb server), the branch at HEAD's
1297
+ // commit among the refs cloned: init.defaultBranch's (else master), then master, then the
1298
+ // first in the remote's order
1299
+ let advertisedDefaultBranch = result.defaultBranch;
1300
+ const remoteHeadRef = result.remoteRefs.find((r) => r.name === "HEAD");
1301
+ if (advertisedDefaultBranch === undefined && remoteHeadRef?.oid !== undefined) {
1302
+ const cloned = new Set(result.fetched.map((f) => f.remoteRef));
1303
+ const branches = result.remoteRefs.filter(
1304
+ (r) =>
1305
+ r.name.startsWith("refs/heads/") && cloned.has(r.name) && r.oid === remoteHeadRef.oid,
1306
+ );
1307
+ const preferred = (await defaultInitialBranch(hostEnvironmentOf(this._workingCopy))).name;
1308
+ advertisedDefaultBranch = (
1309
+ branches.find((r) => r.name === `refs/heads/${preferred}`) ??
1310
+ branches.find((r) => r.name === "refs/heads/master") ??
1311
+ branches[0]
1312
+ )?.name;
1313
+ }
914
1314
  let defaultBranch = branchToClone ?? toBranchName(advertisedDefaultBranch);
915
1315
  let headCommit: ObjectId | undefined;
916
1316
  let checkedOutBranch: string | undefined;
@@ -925,17 +1325,31 @@ export class CloneCommand extends TransportCommand<CloneResult> {
925
1325
 
926
1326
  // git's update_remote_refs (before update_head): refs/remotes/<name>/HEAD names the tracking ref of the
927
1327
  // remote's default branch, when the clone took that branch
928
- const remoteHead = advertisedDefaultBranch?.startsWith("refs/heads/")
929
- ? toBranchName(advertisedDefaultBranch)
1328
+ const remoteHead =
1329
+ this.revision === undefined && advertisedDefaultBranch?.startsWith("refs/heads/")
1330
+ ? toBranchName(advertisedDefaultBranch)
1331
+ : undefined;
1332
+ // (guess_remote_head over the mapped refs: the first mapping of the remote HEAD's branch,
1333
+ // configured refspecs before the clone's own, whose peer ref HEAD then names)
1334
+ const headMapping = remoteHead
1335
+ ? result.fetched.find((f) => f.remoteRef === advertisedDefaultBranch)
930
1336
  : undefined;
931
- if (!this.bare && remoteHead) {
932
- const target = `refs/remotes/${this.remoteName}/${remoteHead}`;
1337
+ if (!this.bare && remoteHead && headMapping?.localRef) {
1338
+ const target = headMapping.localRef;
933
1339
  if ((await this.refsStore.resolve(target))?.objectId) {
934
1340
  await this.refsStore.setSymbolic(`refs/remotes/${this.remoteName}/HEAD`, target, cloneLog);
935
1341
  }
936
1342
  }
937
1343
 
938
- if (detachedTag) {
1344
+ if (revisionRef) {
1345
+ // update_head with opts->detach: HEAD detached at the revision's commit (a tag peeled,
1346
+ // lookup_commit_or_die), bare or not
1347
+ defaultBranch = toBranchName(advertisedDefaultBranch);
1348
+ const id = await this.revisionCommit(revisionRef, messages);
1349
+ await this.refsStore.set("HEAD", id, cloneLog);
1350
+ headCommit = id;
1351
+ if (!this.bare && !this.noCheckout) checkoutId = id;
1352
+ } else if (detachedTag) {
939
1353
  // git clone --branch <tag>: a detached HEAD at the tag's commit
940
1354
  defaultBranch = toBranchName(advertisedDefaultBranch);
941
1355
  const tag = await this.refsStore.resolve(detachedTag);
@@ -952,6 +1366,17 @@ export class CloneCommand extends TransportCommand<CloneResult> {
952
1366
  headCommit = id;
953
1367
  if (!this.bare && !this.noCheckout) checkoutId = id;
954
1368
  }
1369
+ } else if (
1370
+ defaultBranch === undefined &&
1371
+ remoteHeadRef?.oid !== undefined &&
1372
+ !result.isEmpty &&
1373
+ (await history.commits.has(remoteHeadRef.oid).catch(() => false))
1374
+ ) {
1375
+ // update_head's `else if (remote)`: a remote HEAD no branch matches (a bundle made from
1376
+ // `HEAD topic`) detaches HEAD at its commit
1377
+ await this.refsStore.set("HEAD", remoteHeadRef.oid, cloneLog);
1378
+ headCommit = remoteHeadRef.oid;
1379
+ if (!this.bare && !this.noCheckout) checkoutId = remoteHeadRef.oid;
955
1380
  } else if (defaultBranch && !this.bare) {
956
1381
  // The local branch starts at the tracking ref the clone just wrote
957
1382
  const localRef = `refs/heads/${defaultBranch}`;
@@ -984,6 +1409,7 @@ export class CloneCommand extends TransportCommand<CloneResult> {
984
1409
  remoteHead,
985
1410
  checkedOutBranch,
986
1411
  isEmpty: result.isEmpty,
1412
+ revision: this.revision !== undefined,
987
1413
  });
988
1414
 
989
1415
  // Build fetch result
@@ -1015,6 +1441,19 @@ export class CloneCommand extends TransportCommand<CloneResult> {
1015
1441
  ...(messages.length > 0 ? { messages } : {}),
1016
1442
  };
1017
1443
 
1444
+ // clone.c's checkout(): a HEAD that names no commit (a remote without HEAD, such as a
1445
+ // bundle without one) leaves nothing to check out
1446
+ if (
1447
+ checkoutId === undefined &&
1448
+ !this.bare &&
1449
+ !this.noCheckout &&
1450
+ !result.isEmpty &&
1451
+ headCommit === undefined
1452
+ ) {
1453
+ messages.push("warning: remote HEAD refers to nonexistent ref, unable to checkout\n");
1454
+ if (cloneResult.messages === undefined) cloneResult.messages = messages;
1455
+ }
1456
+
1018
1457
  // dissociate_from_references: before the checkout, the borrowed objects copied in
1019
1458
  // (a store without alternates has nothing to dissociate from)
1020
1459
  if (this.dissociate) await history.objects?.alternates?.dissociate?.();
@@ -1040,10 +1479,123 @@ export class CloneCommand extends TransportCommand<CloneResult> {
1040
1479
  false,
1041
1480
  );
1042
1481
  if (code !== 0) cloneResult.hookExitCode = code;
1482
+ // checkout(): the submodules, once the hook succeeded
1483
+ else if (this.recurseSubmodules.length > 0) {
1484
+ cloneResult.submodules = await this.updateSubmodules();
1485
+ }
1043
1486
  }
1044
1487
  return cloneResult;
1045
1488
  }
1046
1489
 
1490
+ /**
1491
+ * clone.c's `git submodule update --require-init --recursive [--depth=1] [--remote
1492
+ * --no-fetch] [--filter=<spec>] [--[no-]single-branch]` in the new repository: what it
1493
+ * printed and its exit status.
1494
+ */
1495
+ /**
1496
+ * clone.c's bundle step: `--bundle-uri` (`fetch_bundle_uri`, `fetch.bundleURI` stored for a
1497
+ * `creationToken` list), else, under `transfer.bundleURI`, the server's list
1498
+ * (`transport_get_remote_bundle_uri`, `fetch_bundle_list`); warnings into `messages`.
1499
+ */
1500
+ private async cloneBundles(
1501
+ connection: UploadPackConnection,
1502
+ remoteUrl: string,
1503
+ compatibility: "2.43" | "2.56",
1504
+ messages: string[],
1505
+ ): Promise<void> {
1506
+ const store = RemoteConfigStore.from(this.workingCopy);
1507
+ const message = (line: string) => messages.push(`${line}\n`);
1508
+ const worktree = repositoryPlaceOf(this.workingCopy);
1509
+ const host = this.bundleUriHost({
1510
+ remoteUrl,
1511
+ compatibility,
1512
+ message,
1513
+ setConfigValue: (key, value) => this.writeConfigValue(key, value, "add"),
1514
+ // odb_mkstemp's `<objects>/bundles/tmp_uri_XXXXXX`, as git's errors name the list
1515
+ tempFileName: () =>
1516
+ absolutePathOf(
1517
+ worktree,
1518
+ `${this.bare ? "" : ".git/"}objects/bundles/tmp_uri_${randomSuffix()}`,
1519
+ ),
1520
+ });
1521
+ if (this.bundleUri !== undefined) {
1522
+ const fetched = await fetchBundleUri(host, this.bundleUri);
1523
+ if (!fetched.ok) {
1524
+ message(`warning: failed to fetch objects from bundle URI '${this.bundleUri}'`);
1525
+ } else if (fetched.hasHeuristic) {
1526
+ await this.writeConfigValue("fetch.bundleuri", this.bundleUri, "add");
1527
+ }
1528
+ return;
1529
+ }
1530
+ // transport_get_remote_bundle_uri: only under transfer.bundleURI, only from a v2 server
1531
+ // advertising `bundle-uri`
1532
+ const enabled = store.value("transfer.bundleURI");
1533
+ if (enabled === undefined || parseGitBool(enabled) !== true) return;
1534
+ if (connection.version !== 2 || !connection.capabilities.has("bundle-uri")) return;
1535
+ const list = new BundleList(remoteUrl);
1536
+ const lines = await bundleUriLines(connection);
1537
+ // get_remote_bundle_uri: the first bad line is reported (its number counted from 2), the
1538
+ // rest read but not parsed
1539
+ let failed = false;
1540
+ lines.forEach((line, index) => {
1541
+ if (failed) return;
1542
+ const parseMessages: string[] = [];
1543
+ const error = parseBundleListLine(list, line, parseMessages);
1544
+ for (const m of parseMessages) message(m);
1545
+ if (error === undefined) return;
1546
+ if (error) message(error);
1547
+ message(`error: error on bundle-uri response line ${index + 2}: ${line}`);
1548
+ failed = true;
1549
+ });
1550
+ if (failed) message("error: could not retrieve server-advertised bundle-uri list");
1551
+ if (list.size === 0) return;
1552
+ if (!(await fetchBundleList(host, list))) {
1553
+ message("warning: failed to fetch advertised bundles");
1554
+ }
1555
+ }
1556
+
1557
+ private async updateSubmodules(): Promise<SubmoduleCommandResult> {
1558
+ const store = RemoteConfigStore.from(this.workingCopy);
1559
+ const configured = store.value("clone.filterSubmodules");
1560
+ const filterSubmodules =
1561
+ this.alsoFilterSubmodules ??
1562
+ (configured === undefined ? false : (parseGitBool(configured) ?? false));
1563
+ const update = new SubmoduleUpdateCommand(this.workingCopy)
1564
+ .setRequireInit(true)
1565
+ .setRecursive(true)
1566
+ .setCompatibility(this.compatibility ?? this.hooks.compatibility);
1567
+ update.shareHooksOf(this);
1568
+ if (this.shallowSubmodules) update.setDepth(1);
1569
+ if (this.remoteSubmodules) update.setRemote(true).setNoFetch(true);
1570
+ if (filterSubmodules && this.filterSpec !== undefined) update.setFilter(this.filterSpec);
1571
+ // option_single_branch, settled before (a deepening clone is a single-branch one, a
1572
+ // --revision clone none): always passed on, as --single-branch or --no-single-branch
1573
+ update.setSingleBranch(
1574
+ this.revision !== undefined
1575
+ ? false
1576
+ : (this.singleBranch ??
1577
+ (this.depth !== undefined ||
1578
+ this.shallowSince !== undefined ||
1579
+ this.shallowExcludes.length > 0)),
1580
+ );
1581
+ update.setTransports(this.getTransports());
1582
+ if (this.credentials) update.setCredentials(this.credentials);
1583
+ if (this.headers) update.setHeaders(this.headers);
1584
+ if (this.timeout !== undefined) update.setTimeout(this.timeout);
1585
+ if (this.credentialHelper) update.setCredentialHelper(this.credentialHelper);
1586
+ if (this.warningCallback) update.setWarningCallback(this.warningCallback);
1587
+ try {
1588
+ return await update.call();
1589
+ } catch (error) {
1590
+ if (!(error instanceof SubmoduleCommandError)) throw error;
1591
+ return {
1592
+ stdout: error.result.stdout,
1593
+ stderr: `${error.result.stderr}${error.message}\n`,
1594
+ exitCode: error.exitCode,
1595
+ };
1596
+ }
1597
+ }
1598
+
1047
1599
  /**
1048
1600
  * The alternates `git clone` writes before it fetches: each `--reference` (a required one
1049
1601
  * that is no usable repository fails the clone; an optional one is reported in the returned
@@ -1136,14 +1688,17 @@ export class CloneCommand extends TransportCommand<CloneResult> {
1136
1688
  * resolves to (`git clone . .`). The directory is named as the worktree's top is
1137
1689
  * ({@link setDirectory}, else its last component, `.` for the root).
1138
1690
  */
1139
- private async refuseNonEmptyDestination(source: OpenedRepository | undefined): Promise<void> {
1140
- const refuse = () => {
1141
- const root = repositoryPlaceOf(this._workingCopy)?.getRoot?.() ?? "";
1142
- const name = this.directory ?? (root.replace(/\/+$/, "").split("/").pop() || ".");
1143
- return new CloneDestinationError(
1144
- `fatal: destination path '${name}' already exists and is not an empty directory.`,
1145
- );
1146
- };
1691
+ /** git's "destination path ... already exists and is not an empty directory." */
1692
+ private destinationRefused(): CloneDestinationError {
1693
+ const root = repositoryPlaceOf(this._workingCopy)?.getRoot?.() ?? "";
1694
+ const name = this.directory ?? (root.replace(/\/+$/, "").split("/").pop() || ".");
1695
+ return new CloneDestinationError(
1696
+ `fatal: destination path '${name}' already exists and is not an empty directory.`,
1697
+ );
1698
+ }
1699
+
1700
+ private async refuseNonEmptyDestination(): Promise<void> {
1701
+ const refuse = () => this.destinationRefused();
1147
1702
  const history = this._workingCopy.history;
1148
1703
  for await (const ref of history.refs.list()) {
1149
1704
  if (!isSymbolicRef(ref)) throw refuse();
@@ -1168,17 +1723,122 @@ export class CloneCommand extends TransportCommand<CloneResult> {
1168
1723
  if (own && (entry.path === own || entry.path.startsWith(`${own}/`))) continue;
1169
1724
  throw refuse();
1170
1725
  }
1171
- if (source) {
1172
- const self = await worktree
1173
- .openRepository?.(".", { checkOwnership: false })
1174
- .catch(() => undefined);
1175
- if (self && (self.commonDir ?? self.gitDir) === (source.commonDir ?? source.gitDir)) {
1176
- throw refuse();
1177
- }
1178
- }
1179
1726
  }
1180
1727
  }
1181
1728
 
1729
+ /** A local source that is the destination itself is refused as a non-empty destination. */
1730
+ private async refuseSourceAsDestination(source: OpenedRepository): Promise<void> {
1731
+ const worktree = this.bare ? undefined : this.worktreeAccess;
1732
+ if (!worktree) return;
1733
+ const self = await worktree
1734
+ .openRepository?.(".", { checkOwnership: false })
1735
+ .catch(() => undefined);
1736
+ if (self && (self.commonDir ?? self.gitDir) === (source.commonDir ?? source.gitDir)) {
1737
+ throw this.destinationRefused();
1738
+ }
1739
+ }
1740
+
1741
+ /**
1742
+ * clone.c's `write_config`: each `-c` entry parsed as `git_config_parse_parameter` (split at
1743
+ * the first `=`, no `=` meaning `true`), its key canonical (`git_config_parse_key`), then
1744
+ * added to the new repository's config file (`CONFIG_REGEX_NONE`), saved before the fetch.
1745
+ * Every entry is checked before the first is written.
1746
+ */
1747
+ private async writeCommandLineConfig(extra: string[] = []): Promise<void> {
1748
+ const entries = [...this.configEntries, ...extra];
1749
+ if (entries.length === 0) return;
1750
+ const parsed: { key: string; value: string }[] = [];
1751
+ for (const entry of entries) {
1752
+ const eq = entry.indexOf("=");
1753
+ const rawKey = eq < 0 ? entry : entry.slice(0, eq);
1754
+ const die = (error: string) =>
1755
+ new GitApiError(`error: ${error}\nfatal: unable to write parameters to config file`);
1756
+ if (rawKey === "") throw die(`bogus config parameter: ${entry}`);
1757
+ const key = parseConfigKey(rawKey);
1758
+ if ("error" in key) throw die(key.error);
1759
+ parsed.push({ key: key.key, value: eq < 0 ? "true" : entry.slice(eq + 1) });
1760
+ }
1761
+ for (const { key, value } of parsed) await this.writeConfigValue(key, value, "add");
1762
+ }
1763
+
1764
+ /**
1765
+ * One config write as git's config writer places it (`repo_config_set_multivar`): through
1766
+ * `git config` (`ConfigCommand`) where the config is a file, so a value added to an existing
1767
+ * section goes at its end; pending edits are saved first and the config is read again
1768
+ * after. `add` is `CONFIG_REGEX_NONE`; `set-empty` replaces an empty value, else adds (the
1769
+ * `^$` pattern of `write_refspec_config`).
1770
+ */
1771
+ private async writeConfigValue(
1772
+ key: string,
1773
+ value: string,
1774
+ mode: "add" | "set-empty",
1775
+ ): Promise<void> {
1776
+ const store = RemoteConfigStore.from(this.workingCopy);
1777
+ const config = this.workingCopy.config;
1778
+ if (!(config instanceof GitWorkingCopyConfig)) {
1779
+ const values = store.localValues(key);
1780
+ const empty = values.indexOf("");
1781
+ if (mode === "set-empty" && empty >= 0) {
1782
+ store.setValues(
1783
+ key,
1784
+ values.map((v, i) => (i === empty ? value : (v ?? "true"))),
1785
+ );
1786
+ } else store.addValue(key, value);
1787
+ await store.save();
1788
+ return;
1789
+ }
1790
+ // config.c's writer over the file's text (as `git config` edits it), then read again
1791
+ await store.save();
1792
+ const files = config.configFiles;
1793
+ const path = config.filePath;
1794
+ const bytes = await files.read(path);
1795
+ const written = setConfigMultivarText(
1796
+ bytes === undefined ? undefined : new TextDecoder().decode(bytes),
1797
+ path,
1798
+ key,
1799
+ value,
1800
+ { valuePattern: mode === "add" ? CONFIG_REGEX_NONE : "^$" },
1801
+ );
1802
+ if (written.status !== 0 || written.text === undefined) {
1803
+ throw new GitApiError(written.stderr.join("\n") || `fatal: could not write ${key}`);
1804
+ }
1805
+ await files.write(path, new TextEncoder().encode(written.text));
1806
+ await config.load();
1807
+ }
1808
+
1809
+ /**
1810
+ * `--revision`'s commit: the fetched object, tags peeled (lookup_commit_or_die, its
1811
+ * "is not a commit!" warning added to `messages`); anything else dies as git
1812
+ * ("object <id> is a tree, not a commit", "could not parse <name>").
1813
+ */
1814
+ private async revisionCommit(
1815
+ revision: { name: string; oid: string },
1816
+ messages: string[],
1817
+ ): Promise<ObjectId> {
1818
+ const tags = this.tagsStore ?? this._workingCopy.history.tags;
1819
+ let id = revision.oid;
1820
+ for (let i = 0; i < 16; i++) {
1821
+ if (!(await tags.has(id))) break;
1822
+ const target = await tags.getTarget(id);
1823
+ if (!target) break;
1824
+ id = target;
1825
+ }
1826
+ if (!(await this.commits.load(id).catch(() => undefined))) {
1827
+ const type = (await this.trees.has(id).catch(() => false))
1828
+ ? "tree"
1829
+ : (await this.blobs.has(id).catch(() => false))
1830
+ ? "blob"
1831
+ : undefined;
1832
+ throw new GitApiError(
1833
+ `${type ? `error: object ${id} is a ${type}, not a commit\n` : ""}fatal: could not parse ${revision.name}`,
1834
+ );
1835
+ }
1836
+ if (id !== revision.oid) {
1837
+ messages.push(`warning: ${revision.name} ${revision.oid} is not a commit!\n`);
1838
+ }
1839
+ return id;
1840
+ }
1841
+
1182
1842
  /**
1183
1843
  * Writes the configuration `git clone` writes (clone.c): `remote.<name>.url`,
1184
1844
  * `remote.<name>.tagOpt` for `--no-tags` and `--mirror` (git 2.49+), the `remote.<name>.fetch` refspec of what was
@@ -1194,6 +1854,8 @@ export class CloneCommand extends TransportCommand<CloneResult> {
1194
1854
  remoteHead?: string;
1195
1855
  checkedOutBranch?: string;
1196
1856
  isEmpty?: boolean;
1857
+ /** --revision: no fetch refspec (write_refspec_config is skipped) */
1858
+ revision?: boolean;
1197
1859
  }): Promise<void> {
1198
1860
  const store = RemoteConfigStore.from(this.workingCopy);
1199
1861
  // git init probes the filesystem: what the worktree cannot represent is turned off
@@ -1213,7 +1875,7 @@ export class CloneCommand extends TransportCommand<CloneResult> {
1213
1875
  let fetchRefspec: string | undefined;
1214
1876
  if (this.mirror) {
1215
1877
  fetchRefspec = "+refs/*:refs/*";
1216
- } else if (!this.bare) {
1878
+ } else if (!this.bare && !clone.revision) {
1217
1879
  const top = `refs/remotes/${this.remoteName}/`;
1218
1880
  if (!clone.singleBranch) fetchRefspec = `+refs/heads/*:${top}*`;
1219
1881
  else if (clone.detachedTag) fetchRefspec = `+${clone.detachedTag}:${clone.detachedTag}`;
@@ -1224,7 +1886,9 @@ export class CloneCommand extends TransportCommand<CloneResult> {
1224
1886
  fetchRefspec = `+refs/heads/${clone.remoteHead}:${top}${clone.remoteHead}`;
1225
1887
  }
1226
1888
  if (fetchRefspec) {
1227
- store.setValue(`${remote}.fetch`, fetchRefspec);
1889
+ // repo_config_set_multivar(key, value, "^$", 0): at the end of the section, after the
1890
+ // values -c wrote, or in place of an empty one
1891
+ await this.writeConfigValue(`${remote}.fetch`, fetchRefspec, "set-empty");
1228
1892
  if (this.mirror) store.setValue(`${remote}.mirror`, "true");
1229
1893
  }
1230
1894
  if (this.filterSpec !== undefined) {
@@ -1235,6 +1899,16 @@ export class CloneCommand extends TransportCommand<CloneResult> {
1235
1899
  store.setValue(`${remote}.promisor`, "true");
1236
1900
  store.setValue(`${remote}.partialclonefilter`, this.filterSpec);
1237
1901
  }
1902
+ // git 2.43 initialized the sparse checkout before update_head's branch config
1903
+ if (
1904
+ this.sparse &&
1905
+ !this.sparseInitialized &&
1906
+ clone.worktree &&
1907
+ (this.compatibility ?? this.hooks.compatibility) === "2.43"
1908
+ ) {
1909
+ await store.save();
1910
+ await this.initSparseCheckout();
1911
+ }
1238
1912
  if (!this.bare && clone.checkedOutBranch) {
1239
1913
  store.setValue(`branch.${clone.checkedOutBranch}.remote`, this.remoteName);
1240
1914
  store.setValue(
@@ -1280,7 +1954,7 @@ export class CloneCommand extends TransportCommand<CloneResult> {
1280
1954
  const sparse =
1281
1955
  this.sparse && worktree
1282
1956
  ? await (async () => {
1283
- await new SparseCheckoutCommand(this.workingCopy).setArguments(["set"]).call();
1957
+ if (!this.sparseInitialized) await this.initSparseCheckout();
1284
1958
  return SparseUnpack.start({
1285
1959
  workingCopy: this.workingCopy,
1286
1960
  worktree,
@@ -1298,6 +1972,7 @@ export class CloneCommand extends TransportCommand<CloneResult> {
1298
1972
  ignoreCase: coreBool(this.workingCopy, "ignorecase", false),
1299
1973
  pathRules: worktreePathRules(this.workingCopy, worktree),
1300
1974
  ...(sparse ? { writes: (path: string) => sparse.writes(path) } : {}),
1975
+ ...(this.progress ? { progress: this.progress } : {}),
1301
1976
  },
1302
1977
  commit.tree,
1303
1978
  CLONE,
@@ -1312,6 +1987,14 @@ export class CloneCommand extends TransportCommand<CloneResult> {
1312
1987
  return collided;
1313
1988
  }
1314
1989
 
1990
+ /** `git sparse-checkout set` in the new repository (git_sparse_checkout_init), once. */
1991
+ private async initSparseCheckout(): Promise<void> {
1992
+ this.sparseInitialized = true;
1993
+ await new SparseCheckoutCommand(this.workingCopy).setArguments(["set"]).call();
1994
+ }
1995
+
1996
+ private sparseInitialized = false;
1997
+
1315
1998
  /** Whether symlinks are written as links: the worktree can, and `core.symlinks` allows. */
1316
1999
  private symlinksEnabled(worktree: Worktree): boolean {
1317
2000
  return worktreeModeTrust(this.workingCopy, worktree).symlinks;
@@ -1326,11 +2009,81 @@ export class CloneCommand extends TransportCommand<CloneResult> {
1326
2009
  * bare name (`main`) is equally legitimate. Both are accepted, and both yield
1327
2010
  * the bare name the ref-building code below prefixes.
1328
2011
  */
2012
+ /** A complete object id (SHA-1 or SHA-256), as a refspec source names one. */
2013
+ const FULL_HEX_ID = /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/;
2014
+
2015
+ /**
2016
+ * Whether `--revision`'s value parses as a fetch refspec's source (refspec.c: a complete
2017
+ * object id, or a ref name allowed one level, `HEAD` included): `refs/heads/main^` does not.
2018
+ */
2019
+ function isRevisionRefspec(revision: string): boolean {
2020
+ return FULL_HEX_ID.test(revision) || isValidRefName(revision, { allowOneLevel: true });
2021
+ }
2022
+
2023
+ /**
2024
+ * The clone's refspecs after the configured `remote.<name>.fetch` ones (remote_get_early,
2025
+ * then the clone's own appended): every remote ref is mapped through them, or, for a
2026
+ * single-branch clone (`selected`), only the one ref it clones (wanted_peer_refs narrows the
2027
+ * list before mapping).
2028
+ */
2029
+ function withConfiguredRefspecs(
2030
+ own: string[] | RefspecResolver,
2031
+ configured: string[],
2032
+ selected: ((remoteRefs: readonly RemoteRef[]) => RemoteRef | undefined) | undefined,
2033
+ allTags: boolean,
2034
+ ): RefspecResolver {
2035
+ return {
2036
+ prefixes: [
2037
+ ...refPrefixes(configured),
2038
+ ...(Array.isArray(own) ? refPrefixes(own) : own.prefixes),
2039
+ ],
2040
+ resolve: (remoteRefs) => {
2041
+ const ownSpecs = Array.isArray(own) ? own : own.resolve(remoteRefs);
2042
+ // get_fetch_map with missing_ok 0: an exact source the (narrowed) list lacks dies
2043
+ const ref = selected?.(remoteRefs);
2044
+ const mappedOver = selected ? (ref ? [ref] : []) : remoteRefs;
2045
+ const listsRefs = remoteRefs.some((r) => r.oid);
2046
+ const missing = listsRefs ? missingSources(mappedOver, configured) : [];
2047
+ if (missing.length > 0) {
2048
+ throw new TransportError(`fatal: couldn't find remote ref ${missing[0]}`);
2049
+ }
2050
+ const mapped = selected
2051
+ ? mapRefs(mappedOver, configured)
2052
+ .filter((p) => p.localRef !== undefined)
2053
+ .map((p) => `${p.force ? "+" : ""}${p.remoteRef}:${p.localRef}`)
2054
+ : configured;
2055
+ const specs = [...mapped, ...ownSpecs];
2056
+ // write_remote_refs' one transaction refuses a ref two mappings write (wanted_peer_refs
2057
+ // removes no duplicate): ref_transaction's "multiple updates", the first name in order
2058
+ const counts = new Map<string, number>();
2059
+ for (const spec of allTags ? [...specs, "refs/tags/*:refs/tags/*"] : specs) {
2060
+ for (const p of mapRefs(remoteRefs, [spec])) {
2061
+ if (p.localRef !== undefined) counts.set(p.localRef, (counts.get(p.localRef) ?? 0) + 1);
2062
+ }
2063
+ }
2064
+ const twice = [...counts].filter(([, n]) => n > 1).map(([name]) => name);
2065
+ if (twice.length > 0) {
2066
+ twice.sort(compareRefNames);
2067
+ throw new TransportError(`fatal: multiple updates for ref '${twice[0]}' not allowed`);
2068
+ }
2069
+ return specs;
2070
+ },
2071
+ };
2072
+ }
2073
+
1329
2074
  /**
1330
2075
  * clone.c's `absolute_pathdup` of a local source: an absolute path as given, a relative one
1331
2076
  * after the directory clone runs in (the worktree top, as the host sees it when the storage
1332
2077
  * has a root directory), without resolving `..` (git writes `/top/../src`).
1333
2078
  */
2079
+ /** mkstemp's six random characters. */
2080
+ function randomSuffix(): string {
2081
+ const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
2082
+ let out = "";
2083
+ for (let i = 0; i < 6; i++) out += chars[Math.floor(Math.random() * chars.length)];
2084
+ return out;
2085
+ }
2086
+
1334
2087
  function absolutePathOf(
1335
2088
  worktree: Pick<Worktree, "getRoot" | "getFiles"> | undefined,
1336
2089
  path: string,