@statewalker/vcs-commands 0.7.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 (410) 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/branch-command.d.ts +148 -18
  15. package/dist/commands/branch-command.d.ts.map +1 -1
  16. package/dist/commands/branch-info-command.d.ts +55 -0
  17. package/dist/commands/branch-info-command.d.ts.map +1 -0
  18. package/dist/commands/branch-tracking.d.ts +106 -17
  19. package/dist/commands/branch-tracking.d.ts.map +1 -1
  20. package/dist/commands/branch-upstream-command.d.ts +83 -0
  21. package/dist/commands/branch-upstream-command.d.ts.map +1 -0
  22. package/dist/commands/checkout-command.d.ts +19 -3
  23. package/dist/commands/checkout-command.d.ts.map +1 -1
  24. package/dist/commands/cherry-pick-command.d.ts +59 -0
  25. package/dist/commands/cherry-pick-command.d.ts.map +1 -1
  26. package/dist/commands/clean-command.d.ts +12 -0
  27. package/dist/commands/clean-command.d.ts.map +1 -1
  28. package/dist/commands/clone-command.d.ts.map +1 -1
  29. package/dist/commands/commit-command.d.ts +191 -5
  30. package/dist/commands/commit-command.d.ts.map +1 -1
  31. package/dist/commands/commit-reuse.d.ts +33 -0
  32. package/dist/commands/commit-reuse.d.ts.map +1 -0
  33. package/dist/commands/config-command.d.ts +236 -0
  34. package/dist/commands/config-command.d.ts.map +1 -0
  35. package/dist/commands/config-value-types.d.ts +91 -0
  36. package/dist/commands/config-value-types.d.ts.map +1 -0
  37. package/dist/commands/core-config.d.ts +20 -0
  38. package/dist/commands/core-config.d.ts.map +1 -1
  39. package/dist/commands/diff-color-config.d.ts +73 -0
  40. package/dist/commands/diff-color-config.d.ts.map +1 -0
  41. package/dist/commands/diff-command.d.ts +252 -5
  42. package/dist/commands/diff-command.d.ts.map +1 -1
  43. package/dist/commands/fetch-command.d.ts +20 -0
  44. package/dist/commands/fetch-command.d.ts.map +1 -1
  45. package/dist/commands/fmt-merge-msg-command.d.ts +124 -0
  46. package/dist/commands/fmt-merge-msg-command.d.ts.map +1 -0
  47. package/dist/commands/fork-point.d.ts +38 -0
  48. package/dist/commands/fork-point.d.ts.map +1 -0
  49. package/dist/commands/format-patch-command.d.ts +41 -1
  50. package/dist/commands/format-patch-command.d.ts.map +1 -1
  51. package/dist/commands/fsck/fetch-fsck.d.ts +51 -0
  52. package/dist/commands/fsck/fetch-fsck.d.ts.map +1 -1
  53. package/dist/commands/gc-command.d.ts +8 -0
  54. package/dist/commands/gc-command.d.ts.map +1 -1
  55. package/dist/commands/git-describe.d.ts +4 -0
  56. package/dist/commands/git-describe.d.ts.map +1 -1
  57. package/dist/commands/git-hooks.d.ts +35 -0
  58. package/dist/commands/git-hooks.d.ts.map +1 -1
  59. package/dist/commands/grep/grep-command.d.ts +210 -0
  60. package/dist/commands/grep/grep-command.d.ts.map +1 -0
  61. package/dist/commands/grep/grep-engine.d.ts +218 -0
  62. package/dist/commands/grep/grep-engine.d.ts.map +1 -0
  63. package/dist/commands/grep/index.d.ts +3 -0
  64. package/dist/commands/grep/index.d.ts.map +1 -0
  65. package/dist/commands/index-adder.d.ts +13 -2
  66. package/dist/commands/index-adder.d.ts.map +1 -1
  67. package/dist/commands/index.d.ts +26 -0
  68. package/dist/commands/index.d.ts.map +1 -1
  69. package/dist/commands/index.js +3 -3
  70. package/dist/commands/interpret-trailers-command.d.ts +90 -0
  71. package/dist/commands/interpret-trailers-command.d.ts.map +1 -0
  72. package/dist/commands/local-transport.d.ts +36 -5
  73. package/dist/commands/local-transport.d.ts.map +1 -1
  74. package/dist/commands/log-command.d.ts +296 -11
  75. package/dist/commands/log-command.d.ts.map +1 -1
  76. package/dist/commands/log-graph.d.ts +26 -1
  77. package/dist/commands/log-graph.d.ts.map +1 -1
  78. package/dist/commands/log-output.d.ts +133 -5
  79. package/dist/commands/log-output.d.ts.map +1 -1
  80. package/dist/commands/ls-remote-command.d.ts +2 -0
  81. package/dist/commands/ls-remote-command.d.ts.map +1 -1
  82. package/dist/commands/mailmap.d.ts +30 -0
  83. package/dist/commands/mailmap.d.ts.map +1 -1
  84. package/dist/commands/merge-base-command.d.ts +60 -0
  85. package/dist/commands/merge-base-command.d.ts.map +1 -0
  86. package/dist/commands/merge-bases.d.ts +23 -0
  87. package/dist/commands/merge-bases.d.ts.map +1 -1
  88. package/dist/commands/merge-command.d.ts +96 -9
  89. package/dist/commands/merge-command.d.ts.map +1 -1
  90. package/dist/commands/merge-support.d.ts.map +1 -1
  91. package/dist/commands/mv-command.d.ts +4 -0
  92. package/dist/commands/mv-command.d.ts.map +1 -1
  93. package/dist/commands/name-rev.d.ts +48 -0
  94. package/dist/commands/name-rev.d.ts.map +1 -0
  95. package/dist/commands/notes-command.d.ts.map +1 -1
  96. package/dist/commands/pathspec-file.d.ts +39 -0
  97. package/dist/commands/pathspec-file.d.ts.map +1 -0
  98. package/dist/commands/pathspec.d.ts +3 -0
  99. package/dist/commands/pathspec.d.ts.map +1 -1
  100. package/dist/commands/pretty-format.d.ts +43 -3
  101. package/dist/commands/pretty-format.d.ts.map +1 -1
  102. package/dist/commands/promisor-remote.d.ts.map +1 -1
  103. package/dist/commands/pull-command.d.ts +10 -0
  104. package/dist/commands/pull-command.d.ts.map +1 -1
  105. package/dist/commands/push-command.d.ts +160 -9
  106. package/dist/commands/push-command.d.ts.map +1 -1
  107. package/dist/commands/read-tree-command.d.ts +6 -0
  108. package/dist/commands/read-tree-command.d.ts.map +1 -1
  109. package/dist/commands/rebase-command.d.ts +168 -6
  110. package/dist/commands/rebase-command.d.ts.map +1 -1
  111. package/dist/commands/ref-filter/for-each-ref-command.d.ts +121 -0
  112. package/dist/commands/ref-filter/for-each-ref-command.d.ts.map +1 -0
  113. package/dist/commands/ref-filter/index.d.ts +8 -0
  114. package/dist/commands/ref-filter/index.d.ts.map +1 -0
  115. package/dist/commands/ref-filter/ref-atoms.d.ts +88 -0
  116. package/dist/commands/ref-filter/ref-atoms.d.ts.map +1 -0
  117. package/dist/commands/ref-filter/ref-filter.d.ts +178 -0
  118. package/dist/commands/ref-filter/ref-filter.d.ts.map +1 -0
  119. package/dist/commands/ref-filter/ref-format.d.ts +222 -0
  120. package/dist/commands/ref-filter/ref-format.d.ts.map +1 -0
  121. package/dist/commands/ref-filter/ref-listing-command.d.ts +56 -0
  122. package/dist/commands/ref-filter/ref-listing-command.d.ts.map +1 -0
  123. package/dist/commands/ref-filter/ref-quote.d.ts +20 -0
  124. package/dist/commands/ref-filter/ref-quote.d.ts.map +1 -0
  125. package/dist/commands/ref-filter/version-compare.d.ts +20 -0
  126. package/dist/commands/ref-filter/version-compare.d.ts.map +1 -0
  127. package/dist/commands/reflog-command.d.ts +120 -0
  128. package/dist/commands/reflog-command.d.ts.map +1 -1
  129. package/dist/commands/reflog-walk.d.ts +72 -0
  130. package/dist/commands/reflog-walk.d.ts.map +1 -0
  131. package/dist/commands/remote-command.d.ts +138 -29
  132. package/dist/commands/remote-command.d.ts.map +1 -1
  133. package/dist/commands/remote-transport.d.ts +7 -1
  134. package/dist/commands/remote-transport.d.ts.map +1 -1
  135. package/dist/commands/reset-command.d.ts +2 -3
  136. package/dist/commands/reset-command.d.ts.map +1 -1
  137. package/dist/commands/restore-command.d.ts +2 -3
  138. package/dist/commands/restore-command.d.ts.map +1 -1
  139. package/dist/commands/rev-filter/commit-filter.d.ts +95 -0
  140. package/dist/commands/rev-filter/commit-filter.d.ts.map +1 -0
  141. package/dist/commands/rev-filter/commit-grep.d.ts +91 -0
  142. package/dist/commands/rev-filter/commit-grep.d.ts.map +1 -0
  143. package/dist/commands/rev-filter/index.d.ts +3 -0
  144. package/dist/commands/rev-filter/index.d.ts.map +1 -0
  145. package/dist/commands/rev-list-command.d.ts +154 -2
  146. package/dist/commands/rev-list-command.d.ts.map +1 -1
  147. package/dist/commands/revert-command.d.ts +32 -0
  148. package/dist/commands/revert-command.d.ts.map +1 -1
  149. package/dist/commands/revision-range.d.ts +32 -1
  150. package/dist/commands/revision-range.d.ts.map +1 -1
  151. package/dist/commands/revision-resolver.d.ts +15 -0
  152. package/dist/commands/revision-resolver.d.ts.map +1 -1
  153. package/dist/commands/rm-command.d.ts +70 -2
  154. package/dist/commands/rm-command.d.ts.map +1 -1
  155. package/dist/commands/sequencer-pick.d.ts +84 -4
  156. package/dist/commands/sequencer-pick.d.ts.map +1 -1
  157. package/dist/commands/sequencer-support.d.ts +2 -0
  158. package/dist/commands/sequencer-support.d.ts.map +1 -1
  159. package/dist/commands/serve-repository.d.ts +7 -0
  160. package/dist/commands/serve-repository.d.ts.map +1 -1
  161. package/dist/commands/show-command.d.ts +130 -0
  162. package/dist/commands/show-command.d.ts.map +1 -0
  163. package/dist/commands/show-commit.d.ts +11 -0
  164. package/dist/commands/show-commit.d.ts.map +1 -0
  165. package/dist/commands/signature-check.d.ts +164 -0
  166. package/dist/commands/signature-check.d.ts.map +1 -0
  167. package/dist/commands/signing.d.ts +160 -0
  168. package/dist/commands/signing.d.ts.map +1 -0
  169. package/dist/commands/sparse-checkout-command.d.ts.map +1 -1
  170. package/dist/commands/sparse-index-view.d.ts +45 -0
  171. package/dist/commands/sparse-index-view.d.ts.map +1 -0
  172. package/dist/commands/ssh-signer.d.ts +29 -0
  173. package/dist/commands/ssh-signer.d.ts.map +1 -0
  174. package/dist/commands/ssh-verifier.d.ts +42 -0
  175. package/dist/commands/ssh-verifier.d.ts.map +1 -0
  176. package/dist/commands/stash-apply-command.d.ts +5 -0
  177. package/dist/commands/stash-apply-command.d.ts.map +1 -1
  178. package/dist/commands/stash-branch-command.d.ts +34 -0
  179. package/dist/commands/stash-branch-command.d.ts.map +1 -0
  180. package/dist/commands/stash-create-command.d.ts +17 -0
  181. package/dist/commands/stash-create-command.d.ts.map +1 -1
  182. package/dist/commands/stash-info.d.ts +93 -0
  183. package/dist/commands/stash-info.d.ts.map +1 -0
  184. package/dist/commands/stash-list-command.d.ts +16 -0
  185. package/dist/commands/stash-list-command.d.ts.map +1 -1
  186. package/dist/commands/stash-pop-command.d.ts +39 -0
  187. package/dist/commands/stash-pop-command.d.ts.map +1 -0
  188. package/dist/commands/stash-show-command.d.ts +48 -0
  189. package/dist/commands/stash-show-command.d.ts.map +1 -0
  190. package/dist/commands/stash-store-command.d.ts +29 -0
  191. package/dist/commands/stash-store-command.d.ts.map +1 -0
  192. package/dist/commands/stash-working-tree.d.ts.map +1 -1
  193. package/dist/commands/status-command.d.ts.map +1 -1
  194. package/dist/commands/status-header.d.ts +5 -0
  195. package/dist/commands/status-header.d.ts.map +1 -1
  196. package/dist/commands/submodule-add-command.d.ts +89 -0
  197. package/dist/commands/submodule-add-command.d.ts.map +1 -0
  198. package/dist/commands/submodule-auth.d.ts +90 -0
  199. package/dist/commands/submodule-auth.d.ts.map +1 -0
  200. package/dist/commands/submodule-commands.d.ts +375 -0
  201. package/dist/commands/submodule-commands.d.ts.map +1 -0
  202. package/dist/commands/submodule-model.d.ts +288 -0
  203. package/dist/commands/submodule-model.d.ts.map +1 -0
  204. package/dist/commands/submodule-update-command.d.ts +198 -0
  205. package/dist/commands/submodule-update-command.d.ts.map +1 -0
  206. package/dist/commands/switch-command.d.ts.map +1 -1
  207. package/dist/commands/tag-command.d.ts +259 -10
  208. package/dist/commands/tag-command.d.ts.map +1 -1
  209. package/dist/commands/trailers.d.ts +218 -17
  210. package/dist/commands/trailers.d.ts.map +1 -1
  211. package/dist/commands/tree-restore.d.ts +7 -0
  212. package/dist/commands/tree-restore.d.ts.map +1 -1
  213. package/dist/commands/verify-command.d.ts +92 -0
  214. package/dist/commands/verify-command.d.ts.map +1 -0
  215. package/dist/commands/worktree-add-command.d.ts +79 -7
  216. package/dist/commands/worktree-add-command.d.ts.map +1 -1
  217. package/dist/commands/worktree-path-rules.d.ts +66 -0
  218. package/dist/commands/worktree-path-rules.d.ts.map +1 -0
  219. package/dist/commands/worktree-remove-command.d.ts +10 -3
  220. package/dist/commands/worktree-remove-command.d.ts.map +1 -1
  221. package/dist/commands/worktree-repair-command.d.ts +15 -2
  222. package/dist/commands/worktree-repair-command.d.ts.map +1 -1
  223. package/dist/commands/worktree-support.d.ts +5 -0
  224. package/dist/commands/worktree-support.d.ts.map +1 -1
  225. package/dist/{commands-DIJ91NnD.js → commands-ISM52N0n.js} +70736 -54492
  226. package/dist/errors/checkout-errors.d.ts +19 -0
  227. package/dist/errors/checkout-errors.d.ts.map +1 -1
  228. package/dist/errors/command-errors.d.ts.map +1 -1
  229. package/dist/errors/index.js +57 -3
  230. package/dist/errors/ref-errors.d.ts +19 -0
  231. package/dist/errors/ref-errors.d.ts.map +1 -1
  232. package/dist/errors/worktree-errors.d.ts +6 -1
  233. package/dist/errors/worktree-errors.d.ts.map +1 -1
  234. package/dist/{git-command-BGiOJ8Zk.js → fsck-DLRpbwTj.js} +6230 -71
  235. package/dist/git-command.d.ts +27 -1
  236. package/dist/git-command.d.ts.map +1 -1
  237. package/dist/git.d.ts +267 -1
  238. package/dist/git.d.ts.map +1 -1
  239. package/dist/index.js +5 -5
  240. package/dist/remote-config/index.d.ts +1 -1
  241. package/dist/remote-config/index.d.ts.map +1 -1
  242. package/dist/remote-config/remote-config-store.d.ts +55 -0
  243. package/dist/remote-config/remote-config-store.d.ts.map +1 -1
  244. package/dist/results/combined-diff.d.ts +3 -0
  245. package/dist/results/combined-diff.d.ts.map +1 -1
  246. package/dist/results/diff-check.d.ts +38 -0
  247. package/dist/results/diff-check.d.ts.map +1 -0
  248. package/dist/results/diff-color.d.ts +135 -0
  249. package/dist/results/diff-color.d.ts.map +1 -0
  250. package/dist/results/diff-output.d.ts +85 -1
  251. package/dist/results/diff-output.d.ts.map +1 -1
  252. package/dist/results/diff-pickaxe.d.ts +67 -0
  253. package/dist/results/diff-pickaxe.d.ts.map +1 -0
  254. package/dist/results/diff-words.d.ts +55 -0
  255. package/dist/results/diff-words.d.ts.map +1 -0
  256. package/dist/results/index.d.ts +4 -0
  257. package/dist/results/index.d.ts.map +1 -1
  258. package/dist/results/index.js +2 -2
  259. package/dist/results/push-result.d.ts +7 -0
  260. package/dist/results/push-result.d.ts.map +1 -1
  261. package/dist/results/rebase-result.d.ts +2 -0
  262. package/dist/results/rebase-result.d.ts.map +1 -1
  263. package/dist/results/stash-result.d.ts +6 -0
  264. package/dist/results/stash-result.d.ts.map +1 -1
  265. package/dist/{results-WVlBhVb1.js → results-TB2IJ64h.js} +2168 -403
  266. package/dist/whitespace/index.d.ts +2 -0
  267. package/dist/whitespace/index.d.ts.map +1 -0
  268. package/dist/whitespace/whitespace-rule.d.ts +94 -0
  269. package/dist/whitespace/whitespace-rule.d.ts.map +1 -0
  270. package/package.json +12 -12
  271. package/src/commands/add-command.ts +178 -17
  272. package/src/commands/am/am-command.ts +262 -42
  273. package/src/commands/am/index.ts +1 -0
  274. package/src/commands/am/mailsplit.ts +326 -0
  275. package/src/commands/apply/apply-command.ts +6 -6
  276. package/src/commands/apply/apply-engine.ts +1 -1
  277. package/src/commands/apply/apply-parse.ts +7 -8
  278. package/src/commands/bisect/bisect-command.ts +18 -5
  279. package/src/commands/branch-command.ts +528 -53
  280. package/src/commands/branch-info-command.ts +150 -0
  281. package/src/commands/branch-tracking.ts +335 -60
  282. package/src/commands/branch-upstream-command.ts +218 -0
  283. package/src/commands/checkout-command.ts +69 -43
  284. package/src/commands/cherry-pick-command.ts +143 -0
  285. package/src/commands/clean-command.ts +34 -3
  286. package/src/commands/clone-command.ts +2 -1
  287. package/src/commands/commit-command.ts +782 -64
  288. package/src/commands/commit-reuse.ts +94 -0
  289. package/src/commands/config-command.ts +1256 -0
  290. package/src/commands/config-value-types.ts +358 -0
  291. package/src/commands/core-config.ts +40 -0
  292. package/src/commands/diff-color-config.ts +274 -0
  293. package/src/commands/diff-command.ts +1009 -49
  294. package/src/commands/fetch-command.ts +142 -8
  295. package/src/commands/fmt-merge-msg-command.ts +715 -0
  296. package/src/commands/fork-point.ts +63 -0
  297. package/src/commands/format-patch-command.ts +314 -46
  298. package/src/commands/fsck/fetch-fsck.ts +172 -18
  299. package/src/commands/gc-command.ts +31 -1
  300. package/src/commands/git-describe.ts +31 -11
  301. package/src/commands/git-hooks.ts +81 -0
  302. package/src/commands/grep/grep-command.ts +1077 -0
  303. package/src/commands/grep/grep-engine.ts +1024 -0
  304. package/src/commands/grep/index.ts +2 -0
  305. package/src/commands/index-adder.ts +46 -7
  306. package/src/commands/index.ts +26 -0
  307. package/src/commands/interpret-trailers-command.ts +256 -0
  308. package/src/commands/local-transport.ts +109 -10
  309. package/src/commands/log-command.ts +1246 -210
  310. package/src/commands/log-graph.ts +123 -26
  311. package/src/commands/log-output.ts +280 -21
  312. package/src/commands/ls-remote-command.ts +5 -0
  313. package/src/commands/mailmap.ts +119 -0
  314. package/src/commands/merge-base-command.ts +170 -0
  315. package/src/commands/merge-bases.ts +63 -8
  316. package/src/commands/merge-command.ts +330 -82
  317. package/src/commands/merge-support.ts +14 -1
  318. package/src/commands/mv-command.ts +6 -3
  319. package/src/commands/name-rev.ts +171 -0
  320. package/src/commands/notes-command.ts +11 -1
  321. package/src/commands/pathspec-file.ts +72 -0
  322. package/src/commands/pathspec.ts +14 -2
  323. package/src/commands/pretty-format.ts +103 -19
  324. package/src/commands/promisor-remote.ts +10 -1
  325. package/src/commands/pull-command.ts +26 -7
  326. package/src/commands/push-command.ts +682 -65
  327. package/src/commands/read-tree-command.ts +28 -1
  328. package/src/commands/rebase-command.ts +933 -129
  329. package/src/commands/ref-filter/for-each-ref-command.ts +298 -0
  330. package/src/commands/ref-filter/index.ts +7 -0
  331. package/src/commands/ref-filter/ref-atoms.ts +581 -0
  332. package/src/commands/ref-filter/ref-filter.ts +651 -0
  333. package/src/commands/ref-filter/ref-format.ts +1070 -0
  334. package/src/commands/ref-filter/ref-listing-command.ts +421 -0
  335. package/src/commands/ref-filter/ref-quote.ts +69 -0
  336. package/src/commands/ref-filter/version-compare.ts +177 -0
  337. package/src/commands/reflog-command.ts +492 -2
  338. package/src/commands/reflog-walk.ts +234 -0
  339. package/src/commands/remote-command.ts +449 -69
  340. package/src/commands/remote-transport.ts +9 -1
  341. package/src/commands/reset-command.ts +36 -31
  342. package/src/commands/restore-command.ts +12 -41
  343. package/src/commands/rev-filter/commit-filter.ts +159 -0
  344. package/src/commands/rev-filter/commit-grep.ts +444 -0
  345. package/src/commands/rev-filter/index.ts +2 -0
  346. package/src/commands/rev-list-command.ts +402 -15
  347. package/src/commands/revert-command.ts +82 -0
  348. package/src/commands/revision-range.ts +204 -4
  349. package/src/commands/revision-resolver.ts +23 -8
  350. package/src/commands/rm-command.ts +282 -21
  351. package/src/commands/sequencer-pick.ts +498 -85
  352. package/src/commands/sequencer-support.ts +20 -2
  353. package/src/commands/serve-repository.ts +18 -3
  354. package/src/commands/show-command.ts +490 -0
  355. package/src/commands/show-commit.ts +24 -0
  356. package/src/commands/signature-check.ts +657 -0
  357. package/src/commands/signing.ts +385 -0
  358. package/src/commands/sparse-checkout-command.ts +2 -9
  359. package/src/commands/sparse-checkout-support.ts +2 -2
  360. package/src/commands/sparse-index-view.ts +135 -0
  361. package/src/commands/ssh-signer.ts +199 -0
  362. package/src/commands/ssh-verifier.ts +523 -0
  363. package/src/commands/stash-apply-command.ts +16 -4
  364. package/src/commands/stash-branch-command.ts +88 -0
  365. package/src/commands/stash-create-command.ts +28 -0
  366. package/src/commands/stash-info.ts +243 -0
  367. package/src/commands/stash-list-command.ts +33 -0
  368. package/src/commands/stash-pop-command.ts +83 -0
  369. package/src/commands/stash-show-command.ts +141 -0
  370. package/src/commands/stash-store-command.ts +82 -0
  371. package/src/commands/stash-working-tree.ts +2 -2
  372. package/src/commands/status-command.ts +5 -2
  373. package/src/commands/status-header.ts +41 -7
  374. package/src/commands/submodule-add-command.ts +509 -0
  375. package/src/commands/submodule-auth.ts +276 -0
  376. package/src/commands/submodule-commands.ts +1517 -0
  377. package/src/commands/submodule-model.ts +930 -0
  378. package/src/commands/submodule-update-command.ts +1092 -0
  379. package/src/commands/switch-command.ts +3 -1
  380. package/src/commands/tag-command.ts +876 -64
  381. package/src/commands/trailers.ts +837 -100
  382. package/src/commands/tree-restore.ts +38 -10
  383. package/src/commands/verify-command.ts +235 -0
  384. package/src/commands/worktree-add-command.ts +268 -24
  385. package/src/commands/worktree-path-rules.ts +183 -0
  386. package/src/commands/worktree-remove-command.ts +39 -5
  387. package/src/commands/worktree-repair-command.ts +52 -5
  388. package/src/commands/worktree-support.ts +22 -1
  389. package/src/errors/checkout-errors.ts +29 -0
  390. package/src/errors/command-errors.ts +2 -1
  391. package/src/errors/ref-errors.ts +23 -0
  392. package/src/errors/worktree-errors.ts +8 -1
  393. package/src/git-command.ts +66 -1
  394. package/src/git.ts +404 -1
  395. package/src/remote-config/index.ts +2 -0
  396. package/src/remote-config/remote-config-store.ts +101 -0
  397. package/src/results/combined-diff.ts +38 -18
  398. package/src/results/diff-check.ts +185 -0
  399. package/src/results/diff-color.ts +868 -0
  400. package/src/results/diff-output.ts +195 -30
  401. package/src/results/diff-pickaxe.ts +304 -0
  402. package/src/results/diff-words.ts +395 -0
  403. package/src/results/index.ts +4 -0
  404. package/src/results/push-result.ts +7 -0
  405. package/src/results/rebase-result.ts +3 -0
  406. package/src/results/stash-result.ts +7 -0
  407. package/src/whitespace/index.ts +1 -0
  408. package/src/{commands/apply/whitespace.ts → whitespace/whitespace-rule.ts} +173 -23
  409. package/dist/commands/apply/whitespace.d.ts +0 -58
  410. package/dist/commands/apply/whitespace.d.ts.map +0 -1
