@statewalker/vcs-commands 0.9.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 (460) hide show
  1. package/README.md +1 -1
  2. package/dist/commands/add-command.d.ts.map +1 -1
  3. package/dist/commands/add-patch/patch-backend.d.ts +2 -0
  4. package/dist/commands/add-patch/patch-backend.d.ts.map +1 -1
  5. package/dist/commands/add-patch/patch-modes.d.ts +6 -2
  6. package/dist/commands/add-patch/patch-modes.d.ts.map +1 -1
  7. package/dist/commands/add-patch/patch-session.d.ts +4 -0
  8. package/dist/commands/add-patch/patch-session.d.ts.map +1 -1
  9. package/dist/commands/am/am-command.d.ts +41 -2
  10. package/dist/commands/am/am-command.d.ts.map +1 -1
  11. package/dist/commands/apply/index.d.ts +1 -1
  12. package/dist/commands/apply/index.d.ts.map +1 -1
  13. package/dist/commands/archive/archive-command.d.ts +169 -0
  14. package/dist/commands/archive/archive-command.d.ts.map +1 -0
  15. package/dist/commands/archive/archive-entry.d.ts +60 -0
  16. package/dist/commands/archive/archive-entry.d.ts.map +1 -0
  17. package/dist/commands/archive/index.d.ts +8 -0
  18. package/dist/commands/archive/index.d.ts.map +1 -0
  19. package/dist/commands/archive/remote-archive-command.d.ts +56 -0
  20. package/dist/commands/archive/remote-archive-command.d.ts.map +1 -0
  21. package/dist/commands/archive/tar-archive.d.ts +31 -0
  22. package/dist/commands/archive/tar-archive.d.ts.map +1 -0
  23. package/dist/commands/archive/tar-commit-id.d.ts +13 -0
  24. package/dist/commands/archive/tar-commit-id.d.ts.map +1 -0
  25. package/dist/commands/archive/upload-archive-writer.d.ts +48 -0
  26. package/dist/commands/archive/upload-archive-writer.d.ts.map +1 -0
  27. package/dist/commands/archive/zip-archive.d.ts +42 -0
  28. package/dist/commands/archive/zip-archive.d.ts.map +1 -0
  29. package/dist/commands/attributes-source.d.ts +10 -0
  30. package/dist/commands/attributes-source.d.ts.map +1 -1
  31. package/dist/commands/blame-command.d.ts +43 -1
  32. package/dist/commands/blame-command.d.ts.map +1 -1
  33. package/dist/commands/bundle/bundle-create-command.d.ts +67 -0
  34. package/dist/commands/bundle/bundle-create-command.d.ts.map +1 -0
  35. package/dist/commands/bundle/bundle-format.d.ts +89 -0
  36. package/dist/commands/bundle/bundle-format.d.ts.map +1 -0
  37. package/dist/commands/bundle/bundle-list.d.ts +92 -0
  38. package/dist/commands/bundle/bundle-list.d.ts.map +1 -0
  39. package/dist/commands/bundle/bundle-read-commands.d.ts +81 -0
  40. package/dist/commands/bundle/bundle-read-commands.d.ts.map +1 -0
  41. package/dist/commands/bundle/bundle-support.d.ts +32 -0
  42. package/dist/commands/bundle/bundle-support.d.ts.map +1 -0
  43. package/dist/commands/bundle/bundle-transport.d.ts +38 -0
  44. package/dist/commands/bundle/bundle-transport.d.ts.map +1 -0
  45. package/dist/commands/bundle/bundle-uri-host.d.ts +43 -0
  46. package/dist/commands/bundle/bundle-uri-host.d.ts.map +1 -0
  47. package/dist/commands/bundle/bundle-uri.d.ts +55 -0
  48. package/dist/commands/bundle/bundle-uri.d.ts.map +1 -0
  49. package/dist/commands/bundle/bundle-verify.d.ts +63 -0
  50. package/dist/commands/bundle/bundle-verify.d.ts.map +1 -0
  51. package/dist/commands/bundle/index.d.ts +14 -0
  52. package/dist/commands/bundle/index.d.ts.map +1 -0
  53. package/dist/commands/cat-file/batch-format.d.ts +58 -0
  54. package/dist/commands/cat-file/batch-format.d.ts.map +1 -0
  55. package/dist/commands/cat-file/cat-file-command.d.ts +135 -0
  56. package/dist/commands/cat-file/cat-file-command.d.ts.map +1 -0
  57. package/dist/commands/cat-file/index.d.ts +3 -0
  58. package/dist/commands/cat-file/index.d.ts.map +1 -0
  59. package/dist/commands/check-attr-command.d.ts +66 -0
  60. package/dist/commands/check-attr-command.d.ts.map +1 -0
  61. package/dist/commands/check-ignore-command.d.ts +58 -0
  62. package/dist/commands/check-ignore-command.d.ts.map +1 -0
  63. package/dist/commands/check-ref-format-command.d.ts +60 -0
  64. package/dist/commands/check-ref-format-command.d.ts.map +1 -0
  65. package/dist/commands/checkout-command.d.ts.map +1 -1
  66. package/dist/commands/checkout-index-command.d.ts +96 -0
  67. package/dist/commands/checkout-index-command.d.ts.map +1 -0
  68. package/dist/commands/cherry-pick-command.d.ts +10 -0
  69. package/dist/commands/cherry-pick-command.d.ts.map +1 -1
  70. package/dist/commands/clone-command.d.ts +19 -0
  71. package/dist/commands/clone-command.d.ts.map +1 -1
  72. package/dist/commands/commit-command.d.ts +9 -1
  73. package/dist/commands/commit-command.d.ts.map +1 -1
  74. package/dist/commands/config-command.d.ts +2 -0
  75. package/dist/commands/config-command.d.ts.map +1 -1
  76. package/dist/commands/daemon-access-hook.d.ts +36 -0
  77. package/dist/commands/daemon-access-hook.d.ts.map +1 -0
  78. package/dist/commands/default-branch.d.ts +42 -0
  79. package/dist/commands/default-branch.d.ts.map +1 -1
  80. package/dist/commands/diff-command.d.ts +132 -5
  81. package/dist/commands/diff-command.d.ts.map +1 -1
  82. package/dist/commands/diff-external.d.ts +43 -0
  83. package/dist/commands/diff-external.d.ts.map +1 -0
  84. package/dist/commands/diff-plumbing/diff-pairs-command.d.ts +27 -0
  85. package/dist/commands/diff-plumbing/diff-pairs-command.d.ts.map +1 -0
  86. package/dist/commands/diff-plumbing/diff-plumbing-command.d.ts +129 -0
  87. package/dist/commands/diff-plumbing/diff-plumbing-command.d.ts.map +1 -0
  88. package/dist/commands/diff-plumbing/index.d.ts +3 -0
  89. package/dist/commands/diff-plumbing/index.d.ts.map +1 -0
  90. package/dist/commands/diff-textconv.d.ts +5 -1
  91. package/dist/commands/diff-textconv.d.ts.map +1 -1
  92. package/dist/commands/fast-export/fast-export-command.d.ts +135 -0
  93. package/dist/commands/fast-export/fast-export-command.d.ts.map +1 -0
  94. package/dist/commands/fast-export/fast-import-command.d.ts +182 -0
  95. package/dist/commands/fast-export/fast-import-command.d.ts.map +1 -0
  96. package/dist/commands/fast-export/fast-stream-support.d.ts +64 -0
  97. package/dist/commands/fast-export/fast-stream-support.d.ts.map +1 -0
  98. package/dist/commands/fast-export/index.d.ts +4 -0
  99. package/dist/commands/fast-export/index.d.ts.map +1 -0
  100. package/dist/commands/fetch-command.d.ts +65 -0
  101. package/dist/commands/fetch-command.d.ts.map +1 -1
  102. package/dist/commands/fetch-multiple-command.d.ts.map +1 -1
  103. package/dist/commands/format-rev-command.d.ts +58 -0
  104. package/dist/commands/format-rev-command.d.ts.map +1 -0
  105. package/dist/commands/fsck/fsck-command.d.ts.map +1 -1
  106. package/dist/commands/fsck/fsck-msg-ids.d.ts +18 -3
  107. package/dist/commands/fsck/fsck-msg-ids.d.ts.map +1 -1
  108. package/dist/commands/fsmonitor-refresh.d.ts +69 -0
  109. package/dist/commands/fsmonitor-refresh.d.ts.map +1 -0
  110. package/dist/commands/gc-command.d.ts +5 -0
  111. package/dist/commands/gc-command.d.ts.map +1 -1
  112. package/dist/commands/git-hooks.d.ts +32 -0
  113. package/dist/commands/git-hooks.d.ts.map +1 -1
  114. package/dist/commands/git-paths.d.ts +26 -0
  115. package/dist/commands/git-paths.d.ts.map +1 -0
  116. package/dist/commands/grep/grep-command.d.ts +2 -1
  117. package/dist/commands/grep/grep-command.d.ts.map +1 -1
  118. package/dist/commands/history-command.d.ts +156 -0
  119. package/dist/commands/history-command.d.ts.map +1 -0
  120. package/dist/commands/http-config.d.ts +38 -0
  121. package/dist/commands/http-config.d.ts.map +1 -0
  122. package/dist/commands/index-adder.d.ts +12 -1
  123. package/dist/commands/index-adder.d.ts.map +1 -1
  124. package/dist/commands/index-host.d.ts.map +1 -1
  125. package/dist/commands/index.d.ts +44 -1
  126. package/dist/commands/index.d.ts.map +1 -1
  127. package/dist/commands/index.js +6 -5
  128. package/dist/commands/init-command.d.ts.map +1 -1
  129. package/dist/commands/last-modified-command.d.ts +102 -0
  130. package/dist/commands/last-modified-command.d.ts.map +1 -0
  131. package/dist/commands/lfs/go-url.d.ts +43 -0
  132. package/dist/commands/lfs/go-url.d.ts.map +1 -0
  133. package/dist/commands/lfs/index.d.ts +3 -0
  134. package/dist/commands/lfs/index.d.ts.map +1 -0
  135. package/dist/commands/lfs/lfs-config.d.ts +174 -0
  136. package/dist/commands/lfs/lfs-config.d.ts.map +1 -0
  137. package/dist/commands/lfs/lfs-endpoint-command.d.ts +83 -0
  138. package/dist/commands/lfs/lfs-endpoint-command.d.ts.map +1 -0
  139. package/dist/commands/local-transport.d.ts.map +1 -1
  140. package/dist/commands/log-command.d.ts +26 -0
  141. package/dist/commands/log-command.d.ts.map +1 -1
  142. package/dist/commands/log-output.d.ts +22 -1
  143. package/dist/commands/log-output.d.ts.map +1 -1
  144. package/dist/commands/ls-files-command.d.ts +153 -0
  145. package/dist/commands/ls-files-command.d.ts.map +1 -0
  146. package/dist/commands/ls-remote-command.d.ts +5 -0
  147. package/dist/commands/ls-remote-command.d.ts.map +1 -1
  148. package/dist/commands/ls-tree-command.d.ts +105 -0
  149. package/dist/commands/ls-tree-command.d.ts.map +1 -0
  150. package/dist/commands/maintenance-run-command.d.ts +122 -0
  151. package/dist/commands/maintenance-run-command.d.ts.map +1 -0
  152. package/dist/commands/merge-command.d.ts +7 -0
  153. package/dist/commands/merge-command.d.ts.map +1 -1
  154. package/dist/commands/merge-config.d.ts +7 -0
  155. package/dist/commands/merge-config.d.ts.map +1 -1
  156. package/dist/commands/merge-drivers.d.ts +67 -5
  157. package/dist/commands/merge-drivers.d.ts.map +1 -1
  158. package/dist/commands/merge-support.d.ts +6 -0
  159. package/dist/commands/merge-support.d.ts.map +1 -1
  160. package/dist/commands/merge-tree-command.d.ts +122 -0
  161. package/dist/commands/merge-tree-command.d.ts.map +1 -0
  162. package/dist/commands/mktag-command.d.ts +51 -0
  163. package/dist/commands/mktag-command.d.ts.map +1 -0
  164. package/dist/commands/object-store/count-objects-command.d.ts +58 -0
  165. package/dist/commands/object-store/count-objects-command.d.ts.map +1 -0
  166. package/dist/commands/object-store/index.d.ts +5 -0
  167. package/dist/commands/object-store/index.d.ts.map +1 -0
  168. package/dist/commands/object-store/objects-directory.d.ts +12 -0
  169. package/dist/commands/object-store/objects-directory.d.ts.map +1 -0
  170. package/dist/commands/object-store/prune-command.d.ts +38 -0
  171. package/dist/commands/object-store/prune-command.d.ts.map +1 -0
  172. package/dist/commands/object-store/show-index-command.d.ts +23 -0
  173. package/dist/commands/object-store/show-index-command.d.ts.map +1 -0
  174. package/dist/commands/ort-merge.d.ts +24 -0
  175. package/dist/commands/ort-merge.d.ts.map +1 -1
  176. package/dist/commands/patch-id-command.d.ts +30 -0
  177. package/dist/commands/patch-id-command.d.ts.map +1 -0
  178. package/dist/commands/patch-id.d.ts +24 -0
  179. package/dist/commands/patch-id.d.ts.map +1 -1
  180. package/dist/commands/plumbing-command.d.ts +66 -0
  181. package/dist/commands/plumbing-command.d.ts.map +1 -0
  182. package/dist/commands/plumbing-input.d.ts +38 -0
  183. package/dist/commands/plumbing-input.d.ts.map +1 -0
  184. package/dist/commands/promisor-remote-reply.d.ts +35 -0
  185. package/dist/commands/promisor-remote-reply.d.ts.map +1 -0
  186. package/dist/commands/promisor-remote.d.ts.map +1 -1
  187. package/dist/commands/pull-command.d.ts.map +1 -1
  188. package/dist/commands/push-command.d.ts +17 -2
  189. package/dist/commands/push-command.d.ts.map +1 -1
  190. package/dist/commands/rebase-command.d.ts +108 -2
  191. package/dist/commands/rebase-command.d.ts.map +1 -1
  192. package/dist/commands/refs-command.d.ts +81 -0
  193. package/dist/commands/refs-command.d.ts.map +1 -0
  194. package/dist/commands/remote-object-info-command.d.ts +55 -0
  195. package/dist/commands/remote-object-info-command.d.ts.map +1 -0
  196. package/dist/commands/remote-transport.d.ts +40 -3
  197. package/dist/commands/remote-transport.d.ts.map +1 -1
  198. package/dist/commands/repack-command.d.ts +115 -0
  199. package/dist/commands/repack-command.d.ts.map +1 -0
  200. package/dist/commands/replace-command.d.ts +143 -0
  201. package/dist/commands/replace-command.d.ts.map +1 -0
  202. package/dist/commands/replay-command.d.ts +117 -0
  203. package/dist/commands/replay-command.d.ts.map +1 -0
  204. package/dist/commands/repo-command.d.ts +136 -0
  205. package/dist/commands/repo-command.d.ts.map +1 -0
  206. package/dist/commands/request-pull-command.d.ts +82 -0
  207. package/dist/commands/request-pull-command.d.ts.map +1 -0
  208. package/dist/commands/rerere-command.d.ts +36 -0
  209. package/dist/commands/rerere-command.d.ts.map +1 -0
  210. package/dist/commands/rerere.d.ts +102 -0
  211. package/dist/commands/rerere.d.ts.map +1 -0
  212. package/dist/commands/rev-filter/commit-grep.d.ts +3 -1
  213. package/dist/commands/rev-filter/commit-grep.d.ts.map +1 -1
  214. package/dist/commands/rev-list-command.d.ts +3 -0
  215. package/dist/commands/rev-list-command.d.ts.map +1 -1
  216. package/dist/commands/rev-parse-command.d.ts +9 -0
  217. package/dist/commands/rev-parse-command.d.ts.map +1 -1
  218. package/dist/commands/revert-command.d.ts +10 -0
  219. package/dist/commands/revert-command.d.ts.map +1 -1
  220. package/dist/commands/revision-range.d.ts +5 -0
  221. package/dist/commands/revision-range.d.ts.map +1 -1
  222. package/dist/commands/revision-resolver.d.ts +12 -0
  223. package/dist/commands/revision-resolver.d.ts.map +1 -1
  224. package/dist/commands/sequencer-pick.d.ts +18 -0
  225. package/dist/commands/sequencer-pick.d.ts.map +1 -1
  226. package/dist/commands/serve-repository.d.ts +23 -1
  227. package/dist/commands/serve-repository.d.ts.map +1 -1
  228. package/dist/commands/session-id.d.ts +18 -0
  229. package/dist/commands/session-id.d.ts.map +1 -0
  230. package/dist/commands/show-branch-command.d.ts +59 -0
  231. package/dist/commands/show-branch-command.d.ts.map +1 -0
  232. package/dist/commands/show-ref-command.d.ts +112 -0
  233. package/dist/commands/show-ref-command.d.ts.map +1 -0
  234. package/dist/commands/signature-check.d.ts +9 -2
  235. package/dist/commands/signature-check.d.ts.map +1 -1
  236. package/dist/commands/signing.d.ts +22 -1
  237. package/dist/commands/signing.d.ts.map +1 -1
  238. package/dist/commands/stash-apply-command.d.ts.map +1 -1
  239. package/dist/commands/stash-export-command.d.ts +115 -0
  240. package/dist/commands/stash-export-command.d.ts.map +1 -0
  241. package/dist/commands/status-command.d.ts +2 -1
  242. package/dist/commands/status-command.d.ts.map +1 -1
  243. package/dist/commands/stripspace-command.d.ts +44 -0
  244. package/dist/commands/stripspace-command.d.ts.map +1 -0
  245. package/dist/commands/submodule-add-command.d.ts +10 -1
  246. package/dist/commands/submodule-add-command.d.ts.map +1 -1
  247. package/dist/commands/submodule-auth.d.ts +3 -1
  248. package/dist/commands/submodule-auth.d.ts.map +1 -1
  249. package/dist/commands/submodule-commands.d.ts +9 -1
  250. package/dist/commands/submodule-commands.d.ts.map +1 -1
  251. package/dist/commands/submodule-update-command.d.ts +13 -1
  252. package/dist/commands/submodule-update-command.d.ts.map +1 -1
  253. package/dist/commands/textconv-cache.d.ts +58 -0
  254. package/dist/commands/textconv-cache.d.ts.map +1 -0
  255. package/dist/commands/tree-restore.d.ts +5 -0
  256. package/dist/commands/tree-restore.d.ts.map +1 -1
  257. package/dist/commands/unpack-objects-command.d.ts +47 -0
  258. package/dist/commands/unpack-objects-command.d.ts.map +1 -0
  259. package/dist/commands/update-index-command.d.ts +110 -0
  260. package/dist/commands/update-index-command.d.ts.map +1 -0
  261. package/dist/commands/uri-protocols.d.ts +13 -0
  262. package/dist/commands/uri-protocols.d.ts.map +1 -0
  263. package/dist/commands/url-parse-command.d.ts +30 -0
  264. package/dist/commands/url-parse-command.d.ts.map +1 -0
  265. package/dist/commands/var-command.d.ts +42 -0
  266. package/dist/commands/var-command.d.ts.map +1 -0
  267. package/dist/{commands-CNvli5bl.js → commands-Mlo1dxQN.js} +52078 -44471
  268. package/dist/errors/command-errors.d.ts +33 -0
  269. package/dist/errors/command-errors.d.ts.map +1 -1
  270. package/dist/errors/index.js +39 -1
  271. package/dist/{fsck-CPeDh9fh.js → fsck-CrhVMNIH.js} +184 -143
  272. package/dist/git-command.d.ts +58 -2
  273. package/dist/git-command.d.ts.map +1 -1
  274. package/dist/git.d.ts +532 -1
  275. package/dist/git.d.ts.map +1 -1
  276. package/dist/guarded-transport-command.d.ts +3 -1
  277. package/dist/guarded-transport-command.d.ts.map +1 -1
  278. package/dist/index.js +7 -6
  279. package/dist/maintenance-run-command-Bw21HEkH.js +13539 -0
  280. package/dist/{remote-transport-CCmBadm-.js → remote-transport-Bu4PGSMD.js} +1009 -10
  281. package/dist/results/cherry-pick-result.d.ts +6 -0
  282. package/dist/results/cherry-pick-result.d.ts.map +1 -1
  283. package/dist/results/diff-entry.d.ts +10 -0
  284. package/dist/results/diff-entry.d.ts.map +1 -1
  285. package/dist/results/diff-formatter.d.ts.map +1 -1
  286. package/dist/results/diff-output.d.ts +49 -3
  287. package/dist/results/diff-output.d.ts.map +1 -1
  288. package/dist/results/fetch-result.d.ts +12 -0
  289. package/dist/results/fetch-result.d.ts.map +1 -1
  290. package/dist/results/index.js +2 -2
  291. package/dist/results/merge-result.d.ts +5 -0
  292. package/dist/results/merge-result.d.ts.map +1 -1
  293. package/dist/results/push-result.d.ts +5 -0
  294. package/dist/results/push-result.d.ts.map +1 -1
  295. package/dist/results/rebase-result.d.ts +7 -0
  296. package/dist/results/rebase-result.d.ts.map +1 -1
  297. package/dist/results/revert-result.d.ts +6 -0
  298. package/dist/results/revert-result.d.ts.map +1 -1
  299. package/dist/results/stash-result.d.ts +5 -0
  300. package/dist/results/stash-result.d.ts.map +1 -1
  301. package/dist/{results-BDuEgdLU.js → results-ERo9vELd.js} +28511 -25685
  302. package/dist/transport-command.d.ts +79 -1
  303. package/dist/transport-command.d.ts.map +1 -1
  304. package/package.json +12 -12
  305. package/src/commands/add-command.ts +3 -0
  306. package/src/commands/add-patch/patch-backend.ts +4 -1
  307. package/src/commands/add-patch/patch-modes.ts +26 -2
  308. package/src/commands/add-patch/patch-session.ts +6 -0
  309. package/src/commands/am/am-command.ts +163 -8
  310. package/src/commands/apply/index.ts +1 -0
  311. package/src/commands/archive/archive-command.ts +1148 -0
  312. package/src/commands/archive/archive-entry.ts +93 -0
  313. package/src/commands/archive/index.ts +7 -0
  314. package/src/commands/archive/remote-archive-command.ts +140 -0
  315. package/src/commands/archive/tar-archive.ts +207 -0
  316. package/src/commands/archive/tar-commit-id.ts +72 -0
  317. package/src/commands/archive/upload-archive-writer.ts +213 -0
  318. package/src/commands/archive/zip-archive.ts +317 -0
  319. package/src/commands/attributes-source.ts +26 -12
  320. package/src/commands/blame-command.ts +118 -19
  321. package/src/commands/bundle/bundle-create-command.ts +405 -0
  322. package/src/commands/bundle/bundle-format.ts +228 -0
  323. package/src/commands/bundle/bundle-list.ts +276 -0
  324. package/src/commands/bundle/bundle-read-commands.ts +157 -0
  325. package/src/commands/bundle/bundle-support.ts +85 -0
  326. package/src/commands/bundle/bundle-transport.ts +107 -0
  327. package/src/commands/bundle/bundle-uri-host.ts +204 -0
  328. package/src/commands/bundle/bundle-uri.ts +236 -0
  329. package/src/commands/bundle/bundle-verify.ts +152 -0
  330. package/src/commands/bundle/index.ts +14 -0
  331. package/src/commands/cat-file/batch-format.ts +193 -0
  332. package/src/commands/cat-file/cat-file-command.ts +857 -0
  333. package/src/commands/cat-file/index.ts +2 -0
  334. package/src/commands/check-attr-command.ts +333 -0
  335. package/src/commands/check-ignore-command.ts +261 -0
  336. package/src/commands/check-ref-format-command.ts +129 -0
  337. package/src/commands/checkout-command.ts +39 -21
  338. package/src/commands/checkout-index-command.ts +568 -0
  339. package/src/commands/checkout-paths.ts +7 -0
  340. package/src/commands/cherry-pick-command.ts +21 -1
  341. package/src/commands/clone-command.ts +208 -7
  342. package/src/commands/commit-command.ts +22 -4
  343. package/src/commands/config-command.ts +9 -0
  344. package/src/commands/daemon-access-hook.ts +78 -0
  345. package/src/commands/default-branch.ts +99 -1
  346. package/src/commands/diff-command.ts +573 -46
  347. package/src/commands/diff-external.ts +131 -0
  348. package/src/commands/diff-plumbing/diff-pairs-command.ts +193 -0
  349. package/src/commands/diff-plumbing/diff-plumbing-command.ts +424 -0
  350. package/src/commands/diff-plumbing/index.ts +2 -0
  351. package/src/commands/diff-textconv.ts +5 -1
  352. package/src/commands/fast-export/fast-export-command.ts +911 -0
  353. package/src/commands/fast-export/fast-import-command.ts +1553 -0
  354. package/src/commands/fast-export/fast-stream-support.ts +162 -0
  355. package/src/commands/fast-export/index.ts +3 -0
  356. package/src/commands/fetch-command.ts +312 -8
  357. package/src/commands/fetch-multiple-command.ts +4 -1
  358. package/src/commands/format-rev-command.ts +251 -0
  359. package/src/commands/fsck/fsck-command.ts +47 -20
  360. package/src/commands/fsck/fsck-msg-ids.ts +19 -3
  361. package/src/commands/fsck/fsck-pack.ts +2 -2
  362. package/src/commands/fsmonitor-refresh.ts +315 -0
  363. package/src/commands/gc-command.ts +10 -0
  364. package/src/commands/git-hooks.ts +123 -6
  365. package/src/commands/git-paths.ts +136 -0
  366. package/src/commands/grep/grep-command.ts +38 -15
  367. package/src/commands/history-command.ts +617 -0
  368. package/src/commands/http-config.ts +139 -0
  369. package/src/commands/index-adder.ts +37 -3
  370. package/src/commands/index-host.ts +6 -1
  371. package/src/commands/index.ts +45 -0
  372. package/src/commands/init-command.ts +14 -0
  373. package/src/commands/last-modified-command.ts +804 -0
  374. package/src/commands/lfs/go-url.ts +370 -0
  375. package/src/commands/lfs/index.ts +2 -0
  376. package/src/commands/lfs/lfs-config.ts +738 -0
  377. package/src/commands/lfs/lfs-endpoint-command.ts +180 -0
  378. package/src/commands/local-transport.ts +252 -4
  379. package/src/commands/log-command.ts +104 -5
  380. package/src/commands/log-output.ts +55 -5
  381. package/src/commands/ls-files-command.ts +1177 -0
  382. package/src/commands/ls-remote-command.ts +6 -0
  383. package/src/commands/ls-tree-command.ts +684 -0
  384. package/src/commands/maintenance-run-command.ts +949 -0
  385. package/src/commands/merge-command.ts +78 -32
  386. package/src/commands/merge-config.ts +23 -1
  387. package/src/commands/merge-drivers.ts +109 -20
  388. package/src/commands/merge-support.ts +29 -5
  389. package/src/commands/merge-tree-command.ts +786 -0
  390. package/src/commands/mktag-command.ts +149 -0
  391. package/src/commands/object-store/count-objects-command.ts +404 -0
  392. package/src/commands/object-store/index.ts +4 -0
  393. package/src/commands/object-store/objects-directory.ts +24 -0
  394. package/src/commands/object-store/prune-command.ts +129 -0
  395. package/src/commands/object-store/show-index-command.ts +151 -0
  396. package/src/commands/ort-merge.ts +92 -25
  397. package/src/commands/patch-id-command.ts +65 -0
  398. package/src/commands/patch-id.ts +218 -0
  399. package/src/commands/plumbing-command.ts +141 -0
  400. package/src/commands/plumbing-input.ts +87 -0
  401. package/src/commands/promisor-remote-reply.ts +276 -0
  402. package/src/commands/promisor-remote.ts +25 -2
  403. package/src/commands/pull-command.ts +2 -0
  404. package/src/commands/push-command.ts +87 -5
  405. package/src/commands/rebase-command.ts +507 -19
  406. package/src/commands/refs-command.ts +274 -0
  407. package/src/commands/remote-object-info-command.ts +109 -0
  408. package/src/commands/remote-transport.ts +116 -1
  409. package/src/commands/repack-command.ts +383 -0
  410. package/src/commands/replace-command.ts +816 -0
  411. package/src/commands/replay-command.ts +674 -0
  412. package/src/commands/repo-command.ts +967 -0
  413. package/src/commands/request-pull-command.ts +356 -0
  414. package/src/commands/rerere-command.ts +179 -0
  415. package/src/commands/rerere.ts +925 -0
  416. package/src/commands/rev-filter/commit-grep.ts +7 -2
  417. package/src/commands/rev-list-command.ts +9 -0
  418. package/src/commands/rev-parse-command.ts +62 -4
  419. package/src/commands/revert-command.ts +21 -1
  420. package/src/commands/revision-range.ts +7 -2
  421. package/src/commands/revision-resolver.ts +44 -3
  422. package/src/commands/sequencer-pick.ts +47 -0
  423. package/src/commands/serve-repository.ts +65 -0
  424. package/src/commands/session-id.ts +31 -0
  425. package/src/commands/show-branch-command.ts +981 -0
  426. package/src/commands/show-command.ts +1 -1
  427. package/src/commands/show-ref-command.ts +439 -0
  428. package/src/commands/signature-check.ts +37 -5
  429. package/src/commands/signing.ts +122 -16
  430. package/src/commands/stash-apply-command.ts +3 -0
  431. package/src/commands/stash-export-command.ts +397 -0
  432. package/src/commands/status-command.ts +43 -6
  433. package/src/commands/stripspace-command.ts +118 -0
  434. package/src/commands/submodule-add-command.ts +22 -1
  435. package/src/commands/submodule-auth.ts +61 -6
  436. package/src/commands/submodule-commands.ts +12 -2
  437. package/src/commands/submodule-update-command.ts +29 -0
  438. package/src/commands/textconv-cache.ts +143 -0
  439. package/src/commands/tree-restore.ts +14 -0
  440. package/src/commands/unpack-objects-command.ts +235 -0
  441. package/src/commands/update-index-command.ts +1016 -0
  442. package/src/commands/uri-protocols.ts +13 -0
  443. package/src/commands/url-parse-command.ts +67 -0
  444. package/src/commands/var-command.ts +219 -0
  445. package/src/errors/command-errors.ts +45 -0
  446. package/src/git-command.ts +131 -1
  447. package/src/git.ts +808 -1
  448. package/src/guarded-transport-command.ts +6 -1
  449. package/src/results/cherry-pick-result.ts +6 -0
  450. package/src/results/diff-entry.ts +12 -0
  451. package/src/results/diff-formatter.ts +7 -4
  452. package/src/results/diff-output.ts +117 -11
  453. package/src/results/diff-pickaxe.ts +1 -1
  454. package/src/results/fetch-result.ts +12 -0
  455. package/src/results/merge-result.ts +5 -0
  456. package/src/results/push-result.ts +5 -0
  457. package/src/results/rebase-result.ts +7 -0
  458. package/src/results/revert-result.ts +6 -0
  459. package/src/results/stash-result.ts +6 -0
  460. package/src/transport-command.ts +182 -1
