@statewalker/vcs-commands 0.6.0 → 0.8.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 (481) hide show
  1. package/dist/commands/add-command.d.ts +38 -0
  2. package/dist/commands/add-command.d.ts.map +1 -1
  3. package/dist/commands/am/am-command.d.ts +55 -1
  4. package/dist/commands/am/am-command.d.ts.map +1 -1
  5. package/dist/commands/am/index.d.ts +1 -0
  6. package/dist/commands/am/index.d.ts.map +1 -1
  7. package/dist/commands/am/mailsplit.d.ts +88 -0
  8. package/dist/commands/am/mailsplit.d.ts.map +1 -0
  9. package/dist/commands/apply/apply-command.d.ts.map +1 -1
  10. package/dist/commands/apply/apply-engine.d.ts.map +1 -1
  11. package/dist/commands/apply/apply-parse.d.ts.map +1 -1
  12. package/dist/commands/bisect/bisect-command.d.ts +2 -0
  13. package/dist/commands/bisect/bisect-command.d.ts.map +1 -1
  14. package/dist/commands/bisect/bisect-engine.d.ts.map +1 -1
  15. package/dist/commands/branch-command.d.ts +148 -18
  16. package/dist/commands/branch-command.d.ts.map +1 -1
  17. package/dist/commands/branch-info-command.d.ts +55 -0
  18. package/dist/commands/branch-info-command.d.ts.map +1 -0
  19. package/dist/commands/branch-tracking.d.ts +106 -17
  20. package/dist/commands/branch-tracking.d.ts.map +1 -1
  21. package/dist/commands/branch-upstream-command.d.ts +83 -0
  22. package/dist/commands/branch-upstream-command.d.ts.map +1 -0
  23. package/dist/commands/checkout-command.d.ts +19 -3
  24. package/dist/commands/checkout-command.d.ts.map +1 -1
  25. package/dist/commands/cherry-pick-command.d.ts +59 -0
  26. package/dist/commands/cherry-pick-command.d.ts.map +1 -1
  27. package/dist/commands/clean-command.d.ts +12 -0
  28. package/dist/commands/clean-command.d.ts.map +1 -1
  29. package/dist/commands/clone-command.d.ts +17 -0
  30. package/dist/commands/clone-command.d.ts.map +1 -1
  31. package/dist/commands/comment-char-config.d.ts +35 -0
  32. package/dist/commands/comment-char-config.d.ts.map +1 -0
  33. package/dist/commands/commit-command.d.ts +191 -5
  34. package/dist/commands/commit-command.d.ts.map +1 -1
  35. package/dist/commands/commit-reuse.d.ts +33 -0
  36. package/dist/commands/commit-reuse.d.ts.map +1 -0
  37. package/dist/commands/config-command.d.ts +236 -0
  38. package/dist/commands/config-command.d.ts.map +1 -0
  39. package/dist/commands/config-value-types.d.ts +91 -0
  40. package/dist/commands/config-value-types.d.ts.map +1 -0
  41. package/dist/commands/core-config.d.ts +20 -0
  42. package/dist/commands/core-config.d.ts.map +1 -1
  43. package/dist/commands/default-branch.d.ts +70 -0
  44. package/dist/commands/default-branch.d.ts.map +1 -0
  45. package/dist/commands/diff-color-config.d.ts +73 -0
  46. package/dist/commands/diff-color-config.d.ts.map +1 -0
  47. package/dist/commands/diff-command.d.ts +252 -5
  48. package/dist/commands/diff-command.d.ts.map +1 -1
  49. package/dist/commands/fetch-command.d.ts +20 -0
  50. package/dist/commands/fetch-command.d.ts.map +1 -1
  51. package/dist/commands/fmt-merge-msg-command.d.ts +124 -0
  52. package/dist/commands/fmt-merge-msg-command.d.ts.map +1 -0
  53. package/dist/commands/fork-point.d.ts +38 -0
  54. package/dist/commands/fork-point.d.ts.map +1 -0
  55. package/dist/commands/format-patch-command.d.ts +41 -1
  56. package/dist/commands/format-patch-command.d.ts.map +1 -1
  57. package/dist/commands/fsck/fetch-fsck.d.ts +51 -0
  58. package/dist/commands/fsck/fetch-fsck.d.ts.map +1 -1
  59. package/dist/commands/fsck/fsck-command.d.ts +2 -0
  60. package/dist/commands/fsck/fsck-command.d.ts.map +1 -1
  61. package/dist/commands/fsck/fsck-loose.d.ts +3 -0
  62. package/dist/commands/fsck/fsck-loose.d.ts.map +1 -1
  63. package/dist/commands/fsck/fsck-object-checks.d.ts +25 -14
  64. package/dist/commands/fsck/fsck-object-checks.d.ts.map +1 -1
  65. package/dist/commands/fsck/fsck-object-table.d.ts +15 -7
  66. package/dist/commands/fsck/fsck-object-table.d.ts.map +1 -1
  67. package/dist/commands/fsck/fsck-pack.d.ts +11 -4
  68. package/dist/commands/fsck/fsck-pack.d.ts.map +1 -1
  69. package/dist/commands/fsck/verify-pack-command.d.ts.map +1 -1
  70. package/dist/commands/gc-command.d.ts +80 -48
  71. package/dist/commands/gc-command.d.ts.map +1 -1
  72. package/dist/commands/git-date.d.ts +1 -65
  73. package/dist/commands/git-date.d.ts.map +1 -1
  74. package/dist/commands/git-describe.d.ts +4 -0
  75. package/dist/commands/git-describe.d.ts.map +1 -1
  76. package/dist/commands/git-hooks.d.ts +43 -0
  77. package/dist/commands/git-hooks.d.ts.map +1 -1
  78. package/dist/commands/grep/grep-command.d.ts +210 -0
  79. package/dist/commands/grep/grep-command.d.ts.map +1 -0
  80. package/dist/commands/grep/grep-engine.d.ts +218 -0
  81. package/dist/commands/grep/grep-engine.d.ts.map +1 -0
  82. package/dist/commands/grep/index.d.ts +3 -0
  83. package/dist/commands/grep/index.d.ts.map +1 -0
  84. package/dist/commands/index-adder.d.ts +15 -2
  85. package/dist/commands/index-adder.d.ts.map +1 -1
  86. package/dist/commands/index.d.ts +28 -0
  87. package/dist/commands/index.d.ts.map +1 -1
  88. package/dist/commands/index.js +3 -3
  89. package/dist/commands/init-command.d.ts +50 -3
  90. package/dist/commands/init-command.d.ts.map +1 -1
  91. package/dist/commands/interpret-trailers-command.d.ts +90 -0
  92. package/dist/commands/interpret-trailers-command.d.ts.map +1 -0
  93. package/dist/commands/legacy-remotes.d.ts +55 -0
  94. package/dist/commands/legacy-remotes.d.ts.map +1 -0
  95. package/dist/commands/local-transport.d.ts +36 -5
  96. package/dist/commands/local-transport.d.ts.map +1 -1
  97. package/dist/commands/log-command.d.ts +296 -11
  98. package/dist/commands/log-command.d.ts.map +1 -1
  99. package/dist/commands/log-graph.d.ts +26 -1
  100. package/dist/commands/log-graph.d.ts.map +1 -1
  101. package/dist/commands/log-output.d.ts +133 -5
  102. package/dist/commands/log-output.d.ts.map +1 -1
  103. package/dist/commands/ls-remote-command.d.ts +2 -0
  104. package/dist/commands/ls-remote-command.d.ts.map +1 -1
  105. package/dist/commands/mailmap.d.ts +30 -0
  106. package/dist/commands/mailmap.d.ts.map +1 -1
  107. package/dist/commands/merge-base-command.d.ts +60 -0
  108. package/dist/commands/merge-base-command.d.ts.map +1 -0
  109. package/dist/commands/merge-bases.d.ts +23 -0
  110. package/dist/commands/merge-bases.d.ts.map +1 -1
  111. package/dist/commands/merge-command.d.ts +108 -9
  112. package/dist/commands/merge-command.d.ts.map +1 -1
  113. package/dist/commands/merge-support.d.ts +11 -3
  114. package/dist/commands/merge-support.d.ts.map +1 -1
  115. package/dist/commands/mv-command.d.ts +4 -0
  116. package/dist/commands/mv-command.d.ts.map +1 -1
  117. package/dist/commands/name-rev.d.ts +48 -0
  118. package/dist/commands/name-rev.d.ts.map +1 -0
  119. package/dist/commands/notes-command.d.ts.map +1 -1
  120. package/dist/commands/notes-merge-command.d.ts.map +1 -1
  121. package/dist/commands/notes-tree.d.ts +11 -1
  122. package/dist/commands/notes-tree.d.ts.map +1 -1
  123. package/dist/commands/patch-id.d.ts +3 -0
  124. package/dist/commands/patch-id.d.ts.map +1 -1
  125. package/dist/commands/pathspec-file.d.ts +39 -0
  126. package/dist/commands/pathspec-file.d.ts.map +1 -0
  127. package/dist/commands/pathspec.d.ts +3 -0
  128. package/dist/commands/pathspec.d.ts.map +1 -1
  129. package/dist/commands/pretty-format.d.ts +43 -3
  130. package/dist/commands/pretty-format.d.ts.map +1 -1
  131. package/dist/commands/promisor-remote.d.ts.map +1 -1
  132. package/dist/commands/pull-command.d.ts +28 -0
  133. package/dist/commands/pull-command.d.ts.map +1 -1
  134. package/dist/commands/push-command.d.ts +160 -9
  135. package/dist/commands/push-command.d.ts.map +1 -1
  136. package/dist/commands/read-tree-command.d.ts +6 -0
  137. package/dist/commands/read-tree-command.d.ts.map +1 -1
  138. package/dist/commands/rebase-command.d.ts +168 -6
  139. package/dist/commands/rebase-command.d.ts.map +1 -1
  140. package/dist/commands/ref-filter/for-each-ref-command.d.ts +121 -0
  141. package/dist/commands/ref-filter/for-each-ref-command.d.ts.map +1 -0
  142. package/dist/commands/ref-filter/index.d.ts +8 -0
  143. package/dist/commands/ref-filter/index.d.ts.map +1 -0
  144. package/dist/commands/ref-filter/ref-atoms.d.ts +88 -0
  145. package/dist/commands/ref-filter/ref-atoms.d.ts.map +1 -0
  146. package/dist/commands/ref-filter/ref-filter.d.ts +178 -0
  147. package/dist/commands/ref-filter/ref-filter.d.ts.map +1 -0
  148. package/dist/commands/ref-filter/ref-format.d.ts +222 -0
  149. package/dist/commands/ref-filter/ref-format.d.ts.map +1 -0
  150. package/dist/commands/ref-filter/ref-listing-command.d.ts +56 -0
  151. package/dist/commands/ref-filter/ref-listing-command.d.ts.map +1 -0
  152. package/dist/commands/ref-filter/ref-quote.d.ts +20 -0
  153. package/dist/commands/ref-filter/ref-quote.d.ts.map +1 -0
  154. package/dist/commands/ref-filter/version-compare.d.ts +20 -0
  155. package/dist/commands/ref-filter/version-compare.d.ts.map +1 -0
  156. package/dist/commands/reflog-command.d.ts +120 -0
  157. package/dist/commands/reflog-command.d.ts.map +1 -1
  158. package/dist/commands/reflog-walk.d.ts +72 -0
  159. package/dist/commands/reflog-walk.d.ts.map +1 -0
  160. package/dist/commands/remote-command.d.ts +138 -29
  161. package/dist/commands/remote-command.d.ts.map +1 -1
  162. package/dist/commands/remote-transport.d.ts +7 -1
  163. package/dist/commands/remote-transport.d.ts.map +1 -1
  164. package/dist/commands/reset-command.d.ts +2 -3
  165. package/dist/commands/reset-command.d.ts.map +1 -1
  166. package/dist/commands/restore-command.d.ts +2 -3
  167. package/dist/commands/restore-command.d.ts.map +1 -1
  168. package/dist/commands/rev-filter/commit-filter.d.ts +95 -0
  169. package/dist/commands/rev-filter/commit-filter.d.ts.map +1 -0
  170. package/dist/commands/rev-filter/commit-grep.d.ts +91 -0
  171. package/dist/commands/rev-filter/commit-grep.d.ts.map +1 -0
  172. package/dist/commands/rev-filter/index.d.ts +3 -0
  173. package/dist/commands/rev-filter/index.d.ts.map +1 -0
  174. package/dist/commands/rev-list-command.d.ts +154 -2
  175. package/dist/commands/rev-list-command.d.ts.map +1 -1
  176. package/dist/commands/rev-parse-command.d.ts +9 -0
  177. package/dist/commands/rev-parse-command.d.ts.map +1 -1
  178. package/dist/commands/revert-command.d.ts +32 -0
  179. package/dist/commands/revert-command.d.ts.map +1 -1
  180. package/dist/commands/revision-range.d.ts +32 -1
  181. package/dist/commands/revision-range.d.ts.map +1 -1
  182. package/dist/commands/revision-resolver.d.ts +21 -2
  183. package/dist/commands/revision-resolver.d.ts.map +1 -1
  184. package/dist/commands/rm-command.d.ts +70 -2
  185. package/dist/commands/rm-command.d.ts.map +1 -1
  186. package/dist/commands/sequencer-pick.d.ts +85 -5
  187. package/dist/commands/sequencer-pick.d.ts.map +1 -1
  188. package/dist/commands/sequencer-support.d.ts +2 -0
  189. package/dist/commands/sequencer-support.d.ts.map +1 -1
  190. package/dist/commands/serve-repository.d.ts +7 -0
  191. package/dist/commands/serve-repository.d.ts.map +1 -1
  192. package/dist/commands/show-command.d.ts +130 -0
  193. package/dist/commands/show-command.d.ts.map +1 -0
  194. package/dist/commands/show-commit.d.ts +11 -0
  195. package/dist/commands/show-commit.d.ts.map +1 -0
  196. package/dist/commands/signature-check.d.ts +164 -0
  197. package/dist/commands/signature-check.d.ts.map +1 -0
  198. package/dist/commands/signing.d.ts +160 -0
  199. package/dist/commands/signing.d.ts.map +1 -0
  200. package/dist/commands/sparse-checkout-command.d.ts.map +1 -1
  201. package/dist/commands/sparse-index-view.d.ts +45 -0
  202. package/dist/commands/sparse-index-view.d.ts.map +1 -0
  203. package/dist/commands/ssh-signer.d.ts +29 -0
  204. package/dist/commands/ssh-signer.d.ts.map +1 -0
  205. package/dist/commands/ssh-verifier.d.ts +42 -0
  206. package/dist/commands/ssh-verifier.d.ts.map +1 -0
  207. package/dist/commands/stash-apply-command.d.ts +5 -0
  208. package/dist/commands/stash-apply-command.d.ts.map +1 -1
  209. package/dist/commands/stash-branch-command.d.ts +34 -0
  210. package/dist/commands/stash-branch-command.d.ts.map +1 -0
  211. package/dist/commands/stash-create-command.d.ts +18 -1
  212. package/dist/commands/stash-create-command.d.ts.map +1 -1
  213. package/dist/commands/stash-info.d.ts +93 -0
  214. package/dist/commands/stash-info.d.ts.map +1 -0
  215. package/dist/commands/stash-list-command.d.ts +16 -0
  216. package/dist/commands/stash-list-command.d.ts.map +1 -1
  217. package/dist/commands/stash-pop-command.d.ts +39 -0
  218. package/dist/commands/stash-pop-command.d.ts.map +1 -0
  219. package/dist/commands/stash-show-command.d.ts +48 -0
  220. package/dist/commands/stash-show-command.d.ts.map +1 -0
  221. package/dist/commands/stash-store-command.d.ts +29 -0
  222. package/dist/commands/stash-store-command.d.ts.map +1 -0
  223. package/dist/commands/stash-working-tree.d.ts.map +1 -1
  224. package/dist/commands/status-command.d.ts.map +1 -1
  225. package/dist/commands/status-header.d.ts +5 -0
  226. package/dist/commands/status-header.d.ts.map +1 -1
  227. package/dist/commands/submodule-add-command.d.ts +89 -0
  228. package/dist/commands/submodule-add-command.d.ts.map +1 -0
  229. package/dist/commands/submodule-auth.d.ts +90 -0
  230. package/dist/commands/submodule-auth.d.ts.map +1 -0
  231. package/dist/commands/submodule-commands.d.ts +375 -0
  232. package/dist/commands/submodule-commands.d.ts.map +1 -0
  233. package/dist/commands/submodule-model.d.ts +288 -0
  234. package/dist/commands/submodule-model.d.ts.map +1 -0
  235. package/dist/commands/submodule-summary-command.d.ts.map +1 -1
  236. package/dist/commands/submodule-update-command.d.ts +198 -0
  237. package/dist/commands/submodule-update-command.d.ts.map +1 -0
  238. package/dist/commands/switch-command.d.ts.map +1 -1
  239. package/dist/commands/tag-command.d.ts +259 -10
  240. package/dist/commands/tag-command.d.ts.map +1 -1
  241. package/dist/commands/trailers.d.ts +218 -17
  242. package/dist/commands/trailers.d.ts.map +1 -1
  243. package/dist/commands/tree-restore.d.ts +7 -0
  244. package/dist/commands/tree-restore.d.ts.map +1 -1
  245. package/dist/commands/untracked-cache-support.d.ts +2 -1
  246. package/dist/commands/untracked-cache-support.d.ts.map +1 -1
  247. package/dist/commands/verify-command.d.ts +92 -0
  248. package/dist/commands/verify-command.d.ts.map +1 -0
  249. package/dist/commands/worktree-add-command.d.ts +79 -7
  250. package/dist/commands/worktree-add-command.d.ts.map +1 -1
  251. package/dist/commands/worktree-list-command.d.ts.map +1 -1
  252. package/dist/commands/worktree-path-rules.d.ts +66 -0
  253. package/dist/commands/worktree-path-rules.d.ts.map +1 -0
  254. package/dist/commands/worktree-remove-command.d.ts +10 -3
  255. package/dist/commands/worktree-remove-command.d.ts.map +1 -1
  256. package/dist/commands/worktree-repair-command.d.ts +15 -2
  257. package/dist/commands/worktree-repair-command.d.ts.map +1 -1
  258. package/dist/commands/worktree-support.d.ts +5 -0
  259. package/dist/commands/worktree-support.d.ts.map +1 -1
  260. package/dist/{commands-DnmlfwGV.js → commands-ISM52N0n.js} +66120 -49271
  261. package/dist/errors/checkout-errors.d.ts +19 -0
  262. package/dist/errors/checkout-errors.d.ts.map +1 -1
  263. package/dist/errors/command-errors.d.ts.map +1 -1
  264. package/dist/errors/index.js +57 -3
  265. package/dist/errors/ref-errors.d.ts +19 -0
  266. package/dist/errors/ref-errors.d.ts.map +1 -1
  267. package/dist/errors/worktree-errors.d.ts +6 -1
  268. package/dist/errors/worktree-errors.d.ts.map +1 -1
  269. package/dist/{git-command-DxvwPrPB.js → fsck-DLRpbwTj.js} +6863 -1070
  270. package/dist/git-command.d.ts +43 -2
  271. package/dist/git-command.d.ts.map +1 -1
  272. package/dist/git.d.ts +276 -3
  273. package/dist/git.d.ts.map +1 -1
  274. package/dist/index.js +5 -5
  275. package/dist/remote-config/index.d.ts +1 -1
  276. package/dist/remote-config/index.d.ts.map +1 -1
  277. package/dist/remote-config/remote-config-store.d.ts +117 -3
  278. package/dist/remote-config/remote-config-store.d.ts.map +1 -1
  279. package/dist/rename/detect-renames.d.ts.map +1 -1
  280. package/dist/results/clone-result.d.ts +8 -0
  281. package/dist/results/clone-result.d.ts.map +1 -1
  282. package/dist/results/combined-diff.d.ts +3 -0
  283. package/dist/results/combined-diff.d.ts.map +1 -1
  284. package/dist/results/diff-check.d.ts +38 -0
  285. package/dist/results/diff-check.d.ts.map +1 -0
  286. package/dist/results/diff-color.d.ts +135 -0
  287. package/dist/results/diff-color.d.ts.map +1 -0
  288. package/dist/results/diff-output.d.ts +85 -1
  289. package/dist/results/diff-output.d.ts.map +1 -1
  290. package/dist/results/diff-pickaxe.d.ts +67 -0
  291. package/dist/results/diff-pickaxe.d.ts.map +1 -0
  292. package/dist/results/diff-words.d.ts +55 -0
  293. package/dist/results/diff-words.d.ts.map +1 -0
  294. package/dist/results/index.d.ts +4 -0
  295. package/dist/results/index.d.ts.map +1 -1
  296. package/dist/results/index.js +2 -2
  297. package/dist/results/init-result.d.ts +7 -0
  298. package/dist/results/init-result.d.ts.map +1 -1
  299. package/dist/results/pull-result.d.ts +5 -0
  300. package/dist/results/pull-result.d.ts.map +1 -1
  301. package/dist/results/push-result.d.ts +12 -0
  302. package/dist/results/push-result.d.ts.map +1 -1
  303. package/dist/results/rebase-result.d.ts +2 -0
  304. package/dist/results/rebase-result.d.ts.map +1 -1
  305. package/dist/results/stash-result.d.ts +6 -0
  306. package/dist/results/stash-result.d.ts.map +1 -1
  307. package/dist/results/status-result.d.ts.map +1 -1
  308. package/dist/{results-BZGa2Z3I.js → results-TB2IJ64h.js} +2178 -412
  309. package/dist/whitespace/index.d.ts +2 -0
  310. package/dist/whitespace/index.d.ts.map +1 -0
  311. package/dist/whitespace/whitespace-rule.d.ts +94 -0
  312. package/dist/whitespace/whitespace-rule.d.ts.map +1 -0
  313. package/package.json +12 -12
  314. package/src/commands/add-command.ts +178 -17
  315. package/src/commands/add-patch/add-interactive.ts +3 -3
  316. package/src/commands/am/am-command.ts +263 -43
  317. package/src/commands/am/index.ts +1 -0
  318. package/src/commands/am/mailsplit.ts +326 -0
  319. package/src/commands/apply/apply-command.ts +18 -8
  320. package/src/commands/apply/apply-engine.ts +6 -7
  321. package/src/commands/apply/apply-parse.ts +10 -10
  322. package/src/commands/attributes-source.ts +1 -1
  323. package/src/commands/bisect/bisect-command.ts +18 -5
  324. package/src/commands/bisect/bisect-engine.ts +2 -1
  325. package/src/commands/branch-command.ts +528 -53
  326. package/src/commands/branch-info-command.ts +150 -0
  327. package/src/commands/branch-tracking.ts +335 -60
  328. package/src/commands/branch-upstream-command.ts +218 -0
  329. package/src/commands/checkout-command.ts +70 -44
  330. package/src/commands/cherry-pick-command.ts +143 -0
  331. package/src/commands/clean-command.ts +34 -3
  332. package/src/commands/clone-command.ts +118 -5
  333. package/src/commands/comment-char-config.ts +160 -0
  334. package/src/commands/commit-command.ts +790 -71
  335. package/src/commands/commit-reuse.ts +94 -0
  336. package/src/commands/config-command.ts +1256 -0
  337. package/src/commands/config-value-types.ts +358 -0
  338. package/src/commands/core-config.ts +47 -2
  339. package/src/commands/default-branch.ts +196 -0
  340. package/src/commands/diff-color-config.ts +274 -0
  341. package/src/commands/diff-command.ts +1053 -75
  342. package/src/commands/fetch-command.ts +161 -13
  343. package/src/commands/fmt-merge-msg-command.ts +715 -0
  344. package/src/commands/fork-point.ts +63 -0
  345. package/src/commands/format-patch-command.ts +316 -43
  346. package/src/commands/fsck/fetch-fsck.ts +172 -18
  347. package/src/commands/fsck/fsck-command.ts +183 -66
  348. package/src/commands/fsck/fsck-loose.ts +14 -4
  349. package/src/commands/fsck/fsck-object-checks.ts +87 -46
  350. package/src/commands/fsck/fsck-object-table.ts +52 -42
  351. package/src/commands/fsck/fsck-pack.ts +64 -34
  352. package/src/commands/fsck/verify-pack-command.ts +5 -2
  353. package/src/commands/gc-command.ts +238 -107
  354. package/src/commands/git-date.ts +9 -895
  355. package/src/commands/git-describe.ts +31 -11
  356. package/src/commands/git-hooks.ts +92 -0
  357. package/src/commands/grep/grep-command.ts +1077 -0
  358. package/src/commands/grep/grep-engine.ts +1024 -0
  359. package/src/commands/grep/index.ts +2 -0
  360. package/src/commands/index-adder.ts +54 -10
  361. package/src/commands/index.ts +28 -0
  362. package/src/commands/init-command.ts +167 -11
  363. package/src/commands/interpret-trailers-command.ts +256 -0
  364. package/src/commands/legacy-remotes.ts +224 -0
  365. package/src/commands/local-transport.ts +109 -10
  366. package/src/commands/log-command.ts +1283 -232
  367. package/src/commands/log-graph.ts +123 -26
  368. package/src/commands/log-output.ts +280 -21
  369. package/src/commands/ls-remote-command.ts +9 -0
  370. package/src/commands/mailmap.ts +119 -0
  371. package/src/commands/merge-base-command.ts +170 -0
  372. package/src/commands/merge-bases.ts +63 -8
  373. package/src/commands/merge-command.ts +360 -82
  374. package/src/commands/merge-support.ts +43 -9
  375. package/src/commands/mv-command.ts +6 -3
  376. package/src/commands/name-rev.ts +171 -0
  377. package/src/commands/notes-command.ts +11 -1
  378. package/src/commands/notes-merge-command.ts +23 -14
  379. package/src/commands/notes-tree.ts +28 -13
  380. package/src/commands/octopus-merge.ts +3 -2
  381. package/src/commands/patch-id.ts +16 -8
  382. package/src/commands/pathspec-file.ts +72 -0
  383. package/src/commands/pathspec.ts +14 -2
  384. package/src/commands/pretty-format.ts +105 -20
  385. package/src/commands/promisor-remote.ts +10 -1
  386. package/src/commands/pull-command.ts +149 -22
  387. package/src/commands/push-command.ts +704 -72
  388. package/src/commands/read-tree-command.ts +34 -3
  389. package/src/commands/rebase-command.ts +957 -142
  390. package/src/commands/ref-filter/for-each-ref-command.ts +298 -0
  391. package/src/commands/ref-filter/index.ts +7 -0
  392. package/src/commands/ref-filter/ref-atoms.ts +581 -0
  393. package/src/commands/ref-filter/ref-filter.ts +651 -0
  394. package/src/commands/ref-filter/ref-format.ts +1070 -0
  395. package/src/commands/ref-filter/ref-listing-command.ts +421 -0
  396. package/src/commands/ref-filter/ref-quote.ts +69 -0
  397. package/src/commands/ref-filter/version-compare.ts +177 -0
  398. package/src/commands/reflog-command.ts +492 -2
  399. package/src/commands/reflog-walk.ts +234 -0
  400. package/src/commands/remote-command.ts +484 -74
  401. package/src/commands/remote-transport.ts +9 -1
  402. package/src/commands/reset-command.ts +40 -42
  403. package/src/commands/restore-command.ts +12 -41
  404. package/src/commands/rev-filter/commit-filter.ts +159 -0
  405. package/src/commands/rev-filter/commit-grep.ts +444 -0
  406. package/src/commands/rev-filter/index.ts +2 -0
  407. package/src/commands/rev-list-command.ts +402 -15
  408. package/src/commands/rev-parse-command.ts +22 -0
  409. package/src/commands/revert-command.ts +82 -0
  410. package/src/commands/revision-range.ts +204 -4
  411. package/src/commands/revision-resolver.ts +55 -22
  412. package/src/commands/rm-command.ts +282 -21
  413. package/src/commands/sequencer-pick.ts +504 -86
  414. package/src/commands/sequencer-support.ts +30 -5
  415. package/src/commands/serve-repository.ts +18 -3
  416. package/src/commands/show-command.ts +490 -0
  417. package/src/commands/show-commit.ts +24 -0
  418. package/src/commands/signature-check.ts +657 -0
  419. package/src/commands/signing.ts +385 -0
  420. package/src/commands/sparse-checkout-command.ts +2 -9
  421. package/src/commands/sparse-checkout-support.ts +2 -2
  422. package/src/commands/sparse-index-view.ts +135 -0
  423. package/src/commands/ssh-signer.ts +199 -0
  424. package/src/commands/ssh-verifier.ts +523 -0
  425. package/src/commands/stash-apply-command.ts +17 -5
  426. package/src/commands/stash-branch-command.ts +88 -0
  427. package/src/commands/stash-create-command.ts +30 -2
  428. package/src/commands/stash-info.ts +243 -0
  429. package/src/commands/stash-list-command.ts +33 -0
  430. package/src/commands/stash-pop-command.ts +83 -0
  431. package/src/commands/stash-show-command.ts +141 -0
  432. package/src/commands/stash-store-command.ts +82 -0
  433. package/src/commands/stash-working-tree.ts +2 -2
  434. package/src/commands/status-command.ts +7 -6
  435. package/src/commands/status-header.ts +44 -8
  436. package/src/commands/submodule-add-command.ts +509 -0
  437. package/src/commands/submodule-auth.ts +276 -0
  438. package/src/commands/submodule-commands.ts +1517 -0
  439. package/src/commands/submodule-model.ts +930 -0
  440. package/src/commands/submodule-summary-command.ts +6 -7
  441. package/src/commands/submodule-update-command.ts +1092 -0
  442. package/src/commands/switch-command.ts +3 -1
  443. package/src/commands/tag-command.ts +876 -64
  444. package/src/commands/trailers.ts +837 -100
  445. package/src/commands/tree-restore.ts +38 -10
  446. package/src/commands/untracked-cache-support.ts +16 -12
  447. package/src/commands/verify-command.ts +235 -0
  448. package/src/commands/worktree-add-command.ts +268 -24
  449. package/src/commands/worktree-list-command.ts +3 -5
  450. package/src/commands/worktree-path-rules.ts +183 -0
  451. package/src/commands/worktree-remove-command.ts +39 -5
  452. package/src/commands/worktree-repair-command.ts +52 -5
  453. package/src/commands/worktree-support.ts +22 -1
  454. package/src/core-commands/add.command.impl.ts +1 -1
  455. package/src/errors/checkout-errors.ts +29 -0
  456. package/src/errors/command-errors.ts +2 -1
  457. package/src/errors/ref-errors.ts +23 -0
  458. package/src/errors/worktree-errors.ts +8 -1
  459. package/src/git-command.ts +98 -3
  460. package/src/git.ts +420 -4
  461. package/src/remote-config/index.ts +4 -0
  462. package/src/remote-config/remote-config-store.ts +238 -11
  463. package/src/rename/detect-renames.ts +5 -1
  464. package/src/results/clone-result.ts +9 -0
  465. package/src/results/combined-diff.ts +38 -18
  466. package/src/results/diff-check.ts +185 -0
  467. package/src/results/diff-color.ts +868 -0
  468. package/src/results/diff-output.ts +204 -37
  469. package/src/results/diff-pickaxe.ts +304 -0
  470. package/src/results/diff-words.ts +395 -0
  471. package/src/results/index.ts +4 -0
  472. package/src/results/init-result.ts +9 -0
  473. package/src/results/pull-result.ts +5 -0
  474. package/src/results/push-result.ts +12 -0
  475. package/src/results/rebase-result.ts +3 -0
  476. package/src/results/stash-result.ts +7 -0
  477. package/src/results/status-result.ts +5 -2
  478. package/src/whitespace/index.ts +1 -0
  479. package/src/{commands/apply/whitespace.ts → whitespace/whitespace-rule.ts} +173 -23
  480. package/dist/commands/apply/whitespace.d.ts +0 -58
  481. package/dist/commands/apply/whitespace.d.ts.map +0 -1
