@statewalker/vcs-commands 0.5.0 → 0.6.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 (546) hide show
  1. package/README.md +123 -8
  2. package/dist/commands/add-command.d.ts +265 -34
  3. package/dist/commands/add-command.d.ts.map +1 -1
  4. package/dist/commands/add-patch/add-interactive.d.ts +46 -0
  5. package/dist/commands/add-patch/add-interactive.d.ts.map +1 -0
  6. package/dist/commands/add-patch/add-patch.d.ts +139 -0
  7. package/dist/commands/add-patch/add-patch.d.ts.map +1 -0
  8. package/dist/commands/add-patch/index.d.ts +6 -0
  9. package/dist/commands/add-patch/index.d.ts.map +1 -0
  10. package/dist/commands/add-patch/patch-backend.d.ts +80 -0
  11. package/dist/commands/add-patch/patch-backend.d.ts.map +1 -0
  12. package/dist/commands/add-patch/patch-modes.d.ts +71 -0
  13. package/dist/commands/add-patch/patch-modes.d.ts.map +1 -0
  14. package/dist/commands/add-patch/patch-session.d.ts +49 -0
  15. package/dist/commands/add-patch/patch-session.d.ts.map +1 -0
  16. package/dist/commands/am/am-command.d.ts +175 -0
  17. package/dist/commands/am/am-command.d.ts.map +1 -0
  18. package/dist/commands/am/index.d.ts +3 -0
  19. package/dist/commands/am/index.d.ts.map +1 -0
  20. package/dist/commands/am/mailinfo.d.ts +58 -0
  21. package/dist/commands/am/mailinfo.d.ts.map +1 -0
  22. package/dist/commands/am/patch-format.d.ts +24 -0
  23. package/dist/commands/am/patch-format.d.ts.map +1 -0
  24. package/dist/commands/apply/apply-command.d.ts +153 -0
  25. package/dist/commands/apply/apply-command.d.ts.map +1 -0
  26. package/dist/commands/apply/apply-engine.d.ts +195 -0
  27. package/dist/commands/apply/apply-engine.d.ts.map +1 -0
  28. package/dist/commands/apply/apply-parse.d.ts +86 -0
  29. package/dist/commands/apply/apply-parse.d.ts.map +1 -0
  30. package/dist/commands/apply/apply-types.d.ts +70 -0
  31. package/dist/commands/apply/apply-types.d.ts.map +1 -0
  32. package/dist/commands/apply/index.d.ts +6 -0
  33. package/dist/commands/apply/index.d.ts.map +1 -0
  34. package/dist/commands/apply/latin1.d.ts +32 -0
  35. package/dist/commands/apply/latin1.d.ts.map +1 -0
  36. package/dist/commands/apply/whitespace.d.ts +58 -0
  37. package/dist/commands/apply/whitespace.d.ts.map +1 -0
  38. package/dist/commands/attributes-source.d.ts +26 -0
  39. package/dist/commands/attributes-source.d.ts.map +1 -0
  40. package/dist/commands/backfill-command.d.ts +110 -0
  41. package/dist/commands/backfill-command.d.ts.map +1 -0
  42. package/dist/commands/bisect/bisect-checkout.d.ts +64 -0
  43. package/dist/commands/bisect/bisect-checkout.d.ts.map +1 -0
  44. package/dist/commands/bisect/bisect-command.d.ts +201 -0
  45. package/dist/commands/bisect/bisect-command.d.ts.map +1 -0
  46. package/dist/commands/bisect/bisect-engine.d.ts +219 -0
  47. package/dist/commands/bisect/bisect-engine.d.ts.map +1 -0
  48. package/dist/commands/bisect/bisect-graph.d.ts +127 -0
  49. package/dist/commands/bisect/bisect-graph.d.ts.map +1 -0
  50. package/dist/commands/bisect/bisect-quote.d.ts +27 -0
  51. package/dist/commands/bisect/bisect-quote.d.ts.map +1 -0
  52. package/dist/commands/bisect/index.d.ts +5 -0
  53. package/dist/commands/bisect/index.d.ts.map +1 -0
  54. package/dist/commands/blame-command.d.ts +122 -131
  55. package/dist/commands/blame-command.d.ts.map +1 -1
  56. package/dist/commands/branch-command.d.ts +52 -2
  57. package/dist/commands/branch-command.d.ts.map +1 -1
  58. package/dist/commands/branch-tracking.d.ts +98 -0
  59. package/dist/commands/branch-tracking.d.ts.map +1 -0
  60. package/dist/commands/checkout-command.d.ts +300 -18
  61. package/dist/commands/checkout-command.d.ts.map +1 -1
  62. package/dist/commands/checkout-paths.d.ts +124 -0
  63. package/dist/commands/checkout-paths.d.ts.map +1 -0
  64. package/dist/commands/cherry-pick-command.d.ts +50 -42
  65. package/dist/commands/cherry-pick-command.d.ts.map +1 -1
  66. package/dist/commands/clean-command.d.ts +49 -16
  67. package/dist/commands/clean-command.d.ts.map +1 -1
  68. package/dist/commands/clone-command.d.ts +117 -0
  69. package/dist/commands/clone-command.d.ts.map +1 -1
  70. package/dist/commands/commit-command.d.ts +311 -17
  71. package/dist/commands/commit-command.d.ts.map +1 -1
  72. package/dist/commands/core-config.d.ts +78 -1
  73. package/dist/commands/core-config.d.ts.map +1 -1
  74. package/dist/commands/date-format.d.ts +58 -0
  75. package/dist/commands/date-format.d.ts.map +1 -0
  76. package/dist/commands/describe-command.d.ts.map +1 -1
  77. package/dist/commands/diff-command.d.ts +377 -30
  78. package/dist/commands/diff-command.d.ts.map +1 -1
  79. package/dist/commands/diff-textconv.d.ts +40 -0
  80. package/dist/commands/diff-textconv.d.ts.map +1 -0
  81. package/dist/commands/fetch-command.d.ts +149 -10
  82. package/dist/commands/fetch-command.d.ts.map +1 -1
  83. package/dist/commands/format-patch-command.d.ts +164 -0
  84. package/dist/commands/format-patch-command.d.ts.map +1 -0
  85. package/dist/commands/fsck/fetch-fsck.d.ts +60 -0
  86. package/dist/commands/fsck/fetch-fsck.d.ts.map +1 -0
  87. package/dist/commands/fsck/fsck-command.d.ts +225 -0
  88. package/dist/commands/fsck/fsck-command.d.ts.map +1 -0
  89. package/dist/commands/fsck/fsck-loose.d.ts +68 -0
  90. package/dist/commands/fsck/fsck-loose.d.ts.map +1 -0
  91. package/dist/commands/fsck/fsck-msg-ids.d.ts +122 -0
  92. package/dist/commands/fsck/fsck-msg-ids.d.ts.map +1 -0
  93. package/dist/commands/fsck/fsck-object-checks.d.ts +148 -0
  94. package/dist/commands/fsck/fsck-object-checks.d.ts.map +1 -0
  95. package/dist/commands/fsck/fsck-object-table.d.ts +132 -0
  96. package/dist/commands/fsck/fsck-object-table.d.ts.map +1 -0
  97. package/dist/commands/fsck/fsck-pack.d.ts +115 -0
  98. package/dist/commands/fsck/fsck-pack.d.ts.map +1 -0
  99. package/dist/commands/fsck/index.d.ts +6 -0
  100. package/dist/commands/fsck/index.d.ts.map +1 -0
  101. package/dist/commands/fsck/verify-pack-command.d.ts +81 -0
  102. package/dist/commands/fsck/verify-pack-command.d.ts.map +1 -0
  103. package/dist/commands/gc-command.d.ts +43 -0
  104. package/dist/commands/gc-command.d.ts.map +1 -1
  105. package/dist/commands/git-date.d.ts +66 -0
  106. package/dist/commands/git-date.d.ts.map +1 -0
  107. package/dist/commands/git-describe.d.ts +67 -0
  108. package/dist/commands/git-describe.d.ts.map +1 -0
  109. package/dist/commands/git-hooks.d.ts +416 -0
  110. package/dist/commands/git-hooks.d.ts.map +1 -0
  111. package/dist/commands/git-ident.d.ts +128 -0
  112. package/dist/commands/git-ident.d.ts.map +1 -0
  113. package/dist/commands/hook-command.d.ts +96 -0
  114. package/dist/commands/hook-command.d.ts.map +1 -0
  115. package/dist/commands/index-adder.d.ts +231 -0
  116. package/dist/commands/index-adder.d.ts.map +1 -0
  117. package/dist/commands/index-host.d.ts +86 -0
  118. package/dist/commands/index-host.d.ts.map +1 -0
  119. package/dist/commands/index.d.ts +54 -0
  120. package/dist/commands/index.d.ts.map +1 -1
  121. package/dist/commands/index.js +3 -2
  122. package/dist/commands/init-command.d.ts +12 -1
  123. package/dist/commands/init-command.d.ts.map +1 -1
  124. package/dist/commands/local-clone.d.ts +60 -0
  125. package/dist/commands/local-clone.d.ts.map +1 -0
  126. package/dist/commands/local-transport.d.ts +117 -0
  127. package/dist/commands/local-transport.d.ts.map +1 -0
  128. package/dist/commands/log-command.d.ts +216 -24
  129. package/dist/commands/log-command.d.ts.map +1 -1
  130. package/dist/commands/log-graph.d.ts +120 -0
  131. package/dist/commands/log-graph.d.ts.map +1 -0
  132. package/dist/commands/log-output.d.ts +323 -0
  133. package/dist/commands/log-output.d.ts.map +1 -0
  134. package/dist/commands/ls-remote-command.d.ts +23 -7
  135. package/dist/commands/ls-remote-command.d.ts.map +1 -1
  136. package/dist/commands/mailmap.d.ts +31 -0
  137. package/dist/commands/mailmap.d.ts.map +1 -0
  138. package/dist/commands/merge-bases.d.ts +85 -0
  139. package/dist/commands/merge-bases.d.ts.map +1 -0
  140. package/dist/commands/merge-command.d.ts +209 -74
  141. package/dist/commands/merge-command.d.ts.map +1 -1
  142. package/dist/commands/merge-config.d.ts +13 -0
  143. package/dist/commands/merge-config.d.ts.map +1 -0
  144. package/dist/commands/merge-drivers.d.ts +130 -0
  145. package/dist/commands/merge-drivers.d.ts.map +1 -0
  146. package/dist/commands/merge-support.d.ts +252 -0
  147. package/dist/commands/merge-support.d.ts.map +1 -0
  148. package/dist/commands/message-cleanup.d.ts +86 -0
  149. package/dist/commands/message-cleanup.d.ts.map +1 -0
  150. package/dist/commands/mv-command.d.ts +94 -0
  151. package/dist/commands/mv-command.d.ts.map +1 -0
  152. package/dist/commands/notes-command.d.ts +256 -0
  153. package/dist/commands/notes-command.d.ts.map +1 -0
  154. package/dist/commands/notes-commands.d.ts +41 -0
  155. package/dist/commands/notes-commands.d.ts.map +1 -0
  156. package/dist/commands/notes-merge-command.d.ts +105 -0
  157. package/dist/commands/notes-merge-command.d.ts.map +1 -0
  158. package/dist/commands/notes-support.d.ts +125 -0
  159. package/dist/commands/notes-support.d.ts.map +1 -0
  160. package/dist/commands/notes-tree.d.ts +106 -0
  161. package/dist/commands/notes-tree.d.ts.map +1 -0
  162. package/dist/commands/object-id-input.d.ts +20 -0
  163. package/dist/commands/object-id-input.d.ts.map +1 -0
  164. package/dist/commands/octopus-merge.d.ts +59 -0
  165. package/dist/commands/octopus-merge.d.ts.map +1 -0
  166. package/dist/commands/ort-merge.d.ts +126 -0
  167. package/dist/commands/ort-merge.d.ts.map +1 -0
  168. package/dist/commands/ort-recursive.d.ts +53 -0
  169. package/dist/commands/ort-recursive.d.ts.map +1 -0
  170. package/dist/commands/pack-refs-command.d.ts +20 -0
  171. package/dist/commands/pack-refs-command.d.ts.map +1 -1
  172. package/dist/commands/patch-id.d.ts +41 -0
  173. package/dist/commands/patch-id.d.ts.map +1 -0
  174. package/dist/commands/pathspec-attributes.d.ts +64 -0
  175. package/dist/commands/pathspec-attributes.d.ts.map +1 -0
  176. package/dist/commands/pathspec.d.ts +324 -0
  177. package/dist/commands/pathspec.d.ts.map +1 -0
  178. package/dist/commands/post-index-change.d.ts +33 -0
  179. package/dist/commands/post-index-change.d.ts.map +1 -0
  180. package/dist/commands/pretty-format.d.ts +222 -0
  181. package/dist/commands/pretty-format.d.ts.map +1 -0
  182. package/dist/commands/promisor-remote.d.ts +80 -0
  183. package/dist/commands/promisor-remote.d.ts.map +1 -0
  184. package/dist/commands/pull-command.d.ts +41 -8
  185. package/dist/commands/pull-command.d.ts.map +1 -1
  186. package/dist/commands/push-command.d.ts +24 -8
  187. package/dist/commands/push-command.d.ts.map +1 -1
  188. package/dist/commands/read-tree-command.d.ts +112 -0
  189. package/dist/commands/read-tree-command.d.ts.map +1 -0
  190. package/dist/commands/rebase-command.d.ts +507 -75
  191. package/dist/commands/rebase-command.d.ts.map +1 -1
  192. package/dist/commands/rebase-todo.d.ts +130 -0
  193. package/dist/commands/rebase-todo.d.ts.map +1 -0
  194. package/dist/commands/ref-decoration-filter.d.ts +53 -0
  195. package/dist/commands/ref-decoration-filter.d.ts.map +1 -0
  196. package/dist/commands/reflog-messages.d.ts +98 -0
  197. package/dist/commands/reflog-messages.d.ts.map +1 -0
  198. package/dist/commands/remote-command.d.ts +31 -0
  199. package/dist/commands/remote-command.d.ts.map +1 -1
  200. package/dist/commands/remote-transport.d.ts +120 -0
  201. package/dist/commands/remote-transport.d.ts.map +1 -0
  202. package/dist/commands/reset-command.d.ts +161 -7
  203. package/dist/commands/reset-command.d.ts.map +1 -1
  204. package/dist/commands/restore-command.d.ts +103 -0
  205. package/dist/commands/restore-command.d.ts.map +1 -0
  206. package/dist/commands/rev-list-command.d.ts +78 -0
  207. package/dist/commands/rev-list-command.d.ts.map +1 -0
  208. package/dist/commands/rev-parse-command.d.ts +80 -0
  209. package/dist/commands/rev-parse-command.d.ts.map +1 -0
  210. package/dist/commands/revert-command.d.ts +46 -38
  211. package/dist/commands/revert-command.d.ts.map +1 -1
  212. package/dist/commands/revision-filenames.d.ts +95 -0
  213. package/dist/commands/revision-filenames.d.ts.map +1 -0
  214. package/dist/commands/revision-range.d.ts +67 -0
  215. package/dist/commands/revision-range.d.ts.map +1 -0
  216. package/dist/commands/revision-resolver.d.ts +321 -0
  217. package/dist/commands/revision-resolver.d.ts.map +1 -0
  218. package/dist/commands/rm-command.d.ts +69 -7
  219. package/dist/commands/rm-command.d.ts.map +1 -1
  220. package/dist/commands/sequencer-pick.d.ts +191 -0
  221. package/dist/commands/sequencer-pick.d.ts.map +1 -0
  222. package/dist/commands/sequencer-support.d.ts +125 -0
  223. package/dist/commands/sequencer-support.d.ts.map +1 -0
  224. package/dist/commands/serve-repository.d.ts +52 -0
  225. package/dist/commands/serve-repository.d.ts.map +1 -0
  226. package/dist/commands/sparse-checkout-command.d.ts +190 -0
  227. package/dist/commands/sparse-checkout-command.d.ts.map +1 -0
  228. package/dist/commands/sparse-checkout-support.d.ts +268 -0
  229. package/dist/commands/sparse-checkout-support.d.ts.map +1 -0
  230. package/dist/commands/stash-apply-command.d.ts +42 -8
  231. package/dist/commands/stash-apply-command.d.ts.map +1 -1
  232. package/dist/commands/stash-create-command.d.ts +155 -1
  233. package/dist/commands/stash-create-command.d.ts.map +1 -1
  234. package/dist/commands/stash-drop-command.d.ts +2 -0
  235. package/dist/commands/stash-drop-command.d.ts.map +1 -1
  236. package/dist/commands/stash-working-tree.d.ts +23 -0
  237. package/dist/commands/stash-working-tree.d.ts.map +1 -1
  238. package/dist/commands/status-command.d.ts +300 -15
  239. package/dist/commands/status-command.d.ts.map +1 -1
  240. package/dist/commands/status-format.d.ts +155 -0
  241. package/dist/commands/status-format.d.ts.map +1 -0
  242. package/dist/commands/status-header.d.ts +64 -0
  243. package/dist/commands/status-header.d.ts.map +1 -0
  244. package/dist/commands/strerror.d.ts +7 -0
  245. package/dist/commands/strerror.d.ts.map +1 -0
  246. package/dist/commands/submodule-config.d.ts +38 -0
  247. package/dist/commands/submodule-config.d.ts.map +1 -0
  248. package/dist/commands/submodule-summary-command.d.ts +80 -0
  249. package/dist/commands/submodule-summary-command.d.ts.map +1 -0
  250. package/dist/commands/submodule-summary.d.ts +150 -0
  251. package/dist/commands/submodule-summary.d.ts.map +1 -0
  252. package/dist/commands/switch-command.d.ts +132 -0
  253. package/dist/commands/switch-command.d.ts.map +1 -0
  254. package/dist/commands/tag-command.d.ts +23 -2
  255. package/dist/commands/tag-command.d.ts.map +1 -1
  256. package/dist/commands/tracking-info.d.ts +64 -0
  257. package/dist/commands/tracking-info.d.ts.map +1 -0
  258. package/dist/commands/trailers.d.ts +73 -0
  259. package/dist/commands/trailers.d.ts.map +1 -0
  260. package/dist/commands/tree-restore.d.ts +85 -1
  261. package/dist/commands/tree-restore.d.ts.map +1 -1
  262. package/dist/commands/untracked-cache-support.d.ts +53 -0
  263. package/dist/commands/untracked-cache-support.d.ts.map +1 -0
  264. package/dist/commands/worktree-add-command.d.ts +108 -0
  265. package/dist/commands/worktree-add-command.d.ts.map +1 -0
  266. package/dist/commands/worktree-list-command.d.ts +69 -0
  267. package/dist/commands/worktree-list-command.d.ts.map +1 -0
  268. package/dist/commands/worktree-lock-command.d.ts +44 -0
  269. package/dist/commands/worktree-lock-command.d.ts.map +1 -0
  270. package/dist/commands/worktree-overwrite-checks.d.ts +146 -6
  271. package/dist/commands/worktree-overwrite-checks.d.ts.map +1 -1
  272. package/dist/commands/worktree-prune-command.d.ts +48 -0
  273. package/dist/commands/worktree-prune-command.d.ts.map +1 -0
  274. package/dist/commands/worktree-remove-command.d.ts +59 -0
  275. package/dist/commands/worktree-remove-command.d.ts.map +1 -0
  276. package/dist/commands/worktree-repair-command.d.ts +35 -0
  277. package/dist/commands/worktree-repair-command.d.ts.map +1 -0
  278. package/dist/commands/worktree-support.d.ts +64 -0
  279. package/dist/commands/worktree-support.d.ts.map +1 -0
  280. package/dist/commands-DnmlfwGV.js +61620 -0
  281. package/dist/core-commands/add.command.impl.d.ts.map +1 -1
  282. package/dist/errors/add-errors.d.ts +55 -0
  283. package/dist/errors/add-errors.d.ts.map +1 -1
  284. package/dist/errors/checkout-errors.d.ts +16 -0
  285. package/dist/errors/checkout-errors.d.ts.map +1 -1
  286. package/dist/errors/command-errors.d.ts +77 -0
  287. package/dist/errors/command-errors.d.ts.map +1 -1
  288. package/dist/errors/commit-errors.d.ts +9 -0
  289. package/dist/errors/commit-errors.d.ts.map +1 -1
  290. package/dist/errors/git-api-error.d.ts +59 -2
  291. package/dist/errors/git-api-error.d.ts.map +1 -1
  292. package/dist/errors/index.d.ts +1 -0
  293. package/dist/errors/index.d.ts.map +1 -1
  294. package/dist/errors/index.js +354 -19
  295. package/dist/errors/rebase-errors.d.ts +9 -0
  296. package/dist/errors/rebase-errors.d.ts.map +1 -1
  297. package/dist/errors/ref-errors.d.ts +32 -0
  298. package/dist/errors/ref-errors.d.ts.map +1 -1
  299. package/dist/errors/transport-errors.d.ts +12 -2
  300. package/dist/errors/transport-errors.d.ts.map +1 -1
  301. package/dist/errors/worktree-errors.d.ts +35 -0
  302. package/dist/errors/worktree-errors.d.ts.map +1 -0
  303. package/dist/git-command-DxvwPrPB.js +7612 -0
  304. package/dist/git-command.d.ts +413 -32
  305. package/dist/git-command.d.ts.map +1 -1
  306. package/dist/git.d.ts +306 -3
  307. package/dist/git.d.ts.map +1 -1
  308. package/dist/index.d.ts +1 -1
  309. package/dist/index.d.ts.map +1 -1
  310. package/dist/index.js +5 -5
  311. package/dist/remote-config/remote-config-store.d.ts +105 -3
  312. package/dist/remote-config/remote-config-store.d.ts.map +1 -1
  313. package/dist/remote-config/remote-refs.d.ts +7 -3
  314. package/dist/remote-config/remote-refs.d.ts.map +1 -1
  315. package/dist/rename/detect-renames.d.ts +148 -0
  316. package/dist/rename/detect-renames.d.ts.map +1 -0
  317. package/dist/rename/git-similarity.d.ts +44 -0
  318. package/dist/rename/git-similarity.d.ts.map +1 -0
  319. package/dist/rename/index.d.ts +2 -0
  320. package/dist/rename/index.d.ts.map +1 -1
  321. package/dist/results/binary-patch.d.ts +11 -0
  322. package/dist/results/binary-patch.d.ts.map +1 -0
  323. package/dist/results/blame-format.d.ts +55 -0
  324. package/dist/results/blame-format.d.ts.map +1 -0
  325. package/dist/results/cherry-pick-result.d.ts +10 -0
  326. package/dist/results/cherry-pick-result.d.ts.map +1 -1
  327. package/dist/results/clone-result.d.ts +10 -0
  328. package/dist/results/clone-result.d.ts.map +1 -1
  329. package/dist/results/combined-diff.d.ts +77 -0
  330. package/dist/results/combined-diff.d.ts.map +1 -0
  331. package/dist/results/diff-entry.d.ts +32 -0
  332. package/dist/results/diff-entry.d.ts.map +1 -1
  333. package/dist/results/diff-formatter.d.ts +34 -60
  334. package/dist/results/diff-formatter.d.ts.map +1 -1
  335. package/dist/results/diff-order.d.ts +25 -0
  336. package/dist/results/diff-order.d.ts.map +1 -0
  337. package/dist/results/diff-output.d.ts +249 -0
  338. package/dist/results/diff-output.d.ts.map +1 -0
  339. package/dist/results/fetch-result.d.ts +15 -0
  340. package/dist/results/fetch-result.d.ts.map +1 -1
  341. package/dist/results/index.d.ts +5 -0
  342. package/dist/results/index.d.ts.map +1 -1
  343. package/dist/results/index.js +2 -252
  344. package/dist/results/merge-result.d.ts +15 -1
  345. package/dist/results/merge-result.d.ts.map +1 -1
  346. package/dist/results/pull-result.d.ts +12 -3
  347. package/dist/results/pull-result.d.ts.map +1 -1
  348. package/dist/results/push-result.d.ts +42 -0
  349. package/dist/results/push-result.d.ts.map +1 -1
  350. package/dist/results/quote-path.d.ts +27 -0
  351. package/dist/results/quote-path.d.ts.map +1 -0
  352. package/dist/results/rebase-result.d.ts +28 -1
  353. package/dist/results/rebase-result.d.ts.map +1 -1
  354. package/dist/results/revert-result.d.ts +10 -0
  355. package/dist/results/revert-result.d.ts.map +1 -1
  356. package/dist/results/stash-result.d.ts +5 -0
  357. package/dist/results/stash-result.d.ts.map +1 -1
  358. package/dist/results/status-result.d.ts +60 -6
  359. package/dist/results/status-result.d.ts.map +1 -1
  360. package/dist/results-BZGa2Z3I.js +2934 -0
  361. package/dist/transport-command.d.ts +44 -1
  362. package/dist/transport-command.d.ts.map +1 -1
  363. package/package.json +15 -11
  364. package/src/commands/add-command.ts +1291 -226
  365. package/src/commands/add-patch/add-interactive.ts +941 -0
  366. package/src/commands/add-patch/add-patch.ts +1169 -0
  367. package/src/commands/add-patch/index.ts +5 -0
  368. package/src/commands/add-patch/patch-backend.ts +239 -0
  369. package/src/commands/add-patch/patch-modes.ts +249 -0
  370. package/src/commands/add-patch/patch-session.ts +159 -0
  371. package/src/commands/am/am-command.ts +1111 -0
  372. package/src/commands/am/index.ts +2 -0
  373. package/src/commands/am/mailinfo.ts +1015 -0
  374. package/src/commands/am/patch-format.ts +121 -0
  375. package/src/commands/apply/apply-command.ts +832 -0
  376. package/src/commands/apply/apply-engine.ts +1603 -0
  377. package/src/commands/apply/apply-parse.ts +1209 -0
  378. package/src/commands/apply/apply-types.ts +112 -0
  379. package/src/commands/apply/index.ts +5 -0
  380. package/src/commands/apply/latin1.ts +171 -0
  381. package/src/commands/apply/whitespace.ts +260 -0
  382. package/src/commands/attributes-source.ts +96 -0
  383. package/src/commands/backfill-command.ts +694 -0
  384. package/src/commands/bisect/bisect-checkout.ts +217 -0
  385. package/src/commands/bisect/bisect-command.ts +788 -0
  386. package/src/commands/bisect/bisect-engine.ts +1079 -0
  387. package/src/commands/bisect/bisect-graph.ts +595 -0
  388. package/src/commands/bisect/bisect-quote.ts +92 -0
  389. package/src/commands/bisect/index.ts +4 -0
  390. package/src/commands/blame-command.ts +711 -986
  391. package/src/commands/branch-command.ts +354 -32
  392. package/src/commands/branch-tracking.ts +331 -0
  393. package/src/commands/checkout-command.ts +1290 -243
  394. package/src/commands/checkout-paths.ts +784 -0
  395. package/src/commands/cherry-pick-command.ts +156 -396
  396. package/src/commands/clean-command.ts +504 -156
  397. package/src/commands/clone-command.ts +634 -67
  398. package/src/commands/commit-command.ts +1781 -166
  399. package/src/commands/core-config.ts +161 -6
  400. package/src/commands/date-format.ts +668 -0
  401. package/src/commands/describe-command.ts +2 -0
  402. package/src/commands/diff-command.ts +1898 -110
  403. package/src/commands/diff-textconv.ts +50 -0
  404. package/src/commands/fetch-command.ts +606 -66
  405. package/src/commands/format-patch-command.ts +969 -0
  406. package/src/commands/fsck/fetch-fsck.ts +229 -0
  407. package/src/commands/fsck/fsck-command.ts +3347 -0
  408. package/src/commands/fsck/fsck-loose.ts +287 -0
  409. package/src/commands/fsck/fsck-msg-ids.ts +176 -0
  410. package/src/commands/fsck/fsck-object-checks.ts +1044 -0
  411. package/src/commands/fsck/fsck-object-table.ts +363 -0
  412. package/src/commands/fsck/fsck-pack.ts +604 -0
  413. package/src/commands/fsck/index.ts +5 -0
  414. package/src/commands/fsck/verify-pack-command.ts +249 -0
  415. package/src/commands/gc-command.ts +147 -1
  416. package/src/commands/git-date.ts +895 -0
  417. package/src/commands/git-describe.ts +316 -0
  418. package/src/commands/git-hooks.ts +1472 -0
  419. package/src/commands/git-ident.ts +344 -0
  420. package/src/commands/hook-command.ts +247 -0
  421. package/src/commands/index-adder.ts +706 -0
  422. package/src/commands/index-host.ts +291 -0
  423. package/src/commands/index.ts +82 -0
  424. package/src/commands/init-command.ts +28 -4
  425. package/src/commands/local-clone.ts +183 -0
  426. package/src/commands/local-transport.ts +762 -0
  427. package/src/commands/log-command.ts +1915 -170
  428. package/src/commands/log-graph.ts +671 -0
  429. package/src/commands/log-output.ts +1359 -0
  430. package/src/commands/ls-remote-command.ts +101 -58
  431. package/src/commands/mailmap.ts +129 -0
  432. package/src/commands/merge-bases.ts +296 -0
  433. package/src/commands/merge-command.ts +1386 -491
  434. package/src/commands/merge-config.ts +25 -0
  435. package/src/commands/merge-drivers.ts +306 -0
  436. package/src/commands/merge-support.ts +1198 -0
  437. package/src/commands/message-cleanup.ts +275 -0
  438. package/src/commands/mv-command.ts +976 -0
  439. package/src/commands/notes-command.ts +890 -0
  440. package/src/commands/notes-commands.ts +87 -0
  441. package/src/commands/notes-merge-command.ts +768 -0
  442. package/src/commands/notes-support.ts +402 -0
  443. package/src/commands/notes-tree.ts +602 -0
  444. package/src/commands/object-id-input.ts +27 -0
  445. package/src/commands/octopus-merge.ts +377 -0
  446. package/src/commands/ort-merge.ts +1660 -0
  447. package/src/commands/ort-recursive.ts +160 -0
  448. package/src/commands/pack-refs-command.ts +39 -22
  449. package/src/commands/patch-id.ts +196 -0
  450. package/src/commands/pathspec-attributes.ts +162 -0
  451. package/src/commands/pathspec.ts +1199 -0
  452. package/src/commands/post-index-change.ts +62 -0
  453. package/src/commands/pretty-format.ts +1431 -0
  454. package/src/commands/promisor-remote.ts +298 -0
  455. package/src/commands/pull-command.ts +207 -22
  456. package/src/commands/push-command.ts +236 -23
  457. package/src/commands/read-tree-command.ts +857 -0
  458. package/src/commands/rebase-command.ts +3808 -371
  459. package/src/commands/rebase-todo.ts +584 -0
  460. package/src/commands/ref-decoration-filter.ts +118 -0
  461. package/src/commands/reflog-messages.ts +177 -0
  462. package/src/commands/remote-command.ts +93 -22
  463. package/src/commands/remote-transport.ts +383 -0
  464. package/src/commands/reset-command.ts +827 -103
  465. package/src/commands/restore-command.ts +350 -0
  466. package/src/commands/rev-list-command.ts +167 -0
  467. package/src/commands/rev-parse-command.ts +277 -0
  468. package/src/commands/revert-command.ts +152 -399
  469. package/src/commands/revision-filenames.ts +254 -0
  470. package/src/commands/revision-range.ts +222 -0
  471. package/src/commands/revision-resolver.ts +1379 -0
  472. package/src/commands/rm-command.ts +613 -67
  473. package/src/commands/sequencer-pick.ts +869 -0
  474. package/src/commands/sequencer-support.ts +869 -0
  475. package/src/commands/serve-repository.ts +125 -0
  476. package/src/commands/sparse-checkout-command.ts +1389 -0
  477. package/src/commands/sparse-checkout-support.ts +793 -0
  478. package/src/commands/stash-apply-command.ts +376 -343
  479. package/src/commands/stash-create-command.ts +625 -42
  480. package/src/commands/stash-drop-command.ts +15 -2
  481. package/src/commands/stash-working-tree.ts +168 -24
  482. package/src/commands/status-command.ts +1328 -105
  483. package/src/commands/status-format.ts +775 -0
  484. package/src/commands/status-header.ts +330 -0
  485. package/src/commands/strerror.ts +29 -0
  486. package/src/commands/submodule-config.ts +94 -0
  487. package/src/commands/submodule-summary-command.ts +334 -0
  488. package/src/commands/submodule-summary.ts +446 -0
  489. package/src/commands/switch-command.ts +402 -0
  490. package/src/commands/tag-command.ts +129 -41
  491. package/src/commands/tracking-info.ts +201 -0
  492. package/src/commands/trailers.ts +417 -0
  493. package/src/commands/tree-restore.ts +204 -4
  494. package/src/commands/untracked-cache-support.ts +194 -0
  495. package/src/commands/worktree-add-command.ts +458 -0
  496. package/src/commands/worktree-list-command.ts +208 -0
  497. package/src/commands/worktree-lock-command.ts +96 -0
  498. package/src/commands/worktree-overwrite-checks.ts +452 -26
  499. package/src/commands/worktree-prune-command.ts +99 -0
  500. package/src/commands/worktree-remove-command.ts +186 -0
  501. package/src/commands/worktree-repair-command.ts +59 -0
  502. package/src/commands/worktree-support.ts +214 -0
  503. package/src/core-commands/add.command.impl.ts +7 -1
  504. package/src/errors/add-errors.ts +45 -0
  505. package/src/errors/checkout-errors.ts +26 -2
  506. package/src/errors/command-errors.ts +101 -1
  507. package/src/errors/commit-errors.ts +18 -2
  508. package/src/errors/git-api-error.ts +82 -2
  509. package/src/errors/index.ts +1 -0
  510. package/src/errors/merge-errors.ts +2 -2
  511. package/src/errors/rebase-errors.ts +12 -0
  512. package/src/errors/ref-errors.ts +56 -2
  513. package/src/errors/remote-errors.ts +2 -2
  514. package/src/errors/stash-errors.ts +1 -1
  515. package/src/errors/transport-errors.ts +20 -4
  516. package/src/errors/worktree-errors.ts +49 -0
  517. package/src/git-command.ts +1177 -118
  518. package/src/git.ts +523 -10
  519. package/src/index.ts +1 -1
  520. package/src/remote-config/remote-config-store.ts +242 -8
  521. package/src/remote-config/remote-refs.ts +22 -6
  522. package/src/rename/detect-renames.ts +711 -0
  523. package/src/rename/git-similarity.ts +116 -0
  524. package/src/rename/index.ts +2 -0
  525. package/src/results/binary-patch.ts +401 -0
  526. package/src/results/blame-format.ts +239 -0
  527. package/src/results/cherry-pick-result.ts +10 -0
  528. package/src/results/clone-result.ts +12 -0
  529. package/src/results/combined-diff.ts +585 -0
  530. package/src/results/diff-entry.ts +35 -0
  531. package/src/results/diff-formatter.ts +152 -288
  532. package/src/results/diff-order.ts +64 -0
  533. package/src/results/diff-output.ts +1051 -0
  534. package/src/results/fetch-result.ts +15 -0
  535. package/src/results/index.ts +5 -0
  536. package/src/results/merge-result.ts +15 -1
  537. package/src/results/pull-result.ts +12 -3
  538. package/src/results/push-result.ts +43 -0
  539. package/src/results/quote-path.ts +103 -0
  540. package/src/results/rebase-result.ts +37 -0
  541. package/src/results/revert-result.ts +10 -0
  542. package/src/results/stash-result.ts +6 -0
  543. package/src/results/status-result.ts +123 -45
  544. package/src/transport-command.ts +121 -2
  545. package/dist/commands-CsLNyvZ1.js +0 -12587
  546. package/dist/status-result-BpyUK1Sg.js +0 -519
