@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
@@ -28,9 +28,10 @@
28
28
  * globally), was not taken; switch only on the human's word.
29
29
  */
30
30
  import { type Commit, collectCommitBytes, type PersonIdent } from "@statewalker/vcs-core";
31
- import { parseGitBool } from "@statewalker/vcs-utils";
31
+ import { createSha256, parseGitBool } from "@statewalker/vcs-utils";
32
32
  import {
33
33
  expandUserPath,
34
+ type GitHostEnvironment,
34
35
  type Signer,
35
36
  type SigningFormat,
36
37
  type SigningRequest,
@@ -161,29 +162,44 @@ export interface SigningConfig {
161
162
  * '<key>' in file '<file>' at line <n>`
162
163
  */
163
164
  export function signingConfigOf(workingCopy: WorkingCopy): SigningConfig {
164
- const config: SigningConfig = { format: "openpgp", programs: { ...DEFAULT_PROGRAMS } };
165
- if (!workingCopy.config) return config;
165
+ if (!workingCopy.config) return { format: "openpgp", programs: { ...DEFAULT_PROGRAMS } };
166
166
  const store = RemoteConfigStore.from(workingCopy);
167
- const environment = hostEnvironmentOf(workingCopy);
168
- const keys = [
169
- "user.signingkey",
170
- "gpg.format",
171
- "gpg.mintrustlevel",
172
- "gpg.ssh.defaultkeycommand",
173
- "gpg.ssh.allowedsignersfile",
174
- "gpg.ssh.revocationfile",
175
- "gpg.program",
176
- "gpg.openpgp.program",
177
- "gpg.x509.program",
178
- "gpg.ssh.program",
179
- ];
167
+ const keys = [...SIGNING_KEYS];
180
168
  const entries: (ConfigValueWhere & { key: string })[] =
181
169
  store.entriesWithOriginFor(keys) ??
182
170
  keys.flatMap((key) => {
183
171
  const text = store.value(key);
184
172
  return text === undefined ? [] : [{ key, text }];
185
173
  });
174
+ return signingConfigFromEntries(entries, hostEnvironmentOf(workingCopy));
175
+ }
176
+
177
+ /** The variables {@link signingConfigOf} reads, lower case. */
178
+ export const SIGNING_KEYS: readonly string[] = [
179
+ "user.signingkey",
180
+ "gpg.format",
181
+ "gpg.mintrustlevel",
182
+ "gpg.ssh.defaultkeycommand",
183
+ "gpg.ssh.allowedsignersfile",
184
+ "gpg.ssh.revocationfile",
185
+ "gpg.program",
186
+ "gpg.openpgp.program",
187
+ "gpg.x509.program",
188
+ "gpg.ssh.program",
189
+ ];
190
+
191
+ /**
192
+ * {@link signingConfigOf} over config entries in git's order (keys lower case, only
193
+ * {@link SIGNING_KEYS} are read), for a configuration that is no working copy's (a served
194
+ * repository's).
195
+ */
196
+ export function signingConfigFromEntries(
197
+ entries: Iterable<ConfigValueWhere & { key: string }>,
198
+ environment: GitHostEnvironment | undefined,
199
+ ): SigningConfig {
200
+ const config: SigningConfig = { format: "openpgp", programs: { ...DEFAULT_PROGRAMS } };
186
201
  for (const { key, text, file, line } of entries) {
202
+ if (!SIGNING_KEYS.includes(key)) continue;
187
203
  const fail = (error: string): never => {
188
204
  const fatal =
189
205
  file !== undefined && line !== undefined
@@ -383,3 +399,93 @@ export async function signCommit(
383
399
  gpgSignature: signature.endsWith("\n") ? signature.slice(0, -1) : signature,
384
400
  };
385
401
  }
402
+
403
+ /** A uint32 length-prefixed string of an ssh wire buffer at `at`. */
404
+ function sshString(bytes: Uint8Array, at: number): { value: Uint8Array; next: number } | undefined {
405
+ if (at + 4 > bytes.length) return undefined;
406
+ const length = new DataView(bytes.buffer, bytes.byteOffset + at, 4).getUint32(0);
407
+ if (at + 4 + length > bytes.length) return undefined;
408
+ return { value: bytes.subarray(at + 4, at + 4 + length), next: at + 4 + length };
409
+ }
410
+
411
+ function base64Bytes(text: string): Uint8Array | undefined {
412
+ try {
413
+ return Uint8Array.from(atob(text.replace(/\s+/g, "")), (c) => c.charCodeAt(0));
414
+ } catch {
415
+ return undefined;
416
+ }
417
+ }
418
+
419
+ /**
420
+ * The public key blob of an ssh key as `ssh-keygen -l` reads it: a public key line
421
+ * (`<type> <base64> [comment]`) or an OpenSSH private key file (its public part, which is
422
+ * never encrypted).
423
+ */
424
+ function sshPublicKeyBlob(text: string): Uint8Array | undefined {
425
+ const pem = /-----BEGIN OPENSSH PRIVATE KEY-----([\s\S]*?)-----END OPENSSH PRIVATE KEY-----/.exec(
426
+ text,
427
+ );
428
+ if (pem) {
429
+ const bytes = base64Bytes(pem[1] as string);
430
+ const magic = new TextEncoder().encode("openssh-key-v1\0");
431
+ if (!bytes || bytes.length < magic.length || magic.some((b, i) => bytes[i] !== b)) {
432
+ return undefined;
433
+ }
434
+ let at = magic.length;
435
+ // ciphername, kdfname, kdfoptions, then the number of keys and the first public key
436
+ for (let i = 0; i < 3; i++) {
437
+ const s = sshString(bytes, at);
438
+ if (!s) return undefined;
439
+ at = s.next;
440
+ }
441
+ return sshString(bytes, at + 4)?.value;
442
+ }
443
+ const line = text.split("\n").find((l) => l.trim() !== "" && !l.startsWith("#"));
444
+ const field = line?.trim().split(/\s+/)[1];
445
+ return field ? base64Bytes(field) : undefined;
446
+ }
447
+
448
+ /**
449
+ * gpg-interface.c's `get_signing_key_id()` for `sign` (`""`: the default key): the key of an
450
+ * openpgp or x509 signature (`user.signingKey`, else the committer as `Name <email>`), the
451
+ * SHA-256 fingerprint of an ssh key (`ssh-keygen -lf`'s `SHA256:...`, for a literal key, a
452
+ * public key file or an OpenSSH private key file).
453
+ *
454
+ * @throws SigningFailedError as git dies when it cannot fingerprint an ssh key (`fatal: failed
455
+ * to get the ssh fingerprint for key '<key>'`), or has none
456
+ */
457
+ export async function signingKeyIdOf(
458
+ workingCopy: WorkingCopy,
459
+ sign: string,
460
+ committer: Pick<PersonIdent, "name" | "email">,
461
+ ): Promise<string> {
462
+ const config = signingConfigOf(workingCopy);
463
+ const key = sign !== "" ? sign : config.signingKey;
464
+ if (config.format !== "ssh") return key ?? `${committer.name} <${committer.email}>`;
465
+ if (key === undefined) {
466
+ throw new SigningFailedError(
467
+ "fatal: either user.signingkey or gpg.ssh.defaultKeyCommand needs to be configured",
468
+ sign,
469
+ 128,
470
+ );
471
+ }
472
+ let text: string | undefined;
473
+ if (key.startsWith("key::")) text = key.slice(5);
474
+ else if (key.startsWith("ssh-")) text = key;
475
+ else {
476
+ const environment = hostEnvironmentOf(workingCopy);
477
+ const path = expandUserPath(key, environment) ?? key;
478
+ const bytes = await environment?.readFile(path).catch(() => undefined);
479
+ text = bytes ? new TextDecoder().decode(bytes) : undefined;
480
+ }
481
+ const blob = text === undefined ? undefined : sshPublicKeyBlob(text);
482
+ if (!blob) {
483
+ throw new SigningFailedError(
484
+ `fatal: failed to get the ssh fingerprint for key '${key}'`,
485
+ sign,
486
+ 128,
487
+ );
488
+ }
489
+ const digest = createSha256().update(blob).digest();
490
+ return `SHA256:${btoa(String.fromCharCode(...digest)).replace(/=+$/, "")}`;
491
+ }
@@ -587,6 +587,8 @@ export class StashApplyCommand extends GitCommand<StashApplyResult> {
587
587
  await editor.finish();
588
588
  await this.staging.write();
589
589
  const warnings = await this.finishSparse(sparse, worktree, writing);
590
+ // do_apply_stash: rerere on the conflicts, before the untracked files come back
591
+ const rerereOutput = await this.rerere();
590
592
  await this.writeUntracked(untrackedPlan, worktree, stashId, trust.symlinks);
591
593
  return {
592
594
  status: StashApplyStatus.CONFLICTS,
@@ -594,6 +596,7 @@ export class StashApplyCommand extends GitCommand<StashApplyResult> {
594
596
  conflicts: [...conflicts.keys()].sort(),
595
597
  messages: this.mergeMessages(merge.messages, stashCommit.tree, stashHeadCommitObj.tree),
596
598
  ...(warnings.length > 0 ? { warnings } : {}),
599
+ ...(rerereOutput.length > 0 ? { rerereOutput } : {}),
597
600
  };
598
601
  }
599
602
  if (restoredIndex) {
@@ -0,0 +1,397 @@
1
+ import type { ObjectId } from "@statewalker/vcs-core";
2
+ import { collect } from "@statewalker/vcs-utils/streams";
3
+
4
+ import { GitApiError, InvalidArgumentError } from "../errors/index.js";
5
+ import { RemoteConfigStore } from "../remote-config/index.js";
6
+ import { StashInfoCommand } from "./stash-info.js";
7
+ import { STASH_REF } from "./stash-list-command.js";
8
+
9
+ /**
10
+ * The ident of an export's base commit: git's fixed `git stash <git@stash>` at
11
+ * 2001-09-17T00:00:00Z (format-patch's date), so the same stashes export to the same ids.
12
+ */
13
+ const BASE_IDENT = "git stash <git@stash> 1000684800 +0000";
14
+ /** The subject prefix of every exported stash commit */
15
+ const EXPORT_PREFIX = "git stash: ";
16
+
17
+ /** What `git stash export` did. */
18
+ export interface StashExportResult {
19
+ /** The tip of the exported chain; undefined when the export stopped at a bad reflog entry */
20
+ readonly commit?: ObjectId;
21
+ /**
22
+ * git's `error:` lines of a run that still exits 0: a `refs/stash` reflog entry that is no
23
+ * stash stops the export (nothing printed, no ref written), as builtin/stash.c does.
24
+ */
25
+ readonly errors: string[];
26
+ }
27
+
28
+ /** What `git stash import` did. */
29
+ export interface StashImportResult {
30
+ /** The stash commits stored, oldest first (the last is `stash@{0}`) */
31
+ readonly imported: ObjectId[];
32
+ /**
33
+ * git's `error:` lines of a run that still exits 0: a root commit without an author or a
34
+ * committer stops the import before anything is stored, as builtin/stash.c does.
35
+ */
36
+ readonly errors: string[];
37
+ }
38
+
39
+ /** Bytes as a binary string (one character per byte), so commit headers keep their bytes */
40
+ function binary(bytes: Uint8Array): string {
41
+ let out = "";
42
+ for (let i = 0; i < bytes.length; i += 0x8000) {
43
+ out += String.fromCharCode(...bytes.subarray(i, i + 0x8000));
44
+ }
45
+ return out;
46
+ }
47
+
48
+ function binaryBytes(text: string): Uint8Array {
49
+ const out = new Uint8Array(text.length);
50
+ for (let i = 0; i < text.length; i++) out[i] = text.charCodeAt(i) & 0xff;
51
+ return out;
52
+ }
53
+
54
+ /** git's find_commit_header: the value of the first `<key> ` header line, else undefined */
55
+ function commitHeader(raw: string, key: string): string | undefined {
56
+ const end = raw.indexOf("\n\n");
57
+ const headers = end < 0 ? raw : raw.slice(0, end);
58
+ for (const line of headers.split("\n")) {
59
+ if (line.startsWith(`${key} `)) return line.slice(key.length + 1);
60
+ }
61
+ return undefined;
62
+ }
63
+
64
+ /** The message: what follows the first empty line, undefined when there is none */
65
+ function commitBody(raw: string): string | undefined {
66
+ const at = raw.indexOf("\n\n");
67
+ return at < 0 ? undefined : raw.slice(at + 2);
68
+ }
69
+
70
+ function error(message: string, exitCode = 128): GitApiError {
71
+ return new GitApiError(message).withExitCode(exitCode);
72
+ }
73
+
74
+ /** The stash subcommands 2.43 lacks: `cmd_stash` takes the name for a pathspec of `push`. */
75
+ function absentIn243(subcommand: string): GitApiError {
76
+ return error(
77
+ `fatal: subcommand wasn't specified; 'push' can't be assumed due to unexpected token '${subcommand}'`,
78
+ 128,
79
+ );
80
+ }
81
+
82
+ /**
83
+ * What export and import share: raw commits read and written byte for byte, and git's
84
+ * check_stash_topology.
85
+ */
86
+ abstract class StashChainCommand<T> extends StashInfoCommand<T> {
87
+ /** The object's content as stored, undefined when it is missing */
88
+ protected async rawObject(id: ObjectId): Promise<{ type: string; raw: string } | undefined> {
89
+ const objects = this.workingCopy.history?.objects;
90
+ const object = await objects?.get(id).catch(() => undefined);
91
+ if (!object) return undefined;
92
+ return { type: object.type, raw: binary(object.bytes ?? (await collect(object.content))) };
93
+ }
94
+
95
+ /** git's lookup_commit_reference: the commit `id` names, tags peeled */
96
+ protected async peelCommit(id: ObjectId): Promise<ObjectId | undefined> {
97
+ const peeled = await this.revisionResolver()
98
+ .peelTags(id)
99
+ .catch(() => undefined);
100
+ return peeled?.type === "commit" ? peeled.id : undefined;
101
+ }
102
+
103
+ /**
104
+ * git's check_stash_topology: two or three parents, the second with one parent (the
105
+ * first), the third with none.
106
+ */
107
+ protected async isStashTopology(id: ObjectId): Promise<boolean> {
108
+ const load = (c: ObjectId) => this.commits.load(c).catch(() => undefined);
109
+ const stash = await load(id);
110
+ if (!stash || stash.parents.length < 2 || stash.parents.length > 3) return false;
111
+ const [p1, p2, p3] = stash.parents as [ObjectId, ObjectId, ObjectId?];
112
+ const first = await load(p1);
113
+ const index = await load(p2);
114
+ const untracked = p3 ? await load(p3) : undefined;
115
+ if (!first || !index || (p3 && !untracked)) return false;
116
+ if (index.parents.length !== 1 || (untracked && untracked.parents.length > 0)) return false;
117
+ return index.parents[0] === p1;
118
+ }
119
+
120
+ /** `encoding <i18n.commitEncoding>` as commit_tree_extended writes it, else "" */
121
+ protected encodingHeader(): string {
122
+ const encoding = RemoteConfigStore.from(this.workingCopy).value("i18n.commitEncoding");
123
+ if (encoding === undefined || /^utf-?8$/i.test(encoding)) return "";
124
+ return `encoding ${encoding}\n`;
125
+ }
126
+
127
+ protected async writeCommit(text: string): Promise<ObjectId> {
128
+ const objects = this.workingCopy.history?.objects;
129
+ if (!objects) throw error("error: could not write commit");
130
+ const bytes = binaryBytes(text);
131
+ return objects.put("commit", bytes.length, [bytes]);
132
+ }
133
+ }
134
+
135
+ /**
136
+ * `git stash export (--print | --to-ref <ref>) [<stash>...]` (git 2.51+): the stashes, every
137
+ * entry of `refs/stash` by default, written as a chain of commits that any transport carries,
138
+ * as builtin/stash.c's do_export_stash writes it.
139
+ *
140
+ * The chain starts at a parentless commit of the empty tree by `git stash <git@stash>` dated
141
+ * 2001-09-17 (the same in every repository). Each stash adds a commit of the empty tree whose
142
+ * first parent is the previous link and whose second is the stash commit itself, with the
143
+ * stash's author and committer and its message after `git stash: `. The oldest stash is linked
144
+ * first, so the tip's second parent is `stash@{0}`; named stashes are linked last to first.
145
+ * The tip is printed (`--print`, see {@link getOutput}) or written to the ref named
146
+ * (`--to-ref`, no reflog message). `git stash import` reads the chain back.
147
+ *
148
+ * As git: `error: exactly one of --print and --to-ref is required`, `error: unable to find
149
+ * stash entry <stash>`, `error: <revision> does not look like a stash commit` (exit 128 as git 2.56; 2.51-2.55 exit 1); a
150
+ * `refs/stash` entry that is no stash stops the export with exit 0 and nothing written
151
+ * (`StashExportResult.errors`). Under `setCompatibility("2.43")` it refuses as git 2.43, which
152
+ * has no such subcommand.
153
+ *
154
+ * @example
155
+ * ```typescript
156
+ * // git stash export --to-ref refs/heads/stashes
157
+ * await git.stashExport().setToRef("refs/heads/stashes").call();
158
+ * // git stash export --print stash@{1}
159
+ * const { commit } = await git.stashExport().setPrint(true).addStash("stash@{1}").call();
160
+ * ```
161
+ */
162
+ export class StashExportCommand extends StashChainCommand<StashExportResult> {
163
+ private print = false;
164
+ private toRef?: string;
165
+ private readonly stashes: string[] = [];
166
+
167
+ /** `--print`: the chain's tip printed on stdout. */
168
+ setPrint(print: boolean): this {
169
+ this.checkCallable();
170
+ this.print = print;
171
+ return this;
172
+ }
173
+
174
+ /** `--to-ref <ref>`: the chain's tip written to `ref`. */
175
+ setToRef(ref: string): this {
176
+ this.checkCallable();
177
+ this.toRef = ref;
178
+ return this;
179
+ }
180
+
181
+ /** A stash to export (`stash@{n}`, `n` or any revision); none: every entry of `refs/stash`. */
182
+ addStash(stash: string): this {
183
+ this.checkCallable();
184
+ this.stashes.push(stash);
185
+ return this;
186
+ }
187
+
188
+ async call(): Promise<StashExportResult> {
189
+ this.checkCallable();
190
+ this.setCallable(false);
191
+ if (this.compatibility === "2.43") {
192
+ if (this.print)
193
+ throw new InvalidArgumentError("print", true, "error: unknown option `print'").withExitCode(
194
+ 129,
195
+ );
196
+ if (this.toRef !== undefined) {
197
+ throw new InvalidArgumentError(
198
+ "to-ref",
199
+ this.toRef,
200
+ "error: unknown option `to-ref'",
201
+ ).withExitCode(129);
202
+ }
203
+ throw absentIn243("export");
204
+ }
205
+ if (this.print === (this.toRef !== undefined)) {
206
+ throw error("error: exactly one of --print and --to-ref is required");
207
+ }
208
+
209
+ // the base commit is written first, whatever follows
210
+ const encoding = this.encodingHeader();
211
+ let tip = await this.writeCommit(
212
+ `tree ${this.objectFormat.emptyTreeId}\nauthor ${BASE_IDENT}\ncommitter ${BASE_IDENT}\n${encoding}\n`,
213
+ );
214
+
215
+ const stashes: ObjectId[] = [];
216
+ const errors: string[] = [];
217
+ if (this.stashes.length > 0) {
218
+ for (const stash of this.stashes) {
219
+ const revision = /^\d*$/.test(stash) ? `${STASH_REF}@{${stash}}` : stash;
220
+ const id = await this.resolveRevision(revision).catch(() => undefined);
221
+ if (id === undefined) throw error(`error: unable to find stash entry ${stash}`);
222
+ const commit = await this.peelCommit(id);
223
+ if (!commit || !(await this.isStashTopology(commit))) {
224
+ throw error(`error: ${revision} does not look like a stash commit`);
225
+ }
226
+ stashes.push(commit);
227
+ }
228
+ } else {
229
+ // refs/stash's reflog, newest first
230
+ for (const id of await this.stashReflog()) {
231
+ const commit = await this.peelCommit(id);
232
+ if (!commit || !(await this.isStashTopology(commit))) {
233
+ errors.push(`error: ${id} does not look like a stash commit`);
234
+ return { errors };
235
+ }
236
+ stashes.push(commit);
237
+ }
238
+ }
239
+
240
+ for (const stash of stashes.reverse()) {
241
+ tip = await this.exportedCommit(tip, stash, encoding);
242
+ }
243
+ if (this.toRef !== undefined) {
244
+ const result = await this.refsStore.batch([{ name: this.toRef, new: tip }], {
245
+ ...this.reflogLine(""),
246
+ });
247
+ if (!result.ok) {
248
+ const why = result.rejected.map((r) => r.reason).join(", ");
249
+ throw error(`fatal: update_ref failed for ref '${this.toRef}': ${why}`, 128);
250
+ }
251
+ } else {
252
+ this.output.push(tip);
253
+ }
254
+ return { commit: tip, errors };
255
+ }
256
+
257
+ /** The ids `refs/stash`'s reflog records, newest first (the ref alone for a store keeping no reflogs) */
258
+ private async stashReflog(): Promise<ObjectId[]> {
259
+ // git walks the reflog alone: a refs/stash without one exports no stash
260
+ if (this.refsStore.getReflog) {
261
+ const reflog = await this.refsStore.getReflog(STASH_REF);
262
+ return reflog ? (await reflog.getReverseEntries()).map((e) => e.newId) : [];
263
+ }
264
+ const top = await this.refsStore.resolve(STASH_REF).catch(() => undefined);
265
+ return top?.objectId ? [top.objectId] : [];
266
+ }
267
+
268
+ /** git's write_commit_with_parents: the stash linked after `previous`. */
269
+ private async exportedCommit(
270
+ previous: ObjectId,
271
+ stash: ObjectId,
272
+ encoding: string,
273
+ ): Promise<ObjectId> {
274
+ const raw = (await this.rawObject(stash))?.raw ?? "";
275
+ const author = commitHeader(raw, "author");
276
+ const committer = commitHeader(raw, "committer");
277
+ if (author === undefined || committer === undefined) {
278
+ throw error(`error: cannot parse commit ${stash}`);
279
+ }
280
+ const ident = /^[^<>\n]*<[^<>\n]*> \d+ [-+]\d{4}$/;
281
+ if (!ident.test(author) || !ident.test(committer)) {
282
+ throw error(`error: invalid author or committer for ${stash}`);
283
+ }
284
+ let message = `${EXPORT_PREFIX}${commitBody(raw) ?? ""}`;
285
+ if (!message.endsWith("\n")) message += "\n";
286
+ return this.writeCommit(
287
+ `tree ${this.objectFormat.emptyTreeId}\nparent ${previous}\nparent ${stash}\n` +
288
+ `author ${author}\ncommitter ${committer}\n${encoding}\n${message}`,
289
+ );
290
+ }
291
+ }
292
+
293
+ /**
294
+ * `git stash import <commit>` (git 2.51+): the stashes of a chain `git stash export` wrote,
295
+ * added to `refs/stash` oldest first, each with its own message as the reflog message (so
296
+ * the chain's tip becomes `stash@{0}`; the entries already there stay below), as
297
+ * builtin/stash.c's do_import_stash adds them.
298
+ *
299
+ * The whole chain is checked before anything is stored, with git's messages (exit 128 as git 2.56; 2.51-2.55 exit 1):
300
+ * `not a valid revision: <rev>`, `not a commit: <rev>`, `<id> is not a valid exported stash
301
+ * commit` (a tree other than the empty one, or neither none nor two parents), `found stash
302
+ * commit <id> without expected prefix`, `<id> does not look like a stash commit`, `found root
303
+ * commit <id> with invalid data` (a base commit not by `git stash <git@stash>` at its date).
304
+ * A base commit without an author or committer stops the import with exit 0 and nothing
305
+ * stored (`StashImportResult.errors`). Under `setCompatibility("2.43")` it refuses as git
306
+ * 2.43, which has no such subcommand.
307
+ *
308
+ * @example
309
+ * ```typescript
310
+ * // git fetch origin refs/heads/stashes && git stash import FETCH_HEAD
311
+ * await git.stashImport().setCommit("FETCH_HEAD").call();
312
+ * ```
313
+ */
314
+ export class StashImportCommand extends StashChainCommand<StashImportResult> {
315
+ private commit?: string;
316
+
317
+ /** The tip of an exported chain (any revision naming it). */
318
+ setCommit(commit: string): this {
319
+ this.checkCallable();
320
+ this.commit = commit;
321
+ return this;
322
+ }
323
+
324
+ async call(): Promise<StashImportResult> {
325
+ this.checkCallable();
326
+ this.setCallable(false);
327
+ if (this.compatibility === "2.43") throw absentIn243("import");
328
+ const rev = this.commit;
329
+ if (rev === undefined) {
330
+ throw new InvalidArgumentError("commit", rev, "fatal: a revision is required").withExitCode(
331
+ 129,
332
+ );
333
+ }
334
+ const id = await this.resolveRevision(rev).catch(() => undefined);
335
+ if (id === undefined) throw error(`error: not a valid revision: ${rev}`);
336
+ let current = await this.peelCommit(id);
337
+ if (current === undefined) {
338
+ const type = (await this.rawObject(id))?.type;
339
+ throw error(
340
+ `${type ? `error: object ${id} is a ${type}, not a commit\n` : ""}error: not a commit: ${rev}`,
341
+ );
342
+ }
343
+
344
+ // the chain, tip first; the stashes collected oldest first
345
+ const stashes: ObjectId[] = [];
346
+ const errors: string[] = [];
347
+ for (;;) {
348
+ const commit = await this.commits.load(current).catch(() => undefined);
349
+ const parents = commit?.parents ?? [];
350
+ if (
351
+ !commit ||
352
+ commit.tree !== this.objectFormat.emptyTreeId ||
353
+ (parents.length !== 0 && parents.length !== 2)
354
+ ) {
355
+ throw error(`error: ${current} is not a valid exported stash commit`);
356
+ }
357
+ const raw = (await this.rawObject(current))?.raw ?? "";
358
+ if (parents.length === 0) {
359
+ const author = commitHeader(raw, "author");
360
+ const committer = commitHeader(raw, "committer");
361
+ if (author === undefined || committer === undefined) {
362
+ errors.push(`error: cannot parse commit ${current}`);
363
+ return { imported: [], errors };
364
+ }
365
+ if (author !== BASE_IDENT || committer !== BASE_IDENT) {
366
+ throw error(`error: found root commit ${current} with invalid data`);
367
+ }
368
+ break;
369
+ }
370
+ const body = commitBody(raw);
371
+ if (body === undefined) throw error(`error: cannot parse commit ${current}`);
372
+ if (!body.startsWith(EXPORT_PREFIX)) {
373
+ throw error(`error: found stash commit ${current} without expected prefix`);
374
+ }
375
+ const [previous, stash] = parents as [ObjectId, ObjectId];
376
+ if (!(await this.isStashTopology(stash))) {
377
+ throw error(`error: ${stash} does not look like a stash commit`);
378
+ }
379
+ stashes.unshift(stash);
380
+ current = previous;
381
+ }
382
+
383
+ const decoder = new TextDecoder();
384
+ for (const stash of stashes) {
385
+ const raw = (await this.rawObject(stash))?.raw;
386
+ const body = raw === undefined ? undefined : commitBody(raw);
387
+ if (body === undefined) throw error(`error: cannot parse commit ${stash}`);
388
+ const message = decoder.decode(binaryBytes(body));
389
+ const result = await this.refsStore.batch([{ name: STASH_REF, new: stash }], {
390
+ ...this.reflogLine(message),
391
+ createReflog: true,
392
+ });
393
+ if (!result.ok) throw error(`error: cannot save the stash for ${stash}`);
394
+ }
395
+ return { imported: stashes, errors };
396
+ }
397
+ }