@statewalker/vcs-commands 0.9.0 → 0.11.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 (468) 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 +144 -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 +28 -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 +54 -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 +60 -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-ipc.d.ts +30 -0
  109. package/dist/commands/fsmonitor-ipc.d.ts.map +1 -0
  110. package/dist/commands/fsmonitor-refresh.d.ts +69 -0
  111. package/dist/commands/fsmonitor-refresh.d.ts.map +1 -0
  112. package/dist/commands/gc-command.d.ts +5 -0
  113. package/dist/commands/gc-command.d.ts.map +1 -1
  114. package/dist/commands/git-hooks.d.ts +32 -0
  115. package/dist/commands/git-hooks.d.ts.map +1 -1
  116. package/dist/commands/git-paths.d.ts +26 -0
  117. package/dist/commands/git-paths.d.ts.map +1 -0
  118. package/dist/commands/grep/grep-command.d.ts +2 -1
  119. package/dist/commands/grep/grep-command.d.ts.map +1 -1
  120. package/dist/commands/history-command.d.ts +156 -0
  121. package/dist/commands/history-command.d.ts.map +1 -0
  122. package/dist/commands/http-config.d.ts +38 -0
  123. package/dist/commands/http-config.d.ts.map +1 -0
  124. package/dist/commands/index-adder.d.ts +12 -1
  125. package/dist/commands/index-adder.d.ts.map +1 -1
  126. package/dist/commands/index-host.d.ts.map +1 -1
  127. package/dist/commands/index.d.ts +45 -1
  128. package/dist/commands/index.d.ts.map +1 -1
  129. package/dist/commands/index.js +6 -5
  130. package/dist/commands/init-command.d.ts.map +1 -1
  131. package/dist/commands/last-modified-command.d.ts +102 -0
  132. package/dist/commands/last-modified-command.d.ts.map +1 -0
  133. package/dist/commands/lfs/go-url.d.ts +43 -0
  134. package/dist/commands/lfs/go-url.d.ts.map +1 -0
  135. package/dist/commands/lfs/index.d.ts +3 -0
  136. package/dist/commands/lfs/index.d.ts.map +1 -0
  137. package/dist/commands/lfs/lfs-config.d.ts +174 -0
  138. package/dist/commands/lfs/lfs-config.d.ts.map +1 -0
  139. package/dist/commands/lfs/lfs-endpoint-command.d.ts +83 -0
  140. package/dist/commands/lfs/lfs-endpoint-command.d.ts.map +1 -0
  141. package/dist/commands/local-transport.d.ts.map +1 -1
  142. package/dist/commands/log-command.d.ts +26 -0
  143. package/dist/commands/log-command.d.ts.map +1 -1
  144. package/dist/commands/log-output.d.ts +28 -1
  145. package/dist/commands/log-output.d.ts.map +1 -1
  146. package/dist/commands/ls-files-command.d.ts +153 -0
  147. package/dist/commands/ls-files-command.d.ts.map +1 -0
  148. package/dist/commands/ls-remote-command.d.ts +5 -0
  149. package/dist/commands/ls-remote-command.d.ts.map +1 -1
  150. package/dist/commands/ls-tree-command.d.ts +105 -0
  151. package/dist/commands/ls-tree-command.d.ts.map +1 -0
  152. package/dist/commands/maintenance-run-command.d.ts +122 -0
  153. package/dist/commands/maintenance-run-command.d.ts.map +1 -0
  154. package/dist/commands/merge-command.d.ts +7 -0
  155. package/dist/commands/merge-command.d.ts.map +1 -1
  156. package/dist/commands/merge-config.d.ts +7 -0
  157. package/dist/commands/merge-config.d.ts.map +1 -1
  158. package/dist/commands/merge-drivers.d.ts +67 -5
  159. package/dist/commands/merge-drivers.d.ts.map +1 -1
  160. package/dist/commands/merge-support.d.ts +6 -0
  161. package/dist/commands/merge-support.d.ts.map +1 -1
  162. package/dist/commands/merge-tree-command.d.ts +122 -0
  163. package/dist/commands/merge-tree-command.d.ts.map +1 -0
  164. package/dist/commands/mktag-command.d.ts +51 -0
  165. package/dist/commands/mktag-command.d.ts.map +1 -0
  166. package/dist/commands/object-store/count-objects-command.d.ts +58 -0
  167. package/dist/commands/object-store/count-objects-command.d.ts.map +1 -0
  168. package/dist/commands/object-store/index.d.ts +5 -0
  169. package/dist/commands/object-store/index.d.ts.map +1 -0
  170. package/dist/commands/object-store/objects-directory.d.ts +12 -0
  171. package/dist/commands/object-store/objects-directory.d.ts.map +1 -0
  172. package/dist/commands/object-store/prune-command.d.ts +38 -0
  173. package/dist/commands/object-store/prune-command.d.ts.map +1 -0
  174. package/dist/commands/object-store/show-index-command.d.ts +23 -0
  175. package/dist/commands/object-store/show-index-command.d.ts.map +1 -0
  176. package/dist/commands/ort-merge.d.ts +24 -0
  177. package/dist/commands/ort-merge.d.ts.map +1 -1
  178. package/dist/commands/patch-id-command.d.ts +30 -0
  179. package/dist/commands/patch-id-command.d.ts.map +1 -0
  180. package/dist/commands/patch-id.d.ts +24 -0
  181. package/dist/commands/patch-id.d.ts.map +1 -1
  182. package/dist/commands/plumbing-command.d.ts +66 -0
  183. package/dist/commands/plumbing-command.d.ts.map +1 -0
  184. package/dist/commands/plumbing-input.d.ts +38 -0
  185. package/dist/commands/plumbing-input.d.ts.map +1 -0
  186. package/dist/commands/promisor-remote-reply.d.ts +35 -0
  187. package/dist/commands/promisor-remote-reply.d.ts.map +1 -0
  188. package/dist/commands/promisor-remote.d.ts.map +1 -1
  189. package/dist/commands/pull-command.d.ts.map +1 -1
  190. package/dist/commands/push-command.d.ts +17 -2
  191. package/dist/commands/push-command.d.ts.map +1 -1
  192. package/dist/commands/rebase-command.d.ts +108 -2
  193. package/dist/commands/rebase-command.d.ts.map +1 -1
  194. package/dist/commands/refs-command.d.ts +81 -0
  195. package/dist/commands/refs-command.d.ts.map +1 -0
  196. package/dist/commands/remote-object-info-command.d.ts +55 -0
  197. package/dist/commands/remote-object-info-command.d.ts.map +1 -0
  198. package/dist/commands/remote-transport.d.ts +40 -3
  199. package/dist/commands/remote-transport.d.ts.map +1 -1
  200. package/dist/commands/repack-command.d.ts +115 -0
  201. package/dist/commands/repack-command.d.ts.map +1 -0
  202. package/dist/commands/replace-command.d.ts +143 -0
  203. package/dist/commands/replace-command.d.ts.map +1 -0
  204. package/dist/commands/replay-command.d.ts +117 -0
  205. package/dist/commands/replay-command.d.ts.map +1 -0
  206. package/dist/commands/repo-command.d.ts +158 -0
  207. package/dist/commands/repo-command.d.ts.map +1 -0
  208. package/dist/commands/request-pull-command.d.ts +82 -0
  209. package/dist/commands/request-pull-command.d.ts.map +1 -0
  210. package/dist/commands/rerere-command.d.ts +36 -0
  211. package/dist/commands/rerere-command.d.ts.map +1 -0
  212. package/dist/commands/rerere.d.ts +102 -0
  213. package/dist/commands/rerere.d.ts.map +1 -0
  214. package/dist/commands/reset-command.d.ts +19 -2
  215. package/dist/commands/reset-command.d.ts.map +1 -1
  216. package/dist/commands/rev-filter/commit-grep.d.ts +3 -1
  217. package/dist/commands/rev-filter/commit-grep.d.ts.map +1 -1
  218. package/dist/commands/rev-list-command.d.ts +3 -0
  219. package/dist/commands/rev-list-command.d.ts.map +1 -1
  220. package/dist/commands/rev-parse-command.d.ts +5 -0
  221. package/dist/commands/rev-parse-command.d.ts.map +1 -1
  222. package/dist/commands/revert-command.d.ts +10 -0
  223. package/dist/commands/revert-command.d.ts.map +1 -1
  224. package/dist/commands/revision-range.d.ts +5 -0
  225. package/dist/commands/revision-range.d.ts.map +1 -1
  226. package/dist/commands/revision-resolver.d.ts +27 -1
  227. package/dist/commands/revision-resolver.d.ts.map +1 -1
  228. package/dist/commands/sequencer-pick.d.ts +18 -0
  229. package/dist/commands/sequencer-pick.d.ts.map +1 -1
  230. package/dist/commands/serve-repository.d.ts +23 -1
  231. package/dist/commands/serve-repository.d.ts.map +1 -1
  232. package/dist/commands/session-id.d.ts +18 -0
  233. package/dist/commands/session-id.d.ts.map +1 -0
  234. package/dist/commands/show-branch-command.d.ts +59 -0
  235. package/dist/commands/show-branch-command.d.ts.map +1 -0
  236. package/dist/commands/show-ref-command.d.ts +112 -0
  237. package/dist/commands/show-ref-command.d.ts.map +1 -0
  238. package/dist/commands/signature-check.d.ts +9 -2
  239. package/dist/commands/signature-check.d.ts.map +1 -1
  240. package/dist/commands/signing.d.ts +30 -2
  241. package/dist/commands/signing.d.ts.map +1 -1
  242. package/dist/commands/stash-apply-command.d.ts.map +1 -1
  243. package/dist/commands/stash-export-command.d.ts +115 -0
  244. package/dist/commands/stash-export-command.d.ts.map +1 -0
  245. package/dist/commands/status-command.d.ts +16 -2
  246. package/dist/commands/status-command.d.ts.map +1 -1
  247. package/dist/commands/stripspace-command.d.ts +44 -0
  248. package/dist/commands/stripspace-command.d.ts.map +1 -0
  249. package/dist/commands/submodule-add-command.d.ts +22 -1
  250. package/dist/commands/submodule-add-command.d.ts.map +1 -1
  251. package/dist/commands/submodule-auth.d.ts +3 -1
  252. package/dist/commands/submodule-auth.d.ts.map +1 -1
  253. package/dist/commands/submodule-commands.d.ts +9 -1
  254. package/dist/commands/submodule-commands.d.ts.map +1 -1
  255. package/dist/commands/submodule-update-command.d.ts +27 -1
  256. package/dist/commands/submodule-update-command.d.ts.map +1 -1
  257. package/dist/commands/tag-command.d.ts.map +1 -1
  258. package/dist/commands/textconv-cache.d.ts +58 -0
  259. package/dist/commands/textconv-cache.d.ts.map +1 -0
  260. package/dist/commands/tree-restore.d.ts +5 -0
  261. package/dist/commands/tree-restore.d.ts.map +1 -1
  262. package/dist/commands/unpack-objects-command.d.ts +47 -0
  263. package/dist/commands/unpack-objects-command.d.ts.map +1 -0
  264. package/dist/commands/update-index-command.d.ts +131 -0
  265. package/dist/commands/update-index-command.d.ts.map +1 -0
  266. package/dist/commands/uri-protocols.d.ts +13 -0
  267. package/dist/commands/uri-protocols.d.ts.map +1 -0
  268. package/dist/commands/url-parse-command.d.ts +30 -0
  269. package/dist/commands/url-parse-command.d.ts.map +1 -0
  270. package/dist/commands/var-command.d.ts +42 -0
  271. package/dist/commands/var-command.d.ts.map +1 -0
  272. package/dist/{commands-CNvli5bl.js → commands-bQQ9OmCh.js} +52514 -44630
  273. package/dist/errors/command-errors.d.ts +33 -0
  274. package/dist/errors/command-errors.d.ts.map +1 -1
  275. package/dist/errors/index.js +39 -1
  276. package/dist/{fsck-CPeDh9fh.js → fsck-BHT9bUS-.js} +184 -143
  277. package/dist/git-command.d.ts +66 -4
  278. package/dist/git-command.d.ts.map +1 -1
  279. package/dist/git.d.ts +532 -1
  280. package/dist/git.d.ts.map +1 -1
  281. package/dist/guarded-transport-command.d.ts +3 -1
  282. package/dist/guarded-transport-command.d.ts.map +1 -1
  283. package/dist/index.js +7 -6
  284. package/dist/maintenance-run-command-Cx2PlGV9.js +13544 -0
  285. package/dist/{remote-transport-CCmBadm-.js → remote-transport-BrQZfyHu.js} +1009 -10
  286. package/dist/results/cherry-pick-result.d.ts +6 -0
  287. package/dist/results/cherry-pick-result.d.ts.map +1 -1
  288. package/dist/results/diff-entry.d.ts +10 -0
  289. package/dist/results/diff-entry.d.ts.map +1 -1
  290. package/dist/results/diff-formatter.d.ts.map +1 -1
  291. package/dist/results/diff-output.d.ts +49 -3
  292. package/dist/results/diff-output.d.ts.map +1 -1
  293. package/dist/results/fetch-result.d.ts +12 -0
  294. package/dist/results/fetch-result.d.ts.map +1 -1
  295. package/dist/results/index.js +2 -2
  296. package/dist/results/merge-result.d.ts +5 -0
  297. package/dist/results/merge-result.d.ts.map +1 -1
  298. package/dist/results/push-result.d.ts +5 -0
  299. package/dist/results/push-result.d.ts.map +1 -1
  300. package/dist/results/rebase-result.d.ts +7 -0
  301. package/dist/results/rebase-result.d.ts.map +1 -1
  302. package/dist/results/revert-result.d.ts +6 -0
  303. package/dist/results/revert-result.d.ts.map +1 -1
  304. package/dist/results/stash-result.d.ts +5 -0
  305. package/dist/results/stash-result.d.ts.map +1 -1
  306. package/dist/{results-BDuEgdLU.js → results-CNHQnU5Y.js} +13707 -10608
  307. package/dist/transport-command.d.ts +79 -1
  308. package/dist/transport-command.d.ts.map +1 -1
  309. package/package.json +13 -13
  310. package/src/commands/add-command.ts +3 -0
  311. package/src/commands/add-patch/patch-backend.ts +4 -1
  312. package/src/commands/add-patch/patch-modes.ts +26 -2
  313. package/src/commands/add-patch/patch-session.ts +6 -0
  314. package/src/commands/am/am-command.ts +193 -22
  315. package/src/commands/apply/index.ts +1 -0
  316. package/src/commands/archive/archive-command.ts +1148 -0
  317. package/src/commands/archive/archive-entry.ts +93 -0
  318. package/src/commands/archive/index.ts +7 -0
  319. package/src/commands/archive/remote-archive-command.ts +140 -0
  320. package/src/commands/archive/tar-archive.ts +207 -0
  321. package/src/commands/archive/tar-commit-id.ts +72 -0
  322. package/src/commands/archive/upload-archive-writer.ts +213 -0
  323. package/src/commands/archive/zip-archive.ts +317 -0
  324. package/src/commands/attributes-source.ts +26 -12
  325. package/src/commands/blame-command.ts +118 -19
  326. package/src/commands/bundle/bundle-create-command.ts +405 -0
  327. package/src/commands/bundle/bundle-format.ts +228 -0
  328. package/src/commands/bundle/bundle-list.ts +276 -0
  329. package/src/commands/bundle/bundle-read-commands.ts +157 -0
  330. package/src/commands/bundle/bundle-support.ts +85 -0
  331. package/src/commands/bundle/bundle-transport.ts +107 -0
  332. package/src/commands/bundle/bundle-uri-host.ts +204 -0
  333. package/src/commands/bundle/bundle-uri.ts +236 -0
  334. package/src/commands/bundle/bundle-verify.ts +152 -0
  335. package/src/commands/bundle/index.ts +14 -0
  336. package/src/commands/cat-file/batch-format.ts +193 -0
  337. package/src/commands/cat-file/cat-file-command.ts +895 -0
  338. package/src/commands/cat-file/index.ts +2 -0
  339. package/src/commands/check-attr-command.ts +333 -0
  340. package/src/commands/check-ignore-command.ts +261 -0
  341. package/src/commands/check-ref-format-command.ts +129 -0
  342. package/src/commands/checkout-command.ts +61 -22
  343. package/src/commands/checkout-index-command.ts +568 -0
  344. package/src/commands/checkout-paths.ts +7 -0
  345. package/src/commands/cherry-pick-command.ts +21 -1
  346. package/src/commands/clone-command.ts +249 -9
  347. package/src/commands/commit-command.ts +22 -4
  348. package/src/commands/config-command.ts +9 -0
  349. package/src/commands/daemon-access-hook.ts +78 -0
  350. package/src/commands/default-branch.ts +118 -1
  351. package/src/commands/diff-command.ts +592 -47
  352. package/src/commands/diff-external.ts +131 -0
  353. package/src/commands/diff-plumbing/diff-pairs-command.ts +193 -0
  354. package/src/commands/diff-plumbing/diff-plumbing-command.ts +424 -0
  355. package/src/commands/diff-plumbing/index.ts +2 -0
  356. package/src/commands/diff-textconv.ts +5 -1
  357. package/src/commands/fast-export/fast-export-command.ts +911 -0
  358. package/src/commands/fast-export/fast-import-command.ts +1553 -0
  359. package/src/commands/fast-export/fast-stream-support.ts +162 -0
  360. package/src/commands/fast-export/index.ts +3 -0
  361. package/src/commands/fetch-command.ts +312 -8
  362. package/src/commands/fetch-multiple-command.ts +4 -1
  363. package/src/commands/format-rev-command.ts +267 -0
  364. package/src/commands/fsck/fsck-command.ts +47 -20
  365. package/src/commands/fsck/fsck-msg-ids.ts +19 -3
  366. package/src/commands/fsck/fsck-pack.ts +2 -2
  367. package/src/commands/fsmonitor-ipc.ts +121 -0
  368. package/src/commands/fsmonitor-refresh.ts +320 -0
  369. package/src/commands/gc-command.ts +10 -0
  370. package/src/commands/git-hooks.ts +123 -6
  371. package/src/commands/git-paths.ts +136 -0
  372. package/src/commands/grep/grep-command.ts +38 -15
  373. package/src/commands/history-command.ts +617 -0
  374. package/src/commands/http-config.ts +139 -0
  375. package/src/commands/index-adder.ts +37 -3
  376. package/src/commands/index-host.ts +6 -1
  377. package/src/commands/index.ts +46 -0
  378. package/src/commands/init-command.ts +14 -0
  379. package/src/commands/last-modified-command.ts +804 -0
  380. package/src/commands/lfs/go-url.ts +370 -0
  381. package/src/commands/lfs/index.ts +2 -0
  382. package/src/commands/lfs/lfs-config.ts +738 -0
  383. package/src/commands/lfs/lfs-endpoint-command.ts +180 -0
  384. package/src/commands/local-transport.ts +252 -4
  385. package/src/commands/log-command.ts +104 -5
  386. package/src/commands/log-output.ts +66 -5
  387. package/src/commands/ls-files-command.ts +1177 -0
  388. package/src/commands/ls-remote-command.ts +6 -0
  389. package/src/commands/ls-tree-command.ts +708 -0
  390. package/src/commands/maintenance-run-command.ts +949 -0
  391. package/src/commands/merge-command.ts +78 -32
  392. package/src/commands/merge-config.ts +23 -1
  393. package/src/commands/merge-drivers.ts +109 -20
  394. package/src/commands/merge-support.ts +29 -5
  395. package/src/commands/merge-tree-command.ts +786 -0
  396. package/src/commands/mktag-command.ts +149 -0
  397. package/src/commands/object-store/count-objects-command.ts +404 -0
  398. package/src/commands/object-store/index.ts +4 -0
  399. package/src/commands/object-store/objects-directory.ts +24 -0
  400. package/src/commands/object-store/prune-command.ts +129 -0
  401. package/src/commands/object-store/show-index-command.ts +151 -0
  402. package/src/commands/ort-merge.ts +92 -25
  403. package/src/commands/patch-id-command.ts +65 -0
  404. package/src/commands/patch-id.ts +218 -0
  405. package/src/commands/plumbing-command.ts +141 -0
  406. package/src/commands/plumbing-input.ts +87 -0
  407. package/src/commands/promisor-remote-reply.ts +276 -0
  408. package/src/commands/promisor-remote.ts +25 -2
  409. package/src/commands/pull-command.ts +2 -0
  410. package/src/commands/push-command.ts +87 -5
  411. package/src/commands/rebase-command.ts +507 -19
  412. package/src/commands/refs-command.ts +274 -0
  413. package/src/commands/remote-object-info-command.ts +109 -0
  414. package/src/commands/remote-transport.ts +116 -1
  415. package/src/commands/repack-command.ts +383 -0
  416. package/src/commands/replace-command.ts +816 -0
  417. package/src/commands/replay-command.ts +674 -0
  418. package/src/commands/repo-command.ts +1066 -0
  419. package/src/commands/request-pull-command.ts +356 -0
  420. package/src/commands/rerere-command.ts +179 -0
  421. package/src/commands/rerere.ts +925 -0
  422. package/src/commands/reset-command.ts +75 -3
  423. package/src/commands/rev-filter/commit-grep.ts +7 -2
  424. package/src/commands/rev-list-command.ts +9 -0
  425. package/src/commands/rev-parse-command.ts +49 -5
  426. package/src/commands/revert-command.ts +21 -1
  427. package/src/commands/revision-range.ts +7 -2
  428. package/src/commands/revision-resolver.ts +97 -14
  429. package/src/commands/sequencer-pick.ts +47 -0
  430. package/src/commands/serve-repository.ts +65 -0
  431. package/src/commands/session-id.ts +31 -0
  432. package/src/commands/show-branch-command.ts +981 -0
  433. package/src/commands/show-command.ts +1 -1
  434. package/src/commands/show-ref-command.ts +439 -0
  435. package/src/commands/signature-check.ts +37 -5
  436. package/src/commands/signing.ts +176 -23
  437. package/src/commands/stash-apply-command.ts +3 -0
  438. package/src/commands/stash-export-command.ts +397 -0
  439. package/src/commands/status-command.ts +74 -8
  440. package/src/commands/stripspace-command.ts +118 -0
  441. package/src/commands/submodule-add-command.ts +40 -2
  442. package/src/commands/submodule-auth.ts +61 -6
  443. package/src/commands/submodule-commands.ts +12 -2
  444. package/src/commands/submodule-update-command.ts +47 -1
  445. package/src/commands/tag-command.ts +33 -11
  446. package/src/commands/textconv-cache.ts +143 -0
  447. package/src/commands/tree-restore.ts +14 -0
  448. package/src/commands/unpack-objects-command.ts +235 -0
  449. package/src/commands/update-index-command.ts +1148 -0
  450. package/src/commands/uri-protocols.ts +13 -0
  451. package/src/commands/url-parse-command.ts +67 -0
  452. package/src/commands/var-command.ts +219 -0
  453. package/src/errors/command-errors.ts +45 -0
  454. package/src/git-command.ts +177 -3
  455. package/src/git.ts +808 -1
  456. package/src/guarded-transport-command.ts +6 -1
  457. package/src/results/cherry-pick-result.ts +6 -0
  458. package/src/results/diff-entry.ts +12 -0
  459. package/src/results/diff-formatter.ts +7 -4
  460. package/src/results/diff-output.ts +117 -11
  461. package/src/results/diff-pickaxe.ts +1 -1
  462. package/src/results/fetch-result.ts +12 -0
  463. package/src/results/merge-result.ts +5 -0
  464. package/src/results/push-result.ts +5 -0
  465. package/src/results/rebase-result.ts +7 -0
  466. package/src/results/revert-result.ts +6 -0
  467. package/src/results/stash-result.ts +6 -0
  468. package/src/transport-command.ts +182 -1