@@ -0,0 +1,869 @@
1
+ /**
2
+ * Pieces of git's sequencer shared by `merge`, `cherry-pick`, `revert` and `rebase`:
3
+ * `git reset --merge` / `--hard` as their `--abort` runs it, the commit message cleanup
4
+ * their `--continue` applies, and `SQUASH_MSG`.
5
+ */
6
+
7
+ import {
8
+ FileMode,
9
+ formatPersonIdent,
10
+ type ObjectId,
11
+ type PersonIdent,
12
+ type RefLogOptions,
13
+ } from "@statewalker/vcs-core";
14
+ import { compareGitPaths } from "@statewalker/vcs-utils/encoding";
15
+ import {
16
+ entryStatOf,
17
+ type IndexEntryOptions,
18
+ isIndexUnborn,
19
+ type StagingEntry,
20
+ type Worktree,
21
+ } from "@statewalker/vcs-working-tree";
22
+ import type { CommandCommits, CommandRefs } from "../git-command.js";
23
+ import { StashApplyStatus } from "../results/stash-result.js";
24
+ import { coreBool, worktreeModeTrust } from "./core-config.js";
25
+ import {
26
+ flatTree,
27
+ type MergeRefusal,
28
+ type MergeWriteContext,
29
+ type OperationState,
30
+ planPathsRestore,
31
+ rewriteIndex,
32
+ } from "./merge-support.js";
33
+ import { stripspace } from "./message-cleanup.js";
34
+ import { markIndexUpdate } from "./post-index-change.js";
35
+ import { updateHead } from "./reflog-messages.js";
36
+ import { pushSparseWarnings, SparseUnpack } from "./sparse-checkout-support.js";
37
+ import { StashApplyCommand } from "./stash-apply-command.js";
38
+ import { StashCreateCommand } from "./stash-create-command.js";
39
+ import { STASH_REF } from "./stash-list-command.js";
40
+ import { restoreCaseOptions, writeTreeRestorePlan } from "./tree-restore.js";
41
+ import {
42
+ type CheckedEntry,
43
+ flaggedEntryDiffers,
44
+ IndexCaseFolding,
45
+ pruneEmptyParents,
46
+ removeCaseVariants,
47
+ untrackedUnder,
48
+ worktreeDiffers,
49
+ worktreeModified,
50
+ } from "./worktree-overwrite-checks.js";
51
+
52
+ /** What resetting the index and worktree needs. */
53
+ export interface SequencerContext extends MergeWriteContext {
54
+ commits: CommandCommits;
55
+ refs: CommandRefs;
56
+ }
57
+
58
+ const sameEntry = (a: CheckedEntry | undefined, b: CheckedEntry | undefined) =>
59
+ a === undefined || b === undefined ? a === b : a.objectId === b.objectId && a.mode === b.mode;
60
+
61
+ /**
62
+ * git's `reset --merge <commit>` (and with `hard`, the `reset --hard` of `reset_head` that
63
+ * `rebase --abort`, `--skip` and the autostash run) of the index and the worktree, as
64
+ * unpack-trees' `oneway_merge` runs it with update: unmerged entries and entries that
65
+ * differ from the commit's tree take its version; paths the index and the commit agree on
66
+ * keep their worktree file as it is (with `hard`, a modified or missing file is written
67
+ * again). Refused before anything is written, with git's plumbing messages, where it
68
+ * would lose work: a file holding unstaged changes (`verify_uptodate`, not with `hard`),
69
+ * an untracked file where a file goes or on a leading path of one (`verify_absent`), an
70
+ * untracked file or nested repository in a directory a file replaces
71
+ * (`verify_clean_subdirectory`). Ignored files are expendable. HEAD is not moved.
72
+ */
73
+ export async function resetMerge(
74
+ ctx: SequencerContext,
75
+ targetId: ObjectId,
76
+ label: string,
77
+ options: OnewayMergeOptions = {},
78
+ ): Promise<MergeRefusal | undefined> {
79
+ // unpack-trees: post-index-change's worktree flag for the index written next
80
+ markIndexUpdate(ctx.staging, { workdir: true });
81
+ // in a sparse checkout: unpack-trees with its patterns; reset prints its sparse warnings
82
+ // as plain errors (no porcelain messages). Without update the patterns are not applied
83
+ // (`skip_sparse_checkout` when `!o->update`)
84
+ const sparse =
85
+ options.update === false || options.skipSparseCheckout
86
+ ? undefined
87
+ : await SparseUnpack.start(ctx);
88
+ const done = await resetMergeWith(ctx, targetId, label, options, sparse);
89
+ if (done.refused) return done.refused;
90
+ if (sparse) {
91
+ const outcome = await sparse.finish(ctx, {
92
+ written: done.written,
93
+ overwrite: options.hard === true,
94
+ });
95
+ pushSparseWarnings(ctx.sparseWarnings, sparse, outcome, false);
96
+ }
97
+ return undefined;
98
+ }
99
+
100
+ /** Options of {@link resetMerge}, git's `oneway_merge` settings. */
101
+ export interface OnewayMergeOptions {
102
+ /** `o->reset`: local changes are no refusal, modified or missing files written again */
103
+ hard?: boolean;
104
+ /** `o->update` (default true); false: files are checked (`verify_uptodate`), never written */
105
+ update?: boolean;
106
+ /** `UNPACK_RESET_OVERWRITE_UNTRACKED` (`read-tree --reset -u`): untracked files written over */
107
+ overwriteUntracked?: boolean;
108
+ /** `--no-sparse-checkout` */
109
+ skipSparseCheckout?: boolean;
110
+ /**
111
+ * The tree to read (`targetId` is then only a label): `read-tree -m <tree>` takes any
112
+ * tree-ish
113
+ */
114
+ targetTree?: ObjectId;
115
+ /** `read-tree`'s refusal: the `error:` line alone, without `fatal: Could not reset ...` */
116
+ plain?: boolean;
117
+ }
118
+
119
+ async function resetMergeWith(
120
+ ctx: SequencerContext,
121
+ targetId: ObjectId,
122
+ label: string,
123
+ options: OnewayMergeOptions,
124
+ sparse: SparseUnpack | undefined,
125
+ ): Promise<{ refused?: MergeRefusal; written: Set<string> }> {
126
+ const refusedWith = (refused: MergeRefusal) => ({ refused, written: new Set<string>() });
127
+ // a path staying outside the sparse checkout: neither checked nor touched in the worktree
128
+ const quiet = (path: string) => sparse?.leavesAlone(path) === true;
129
+ const checkUptodate = !options.hard;
130
+ const targetTree = options.targetTree ?? (await ctx.commits.getTree(targetId));
131
+ const target = await flatTree(ctx.trees, targetTree);
132
+ const index = new Map<string, CheckedEntry>();
133
+ const unmerged = new Set<string>();
134
+ // what read_index_unmerged leaves of a conflict: its first stage, as a stage-0 entry
135
+ const conflictEntries = new Map<string, CheckedEntry>();
136
+ for await (const entry of ctx.staging.entries()) {
137
+ if (entry.stage === 0) index.set(entry.path, entry);
138
+ else {
139
+ unmerged.add(entry.path);
140
+ if (!conflictEntries.has(entry.path)) {
141
+ conflictEntries.set(entry.path, { objectId: entry.objectId, mode: entry.mode });
142
+ }
143
+ }
144
+ }
145
+ const update = options.update !== false;
146
+ // without update the files are still checked (verify_uptodate), never written; untracked
147
+ // files are not looked for (verify_absent returns early)
148
+ const checkedWorktree = ctx.worktree;
149
+ const worktree = update ? ctx.worktree : undefined;
150
+ const absentWorktree = options.overwriteUntracked ? undefined : worktree;
151
+ const checked = conflictEntries.size > 0 ? new Map([...index, ...conflictEntries]) : index;
152
+ const trust = checkedWorktree ? worktreeModeTrust(ctx.workingCopy, checkedWorktree) : undefined;
153
+ const indexTime = ctx.staging.getUpdateTime();
154
+ // core.ignorecase: verify_absent asks the source index folding case (icase_exists,
155
+ // verify_clean_subdirectory's read_directory); the case variants found go before the writes
156
+ const folding = await caseFoldingOf(ctx, checked);
157
+ const caseVariants: string[] = [];
158
+ const refuse = (message: string, path: string): MergeRefusal => ({
159
+ message: options.plain
160
+ ? `error: ${message}`
161
+ : `error: ${message}\nfatal: Could not reset index file to revision '${label}'.`,
162
+ paths: [path],
163
+ });
164
+ const notUptodate = (path: string) => refuse(`Entry '${path}' not uptodate. Cannot merge.`, path);
165
+ // verify_uptodate_1: an entry whose flags cheat (assume-unchanged, skip-worktree) is checked
166
+ // by its stat even by a hard reset; any other only when not resetting hard
167
+ const notUptodateEntry = async (i: CheckedEntry): Promise<boolean> => {
168
+ const worktree = checkedWorktree;
169
+ if (!worktree) return false;
170
+ const e = i as StagingEntry;
171
+ if (e.assumeValid || e.skipWorktree) {
172
+ return flaggedEntryDiffers(worktree, e.path, e, trust, indexTime);
173
+ }
174
+ return checkUptodate && worktreeDiffers(worktree, e.path, i, trust, indexTime);
175
+ };
176
+ const changes: string[] = [];
177
+ /** Paths the reset removes from the index (git's CE_REMOVE in the result) */
178
+ const removing = new Set<string>();
179
+ const inIndex = (p: string) => index.has(p) || unmerged.has(p);
180
+ const paths = [...new Set([...index.keys(), ...unmerged, ...target.keys()])].sort(compareBytes);
181
+ for (const path of paths) {
182
+ const i = index.get(path);
183
+ const t = target.get(path);
184
+ const conflicted = unmerged.has(path);
185
+ if (!t) {
186
+ // deleted_entry: a directory standing there keeps what is untracked in it
187
+ // (a submodule's directory is not touched)
188
+ const gitlink = i?.mode === FileMode.GITLINK;
189
+ if (
190
+ absentWorktree &&
191
+ !gitlink &&
192
+ !quiet(path) &&
193
+ (await directoryLosesUntracked(absentWorktree, path, inIndex))
194
+ ) {
195
+ return refusedWith(refuse(`Updating '${path}' would lose untracked files in it`, path));
196
+ }
197
+ if (!conflicted && i && !quiet(path) && (await notUptodateEntry(i))) {
198
+ return refusedWith(notUptodate(path));
199
+ }
200
+ removing.add(path);
201
+ changes.push(path);
202
+ continue;
203
+ }
204
+ if (!conflicted && sameEntry(i, t)) {
205
+ // reset --hard writes a modified or missing file again (a skip-worktree entry is left
206
+ // alone: oneway_merge)
207
+ if (
208
+ options.hard &&
209
+ i &&
210
+ worktree &&
211
+ !(i as StagingEntry).skipWorktree &&
212
+ (!sparse || sparse.writes(path)) &&
213
+ (await worktreeModified(worktree, path, i, trust, indexTime))
214
+ ) {
215
+ changes.push(path);
216
+ }
217
+ continue;
218
+ }
219
+ if (worktree && !i && !conflicted && !quiet(path)) {
220
+ // a new path: verify_absent
221
+ const refusal = absentWorktree
222
+ ? await verifyAbsent(absentWorktree, path, t, checked, removing, {
223
+ hard: options.hard === true,
224
+ tracked: inIndex,
225
+ trust,
226
+ indexTime,
227
+ refuse,
228
+ notUptodate,
229
+ folding,
230
+ caseVariants,
231
+ })
232
+ : undefined;
233
+ if (refusal) return refusedWith(refusal);
234
+ } else if (i && !conflicted && !quiet(path) && (await notUptodateEntry(i))) {
235
+ return refusedWith(notUptodate(path));
236
+ }
237
+ changes.push(path);
238
+ }
239
+
240
+ // the files written: in a sparse checkout, those of the paths in its patterns only
241
+ const writing = new Set(changes.filter((p) => target.has(p) && (!sparse || sparse.writes(p))));
242
+ if (worktree) {
243
+ if (sparse) {
244
+ // apply_sparse_checkout before check_updates: the files leaving the checkout
245
+ const changed = new Set(changes);
246
+ const unlink = await sparse.leaving(
247
+ worktree,
248
+ (p) => (changed.has(p) ? target.get(p) : (index.get(p) ?? target.get(p))),
249
+ { reset: options.hard === true, trust },
250
+ );
251
+ await sparse.unlink(worktree, unlink);
252
+ }
253
+ for (const path of changes) {
254
+ if (target.has(path) || quiet(path)) continue;
255
+ const entry = await worktree.getEntry(path);
256
+ if (entry && !entry.isDirectory) {
257
+ await worktree.remove(path);
258
+ await pruneEmptyParents(worktree, path);
259
+ }
260
+ }
261
+ // core.ignorecase: what verify_clean_subdirectory took as tracked in a directory a file
262
+ // replaces goes with the directory (checkout_entry removes the subtree)
263
+ await removeCaseVariants(worktree, caseVariants);
264
+ if (writing.size > 0) {
265
+ const plan = await planPathsRestore(ctx, target, targetTree, writing, "reset");
266
+ await writeTreeRestorePlan(worktree, ctx.blobs, plan, "reset", {
267
+ symlinks: trust?.symlinks ?? true,
268
+ gitlinks: true,
269
+ replaceInTheWay: true,
270
+ ...(options.overwriteUntracked ? { discardUntracked: true } : {}),
271
+ });
272
+ }
273
+ }
274
+ const edits = new Map<string, IndexEntryOptions[]>();
275
+ for (const path of changes) {
276
+ const t = target.get(path);
277
+ if (!t) {
278
+ edits.set(path, []);
279
+ continue;
280
+ }
281
+ const stats = worktree && writing.has(path) ? await worktree.getEntry(path) : undefined;
282
+ // an unchanged entry rewritten keeps its flags (oneway_merge keeps the old entry); a
283
+ // changed one keeps the skip-worktree bit (merged_entry)
284
+ const old = index.get(path) as StagingEntry | undefined;
285
+ const same = old !== undefined && !unmerged.has(path) && sameEntry(old, t);
286
+ edits.set(path, [
287
+ {
288
+ path,
289
+ objectId: t.objectId,
290
+ mode: t.mode,
291
+ ...entryStatOf(stats && !stats.isDirectory ? stats : {}),
292
+ ...(old?.skipWorktree && !unmerged.has(path) ? { skipWorktree: true } : {}),
293
+ ...(same && old?.assumeValid ? { assumeValid: true } : {}),
294
+ ...(same && old?.intentToAdd ? { intentToAdd: true } : {}),
295
+ },
296
+ ]);
297
+ }
298
+ // unpack-trees writes a new index: no resolve-undo record survives the reset
299
+ ctx.staging.clearResolveUndo?.();
300
+ await rewriteIndex(ctx.staging, edits, { updateCacheTreeWith: ctx.trees });
301
+ return { written: worktree ? writing : new Set() };
302
+ }
303
+
304
+ /**
305
+ * The first step of `am --abort`'s `clean_index`: `read_index_unmerged`, then unpack-trees'
306
+ * `twoway_merge` from HEAD to HEAD with update and `UNPACK_RESET_PROTECT_UNTRACKED`. With
307
+ * the old tree equal to the new one only conflicted entries change: each takes HEAD's
308
+ * version (or leaves the index and the worktree where HEAD has no such path) without the
309
+ * up-to-date check. Every other index entry stays as it is, worktree file and all, and a
310
+ * path missing from the index stays a staged deletion.
311
+ */
312
+ export async function resetUnmergedToHead(
313
+ ctx: SequencerContext,
314
+ headId: ObjectId | undefined,
315
+ ): Promise<void> {
316
+ const unmerged = new Set<string>();
317
+ for await (const entry of ctx.staging.entries()) {
318
+ if (entry.stage !== 0) unmerged.add(entry.path);
319
+ }
320
+ if (unmerged.size === 0) return;
321
+ const headTree = headId ? await ctx.commits.getTree(headId) : undefined;
322
+ const head = headTree ? await flatTree(ctx.trees, headTree) : new Map<string, CheckedEntry>();
323
+ const worktree = ctx.worktree;
324
+ const trust = worktree ? worktreeModeTrust(ctx.workingCopy, worktree) : undefined;
325
+ const paths = [...unmerged].sort(compareBytes);
326
+ if (worktree) {
327
+ for (const path of paths) {
328
+ if (head.has(path)) continue;
329
+ const entry = await worktree.getEntry(path);
330
+ if (entry && !entry.isDirectory) {
331
+ await worktree.remove(path);
332
+ await pruneEmptyParents(worktree, path);
333
+ }
334
+ }
335
+ const writing = new Set(paths.filter((p) => head.has(p)));
336
+ if (writing.size > 0 && headTree) {
337
+ const plan = await planPathsRestore(ctx, head, headTree, writing, "reset");
338
+ await writeTreeRestorePlan(worktree, ctx.blobs, plan, "reset", {
339
+ symlinks: trust?.symlinks ?? true,
340
+ gitlinks: true,
341
+ replaceInTheWay: true,
342
+ });
343
+ }
344
+ }
345
+ const edits = new Map<string, IndexEntryOptions[]>();
346
+ for (const path of paths) {
347
+ const h = head.get(path);
348
+ if (!h) {
349
+ edits.set(path, []);
350
+ continue;
351
+ }
352
+ const stats = worktree ? await worktree.getEntry(path) : undefined;
353
+ edits.set(path, [
354
+ {
355
+ path,
356
+ objectId: h.objectId,
357
+ mode: h.mode,
358
+ ...entryStatOf(stats && !stats.isDirectory ? stats : {}),
359
+ },
360
+ ]);
361
+ }
362
+ ctx.staging.clearResolveUndo?.();
363
+ await rewriteIndex(ctx.staging, edits, { updateCacheTreeWith: ctx.trees });
364
+ }
365
+
366
+ /**
367
+ * git's `reset --keep <commit>` of the index and the worktree: unpack-trees' `twoway_merge`
368
+ * from HEAD to the commit with update, then the index reset to the commit (`reset_index`
369
+ * MIXED). Paths HEAD and the commit agree on keep their worktree file, local changes and
370
+ * all (a staged change stays as an unstaged one); a path they differ on takes the commit's
371
+ * version, refused before anything is written where that would lose work: an index entry
372
+ * that is neither HEAD's nor the commit's ("would be overwritten"), a file with unstaged
373
+ * changes (`verify_uptodate`), an untracked file in the way (`verify_absent`). HEAD is not
374
+ * moved. The caller refuses an index with unmerged entries first.
375
+ */
376
+ export async function resetKeep(
377
+ ctx: SequencerContext,
378
+ headId: ObjectId,
379
+ targetId: ObjectId,
380
+ label: string,
381
+ ): Promise<MergeRefusal | undefined> {
382
+ // unpack-trees: post-index-change's worktree flag for the index written next
383
+ markIndexUpdate(ctx.staging, { workdir: true });
384
+ // in a sparse checkout: unpack-trees with its patterns; reset prints its sparse warnings
385
+ // as plain errors (no porcelain messages)
386
+ const sparse = await SparseUnpack.start(ctx);
387
+ const done = await resetKeepWith(ctx, headId, targetId, label, sparse);
388
+ if (done.refused) return done.refused;
389
+ if (sparse) {
390
+ const outcome = await sparse.finish(ctx, { written: done.written });
391
+ pushSparseWarnings(ctx.sparseWarnings, sparse, outcome, false);
392
+ }
393
+ return undefined;
394
+ }
395
+
396
+ async function resetKeepWith(
397
+ ctx: SequencerContext,
398
+ headId: ObjectId,
399
+ targetId: ObjectId,
400
+ label: string,
401
+ sparse: SparseUnpack | undefined,
402
+ ): Promise<{ refused?: MergeRefusal; written: Set<string> }> {
403
+ const refusedWith = (refused: MergeRefusal) => ({ refused, written: new Set<string>() });
404
+ // a path staying outside the sparse checkout: neither checked nor touched in the worktree
405
+ const quiet = (path: string) => sparse?.leavesAlone(path) === true;
406
+ const head = await flatTree(ctx.trees, await ctx.commits.getTree(headId));
407
+ const targetTree = await ctx.commits.getTree(targetId);
408
+ const target = await flatTree(ctx.trees, targetTree);
409
+ const index = new Map<string, CheckedEntry>();
410
+ for await (const entry of ctx.staging.entries()) {
411
+ if (entry.stage === 0) index.set(entry.path, entry);
412
+ }
413
+ const worktree = ctx.worktree;
414
+ const trust = worktree ? worktreeModeTrust(ctx.workingCopy, worktree) : undefined;
415
+ const indexTime = ctx.staging.getUpdateTime();
416
+ const folding = await caseFoldingOf(ctx, index);
417
+ const caseVariants: string[] = [];
418
+ const refuse = (message: string, path: string): MergeRefusal => ({
419
+ message: `error: ${message}\nfatal: Could not reset index file to revision '${label}'.`,
420
+ paths: [path],
421
+ });
422
+ const notUptodate = (path: string) => refuse(`Entry '${path}' not uptodate. Cannot merge.`, path);
423
+ const changes: string[] = [];
424
+ const removing = new Set<string>();
425
+ const paths = [...new Set([...index.keys(), ...head.keys(), ...target.keys()])].sort(
426
+ compareBytes,
427
+ );
428
+ for (const path of paths) {
429
+ const h = head.get(path);
430
+ const t = target.get(path);
431
+ const i = index.get(path);
432
+ // HEAD and the commit agree: index and worktree stay as they are
433
+ if (sameEntry(h, t)) continue;
434
+ if (!sameEntry(i, h)) {
435
+ // the index has the commit's version already, or a change the reset would lose
436
+ if (sameEntry(i, t)) continue;
437
+ return refusedWith(
438
+ refuse(`Entry '${path}' would be overwritten by merge. Cannot merge.`, path),
439
+ );
440
+ }
441
+ if (worktree && i && !quiet(path)) {
442
+ // verify_uptodate_1: an entry whose flags cheat is checked by its stat
443
+ const e = i as StagingEntry;
444
+ const differs =
445
+ e.assumeValid || e.skipWorktree
446
+ ? await flaggedEntryDiffers(worktree, path, e, trust, indexTime)
447
+ : await worktreeDiffers(worktree, path, i, trust, indexTime);
448
+ if (differs) return refusedWith(notUptodate(path));
449
+ }
450
+ if (!t) {
451
+ removing.add(path);
452
+ } else if (worktree && !i && !quiet(path)) {
453
+ const refusal = await verifyAbsent(worktree, path, t, index, removing, {
454
+ hard: false,
455
+ tracked: (p) => index.has(p),
456
+ trust,
457
+ indexTime,
458
+ refuse,
459
+ notUptodate,
460
+ folding,
461
+ caseVariants,
462
+ });
463
+ if (refusal) return refusedWith(refusal);
464
+ }
465
+ changes.push(path);
466
+ }
467
+
468
+ // the files written: in a sparse checkout, those of the paths in its patterns only
469
+ const writing = new Set(changes.filter((p) => target.has(p) && (!sparse || sparse.writes(p))));
470
+ if (worktree) {
471
+ if (sparse) {
472
+ // apply_sparse_checkout before check_updates: the files leaving the checkout
473
+ const changed = new Set(changes);
474
+ const unlink = await sparse.leaving(
475
+ worktree,
476
+ (p) => (changed.has(p) || !index.has(p) ? target.get(p) : index.get(p)),
477
+ { trust },
478
+ );
479
+ await sparse.unlink(worktree, unlink);
480
+ }
481
+ for (const path of removing) {
482
+ if (quiet(path)) continue;
483
+ const entry = await worktree.getEntry(path);
484
+ if (entry && !entry.isDirectory) {
485
+ await worktree.remove(path);
486
+ await pruneEmptyParents(worktree, path);
487
+ }
488
+ }
489
+ // core.ignorecase: what verify_clean_subdirectory took as tracked in a directory a file
490
+ // replaces goes with the directory (checkout_entry removes the subtree)
491
+ await removeCaseVariants(worktree, caseVariants);
492
+ if (writing.size > 0) {
493
+ const plan = await planPathsRestore(ctx, target, targetTree, writing, "reset");
494
+ await writeTreeRestorePlan(worktree, ctx.blobs, plan, "reset", {
495
+ symlinks: trust?.symlinks ?? true,
496
+ gitlinks: true,
497
+ replaceInTheWay: true,
498
+ });
499
+ }
500
+ }
501
+ // the index is the commit's tree: an entry that holds it already keeps its stat, a file
502
+ // just written takes the stat it has now
503
+ const written = new Set([...writing]);
504
+ const edits = new Map<string, IndexEntryOptions[]>();
505
+ for (const path of index.keys()) if (!target.has(path)) edits.set(path, []);
506
+ for (const [path, t] of target) {
507
+ if (sameEntry(index.get(path), t) && !written.has(path)) continue;
508
+ const stats = worktree && written.has(path) ? await worktree.getEntry(path) : undefined;
509
+ // merged_entry: the replaced entry's skip-worktree bit migrates over
510
+ const old = index.get(path) as StagingEntry | undefined;
511
+ edits.set(path, [
512
+ {
513
+ path,
514
+ objectId: t.objectId,
515
+ mode: t.mode,
516
+ ...entryStatOf(stats && !stats.isDirectory ? stats : {}),
517
+ ...(old?.skipWorktree ? { skipWorktree: true } : {}),
518
+ },
519
+ ]);
520
+ }
521
+ ctx.staging.clearResolveUndo?.();
522
+ await rewriteIndex(ctx.staging, edits, { updateCacheTreeWith: ctx.trees });
523
+ return { written: worktree ? writing : new Set() };
524
+ }
525
+
526
+ /**
527
+ * git's reset `update_refs`: ORIG_HEAD set to the HEAD left (`headId`), given the ORIG_HEAD
528
+ * it read as the old value (none when absent), then HEAD moved to `target` expecting the
529
+ * HEAD left, as the reference-transaction hook sees both. Without a HEAD (unborn), HEAD's
530
+ * branch is set as it is. An ORIG_HEAD that cannot be written (its lock held, another
531
+ * value meanwhile) is reported and HEAD still moves, as git's `update_ref` with
532
+ * UPDATE_REFS_MSG_ON_ERR: the `error:` lines are returned (after git's `warning:` for a
533
+ * symbolic ORIG_HEAD naming nothing).
534
+ */
535
+ export async function moveHeadAsReset(
536
+ refs: CommandRefs,
537
+ state: OperationState,
538
+ headId: ObjectId | undefined,
539
+ target: ObjectId,
540
+ log: RefLogOptions,
541
+ /** ORIG_HEAD's reflog message (a log only a symbolic ORIG_HEAD's target keeps) */
542
+ origHeadMessage = "reset: updating ORIG_HEAD",
543
+ /** HEAD detached at `target` (git's RESET_HEAD_DETACH: REF_NO_DEREF) rather than written through */
544
+ options: { detach?: boolean } = {},
545
+ ): Promise<string[]> {
546
+ const detach = options.detach === true;
547
+ if (!headId) {
548
+ if (detach) await refs.set("HEAD", target, log);
549
+ else await updateHead(refs, target, log);
550
+ return [];
551
+ }
552
+ const errors: string[] = [];
553
+ if (state.supported) {
554
+ // git's get_oid("ORIG_HEAD"): through a symbolic ORIG_HEAD to the id its target holds
555
+ // (the old value the write through it expects), warning of one naming nothing
556
+ const resolved = async () =>
557
+ (await refs.resolve("ORIG_HEAD").catch(() => undefined))?.objectId ?? undefined;
558
+ const ref = await refs.get("ORIG_HEAD").catch(() => undefined);
559
+ const old = (await resolved()) ?? null;
560
+ if (ref && "target" in ref && old === null) {
561
+ errors.push("warning: ignoring dangling symref ORIG_HEAD");
562
+ }
563
+ try {
564
+ await state.setRef("ORIG_HEAD", headId, { old, log: { ...log, message: origHeadMessage } });
565
+ } catch (error) {
566
+ errors.push(origHeadError(error, old, await resolved()));
567
+ }
568
+ }
569
+ const result = await refs.batch(
570
+ [{ name: "HEAD", old: headId, new: target, ...(detach ? { noDeref: true } : {}) }],
571
+ log,
572
+ );
573
+ // a store that cannot batch HEAD: the plain update
574
+ if (!result.ok) {
575
+ if (detach) await refs.set("HEAD", target, log);
576
+ else await updateHead(refs, target, log);
577
+ }
578
+ return errors;
579
+ }
580
+
581
+ /** git's `update_ref failed for ref 'ORIG_HEAD'` error for a write the store rejected. */
582
+ function origHeadError(error: unknown, old: ObjectId | null, now: ObjectId | undefined): string {
583
+ const rejected = (error as { rejected?: { reason: string }[] }).rejected ?? [];
584
+ const reason = rejected[0]?.reason;
585
+ const why =
586
+ reason === "locked"
587
+ ? "Unable to create 'ORIG_HEAD.lock': File exists."
588
+ : reason === "mismatch"
589
+ ? old === null
590
+ ? "reference already exists"
591
+ : now === undefined
592
+ ? "unable to resolve reference 'ORIG_HEAD'"
593
+ : `is at ${now} but expected ${old}`
594
+ : error instanceof Error
595
+ ? error.message
596
+ : String(error);
597
+ return `error: update_ref failed for ref 'ORIG_HEAD': cannot lock ref 'ORIG_HEAD': ${why}`;
598
+ }
599
+
600
+ /**
601
+ * git's remove_branch_state (a branch switch, a reset): the merge, cherry-pick or revert
602
+ * stopped before its commit is forgotten (MERGE_HEAD, MERGE_MSG, MERGE_MODE, SQUASH_MSG,
603
+ * CHERRY_PICK_HEAD, REVERT_HEAD, AUTO_MERGE), its MERGE_AUTOSTASH kept on `refs/stash`.
604
+ */
605
+ export async function removeBranchState(
606
+ ctx: Pick<SequencerContext, "commits" | "refs">,
607
+ state: OperationState,
608
+ ): Promise<string[]> {
609
+ if (!state.supported) return [];
610
+ // sequencer_post_commit_cleanup: CHERRY_PICK_HEAD and REVERT_HEAD when there, AUTO_MERGE
611
+ // in any case (as remove_merge_branch_state again below: git 2.5x's reference-transaction
612
+ // hook hears of both deletions)
613
+ await state.removeRef("CHERRY_PICK_HEAD", "REVERT_HEAD");
614
+ await state.deleteRef("AUTO_MERGE");
615
+ await state.remove("SQUASH_MSG");
616
+ return removeMergeBranchState(ctx, state);
617
+ }
618
+
619
+ /**
620
+ * git's `remove_merge_branch_state` (an "Already up to date." merge, `merge --quit`, and
621
+ * through remove_branch_state a reset or a branch switch): MERGE_HEAD, MERGE_RR, MERGE_MSG,
622
+ * MERGE_MODE and AUTO_MERGE go, a MERGE_AUTOSTASH is kept on `refs/stash`
623
+ * (`save_autostash_ref`). Returns the lines git prints on stderr for a kept autostash.
624
+ */
625
+ export async function removeMergeBranchState(
626
+ ctx: Pick<SequencerContext, "commits" | "refs">,
627
+ state: OperationState,
628
+ ): Promise<string[]> {
629
+ if (!state.supported) return [];
630
+ await state.removeRef("MERGE_HEAD");
631
+ await state.remove("MERGE_RR", "MERGE_MSG", "MERGE_MODE");
632
+ await state.deleteRef("AUTO_MERGE");
633
+ const autostash = (await state.read("MERGE_AUTOSTASH"))?.trim();
634
+ if (!autostash) return [];
635
+ await saveAutostash(ctx, autostash);
636
+ await state.remove("MERGE_AUTOSTASH");
637
+ return [...AUTOSTASH_SAVED_LINES];
638
+ }
639
+
640
+ /** What git's `apply_save_autostash_oid` prints when it stores an autostash it does not apply. */
641
+ export const AUTOSTASH_SAVED_LINES: readonly string[] = [
642
+ "Autostash exists; creating a new stash entry.",
643
+ "Your changes are safe in the stash.",
644
+ 'You can run "git stash pop" or "git stash drop" at any time.',
645
+ ];
646
+
647
+ /** Byte order of paths, as git sorts the index. */
648
+ function compareBytes(a: string, b: string): number {
649
+ return compareGitPaths(a, b);
650
+ }
651
+
652
+ /** Whether a directory stands at `path` holding untracked content (not a link to one). */
653
+ async function directoryLosesUntracked(
654
+ worktree: Worktree,
655
+ path: string,
656
+ tracked: (p: string) => boolean,
657
+ ): Promise<boolean> {
658
+ const entry = await worktree.getEntry(path);
659
+ if (!entry?.isDirectory) return false;
660
+ return untrackedUnder(worktree, path, tracked);
661
+ }
662
+
663
+ /**
664
+ * unpack-trees' `verify_absent` for a path the reset adds: an untracked (not ignored) file
665
+ * or link on a leading path or at the path itself, or a directory there with tracked files
666
+ * holding local changes or untracked content, refuses the reset.
667
+ */
668
+ async function verifyAbsent(
669
+ worktree: Worktree,
670
+ path: string,
671
+ t: CheckedEntry,
672
+ index: Map<string, CheckedEntry>,
673
+ removing: Set<string>,
674
+ options: {
675
+ hard: boolean;
676
+ /** Paths the index tracks, at any stage (unmerged ones are no untracked files) */
677
+ tracked: (path: string) => boolean;
678
+ trust: ReturnType<typeof worktreeModeTrust> | undefined;
679
+ /** The index file's mtime (racy entries are checked by content) */
680
+ indexTime?: number;
681
+ refuse: (message: string, path: string) => MergeRefusal;
682
+ notUptodate: (path: string) => MergeRefusal;
683
+ /** `core.ignorecase`'s folding lookups of the source index */
684
+ folding?: IndexCaseFolding;
685
+ /** Receives the case variants a replaced directory holds (removed before the writes) */
686
+ caseVariants?: string[];
687
+ },
688
+ ): Promise<MergeRefusal | undefined> {
689
+ const overwritten = (p: string) =>
690
+ options.refuse(`Untracked working tree file '${p}' would be overwritten by merge.`, p);
691
+ // check_leading_path: the first leading component that is no directory
692
+ const parts = path.split("/");
693
+ for (let k = 1; k < parts.length; k++) {
694
+ const prefix = parts.slice(0, k).join("/");
695
+ const entry = await worktree.getEntry(prefix);
696
+ if (!entry) return undefined;
697
+ if (entry.isDirectory) continue;
698
+ if (removing.has(prefix) || (await worktree.isIgnored(prefix))) return undefined;
699
+ // check_ok_to_remove: a case variant of an index entry's own file (icase_exists)
700
+ if (await options.folding?.exists(worktree, prefix, entry)) return undefined;
701
+ return overwritten(prefix);
702
+ }
703
+ const entry = await worktree.getEntry(path);
704
+ if (!entry) return undefined;
705
+ if (entry.isDirectory) {
706
+ // a submodule's directory stays as it is
707
+ if (t.mode === FileMode.GITLINK) return undefined;
708
+ // verify_clean_subdirectory: the tracked files there unchanged (a conflicted one must
709
+ // hold its first stage), nothing untracked
710
+ const under = `${path}/`;
711
+ for (const [p, i] of index) {
712
+ if (!p.startsWith(under)) continue;
713
+ if (
714
+ !options.hard &&
715
+ (await worktreeDiffers(worktree, p, i, options.trust, options.indexTime))
716
+ ) {
717
+ return options.notUptodate(p);
718
+ }
719
+ }
720
+ const variants = options.caseVariants ? options.folding?.variants() : undefined;
721
+ if (await untrackedUnder(worktree, path, options.tracked, false, variants)) {
722
+ return options.refuse(`Updating '${path}' would lose untracked files in it`, path);
723
+ }
724
+ if (variants) options.caseVariants?.push(...variants.found);
725
+ return undefined;
726
+ }
727
+ if (await worktree.isIgnored(path)) return undefined;
728
+ if (await options.folding?.exists(worktree, path, entry)) return undefined;
729
+ return overwritten(path);
730
+ }
731
+
732
+ /** The source index's case-folding lookups under `core.ignorecase` (undefined: off). */
733
+ async function caseFoldingOf(
734
+ ctx: SequencerContext,
735
+ index: Map<string, CheckedEntry>,
736
+ ): Promise<IndexCaseFolding | undefined> {
737
+ if (!ctx.worktree || !coreBool(ctx.workingCopy, "ignorecase", false)) return undefined;
738
+ return new IndexCaseFolding(index, await restoreCaseOptions(ctx.worktree, true));
739
+ }
740
+
741
+ /**
742
+ * git's autostash (`rebase.autoStash`, `merge.autoStash`): the local changes saved as a
743
+ * stash commit (not on `refs/stash`), the index and worktree reset to HEAD. Undefined when
744
+ * there is nothing to save: git's create_autostash stashes only on `has_unstaged_changes ||
745
+ * has_uncommitted_changes`, and an unborn index (no index file) has neither (no entries to
746
+ * differ from their files, `has_uncommitted_changes` 0 by `is_index_unborn`).
747
+ */
748
+ export async function createAutostash(
749
+ ctx: SequencerContext,
750
+ headId: ObjectId,
751
+ ): Promise<ObjectId | undefined> {
752
+ if (await isIndexUnborn(ctx.staging)) return undefined;
753
+ const id = await new StashCreateCommand(ctx.workingCopy)
754
+ .setRef(null)
755
+ .setMessage("autostash")
756
+ .call();
757
+ if (!id) return undefined;
758
+ await resetMerge(ctx, headId, "HEAD", { hard: true });
759
+ return id;
760
+ }
761
+
762
+ /**
763
+ * Applies an autostash back (`Applied autostash.`); where it conflicts, the stash is kept on
764
+ * `refs/stash` as git keeps it. Returns git's lines.
765
+ */
766
+ export async function applyAutostash(ctx: SequencerContext, id: ObjectId): Promise<string[]> {
767
+ try {
768
+ const result = await new StashApplyCommand(ctx.workingCopy).setStashRef(id).call();
769
+ if (result.status === StashApplyStatus.OK) return ["Applied autostash."];
770
+ } catch {
771
+ // refused: kept in the stash below
772
+ }
773
+ await saveAutostash(ctx, id);
774
+ return [
775
+ "Applying autostash resulted in conflicts.",
776
+ "Your changes are safe in the stash.",
777
+ 'You can run "git stash pop" or "git stash drop" at any time.',
778
+ ];
779
+ }
780
+
781
+ /** An autostash kept on `refs/stash` (git's `save_autostash`), for `git stash pop` later. */
782
+ export async function saveAutostash(
783
+ ctx: Pick<SequencerContext, "commits" | "refs">,
784
+ id: ObjectId,
785
+ ): Promise<void> {
786
+ const commit = await ctx.commits.load(id);
787
+ await ctx.refs.batch([{ name: STASH_REF, new: id }], {
788
+ ident: commit ? formatPersonIdent(commit.committer) : undefined,
789
+ message: "autostash",
790
+ createReflog: true,
791
+ });
792
+ }
793
+
794
+ /**
795
+ * git's commit message cleanup (`strip`, as `git commit` applies it to an edited message):
796
+ * comment lines dropped, trailing whitespace removed, runs of blank lines collapsed, blank
797
+ * lines at the start and end dropped, a final newline.
798
+ */
799
+ export function cleanupMessage(message: string, commentChar = "#"): string {
800
+ return stripspace(message, commentChar);
801
+ }
802
+
803
+ const DAYS = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
804
+ const MONTHS = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
805
+
806
+ /** git's default date format (`Tue Nov 14 22:13:20 2023 +0000`), in the ident's zone. */
807
+ export function formatGitDate(ident: PersonIdent): string {
808
+ const tz = ident.tzOffset || "+0000";
809
+ const sign = tz.startsWith("-") ? -1 : 1;
810
+ const minutes = sign * (Number(tz.slice(1, 3)) * 60 + Number(tz.slice(3, 5)));
811
+ const d = new Date((ident.timestamp + minutes * 60) * 1000);
812
+ const two = (n: number) => String(n).padStart(2, "0");
813
+ return `${DAYS[d.getUTCDay()]} ${MONTHS[d.getUTCMonth()]} ${d.getUTCDate()} ${two(d.getUTCHours())}:${two(d.getUTCMinutes())}:${two(d.getUTCSeconds())} ${d.getUTCFullYear()} ${tz}`;
814
+ }
815
+
816
+ /**
817
+ * git's `SQUASH_MSG`: `Squashed commit of the following:` and the commits `src` has that
818
+ * `head` has not, newest first, as `git log` prints them. Several heads (an octopus) list
819
+ * what any of them has. `abbreviate` shortens the parents of `Merge:` lines.
820
+ */
821
+ export async function squashMessage(
822
+ commits: CommandCommits,
823
+ headId: ObjectId,
824
+ srcId: ObjectId | ObjectId[],
825
+ abbreviate: (id: ObjectId) => Promise<string>,
826
+ ): Promise<string> {
827
+ const reachable = new Set<ObjectId>();
828
+ const stack = [headId];
829
+ while (stack.length > 0) {
830
+ const id = stack.pop() as ObjectId;
831
+ if (reachable.has(id)) continue;
832
+ reachable.add(id);
833
+ const commit = await commits.load(id);
834
+ if (commit) stack.push(...commit.parents);
835
+ }
836
+ const listed: { id: ObjectId; time: number; order: number }[] = [];
837
+ const seen = new Set<ObjectId>();
838
+ const queue = Array.isArray(srcId) ? [...srcId] : [srcId];
839
+ while (queue.length > 0) {
840
+ const id = queue.shift() as ObjectId;
841
+ if (seen.has(id) || reachable.has(id)) continue;
842
+ seen.add(id);
843
+ const commit = await commits.load(id);
844
+ if (!commit) continue;
845
+ listed.push({ id, time: commit.committer.timestamp, order: listed.length });
846
+ queue.push(...commit.parents);
847
+ }
848
+ listed.sort((a, b) => b.time - a.time || a.order - b.order);
849
+ let out = "Squashed commit of the following:\n";
850
+ for (const { id } of listed) {
851
+ const commit = await commits.load(id);
852
+ if (!commit) continue;
853
+ out += `\ncommit ${id}\n`;
854
+ if (commit.parents.length > 1) {
855
+ // pp_header: each parent through repo_find_unique_abbrev (DEFAULT_ABBREV)
856
+ const parents: string[] = [];
857
+ for (const p of commit.parents) parents.push(await abbreviate(p));
858
+ out += `Merge: ${parents.join(" ")}\n`;
859
+ }
860
+ out += `Author: ${commit.author.name} <${commit.author.email}>\n`;
861
+ out += `Date: ${formatGitDate(commit.author)}\n\n`;
862
+ const body = commit.message.replace(/\n+$/, "");
863
+ out += `${body
864
+ .split("\n")
865
+ .map((l) => ` ${l}`)
866
+ .join("\n")}\n`;
867
+ }
868
+ return out;
869
+ }