@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
@@ -6,7 +6,12 @@
6
6
  * `--continue`, `--skip` or `--abort` what we started and the other way round.
7
7
  */
8
8
 
9
- import type { Commit, ObjectId, PersonIdent } from "@statewalker/vcs-core";
9
+ import {
10
+ type Commit,
11
+ type ObjectId,
12
+ objectFormatOf,
13
+ type PersonIdent,
14
+ } from "@statewalker/vcs-core";
10
15
  import { compareGitPaths, parseGitBool } from "@statewalker/vcs-utils/encoding";
11
16
  import type { Worktree } from "@statewalker/vcs-working-tree";
12
17
  import { GitApiError } from "../errors/git-api-error.js";
@@ -16,6 +21,7 @@ import {
16
21
  } from "../errors/merge-errors.js";
17
22
  import { NotACommitError, RefNotFoundError } from "../errors/ref-errors.js";
18
23
  import type { CommandCommits, CommandRefs, CommandTrees } from "../git-command.js";
24
+ import { RemoteConfigStore } from "../remote-config/index.js";
19
25
  import { coreBool, createIdAbbreviator, type IdAbbreviator } from "./core-config.js";
20
26
  import { type HookSession, sequencerPostCommit, sequencerPrepareMessage } from "./git-hooks.js";
21
27
  import { authorIdentOf, committerIdentOf } from "./git-ident.js";
@@ -45,6 +51,8 @@ import {
45
51
  removeBranchState,
46
52
  resetMerge,
47
53
  } from "./sequencer-support.js";
54
+ import { SigningFailedError, type SignRequest, signCommit, signRequestOf } from "./signing.js";
55
+ import { appendSignoff, signoffLine, trailerConfigOf, trailerLinesOf } from "./trailers.js";
48
56
 
49
57
  /** What the sequencer does with each commit. */
50
58
  export type PickAction = "pick" | "revert";
