@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
@@ -1,6 +1,5 @@
1
1
  import {
2
2
  type Commit,
3
- EMPTY_TREE_ID,
4
3
  isSymbolicRef,
5
4
  listObjectsWithPrefix,
6
5
  type ObjectId,
@@ -14,12 +13,12 @@ import { isIndexUnborn, type Worktree } from "@statewalker/vcs-working-tree";
14
13
 
15
14
  import {
16
15
  CommitNotFoundError,
16
+ GitApiError,
17
17
  InvalidArgumentError,
18
18
  NoHeadError,
19
19
  NoRebaseInProgressError,
20
20
  RebaseTodoMissingError,
21
21
  RefNotFoundError,
22
- UpstreamRequiredError,
23
22
  } from "../errors/index.js";
24
23
  import { GitCommand } from "../git-command.js";
25
24
  import { RemoteConfigStore } from "../remote-config/index.js";
@@ -32,7 +31,9 @@ import {
32
31
  } from "../results/merge-result.js";
33
32
  import type { RebaseResult, RebaseTodoLine } from "../results/rebase-result.js";
34
33
  import { RebaseAction, RebaseStatus } from "../results/rebase-result.js";
34
+ import { AmCommand } from "./am/index.js";
35
35
  import { coreBool, createIdAbbreviator, worktreeModeTrust } from "./core-config.js";
36
+ import { findForkPoint } from "./fork-point.js";
36
37
  import { createDescriber, type DescribeOptions } from "./git-describe.js";
37
38
  import {
38
39
  type GitCommitHookRun,
@@ -43,6 +44,7 @@ import {
43
44
  sequencerPrepareMessage,
44
45
  } from "./git-hooks.js";
45
46
  import { hostEnvironmentOf, localTimezoneOffset } from "./git-ident.js";
47
+ import { commitsBaseSource, MergeBaseGraph } from "./merge-bases.js";
46
48
  import { favorOf, MergeCommand } from "./merge-command.js";
47
49
  import { configBool, configValue, conflictStyleOf } from "./merge-config.js";
48
50
  import { ortConfigOptions } from "./merge-drivers.js";
@@ -90,16 +92,27 @@ import { reflogMessages, updateHeadExpecting } from "./reflog-messages.js";
90
92
  import { revisionMergeBases } from "./rev-parse-command.js";
91
93
  import { expandCommitId } from "./sequencer-pick.js";
92
94
  import {
95
+ AUTOSTASH_SAVED_LINES,
93
96
  applyAutostash,
94
97
  cleanupMessage,
95
98
  createAutostash,
96
99
  moveHeadAsReset,
97
100
  removeBranchState,
98
101
  resetMerge,
102
+ saveAutostash,
99
103
  } from "./sequencer-support.js";
100
- import { appendSignoff, trailerConfigOf } from "./trailers.js";
104
+ import { showCommit } from "./show-commit.js";
105
+ import { SigningFailedError, type SignRequest, signRequestOf } from "./signing.js";
106
+ import {
107
+ amendWithTrailers,
108
+ appendSignoff,
109
+ type TrailerCommandRunner,
110
+ type TrailerConfig,
111
+ trailerConfigOf,
112
+ validateTrailerArgs,
113
+ } from "./trailers.js";
101
114
  import { worktreeModified } from "./worktree-overwrite-checks.js";
102
- import { usesBranch } from "./worktree-support.js";
115
+ import { refuseIfCheckedOut, usesBranch } from "./worktree-support.js";
103
116
 
104
117
  /**
105
118
  * Rebase operation types.
@@ -117,6 +130,16 @@ export enum RebaseOperation {
117
130
  PROCESS_STEPS = "process-steps",
118
131
  /** `--edit-todo`: the rest of the todo list edited (the interactive handler's editTodo) */
119
132
  EDIT_TODO = "edit-todo",
133
+ /**
134
+ * `--quit`: the rebase forgotten (its state directory removed, its autostash kept on
135
+ * `refs/stash`), HEAD, the index and the worktree left as they are
136
+ */
137
+ QUIT = "quit",
138
+ /**
139
+ * `--show-current-patch`: `git show REBASE_HEAD` (merge backend) or `git am
140
+ * --show-current-patch` (apply backend), in {@link RebaseResult.currentPatch}
141
+ */
142
+ SHOW_CURRENT_PATCH = "show-current-patch",
120
143
  }
121
144
 
122
145
  /**
@@ -171,7 +194,11 @@ interface UpdateRefRecord {
171
194
 
172
195
  /** What a pick (do_pick_commit) did. */
173
196
  type PickOutcome =
174
- | { kind: "ok" }
197
+ | {
198
+ kind: "ok";
199
+ /** The message picked (do_pick_commit's ctx->message), when the pick was not fast-forwarded */
200
+ message?: string;
201
+ }
175
202
  | { kind: "dropped" }
176
203
  | {
177
204
  kind: "conflicts";
@@ -180,11 +207,11 @@ type PickOutcome =
180
207
  conflicts: string[];
181
208
  /** What error_with_patch writes to `rebase-merge/message` */
182
209
  message?: string;
210
+ /** error_failed_squash's to_amend (default true): 2.43 stops a failed squash unamended */
211
+ toAmend?: boolean;
183
212
  }
184
213
  | { kind: "reschedule"; result: RebaseResult & { reschedule?: boolean } };
185
214
 
186
- const ZERO_ID = "0000000000000000000000000000000000000000";
187
-
188
215
  /**
189
216
  * What a todo command came to: nothing (go on), `checkTodo` (go on, the list read again if
190
217
  * it changed), or a result that stops the rebase (`reschedule`: the command goes back).
@@ -193,19 +220,49 @@ type StepOutcome =
193
220
  | (Partial<RebaseResult> & { reschedule?: boolean; checkTodo?: boolean })
194
221
  | undefined;
195
222
 
196
- /** sequencer.c's staged_changes_advice (no `-S`). */
197
- const STAGED_CHANGES_ADVICE = `error: you have staged changes in your working tree
223
+ /** sequencer.c's staged_changes_advice, with the run's quoted `-S<key>` (gpg_sign_opt_quoted). */
224
+ function stagedChangesAdvice(gpgSignOpt: string): string {
225
+ return `error: you have staged changes in your working tree
198
226
  If these changes are meant to be squashed into the previous commit, run:
199
227
 
200
- git commit --amend
228
+ git commit --amend ${gpgSignOpt}
201
229
 
202
230
  If they are meant to go into a new commit, run:
203
231
 
204
- git commit
232
+ git commit ${gpgSignOpt}
205
233
 
206
234
  In both cases, once you're done, continue with:
207
235
 
208
236
  git rebase --continue`;
237
+ }
238
+
239
+ /**
240
+ * commit_staged_changes' git commit dying on its signature (not signed yet): gpg's lines,
241
+ * git commit's death, then the sequencer's error; nothing committed, the stop kept.
242
+ */
243
+ function commitStagedSigningFailure(error: SigningFailedError): RebaseResult {
244
+ return {
245
+ status: RebaseStatus.FAILED,
246
+ message: [
247
+ error.message,
248
+ "fatal: failed to write commit object",
249
+ "error: could not commit staged changes.",
250
+ ].join("\n"),
251
+ };
252
+ }
253
+
254
+ /**
255
+ * A reword's `git commit --amend -e` dying on its signature: gpg's lines and git commit's
256
+ * death, the rebase stopped with HEAD to amend; undefined for any other failure.
257
+ */
258
+ function signingFailure(error: unknown): Extract<PickOutcome, { kind: "conflicts" }> | undefined {
259
+ if (!(error instanceof SigningFailedError)) return undefined;
260
+ return {
261
+ kind: "conflicts",
262
+ conflicts: [],
263
+ lines: [error.message, "fatal: failed to write commit object"],
264
+ };
265
+ }
209
266
 
210
267
  /** rebase-interactive.c's edit_todo_list_advice. */
211
268
  const EDIT_TODO_ADVICE = [
@@ -255,6 +312,8 @@ export class RebaseCommand extends GitCommand<RebaseResult> {
255
312
  private contentStrategy?: ContentMergeStrategy;
256
313
  private preserveMerges = false;
257
314
  private interactiveHandler?: InteractiveHandler;
315
+ /** Whose messages to give where git 2.43 and 2.5x differ (default: the hooks') */
316
+ private compatibility?: "2.43" | "2.56";
258
317
  private committer?: PersonIdent;
259
318
  /** `--committer-date-is-author-date` (kept in `rebase-merge/cdate_is_adate`) */
260
319
  private committerDateIsAuthorDate = false;
@@ -262,8 +321,24 @@ export class RebaseCommand extends GitCommand<RebaseResult> {
262
321
  private ignoreDate = false;
263
322
  /** `--signoff` (kept in `rebase-merge/signoff`) */
264
323
  private signoff = false;
324
+ /** `--force-rebase` (REBASE_FORCE) */
325
+ private forceRebase = false;
326
+ /** `-S[<keyid>]` / `--no-gpg-sign` (undefined: `commit.gpgSign`; kept in `gpg_sign_opt`) */
327
+ private sign?: boolean | string;
328
+ /** What this run signs with (git's opts->gpg_sign), once known */
329
+ private runSign?: { key: SignRequest };
265
330
  private autoStash?: boolean;
266
- private reapplyCherryPicks = false;
331
+ private reapplyCherryPicks?: boolean;
332
+ /** `--onto <newbase>` as given (`A...B` included) */
333
+ private ontoName?: string;
334
+ /** The `<branch>` argument: switched to before the rebase */
335
+ private branchArg?: string;
336
+ /** `--keep-base` */
337
+ private keepBase = false;
338
+ /** `--[no-]fork-point`; undefined: git's default (on for an implicit upstream) */
339
+ private forkPoint?: boolean;
340
+ /** The onto name of the rebase running (git's `onto_name`), for the reflog */
341
+ private runOntoName?: string;
267
342
  /** `--rebase-merges` (undefined: `rebase.rebaseMerges`) */
268
343
  private rebaseMerges?: boolean;
269
344
  /** `--rebase-merges=rebase-cousins` */
@@ -295,6 +370,24 @@ export class RebaseCommand extends GitCommand<RebaseResult> {
295
370
  /** `--root`: every commit of the branch rebased (onto the upstream given, else a new root) */
296
371
  private root = false;
297
372
  private noVerify = false;
373
+ /** `--trailer` arguments (kept in `rebase-merge/trailer`, one per line) */
374
+ private trailerArgs: string[] = [];
375
+
376
+ /**
377
+ * `--trailer <token>[(=|:)<value>]` (git 2.46+): each rebased commit's message gets the
378
+ * trailer as `git interpret-trailers --no-divider --trailer` adds it (`trailer.*`
379
+ * configuration applies; a fixup or squash none, a `fixup -C` the message it takes). Like
380
+ * git, it implies `--force-rebase` and is kept in `rebase-merge/trailer` for `--continue`;
381
+ * an empty argument or one without a key is refused before anything is done, and under
382
+ * 2.43 compatibility the option itself (`error: unknown option \`trailer'`, exit 129).
383
+ * git's apply backend refuses it (`--trailer requires the merge backend`); ours has only
384
+ * the merge backend.
385
+ */
386
+ addTrailer(trailer: string): this {
387
+ this.checkCallable();
388
+ this.trailerArgs.push(trailer);
389
+ return this;
390
+ }
298
391
 
