@statewalker/vcs-commands 0.9.0 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (460) hide show
  1. package/README.md +1 -1
  2. package/dist/commands/add-command.d.ts.map +1 -1
  3. package/dist/commands/add-patch/patch-backend.d.ts +2 -0
  4. package/dist/commands/add-patch/patch-backend.d.ts.map +1 -1
  5. package/dist/commands/add-patch/patch-modes.d.ts +6 -2
  6. package/dist/commands/add-patch/patch-modes.d.ts.map +1 -1
  7. package/dist/commands/add-patch/patch-session.d.ts +4 -0
  8. package/dist/commands/add-patch/patch-session.d.ts.map +1 -1
  9. package/dist/commands/am/am-command.d.ts +41 -2
  10. package/dist/commands/am/am-command.d.ts.map +1 -1
  11. package/dist/commands/apply/index.d.ts +1 -1
  12. package/dist/commands/apply/index.d.ts.map +1 -1
  13. package/dist/commands/archive/archive-command.d.ts +169 -0
  14. package/dist/commands/archive/archive-command.d.ts.map +1 -0
  15. package/dist/commands/archive/archive-entry.d.ts +60 -0
  16. package/dist/commands/archive/archive-entry.d.ts.map +1 -0
  17. package/dist/commands/archive/index.d.ts +8 -0
  18. package/dist/commands/archive/index.d.ts.map +1 -0
  19. package/dist/commands/archive/remote-archive-command.d.ts +56 -0
  20. package/dist/commands/archive/remote-archive-command.d.ts.map +1 -0
  21. package/dist/commands/archive/tar-archive.d.ts +31 -0
  22. package/dist/commands/archive/tar-archive.d.ts.map +1 -0
  23. package/dist/commands/archive/tar-commit-id.d.ts +13 -0
  24. package/dist/commands/archive/tar-commit-id.d.ts.map +1 -0
  25. package/dist/commands/archive/upload-archive-writer.d.ts +48 -0
  26. package/dist/commands/archive/upload-archive-writer.d.ts.map +1 -0
  27. package/dist/commands/archive/zip-archive.d.ts +42 -0
  28. package/dist/commands/archive/zip-archive.d.ts.map +1 -0
  29. package/dist/commands/attributes-source.d.ts +10 -0
  30. package/dist/commands/attributes-source.d.ts.map +1 -1
  31. package/dist/commands/blame-command.d.ts +43 -1
  32. package/dist/commands/blame-command.d.ts.map +1 -1
  33. package/dist/commands/bundle/bundle-create-command.d.ts +67 -0
  34. package/dist/commands/bundle/bundle-create-command.d.ts.map +1 -0
  35. package/dist/commands/bundle/bundle-format.d.ts +89 -0
  36. package/dist/commands/bundle/bundle-format.d.ts.map +1 -0
  37. package/dist/commands/bundle/bundle-list.d.ts +92 -0
  38. package/dist/commands/bundle/bundle-list.d.ts.map +1 -0
  39. package/dist/commands/bundle/bundle-read-commands.d.ts +81 -0
  40. package/dist/commands/bundle/bundle-read-commands.d.ts.map +1 -0
  41. package/dist/commands/bundle/bundle-support.d.ts +32 -0
  42. package/dist/commands/bundle/bundle-support.d.ts.map +1 -0
  43. package/dist/commands/bundle/bundle-transport.d.ts +38 -0
  44. package/dist/commands/bundle/bundle-transport.d.ts.map +1 -0
  45. package/dist/commands/bundle/bundle-uri-host.d.ts +43 -0
  46. package/dist/commands/bundle/bundle-uri-host.d.ts.map +1 -0
  47. package/dist/commands/bundle/bundle-uri.d.ts +55 -0
  48. package/dist/commands/bundle/bundle-uri.d.ts.map +1 -0
  49. package/dist/commands/bundle/bundle-verify.d.ts +63 -0
  50. package/dist/commands/bundle/bundle-verify.d.ts.map +1 -0
  51. package/dist/commands/bundle/index.d.ts +14 -0
  52. package/dist/commands/bundle/index.d.ts.map +1 -0
  53. package/dist/commands/cat-file/batch-format.d.ts +58 -0
  54. package/dist/commands/cat-file/batch-format.d.ts.map +1 -0
  55. package/dist/commands/cat-file/cat-file-command.d.ts +135 -0
  56. package/dist/commands/cat-file/cat-file-command.d.ts.map +1 -0
  57. package/dist/commands/cat-file/index.d.ts +3 -0
  58. package/dist/commands/cat-file/index.d.ts.map +1 -0
  59. package/dist/commands/check-attr-command.d.ts +66 -0
  60. package/dist/commands/check-attr-command.d.ts.map +1 -0
  61. package/dist/commands/check-ignore-command.d.ts +58 -0
  62. package/dist/commands/check-ignore-command.d.ts.map +1 -0
  63. package/dist/commands/check-ref-format-command.d.ts +60 -0
  64. package/dist/commands/check-ref-format-command.d.ts.map +1 -0
  65. package/dist/commands/checkout-command.d.ts.map +1 -1
  66. package/dist/commands/checkout-index-command.d.ts +96 -0
  67. package/dist/commands/checkout-index-command.d.ts.map +1 -0
  68. package/dist/commands/cherry-pick-command.d.ts +10 -0
  69. package/dist/commands/cherry-pick-command.d.ts.map +1 -1
  70. package/dist/commands/clone-command.d.ts +19 -0
  71. package/dist/commands/clone-command.d.ts.map +1 -1
  72. package/dist/commands/commit-command.d.ts +9 -1
  73. package/dist/commands/commit-command.d.ts.map +1 -1
  74. package/dist/commands/config-command.d.ts +2 -0
  75. package/dist/commands/config-command.d.ts.map +1 -1
  76. package/dist/commands/daemon-access-hook.d.ts +36 -0
  77. package/dist/commands/daemon-access-hook.d.ts.map +1 -0
  78. package/dist/commands/default-branch.d.ts +42 -0
  79. package/dist/commands/default-branch.d.ts.map +1 -1
  80. package/dist/commands/diff-command.d.ts +132 -5
  81. package/dist/commands/diff-command.d.ts.map +1 -1
  82. package/dist/commands/diff-external.d.ts +43 -0
  83. package/dist/commands/diff-external.d.ts.map +1 -0
  84. package/dist/commands/diff-plumbing/diff-pairs-command.d.ts +27 -0
  85. package/dist/commands/diff-plumbing/diff-pairs-command.d.ts.map +1 -0
  86. package/dist/commands/diff-plumbing/diff-plumbing-command.d.ts +129 -0
  87. package/dist/commands/diff-plumbing/diff-plumbing-command.d.ts.map +1 -0
  88. package/dist/commands/diff-plumbing/index.d.ts +3 -0
  89. package/dist/commands/diff-plumbing/index.d.ts.map +1 -0
  90. package/dist/commands/diff-textconv.d.ts +5 -1
  91. package/dist/commands/diff-textconv.d.ts.map +1 -1
  92. package/dist/commands/fast-export/fast-export-command.d.ts +135 -0
  93. package/dist/commands/fast-export/fast-export-command.d.ts.map +1 -0
  94. package/dist/commands/fast-export/fast-import-command.d.ts +182 -0
  95. package/dist/commands/fast-export/fast-import-command.d.ts.map +1 -0
  96. package/dist/commands/fast-export/fast-stream-support.d.ts +64 -0
  97. package/dist/commands/fast-export/fast-stream-support.d.ts.map +1 -0
  98. package/dist/commands/fast-export/index.d.ts +4 -0
  99. package/dist/commands/fast-export/index.d.ts.map +1 -0
  100. package/dist/commands/fetch-command.d.ts +65 -0
  101. package/dist/commands/fetch-command.d.ts.map +1 -1
  102. package/dist/commands/fetch-multiple-command.d.ts.map +1 -1
  103. package/dist/commands/format-rev-command.d.ts +58 -0
  104. package/dist/commands/format-rev-command.d.ts.map +1 -0
  105. package/dist/commands/fsck/fsck-command.d.ts.map +1 -1
  106. package/dist/commands/fsck/fsck-msg-ids.d.ts +18 -3
  107. package/dist/commands/fsck/fsck-msg-ids.d.ts.map +1 -1
  108. package/dist/commands/fsmonitor-refresh.d.ts +69 -0
  109. package/dist/commands/fsmonitor-refresh.d.ts.map +1 -0
  110. package/dist/commands/gc-command.d.ts +5 -0
  111. package/dist/commands/gc-command.d.ts.map +1 -1
  112. package/dist/commands/git-hooks.d.ts +32 -0
  113. package/dist/commands/git-hooks.d.ts.map +1 -1
  114. package/dist/commands/git-paths.d.ts +26 -0
  115. package/dist/commands/git-paths.d.ts.map +1 -0
  116. package/dist/commands/grep/grep-command.d.ts +2 -1
  117. package/dist/commands/grep/grep-command.d.ts.map +1 -1
  118. package/dist/commands/history-command.d.ts +156 -0
  119. package/dist/commands/history-command.d.ts.map +1 -0
  120. package/dist/commands/http-config.d.ts +38 -0
  121. package/dist/commands/http-config.d.ts.map +1 -0
  122. package/dist/commands/index-adder.d.ts +12 -1
  123. package/dist/commands/index-adder.d.ts.map +1 -1
  124. package/dist/commands/index-host.d.ts.map +1 -1
  125. package/dist/commands/index.d.ts +44 -1
  126. package/dist/commands/index.d.ts.map +1 -1
  127. package/dist/commands/index.js +6 -5
  128. package/dist/commands/init-command.d.ts.map +1 -1
  129. package/dist/commands/last-modified-command.d.ts +102 -0
  130. package/dist/commands/last-modified-command.d.ts.map +1 -0
  131. package/dist/commands/lfs/go-url.d.ts +43 -0
  132. package/dist/commands/lfs/go-url.d.ts.map +1 -0
  133. package/dist/commands/lfs/index.d.ts +3 -0
  134. package/dist/commands/lfs/index.d.ts.map +1 -0
  135. package/dist/commands/lfs/lfs-config.d.ts +174 -0
  136. package/dist/commands/lfs/lfs-config.d.ts.map +1 -0
  137. package/dist/commands/lfs/lfs-endpoint-command.d.ts +83 -0
  138. package/dist/commands/lfs/lfs-endpoint-command.d.ts.map +1 -0
  139. package/dist/commands/local-transport.d.ts.map +1 -1
  140. package/dist/commands/log-command.d.ts +26 -0
  141. package/dist/commands/log-command.d.ts.map +1 -1
  142. package/dist/commands/log-output.d.ts +22 -1
  143. package/dist/commands/log-output.d.ts.map +1 -1
  144. package/dist/commands/ls-files-command.d.ts +153 -0
  145. package/dist/commands/ls-files-command.d.ts.map +1 -0
  146. package/dist/commands/ls-remote-command.d.ts +5 -0
  147. package/dist/commands/ls-remote-command.d.ts.map +1 -1
  148. package/dist/commands/ls-tree-command.d.ts +105 -0
  149. package/dist/commands/ls-tree-command.d.ts.map +1 -0
  150. package/dist/commands/maintenance-run-command.d.ts +122 -0
  151. package/dist/commands/maintenance-run-command.d.ts.map +1 -0
  152. package/dist/commands/merge-command.d.ts +7 -0
  153. package/dist/commands/merge-command.d.ts.map +1 -1
  154. package/dist/commands/merge-config.d.ts +7 -0
  155. package/dist/commands/merge-config.d.ts.map +1 -1
  156. package/dist/commands/merge-drivers.d.ts +67 -5
  157. package/dist/commands/merge-drivers.d.ts.map +1 -1
  158. package/dist/commands/merge-support.d.ts +6 -0
  159. package/dist/commands/merge-support.d.ts.map +1 -1
  160. package/dist/commands/merge-tree-command.d.ts +122 -0
  161. package/dist/commands/merge-tree-command.d.ts.map +1 -0
  162. package/dist/commands/mktag-command.d.ts +51 -0
  163. package/dist/commands/mktag-command.d.ts.map +1 -0
  164. package/dist/commands/object-store/count-objects-command.d.ts +58 -0
  165. package/dist/commands/object-store/count-objects-command.d.ts.map +1 -0
  166. package/dist/commands/object-store/index.d.ts +5 -0
  167. package/dist/commands/object-store/index.d.ts.map +1 -0
  168. package/dist/commands/object-store/objects-directory.d.ts +12 -0
  169. package/dist/commands/object-store/objects-directory.d.ts.map +1 -0
  170. package/dist/commands/object-store/prune-command.d.ts +38 -0
  171. package/dist/commands/object-store/prune-command.d.ts.map +1 -0
  172. package/dist/commands/object-store/show-index-command.d.ts +23 -0
  173. package/dist/commands/object-store/show-index-command.d.ts.map +1 -0
  174. package/dist/commands/ort-merge.d.ts +24 -0
  175. package/dist/commands/ort-merge.d.ts.map +1 -1
  176. package/dist/commands/patch-id-command.d.ts +30 -0
  177. package/dist/commands/patch-id-command.d.ts.map +1 -0
  178. package/dist/commands/patch-id.d.ts +24 -0
  179. package/dist/commands/patch-id.d.ts.map +1 -1
  180. package/dist/commands/plumbing-command.d.ts +66 -0
  181. package/dist/commands/plumbing-command.d.ts.map +1 -0
  182. package/dist/commands/plumbing-input.d.ts +38 -0
  183. package/dist/commands/plumbing-input.d.ts.map +1 -0
  184. package/dist/commands/promisor-remote-reply.d.ts +35 -0
  185. package/dist/commands/promisor-remote-reply.d.ts.map +1 -0
  186. package/dist/commands/promisor-remote.d.ts.map +1 -1
  187. package/dist/commands/pull-command.d.ts.map +1 -1
  188. package/dist/commands/push-command.d.ts +17 -2
  189. package/dist/commands/push-command.d.ts.map +1 -1
  190. package/dist/commands/rebase-command.d.ts +108 -2
  191. package/dist/commands/rebase-command.d.ts.map +1 -1
  192. package/dist/commands/refs-command.d.ts +81 -0
  193. package/dist/commands/refs-command.d.ts.map +1 -0
  194. package/dist/commands/remote-object-info-command.d.ts +55 -0
  195. package/dist/commands/remote-object-info-command.d.ts.map +1 -0
  196. package/dist/commands/remote-transport.d.ts +40 -3
  197. package/dist/commands/remote-transport.d.ts.map +1 -1
  198. package/dist/commands/repack-command.d.ts +115 -0
  199. package/dist/commands/repack-command.d.ts.map +1 -0
  200. package/dist/commands/replace-command.d.ts +143 -0
  201. package/dist/commands/replace-command.d.ts.map +1 -0
  202. package/dist/commands/replay-command.d.ts +117 -0
  203. package/dist/commands/replay-command.d.ts.map +1 -0
  204. package/dist/commands/repo-command.d.ts +136 -0
  205. package/dist/commands/repo-command.d.ts.map +1 -0
  206. package/dist/commands/request-pull-command.d.ts +82 -0
  207. package/dist/commands/request-pull-command.d.ts.map +1 -0
  208. package/dist/commands/rerere-command.d.ts +36 -0
  209. package/dist/commands/rerere-command.d.ts.map +1 -0
  210. package/dist/commands/rerere.d.ts +102 -0
  211. package/dist/commands/rerere.d.ts.map +1 -0
  212. package/dist/commands/rev-filter/commit-grep.d.ts +3 -1
  213. package/dist/commands/rev-filter/commit-grep.d.ts.map +1 -1
  214. package/dist/commands/rev-list-command.d.ts +3 -0
  215. package/dist/commands/rev-list-command.d.ts.map +1 -1
  216. package/dist/commands/rev-parse-command.d.ts +9 -0
  217. package/dist/commands/rev-parse-command.d.ts.map +1 -1
  218. package/dist/commands/revert-command.d.ts +10 -0
  219. package/dist/commands/revert-command.d.ts.map +1 -1
  220. package/dist/commands/revision-range.d.ts +5 -0
  221. package/dist/commands/revision-range.d.ts.map +1 -1
  222. package/dist/commands/revision-resolver.d.ts +12 -0
  223. package/dist/commands/revision-resolver.d.ts.map +1 -1
  224. package/dist/commands/sequencer-pick.d.ts +18 -0
  225. package/dist/commands/sequencer-pick.d.ts.map +1 -1
  226. package/dist/commands/serve-repository.d.ts +23 -1
  227. package/dist/commands/serve-repository.d.ts.map +1 -1
  228. package/dist/commands/session-id.d.ts +18 -0
  229. package/dist/commands/session-id.d.ts.map +1 -0
  230. package/dist/commands/show-branch-command.d.ts +59 -0
  231. package/dist/commands/show-branch-command.d.ts.map +1 -0
  232. package/dist/commands/show-ref-command.d.ts +112 -0
  233. package/dist/commands/show-ref-command.d.ts.map +1 -0
  234. package/dist/commands/signature-check.d.ts +9 -2
  235. package/dist/commands/signature-check.d.ts.map +1 -1
  236. package/dist/commands/signing.d.ts +22 -1
  237. package/dist/commands/signing.d.ts.map +1 -1
  238. package/dist/commands/stash-apply-command.d.ts.map +1 -1
  239. package/dist/commands/stash-export-command.d.ts +115 -0
  240. package/dist/commands/stash-export-command.d.ts.map +1 -0
  241. package/dist/commands/status-command.d.ts +2 -1
  242. package/dist/commands/status-command.d.ts.map +1 -1
  243. package/dist/commands/stripspace-command.d.ts +44 -0
  244. package/dist/commands/stripspace-command.d.ts.map +1 -0
  245. package/dist/commands/submodule-add-command.d.ts +10 -1
  246. package/dist/commands/submodule-add-command.d.ts.map +1 -1
  247. package/dist/commands/submodule-auth.d.ts +3 -1
  248. package/dist/commands/submodule-auth.d.ts.map +1 -1
  249. package/dist/commands/submodule-commands.d.ts +9 -1
  250. package/dist/commands/submodule-commands.d.ts.map +1 -1
  251. package/dist/commands/submodule-update-command.d.ts +13 -1
  252. package/dist/commands/submodule-update-command.d.ts.map +1 -1
  253. package/dist/commands/textconv-cache.d.ts +58 -0
  254. package/dist/commands/textconv-cache.d.ts.map +1 -0
  255. package/dist/commands/tree-restore.d.ts +5 -0
  256. package/dist/commands/tree-restore.d.ts.map +1 -1
  257. package/dist/commands/unpack-objects-command.d.ts +47 -0
  258. package/dist/commands/unpack-objects-command.d.ts.map +1 -0
  259. package/dist/commands/update-index-command.d.ts +110 -0
  260. package/dist/commands/update-index-command.d.ts.map +1 -0
  261. package/dist/commands/uri-protocols.d.ts +13 -0
  262. package/dist/commands/uri-protocols.d.ts.map +1 -0
  263. package/dist/commands/url-parse-command.d.ts +30 -0
  264. package/dist/commands/url-parse-command.d.ts.map +1 -0
  265. package/dist/commands/var-command.d.ts +42 -0
  266. package/dist/commands/var-command.d.ts.map +1 -0
  267. package/dist/{commands-CNvli5bl.js → commands-Mlo1dxQN.js} +52078 -44471
  268. package/dist/errors/command-errors.d.ts +33 -0
  269. package/dist/errors/command-errors.d.ts.map +1 -1
  270. package/dist/errors/index.js +39 -1
  271. package/dist/{fsck-CPeDh9fh.js → fsck-CrhVMNIH.js} +184 -143
  272. package/dist/git-command.d.ts +58 -2
  273. package/dist/git-command.d.ts.map +1 -1
  274. package/dist/git.d.ts +532 -1
  275. package/dist/git.d.ts.map +1 -1
  276. package/dist/guarded-transport-command.d.ts +3 -1
  277. package/dist/guarded-transport-command.d.ts.map +1 -1
  278. package/dist/index.js +7 -6
  279. package/dist/maintenance-run-command-Bw21HEkH.js +13539 -0
  280. package/dist/{remote-transport-CCmBadm-.js → remote-transport-Bu4PGSMD.js} +1009 -10
  281. package/dist/results/cherry-pick-result.d.ts +6 -0
  282. package/dist/results/cherry-pick-result.d.ts.map +1 -1
  283. package/dist/results/diff-entry.d.ts +10 -0
  284. package/dist/results/diff-entry.d.ts.map +1 -1
  285. package/dist/results/diff-formatter.d.ts.map +1 -1
  286. package/dist/results/diff-output.d.ts +49 -3
  287. package/dist/results/diff-output.d.ts.map +1 -1
  288. package/dist/results/fetch-result.d.ts +12 -0
  289. package/dist/results/fetch-result.d.ts.map +1 -1
  290. package/dist/results/index.js +2 -2
  291. package/dist/results/merge-result.d.ts +5 -0
  292. package/dist/results/merge-result.d.ts.map +1 -1
  293. package/dist/results/push-result.d.ts +5 -0
  294. package/dist/results/push-result.d.ts.map +1 -1
  295. package/dist/results/rebase-result.d.ts +7 -0
  296. package/dist/results/rebase-result.d.ts.map +1 -1
  297. package/dist/results/revert-result.d.ts +6 -0
  298. package/dist/results/revert-result.d.ts.map +1 -1
  299. package/dist/results/stash-result.d.ts +5 -0
  300. package/dist/results/stash-result.d.ts.map +1 -1
  301. package/dist/{results-BDuEgdLU.js → results-ERo9vELd.js} +28511 -25685
  302. package/dist/transport-command.d.ts +79 -1
  303. package/dist/transport-command.d.ts.map +1 -1
  304. package/package.json +12 -12
  305. package/src/commands/add-command.ts +3 -0
  306. package/src/commands/add-patch/patch-backend.ts +4 -1
  307. package/src/commands/add-patch/patch-modes.ts +26 -2
  308. package/src/commands/add-patch/patch-session.ts +6 -0
  309. package/src/commands/am/am-command.ts +163 -8
  310. package/src/commands/apply/index.ts +1 -0
  311. package/src/commands/archive/archive-command.ts +1148 -0
  312. package/src/commands/archive/archive-entry.ts +93 -0
  313. package/src/commands/archive/index.ts +7 -0
  314. package/src/commands/archive/remote-archive-command.ts +140 -0
  315. package/src/commands/archive/tar-archive.ts +207 -0
  316. package/src/commands/archive/tar-commit-id.ts +72 -0
  317. package/src/commands/archive/upload-archive-writer.ts +213 -0
  318. package/src/commands/archive/zip-archive.ts +317 -0
  319. package/src/commands/attributes-source.ts +26 -12
  320. package/src/commands/blame-command.ts +118 -19
  321. package/src/commands/bundle/bundle-create-command.ts +405 -0
  322. package/src/commands/bundle/bundle-format.ts +228 -0
  323. package/src/commands/bundle/bundle-list.ts +276 -0
  324. package/src/commands/bundle/bundle-read-commands.ts +157 -0
  325. package/src/commands/bundle/bundle-support.ts +85 -0
  326. package/src/commands/bundle/bundle-transport.ts +107 -0
  327. package/src/commands/bundle/bundle-uri-host.ts +204 -0
  328. package/src/commands/bundle/bundle-uri.ts +236 -0
  329. package/src/commands/bundle/bundle-verify.ts +152 -0
  330. package/src/commands/bundle/index.ts +14 -0
  331. package/src/commands/cat-file/batch-format.ts +193 -0
  332. package/src/commands/cat-file/cat-file-command.ts +857 -0
  333. package/src/commands/cat-file/index.ts +2 -0
  334. package/src/commands/check-attr-command.ts +333 -0
  335. package/src/commands/check-ignore-command.ts +261 -0
  336. package/src/commands/check-ref-format-command.ts +129 -0
  337. package/src/commands/checkout-command.ts +39 -21
  338. package/src/commands/checkout-index-command.ts +568 -0
  339. package/src/commands/checkout-paths.ts +7 -0
  340. package/src/commands/cherry-pick-command.ts +21 -1
  341. package/src/commands/clone-command.ts +208 -7
  342. package/src/commands/commit-command.ts +22 -4
  343. package/src/commands/config-command.ts +9 -0
  344. package/src/commands/daemon-access-hook.ts +78 -0
  345. package/src/commands/default-branch.ts +99 -1
  346. package/src/commands/diff-command.ts +573 -46
  347. package/src/commands/diff-external.ts +131 -0
  348. package/src/commands/diff-plumbing/diff-pairs-command.ts +193 -0
  349. package/src/commands/diff-plumbing/diff-plumbing-command.ts +424 -0
  350. package/src/commands/diff-plumbing/index.ts +2 -0
  351. package/src/commands/diff-textconv.ts +5 -1
  352. package/src/commands/fast-export/fast-export-command.ts +911 -0
  353. package/src/commands/fast-export/fast-import-command.ts +1553 -0
  354. package/src/commands/fast-export/fast-stream-support.ts +162 -0
  355. package/src/commands/fast-export/index.ts +3 -0
  356. package/src/commands/fetch-command.ts +312 -8
  357. package/src/commands/fetch-multiple-command.ts +4 -1
  358. package/src/commands/format-rev-command.ts +251 -0
  359. package/src/commands/fsck/fsck-command.ts +47 -20
  360. package/src/commands/fsck/fsck-msg-ids.ts +19 -3
  361. package/src/commands/fsck/fsck-pack.ts +2 -2
  362. package/src/commands/fsmonitor-refresh.ts +315 -0
  363. package/src/commands/gc-command.ts +10 -0
  364. package/src/commands/git-hooks.ts +123 -6
  365. package/src/commands/git-paths.ts +136 -0
  366. package/src/commands/grep/grep-command.ts +38 -15
  367. package/src/commands/history-command.ts +617 -0
  368. package/src/commands/http-config.ts +139 -0
  369. package/src/commands/index-adder.ts +37 -3
  370. package/src/commands/index-host.ts +6 -1
  371. package/src/commands/index.ts +45 -0
  372. package/src/commands/init-command.ts +14 -0
  373. package/src/commands/last-modified-command.ts +804 -0
  374. package/src/commands/lfs/go-url.ts +370 -0
  375. package/src/commands/lfs/index.ts +2 -0
  376. package/src/commands/lfs/lfs-config.ts +738 -0
  377. package/src/commands/lfs/lfs-endpoint-command.ts +180 -0
  378. package/src/commands/local-transport.ts +252 -4
  379. package/src/commands/log-command.ts +104 -5
  380. package/src/commands/log-output.ts +55 -5
  381. package/src/commands/ls-files-command.ts +1177 -0
  382. package/src/commands/ls-remote-command.ts +6 -0
  383. package/src/commands/ls-tree-command.ts +684 -0
  384. package/src/commands/maintenance-run-command.ts +949 -0
  385. package/src/commands/merge-command.ts +78 -32
  386. package/src/commands/merge-config.ts +23 -1
  387. package/src/commands/merge-drivers.ts +109 -20
  388. package/src/commands/merge-support.ts +29 -5
  389. package/src/commands/merge-tree-command.ts +786 -0
  390. package/src/commands/mktag-command.ts +149 -0
  391. package/src/commands/object-store/count-objects-command.ts +404 -0
  392. package/src/commands/object-store/index.ts +4 -0
  393. package/src/commands/object-store/objects-directory.ts +24 -0
  394. package/src/commands/object-store/prune-command.ts +129 -0
  395. package/src/commands/object-store/show-index-command.ts +151 -0
  396. package/src/commands/ort-merge.ts +92 -25
  397. package/src/commands/patch-id-command.ts +65 -0
  398. package/src/commands/patch-id.ts +218 -0
  399. package/src/commands/plumbing-command.ts +141 -0
  400. package/src/commands/plumbing-input.ts +87 -0
  401. package/src/commands/promisor-remote-reply.ts +276 -0
  402. package/src/commands/promisor-remote.ts +25 -2
  403. package/src/commands/pull-command.ts +2 -0
  404. package/src/commands/push-command.ts +87 -5
  405. package/src/commands/rebase-command.ts +507 -19
  406. package/src/commands/refs-command.ts +274 -0
  407. package/src/commands/remote-object-info-command.ts +109 -0
  408. package/src/commands/remote-transport.ts +116 -1
  409. package/src/commands/repack-command.ts +383 -0
  410. package/src/commands/replace-command.ts +816 -0
  411. package/src/commands/replay-command.ts +674 -0
  412. package/src/commands/repo-command.ts +967 -0
  413. package/src/commands/request-pull-command.ts +356 -0
  414. package/src/commands/rerere-command.ts +179 -0
  415. package/src/commands/rerere.ts +925 -0
  416. package/src/commands/rev-filter/commit-grep.ts +7 -2
  417. package/src/commands/rev-list-command.ts +9 -0
  418. package/src/commands/rev-parse-command.ts +62 -4
  419. package/src/commands/revert-command.ts +21 -1
  420. package/src/commands/revision-range.ts +7 -2
  421. package/src/commands/revision-resolver.ts +44 -3
  422. package/src/commands/sequencer-pick.ts +47 -0
  423. package/src/commands/serve-repository.ts +65 -0
  424. package/src/commands/session-id.ts +31 -0
  425. package/src/commands/show-branch-command.ts +981 -0
  426. package/src/commands/show-command.ts +1 -1
  427. package/src/commands/show-ref-command.ts +439 -0
  428. package/src/commands/signature-check.ts +37 -5
  429. package/src/commands/signing.ts +122 -16
  430. package/src/commands/stash-apply-command.ts +3 -0
  431. package/src/commands/stash-export-command.ts +397 -0
  432. package/src/commands/status-command.ts +43 -6
  433. package/src/commands/stripspace-command.ts +118 -0
  434. package/src/commands/submodule-add-command.ts +22 -1
  435. package/src/commands/submodule-auth.ts +61 -6
  436. package/src/commands/submodule-commands.ts +12 -2
  437. package/src/commands/submodule-update-command.ts +29 -0
  438. package/src/commands/textconv-cache.ts +143 -0
  439. package/src/commands/tree-restore.ts +14 -0
  440. package/src/commands/unpack-objects-command.ts +235 -0
  441. package/src/commands/update-index-command.ts +1016 -0
  442. package/src/commands/uri-protocols.ts +13 -0
  443. package/src/commands/url-parse-command.ts +67 -0
  444. package/src/commands/var-command.ts +219 -0
  445. package/src/errors/command-errors.ts +45 -0
  446. package/src/git-command.ts +131 -1
  447. package/src/git.ts +808 -1
  448. package/src/guarded-transport-command.ts +6 -1
  449. package/src/results/cherry-pick-result.ts +6 -0
  450. package/src/results/diff-entry.ts +12 -0
  451. package/src/results/diff-formatter.ts +7 -4
  452. package/src/results/diff-output.ts +117 -11
  453. package/src/results/diff-pickaxe.ts +1 -1
  454. package/src/results/fetch-result.ts +12 -0
  455. package/src/results/merge-result.ts +5 -0
  456. package/src/results/push-result.ts +5 -0
  457. package/src/results/rebase-result.ts +7 -0
  458. package/src/results/revert-result.ts +6 -0
  459. package/src/results/stash-result.ts +6 -0
  460. package/src/transport-command.ts +182 -1
