@statewalker/vcs-commands 0.5.0 → 0.7.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 (561) hide show
  1. package/README.md +123 -8
  2. package/dist/commands/add-command.d.ts +265 -34
  3. package/dist/commands/add-command.d.ts.map +1 -1
  4. package/dist/commands/add-patch/add-interactive.d.ts +46 -0
  5. package/dist/commands/add-patch/add-interactive.d.ts.map +1 -0
  6. package/dist/commands/add-patch/add-patch.d.ts +139 -0
  7. package/dist/commands/add-patch/add-patch.d.ts.map +1 -0
  8. package/dist/commands/add-patch/index.d.ts +6 -0
  9. package/dist/commands/add-patch/index.d.ts.map +1 -0
  10. package/dist/commands/add-patch/patch-backend.d.ts +80 -0
  11. package/dist/commands/add-patch/patch-backend.d.ts.map +1 -0
  12. package/dist/commands/add-patch/patch-modes.d.ts +71 -0
  13. package/dist/commands/add-patch/patch-modes.d.ts.map +1 -0
  14. package/dist/commands/add-patch/patch-session.d.ts +49 -0
  15. package/dist/commands/add-patch/patch-session.d.ts.map +1 -0
  16. package/dist/commands/am/am-command.d.ts +175 -0
  17. package/dist/commands/am/am-command.d.ts.map +1 -0
  18. package/dist/commands/am/index.d.ts +3 -0
  19. package/dist/commands/am/index.d.ts.map +1 -0
  20. package/dist/commands/am/mailinfo.d.ts +58 -0
  21. package/dist/commands/am/mailinfo.d.ts.map +1 -0
  22. package/dist/commands/am/patch-format.d.ts +24 -0
  23. package/dist/commands/am/patch-format.d.ts.map +1 -0
  24. package/dist/commands/apply/apply-command.d.ts +153 -0
  25. package/dist/commands/apply/apply-command.d.ts.map +1 -0
  26. package/dist/commands/apply/apply-engine.d.ts +195 -0
  27. package/dist/commands/apply/apply-engine.d.ts.map +1 -0
  28. package/dist/commands/apply/apply-parse.d.ts +86 -0
  29. package/dist/commands/apply/apply-parse.d.ts.map +1 -0
  30. package/dist/commands/apply/apply-types.d.ts +70 -0
  31. package/dist/commands/apply/apply-types.d.ts.map +1 -0
  32. package/dist/commands/apply/index.d.ts +6 -0
  33. package/dist/commands/apply/index.d.ts.map +1 -0
  34. package/dist/commands/apply/latin1.d.ts +32 -0
  35. package/dist/commands/apply/latin1.d.ts.map +1 -0
  36. package/dist/commands/apply/whitespace.d.ts +58 -0
  37. package/dist/commands/apply/whitespace.d.ts.map +1 -0
  38. package/dist/commands/attributes-source.d.ts +26 -0
  39. package/dist/commands/attributes-source.d.ts.map +1 -0
  40. package/dist/commands/backfill-command.d.ts +110 -0
  41. package/dist/commands/backfill-command.d.ts.map +1 -0
  42. package/dist/commands/bisect/bisect-checkout.d.ts +64 -0
  43. package/dist/commands/bisect/bisect-checkout.d.ts.map +1 -0
  44. package/dist/commands/bisect/bisect-command.d.ts +201 -0
  45. package/dist/commands/bisect/bisect-command.d.ts.map +1 -0
  46. package/dist/commands/bisect/bisect-engine.d.ts +219 -0
  47. package/dist/commands/bisect/bisect-engine.d.ts.map +1 -0
  48. package/dist/commands/bisect/bisect-graph.d.ts +127 -0
  49. package/dist/commands/bisect/bisect-graph.d.ts.map +1 -0
  50. package/dist/commands/bisect/bisect-quote.d.ts +27 -0
  51. package/dist/commands/bisect/bisect-quote.d.ts.map +1 -0
  52. package/dist/commands/bisect/index.d.ts +5 -0
  53. package/dist/commands/bisect/index.d.ts.map +1 -0
  54. package/dist/commands/blame-command.d.ts +122 -131
  55. package/dist/commands/blame-command.d.ts.map +1 -1
  56. package/dist/commands/branch-command.d.ts +52 -2
  57. package/dist/commands/branch-command.d.ts.map +1 -1
  58. package/dist/commands/branch-tracking.d.ts +98 -0
  59. package/dist/commands/branch-tracking.d.ts.map +1 -0
  60. package/dist/commands/checkout-command.d.ts +300 -18
  61. package/dist/commands/checkout-command.d.ts.map +1 -1
  62. package/dist/commands/checkout-paths.d.ts +124 -0
  63. package/dist/commands/checkout-paths.d.ts.map +1 -0
  64. package/dist/commands/cherry-pick-command.d.ts +50 -42
  65. package/dist/commands/cherry-pick-command.d.ts.map +1 -1
  66. package/dist/commands/clean-command.d.ts +49 -16
  67. package/dist/commands/clean-command.d.ts.map +1 -1
  68. package/dist/commands/clone-command.d.ts +134 -0
  69. package/dist/commands/clone-command.d.ts.map +1 -1
  70. package/dist/commands/comment-char-config.d.ts +35 -0
  71. package/dist/commands/comment-char-config.d.ts.map +1 -0
  72. package/dist/commands/commit-command.d.ts +311 -17
  73. package/dist/commands/commit-command.d.ts.map +1 -1
  74. package/dist/commands/core-config.d.ts +78 -1
  75. package/dist/commands/core-config.d.ts.map +1 -1
  76. package/dist/commands/date-format.d.ts +58 -0
  77. package/dist/commands/date-format.d.ts.map +1 -0
  78. package/dist/commands/default-branch.d.ts +70 -0
  79. package/dist/commands/default-branch.d.ts.map +1 -0
  80. package/dist/commands/describe-command.d.ts.map +1 -1
  81. package/dist/commands/diff-command.d.ts +377 -30
  82. package/dist/commands/diff-command.d.ts.map +1 -1
  83. package/dist/commands/diff-textconv.d.ts +40 -0
  84. package/dist/commands/diff-textconv.d.ts.map +1 -0
  85. package/dist/commands/fetch-command.d.ts +149 -10
  86. package/dist/commands/fetch-command.d.ts.map +1 -1
  87. package/dist/commands/format-patch-command.d.ts +164 -0
  88. package/dist/commands/format-patch-command.d.ts.map +1 -0
  89. package/dist/commands/fsck/fetch-fsck.d.ts +60 -0
  90. package/dist/commands/fsck/fetch-fsck.d.ts.map +1 -0
  91. package/dist/commands/fsck/fsck-command.d.ts +227 -0
  92. package/dist/commands/fsck/fsck-command.d.ts.map +1 -0
  93. package/dist/commands/fsck/fsck-loose.d.ts +71 -0
  94. package/dist/commands/fsck/fsck-loose.d.ts.map +1 -0
  95. package/dist/commands/fsck/fsck-msg-ids.d.ts +122 -0
  96. package/dist/commands/fsck/fsck-msg-ids.d.ts.map +1 -0
  97. package/dist/commands/fsck/fsck-object-checks.d.ts +159 -0
  98. package/dist/commands/fsck/fsck-object-checks.d.ts.map +1 -0
  99. package/dist/commands/fsck/fsck-object-table.d.ts +140 -0
  100. package/dist/commands/fsck/fsck-object-table.d.ts.map +1 -0
  101. package/dist/commands/fsck/fsck-pack.d.ts +122 -0
  102. package/dist/commands/fsck/fsck-pack.d.ts.map +1 -0
  103. package/dist/commands/fsck/index.d.ts +6 -0
  104. package/dist/commands/fsck/index.d.ts.map +1 -0
  105. package/dist/commands/fsck/verify-pack-command.d.ts +81 -0
  106. package/dist/commands/fsck/verify-pack-command.d.ts.map +1 -0
  107. package/dist/commands/gc-command.d.ts +106 -39
  108. package/dist/commands/gc-command.d.ts.map +1 -1
  109. package/dist/commands/git-date.d.ts +2 -0
  110. package/dist/commands/git-date.d.ts.map +1 -0
  111. package/dist/commands/git-describe.d.ts +67 -0
  112. package/dist/commands/git-describe.d.ts.map +1 -0
  113. package/dist/commands/git-hooks.d.ts +424 -0
  114. package/dist/commands/git-hooks.d.ts.map +1 -0
  115. package/dist/commands/git-ident.d.ts +128 -0
  116. package/dist/commands/git-ident.d.ts.map +1 -0
  117. package/dist/commands/hook-command.d.ts +96 -0
  118. package/dist/commands/hook-command.d.ts.map +1 -0
  119. package/dist/commands/index-adder.d.ts +233 -0
  120. package/dist/commands/index-adder.d.ts.map +1 -0
  121. package/dist/commands/index-host.d.ts +86 -0
  122. package/dist/commands/index-host.d.ts.map +1 -0
  123. package/dist/commands/index.d.ts +56 -0
  124. package/dist/commands/index.d.ts.map +1 -1
  125. package/dist/commands/index.js +3 -2
  126. package/dist/commands/init-command.d.ts +62 -4
  127. package/dist/commands/init-command.d.ts.map +1 -1
  128. package/dist/commands/legacy-remotes.d.ts +55 -0
  129. package/dist/commands/legacy-remotes.d.ts.map +1 -0
  130. package/dist/commands/local-clone.d.ts +60 -0
  131. package/dist/commands/local-clone.d.ts.map +1 -0
  132. package/dist/commands/local-transport.d.ts +117 -0
  133. package/dist/commands/local-transport.d.ts.map +1 -0
  134. package/dist/commands/log-command.d.ts +216 -24
  135. package/dist/commands/log-command.d.ts.map +1 -1
  136. package/dist/commands/log-graph.d.ts +120 -0
  137. package/dist/commands/log-graph.d.ts.map +1 -0
  138. package/dist/commands/log-output.d.ts +323 -0
  139. package/dist/commands/log-output.d.ts.map +1 -0
  140. package/dist/commands/ls-remote-command.d.ts +23 -7
  141. package/dist/commands/ls-remote-command.d.ts.map +1 -1
  142. package/dist/commands/mailmap.d.ts +31 -0
  143. package/dist/commands/mailmap.d.ts.map +1 -0
  144. package/dist/commands/merge-bases.d.ts +85 -0
  145. package/dist/commands/merge-bases.d.ts.map +1 -0
  146. package/dist/commands/merge-command.d.ts +221 -74
  147. package/dist/commands/merge-command.d.ts.map +1 -1
  148. package/dist/commands/merge-config.d.ts +13 -0
  149. package/dist/commands/merge-config.d.ts.map +1 -0
  150. package/dist/commands/merge-drivers.d.ts +130 -0
  151. package/dist/commands/merge-drivers.d.ts.map +1 -0
  152. package/dist/commands/merge-support.d.ts +260 -0
  153. package/dist/commands/merge-support.d.ts.map +1 -0
  154. package/dist/commands/message-cleanup.d.ts +86 -0
  155. package/dist/commands/message-cleanup.d.ts.map +1 -0
  156. package/dist/commands/mv-command.d.ts +94 -0
  157. package/dist/commands/mv-command.d.ts.map +1 -0
  158. package/dist/commands/notes-command.d.ts +256 -0
  159. package/dist/commands/notes-command.d.ts.map +1 -0
  160. package/dist/commands/notes-commands.d.ts +41 -0
  161. package/dist/commands/notes-commands.d.ts.map +1 -0
  162. package/dist/commands/notes-merge-command.d.ts +105 -0
  163. package/dist/commands/notes-merge-command.d.ts.map +1 -0
  164. package/dist/commands/notes-support.d.ts +125 -0
  165. package/dist/commands/notes-support.d.ts.map +1 -0
  166. package/dist/commands/notes-tree.d.ts +116 -0
  167. package/dist/commands/notes-tree.d.ts.map +1 -0
  168. package/dist/commands/object-id-input.d.ts +20 -0
  169. package/dist/commands/object-id-input.d.ts.map +1 -0
  170. package/dist/commands/octopus-merge.d.ts +59 -0
  171. package/dist/commands/octopus-merge.d.ts.map +1 -0
  172. package/dist/commands/ort-merge.d.ts +126 -0
  173. package/dist/commands/ort-merge.d.ts.map +1 -0
  174. package/dist/commands/ort-recursive.d.ts +53 -0
  175. package/dist/commands/ort-recursive.d.ts.map +1 -0
  176. package/dist/commands/pack-refs-command.d.ts +20 -0
  177. package/dist/commands/pack-refs-command.d.ts.map +1 -1
  178. package/dist/commands/patch-id.d.ts +44 -0
  179. package/dist/commands/patch-id.d.ts.map +1 -0
  180. package/dist/commands/pathspec-attributes.d.ts +64 -0
  181. package/dist/commands/pathspec-attributes.d.ts.map +1 -0
  182. package/dist/commands/pathspec.d.ts +324 -0
  183. package/dist/commands/pathspec.d.ts.map +1 -0
  184. package/dist/commands/post-index-change.d.ts +33 -0
  185. package/dist/commands/post-index-change.d.ts.map +1 -0
  186. package/dist/commands/pretty-format.d.ts +222 -0
  187. package/dist/commands/pretty-format.d.ts.map +1 -0
  188. package/dist/commands/promisor-remote.d.ts +80 -0
  189. package/dist/commands/promisor-remote.d.ts.map +1 -0
  190. package/dist/commands/pull-command.d.ts +59 -8
  191. package/dist/commands/pull-command.d.ts.map +1 -1
  192. package/dist/commands/push-command.d.ts +24 -8
  193. package/dist/commands/push-command.d.ts.map +1 -1
  194. package/dist/commands/read-tree-command.d.ts +112 -0
  195. package/dist/commands/read-tree-command.d.ts.map +1 -0
  196. package/dist/commands/rebase-command.d.ts +507 -75
  197. package/dist/commands/rebase-command.d.ts.map +1 -1
  198. package/dist/commands/rebase-todo.d.ts +130 -0
  199. package/dist/commands/rebase-todo.d.ts.map +1 -0
  200. package/dist/commands/ref-decoration-filter.d.ts +53 -0
  201. package/dist/commands/ref-decoration-filter.d.ts.map +1 -0
  202. package/dist/commands/reflog-messages.d.ts +98 -0
  203. package/dist/commands/reflog-messages.d.ts.map +1 -0
  204. package/dist/commands/remote-command.d.ts +31 -0
  205. package/dist/commands/remote-command.d.ts.map +1 -1
  206. package/dist/commands/remote-transport.d.ts +120 -0
  207. package/dist/commands/remote-transport.d.ts.map +1 -0
  208. package/dist/commands/reset-command.d.ts +161 -7
  209. package/dist/commands/reset-command.d.ts.map +1 -1
  210. package/dist/commands/restore-command.d.ts +103 -0
  211. package/dist/commands/restore-command.d.ts.map +1 -0
  212. package/dist/commands/rev-list-command.d.ts +78 -0
  213. package/dist/commands/rev-list-command.d.ts.map +1 -0
  214. package/dist/commands/rev-parse-command.d.ts +89 -0
  215. package/dist/commands/rev-parse-command.d.ts.map +1 -0
  216. package/dist/commands/revert-command.d.ts +46 -38
  217. package/dist/commands/revert-command.d.ts.map +1 -1
  218. package/dist/commands/revision-filenames.d.ts +95 -0
  219. package/dist/commands/revision-filenames.d.ts.map +1 -0
  220. package/dist/commands/revision-range.d.ts +67 -0
  221. package/dist/commands/revision-range.d.ts.map +1 -0
  222. package/dist/commands/revision-resolver.d.ts +325 -0
  223. package/dist/commands/revision-resolver.d.ts.map +1 -0
  224. package/dist/commands/rm-command.d.ts +69 -7
  225. package/dist/commands/rm-command.d.ts.map +1 -1
  226. package/dist/commands/sequencer-pick.d.ts +191 -0
  227. package/dist/commands/sequencer-pick.d.ts.map +1 -0
  228. package/dist/commands/sequencer-support.d.ts +125 -0
  229. package/dist/commands/sequencer-support.d.ts.map +1 -0
  230. package/dist/commands/serve-repository.d.ts +52 -0
  231. package/dist/commands/serve-repository.d.ts.map +1 -0
  232. package/dist/commands/sparse-checkout-command.d.ts +190 -0
  233. package/dist/commands/sparse-checkout-command.d.ts.map +1 -0
  234. package/dist/commands/sparse-checkout-support.d.ts +268 -0
  235. package/dist/commands/sparse-checkout-support.d.ts.map +1 -0
  236. package/dist/commands/stash-apply-command.d.ts +42 -8
  237. package/dist/commands/stash-apply-command.d.ts.map +1 -1
  238. package/dist/commands/stash-create-command.d.ts +156 -2
  239. package/dist/commands/stash-create-command.d.ts.map +1 -1
  240. package/dist/commands/stash-drop-command.d.ts +2 -0
  241. package/dist/commands/stash-drop-command.d.ts.map +1 -1
  242. package/dist/commands/stash-working-tree.d.ts +23 -0
  243. package/dist/commands/stash-working-tree.d.ts.map +1 -1
  244. package/dist/commands/status-command.d.ts +300 -15
  245. package/dist/commands/status-command.d.ts.map +1 -1
  246. package/dist/commands/status-format.d.ts +155 -0
  247. package/dist/commands/status-format.d.ts.map +1 -0
  248. package/dist/commands/status-header.d.ts +64 -0
  249. package/dist/commands/status-header.d.ts.map +1 -0
  250. package/dist/commands/strerror.d.ts +7 -0
  251. package/dist/commands/strerror.d.ts.map +1 -0
  252. package/dist/commands/submodule-config.d.ts +38 -0
  253. package/dist/commands/submodule-config.d.ts.map +1 -0
  254. package/dist/commands/submodule-summary-command.d.ts +80 -0
  255. package/dist/commands/submodule-summary-command.d.ts.map +1 -0
  256. package/dist/commands/submodule-summary.d.ts +150 -0
  257. package/dist/commands/submodule-summary.d.ts.map +1 -0
  258. package/dist/commands/switch-command.d.ts +132 -0
  259. package/dist/commands/switch-command.d.ts.map +1 -0
  260. package/dist/commands/tag-command.d.ts +23 -2
  261. package/dist/commands/tag-command.d.ts.map +1 -1
  262. package/dist/commands/tracking-info.d.ts +64 -0
  263. package/dist/commands/tracking-info.d.ts.map +1 -0
  264. package/dist/commands/trailers.d.ts +73 -0
  265. package/dist/commands/trailers.d.ts.map +1 -0
  266. package/dist/commands/tree-restore.d.ts +85 -1
  267. package/dist/commands/tree-restore.d.ts.map +1 -1
  268. package/dist/commands/untracked-cache-support.d.ts +54 -0
  269. package/dist/commands/untracked-cache-support.d.ts.map +1 -0
  270. package/dist/commands/worktree-add-command.d.ts +108 -0
  271. package/dist/commands/worktree-add-command.d.ts.map +1 -0
  272. package/dist/commands/worktree-list-command.d.ts +69 -0
  273. package/dist/commands/worktree-list-command.d.ts.map +1 -0
  274. package/dist/commands/worktree-lock-command.d.ts +44 -0
  275. package/dist/commands/worktree-lock-command.d.ts.map +1 -0
  276. package/dist/commands/worktree-overwrite-checks.d.ts +146 -6
  277. package/dist/commands/worktree-overwrite-checks.d.ts.map +1 -1
  278. package/dist/commands/worktree-prune-command.d.ts +48 -0
  279. package/dist/commands/worktree-prune-command.d.ts.map +1 -0
  280. package/dist/commands/worktree-remove-command.d.ts +59 -0
  281. package/dist/commands/worktree-remove-command.d.ts.map +1 -0
  282. package/dist/commands/worktree-repair-command.d.ts +35 -0
  283. package/dist/commands/worktree-repair-command.d.ts.map +1 -0
  284. package/dist/commands/worktree-support.d.ts +64 -0
  285. package/dist/commands/worktree-support.d.ts.map +1 -0
  286. package/dist/commands-DIJ91NnD.js +62225 -0
  287. package/dist/core-commands/add.command.impl.d.ts.map +1 -1
  288. package/dist/errors/add-errors.d.ts +55 -0
  289. package/dist/errors/add-errors.d.ts.map +1 -1
  290. package/dist/errors/checkout-errors.d.ts +16 -0
  291. package/dist/errors/checkout-errors.d.ts.map +1 -1
  292. package/dist/errors/command-errors.d.ts +77 -0
  293. package/dist/errors/command-errors.d.ts.map +1 -1
  294. package/dist/errors/commit-errors.d.ts +9 -0
  295. package/dist/errors/commit-errors.d.ts.map +1 -1
  296. package/dist/errors/git-api-error.d.ts +59 -2
  297. package/dist/errors/git-api-error.d.ts.map +1 -1
  298. package/dist/errors/index.d.ts +1 -0
  299. package/dist/errors/index.d.ts.map +1 -1
  300. package/dist/errors/index.js +354 -19
  301. package/dist/errors/rebase-errors.d.ts +9 -0
  302. package/dist/errors/rebase-errors.d.ts.map +1 -1
  303. package/dist/errors/ref-errors.d.ts +32 -0
  304. package/dist/errors/ref-errors.d.ts.map +1 -1
  305. package/dist/errors/transport-errors.d.ts +12 -2
  306. package/dist/errors/transport-errors.d.ts.map +1 -1
  307. package/dist/errors/worktree-errors.d.ts +35 -0
  308. package/dist/errors/worktree-errors.d.ts.map +1 -0
  309. package/dist/git-command-BGiOJ8Zk.js +7246 -0
  310. package/dist/git-command.d.ts +428 -32
  311. package/dist/git-command.d.ts.map +1 -1
  312. package/dist/git.d.ts +315 -5
  313. package/dist/git.d.ts.map +1 -1
  314. package/dist/index.d.ts +1 -1
  315. package/dist/index.d.ts.map +1 -1
  316. package/dist/index.js +5 -5
  317. package/dist/remote-config/index.d.ts +1 -1
  318. package/dist/remote-config/index.d.ts.map +1 -1
  319. package/dist/remote-config/remote-config-store.d.ts +167 -6
  320. package/dist/remote-config/remote-config-store.d.ts.map +1 -1
  321. package/dist/remote-config/remote-refs.d.ts +7 -3
  322. package/dist/remote-config/remote-refs.d.ts.map +1 -1
  323. package/dist/rename/detect-renames.d.ts +148 -0
  324. package/dist/rename/detect-renames.d.ts.map +1 -0
  325. package/dist/rename/git-similarity.d.ts +44 -0
  326. package/dist/rename/git-similarity.d.ts.map +1 -0
  327. package/dist/rename/index.d.ts +2 -0
  328. package/dist/rename/index.d.ts.map +1 -1
  329. package/dist/results/binary-patch.d.ts +11 -0
  330. package/dist/results/binary-patch.d.ts.map +1 -0
  331. package/dist/results/blame-format.d.ts +55 -0
  332. package/dist/results/blame-format.d.ts.map +1 -0
  333. package/dist/results/cherry-pick-result.d.ts +10 -0
  334. package/dist/results/cherry-pick-result.d.ts.map +1 -1
  335. package/dist/results/clone-result.d.ts +18 -0
  336. package/dist/results/clone-result.d.ts.map +1 -1
  337. package/dist/results/combined-diff.d.ts +77 -0
  338. package/dist/results/combined-diff.d.ts.map +1 -0
  339. package/dist/results/diff-entry.d.ts +32 -0
  340. package/dist/results/diff-entry.d.ts.map +1 -1
  341. package/dist/results/diff-formatter.d.ts +34 -60
  342. package/dist/results/diff-formatter.d.ts.map +1 -1
  343. package/dist/results/diff-order.d.ts +25 -0
  344. package/dist/results/diff-order.d.ts.map +1 -0
  345. package/dist/results/diff-output.d.ts +249 -0
  346. package/dist/results/diff-output.d.ts.map +1 -0
  347. package/dist/results/fetch-result.d.ts +15 -0
  348. package/dist/results/fetch-result.d.ts.map +1 -1
  349. package/dist/results/index.d.ts +5 -0
  350. package/dist/results/index.d.ts.map +1 -1
  351. package/dist/results/index.js +2 -252
  352. package/dist/results/init-result.d.ts +7 -0
  353. package/dist/results/init-result.d.ts.map +1 -1
  354. package/dist/results/merge-result.d.ts +15 -1
  355. package/dist/results/merge-result.d.ts.map +1 -1
  356. package/dist/results/pull-result.d.ts +17 -3
  357. package/dist/results/pull-result.d.ts.map +1 -1
  358. package/dist/results/push-result.d.ts +47 -0
  359. package/dist/results/push-result.d.ts.map +1 -1
  360. package/dist/results/quote-path.d.ts +27 -0
  361. package/dist/results/quote-path.d.ts.map +1 -0
  362. package/dist/results/rebase-result.d.ts +28 -1
  363. package/dist/results/rebase-result.d.ts.map +1 -1
  364. package/dist/results/revert-result.d.ts +10 -0
  365. package/dist/results/revert-result.d.ts.map +1 -1
  366. package/dist/results/stash-result.d.ts +5 -0
  367. package/dist/results/stash-result.d.ts.map +1 -1
  368. package/dist/results/status-result.d.ts +60 -6
  369. package/dist/results/status-result.d.ts.map +1 -1
  370. package/dist/results-WVlBhVb1.js +2935 -0
  371. package/dist/transport-command.d.ts +44 -1
  372. package/dist/transport-command.d.ts.map +1 -1
  373. package/package.json +15 -11
  374. package/src/commands/add-command.ts +1291 -226
  375. package/src/commands/add-patch/add-interactive.ts +941 -0
  376. package/src/commands/add-patch/add-patch.ts +1169 -0
  377. package/src/commands/add-patch/index.ts +5 -0
  378. package/src/commands/add-patch/patch-backend.ts +239 -0
  379. package/src/commands/add-patch/patch-modes.ts +249 -0
  380. package/src/commands/add-patch/patch-session.ts +159 -0
  381. package/src/commands/am/am-command.ts +1111 -0
  382. package/src/commands/am/index.ts +2 -0
  383. package/src/commands/am/mailinfo.ts +1015 -0
  384. package/src/commands/am/patch-format.ts +121 -0
  385. package/src/commands/apply/apply-command.ts +842 -0
  386. package/src/commands/apply/apply-engine.ts +1602 -0
  387. package/src/commands/apply/apply-parse.ts +1210 -0
  388. package/src/commands/apply/apply-types.ts +112 -0
  389. package/src/commands/apply/index.ts +5 -0
  390. package/src/commands/apply/latin1.ts +171 -0
  391. package/src/commands/apply/whitespace.ts +260 -0
  392. package/src/commands/attributes-source.ts +96 -0
  393. package/src/commands/backfill-command.ts +694 -0
  394. package/src/commands/bisect/bisect-checkout.ts +217 -0
  395. package/src/commands/bisect/bisect-command.ts +788 -0
  396. package/src/commands/bisect/bisect-engine.ts +1080 -0
  397. package/src/commands/bisect/bisect-graph.ts +595 -0
  398. package/src/commands/bisect/bisect-quote.ts +92 -0
  399. package/src/commands/bisect/index.ts +4 -0
  400. package/src/commands/blame-command.ts +711 -986
  401. package/src/commands/branch-command.ts +354 -32
  402. package/src/commands/branch-tracking.ts +331 -0
  403. package/src/commands/checkout-command.ts +1290 -243
  404. package/src/commands/checkout-paths.ts +784 -0
  405. package/src/commands/cherry-pick-command.ts +156 -396
  406. package/src/commands/clean-command.ts +504 -156
  407. package/src/commands/clone-command.ts +748 -69
  408. package/src/commands/comment-char-config.ts +160 -0
  409. package/src/commands/commit-command.ts +1782 -166
  410. package/src/commands/core-config.ts +166 -6
  411. package/src/commands/date-format.ts +668 -0
  412. package/src/commands/default-branch.ts +196 -0
  413. package/src/commands/describe-command.ts +2 -0
  414. package/src/commands/diff-command.ts +1916 -110
  415. package/src/commands/diff-textconv.ts +50 -0
  416. package/src/commands/fetch-command.ts +622 -68
  417. package/src/commands/format-patch-command.ts +974 -0
  418. package/src/commands/fsck/fetch-fsck.ts +229 -0
  419. package/src/commands/fsck/fsck-command.ts +3464 -0
  420. package/src/commands/fsck/fsck-loose.ts +297 -0
  421. package/src/commands/fsck/fsck-msg-ids.ts +176 -0
  422. package/src/commands/fsck/fsck-object-checks.ts +1085 -0
  423. package/src/commands/fsck/fsck-object-table.ts +373 -0
  424. package/src/commands/fsck/fsck-pack.ts +634 -0
  425. package/src/commands/fsck/index.ts +5 -0
  426. package/src/commands/fsck/verify-pack-command.ts +252 -0
  427. package/src/commands/gc-command.ts +324 -77
  428. package/src/commands/git-date.ts +9 -0
  429. package/src/commands/git-describe.ts +316 -0
  430. package/src/commands/git-hooks.ts +1483 -0
  431. package/src/commands/git-ident.ts +344 -0
  432. package/src/commands/hook-command.ts +247 -0
  433. package/src/commands/index-adder.ts +711 -0
  434. package/src/commands/index-host.ts +291 -0
  435. package/src/commands/index.ts +84 -0
  436. package/src/commands/init-command.ts +194 -14
  437. package/src/commands/legacy-remotes.ts +224 -0
  438. package/src/commands/local-clone.ts +183 -0
  439. package/src/commands/local-transport.ts +762 -0
  440. package/src/commands/log-command.ts +1930 -170
  441. package/src/commands/log-graph.ts +671 -0
  442. package/src/commands/log-output.ts +1359 -0
  443. package/src/commands/ls-remote-command.ts +105 -58
  444. package/src/commands/mailmap.ts +129 -0
  445. package/src/commands/merge-bases.ts +296 -0
  446. package/src/commands/merge-command.ts +1416 -491
  447. package/src/commands/merge-config.ts +25 -0
  448. package/src/commands/merge-drivers.ts +306 -0
  449. package/src/commands/merge-support.ts +1219 -0
  450. package/src/commands/message-cleanup.ts +275 -0
  451. package/src/commands/mv-command.ts +976 -0
  452. package/src/commands/notes-command.ts +890 -0
  453. package/src/commands/notes-commands.ts +87 -0
  454. package/src/commands/notes-merge-command.ts +777 -0
  455. package/src/commands/notes-support.ts +402 -0
  456. package/src/commands/notes-tree.ts +617 -0
  457. package/src/commands/object-id-input.ts +27 -0
  458. package/src/commands/octopus-merge.ts +378 -0
  459. package/src/commands/ort-merge.ts +1660 -0
  460. package/src/commands/ort-recursive.ts +160 -0
  461. package/src/commands/pack-refs-command.ts +39 -22
  462. package/src/commands/patch-id.ts +204 -0
  463. package/src/commands/pathspec-attributes.ts +162 -0
  464. package/src/commands/pathspec.ts +1199 -0
  465. package/src/commands/post-index-change.ts +62 -0
  466. package/src/commands/pretty-format.ts +1432 -0
  467. package/src/commands/promisor-remote.ts +298 -0
  468. package/src/commands/pull-command.ts +326 -33
  469. package/src/commands/push-command.ts +257 -29
  470. package/src/commands/read-tree-command.ts +861 -0
  471. package/src/commands/rebase-command.ts +3820 -372
  472. package/src/commands/rebase-todo.ts +584 -0
  473. package/src/commands/ref-decoration-filter.ts +118 -0
  474. package/src/commands/reflog-messages.ts +177 -0
  475. package/src/commands/remote-command.ts +124 -23
  476. package/src/commands/remote-transport.ts +383 -0
  477. package/src/commands/reset-command.ts +821 -104
  478. package/src/commands/restore-command.ts +350 -0
  479. package/src/commands/rev-list-command.ts +167 -0
  480. package/src/commands/rev-parse-command.ts +299 -0
  481. package/src/commands/revert-command.ts +152 -399
  482. package/src/commands/revision-filenames.ts +254 -0
  483. package/src/commands/revision-range.ts +222 -0
  484. package/src/commands/revision-resolver.ts +1397 -0
  485. package/src/commands/rm-command.ts +613 -67
  486. package/src/commands/sequencer-pick.ts +874 -0
  487. package/src/commands/sequencer-support.ts +876 -0
  488. package/src/commands/serve-repository.ts +125 -0
  489. package/src/commands/sparse-checkout-command.ts +1389 -0
  490. package/src/commands/sparse-checkout-support.ts +793 -0
  491. package/src/commands/stash-apply-command.ts +376 -343
  492. package/src/commands/stash-create-command.ts +625 -42
  493. package/src/commands/stash-drop-command.ts +15 -2
  494. package/src/commands/stash-working-tree.ts +168 -24
  495. package/src/commands/status-command.ts +1326 -105
  496. package/src/commands/status-format.ts +775 -0
  497. package/src/commands/status-header.ts +332 -0
  498. package/src/commands/strerror.ts +29 -0
  499. package/src/commands/submodule-config.ts +94 -0
  500. package/src/commands/submodule-summary-command.ts +333 -0
  501. package/src/commands/submodule-summary.ts +446 -0
  502. package/src/commands/switch-command.ts +402 -0
  503. package/src/commands/tag-command.ts +129 -41
  504. package/src/commands/tracking-info.ts +201 -0
  505. package/src/commands/trailers.ts +417 -0
  506. package/src/commands/tree-restore.ts +204 -4
  507. package/src/commands/untracked-cache-support.ts +198 -0
  508. package/src/commands/worktree-add-command.ts +458 -0
  509. package/src/commands/worktree-list-command.ts +206 -0
  510. package/src/commands/worktree-lock-command.ts +96 -0
  511. package/src/commands/worktree-overwrite-checks.ts +452 -26
  512. package/src/commands/worktree-prune-command.ts +99 -0
  513. package/src/commands/worktree-remove-command.ts +186 -0
  514. package/src/commands/worktree-repair-command.ts +59 -0
  515. package/src/commands/worktree-support.ts +214 -0
  516. package/src/core-commands/add.command.impl.ts +8 -2
  517. package/src/errors/add-errors.ts +45 -0
  518. package/src/errors/checkout-errors.ts +26 -2
  519. package/src/errors/command-errors.ts +101 -1
  520. package/src/errors/commit-errors.ts +18 -2
  521. package/src/errors/git-api-error.ts +82 -2
  522. package/src/errors/index.ts +1 -0
  523. package/src/errors/merge-errors.ts +2 -2
  524. package/src/errors/rebase-errors.ts +12 -0
  525. package/src/errors/ref-errors.ts +56 -2
  526. package/src/errors/remote-errors.ts +2 -2
  527. package/src/errors/stash-errors.ts +1 -1
  528. package/src/errors/transport-errors.ts +20 -4
  529. package/src/errors/worktree-errors.ts +49 -0
  530. package/src/git-command.ts +1207 -118
  531. package/src/git.ts +538 -12
  532. package/src/index.ts +1 -1
  533. package/src/remote-config/index.ts +2 -0
  534. package/src/remote-config/remote-config-store.ts +378 -18
  535. package/src/remote-config/remote-refs.ts +22 -6
  536. package/src/rename/detect-renames.ts +715 -0
  537. package/src/rename/git-similarity.ts +116 -0
  538. package/src/rename/index.ts +2 -0
  539. package/src/results/binary-patch.ts +401 -0
  540. package/src/results/blame-format.ts +239 -0
  541. package/src/results/cherry-pick-result.ts +10 -0
  542. package/src/results/clone-result.ts +21 -0
  543. package/src/results/combined-diff.ts +585 -0
  544. package/src/results/diff-entry.ts +35 -0
  545. package/src/results/diff-formatter.ts +152 -288
  546. package/src/results/diff-order.ts +64 -0
  547. package/src/results/diff-output.ts +1053 -0
  548. package/src/results/fetch-result.ts +15 -0
  549. package/src/results/index.ts +5 -0
  550. package/src/results/init-result.ts +9 -0
  551. package/src/results/merge-result.ts +15 -1
  552. package/src/results/pull-result.ts +17 -3
  553. package/src/results/push-result.ts +48 -0
  554. package/src/results/quote-path.ts +103 -0
  555. package/src/results/rebase-result.ts +37 -0
  556. package/src/results/revert-result.ts +10 -0
  557. package/src/results/stash-result.ts +6 -0
  558. package/src/results/status-result.ts +127 -46
  559. package/src/transport-command.ts +121 -2
  560. package/dist/commands-CsLNyvZ1.js +0 -12587
  561. package/dist/status-result-BpyUK1Sg.js +0 -519
