@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,2 @@
1
+ export * from "./grep-command.js";
2
+ export * from "./grep-engine.js";
@@ -8,6 +8,7 @@ import {
8
8
  FileMode,
9
9
  isValidWorktreePath,
10
10
  type ObjectId,
11
+ type WorktreePathOptions,
11
12
  } from "@statewalker/vcs-core";
12
13
  import { compareGitPaths, foldAsciiCase } from "@statewalker/vcs-utils/encoding";
13
14
  import {
@@ -30,6 +31,7 @@ import {
30
31
  wholeSeconds,
31
32
  } from "@statewalker/vcs-working-tree";
32
33
  import { storeWorktreeFile } from "../core-commands/index.js";
34
+ import { strerror } from "./strerror.js";
33
35
 
34
36
  const SURROGATE = /[\ud800-\udfff]/;
35
37
 
@@ -58,6 +60,19 @@ export interface AddToIndexOptions {
58
60
  indexed?: StagingEntry;
59
61
  }
60
62
 
63
+ /**
64
+ * A file `index_path` cannot open (an errno such as EACCES): git's `error_errno` of its
65
+ * `open`, then add_to_index's "unable to index file" line. Anything else is rethrown.
66
+ */
67
+ function unreadable(path: string, error: unknown): never {
68
+ const code = (error as { code?: unknown })?.code;
69
+ if (typeof code !== "string" || !/^E[A-Z]+$/.test(code) || code === "ENOENT") throw error;
70
+ throw new AddToIndexError(path, [
71
+ `error: open("${path}"): ${strerror(error)}`,
72
+ `error: unable to index file '${path}'`,
73
+ ]);
74
+ }
75
+
61
76
  /** A path `add_to_index` cannot add: git's error lines (`fatal: adding files failed` follows). */
62
77
  export class AddToIndexError extends Error {
63
78
  constructor(
@@ -184,13 +199,29 @@ export async function chmodIndexEntries(
184
199
  staging: Staging,
185
200
  flip: "+" | "-",
186
201
  matches: (entry: StagingEntry) => boolean,
187
- options: { pretend?: boolean } = {},
202
+ /**
203
+ * `includeSkipWorktree`: skip-worktree entries too (`git add --sparse --chmod`);
204
+ * `collapsed`: sparse directories git holds as one entry each (`out/`), refused as any
205
+ * entry that is no regular file when matched
206
+ */
207
+ options: { pretend?: boolean; includeSkipWorktree?: boolean; collapsed?: readonly string[] } = {},
188
208
  ): Promise<string[]> {
189
209
  const errors: string[] = [];
190
210
  const editor = staging.createEditor();
191
211
  const touched: string[] = [];
212
+ const collapsed = options.collapsed ?? [];
213
+ let lastDir: string | undefined;
192
214
  for await (const entry of staging.entries()) {
193
- if (entry.skipWorktree || !matches(entry)) continue;
215
+ const dir = collapsed.find((d) => entry.path.startsWith(d));
216
+ if (dir) {
217
+ if (dir !== lastDir) {
218
+ lastDir = dir;
219
+ const dirEntry: StagingEntry = { ...entry, path: dir, mode: FileMode.TREE };
220
+ if (matches(dirEntry)) errors.push(`error: cannot chmod ${flip}x '${dir}'`);
221
+ }
222
+ continue;
223
+ }
224
+ if ((entry.skipWorktree && !options.includeSkipWorktree) || !matches(entry)) continue;
194
225
  if ((entry.mode & 0o170000) !== 0o100000) {
195
226
  errors.push(`error: cannot chmod ${flip}x '${entry.path}'`);
196
227
  continue;
@@ -261,6 +292,8 @@ export class IndexAdder {
261
292
  private readonly trust: WorktreeModeTrust,
262
293
  /** git's `ADD_CACHE_PRETEND` (`add --dry-run`): nothing is written or edited */
263
294
  private readonly pretend: boolean,
295
+ /** `verify_path`'s rules (`core.protectNTFS`, `core.protectHFS`; default both on) */
296
+ private readonly pathRules: WorktreePathOptions = {},
264
297
  ) {
265
298
  this.editor = staging.createEditor();
266
299
  this.indexTime = staging.getUpdateTime();
@@ -274,9 +307,15 @@ export class IndexAdder {
274
307
  staging: Staging,
275
308
  blobs: Blobs,
276
309
  trust: WorktreeModeTrust,
277
- options: { pretend?: boolean } = {},
310
+ options: { pretend?: boolean; pathRules?: WorktreePathOptions } = {},
278
311
  ): Promise<IndexAdder> {
279
- const adder = new IndexAdder(staging, blobs, trust, options.pretend === true);
312
+ const adder = new IndexAdder(
313
+ staging,
314
+ blobs,
315
+ trust,
316
+ options.pretend === true,
317
+ options.pathRules,
318
+ );
280
319
  const take = (entry: StagingEntry) => {
281
320
  if (entry.stage === 0) {
282
321
  adder.basePaths.push(entry.path);
@@ -396,7 +435,7 @@ export class IndexAdder {
396
435
  // add_index_entry's verify_path (after the file is hashed; never with ADD_CACHE_PRETEND)
397
436
  if (!this.pretend) {
398
437
  const mode = modeFromWorktree(entry.mode, indexed?.mode, this.trust);
399
- if (!isValidWorktreePath(name, mode)) {
438
+ if (!isValidWorktreePath(name, mode, this.pathRules)) {
400
439
  const shown = options.displayPath ?? path;
401
440
  throw new AddToIndexError(path, [
402
441
  `error: invalid path '${shown}'`,
@@ -412,7 +451,7 @@ export class IndexAdder {
412
451
  await this.storeEmptyBlob();
413
452
  if (indexed) {
414
453
  if (!this.pretend) this.touched.add(name);
415
- return indexed.objectId === EMPTY_BLOB_ID ? "same" : "added";
454
+ return indexed.objectId === this.emptyBlobId ? "same" : "added";
416
455
  }
417
456
  if (this.pretend) return "added";
418
457
  this.resolve(name);
@@ -423,7 +462,7 @@ export class IndexAdder {
423
462
  this.editor.add(
424
463
  new UpdateStagingEntry(
425
464
  name,
426
- EMPTY_BLOB_ID,
465
+ this.emptyBlobId,
427
466
  mode,
428
467
  { size: 0, mtime: 0 },
429
468
  { intentToAdd: true },
@@ -437,7 +476,7 @@ export class IndexAdder {
437
476
  const known = indexed ?? this.unmerged.get(name)?.[0];
438
477
  if (this.pretend) {
439
478
  // git's ADD_CACHE_PRETEND: hashed, never written
440
- const id = await worktree.computeHash(path);
479
+ const id = await worktree.computeHash(path).catch((error) => unreadable(path, error));
441
480
  const mode = modeFromWorktree(entry.mode, known?.mode, this.trust);
442
481
  return indexed && indexed.objectId === id && indexed.mode === mode ? "same" : "added";
443
482
  }
@@ -445,7 +484,7 @@ export class IndexAdder {
445
484
  const stored = await storeWorktreeFile(this.blobs, worktree, path, entry, {
446
485
  onWarning: options.onWarning,
447
486
  ...(options.renormalize ? { renormalize: true } : {}),
448
- });
487
+ }).catch((error) => unreadable(path, error));
449
488
  const mode = modeFromWorktree(stored.entry.mode, known?.mode, this.trust);
450
489
  this.stage(name, stored.id, mode, entryStatOf(stored.entry));
451
490
  return indexed && indexed.objectId === stored.id && indexed.mode === mode ? "same" : "added";
@@ -500,7 +539,7 @@ export class IndexAdder {
500
539
  this.editor.add(
501
540
  new UpdateStagingEntry(
502
541
  path,
503
- EMPTY_BLOB_ID,
542
+ this.emptyBlobId,
504
543
  FileMode.GITLINK,
505
544
  { size: 0, mtime: 0 },
506
545
  { intentToAdd: true },
@@ -542,6 +581,11 @@ export class IndexAdder {
542
581
  }
543
582
 
544
583
  /** git's `set_object_name_for_intent_to_add_entry`: the empty blob written (once). */
584
+ /** The empty blob's id in the repository's format (the id an intent-to-add entry gets) */
585
+ private get emptyBlobId(): ObjectId {
586
+ return this.blobs.objectFormat?.emptyBlobId ?? EMPTY_BLOB_ID;
587
+ }
588
+
545
589
  private async storeEmptyBlob(): Promise<void> {
546
590
  if (this.emptyBlobStored) return;
547
591
  this.emptyBlobStored = true;
@@ -6,24 +6,32 @@ export * from "./backfill-command.js";
6
6
  export * from "./bisect/index.js";
7
7
  export * from "./blame-command.js";
8
8
  export * from "./branch-command.js";
9
+ export * from "./branch-info-command.js";
9
10
  export { TrackMode } from "./branch-tracking.js";
11
+ export * from "./branch-upstream-command.js";
10
12
  export * from "./checkout-command.js";
11
13
  export * from "./checkout-paths.js";
12
14
  export * from "./cherry-pick-command.js";
13
15
  export * from "./clean-command.js";
14
16
  export * from "./clone-command.js";
17
+ export * from "./comment-char-config.js";
15
18
  export * from "./commit-command.js";
19
+ export * from "./config-command.js";
16
20
  export * from "./date-format.js";
21
+ export * from "./default-branch.js";
17
22
  export * from "./describe-command.js";
23
+ export * from "./diff-color-config.js";
18
24
  export * from "./diff-command.js";
19
25
  export * from "./diff-textconv.js";
20
26
  export * from "./fetch-command.js";
27
+ export * from "./fmt-merge-msg-command.js";
21
28
  export * from "./format-patch-command.js";
22
29
  export * from "./fsck/index.js";
23
30
  export * from "./gc-command.js";
24
31
  export * from "./git-describe.js";
25
32
  export * from "./git-hooks.js";
26
33
  export * from "./git-ident.js";
34
+ export * from "./grep/index.js";
27
35
  export * from "./hook-command.js";
28
36
  export {
29
37
  IndexVersionConfigError,
@@ -32,12 +40,14 @@ export {
32
40
  takeIndexWarnings,
33
41
  } from "./index-host.js";
34
42
  export * from "./init-command.js";
43
+ export * from "./interpret-trailers-command.js";
35
44
  export { httpBackendEnv, quarantineEnv, remoteHookSession } from "./local-transport.js";
36
45
  export * from "./log-command.js";
37
46
  export * from "./log-graph.js";
38
47
  export * from "./log-output.js";
39
48
  export * from "./ls-remote-command.js";
40
49
  export * from "./mailmap.js";
50
+ export * from "./merge-base-command.js";
41
51
  export * from "./merge-command.js";
42
52
  export {
43
53
  createMergeDriver,
@@ -71,6 +81,7 @@ export * from "./push-command.js";
71
81
  export * from "./read-tree-command.js";
72
82
  export * from "./rebase-command.js";
73
83
  export * from "./ref-decoration-filter.js";
84
+ export * from "./ref-filter/index.js";
74
85
  export * from "./reflog-command.js";
75
86
  export {
76
87
  committerIdent,
@@ -80,6 +91,7 @@ export {
80
91
  export * from "./remote-command.js";
81
92
  export * from "./reset-command.js";
82
93
  export * from "./restore-command.js";
94
+ export * from "./rev-filter/index.js";
83
95
  export * from "./rev-list-command.js";
84
96
  export * from "./rev-parse-command.js";
85
97
  export * from "./revert-command.js";
@@ -89,19 +101,35 @@ export * from "./revision-resolver.js";
89
101
  export * from "./rm-command.js";
90
102
  export { SequencerOperation } from "./sequencer-pick.js";
91
103
  export * from "./serve-repository.js";
104
+ export * from "./show-command.js";
105
+ export * from "./signature-check.js";
106
+ export * from "./signing.js";
92
107
  export * from "./sparse-checkout-command.js";
108
+ export * from "./ssh-signer.js";
109
+ export * from "./ssh-verifier.js";
93
110
  export * from "./stash-apply-command.js";
111
+ export * from "./stash-branch-command.js";
94
112
  export * from "./stash-create-command.js";
95
113
  export * from "./stash-drop-command.js";
114
+ export * from "./stash-info.js";
96
115
  export * from "./stash-list-command.js";
116
+ export * from "./stash-pop-command.js";
117
+ export * from "./stash-show-command.js";
118
+ export * from "./stash-store-command.js";
97
119
  export * from "./stash-working-tree.js";
98
120
  export * from "./status-command.js";
99
121
  export * from "./status-format.js";
122
+ export * from "./submodule-add-command.js";
123
+ export * from "./submodule-auth.js";
124
+ export * from "./submodule-commands.js";
125
+ export * from "./submodule-model.js";
100
126
  export * from "./submodule-summary.js";
101
127
  export * from "./submodule-summary-command.js";
128
+ export * from "./submodule-update-command.js";
102
129
  export * from "./switch-command.js";
103
130
  export * from "./tag-command.js";
104
131
  export * from "./trailers.js";
132
+ export * from "./verify-command.js";
105
133
  export * from "./worktree-add-command.js";
106
134
  export * from "./worktree-list-command.js";
107
135
  export * from "./worktree-lock-command.js";
@@ -10,10 +10,18 @@ import {
10
10
  createGitFilesHistoryFromFiles,
11
11
  FileStagingStore,
12
12
  probeCaseFolding,
13
+ readProtectedConfig,
14
+ readRepositoryFormat,
13
15
  resolveLinkedGitDir,
14
16
  } from "@statewalker/vcs-store-files";
15
17
  import { MemoryStagingStore } from "@statewalker/vcs-store-mem";
16
- import { decodeGitPath, encodeGitPath } from "@statewalker/vcs-utils";
18
+ import {
19
+ decodeGitPath,
20
+ encodeGitPath,
21
+ type ObjectFormat,
22
+ objectFormatByName,
23
+ SHA1_OBJECT_FORMAT,
24
+ } from "@statewalker/vcs-utils";
17
25
  import {
18
26
  createMemoryCheckout,
19
27
  type GitHostEnvironment,
@@ -24,6 +32,12 @@ import {
24
32
 
25
33
  import { Git } from "../git.js";
26
34
  import type { InitResult } from "../results/init-result.js";
35
+ import {
36
+ defaultInitialBranch,
37
+ defaultRefFormat,
38
+ InvalidInitialBranchError,
39
+ isValidBranchName,
40
+ } from "./default-branch.js";
27
41
 
28
42
  /**
29
43
  * Command to initialize a new Git repository.
@@ -67,13 +81,35 @@ export class InitCommand {
67
81
  private directory?: string;
68
82
  private gitDir?: string;
69
83
  private bare = false;
70
- private initialBranch = "main";
84
+ /** `--initial-branch`; undefined: git's default (see {@link defaultInitialBranch}) */
85
+ private initialBranch?: string;
71
86
  private stagingStore?: Staging;
72
87
  private worktreeEnabled = false;
73
88
  private worktreeStore?: Worktree;
74
89
  private environment?: GitHostEnvironment;
90
+ /** `--object-format`; undefined: `$GIT_DEFAULT_HASH`, `init.defaultObjectFormat`, else sha1 */
91
+ private objectFormatName?: string;
92
+ /** `--ref-format`; undefined: git's default (see {@link defaultRefFormat}) */
93
+ private refFormat?: string;
75
94
  private callable = true;
76
95
 
96
+ /**
97
+ * Set the object format of the new repository (`git init --object-format=<format>`):
98
+ * `sha1` (git's default) or `sha256`. Without it, `$GIT_DEFAULT_HASH`
99
+ * (`GitHostEnvironment.defaultHash`), then `init.defaultObjectFormat` from the system or
100
+ * global configuration (or `git -c`), else SHA-1. A name git does not know fails the call
101
+ * (`UnknownHashAlgorithmError`), and so does re-initialising an existing repository with
102
+ * another format (`ReinitializeHashError`); an existing repository keeps its own otherwise.
103
+ *
104
+ * @param format `sha1` or `sha256`
105
+ * @returns this for method chaining
106
+ */
107
+ setObjectFormat(format: string): this {
108
+ this.checkCallable();
109
+ this.objectFormatName = format;
110
+ return this;
111
+ }
112
+
77
113
  /**
78
114
  * Set the FilesApi implementation for storage.
79
115
  *
@@ -136,8 +172,9 @@ export class InitCommand {
136
172
  /**
137
173
  * Set the initial branch name.
138
174
  *
139
- * This is the branch that HEAD will point to after initialization.
140
- * Defaults to "main".
175
+ * This is the branch that HEAD will point to after initialization. Without it, git's
176
+ * default: `init.defaultBranch` from the system or global configuration (or `git -c`),
177
+ * else `master`, or `main` with `GitHostEnvironment.breakingChanges` (git 3.0).
141
178
  *
142
179
  * @param branch The initial branch name
143
180
  * @returns this for method chaining
@@ -148,6 +185,21 @@ export class InitCommand {
148
185
  return this;
149
186
  }
150
187
 
188
+ /**
189
+ * Set the ref storage format of a new repository (`git init --ref-format`): `files` (loose
190
+ * refs and packed-refs) or `reftable` (`.git/reftable`). Without it, git's default:
191
+ * `$GIT_DEFAULT_REF_FORMAT`, `init.defaultRefFormat`, else `files`, or `reftable` with
192
+ * `GitHostEnvironment.breakingChanges` (git 3.0). An existing repository keeps its format.
193
+ *
194
+ * @param format "files" or "reftable"
195
+ * @returns this for method chaining
196
+ */
197
+ setRefFormat(format: "files" | "reftable" | string): this {
198
+ this.checkCallable();
199
+ this.refFormat = format;
200
+ return this;
201
+ }
202
+
151
203
  /**
152
204
  * Set a custom staging store.
153
205
  *
@@ -243,6 +295,29 @@ export class InitCommand {
243
295
  this.checkCallable();
244
296
  this.setCallable(false);
245
297
 
298
+ // git's -b / init.defaultBranch / built-in default (repo_default_branch_name), worked out
299
+ // only for a repository without HEAD (create_reference_database runs only then): an
300
+ // existing repository keeps its HEAD, ignores -b with a warning and checks no name
301
+ let initialBranch = "";
302
+ let hints: string[] | undefined;
303
+ const warnings: string[] = [];
304
+ const chooseBranch = async () => {
305
+ if (this.initialBranch !== undefined && !isValidBranchName(this.initialBranch)) {
306
+ throw new InvalidInitialBranchError(this.initialBranch);
307
+ }
308
+ const chosen =
309
+ this.initialBranch !== undefined
310
+ ? { name: this.initialBranch }
311
+ : await defaultInitialBranch(this.environment);
312
+ initialBranch = chosen.name;
313
+ hints = chosen.hint;
314
+ };
315
+
316
+ // an explicit --object-format git does not know dies before anything is written
317
+ const explicitFormat =
318
+ this.objectFormatName === undefined ? undefined : knownHashAlgorithm(this.objectFormatName);
319
+ let objectFormat: ObjectFormat = SHA1_OBJECT_FORMAT;
320
+
246
321
  // Use in-memory FilesApi if none provided
247
322
  const files = this.files ?? createInMemoryFilesApi();
248
323
 
@@ -264,12 +339,33 @@ export class InitCommand {
264
339
  // A repository with a config but no HEAD (damaged or half-made) is opened, not
265
340
  // re-created: creating rewrites the config, and its remotes and settings with it.
266
341
  const fresh = !hasHead && !(await isFile(`${dir}/config`));
342
+ if (fresh) {
343
+ objectFormat = explicitFormat ?? (await this.defaultObjectFormat(warnings));
344
+ } else {
345
+ // validate_hash_algorithm: an existing repository keeps its format, and refuses
346
+ // another one asked for explicitly (git 2.5x ignores $GIT_DEFAULT_HASH there)
347
+ objectFormat = (await readRepositoryFormat(repoFiles, dir)).objectFormat;
348
+ if (explicitFormat && explicitFormat.name !== objectFormat.name) {
349
+ throw new ReinitializeHashError();
350
+ }
351
+ }
352
+ if (!hasHead) await chooseBranch();
353
+ else if (this.initialBranch !== undefined) {
354
+ warnings.push(`warning: re-init: ignored --initial-branch=${this.initialBranch}`);
355
+ }
356
+ // the ref storage of a repository created here (an existing one keeps its own)
357
+ const refFormat = fresh
358
+ ? await defaultRefFormat(this.environment, this.refFormat)
359
+ : undefined;
360
+ if (refFormat) warnings.push(...refFormat.warnings);
267
361
  const open = (create: boolean) =>
268
362
  createGitFilesHistoryFromFiles({
269
363
  files: repoFiles,
270
364
  gitDir,
271
365
  create,
272
- defaultBranch: this.initialBranch,
366
+ defaultBranch: initialBranch,
367
+ ...(create ? { objectFormat } : {}),
368
+ ...(create && refFormat ? { refFormat: refFormat.format } : {}),
273
369
  ...(this.environment ? { environment: this.environment } : {}),
274
370
  });
275
371
  if (fresh && this.bare && dir !== ".") {
@@ -282,6 +378,14 @@ export class InitCommand {
282
378
  history = await open(fresh);
283
379
  }
284
380
  await history.initialize();
381
+ if (hasHead) {
382
+ // the branch an existing repository's HEAD names (empty when detached)
383
+ const head = await history.refs.get("HEAD");
384
+ initialBranch =
385
+ head && "target" in head && head.target.startsWith("refs/heads/")
386
+ ? head.target.slice("refs/heads/".length)
387
+ : "";
388
+ }
285
389
  if (fresh) {
286
390
  // git init's probe: a filesystem that folds case or Unicode composition
287
391
  const folding = await probeCaseFolding(repoFiles as PosixFilesApi, dir);
@@ -292,7 +396,7 @@ export class InitCommand {
292
396
  }
293
397
  }
294
398
  if (!hasHead && !fresh) {
295
- await history.refs.setSymbolic("HEAD", `refs/heads/${this.initialBranch}`);
399
+ await history.refs.setSymbolic("HEAD", `refs/heads/${initialBranch}`);
296
400
  }
297
401
  // The index lives in the repository too: a reopened repository keeps what was staged
298
402
  // (its last commit's files), so the next commit does not drop them.
@@ -301,15 +405,18 @@ export class InitCommand {
301
405
  } else if (this.bare) {
302
406
  staging = new MemoryStagingStore();
303
407
  } else {
304
- const fileStaging = new FileStagingStore(repoFiles, `${dir}/index`);
305
- await fileStaging.read();
408
+ const fileStaging = new FileStagingStore(repoFiles, `${dir}/index`, { objectFormat });
409
+ // a SHA-256 repository's index is not read yet: its first use refuses
410
+ if (objectFormat.name === "sha1") await fileStaging.read();
306
411
  staging = fileStaging;
307
412
  }
308
413
  } else {
309
- history = createMemoryHistory();
414
+ objectFormat = explicitFormat ?? (await this.defaultObjectFormat(warnings));
415
+ await chooseBranch();
416
+ history = createMemoryHistory({ objectFormat });
310
417
  await history.initialize();
311
418
  // Set initial branch by creating symbolic ref for HEAD
312
- await history.refs.setSymbolic("HEAD", `refs/heads/${this.initialBranch}`);
419
+ await history.refs.setSymbolic("HEAD", `refs/heads/${initialBranch}`);
313
420
  staging = this.stagingStore ?? new MemoryStagingStore();
314
421
  }
315
422
 
@@ -405,12 +512,34 @@ export class InitCommand {
405
512
  git,
406
513
  workingCopy,
407
514
  repository: history,
408
- initialBranch: this.initialBranch,
515
+ initialBranch,
516
+ ...(hints ? { hints } : {}),
517
+ ...(warnings.length > 0 ? { warnings } : {}),
409
518
  bare: this.bare,
410
519
  gitDir,
411
520
  };
412
521
  }
413
522
 
523
+ /**
524
+ * The format of a new repository without `--object-format` (validate_hash_algorithm):
525
+ * `$GIT_DEFAULT_HASH` (an unknown name dies), else `init.defaultObjectFormat` (git 2.45+;
526
+ * an unknown name warns and is ignored), else SHA-1.
527
+ */
528
+ private async defaultObjectFormat(warnings: string[]): Promise<ObjectFormat> {
529
+ const env = this.environment?.defaultHash;
530
+ if (env !== undefined) return knownHashAlgorithm(env);
531
+ const config = await readProtectedConfig(this.environment);
532
+ const configured = config
533
+ .filter((e) => e.key.toLowerCase() === "init.defaultobjectformat")
534
+ .at(-1);
535
+ if (configured?.value !== undefined) {
536
+ const found = objectFormatByName(configured.value);
537
+ if (found) return found;
538
+ warnings.push(`warning: unknown hash algorithm '${configured.value}'`);
539
+ }
540
+ return SHA1_OBJECT_FORMAT;
541
+ }
542
+
414
543
  /**
415
544
  * Resolve the git directory path based on configuration.
416
545
  */
@@ -453,6 +582,33 @@ export class InitCommand {
453
582
  }
454
583
  }
455
584
 
585
+ /** `--object-format` or `$GIT_DEFAULT_HASH` names no format git knows: git dies (exit 128). */
586
+ export class UnknownHashAlgorithmError extends Error {
587
+ override name = "UnknownHashAlgorithmError";
588
+ readonly lines: string[];
589
+ constructor(readonly value: string) {
590
+ const line = `fatal: unknown hash algorithm '${value}'`;
591
+ super(line);
592
+ this.lines = [line];
593
+ }
594
+ }
595
+
596
+ /** `--object-format` names another format than the existing repository's: git dies (exit 128). */
597
+ export class ReinitializeHashError extends Error {
598
+ override name = "ReinitializeHashError";
599
+ readonly lines = ["fatal: attempt to reinitialize repository with different hash"];
600
+ constructor() {
601
+ super("fatal: attempt to reinitialize repository with different hash");
602
+ }
603
+ }
604
+
605
+ /** The format named `name`, or `UnknownHashAlgorithmError` (git's `hash_algo_by_name`). */
606
+ function knownHashAlgorithm(name: string): ObjectFormat {
607
+ const found = objectFormatByName(name);
608
+ if (!found) throw new UnknownHashAlgorithmError(name);
609
+ return found;
610
+ }
611
+
456
612
  /** Sets `core.bare = true` in a config file written by the git directory layout. */
457
613
  async function markBare(files: FilesApi, configPath: string): Promise<void> {
458
614
  await setCoreValue(files, configPath, "bare", "true");