@@ -0,0 +1,1256 @@
1
+ /**
2
+ * `git config` as a library command (builtin/config.c): `get`, `set`, `--add`, `unset`,
3
+ * `--replace-all` / `--unset-all` with value patterns, `rename-section` and
4
+ * `remove-section`, on the repository's file or on one scope's.
5
+ *
6
+ * ```typescript
7
+ * await git.config().set("core.editor", "vim").call();
8
+ * await git.config().add("remote.origin.fetch", "+refs/tags/*:refs/tags/*").call();
9
+ * await git.config().unset("remote.origin.fetch").setValuePattern("tags").call();
10
+ * await git.config().setScope("global").set("user.name", "A U Thor").call();
11
+ * await git.config().renameSection("remote.origin", "remote.upstream").call();
12
+ * const { stdout, exitCode } = await git.config().get("core.bare").call(); // "false\n", 0
13
+ * ```
14
+ *
15
+ * Writes edit the scope's file as git does (`setConfigMultivarInFile`,
16
+ * `renameConfigSectionInFile` of vcs-store-files: under `<file>.lock`, comments, includes and
17
+ * other sections kept byte for byte), and give git's exit status and stderr: 5 for a key to
18
+ * unset that is not there or several values without `setAll`, 1 or 2 for an invalid key, 6
19
+ * for an invalid pattern, 3 for a file whose header git cannot name, 255 for a lock held,
20
+ * 128 where git dies (`no such section`, a bad config line).
21
+ *
22
+ * Reads follow `git config --get`, `--get-all`, `--get-regexp`, `--get-urlmatch`, `--list`,
23
+ * `--get-color` and `--get-colorbool` (and 2.46's `get [--all] [--regexp] [--url=<url>]` and
24
+ * `list`): values canonicalised by {@link ConfigCommand.setType} as builtin/config.c's
25
+ * `format_config` (`--type=bool|int|bool-or-int|bool-or-str|path|expiry-date|color`; `set`
26
+ * writes them as `normalize_value`), `--default`, `--show-origin`, `--show-scope`,
27
+ * `--name-only`, `--show-names`, `-z`, and `--blob=<rev>:<path>`.
28
+ *
29
+ * ```typescript
30
+ * const { stdout } = await git.config().list().setShowOrigin(true).call(); // "file:.git/config\tcore.bare=false\n"
31
+ * await git.config().get("pack.window").setType("int").call(); // "1024\n" for `1k`
32
+ * await git.config().getUrlmatch("http", "https://example.com/repo").call(); // "http.sslverify false\n"
33
+ * await git.config().getRegexp("^remote\\.").setBlob("HEAD:shared.config").call();
34
+ * ```
35
+ */
36
+
37
+ import {
38
+ CONFIG_REGEX_NONE,
39
+ type ConfigFileLocation,
40
+ ConfigParseError,
41
+ type ConfigScope,
42
+ GitWorkingCopyConfig,
43
+ parseConfigKey,
44
+ prepareConfigComment,
45
+ readConfigFileThroughLinks,
46
+ renameConfigSectionInFile,
47
+ setConfigMultivarInFile,
48
+ } from "@statewalker/vcs-store-files";
49
+ import {
50
+ compilePosixRegex,
51
+ isUrlNormalizeError,
52
+ normalizeUrl,
53
+ PosixRegexError,
54
+ selectUrlMatches,
55
+ } from "@statewalker/vcs-utils";
56
+ import { encodeGitPath } from "@statewalker/vcs-utils/encoding";
57
+ import type { FilesApi } from "@statewalker/vcs-utils/files";
58
+ import {
59
+ expandUserPath,
60
+ type GitHostEnvironment,
61
+ xdgConfigPath,
62
+ } from "@statewalker/vcs-working-tree";
63
+ import { GitApiError } from "../errors/index.js";
64
+ import { GitCommand } from "../git-command.js";
65
+ import { quotePath } from "../results/quote-path.js";
66
+ import {
67
+ CONFIG_VALUE_TYPES,
68
+ type ConfigValueContext,
69
+ ConfigValueDeath,
70
+ type ConfigValueSource,
71
+ type ConfigValueType,
72
+ type FormattedConfigValue,
73
+ formatConfigValue,
74
+ gitConfigBool,
75
+ gitConfigColorBool,
76
+ normalizeConfigValue,
77
+ parseGitColor,
78
+ } from "./config-value-types.js";
79
+ import { hostEnvironmentOf } from "./git-ident.js";
80
+
81
+ /** The file `git config` reads or writes: `--local`, `--worktree`, `--global`, `--system`. */
82
+ export type ConfigCommandScope = "local" | "worktree" | "global" | "system";
83
+
84
+ /** What {@link ConfigCommand} did. */
85
+ export interface ConfigCommandResult {
86
+ /** git's exit status */
87
+ exitCode: number;
88
+ /** git's stdout: the values `get` prints, one per line */
89
+ stdout: string;
90
+ /** git's stderr: its `warning:`, `error:` and `fatal:` lines */
91
+ stderr: string;
92
+ /** The values `get` found, in order (undefined for a variable without `=`) */
93
+ values?: (string | undefined)[];
94
+ }
95
+
96
+ type ConfigAction =
97
+ | { kind: "get"; key: string }
98
+ | { kind: "get-regexp"; pattern: string }
99
+ | { kind: "get-urlmatch"; name: string; url: string }
100
+ | { kind: "list" }
101
+ | { kind: "get-color"; slot: string; defaultColor?: string }
102
+ | { kind: "get-colorbool"; slot: string; stdoutIsTty?: string }
103
+ | { kind: "set"; key: string; value: string }
104
+ | { kind: "add"; key: string; value: string }
105
+ | { kind: "unset"; key: string }
106
+ | { kind: "rename-section"; from: string; to: string }
107
+ | { kind: "remove-section"; name: string };
108
+
109
+ /** One value as a query reads it, with where it was read (git's `key_value_info`). */
110
+ interface QueryEntry extends ConfigValueSource {
111
+ /** The canonical key */
112
+ key: string;
113
+ /** The value as written; undefined for a key without `=` */
114
+ text: string | undefined;
115
+ /** The scope of the value (`--show-scope`) */
116
+ scope?: ConfigScope;
117
+ /** Its line in its file or blob */
118
+ line?: number;
119
+ }
120
+
121
+ /** builtin/config.c's display terminators. */
122
+ interface Display {
123
+ term: string;
124
+ keyDelim: string;
125
+ showKeys: boolean;
126
+ omitValues: boolean;
127
+ }
128
+
129
+ /** A refusal of git's: its exit status and its lines. */
130
+ class Refusal {
131
+ constructor(
132
+ readonly exitCode: number,
133
+ readonly lines: string[],
134
+ ) {}
135
+ }
136
+
137
+ const fatal = (message: string) => new Refusal(128, [`fatal: ${message}`]);
138
+
139
+ /**
140
+ * `git config` on one key or section (see the module comment).
141
+ *
142
+ * The action is one of {@link get}, {@link set}, {@link add}, {@link unset},
143
+ * {@link renameSection}, {@link removeSection}. Without {@link setScope} or {@link setFile}
144
+ * writes go to the repository's `config` and `get` reads the whole configuration (system,
145
+ * global, the repository's, `config.worktree`, the command line, includes followed); with one,
146
+ * only that file is read, its includes not followed, as git does.
147
+ *
148
+ * git's two syntaxes differ only in their messages and refusals: the legacy one (`git config
149
+ * <key> <value> [<value-pattern>]`, `--add`, `--replace-all`, `--unset[-all]`,
150
+ * `--rename-section`, `--remove-section`, `--get[-all]`) with {@link setLegacySyntax}, else
151
+ * git 2.46's subcommands (`git config set [--all] [--value=<pattern>] [--append]`,
152
+ * `unset`, `get`, `rename-section`, `remove-section`).
153
+ */
154
+ export class ConfigCommand extends GitCommand<ConfigCommandResult> {
155
+ /** git's command reads no core settings: an unparsable `core.whitespace` does not stop it */
156
+ protected override readsCoreConfig(): boolean {
157
+ return false;
158
+ }
159
+
160
+ private action?: ConfigAction;
161
+ private scope?: ConfigCommandScope;
162
+ private file?: string;
163
+ private all = false;
164
+ private valuePattern?: string;
165
+ private fixedValue = false;
166
+ private comment?: string;
167
+ private defaultValue?: string;
168
+ private legacy = false;
169
+ private type?: ConfigValueType;
170
+ private blob?: string;
171
+ private includes?: boolean;
172
+ private showOrigin = false;
173
+ private showScope = false;
174
+ private nameOnly = false;
175
+ private showNames = false;
176
+ private nullTerminated = false;
177
+ private compatibility: "2.43" | "2.56" = "2.56";
178
+ private dumbTerminal = false;
179
+ /** git's warnings of a read (a file it cannot open), printed before the values */
180
+ private warnings: string[] = [];
181
+
182
+ /** `get <key>` / `--get <key>` (`--get-all` with {@link setAll}). */
183
+ get(key: string): this {
184
+ return this.setAction({ kind: "get", key });
185
+ }
186
+
187
+ /**
188
+ * `set <key> <value>` / `<key> <value>`: the key's value replaced (`--all` /
189
+ * `--replace-all` with {@link setAll}; only values matching {@link setValuePattern}).
190
+ */
191
+ set(key: string, value: string): this {
192
+ return this.setAction({ kind: "set", key, value });
193
+ }
194
+
195
+ /** `set --append <key> <value>` / `--add <key> <value>`: a new line, the old ones kept. */
196
+ add(key: string, value: string): this {
197
+ return this.setAction({ kind: "add", key, value });
198
+ }
199
+
200
+ /** `unset <key>` / `--unset <key>` (`--all` / `--unset-all` with {@link setAll}). */
201
+ unset(key: string): this {
202
+ return this.setAction({ kind: "unset", key });
203
+ }
204
+
205
+ /** `rename-section <old> <new>` / `--rename-section`: `old` as written in its headers. */
206
+ renameSection(from: string, to: string): this {
207
+ return this.setAction({ kind: "rename-section", from, to });
208
+ }
209
+
210
+ /** `remove-section <name>` / `--remove-section`: every section of that name, whole. */
211
+ removeSection(name: string): this {
212
+ return this.setAction({ kind: "remove-section", name });
213
+ }
214
+
215
+ /** `--local`, `--worktree`, `--global`, `--system`: the file read or written. */
216
+ setScope(scope: ConfigCommandScope | undefined): this {
217
+ this.checkCallable();
218
+ this.scope = scope;
219
+ return this;
220
+ }
221
+
222
+ /**
223
+ * `--get-regexp <pattern>` / `get --regexp <pattern>`: the keys matching a POSIX extended
224
+ * regex (its section and last part lowered, as git does). The legacy syntax prints every
225
+ * value with its key; the subcommand only the last value unless {@link setAll}, with its
226
+ * key under {@link setShowNames}.
227
+ */
228
+ getRegexp(pattern: string): this {
229
+ return this.setAction({ kind: "get-regexp", pattern });
230
+ }
231
+
232
+ /**
233
+ * `--get-urlmatch <name> <url>` / `get --url=<url> <name>`: the value of `<section>.<key>`
234
+ * (or, for a bare section, of each of its keys with the key) that best matches the URL
235
+ * among `<section>.<url-pattern>.<key>` entries (urlmatch.c).
236
+ */
237
+ getUrlmatch(name: string, url: string): this {
238
+ return this.setAction({ kind: "get-urlmatch", name, url });
239
+ }
240
+
241
+ /** `--list` / `list`: every value, `key=value` per line. */
242
+ list(): this {
243
+ return this.setAction({ kind: "list" });
244
+ }
245
+
246
+ /**
247
+ * `--get-color <slot> [<default>]`: the escape sequence of the color the slot is set to
248
+ * (the default's when unset), with no newline.
249
+ */
250
+ getColor(slot: string, defaultColor?: string): this {
251
+ return this.setAction({
252
+ kind: "get-color",
253
+ slot,
254
+ ...(defaultColor !== undefined ? { defaultColor } : {}),
255
+ });
256
+ }
257
+
258
+ /**
259
+ * `--get-colorbool <slot> [<stdout-is-tty>]`: whether color is wanted for the slot (falling
260
+ * back to `diff.color` for `color.diff`, then `color.ui`). With `stdoutIsTty` (a boolean as
261
+ * git reads it) git prints `true`/`false`; without, the exit status tells (stdout is no
262
+ * terminal here). `auto` needs a terminal that is not dumb ({@link setDumbTerminal}).
263
+ */
264
+ getColorBool(slot: string, stdoutIsTty?: string): this {
265
+ return this.setAction({
266
+ kind: "get-colorbool",
267
+ slot,
268
+ ...(stdoutIsTty !== undefined ? { stdoutIsTty } : {}),
269
+ });
270
+ }
271
+
272
+ /**
273
+ * `--type=<type>` (`--bool`, `--int`, `--bool-or-int`, `--bool-or-str`, `--path`,
274
+ * `--expiry-date`, `--type=color`): values printed canonical, and written canonical by
275
+ * `set`/`add`. A name git does not know is refused when the command runs (git's
276
+ * `unrecognized --type argument`).
277
+ */
278
+ setType(type: ConfigValueType | string | undefined): this {
279
+ this.checkCallable();
280
+ this.type = type as ConfigValueType | undefined;
281
+ return this;
282
+ }
283
+
284
+ /** `--blob=<blob-ish>`: read the configuration from a blob (`HEAD:shared.config`). */
285
+ setBlob(blob: string | undefined): this {
286
+ this.checkCallable();
287
+ this.blob = blob;
288
+ return this;
289
+ }
290
+
291
+ /**
292
+ * `--includes` / `--no-includes` for a file read with {@link setScope} or {@link setFile}
293
+ * (default off there, as git; the whole configuration always follows them).
294
+ */
295
+ setIncludes(includes: boolean | undefined): this {
296
+ this.checkCallable();
297
+ this.includes = includes;
298
+ return this;
299
+ }
300
+
301
+ /** `--show-origin`: each value after `file:<name>`, `blob:<name>` or `command line:`. */
302
+ setShowOrigin(show: boolean): this {
303
+ this.checkCallable();
304
+ this.showOrigin = show;
305
+ return this;
306
+ }
307
+
308
+ /** `--show-scope`: each value after its scope (`local`, `global`, `command`, ...). */
309
+ setShowScope(show: boolean): this {
310
+ this.checkCallable();
311
+ this.showScope = show;
312
+ return this;
313
+ }
314
+
315
+ /** `--name-only`: keys without their values (`--list`, `--get-regexp`). */
316
+ setNameOnly(nameOnly: boolean): this {
317
+ this.checkCallable();
318
+ this.nameOnly = nameOnly;
319
+ return this;
320
+ }
321
+
322
+ /** `--show-names` (2.46's `get`): each value after its key. */
323
+ setShowNames(show: boolean): this {
324
+ this.checkCallable();
325
+ this.showNames = show;
326
+ return this;
327
+ }
328
+
329
+ /** `-z` / `--null`: values end with NUL, a key and its value separated by a newline. */
330
+ setNullTerminated(nul: boolean): this {
331
+ this.checkCallable();
332
+ this.nullTerminated = nul;
333
+ return this;
334
+ }
335
+
336
+ /**
337
+ * The git version whose behaviour applies where they differ (default 2.56): 2.43's `--list`
338
+ * ignores `--type`, knows no `:(optional)` paths nor `#rgb` colors, and dies on a
339
+ * `--get-color` default it cannot parse (2.5x: an error, exit 255).
340
+ */
341
+ setCompatibility(version: "2.43" | "2.56"): this {
342
+ this.checkCallable();
343
+ this.compatibility = version;
344
+ return this;
345
+ }
346
+
347
+ /** Whether the terminal is dumb (`TERM` unset or `dumb`): `--get-colorbool`'s `auto`. */
348
+ setDumbTerminal(dumb: boolean): this {
349
+ this.checkCallable();
350
+ this.dumbTerminal = dumb;
351
+ return this;
352
+ }
353
+
354
+ /**
355
+ * `--file <path>`: an absolute host path (written through the host environment's
356
+ * `hostFilesOf`), or a path relative to the worktree top.
357
+ */
358
+ setFile(path: string | undefined): this {
359
+ this.checkCallable();
360
+ this.file = path;
361
+ return this;
362
+ }
363
+
364
+ /** `--all` (`--get-all`, `--replace-all`, `--unset-all`): every value matching. */
365
+ setAll(all: boolean): this {
366
+ this.checkCallable();
367
+ this.all = all;
368
+ return this;
369
+ }
370
+
371
+ /**
372
+ * `--value=<pattern>` / the legacy positional `<value-pattern>`: only the values matching it
373
+ * (a POSIX extended regex, `!` first to invert, or the string with {@link setFixedValue}).
374
+ */
375
+ setValuePattern(pattern: string | undefined): this {
376
+ this.checkCallable();
377
+ this.valuePattern = pattern;
378
+ return this;
379
+ }
380
+
381
+ /** `--fixed-value`: the value pattern is compared as a string. */
382
+ setFixedValue(fixed: boolean): this {
383
+ this.checkCallable();
384
+ this.fixedValue = fixed;
385
+ return this;
386
+ }
387
+
388
+ /** `--comment <text>`: written after the value set or added. */
389
+ setComment(comment: string | undefined): this {
390
+ this.checkCallable();
391
+ this.comment = comment;
392
+ return this;
393
+ }
394
+
395
+ /** `--default <value>`: what `get` prints when the key has no value. */
396
+ setDefault(value: string | undefined): this {
397
+ this.checkCallable();
398
+ this.defaultValue = value;
399
+ return this;
400
+ }
401
+
402
+ /** git's legacy option syntax (`--add`, `--unset-all`, ...): its messages and refusals. */
403
+ setLegacySyntax(legacy: boolean): this {
404
+ this.checkCallable();
405
+ this.legacy = legacy;
406
+ return this;
407
+ }
408
+
409
+ private setAction(action: ConfigAction): this {
410
+ this.checkCallable();
411
+ this.action = action;
412
+ return this;
413
+ }
414
+
415
+ async call(): Promise<ConfigCommandResult> {
416
+ this.checkCallable();
417
+ this.setCallable(false);
418
+ const action = this.action;
419
+ if (!action) throw new GitApiError("error: no action specified", { exitCode: 129 });
420
+ try {
421
+ return await this.run(action);
422
+ } catch (error) {
423
+ if (error instanceof Refusal) return result(error.exitCode, error.lines);
424
+ throw error;
425
+ }
426
+ }
427
+
428
+ private async run(action: ConfigAction): Promise<ConfigCommandResult> {
429
+ if (this.type !== undefined && !CONFIG_VALUE_TYPES.includes(this.type)) {
430
+ throw fatal(`unrecognized --type argument, ${this.type}`);
431
+ }
432
+ const sources =
433
+ (this.scope !== undefined ? 1 : 0) +
434
+ (this.file !== undefined ? 1 : 0) +
435
+ (this.blob !== undefined ? 1 : 0);
436
+ if (sources > 1) throw new Refusal(129, ["error: only one config file at a time"]);
437
+ this.checkOptions(action);
438
+ const comment = this.comment === undefined ? undefined : prepared(this.comment);
439
+ switch (action.kind) {
440
+ case "get":
441
+ // cmd_config_get: `get --type=color --default=<color> ""` is `--get-color "" <color>`
442
+ if (
443
+ !this.legacy &&
444
+ this.type === "color" &&
445
+ action.key === "" &&
446
+ this.defaultValue !== undefined
447
+ ) {
448
+ return this.runGetColor("", this.defaultValue);
449
+ }
450
+ return this.runGet(action.key, false);
451
+ case "get-regexp":
452
+ return this.runGet(action.pattern, true);
453
+ case "list":
454
+ return this.runList();
455
+ case "get-urlmatch":
456
+ return this.runUrlmatch(action.name, action.url);
457
+ case "get-color":
458
+ return this.runGetColor(action.slot, action.defaultColor);
459
+ case "get-colorbool":
460
+ return this.runGetColorBool(action.slot, action.stdoutIsTty);
461
+ }
462
+ if (this.blob !== undefined) throw fatal("writing config blobs is not supported");
463
+ const location = await this.location();
464
+ let outcome: { status: number; stderr: string[] };
465
+ switch (action.kind) {
466
+ case "set":
467
+ case "add": {
468
+ const pattern =
469
+ action.kind === "add" ? CONFIG_REGEX_NONE : (this.valuePattern ?? undefined);
470
+ const value = this.normalized(action.key, action.value);
471
+ outcome = await setConfigMultivarInFile(location, action.key, value, {
472
+ ...(pattern !== undefined ? { valuePattern: pattern } : {}),
473
+ fixedValue: this.fixedValue,
474
+ multiReplace: action.kind === "set" && this.all,
475
+ ...(comment !== undefined ? { comment } : {}),
476
+ });
477
+ if (
478
+ outcome.status === 5 &&
479
+ action.kind === "set" &&
480
+ !this.all &&
481
+ this.valuePattern === undefined
482
+ ) {
483
+ outcome.stderr.push(
484
+ "error: cannot overwrite multiple values with a single value",
485
+ this.legacy
486
+ ? ` Use a regexp, --add or --replace-all to change ${action.key}.`
487
+ : ` Use --value=<pattern>, --append or --all to change ${action.key}.`,
488
+ );
489
+ }
490
+ break;
491
+ }
492
+ case "unset":
493
+ outcome = await setConfigMultivarInFile(location, action.key, undefined, {
494
+ ...(this.valuePattern !== undefined ? { valuePattern: this.valuePattern } : {}),
495
+ fixedValue: this.fixedValue,
496
+ multiReplace: this.all,
497
+ });
498
+ break;
499
+ case "rename-section":
500
+ case "remove-section": {
501
+ const from = action.kind === "rename-section" ? action.from : action.name;
502
+ const renamed = await renameConfigSectionInFile(
503
+ location,
504
+ from,
505
+ action.kind === "rename-section" ? action.to : undefined,
506
+ );
507
+ if (renamed.count < 0) outcome = { status: 255, stderr: renamed.stderr };
508
+ else if (renamed.count === 0) {
509
+ outcome = { status: 128, stderr: [...renamed.stderr, `fatal: no such section: ${from}`] };
510
+ } else outcome = { status: 0, stderr: renamed.stderr };
511
+ break;
512
+ }
513
+ }
514
+ if (outcome.status === 0 || action.kind === "rename-section") await this.reloadConfig();
515
+ return result(outcome.status, outcome.stderr);
516
+ }
517
+
518
+ /** builtin/config.c's `normalize_value` of a value to write, or git's death. */
519
+ private normalized(key: string, value: string): string {
520
+ try {
521
+ return normalizeConfigValue(this.type, key, value, this.compatibility);
522
+ } catch (error) {
523
+ if (error instanceof ConfigValueDeath) throw new Refusal(128, error.lines);
524
+ throw error;
525
+ }
526
+ }
527
+
528
+ /** The option checks git makes before it reads or writes anything. */
529
+ private checkOptions(action: ConfigAction): void {
530
+ const hasPattern = this.valuePattern !== undefined;
531
+ const sectionAction = action.kind === "rename-section" || action.kind === "remove-section";
532
+ const reads = new Set([
533
+ "get",
534
+ "get-regexp",
535
+ "get-urlmatch",
536
+ "list",
537
+ "get-color",
538
+ "get-colorbool",
539
+ ]);
540
+ if (this.legacy) {
541
+ // cmd_config_actions: the action's argument count, then the option combinations
542
+ if (
543
+ (action.kind === "get-color" || action.kind === "get-colorbool") &&
544
+ this.type !== undefined
545
+ ) {
546
+ throw new Refusal(129, ["error: --get-color and variable type are incoherent"]);
547
+ }
548
+ if (action.kind === "add" && hasPattern) {
549
+ throw new Refusal(129, ["error: wrong number of arguments, should be 2"]);
550
+ }
551
+ if (sectionAction && (hasPattern || this.all)) {
552
+ throw new Refusal(129, ["error: only one action at a time"]);
553
+ }
554
+ if (this.nameOnly && !(action.kind === "list" || action.kind === "get-regexp")) {
555
+ throw new Refusal(129, ["error: --name-only is only applicable to --list or --get-regexp"]);
556
+ }
557
+ if (
558
+ this.showOrigin &&
559
+ !(action.kind === "get" || action.kind === "get-regexp" || action.kind === "list")
560
+ ) {
561
+ throw new Refusal(129, [
562
+ "error: --show-origin is only applicable to --get, --get-all, --get-regexp, and --list",
563
+ ]);
564
+ }
565
+ if (this.defaultValue !== undefined && (action.kind !== "get" || this.all)) {
566
+ throw new Refusal(129, ["error: --default is only applicable to --get"]);
567
+ }
568
+ if (this.comment !== undefined && !(action.kind === "set" || action.kind === "add")) {
569
+ throw new Refusal(129, [
570
+ "error: --comment is only applicable to add/set/replace operations",
571
+ ]);
572
+ }
573
+ if (
574
+ this.fixedValue &&
575
+ (!hasPattern ||
576
+ action.kind === "add" ||
577
+ sectionAction ||
578
+ action.kind === "list" ||
579
+ action.kind === "get-urlmatch" ||
580
+ action.kind === "get-color" ||
581
+ action.kind === "get-colorbool")
582
+ ) {
583
+ throw new Refusal(129, ["error: --fixed-value only applies with 'value-pattern'"]);
584
+ }
585
+ return;
586
+ }
587
+ if (action.kind === "get-color" || action.kind === "get-colorbool") {
588
+ throw new GitApiError(
589
+ "git config has no get-color subcommand: use the legacy syntax (setLegacySyntax)",
590
+ );
591
+ }
592
+ if (sectionAction && (hasPattern || this.all || this.fixedValue)) {
593
+ throw new Refusal(129, [`error: unknown option for ${action.kind}`]);
594
+ }
595
+ if (reads.has(action.kind) && this.comment !== undefined) {
596
+ throw new Refusal(129, ["error: unknown option `comment'"]);
597
+ }
598
+ if (action.kind === "list") {
599
+ if (hasPattern) throw new Refusal(129, ["error: unknown option `value'"]);
600
+ if (this.defaultValue !== undefined) {
601
+ throw new Refusal(129, ["error: unknown option `default'"]);
602
+ }
603
+ return;
604
+ }
605
+ if (this.fixedValue && !hasPattern) {
606
+ throw fatal(
607
+ action.kind === "set" || action.kind === "add"
608
+ ? "--fixed-value only applies with --value=<pattern>"
609
+ : "--fixed-value only applies with 'value-pattern'",
610
+ );
611
+ }
612
+ if (action.kind === "add" && hasPattern) {
613
+ throw fatal("--append cannot be used with --value=<pattern>");
614
+ }
615
+ const getLike =
616
+ action.kind === "get" || action.kind === "get-regexp" || action.kind === "get-urlmatch";
617
+ if (
618
+ getLike &&
619
+ this.defaultValue !== undefined &&
620
+ (this.all || action.kind === "get-urlmatch")
621
+ ) {
622
+ throw fatal("--default= cannot be used with --all or --url=");
623
+ }
624
+ if (action.kind === "get-urlmatch" && (this.all || hasPattern)) {
625
+ throw fatal("--url= cannot be used with --all, --regexp or --value");
626
+ }
627
+ if (!getLike && this.defaultValue !== undefined) {
628
+ throw new Refusal(129, ["error: unknown option `default'"]);
629
+ }
630
+ }
631
+
632
+ /** The display options as builtin/config.c's `display_options_init` sets them. */
633
+ private display(list: boolean): Display {
634
+ const nul = this.nullTerminated;
635
+ return {
636
+ term: nul ? "\0" : "\n",
637
+ keyDelim: nul ? "\n" : list ? "=" : " ",
638
+ showKeys: list,
639
+ omitValues: this.nameOnly,
640
+ };
641
+ }
642
+
643
+ /** What a value's formatting needs from the host. */
644
+ private valueContext(): ConfigValueContext {
645
+ const environment = hostEnvironmentOf(this.workingCopy);
646
+ return {
647
+ compatibility: this.compatibility,
648
+ home: environment?.home,
649
+ now: this.clock(),
650
+ userHome: async (name) => environment?.expandUserHome?.(name),
651
+ isMissing: async (path) => {
652
+ try {
653
+ if (path.startsWith("/")) {
654
+ if (environment?.statFile) return (await environment.statFile(path)) === undefined;
655
+ return (await environment?.readFile(path)) === undefined;
656
+ }
657
+ const worktree = this.worktreeAccess;
658
+ const files = worktree?.getFiles?.();
659
+ if (!worktree || !files) return true;
660
+ const root = worktree.getRoot().replace(/\/+$/, "");
661
+ return (await files.stats(root ? `${root}/${path}` : path)) === undefined;
662
+ } catch {
663
+ return true;
664
+ }
665
+ },
666
+ };
667
+ }
668
+
669
+ /**
670
+ * builtin/config.c's `format_config`: scope, origin, key and the value as typed, ended
671
+ * with the terminator; a death of git's thrown as a {@link Refusal}.
672
+ */
673
+ private async format(
674
+ display: Display,
675
+ entry: QueryEntry,
676
+ key: string,
677
+ gently: boolean,
678
+ typed = true,
679
+ ): Promise<{ text: string } | { skip: true } | { error: string[]; partial: string }> {
680
+ const sep = this.nullTerminated ? "\0" : "\t";
681
+ let text = "";
682
+ if (this.showScope) text += `${entry.scope ?? "unknown"}${sep}`;
683
+ if (this.showOrigin) {
684
+ text += `${entry.origin}:${this.nullTerminated ? entry.name : quotePath(entry.name)}${sep}`;
685
+ }
686
+ if (display.showKeys) text += key;
687
+ if (!display.omitValues) {
688
+ if (display.showKeys) text += display.keyDelim;
689
+ if (this.type === undefined || !typed) {
690
+ if (entry.text !== undefined) text += entry.text;
691
+ else if (display.showKeys) text = text.slice(0, -display.keyDelim.length);
692
+ } else {
693
+ let formatted: FormattedConfigValue;
694
+ try {
695
+ formatted = await formatConfigValue(
696
+ this.type,
697
+ key,
698
+ entry.text,
699
+ entry,
700
+ this.valueContext(),
701
+ gently,
702
+ );
703
+ } catch (error) {
704
+ if (error instanceof ConfigValueDeath) throw new Refusal(128, error.lines);
705
+ throw error;
706
+ }
707
+ if ("skip" in formatted) return formatted;
708
+ if ("error" in formatted) return { error: formatted.error, partial: text };
709
+ text += formatted.ok;
710
+ }
711
+ }
712
+ return { text: text + display.term };
713
+ }
714
+
715
+ /**
716
+ * A value that failed to format while git read the configuration: the read stops with git's
717
+ * `bad config line` (or the command line's) death after the formatter's error.
718
+ */
719
+ private configReadDeath(entry: QueryEntry, lines: string[]): Refusal {
720
+ const where =
721
+ entry.origin === "command line"
722
+ ? "fatal: unable to parse command-line config"
723
+ : entry.origin === "blob"
724
+ ? `fatal: bad config line ${entry.line ?? 0} in blob ${entry.name}`
725
+ : entry.origin === "file"
726
+ ? `fatal: bad config line ${entry.line ?? 0} in file ${entry.name}`
727
+ : `fatal: bad config line ${entry.line ?? 0} in ${entry.name}`;
728
+ return new Refusal(128, [...this.warnings, ...lines, where]);
729
+ }
730
+
731
+ /** `get` / `--get[-all]` / `--get-regexp`: builtin/config.c's `get_value`. */
732
+ private async runGet(name: string, keyRegexp: boolean): Promise<ConfigCommandResult> {
733
+ let matchKey: (key: string) => boolean;
734
+ if (keyRegexp) {
735
+ // git lowers the section (up to the first dot) and the part after the last dot
736
+ const lastDot = name.lastIndexOf(".");
737
+ const firstDot = name.indexOf(".");
738
+ let lowered = name;
739
+ if (lastDot < 0) lowered = name.toLowerCase();
740
+ else {
741
+ lowered =
742
+ name.slice(0, firstDot).toLowerCase() +
743
+ name.slice(firstDot, lastDot + 1) +
744
+ name.slice(lastDot + 1).toLowerCase();
745
+ }
746
+ let regex: ReturnType<typeof compilePosixRegex>;
747
+ try {
748
+ regex = compilePosixRegex(encodeGitPath(lowered), { extended: true });
749
+ } catch (error) {
750
+ if (!(error instanceof PosixRegexError)) throw error;
751
+ return result(6, [`error: invalid key pattern: ${name}`]);
752
+ }
753
+ matchKey = (key) => regex.test(encodeGitPath(key));
754
+ } else {
755
+ const parsed = parseConfigKey(name);
756
+ if ("status" in parsed) return result(1, [`error: ${parsed.error}`]);
757
+ matchKey = (key) => key === parsed.key;
758
+ }
759
+ let matcher: ((value: string | undefined) => boolean) | undefined;
760
+ const pattern = this.valuePattern;
761
+ if (pattern !== undefined && this.fixedValue) {
762
+ matcher = (value) => pattern === (value ?? "");
763
+ } else if (pattern !== undefined) {
764
+ const invert = pattern.startsWith("!");
765
+ const source = invert ? pattern.slice(1) : pattern;
766
+ let regex: ReturnType<typeof compilePosixRegex>;
767
+ try {
768
+ regex = compilePosixRegex(encodeGitPath(source), { extended: true });
769
+ } catch (error) {
770
+ if (!(error instanceof PosixRegexError)) throw error;
771
+ return result(6, [`error: invalid pattern: ${source}`]);
772
+ }
773
+ matcher = (value) => invert !== regex.test(encodeGitPath(value ?? ""));
774
+ }
775
+ const entries = await this.readEntries(false);
776
+ const display = this.display(false);
777
+ const all = keyRegexp && this.legacy ? true : this.all;
778
+ display.showKeys = keyRegexp && this.legacy ? true : this.showNames;
779
+ const matched = entries.filter((e) => matchKey(e.key) && (!matcher || matcher(e.text)));
780
+ const shown: string[] = [];
781
+ const values: (string | undefined)[] = [];
782
+ for (const entry of matched) {
783
+ const formatted = await this.format(display, entry, entry.key, false);
784
+ if ("error" in formatted) throw this.configReadDeath(entry, formatted.error);
785
+ if ("skip" in formatted) continue;
786
+ shown.push(formatted.text);
787
+ values.push(entry.text);
788
+ }
789
+ if (shown.length === 0 && this.defaultValue !== undefined) {
790
+ const param: QueryEntry = {
791
+ key: name,
792
+ text: this.defaultValue,
793
+ origin: "command line",
794
+ name: "",
795
+ scope: "command",
796
+ };
797
+ const formatted = await this.format(display, param, name, false);
798
+ if ("error" in formatted) {
799
+ throw new Refusal(128, [
800
+ ...this.warnings,
801
+ ...formatted.error,
802
+ `fatal: failed to format default config value: ${this.defaultValue}`,
803
+ ]);
804
+ }
805
+ if ("text" in formatted) {
806
+ return {
807
+ ...result(0, this.warnings),
808
+ stdout: formatted.text,
809
+ values: [this.defaultValue],
810
+ };
811
+ }
812
+ }
813
+ const printed = all ? shown : shown.slice(-1);
814
+ return {
815
+ ...result(shown.length > 0 ? 0 : 1, this.warnings),
816
+ stdout: printed.join(""),
817
+ values,
818
+ };
819
+ }
820
+
821
+ /** `list` / `--list`: builtin/config.c's `show_all_config` over the whole read. */
822
+ private async runList(): Promise<ConfigCommandResult> {
823
+ const entries = await this.readEntries(true);
824
+ const display = this.display(true);
825
+ const errors: string[] = [];
826
+ let stdout = "";
827
+ for (const entry of entries) {
828
+ // 2.43 prints values as written whatever the type; 2.5x drops those it cannot format
829
+ const formatted = await this.format(
830
+ display,
831
+ entry,
832
+ entry.key,
833
+ true,
834
+ this.compatibility !== "2.43",
835
+ );
836
+ if ("text" in formatted) stdout += formatted.text;
837
+ else if ("error" in formatted) errors.push(...formatted.error);
838
+ }
839
+ return { ...result(0, [...this.warnings, ...errors]), stdout };
840
+ }
841
+
842
+ /** `--get-urlmatch` / `get --url=`: builtin/config.c's `get_urlmatch`. */
843
+ private async runUrlmatch(name: string, url: string): Promise<ConfigCommandResult> {
844
+ const normalized = normalizeUrl(url);
845
+ if (isUrlNormalizeError(normalized)) throw fatal(normalized.error);
846
+ const lowered = name.toLowerCase();
847
+ const dot = lowered.indexOf(".");
848
+ const section = dot < 0 ? lowered : lowered.slice(0, dot);
849
+ const key = dot < 0 ? undefined : lowered.slice(dot + 1);
850
+ const entries = await this.readEntries(false);
851
+ const chosen = selectUrlMatches(entries, section, normalized, key);
852
+ const display = this.display(false);
853
+ display.showKeys = key === undefined;
854
+ display.omitValues = false;
855
+ let stdout = "";
856
+ const errors: string[] = [];
857
+ for (const [synthetic, entry] of chosen) {
858
+ const formatted = await this.format(display, entry, synthetic, false);
859
+ if ("text" in formatted) stdout += formatted.text;
860
+ else if ("error" in formatted) {
861
+ errors.push(...formatted.error);
862
+ // 2.43 writes what it formatted before the failure, unterminated
863
+ if (this.compatibility === "2.43") stdout += formatted.partial;
864
+ }
865
+ }
866
+ return { ...result(chosen.size > 0 ? 0 : 1, [...this.warnings, ...errors]), stdout };
867
+ }
868
+
869
+ /** `--get-color`: builtin/config.c's `get_color`. */
870
+ private async runGetColor(
871
+ slot: string,
872
+ defaultColor: string | undefined,
873
+ ): Promise<ConfigCommandResult> {
874
+ const entries = await this.readEntries(false);
875
+ let parsed = "";
876
+ let found = false;
877
+ for (const entry of entries) {
878
+ if (entry.key !== slot) continue;
879
+ const lines = entry.text === undefined ? [`error: missing value for '${slot}'`] : [];
880
+ const color =
881
+ entry.text === undefined ? undefined : parseGitColor(entry.text, this.compatibility);
882
+ if (color === undefined) {
883
+ throw this.configReadDeath(entry, [
884
+ ...lines,
885
+ `error: invalid color value: ${entry.text ?? ""}`,
886
+ ]);
887
+ }
888
+ parsed = color;
889
+ found = true;
890
+ }
891
+ if (!found && defaultColor !== undefined) {
892
+ const color = parseGitColor(defaultColor, this.compatibility);
893
+ if (color === undefined) {
894
+ const invalid = `error: invalid color value: ${defaultColor}`;
895
+ if (this.compatibility === "2.43") {
896
+ throw new Refusal(128, [invalid, "fatal: unable to parse default color value"]);
897
+ }
898
+ return result(255, [
899
+ ...this.warnings,
900
+ invalid,
901
+ "error: unable to parse default color value",
902
+ ]);
903
+ }
904
+ parsed = color;
905
+ }
906
+ return { ...result(0, this.warnings), stdout: parsed };
907
+ }
908
+
909
+ /** `--get-colorbool`: builtin/config.c's `get_colorbool`. */
910
+ private async runGetColorBool(
911
+ slot: string,
912
+ stdoutIsTty: string | undefined,
913
+ ): Promise<ConfigCommandResult> {
914
+ let tty = false;
915
+ try {
916
+ if (stdoutIsTty !== undefined) tty = gitConfigBool("command line", stdoutIsTty);
917
+ const entries = await this.readEntries(false);
918
+ let found: "never" | "always" | "auto" | undefined;
919
+ let diff: typeof found;
920
+ let ui: typeof found;
921
+ for (const entry of entries) {
922
+ if (entry.key === slot) found = gitConfigColorBool(entry.key, entry.text);
923
+ else if (entry.key === "diff.color") diff = gitConfigColorBool(entry.key, entry.text);
924
+ else if (entry.key === "color.ui") ui = gitConfigColorBool(entry.key, entry.text);
925
+ }
926
+ if (found === undefined) {
927
+ if (slot === "color.diff") found = diff;
928
+ if (found === undefined) found = ui;
929
+ }
930
+ const wanted = (found ?? "auto") === "auto" ? tty && !this.dumbTerminal : found === "always";
931
+ if (stdoutIsTty !== undefined) {
932
+ return { ...result(0, this.warnings), stdout: wanted ? "true\n" : "false\n" };
933
+ }
934
+ return result(wanted ? 0 : 1, this.warnings);
935
+ } catch (error) {
936
+ if (error instanceof ConfigValueDeath)
937
+ throw new Refusal(128, [...this.warnings, ...error.lines]);
938
+ throw error;
939
+ }
940
+ }
941
+
942
+ /**
943
+ * The entries read, in git's order: of the blob, of the scope's file or `--file`, or of the
944
+ * whole configuration. A source `list` cannot read is git's death there; `get` reads it as
945
+ * empty.
946
+ */
947
+ private async readEntries(list: boolean): Promise<QueryEntry[]> {
948
+ if (this.blob !== undefined) return this.readBlobEntries(list);
949
+ if (this.scope === undefined && this.file === undefined) {
950
+ const config = this.workingCopy.config as GitWorkingCopyConfig | undefined;
951
+ if (!config) return [];
952
+ if (typeof config.listWithOrigin !== "function") return plainConfigEntries(config);
953
+ return config.listWithOrigin().map((e) => ({
954
+ key: e.key,
955
+ text: e.text,
956
+ origin: e.file !== undefined ? "file" : e.scope === "command" ? "command line" : "",
957
+ name: e.file ?? "",
958
+ ...(e.scope !== undefined ? { scope: e.scope } : {}),
959
+ ...(e.line !== undefined ? { line: e.line } : {}),
960
+ }));
961
+ }
962
+ const location = await this.location();
963
+ const environment = hostEnvironmentOf(this.workingCopy);
964
+ const scope: ConfigScope =
965
+ this.file !== undefined
966
+ ? "command"
967
+ : this.scope === "global"
968
+ ? "global"
969
+ : this.scope === "system"
970
+ ? "system"
971
+ : "local";
972
+ let failure: string | undefined;
973
+ const reader = new GitWorkingCopyConfig(
974
+ {
975
+ read: async (path) => {
976
+ // read through its links, as git's open; one it cannot open is warned about
977
+ const read = await readConfigFileThroughLinks(location.files, path);
978
+ if (read.kind === "error" || read.kind === "directory") {
979
+ const reason = read.kind === "error" ? read.reason : "Is a directory";
980
+ if (path === location.path) {
981
+ this.warnings.push(`warning: unable to access '${location.name}': ${reason}`);
982
+ failure = reason;
983
+ }
984
+ return undefined;
985
+ }
986
+ if (read.kind === "absent" && path === location.path) {
987
+ failure = "No such file or directory";
988
+ }
989
+ return read.kind === "file" ? read.bytes : undefined;
990
+ },
991
+ write: async () => {
992
+ throw new Error("read only");
993
+ },
994
+ },
995
+ location.path,
996
+ {
997
+ includes: this.includes ?? false,
998
+ fileOnly: true,
999
+ ...(environment ? { environment } : {}),
1000
+ },
1001
+ );
1002
+ try {
1003
+ await reader.load();
1004
+ } catch (error) {
1005
+ if (error instanceof ConfigParseError) {
1006
+ throw fatal(`bad config line ${error.line} in file ${location.name}`);
1007
+ }
1008
+ throw error;
1009
+ }
1010
+ if (failure !== undefined && list) {
1011
+ throw new Refusal(128, [
1012
+ ...this.warnings,
1013
+ `fatal: unable to read config file '${location.name}': ${failure}`,
1014
+ ]);
1015
+ }
1016
+ // the file alone: not the `config.worktree` its `extensions.worktreeConfig` would add
1017
+ return reader
1018
+ .listWithOrigin()
1019
+ .filter((e) => e.scope !== "worktree")
1020
+ .map((e) => {
1021
+ const bare = (path: string) => path.replace(/^\/+/, "");
1022
+ const own = e.file === undefined || bare(e.file) === bare(location.path);
1023
+ return {
1024
+ key: e.key,
1025
+ text: e.text,
1026
+ origin: "file",
1027
+ name: own
1028
+ ? scope === "local"
1029
+ ? bare(location.name)
1030
+ : location.name
1031
+ : (e.file as string),
1032
+ scope,
1033
+ ...(e.line !== undefined ? { line: e.line } : {}),
1034
+ };
1035
+ });
1036
+ }
1037
+
1038
+ /** `--blob=<blob-ish>`: git's `git_config_from_blob_ref`. */
1039
+ private async readBlobEntries(list: boolean): Promise<QueryEntry[]> {
1040
+ const name = this.blob as string;
1041
+ const refuse = (line: string): QueryEntry[] => {
1042
+ if (list) throw new Refusal(128, [line, "fatal: error processing config file(s)"]);
1043
+ this.warnings.push(line);
1044
+ return [];
1045
+ };
1046
+ let id: string | undefined;
1047
+ try {
1048
+ id = await this.revisionResolver().resolve(name);
1049
+ } catch {
1050
+ id = undefined;
1051
+ }
1052
+ if (id === undefined) return refuse(`error: unable to resolve config blob '${name}'`);
1053
+ const bytes =
1054
+ (await this.revisionResolver().objectType(id)) === "blob"
1055
+ ? await this.readBlob(id)
1056
+ : undefined;
1057
+ if (bytes === undefined) return refuse(`error: reference '${name}' does not point to a blob`);
1058
+ const reader = new GitWorkingCopyConfig(
1059
+ {
1060
+ read: async () => bytes,
1061
+ write: async () => {
1062
+ throw new Error("read only");
1063
+ },
1064
+ },
1065
+ "blob",
1066
+ // the blob alone: its own `extensions.worktreeConfig` adds no `config.worktree`
1067
+ { includes: false, fileOnly: true },
1068
+ );
1069
+ try {
1070
+ await reader.load();
1071
+ } catch (error) {
1072
+ if (error instanceof ConfigParseError) {
1073
+ return refuse(`error: bad config line ${error.line} in blob ${name}`);
1074
+ }
1075
+ throw error;
1076
+ }
1077
+ return reader.listWithOrigin().map((e) => ({
1078
+ key: e.key,
1079
+ text: e.text,
1080
+ origin: "blob",
1081
+ name,
1082
+ scope: "command",
1083
+ ...(e.line !== undefined ? { line: e.line } : {}),
1084
+ }));
1085
+ }
1086
+
1087
+ /** A blob's bytes. */
1088
+ private async readBlob(id: string): Promise<Uint8Array | undefined> {
1089
+ const content = await this.blobs.load(id);
1090
+ if (!content) return undefined;
1091
+ const chunks: Uint8Array[] = [];
1092
+ let size = 0;
1093
+ for await (const c of content) {
1094
+ chunks.push(c);
1095
+ size += c.length;
1096
+ }
1097
+ const out = new Uint8Array(size);
1098
+ let at = 0;
1099
+ for (const c of chunks) {
1100
+ out.set(c, at);
1101
+ at += c.length;
1102
+ }
1103
+ return out;
1104
+ }
1105
+
1106
+ /** The working copy's configuration, read again after a write (git's `repo_config_clear`). */
1107
+ private async reloadConfig(): Promise<void> {
1108
+ const config = this.workingCopy.config as { load?: () => Promise<void> } | undefined;
1109
+ if (config instanceof GitWorkingCopyConfig) await config.load();
1110
+ }
1111
+
1112
+ /** git's `location_options_init`: the file the scope names. */
1113
+ private async location(): Promise<ConfigFileLocation> {
1114
+ const environment = hostEnvironmentOf(this.workingCopy);
1115
+ if (this.file !== undefined) return this.fileLocation(this.file, environment);
1116
+ if (this.scope === "global") {
1117
+ const path = await globalConfigPath(environment);
1118
+ if (path === undefined) throw fatal("$HOME not set");
1119
+ return await hostLocation(path, environment);
1120
+ }
1121
+ if (this.scope === "system") {
1122
+ const path = environment?.systemConfig;
1123
+ if (path === undefined) {
1124
+ throw new GitApiError(
1125
+ "cannot use --system: the host environment names no system configuration file",
1126
+ );
1127
+ }
1128
+ return await hostLocation(path, environment);
1129
+ }
1130
+ const config = this.repositoryConfig();
1131
+ let path = config.filePath;
1132
+ if (this.scope === "worktree") {
1133
+ const enabled = config.getLocal("extensions.worktreeConfig");
1134
+ const on = enabled.length > 0 && isTrue(enabled[enabled.length - 1]);
1135
+ if (on) path = config.worktreeFilePath;
1136
+ else if (((await this.workingCopy.worktrees?.list()) ?? []).length > 1) {
1137
+ throw fatal(
1138
+ "--worktree cannot be used with multiple working trees unless the config\n" +
1139
+ 'extension worktreeConfig is enabled. Please read "CONFIGURATION FILE"\n' +
1140
+ 'section in "git help worktree" for details',
1141
+ );
1142
+ }
1143
+ }
1144
+ const files = config.configFiles.storage as FilesApi;
1145
+ return { files, path, name: path };
1146
+ }
1147
+
1148
+ /** The repository's configuration, which must be backed by files to be edited. */
1149
+ private repositoryConfig(): GitWorkingCopyConfig {
1150
+ const config = this.workingCopy.config;
1151
+ if (!(config instanceof GitWorkingCopyConfig) || !config.configFiles.storage) {
1152
+ throw new GitApiError("cannot edit the configuration: it is not stored in files");
1153
+ }
1154
+ return config;
1155
+ }
1156
+
1157
+ /** `--file <path>`: a host path, or one relative to the worktree top. */
1158
+ private async fileLocation(
1159
+ path: string,
1160
+ environment: GitHostEnvironment | undefined,
1161
+ ): Promise<ConfigFileLocation> {
1162
+ if (path.startsWith("/")) return await hostLocation(path, environment);
1163
+ const worktree = this.worktreeAccess;
1164
+ const files = worktree?.getFiles?.();
1165
+ if (!worktree || !files) {
1166
+ throw new GitApiError(`cannot use --file ${path}: there is no worktree to resolve it in`);
1167
+ }
1168
+ const root = worktree.getRoot().replace(/\/+$/, "");
1169
+ return { files, path: root ? `${root}/${path}` : path, name: path };
1170
+ }
1171
+ }
1172
+
1173
+ /**
1174
+ * The entries of a configuration held as a plain object (a `MemoryWorkingCopy`'s): `true`
1175
+ * for a key without a value, an array for several values, anything else as its string.
1176
+ */
1177
+ function plainConfigEntries(config: Record<string, unknown>): QueryEntry[] {
1178
+ const out: QueryEntry[] = [];
1179
+ for (const [name, raw] of Object.entries(config)) {
1180
+ if (typeof raw === "function" || raw === undefined || raw === null) continue;
1181
+ const parsed = parseConfigKey(name);
1182
+ const key = "status" in parsed ? name : parsed.key;
1183
+ for (const v of Array.isArray(raw) ? raw : [raw]) {
1184
+ out.push({
1185
+ key,
1186
+ text: v === true ? undefined : String(v),
1187
+ origin: "",
1188
+ name: "",
1189
+ });
1190
+ }
1191
+ }
1192
+ return out;
1193
+ }
1194
+
1195
+ /** A result of the lines git wrote on stderr. */
1196
+ function result(exitCode: number, lines: string[]): ConfigCommandResult {
1197
+ return {
1198
+ exitCode,
1199
+ stdout: "",
1200
+ stderr: lines.length > 0 ? `${lines.join("\n")}\n` : "",
1201
+ };
1202
+ }
1203
+
1204
+ /** `--comment` as git writes it, or git's death. */
1205
+ function prepared(comment: string): string {
1206
+ try {
1207
+ return prepareConfigComment(comment);
1208
+ } catch (error) {
1209
+ throw fatal((error as Error).message);
1210
+ }
1211
+ }
1212
+
1213
+ /** A host path written through the host environment's storage. */
1214
+ async function hostLocation(
1215
+ path: string,
1216
+ environment: GitHostEnvironment | undefined,
1217
+ ): Promise<ConfigFileLocation> {
1218
+ const host = await environment?.hostFilesOf?.(path);
1219
+ if (!host) {
1220
+ throw new GitApiError(
1221
+ `cannot write ${path}: the host environment gives no access to its files`,
1222
+ );
1223
+ }
1224
+ return { files: host.files, path: host.path, name: path };
1225
+ }
1226
+
1227
+ /**
1228
+ * git's `git_global_config`: `$GIT_CONFIG_GLOBAL`, else `~/.gitconfig` unless it cannot be
1229
+ * read and `$XDG_CONFIG_HOME/git/config` can.
1230
+ */
1231
+ async function globalConfigPath(
1232
+ environment: GitHostEnvironment | undefined,
1233
+ ): Promise<string | undefined> {
1234
+ if (environment?.globalConfig) return environment.globalConfig;
1235
+ const user = expandUserPath("~/.gitconfig", environment);
1236
+ if (user === undefined) return undefined;
1237
+ const xdg = xdgConfigPath(environment, "config");
1238
+ if (
1239
+ xdg !== undefined &&
1240
+ (await environment?.readFile(user)) === undefined &&
1241
+ (await environment?.readFile(xdg)) !== undefined
1242
+ ) {
1243
+ return xdg;
1244
+ }
1245
+ return user;
1246
+ }
1247
+
1248
+ /** git's `git_config_bool` of a value as the configuration gives it. */
1249
+ function isTrue(value: unknown): boolean {
1250
+ if (value === true) return true;
1251
+ if (value === false || value === undefined) return false;
1252
+ const text = String(value).toLowerCase();
1253
+ if (["true", "yes", "on"].includes(text)) return true;
1254
+ const n = Number(text);
1255
+ return text !== "" && Number.isFinite(n) && n !== 0;
1256
+ }