@@ -0,0 +1,1177 @@
1
+ /**
2
+ * `git ls-files` (builtin/ls-files.c): the index's entries, the untracked, ignored, deleted,
3
+ * modified and killed files, with git's output formats (`-s`, `-t`, `-v`, `--eol`,
4
+ * `--format`, `-z`) and its pathspec rules, run from any directory of the worktree.
5
+ *
6
+ * @example
7
+ * ```typescript
8
+ * // git ls-files -s
9
+ * const { stdout } = await git.lsFiles().setStage(true).callOutput();
10
+ * // "100644 3b18e512dba79e4c8300dd08aeb37f8e728b8dad 0\thello.txt\n"
11
+ *
12
+ * // git ls-files --others --exclude-standard (from the subdirectory src/)
13
+ * await git.lsFiles().setOthers(true).setExcludeStandard().setPrefix("src/").callOutput();
14
+ * ```
15
+ */
16
+
17
+ import { parseGitBool } from "@statewalker/vcs-utils";
18
+ import { compareGitPaths, decodeGitPatternFile } from "@statewalker/vcs-utils/encoding";
19
+ import { FileMode } from "@statewalker/vcs-utils/files";
20
+ import {
21
+ compareWithWorktree,
22
+ createCommandLineExcludes,
23
+ createIgnoreNode,
24
+ DIR_COLLECT_KILLED_ONLY,
25
+ DIR_HIDE_EMPTY_DIRECTORIES,
26
+ DIR_SHOW_IGNORED,
27
+ DIR_SHOW_OTHER_DIRECTORIES,
28
+ eolStatsAscii,
29
+ expandUserPath,
30
+ type IgnoreNode,
31
+ IndexPathLookup,
32
+ type ResolveUndoRecord,
33
+ type StagingEntry,
34
+ scanUntracked,
35
+ type UntrackedScanHost,
36
+ unreadableDirectoryWarning,
37
+ type Worktree,
38
+ walkUntrackedScanHost,
39
+ withWorktreeEntries,
40
+ xdgConfigPath,
41
+ } from "@statewalker/vcs-working-tree";
42
+ import { RemoteConfigStore } from "../remote-config/index.js";
43
+ import { quotePath } from "../results/quote-path.js";
44
+ import { coreBool, worktreeModeTrust } from "./core-config.js";
45
+ import { hostEnvironmentOf } from "./git-ident.js";
46
+ import { prefixPathGently, relativePath } from "./git-paths.js";
47
+ import {
48
+ DO_MATCH_DIRECTORY,
49
+ matchPathspec,
50
+ matchPathspecSeen,
51
+ type PathspecItem,
52
+ parsePathspec,
53
+ pathspecCommonPrefix,
54
+ pathspecErrors,
55
+ pathspecName,
56
+ untrackedScanPathspec,
57
+ } from "./pathspec.js";
58
+ import { PlumbingCommand, PlumbingError } from "./plumbing-command.js";
59
+
60
+ /** One entry of the index as ls-files walks it (`struct cache_entry`). */
61
+ interface ListedEntry {
62
+ path: string;
63
+ mode: number;
64
+ objectId: string;
65
+ stage: number;
66
+ assumeValid: boolean;
67
+ skipWorktree: boolean;
68
+ intentToAdd: boolean;
69
+ /** git's `CE_UPDATE` mark of `--with-tree`: a tree entry a stage-0 entry shadows */
70
+ shadowed: boolean;
71
+ /** The index entry itself (for the stat comparison); none for a `--with-tree` entry */
72
+ entry?: StagingEntry;
73
+ }
74
+
75
+ /** An exclude source given in order (`-X <file>`, `--exclude-standard`). */
76
+ type ExcludeSource = { kind: "file"; path: string } | { kind: "standard" };
77
+
78
+ const S_IFMT = 0o170000;
79
+ const isRegularMode = (mode: number) => (mode & S_IFMT) === 0o100000;
80
+
81
+ /**
82
+ * `git ls-files`. Output is written as git writes it ({@link PlumbingCommand}); the exit
83
+ * status is 1 when `--error-unmatch` finds an element matching nothing.
84
+ *
85
+ * Not supported: `--recurse-submodules` and `--debug` (refused). `--sparse` has no effect: the index is always held
86
+ * expanded, so the directory entries of a sparse index are listed as their files, as git
87
+ * lists them without `--sparse`.
88
+ */
89
+ export class LsFilesCommand extends PlumbingCommand {
90
+ private cached = false;
91
+ private deleted = false;
92
+ private modified = false;
93
+ private others = false;
94
+ private ignored = false;
95
+ private stage = false;
96
+ private killed = false;
97
+ private unmerged = false;
98
+ private resolveUndo = false;
99
+ private directory = false;
100
+ private hideEmptyDirectories = false;
101
+ private tags = false;
102
+ private validBit = false;
103
+ private fsmonitorBit = false;
104
+ private nul = false;
105
+ private eol = false;
106
+ private deduplicate = false;
107
+ private fullName = false;
108
+ private errorUnmatch = false;
109
+ private recurseSubmodules = false;
110
+ private abbrev: number | true = 0;
111
+ private withTree?: string;
112
+ private format?: string;
113
+ private prefix = "";
114
+ private readonly paths: string[] = [];
115
+ private readonly excludes: string[] = [];
116
+ private readonly excludeSources: ExcludeSource[] = [];
117
+ private excludePerDirectory?: string;
118
+ private compatibility: "2.43" | "2.56" = "2.56";
119
+
120
+ /** `-c`/`--cached`: the index's entries (the default when nothing else is asked). */
121
+ setCached(value: boolean): this {
122
+ return this.set(() => {
123
+ this.cached = value;
124
+ });
125
+ }
126
+
127
+ /** `-d`/`--deleted`: entries whose file is gone. */
128
+ setDeleted(value: boolean): this {
129
+ return this.set(() => {
130
+ this.deleted = value;
131
+ });
132
+ }
133
+
134
+ /** `-m`/`--modified`: entries whose file differs (a deleted one included). */
135
+ setModified(value: boolean): this {
136
+ return this.set(() => {
137
+ this.modified = value;
138
+ });
139
+ }
140
+
141
+ /** `-o`/`--others`: the untracked files. */
142
+ setOthers(value: boolean): this {
143
+ return this.set(() => {
144
+ this.others = value;
145
+ });
146
+ }
147
+
148
+ /** `-i`/`--ignored`: only the ignored files (with `-o`) or entries (with `-c`). */
149
+ setIgnored(value: boolean): this {
150
+ return this.set(() => {
151
+ this.ignored = value;
152
+ });
153
+ }
154
+
155
+ /** `-s`/`--stage`: each entry's mode, object name and stage. */
156
+ setStage(value: boolean): this {
157
+ return this.set(() => {
158
+ this.stage = value;
159
+ });
160
+ }
161
+
162
+ /** `-k`/`--killed`: the untracked files a checkout of the index would remove. */
163
+ setKilled(value: boolean): this {
164
+ return this.set(() => {
165
+ this.killed = value;
166
+ });
167
+ }
168
+
169
+ /** `-u`/`--unmerged`: the unmerged entries (implies `-s`). */
170
+ setUnmerged(value: boolean): this {
171
+ return this.set(() => {
172
+ this.unmerged = value;
173
+ });
174
+ }
175
+
176
+ /** `--resolve-undo`: the resolve-undo records (`U` tag with `-t`). */
177
+ setResolveUndo(value: boolean): this {
178
+ return this.set(() => {
179
+ this.resolveUndo = value;
180
+ });
181
+ }
182
+
183
+ /** `--directory`: an untracked directory as `dir/` rather than its files. */
184
+ setDirectory(value: boolean): this {
185
+ return this.set(() => {
186
+ this.directory = value;
187
+ });
188
+ }
189
+
190
+ /** `--[no-]empty-directory`: false hides empty untracked directories. */
191
+ setEmptyDirectory(show: boolean): this {
192
+ return this.set(() => {
193
+ this.hideEmptyDirectories = !show;
194
+ });
195
+ }
196
+
197
+ /** `-t`: a status tag before each path (`H`, `S`, `M`, `R`, `C`, `K`, `?`, `U`). */
198
+ setShowTags(value: boolean): this {
199
+ return this.set(() => {
200
+ this.tags = value;
201
+ });
202
+ }
203
+
204
+ /** `-v`: tags, lowercase for assume-unchanged entries. */
205
+ setShowValidBit(value: boolean): this {
206
+ return this.set(() => {
207
+ this.validBit = value;
208
+ });
209
+ }
210
+
211
+ /** `-f`: tags, lowercase for fsmonitor-valid entries (`core.fsmonitor`, the monitor asked). */
212
+ setShowFsmonitorBit(value: boolean): this {
213
+ return this.set(() => {
214
+ this.fsmonitorBit = value;
215
+ });
216
+ }
217
+
218
+ /** `-z`: paths ended by NUL and never quoted. */
219
+ setNulTerminated(value: boolean): this {
220
+ return this.set(() => {
221
+ this.nul = value;
222
+ });
223
+ }
224
+
225
+ /** `--eol`: the `i/`, `w/` and `attr/` line-ending columns before each path. */
226
+ setEol(value: boolean): this {
227
+ return this.set(() => {
228
+ this.eol = value;
229
+ });
230
+ }
231
+
232
+ /** `--deduplicate`: each path once. */
233
+ setDeduplicate(value: boolean): this {
234
+ return this.set(() => {
235
+ this.deduplicate = value;
236
+ });
237
+ }
238
+
239
+ /** `--full-name`: paths from the top of the worktree, whatever the prefix. */
240
+ setFullName(value: boolean): this {
241
+ return this.set(() => {
242
+ this.fullName = value;
243
+ });
244
+ }
245
+
246
+ /** `--error-unmatch`: an element matching nothing is an error (exit 1). */
247
+ setErrorUnmatch(value: boolean): this {
248
+ return this.set(() => {
249
+ this.errorUnmatch = value;
250
+ });
251
+ }
252
+
253
+ /** `--recurse-submodules` (refused: not supported). */
254
+ setRecurseSubmodules(value: boolean): this {
255
+ return this.set(() => {
256
+ this.recurseSubmodules = value;
257
+ });
258
+ }
259
+
260
+ /**
261
+ * `--abbrev[=<n>]`: object names abbreviated (`true`: `core.abbrev`'s length; a number: at
262
+ * least that many digits, 4 at the least; 0: full names, the default).
263
+ */
264
+ setAbbrev(value: number | boolean): this {
265
+ return this.set(() => {
266
+ if (value === false) this.abbrev = 0;
267
+ else if (value === true) this.abbrev = true;
268
+ else this.abbrev = value > 0 && value < 4 ? 4 : value;
269
+ });
270
+ }
271
+
272
+ /** `--with-tree=<tree-ish>`: the tree's paths the index lacks are listed too. */
273
+ setWithTree(treeish: string): this {
274
+ return this.set(() => {
275
+ this.withTree = treeish;
276
+ });
277
+ }
278
+
279
+ /** `--format=<format>`: each entry through a format of `%(atom)`s. */
280
+ setFormat(format: string): this {
281
+ return this.set(() => {
282
+ this.format = format;
283
+ });
284
+ }
285
+
286
+ /** `-x`/`--exclude=<pattern>`: an exclude pattern (git's `EXC_CMDL`). */
287
+ addExclude(pattern: string): this {
288
+ return this.set(() => {
289
+ this.excludes.push(pattern);
290
+ });
291
+ }
292
+
293
+ /** `-X`/`--exclude-from=<file>`: exclude patterns from a file (from the worktree's top). */
294
+ addExcludeFrom(file: string): this {
295
+ return this.set(() => {
296
+ this.excludeSources.push({ kind: "file", path: file });
297
+ });
298
+ }
299
+
300
+ /** `--exclude-per-directory=<file>`: per-directory exclude files of that name. */
301
+ setExcludePerDirectory(name: string): this {
302
+ return this.set(() => {
303
+ this.excludePerDirectory = name;
304
+ });
305
+ }
306
+
307
+ /**
308
+ * `--exclude-standard`: `core.excludesFile`, `$GIT_DIR/info/exclude` and `.gitignore`
309
+ * files.
310
+ */
311
+ setExcludeStandard(): this {
312
+ return this.set(() => {
313
+ this.excludeSources.push({ kind: "standard" });
314
+ this.excludePerDirectory = ".gitignore";
315
+ });
316
+ }
317
+
318
+ /** Pathspec elements, read from the {@link setPrefix} directory. */
319
+ addPathspec(...paths: string[]): this {
320
+ return this.set(() => {
321
+ this.paths.push(...paths);
322
+ });
323
+ }
324
+
325
+ /** The current directory below the top of the worktree (`sub/dir/`). */
326
+ setPrefix(prefix: string): this {
327
+ return this.set(() => {
328
+ this.prefix = prefix === "" || prefix.endsWith("/") ? prefix : `${prefix}/`;
329
+ });
330
+ }
331
+
332
+ /** The git version whose behaviour to follow (default 2.56). */
333
+ setCompatibility(version: "2.43" | "2.56"): this {
334
+ return this.set(() => {
335
+ this.compatibility = version;
336
+ });
337
+ }
338
+
339
+ private set(apply: () => void): this {
340
+ this.checkCallable();
341
+ apply();
342
+ return this;
343
+ }
344
+
345
+ /** It reads objects only: ids are abbreviated over cached listings. */
346
+ protected override writesNoObjects(): boolean {
347
+ return true;
348
+ }
349
+
350
+ protected async run(): Promise<number> {
351
+ if (
352
+ this.format !== undefined &&
353
+ (this.stage ||
354
+ this.others ||
355
+ this.killed ||
356
+ this.resolveUndo ||
357
+ this.deduplicate ||
358
+ this.eol ||
359
+ this.tags)
360
+ ) {
361
+ throw new PlumbingError(
362
+ "fatal: --format cannot be used with -s, -o, -k, -t, --resolve-undo, --deduplicate, --eol",
363
+ 129,
364
+ );
365
+ }
366
+ const tagged = this.tags || this.validBit || this.fsmonitorBit;
367
+ const showStage = this.stage || this.unmerged;
368
+ const dedup = this.deduplicate && !(this.tags || showStage);
369
+ const excludeGiven =
370
+ this.excludes.length > 0 ||
371
+ this.excludeSources.length > 0 ||
372
+ this.excludePerDirectory !== undefined;
373
+ const needsWorktree =
374
+ this.modified || this.others || this.deleted || this.ignored || this.killed;
375
+ const worktree = needsWorktree ? this.worktreeAccess : undefined;
376
+ if (needsWorktree && !worktree) {
377
+ throw new PlumbingError("fatal: this operation must be run in a work tree");
378
+ }
379
+ if (
380
+ this.recurseSubmodules &&
381
+ (this.deleted ||
382
+ this.others ||
383
+ this.unmerged ||
384
+ this.killed ||
385
+ this.modified ||
386
+ this.resolveUndo ||
387
+ this.withTree !== undefined)
388
+ ) {
389
+ throw new PlumbingError("fatal: ls-files --recurse-submodules unsupported mode");
390
+ }
391
+ if (this.recurseSubmodules && this.errorUnmatch) {
392
+ throw new PlumbingError(
393
+ "fatal: ls-files --recurse-submodules does not support --error-unmatch",
394
+ );
395
+ }
396
+ if (this.recurseSubmodules) {
397
+ throw new PlumbingError("fatal: ls-files --recurse-submodules is not supported");
398
+ }
399
+
400
+ // parse_pathspec with PATHSPEC_PREFER_CWD: no element, or only excludes, is the current
401
+ // directory; each element is read against it (prefix_path_gently), absolute ones too
402
+ const prefix = this.prefix;
403
+ const top = this.paths.length > 0 ? await this.hostWorkingDir() : undefined;
404
+ const args = this.paths.map((p) => prefixedElement(p, prefix, top));
405
+ const originals = this.paths.length > 0 ? [...this.paths] : prefix ? [""] : [];
406
+ let items: PathspecItem[];
407
+ try {
408
+ if (args.length === 0 && prefix) args.push(prefix);
409
+ items = parsePathspec(args);
410
+ // only excludes: parse_pathspec's implicit item is the current directory
411
+ if (prefix && items.length > args.length) {
412
+ items[items.length - 1] = parsePathspec([prefix])[0] as PathspecItem;
413
+ }
414
+ } catch (e) {
415
+ throw new PlumbingError(`fatal: ${(e as Error).message}`);
416
+ }
417
+ const maxPrefix = pathspecCommonPrefix(items);
418
+ const pruneBy = maxPrefix.endsWith("/") ? maxPrefix.slice(0, -1) : maxPrefix;
419
+ const seen = this.errorUnmatch && items.length > 0 ? items.map(() => 0) : undefined;
420
+ const exactStopsGlobs = this.compatibility === "2.43";
421
+ const match = (path: string, isDir: boolean) => {
422
+ const flags = isDir ? DO_MATCH_DIRECTORY : 0;
423
+ return seen
424
+ ? matchPathspecSeen(items, path, flags, seen, exactStopsGlobs) > 0
425
+ : matchPathspec(items, path, flags) > 0;
426
+ };
427
+
428
+ if (this.ignored && !this.others && !this.cached) {
429
+ throw new PlumbingError("fatal: ls-files -i must be used with either -o or -c");
430
+ }
431
+ if (this.ignored && !excludeGiven) {
432
+ throw new PlumbingError("fatal: ls-files --ignored needs some exclude pattern");
433
+ }
434
+ const cached =
435
+ this.cached ||
436
+ !(
437
+ showStage ||
438
+ this.deleted ||
439
+ this.others ||
440
+ this.unmerged ||
441
+ this.killed ||
442
+ this.modified ||
443
+ this.resolveUndo
444
+ );
445
+
446
+ await this.readCurrentIndex(false);
447
+ // `-f`: the monitor asked as git asks it on reading the index (tweak_fsmonitor)
448
+ const fsm = this.fsmonitorBit ? await this.fsmonitorRefresh(this.staging) : undefined;
449
+ // prune_index: only the entries under the pathspec's common leading directory
450
+ const list: ListedEntry[] = [];
451
+ for await (const e of this.staging.entryList?.() ?? this.staging.entries()) {
452
+ if (pruneBy && !pathspecName(e.path).startsWith(pruneBy)) continue;
453
+ list.push({
454
+ path: e.path,
455
+ mode: e.mode,
456
+ objectId: e.objectId,
457
+ stage: e.stage,
458
+ assumeValid: e.assumeValid === true,
459
+ skipWorktree: e.skipWorktree === true,
460
+ intentToAdd: e.intentToAdd === true,
461
+ shadowed: false,
462
+ entry: e,
463
+ });
464
+ }
465
+ if (this.withTree !== undefined) {
466
+ if (showStage) {
467
+ throw new PlumbingError(
468
+ "fatal: options 'ls-files --with-tree' and '-s/-u' cannot be used together",
469
+ );
470
+ }
471
+ await this.overlayTree(list, this.withTree, maxPrefix);
472
+ }
473
+
474
+ const quoteFully =
475
+ parseGitBool(RemoteConfigStore.from(this.workingCopy).value("core.quotePath") ?? "true") ??
476
+ true;
477
+ const term = this.nul ? "\0" : "\n";
478
+ const relative = (path: string) =>
479
+ this.fullName || !prefix ? path : relativePath(path, prefix);
480
+ const nameText = (path: string) => {
481
+ const rel = relative(path);
482
+ return this.nul ? rel : quotePath(rel, quoteFully);
483
+ };
484
+
485
+ const tag = (name: string) => (tagged ? `${name} ` : "");
486
+ const rules = excludeGiven ? await this.excludeRules(worktree, list) : undefined;
487
+ const eolColumns = this.eol ? await this.eolColumns(worktree, list) : undefined;
488
+
489
+ const body = async () => {
490
+ // show_files: the directory walk for -o and -k first
491
+ if (this.others || this.killed) {
492
+ const ws = worktree as Worktree;
493
+ const names = await this.walkOthers(ws, items, list, rules);
494
+ if (this.others) {
495
+ for (const name of names) {
496
+ // index_name_is_other: a directory named as an index entry is no other file
497
+ if (isInIndex(list, name.endsWith("/") ? name.slice(0, -1) : name)) continue;
498
+ if (seen) {
499
+ const dir = name.endsWith("/");
500
+ matchPathspecSeen(
501
+ items,
502
+ dir ? name.slice(0, -1) : name,
503
+ dir ? DO_MATCH_DIRECTORY : 0,
504
+ seen,
505
+ exactStopsGlobs,
506
+ );
507
+ }
508
+ await this.write(
509
+ `${tag("?")}${eolColumns ? await eolColumns(name, undefined) : ""}${nameText(name)}${term}`,
510
+ );
511
+ }
512
+ }
513
+ if (this.killed) {
514
+ for (const name of names) {
515
+ if (!isKilled(list, name)) continue;
516
+ if (seen) {
517
+ const dir = name.endsWith("/");
518
+ matchPathspecSeen(
519
+ items,
520
+ dir ? name.slice(0, -1) : name,
521
+ dir ? DO_MATCH_DIRECTORY : 0,
522
+ seen,
523
+ exactStopsGlobs,
524
+ );
525
+ }
526
+ await this.write(
527
+ `${tag("K")}${eolColumns ? await eolColumns(name, undefined) : ""}${nameText(name)}${term}`,
528
+ );
529
+ }
530
+ }
531
+ }
532
+ if (!(cached || showStage || this.deleted || this.modified)) return;
533
+
534
+ const showCe = async (e: ListedEntry, name: string) => {
535
+ const isDir = (e.mode & S_IFMT) === 0o040000 || e.mode === FileMode.GITLINK;
536
+ if (!match(e.path, isDir)) return;
537
+ if (this.format !== undefined) {
538
+ await this.write(`${await this.formatEntry(e, worktree, list, nameText)}${term}`);
539
+ return;
540
+ }
541
+ let t = tagged ? `${name} ` : "";
542
+ if (t && this.validBit && e.assumeValid) t = lowerTag(t);
543
+ if (t && fsm && e.entry && fsm.state.isValid(e.entry)) t = lowerTag(t);
544
+ let line = t;
545
+ if (showStage) {
546
+ line += `${e.mode.toString(8).padStart(6, "0")} ${await this.abbreviated(e.objectId)} ${e.stage}\t`;
547
+ }
548
+ if (eolColumns) line += await eolColumns(e.path, e);
549
+ await this.write(`${line}${nameText(e.path)}${term}`);
550
+ };
551
+
552
+ // the entries a stat pass looks at (-d, -m)
553
+ const statted = (e: ListedEntry) => (this.deleted || this.modified) && !e.skipWorktree;
554
+ const trust = worktree ? worktreeModeTrust(this.workingCopy, worktree) : undefined;
555
+ const indexTime = this.staging.getUpdateTime();
556
+ const walk = worktree
557
+ ? withWorktreeEntries(worktree, list, statted)
558
+ : (async function* () {
559
+ for (const item of list) yield { item, current: undefined };
560
+ })();
561
+ let skipName: string | undefined;
562
+ for await (const { item: e, current } of walk) {
563
+ if (skipName !== undefined && e.path === skipName) continue;
564
+ skipName = undefined;
565
+ if (rules) {
566
+ const isDir = e.mode === FileMode.GITLINK;
567
+ await rules.loadFor(e.path);
568
+ if (this.ignored && !rules.isExcluded(e.path, isDir)) continue;
569
+ }
570
+ if (e.shadowed) continue;
571
+ if ((cached || showStage) && (!this.unmerged || e.stage !== 0)) {
572
+ await showCe(e, e.stage !== 0 ? "M" : e.skipWorktree ? "S" : "H");
573
+ if (dedup) {
574
+ skipName = e.path;
575
+ continue;
576
+ }
577
+ }
578
+ if (!(this.deleted || this.modified)) continue;
579
+ if (e.skipWorktree) continue;
580
+ const missing = !current;
581
+ if (missing && this.deleted) {
582
+ await showCe(e, "R");
583
+ if (dedup) {
584
+ skipName = e.path;
585
+ continue;
586
+ }
587
+ }
588
+ if (
589
+ this.modified &&
590
+ (missing || (await this.entryModified(e, current, worktree, trust, indexTime)))
591
+ ) {
592
+ await showCe(e, "C");
593
+ if (dedup) {
594
+ skipName = e.path;
595
+ }
596
+ }
597
+ }
598
+ };
599
+ if (worktree?.batch) await worktree.batch(body);
600
+ else await body();
601
+
602
+ if (this.resolveUndo) {
603
+ const records = [...(this.staging.getResolveUndo?.() ?? [])].sort((a, b) =>
604
+ compareGitPaths(a.path, b.path),
605
+ );
606
+ for (const record of records)
607
+ await this.showResolveUndo(record, pruneBy, match, tag, nameText, term);
608
+ }
609
+
610
+ if (seen) {
611
+ const errors = pathspecErrors(originals, seen);
612
+ if (errors.length > 0) {
613
+ for (const line of errors) this.warn(line);
614
+ this.warn("Did you forget to 'git add'?");
615
+ return 1;
616
+ }
617
+ }
618
+ return 0;
619
+ }
620
+
621
+ /** show_ru_info: one line per stage the record keeps. */
622
+ private async showResolveUndo(
623
+ record: ResolveUndoRecord,
624
+ pruneBy: string,
625
+ match: (path: string, isDir: boolean) => boolean,
626
+ tag: (name: string) => string,
627
+ nameText: (path: string) => string,
628
+ term: string,
629
+ ): Promise<void> {
630
+ if (pathspecName(record.path).length < pruneBy.length) return;
631
+ if (!match(record.path, false)) return;
632
+ for (let i = 0; i < 3; i++) {
633
+ const mode = record.modes[i] as number;
634
+ const id = record.objectIds[i];
635
+ if (!mode || !id) continue;
636
+ await this.write(
637
+ `${tag("U")}${mode.toString(8).padStart(6, "0")} ${await this.abbreviated(id)} ${i + 1}\t${nameText(record.path)}${term}`,
638
+ );
639
+ }
640
+ }
641
+
642
+ /** ie_modified for an entry whose file is there (`current`). */
643
+ private async entryModified(
644
+ e: ListedEntry,
645
+ current: unknown,
646
+ worktree: Worktree | undefined,
647
+ trust: ReturnType<typeof worktreeModeTrust> | undefined,
648
+ indexTime: number,
649
+ ): Promise<boolean> {
650
+ if (e.assumeValid) return false;
651
+ if (e.intentToAdd) return true;
652
+ if (!worktree || !e.entry) return true;
653
+ const file = current as { isDirectory?: boolean } | null | undefined;
654
+ // a directory where a file was: TYPE_CHANGED
655
+ if (file?.isDirectory && e.mode !== FileMode.GITLINK) return true;
656
+ const compared = await compareWithWorktree(
657
+ worktree,
658
+ e.entry,
659
+ { ...(trust ? { trust } : {}), indexTime },
660
+ (current ?? null) as Parameters<typeof compareWithWorktree>[3],
661
+ );
662
+ return compared.kind !== undefined;
663
+ }
664
+
665
+ /** An object name as `--abbrev` asks (full by default). */
666
+ private async abbreviated(id: string): Promise<string> {
667
+ if (this.abbrev === 0 || (typeof this.abbrev === "number" && this.abbrev >= id.length)) {
668
+ return id;
669
+ }
670
+ if (this.abbrev === true) return this.abbreviateObjectId(id);
671
+ const length = (await this.idAbbreviator().lengths([id], this.abbrev)).get(id) ?? id.length;
672
+ return id.slice(0, length);
673
+ }
674
+
675
+ /**
676
+ * overlay_tree_on_index: the tree's entries under `prefix` at stage 1 (unmerged entries
677
+ * hoisted to stage 3), those a stage-0 entry of the same path shadows marked.
678
+ */
679
+ private async overlayTree(list: ListedEntry[], name: string, prefix: string): Promise<void> {
680
+ let id: string;
681
+ try {
682
+ id = await this.resolveRevision(name);
683
+ } catch {
684
+ throw new PlumbingError(`fatal: tree-ish ${name} not found.`);
685
+ }
686
+ let tree: string;
687
+ try {
688
+ tree = await this.resolveRevision(`${id}^{tree}`);
689
+ } catch {
690
+ throw new PlumbingError(`fatal: bad tree-ish ${name}`);
691
+ }
692
+ for (const e of list) if (e.stage !== 0) e.stage = 3;
693
+ const add = async (treeId: string, base: string) => {
694
+ for (const entry of await this.treeEntries(treeId)) {
695
+ const path = base + entry.name;
696
+ const nameBytes = pathspecName(path);
697
+ if ((entry.mode & S_IFMT) === 0o040000) {
698
+ const dirBytes = `${nameBytes}/`;
699
+ if (prefix && !prefix.startsWith(dirBytes) && !dirBytes.startsWith(prefix)) continue;
700
+ await add(entry.id, `${path}/`);
701
+ continue;
702
+ }
703
+ if (prefix && !nameBytes.startsWith(prefix)) continue;
704
+ list.push({
705
+ path,
706
+ mode: entry.mode,
707
+ objectId: entry.id,
708
+ stage: 1,
709
+ assumeValid: false,
710
+ skipWorktree: false,
711
+ intentToAdd: false,
712
+ shadowed: false,
713
+ });
714
+ }
715
+ };
716
+ await add(tree, "");
717
+ list.sort((a, b) => compareGitPaths(a.path, b.path) || a.stage - b.stage);
718
+ let lastStage0: string | undefined;
719
+ for (const e of list) {
720
+ if (e.stage === 0) lastStage0 = e.path;
721
+ else if (e.stage === 1 && lastStage0 === e.path) e.shadowed = true;
722
+ }
723
+ }
724
+
725
+ /** fill_directory: the untracked (or with `-i` ignored) paths, as dir.c's walk finds them. */
726
+ private async walkOthers(
727
+ worktree: Worktree,
728
+ items: PathspecItem[],
729
+ list: ListedEntry[],
730
+ rules: ExcludeRules | undefined,
731
+ ): Promise<string[]> {
732
+ const base: UntrackedScanHost = worktree.untrackedScanHost
733
+ ? await worktree.untrackedScanHost()
734
+ : await walkUntrackedScanHost(worktree);
735
+ const host: UntrackedScanHost = {
736
+ listDirectory: (path, readdirOrder) => base.listDirectory(path, readdirOrder),
737
+ lstat: (path) => base.lstat(path),
738
+ isNestedRepository: (path) => base.isNestedRepository(path),
739
+ loadIgnoreFile: async (dir) => {
740
+ await rules?.load(dir);
741
+ return { kind: "missing" };
742
+ },
743
+ isExcluded: (path, isDirectory) => rules?.isExcluded(path, isDirectory) ?? false,
744
+ };
745
+ let flags = 0;
746
+ if (this.ignored) flags |= DIR_SHOW_IGNORED;
747
+ if (this.directory) flags |= DIR_SHOW_OTHER_DIRECTORIES;
748
+ if (this.hideEmptyDirectories) flags |= DIR_HIDE_EMPTY_DIRECTORIES;
749
+ if (!this.others) flags |= DIR_COLLECT_KILLED_ONLY;
750
+ const ignoreCase = coreBool(this.workingCopy, "ignorecase", false);
751
+ const paths: string[] = [];
752
+ const gitlinks: string[] = [];
753
+ let last: string | undefined;
754
+ for (const e of list) {
755
+ if (e.path === last) continue;
756
+ last = e.path;
757
+ paths.push(e.path);
758
+ if (e.mode === FileMode.GITLINK) gitlinks.push(e.path);
759
+ }
760
+ const index = new IndexPathLookup(paths, { ignoreCase, gitlinks, sorted: true });
761
+ const result = await scanUntracked(host, {
762
+ isTracked: (p) => index.has(p),
763
+ isTrackedExactly: (p) => index.hasExactly(p),
764
+ trackedIn: (dir) => index.trackedIn(dir),
765
+ indexDirectory: (dir) => index.indexDirectory(dir),
766
+ flags,
767
+ allEntries: true,
768
+ ...(items.length > 0 ? { matcher: untrackedScanPathspec(items) } : {}),
769
+ onUnreadable: (path, error) => this.warn(unreadableDirectoryWarning(path, error)),
770
+ });
771
+ return result.paths;
772
+ }
773
+
774
+ /** The exclude rules of `-x`, `-X`, `--exclude-per-directory` and `--exclude-standard`. */
775
+ private async excludeRules(
776
+ worktree: Worktree | undefined,
777
+ list: ListedEntry[],
778
+ ): Promise<ExcludeRules> {
779
+ const environment = hostEnvironmentOf(this.workingCopy);
780
+ const top = worktree?.hostPath;
781
+ const config = RemoteConfigStore.from(this.workingCopy);
782
+ const readHostFile = async (path: string): Promise<Uint8Array | undefined> => {
783
+ const absolute = path.startsWith("/") ? path : top ? `${top}/${path}` : undefined;
784
+ if (absolute && environment) {
785
+ const bytes = await environment.readFile(absolute).catch(() => undefined);
786
+ if (bytes) return bytes;
787
+ }
788
+ if (!path.startsWith("/") && worktree) {
789
+ if (path.startsWith(".git/") && worktree.readGitDirFile) {
790
+ return worktree.readGitDirFile(path.slice(5)).catch(() => undefined);
791
+ }
792
+ return readAll(worktree.readContent(path)).catch(() => undefined);
793
+ }
794
+ return undefined;
795
+ };
796
+ const files: IgnoreNode[] = [];
797
+ const parse = (bytes: Uint8Array) => {
798
+ const node = createIgnoreNode();
799
+ node.parse(decodeGitPatternFile(bytes));
800
+ return node;
801
+ };
802
+ for (const source of this.excludeSources) {
803
+ if (source.kind === "file") {
804
+ const bytes = await readHostFile(source.path);
805
+ if (!bytes) throw new PlumbingError(`fatal: cannot use ${source.path} as an exclude file`);
806
+ files.push(parse(bytes));
807
+ continue;
808
+ }
809
+ // setup_standard_excludes: core.excludesFile (else XDG), then info/exclude
810
+ const configured = config.value("core.excludesFile");
811
+ const excludesFile =
812
+ configured !== undefined && configured !== ""
813
+ ? environment
814
+ ? expandUserPath(configured, environment)
815
+ : configured
816
+ : environment
817
+ ? xdgConfigPath(environment, "ignore")
818
+ : undefined;
819
+ if (excludesFile) {
820
+ const bytes = await readHostFile(excludesFile);
821
+ if (bytes) files.push(parse(bytes));
822
+ }
823
+ const info = await worktree?.readGitDirFile?.("info/exclude").catch(() => undefined);
824
+ if (info) files.push(parse(info));
825
+ }
826
+ const perDir = this.excludePerDirectory;
827
+ const skipWorktree = new Map<string, string>();
828
+ for (const e of list) if (e.stage === 0 && e.skipWorktree) skipWorktree.set(e.path, e.objectId);
829
+ const readPerDir = async (path: string): Promise<string | undefined> => {
830
+ if (worktree) {
831
+ const entry = await worktree.getEntry(path).catch(() => undefined);
832
+ if (entry && !entry.isDirectory && entry.mode !== FileMode.SYMLINK) {
833
+ const bytes = await readAll(worktree.readContent(path)).catch(() => undefined);
834
+ if (bytes) return decodeGitPatternFile(bytes);
835
+ }
836
+ if (entry) return undefined;
837
+ }
838
+ // read_skip_worktree_file_from_index
839
+ const id = skipWorktree.get(path);
840
+ if (!id) return undefined;
841
+ const content = await this.blobs.load(id).catch(() => undefined);
842
+ return content ? decodeGitPatternFile(await readAll(content)) : undefined;
843
+ };
844
+ return new ExcludeRules(
845
+ this.excludes.length > 0 ? createCommandLineExcludes(this.excludes) : undefined,
846
+ files,
847
+ perDir,
848
+ coreBool(this.workingCopy, "ignorecase", false),
849
+ readPerDir,
850
+ );
851
+ }
852
+
853
+ /** write_eolinfo: `i/<index> w/<worktree> attr/<attributes>\t`. */
854
+ private async eolColumns(
855
+ worktree: Worktree | undefined,
856
+ list: ListedEntry[],
857
+ ): Promise<(path: string, e: ListedEntry | undefined) => Promise<string>> {
858
+ const ws = worktree ?? this.worktreeAccess;
859
+ return async (path, e) => {
860
+ const i = e && isRegularMode(e.mode) ? await this.indexEolInfo(list, e.path) : "";
861
+ const w = ws ? await worktreeEolInfo(ws, path) : "";
862
+ const a = (await ws?.contentFilter?.eolAttribute?.(path).catch(() => "")) ?? "";
863
+ return `i/${i.padEnd(5)} w/${w.padEnd(5)} attr/${a.padEnd(17)}\t`;
864
+ };
865
+ }
866
+
867
+ /** get_cached_convert_stats_ascii: the stage-0 (else stage-2) blob of `path`. */
868
+ private async indexEolInfo(list: ListedEntry[], path: string): Promise<string> {
869
+ let found: ListedEntry | undefined;
870
+ // the entries of `path` start where index_name_pos puts its stage 0
871
+ const pos = namePos(list, path);
872
+ for (let k = pos >= 0 ? pos : -pos - 1; k < list.length; k++) {
873
+ const e = list[k] as ListedEntry;
874
+ if (e.path !== path) break;
875
+ if (e.shadowed) continue;
876
+ if (e.stage === 0) {
877
+ found = e;
878
+ break;
879
+ }
880
+ if (e.stage === 2) found = e;
881
+ }
882
+ if (!found) return eolStatsAscii(undefined);
883
+ const content = await this.blobs.load(found.objectId).catch(() => undefined);
884
+ return eolStatsAscii(content ? await readAll(content) : undefined);
885
+ }
886
+
887
+ /** show_ce_fmt: one entry through `--format`. */
888
+ private async formatEntry(
889
+ e: ListedEntry,
890
+ worktree: Worktree | undefined,
891
+ list: ListedEntry[],
892
+ nameText: (path: string) => string,
893
+ ): Promise<string> {
894
+ const format = this.format as string;
895
+ const ws = worktree ?? this.worktreeAccess;
896
+ let out = "";
897
+ let i = 0;
898
+ while (i < format.length) {
899
+ const pct = format.indexOf("%", i);
900
+ if (pct < 0) {
901
+ out += format.slice(i);
902
+ break;
903
+ }
904
+ out += format.slice(i, pct);
905
+ const rest = format.slice(pct + 1);
906
+ if (rest.startsWith("%")) {
907
+ out += "%";
908
+ i = pct + 2;
909
+ continue;
910
+ }
911
+ if (rest.startsWith("n")) {
912
+ out += "\n";
913
+ i = pct + 2;
914
+ continue;
915
+ }
916
+ if (rest.startsWith("x") && /^[0-9a-fA-F]{2}/.test(rest.slice(1))) {
917
+ // the byte itself: above 0x7f as the escape encodeGitPath writes back as that byte
918
+ const byte = Number.parseInt(rest.slice(1, 3), 16);
919
+ out += String.fromCharCode(byte < 0x80 ? byte : 0xdc00 + byte);
920
+ i = pct + 4;
921
+ continue;
922
+ }
923
+ if (!rest.startsWith("(")) {
924
+ throw new PlumbingError(
925
+ `fatal: bad ls-files format: element '${rest}' does not start with '('`,
926
+ );
927
+ }
928
+ const end = rest.indexOf(")", 1);
929
+ if (end < 0) {
930
+ throw new PlumbingError(
931
+ `fatal: bad ls-files format: element '${rest}' does not end in ')'`,
932
+ );
933
+ }
934
+ const atom = rest.slice(0, end + 1);
935
+ i = pct + 1 + atom.length;
936
+ const type = objectTypeOfMode(e.mode);
937
+ switch (atom) {
938
+ case "(objectmode)":
939
+ out += e.mode.toString(8).padStart(6, "0");
940
+ break;
941
+ case "(objectname)":
942
+ out += await this.abbreviated(e.objectId);
943
+ break;
944
+ case "(objecttype)":
945
+ out += type;
946
+ break;
947
+ case "(objectsize:padded)":
948
+ case "(objectsize)": {
949
+ const padded = atom === "(objectsize:padded)";
950
+ let text = "-";
951
+ if (type === "blob") {
952
+ const size = await this.blobs.size(e.objectId).catch(() => undefined);
953
+ if (size === undefined) {
954
+ throw new PlumbingError(`fatal: could not get object info about '${e.objectId}'`);
955
+ }
956
+ text = String(size);
957
+ }
958
+ out += padded ? text.padStart(7) : text;
959
+ break;
960
+ }
961
+ case "(stage)":
962
+ out += String(e.stage);
963
+ break;
964
+ case "(eolinfo:index)":
965
+ out += isRegularMode(e.mode) ? await this.indexEolInfo(list, e.path) : "";
966
+ break;
967
+ case "(eolinfo:worktree)":
968
+ out += ws ? await worktreeEolInfo(ws, e.path) : "";
969
+ break;
970
+ case "(eolattr)":
971
+ out += (await ws?.contentFilter?.eolAttribute?.(e.path).catch(() => "")) ?? "";
972
+ break;
973
+ case "(path)":
974
+ out += nameText(e.path);
975
+ break;
976
+ default:
977
+ throw new PlumbingError(`fatal: bad ls-files format: %${atom}`);
978
+ }
979
+ }
980
+ return out;
981
+ }
982
+ }
983
+
984
+ /** The rules `is_excluded` asks: command line, per-directory files, exclude files. */
985
+ class ExcludeRules {
986
+ private readonly dirs = new Map<string, IgnoreNode | null>();
987
+
988
+ constructor(
989
+ private readonly commandLine: IgnoreNode | undefined,
990
+ /** The exclude files in the order added (the last added asked first) */
991
+ private readonly files: IgnoreNode[],
992
+ private readonly perDirectory: string | undefined,
993
+ private readonly ignoreCase: boolean,
994
+ private readonly readFile: (path: string) => Promise<string | undefined>,
995
+ ) {}
996
+
997
+ /** Reads `dir`'s per-directory exclude file (once). */
998
+ async load(dir: string): Promise<void> {
999
+ if (!this.perDirectory || this.dirs.has(dir)) return;
1000
+ this.dirs.set(dir, null);
1001
+ const text = await this.readFile(dir ? `${dir}/${this.perDirectory}` : this.perDirectory);
1002
+ if (text === undefined) return;
1003
+ const node = createIgnoreNode();
1004
+ node.parse(text);
1005
+ this.dirs.set(dir, node);
1006
+ }
1007
+
1008
+ /** Reads the per-directory files of every directory above `path`. */
1009
+ async loadFor(path: string): Promise<void> {
1010
+ if (!this.perDirectory) return;
1011
+ await this.load("");
1012
+ for (let k = path.indexOf("/"); k > 0; k = path.indexOf("/", k + 1)) {
1013
+ await this.load(path.slice(0, k));
1014
+ }
1015
+ }
1016
+
1017
+ /** last_matching_pattern_from_lists: true excluded, false re-included, undefined none. */
1018
+ private match(path: string, isDirectory: boolean): boolean | undefined {
1019
+ const cmdl = this.commandLine?.checkIgnored(path, isDirectory, this.ignoreCase);
1020
+ if (cmdl !== undefined) return cmdl;
1021
+ let dir = path;
1022
+ for (;;) {
1023
+ const slash = dir.lastIndexOf("/");
1024
+ dir = slash < 0 ? "" : dir.slice(0, slash);
1025
+ const node = this.dirs.get(dir);
1026
+ if (node) {
1027
+ const relative = dir ? path.slice(dir.length + 1) : path;
1028
+ const result = node.checkIgnored(relative, isDirectory, this.ignoreCase);
1029
+ if (result !== undefined) return result;
1030
+ }
1031
+ if (dir === "") break;
1032
+ }
1033
+ for (let i = this.files.length - 1; i >= 0; i--) {
1034
+ const result = (this.files[i] as IgnoreNode).checkIgnored(path, isDirectory, this.ignoreCase);
1035
+ if (result !== undefined) return result;
1036
+ }
1037
+ return undefined;
1038
+ }
1039
+
1040
+ /** is_excluded: the path, or a directory above it, matches an exclude pattern. */
1041
+ isExcluded(path: string, isDirectory: boolean): boolean {
1042
+ const clean = path.endsWith("/") ? path.slice(0, -1) : path;
1043
+ for (let k = clean.indexOf("/"); k > 0; k = clean.indexOf("/", k + 1)) {
1044
+ if (this.match(clean.slice(0, k), true) === true) return true;
1045
+ }
1046
+ return this.match(clean, isDirectory) === true;
1047
+ }
1048
+ }
1049
+
1050
+ /** git's tag letter in lowercase (`-v` for an assume-unchanged entry). */
1051
+ function lowerTag(tag: string): string {
1052
+ const c = tag[0] as string;
1053
+ if (/[A-Za-z]/.test(c)) return c.toLowerCase() + tag.slice(1);
1054
+ if (c === "?") return `!${tag.slice(1)}`;
1055
+ return `v${c} `;
1056
+ }
1057
+
1058
+ /** object_type of an index mode. */
1059
+ function objectTypeOfMode(mode: number): string {
1060
+ if ((mode & S_IFMT) === 0o040000) return "tree";
1061
+ if (mode === FileMode.GITLINK) return "commit";
1062
+ return "blob";
1063
+ }
1064
+
1065
+ /**
1066
+ * show_killed_files' test of one walked path: a leading directory of it is an index file, or
1067
+ * (for the last component) the index has entries below it.
1068
+ */
1069
+ function isKilled(list: readonly ListedEntry[], name: string): boolean {
1070
+ const len = name.length;
1071
+ for (let cp = 0; cp < len; ) {
1072
+ const sp = name.indexOf("/", cp);
1073
+ if (sp < 0) {
1074
+ let pos = -namePos(list, name) - 1;
1075
+ while (pos < list.length && (list[pos] as ListedEntry).stage !== 0) pos++;
1076
+ if (pos >= list.length) return false;
1077
+ const next = (list[pos] as ListedEntry).path;
1078
+ return len < next.length && next.startsWith(name) && next[len] === "/";
1079
+ }
1080
+ if (namePos(list, name.slice(0, sp)) >= 0) return true;
1081
+ cp = sp + 1;
1082
+ }
1083
+ return false;
1084
+ }
1085
+
1086
+ /** Whether the index has an entry (any stage) at exactly `name`. */
1087
+ function isInIndex(list: readonly ListedEntry[], name: string): boolean {
1088
+ const pos = namePos(list, name);
1089
+ if (pos >= 0) return true;
1090
+ const next = list[-pos - 1];
1091
+ return next !== undefined && next.path === name;
1092
+ }
1093
+
1094
+ /** index_name_pos for stage 0: the position, else -(insertion point) - 1. */
1095
+ function namePos(list: readonly ListedEntry[], name: string): number {
1096
+ let lo = 0;
1097
+ let hi = list.length;
1098
+ while (lo < hi) {
1099
+ const mid = (lo + hi) >>> 1;
1100
+ const e = list[mid] as ListedEntry;
1101
+ const cmp = compareGitPaths(e.path, name) || e.stage;
1102
+ if (cmp === 0) return mid;
1103
+ if (cmp < 0) lo = mid + 1;
1104
+ else hi = mid;
1105
+ }
1106
+ return -lo - 1;
1107
+ }
1108
+
1109
+ /** get_wt_convert_stats_ascii of a regular file (no link, no directory), else "". */
1110
+ async function worktreeEolInfo(worktree: Worktree, path: string): Promise<string> {
1111
+ if (path.endsWith("/")) return "";
1112
+ const entry = await worktree.getEntry(path).catch(() => undefined);
1113
+ if (
1114
+ !entry ||
1115
+ entry.isDirectory ||
1116
+ entry.mode === FileMode.SYMLINK ||
1117
+ entry.mode === FileMode.GITLINK
1118
+ )
1119
+ return "";
1120
+ const bytes = await readAll(worktree.readContent(path)).catch(() => undefined);
1121
+ return bytes ? eolStatsAscii(bytes) : "";
1122
+ }
1123
+
1124
+ async function readAll(content: AsyncIterable<Uint8Array>): Promise<Uint8Array> {
1125
+ const chunks: Uint8Array[] = [];
1126
+ let size = 0;
1127
+ for await (const c of content) {
1128
+ chunks.push(c);
1129
+ size += c.length;
1130
+ }
1131
+ const out = new Uint8Array(size);
1132
+ let at = 0;
1133
+ for (const c of chunks) {
1134
+ out.set(c, at);
1135
+ at += c.length;
1136
+ }
1137
+ return out;
1138
+ }
1139
+
1140
+ const SHORT_MAGIC = new Set([..."!\"#%&',-;<=>@_`~^/"]);
1141
+
1142
+ /**
1143
+ * A pathspec element read against the current directory, as parse_pathspec's
1144
+ * `prefix_path_gently` reads it (`:(top)` and `:/` from the top; an absolute path against the
1145
+ * worktree's host directory `top`); dies as git when it leaves the worktree.
1146
+ */
1147
+ export function prefixedElement(arg: string, prefix: string, top: string | undefined): string {
1148
+ let magicEnd = 0;
1149
+ let fromTop = false;
1150
+ if (arg.startsWith(":(")) {
1151
+ const close = arg.indexOf(")");
1152
+ if (close < 0) return arg;
1153
+ const words = arg
1154
+ .slice(2, close)
1155
+ .split(",")
1156
+ .map((w) => w.trim());
1157
+ fromTop = words.includes("top");
1158
+ magicEnd = close + 1;
1159
+ } else if (arg.startsWith(":")) {
1160
+ let i = 1;
1161
+ while (i < arg.length && arg[i] !== ":" && SHORT_MAGIC.has(arg[i] as string)) i++;
1162
+ fromTop = arg.slice(1, i).includes("/");
1163
+ if (arg[i] === ":") i++;
1164
+ magicEnd = i;
1165
+ }
1166
+ const rest = arg.slice(magicEnd);
1167
+ if (fromTop) return arg;
1168
+ // an empty element is parse_pathspec's own refusal
1169
+ if (rest === "") return arg;
1170
+ const normalized = prefixPathGently(prefix, rest, top);
1171
+ if (normalized === undefined) {
1172
+ const root = (top ?? "").replace(/\/+$/, "") || "/";
1173
+ throw new PlumbingError(`fatal: ${arg}: '${rest}' is outside repository at '${root}'`);
1174
+ }
1175
+ // the top itself (`..` from a subdirectory) matches everything
1176
+ return arg.slice(0, magicEnd) + (normalized === "" ? "." : normalized);
1177
+ }