@@ -0,0 +1,857 @@
1
+ /**
2
+ * `git cat-file` (builtin/cat-file.c): an object's type, size, existence or content, one
3
+ * object named on the command line (`-t`, `-s`, `-e`, `-p`, `<type> <object>`) or many read
4
+ * from stdin (`--batch`, `--batch-check`, `--batch-command`, `--batch-all-objects`).
5
+ *
6
+ * @example
7
+ * ```typescript
8
+ * // git cat-file -p HEAD:README.md
9
+ * await git.catFile().setMode("pretty").setObject("HEAD:README.md").setStdout(write).call();
10
+ * // printf 'HEAD\nHEAD:a.txt\n' | git cat-file --batch-check
11
+ * const { stdout } = await git.catFile().setBatch("info").setStdin("HEAD\nHEAD:a.txt\n").callOutput();
12
+ * ```
13
+ */
14
+
15
+ import {
16
+ type CompatObjects,
17
+ decodeTreeBytes,
18
+ type GitObjects,
19
+ type ObjectId,
20
+ } from "@statewalker/vcs-core";
21
+ import { ObjectInfoError } from "@statewalker/vcs-transport";
22
+ import { parseGitBool } from "@statewalker/vcs-utils";
23
+ import { decodeGitPath } from "@statewalker/vcs-utils/encoding";
24
+ import { RemoteConfigStore } from "../../remote-config/index.js";
25
+ import { quotePath } from "../../results/quote-path.js";
26
+ import { PlumbingCommand, PlumbingError } from "../plumbing-command.js";
27
+ import {
28
+ RemoteObjectInfoCommand,
29
+ type RemoteObjectInfoResult,
30
+ RemoteObjectInfoUnsupportedError,
31
+ } from "../remote-object-info-command.js";
32
+ import { applyMailmapToHeader } from "../rev-filter/index.js";
33
+ import type { RevisionResolver } from "../revision-resolver.js";
34
+ import {
35
+ type BatchFormat,
36
+ type BatchObjectData,
37
+ DEFAULT_BATCH_FORMAT,
38
+ expandBatchFormat,
39
+ parseBatchFormat,
40
+ } from "./batch-format.js";
41
+
42
+ /** `-t`, `-s`, `-e`, `-p`. */
43
+ export type CatFileMode = "type" | "size" | "exists" | "pretty";
44
+
45
+ /** `--batch` (contents), `--batch-check` (info), `--batch-command` (command). */
46
+ export type CatFileBatchMode = "contents" | "info" | "command";
47
+
48
+ /** What `--batch*` reads as stdin: text, bytes, or chunks read as they come. */
49
+ export type CatFileInput = string | Uint8Array | AsyncIterable<Uint8Array> | Iterable<Uint8Array>;
50
+
51
+ const OBJECT_TYPES = new Set(["blob", "tree", "commit", "tag"]);
52
+ const S_IFMT = 0o170000;
53
+ const S_IFGITLINK = 0o160000;
54
+ const encoder = new TextEncoder();
55
+ const MAILMAP_HEADERS = ["author ", "committer ", "tagger "].map((h) => encoder.encode(h));
56
+ /** git's `MAXREPLACEDEPTH` */
57
+ const MAX_REPLACE_DEPTH = 5;
58
+
59
+ interface ObjectInfo {
60
+ type: string;
61
+ size: number;
62
+ }
63
+
64
+ /**
65
+ * `git cat-file`. Stdout goes to {@link setStdout} as git writes it: a blob's content is
66
+ * streamed chunk by chunk as the store reads it (never held whole), and `--batch` input is
67
+ * read line by line as {@link setStdin}'s chunks arrive, so a caller can feed names while it
68
+ * reads the answers.
69
+ *
70
+ * Replace refs apply as in git (`OBJECT_INFO_LOOKUP_REPLACE`): the name printed is the one
71
+ * asked, the type, size and content the replacement's; `--batch-all-objects` reads none.
72
+ *
73
+ * `--batch-command`'s `remote-object-info <remote> <id>...` (2.56) asks the remote's v2
74
+ * `object-info` through {@link setRemoteObjectInfo}'s command: only the atoms the server
75
+ * answered expand (`%(objectname)` always), and an object it lacks prints `<id> missing`.
76
+ *
77
+ * Not implemented: `--textconv`, `--filters`, `--path`, `--follow-symlinks`, `--filter`
78
+ * (2.5x), and the `%(objectsize:disk)` and `%(deltabase)` atoms (refused: the stores report
79
+ * neither; git's `remote-object-info` would print them empty). `--unordered` lists objects in
80
+ * the store's listing order, not pack order. The promisor-remote warning of
81
+ * `--batch-all-objects` is not printed.
82
+ */
83
+ export class CatFileCommand extends PlumbingCommand {
84
+ private mode?: CatFileMode;
85
+ private type?: string;
86
+ private object?: string;
87
+ private batch?: CatFileBatchMode;
88
+ private format?: string;
89
+ private buffer?: boolean;
90
+ private nulInput = false;
91
+ private nulTerminated = false;
92
+ private allObjects = false;
93
+ private unordered = false;
94
+ private useMailmap = false;
95
+ private stdin?: CatFileInput;
96
+ private compatibility: "2.43" | "2.56" = "2.56";
97
+
98
+ /** `-t` (type), `-s` (size), `-e` (exists: exit 1 when absent), `-p` (pretty). */
99
+ setMode(mode: CatFileMode): this {
100
+ this.checkCallable();
101
+ this.mode = mode;
102
+ return this;
103
+ }
104
+
105
+ /** `<type> <object>`: the object peeled to this type (`blob`, `tree`, `commit`, `tag`). */
106
+ setType(type: string): this {
107
+ this.checkCallable();
108
+ this.type = type;
109
+ return this;
110
+ }
111
+
112
+ /** The object named on the command line. */
113
+ setObject(name: string): this {
114
+ this.checkCallable();
115
+ this.object = name;
116
+ return this;
117
+ }
118
+
119
+ /**
120
+ * `--batch[=<format>]` (`contents`), `--batch-check[=<format>]` (`info`),
121
+ * `--batch-command[=<format>]` (`command`).
122
+ */
123
+ setBatch(mode: CatFileBatchMode, format?: string): this {
124
+ this.checkCallable();
125
+ this.batch = mode;
126
+ this.format = format;
127
+ return this;
128
+ }
129
+
130
+ /** `--buffer` (`--batch-command`'s `flush` needs it; output itself is the same). */
131
+ setBuffer(buffer: boolean): this {
132
+ this.checkCallable();
133
+ this.buffer = buffer;
134
+ return this;
135
+ }
136
+
137
+ /** `-z`: stdin is NUL-terminated. */
138
+ setNulInput(nul: boolean): this {
139
+ this.checkCallable();
140
+ this.nulInput = nul;
141
+ return this;
142
+ }
143
+
144
+ /** `-Z`: stdin and stdout are NUL-terminated. */
145
+ setNulTerminated(nul: boolean): this {
146
+ this.checkCallable();
147
+ this.nulTerminated = nul;
148
+ return this;
149
+ }
150
+
151
+ /** `--batch-all-objects`: every object of the repository, stdin ignored. */
152
+ setBatchAllObjects(all: boolean): this {
153
+ this.checkCallable();
154
+ this.allObjects = all;
155
+ return this;
156
+ }
157
+
158
+ /** `--unordered` (with `--batch-all-objects`): the store's order, not sorted by id. */
159
+ setUnordered(unordered: boolean): this {
160
+ this.checkCallable();
161
+ this.unordered = unordered;
162
+ return this;
163
+ }
164
+
165
+ /**
166
+ * The `remote-object-info` command a `--batch-command` line runs (default: one over the
167
+ * default transports; `Git.catFile()` gives the facade's): its credentials and transports.
168
+ */
169
+ setRemoteObjectInfo(factory: () => RemoteObjectInfoCommand): this {
170
+ this.checkCallable();
171
+ this.remoteObjectInfoFactory = factory;
172
+ return this;
173
+ }
174
+
175
+ private remoteObjectInfoFactory?: () => RemoteObjectInfoCommand;
176
+
177
+ /** `--use-mailmap`: idents of commits and tags mapped through the mailmap. */
178
+ setUseMailmap(use: boolean): this {
179
+ this.checkCallable();
180
+ this.useMailmap = use;
181
+ return this;
182
+ }
183
+
184
+ /** The batch modes' stdin. */
185
+ setStdin(input: CatFileInput): this {
186
+ this.checkCallable();
187
+ this.stdin = input;
188
+ return this;
189
+ }
190
+
191
+ /** The git version whose behaviour to follow (default 2.56). */
192
+ setCompatibility(version: "2.43" | "2.56"): this {
193
+ this.checkCallable();
194
+ this.compatibility = version;
195
+ return this;
196
+ }
197
+
198
+ protected override writesNoObjects(): boolean {
199
+ return true;
200
+ }
201
+
202
+ protected async run(): Promise<number> {
203
+ this.checkOptions();
204
+ if (this.batch) return this.runBatch();
205
+ return this.catOne(this.object as string);
206
+ }
207
+
208
+ /** The option checks of cmd_cat_file that the setters can still break. */
209
+ private checkOptions(): void {
210
+ const usage = (message: string) => new PlumbingError(`fatal: ${message}`, 129);
211
+ if (this.batch) {
212
+ if (this.mode) throw usage(`'-${modeLetter(this.mode)}' is incompatible with batch mode`);
213
+ if (this.object !== undefined || this.type !== undefined) {
214
+ throw usage("batch modes take no arguments");
215
+ }
216
+ return;
217
+ }
218
+ const batchOption =
219
+ this.buffer !== undefined
220
+ ? "--buffer"
221
+ : this.allObjects
222
+ ? "--batch-all-objects"
223
+ : this.nulInput
224
+ ? "-z"
225
+ : this.nulTerminated
226
+ ? "-Z"
227
+ : undefined;
228
+ if (batchOption) throw usage(`'${batchOption}' requires a batch mode`);
229
+ if (this.mode) {
230
+ if (this.object === undefined) {
231
+ throw usage(`<object> required with '-${modeLetter(this.mode)}'`);
232
+ }
233
+ if (this.type !== undefined) throw usage("too many arguments");
234
+ } else if (this.object === undefined || this.type === undefined) {
235
+ throw usage("only two arguments allowed in <type> <object> mode, not 1");
236
+ }
237
+ }
238
+
239
+ private get objects(): GitObjects {
240
+ const objects = this._workingCopy.history?.objects;
241
+ if (!objects) throw new Error("WorkingCopy.history is required for commands");
242
+ return objects;
243
+ }
244
+
245
+ /** `lookup_replace_object`: the object reads go to. */
246
+ private async replaced(id: ObjectId): Promise<ObjectId> {
247
+ const replacements = await this.objectReplacements();
248
+ if (!replacements) return id;
249
+ let current = id;
250
+ for (let depth = 0; ; depth++) {
251
+ const next = replacements.replace.get(current);
252
+ if (next === undefined) return current;
253
+ if (depth >= MAX_REPLACE_DEPTH) {
254
+ throw new PlumbingError(`fatal: replace depth too high for object ${id}`);
255
+ }
256
+ current = next;
257
+ }
258
+ }
259
+
260
+ /** `oid_object_info`: type and size from the headers, else from a read. */
261
+ private async info(id: ObjectId): Promise<ObjectInfo | undefined> {
262
+ const objects = this.objects;
263
+ const header = await objects.header?.(id).catch(() => undefined);
264
+ if (header) return header;
265
+ const object = await objects.get(id).catch(() => undefined);
266
+ if (!object) return undefined;
267
+ await object.content[Symbol.asyncIterator]().return?.();
268
+ return { type: object.type, size: object.size };
269
+ }
270
+
271
+ /** The whole content of a (small) object. */
272
+ private async read(id: ObjectId): Promise<{ type: string; bytes: Uint8Array } | undefined> {
273
+ const object = await this.objects.get(id).catch(() => undefined);
274
+ if (!object) return undefined;
275
+ if (object.bytes) {
276
+ await object.content[Symbol.asyncIterator]().return?.();
277
+ return { type: object.type, bytes: object.bytes };
278
+ }
279
+ const chunks: Uint8Array[] = [];
280
+ for await (const c of object.content) chunks.push(c.slice());
281
+ return { type: object.type, bytes: concat(chunks) };
282
+ }
283
+
284
+ /** `stream_blob`: the blob's content written chunk by chunk. */
285
+ private async streamBlob(id: ObjectId): Promise<void> {
286
+ const object = await this.objects.get(id).catch(() => undefined);
287
+ if (!object) throw new PlumbingError(`fatal: unable to stream ${id} to stdout`);
288
+ for await (const chunk of object.content) await this.write(chunk.slice());
289
+ }
290
+
291
+ private mailmapped?: Promise<(bytes: Uint8Array) => Uint8Array>;
292
+
293
+ /** `replace_idents_using_mailmap` (identity without `--use-mailmap`). */
294
+ private async mapIdents(bytes: Uint8Array): Promise<Uint8Array> {
295
+ if (!this.useMailmap) return bytes;
296
+ this.mailmapped ??= this.readMailmap().then(
297
+ (mailmap) => (raw: Uint8Array) => applyMailmapToHeader(raw, mailmap, MAILMAP_HEADERS),
298
+ );
299
+ return (await this.mailmapped)(bytes);
300
+ }
301
+
302
+ /** cat_one_file */
303
+ private async catOne(name: string): Promise<number> {
304
+ const compat = this.compatObjects;
305
+ // GET_OID_HASH_ANY: a full id of the compatibility format names the object as that
306
+ // format sees it (its storage object converted)
307
+ if (compat && name.length === compat.compat.hexLength && /^[0-9a-f]+$/.test(name)) {
308
+ return this.catOneCompat(name, compat);
309
+ }
310
+ const resolver = this.revisionResolver();
311
+ let id: ObjectId | undefined;
312
+ try {
313
+ id = await resolver.resolve(name, { onlyToDie: true });
314
+ } finally {
315
+ for (const line of resolver.warnings) this.warn(line);
316
+ resolver.warnings.length = 0;
317
+ }
318
+ if (id === undefined) throw new PlumbingError(`fatal: Not a valid object name ${name}`);
319
+ const couldNotGetInfo = () =>
320
+ new PlumbingError("fatal: git cat-file: could not get object info");
321
+ switch (this.mode) {
322
+ case "type": {
323
+ const info = await this.info(await this.replaced(id));
324
+ if (!info) throw couldNotGetInfo();
325
+ await this.write(`${info.type}\n`);
326
+ return 0;
327
+ }
328
+ case "size": {
329
+ const target = await this.replaced(id);
330
+ const info = await this.info(target);
331
+ if (!info) throw couldNotGetInfo();
332
+ let size = info.size;
333
+ if (this.useMailmap && (info.type === "commit" || info.type === "tag")) {
334
+ const object = await this.read(target);
335
+ if (object) size = (await this.mapIdents(object.bytes)).length;
336
+ }
337
+ await this.write(`${size}\n`);
338
+ return 0;
339
+ }
340
+ case "exists":
341
+ return (await this.objects.has(id)) ? 0 : 1;
342
+ case "pretty":
343
+ return this.pretty(name, await this.replaced(id));
344
+ default:
345
+ return this.catTyped(name, id, this.type as string);
346
+ }
347
+ }
348
+
349
+ /**
350
+ * cat_one_file for an id of the compatibility format: the object read through the map and
351
+ * converted (`odb_read_object_info_extended` with an id of the other format).
352
+ */
353
+ private async catOneCompat(name: string, compat: CompatObjects): Promise<number> {
354
+ const read = (id: string) => compat.readAsCompat(id);
355
+ if (this.mode === "exists")
356
+ return (await compat.toStorage(name)) !== undefined && (await read(name)) !== undefined
357
+ ? 0
358
+ : 1;
359
+ const object = await read(name);
360
+ if (!object) {
361
+ if (this.mode === "type" || this.mode === "size") {
362
+ throw new PlumbingError("fatal: git cat-file: could not get object info");
363
+ }
364
+ throw new PlumbingError(`fatal: Not a valid object name ${name}`);
365
+ }
366
+ switch (this.mode) {
367
+ case "type":
368
+ await this.write(`${object.type}\n`);
369
+ return 0;
370
+ case "size":
371
+ await this.write(`${object.content.length}\n`);
372
+ return 0;
373
+ case "pretty":
374
+ if (object.type === "tree") {
375
+ const config = RemoteConfigStore.from(this._workingCopy);
376
+ const quoteFully = parseGitBool(config.value("core.quotePath")) ?? true;
377
+ let out = "";
378
+ for (const entry of decodeTreeBytes(object.content, {
379
+ idLength: compat.compat.rawLength,
380
+ checkNames: false,
381
+ })) {
382
+ const kind = entry.mode & S_IFMT;
383
+ const type = kind === 0o040000 ? "tree" : kind === S_IFGITLINK ? "commit" : "blob";
384
+ const mode = entry.mode.toString(8).padStart(6, "0");
385
+ out += `${mode} ${type} ${entry.id}\t${quotePath(entry.name, quoteFully)}\n`;
386
+ }
387
+ await this.write(out);
388
+ return 0;
389
+ }
390
+ await this.write(
391
+ object.type === "blob" ? object.content : await this.mapIdents(object.content),
392
+ );
393
+ return 0;
394
+ default: {
395
+ const type = this.type as string;
396
+ if (!OBJECT_TYPES.has(type)) {
397
+ throw new PlumbingError(`fatal: invalid object type "${type}"`);
398
+ }
399
+ // odb_read_object_peeled, through the compatibility ids
400
+ let current: { type: string; content: Uint8Array } | undefined = object;
401
+ while (current && current.type !== type) {
402
+ const text = new TextDecoder().decode(current.content.subarray(0, 200));
403
+ let next: RegExpExecArray | null = null;
404
+ if (current.type === "tag") next = /^object ([0-9a-f]+)/.exec(text);
405
+ else if (current.type === "commit" && type === "tree") {
406
+ next = /^tree ([0-9a-f]+)/.exec(text);
407
+ }
408
+ current = next ? await read(next[1] as string) : undefined;
409
+ }
410
+ if (!current) throw new PlumbingError(`fatal: git cat-file ${name}: bad file`);
411
+ await this.write(
412
+ current.type === "blob" ? current.content : await this.mapIdents(current.content),
413
+ );
414
+ return 0;
415
+ }
416
+ }
417
+ }
418
+
419
+ /** `-p` */
420
+ private async pretty(name: string, id: ObjectId): Promise<number> {
421
+ const info = await this.info(id);
422
+ if (!info) throw new PlumbingError(`fatal: Not a valid object name ${name}`);
423
+ if (info.type === "tree") {
424
+ await this.listTree(id);
425
+ return 0;
426
+ }
427
+ if (info.type === "blob") {
428
+ await this.streamBlob(id);
429
+ return 0;
430
+ }
431
+ const object = await this.read(id);
432
+ if (!object) throw new PlumbingError(`fatal: Cannot read object ${name}`);
433
+ await this.write(await this.mapIdents(object.bytes));
434
+ return 0;
435
+ }
436
+
437
+ /** `git ls-tree <tree>`, as `-p` prints a tree. */
438
+ private async listTree(id: ObjectId): Promise<void> {
439
+ const config = RemoteConfigStore.from(this._workingCopy);
440
+ const quoteFully = parseGitBool(config.value("core.quotePath")) ?? true;
441
+ const entries = await this.listedTreeEntries(id);
442
+ if (!entries) throw new PlumbingError(`fatal: Cannot read object ${id}`);
443
+ let out = "";
444
+ for (const entry of entries) {
445
+ const kind = entry.mode & S_IFMT;
446
+ const type = kind === 0o040000 ? "tree" : kind === S_IFGITLINK ? "commit" : "blob";
447
+ const mode = entry.mode.toString(8).padStart(6, "0");
448
+ out += `${mode} ${type} ${entry.id}\t${quotePath(entry.name, quoteFully)}\n`;
449
+ if (out.length >= 1 << 16) {
450
+ await this.write(out);
451
+ out = "";
452
+ }
453
+ }
454
+ await this.write(out);
455
+ }
456
+
457
+ /** `<type> <object>` */
458
+ private async catTyped(name: string, id: ObjectId, type: string): Promise<number> {
459
+ if (!OBJECT_TYPES.has(type)) throw new PlumbingError(`fatal: invalid object type "${type}"`);
460
+ if (type === "blob") {
461
+ let blob = id;
462
+ const target = await this.replaced(id);
463
+ if ((await this.info(target))?.type === "tag") {
464
+ const tag = await this.read(target);
465
+ const match = tag && /^object ([0-9a-f]+)/.exec(new TextDecoder().decode(tag.bytes));
466
+ if (!match || !this.isFullObjectId(match[1] as string)) {
467
+ throw new PlumbingError(`fatal: ${id} not a valid tag`);
468
+ }
469
+ blob = match[1] as string;
470
+ }
471
+ const blobTarget = await this.replaced(blob);
472
+ if ((await this.info(blobTarget))?.type === "blob") {
473
+ await this.streamBlob(blobTarget);
474
+ return 0;
475
+ }
476
+ }
477
+ const bytes = await this.peeled(id, type);
478
+ if (!bytes) throw new PlumbingError(`fatal: git cat-file ${name}: bad file`);
479
+ await this.write(await this.mapIdents(bytes));
480
+ return 0;
481
+ }
482
+
483
+ /** `odb_read_object_peeled`: tags followed, a commit's tree for a tree. */
484
+ private async peeled(id: ObjectId, type: string): Promise<Uint8Array | undefined> {
485
+ let current = id;
486
+ for (;;) {
487
+ const object = await this.read(await this.replaced(current));
488
+ if (!object) return undefined;
489
+ if (object.type === type) return object.bytes;
490
+ const text = new TextDecoder().decode(object.bytes.subarray(0, 200));
491
+ let next: RegExpExecArray | null = null;
492
+ if (object.type === "tag") next = /^object ([0-9a-f]+)/.exec(text);
493
+ else if (object.type === "commit" && type === "tree") next = /^tree ([0-9a-f]+)/.exec(text);
494
+ if (!next || !this.isFullObjectId(next[1] as string)) return undefined;
495
+ current = next[1] as string;
496
+ }
497
+ }
498
+
499
+ /** batch_objects */
500
+ private async runBatch(): Promise<number> {
501
+ const compatibility = this.compatibility;
502
+ // --batch-command defers %(objectsize:disk)/%(deltabase) to the first local object: a
503
+ // remote-object-info line prints them empty, as git
504
+ const format = parseBatchFormat(this.format ?? DEFAULT_BATCH_FORMAT, compatibility, {
505
+ deferUnsupported: this.batch === "command",
506
+ });
507
+ const plain = this.format === undefined || this.format === DEFAULT_BATCH_FORMAT;
508
+ const state: BatchState = {
509
+ format,
510
+ plain,
511
+ delim: this.nulTerminated ? "\0" : "\n",
512
+ contents: this.batch === "contents",
513
+ replace: !this.allObjects,
514
+ };
515
+ if (this.allObjects) {
516
+ const ids: ObjectId[] = [];
517
+ for await (const id of this.objects.list()) ids.push(id);
518
+ const listed = this.unordered ? ids : [...new Set(ids)].sort();
519
+ const seen = new Set<ObjectId>();
520
+ for (const id of listed) {
521
+ if (seen.has(id)) continue;
522
+ seen.add(id);
523
+ await this.batchObjectWrite(state, undefined, { id });
524
+ }
525
+ return 0;
526
+ }
527
+ const resolver = this.revisionResolver();
528
+ const lines = readLines(this.stdin ?? "", this.nulTerminated || this.nulInput ? 0 : 0x0a);
529
+ if (this.batch === "command") {
530
+ await this.batchCommands(state, resolver, lines);
531
+ return 0;
532
+ }
533
+ for await (const line of lines) {
534
+ let name = line;
535
+ let rest: string | undefined;
536
+ if (format.splitOnWhitespace) {
537
+ const split = /[ \t]/.exec(line);
538
+ if (split) {
539
+ name = line.slice(0, split.index);
540
+ rest = line.slice(split.index).replace(/^[ \t]+/, "");
541
+ }
542
+ }
543
+ await this.batchOne(state, resolver, name, rest);
544
+ }
545
+ return 0;
546
+ }
547
+
548
+ /** batch_objects_command: `contents`, `info`, `flush` (and 2.5x's `mailmap`). */
549
+ private async batchCommands(
550
+ state: BatchState,
551
+ resolver: RevisionResolver,
552
+ lines: AsyncIterable<string>,
553
+ ): Promise<void> {
554
+ const buffer = this.buffer ?? false;
555
+ const commands =
556
+ this.compatibility === "2.43"
557
+ ? [
558
+ ["contents", true],
559
+ ["info", true],
560
+ ["flush", false],
561
+ ]
562
+ : [
563
+ ["contents", true],
564
+ ["flush", false],
565
+ ["info", true],
566
+ ["mailmap", true],
567
+ ["remote-object-info", true],
568
+ ];
569
+ const queue: { name: string; arg: string }[] = [];
570
+ const dispatch = async (name: string, arg: string) => {
571
+ if (name === "mailmap") {
572
+ const value = parseGitBool(arg);
573
+ if (value === undefined)
574
+ throw new PlumbingError(`fatal: mailmap: invalid boolean '${arg}'`);
575
+ this.useMailmap = value;
576
+ return;
577
+ }
578
+ if (name === "remote-object-info") {
579
+ await this.remoteObjectInfo(state, arg);
580
+ return;
581
+ }
582
+ await this.batchOne({ ...state, contents: name === "contents" }, resolver, arg, undefined);
583
+ };
584
+ const flush = async () => {
585
+ if (!buffer) throw new PlumbingError("fatal: flush is only for --buffer mode");
586
+ for (const call of queue.splice(0)) await dispatch(call.name, call.arg);
587
+ };
588
+ for await (const line of lines) {
589
+ if (line === "") throw new PlumbingError("fatal: empty command in input");
590
+ if (/^[ \t\n\v\f\r]/.test(line)) {
591
+ throw new PlumbingError(`fatal: whitespace before command: '${line}'`);
592
+ }
593
+ let found: { name: string; arg: string } | undefined;
594
+ for (const [name, takesArgs] of commands as [string, boolean][]) {
595
+ if (!line.startsWith(name)) continue;
596
+ const end = line.slice(name.length);
597
+ if (takesArgs) {
598
+ if (end[0] !== " ") throw new PlumbingError(`fatal: ${name} requires arguments`);
599
+ } else if (end !== "") {
600
+ throw new PlumbingError(`fatal: ${name} takes no arguments`);
601
+ }
602
+ found = { name, arg: end.slice(1) };
603
+ break;
604
+ }
605
+ if (!found) throw new PlumbingError(`fatal: unknown command: '${line}'`);
606
+ if (found.name === "flush") await flush();
607
+ else if (!buffer) await dispatch(found.name, found.arg);
608
+ else queue.push(found);
609
+ }
610
+ if (buffer && queue.length > 0) await flush();
611
+ }
612
+
613
+ /**
614
+ * parse_cmd_remote_object_info: `<remote> <id>...` split as git's `split_cmdline` (quotes
615
+ * and backslashes), the ids checked before the remote is asked, then one line per id in
616
+ * order: `<id> missing` for an object the server lacks, else the format with only the
617
+ * atoms the server answered (the default format prints the type and size it got).
618
+ */
619
+ private async remoteObjectInfo(state: BatchState, line: string): Promise<void> {
620
+ if (line.length >= MAX_REMOTE_OBJ_INFO_LINE) {
621
+ throw new PlumbingError("fatal: remote-object-info command too long");
622
+ }
623
+ const argv = splitCmdline(line);
624
+ if (typeof argv === "string") {
625
+ throw new PlumbingError(`fatal: remote-object-info: failed to parse command line: ${argv}`);
626
+ }
627
+ if (argv.length - 1 > MAX_ALLOWED_OBJ_LIMIT) {
628
+ throw new PlumbingError(
629
+ `fatal: remote-object-info supports at most ${MAX_ALLOWED_OBJ_LIMIT} objects`,
630
+ );
631
+ }
632
+ // get_remote_info: get_oid_hex reads the first hexsz digits (any case) and nothing after
633
+ const hexLength = this.objectFormat.hexLength;
634
+ const ids: string[] = [];
635
+ for (const arg of argv.slice(1)) {
636
+ const head = arg.slice(0, hexLength);
637
+ if (head.length === hexLength && /^[0-9a-fA-F]+$/.test(head)) {
638
+ ids.push(head.toLowerCase());
639
+ continue;
640
+ }
641
+ if (arg.length < hexLength && arg.length >= 4 && /^[0-9a-fA-F]+$/.test(arg)) {
642
+ throw new PlumbingError(
643
+ `fatal: remote-object-info does not support short oids, ${hexLength} characters required`,
644
+ );
645
+ }
646
+ throw new PlumbingError(`fatal: not a valid object name '${arg}'`);
647
+ }
648
+ if (ids.length === 0) throw new PlumbingError("fatal: remote-object-info requires objects");
649
+ const command = (
650
+ this.remoteObjectInfoFactory?.() ?? new RemoteObjectInfoCommand(this.workingCopy)
651
+ )
652
+ .setRemote(argv[0] as string)
653
+ .setSize(state.plain || state.format.needsSize)
654
+ .setType(state.plain || state.format.needsType);
655
+ for (const id of ids) command.addObjectId(id);
656
+ let answer: RemoteObjectInfoResult;
657
+ try {
658
+ answer = await command.call();
659
+ } catch (error) {
660
+ if (error instanceof ObjectInfoError || error instanceof RemoteObjectInfoUnsupportedError) {
661
+ throw new PlumbingError(`fatal: ${error.message}`);
662
+ }
663
+ throw error;
664
+ }
665
+ const remote = { size: answer.size, type: answer.type };
666
+ for (const object of answer.objects) {
667
+ if (object.missing) {
668
+ await this.write(`${object.id} missing${state.delim}`);
669
+ continue;
670
+ }
671
+ const data: BatchObjectData = {
672
+ id: object.id,
673
+ ...(object.type !== undefined ? { type: object.type } : {}),
674
+ ...(object.size !== undefined ? { size: object.size } : {}),
675
+ };
676
+ await this.write(
677
+ state.plain
678
+ ? `${data.id} ${data.type ?? ""} ${data.size ?? 0}${state.delim}`
679
+ : `${expandBatchFormat(state.format, data, remote)}${state.delim}`,
680
+ );
681
+ }
682
+ }
683
+
684
+ /** batch_one_object */
685
+ private async batchOne(
686
+ state: BatchState,
687
+ resolver: RevisionResolver,
688
+ name: string,
689
+ rest: string | undefined,
690
+ ): Promise<void> {
691
+ let id: ObjectId | undefined;
692
+ try {
693
+ id = await resolver.resolve(name);
694
+ } finally {
695
+ for (const line of resolver.warnings) this.warn(line);
696
+ }
697
+ const ambiguous = resolver.warnings.some((l) => l.startsWith("error: short object ID "));
698
+ resolver.warnings.length = 0;
699
+ if (id === undefined) {
700
+ await this.write(`${name} ${ambiguous ? "ambiguous" : "missing"}${state.delim}`);
701
+ return;
702
+ }
703
+ await this.batchObjectWrite(state, name, {
704
+ id,
705
+ ...(resolver.lastMode !== undefined ? { mode: resolver.lastMode } : {}),
706
+ ...(rest !== undefined ? { rest } : {}),
707
+ });
708
+ }
709
+
710
+ /** batch_object_write */
711
+ private async batchObjectWrite(
712
+ state: BatchState,
713
+ name: string | undefined,
714
+ data: BatchObjectData,
715
+ ): Promise<void> {
716
+ const target = state.replace ? await this.replaced(data.id) : data.id;
717
+ const info = await this.info(target);
718
+ if (!info) {
719
+ if (this.compatibility !== "2.43" && data.mode !== undefined) {
720
+ if ((data.mode & S_IFMT) === S_IFGITLINK) {
721
+ await this.write(`${data.id} submodule${state.delim}`);
722
+ return;
723
+ }
724
+ }
725
+ await this.write(`${name ?? data.id} missing${state.delim}`);
726
+ return;
727
+ }
728
+ data.type = info.type;
729
+ data.size = info.size;
730
+ let content: Uint8Array | undefined;
731
+ if (this.useMailmap && (info.type === "commit" || info.type === "tag")) {
732
+ const object = await this.read(target);
733
+ if (!object) throw new PlumbingError(`fatal: unable to read ${data.id}`);
734
+ content = await this.mapIdents(object.bytes);
735
+ data.size = content.length;
736
+ }
737
+ const header = state.plain
738
+ ? `${data.id} ${data.type} ${data.size}${state.delim}`
739
+ : `${expandBatchFormat(state.format, data)}${state.delim}`;
740
+ await this.write(header);
741
+ if (!state.contents) return;
742
+ if (info.type === "blob") {
743
+ await this.streamBlob(target);
744
+ } else {
745
+ if (!content) {
746
+ const object = await this.read(target);
747
+ if (!object) throw new PlumbingError(`fatal: object ${data.id} disappeared`);
748
+ content = object.bytes;
749
+ }
750
+ await this.write(content);
751
+ }
752
+ await this.write(state.delim);
753
+ }
754
+ }
755
+
756
+ interface BatchState {
757
+ format: BatchFormat;
758
+ /** No format, or the default one: git's print_default_format */
759
+ plain: boolean;
760
+ delim: string;
761
+ /** `--batch`, or a `contents` command: the content follows the header */
762
+ contents: boolean;
763
+ /** Replace refs apply (not under `--batch-all-objects`) */
764
+ replace: boolean;
765
+ }
766
+
767
+ /** cat-file.c's MAX_ALLOWED_OBJ_LIMIT: ids one remote-object-info line may ask about. */
768
+ const MAX_ALLOWED_OBJ_LIMIT = 10000;
769
+
770
+ /** cat-file.c's MAX_REMOTE_OBJ_INFO_LINE: a URL of 8 KiB and the ids (GIT_MAX_HEXSZ + 1 each). */
771
+ const MAX_REMOTE_OBJ_INFO_LINE = 8 * 1024 + MAX_ALLOWED_OBJ_LIMIT * (64 + 1);
772
+
773
+ /**
774
+ * alias.c's split_cmdline: words split on whitespace, quotes removed, a backslash escaping
775
+ * the next character outside single quotes; split_cmdline_strerror's text on an error.
776
+ */
777
+ function splitCmdline(line: string): string[] | string {
778
+ // one word to begin with; every whitespace run ends one and starts the next (a trailing
779
+ // run leaves an empty last word, as git's)
780
+ const args: string[] = [];
781
+ let current = "";
782
+ let quoted = "";
783
+ for (let i = 0; i < line.length; i++) {
784
+ const c = line[i] as string;
785
+ if (!quoted && /[ \t\n\r]/.test(c)) {
786
+ args.push(current);
787
+ current = "";
788
+ while (i + 1 < line.length && /[ \t\n\r]/.test(line[i + 1] as string)) i++;
789
+ } else if (!quoted && (c === "'" || c === '"')) {
790
+ quoted = c;
791
+ } else if (c === quoted) {
792
+ quoted = "";
793
+ } else {
794
+ if (c === "\\" && quoted !== "'") {
795
+ i++;
796
+ if (i >= line.length) return "cmdline ends with \\";
797
+ }
798
+ current += line[i];
799
+ }
800
+ }
801
+ if (quoted) return "unclosed quote";
802
+ args.push(current);
803
+ return args;
804
+ }
805
+
806
+ function modeLetter(mode: CatFileMode): string {
807
+ return mode === "type" ? "t" : mode === "size" ? "s" : mode === "exists" ? "e" : "p";
808
+ }
809
+
810
+ function concat(chunks: Uint8Array[]): Uint8Array {
811
+ if (chunks.length === 1) return chunks[0] as Uint8Array;
812
+ let size = 0;
813
+ for (const c of chunks) size += c.length;
814
+ const out = new Uint8Array(size);
815
+ let at = 0;
816
+ for (const c of chunks) {
817
+ out.set(c, at);
818
+ at += c.length;
819
+ }
820
+ return out;
821
+ }
822
+
823
+ /**
824
+ * `strbuf_getline` (`strbuf_getdelim_strip_crlf`) over the input as it arrives: each record
825
+ * without its delimiter, and for newline-terminated input without a CR before it (`-z`'s
826
+ * `strbuf_getline_nul` keeps the CR); a last record without a delimiter is read too.
827
+ * Records are bytes: they are decoded as git paths ({@link decodeGitPath}), so a name that
828
+ * is not UTF-8 resolves and is echoed (`<name> missing`) with its bytes.
829
+ */
830
+ async function* readLines(input: CatFileInput, delimiter: number): AsyncGenerator<string> {
831
+ const chunks: AsyncIterable<Uint8Array> | Iterable<Uint8Array> =
832
+ typeof input === "string"
833
+ ? [encoder.encode(input)]
834
+ : input instanceof Uint8Array
835
+ ? [input]
836
+ : input;
837
+ let pending: Uint8Array[] = [];
838
+ const emit = (bytes: Uint8Array) => {
839
+ let end = bytes.length;
840
+ if (delimiter === 0x0a && end > 0 && bytes[end - 1] === 0x0d) end--;
841
+ return decodeGitPath(bytes.subarray(0, end));
842
+ };
843
+ for await (const chunk of chunks) {
844
+ let start = 0;
845
+ for (;;) {
846
+ const at = chunk.indexOf(delimiter, start);
847
+ if (at < 0) break;
848
+ const piece = chunk.subarray(start, at);
849
+ const line = pending.length > 0 ? concat([...pending, piece]) : piece;
850
+ pending = [];
851
+ yield emit(line);
852
+ start = at + 1;
853
+ }
854
+ if (start < chunk.length) pending.push(chunk.slice(start));
855
+ }
856
+ if (pending.length > 0) yield emit(concat(pending));
857
+ }