@@ -0,0 +1,1389 @@
1
+ /**
2
+ * `git sparse-checkout`: the subcommands of git's builtin/sparse-checkout.c (`init`, `set`,
3
+ * `add`, `list`, `reapply`, `disable`, `check-rules`) over the same files git keeps
4
+ * (`$GIT_DIR/info/sparse-checkout`, `core.sparseCheckout` and `core.sparseCheckoutCone` in
5
+ * `config.worktree`), so native git and this command continue each other's work.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * // git sparse-checkout set k s/t
10
+ * await git.sparseCheckout().setArguments(["set", "k", "s/t"]).call();
11
+ * // the same, typed
12
+ * await git.sparseCheckout().setSubcommand("set").addPattern("k").addPattern("s/t").call();
13
+ * const listed = await git.sparseCheckout().setSubcommand("list").call();
14
+ * console.log(listed.stdout); // "k\ns/t\n"
15
+ * ```
16
+ */
17
+
18
+ import { FileMode, joinPath, type PosixFilesApi } from "@statewalker/vcs-core";
19
+ import { GitWorkingCopyConfig } from "@statewalker/vcs-store-files";
20
+ import { parseGitBool } from "@statewalker/vcs-utils";
21
+ import {
22
+ decodeGitPath,
23
+ encodeGitPath,
24
+ foldAsciiCase,
25
+ unquoteGitPath,
26
+ } from "@statewalker/vcs-utils/encoding";
27
+ import {
28
+ type SparseCheckoutPatterns,
29
+ type SparseConeSets,
30
+ type Staging,
31
+ sparsePatternsFromCone,
32
+ sparsePatternsFromLines,
33
+ splitPatternLines,
34
+ type WorkingCopyConfig,
35
+ type Worktree,
36
+ } from "@statewalker/vcs-working-tree";
37
+
38
+ import { GitCommand } from "../git-command.js";
39
+ import { RemoteConfigStore } from "../remote-config/index.js";
40
+ import { quotePath } from "../results/quote-path.js";
41
+ import {
42
+ cleanTrackedSparseDirectories,
43
+ entryList,
44
+ readSparseCheckoutFile,
45
+ sparseCheckoutConfig,
46
+ sparseDirectoriesOf,
47
+ sparseWarningText,
48
+ updateSparsity,
49
+ } from "./sparse-checkout-support.js";
50
+
51
+ /** What a `git sparse-checkout` command did. */
52
+ export interface SparseCheckoutResult {
53
+ /** git's exit status: 0, 128 when it dies, 129 for a usage error */
54
+ exitCode: number;
55
+ /** What git prints on stdout (`list`, `check-rules`) */
56
+ stdout: string;
57
+ /** What git prints on stderr: its `warning:`, `error:` and `fatal:` lines */
58
+ stderr: string;
59
+ /**
60
+ * The warnings among them, without `warning: `: the patterns' own (`unrecognized pattern:
61
+ * '<p>'`, `disabling cone pattern matching`), the paths left despite the patterns, ...
62
+ */
63
+ warnings: string[];
64
+ }
65
+
66
+ /** The subcommands this command runs. */
67
+ export type SparseCheckoutSubcommand =
68
+ | "init"
69
+ | "set"
70
+ | "add"
71
+ | "list"
72
+ | "reapply"
73
+ | "disable"
74
+ | "check-rules"
75
+ | "clean";
76
+
77
+ const SUBCOMMANDS = new Set<string>([
78
+ "list",
79
+ "init",
80
+ "set",
81
+ "add",
82
+ "reapply",
83
+ "disable",
84
+ "check-rules",
85
+ "clean",
86
+ ]);
87
+
88
+ const CONE_HELP = " --[no-]cone initialize the sparse-checkout in cone mode";
89
+ const SPARSE_INDEX_HELP = " --[no-]sparse-index toggle the use of a sparse index";
90
+ const SKIP_CHECKS_HELP =
91
+ " --skip-checks skip some sanity checks on the given paths that might give false positives";
92
+
93
+ /** Each subcommand's usage line and option help, as parse_options prints them. */
94
+ const USAGE: Record<string, { line: string; options: string[] }> = {
95
+ list: { line: "git sparse-checkout list", options: [] },
96
+ init: {
97
+ line: "git sparse-checkout init [--cone] [--[no-]sparse-index]",
98
+ options: [CONE_HELP, SPARSE_INDEX_HELP],
99
+ },
100
+ set: {
101
+ line: "git sparse-checkout set [--[no-]cone] [--[no-]sparse-index] [--skip-checks] (--stdin | <patterns>)",
102
+ options: [
103
+ CONE_HELP,
104
+ SPARSE_INDEX_HELP,
105
+ SKIP_CHECKS_HELP,
106
+ " --stdin read patterns from standard in",
107
+ ],
108
+ },
109
+ add: {
110
+ line: "git sparse-checkout add [--skip-checks] (--stdin | <patterns>)",
111
+ options: [SKIP_CHECKS_HELP, " --[no-]stdin read patterns from standard in"],
112
+ },
113
+ reapply: {
114
+ line: "git sparse-checkout reapply [--[no-]cone] [--[no-]sparse-index]",
115
+ options: [CONE_HELP, SPARSE_INDEX_HELP],
116
+ },
117
+ disable: { line: "git sparse-checkout disable", options: [] },
118
+ "check-rules": {
119
+ line: "git sparse-checkout check-rules [-z] [--skip-checks][--[no-]cone] [--rules-file <file>]",
120
+ options: [
121
+ " -z terminate input and output files by a NUL character",
122
+ " --[no-]cone when used with --rules-file interpret patterns as cone mode patterns",
123
+ " --[no-]rules-file <file>",
124
+ " use patterns in <file> instead of the current ones.",
125
+ ],
126
+ },
127
+ };
128
+
129
+ /** The git version whose behaviour is reproduced where versions differ. */
130
+ export type SparseCheckoutCompatibility = "2.43" | "2.56";
131
+
132
+ /** git dying: `fatal: <message>`, exit 128 (or a usage error, exit 129). */
133
+ class SparseDie extends Error {
134
+ constructor(
135
+ message: string,
136
+ readonly exitCode = 128,
137
+ readonly raw = false,
138
+ ) {
139
+ super(message);
140
+ }
141
+ }
142
+
143
+ /** The options of a subcommand, as its parse_options leaves them. */
144
+ interface SubOptions {
145
+ cone: number;
146
+ sparseIndex: number;
147
+ skipChecks: boolean;
148
+ stdin: boolean;
149
+ nul: boolean;
150
+ rulesFile?: string;
151
+ args: string[];
152
+ }
153
+
154
+ /** A pattern list being built (git's `struct pattern_list`). */
155
+ interface PatternList {
156
+ /** `use_cone_patterns` */
157
+ cone: boolean;
158
+ /** The patterns in order (non-cone mode, and the cone file's lines) */
159
+ lines: string[];
160
+ /** The recursive directories (cone mode; a multiset) */
161
+ recursive: string[];
162
+ /** The parent directories (cone mode; each once) */
163
+ parent: string[];
164
+ }
165
+
166
+ /** The repository's settings as git holds them in its globals while the command runs. */
167
+ interface RunState {
168
+ apply: boolean;
169
+ cone: boolean;
170
+ ignoreCase: boolean;
171
+ }
172
+
173
+ /**
174
+ * `git sparse-checkout <subcommand> <options>` as git 2.5x runs it. Arguments are given as
175
+ * on git's command line ({@link setArguments}) or with the typed setters; `--stdin` reads
176
+ * {@link setStdin}, `--rules-file` the file named (relative to the worktree's root) or the
177
+ * text given to {@link setRulesFile}. `--sparse-index` records `index.sparse=true` and the
178
+ * index is written as a sparse index where cone mode allows it; `--no-sparse-index` records
179
+ * `index.sparse=false` and writes it whole (both in `config.worktree` once the worktree
180
+ * config is on, else in the repository's config, as git).
181
+ */
182
+ export class SparseCheckoutCommand extends GitCommand<SparseCheckoutResult> {
183
+ private args?: string[];
184
+ private subcommand?: SparseCheckoutSubcommand;
185
+ private patterns: string[] = [];
186
+ private cone?: boolean;
187
+ private sparseIndex?: boolean;
188
+ private skipChecks = false;
189
+ private useStdin = false;
190
+ private nulTerminated = false;
191
+ private stdin: Uint8Array = new Uint8Array();
192
+ private rulesFileText?: string;
193
+ private compatibility: SparseCheckoutCompatibility = "2.56";
194
+ private dryRun = false;
195
+ private force = false;
196
+ private verbose = false;
197
+
198
+ private out = "";
199
+ private err = "";
200
+ /**
201
+ * Whether expanding the index still gives git 2.5x's `advice.sparseIndexExpanded` hint
202
+ * (`give_advice_on_expansion`): the index read sparse and not expanded yet
203
+ */
204
+ private adviseOnExpansion = false;
205
+ private warningList: string[] = [];
206
+
207
+ /** The arguments after `git sparse-checkout` (the typed setters are then ignored). */
208
+ setArguments(args: string[]): this {
209
+ this.checkCallable();
210
+ this.args = [...args];
211
+ return this;
212
+ }
213
+
214
+ /** The subcommand to run. */
215
+ setSubcommand(subcommand: SparseCheckoutSubcommand): this {
216
+ this.checkCallable();
217
+ this.subcommand = subcommand;
218
+ return this;
219
+ }
220
+
221
+ /** A directory (cone mode) or pattern (non-cone mode) for `set` and `add`. */
222
+ addPattern(pattern: string): this {
223
+ this.checkCallable();
224
+ this.patterns.push(pattern);
225
+ return this;
226
+ }
227
+
228
+ /** `--cone` (true) or `--no-cone` (false) for `init`, `set`, `reapply` and `check-rules`. */
229
+ setCone(cone: boolean): this {
230
+ this.checkCallable();
231
+ this.cone = cone;
232
+ return this;
233
+ }
234
+
235
+ /** `--sparse-index` or `--no-sparse-index`. */
236
+ setSparseIndex(sparseIndex: boolean): this {
237
+ this.checkCallable();
238
+ this.sparseIndex = sparseIndex;
239
+ return this;
240
+ }
241
+
242
+ /** `--skip-checks` for `set` and `add`. */
243
+ setSkipChecks(skip: boolean): this {
244
+ this.checkCallable();
245
+ this.skipChecks = skip;
246
+ return this;
247
+ }
248
+
249
+ /** What `--stdin` (`set`, `add`) and `check-rules` read; with `useStdin` the typed `--stdin`. */
250
+ setStdin(input: string | Uint8Array, useStdin = true): this {
251
+ this.checkCallable();
252
+ this.stdin = typeof input === "string" ? encodeGitPath(input) : input;
253
+ this.useStdin = useStdin;
254
+ return this;
255
+ }
256
+
257
+ /** `clean --dry-run` (`-n`): print what would be removed, remove nothing. */
258
+ setDryRun(dryRun: boolean): this {
259
+ this.checkCallable();
260
+ this.dryRun = dryRun;
261
+ return this;
262
+ }
263
+
264
+ /** `clean --force` (`-f`), needed unless `--dry-run` or `clean.requireForce=false`. */
265
+ setForce(force: boolean): this {
266
+ this.checkCallable();
267
+ this.force = force;
268
+ return this;
269
+ }
270
+
271
+ /** `clean --verbose` (`-v`): each file removed, not only its directory. */
272
+ setVerbose(verbose: boolean): this {
273
+ this.checkCallable();
274
+ this.verbose = verbose;
275
+ return this;
276
+ }
277
+
278
+ /** `check-rules -z`: input and output terminated by NUL. */
279
+ setNulTerminated(nul: boolean): this {
280
+ this.checkCallable();
281
+ this.nulTerminated = nul;
282
+ return this;
283
+ }
284
+
285
+ /** `check-rules --rules-file`: the rules' text instead of a file. */
286
+ setRulesFile(text: string): this {
287
+ this.checkCallable();
288
+ this.rulesFileText = text;
289
+ return this;
290
+ }
291
+
292
+ /**
293
+ * The git version reproduced (default 2.56): 2.43 takes an unknown option of `set`, `add`
294
+ * and `check-rules` as an argument (`PARSE_OPT_KEEP_UNKNOWN_OPT`) and knows no `clean`.
295
+ */
296
+ setCompatibility(version: SparseCheckoutCompatibility): this {
297
+ this.checkCallable();
298
+ this.compatibility = version;
299
+ return this;
300
+ }
301
+
302
+ async call(): Promise<SparseCheckoutResult> {
303
+ this.checkCallable();
304
+ this.setCallable(false);
305
+ let exitCode = 0;
306
+ try {
307
+ exitCode = await this.dispatch(this.args ?? this.typedArguments());
308
+ } catch (error) {
309
+ if (!(error instanceof SparseDie)) throw error;
310
+ exitCode = error.exitCode;
311
+ this.err += error.raw ? error.message : `fatal: ${error.message}\n`;
312
+ }
313
+ return { exitCode, stdout: this.out, stderr: this.err, warnings: this.warningList };
314
+ }
315
+
316
+ /** The command line the typed setters stand for. */
317
+ private typedArguments(): string[] {
318
+ const args: string[] = [this.subcommand ?? "list"];
319
+ if (this.cone !== undefined) args.push(this.cone ? "--cone" : "--no-cone");
320
+ if (this.sparseIndex !== undefined) {
321
+ args.push(this.sparseIndex ? "--sparse-index" : "--no-sparse-index");
322
+ }
323
+ if (this.skipChecks) args.push("--skip-checks");
324
+ if (this.useStdin && (this.subcommand === "set" || this.subcommand === "add")) {
325
+ args.push("--stdin");
326
+ }
327
+ if (this.nulTerminated) args.push("-z");
328
+ if (this.subcommand === "clean") {
329
+ if (this.dryRun) args.push("--dry-run");
330
+ if (this.force) args.push("--force");
331
+ if (this.verbose) args.push("--verbose");
332
+ }
333
+ if (this.patterns.length > 0) args.push("--", ...this.patterns);
334
+ return args;
335
+ }
336
+
337
+ private warn(message: string): void {
338
+ this.warningList.push(message);
339
+ this.err += `warning: ${message}\n`;
340
+ }
341
+
342
+ /** git's `warning:` lines for the patterns read, in the order git prints them. */
343
+ private warnPatterns(patterns: SparseCheckoutPatterns): void {
344
+ for (const w of patterns.warnings) this.warn(w);
345
+ }
346
+
347
+ /** cmd_sparse_checkout: OPT_SUBCOMMANDs */
348
+ private async dispatch(argv: string[]): Promise<number> {
349
+ const [sub, ...rest] = argv;
350
+ const known = (name: string) =>
351
+ SUBCOMMANDS.has(name) && (name !== "clean" || this.compatibility !== "2.43");
352
+ if (sub === undefined) throw this.usage("", "need a subcommand");
353
+ if (!known(sub)) {
354
+ if (sub.startsWith("-") && sub !== "-") throw this.usage("", unknownOption(sub));
355
+ throw this.usage("", `unknown subcommand: \`${sub}'`);
356
+ }
357
+ if (sub === "clean") return this.clean(rest);
358
+ const opts = this.parseOptions(sub, rest);
359
+ const state = this.runState();
360
+ // disable expands the index on purpose: no hint
361
+ this.adviseOnExpansion =
362
+ sub !== "disable" &&
363
+ this.compatibility !== "2.43" &&
364
+ this.staging.indexLayout?.().sparse === true;
365
+ switch (sub) {
366
+ case "list":
367
+ return this.list(state);
368
+ case "init":
369
+ return this.init(state, opts);
370
+ case "set":
371
+ return this.set(state, opts);
372
+ case "add":
373
+ return this.add(state, opts);
374
+ case "reapply":
375
+ return this.reapply(state, opts);
376
+ case "disable":
377
+ return this.disable(state);
378
+ default:
379
+ return this.checkRules(state, opts);
380
+ }
381
+ }
382
+
383
+ /** parse_options' usage error: `error: <message>`, the usage and option help, exit 129. */
384
+ private usage(sub: string, message: string): SparseDie {
385
+ if (sub === "") {
386
+ const subs = `init | list | set | add | reapply | disable | check-rules${
387
+ this.compatibility === "2.43" ? "" : " | clean"
388
+ }`;
389
+ return new SparseDie(
390
+ `error: ${message}\nusage: git sparse-checkout (${subs}) [<options>]\n\n`,
391
+ 129,
392
+ true,
393
+ );
394
+ }
395
+ const usage = USAGE[sub] as { line: string; options: string[] };
396
+ const options = usage.options.length > 0 ? `${usage.options.join("\n")}\n\n` : "";
397
+ return new SparseDie(`error: ${message}\nusage: ${usage.line}\n\n${options}`, 129, true);
398
+ }
399
+
400
+ /** Each subcommand's parse_options: its options, anywhere before `--`. */
401
+ private parseOptions(sub: string, rest: string[]): SubOptions {
402
+ const opts: SubOptions = {
403
+ cone: -1,
404
+ sparseIndex: -1,
405
+ skipChecks: false,
406
+ stdin: false,
407
+ nul: false,
408
+ args: [],
409
+ };
410
+ const accepts = (name: string) => {
411
+ switch (sub) {
412
+ case "init":
413
+ return name === "cone" || name === "sparse-index";
414
+ case "set":
415
+ return ["cone", "sparse-index", "skip-checks", "stdin"].includes(name);
416
+ case "add":
417
+ return name === "skip-checks" || name === "stdin";
418
+ case "reapply":
419
+ return name === "cone" || name === "sparse-index";
420
+ case "check-rules":
421
+ return name === "cone" || name === "rules-file" || name === "z";
422
+ default:
423
+ return false;
424
+ }
425
+ };
426
+ // OPT_BOOL_F(..., PARSE_OPT_NONEG): no `--no-` form
427
+ const noNegation = (name: string) =>
428
+ name === "skip-checks" || (name === "stdin" && sub === "set");
429
+ for (let i = 0; i < rest.length; i++) {
430
+ const arg = rest[i] as string;
431
+ if (arg === "--") {
432
+ opts.args.push(...rest.slice(i + 1));
433
+ break;
434
+ }
435
+ if (arg === "-z" && accepts("z")) {
436
+ opts.nul = true;
437
+ continue;
438
+ }
439
+ if (!arg.startsWith("-") || arg === "-") {
440
+ opts.args.push(arg);
441
+ continue;
442
+ }
443
+ if (!arg.startsWith("--")) {
444
+ if (this.keepsUnknown(sub)) opts.args.push(arg);
445
+ else throw this.usage(sub, unknownOption(arg));
446
+ continue;
447
+ }
448
+ let name = arg.slice(2);
449
+ let value: string | undefined;
450
+ const eq = name.indexOf("=");
451
+ if (eq >= 0) {
452
+ value = name.slice(eq + 1);
453
+ name = name.slice(0, eq);
454
+ }
455
+ let negated = false;
456
+ if (name.startsWith("no-") && accepts(name.slice(3)) && !noNegation(name.slice(3))) {
457
+ negated = true;
458
+ name = name.slice(3);
459
+ }
460
+ if (!accepts(name)) {
461
+ if (this.keepsUnknown(sub)) opts.args.push(arg);
462
+ else throw this.usage(sub, unknownOption(arg));
463
+ continue;
464
+ }
465
+ if (name === "rules-file") {
466
+ if (negated) {
467
+ opts.rulesFile = undefined;
468
+ continue;
469
+ }
470
+ if (value === undefined) {
471
+ value = rest[++i];
472
+ if (value === undefined) {
473
+ throw new SparseDie("error: option `rules-file' requires a value\n", 129, true);
474
+ }
475
+ }
476
+ opts.rulesFile = value;
477
+ continue;
478
+ }
479
+ if (value !== undefined) {
480
+ throw new SparseDie(`error: option \`${name}' takes no value\n`, 129, true);
481
+ }
482
+ if (name === "cone") opts.cone = negated ? 0 : 1;
483
+ else if (name === "sparse-index") opts.sparseIndex = negated ? 0 : 1;
484
+ else if (name === "skip-checks") opts.skipChecks = true;
485
+ else if (name === "stdin") opts.stdin = !negated;
486
+ }
487
+ if (this.args === undefined && this.rulesFileText !== undefined && sub === "check-rules") {
488
+ opts.rulesFile = "";
489
+ }
490
+ return opts;
491
+ }
492
+
493
+ /** 2.43's PARSE_OPT_KEEP_UNKNOWN_OPT of `set`, `add` and `check-rules` */
494
+ private keepsUnknown(sub: string): boolean {
495
+ return (
496
+ this.compatibility === "2.43" && (sub === "set" || sub === "add" || sub === "check-rules")
497
+ );
498
+ }
499
+
500
+ private runState(): RunState {
501
+ const config = sparseCheckoutConfig(this.workingCopy);
502
+ return { apply: config.enabled, cone: config.cone, ignoreCase: config.ignoreCase };
503
+ }
504
+
505
+ // ---------------------------------------------------------------- subcommands
506
+
507
+ /**
508
+ * sparse_checkout_clean (git 2.5x): every directory the index collapses to a sparse
509
+ * directory (`convert_to_sparse` in memory, whatever `index.sparse` says) is removed with
510
+ * all it holds, untracked and ignored files too; a directory missing from the worktree is
511
+ * passed over. A sparse directory that is a symbolic link in the worktree is passed over
512
+ * too, where git follows it (`remove_dir_recursively` of the path) and empties the
513
+ * directory it points to, which may lie outside the worktree: ours keeps that data, the
514
+ * safer choice.
515
+ */
516
+ private async clean(rest: string[]): Promise<number> {
517
+ const state = this.runState();
518
+ // setup_work_tree, then the mode checks before parse_options
519
+ if (!state.apply) throw new SparseDie("must be in a sparse-checkout to clean directories");
520
+ if (!state.cone) {
521
+ throw new SparseDie("must be in a cone-mode sparse-checkout to clean directories");
522
+ }
523
+ const opts = parseCleanOptions(rest);
524
+ if (opts.help) {
525
+ this.out += CLEAN_USAGE;
526
+ return 0;
527
+ }
528
+ if (opts.error !== undefined) {
529
+ // a value given to a flag is reported alone, as parse_options does
530
+ const usage = opts.error.endsWith("takes no value") ? "" : CLEAN_USAGE;
531
+ throw new SparseDie(`error: ${opts.error}\n${usage}`, 129, true);
532
+ }
533
+ const raw = RemoteConfigStore.from(this.workingCopy).value("clean.requireforce");
534
+ let requireForce = true;
535
+ if (raw !== undefined) {
536
+ const parsed = parseGitBool(raw);
537
+ if (parsed === undefined) {
538
+ throw new SparseDie(`bad boolean config value '${raw}' for 'clean.requireforce'`);
539
+ }
540
+ requireForce = parsed;
541
+ }
542
+ if (requireForce && !opts.force && !opts.dryRun) {
543
+ throw new SparseDie("for safety, refusing to clean without one of --force or --dry-run");
544
+ }
545
+ const content = await readSparseCheckoutFile(this.workingCopy);
546
+ const patterns = sparsePatternsFromLines(
547
+ content === undefined ? [] : splitPatternLines(content),
548
+ state.cone,
549
+ state.ignoreCase,
550
+ );
551
+ const dirs = sparseDirectoriesOf(await entryList(this.staging), patterns);
552
+ if (!dirs) {
553
+ throw new SparseDie(
554
+ "failed to convert index to a sparse index; resolve merge conflicts and try again",
555
+ );
556
+ }
557
+ const worktree = this.worktreeAccess;
558
+ if (!worktree) return 0;
559
+ const message = opts.dryRun ? "Would remove" : "Removing";
560
+ for (const dir of dirs) {
561
+ const path = dir.slice(0, -1);
562
+ const current = await worktree.getEntry(path).catch(() => undefined);
563
+ if (!current?.isDirectory || current.mode === FileMode.SYMLINK) continue;
564
+ if (opts.verbose) {
565
+ for (const file of await this.filesBelow(worktree, dir)) this.out += `${message} ${file}\n`;
566
+ } else {
567
+ this.out += `${message} ${dir}\n`;
568
+ }
569
+ if (opts.dryRun) continue;
570
+ const removed = await worktree.remove(path, { recursive: true }).catch(() => false);
571
+ if (!removed) this.warn(`failed to remove '${dir}'`);
572
+ }
573
+ return 0;
574
+ }
575
+
576
+ /**
577
+ * dir.c's for_each_file_in_dir under `dir` (with its trailing slash): the regular files,
578
+ * depth first in readdir order; symbolic links and other kinds are not listed.
579
+ */
580
+ private async filesBelow(worktree: Worktree, dir: string): Promise<string[]> {
581
+ const files = worktree.getFiles?.() as PosixFilesApi | undefined;
582
+ const root = worktree.getRoot?.() ?? "";
583
+ if (!files) return [];
584
+ const full = (path: string) => (root ? joinPath(root, path) : path);
585
+ const out: string[] = [];
586
+ const walk = async (prefix: string): Promise<void> => {
587
+ let entries: { name: string; kind?: string }[] = [];
588
+ try {
589
+ if (files.listKinds) {
590
+ entries = await files.listKinds(full(prefix.slice(0, -1)), { readdirOrder: true });
591
+ } else {
592
+ for await (const e of files.list(full(prefix.slice(0, -1)))) {
593
+ entries.push({ name: e.name, kind: e.kind });
594
+ }
595
+ }
596
+ } catch {
597
+ return;
598
+ }
599
+ for (const entry of entries) {
600
+ const path = `${prefix}${entry.name}`;
601
+ let kind = entry.kind;
602
+ if (kind === undefined)
603
+ kind = (await files.lstat?.(full(path)).catch(() => undefined))?.kind;
604
+ if (kind === "file") out.push(path);
605
+ else if (kind === "directory") await walk(`${path}/`);
606
+ }
607
+ };
608
+ await walk(dir);
609
+ return out;
610
+ }
611
+
612
+ /** sparse_checkout_list */
613
+ private async list(state: RunState): Promise<number> {
614
+ if (!state.apply) throw new SparseDie("this worktree is not sparse");
615
+ const content = await readSparseCheckoutFile(this.workingCopy);
616
+ if (content === undefined) {
617
+ this.warn("this worktree is not sparse (sparse-checkout file may not exist)");
618
+ return 0;
619
+ }
620
+ const patterns = sparsePatternsFromLines(
621
+ splitPatternLines(content),
622
+ state.cone,
623
+ state.ignoreCase,
624
+ );
625
+ this.warnPatterns(patterns);
626
+ if (patterns.coneSets) {
627
+ const names = sortUnique(patterns.coneSets.recursive.map((p) => p.slice(1)));
628
+ const quote = this.quotePathFully();
629
+ for (const name of names) this.out += `${quotePath(name, quote)}\n`;
630
+ } else {
631
+ for (const line of patterns.lines) this.out += `${line}\n`;
632
+ }
633
+ return 0;
634
+ }
635
+
636
+ /** sparse_checkout_init */
637
+ private async init(state: RunState, opts: SubOptions): Promise<number> {
638
+ await this.readCurrentIndex();
639
+ await this.updateModes(state, opts);
640
+ const content = await readSparseCheckoutFile(this.workingCopy);
641
+ // an existing sparse-checkout file is used as it is
642
+ if (content !== undefined) return this.updateWorkingDirectory(state, undefined);
643
+ const head = await this.refsStore.resolve("HEAD").catch(() => undefined);
644
+ if (!head?.objectId) {
645
+ // a fresh repository: the file written, nothing to update
646
+ await this.writeSparseFile("/*\n!/*/\n");
647
+ return 0;
648
+ }
649
+ const pl: PatternList = {
650
+ cone: opts.cone !== 0,
651
+ lines: ["/*", "!/*/"],
652
+ recursive: [],
653
+ parent: [],
654
+ };
655
+ return this.writePatternsAndUpdate(state, pl);
656
+ }
657
+
658
+ /** sparse_checkout_set */
659
+ private async set(state: RunState, opts: SubOptions): Promise<number> {
660
+ await this.readCurrentIndex();
661
+ await this.updateModes(state, opts);
662
+ let patterns: string[];
663
+ if (!state.cone && !opts.stdin && opts.args.length === 0) {
664
+ // non-cone mode without patterns: the top-level directory only, as `init`
665
+ patterns = ["/*", "!/*/"];
666
+ } else {
667
+ patterns = [...opts.args];
668
+ await this.sanitizePaths(state, patterns, opts.skipChecks);
669
+ }
670
+ return this.modifyPatternList(state, patterns, opts.stdin, "replace");
671
+ }
672
+
673
+ /** sparse_checkout_add */
674
+ private async add(state: RunState, opts: SubOptions): Promise<number> {
675
+ if (!state.apply) throw new SparseDie("no sparse-checkout to add to");
676
+ await this.readCurrentIndex();
677
+ const patterns = [...opts.args];
678
+ await this.sanitizePaths(state, patterns, opts.skipChecks);
679
+ return this.modifyPatternList(state, patterns, opts.stdin, "add");
680
+ }
681
+
682
+ /** sparse_checkout_reapply */
683
+ private async reapply(state: RunState, opts: SubOptions): Promise<number> {
684
+ if (!state.apply) {
685
+ throw new SparseDie("must be in a sparse-checkout to reapply sparsity patterns");
686
+ }
687
+ await this.readCurrentIndex();
688
+ await this.updateModes(state, opts);
689
+ return this.updateWorkingDirectory(state, undefined);
690
+ }
691
+
692
+ /** sparse_checkout_disable: back to a full checkout, whatever the state */
693
+ private async disable(state: RunState): Promise<number> {
694
+ await this.readCurrentIndex();
695
+ state.apply = true;
696
+ const pl: PatternList = { cone: false, lines: ["/*"], recursive: [], parent: [] };
697
+ if ((await this.updateWorkingDirectory(state, pl)) !== 0) {
698
+ throw new SparseDie("error while refreshing working directory");
699
+ }
700
+ await this.setConfig("none");
701
+ return 0;
702
+ }
703
+
704
+ /** sparse_checkout_check_rules */
705
+ private async checkRules(state: RunState, opts: SubOptions): Promise<number> {
706
+ let cone = opts.cone;
707
+ if (opts.rulesFile !== undefined && cone < 0) cone = 1;
708
+ this.updateConeMode(state, cone);
709
+ let patterns: SparseCheckoutPatterns;
710
+ if (opts.rulesFile !== undefined) {
711
+ const text = this.rulesFileText ?? (await this.readRulesFile(opts.rulesFile));
712
+ const pl = this.patternsFromInput(state, [], linesOf(text));
713
+ patterns = this.matcherOf(pl, state);
714
+ } else {
715
+ const content = await readSparseCheckoutFile(this.workingCopy);
716
+ if (content === undefined)
717
+ throw new SparseDie("unable to load existing sparse-checkout patterns");
718
+ patterns = sparsePatternsFromLines(splitPatternLines(content), state.cone, state.ignoreCase);
719
+ this.warnPatterns(patterns);
720
+ }
721
+ const terminator = opts.nul ? "\0" : "\n";
722
+ const quote = this.quotePathFully();
723
+ for (const raw of inputLines(this.stdin, opts.nul)) {
724
+ let path = decodeGitPath(raw);
725
+ if (!opts.nul && raw[0] === 0x22) {
726
+ const unquoted = unquoteGitPath(raw);
727
+ if (!unquoted) throw new SparseDie(`unable to unquote C-style string '${path}'`);
728
+ path = unquoted.path;
729
+ }
730
+ if (patterns.includes(path)) {
731
+ this.out += `${opts.nul ? path : quotePath(path, quote)}${terminator}`;
732
+ }
733
+ }
734
+ return 0;
735
+ }
736
+
737
+ // ---------------------------------------------------------------- git's helpers
738
+
739
+ /** update_cone_mode */
740
+ private updateConeMode(state: RunState, coneMode: number): "cone" | "all" {
741
+ let cone = coneMode;
742
+ // if not given, the previous definition of cone mode
743
+ if (cone === -1 && state.apply) cone = state.cone ? 1 : 0;
744
+ state.apply = true;
745
+ if (cone === 1 || cone === -1) {
746
+ state.cone = true;
747
+ return "cone";
748
+ }
749
+ state.cone = false;
750
+ return "all";
751
+ }
752
+
753
+ /** update_modes */
754
+ private async updateModes(state: RunState, opts: SubOptions): Promise<void> {
755
+ const recordMode = opts.cone !== -1 || !state.apply;
756
+ const mode = this.updateConeMode(state, opts.cone);
757
+ if (recordMode) await this.setConfig(mode);
758
+ // set_sparse_index_config: the setting recorded, the index written again (sparse when
759
+ // the cone allows it, whole for --no-sparse-index) by update_working_directory's write
760
+ if (opts.sparseIndex >= 0) {
761
+ await this.setWorktreeConfigGently([
762
+ ["index.sparse", opts.sparseIndex === 1 ? "true" : "false"],
763
+ ]);
764
+ // ensure_full_index
765
+ if (opts.sparseIndex === 0) this.expandIndex();
766
+ }
767
+ }
768
+
769
+ /** git's `expand_index` to a full index: 2.5x's hint the first time a sparse index expands. */
770
+ private expandIndex(): void {
771
+ if (!this.adviseOnExpansion) return;
772
+ this.adviseOnExpansion = false;
773
+ const config = this.workingCopy.config as { get?(key: string): unknown } | undefined;
774
+ const value = String(config?.get?.("advice.sparseIndexExpanded") ?? "true").toLowerCase();
775
+ if (["false", "no", "off", "0"].includes(value)) return;
776
+ this.err +=
777
+ "hint: The sparse index is expanding to a full index, a slow operation.\n" +
778
+ "hint: Your working directory likely has contents that are outside of\n" +
779
+ "hint: your sparse-checkout patterns. Use 'git sparse-checkout list' to\n" +
780
+ "hint: see your sparse-checkout definition and compare it to your working\n" +
781
+ "hint: directory contents. Cleaning up any merge conflicts or staged\n" +
782
+ "hint: changes before running 'git sparse-checkout clean' or 'git\n" +
783
+ "hint: sparse-checkout reapply' may assist in this cleanup.\n" +
784
+ 'hint: Disable this message with "git config set advice.sparseIndexExpanded false"\n';
785
+ }
786
+
787
+ /** set_config: the worktree's config (init_worktree_config first) */
788
+ private async setConfig(mode: "none" | "all" | "cone"): Promise<void> {
789
+ const values: [string, string][] = [
790
+ ["core.sparseCheckout", mode === "none" ? "false" : "true"],
791
+ ["core.sparseCheckoutCone", mode === "cone" ? "true" : "false"],
792
+ ];
793
+ if (mode === "none") values.push(["index.sparse", "false"]);
794
+ await this.writeWorktreeConfig(values);
795
+ }
796
+
797
+ /**
798
+ * `repo_config_set_worktree_gently` after `init_worktree_config`: `extensions.worktreeConfig`
799
+ * set in the repository's config if it is not, then the values written to this worktree's
800
+ * `config.worktree`. A configuration without files takes the values itself.
801
+ */
802
+ private async writeWorktreeConfig(values: [string, string][]): Promise<void> {
803
+ const config = this.workingCopy.config as
804
+ | (WorkingCopyConfig & {
805
+ get?(key: string): unknown;
806
+ set?(key: string, value: unknown): void;
807
+ save?(): Promise<void>;
808
+ load?(): Promise<void>;
809
+ })
810
+ | undefined;
811
+ if (!config) return;
812
+ const checkout = this.workingCopy.checkout;
813
+ const fileBacked =
814
+ typeof config.load === "function" &&
815
+ typeof config.save === "function" &&
816
+ typeof config.set === "function" &&
817
+ typeof checkout?.readStateFile === "function" &&
818
+ typeof checkout?.writeStateFile === "function";
819
+ if (!fileBacked || !checkout?.readStateFile || !checkout.writeStateFile) {
820
+ for (const [key, value] of values) {
821
+ if (typeof config.set === "function") config.set(key, value);
822
+ else config[key] = value;
823
+ }
824
+ return;
825
+ }
826
+ const enabled = String(config.get?.("extensions.worktreeConfig") ?? "").toLowerCase();
827
+ if (!["true", "yes", "on", "1"].includes(enabled)) {
828
+ config.set?.("extensions.worktreeConfig", "true");
829
+ await config.save?.();
830
+ }
831
+ const read = checkout.readStateFile.bind(checkout);
832
+ const write = checkout.writeStateFile.bind(checkout);
833
+ const worktreeConfig = new GitWorkingCopyConfig(
834
+ { read: (path) => read(path), write: (path, content) => write(path, content) },
835
+ "config.worktree",
836
+ { includes: false },
837
+ );
838
+ await worktreeConfig.load();
839
+ for (const [key, value] of values) worktreeConfig.set(key, value);
840
+ await worktreeConfig.save();
841
+ // the repository's config reads config.worktree again
842
+ await config.load?.();
843
+ }
844
+
845
+ /**
846
+ * `repo_config_set_worktree_gently`: the values written to this worktree's
847
+ * `config.worktree` when `extensions.worktreeConfig` is on, else to the repository's config.
848
+ */
849
+ private async setWorktreeConfigGently(values: [string, string][]): Promise<void> {
850
+ const config = this.workingCopy.config as
851
+ | (WorkingCopyConfig & {
852
+ get?(key: string): unknown;
853
+ set?(key: string, value: unknown): void;
854
+ save?(): Promise<void>;
855
+ })
856
+ | undefined;
857
+ const enabled = String(config?.get?.("extensions.worktreeConfig") ?? "").toLowerCase();
858
+ if (["true", "yes", "on", "1"].includes(enabled) || !config?.save || !config.set) {
859
+ await this.writeWorktreeConfig(values);
860
+ return;
861
+ }
862
+ for (const [key, value] of values) config.set(key, value);
863
+ await config.save();
864
+ }
865
+
866
+ /** modify_pattern_list */
867
+ private async modifyPatternList(
868
+ state: RunState,
869
+ args: string[],
870
+ useStdin: boolean,
871
+ kind: "replace" | "add",
872
+ ): Promise<number> {
873
+ const stdinLines = useStdin ? linesOf(decodeGitPath(this.stdin)) : undefined;
874
+ let pl: PatternList;
875
+ if (kind === "add") {
876
+ pl = state.cone
877
+ ? await this.addPatternsConeMode(state, args, stdinLines)
878
+ : await this.addPatternsLiteral(state, args, stdinLines);
879
+ } else {
880
+ pl = this.patternsFromInput(state, args, stdinLines);
881
+ }
882
+ let changedConfig = false;
883
+ if (!state.apply) {
884
+ await this.setConfig("all");
885
+ state.apply = true;
886
+ changedConfig = true;
887
+ }
888
+ const result = await this.writePatternsAndUpdate(state, pl);
889
+ if (result && changedConfig) await this.setConfig("none");
890
+ return result;
891
+ }
892
+
893
+ /** add_patterns_from_input: cone-mode directories or literal patterns */
894
+ private patternsFromInput(
895
+ state: RunState,
896
+ args: string[],
897
+ stdinLines: string[] | undefined,
898
+ ): PatternList {
899
+ const pl: PatternList = { cone: false, lines: [], recursive: [], parent: [] };
900
+ if (state.cone) {
901
+ pl.cone = true;
902
+ if (stdinLines) {
903
+ for (const raw of stdinLines) {
904
+ let line = raw;
905
+ if (line.startsWith('"')) {
906
+ const unquoted = unquoteGitPath(encodeGitPath(line));
907
+ if (!unquoted) throw new SparseDie(`unable to unquote C-style string '${line}'`);
908
+ line = unquoted.path;
909
+ }
910
+ this.toConePattern(line, pl, state);
911
+ }
912
+ } else {
913
+ for (const arg of args) this.toConePattern(arg, pl, state);
914
+ }
915
+ } else {
916
+ pl.lines.push(...(stdinLines ?? args));
917
+ }
918
+ return pl;
919
+ }
920
+
921
+ /** strbuf_to_cone_pattern */
922
+ private toConePattern(input: string, pl: PatternList, state: RunState): void {
923
+ let line = input.replace(/^[ \t\n\v\f\r]+|[ \t\n\v\f\r]+$/g, "");
924
+ while (line.endsWith("/")) line = line.slice(0, -1);
925
+ const normalized = normalizePath(line);
926
+ if (normalized === undefined) throw new SparseDie(`could not normalize path ${line}`);
927
+ if (!normalized) return;
928
+ insertRecursivePattern(pl, normalized.startsWith("/") ? normalized : `/${normalized}`, state);
929
+ }
930
+
931
+ /** add_patterns_cone_mode */
932
+ private async addPatternsConeMode(
933
+ state: RunState,
934
+ args: string[],
935
+ stdinLines: string[] | undefined,
936
+ ): Promise<PatternList> {
937
+ const pl = this.patternsFromInput(state, args, stdinLines);
938
+ const content = await readSparseCheckoutFile(this.workingCopy);
939
+ if (content === undefined)
940
+ throw new SparseDie("unable to load existing sparse-checkout patterns");
941
+ const existing = sparsePatternsFromLines(
942
+ splitPatternLines(content),
943
+ state.cone,
944
+ state.ignoreCase,
945
+ );
946
+ this.warnPatterns(existing);
947
+ if (!existing.coneSets)
948
+ throw new SparseDie("existing sparse-checkout patterns do not use cone mode");
949
+ for (const pattern of existing.coneSets.recursive) {
950
+ if (
951
+ !containsParent(pl.recursive, pattern, state) ||
952
+ !containsParent(pl.parent, pattern, state)
953
+ ) {
954
+ insertRecursivePattern(pl, pattern, state);
955
+ }
956
+ }
957
+ return pl;
958
+ }
959
+
960
+ /** add_patterns_literal */
961
+ private async addPatternsLiteral(
962
+ state: RunState,
963
+ args: string[],
964
+ stdinLines: string[] | undefined,
965
+ ): Promise<PatternList> {
966
+ const content = await readSparseCheckoutFile(this.workingCopy);
967
+ if (content === undefined)
968
+ throw new SparseDie("unable to load existing sparse-checkout patterns");
969
+ const pl = this.patternsFromInput(state, args, stdinLines);
970
+ pl.lines.unshift(...splitPatternLines(content));
971
+ return pl;
972
+ }
973
+
974
+ /** sanitize_paths (from the top-level directory: no prefix) */
975
+ private async sanitizePaths(state: RunState, args: string[], skipChecks: boolean): Promise<void> {
976
+ if (args.length === 0 || skipChecks) return;
977
+ if (state.cone) {
978
+ for (const arg of args) {
979
+ if (arg.startsWith("/")) {
980
+ throw new SparseDie("specify directories rather than patterns (no leading slash)");
981
+ }
982
+ if (arg.startsWith("!")) {
983
+ throw new SparseDie(
984
+ "specify directories rather than patterns. If your directory starts with a '!', pass --skip-checks",
985
+ );
986
+ }
987
+ if (/[*?[\]]/.test(arg)) {
988
+ throw new SparseDie(
989
+ "specify directories rather than patterns. If your directory really has any of '*?[]\\' in it, pass --skip-checks",
990
+ );
991
+ }
992
+ }
993
+ }
994
+ const tracked = new Set<string>();
995
+ for await (const entry of this.staging.entries()) {
996
+ if (entry.stage === 0) tracked.add(entry.path);
997
+ }
998
+ for (const arg of args) {
999
+ if (!tracked.has(arg)) continue;
1000
+ if (state.cone) {
1001
+ throw new SparseDie(
1002
+ `'${arg}' is not a directory; to treat it as a directory anyway, rerun with --skip-checks`,
1003
+ );
1004
+ }
1005
+ this.warn(
1006
+ `pass a leading slash before paths such as '${arg}' if you want a single file (see NON-CONE PROBLEMS in the git-sparse-checkout manual).`,
1007
+ );
1008
+ }
1009
+ }
1010
+
1011
+ /** write_patterns_and_update */
1012
+ private async writePatternsAndUpdate(state: RunState, pl: PatternList): Promise<number> {
1013
+ const result = await this.updateWorkingDirectory(state, pl);
1014
+ if (result) {
1015
+ await this.updateWorkingDirectory(state, undefined);
1016
+ return result;
1017
+ }
1018
+ await this.writeSparseFile(state.cone ? coneFileText(pl, state) : patternsFileText(pl.lines));
1019
+ return 0;
1020
+ }
1021
+
1022
+ /**
1023
+ * The matcher of a pattern list as git's `path_in_sparse_checkout` uses it: a cone-mode
1024
+ * list by its hashsets (none for `init`'s, whose patterns were added before cone mode was
1025
+ * set), any other by its patterns.
1026
+ */
1027
+ private matcherOf(pl: PatternList, state: RunState): SparseCheckoutPatterns {
1028
+ if (pl.cone) {
1029
+ const sets: SparseConeSets = { full: false, recursive: pl.recursive, parent: pl.parent };
1030
+ return sparsePatternsFromCone(sets, state.ignoreCase);
1031
+ }
1032
+ return sparsePatternsFromLines(pl.lines, false, state.ignoreCase);
1033
+ }
1034
+
1035
+ /** update_working_directory: git's `update_sparsity` with `pl` (absent: the file's patterns) */
1036
+ private async updateWorkingDirectory(
1037
+ state: RunState,
1038
+ pl: PatternList | undefined,
1039
+ ): Promise<number> {
1040
+ const staging = this.staging;
1041
+ // no branch checked out: nothing to update
1042
+ let any = false;
1043
+ for await (const _ of staging.entries()) {
1044
+ any = true;
1045
+ break;
1046
+ }
1047
+ if (!any) return 0;
1048
+ let patterns: SparseCheckoutPatterns;
1049
+ if (pl) patterns = this.matcherOf(pl, state);
1050
+ else {
1051
+ const content = await readSparseCheckoutFile(this.workingCopy);
1052
+ patterns = sparsePatternsFromLines(
1053
+ content === undefined ? [] : splitPatternLines(content),
1054
+ state.cone,
1055
+ state.ignoreCase,
1056
+ );
1057
+ this.warnPatterns(patterns);
1058
+ }
1059
+ // update_sparsity's expand_index: patterns not of the cone's shape expand it fully
1060
+ if (!patterns.cone || patterns.coneSets === undefined) this.expandIndex();
1061
+ // write_locked_index converts to a sparse index with the patterns being applied (git sets
1062
+ // them on the index for update_sparsity), when index.sparse and cone mode allow it
1063
+ const previousHost = staging.getIndexHost?.();
1064
+ if (staging.setIndexHost) {
1065
+ const allowed = state.apply && state.cone && patterns.cone && patterns.coneSets !== undefined;
1066
+ staging.setIndexHost({
1067
+ ...(previousHost ?? {}),
1068
+ ...(previousHost?.trees ? { trees: previousHost.trees } : {}),
1069
+ settings: async () => {
1070
+ const settings = { ...((await previousHost?.settings?.()) ?? {}) };
1071
+ const config = RemoteConfigStore.from(this.workingCopy);
1072
+ const indexSparse = (() => {
1073
+ try {
1074
+ return parseGitBool(config.value("index.sparse")) === true;
1075
+ } catch {
1076
+ return false;
1077
+ }
1078
+ })();
1079
+ if (allowed && indexSparse) settings.sparse = patterns;
1080
+ else delete settings.sparse;
1081
+ return settings;
1082
+ },
1083
+ });
1084
+ }
1085
+ try {
1086
+ return await this.applySparsity(state, pl, patterns, staging);
1087
+ } finally {
1088
+ staging.setIndexHost?.(previousHost);
1089
+ }
1090
+ }
1091
+
1092
+ /** update_working_directory once its patterns are known: update_sparsity, then the write. */
1093
+ private async applySparsity(
1094
+ state: RunState,
1095
+ pl: PatternList | undefined,
1096
+ patterns: SparseCheckoutPatterns,
1097
+ staging: Staging,
1098
+ ): Promise<number> {
1099
+ const outcome = await updateSparsity(
1100
+ {
1101
+ workingCopy: this.workingCopy,
1102
+ worktree: this.worktreeAccess,
1103
+ staging,
1104
+ blobs: this.blobs,
1105
+ },
1106
+ patterns,
1107
+ );
1108
+ // check_updates (its unlink warnings) before display_warning_msgs
1109
+ for (const line of outcome.unlinkWarnings) {
1110
+ this.err += line;
1111
+ this.warningList.push(line.slice("warning: ".length, -1));
1112
+ }
1113
+ const text = sparseWarningText(outcome, true);
1114
+ if (text) {
1115
+ this.err += text;
1116
+ for (const block of text.split("\n\n")) {
1117
+ if (block.startsWith("warning: ")) this.warningList.push(block.slice("warning: ".length));
1118
+ }
1119
+ }
1120
+ // write_locked_index: also the flags cleared on reading the index
1121
+ if (!outcome.changed) await staging.write();
1122
+ // clean_tracked_sparse_directories reads the patterns again (init_sparse_checkout_patterns)
1123
+ // when none were given: their warnings are printed twice
1124
+ if (!pl && state.apply) this.warnPatterns(patterns);
1125
+ const cleaned = await cleanTrackedSparseDirectories(
1126
+ { worktree: this.worktreeAccess, staging },
1127
+ patterns,
1128
+ );
1129
+ for (const line of cleaned.split("\n")) {
1130
+ if (line) this.warn(line.slice("warning: ".length));
1131
+ }
1132
+ return 0;
1133
+ }
1134
+
1135
+ private async writeSparseFile(text: string): Promise<void> {
1136
+ const checkout = this.workingCopy.checkout;
1137
+ if (!checkout?.writeStateFile) {
1138
+ throw new SparseDie("failed to create directory for sparse-checkout file");
1139
+ }
1140
+ await checkout.writeStateFile("info/sparse-checkout", encodeGitPath(text));
1141
+ }
1142
+
1143
+ /** OPT_FILENAME: the rules file, relative to the worktree's root */
1144
+ private async readRulesFile(path: string): Promise<string> {
1145
+ const worktree = this.worktreeAccess;
1146
+ const fail = () =>
1147
+ new SparseDie(`could not open '${path}' for reading: No such file or directory`);
1148
+ if (!worktree) throw fail();
1149
+ const entry = await worktree.getEntry(path).catch(() => undefined);
1150
+ if (!entry || entry.isDirectory) throw fail();
1151
+ const chunks: Uint8Array[] = [];
1152
+ for await (const chunk of worktree.readContent(path)) chunks.push(chunk);
1153
+ let size = 0;
1154
+ for (const c of chunks) size += c.length;
1155
+ const bytes = new Uint8Array(size);
1156
+ let at = 0;
1157
+ for (const c of chunks) {
1158
+ bytes.set(c, at);
1159
+ at += c.length;
1160
+ }
1161
+ return decodeGitPath(bytes);
1162
+ }
1163
+
1164
+ /** `core.quotePath` */
1165
+ private quotePathFully(): boolean {
1166
+ const config = this.workingCopy.config as { get?(key: string): unknown } | undefined;
1167
+ const value = String(config?.get?.("core.quotePath") ?? "true").toLowerCase();
1168
+ return !["false", "no", "off", "0"].includes(value);
1169
+ }
1170
+ }
1171
+
1172
+ // ------------------------------------------------------------------ helpers
1173
+
1174
+ const CLEAN_USAGE =
1175
+ "usage: git sparse-checkout clean [-n|--dry-run]\n\n" +
1176
+ " -n, --[no-]dry-run dry run\n" +
1177
+ " -f, --[no-]force force\n" +
1178
+ " -v, --[no-]verbose report each affected file, not just directories\n\n";
1179
+
1180
+ /**
1181
+ * parse_options of `sparse-checkout clean`: `-n`/`--dry-run`, `-f`/`--force` and
1182
+ * `-v`/`--verbose` (bundled short options, unique prefixes, `--no-` forms), anywhere before
1183
+ * `--`; other arguments are ignored, as git ignores them.
1184
+ */
1185
+ function parseCleanOptions(rest: string[]): {
1186
+ dryRun: boolean;
1187
+ force: boolean;
1188
+ verbose: boolean;
1189
+ help?: boolean;
1190
+ error?: string;
1191
+ } {
1192
+ const opts = { dryRun: false, force: false, verbose: false };
1193
+ const longs = ["dry-run", "force", "verbose"] as const;
1194
+ const set = (name: (typeof longs)[number], value: boolean) => {
1195
+ if (name === "dry-run") opts.dryRun = value;
1196
+ else if (name === "force") opts.force = value;
1197
+ else opts.verbose = value;
1198
+ };
1199
+ for (const arg of rest) {
1200
+ if (arg === "--") break;
1201
+ if (arg === "-h") return { ...opts, help: true };
1202
+ if (!arg.startsWith("-") || arg === "-") continue;
1203
+ if (!arg.startsWith("--")) {
1204
+ for (const c of arg.slice(1)) {
1205
+ if (c === "n") opts.dryRun = true;
1206
+ else if (c === "f") opts.force = true;
1207
+ else if (c === "v") opts.verbose = true;
1208
+ else if (c === "h") return { ...opts, help: true };
1209
+ else return { ...opts, error: `unknown switch \`${c}'` };
1210
+ }
1211
+ continue;
1212
+ }
1213
+ let name = arg.slice(2);
1214
+ const eq = name.indexOf("=");
1215
+ const hasValue = eq >= 0;
1216
+ if (hasValue) name = name.slice(0, eq);
1217
+ let negated = false;
1218
+ let candidates: string[] = longs.filter((l) => l === name);
1219
+ if (candidates.length === 0 && name.startsWith("no-")) {
1220
+ candidates = longs.filter((l) => l === name.slice(3));
1221
+ negated = candidates.length > 0;
1222
+ }
1223
+ if (candidates.length === 0) {
1224
+ const all = [
1225
+ ...longs.map((l) => [l, false] as const),
1226
+ ...longs.map((l) => [l, true] as const),
1227
+ ];
1228
+ const found = all.filter(([l, neg]) => (neg ? `no-${l}` : l).startsWith(name));
1229
+ if (found.length > 1) {
1230
+ const names = found.slice(0, 2).map(([l, neg]) => `--${neg ? "no-" : ""}${l}`);
1231
+ return { ...opts, error: `ambiguous option: ${name} (could be ${names.join(" or ")})` };
1232
+ }
1233
+ if (found.length === 1) {
1234
+ candidates = [(found[0] as readonly [string, boolean])[0]];
1235
+ negated = (found[0] as readonly [string, boolean])[1];
1236
+ }
1237
+ }
1238
+ const match = candidates[0] as (typeof longs)[number] | undefined;
1239
+ if (!match) return { ...opts, error: `unknown option \`${name}'` };
1240
+ if (hasValue) return { ...opts, error: `option \`${match}' takes no value` };
1241
+ set(match, !negated);
1242
+ }
1243
+ return opts;
1244
+ }
1245
+
1246
+ function unknownOption(arg: string): string {
1247
+ return arg.startsWith("--") ? `unknown option \`${arg.slice(2)}'` : `unknown switch \`${arg[1]}'`;
1248
+ }
1249
+
1250
+ /** strbuf_getline over text: lines without `\n` (and a CR before it); a last unterminated one counts. */
1251
+ function linesOf(text: string): string[] {
1252
+ if (text === "") return [];
1253
+ const lines = text.split("\n");
1254
+ if (lines[lines.length - 1] === "") lines.pop();
1255
+ return lines.map((l) => (l.endsWith("\r") ? l.slice(0, -1) : l));
1256
+ }
1257
+
1258
+ /** The input lines of check-rules as bytes (strbuf_getline or strbuf_getline_nul). */
1259
+ function inputLines(bytes: Uint8Array, nul: boolean): Uint8Array[] {
1260
+ const out: Uint8Array[] = [];
1261
+ const sep = nul ? 0 : 0x0a;
1262
+ let start = 0;
1263
+ for (let i = 0; i <= bytes.length; i++) {
1264
+ if (i < bytes.length && bytes[i] !== sep) continue;
1265
+ if (i === bytes.length && start === i) break;
1266
+ let end = i;
1267
+ if (!nul && end > start && bytes[end - 1] === 0x0d) end--;
1268
+ out.push(bytes.subarray(start, end));
1269
+ start = i + 1;
1270
+ }
1271
+ return out;
1272
+ }
1273
+
1274
+ /** strcmp order of the names' bytes, duplicates dropped (string_list_sort_u). */
1275
+ function sortUnique(names: string[]): string[] {
1276
+ const sorted = [...names].sort((a, b) => compareBytes(a, b));
1277
+ return sorted.filter((name, i) => i === 0 || sorted[i - 1] !== name);
1278
+ }
1279
+
1280
+ function compareBytes(a: string, b: string): number {
1281
+ const x = encodeGitPath(a);
1282
+ const y = encodeGitPath(b);
1283
+ for (let i = 0; i < Math.min(x.length, y.length); i++) {
1284
+ if (x[i] !== y[i]) return (x[i] as number) - (y[i] as number);
1285
+ }
1286
+ return x.length - y.length;
1287
+ }
1288
+
1289
+ const foldOf = (state: RunState) => (state.ignoreCase ? foldAsciiCase : (s: string) => s);
1290
+
1291
+ /** insert_recursive_pattern: the directory and each of its parents */
1292
+ function insertRecursivePattern(pl: PatternList, path: string, state: RunState): void {
1293
+ const fold = foldOf(state);
1294
+ pl.recursive.push(path);
1295
+ let pattern = path;
1296
+ while (pattern.length > 0) {
1297
+ const slash = pattern.lastIndexOf("/");
1298
+ if (slash <= 0) break;
1299
+ pattern = pattern.slice(0, slash);
1300
+ const folded = fold(pattern);
1301
+ if (!pl.parent.some((p) => fold(p) === folded)) pl.parent.push(pattern);
1302
+ }
1303
+ }
1304
+
1305
+ /** hashmap_contains_parent: whether a proper parent directory of `path` is in `set` */
1306
+ function containsParent(set: string[], path: string, state: RunState): boolean {
1307
+ const fold = foldOf(state);
1308
+ const keys = new Set(set.map(fold));
1309
+ let buffer = path.startsWith("/") ? path : `/${path}`;
1310
+ for (let slash = buffer.lastIndexOf("/"); slash > 0; slash = buffer.lastIndexOf("/")) {
1311
+ buffer = buffer.slice(0, slash);
1312
+ if (keys.has(fold(buffer))) return true;
1313
+ }
1314
+ return false;
1315
+ }
1316
+
1317
+ /** escaped_pattern: each glob character escaped */
1318
+ function escapedPattern(pattern: string): string {
1319
+ return pattern.replace(/[*?[\\]/g, (c) => `\\${c}`);
1320
+ }
1321
+
1322
+ /** write_cone_to_file */
1323
+ function coneFileText(pl: PatternList, state: RunState): string {
1324
+ const fold = foldOf(state);
1325
+ const recursiveKeys = new Set(pl.recursive.map(fold));
1326
+ const parents = pl.parent.filter(
1327
+ (p) => !recursiveKeys.has(fold(p)) && !containsParent(pl.recursive, p, state),
1328
+ );
1329
+ let text = "/*\n!/*/\n";
1330
+ for (const parent of sortUnique(parents)) {
1331
+ const pattern = escapedPattern(parent);
1332
+ if (pattern.length > 0) text += `${pattern}/\n!${pattern}/*/\n`;
1333
+ }
1334
+ const recursive = pl.recursive.filter((p) => !containsParent(pl.recursive, p, state));
1335
+ for (const dir of sortUnique(recursive)) text += `${escapedPattern(dir)}/\n`;
1336
+ return text;
1337
+ }
1338
+
1339
+ /** write_patterns_to_file */
1340
+ function patternsFileText(lines: string[]): string {
1341
+ return lines.map((l) => `${l}\n`).join("");
1342
+ }
1343
+
1344
+ /** normalize_path_copy_len (POSIX): undefined when the path climbs above its start. */
1345
+ function normalizePath(src: string): string | undefined {
1346
+ let dst = "";
1347
+ let i = 0;
1348
+ if (src.startsWith("/")) {
1349
+ dst = "/";
1350
+ i = 1;
1351
+ }
1352
+ const dst0 = dst.length;
1353
+ while (src[i] === "/") i++;
1354
+ for (;;) {
1355
+ if (src[i] === ".") {
1356
+ const next = src[i + 1];
1357
+ if (next === undefined) {
1358
+ i++;
1359
+ } else if (next === "/") {
1360
+ i += 2;
1361
+ while (src[i] === "/") i++;
1362
+ continue;
1363
+ } else if (next === ".") {
1364
+ const after = src[i + 2];
1365
+ if (after === undefined || after === "/") {
1366
+ i += after === undefined ? 2 : 3;
1367
+ while (src[i] === "/") i++;
1368
+ // up one: dst ends with '/'
1369
+ let end = dst.length - 1;
1370
+ if (end <= dst0) return undefined;
1371
+ while (end > dst0 && dst[end - 1] !== "/") end--;
1372
+ dst = dst.slice(0, end);
1373
+ continue;
1374
+ }
1375
+ }
1376
+ }
1377
+ // copy up to the next '/', and eat all '/'
1378
+ let c = src[i++];
1379
+ while (c !== undefined && c !== "/") {
1380
+ dst += c;
1381
+ c = src[i++];
1382
+ }
1383
+ if (c === "/") {
1384
+ dst += "/";
1385
+ while (src[i] === "/") i++;
1386
+ } else break;
1387
+ }
1388
+ return dst;
1389
+ }