@@ -0,0 +1,708 @@
1
+ /**
2
+ * `git ls-tree` (builtin/ls-tree.c): the entries of a tree, byte for byte as git prints them.
3
+ *
4
+ * @example
5
+ * ```typescript
6
+ * // git ls-tree -r --name-only HEAD src/
7
+ * const { stdout } = await git.lsTree().setTreeish("HEAD").setRecursive(true)
8
+ * .setNameOnly().addPaths("src/").callOutput();
9
+ * ```
10
+ */
11
+
12
+ import { parseGitBool } from "@statewalker/vcs-utils";
13
+ import { encodeGitPath } from "@statewalker/vcs-utils/encoding";
14
+ import { RefNotFoundError } from "../errors/index.js";
15
+ import { RemoteConfigStore } from "../remote-config/index.js";
16
+ import { quoteCStyleBody } from "../results/quote-path.js";
17
+ import { prefixPathGently, relativePath } from "./git-paths.js";
18
+ import {
19
+ ALL_ENTRIES_INTERESTING,
20
+ ALL_ENTRIES_NOT_INTERESTING,
21
+ ENTRY_NOT_INTERESTING,
22
+ latin1Bytes,
23
+ latin1String,
24
+ type PathspecItem,
25
+ pathspecItemBytes,
26
+ type TreePathspec,
27
+ treeEntryInteresting,
28
+ treePathspec,
29
+ } from "./pathspec.js";
30
+ import { PlumbingCommand, PlumbingError } from "./plumbing-command.js";
31
+
32
+ /** ls-tree's `cmdmode`: the output options that exclude one another. */
33
+ export type LsTreeMode = "long" | "name-only" | "name-status" | "object-only";
34
+
35
+ /** The fast paths ls-tree takes for a `--format` equal to a mode's own format. */
36
+ const MODE_FORMATS: ["default" | "long" | "name-only" | "object-only", string][] = [
37
+ ["default", "%(objectmode) %(objecttype) %(objectname)%x09%(path)"],
38
+ ["long", "%(objectmode) %(objecttype) %(objectname) %(objectsize:padded)%x09%(path)"],
39
+ ["name-only", "%(path)"],
40
+ ["object-only", "%(objectname)"],
41
+ ];
42
+
43
+ const USAGE = "usage: git ls-tree [<options>] <tree-ish> [<path>...]";
44
+
45
+ /** pathspec.c's `pathspec_magic`: the bits, mnemonics and names, in its order */
46
+ const MAGIC = [
47
+ { name: "top", mnemonic: "/" },
48
+ { name: "literal", mnemonic: "" },
49
+ { name: "glob", mnemonic: "" },
50
+ { name: "icase", mnemonic: "" },
51
+ { name: "exclude", mnemonic: "!" },
52
+ { name: "attr", mnemonic: "" },
53
+ ] as const;
54
+
55
+ /** ctype.c's GIT_PATHSPEC_MAGIC characters (and `/`, `^`) */
56
+ const SHORT_MAGIC = new Set([..."!\"#%&',-;<=>@_`~^/"]);
57
+
58
+ const FLUSH_AT = 64 * 1024;
59
+
60
+ /**
61
+ * `git ls-tree [<options>] <tree-ish> [<path>...]`.
62
+ *
63
+ * Paths are ls-tree's own: literal pathspecs (only `:(top)` and `:(literal)` magic), a tree
64
+ * shown or entered by leading path components (`show_recursive`), not wildcard matches.
65
+ * Output paths are relative to {@link setPrefix} unless `--full-name`/`--full-tree`.
66
+ *
67
+ * git 2.43 (`setCompatibility("2.43")`) words the conflict of two output modes as
68
+ * `error: <b> is incompatible with <a>`, 2.45 and later as `error: options '<b>' and '<a>'
69
+ * cannot be used together`. Usage errors exit 129 with that first line only (git prints its
70
+ * usage after it).
71
+ */
72
+ export class LsTreeCommand extends PlumbingCommand {
73
+ private treeish?: string;
74
+ private readonly paths: string[] = [];
75
+ private treesOnly = false;
76
+ private recursive = false;
77
+ private showTrees = false;
78
+ private nul = false;
79
+ private readonly modes: { mode: LsTreeMode; option: string }[] = [];
80
+ private fullName?: boolean;
81
+ private fullTree = false;
82
+ private format?: string;
83
+ private abbrev = 0;
84
+ private prefix = "";
85
+ private compatibility: "2.43" | "2.56" = "2.56";
86
+
87
+ /** The `<tree-ish>` argument. */
88
+ setTreeish(name: string): this {
89
+ this.checkCallable();
90
+ this.treeish = name;
91
+ return this;
92
+ }
93
+
94
+ /** `<path>...` arguments, read against {@link setPrefix}. */
95
+ addPaths(...paths: string[]): this {
96
+ this.checkCallable();
97
+ this.paths.push(...paths);
98
+ return this;
99
+ }
100
+
101
+ /** `-d`: only trees (and gitlinks). */
102
+ setTreesOnly(on = true): this {
103
+ this.checkCallable();
104
+ this.treesOnly = on;
105
+ return this;
106
+ }
107
+
108
+ /** `-r`: recurse into subtrees. */
109
+ setRecursive(on = true): this {
110
+ this.checkCallable();
111
+ this.recursive = on;
112
+ return this;
113
+ }
114
+
115
+ /** `-t`: show the trees recursed into. */
116
+ setShowTrees(on = true): this {
117
+ this.checkCallable();
118
+ this.showTrees = on;
119
+ return this;
120
+ }
121
+
122
+ /** `-z`: entries end with NUL, paths unquoted. */
123
+ setNullTerminated(on = true): this {
124
+ this.checkCallable();
125
+ this.nul = on;
126
+ return this;
127
+ }
128
+
129
+ /**
130
+ * An output mode option (`-l`/`--long`, `--name-only`, `--name-status`, `--object-only`),
131
+ * `option` its spelling for git's conflict message; a second, different mode is refused.
132
+ */
133
+ addMode(mode: LsTreeMode, option = `--${mode}`): this {
134
+ this.checkCallable();
135
+ this.modes.push({ mode, option });
136
+ return this;
137
+ }
138
+
139
+ /** `-l`/`--long`: object sizes. */
140
+ setLong(option = "--long"): this {
141
+ return this.addMode("long", option);
142
+ }
143
+
144
+ /** `--name-only`: paths only. */
145
+ setNameOnly(): this {
146
+ return this.addMode("name-only");
147
+ }
148
+
149
+ /** `--name-status`: as `--name-only`. */
150
+ setNameStatus(): this {
151
+ return this.addMode("name-status");
152
+ }
153
+
154
+ /** `--object-only`: object names only. */
155
+ setObjectOnly(): this {
156
+ return this.addMode("object-only");
157
+ }
158
+
159
+ /** `--[no-]full-name`: paths from the top (default: on when there is no prefix). */
160
+ setFullName(on = true): this {
161
+ this.checkCallable();
162
+ this.fullName = on;
163
+ return this;
164
+ }
165
+
166
+ /** `--full-tree`: the whole tree, paths from the top, the prefix ignored. */
167
+ setFullTree(on = true): this {
168
+ this.checkCallable();
169
+ this.fullTree = on;
170
+ return this;
171
+ }
172
+
173
+ /** `--format=<format>`. */
174
+ setFormat(format: string): this {
175
+ this.checkCallable();
176
+ this.format = format;
177
+ return this;
178
+ }
179
+
180
+ /**
181
+ * `--abbrev[=<n>]`: `undefined` is `--abbrev` (core.abbrev, else automatic), 0 the full
182
+ * id (`--no-abbrev`), else at least `n` digits (4 at least).
183
+ */
184
+ setAbbrev(length?: number): this {
185
+ this.checkCallable();
186
+ this.abbrev = length === undefined ? -1 : length;
187
+ return this;
188
+ }
189
+
190
+ /** The directory git runs in, relative to the top of the worktree (git's prefix). */
191
+ setPrefix(prefix: string): this {
192
+ this.checkCallable();
193
+ const p = prefix.replace(/^\/+|\/+$/g, "");
194
+ this.prefix = p ? `${p}/` : "";
195
+ return this;
196
+ }
197
+
198
+ /** The git version whose messages to follow (default 2.56). */
199
+ setCompatibility(version: "2.43" | "2.56"): this {
200
+ this.checkCallable();
201
+ this.compatibility = version;
202
+ return this;
203
+ }
204
+
205
+ protected override writesNoObjects(): boolean {
206
+ return true;
207
+ }
208
+
209
+ private out: Uint8Array[] = [];
210
+ private outSize = 0;
211
+
212
+ private emit(bytes: Uint8Array): Promise<void> | undefined {
213
+ this.out.push(bytes);
214
+ this.outSize += bytes.length;
215
+ return this.outSize >= FLUSH_AT ? this.flush() : undefined;
216
+ }
217
+
218
+ private async flush(): Promise<void> {
219
+ if (this.outSize === 0) return;
220
+ const all = new Uint8Array(this.outSize);
221
+ let at = 0;
222
+ for (const c of this.out) {
223
+ all.set(c, at);
224
+ at += c.length;
225
+ }
226
+ this.out = [];
227
+ this.outSize = 0;
228
+ await this.write(all);
229
+ }
230
+
231
+ protected async run(): Promise<number> {
232
+ // parse_options: OPT_CMDMODE refuses a second, different mode
233
+ let mode: LsTreeMode | undefined;
234
+ let modeOption = "";
235
+ for (const m of this.modes) {
236
+ if (mode !== undefined && m.mode !== mode) {
237
+ throw new PlumbingError(
238
+ this.compatibility === "2.43"
239
+ ? `error: ${m.option} is incompatible with ${modeOption}`
240
+ : `error: options '${m.option}' and '${modeOption}' cannot be used together`,
241
+ 129,
242
+ );
243
+ }
244
+ mode = m.mode;
245
+ modeOption = m.option;
246
+ }
247
+ if (mode === "name-status") mode = "name-only";
248
+ let prefix: string | undefined = this.prefix || undefined;
249
+ if (this.fullTree) prefix = undefined;
250
+ const fullName = this.fullName ?? !this.prefix;
251
+ const outputPrefix = fullName ? undefined : prefix;
252
+ let showTrees = this.showTrees;
253
+ // -d -r implies -t
254
+ if (this.treesOnly && this.recursive) showTrees = true;
255
+ if (this.format !== undefined && mode !== undefined) {
256
+ throw new PlumbingError(
257
+ "fatal: --format can't be combined with other format-altering options",
258
+ 129,
259
+ );
260
+ }
261
+ if (this.treeish === undefined) throw new PlumbingError(USAGE, 129);
262
+
263
+ const resolver = this.revisionResolver();
264
+ let id: string | undefined;
265
+ try {
266
+ // GET_OID_HASH_ANY: a tree named by an id of the compatibility format is listed with
267
+ // that format's ids
268
+ id = await resolver.resolve(this.treeish, { hashAny: true });
269
+ } catch (e) {
270
+ if (!(e instanceof RefNotFoundError)) throw e;
271
+ }
272
+ for (const w of resolver.warnings) this.warn(w);
273
+ resolver.warnings.length = 0;
274
+ if (id === undefined) throw new PlumbingError(`fatal: Not a valid object name ${this.treeish}`);
275
+
276
+ const items = await this.parsePaths(prefix);
277
+ const tree = await this.peelToTree(id);
278
+ if (tree === undefined) throw new PlumbingError("fatal: not a tree object");
279
+
280
+ let fn: "default" | "long" | "name-only" | "object-only" | "format";
281
+ if (this.format !== undefined) {
282
+ const fast = MODE_FORMATS.find(([, f]) => f === this.format);
283
+ fn = fast ? fast[0] : "format";
284
+ } else fn = mode ?? "default";
285
+
286
+ const config = this._workingCopy.config ? RemoteConfigStore.from(this._workingCopy) : undefined;
287
+ const quotePathValue = config?.value("core.quotePath");
288
+ const quoteFully = quotePathValue === undefined ? true : (parseGitBool(quotePathValue) ?? true);
289
+
290
+ const ctx: WalkContext = {
291
+ items,
292
+ ps: items.length > 0 ? treePathspec(items) : undefined,
293
+ fn,
294
+ treesOnly: this.treesOnly,
295
+ recursive: this.recursive,
296
+ showTrees,
297
+ outputPrefix:
298
+ outputPrefix === undefined ? undefined : latin1String(encodeGitPath(outputPrefix)),
299
+ quoteFully,
300
+ nulTerminated: this.nul,
301
+ };
302
+ let ok: boolean;
303
+ try {
304
+ ok = await this.walk(ctx, tree, "");
305
+ } finally {
306
+ await this.flush();
307
+ }
308
+ return ok ? 0 : 1;
309
+ }
310
+
311
+ /** parse_pathspec with ls-tree's magic mask and PATHSPEC_PREFER_CWD: literal elements. */
312
+ private async parsePaths(prefix: string | undefined): Promise<PathspecItem[]> {
313
+ const literal = (match: string): PathspecItem =>
314
+ pathspecItemBytes({
315
+ match,
316
+ nowildcardLen: match.length,
317
+ oneStar: false,
318
+ exclude: false,
319
+ glob: false,
320
+ icase: false,
321
+ });
322
+ if (this.paths.length === 0) return prefix ? [literal(prefix)] : [];
323
+ for (const p of this.paths) {
324
+ if (p === "") {
325
+ throw new PlumbingError(
326
+ "fatal: empty string is not a valid pathspec. please use . instead if you meant to match all paths",
327
+ );
328
+ }
329
+ }
330
+ const items: PathspecItem[] = [];
331
+ for (const elem of this.paths) {
332
+ const { magic, rest } = parseElementMagic(elem);
333
+ if (magic.has("literal") && magic.has("glob")) {
334
+ throw new PlumbingError(`fatal: ${elem}: 'literal' and 'glob' are incompatible`);
335
+ }
336
+ let match: string;
337
+ if (magic.has("top")) match = rest;
338
+ else {
339
+ const normalized = await this.prefixPath(prefix ?? "", rest);
340
+ if (normalized === undefined) {
341
+ const top = (await this.hostWorkingDir()) ?? "";
342
+ throw new PlumbingError(
343
+ `fatal: ${elem}: '${rest}' is outside repository at '${top.replace(/\/+$/, "") || "/"}'`,
344
+ );
345
+ }
346
+ match = normalized;
347
+ }
348
+ const unsupported = MAGIC.filter((m) => m.name !== "top" && m.name !== "literal").filter(
349
+ (m) => magic.has(m.name),
350
+ );
351
+ if (unsupported.length > 0) {
352
+ const names = unsupported
353
+ .map((m) => (m.mnemonic ? `'${m.name}' (mnemonic: '${m.mnemonic}')` : `'${m.name}'`))
354
+ .join(", ");
355
+ throw new PlumbingError(
356
+ `fatal: ${elem}: pathspec magic not supported by this command: ${names}`,
357
+ );
358
+ }
359
+ items.push(literal(match));
360
+ }
361
+ return items;
362
+ }
363
+
364
+ /** prefix_path_gently: the path from the top, undefined when it leaves the worktree. */
365
+ private async prefixPath(prefix: string, path: string): Promise<string | undefined> {
366
+ return prefixPathGently(
367
+ prefix,
368
+ path,
369
+ path.startsWith("/") ? await this.hostWorkingDir() : undefined,
370
+ );
371
+ }
372
+
373
+ /** parse_tree_indirect: a commit's tree, a tag's object peeled, a tree itself. */
374
+ private async peelToTree(id: string): Promise<string | undefined> {
375
+ const compat = this.compatObjects;
376
+ if (compat && id.length !== this.objectFormat.hexLength) {
377
+ // git parses an object named by a compatibility id with the storage format's parsers:
378
+ // a tree reads (its entries decoded at the id's width), a commit's `tree` line is too
379
+ // short for them (`bogus commit object`), a blob is hashed with the storage format's
380
+ // hash (`hash mismatch`), a tag fails quietly
381
+ const type = (await compat.readAsCompat(id).catch(() => undefined))?.type;
382
+ if (type === "tree") return id;
383
+ if (type === "commit") this.warn(`error: bogus commit object ${id}`);
384
+ if (type === "blob") this.warn(`error: hash mismatch ${id}`);
385
+ return undefined;
386
+ }
387
+ const peeled = await this.revisionResolver().peelTags(id);
388
+ if (peeled.type === "tree") return peeled.id;
389
+ if (peeled.type === "commit") {
390
+ const commit = await this.commits.load(peeled.id).catch(() => undefined);
391
+ return commit?.tree;
392
+ }
393
+ return undefined;
394
+ }
395
+
396
+ /** read_tree_at: false when a tree could not be read (git's `-1`). */
397
+ private async walk(ctx: WalkContext, tree: string, base: string): Promise<boolean> {
398
+ const entries = await this.listedTreeEntries(tree);
399
+ if (!entries) {
400
+ this.warn(`error: Could not read ${tree}`);
401
+ return false;
402
+ }
403
+ const baseBytes = latin1Bytes(base);
404
+ let all = false;
405
+ for (const e of entries) {
406
+ const nameBytes = encodeGitPath(e.name);
407
+ const mode = e.mode;
408
+ if (ctx.ps && !all) {
409
+ const r = treeEntryInteresting(ctx.ps, nameBytes, 0, nameBytes.length, mode, baseBytes);
410
+ if (r === ALL_ENTRIES_NOT_INTERESTING) break;
411
+ if (r === ENTRY_NOT_INTERESTING) continue;
412
+ if (r === ALL_ENTRIES_INTERESTING) all = true;
413
+ }
414
+ const name = latin1String(nameBytes);
415
+ const type = objectTypeOfMode(mode);
416
+ // show_tree_common / show_tree_fmt
417
+ let recurse = false;
418
+ let show = true;
419
+ if (type === "blob") {
420
+ if (ctx.treesOnly) show = false;
421
+ } else if (type === "tree" && this.showRecursive(ctx, base, name)) {
422
+ recurse = true;
423
+ if (!ctx.showTrees) show = false;
424
+ }
425
+ if (show) {
426
+ const pending = this.emit(await this.entryLine(ctx, e.id, mode, type, base + name));
427
+ if (pending) await pending;
428
+ }
429
+ if (recurse && !(await this.walk(ctx, e.id, `${base + name}/`))) return false;
430
+ }
431
+ return true;
432
+ }
433
+
434
+ /** show_recursive: whether a tree is entered. */
435
+ private showRecursive(ctx: WalkContext, base: string, pathname: string): boolean {
436
+ if (ctx.recursive) return true;
437
+ for (const item of ctx.items) {
438
+ const spec = item.match;
439
+ if (!spec.startsWith(base)) continue;
440
+ const rest = spec.slice(base.length);
441
+ const len = pathname.length;
442
+ if (rest.length <= len) continue;
443
+ if (rest[len] !== "/") continue;
444
+ if (rest.slice(0, len) !== pathname) continue;
445
+ return true;
446
+ }
447
+ return false;
448
+ }
449
+
450
+ private async abbreviated(id: string): Promise<string> {
451
+ if (this.abbrev === 0) return id;
452
+ if (id.length !== this.objectFormat.hexLength) {
453
+ // an id of the compatibility format: the minimum asked (default 7), not measured
454
+ // against the repository's ids
455
+ const min = this.abbrev < 0 ? 7 : Math.max(4, this.abbrev);
456
+ return id.slice(0, Math.min(min, id.length));
457
+ }
458
+ const hex = this.objectFormat.hexLength;
459
+ const min =
460
+ this.abbrev < 0 ? undefined : this.abbrev < 4 ? 4 : this.abbrev > hex ? hex : this.abbrev;
461
+ const length = (await this.idAbbreviator().lengths([id], min)).get(id) ?? hex;
462
+ return id.slice(0, length);
463
+ }
464
+
465
+ /** The blob's size, undefined when it cannot be read. */
466
+ private async blobSize(id: string): Promise<number | undefined> {
467
+ const compat = this.compatObjects;
468
+ if (compat && id.length !== this.objectFormat.hexLength) {
469
+ return (await compat.readAsCompat(id).catch(() => undefined))?.content.length;
470
+ }
471
+ const objects = this._workingCopy.history?.objects;
472
+ try {
473
+ if (objects) {
474
+ // the entry headers when the store can read them (oid_object_info), else the object
475
+ const header = await objects.header?.(id);
476
+ if (header) return header.size;
477
+ const obj = await objects.get(id);
478
+ if (!obj) return undefined;
479
+ await obj.content[Symbol.asyncIterator]().return?.();
480
+ return obj.size;
481
+ }
482
+ return await this.blobs.size(id);
483
+ } catch {
484
+ return undefined;
485
+ }
486
+ }
487
+
488
+ /** The path (a byte string) as the fast paths print it. */
489
+ private fastPath(ctx: WalkContext, path: string): Uint8Array {
490
+ const rel = relativePath(path, ctx.outputPrefix);
491
+ if (ctx.nulTerminated) return latin1Bytes(`${rel}\0`);
492
+ return latin1Bytes(`${quoteBytes(rel, ctx.quoteFully)}\n`);
493
+ }
494
+
495
+ private async entryLine(
496
+ ctx: WalkContext,
497
+ id: string,
498
+ mode: number,
499
+ type: string,
500
+ path: string,
501
+ ): Promise<Uint8Array> {
502
+ const modeText = mode.toString(8).padStart(6, "0");
503
+ switch (ctx.fn) {
504
+ case "default":
505
+ return concat(
506
+ latin1Bytes(`${modeText} ${type} ${await this.abbreviated(id)}\t`),
507
+ this.fastPath(ctx, path),
508
+ );
509
+ case "long": {
510
+ let size = "-";
511
+ if (type === "blob") size = String((await this.blobSize(id)) ?? "BAD");
512
+ return concat(
513
+ latin1Bytes(`${modeText} ${type} ${await this.abbreviated(id)} ${size.padStart(7)}\t`),
514
+ this.fastPath(ctx, path),
515
+ );
516
+ }
517
+ case "name-only":
518
+ return this.fastPath(ctx, path);
519
+ case "object-only":
520
+ return latin1Bytes(`${await this.abbreviated(id)}${this.nul ? "\0" : "\n"}`);
521
+ default:
522
+ return latin1Bytes(
523
+ `${await this.expandFormat(ctx, id, modeText, type, path)}${this.nul ? "\0" : "\n"}`,
524
+ );
525
+ }
526
+ }
527
+
528
+ /** show_tree_fmt's expansion (a byte string). */
529
+ private async expandFormat(
530
+ ctx: WalkContext,
531
+ id: string,
532
+ modeText: string,
533
+ type: string,
534
+ path: string,
535
+ ): Promise<string> {
536
+ const format = latin1String(encodeGitPath(this.format ?? ""));
537
+ let out = "";
538
+ let i = 0;
539
+ const size = async (padded: boolean) => {
540
+ let text = "-";
541
+ if (type === "blob") {
542
+ const s = await this.blobSize(id);
543
+ if (s === undefined)
544
+ throw new PlumbingError(`fatal: could not get object info about '${id}'`);
545
+ text = String(s);
546
+ }
547
+ return padded ? text.padStart(7) : text;
548
+ };
549
+ while (i < format.length) {
550
+ const at = format.indexOf("%", i);
551
+ if (at < 0) {
552
+ out += format.slice(i);
553
+ break;
554
+ }
555
+ out += format.slice(i, at);
556
+ i = at + 1;
557
+ const rest = format.slice(i);
558
+ if (rest.startsWith("%")) {
559
+ out += "%";
560
+ i += 1;
561
+ continue;
562
+ }
563
+ if (rest.startsWith("n")) {
564
+ out += "\n";
565
+ i += 1;
566
+ continue;
567
+ }
568
+ const hex = /^x([0-9a-fA-F]{2})/.exec(rest);
569
+ if (hex) {
570
+ out += String.fromCharCode(Number.parseInt(hex[1] as string, 16));
571
+ i += 3;
572
+ continue;
573
+ }
574
+ const atom = /^\((objectmode|objecttype|objectsize:padded|objectsize|objectname|path)\)/.exec(
575
+ rest,
576
+ );
577
+ if (!atom) {
578
+ const shown = decodeLatin1Path(rest);
579
+ if (!rest.startsWith("(")) {
580
+ throw new PlumbingError(
581
+ `fatal: bad ls-tree format: element '${shown}' does not start with '('`,
582
+ );
583
+ }
584
+ const close = rest.indexOf(")", 1);
585
+ if (close < 0) {
586
+ throw new PlumbingError(
587
+ `fatal: bad ls-tree format: element '${shown}' does not end in ')'`,
588
+ );
589
+ }
590
+ throw new PlumbingError(
591
+ `fatal: bad ls-tree format: %${decodeLatin1Path(rest.slice(0, close + 1))}`,
592
+ );
593
+ }
594
+ i += atom[0].length;
595
+ switch (atom[1]) {
596
+ case "objectmode":
597
+ out += modeText;
598
+ break;
599
+ case "objecttype":
600
+ out += type;
601
+ break;
602
+ case "objectsize:padded":
603
+ out += await size(true);
604
+ break;
605
+ case "objectsize":
606
+ out += await size(false);
607
+ break;
608
+ case "objectname":
609
+ out += await this.abbreviated(id);
610
+ break;
611
+ default:
612
+ out += quoteBytes(relativePath(path, ctx.outputPrefix), ctx.quoteFully);
613
+ }
614
+ }
615
+ return out;
616
+ }
617
+ }
618
+
619
+ interface WalkContext {
620
+ items: PathspecItem[];
621
+ ps: TreePathspec | undefined;
622
+ fn: "default" | "long" | "name-only" | "object-only" | "format";
623
+ treesOnly: boolean;
624
+ recursive: boolean;
625
+ showTrees: boolean;
626
+ /** The prefix paths are printed relative to (a byte string), if any */
627
+ outputPrefix: string | undefined;
628
+ quoteFully: boolean;
629
+ nulTerminated: boolean;
630
+ }
631
+
632
+ function objectTypeOfMode(mode: number): "tree" | "commit" | "blob" {
633
+ const kind = mode & 0o170000;
634
+ if (kind === 0o040000) return "tree";
635
+ if (kind === 0o160000) return "commit";
636
+ return "blob";
637
+ }
638
+
639
+ function concat(a: Uint8Array, b: Uint8Array): Uint8Array {
640
+ const out = new Uint8Array(a.length + b.length);
641
+ out.set(a);
642
+ out.set(b, a.length);
643
+ return out;
644
+ }
645
+
646
+ /** A byte string as git prints it in an error message (bytes as they are). */
647
+ function decodeLatin1Path(s: string): string {
648
+ return new TextDecoder().decode(latin1Bytes(s));
649
+ }
650
+
651
+ /** quote_c_style of a byte string, as a byte string. */
652
+ function quoteBytes(path: string, quoteFully: boolean): string {
653
+ const body = quoteCStyleBody(latin1Bytes(path), quoteFully);
654
+ if (body === undefined) return path;
655
+ return latin1String(encodeGitPath(`"${body}"`));
656
+ }
657
+
658
+ /** parse_element_magic: the magic names an element carries and the path after them. */
659
+ function parseElementMagic(elem: string): { magic: Set<string>; rest: string } {
660
+ const magic = new Set<string>();
661
+ if (!elem.startsWith(":")) return { magic, rest: elem };
662
+ if (elem[1] === "(") {
663
+ let pos = 2;
664
+ while (pos < elem.length && elem[pos] !== ")") {
665
+ let len = 0;
666
+ while (pos + len < elem.length && elem[pos + len] !== "," && elem[pos + len] !== ")") {
667
+ if (elem[pos + len] === "\\" && pos + len + 1 < elem.length) len++;
668
+ len++;
669
+ }
670
+ const next = elem[pos + len] === "," ? pos + len + 1 : pos + len;
671
+ const word = elem.slice(pos, pos + len);
672
+ pos = next;
673
+ if (!word) continue;
674
+ if (word.startsWith("prefix:")) {
675
+ if (!/^-?\d+$/.test(word.slice(7))) {
676
+ throw new PlumbingError("fatal: invalid parameter for pathspec magic 'prefix'");
677
+ }
678
+ continue;
679
+ }
680
+ if (word.startsWith("attr:")) {
681
+ magic.add("attr");
682
+ continue;
683
+ }
684
+ if (!MAGIC.some((m) => m.name === word)) {
685
+ throw new PlumbingError(`fatal: Invalid pathspec magic '${word}' in '${elem}'`);
686
+ }
687
+ magic.add(word);
688
+ }
689
+ if (elem[pos] !== ")") {
690
+ throw new PlumbingError(`fatal: Missing ')' at the end of pathspec magic in '${elem}'`);
691
+ }
692
+ return { magic, rest: elem.slice(pos + 1) };
693
+ }
694
+ let pos = 1;
695
+ for (; pos < elem.length && elem[pos] !== ":"; pos++) {
696
+ const ch = elem[pos] as string;
697
+ if (ch === "^") {
698
+ magic.add("exclude");
699
+ continue;
700
+ }
701
+ if (!SHORT_MAGIC.has(ch)) break;
702
+ const m = MAGIC.find((x) => x.mnemonic === ch);
703
+ if (!m) throw new PlumbingError(`fatal: Unimplemented pathspec magic '${ch}' in '${elem}'`);
704
+ magic.add(m.name);
705
+ }
706
+ if (elem[pos] === ":") pos++;
707
+ return { magic, rest: elem.slice(pos) };
708
+ }