@@ -6,6 +6,7 @@ import {
6
6
  type TreeEntry,
7
7
  } from "@statewalker/vcs-core";
8
8
  import { FileStagingStore } from "@statewalker/vcs-store-files";
9
+ import { compilePosixRegex, type PosixRegex } from "@statewalker/vcs-utils";
9
10
  import { compareGitPaths } from "@statewalker/vcs-utils/encoding";
10
11
  import type { FilesApi } from "@statewalker/vcs-utils/files";
11
12
  import {
@@ -16,7 +17,6 @@ import {
16
17
  type Worktree,
17
18
  type WorktreeEntry,
18
19
  } from "@statewalker/vcs-working-tree";
19
-
20
20
  import {
21
21
  EmptyCommitError,
22
22
  GitApiError,
@@ -33,10 +33,28 @@ import {
33
33
  import { GitCommand } from "../git-command.js";
34
34
  import { RemoteConfigStore } from "../remote-config/index.js";
35
35
  import { AddCommand } from "./add-command.js";
36
+ import {
37
+ amendCommitText,
38
+ autosquashSubject,
39
+ commitSubjectLength,
40
+ type FixupKind,
41
+ parseFixupSpec,
42
+ refuseIncompatible,
43
+ skipBlankLines,
44
+ } from "./commit-reuse.js";
36
45
  import { worktreeModeTrust } from "./core-config.js";
37
46
  import { DEFAULT_DATE_MODE, showDate } from "./date-format.js";
38
- import { hostEnvironmentOf, withoutCrud } from "./git-ident.js";
47
+ import { approxidateCareful } from "./git-date.js";
48
+ import {
49
+ hostEnvironmentOf,
50
+ InvalidDateError,
51
+ InvalidIdentError,
52
+ parseGitDate,
53
+ withoutCrud,
54
+ } from "./git-ident.js";
39
55
  import { IndexAdder, readGitlinkHead } from "./index-adder.js";
56
+ import { reencodedCommitParts } from "./log-output.js";
57
+ import { readRepositoryMailmap } from "./mailmap.js";
40
58
  import {
41
59
  flatTree,
42
60
  OperationState,
@@ -63,8 +81,10 @@ import {
63
81
  pathspecItemMayMatch,
64
82
  } from "./pathspec.js";
65
83
  import { PathspecAttributes } from "./pathspec-attributes.js";
84
+ import { PathspecFile } from "./pathspec-file.js";
66
85
  import { type CommitReflogKind, reflogMessages, updateHead } from "./reflog-messages.js";
67
86
  import { applyAutostash } from "./sequencer-support.js";
87
+ import { signCommit, signRequestOf } from "./signing.js";
68
88
  import {
69
89
  cutLine,
70
90
  readShowUntrackedFiles,
@@ -74,6 +94,16 @@ import {
74
94
  } from "./status-command.js";
75
95
  import { type CommitWhence, StatusPrinter } from "./status-format.js";
76
96
  import { readDiffSubmoduleConfig } from "./submodule-summary.js";
97
+ import {
98
+ amendWithTrailers,
99
+ appendSignoff,
100
+ ignoredLogMessageBytes,
101
+ signoffLine,
102
+ type TrailerCommandRunner,
103
+ trailerConfigOf,
104
+ validateTrailerArgs,
105
+ } from "./trailers.js";
106
+ import { worktreePathRules } from "./worktree-path-rules.js";
77
107
 
78
108
  /**
79
109
  * Result of a commit operation.
@@ -144,9 +174,13 @@ export class CommitCommand extends GitCommand<CommitResult> {
144
174
  private amend = false;
145
175
  private noPostRewrite = false;
146
176
  private noVerify = false;
177
+ /** `-S[<keyid>]` / `--no-gpg-sign` (undefined: `commit.gpgSign`) */
178
+ private sign?: boolean | string;
147
179
  private allowEmpty = false;
148
180
  private parents: ObjectId[] = [];
149
181
  private onlyPaths: string[] = [];
182
+ /** `--pathspec-from-file` */
183
+ private readonly pathspecFile = new PathspecFile();
150
184
  private all = false;
151
185
  private include = false;
152
186
  private includePaths: string[] = [];
@@ -163,6 +197,24 @@ export class CommitCommand extends GitCommand<CommitResult> {
163
197
  private nullTermination = false;
164
198
  private aheadBehind?: boolean;
165
199
  private templateFile?: string;
200
+ /** `--author=<string>` as given: `Name <email>`, or a pattern of an existing author */
201
+ private authorString?: string;
202
+ /** `--date=<date>`, and the clock its relative forms count from */
203
+ private forceDate?: { text: string; now?: number };
204
+ private signoff = false;
205
+ private trailerArgs: string[] = [];
206
+ /** `-C <commit>`: the commit whose message (and author) are reused */
207
+ private reuseMessage?: string;
208
+ /** The commit `-C` (or `-c`) names, read once the options are checked */
209
+ private reused?: Commit;
210
+ /** `-c <commit>` */
211
+ private reeditMessageFrom?: string;
212
+ /** `--fixup=[(amend|reword):]<commit>` as given */
213
+ private fixupSpec?: string;
214
+ /** `--squash=<commit>` */
215
+ private squashFrom?: string;
216
+ /** --fixup, parsed when the commit runs */
217
+ private fixup?: { kind: FixupKind; target: string };
166
218
 
167
219
  /**
168
220
  * Set the commit message, as git's `commit -m` takes it: its last line is ended and it is
@@ -221,17 +273,78 @@ export class CommitCommand extends GitCommand<CommitResult> {
221
273
  }
222
274
 
223
275
  /**
224
- * Set the author identity.
276
+ * Set the author identity (git's `--author`): a name and an email, or one string as git's
277
+ * `--author=<author>` takes it. A string with a `>` is `Name <email>` (refused as
278
+ * `fatal: malformed --author parameter` without a `<`); any other is a pattern looked up as
279
+ * git's `find_author_by_nickname` does: the newest commit of `--all` whose (mailmapped)
280
+ * author matches it as a basic regular expression, ignoring case, gives its `Name <email>`,
281
+ * else `fatal: --author '<x>' is not 'Name <email>' and matches no existing author`.
225
282
  *
226
- * @param name Author name
283
+ * @example
284
+ * ```typescript
285
+ * await git.commit().setAuthor("Ada <ada@example.com>").setMessage("m").call();
286
+ * await git.commit().setAuthor("ada").setMessage("m").call(); // an existing author
287
+ * ```
288
+ *
289
+ * @param name Author name, or the whole `--author` string when `email` is not given
227
290
  * @param email Author email
228
291
  */
229
- setAuthor(name: string, email: string): this {
292
+ setAuthor(name: string, email?: string): this {
230
293
  this.checkCallable();
231
294
  // git's --author: the name and email; the date is the amended commit's, the picked
232
295
  // commit's, else GIT_AUTHOR_DATE or now
233
296
  this.author = undefined;
234
- this.authorName = { name, email };
297
+ if (email === undefined) {
298
+ this.authorName = undefined;
299
+ this.authorString = name;
300
+ } else {
301
+ this.authorString = undefined;
302
+ this.authorName = { name, email };
303
+ }
304
+ return this;
305
+ }
306
+
307
+ /**
308
+ * `--date=<date>`: the author's date, in any form git's `parse_date` reads (`@<seconds>
309
+ * <offset>`, RFC 2822, ISO 8601, ...) or else as `approxidate` reads it (`yesterday`,
310
+ * `2.weeks.ago`, `noon`), counting from `now` (seconds; default the command's clock, git's
311
+ * `GIT_TEST_DATE_NOW`). A date git cannot read fails as `fatal: invalid date format: <date>`.
312
+ */
313
+ setDate(date: string, options: { now?: number } = {}): this {
314
+ this.checkCallable();
315
+ this.forceDate = { text: date, ...(options.now !== undefined ? { now: options.now } : {}) };
316
+ return this;
317
+ }
318
+
319
+ /**
320
+ * `-s` / `--signoff`: a `Signed-off-by: <committer>` trailer added to the message as git's
321
+ * `append_signoff` adds it (after a blank line unless the message ends with trailers; none
322
+ * when the last trailer is that line already).
323
+ */
324
+ setSignoff(signoff: boolean): this {
325
+ this.checkCallable();
326
+ this.signoff = signoff;
327
+ return this;
328
+ }
329
+
330
+ /**
331
+ * `--trailer <token>[(=|:)<value>]`: a trailer added to the message as `git
332
+ * interpret-trailers --no-divider --trailer` adds it (`trailer.*` configuration applies).
333
+ * Each call adds one, in order.
334
+ */
335
+ addTrailer(trailer: string): this {
336
+ this.checkCallable();
337
+ this.trailerArgs.push(trailer);
338
+ return this;
339
+ }
340
+
341
+ /**
342
+ * `-C <commit>`: the commit's message taken as it is, and its author (name, email and
343
+ * date) unless {@link setResetAuthor}. With {@link setEdit}(true) it is `-c`.
344
+ */
345
+ setReuseMessage(commit: string): this {
346
+ this.checkCallable();
347
+ this.reuseMessage = commit;
235
348
  return this;
236
349
  }
237
350
 
@@ -274,8 +387,8 @@ export class CommitCommand extends GitCommand<CommitResult> {
274
387
  }
275
388
 
276
389
  /**
277
- * `--reset-author`: an amended commit, or the commit that concludes a cherry-pick, is
278
- * authored as a new one (the author resolved as git resolves it, dated now) instead of
390
+ * `--reset-author`: an amended commit, a `-C` commit, or the commit that concludes a
391
+ * cherry-pick, is authored as a new one (the author resolved as git resolves it, dated now) instead of
279
392
  * keeping the earlier commit's author.
280
393
  *
281
394
  * @param reset Whether to reset the author
@@ -306,6 +419,29 @@ export class CommitCommand extends GitCommand<CommitResult> {
306
419
  return this;
307
420
  }
308
421
 
422
+ /**
423
+ * `-S` (true) / `--no-gpg-sign` (false): whether to sign the commit; undefined (the
424
+ * default) leaves it to `commit.gpgSign`. The commit is signed with the default key
425
+ * (`user.signingKey`, else as `gpg.format` says) through the host's signer
426
+ * (`GitHostEnvironment.signer`) and carries the signature in its `gpgsig` header
427
+ * ({@link signCommit}). Without a signer, or when it fails, the commit fails as git fails
428
+ * when gpg cannot sign (`error: gpg failed to sign the data:`, `fatal: failed to write
429
+ * commit object`, exit 128: {@link SigningFailedError}) once everything before the signing
430
+ * is done, and nothing is committed.
431
+ */
432
+ setSign(sign: boolean | undefined): this {
433
+ this.checkCallable();
434
+ this.sign = sign;
435
+ return this;
436
+ }
437
+
438
+ /** `-S<keyid>`: sign with this key (see {@link setSign}). */
439
+ setSigningKey(keyId: string): this {
440
+ this.checkCallable();
441
+ this.sign = keyId;
442
+ return this;
443
+ }
444
+
309
445
  /**
310
446
  * Set whether to amend the previous commit.
311
447
  *
@@ -376,6 +512,29 @@ export class CommitCommand extends GitCommand<CommitResult> {
376
512
  return this;
377
513
  }
378
514
 
515
+ /**
516
+ * `--pathspec-from-file` (and `--pathspec-file-nul` with `nul`): the pathspec elements of
517
+ * `content`, one per line (a line starting with `"` unquoted as a C string), or separated
518
+ * by NUL with `nul`, committed as {@link setOnly} paths (or {@link setInclude}'s with
519
+ * `setInclude()`). As git's prepare_index: refused with {@link setAll} ("options
520
+ * '--pathspec-from-file' and '-a' cannot be used together") and beside paths given to
521
+ * `setOnly`/`setInclude` ("'--pathspec-from-file' and pathspec arguments cannot be used
522
+ * together"); an empty file commits the index as it is (with `setInclude()`: "No paths
523
+ * with --include/--only does not make sense.").
524
+ *
525
+ * @example
526
+ * ```typescript
527
+ * await git.commit().setPathspecFromFile("src/a.ts\n").setMessage("Fix a").call();
528
+ * ```
529
+ *
530
+ * @throws InvalidArgumentError "fatal: line is badly quoted: <line>"
531
+ */
532
+ setPathspecFromFile(content: string | Uint8Array, nul = false): this {
533
+ this.checkCallable();
534
+ this.pathspecFile.read(content, nul);
535
+ return this;
536
+ }
537
+
379
538
  /**
380
539
  * Set whether to auto-stage modified tracked files before committing.
381
540
  *
@@ -481,6 +640,50 @@ export class CommitCommand extends GitCommand<CommitResult> {
481
640
  return this;
482
641
  }
483
642
 
643
+ /**
644
+ * `-c <commit>` / `--reedit-message=<commit>`: as {@link setReuseMessage} (or `-C` with {@link setEdit}(true)), with the message
645
+ * then given to the editor ({@link setEditor}; without one it is taken as it is).
646
+ */
647
+ setReeditMessage(commit: string): this {
648
+ this.checkCallable();
649
+ this.reeditMessageFrom = commit;
650
+ return this;
651
+ }
652
+
653
+ /**
654
+ * `--fixup=[(amend|reword):]<commit>`: a commit `rebase --autosquash` folds into `commit`.
655
+ * Plain, its message is `fixup! <subject>` (then the {@link setMessage} text, if any) and
656
+ * no editor runs. `amend:<commit>` makes `amend! <subject>` followed by the commit's whole
657
+ * message (its body alone when it is an `amend!` commit itself) for the editor to change,
658
+ * empty commits allowed and a message given with {@link setMessage} refused; `reword:` is
659
+ * `amend:` committing HEAD's tree (only the message changes), refused with paths, `-a`,
660
+ * `-i`, and during a merge or cherry-pick. An `amend!` message without a body is refused
661
+ * (`Aborting commit due to empty commit message body.`).
662
+ *
663
+ * @example
664
+ * ```typescript
665
+ * await git.commit().setFixup("HEAD~1").call();
666
+ * await git.commit().setFixup("reword:HEAD~1").setEditor(edit).call();
667
+ * ```
668
+ */
669
+ setFixup(commit: string): this {
670
+ this.checkCallable();
671
+ this.fixupSpec = commit;
672
+ return this;
673
+ }
674
+
675
+ /**
676
+ * `--squash=<commit>`: the message starts with `squash! <subject>` and a blank line, then
677
+ * the message given ({@link setMessage}, {@link setReuseMessage}: only `squash! ` when it
678
+ * names the same commit as given here), else what the editor makes of it. Refused with
679
+ * {@link setFixup}.
680
+ */
681
+ setSquash(commit: string): this {
682
+ this.checkCallable();
683
+ this.squashFrom = commit;
684
+ return this;
685
+ }
686
+
484
687
  /** `-e` / `--no-edit`: edit a given message too, or never edit (default: edit when none is given). */
485
688
  setEdit(edit: boolean): this {
486
689
  this.checkCallable();
@@ -560,6 +763,8 @@ export class CommitCommand extends GitCommand<CommitResult> {
560
763
  // ... and git_diff_ui_config: a diff.submodule without a value dies
561
764
  readDiffSubmoduleConfig(this.workingCopy);
562
765
  await this.readCurrentIndex();
766
+ await this.checkReuseOptions();
767
+ this.applyPathspecFile();
563
768
  // `-i` refuses what it refuses for a commit, before anything is read
564
769
  if (this.include) this.checkIncludeOptions();
565
770
  const state = new OperationState(this.workingCopy.checkout, this.refsStore);
@@ -620,7 +825,23 @@ export class CommitCommand extends GitCommand<CommitResult> {
620
825
  /** git's use_editor: an editor is set, and no message is given or `-e` asks for it. */
621
826
  private usesEditor(): boolean {
622
827
  if (!this.editor || this.edit === false) return false;
623
- return this.edit === true || this.message === undefined;
828
+ return this.edit === true || this.editsByDefault();
829
+ }
830
+
831
+ /**
832
+ * git's use_editor before `-e`/`--no-edit`: no message given (`-m`, `-C`) and no plain
833
+ * `--fixup`, whose messages are taken as they are.
834
+ */
835
+ private editsByDefault(): boolean {
836
+ if (this.message !== undefined || this.reuseMessage !== undefined) return false;
837
+ if (this.fixupSpec === undefined) return true;
838
+ const parsed = parseFixupSpec(this.fixupSpec);
839
+ return !("kind" in parsed) || parsed.kind !== "fixup";
840
+ }
841
+
842
+ /** The revision `-c` or `-C` names (git's use_message), as given. */
843
+ private reusedName(): string | undefined {
844
+ return this.reeditMessageFrom ?? this.reuseMessage;
624
845
  }
625
846
 
626
847
  /**
@@ -650,7 +871,11 @@ export class CommitCommand extends GitCommand<CommitResult> {
650
871
  const { state } = ctx;
651
872
  const config = RemoteConfigStore.from(this.workingCopy);
652
873
  const mode = editorCleanupMode(this.workingCopy, this.cleanupMode);
653
- const templateText = await this.readTemplate(config);
874
+ // (-m, -C, -c and --fixup drop the template: git frees template_file)
875
+ const templateText =
876
+ this.message !== undefined || this.reused || this.fixup
877
+ ? undefined
878
+ : await this.readTemplate(config);
654
879
  const rebasing = (await state.read("rebase-merge/head-name")) !== undefined;
655
880
  const whence: CommitWhence =
656
881
  ctx.mergeHeads.length > 0
@@ -665,7 +890,9 @@ export class CommitCommand extends GitCommand<CommitResult> {
665
890
  let cutLineAdded = false;
666
891
  const mergeMsg = await state.read("MERGE_MSG");
667
892
  const squashMsg = await state.read("SQUASH_MSG");
668
- if (this.message !== undefined) sb = completeLine(this.message);
893
+ const reusedMessage = await this.reusedMessage();
894
+ if (reusedMessage.text !== undefined) sb = reusedMessage.text;
895
+ else if (this.message !== undefined) sb = completeLine(this.message);
669
896
  else if (this.amend && ctx.previousCommit) {
670
897
  sb = ctx.previousCommit.message.replace(/^(?:[ \t\r]*\n)+/, "");
671
898
  } else if (mergeMsg !== undefined) {
@@ -676,14 +903,17 @@ export class CommitCommand extends GitCommand<CommitResult> {
676
903
  }
677
904
  } else if (squashMsg !== undefined) sb = squashMsg;
678
905
  else if (templateText !== undefined) sb = templateText;
906
+ sb = reusedMessage.prefix + sb;
679
907
  // clean_message_contents: not for a template, which goes in as it is
680
908
  const fromTemplate =
909
+ reusedMessage.text === undefined &&
681
910
  this.message === undefined &&
682
911
  !(this.amend && ctx.previousCommit) &&
683
912
  mergeMsg === undefined &&
684
913
  squashMsg === undefined &&
685
914
  templateText !== undefined;
686
915
  if (mode !== CleanupMode.VERBATIM && !fromTemplate) sb = stripspace(sb);
916
+ sb = this.signedOff(sb, ctx.committer);
687
917
  // core.commentChar=auto: a character the message does not start a line with
688
918
  const comment = commentPrefixOf(this.workingCopy, sb);
689
919
  // (a prepared message taken without an editor: as `--no-status`, unless asked for)
@@ -765,8 +995,10 @@ export class CommitCommand extends GitCommand<CommitResult> {
765
995
  : this.objectFormat.emptyTreeId;
766
996
  committable = ctx.treeId !== parentTree;
767
997
  }
768
- // COMMIT_EDITMSG written in full, then an empty commit refused before the editor runs
998
+ // COMMIT_EDITMSG written in full, its trailers added (amend_file_with_trailers), then an
999
+ // empty commit refused before the editor runs
769
1000
  await state.write("COMMIT_EDITMSG", template);
1001
+ template = await this.withTrailers(template, state, comment);
770
1002
  const isMerge = (ctx.previousCommit?.parents.length ?? 0) > 1;
771
1003
  if (!committable && whence !== "merge" && !this.allowEmpty && !(this.amend && isMerge)) {
772
1004
  throw new EmptyCommitError();
@@ -809,6 +1041,59 @@ export class CommitCommand extends GitCommand<CommitResult> {
809
1041
  };
810
1042
  }
811
1043
 
1044
+ /**
1045
+ * `-s`: the message so far with the committer's sign-off (append_signoff with
1046
+ * ignored_log_message_bytes: before trailing comments and the scissors line).
1047
+ */
1048
+ private signedOff(message: string, committer: PersonIdent): string {
1049
+ if (!this.signoff) return message;
1050
+ const config = trailerConfigOf(this.workingCopy);
1051
+ return appendSignoff(
1052
+ message,
1053
+ signoffLine(committer),
1054
+ config,
1055
+ false,
1056
+ ignoredLogMessageBytes(message, config.commentString),
1057
+ );
1058
+ }
1059
+
1060
+ /**
1061
+ * `--trailer`: COMMIT_EDITMSG (written as `message`) with the trailers added, as git's
1062
+ * amend_file_with_trailers (2.43: a child `interpret-trailers --in-place --no-divider`,
1063
+ * which takes an empty argument for nothing and refuses none); the new text, written back.
1064
+ */
1065
+ private async withTrailers(
1066
+ message: string,
1067
+ state: OperationState,
1068
+ comment: string | undefined,
1069
+ ): Promise<string> {
1070
+ if (this.trailerArgs.length === 0) return message;
1071
+ const hooks = this.hooks;
1072
+ const compatibility = hooks.compatibility;
1073
+ const config = {
1074
+ ...trailerConfigOf(this.workingCopy),
1075
+ ...(comment !== undefined ? { commentString: comment } : {}),
1076
+ compatibility,
1077
+ };
1078
+ let args = this.trailerArgs;
1079
+ if (compatibility === "2.43") args = args.filter((a) => a !== "");
1080
+ else {
1081
+ const refused = validateTrailerArgs(args, config);
1082
+ if (refused !== undefined) {
1083
+ throw new GitApiError(`${refused}\nfatal: unable to pass trailers to --trailers`, {
1084
+ exitCode: 128,
1085
+ });
1086
+ }
1087
+ }
1088
+ if (args.length === 0) return message;
1089
+ const runCommand: TrailerCommandRunner | undefined = hooks.enabled
1090
+ ? (command) => hooks.runShellCommand("trailer", command.command, command.args)
1091
+ : undefined;
1092
+ const { output } = await amendWithTrailers(message, args, config, runCommand);
1093
+ await state.write("COMMIT_EDITMSG", output);
1094
+ return output;
1095
+ }
1096
+
812
1097
  /**
813
1098
  * The commit template (`-t`, else `commit.template`, `~/` expanded) read through the host,
814
1099
  * undefined when none is set; one that cannot be read fails as git's `die_errno`.
@@ -969,11 +1254,14 @@ export class CommitCommand extends GitCommand<CommitResult> {
969
1254
  readShowUntrackedFiles(this.workingCopy);
970
1255
  // ... and git_diff_ui_config: a diff.submodule without a value dies
971
1256
  readDiffSubmoduleConfig(this.workingCopy);
1257
+ await this.parseAuthorOptions();
972
1258
  // the index as it is now: one another writer replaced is read again (git reads the
973
1259
  // index at its start), unless this instance holds unwritten edits (refused)
974
1260
  await this.readCurrentIndex();
1261
+ this.applyPathspecFile();
975
1262
  if (this.include) return this.commitIncluded();
976
- const partial = this.onlyPaths.length > 0;
1263
+ // `--fixup=reword:` is a partial commit of no path: HEAD's tree (git sets `only`)
1264
+ const partial = this.onlyPaths.length > 0 || this.fixup?.kind === "reword";
977
1265
  if (!this.all) return this.commitWith(partial, undefined);
978
1266
  // `-a` (git's COMMIT_NORMAL): the index lock held from before the tracked changes are
979
1267
  // staged until HEAD has moved
@@ -1008,6 +1296,345 @@ export class CommitCommand extends GitCommand<CommitResult> {
1008
1296
  }
1009
1297
  }
1010
1298
 
1299
+ /**
1300
+ * parse_and_validate_options' handling of `--author`, `-m` with `-C`, `--reset-author`,
1301
+ * and `-C`'s commit (read_commit_message), in git's order.
1302
+ */
1303
+ private async parseAuthorOptions(): Promise<void> {
1304
+ if (this.authorString !== undefined) {
1305
+ let text = this.authorString;
1306
+ if (!text.includes(">")) text = await this.findAuthorByNickname(text);
1307
+ if (this.resetAuthor) {
1308
+ throw new IncompatibleOptionsError(
1309
+ ["--reset-author", "--author"],
1310
+ "fatal: options '--reset-author' and '--author' cannot be used together",
1311
+ );
1312
+ }
1313
+ // split_ident_line: the name up to the `<` (trailing spaces dropped), the email up to
1314
+ // the first `>` after it
1315
+ const lt = text.indexOf("<");
1316
+ const gt = lt < 0 ? -1 : text.indexOf(">", lt + 1);
1317
+ if (gt < 0) {
1318
+ throw new InvalidArgumentError(
1319
+ "author",
1320
+ this.authorString,
1321
+ "fatal: malformed --author parameter",
1322
+ );
1323
+ }
1324
+ const name = text.slice(0, lt).replace(/[ \t\n\v\f\r]+$/, "");
1325
+ this.authorName = { name, email: text.slice(lt + 1, gt) };
1326
+ }
1327
+ await this.checkReuseOptions();
1328
+ if (this.forceDate) this.forcedDate();
1329
+ }
1330
+
1331
+ /** A blob's bytes, undefined when it cannot be read. */
1332
+ private async readBlobBytes(id: ObjectId): Promise<Uint8Array | undefined> {
1333
+ try {
1334
+ const content = await this.blobs.load(id);
1335
+ if (!content) return undefined;
1336
+ const chunks: Uint8Array[] = [];
1337
+ let size = 0;
1338
+ for await (const c of content) {
1339
+ chunks.push(c);
1340
+ size += c.length;
1341
+ }
1342
+ const out = new Uint8Array(size);
1343
+ let at = 0;
1344
+ for (const c of chunks) {
1345
+ out.set(c, at);
1346
+ at += c.length;
1347
+ }
1348
+ return out;
1349
+ } catch {
1350
+ return undefined;
1351
+ }
1352
+ }
1353
+
1354
+ /**
1355
+ * `--date` (parse_force_date): the date as `parse_date` reads it, else as `approxidate`
1356
+ * does, refused as git refuses it.
1357
+ */
1358
+ private forcedDate(): Pick<PersonIdent, "timestamp" | "tzOffset"> | undefined {
1359
+ if (!this.forceDate) return undefined;
1360
+ const { text } = this.forceDate;
1361
+ const parsed = parseGitDate(text);
1362
+ if (parsed) return parsed;
1363
+ const approx = approxidateCareful(text, this.forceDate.now ?? this.clock());
1364
+ // fmt_ident's parse_date of `@<seconds>`: the local offset of that time
1365
+ const date = approx.error ? undefined : parseGitDate(`@${approx.timestamp}`);
1366
+ if (!date) throw new InvalidDateError(text);
1367
+ return date;
1368
+ }
1369
+
1370
+ /**
1371
+ * builtin/commit.c's find_author_by_nickname: the first commit of `rev-list --all -i
1372
+ * --author=<name>` (newest first, the mailmap applied before matching) gives `%aN <%aE>`.
1373
+ */
1374
+ private async findAuthorByNickname(name: string): Promise<string> {
1375
+ let pattern: PosixRegex;
1376
+ try {
1377
+ pattern = compilePosixRegex(name, { icase: true });
1378
+ } catch (error) {
1379
+ throw new InvalidArgumentError(
1380
+ "author",
1381
+ name,
1382
+ `fatal: '${name}': ${error instanceof Error ? error.message : String(error)}`,
1383
+ );
1384
+ }
1385
+ const config = RemoteConfigStore.from(this.workingCopy);
1386
+ const mailmap = await readRepositoryMailmap({
1387
+ config: (key) => config.value(key),
1388
+ worktree: this.worktreeAccess,
1389
+ environment: hostEnvironmentOf(this.workingCopy),
1390
+ readBlobNamed: async (blob) => {
1391
+ const id = await this.revisionResolver()
1392
+ .resolve(blob)
1393
+ .catch(() => undefined);
1394
+ return id ? this.readBlobBytes(id) : undefined;
1395
+ },
1396
+ });
1397
+ const encoder = new TextEncoder();
1398
+ // revision.c's walk of --all: refs under refs/ in name order, then HEAD, tags peeled;
1399
+ // commits come out by commit date, newest first
1400
+ const starts: { name: string; id: ObjectId }[] = [];
1401
+ for await (const ref of this.refsStore.list()) {
1402
+ if (!ref.name.startsWith("refs/")) continue;
1403
+ let id = "objectId" in ref ? ref.objectId : undefined;
1404
+ if (!id) id = (await this.refsStore.resolve(ref.name).catch(() => undefined))?.objectId;
1405
+ if (id) starts.push({ name: ref.name, id });
1406
+ }
1407
+ starts.sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0));
1408
+ const head = (await this.refsStore.resolve("HEAD").catch(() => undefined))?.objectId;
1409
+ const ids = starts.map((s) => s.id);
1410
+ if (head) ids.push(head);
1411
+ const queue: { id: ObjectId; commit: Commit; date: number; order: number }[] = [];
1412
+ const seen = new Set<ObjectId>();
1413
+ let order = 0;
1414
+ const put = async (start: ObjectId) => {
1415
+ let id = start;
1416
+ const tags = this.tagsStore;
1417
+ for (let depth = 0; depth < 32 && tags && (await tags.has(id).catch(() => false)); depth++) {
1418
+ const tag = await tags.load(id).catch(() => undefined);
1419
+ if (!tag) break;
1420
+ id = tag.object;
1421
+ }
1422
+ if (seen.has(id)) return;
1423
+ const commit = await this.commits.load(id).catch(() => undefined);
1424
+ if (!commit) return;
1425
+ seen.add(id);
1426
+ queue.push({ id, commit, date: commit.committer.timestamp, order: order++ });
1427
+ };
1428
+ for (const id of ids) await put(id);
1429
+ while (queue.length > 0) {
1430
+ let best = 0;
1431
+ for (let i = 1; i < queue.length; i++) {
1432
+ const a = queue[i] as (typeof queue)[number];
1433
+ const b = queue[best] as (typeof queue)[number];
1434
+ if (a.date > b.date || (a.date === b.date && a.order < b.order)) best = i;
1435
+ }
1436
+ const [next] = queue.splice(best, 1);
1437
+ if (!next) break;
1438
+ const who = mailmap.map(next.commit.author.name, next.commit.author.email);
1439
+ if (pattern.test(encoder.encode(`${who.name} <${who.email}>`))) {
1440
+ return `${who.name} <${who.email}>`;
1441
+ }
1442
+ for (const parent of next.commit.parents) await put(parent);
1443
+ }
1444
+ throw new InvalidArgumentError(
1445
+ "author",
1446
+ name,
1447
+ `fatal: --author '${name}' is not 'Name <email>' and matches no existing author`,
1448
+ );
1449
+ }
1450
+
1451
+ /**
1452
+ * parse_and_validate_options for `-C`, `-c`, `--fixup` and `--squash`, in git's order: the
1453
+ * incompatible options, the commit `-C`/`-c` names read (`could not lookup commit`), then
1454
+ * `--fixup`'s suboption (`amend:`/`reword:` allow empty commits; `reword:` refuses paths,
1455
+ * `-a`, `-i` and a merge or cherry-pick in progress).
1456
+ */
1457
+ private async checkReuseOptions(): Promise<void> {
1458
+ if (this.fixupSpec !== undefined && this.squashFrom !== undefined) {
1459
+ throw new IncompatibleOptionsError(
1460
+ ["--squash", "--fixup"],
1461
+ "fatal: options '--squash' and '--fixup' cannot be used together",
1462
+ );
1463
+ }
1464
+ refuseIncompatible([
1465
+ ["-C", this.reuseMessage !== undefined],
1466
+ ["-c", this.reeditMessageFrom !== undefined],
1467
+ ["--fixup", this.fixupSpec !== undefined],
1468
+ ]);
1469
+ refuseIncompatible([
1470
+ ["-m", this.message !== undefined],
1471
+ ["-c", this.reeditMessageFrom !== undefined],
1472
+ ["-C", this.reuseMessage !== undefined],
1473
+ ]);
1474
+ const use = this.reusedName();
1475
+ if (use !== undefined) this.reused = await this.lookupCommit(use);
1476
+ if (this.fixupSpec === undefined) return;
1477
+ const parsed = parseFixupSpec(this.fixupSpec);
1478
+ if ("unknown" in parsed) {
1479
+ throw new InvalidArgumentError(
1480
+ "fixup",
1481
+ this.fixupSpec,
1482
+ `fatal: unknown option: --fixup=${parsed.unknown}:${parsed.target}`,
1483
+ );
1484
+ }
1485
+ this.fixup = parsed;
1486
+ if (parsed.kind === "fixup") return;
1487
+ this.allowEmpty = true;
1488
+ if (parsed.kind !== "reword") return;
1489
+ // check_fixup_reword_options
1490
+ const state = new OperationState(this.workingCopy.checkout, this.refsStore);
1491
+ if ((await this.mergeHeads(state)).length > 0) {
1492
+ throw new InvalidArgumentError(
1493
+ "fixup",
1494
+ this.fixupSpec,
1495
+ "fatal: You are in the middle of a merge -- cannot reword.",
1496
+ );
1497
+ }
1498
+ const pick = await state.ref("CHERRY_PICK_HEAD");
1499
+ // (a rebase stopped at a pick is no cherry-pick: git's is_from_cherry_pick)
1500
+ if (
1501
+ pick &&
1502
+ !(
1503
+ (await state.read("rebase-merge/head-name")) !== undefined &&
1504
+ (await state.ref("REBASE_HEAD")) === pick
1505
+ )
1506
+ ) {
1507
+ throw new InvalidArgumentError(
1508
+ "fixup",
1509
+ this.fixupSpec,
1510
+ "fatal: You are in the middle of a cherry-pick -- cannot reword.",
1511
+ );
1512
+ }
1513
+ const path = this.onlyPaths[0] ?? this.includePaths[0];
1514
+ if (path !== undefined) {
1515
+ throw new IncompatibleOptionsError(
1516
+ ["--fixup", "paths"],
1517
+ `fatal: reword option of '--fixup' and path '${path}' cannot be used together`,
1518
+ );
1519
+ }
1520
+ if (this.all || this.include) {
1521
+ throw new IncompatibleOptionsError(
1522
+ ["--fixup", "--all"],
1523
+ "fatal: reword option of '--fixup' and '--patch/--interactive/--all/--include/--only' cannot be used together",
1524
+ );
1525
+ }
1526
+ }
1527
+
1528
+ /** git's lookup_commit_reference_by_name, dying as `could not lookup commit '<name>'`. */
1529
+ private async lookupCommit(name: string): Promise<Commit> {
1530
+ const fatal = `fatal: could not lookup commit '${name}'`;
1531
+ let id: ObjectId;
1532
+ try {
1533
+ id = await this.resolveRevision(name);
1534
+ } catch (error) {
1535
+ if (error instanceof RefNotFoundError) throw new GitApiError(fatal);
1536
+ throw error;
1537
+ }
1538
+ const peeled = await this.revisionResolver().peelTags(id);
1539
+ const commit = peeled.type === "commit" ? await this.commits.load(peeled.id) : undefined;
1540
+ if (!commit) {
1541
+ throw new GitApiError(
1542
+ peeled.type
1543
+ ? `error: object ${peeled.id} is a ${peeled.type}, not a commit\n${fatal}`
1544
+ : fatal,
1545
+ );
1546
+ }
1547
+ return this.inCommitOutputEncoding(peeled.id, commit);
1548
+ }
1549
+
1550
+ /**
1551
+ * A commit's message and author as `git commit` reads another commit's (read_commit_message,
1552
+ * format_commit_message): converted from its `encoding` header into the commit output
1553
+ * encoding (`i18n.commitEncoding`, else UTF-8). Ours writes UTF-8 messages only, so a
1554
+ * commit is converted only when that encoding is UTF-8.
1555
+ */
1556
+ private async inCommitOutputEncoding(id: ObjectId, commit: Commit): Promise<Commit> {
1557
+ if (commit.encoding === undefined) return commit;
1558
+ const configured = RemoteConfigStore.from(this.workingCopy).value("i18n.commitEncoding");
1559
+ const output = configured ? configured : "UTF-8";
1560
+ if (!/^utf-?8$/i.test(output)) return commit;
1561
+ const raw = await this.readRawObject(id);
1562
+ const parts = raw && reencodedCommitParts(raw, output);
1563
+ if (!parts) return commit;
1564
+ return { ...commit, message: parts.message, ...(parts.author ? { author: parts.author } : {}) };
1565
+ }
1566
+
1567
+ /** The stored bytes of an object (undefined where the store cannot give them). */
1568
+ private async readRawObject(id: ObjectId): Promise<Uint8Array | undefined> {
1569
+ const objects = this.workingCopy.history?.objects;
1570
+ if (!objects) return undefined;
1571
+ try {
1572
+ const obj = await objects.get(id);
1573
+ if (!obj) return undefined;
1574
+ if (obj.bytes) return obj.bytes;
1575
+ const chunks: Uint8Array[] = [];
1576
+ let size = 0;
1577
+ for await (const c of obj.content) {
1578
+ chunks.push(c);
1579
+ size += c.length;
1580
+ }
1581
+ const out = new Uint8Array(size);
1582
+ let at = 0;
1583
+ for (const c of chunks) {
1584
+ out.set(c, at);
1585
+ at += c.length;
1586
+ }
1587
+ return out;
1588
+ } catch {
1589
+ return undefined;
1590
+ }
1591
+ }
1592
+
1593
+ /**
1594
+ * The start of prepare_to_commit's message from `-C`/`-c`/`--fixup`/`--squash`: the
1595
+ * `squash! ` subject (`prefix`, put before whatever message follows) and, for `-C`/`-c`
1596
+ * and `--fixup`, the text that replaces the other sources (undefined: they apply).
1597
+ */
1598
+ private async reusedMessage(): Promise<{ prefix: string; text: string | undefined }> {
1599
+ let prefix = "";
1600
+ if (this.squashFrom !== undefined) {
1601
+ prefix =
1602
+ (this.reusedName() ?? (this.amend && !this.fixup ? "HEAD" : undefined)) === this.squashFrom
1603
+ ? "squash! "
1604
+ : autosquashSubject("squash", (await this.lookupCommit(this.squashFrom)).message);
1605
+ }
1606
+ if (this.reused) return { prefix, text: skipBlankLines(this.reused.message) };
1607
+ if (!this.fixup) return { prefix, text: undefined };
1608
+ const target = await this.lookupCommit(this.fixup.target);
1609
+ if (this.fixup.kind === "fixup") {
1610
+ const given = this.message !== undefined ? completeLine(this.message) : "";
1611
+ return { prefix, text: autosquashSubject("fixup", target.message) + given };
1612
+ }
1613
+ if (this.message !== undefined) {
1614
+ throw new IncompatibleOptionsError(
1615
+ ["-m", "--fixup"],
1616
+ `fatal: options '-m' and '--fixup:${this.fixup.kind}' cannot be used together`,
1617
+ );
1618
+ }
1619
+ return {
1620
+ prefix,
1621
+ text: autosquashSubject("amend", target.message) + amendCommitText(target.message),
1622
+ };
1623
+ }
1624
+
1625
+ /**
1626
+ * prepare_index's `--pathspec-from-file`: refused with `-a` and beside pathspec arguments
1627
+ * ({@link setOnly}, {@link setInclude}); its elements are then the paths of `-i`, else of
1628
+ * `--only`.
1629
+ */
1630
+ private applyPathspecFile(): void {
1631
+ if (!this.pathspecFile.given) return;
1632
+ this.pathspecFile.refuse("-a", this.all);
1633
+ this.pathspecFile.refuseArguments([...this.onlyPaths, ...this.includePaths]);
1634
+ if (this.include) this.includePaths = [...this.pathspecFile.elements];
1635
+ else this.onlyPaths = [...this.pathspecFile.elements];
1636
+ }
1637
+
1011
1638
  /** `-i <paths>`: parse_and_validate_options' and prepare_index's refusals. */
1012
1639
  private checkIncludeOptions(): void {
1013
1640
  if (this.onlyPaths.length > 0) {
@@ -1058,6 +1685,13 @@ export class CommitCommand extends GitCommand<CommitResult> {
1058
1685
  const state = new OperationState(this.workingCopy.checkout, this.refsStore);
1059
1686
  const mergeHeads = await this.mergeHeads(state);
1060
1687
  const pickHead = await state.ref("CHERRY_PICK_HEAD");
1688
+ if (this.resetAuthor && !this.amend && !this.reused && !pickHead) {
1689
+ throw new InvalidArgumentError(
1690
+ "reset-author",
1691
+ true,
1692
+ "fatal: --reset-author can be used only with -C, -c or --amend.",
1693
+ );
1694
+ }
1061
1695
  if (this.amend && mergeHeads.length > 0) {
1062
1696
  throw new InvalidArgumentError(
1063
1697
  "amend",
@@ -1069,8 +1703,11 @@ export class CommitCommand extends GitCommand<CommitResult> {
1069
1703
  const headId = (await this.refsStore.resolve("HEAD"))?.objectId;
1070
1704
  let partialTree: ObjectId | undefined;
1071
1705
  let falseIndexFile: FalseIndexFile | undefined;
1706
+ // (`--fixup=reword:` names no path: the false index is HEAD's tree)
1072
1707
  const partialPaths = partial
1073
- ? await this.listPartialPaths(state, mergeHeads, headId)
1708
+ ? this.fixup?.kind === "reword"
1709
+ ? new Map<string, boolean>()
1710
+ : await this.listPartialPaths(state, mergeHeads, headId)
1074
1711
  : undefined;
1075
1712
  if (partialPaths) {
1076
1713
  // git's partial commit (prepare_index): the index lock taken once the paths are
@@ -1182,17 +1819,90 @@ export class CommitCommand extends GitCommand<CommitResult> {
1182
1819
  const mergeMsgPresent =
1183
1820
  (await state.read("MERGE_MSG")) !== undefined ||
1184
1821
  (await state.read("SQUASH_MSG")) !== undefined;
1822
+ const reused = this.reused;
1823
+ // (-c, --squash and --fixup=amend:/reword: prepare a message for the editor: without
1824
+ // one it is taken as it is, as with GIT_EDITOR=:)
1825
+ const preparedForEditor =
1826
+ this.reeditMessageFrom !== undefined ||
1827
+ this.squashFrom !== undefined ||
1828
+ (this.fixup !== undefined && this.fixup.kind !== "fixup");
1185
1829
  const editorLike =
1186
1830
  this.usesEditor() ||
1187
- (this.message === undefined && !this.amend && this.edit !== false && mergeMsgPresent);
1831
+ (this.edit !== false &&
1832
+ this.editsByDefault() &&
1833
+ ((!reused && !this.amend && mergeMsgPresent) || preparedForEditor));
1188
1834
  const editor: CommitEditor = this.usesEditor()
1189
1835
  ? (this.editor as CommitEditor)
1190
1836
  : async () => undefined;
1191
1837
  const message = this.message;
1192
- if (!editorLike && message === undefined && !this.amend && !mergeMsgPresent) {
1838
+ if (
1839
+ !editorLike &&
1840
+ message === undefined &&
1841
+ !reused &&
1842
+ !this.amend &&
1843
+ !mergeMsgPresent &&
1844
+ !this.fixup &&
1845
+ this.squashFrom === undefined
1846
+ ) {
1193
1847
  throw new NoMessageError();
1194
1848
  }
1195
1849
 
1850
+ let previousCommit: Commit | undefined;
1851
+ let amendedId: ObjectId | undefined;
1852
+
1853
+ if (this.amend) {
1854
+ const headId = await this.resolveHead();
1855
+ amendedId = headId;
1856
+ previousCommit = await this.commits.load(headId);
1857
+ if (!previousCommit) {
1858
+ throw new NoHeadError("Cannot amend: HEAD commit not found");
1859
+ }
1860
+ // (its message and author as git reads them: use_message = "HEAD")
1861
+ previousCommit = await this.inCommitOutputEncoding(headId, previousCommit);
1862
+ }
1863
+
1864
+ // The author (git's determine_author_info, which prepare_to_commit runs before the
1865
+ // pre-commit hook): the one given; else an amended commit's or
1866
+ // a concluded cherry-pick's author (its date too; `--author` replaces only the name and
1867
+ // email), unless --reset-author; else resolved as git does (GIT_AUTHOR_*, author.*,
1868
+ // user.*, GIT_AUTHOR_DATE or now)
1869
+ // (`--amend --fixup` keeps no author: git's author_message is use_message's, which
1870
+ // --fixup leaves unset)
1871
+ const amendKeeps = this.amend && !!previousCommit && !this.fixup;
1872
+ let author = this.author;
1873
+ if (!author) {
1874
+ // (git's author_message: a cherry-pick's CHERRY_PICK_HEAD, else -C's commit, else the
1875
+ // amended HEAD)
1876
+ const kept = this.resetAuthor
1877
+ ? undefined
1878
+ : pickHead
1879
+ ? (await this.commits.load(pickHead))?.author
1880
+ : reused
1881
+ ? reused.author
1882
+ : amendKeeps
1883
+ ? previousCommit?.author
1884
+ : undefined;
1885
+ // fmt_ident's IDENT_STRICT refusals of the name chosen (an empty one, crud only)
1886
+ if (kept || this.authorName) {
1887
+ strictAuthorName(
1888
+ this.authorName?.name ?? (kept as PersonIdent).name,
1889
+ this.authorName?.email ?? (kept as PersonIdent).email,
1890
+ );
1891
+ }
1892
+ if (kept) {
1893
+ author = this.authorName
1894
+ ? {
1895
+ ...kept,
1896
+ name: withoutCrud(this.authorName.name),
1897
+ email: withoutCrud(this.authorName.email),
1898
+ }
1899
+ : kept;
1900
+ } else if (this.authorName) author = this.datedIdent("author", this.authorName);
1901
+ else author = this.resolveAuthor(this.committer ?? this.committerName);
1902
+ }
1903
+ // --date: the author's date, whatever gave the rest
1904
+ const forced = this.forcedDate();
1905
+ if (forced) author = { ...author, ...forced };
1196
1906
  // prepare_to_commit's pre-commit hook (not with --no-verify), over the index the commit
1197
1907
  // records (the lock `-a` and a partial commit wrote); a hook that ran may have changed
1198
1908
  // the index, which is read again (git's discard_index + read_index_from)
@@ -1255,42 +1965,6 @@ export class CommitCommand extends GitCommand<CommitResult> {
1255
1965
  // a stored subtree no edit touched stays the one stored)
1256
1966
  treeId = await writeIndexAsTree(this.staging, this.trees, this.objectFormat);
1257
1967
  }
1258
- let previousCommit: Commit | undefined;
1259
- let amendedId: ObjectId | undefined;
1260
-
1261
- if (this.amend) {
1262
- const headId = await this.resolveHead();
1263
- amendedId = headId;
1264
- previousCommit = await this.commits.load(headId);
1265
- if (!previousCommit) {
1266
- throw new NoHeadError("Cannot amend: HEAD commit not found");
1267
- }
1268
- }
1269
-
1270
- // The author (git's determine_author_info): the one given; else an amended commit's or
1271
- // a concluded cherry-pick's author (its date too; `--author` replaces only the name and
1272
- // email), unless --reset-author; else resolved as git does (GIT_AUTHOR_*, author.*,
1273
- // user.*, GIT_AUTHOR_DATE or now)
1274
- let author = this.author;
1275
- if (!author) {
1276
- const kept = this.resetAuthor
1277
- ? undefined
1278
- : this.amend && previousCommit
1279
- ? previousCommit.author
1280
- : pickHead
1281
- ? (await this.commits.load(pickHead))?.author
1282
- : undefined;
1283
- if (kept) {
1284
- author = this.authorName
1285
- ? {
1286
- ...kept,
1287
- name: withoutCrud(this.authorName.name),
1288
- email: withoutCrud(this.authorName.email),
1289
- }
1290
- : kept;
1291
- } else if (this.authorName) author = this.datedIdent("author", this.authorName);
1292
- else author = this.resolveAuthor(this.committer ?? this.committerName);
1293
- }
1294
1968
  // the committer: always resolved (GIT_COMMITTER_*, committer.*, user.*), unless given
1295
1969
  const committer =
1296
1970
  this.committer ??
@@ -1313,7 +1987,11 @@ export class CommitCommand extends GitCommand<CommitResult> {
1313
1987
  previousCommit,
1314
1988
  author,
1315
1989
  committer,
1316
- authorKept: !this.author && !this.resetAuthor && (!!previousCommit || !!pickHead),
1990
+ // author_date_is_interesting: an author_message, or --date
1991
+ authorKept:
1992
+ !this.author &&
1993
+ (this.forceDate !== undefined ||
1994
+ (!this.resetAuthor && (amendKeeps || !!pickHead || !!reused))),
1317
1995
  hookEnv,
1318
1996
  },
1319
1997
  editor,
@@ -1328,16 +2006,22 @@ export class CommitCommand extends GitCommand<CommitResult> {
1328
2006
  // whitespace) is written to COMMIT_EDITMSG; then a commit with nothing to commit is
1329
2007
  // refused; then the file's text is cleaned up (cleanup_message) and checked
1330
2008
  cleanup = commitCleanupMode(this.workingCopy, this.cleanupMode);
2009
+ const reusedMessage = await this.reusedMessage();
1331
2010
  let sb: string;
1332
- if (message !== undefined) sb = completeLine(message);
2011
+ if (reusedMessage.text !== undefined) sb = reusedMessage.text;
2012
+ else if (message !== undefined) sb = completeLine(message);
1333
2013
  else if (previousCommit) sb = previousCommit.message.replace(/^(?:[ \t\r]*\n)+/, "");
1334
2014
  else {
1335
2015
  const mergeMsg = await state.read("MERGE_MSG");
1336
2016
  const squashMsg = await state.read("SQUASH_MSG");
1337
2017
  sb = mergeMsg !== undefined ? `${squashMsg ?? ""}${mergeMsg}` : (squashMsg ?? "");
1338
2018
  }
2019
+ sb = reusedMessage.prefix + sb;
1339
2020
  if (cleanup !== CleanupMode.VERBATIM) sb = stripspace(sb);
2021
+ sb = this.signedOff(sb, committer);
1340
2022
  await state.write("COMMIT_EDITMSG", sb);
2023
+ // amend_file_with_trailers over COMMIT_EDITMSG
2024
+ sb = await this.withTrailers(sb, state, undefined);
1341
2025
  await this.refuseNothingToCommit(treeId, parents, mergeHeads, previousCommit);
1342
2026
  // prepare-commit-msg and commit-msg, which may rewrite COMMIT_EDITMSG: the commit
1343
2027
  // takes the file's text (cmd_commit reads it back)
@@ -1380,6 +2064,13 @@ export class CommitCommand extends GitCommand<CommitResult> {
1380
2064
  if (untouched && !this.allowEmptyMessage) {
1381
2065
  throw new NoMessageError("Aborting commit; you did not edit the message.");
1382
2066
  }
2067
+ // an `amend!` message needs a body (the message the amended commit takes)
2068
+ if (this.fixup && finalMessage.startsWith("amend! ") && !this.allowEmptyMessage) {
2069
+ const body = finalMessage.slice(commitSubjectLength(finalMessage));
2070
+ if ((cleanup !== CleanupMode.VERBATIM || body.length === 0) && isEmptyMessage(body)) {
2071
+ throw new NoMessageError("Aborting commit due to empty commit message body.");
2072
+ }
2073
+ }
1383
2074
 
1384
2075
  return this.finishCommit(treeId, parents, mergeHeads, pickHead, {
1385
2076
  author,
@@ -1436,15 +2127,15 @@ export class CommitCommand extends GitCommand<CommitResult> {
1436
2127
  ): Promise<CommitResult> {
1437
2128
  const { author, committer, finalMessage, state, amendedId } = info;
1438
2129
 
1439
- // Create commit
1440
- const commit: Commit = {
1441
- tree: treeId,
1442
- parents,
1443
- author,
1444
- committer,
1445
- message: finalMessage,
1446
- };
1447
-
2130
+ // Create commit; commit_tree_extended signs it before writing it (without a signer, or
2131
+ // when the signer fails: git's failure, nothing written)
2132
+ const sign = signRequestOf(this.workingCopy, this.sign);
2133
+ const commit: Commit = await signCommit(
2134
+ this.workingCopy,
2135
+ sign,
2136
+ { tree: treeId, parents, author, committer, message: finalMessage },
2137
+ sign === undefined ? {} : { cwd: await this.signingCwd() },
2138
+ );
1448
2139
  const commitId = await this.commits.store(commit);
1449
2140
 
1450
2141
  // Update HEAD/branch ref, with git's reflog line in the branch's log and HEAD's
@@ -1507,6 +2198,15 @@ export class CommitCommand extends GitCommand<CommitResult> {
1507
2198
  return { ...commit, id: commitId };
1508
2199
  }
1509
2200
 
2201
+ /** The host directory the signing program runs in, if the repository has one. */
2202
+ private async signingCwd(): Promise<string | undefined> {
2203
+ try {
2204
+ return await this.hooks.hostWorkingDirectory();
2205
+ } catch {
2206
+ return undefined;
2207
+ }
2208
+ }
2209
+
1510
2210
  /**
1511
2211
  * The variables of the commit hooks (git's `run_commit_hook`): `GIT_INDEX_FILE` names the
1512
2212
  * index the commit records (the lock `-a` and a partial commit write; git's false index of
@@ -1557,7 +2257,12 @@ export class CommitCommand extends GitCommand<CommitResult> {
1557
2257
  mergeHeads: ObjectId[],
1558
2258
  pickHead: ObjectId | undefined,
1559
2259
  ): string[] {
2260
+ // --squash tells "message" whatever the message's source (an empty second argument)
2261
+ if (this.squashFrom !== undefined) return ["message", ""];
1560
2262
  if (this.message !== undefined) return ["message"];
2263
+ const reusedName = this.reusedName();
2264
+ if (reusedName !== undefined) return ["commit", reusedName];
2265
+ if (this.fixup) return ["message"];
1561
2266
  // --amend without a message reuses HEAD's (git's use_message = "HEAD")
1562
2267
  if (this.amend) return ["commit", "HEAD"];
1563
2268
  if (mergeMsg !== undefined) return [squashMsg !== undefined ? "squash" : "merge"];
@@ -1878,7 +2583,9 @@ export class CommitCommand extends GitCommand<CommitResult> {
1878
2583
  found.set(path, entry);
1879
2584
  }
1880
2585
  const trust = worktreeModeTrust(this.workingCopy, worktree);
1881
- const adder = await IndexAdder.open(this.staging, this.blobs, trust);
2586
+ const adder = await IndexAdder.open(this.staging, this.blobs, trust, {
2587
+ pathRules: worktreePathRules(this.workingCopy),
2588
+ });
1882
2589
  for (const path of taken) {
1883
2590
  const entry = found.get(path);
1884
2591
  if (entry) await adder.add(worktree, path, entry);
@@ -2143,3 +2850,14 @@ export interface CommitDryRunResult extends StatusTextResult {
2143
2850
  /** 0 when there is something to commit, 1 when not (dry_run_commit) */
2144
2851
  exitCode: number;
2145
2852
  }
2853
+
2854
+ /**
2855
+ * fmt_ident's IDENT_STRICT checks of an author name given or kept (`--author`, `-C`,
2856
+ * `--amend`): an empty name, or one of crud only, refused with git's line.
2857
+ */
2858
+ function strictAuthorName(name: string, email: string): void {
2859
+ if (name === "") throw new InvalidIdentError("author", "empty", email, false);
2860
+ if (![...name].some((c) => !(c <= " " || ",:;<>\"\\'".includes(c)))) {
2861
+ throw new InvalidIdentError("author", "crud", name, false);
2862
+ }
2863
+ }