@@ -100,7 +108,7 @@ export interface SequencerDeps extends MergeWriteContext {
100
108
 
101
109
  /** The `git commit` the sequencer runs (see {@link SequencerDeps.gitCommit}). */
102
110
  export type PickCommitMode =
103
- | { kind: "pick"; reflogAction: string }
111
+ | { kind: "pick"; reflogAction: string; allowEmpty?: boolean }
104
112
  | { kind: "continue"; edit: boolean };
105
113
 
106
114
  /** Options of one sequencer run. */
@@ -126,6 +134,121 @@ export interface PickOptions {
126
134
  * (git's `options.edit`), left out when neither was given.
127
135
  */
128
136
  edit?: boolean;
137
+ /**
138
+ * `-S[<keyid>]` (true or the key) / `--no-gpg-sign` (false); undefined: `commit.gpgSign`.
139
+ * Saved in `sequencer/opts` (`options.gpg-sign`) for a run of several commits.
140
+ */
141
+ sign?: boolean | string;
142
+ /** `-x`: `(cherry picked from commit <id>)` appended to a pick's message (record_origin) */
143
+ recordOrigin?: boolean;
144
+ /** `-s` / `--signoff`: the committer's `Signed-off-by:` appended (append_signoff) */
145
+ signoff?: boolean;
146
+ /** `--allow-empty`: a commit empty in itself (its tree its first parent's) is committed */
147
+ allowEmpty?: boolean;
148
+ /** `--allow-empty-message` (saved in `sequencer/opts`; the sequencer commits any message) */
149
+ allowEmptyMessage?: boolean;
150
+ /**
151
+ * `--keep-redundant-commits` / `--empty=keep`: a commit that becomes empty is committed
152
+ * (implies {@link allowEmpty})
153
+ */
154
+ keepRedundant?: boolean;
155
+ /** `--empty=drop`: a commit that becomes empty is dropped, git's `dropping ...` line printed */
156
+ dropRedundant?: boolean;
157
+ /** `--ff`: a commit whose parent is HEAD is fast-forwarded to, not picked */
158
+ allowFf?: boolean;
159
+ /**
160
+ * `revert --reference` (or `revert.reference`): the reverted commit named as
161
+ * `<abbrev> (<subject>, <date>)` under a `*** SAY WHY ...` comment for the title
162
+ */
163
+ reference?: boolean;
164
+ }
165
+
166
+ /** The flags of a run, read back from `sequencer/opts` (git's replay_opts). */
167
+ interface PickFlags {
168
+ noCommit: boolean;
169
+ mainline?: number;
170
+ recordOrigin: boolean;
171
+ signoff: boolean;
172
+ allowEmpty: boolean;
173
+ allowEmptyMessage: boolean;
174
+ keepRedundant: boolean;
175
+ dropRedundant: boolean;
176
+ allowFf: boolean;
177
+ }
178
+
179
+ /** commit.cleanup as the sequencer reads it (git_sequencer_config). */
180
+ type SequencerCleanup = "whitespace" | "verbatim" | "scissors" | "strip";
181
+
182
+ /**
183
+ * builtin/revert.c's verify_opt_compatible: the `fatal:` line refusing an option that cannot
184
+ * go with `--continue`/`--skip`/`--abort`/`--quit` or with `--ff`, as git checks them; undefined
185
+ * when the options go together.
186
+ */
187
+ export function pickOptionsConflict(
188
+ action: PickAction,
189
+ operation: SequencerOperation,
190
+ options: PickOptions & { emptyGiven?: boolean },
191
+ /** git 2.43 lets `--keep-redundant-commits` and `--empty` go with the operations */
192
+ compatibility?: "2.43" | "2.56",
193
+ ): string | undefined {
194
+ const me = ACTION_NAME[action];
195
+ const keep = !!options.keepRedundant;
196
+ if (operation !== SequencerOperation.START) {
197
+ const op = `--${operation}`;
198
+ const given: [string, boolean][] = [
199
+ ["--no-commit", !!options.noCommit],
200
+ ["--signoff", !!options.signoff],
201
+ ["--mainline", !!options.mainline],
202
+ ["-x", !!options.recordOrigin],
203
+ ["--ff", !!options.allowFf],
204
+ ["--keep-redundant-commits", keep && compatibility !== "2.43"],
205
+ ["--empty", !!options.emptyGiven && compatibility !== "2.43"],
206
+ ];
207
+ const first = given.find(([, on]) => on);
208
+ if (first) return `fatal: ${me}: ${first[0]} cannot be used with ${op}`;
209
+ }
210
+ if (options.allowFf) {
211
+ const given: [string, boolean][] = [
212
+ ["--signoff", !!options.signoff],
213
+ ["--no-commit", !!options.noCommit],
214
+ ["-x", !!options.recordOrigin],
215
+ ["--edit", options.edit === true],
216
+ ];
217
+ const first = given.find(([, on]) => on);
218
+ if (first) return `fatal: ${me}: ${first[0]} cannot be used with --ff`;
219
+ }
220
+ return undefined;
221
+ }
222
+
223
+ /** The boolean options of `sequencer/opts` (populate_opts_cb). */
224
+ const SAVED_FLAGS: Record<string, keyof Omit<PickFlags, "mainline"> | undefined> = {
225
+ "no-commit": "noCommit",
226
+ "allow-empty": "allowEmpty",
227
+ "allow-empty-message": "allowEmptyMessage",
228
+ "drop-redundant-commits": "dropRedundant",
229
+ "keep-redundant-commits": "keepRedundant",
230
+ signoff: "signoff",
231
+ "record-origin": "recordOrigin",
232
+ "allow-ff": "allowFf",
233
+ };
234
+
235
+ /** git_sequencer_config's commit.cleanup (get_cleanup_mode for a saved one). */
236
+ function cleanupOf(value: string | undefined): SequencerCleanup | undefined {
237
+ switch (value) {
238
+ case "verbatim":
239
+ case "whitespace":
240
+ case "strip":
241
+ case "scissors":
242
+ return value;
243
+ default:
244
+ return undefined;
245
+ }
246
+ }
247
+
248
+ function configuredCleanup(
249
+ workingCopy: SequencerDeps["workingCopy"],
250
+ ): SequencerCleanup | undefined {
251
+ return cleanupOf(RemoteConfigStore.from(workingCopy).value("commit.cleanup"));
129
252
  }
130
253
 
131
254
  const ACTION_NAME = { pick: "cherry-pick", revert: "revert" } as const;
@@ -147,6 +270,12 @@ export class PickSequencer {
147
270
  private readonly abbreviator: IdAbbreviator;
148
271
  /** `--edit` / `--no-edit` (git's opts->edit, unset: undefined), read back from the opts */
149
272
  private edit: boolean | undefined;
273
+ /** What the commits are signed with (git's opts->gpg_sign), read back from the opts */
274
+ private sign: SignRequest;
275
+ /** The flags of the run (given, or read back from `sequencer/opts`) */
276
+ private readonly flags: PickFlags;
277
+ /** commit.cleanup (git's default_msg_cleanup with explicit_cleanup), or saved in the opts */
278
+ private cleanup: SequencerCleanup | undefined;
150
279
 
151
280
  constructor(
152
281
  private readonly deps: SequencerDeps,
@@ -155,6 +284,25 @@ export class PickSequencer {
155
284
  this.flats = new FlatTreeCache(deps.trees);
156
285
  this.abbreviator = createIdAbbreviator(deps.workingCopy);
157
286
  this.edit = options.edit;
287
+ this.sign = signRequestOf(deps.workingCopy, options.sign);
288
+ const keepRedundant = !!options.keepRedundant;
289
+ this.flags = {
290
+ noCommit: !!options.noCommit,
291
+ mainline: options.mainline,
292
+ recordOrigin: !!options.recordOrigin,
293
+ signoff: !!options.signoff,
294
+ // --keep-redundant-commits implies --allow-empty (run_sequencer)
295
+ allowEmpty: !!options.allowEmpty || keepRedundant,
296
+ allowEmptyMessage: !!options.allowEmptyMessage,
297
+ keepRedundant,
298
+ dropRedundant: !!options.dropRedundant,
299
+ allowFf: !!options.allowFf,
300
+ };
301
+ this.cleanup = configuredCleanup(deps.workingCopy);
302
+ }
303
+
304
+ private config(key: string): string | undefined {
305
+ return RemoteConfigStore.from(this.deps.workingCopy).value(key);
158
306
  }
159
307
 
160
308
  private get name(): string {
@@ -169,6 +317,10 @@ export class PickSequencer {
169
317
  async start(names: string[]): Promise<PickOutcome> {
170
318
  const { state } = this.deps;
171
319
  const { unmerged } = await readIndex(this.deps.staging);
320
+ if (unmerged.length > 0 && this.flags.noCommit) {
321
+ // do_pick_commit's write_index_as_tree fails first
322
+ return this.fail(`error: your index file is unmerged.\nfatal: ${this.name} failed`);
323
+ }
172
324
  if (unmerged.length > 0) {
173
325
  return this.fail(
174
326
  [
@@ -185,17 +337,42 @@ export class PickSequencer {
185
337
  );
186
338
  }
187
339
  const ids: ObjectId[] = [];
188
- for (const name of names) ids.push(await this.resolvePick(name));
340
+ let lastNamed = "";
341
+ for (const name of names) {
342
+ const id = await this.resolvePick(name);
343
+ lastNamed = id;
344
+ // the revision walk lists each commit once (its SEEN flag), first naming first
345
+ if (!ids.includes(id)) ids.push(id);
346
+ }
189
347
  const todo = ids.map((id) => ({ action: this.options.action, id }));
190
- const headId = await this.headId();
191
348
  if (todo.length > 1) {
192
- await state.write("sequencer/head", `${headId}\n`);
349
+ // sequencer_pick_revisions on an unborn HEAD refuses only a revert; a pick saves as
350
+ // sequencer/head what its failed repo_get_oid("HEAD") left in `oid`, which in git 2.43
351
+ // and 2.56 builds alike is the id of the last commit named (the loop over the pending
352
+ // revisions shares its stack slot), and an empty abort-safety
353
+ const headId = await this.headIfBorn();
354
+ if (!headId && this.options.action === "revert") {
355
+ return this.fail(`error: can't revert as initial commit\nfatal: ${this.name} failed`);
356
+ }
357
+ await state.write("sequencer/head", `${headId ?? lastNamed}\n`);
193
358
  await this.writeTodo(todo);
194
- await state.write("sequencer/abort-safety", `${headId}\n`);
195
- // save_opts: options.no-commit, then options.edit when given (git config's format)
359
+ await state.write("sequencer/abort-safety", `${headId ?? ""}\n`);
360
+ // save_opts, in its order (git config's format)
361
+ const f = this.flags;
196
362
  const opts: string[] = [];
197
- if (this.options.noCommit) opts.push("\tno-commit = true\n");
363
+ const flag = (name: string, on: boolean) => on && opts.push(`\t${name} = true\n`);
364
+ flag("no-commit", f.noCommit);
198
365
  if (this.edit !== undefined) opts.push(`\tedit = ${this.edit}\n`);
366
+ flag("allow-empty", f.allowEmpty);
367
+ flag("allow-empty-message", f.allowEmptyMessage);
368
+ flag("drop-redundant-commits", f.dropRedundant);
369
+ flag("keep-redundant-commits", f.keepRedundant);
370
+ flag("signoff", f.signoff);
371
+ flag("record-origin", f.recordOrigin);
372
+ flag("allow-ff", f.allowFf);
373
+ if (f.mainline) opts.push(`\tmainline = ${f.mainline}\n`);
374
+ if (this.sign !== undefined) opts.push(`\tgpg-sign = ${this.sign}\n`);
375
+ if (this.cleanup) opts.push(`\tdefault-msg-cleanup = ${this.cleanup}\n`);
199
376
  if (opts.length > 0) await state.write("sequencer/opts", `[options]\n${opts.join("")}`);
200
377
  }
201
378
  return this.run(todo, todo.length > 1);
@@ -221,14 +398,17 @@ export class PickSequencer {
221
398
  private async run(todo: TodoItem[], sequenced: boolean): Promise<PickOutcome> {
222
399
  const output: string[] = [];
223
400
  const picked: ObjectId[] = [];
224
- let newHead = await this.headId();
401
+ let newHead = await this.headIfBorn();
225
402
  for (let k = 0; k < todo.length; k++) {
226
403
  const item = todo[k];
227
404
  const outcome = await this.pickOne(item, output);
228
405
  if (outcome.status !== "ok") {
229
406
  if (sequenced) {
230
407
  await this.writeTodo(todo.slice(k));
231
- await this.deps.state.write("sequencer/abort-safety", `${await this.headId()}\n`);
408
+ await this.deps.state.write(
409
+ "sequencer/abort-safety",
410
+ `${(await this.headIfBorn()) ?? ""}\n`,
411
+ );
232
412
  }
233
413
  return { ...outcome, picked, output };
234
414
  }
@@ -236,7 +416,7 @@ export class PickSequencer {
236
416
  newHead = outcome.newHead ?? newHead;
237
417
  if (sequenced) {
238
418
  await this.writeTodo(todo.slice(k + 1));
239
- await this.deps.state.write("sequencer/abort-safety", `${newHead}\n`);
419
+ await this.deps.state.write("sequencer/abort-safety", `${newHead ?? ""}\n`);
240
420
  }
241
421
  }
242
422
  if (sequenced) await this.deps.state.remove("sequencer");
@@ -245,44 +425,58 @@ export class PickSequencer {
245
425
 
246
426
  /** One commit's change merged into HEAD (do_pick_commit). */
247
427
  private async pickOne(item: TodoItem, output: string[]): Promise<PickOutcome> {
248
- const { deps } = this;
428
+ const { deps, flags } = this;
249
429
  const action = item.action;
430
+ const name = ACTION_NAME[action];
431
+ const format = objectFormatOf(deps.workingCopy.history);
250
432
  const commit = await deps.commits.load(item.id);
251
433
  if (!commit) throw new RefNotFoundError(item.id, `Cannot find commit: ${item.id}`);
252
- const headId = await this.headId();
253
- const headCommit = await deps.commits.load(headId);
254
- if (!headCommit) throw new RefNotFoundError(headId, "HEAD commit not found");
434
+ // an unborn HEAD picks onto the empty tree (repo_get_oid fails: `unborn`)
435
+ const headId = await this.headIfBorn();
436
+ const headCommit = headId ? await deps.commits.load(headId) : undefined;
437
+ if (headId && !headCommit) throw new RefNotFoundError(headId, "HEAD commit not found");
438
+ const headTree = headCommit?.tree ?? format.emptyTreeId;
255
439
  // with --no-commit the change is merged into the index as it is (git's
256
440
  // write_index_as_tree): each commit's change on top of the previous one's
257
- const headTreeId = this.options.noCommit
258
- ? await writeIndexAsTree(deps.staging, deps.trees)
259
- : headCommit.tree;
441
+ const headTreeId = flags.noCommit
442
+ ? await writeIndexAsTree(deps.staging, deps.trees, format)
443
+ : headTree;
260
444
  // a commit is never made on top of staged changes (error_dirty_index)
261
445
  const { index } = await readIndex(deps.staging);
262
- if (
263
- !this.options.noCommit &&
264
- (await indexChangesFromTree(index, deps.trees, headTreeId)).length > 0
265
- ) {
446
+ if (!flags.noCommit && (await indexChangesFromTree(index, deps.trees, headTreeId)).length > 0) {
266
447
  return this.fail(
267
- `error: your local changes would be overwritten by ${ACTION_NAME[action]}.\nhint: commit your changes or stash them to proceed.\nfatal: ${ACTION_NAME[action]} failed`,
448
+ `error: your local changes would be overwritten by ${name}.\nhint: commit your changes or stash them to proceed.\nfatal: ${name} failed`,
268
449
  );
269
450
  }
270
451
 
271
- // the parent the change is taken against
452
+ // the parent the change is taken against (`-m`: a merge's parent, at most 1 otherwise)
272
453
  let parentId: ObjectId | undefined;
454
+ const mainline = flags.mainline;
455
+ const noParent = (n: number) =>
456
+ new InvalidMainlineParentError(
457
+ n,
458
+ commit.parents.length,
459
+ `error: commit ${item.id} does not have parent ${n}\nfatal: ${name} failed`,
460
+ );
273
461
  if (commit.parents.length > 1) {
274
- if (this.options.mainline === undefined) {
462
+ if (!mainline) {
275
463
  throw new MultipleParentsNotAllowedError(
276
- `error: commit ${item.id} is a merge but no -m option was given.\nfatal: ${ACTION_NAME[action]} failed`,
464
+ `error: commit ${item.id} is a merge but no -m option was given.\nfatal: ${name} failed`,
277
465
  );
278
466
  }
279
- if (this.options.mainline < 1 || this.options.mainline > commit.parents.length) {
280
- throw new InvalidMainlineParentError(this.options.mainline, commit.parents.length);
281
- }
282
- parentId = commit.parents[this.options.mainline - 1];
467
+ if (mainline > commit.parents.length) throw noParent(mainline);
468
+ parentId = commit.parents[mainline - 1];
469
+ } else if (mainline !== undefined && mainline > 1) {
470
+ throw noParent(mainline);
283
471
  } else {
284
472
  parentId = commit.parents[0];
285
473
  }
474
+
475
+ // --ff: a commit on HEAD (a root commit on an unborn branch) is fast-forwarded to
476
+ if (flags.allowFf && ((parentId && parentId === headId) || (!parentId && !headId))) {
477
+ return this.fastForward(item.id, headId, headTree, commit.tree, output);
478
+ }
479
+
286
480
  const parentTreeId = parentId ? await deps.commits.getTree(parentId) : undefined;
287
481
  const subject = subjectOf(commit.message);
288
482
  // get_message: short_commit_name, repo_find_unique_abbrev with DEFAULT_ABBREV
@@ -318,25 +512,25 @@ export class PickSequencer {
318
512
  const delta = await treeDelta(deps.trees, headTreeId, treeId);
319
513
  const refused = await switchTrees(deps, delta.from, delta.to, {
320
514
  action: "merge",
321
- operation: ACTION_NAME[action],
515
+ operation: name,
322
516
  conflicts,
323
517
  targetTree: treeId,
324
518
  });
325
519
  if (refused) {
326
- return this.fail(`${refused.message}\nfatal: ${ACTION_NAME[action]} failed`);
520
+ return this.fail(`${refused.message}\nfatal: ${name} failed`);
327
521
  }
328
522
  output.push(...merge.messages);
329
523
  await deps.state.setRef("AUTO_MERGE", treeId);
330
- const message = this.messageFor(action, item.id, commit, parentId);
524
+ const message = await this.messageFor(action, item.id, commit, parentId);
331
525
 
332
526
  if (conflicts.length > 0 || !merge.clean) {
333
527
  const paths = [...new Set(conflicts.map((c) => c.stagePath))].sort(compareGitPaths);
334
528
  // git records REVERT_HEAD for a revert -n too (do_pick_commit), never CHERRY_PICK_HEAD
335
- if (!this.options.noCommit || action === "revert") {
529
+ if (!flags.noCommit || action === "revert") {
336
530
  await deps.state.setRef(HEAD_REF[action], item.id);
337
531
  }
338
532
  await deps.state.write("MERGE_MSG", `${message}${conflictsComment(paths, true)}`);
339
- const advice = this.options.noCommit
533
+ const advice = flags.noCommit
340
534
  ? [
341
535
  "hint: after resolving the conflicts, mark the corrected paths",
342
536
  "hint: with 'git add <paths>' or 'git rm <paths>'",
@@ -344,10 +538,10 @@ export class PickSequencer {
344
538
  : [
345
539
  "hint: After resolving the conflicts, mark them with",
346
540
  'hint: "git add/rm <pathspec>", then run',
347
- `hint: "git ${ACTION_NAME[action]} --continue".`,
348
- `hint: You can instead skip this commit with "git ${ACTION_NAME[action]} --skip".`,
349
- `hint: To abort and get back to the state before "git ${ACTION_NAME[action]}",`,
350
- `hint: run "git ${ACTION_NAME[action]} --abort".`,
541
+ `hint: "git ${name} --continue".`,
542
+ `hint: You can instead skip this commit with "git ${name} --skip".`,
543
+ `hint: To abort and get back to the state before "git ${name}",`,
544
+ `hint: run "git ${name} --abort".`,
351
545
  ];
352
546
  return {
353
547
  status: "conflicting",
@@ -360,28 +554,55 @@ export class PickSequencer {
360
554
  ].join("\n"),
361
555
  };
362
556
  }
363
- if (this.options.noCommit) {
364
- await deps.state.write("MERGE_MSG", message);
365
- if (action === "revert") await deps.state.setRef(HEAD_REF[action], item.id);
557
+ // a clean merge: CHERRY_PICK_HEAD (not with --no-commit), MERGE_MSG, REVERT_HEAD for a
558
+ // revert -n, before allow_empty and do_commit (a commit that fails leaves them)
559
+ if (action === "pick" && !flags.noCommit) await deps.state.setRef(HEAD_REF[action], item.id);
560
+ await deps.state.write("MERGE_MSG", message);
561
+ if (action === "revert" && flags.noCommit) await deps.state.setRef(HEAD_REF[action], item.id);
562
+
563
+ // allow_empty: a result equal to HEAD's tree is committed (1), dropped (2) or stops (0)
564
+ let allow: 0 | 1 | 2 = 0;
565
+ if (treeId === headTree) {
566
+ const firstParentTree = commit.parents[0]
567
+ ? await deps.commits.getTree(commit.parents[0])
568
+ : format.emptyTreeId;
569
+ const originallyEmpty = firstParentTree === commit.tree;
570
+ allow = originallyEmpty
571
+ ? flags.allowEmpty
572
+ ? 1
573
+ : 0
574
+ : flags.keepRedundant
575
+ ? 1
576
+ : flags.dropRedundant
577
+ ? 2
578
+ : 0;
579
+ }
580
+ if (allow === 2) {
581
+ await deps.state.deleteRef("CHERRY_PICK_HEAD");
582
+ await deps.state.remove("MERGE_MSG");
583
+ await deps.state.deleteRef("AUTO_MERGE");
584
+ output.push(`dropping ${item.id} ${subject} -- patch contents already upstream`);
585
+ return { status: "ok", newHead: headId, picked: [item.id], output };
586
+ }
587
+ if (flags.noCommit) {
366
588
  return { status: "ok", newHead: headId, picked: [item.id], output };
367
589
  }
368
- if (treeId === headCommit.tree) {
369
- // nothing to commit: git stops, the pick in progress, for --allow-empty or --skip
370
- // (CHERRY_PICK_HEAD only: git records REVERT_HEAD for a revert that conflicts)
371
- if (action === "pick") await deps.state.setRef(HEAD_REF[action], item.id);
372
- await deps.state.write("MERGE_MSG", message);
590
+ if (treeId === headTree && allow === 0) {
591
+ // nothing to commit: try_to_commit leaves it to `git commit`, which stops, the pick in
592
+ // progress, for `git commit --allow-empty` or --skip (CHERRY_PICK_HEAD only: git
593
+ // records REVERT_HEAD for a revert that conflicts)
373
594
  return {
374
595
  status: "conflicting",
375
596
  conflicts: [],
376
597
  picked: [],
377
598
  output,
378
599
  message: [
379
- `The previous ${ACTION_NAME[action]} is now empty, possibly due to conflict resolution.`,
600
+ `The previous ${name} is now empty, possibly due to conflict resolution.`,
380
601
  "If you wish to commit it anyway, use:",
381
602
  "",
382
603
  " git commit --allow-empty",
383
604
  "",
384
- `Otherwise, please use 'git ${ACTION_NAME[action]} --skip'`,
605
+ `Otherwise, please use 'git ${name} --skip'`,
385
606
  ].join("\n"),
386
607
  };
387
608
  }
@@ -389,13 +610,12 @@ export class PickSequencer {
389
610
  // do_pick_commit with EDIT_MSG: the message in MERGE_MSG, CHERRY_PICK_HEAD for a pick
390
611
  // (git commit then takes its author and says it concludes a cherry-pick), then
391
612
  // run_git_commit; git commit cleans up after itself (CHERRY_PICK_HEAD, MERGE_MSG)
392
- if (action === "pick") await deps.state.setRef(HEAD_REF[action], item.id);
393
- await deps.state.write("MERGE_MSG", message);
394
613
  let newHead: ObjectId;
395
614
  try {
396
615
  newHead = await deps.gitCommit({
397
616
  kind: "pick",
398
- reflogAction: this.options.reflogAction ?? ACTION_NAME[action],
617
+ reflogAction: this.options.reflogAction ?? name,
618
+ allowEmpty: allow === 1,
399
619
  });
400
620
  } catch (error) {
401
621
  if (!(error instanceof GitApiError)) throw error;
@@ -404,20 +624,15 @@ export class PickSequencer {
404
624
  }
405
625
  return { status: "ok", newHead, picked: [item.id], output };
406
626
  }
407
- // do_pick_commit records CHERRY_PICK_HEAD for a clean pick too, and writes MERGE_MSG,
408
- // before do_commit: a commit that fails (HEAD's lock held) leaves both
409
- if (action === "pick") await deps.state.setRef(HEAD_REF[action], item.id);
410
- await deps.state.write("MERGE_MSG", message);
411
627
  const committer = this.committer();
412
- const commitMessage = action === "pick" ? commit.message : message;
413
628
  const newHead = await this.commit(
414
629
  treeId,
415
- [headId],
630
+ headId ? [headId] : [],
416
631
  action === "pick" ? commit.author : this.revertAuthor(committer),
417
632
  committer,
418
- commitMessage,
633
+ message,
419
634
  // the sequencer's update_head_with_reflog: "cherry-pick: <subject>", "revert: ..."
420
- reflogMessages.pick(this.options.reflogAction ?? ACTION_NAME[action], commitMessage),
635
+ (text) => reflogMessages.pick(this.options.reflogAction ?? name, text),
421
636
  );
422
637
  // do_commit after try_to_commit: CHERRY_PICK_HEAD (deleted whether there or not) and
423
638
  // MERGE_MSG go, a stopped empty pick's left over included (REVERT_HEAD and AUTO_MERGE stay)
@@ -426,6 +641,29 @@ export class PickSequencer {
426
641
  return { status: "ok", newHead, picked: [item.id], output };
427
642
  }
428
643
 
644
+ /**
645
+ * fast_forward_to: the index and worktree switched from HEAD's tree to the commit's
646
+ * (checkout_fast_forward, a two-way switch refusing over local changes), then HEAD moved
647
+ * there with the reflog line `<action>: fast-forward`.
648
+ */
649
+ private async fastForward(
650
+ id: ObjectId,
651
+ headId: ObjectId | undefined,
652
+ headTree: ObjectId,
653
+ targetTree: ObjectId,
654
+ output: string[],
655
+ ): Promise<PickOutcome> {
656
+ const delta = await treeDelta(this.deps.trees, headTree, targetTree);
657
+ const refused = await switchTrees(this.deps, delta.from, delta.to, {
658
+ action: "merge",
659
+ operation: this.name,
660
+ targetTree,
661
+ });
662
+ if (refused) return this.fail(`${refused.message}\nfatal: ${this.name} failed`);
663
+ await this.moveHead(id, `${this.name}: fast-forward`, headId ?? null);
664
+ return { status: "ok", newHead: id, picked: [id], output };
665
+ }
666
+
429
667
  /** `--continue`: the resolved conflict committed, then the rest picked. */
430
668
  async continue(): Promise<PickOutcome> {
431
669
  const { state } = this.deps;
@@ -447,7 +685,7 @@ export class PickSequencer {
447
685
  if (!commit) throw new RefNotFoundError(stopped, "Commit being picked not found");
448
686
  const treeId = await this.deps.staging.writeTree(this.deps.trees);
449
687
  const headCommit = await this.deps.commits.load(newHead);
450
- const fallback = this.messageFor(action, stopped, commit, commit.parents[0]);
688
+ const fallback = await this.messageFor(action, stopped, commit, commit.parents[0]);
451
689
  const prepared = (await state.read("MERGE_MSG")) ?? fallback;
452
690
  // continue_single_pick runs `git commit --no-edit --cleanup=strip` (plain `git commit`
453
691
  // under --edit): without the editor its prepare_to_commit writes MERGE_MSG with its
@@ -485,7 +723,8 @@ export class PickSequencer {
485
723
  message,
486
724
  // `--continue` commits as `git commit` does: "commit (cherry-pick): <subject>" (a
487
725
  // revert is no whence of git commit: "commit: <subject>")
488
- reflogMessages.commit(action === "pick" ? "cherry-pick" : undefined, message),
726
+ (text) => reflogMessages.commit(action === "pick" ? "cherry-pick" : undefined, text),
727
+ "verbatim",
489
728
  );
490
729
  // the commit ends the stopped pick (git commit's remove_merge_branch_state)
491
730
  await state.removeRef("CHERRY_PICK_HEAD", "REVERT_HEAD", "AUTO_MERGE");
@@ -504,7 +743,8 @@ export class PickSequencer {
504
743
  const { state } = this.deps;
505
744
  const stopped = (await state.ref("CHERRY_PICK_HEAD")) ?? (await state.ref("REVERT_HEAD"));
506
745
  if (!stopped) {
507
- return this.fail(`error: no cherry-pick or revert in progress\nfatal: ${this.name} failed`);
746
+ // sequencer_skip: neither this action's head nor a sequence of it to go on with
747
+ return this.fail(`error: no ${this.name} in progress\nfatal: ${this.name} failed`);
508
748
  }
509
749
  await this.readSavedOptions();
510
750
  const headId = await this.headId();
@@ -543,6 +783,12 @@ export class PickSequencer {
543
783
  await state.remove("sequencer");
544
784
  return this.fail(`error: could not read 'sequencer/head'\nfatal: ${this.name} failed`);
545
785
  }
786
+ if (/^0+$/.test(origHead)) {
787
+ // sequencer_rollback: a run started on an unborn branch is not rewound (state kept)
788
+ return this.fail(
789
+ `error: cannot abort from a branch yet to be born\nfatal: ${this.name} failed`,
790
+ );
791
+ }
546
792
  if (safety && safety !== headId) {
547
793
  await state.remove("sequencer");
548
794
  return this.fail(
@@ -557,11 +803,18 @@ export class PickSequencer {
557
803
  return { status: "ok", newHead: origHead, picked: [], output: errors };
558
804
  }
559
805
 
560
- /** `--quit`: the operation forgotten, index, worktree and HEAD kept. */
806
+ /**
807
+ * `--quit` (builtin/revert.c): sequencer_remove_state (`sequencer/` removed), then
808
+ * remove_branch_state (CHERRY_PICK_HEAD, REVERT_HEAD, AUTO_MERGE, SQUASH_MSG, MERGE_MSG,
809
+ * MERGE_HEAD, MERGE_MODE, MERGE_RR go, a MERGE_AUTOSTASH is kept on `refs/stash`); the
810
+ * index, the worktree, HEAD and ORIG_HEAD are kept. Nothing in progress is no error.
811
+ */
561
812
  async quit(): Promise<PickOutcome> {
562
813
  await this.deps.state.remove("sequencer");
563
- await this.deps.state.removeRef("CHERRY_PICK_HEAD", "REVERT_HEAD");
564
- return { status: "ok", newHead: await this.headId(), picked: [], output: [] };
814
+ const output = await removeBranchState(this.deps, this.deps.state);
815
+ // an unborn HEAD is no error here
816
+ const head = (await this.deps.refs.resolve("HEAD").catch(() => undefined))?.objectId;
817
+ return { status: "ok", ...(head ? { newHead: head } : {}), picked: [], output };
565
818
  }
566
819
 
567
820
  /**
@@ -584,8 +837,9 @@ export class PickSequencer {
584
837
  }
585
838
 
586
839
  /**
587
- * read_populate_opts: `options.edit` of `sequencer/opts` (git config's syntax, the last
588
- * value wins), the `--edit` / `--no-edit` the run started with.
840
+ * read_populate_opts: `options.edit` and `options.gpg-sign` of `sequencer/opts` (git
841
+ * config's syntax, the last value wins), the `--edit` / `--no-edit` and `-S` the run
842
+ * started with.
589
843
  */
590
844
  private async readSavedOptions(): Promise<void> {
591
845
  const text = await this.deps.state.read("sequencer/opts");
@@ -599,9 +853,27 @@ export class PickSequencer {
599
853
  continue;
600
854
  }
601
855
  const entry = /^([A-Za-z][A-Za-z0-9-]*)\s*=\s*(.*)$/.exec(line);
602
- if (section !== "options" || !entry || entry[1].toLowerCase() !== "edit") continue;
603
- const value = parseGitBool(entry[2].replace(/^"(.*)"$/, "$1"));
604
- if (value !== undefined) this.edit = value;
856
+ if (section !== "options" || !entry) continue;
857
+ const name = entry[1].toLowerCase();
858
+ const text = entry[2].replace(/^"(.*)"$/, "$1");
859
+ if (name === "gpg-sign") {
860
+ this.sign = text;
861
+ continue;
862
+ }
863
+ if (name === "mainline") {
864
+ const value = Number.parseInt(text, 10);
865
+ if (Number.isFinite(value)) this.flags.mainline = value;
866
+ continue;
867
+ }
868
+ if (name === "default-msg-cleanup") {
869
+ this.cleanup = cleanupOf(text) ?? this.cleanup;
870
+ continue;
871
+ }
872
+ const value = parseGitBool(text);
873
+ if (value === undefined) continue;
874
+ if (name === "edit") this.edit = value;
875
+ const key = SAVED_FLAGS[name];
876
+ if (key) this.flags[key] = value;
605
877
  }
606
878
  }
607
879
 
@@ -610,22 +882,74 @@ export class PickSequencer {
610
882
  await this.deps.state.remove("MERGE_MSG", "sequencer");
611
883
  }
612
884
 
613
- /** git's message for the commit a pick or revert makes. */
614
- private messageFor(
885
+ /**
886
+ * git's message for the commit a pick or revert makes (do_pick_commit's ctx->message): a
887
+ * pick's message from its subject on, with `-x`'s `(cherry picked from commit <id>)` (after a
888
+ * blank line unless the message ends with a trailer block); a revert's `Revert "<subject>"`
889
+ * (`Reapply "..."` for a revert of a revert, `--reference`'s comment and `<abbrev> (<subject>,
890
+ * <date>)`); then `-s`'s sign-off (append_signoff).
891
+ */
892
+ private async messageFor(
615
893
  action: PickAction,
616
894
  id: ObjectId,
617
895
  commit: Commit,
618
896
  parentId: ObjectId | undefined,
619
- ): string {
897
+ ): Promise<string> {
898
+ let message: string;
620
899
  if (action === "pick") {
621
- return commit.message.endsWith("\n") ? commit.message : `${commit.message}\n`;
900
+ // find_commit_subject: the message from its first non-blank line
901
+ message = commit.message.replace(/^(?:[ \t]*\n)+/, "");
902
+ if (this.flags.recordOrigin) {
903
+ if (message.length > 0 && !message.endsWith("\n")) message += "\n";
904
+ if (trailerLinesOf(message, trailerConfigOf(this.deps.workingCopy)).length === 0) {
905
+ message += "\n";
906
+ }
907
+ message += `(cherry picked from commit ${id})\n`;
908
+ }
909
+ } else {
910
+ message = await this.revertMessage(id, commit, parentId);
622
911
  }
912
+ if (this.flags.signoff) {
913
+ const committer = this.options.committer ?? committerIdentOf(this.deps.workingCopy);
914
+ message = appendSignoff(
915
+ message,
916
+ signoffLine(committer),
917
+ trailerConfigOf(this.deps.workingCopy),
918
+ );
919
+ }
920
+ return message;
921
+ }
922
+
923
+ /** sequencer_format_revert_message. */
924
+ private async revertMessage(
925
+ id: ObjectId,
926
+ commit: Commit,
927
+ parentId: ObjectId | undefined,
928
+ ): Promise<string> {
623
929
  const subject = subjectOf(commit.message);
624
- const reverting =
625
- commit.parents.length > 1 && parentId
626
- ? `This reverts commit ${id}, reversing\nchanges made to ${parentId}.`
627
- : `This reverts commit ${id}.`;
628
- return `Revert "${subject}"\n\n${reverting}\n`;
930
+ const reference = this.options.reference ?? revertReferenceOf(this.deps.workingCopy);
931
+ let out: string;
932
+ if (reference) {
933
+ // git 2.43 wrote `#` whatever core.commentChar said (2.45 follows it)
934
+ const comment =
935
+ this.deps.hooks?.compatibility === "2.43" ? "#" : commentStringOf(this.deps.workingCopy);
936
+ out = `${comment} *** SAY WHY WE ARE REVERTING ON THE TITLE LINE ***\n`;
937
+ } else if (subject.startsWith('Revert "') && !subject.slice(8).startsWith('Revert "')) {
938
+ out = `Reapply "${subject.slice(8)}\n`;
939
+ } else {
940
+ out = `Revert "${subject}"\n`;
941
+ }
942
+ const refer = async (target: ObjectId) => {
943
+ if (!reference) return target;
944
+ const referred = await this.deps.commits.load(target);
945
+ const short = await this.abbreviator.abbreviate(target);
946
+ return `${short} (${subjectOf(referred?.message ?? "")}, ${shortDate(referred?.author)})`;
947
+ };
948
+ out += `\nThis reverts commit ${await refer(id)}`;
949
+ if (commit.parents.length > 1 && parentId) {
950
+ out += `, reversing\nchanges made to ${await refer(parentId)}`;
951
+ }
952
+ return `${out}.\n`;
629
953
  }
630
954
 
631
955
  /**
@@ -653,24 +977,88 @@ export class PickSequencer {
653
977
  author: PersonIdent,
654
978
  committer: PersonIdent,
655
979
  message: string,
656
- reflogMessage: string,
980
+ reflogMessage: (text: string) => string,
981
+ /** a cleanup of the message after the hook (default: the sequencer's, see cleanupMode) */
982
+ cleanup: SequencerCleanup = this.commitCleanup(),
657
983
  ): Promise<ObjectId> {
658
984
  // try_to_commit: prepare-commit-msg may rewrite the message; post-commit after
659
985
  const hooks = this.deps.hooks;
660
- const text = hooks ? await sequencerPrepareMessage(hooks, this.deps.state, message) : message;
661
- const id = await this.deps.commits.store({ tree, parents, author, committer, message: text });
662
- await this.moveHead(id, reflogMessage);
986
+ let text = hooks ? await sequencerPrepareMessage(hooks, this.deps.state, message) : message;
987
+ if (cleanup !== "verbatim") {
988
+ text = stripspace(
989
+ text,
990
+ cleanup === "strip" ? commentStringOf(this.deps.workingCopy) : undefined,
991
+ );
992
+ }
993
+ const id = await this.deps.commits.store(
994
+ await this.signed({ tree, parents, author, committer, message: text }),
995
+ );
996
+ await this.moveHead(id, reflogMessage(text));
663
997
  if (hooks) await sequencerPostCommit(hooks);
664
998
  return id;
665
999
  }
666
1000
 
1001
+ /**
1002
+ * try_to_commit's cleanup: whitespace for `-s`/`-x` unless commit.cleanup is set, else
1003
+ * commit.cleanup's (`scissors` is whitespace without an editor), else none.
1004
+ */
1005
+ private commitCleanup(): SequencerCleanup {
1006
+ if ((this.flags.signoff || this.flags.recordOrigin) && !this.cleanup) return "whitespace";
1007
+ if (this.cleanup === "scissors") return "whitespace";
1008
+ return this.cleanup ?? "verbatim";
1009
+ }
1010
+
1011
+ /**
1012
+ * try_to_commit's commit_tree signing `commit` for the run's key (git's opts->gpg_sign),
1013
+ * the signing program in the worktree top. When it cannot be signed: gpg's error and
1014
+ * `error: failed to write commit object`, then in git 2.43 `fatal: <action> failed` (exit
1015
+ * 128); 2.5x returns after the error (exit 1). The pick stays in progress
1016
+ * (CHERRY_PICK_HEAD, MERGE_MSG), as git leaves it.
1017
+ */
1018
+ private async signed(commit: Commit): Promise<Commit> {
1019
+ const sign = this.sign;
1020
+ if (sign === undefined) return commit;
1021
+ const legacy = this.deps.hooks?.compatibility === "2.43";
1022
+ const cwd = await this.deps.hooks?.hostWorkingDirectory().catch(() => undefined);
1023
+ try {
1024
+ return await signCommit(this.deps.workingCopy, sign, commit, {
1025
+ tail: [],
1026
+ ...(cwd !== undefined ? { cwd } : {}),
1027
+ });
1028
+ } catch (error) {
1029
+ if (!(error instanceof SigningFailedError)) throw error;
1030
+ // the signing died itself (ssh without a key): git dies there
1031
+ if (/(^|\n)fatal: [^\n]*$/.test(error.message)) throw error;
1032
+ throw new SigningFailedError(
1033
+ [
1034
+ error.message,
1035
+ "error: failed to write commit object",
1036
+ ...(legacy ? [`fatal: ${this.name} failed`] : []),
1037
+ ].join("\n"),
1038
+ sign,
1039
+ legacy ? 128 : 1,
1040
+ {
1041
+ ...(error.signerMessages ? { signerMessages: error.signerMessages } : {}),
1042
+ ...(error.programExitCode !== undefined
1043
+ ? { programExitCode: error.programExitCode }
1044
+ : {}),
1045
+ },
1046
+ );
1047
+ }
1048
+ }
1049
+
667
1050
  /** HEAD (its branch, when attached) moved to `id`, with `message` in the reflogs. */
668
- private async moveHead(id: ObjectId, message: string): Promise<void> {
1051
+ private async moveHead(
1052
+ id: ObjectId,
1053
+ message: string,
1054
+ /** the old value the transaction expects (default HEAD's, null for an unborn HEAD) */
1055
+ expected?: ObjectId | null,
1056
+ ): Promise<void> {
669
1057
  this.clock ??= Math.floor(Date.now() / 1000);
670
1058
  const log = reflogLine(this.deps.workingCopy, message, this.options.committer, this.clock);
671
1059
  // update_head_with_reflog: one transaction on HEAD expecting the commit's parent, as the
672
1060
  // reference-transaction hook sees it
673
- const current = (await this.deps.refs.resolve("HEAD"))?.objectId;
1061
+ const current = expected !== undefined ? expected : await this.headIfBorn();
674
1062
  const result = await this.deps.refs.batch(
675
1063
  [{ name: "HEAD", old: current ?? null, new: id }],
676
1064
  log,
@@ -726,6 +1114,12 @@ export class PickSequencer {
726
1114
  );
727
1115
  }
728
1116
 
1117
+ /** HEAD's commit, undefined while HEAD's branch is unborn. */
1118
+ private async headIfBorn(): Promise<ObjectId | undefined> {
1119
+ const resolved = await this.deps.refs.resolve("HEAD").catch(() => undefined);
1120
+ return resolved?.objectId || undefined;
1121
+ }
1122
+
729
1123
  private async headId(): Promise<ObjectId> {
730
1124
  const resolved = await this.deps.refs.resolve("HEAD");
731
1125
  if (!resolved?.objectId) throw new RefNotFoundError("HEAD", "HEAD cannot be resolved");
@@ -867,3 +1261,27 @@ export async function expandCommitIds(
867
1261
  return found;
868
1262
  });
869
1263
  }
1264
+
1265
+ /** `revert.reference` (git_sequencer_config, revert only). */
1266
+ function revertReferenceOf(workingCopy: SequencerDeps["workingCopy"]): boolean {
1267
+ const value = RemoteConfigStore.from(workingCopy).value("revert.reference");
1268
+ return value === undefined ? false : (parseGitBool(value) ?? false);
1269
+ }
1270
+
1271
+ /** comment_line_str: `core.commentString`, else `core.commentChar` (`auto`: `#`). */
1272
+ function commentStringOf(workingCopy: SequencerDeps["workingCopy"]): string {
1273
+ const config = RemoteConfigStore.from(workingCopy);
1274
+ const value = config.value("core.commentString") ?? config.value("core.commentChar");
1275
+ return value && value !== "auto" ? value : "#";
1276
+ }
1277
+
1278
+ /** DATE_SHORT of an ident: `YYYY-MM-DD` in its own zone. */
1279
+ function shortDate(ident: PersonIdent | undefined): string {
1280
+ if (!ident) return "";
1281
+ const tz = ident.tzOffset || "+0000";
1282
+ const sign = tz.startsWith("-") ? -1 : 1;
1283
+ const minutes = sign * (Number(tz.slice(1, 3)) * 60 + Number(tz.slice(3, 5)));
1284
+ const d = new Date((ident.timestamp + minutes * 60) * 1000);
1285
+ const pad = (n: number) => String(n).padStart(2, "0");
1286
+ return `${d.getUTCFullYear()}-${pad(d.getUTCMonth() + 1)}-${pad(d.getUTCDate())}`;
1287
+ }