299
392
  /** `--no-verify`: the pre-rebase hook does not run. */
300
393
  setNoVerify(noVerify: boolean): this {
@@ -336,18 +429,66 @@ export class RebaseCommand extends GitCommand<RebaseResult> {
336
429
  * builtin/rebase.c's `lookup_commit_reference_by_name(options.upstream_name)`: the commit
337
430
  * an upstream names, or git's "fatal: invalid upstream '<name>'" (exit 128).
338
431
  */
339
- private async resolveUpstream(name: string): Promise<ObjectId> {
340
- const fatal = (n: string) => `fatal: invalid upstream '${n}'`;
432
+ private async resolveUpstream(name: string, shown = name): Promise<ObjectId> {
433
+ const fatal = () => `fatal: invalid upstream '${shown}'`;
341
434
  try {
342
435
  return await this.resolveRef(name, fatal);
343
436
  } catch (error) {
344
437
  if (error instanceof RefNotFoundError) {
345
- throw new RefNotFoundError(name, fatal(name)).withExitCode(128);
438
+ throw new RefNotFoundError(name, fatal()).withExitCode(128);
346
439
  }
347
440
  throw error;
348
441
  }
349
442
  }
350
443
 
444
+ /**
445
+ * `--onto <newbase>`: the commits of `<upstream>..HEAD` go onto `newbase` instead of onto
446
+ * the upstream. Any revision, or `A...B` for the one merge base of A and B (either side
447
+ * empty is HEAD): git's `fatal: '<A...B>': need exactly one merge base` when there are
448
+ * none or several, `fatal: Does not point to a valid commit '<newbase>'` when it names no
449
+ * commit. With {@link setRoot} it is `--root --onto <newbase>`.
450
+ */
451
+ setOnto(newbase: string): this {
452
+ this.checkCallable();
453
+ this.ontoName = newbase;
454
+ return this;
455
+ }
456
+
457
+ /**
458
+ * The `<branch>` argument: `git rebase <upstream> <branch>` switches to it first (a local
459
+ * branch, which then moves; or any commit, rebased on a detached HEAD), as
460
+ * `git switch <branch>` would; a branch another worktree has checked out is refused.
461
+ */
462
+ setBranch(branch: string): this {
463
+ this.checkCallable();
464
+ this.branchArg = branch;
465
+ return this;
466
+ }
467
+
468
+ /**
469
+ * `--keep-base`: onto the merge base of the upstream and the branch (`<upstream>...<branch>`),
470
+ * so the commits stay where they are while the upstream's are left out. Implies
471
+ * `--no-fork-point` and `--reapply-cherry-picks` unless set; refused with `--onto` and
472
+ * `--root`.
473
+ */
474
+ setKeepBase(keepBase: boolean): this {
475
+ this.checkCallable();
476
+ this.keepBase = keepBase;
477
+ return this;
478
+ }
479
+
480
+ /**
481
+ * `--fork-point` / `--no-fork-point`: leave out the commits the upstream's reflog shows
482
+ * were once on it (git's get_fork_point: the one merge base of the branch and the values
483
+ * the upstream's reflog records, when it is one of them). Default: on when no upstream is
484
+ * given (the branch's `@{upstream}`), unless `rebase.forkPoint` is false; off otherwise.
485
+ */
486
+ setForkPoint(forkPoint: boolean): this {
487
+ this.checkCallable();
488
+ this.forkPoint = forkPoint;
489
+ return this;
490
+ }
491
+
351
492
  /**
352
493
  * Set the upstream name for messages.
353
494
  *
@@ -376,6 +517,17 @@ export class RebaseCommand extends GitCommand<RebaseResult> {
376
517
  *
377
518
  * @param operation Rebase operation
378
519
  */
520
+ /**
521
+ * Whose messages to give where git 2.43 and 2.5x differ (`fatal: No rebase in progress?`
522
+ * in 2.43, `fatal: no rebase in progress` in 2.5x). Default: the hook runner's
523
+ * compatibility, else 2.56.
524
+ */
525
+ setCompatibility(version: "2.43" | "2.56"): this {
526
+ this.checkCallable();
527
+ this.compatibility = version;
528
+ return this;
529
+ }
530
+
379
531
  setOperation(operation: RebaseOperation): this {
380
532
  this.checkCallable();
381
533
  this.operation = operation;
@@ -536,6 +688,84 @@ export class RebaseCommand extends GitCommand<RebaseResult> {
536
688
  return this;
537
689
  }
538
690
 
691
+ /**
692
+ * `-S` (true) / `--no-gpg-sign` (false): whether to sign the commits the rebase makes;
693
+ * undefined (the default) leaves it to `commit.gpgSign`. Kept in
694
+ * `rebase-merge/gpg_sign_opt` for `--continue`. Every commit the rebase writes is signed
695
+ * through the host's signer (`GitHostEnvironment.signer`) as git's sequencer signs it; when
696
+ * it cannot be signed the step fails as git's does (`error: gpg failed to sign the data:`,
697
+ * `error: failed to write commit object`) and the rebase stops there (2.5x: `Could not
698
+ * apply ...`, the pick to commit; 2.43: the pick rescheduled), the branch untouched.
699
+ * Picks kept as they are (fast-forwarded) sign nothing, as in git.
700
+ */
701
+ setSign(sign: boolean | undefined): this {
702
+ this.checkCallable();
703
+ this.sign = sign;
704
+ return this;
705
+ }
706
+
707
+ /** `-S<keyid>`: sign with this key (see {@link setSign}). */
708
+ setSigningKey(keyId: string): this {
709
+ this.checkCallable();
710
+ this.sign = keyId;
711
+ return this;
712
+ }
713
+
714
+ /**
715
+ * The key this run's commits are signed with: the one it started with, else (a
716
+ * `--continue`) `rebase-merge/gpg_sign_opt` over `commit.gpgSign` (read_populate_opts).
717
+ */
718
+ private async signRequest(state: OperationState): Promise<SignRequest> {
719
+ if (this.runSign) return this.runSign.key;
720
+ const saved = (await state.read(`${DIR}/gpg_sign_opt`))?.replace(/\n$/, "");
721
+ const key =
722
+ saved?.startsWith("-S") === true
723
+ ? saved.slice(2)
724
+ : signRequestOf(this.workingCopy, undefined);
725
+ this.runSign = { key };
726
+ return key;
727
+ }
728
+
729
+ /**
730
+ * commit_tree's signing of a commit the rebase makes, with this run's key (git's
731
+ * opts->gpg_sign), the signing program in the worktree top. When it cannot be signed:
732
+ * {@link SigningFailedError} with gpg's lines alone; the step says what follows.
733
+ */
734
+ private async signedRebaseCommit(state: OperationState, commit: Commit): Promise<Commit> {
735
+ return this.signedCommit(await this.signRequest(state), commit, []);
736
+ }
737
+
738
+ /** sequencer.c's gpg_sign_opt_quoted: `'-S<key>'` (shell-quoted) when the run signs, else "". */
739
+ private async gpgSignOptQuoted(state: OperationState): Promise<string> {
740
+ const sign = await this.signRequest(state);
741
+ return sign === undefined
742
+ ? ""
743
+ : `'-S${sign.replaceAll("'", "'\\''").replaceAll("!", "'\\!'")}'`;
744
+ }
745
+
746
+ /**
747
+ * try_to_commit failing to sign a pick or a fixup: 2.43 reschedules the command (its
748
+ * `error:` lines, the rescheduled advice), 2.5x stops as after a conflict.
749
+ */
750
+ private signingStop(
751
+ item: TodoItem,
752
+ lines: string[],
753
+ options: { message?: string } = {},
754
+ ): PickOutcome {
755
+ if (this.hooks.compatibility === "2.43") {
756
+ return {
757
+ kind: "reschedule",
758
+ result: {
759
+ status: RebaseStatus.FAILED,
760
+ currentCommit: item.id,
761
+ message: lines.join("\n"),
762
+ reschedule: true,
763
+ },
764
+ };
765
+ }
766
+ return { kind: "conflicts", conflicts: [], lines, ...options };
767
+ }
768
+
539
769
  /**
540
770
  * `--exec <command>` (`-x`): an `exec <command>` line after each pick (after its fixup and
541
771
  * squash chain) and each merge; implies an interactive list (no fast-forward shortcut) and
@@ -612,6 +842,18 @@ export class RebaseCommand extends GitCommand<RebaseResult> {
612
842
  return this;
613
843
  }
614
844
 
845
+ /**
846
+ * `--force-rebase` (`-f`, `--no-ff`): every commit is picked again, even one whose parent is
847
+ * already where the rebase puts it (git's REBASE_FORCE: no allow_ff, no up-to-date
848
+ * shortcut, `Current branch <name> is up to date, rebase forced.`). Like git, a `--continue`
849
+ * does not remember it.
850
+ */
851
+ setForceRebase(value: boolean): this {
852
+ this.checkCallable();
853
+ this.forceRebase = value;
854
+ return this;
855
+ }
856
+
615
857
  /**
616
858
  * `--root`: all the commits of the branch are rebased, its root commit too. With an
617
859
  * upstream set ({@link setUpstream}) that is `--root --onto <upstream>`; without one the
@@ -652,7 +894,18 @@ export class RebaseCommand extends GitCommand<RebaseResult> {
652
894
  };
653
895
  }
654
896
  }
897
+ // parse_options: --trailer is unknown to 2.43; validate_trailer_args, then die(NULL)
898
+ if (this.trailerArgs.length > 0) {
899
+ if ((this.compatibility ?? this.hooks.compatibility) === "2.43") {
900
+ throw new GitApiError("error: unknown option `trailer'", { exitCode: 129 });
901
+ }
902
+ const refused = validateTrailerArgs(this.trailerArgs, this.trailerConfig());
903
+ if (refused !== undefined) throw new GitApiError(refused, { exitCode: 128 });
904
+ }
655
905
  switch (this.operation) {
906
+ case RebaseOperation.QUIT:
907
+ case RebaseOperation.SHOW_CURRENT_PATCH:
908
+ return this.quitOrShow(state, worktree, this.operation);
656
909
  case RebaseOperation.ABORT:
657
910
  return this.abort(state, worktree);
658
911
  case RebaseOperation.CONTINUE:
@@ -686,19 +939,260 @@ export class RebaseCommand extends GitCommand<RebaseResult> {
686
939
  );
687
940
  }
688
941
 
942
+ /**
943
+ * cmd_rebase's checks of the options among themselves; the fork-point setting as git
944
+ * settles it then (1 on, 0 off, -1 the default: on for an implicit upstream).
945
+ */
946
+ private checkBeginOptions(): number {
947
+ // rebase_config: rebase.forkPoint=false turns the default off, true leaves it
948
+ const configured = configValue(this.workingCopy, "rebase.forkPoint");
949
+ let forkPoint = configured !== undefined && parseGitBool(configured) === false ? 0 : -1;
950
+ if (this.forkPoint !== undefined) forkPoint = this.forkPoint ? 1 : 0;
951
+ const together = (a: string, b: string) =>
952
+ new GitApiError(`fatal: options '${a}' and '${b}' cannot be used together`);
953
+ if (this.keepBase) {
954
+ if (this.ontoName !== undefined) throw together("--keep-base", "--onto");
955
+ if (this.root) throw together("--keep-base", "--root");
956
+ // --keep-base defaults to --no-fork-point to keep the base the same
957
+ if (forkPoint < 0) forkPoint = 0;
958
+ }
959
+ if (this.root && forkPoint > 0) throw together("--root", "--fork-point");
960
+ return forkPoint;
961
+ }
962
+
963
+ /**
964
+ * cmd_rebase's names and commits: the upstream (given, else the branch's `@{upstream}`),
965
+ * the branch rebased (the `<branch>` argument, else HEAD's), onto (`--onto`, `A...B`,
966
+ * `--keep-base`, `--root`'s squash-onto), the fork point and the branch base (the one
967
+ * merge base of onto and the branch, which can_fast_forward reads).
968
+ */
969
+ private async settleBegin(
970
+ forkPoint: number,
971
+ /** What git prints reading the names (`warning: refname 'x' is ambiguous.`) */
972
+ warnings: string[],
973
+ ): Promise<
974
+ | RebaseResult
975
+ | {
976
+ currentHead: ObjectId;
977
+ origHead: ObjectId;
978
+ headName: string;
979
+ branchName: string;
980
+ onto: ObjectId;
981
+ ontoName: string;
982
+ upstream?: ObjectId;
983
+ upstreamName?: string;
984
+ restrict?: ObjectId;
985
+ branchBase?: ObjectId;
986
+ squashOnto?: ObjectId;
987
+ }
988
+ > {
989
+ const fatal = (message: string) => new GitApiError(`fatal: ${message}`);
990
+ let upstreamName: string | undefined;
991
+ let upstream: ObjectId | undefined;
992
+ let ontoName = this.ontoName;
993
+ let onto: ObjectId | undefined;
994
+ let squashOnto: ObjectId | undefined;
995
+ if (!this.root) {
996
+ if (this.upstreamCommit === undefined) {
997
+ const missing = await this.defaultUpstream();
998
+ if (typeof missing !== "string") return missing;
999
+ upstreamName = missing;
1000
+ if (forkPoint < 0) forkPoint = 1;
1001
+ } else {
1002
+ upstreamName = this.upstreamCommitName === "-" ? "@{-1}" : this.upstreamCommitName;
1003
+ }
1004
+ // the upstream as given (setUpstream takes a name too) peeled to the commit it names
1005
+ // before anything is written, so HEAD is never set to a name ("main\n" in .git/HEAD);
1006
+ // an empty name too: "fatal: invalid upstream ''"
1007
+ const given =
1008
+ this.upstreamCommit === undefined || this.upstreamCommit === "-"
1009
+ ? (upstreamName as string)
1010
+ : this.upstreamCommit;
1011
+ upstream = await this.resolveUpstream(given, upstreamName as string);
1012
+ warnings.push(...(await this.nameWarnings(given)));
1013
+ } else if (ontoName === undefined) {
1014
+ if (this.upstreamCommit !== undefined) {
1015
+ // setRoot with setUpstream: `--root --onto <upstream>`
1016
+ onto = await this.resolveUpstream(this.upstreamCommit);
1017
+ ontoName = this.upstreamCommitName ?? onto;
1018
+ } else {
1019
+ // --root without --onto: the commits go onto git's squash_onto, a commit of the
1020
+ // empty tree with no parent (their root is then a root again)
1021
+ squashOnto = await this.createSquashOnto();
1022
+ onto = squashOnto;
1023
+ ontoName = squashOnto;
1024
+ }
1025
+ }
1026
+
1027
+ const headResolved = await this.refsStore.resolve("HEAD");
1028
+ if (!headResolved?.objectId) throw new NoHeadError("HEAD cannot be resolved");
1029
+ const currentHead = headResolved.objectId;
1030
+ let headName: string;
1031
+ let branchName: string;
1032
+ let origHead: ObjectId;
1033
+ if (this.branchArg !== undefined) {
1034
+ // "rebase other branchname" or "rebase other commit"
1035
+ branchName = this.branchArg;
1036
+ const ref = `refs/heads/${branchName}`;
1037
+ const local = (await this.refsStore.resolve(ref).catch(() => undefined))?.objectId;
1038
+ if (local) {
1039
+ const worktrees = this.workingCopy.worktrees;
1040
+ if (worktrees) await refuseIfCheckedOut(worktrees, ref, true);
1041
+ if (!(await this.loadCommit(local))) {
1042
+ throw fatal(`no such branch/commit '${branchName}'`);
1043
+ }
1044
+ headName = ref;
1045
+ origHead = local;
1046
+ } else {
1047
+ const id = await this.revisionResolver()
1048
+ .resolve(branchName, { hint: "committish" })
1049
+ .catch(() => undefined);
1050
+ const commit = id && (await this.revisionResolver().commitReference(id));
1051
+ if (!commit) throw fatal(`no such branch/commit '${branchName}'`);
1052
+ headName = "detached HEAD";
1053
+ origHead = commit;
1054
+ }
1055
+ } else {
1056
+ const headRef = await this.refsStore.get("HEAD");
1057
+ if (headRef && isSymbolicRef(headRef)) {
1058
+ headName = headRef.target;
1059
+ branchName = headName.startsWith("refs/heads/")
1060
+ ? headName.slice("refs/heads/".length)
1061
+ : headName;
1062
+ } else {
1063
+ headName = "detached HEAD";
1064
+ branchName = "HEAD";
1065
+ }
1066
+ origHead = currentHead;
1067
+ }
1068
+
1069
+ // make sure the branch to rebase onto is valid
1070
+ let branchBase: ObjectId | undefined;
1071
+ if (this.keepBase) ontoName = `${upstreamName}...${branchName}`;
1072
+ else if (ontoName === undefined) ontoName = upstreamName as string;
1073
+ if (onto === undefined && !ontoName.includes("...")) {
1074
+ warnings.push(...(await this.nameWarnings(ontoName)));
1075
+ }
1076
+ if (onto === undefined && ontoName.includes("...")) {
1077
+ onto = await this.mergeBaseOfDots(ontoName);
1078
+ if (onto === undefined) {
1079
+ throw this.keepBase
1080
+ ? fatal(`'${upstreamName}': need exactly one merge base with branch`)
1081
+ : fatal(`'${ontoName}': need exactly one merge base`);
1082
+ }
1083
+ branchBase = onto;
1084
+ } else {
1085
+ if (onto === undefined) {
1086
+ const id =
1087
+ ontoName === upstreamName && upstream !== undefined
1088
+ ? upstream
1089
+ : await this.resolveRef(
1090
+ ontoName,
1091
+ (n) => `fatal: Does not point to a valid commit '${n}'`,
1092
+ ).catch((error: unknown) => {
1093
+ if (error instanceof RefNotFoundError) {
1094
+ throw fatal(`Does not point to a valid commit '${ontoName}'`);
1095
+ }
1096
+ throw error;
1097
+ });
1098
+ onto = id;
1099
+ }
1100
+ // fill_branch_base: the one merge base of onto and the branch, else none
1101
+ const bases = await revisionMergeBases(this.commits, onto, origHead);
1102
+ branchBase = bases.length === 1 ? bases[0] : undefined;
1103
+ }
1104
+ // --keep-base keeps cherry-picks (unless --no-reapply-cherry-picks): the upstream is
1105
+ // onto, so none can be detected
1106
+ if (this.keepBase && (this.reapplyCherryPicks ?? true)) upstream = onto;
1107
+ let restrict: ObjectId | undefined;
1108
+ if (forkPoint > 0 && upstreamName !== undefined) {
1109
+ const graph = new MergeBaseGraph(commitsBaseSource(this.commits, async () => new Map()));
1110
+ restrict = await findForkPoint(this.forkPointSource(graph), upstreamName, origHead);
1111
+ }
1112
+ return {
1113
+ currentHead,
1114
+ origHead,
1115
+ headName,
1116
+ branchName,
1117
+ onto,
1118
+ ontoName,
1119
+ upstream,
1120
+ upstreamName,
1121
+ restrict,
1122
+ branchBase,
1123
+ squashOnto,
1124
+ };
1125
+ }
1126
+
1127
+ /**
1128
+ * branch_get_upstream for `git rebase` without an upstream: the current branch's
1129
+ * `@{upstream}`, else error_on_missing_default_upstream's advice (stdout, exit 1).
1130
+ */
1131
+ private async defaultUpstream(): Promise<string | RebaseResult> {
1132
+ const headRef = await this.refsStore.get("HEAD").catch(() => undefined);
1133
+ const branch =
1134
+ headRef && isSymbolicRef(headRef) && headRef.target.startsWith("refs/heads/")
1135
+ ? headRef.target.slice("refs/heads/".length)
1136
+ : undefined;
1137
+ if (branch !== undefined) {
1138
+ try {
1139
+ return await this.revisionResolver().upstreamOf(branch);
1140
+ } catch {
1141
+ // no upstream: the advice below
1142
+ }
1143
+ }
1144
+ const output = [
1145
+ branch !== undefined
1146
+ ? "There is no tracking information for the current branch."
1147
+ : "You are not currently on a branch.",
1148
+ "Please specify which branch you want to rebase against.",
1149
+ "See git-rebase(1) for details.",
1150
+ "",
1151
+ " git rebase '<branch>'",
1152
+ "",
1153
+ ];
1154
+ if (branch !== undefined) {
1155
+ const remote =
1156
+ RemoteConfigStore.from(this.workingCopy).value(`branch.${branch}.remote`) ?? "<remote>";
1157
+ output.push(
1158
+ "If you wish to set tracking information for this branch you can do so with:",
1159
+ "",
1160
+ ` git branch --set-upstream-to=${remote}/<branch> ${branch}`,
1161
+ "",
1162
+ );
1163
+ }
1164
+ return { status: RebaseStatus.FAILED, output };
1165
+ }
1166
+
1167
+ /** What git prints while it reads `name` (an ambiguous refname's warning). */
1168
+ private async nameWarnings(name: string): Promise<string[]> {
1169
+ const resolver = this.revisionResolver();
1170
+ await resolver.resolve(name, { hint: "committish" }).catch(() => undefined);
1171
+ return resolver.warnings;
1172
+ }
1173
+
1174
+ /** repo_get_oid_mb: the one merge base of `A...B` (either side empty is HEAD). */
1175
+ private async mergeBaseOfDots(name: string): Promise<ObjectId | undefined> {
1176
+ const dots = name.indexOf("...");
1177
+ const resolver = this.revisionResolver();
1178
+ const commitOf = async (rev: string) => {
1179
+ const id = await resolver.resolve(rev, { hint: "committish" }).catch(() => undefined);
1180
+ return id === undefined ? undefined : resolver.commitReference(id);
1181
+ };
1182
+ const one = await commitOf(dots === 0 ? "HEAD" : name.slice(0, dots));
1183
+ if (one === undefined) return undefined;
1184
+ const rest = name.slice(dots + 3);
1185
+ const two = await commitOf(rest === "" ? "HEAD" : rest);
1186
+ if (two === undefined) return undefined;
1187
+ const bases = await revisionMergeBases(this.commits, one, two);
1188
+ return bases.length === 1 ? bases[0] : undefined;
1189
+ }
1190
+
689
1191
  private async begin(
690
1192
  state: OperationState,
691
1193
  worktree: Worktree | undefined,
692
1194
  ): Promise<RebaseResult> {
693
- if (this.upstreamCommit === undefined && !this.root) {
694
- throw new UpstreamRequiredError("Upstream commit is required for rebase BEGIN operation");
695
- }
696
- // the upstream as given (setUpstream takes a name too) peeled to the commit it names
697
- // before anything is written, so HEAD is never set to a name ("main\n" in .git/HEAD)
698
- // an empty name too: "fatal: invalid upstream ''"
699
- if (this.upstreamCommit !== undefined) {
700
- this.upstreamCommit = await this.resolveUpstream(this.upstreamCommit);
701
- }
1195
+ const forkPoint = this.checkBeginOptions();
702
1196
  if (await this.inProgress(state)) {
703
1197
  return {
704
1198
  status: RebaseStatus.FAILED,
@@ -717,23 +1211,35 @@ export class RebaseCommand extends GitCommand<RebaseResult> {
717
1211
  if (command === "")
718
1212
  return { status: RebaseStatus.FAILED, message: "error: empty exec command" };
719
1213
  }
720
- const headResolved = await this.refsStore.resolve("HEAD");
721
- if (!headResolved?.objectId) throw new NoHeadError("HEAD cannot be resolved");
722
- const headId = headResolved.objectId;
723
- const headRef = await this.refsStore.get("HEAD");
724
- const headName = headRef && isSymbolicRef(headRef) ? headRef.target : "detached HEAD";
725
- // --root without --onto: the commits go onto git's squash_onto, a commit of the empty
726
- // tree with no parent (their root is then a root again)
727
- let squashOnto: ObjectId | undefined;
728
- if (!this.upstreamCommit) {
729
- squashOnto = await this.createSquashOnto();
730
- this.upstreamCommitName = squashOnto;
1214
+ const nameWarnings: string[] = [];
1215
+ let settled: Awaited<ReturnType<RebaseCommand["settleBegin"]>>;
1216
+ try {
1217
+ settled = await this.settleBegin(forkPoint, nameWarnings);
1218
+ } catch (error) {
1219
+ if (error instanceof GitApiError && nameWarnings.length > 0) {
1220
+ error.message = [...nameWarnings, error.message].join("\n");
1221
+ }
1222
+ throw error;
731
1223
  }
732
- const onto = (this.upstreamCommit ?? squashOnto) as ObjectId;
1224
+ if ("status" in settled) return settled;
1225
+ const {
1226
+ currentHead: headId,
1227
+ origHead,
1228
+ headName,
1229
+ branchName,
1230
+ onto,
1231
+ ontoName,
1232
+ upstream,
1233
+ upstreamName,
1234
+ restrict,
1235
+ branchBase,
1236
+ squashOnto,
1237
+ } = settled;
1238
+ this.runOntoName = ontoName;
733
1239
 
734
1240
  // git's require_clean_work_tree: no unstaged, no staged changes, unless they are
735
1241
  // stashed away for the rebase (rebase.autoStash) and applied again after it
736
- const output: string[] = [];
1242
+ const output: string[] = [...nameWarnings];
737
1243
  let autostash: ObjectId | undefined;
738
1244
  const refusal = await this.uncleanWorktree(headId, worktree);
739
1245
  if (refusal) {
@@ -774,27 +1280,39 @@ export class RebaseCommand extends GitCommand<RebaseResult> {
774
1280
  // git's can_fast_forward: HEAD already on upstream with a linear history since, nothing
775
1281
  // to do (unless forced, as the date options and --signoff do); an interactive rebase,
776
1282
  // --exec and --autosquash never take the shortcut (allow_preemptive_ff)
777
- const forced = this.committerDateIsAuthorDate || this.ignoreDate || this.signoff;
1283
+ const forced =
1284
+ this.forceRebase ||
1285
+ this.committerDateIsAuthorDate ||
1286
+ this.ignoreDate ||
1287
+ this.signoff ||
1288
+ this.trailerArgs.length > 0;
778
1289
  const preemptive = !interactive && execs.length === 0 && this.autosquash !== true;
779
- if (preemptive && !this.root && (await this.canFastForward(onto, headId))) {
780
- const upToDate = headName.startsWith("refs/")
781
- ? `Current branch ${headName.replace(/^refs\/heads\//, "")} is up to date`
782
- : "HEAD is up to date";
1290
+ if (preemptive && (await this.canFastForward(onto, upstream, restrict, origHead, branchBase))) {
1291
+ const upToDate =
1292
+ branchName === "HEAD" ? "HEAD is up to date" : `Current branch ${branchName} is up to date`;
783
1293
  if (!forced) {
1294
+ // lazily switch to the target branch if needed (checkout_up_to_date)
1295
+ if (this.branchArg !== undefined) {
1296
+ const refused = await this.checkoutUpToDate(worktree, headId, origHead, headName);
1297
+ if (refused) {
1298
+ await unstash();
1299
+ return { ...refused, output: [...output, ...(refused.output ?? [])] };
1300
+ }
1301
+ }
784
1302
  output.push(`${upToDate}.`);
785
1303
  // finish_rebase: what an earlier rebase left removed
786
1304
  await state.removeRef("REBASE_HEAD", "AUTO_MERGE");
787
1305
  await unstash();
788
- return { status: RebaseStatus.UP_TO_DATE, newHead: headId, output };
1306
+ return { status: RebaseStatus.UP_TO_DATE, newHead: origHead, output };
789
1307
  }
790
1308
  output.push(`${upToDate}, rebase forced.`);
791
1309
  }
792
1310
 
793
1311
  // the pre-rebase hook, told the upstream as given (`--root` with --root), may refuse
794
1312
  if (!this.noVerify) {
795
- const upstreamArg =
796
- this.root && !this.upstreamCommit ? "--root" : (this.upstreamCommitName ?? onto);
797
- const pre = await this.hooks.run("pre-rebase", { args: [upstreamArg] });
1313
+ const upstreamArg = this.root ? "--root" : (upstreamName as string);
1314
+ const args = this.branchArg !== undefined ? [upstreamArg, this.branchArg] : [upstreamArg];
1315
+ const pre = await this.hooks.run("pre-rebase", { args });
798
1316
  if (pre && pre.exitCode !== 0) {
799
1317
  await unstash();
800
1318
  return {
@@ -826,15 +1344,20 @@ export class RebaseCommand extends GitCommand<RebaseResult> {
826
1344
  output,
827
1345
  };
828
1346
  }
829
- await state.setRef("ORIG_HEAD", headId);
1347
+ await state.setRef("ORIG_HEAD", origHead);
830
1348
  await this.refsStore.set("HEAD", onto, this.startLog());
831
1349
  await runPostCheckoutHook(this.hooks, headId, onto, true);
832
1350
  await this.finishBranch(headName, onto, onto);
833
1351
  await unstash();
834
1352
  return { status, newHead: onto, output };
835
1353
  };
836
- // nothing of HEAD's to replay: HEAD moves to upstream
837
- if (await this.isAncestor(headId, onto)) return moveToOnto(RebaseStatus.FAST_FORWARD);
1354
+ // nothing of HEAD's to replay: HEAD moves to upstream (an interactive rebase still
1355
+ // shows its `noop` list to the editor, which may add commands)
1356
+ // get_revision_ranges' base: the upstream, else (--root) onto
1357
+ const base = upstream ?? onto;
1358
+ if (!interactive && base === onto && !restrict && (await this.isAncestor(origHead, onto))) {
1359
+ return moveToOnto(RebaseStatus.FAST_FORWARD);
1360
+ }
838
1361
 
839
1362
  // `--rebase-merges` (else `rebase.rebaseMerges`, a boolean or a cousins mode)
840
1363
  let rebaseMerges = this.rebaseMerges;
@@ -849,15 +1372,19 @@ export class RebaseCommand extends GitCommand<RebaseResult> {
849
1372
  }
850
1373
  // the commits to pick: HEAD's, not upstream's, merges dropped (kept with
851
1374
  // --rebase-merges), oldest first
852
- const range = await this.commitsToRebase(headId, onto, !!rebaseMerges);
1375
+ // (git's `<upstream>...<branch>` right side, `^<fork point>` excluded; with --root
1376
+ // everything below the branch)
1377
+ const excluded = [base, restrict].filter((id): id is ObjectId => id !== undefined);
1378
+ const range = await this.commitsToRebase(origHead, excluded, !!rebaseMerges);
853
1379
  // only merges since upstream (dropped without --rebase-merges): git's todo is a `noop`,
854
- // and the branch still moves to upstream
855
- if (range.length === 0) return moveToOnto(RebaseStatus.OK);
1380
+ // and the branch still moves to upstream (an interactive rebase shows that `noop`)
1381
+ if (range.length === 0 && !interactive) return moveToOnto(RebaseStatus.OK);
856
1382
  // commits whose change upstream has already (`--cherry-mark`): left out, with git's
857
1383
  // warnings (`make_script`), unless --reapply-cherry-picks
858
- const skipped = this.reapplyCherryPicks
859
- ? new Set<ObjectId>()
860
- : await this.appliedUpstream(headId, onto, range);
1384
+ const skipped =
1385
+ (this.reapplyCherryPicks ?? this.keepBase)
1386
+ ? new Set<ObjectId>()
1387
+ : await this.appliedUpstream(origHead, base, range, restrict);
861
1388
  const ids = range.filter((id) => !skipped.has(id));
862
1389
  if (skipped.size > 0) {
863
1390
  for (const id of range) {
@@ -869,7 +1396,8 @@ export class RebaseCommand extends GitCommand<RebaseResult> {
869
1396
  if (configBool(this.workingCopy, "advice.skippedCherryPicks", true)) {
870
1397
  output.push(
871
1398
  "hint: use --reapply-cherry-picks to include skipped commits",
872
- 'hint: Disable this message with "git config set advice.skippedCherryPicks false"',
1399
+ // 2.43's advice: `git config <key> false`
1400
+ `hint: Disable this message with "git config${(this.compatibility ?? this.hooks.compatibility) === "2.43" ? "" : " set"} advice.skippedCherryPicks false"`,
873
1401
  );
874
1402
  }
875
1403
  }
@@ -878,8 +1406,8 @@ export class RebaseCommand extends GitCommand<RebaseResult> {
878
1406
  let script = "";
879
1407
  if (rebaseMerges) {
880
1408
  script = await this.makeScriptWithMerges(
881
- headId,
882
- onto,
1409
+ origHead,
1410
+ base,
883
1411
  range,
884
1412
  skipped,
885
1413
  rebaseCousins,
@@ -902,12 +1430,19 @@ export class RebaseCommand extends GitCommand<RebaseResult> {
902
1430
  // init_basic_state / write_basic_state
903
1431
  await state.write(`${DIR}/head-name`, `${headName}\n`);
904
1432
  await state.write(`${DIR}/onto`, `${onto}\n`);
905
- await state.write(`${DIR}/orig-head`, `${headId}\n`);
1433
+ await state.write(`${DIR}/orig-head`, `${origHead}\n`);
1434
+ // write_basic_state: gpg_sign_opt (`-S<key>`) when the run signs
1435
+ const sign = signRequestOf(this.workingCopy, this.sign);
1436
+ this.runSign = { key: sign };
1437
+ if (sign !== undefined) await state.write(`${DIR}/gpg_sign_opt`, `-S${sign}\n`);
906
1438
  if (this.signoff) await state.write(`${DIR}/signoff`, "--signoff\n");
907
1439
  if (emptyMode === "drop") await state.write(`${DIR}/drop_redundant_commits`, "");
908
1440
  if (emptyMode === "keep") await state.write(`${DIR}/keep_redundant_commits`, "");
909
1441
  if (this.committerDateIsAuthorDate) await state.write(`${DIR}/cdate_is_adate`, "");
910
1442
  if (this.ignoreDate) await state.write(`${DIR}/ignore_date`, "");
1443
+ if (this.trailerArgs.length > 0) {
1444
+ await state.write(`${DIR}/trailer`, this.trailerArgs.map((t) => `${t}\n`).join(""));
1445
+ }
911
1446
  await state.write(
912
1447
  `${DIR}/${reschedule ? "reschedule-failed-exec" : "no-reschedule-failed-exec"}`,
913
1448
  "",
@@ -949,8 +1484,8 @@ export class RebaseCommand extends GitCommand<RebaseResult> {
949
1484
  comment,
950
1485
  {
951
1486
  shortRevisions: this.root
952
- ? await this.abbreviateObjectId(headId)
953
- : `${shortOnto}..${await this.abbreviateObjectId(headId)}`,
1487
+ ? await this.abbreviateObjectId(origHead)
1488
+ : `${await this.abbreviateObjectId(base)}..${await this.abbreviateObjectId(origHead)}`,
954
1489
  shortOnto,
955
1490
  },
956
1491
  missingCheck === "error",
@@ -987,7 +1522,7 @@ export class RebaseCommand extends GitCommand<RebaseResult> {
987
1522
  targetTree: ontoTreeId,
988
1523
  });
989
1524
  if (!refused) {
990
- await state.setRef("ORIG_HEAD", headId);
1525
+ await state.setRef("ORIG_HEAD", origHead);
991
1526
  await this.refsStore.set("HEAD", onto, this.startLog());
992
1527
  }
993
1528
  return { status: RebaseStatus.FAILED, message: lines.join("\n"), output };
@@ -1062,7 +1597,7 @@ export class RebaseCommand extends GitCommand<RebaseResult> {
1062
1597
  start,
1063
1598
  this.startLog(),
1064
1599
  "rebase: updating ORIG_HEAD",
1065
- { detach: true },
1600
+ { detach: true, origHead },
1066
1601
  )),
1067
1602
  );
1068
1603
  // checkout_onto's post-checkout hook: the HEAD left, the commit the picks start from
@@ -1251,13 +1786,30 @@ export class RebaseCommand extends GitCommand<RebaseResult> {
1251
1786
  if (!conflicts) {
1252
1787
  lines.push(`Stopped at ${await this.abbreviateObjectId(item.id)}... ${rest}`);
1253
1788
  }
1789
+ // error_with_patch: 2.5x writes the picked message as it is (have_message), 2.43 and a
1790
+ // fast-forwarded pick leave it to make_patch (the commit's, a line end added)
1791
+ const picked =
1792
+ outcome.kind === "ok" && (this.compatibility ?? this.hooks.compatibility) !== "2.43"
1793
+ ? outcome.message
1794
+ : undefined;
1254
1795
  lines.push(
1255
1796
  ...(await this.errorWithPatch(state, item.id, rest, {
1256
1797
  exitCode: conflicts ? 1 : 0,
1257
1798
  toAmend: outcome.kind === "ok",
1258
- ...(conflicts ? { message: outcome.message } : {}),
1259
- // the picked message (do_pick_commit's, --signoff's trailer appended)
1260
- signoff: !conflicts && (await state.exists(`${DIR}/signoff`)),
1799
+ ...(conflicts
1800
+ ? { message: outcome.message }
1801
+ : picked !== undefined
1802
+ ? { message: picked }
1803
+ : {}),
1804
+ // the picked message (do_pick_commit's, --signoff's and --trailer's trailers
1805
+ // added); a fast-forwarded pick (possible with --trailer after --continue) has
1806
+ // none, and make_patch writes the commit's own
1807
+ picked:
1808
+ !conflicts &&
1809
+ ((await state.exists(`${DIR}/signoff`)) ||
1810
+ (outcome.kind === "ok" &&
1811
+ outcome.message !== undefined &&
1812
+ (await state.exists(`${DIR}/trailer`)))),
1261
1813
  })),
1262
1814
  );
1263
1815
  return {
@@ -1287,7 +1839,10 @@ export class RebaseCommand extends GitCommand<RebaseResult> {
1287
1839
  conflicts: outcome.conflicts,
1288
1840
  message: [
1289
1841
  ...outcome.lines,
1290
- ...(await this.errorWithPatch(state, item.id, rest, { exitCode: 1, toAmend: true })),
1842
+ ...(await this.errorWithPatch(state, item.id, rest, {
1843
+ exitCode: 1,
1844
+ toAmend: outcome.toAmend ?? true,
1845
+ })),
1291
1846
  ].join("\n"),
1292
1847
  };
1293
1848
  }
@@ -1322,7 +1877,7 @@ export class RebaseCommand extends GitCommand<RebaseResult> {
1322
1877
  state: OperationState,
1323
1878
  id: ObjectId,
1324
1879
  rest: string,
1325
- options: { exitCode: number; toAmend: boolean; message?: string; signoff?: boolean },
1880
+ options: { exitCode: number; toAmend: boolean; message?: string; picked?: boolean },
1326
1881
  ): Promise<string[]> {
1327
1882
  if (options.message !== undefined && !(await state.exists(`${DIR}/message`))) {
1328
1883
  await state.write(`${DIR}/message`, options.message);
@@ -1336,9 +1891,7 @@ export class RebaseCommand extends GitCommand<RebaseResult> {
1336
1891
  const body = messageBody(commit?.message ?? "");
1337
1892
  await state.write(
1338
1893
  `${DIR}/message`,
1339
- options.signoff
1340
- ? appendSignoff(body, this.signoffLine(), trailerConfigOf(this.workingCopy))
1341
- : `${body}\n`,
1894
+ options.picked ? await this.pickedMessageOf(state, body) : `${body}\n`,
1342
1895
  );
1343
1896
  }
1344
1897
  if (options.toAmend) {
@@ -1346,7 +1899,7 @@ export class RebaseCommand extends GitCommand<RebaseResult> {
1346
1899
  return [
1347
1900
  "You can amend the commit now, with",
1348
1901
  "",
1349
- " git commit --amend ",
1902
+ ` git commit --amend ${await this.gpgSignOptQuoted(state)}`,
1350
1903
  "",
1351
1904
  "Once you are satisfied with your changes, run",
1352
1905
  "",
@@ -1402,7 +1955,7 @@ export class RebaseCommand extends GitCommand<RebaseResult> {
1402
1955
  await this.rewordHead(state);
1403
1956
  } catch (error) {
1404
1957
  // fast_forward_edit's git commit failed: a stop with HEAD to amend
1405
- return editorFailure(error);
1958
+ return signingFailure(error) ?? editorFailure(error);
1406
1959
  }
1407
1960
  }
1408
1961
  return { kind: "ok" };
@@ -1416,12 +1969,10 @@ export class RebaseCommand extends GitCommand<RebaseResult> {
1416
1969
  const parentTreeId = parentId ? await this.commits.getTree(parentId) : undefined;
1417
1970
  const subject = subjectOf(commit.message);
1418
1971
  // do_pick_commit: the message from its subject on; --signoff appends the committer's
1419
- // sign-off (not for a fixup or squash), before the merge (MERGE_MSG has it)
1972
+ // sign-off and --trailer its trailers (not for a fixup or squash), before the merge
1973
+ // (MERGE_MSG has them)
1420
1974
  const body = messageBody(commit.message);
1421
- const pickedMessage =
1422
- signoff && !fixup
1423
- ? appendSignoff(body, this.signoffLine(), trailerConfigOf(this.workingCopy))
1424
- : body;
1975
+ const pickedMessage = fixup ? body : await this.pickedMessageOf(state, body);
1425
1976
  let messageFile: "squash" | "fixup" | "edit" | undefined;
1426
1977
  if (fixup) {
1427
1978
  await this.updateSquashMessages(state, item, commit.message);
@@ -1497,13 +2048,7 @@ export class RebaseCommand extends GitCommand<RebaseResult> {
1497
2048
  conflicts: [...new Set(merge.conflicts.keys())].sort(),
1498
2049
  // git 2.43 writes the message and a blank line (2.5x the conflict list after it)
1499
2050
  message: `${merged}\n`,
1500
- lines: [
1501
- `error: could not apply ${short}... ${subject}`,
1502
- "hint: Resolve all conflicts manually, mark them as resolved with",
1503
- 'hint: "git add/rm <conflicted_files>", then run "git rebase --continue".',
1504
- 'hint: You can instead skip this commit: run "git rebase --skip".',
1505
- 'hint: To abort and get back to the state before "git rebase", run "git rebase --abort".',
1506
- ],
2051
+ lines: [`error: could not apply ${short}... ${subject}`, ...this.mergeConflictAdvice()],
1507
2052
  };
1508
2053
  }
1509
2054
  await state.write("MERGE_MSG", pickedMessage);
@@ -1511,7 +2056,7 @@ export class RebaseCommand extends GitCommand<RebaseResult> {
1511
2056
  // dropped (drop_redundant_commits), kept (keep_redundant_commits) or stops the rebase
1512
2057
  let allowEmpty = false;
1513
2058
  if (treeId === headTreeId) {
1514
- if (commit.tree === (parentTreeId ?? EMPTY_TREE_ID)) allowEmpty = true;
2059
+ if (commit.tree === (parentTreeId ?? this.objectFormat.emptyTreeId)) allowEmpty = true;
1515
2060
  else if (await state.exists(`${DIR}/keep_redundant_commits`)) allowEmpty = true;
1516
2061
  else if (await state.exists(`${DIR}/drop_redundant_commits`)) {
1517
2062
  await state.removeRef("AUTO_MERGE");
@@ -1533,7 +2078,7 @@ export class RebaseCommand extends GitCommand<RebaseResult> {
1533
2078
  if (!allowEmpty && head.parents.length <= 1) {
1534
2079
  const parentTree = head.parents[0]
1535
2080
  ? await this.commits.getTree(head.parents[0])
1536
- : EMPTY_TREE_ID;
2081
+ : this.objectFormat.emptyTreeId;
1537
2082
  if (parentTree === treeId) {
1538
2083
  // do_commit: REBASE_HEAD written before git commit runs
1539
2084
  await state.setRef("REBASE_HEAD", item.id);
@@ -1566,7 +2111,24 @@ export class RebaseCommand extends GitCommand<RebaseResult> {
1566
2111
  )) ?? "";
1567
2112
  if (signoff) message = stripspace(message);
1568
2113
  }
1569
- await this.amendHead(state, treeId, message, item.action, messageFile === "edit");
2114
+ try {
2115
+ await this.amendHead(state, treeId, message, item.action, messageFile === "edit");
2116
+ } catch (error) {
2117
+ if (!(error instanceof SigningFailedError)) throw error;
2118
+ // the end of a chain with a squash is git commit's (it dies), the rest try_to_commit's
2119
+ // (an error); then error_failed_squash, 2.43 rescheduling an in-process amend
2120
+ if (messageFile === "edit") {
2121
+ // git commit died before its cleanup: AUTO_MERGE stays
2122
+ await state.setRef("AUTO_MERGE", treeId);
2123
+ return {
2124
+ kind: "conflicts",
2125
+ conflicts: [],
2126
+ lines: [error.message, "fatal: failed to write commit object"],
2127
+ toAmend: this.hooks.compatibility !== "2.43",
2128
+ };
2129
+ }
2130
+ return this.signingStop(item, [error.message, "error: failed to write commit object"]);
2131
+ }
1570
2132
  // try_to_commit removes MERGE_MSG; git commit (the edited end of a chain) SQUASH_MSG too
1571
2133
  await state.remove("MERGE_MSG");
1572
2134
  if (messageFile === "edit") await state.remove("SQUASH_MSG");
@@ -1592,22 +2154,40 @@ export class RebaseCommand extends GitCommand<RebaseResult> {
1592
2154
  const message = signoff ? stripspace(pickedMessage) : pickedMessage;
1593
2155
  // do_pick_commit writes CHERRY_PICK_HEAD for the commit to come; do_commit deletes it
1594
2156
  // once try_to_commit made it
1595
- await state.withRefDuring("CHERRY_PICK_HEAD", item.id, () =>
1596
- this.commitOnto(state, unborn ? [] : [headId], treeId, commit.author, message, item.action),
1597
- );
2157
+ try {
2158
+ await state.withRefDuring("CHERRY_PICK_HEAD", item.id, () =>
2159
+ this.commitOnto(
2160
+ state,
2161
+ unborn ? [] : [headId],
2162
+ treeId,
2163
+ commit.author,
2164
+ message,
2165
+ item.action,
2166
+ ),
2167
+ );
2168
+ } catch (error) {
2169
+ if (!(error instanceof SigningFailedError)) throw error;
2170
+ // try_to_commit could not sign: 2.43 reschedules the pick, 2.5x stops as after a
2171
+ // conflict, the merged result staged for `--continue` (CHERRY_PICK_HEAD left)
2172
+ await state.setRef("CHERRY_PICK_HEAD", item.id);
2173
+ return this.signingStop(item, [error.message, "error: failed to write commit object"], {
2174
+ message: pickedMessage,
2175
+ });
2176
+ }
1598
2177
  // do_commit: the commit made, MERGE_MSG removed
1599
2178
  await state.remove("MERGE_MSG");
1600
2179
  if (item.action === RebaseAction.REWORD) {
1601
2180
  try {
1602
2181
  await this.rewordHead(state);
1603
2182
  } catch (error) {
1604
- // git commit --amend -e failed (the editor): the pick stays, the rebase stops
1605
- return { ...editorFailure(error), message: pickedMessage };
2183
+ // git commit --amend -e failed (the editor, the signing): the pick stays, the
2184
+ // rebase stops
2185
+ return { ...(signingFailure(error) ?? editorFailure(error)), message: pickedMessage };
1606
2186
  }
1607
2187
  }
1608
2188
  }
1609
2189
  if (finalFixup) await this.endFixupChain(state);
1610
- return { kind: "ok" };
2190
+ return fixup ? { kind: "ok" } : { kind: "ok", message: pickedMessage };
1611
2191
  }
1612
2192
 
1613
2193
  /** do_pick_commit after a final fixup: the chain's files removed. */
@@ -1750,10 +2330,12 @@ export class RebaseCommand extends GitCommand<RebaseResult> {
1750
2330
  const fixupOff = buf.length;
1751
2331
  buf += body.slice(commented);
1752
2332
  if (fixupFlag && !seenSquash) {
1753
- // the message replaced: --signoff's trailer appended (append_squash_message)
2333
+ // the message replaced: --signoff's and --trailer's trailers appended
2334
+ // (append_squash_message)
1754
2335
  if (await state.exists(`${DIR}/signoff`)) {
1755
- buf = appendSignoff(buf, this.signoffLine(), trailerConfigOf(this.workingCopy));
2336
+ buf = appendSignoff(buf, this.signoffLine(), this.trailerConfig());
1756
2337
  }
2338
+ buf = await this.withTrailers(state, buf);
1757
2339
  if (
1758
2340
  item.replaceMessage &&
1759
2341
  ((await state.exists(`${DIR}/message-fixup`)) ||
@@ -2150,14 +2732,32 @@ export class RebaseCommand extends GitCommand<RebaseResult> {
2150
2732
  // git commit -n -F MERGE_MSG --cleanup=verbatim (whitespace with --signoff, which the
2151
2733
  // merge does not get): the merge committed, its state removed
2152
2734
  const committed = (await state.exists(`${DIR}/signoff`)) ? stripspace(message) : message;
2153
- const newId = await this.commitOnto(
2154
- state,
2155
- [headId, head.id],
2156
- treeId,
2157
- author,
2158
- committed,
2159
- "merge",
2160
- );
2735
+ let newId: ObjectId;
2736
+ try {
2737
+ newId = await this.commitOnto(state, [headId, head.id], treeId, author, committed, "merge");
2738
+ } catch (error) {
2739
+ if (!(error instanceof SigningFailedError)) throw error;
2740
+ // do_merge's git commit dies signing: the merge stays staged (MERGE_HEAD, MERGE_MSG)
2741
+ // for --continue, the rebase stops as at a conflicting merge (AUTO_MERGE written)
2742
+ await state.setRef("AUTO_MERGE", treeId);
2743
+ await state.write(`${DIR}/message`, message);
2744
+ if (item.id) {
2745
+ await state.write(`${DIR}/stopped-sha`, `${item.id}\n`);
2746
+ await state.setRef("REBASE_HEAD", item.id);
2747
+ await state.write(`${DIR}/patch`, "");
2748
+ }
2749
+ const short = item.id ? await this.abbreviateObjectId(item.id) : "";
2750
+ return {
2751
+ status: RebaseStatus.STOPPED,
2752
+ ...(item.id ? { currentCommit: item.id } : {}),
2753
+ conflicts: [],
2754
+ message: [
2755
+ error.message,
2756
+ "fatal: failed to write commit object",
2757
+ item.id ? `Could not apply ${short}... ${arg}` : `Could not merge ${arg}`,
2758
+ ].join("\n"),
2759
+ };
2760
+ }
2161
2761
  // (git commit removes SQUASH_MSG too; the octopus' git merge leaves it)
2162
2762
  await state.remove("MERGE_MSG", "MERGE_HEAD", "MERGE_MODE", "SQUASH_MSG");
2163
2763
  await state.removeRef("AUTO_MERGE");
@@ -2202,6 +2802,10 @@ export class RebaseCommand extends GitCommand<RebaseResult> {
2202
2802
  .setCommitter(committer);
2203
2803
  // `merge -c`: --edit, the message cleaned up as an edited one
2204
2804
  if (item.editMessage) command.setCleanupMode(CleanupMode.STRIP);
2805
+ // do_merge passes the run's -S<key> to git merge, else --no-gpg-sign
2806
+ const sign = await this.signRequest(state);
2807
+ if (sign !== undefined) command.setSigningKey(sign);
2808
+ else command.setSign(false);
2205
2809
  // the merge inherits pull's GIT_REFLOG_ACTION, not the rebase's own action
2206
2810
  if (this.hasReflogAction()) command.setReflogAction(this.reflogAction("rebase"));
2207
2811
  for (const head of heads) command.include(head.id);
@@ -2258,13 +2862,15 @@ export class RebaseCommand extends GitCommand<RebaseResult> {
2258
2862
  tzOffset: commit.author.tzOffset,
2259
2863
  };
2260
2864
  }
2261
- const newId = await this.commits.store({
2262
- tree: commit.tree,
2263
- parents: commit.parents,
2264
- author: commit.author,
2265
- committer,
2266
- message,
2267
- });
2865
+ const newId = await this.commits.store(
2866
+ await this.signedRebaseCommit(state, {
2867
+ tree: commit.tree,
2868
+ parents: commit.parents,
2869
+ author: commit.author,
2870
+ committer,
2871
+ message,
2872
+ }),
2873
+ );
2268
2874
  const action = reflogMessages.rebaseStep(this.reflogAction("rebase"), "merge");
2269
2875
  await this.refsStore.set(
2270
2876
  "HEAD",
@@ -2318,12 +2924,86 @@ export class RebaseCommand extends GitCommand<RebaseResult> {
2318
2924
  * options and --signoff imply (`cdate_is_adate`, `ignore_date`, `signoff` in the state).
2319
2925
  */
2320
2926
  private async allowFastForward(state: OperationState): Promise<boolean> {
2927
+ // --trailer forces the run that starts the rebase (REBASE_FORCE) but, as in git, is not
2928
+ // read back as a reason to: a --continue may fast-forward again
2929
+ if (this.operation === RebaseOperation.BEGIN && this.trailerArgs.length > 0) return false;
2930
+ // so does --force-rebase (REBASE_FORCE, never saved in the state)
2931
+ if (this.operation === RebaseOperation.BEGIN && this.forceRebase) return false;
2321
2932
  for (const name of ["cdate_is_adate", "ignore_date", "signoff"]) {
2322
2933
  if (await state.exists(`${DIR}/${name}`)) return false;
2323
2934
  }
2324
2935
  return true;
2325
2936
  }
2326
2937
 
2938
+ /** The trailer configuration `--trailer` and `--signoff` apply (`trailer.*`). */
2939
+ private trailerConfig(): TrailerConfig {
2940
+ return {
2941
+ ...trailerConfigOf(this.workingCopy),
2942
+ compatibility: this.compatibility ?? this.hooks.compatibility,
2943
+ };
2944
+ }
2945
+
2946
+ /**
2947
+ * do_pick_commit's message of a pick: `--signoff`'s trailer, then the `--trailer`s
2948
+ * (amend_strbuf_with_trailers) kept in `rebase-merge/trailer`.
2949
+ */
2950
+ private async pickedMessageOf(state: OperationState, body: string): Promise<string> {
2951
+ let message = body;
2952
+ if (await state.exists(`${DIR}/signoff`)) {
2953
+ message = appendSignoff(message, this.signoffLine(), this.trailerConfig());
2954
+ }
2955
+ return this.withTrailers(state, message);
2956
+ }
2957
+
2958
+ /** amend_strbuf_with_trailers with the run's `--trailer`s (read_trailers), if any. */
2959
+ private async withTrailers(state: OperationState, message: string): Promise<string> {
2960
+ const args = await this.runTrailers(state);
2961
+ if (args.length === 0) return message;
2962
+ const hooks = this.hooks;
2963
+ const runCommand: TrailerCommandRunner | undefined = hooks.enabled
2964
+ ? (command) => hooks.runShellCommand("trailer", command.command, command.args)
2965
+ : undefined;
2966
+ return (await amendWithTrailers(message, args, this.trailerConfig(), runCommand)).output;
2967
+ }
2968
+
2969
+ /** read_trailers: the lines of `rebase-merge/trailer` (none without the file). */
2970
+ private async runTrailers(state: OperationState): Promise<string[]> {
2971
+ const text = await state.read(`${DIR}/trailer`);
2972
+ if (text === undefined) return [];
2973
+ if (text === "") {
2974
+ throw new GitApiError("error: trailers file is empty", { exitCode: 1 });
2975
+ }
2976
+ const lines = text.split("\n");
2977
+ // a last line without its newline is not read (strchr finds none)
2978
+ lines.pop();
2979
+ if (lines.some((l) => l === "")) {
2980
+ throw new GitApiError("error: trailers file contains empty line", { exitCode: 1 });
2981
+ }
2982
+ return lines;
2983
+ }
2984
+
2985
+ /**
2986
+ * print_advice's hints at a conflicting pick (`advice.mergeConflict`, 2.45+: off drops
2987
+ * them, unset adds how to turn them off; 2.43 always gives them as they are).
2988
+ */
2989
+ private mergeConflictAdvice(): string[] {
2990
+ const hints = [
2991
+ "hint: Resolve all conflicts manually, mark them as resolved with",
2992
+ 'hint: "git add/rm <conflicted_files>", then run "git rebase --continue".',
2993
+ 'hint: You can instead skip this commit: run "git rebase --skip".',
2994
+ 'hint: To abort and get back to the state before "git rebase", run "git rebase --abort".',
2995
+ ];
2996
+ if ((this.compatibility ?? this.hooks.compatibility) === "2.43") return hints;
2997
+ const value = configValue(this.workingCopy, "advice.mergeConflict");
2998
+ if (value === undefined) {
2999
+ return [
3000
+ ...hints,
3001
+ 'hint: Disable this message with "git config set advice.mergeConflict false"',
3002
+ ];
3003
+ }
3004
+ return (parseGitBool(value) ?? true) ? hints : [];
3005
+ }
3006
+
2327
3007
  /** append_signoff's `Signed-off-by: <committer name> <email>` line. */
2328
3008
  private signoffLine(): string {
2329
3009
  const committer = this.committer ?? this.resolveCommitter();
@@ -2404,7 +3084,7 @@ export class RebaseCommand extends GitCommand<RebaseResult> {
2404
3084
  }
2405
3085
  if (buf === "") buf = `rev-${await this.abbreviateObjectId(oid)}`;
2406
3086
  if (
2407
- (buf.length === 40 && /^[0-9a-fA-F]{40}$/.test(buf)) ||
3087
+ (buf.length === this.objectFormat.hexLength && /^[0-9a-fA-F]+$/.test(buf)) ||
2408
3088
  buf === "#" ||
2409
3089
  labels.has(buf)
2410
3090
  ) {
@@ -2443,7 +3123,7 @@ export class RebaseCommand extends GitCommand<RebaseResult> {
2443
3123
  if (!commit) throw new CommitNotFoundError(id);
2444
3124
  const parentTree = commit.parents[0]
2445
3125
  ? (await this.loadCommit(commit.parents[0]))?.tree
2446
- : EMPTY_TREE_ID;
3126
+ : this.objectFormat.emptyTreeId;
2447
3127
  const empty = commit.tree === parentTree;
2448
3128
  if (!empty && skipped.has(id)) continue;
2449
3129
  if (empty && !keepEmpty) continue;
@@ -2627,7 +3307,10 @@ export class RebaseCommand extends GitCommand<RebaseResult> {
2627
3307
  const treeId = await this.staging.writeTree(this.trees);
2628
3308
  const isClean = headCommit?.tree === treeId;
2629
3309
  if (!isClean && !(await state.exists(`${DIR}/message`))) {
2630
- return { status: RebaseStatus.FAILED, message: STAGED_CHANGES_ADVICE };
3310
+ return {
3311
+ status: RebaseStatus.FAILED,
3312
+ message: stagedChangesAdvice(await this.gpgSignOptQuoted(state)),
3313
+ };
2631
3314
  }
2632
3315
  let amend = false;
2633
3316
  let finalFixup = false;
@@ -2740,6 +3423,7 @@ export class RebaseCommand extends GitCommand<RebaseResult> {
2740
3423
  }
2741
3424
  }
2742
3425
  } catch (error) {
3426
+ if (error instanceof SigningFailedError) return commitStagedSigningFailure(error);
2743
3427
  // git commit failed on its editor: nothing committed, the stop stays as it is
2744
3428
  return {
2745
3429
  status: RebaseStatus.FAILED,
@@ -2750,8 +3434,14 @@ export class RebaseCommand extends GitCommand<RebaseResult> {
2750
3434
  }
2751
3435
  if (gitCommit) {
2752
3436
  // committed above, with git commit's hooks
2753
- } else if (amend) await this.amendHead(state, treeId, message, "continue", true);
2754
- else {
3437
+ } else if (amend) {
3438
+ try {
3439
+ await this.amendHead(state, treeId, message, "continue", true);
3440
+ } catch (error) {
3441
+ if (error instanceof SigningFailedError) return commitStagedSigningFailure(error);
3442
+ throw error;
3443
+ }
3444
+ } else {
2755
3445
  // a stopped merge: its other parents (git commit reads MERGE_HEAD, one per line: an
2756
3446
  // octopus has several)
2757
3447
  const mergeHeads = ((await state.read("MERGE_HEAD")) ?? "")
@@ -2760,7 +3450,12 @@ export class RebaseCommand extends GitCommand<RebaseResult> {
2760
3450
  .filter((line) => /^[0-9a-f]{40,64}$/.test(line));
2761
3451
  const author =
2762
3452
  parseAuthorScript((await state.read(`${DIR}/author-script`)) ?? "") ?? this.resolveAuthor();
2763
- await this.commitOnto(state, [headId, ...mergeHeads], treeId, author, message, "continue");
3453
+ try {
3454
+ await this.commitOnto(state, [headId, ...mergeHeads], treeId, author, message, "continue");
3455
+ } catch (error) {
3456
+ if (error instanceof SigningFailedError) return commitStagedSigningFailure(error);
3457
+ throw error;
3458
+ }
2764
3459
  }
2765
3460
  // git commit's cleanup (SQUASH_MSG of a final squash too), then commit_staged_changes'
2766
3461
  await state.remove(`${DIR}/amend`, "MERGE_HEAD", "MERGE_MODE", "MERGE_MSG", "SQUASH_MSG");
@@ -2789,6 +3484,63 @@ export class RebaseCommand extends GitCommand<RebaseResult> {
2789
3484
  return this.resume(state, worktree);
2790
3485
  }
2791
3486
 
3487
+ /**
3488
+ * `git rebase --quit` and `--show-current-patch` (builtin/rebase.c's ACTION_QUIT and
3489
+ * ACTION_SHOW_CURRENT_PATCH): the backend found as cmd_rebase finds it (`rebase-apply/`
3490
+ * first, `rebase-apply/applying` being git am's), refused when no rebase is in progress.
3491
+ */
3492
+ private async quitOrShow(
3493
+ state: OperationState,
3494
+ worktree: Worktree | undefined,
3495
+ operation: RebaseOperation,
3496
+ ): Promise<RebaseResult> {
3497
+ const APPLY_DIR = "rebase-apply";
3498
+ if (await state.exists(`${APPLY_DIR}/applying`)) {
3499
+ return {
3500
+ status: RebaseStatus.FAILED,
3501
+ message: "fatal: It looks like 'git am' is in progress. Cannot rebase.",
3502
+ };
3503
+ }
3504
+ const apply = await state.exists(APPLY_DIR);
3505
+ if (!apply && !(await state.exists(DIR))) {
3506
+ const legacy = (this.compatibility ?? this.hooks.compatibility) === "2.43";
3507
+ return {
3508
+ status: RebaseStatus.FAILED,
3509
+ message: legacy ? "fatal: No rebase in progress?" : "fatal: no rebase in progress",
3510
+ };
3511
+ }
3512
+ const stateDir = apply ? APPLY_DIR : DIR;
3513
+ if (operation === RebaseOperation.SHOW_CURRENT_PATCH) {
3514
+ if (apply) {
3515
+ // run_am: `git am --show-current-patch` (its rebasing session shows the original
3516
+ // commit, `git show <original-commit>`)
3517
+ const am = await new AmCommand(this.workingCopy).setShowCurrentPatch("raw").call();
3518
+ if (am.exitCode !== 0) {
3519
+ return { status: RebaseStatus.FAILED, message: am.errors.replace(/\n$/, "") };
3520
+ }
3521
+ return { status: RebaseStatus.OK, currentPatch: am.output };
3522
+ }
3523
+ // run_sequencer_rebase: `git show REBASE_HEAD --` (its failure is rebase's exit 1)
3524
+ const id = await state.ref("REBASE_HEAD");
3525
+ if (!id) return { status: RebaseStatus.FAILED, message: "fatal: bad revision 'REBASE_HEAD'" };
3526
+ return { status: RebaseStatus.OK, currentPatch: await showCommit(this.workingCopy, id) };
3527
+ }
3528
+ // ACTION_QUIT: save_autostash (kept on refs/stash), then sequencer_remove_state for the
3529
+ // merge backend (refs-to-delete deleted, the directory removed) or the directory alone;
3530
+ // REBASE_HEAD, AUTO_MERGE, ORIG_HEAD, MERGE_MSG and HEAD stay as they are
3531
+ const output: string[] = [];
3532
+ const autostash = (await state.read(`${stateDir}/autostash`))?.trim();
3533
+ if (autostash) {
3534
+ await saveAutostash(this.context(worktree), autostash);
3535
+ await state.remove(`${stateDir}/autostash`);
3536
+ output.push(...AUTOSTASH_SAVED_LINES);
3537
+ }
3538
+ if (!apply) await this.deleteRewrittenRefs(state);
3539
+ await state.remove(stateDir);
3540
+ const head = (await this.refsStore.resolve("HEAD").catch(() => undefined))?.objectId;
3541
+ return { status: RebaseStatus.OK, ...(head ? { newHead: head } : {}), output };
3542
+ }
3543
+
2792
3544
  /** `git rebase --abort`: back to the original branch and commit (`reset --hard`). */
2793
3545
  private async abort(
2794
3546
  state: OperationState,
@@ -2919,13 +3671,10 @@ export class RebaseCommand extends GitCommand<RebaseResult> {
2919
3671
  commentPrefixOf(this.workingCopy),
2920
3672
  )
2921
3673
  : await sequencerPrepareMessage(this.hooks, state, message);
2922
- const id = await this.commits.store({
2923
- tree,
2924
- parents,
2925
- author,
2926
- committer,
2927
- message: hooked,
2928
- });
3674
+ // commit_tree signs: when it cannot, git's failure (each step says what follows)
3675
+ const id = await this.commits.store(
3676
+ await this.signedRebaseCommit(state, { tree, parents, author, committer, message: hooked }),
3677
+ );
2929
3678
  const action = reflogMessages.rebaseStep(this.reflogAction("rebase"), step);
2930
3679
  const log = this.reflogLine(reflogMessages.pick(action, hooked), this.committer);
2931
3680
  const refs = this.refsStore;
@@ -2970,7 +3719,7 @@ export class RebaseCommand extends GitCommand<RebaseResult> {
2970
3719
 
2971
3720
  /** HEAD detached at upstream: `rebase (start): checkout <upstream as given>`. */
2972
3721
  private startLog(): RefLogOptions {
2973
- const onto = this.upstreamCommitName ?? this.upstreamCommit ?? "";
3722
+ const onto = this.runOntoName ?? this.upstreamCommitName ?? this.upstreamCommit ?? "";
2974
3723
  return this.reflogLine(
2975
3724
  reflogMessages.rebaseStart(this.reflogAction("rebase"), onto),
2976
3725
  this.committer,
@@ -3326,7 +4075,7 @@ export class RebaseCommand extends GitCommand<RebaseResult> {
3326
4075
  if (!commit) return false;
3327
4076
  const parentTree = commit.parents[0]
3328
4077
  ? (await this.loadCommit(commit.parents[0]))?.tree
3329
- : EMPTY_TREE_ID;
4078
+ : this.objectFormat.emptyTreeId;
3330
4079
  return commit.tree === parentTree;
3331
4080
  }
3332
4081
 
@@ -3606,7 +4355,11 @@ export class RebaseCommand extends GitCommand<RebaseResult> {
3606
4355
  } else {
3607
4356
  out.push({ action: RebaseAction.UPDATE_REF, id: "", rest: name, blankAfter: true });
3608
4357
  if (!records.some((r) => r.ref === name)) {
3609
- records.push({ ref: name, before: values.get(name) ?? ZERO_ID, after: ZERO_ID });
4358
+ records.push({
4359
+ ref: name,
4360
+ before: values.get(name) ?? this.objectFormat.nullId,
4361
+ after: this.objectFormat.nullId,
4362
+ });
3610
4363
  }
3611
4364
  }
3612
4365
  }
@@ -3626,14 +4379,18 @@ export class RebaseCommand extends GitCommand<RebaseResult> {
3626
4379
  .map((item) => item.rest ?? "");
3627
4380
  let updated = false;
3628
4381
  const kept = records.filter((r) => {
3629
- const keep = r.after !== ZERO_ID || named.includes(r.ref);
4382
+ const keep = r.after !== this.objectFormat.nullId || named.includes(r.ref);
3630
4383
  if (!keep) updated = true;
3631
4384
  return keep;
3632
4385
  });
3633
4386
  for (const ref of named) {
3634
4387
  if (!kept.some((r) => r.ref === ref)) {
3635
4388
  const value = (await this.refsStore.resolve(ref).catch(() => undefined))?.objectId;
3636
- kept.push({ ref, before: value ?? ZERO_ID, after: ZERO_ID });
4389
+ kept.push({
4390
+ ref,
4391
+ before: value ?? this.objectFormat.nullId,
4392
+ after: this.objectFormat.nullId,
4393
+ });
3637
4394
  updated = true;
3638
4395
  }
3639
4396
  }
@@ -3663,7 +4420,10 @@ export class RebaseCommand extends GitCommand<RebaseResult> {
3663
4420
  const failed: string[] = [];
3664
4421
  for (const record of records) {
3665
4422
  const value = (await this.refsStore.resolve(record.ref).catch(() => undefined))?.objectId;
3666
- if ((value ?? ZERO_ID) !== record.before || record.after === ZERO_ID) {
4423
+ if (
4424
+ (value ?? this.objectFormat.nullId) !== record.before ||
4425
+ record.after === this.objectFormat.nullId
4426
+ ) {
3667
4427
  failed.push(record.ref);
3668
4428
  continue;
3669
4429
  }
@@ -3765,11 +4525,11 @@ export class RebaseCommand extends GitCommand<RebaseResult> {
3765
4525
  */
3766
4526
  private async commitsToRebase(
3767
4527
  head: ObjectId,
3768
- upstream: ObjectId,
4528
+ excluded: ObjectId[],
3769
4529
  keepMerges = false,
3770
4530
  ): Promise<ObjectId[]> {
3771
4531
  const upstreamCommits = new Set<ObjectId>();
3772
- const walk = [upstream];
4532
+ const walk = [...excluded];
3773
4533
  while (walk.length > 0) {
3774
4534
  const id = walk.pop() as ObjectId;
3775
4535
  if (upstreamCommits.has(id)) continue;
@@ -3825,9 +4585,11 @@ export class RebaseCommand extends GitCommand<RebaseResult> {
3825
4585
  head: ObjectId,
3826
4586
  upstream: ObjectId,
3827
4587
  range: ObjectId[],
4588
+ /** The fork point (`^<fork point>`), which limits upstream's side too */
4589
+ restrict?: ObjectId,
3828
4590
  ): Promise<Set<ObjectId>> {
3829
4591
  const skipped = new Set<ObjectId>();
3830
- const left = await this.onlyReachableFrom(upstream, head);
4592
+ const left = await this.onlyReachableFrom(upstream, restrict ? [head, restrict] : [head]);
3831
4593
  if (left.length === 0 || range.length === 0) return skipped;
3832
4594
  // each tree read once: a commit's tree is its child's parent tree
3833
4595
  const treeEntries = new Map<ObjectId, TreeEntry[]>();
@@ -3849,7 +4611,10 @@ export class RebaseCommand extends GitCommand<RebaseResult> {
3849
4611
  const parentTree = commit.parents[0]
3850
4612
  ? (await this.loadCommit(commit.parents[0]))?.tree
3851
4613
  : undefined;
3852
- return patchId(trees, this.blobs, parentTree, commit.tree, { headerOnly });
4614
+ return patchId(trees, this.blobs, parentTree, commit.tree, {
4615
+ headerOnly,
4616
+ objectFormat: this.objectFormat,
4617
+ });
3853
4618
  };
3854
4619
  const full = new Map<ObjectId, string | undefined>();
3855
4620
  const fullOf = async (id: ObjectId) => {
@@ -3885,7 +4650,7 @@ export class RebaseCommand extends GitCommand<RebaseResult> {
3885
4650
  * what `other` reaches painted uninteresting, done once every commit still queued is
3886
4651
  * uninteresting (and a few more, git's slop against clock skew).
3887
4652
  */
3888
- private async onlyReachableFrom(tip: ObjectId, other: ObjectId): Promise<ObjectId[]> {
4653
+ private async onlyReachableFrom(tip: ObjectId, others: ObjectId[]): Promise<ObjectId[]> {
3889
4654
  interface Node {
3890
4655
  id: ObjectId;
3891
4656
  time: number;
@@ -3927,7 +4692,7 @@ export class RebaseCommand extends GitCommand<RebaseResult> {
3927
4692
  }
3928
4693
  }
3929
4694
  };
3930
- await push(other, true);
4695
+ for (const other of others) await push(other, true);
3931
4696
  await push(tip, false);
3932
4697
  const out: Node[] = [];
3933
4698
  let slop = 5;
@@ -3957,13 +4722,63 @@ export class RebaseCommand extends GitCommand<RebaseResult> {
3957
4722
  }
3958
4723
 
3959
4724
  /**
3960
- * builtin/rebase.c's can_fast_forward for `git rebase <upstream>` (onto the upstream, no
3961
- * fork point, no --keep-base): HEAD and upstream have one merge base, upstream itself, and
3962
- * the first-parent line from HEAD down to it has no merge (is_linear_history). Upstream
3963
- * in HEAD's history is that one merge base.
4725
+ * builtin/rebase.c's checkout_up_to_date: the `<branch>` argument checked out when there
4726
+ * is nothing to rebase (reset_working_tree: the worktree switched from HEAD, the branch
4727
+ * and HEAD logged `rebase: checkout <branch>`, the post-checkout hook run).
4728
+ */
4729
+ private async checkoutUpToDate(
4730
+ worktree: Worktree | undefined,
4731
+ headId: ObjectId,
4732
+ origHead: ObjectId,
4733
+ headName: string,
4734
+ ): Promise<RebaseResult | undefined> {
4735
+ const branch = this.branchArg as string;
4736
+ const headTree = await flatTree(this.trees, await this.commits.getTree(headId));
4737
+ const targetTreeId = await this.commits.getTree(origHead);
4738
+ const targetTree = await flatTree(this.trees, targetTreeId);
4739
+ const refused = await switchTrees(this.context(worktree), headTree, targetTree, {
4740
+ action: "checkout",
4741
+ operation: "rebase",
4742
+ targetTree: targetTreeId,
4743
+ });
4744
+ if (refused) {
4745
+ return {
4746
+ status: RebaseStatus.FAILED,
4747
+ message: `${refused.message}\nerror: could not switch to ${branch}`,
4748
+ };
4749
+ }
4750
+ const log = this.reflogLine(
4751
+ `${this.reflogAction("rebase")}: checkout ${branch}`,
4752
+ this.committer,
4753
+ );
4754
+ if (headName.startsWith("refs/")) {
4755
+ await this.refsStore.set(headName, origHead, log);
4756
+ await this.refsStore.setSymbolic("HEAD", headName, log);
4757
+ } else {
4758
+ await this.refsStore.set("HEAD", origHead, log);
4759
+ }
4760
+ await runPostCheckoutHook(this.hooks, headId, origHead, true);
4761
+ return undefined;
4762
+ }
4763
+
4764
+ /**
4765
+ * builtin/rebase.c's can_fast_forward: the branch's one merge base with onto is onto
4766
+ * (`branchBase`), the fork point (if any) is that base too, the upstream (none with
4767
+ * --root) and the branch have one merge base, onto, and the first-parent line from the
4768
+ * branch down to onto has no merge (is_linear_history).
3964
4769
  */
3965
- private async canFastForward(onto: ObjectId, head: ObjectId): Promise<boolean> {
3966
- if (!(await this.isAncestor(onto, head))) return false;
4770
+ private async canFastForward(
4771
+ onto: ObjectId,
4772
+ upstream: ObjectId | undefined,
4773
+ restrict: ObjectId | undefined,
4774
+ head: ObjectId,
4775
+ branchBase: ObjectId | undefined,
4776
+ ): Promise<boolean> {
4777
+ if (branchBase === undefined || branchBase !== onto) return false;
4778
+ if (restrict !== undefined && restrict !== branchBase) return false;
4779
+ if (upstream === undefined) return false;
4780
+ const bases = await revisionMergeBases(this.commits, upstream, head);
4781
+ if (bases.length !== 1 || bases[0] !== onto) return false;
3967
4782
  let id: ObjectId | undefined = head;
3968
4783
  while (id !== undefined && id !== onto) {
3969
4784
  const parents: ObjectId[] = (await this.loadCommit(id))?.parents ?? [];