@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
@@ -1,11 +1,66 @@
1
- import type { ObjectId, Ref } from "@statewalker/vcs-core";
2
- import { isSymbolicRef } from "@statewalker/vcs-core";
3
-
1
+ import {
2
+ type Blobs,
3
+ EMPTY_BLOB_ID,
4
+ EMPTY_TREE_ID,
5
+ FileMode,
6
+ type ObjectId,
7
+ type Ref,
8
+ } from "@statewalker/vcs-core";
9
+ import { compareGitPaths } from "@statewalker/vcs-utils/encoding";
10
+ import {
11
+ applyStatUpdate,
12
+ cacheTreeOfTree,
13
+ compareWithWorktree,
14
+ copyCacheTree,
15
+ entryStatOf,
16
+ getWorktreeEntries,
17
+ type IndexEntryOptions,
18
+ type IndexStatUpdate,
19
+ invalidateCacheTreePath,
20
+ type ResolveUndoRecord,
21
+ type Staging,
22
+ type StagingEntry,
23
+ statUpdateOf,
24
+ type WorkingCopy,
25
+ type Worktree,
26
+ withWorktreeEntries,
27
+ } from "@statewalker/vcs-working-tree";
28
+ import {
29
+ IncompatibleOptionsError,
30
+ InvalidArgumentError,
31
+ ResetRefusedError,
32
+ } from "../errors/command-errors.js";
4
33
  import { RefNotFoundError } from "../errors/ref-errors.js";
5
- import { GitCommand } from "../git-command.js";
34
+ import { type CommandTrees, GitCommand } from "../git-command.js";
6
35
  import { ResetMode } from "../types.js";
36
+ import {
37
+ type PatchCompatibility,
38
+ type PatchOptions,
39
+ type PatchResult,
40
+ type PatchSelector,
41
+ patchModeFor,
42
+ runPatchSelection,
43
+ } from "./add-patch/index.js";
7
44
  import { coreBool, worktreeModeTrust } from "./core-config.js";
8
- import { planTreeRestore, writeTreeRestorePlan } from "./tree-restore.js";
45
+ import { hostEnvironmentOf } from "./git-ident.js";
46
+ import { addLeadingDirs, stageZeroClashes } from "./index-adder.js";
47
+ import { configBool } from "./merge-config.js";
48
+ import { flatTree, OperationState, rewriteIndex } from "./merge-support.js";
49
+ import {
50
+ DO_MATCH_DIRECTORY,
51
+ globalPathspecMagic,
52
+ matchPathspec,
53
+ type PathspecItem,
54
+ parsePathspec,
55
+ parsePathspecFile,
56
+ } from "./pathspec.js";
57
+ import { PathspecAttributes } from "./pathspec-attributes.js";
58
+ import { markIndexUpdate } from "./post-index-change.js";
59
+ import { reflogMessages } from "./reflog-messages.js";
60
+ import { moveHeadAsReset, removeBranchState, resetKeep, resetMerge } from "./sequencer-support.js";
61
+ import { pushSparseWarnings, SparseUnpack } from "./sparse-checkout-support.js";
62
+ import { planTreeRestore, restoreCaseOptions, writeTreeRestorePlan } from "./tree-restore.js";
63
+ import { flaggedEntryDiffers, pruneEmptyParents } from "./worktree-overwrite-checks.js";
9
64
 
10
65
  /** Names this operation in restore failure messages. */
11
66
  const RESET_HARD = "reset --hard";
@@ -46,6 +101,118 @@ export class ResetCommand extends GitCommand<Ref> {
46
101
  private ref?: string;
47
102
  private mode = ResetMode.MIXED;
48
103
  private paths: string[] = [];
104
+ private pathspecFromFile: string[] = [];
105
+ /** Whether `--pathspec-from-file` was given (an empty file included) */
106
+ private pathspecFileGiven = false;
107
+ private modeSet = false;
108
+ private intentToAdd = false;
109
+ private quiet = false;
110
+ private noRefresh = false;
111
+ private readonly output: string[] = [];
112
+ private patch = false;
113
+ private patchSelector?: PatchSelector;
114
+ private patchOptions: PatchOptions = {};
115
+ private patchResult?: PatchResult;
116
+ private compatibility: PatchCompatibility = "2.56";
117
+
118
+ /**
119
+ * `-q` / `--quiet`: a mixed reset does not list the files left with unstaged changes
120
+ * (refresh_index with `REFRESH_QUIET`: only unmerged paths, as `<path>: needs merge`), and
121
+ * gives no hint about a slow refresh. (`reset.quiet` is read by neither git 2.43 nor 2.5x.)
122
+ */
123
+ setQuiet(quiet: boolean): this {
124
+ this.checkCallable();
125
+ this.quiet = quiet;
126
+ return this;
127
+ }
128
+
129
+ /**
130
+ * `git reset -p [<tree-ish>] [-- <paths>]`: the differences between the tree-ish (HEAD by
131
+ * default) and the index are offered hunk by hunk, as git's add-patch.c does; the selected
132
+ * hunks are taken out of the index ("Unstage this hunk"), or with another tree-ish applied
133
+ * to it ("Apply this hunk to index"). HEAD and the worktree stay. The prompts are answered
134
+ * by {@link setPatchSelector}; {@link getPatchResult} gives git's transcript. Not with a
135
+ * mode (`--soft`, `--mixed`, `--hard`...).
136
+ *
137
+ * @example
138
+ * ```typescript
139
+ * const answers = ["y", "n"];
140
+ * const reset = git.reset().setPatch(true).setPatchSelector(() => answers.shift());
141
+ * await reset.call();
142
+ * console.log(reset.getPatchResult()?.output);
143
+ * ```
144
+ */
145
+ setPatch(patch: boolean): this {
146
+ this.checkCallable();
147
+ this.patch = patch;
148
+ return this;
149
+ }
150
+
151
+ /** Answers the prompts of {@link setPatch}. */
152
+ setPatchSelector(selector: PatchSelector): this {
153
+ this.checkCallable();
154
+ this.patchSelector = selector;
155
+ return this;
156
+ }
157
+
158
+ /** `-U<n>`, `--inter-hunk-context=<n>` and `--no-auto-advance` of {@link setPatch}. */
159
+ setPatchOptions(options: PatchOptions): this {
160
+ this.checkCallable();
161
+ this.patchOptions = { ...options };
162
+ return this;
163
+ }
164
+
165
+ /** The git version whose prompts {@link setPatch} reproduces (default 2.56). */
166
+ setCompatibility(version: PatchCompatibility): this {
167
+ this.checkCallable();
168
+ this.compatibility = version;
169
+ return this;
170
+ }
171
+
172
+ /** What {@link setPatch}'s selection printed and applied; read after {@link call}. */
173
+ getPatchResult(): PatchResult | undefined {
174
+ return this.patchResult;
175
+ }
176
+
177
+ /** `git reset -p`: run_add_p(ADD_P_RESET, rev). */
178
+ private async callPatch(): Promise<Ref> {
179
+ if (this.modeSet) {
180
+ throw new IncompatibleOptionsError(
181
+ ["--patch", "--{hard,mixed,soft}"],
182
+ "fatal: options '--patch' and '--{hard,mixed,soft}' cannot be used together",
183
+ );
184
+ }
185
+ const rev = this.ref === undefined || this.ref === "@" ? "HEAD" : this.ref;
186
+ const head = await this.refsStore.resolve("HEAD");
187
+ const diffRevision = rev === "HEAD" && !head?.objectId ? EMPTY_TREE_ID : rev;
188
+ if (diffRevision !== EMPTY_TREE_ID) await this.resolveRef(rev);
189
+ this.patchResult = await runPatchSelection(this.workingCopy, {
190
+ hookSource: this,
191
+ ...this.patchOptions,
192
+ mode: patchModeFor("reset", rev),
193
+ selector: this.patchSelector,
194
+ diffRevision,
195
+ paths: [...this.pathspecFromFile, ...this.paths],
196
+ compatibility: this.compatibility,
197
+ });
198
+ return (await this.refsStore.resolve("HEAD")) as Ref;
199
+ }
200
+
201
+ /** `--no-refresh`: a mixed reset leaves the index's stat data as the reset wrote it. */
202
+ setNoRefresh(noRefresh: boolean): this {
203
+ this.checkCallable();
204
+ this.noRefresh = noRefresh;
205
+ return this;
206
+ }
207
+
208
+ /**
209
+ * What the reset printed on stdout, line by line: after a mixed reset (with paths too),
210
+ * git's "Unstaged changes after reset:" and a `M\t<path>` (`D`, `T`, `A`, `U`) line per
211
+ * file whose content differs from its entry. Read after {@link call}.
212
+ */
213
+ getOutput(): string[] {
214
+ return [...this.output];
215
+ }
49
216
 
50
217
  /**
51
218
  * Set the ref to reset to.
@@ -69,15 +236,40 @@ export class ResetCommand extends GitCommand<Ref> {
69
236
  * - HARD: Move HEAD, reset staging, and reset working tree. DESTRUCTIVE -
70
237
  * uncommitted changes to tracked files are discarded and tracked files
71
238
  * absent from the target commit are deleted from the working tree.
239
+ * - MERGE: as git's `reset --merge`: index entries that differ from the target take
240
+ * its version, worktree files with them; refused (ResetRefusedError) where a file
241
+ * with unstaged changes or an untracked file would be lost. Unmerged entries are reset.
242
+ * - KEEP: as git's `reset --keep`: files that differ between HEAD and the target are
243
+ * switched, local changes elsewhere kept; refused where a switched file has local
244
+ * changes, and in the middle of a merge.
245
+ *
246
+ * Every mode records the old HEAD in ORIG_HEAD and, as git's reset, forgets a merge,
247
+ * cherry-pick or revert in progress (MERGE_HEAD, CHERRY_PICK_HEAD, ...).
72
248
  *
73
249
  * @param mode Reset mode
74
250
  */
75
251
  setMode(mode: ResetMode): this {
76
252
  this.checkCallable();
77
253
  this.mode = mode;
254
+ this.modeSet = true;
78
255
  return this;
79
256
  }
80
257
 
258
+ /**
259
+ * What the reset printed on stderr while applying the sparse checkout's patterns, line by
260
+ * line: the patterns' warnings, and git's `error: Path '<p>' not uptodate; will not remove
261
+ * from working tree.` for a changed file left outside them (`--merge`, `--keep`), and
262
+ * "Autostash exists; creating a new stash entry." with its lines when a stopped merge's
263
+ * autostash is kept on `refs/stash`, and git's `error: update_ref failed for ref
264
+ * 'ORIG_HEAD': ...` when ORIG_HEAD cannot be written (HEAD moves all the same). Read after
265
+ * {@link call}.
266
+ */
267
+ getWarnings(): string[] {
268
+ return [...this.warnings];
269
+ }
270
+
271
+ private readonly warnings: string[] = [];
272
+
81
273
  /**
82
274
  * Add a path to reset.
83
275
  *
@@ -92,6 +284,35 @@ export class ResetCommand extends GitCommand<Ref> {
92
284
  return this;
93
285
  }
94
286
 
287
+ /**
288
+ * `-N` / `--intent-to-add` (mixed resets only): a path the tree lacks stays in the index as
289
+ * an intent-to-add entry instead of leaving it.
290
+ */
291
+ setIntentToAdd(intentToAdd: boolean): this {
292
+ this.checkCallable();
293
+ this.intentToAdd = intentToAdd;
294
+ return this;
295
+ }
296
+
297
+ /**
298
+ * `--pathspec-from-file` (and `--pathspec-file-nul` with `nul`): the pathspec elements of
299
+ * `content`, one per line.
300
+ */
301
+ setPathspecFromFile(content: string | Uint8Array, nul = false): this {
302
+ this.checkCallable();
303
+ this.pathspecFileGiven = true;
304
+ try {
305
+ this.pathspecFromFile = parsePathspecFile(content, nul);
306
+ } catch (error) {
307
+ throw new InvalidArgumentError(
308
+ "pathspecFromFile",
309
+ content,
310
+ `fatal: ${(error as Error).message}`,
311
+ );
312
+ }
313
+ return this;
314
+ }
315
+
95
316
  /**
96
317
  * Execute the reset.
97
318
  *
@@ -99,11 +320,46 @@ export class ResetCommand extends GitCommand<Ref> {
99
320
  * @throws RefNotFoundError if ref cannot be resolved
100
321
  */
101
322
  async call(): Promise<Ref> {
323
+ // git writes the index once: one post-index-change run, after the worktree is updated
324
+ // a whole-tree reset writes the index and then the stat of the files it wrote: held back
325
+ // and written once, as git's one write (the patch and path modes read the index back)
326
+ const wholeTree = !this.patch && this.paths.length === 0 && !this.pathspecFileGiven;
327
+ // one worktree operation: the files refreshed or written convert with attributes read
328
+ // once, not once per file
329
+ return this.withOneIndexWrite("last", () => this.inOneOperation(() => this.resetOnce()), {
330
+ holdWrites: wholeTree,
331
+ });
332
+ }
333
+
334
+ private async resetOnce(): Promise<Ref> {
102
335
  this.checkCallable();
103
336
  this.setCallable(false);
337
+ // the index as it is now, before the worktree or a ref is touched: one another writer
338
+ // replaced is read again (git reads the index at its start), unless this instance holds
339
+ // unwritten edits (refused)
340
+ await this.readCurrentIndex();
104
341
 
342
+ if (this.pathspecFileGiven && this.patch)
343
+ throw new IncompatibleOptionsError(
344
+ ["--pathspec-from-file", "--patch"],
345
+ "fatal: options '--pathspec-from-file' and '--patch' cannot be used together",
346
+ );
347
+ if (this.paths.length > 0 && this.pathspecFromFile.length > 0) {
348
+ throw new InvalidArgumentError(
349
+ "pathspecFromFile",
350
+ this.pathspecFromFile,
351
+ "fatal: '--pathspec-from-file' and pathspec arguments cannot be used together",
352
+ );
353
+ }
354
+ if (this.intentToAdd && this.mode !== ResetMode.MIXED) {
355
+ throw new IncompatibleOptionsError(
356
+ ["-N", "--mixed"],
357
+ "fatal: the option '-N' requires '--mixed'",
358
+ );
359
+ }
360
+ if (this.patch) return this.callPatch();
105
361
  // If paths are specified, do path reset
106
- if (this.paths.length > 0) {
362
+ if (this.paths.length > 0 || this.pathspecFromFile.length > 0) {
107
363
  return this.resetPaths();
108
364
  }
109
365
 
@@ -117,86 +373,376 @@ export class ResetCommand extends GitCommand<Ref> {
117
373
  const trackedBefore =
118
374
  this.mode === ResetMode.HARD ? await this.collectTrackedPaths() : undefined;
119
375
 
120
- // Move HEAD/branch
121
- await this.moveHead(targetId);
376
+ const state = new OperationState(this.workingCopy.checkout, this.refsStore);
377
+ const headId = (await this.refsStore.resolve("HEAD"))?.objectId;
378
+ // git refuses a soft or keep reset in the middle of a merge (die_if_unmerged_cache)
379
+ if (this.mode === ResetMode.SOFT || this.mode === ResetMode.KEEP) {
380
+ let unmerged = false;
381
+ for await (const entry of this.staging.entries()) if (entry.stage > 0) unmerged = true;
382
+ if (unmerged || (await state.exists("MERGE_HEAD"))) {
383
+ throw new ResetRefusedError(
384
+ `fatal: Cannot do a ${this.mode} reset in the middle of a merge.`,
385
+ );
386
+ }
387
+ }
388
+ // --merge and --keep: the index and worktree first, refused before anything changes
389
+ if (this.mode === ResetMode.MERGE || this.mode === ResetMode.KEEP) {
390
+ const ctx = {
391
+ workingCopy: this.workingCopy,
392
+ worktree: this.worktreeAccess,
393
+ staging: this.staging,
394
+ blobs: this.blobs,
395
+ trees: this.trees,
396
+ commits: this.commits,
397
+ refs: this.refsStore,
398
+ sparseWarnings: this.warnings,
399
+ };
400
+ const refused =
401
+ this.mode === ResetMode.MERGE
402
+ ? await resetMerge(ctx, targetId, targetRef)
403
+ : await resetKeep(ctx, headId ?? targetId, targetId, targetRef);
404
+ if (refused) throw new ResetRefusedError(refused.message, refused.paths);
405
+ }
406
+
407
+ // a hard reset in a sparse checkout: unpack-trees with its patterns (what stays outside
408
+ // is neither checked nor touched)
409
+ const sparse =
410
+ this.mode === ResetMode.HARD
411
+ ? await SparseUnpack.start({
412
+ workingCopy: this.workingCopy,
413
+ worktree: this.worktreeAccess,
414
+ staging: this.staging,
415
+ })
416
+ : undefined;
417
+
418
+ // --hard: unpack-trees' one-way merge checks the entries whose flags cheat (assume-unchanged,
419
+ // skip-worktree) before anything changes; a file kept outside the worktree stays so
420
+ let flagged: FlaggedEntries | undefined;
421
+ if (this.mode === ResetMode.HARD) {
422
+ const commit = await this.commits.load(targetId);
423
+ if (commit) {
424
+ flagged = await checkFlaggedEntries(
425
+ {
426
+ trees: this.trees,
427
+ staging: this.staging,
428
+ workingCopy: this.workingCopy,
429
+ worktree: this.worktreeAccess,
430
+ },
431
+ commit.tree,
432
+ sparse,
433
+ );
434
+ if (flagged.refused !== undefined) {
435
+ throw new ResetRefusedError(
436
+ `error: Entry '${flagged.refused}' not uptodate. Cannot merge.\n` +
437
+ `fatal: Could not reset index file to revision '${targetRef}'.`,
438
+ [flagged.refused],
439
+ );
440
+ }
441
+ }
442
+ }
443
+
444
+ // git's set_reflog_message: "reset: moving to <rev>", or "<action>: updating HEAD"
445
+ const message = this.hasReflogAction()
446
+ ? `${this.reflogAction("reset")}: updating HEAD`
447
+ : reflogMessages.reset(targetRef);
448
+ // Move HEAD/branch, the old HEAD kept in ORIG_HEAD (git's update_refs)
449
+ // (an ORIG_HEAD it cannot write reported on stderr, HEAD moved all the same)
450
+ this.warnings.push(
451
+ ...(await moveHeadAsReset(
452
+ this.refsStore,
453
+ state,
454
+ headId,
455
+ targetId,
456
+ this.reflogLine(message),
457
+ `${this.hasReflogAction() ? this.reflogAction("reset") : "reset"}: updating ORIG_HEAD`,
458
+ )),
459
+ );
122
460
 
123
461
  // Reset staging area (for MIXED and HARD)
124
462
  if (this.mode === ResetMode.MIXED || this.mode === ResetMode.HARD) {
463
+ // post-index-change: unpack-trees updated the worktree (hard), or read_from_tree may
464
+ // have changed skip-worktree bits (mixed)
465
+ markIndexUpdate(
466
+ this.staging,
467
+ this.mode === ResetMode.HARD ? { workdir: true } : { skipWorktree: true },
468
+ );
125
469
  await this.resetStaging(targetId);
126
470
  }
471
+ // a mixed reset refreshes the index and lists what is left unstaged
472
+ if (this.mode === ResetMode.MIXED && (await this.refreshAfterReset())) {
473
+ await this.staging.write();
474
+ }
127
475
 
128
476
  // Reset working tree (for HARD) - this DESTROYS uncommitted changes
129
477
  if (this.mode === ResetMode.HARD) {
130
- await this.resetWorkingTree(targetId, trackedBefore ?? new Set());
478
+ const written = await this.resetWorkingTree(
479
+ targetId,
480
+ trackedBefore ?? new Set(),
481
+ flagged?.keptOut,
482
+ sparse,
483
+ );
484
+ // check_updates: the entries written carry the stat of their new files
485
+ if (this.worktreeAccess && written.size > 0) {
486
+ await recordWrittenStat(this.staging, this.worktreeAccess, written);
487
+ await this.staging.write();
488
+ }
489
+ if (sparse) {
490
+ // UNPACK_RESET_OVERWRITE_UNTRACKED: an entry coming back is written over anything
491
+ const outcome = await sparse.finish(
492
+ {
493
+ workingCopy: this.workingCopy,
494
+ worktree: this.worktreeAccess,
495
+ staging: this.staging,
496
+ blobs: this.blobs,
497
+ },
498
+ { written, overwrite: true },
499
+ );
500
+ pushSparseWarnings(this.warnings, sparse, outcome, false);
501
+ }
131
502
  }
132
503
 
504
+ // git's remove_branch_state: a merge, cherry-pick or revert in progress is forgotten
505
+ // (a merge's autostash kept on refs/stash, git's lines printed)
506
+ this.warnings.push(
507
+ ...(await removeBranchState({ commits: this.commits, refs: this.refsStore }, state)),
508
+ );
509
+
133
510
  // Return the updated HEAD ref
134
511
  const headRef = await this.refsStore.resolve("HEAD");
135
512
  return headRef as Ref;
136
513
  }
137
514
 
138
515
  /**
139
- * Reset specific paths in staging area.
516
+ * `git reset [<tree-ish>] [--] <pathspec>...` (builtin/reset.c): the index entries the
517
+ * pathspec names are set to the tree's (`read_from_tree`); HEAD and the worktree stay.
140
518
  */
141
519
  private async resetPaths(): Promise<Ref> {
142
- // For path reset, we reset the staging entries to match the ref
143
- const targetRef = this.ref ?? "HEAD";
144
- const targetId = await this.resolveRef(targetRef);
145
-
146
- // Load target commit's tree
147
- const targetCommit = await this.commits.load(targetId);
148
- if (!targetCommit) {
149
- throw new RefNotFoundError(targetId, "Target commit not found");
520
+ // cmd_reset: only a mixed reset takes paths (an explicit --mixed is deprecated)
521
+ if (this.modeSet && this.mode !== ResetMode.MIXED) {
522
+ throw new ResetRefusedError(`fatal: Cannot do ${this.mode} reset with paths.`);
150
523
  }
151
- const treeId = targetCommit.tree;
152
-
153
- // Reset each path in staging
154
- const editor = this.staging.createEditor();
524
+ if (this.modeSet) {
525
+ this.warnings.push(
526
+ "warning: --mixed with paths is deprecated; use 'git reset -- <paths>' instead.",
527
+ );
528
+ }
529
+ let items: PathspecItem[];
530
+ try {
531
+ const global = globalPathspecMagic(hostEnvironmentOf(this.workingCopy)?.pathspecs);
532
+ items = parsePathspec([...this.pathspecFromFile, ...this.paths], { attr: true, global });
533
+ } catch (error) {
534
+ throw new InvalidArgumentError("path", this.paths, `fatal: ${(error as Error).message}`);
535
+ }
536
+ const treeId = await this.resetTree(true);
537
+ await this.readFromTree(treeId, items);
538
+ await this.refreshAfterReset();
539
+ markIndexUpdate(this.staging, { skipWorktree: true });
540
+ await this.staging.write();
541
+ const headRef = await this.refsStore.resolve("HEAD");
542
+ return headRef as Ref;
543
+ }
155
544
 
156
- for (const path of this.paths) {
157
- const entry = await this.getTreeEntryForPath(treeId, path);
158
- if (entry) {
159
- // Path exists in target - update staging to match
160
- editor.add({
161
- path,
162
- apply: () => ({
163
- path,
164
- mode: entry.mode,
165
- objectId: entry.objectId,
166
- stage: 0,
167
- size: 0,
168
- mtime: Date.now(),
169
- }),
170
- });
171
- } else {
172
- // Path doesn't exist in target - remove from staging
545
+ /**
546
+ * cmd_reset's refresh after a mixed reset (`refresh_index` with `REFRESH_IN_PORCELAIN`, or
547
+ * `REFRESH_QUIET` with `--quiet`): every stage-0 entry compared with its file, those still
548
+ * holding their content given the file's stat; the others listed under "Unstaged changes
549
+ * after reset:" (unmerged paths whatever the flag). Skip-worktree and assume-unchanged
550
+ * entries are taken as up to date. With git's hint when it took over two seconds
551
+ * (`advice.resetNoRefresh`). Whether any entry's stat changed (the index is to be written).
552
+ */
553
+ private async refreshAfterReset(): Promise<boolean> {
554
+ const worktree = this.worktreeAccess;
555
+ if (this.noRefresh || !worktree) return false;
556
+ const started = Date.now();
557
+ let first = true;
558
+ const show = (line: string) => {
559
+ if (!this.quiet && first) this.output.push("Unstaged changes after reset:");
560
+ first = false;
561
+ this.output.push(line);
562
+ };
563
+ const trust = worktreeModeTrust(this.workingCopy, worktree);
564
+ const indexTime = this.staging.getUpdateTime();
565
+ const entries: StagingEntry[] = [];
566
+ for await (const entry of this.staging.entryList?.() ?? this.staging.entries()) {
567
+ entries.push(entry);
568
+ }
569
+ const stated = (entry: StagingEntry) =>
570
+ entry.stage === 0 && !entry.skipWorktree && !entry.assumeValid;
571
+ const updates: IndexStatUpdate[] = [];
572
+ let lastUnmerged: string | undefined;
573
+ for await (const { item: entry, current } of withWorktreeEntries(worktree, entries, stated)) {
574
+ if (entry.stage !== 0) {
575
+ if (entry.path === lastUnmerged) continue;
576
+ lastUnmerged = entry.path;
577
+ show(this.quiet ? `${entry.path}: needs merge` : `U\t${entry.path}`);
578
+ continue;
579
+ }
580
+ if (entry.skipWorktree || entry.assumeValid) continue;
581
+ const compared = await compareWithWorktree(worktree, entry, { trust, indexTime }, current);
582
+ if (!compared.kind && !entry.intentToAdd) {
583
+ const update = statUpdateOf(entry, compared);
584
+ if (update && !update.smudge) updates.push(update);
585
+ continue;
586
+ }
587
+ if (this.quiet) continue;
588
+ const code =
589
+ compared.kind === "deleted"
590
+ ? "D"
591
+ : entry.intentToAdd
592
+ ? "A"
593
+ : compared.kind === "typechange"
594
+ ? "T"
595
+ : "M";
596
+ show(`${code}\t${entry.path}`);
597
+ }
598
+ if (updates.length > 0) {
599
+ const now = Date.now();
600
+ const editor = this.staging.createEditor();
601
+ for (const update of updates) {
173
602
  editor.add({
174
- path,
175
- apply: () => undefined,
603
+ path: update.path,
604
+ apply: (existing) => applyStatUpdate(existing, update, now) ?? existing,
176
605
  });
177
606
  }
607
+ await editor.finish();
178
608
  }
609
+ const elapsed = Date.now() - started;
610
+ if (
611
+ !this.quiet &&
612
+ elapsed > 2000 &&
613
+ configBool(this.workingCopy, "advice.resetNoRefresh", true)
614
+ ) {
615
+ this.warnings.push(
616
+ `hint: It took ${(elapsed / 1000).toFixed(2)} seconds to refresh the index after reset. You can use\n` +
617
+ "hint: '--no-refresh' to avoid this.",
618
+ );
619
+ }
620
+ return updates.length > 0;
621
+ }
179
622
 
180
- await editor.finish();
181
- await this.staging.write();
182
-
183
- const headRef = await this.refsStore.resolve("HEAD");
184
- return headRef as Ref;
623
+ /**
624
+ * The tree a path reset (or a `-N` reset) reads: the empty tree on an unborn HEAD, else the
625
+ * tree-ish's tree (git's "Failed to resolve '<rev>' as a valid tree.").
626
+ */
627
+ private async resetTree(paths: boolean): Promise<ObjectId | undefined> {
628
+ const targetRef = this.ref ?? "HEAD";
629
+ let id: ObjectId;
630
+ try {
631
+ id = await this.resolveRevision(targetRef);
632
+ } catch (error) {
633
+ if (targetRef === "HEAD" && error instanceof RefNotFoundError) return undefined;
634
+ if (error instanceof RefNotFoundError) {
635
+ throw new RefNotFoundError(
636
+ targetRef,
637
+ paths
638
+ ? `fatal: Failed to resolve '${targetRef}' as a valid tree.`
639
+ : `fatal: Failed to resolve '${targetRef}' as a valid revision.`,
640
+ );
641
+ }
642
+ throw error;
643
+ }
644
+ const treeId = await this.revisionResolver().peelToType(id, "tree");
645
+ if (treeId === undefined) {
646
+ throw new RefNotFoundError(targetRef, `fatal: Could not parse object '${targetRef}'.`);
647
+ }
648
+ return treeId;
185
649
  }
186
650
 
187
651
  /**
188
- * Move HEAD (and branch if applicable) to target commit.
652
+ * git's `read_from_tree` (`do_diff_cache` of the tree and the index, then
653
+ * `update_index_from_diff`): each path the pathspec names (every path without one) where
654
+ * the index differs from the tree (mode or blob; an unmerged path always) takes the
655
+ * tree's entry, stage 0, or leaves the index when the tree lacks it (with `-N` it stays as
656
+ * an intent-to-add entry). A new entry keeps a skip-worktree bit, or gets one outside the
657
+ * sparse checkout; the conflict stages it replaces are recorded for resolve-undo.
189
658
  */
190
- private async moveHead(targetId: ObjectId): Promise<void> {
191
- const head = await this.refsStore.get("HEAD");
192
-
193
- if (head && isSymbolicRef(head)) {
194
- // HEAD points to a branch - update the branch
195
- await this.refsStore.set(head.target, targetId);
196
- } else {
197
- // Detached HEAD - update HEAD directly
198
- await this.refsStore.set("HEAD", targetId);
659
+ private async readFromTree(treeId: ObjectId | undefined, items: PathspecItem[]): Promise<void> {
660
+ const tree = await flatTree(this.trees, treeId);
661
+ const index = new Map<string, StagingEntry[]>();
662
+ for await (const entry of this.staging.entries()) {
663
+ const list = index.get(entry.path);
664
+ if (list) list.push(entry);
665
+ else index.set(entry.path, [entry]);
199
666
  }
667
+ const attributes = PathspecAttributes.forWorktree(items, this.worktreeAccess);
668
+ if (attributes) await attributes.load([...index.keys(), ...tree.keys()]);
669
+ const named = (path: string, mode: number) =>
670
+ items.length === 0 ||
671
+ matchPathspec(items, path, mode === FileMode.GITLINK ? DO_MATCH_DIRECTORY : 0) > 0;
672
+ const patterns = await this.sparseCheckoutPatterns();
673
+ const changes = new Map<string, IndexEntryOptions[]>();
674
+ const undo: ResolveUndoRecord[] = [];
675
+ // the index as edited so far, for add_index_entry's file/directory clashes
676
+ const current = (path: string): readonly IndexEntryOptions[] =>
677
+ changes.get(path) ?? index.get(path) ?? [];
678
+ const hasStageZero = (path: string) => current(path).some((e) => (e.stage ?? 0) === 0);
679
+ const dirs = new Set<string>();
680
+ for (const path of index.keys()) addLeadingDirs(dirs, path);
681
+ // update_index_from_diff works through the diff queue in the index's order
682
+ const paths = [...new Set([...index.keys(), ...tree.keys()])].sort(compareGitPaths);
683
+ let intentToAddCreated = false;
684
+ for (const path of paths) {
685
+ const entries = index.get(path) ?? [];
686
+ const t = tree.get(path);
687
+ // diff-lib's oneway_diff matches the index entry, else the tree's
688
+ const first = entries[0];
689
+ if (!named(path, first ? first.mode : (t?.mode ?? 0))) continue;
690
+ const unmerged = entries.some((e) => e.stage > 0);
691
+ const staged = entries.find((e) => e.stage === 0);
692
+ if (!unmerged) {
693
+ // the same mode and blob: no change (an intent-to-add entry included)
694
+ if (staged && t && staged.mode === t.mode && staged.objectId === t.objectId) continue;
695
+ if (!staged && !t) continue;
696
+ }
697
+ if (unmerged) {
698
+ const record: ResolveUndoRecord = {
699
+ path,
700
+ modes: [0, 0, 0],
701
+ objectIds: [undefined, undefined, undefined],
702
+ };
703
+ for (const e of entries) {
704
+ if (e.stage < 1 || e.stage > 3) continue;
705
+ record.modes[e.stage - 1] = e.mode;
706
+ record.objectIds[e.stage - 1] = e.objectId;
707
+ }
708
+ undo.push(record);
709
+ }
710
+ if (!t && !this.intentToAdd) {
711
+ changes.set(path, []);
712
+ continue;
713
+ }
714
+ const skipWorktree = staged
715
+ ? staged.skipWorktree === true
716
+ : patterns !== undefined && !patterns.includes(path);
717
+ // add_index_entry: the new stage-0 entry replaces the stage-0 entries it clashes with
718
+ // as a file or a directory (has_dir_name / has_file_name; conflict stages stay)
719
+ for (const other of stageZeroClashes(path, hasStageZero, paths, dirs)) {
720
+ changes.set(
721
+ other,
722
+ current(other).filter((e) => (e.stage ?? 0) > 0),
723
+ );
724
+ }
725
+ addLeadingDirs(dirs, path);
726
+ if (!t) intentToAddCreated = true;
727
+ changes.set(path, [
728
+ {
729
+ path,
730
+ // make_cache_entry of a path the tree lacks: create_ce_mode(0), a regular file
731
+ mode: t ? t.mode : FileMode.REGULAR_FILE,
732
+ objectId: t ? t.objectId : EMPTY_BLOB_ID,
733
+ stage: 0,
734
+ size: 0,
735
+ mtime: 0,
736
+ ...(skipWorktree ? { skipWorktree: true } : {}),
737
+ ...(t ? {} : { intentToAdd: true }),
738
+ },
739
+ ]);
740
+ }
741
+ // set_object_name_for_intent_to_add_entry: the empty blob an intent-to-add entry names
742
+ // is written, so the index never names a missing object
743
+ if (intentToAddCreated) await this.blobs.store([new Uint8Array(0)], 0);
744
+ if (undo.length > 0) this.staging.recordResolveUndo?.(undo);
745
+ if (changes.size > 0) await rewriteIndex(this.staging, changes);
200
746
  }
201
747
 
202
748
  /**
@@ -225,41 +771,29 @@ export class ResetCommand extends GitCommand<Ref> {
225
771
  * @param targetId Commit to reset the working tree to
226
772
  * @param trackedBefore Paths tracked before staging was reset
227
773
  */
228
- private async resetWorkingTree(targetId: ObjectId, trackedBefore: Set<string>): Promise<void> {
774
+ private async resetWorkingTree(
775
+ targetId: ObjectId,
776
+ trackedBefore: Set<string>,
777
+ keptOut?: ReadonlySet<string>,
778
+ sparse?: SparseUnpack,
779
+ ): Promise<Set<string>> {
229
780
  const worktree = this.worktreeAccess;
230
781
  if (!worktree) {
231
782
  // Bare repository: there is no working tree to reset.
232
- return;
783
+ return new Set();
233
784
  }
234
785
 
235
786
  const commit = await this.commits.load(targetId);
236
787
  if (!commit) {
237
788
  throw new RefNotFoundError(targetId, "Target commit not found");
238
789
  }
239
-
240
- // Plan the whole restore first. Anything unrestorable then fails while the
241
- // working tree is still untouched, instead of half-way through rewriting it.
242
- const plan = await planTreeRestore(this.trees, this.blobs, commit.tree, RESET_HARD, {
243
- symlinks: true,
244
- ignoreCase: coreBool(this.workingCopy, "ignorecase", false),
245
- windows: worktree.capabilities?.windowsPaths === true,
246
- reservedNames: worktree.capabilities?.reservedNames,
247
- });
248
-
249
- // Delete the files that were tracked but are not in the target tree first, as git's
250
- // unpack-trees does: a tracked file or symlink `d` then makes way for `d/x`, and is
251
- // never written beneath or through.
252
- for (const path of trackedBefore) {
253
- if (plan.paths.has(path)) continue;
254
- await worktree.remove(path);
255
- }
256
-
257
- // a forced checkout: a file or link where a directory must go is unlinked, never
258
- // written through; links are written as links where the worktree has them
259
- await writeTreeRestorePlan(worktree, this.blobs, plan, RESET_HARD, {
260
- symlinks: worktreeModeTrust(this.workingCopy, worktree).symlinks,
261
- replaceInTheWay: true,
262
- });
790
+ return restoreWorktreeHard(
791
+ { trees: this.trees, blobs: this.blobs, workingCopy: this.workingCopy, worktree },
792
+ commit.tree,
793
+ trackedBefore,
794
+ keptOut,
795
+ sparse,
796
+ );
263
797
  }
264
798
 
265
799
  /**
@@ -268,38 +802,228 @@ export class ResetCommand extends GitCommand<Ref> {
268
802
  private async resetStaging(commitId: ObjectId): Promise<void> {
269
803
  const commit = await this.commits.load(commitId);
270
804
  if (commit) {
271
- await this.staging.readTree(this.trees, commit.tree);
805
+ if (this.mode !== ResetMode.MIXED) {
806
+ // oneway_merge: an unchanged entry keeps its flags, a changed one its skip-worktree
807
+ // bit (the stat data goes: every file is written again)
808
+ await this.staging.readTree(this.trees, commit.tree, { keepMatching: "flags" });
809
+ await this.primeCacheTree(commit.tree);
810
+ await this.staging.write();
811
+ return;
812
+ }
813
+ if (this.intentToAdd) {
814
+ // -N: the paths the commit lacks stay as intent-to-add entries
815
+ await this.readFromTree(commit.tree, []);
816
+ await this.staging.write();
817
+ return;
818
+ }
819
+ // git's reset --mixed edits the index in place (read_from_tree): the resolve-undo
820
+ // records stay, and the conflict stages it removes are recorded as well
821
+ const unmerged = new Map<string, ResolveUndoRecord>();
822
+ // read_from_tree edits the index entry by entry: the cache-tree keeps its nodes, those
823
+ // of the paths it changes invalid (not primed, as a hard reset's is)
824
+ const cached = this.staging.getCacheTree?.();
825
+ const before = new Map<string, string>();
826
+ for await (const entry of this.staging.entries()) {
827
+ before.set(
828
+ entry.path,
829
+ `${before.has(entry.path) ? "u" : ""}${entry.mode} ${entry.objectId}`,
830
+ );
831
+ if (entry.stage < 1 || entry.stage > 3) continue;
832
+ let record = unmerged.get(entry.path);
833
+ if (!record) {
834
+ record = {
835
+ path: entry.path,
836
+ modes: [0, 0, 0],
837
+ objectIds: [undefined, undefined, undefined],
838
+ };
839
+ unmerged.set(entry.path, record);
840
+ }
841
+ record.modes[entry.stage - 1] = entry.mode;
842
+ record.objectIds[entry.stage - 1] = entry.objectId;
843
+ }
844
+ // read_from_tree leaves the entries it does not change alone (their flags and stat), and
845
+ // a changed entry keeps its skip-worktree bit (update_index_from_diff)
846
+ await this.staging.readTree(this.trees, commit.tree, {
847
+ keepResolveUndo: true,
848
+ keepMatching: true,
849
+ });
850
+ if (unmerged.size > 0) this.staging.recordResolveUndo?.([...unmerged.values()]);
851
+ if (cached && this.staging.setCacheTree) {
852
+ const tree = copyCacheTree(cached);
853
+ for await (const entry of this.staging.entries()) {
854
+ if (before.get(entry.path) !== `${entry.mode} ${entry.objectId}`) {
855
+ invalidateCacheTreePath(tree, entry.path);
856
+ }
857
+ before.delete(entry.path);
858
+ }
859
+ for (const path of before.keys()) invalidateCacheTreePath(tree, path);
860
+ this.staging.setCacheTree(tree);
861
+ }
272
862
  await this.staging.write();
273
863
  }
274
864
  }
275
865
 
276
866
  /**
277
- * Get tree entry for a path.
867
+ * git's `prime_cache_tree` after a hard reset: the index's cache-tree is the
868
+ * target tree's, every directory valid with the tree stored there (a tree holding 100664
869
+ * modes is kept, so a write-tree of the unchanged index gives it back).
278
870
  */
279
- private async getTreeEntryForPath(
280
- treeId: ObjectId,
281
- path: string,
282
- ): Promise<{ objectId: ObjectId; mode: number } | undefined> {
283
- const parts = path.split("/").filter((p) => p.length > 0);
284
- let currentTreeId = treeId;
871
+ private async primeCacheTree(treeId: ObjectId): Promise<void> {
872
+ if (!this.staging.setCacheTree) return;
873
+ this.staging.setCacheTree(await cacheTreeOfTree(this.trees, treeId));
874
+ }
875
+ }
876
+
877
+ /**
878
+ * The working tree half of `git reset --hard` (unpack-trees `oneway_merge` with `update`):
879
+ * `treeId` written over the worktree, the paths of `trackedBefore` it lacks deleted first.
880
+ * Untracked files in the way are overwritten, as git's reset does. The restore is planned
881
+ * in full before any file is touched. In a sparse checkout (`sparse`) only the paths in its
882
+ * patterns are written, nothing that stays outside is removed, and the files leaving the
883
+ * checkout are unlinked first. Returns the paths written.
884
+ */
885
+ export async function restoreWorktreeHard(
886
+ deps: { trees: CommandTrees; blobs: Blobs; workingCopy: WorkingCopy; worktree: Worktree },
887
+ treeId: ObjectId,
888
+ trackedBefore: Set<string>,
889
+ keptOut?: ReadonlySet<string>,
890
+ sparse?: SparseUnpack,
891
+ ): Promise<Set<string>> {
892
+ const { trees, blobs, workingCopy, worktree } = deps;
893
+ // Plan the whole restore first. Anything unrestorable then fails while the
894
+ // working tree is still untouched, instead of half-way through rewriting it.
895
+ const fullPlan = await planTreeRestore(trees, blobs, treeId, RESET_HARD, {
896
+ symlinks: true,
897
+ ...(await restoreCaseOptions(worktree, coreBool(workingCopy, "ignorecase", false))),
898
+ windows: worktree.capabilities?.windowsPaths === true,
899
+ reservedNames: worktree.capabilities?.reservedNames,
900
+ });
901
+ // a skip-worktree entry the tree keeps is not checked out (oneway_merge skips it); in a
902
+ // sparse checkout, nothing outside its patterns is (apply_sparse_checkout), and an entry
903
+ // coming back into them is written
904
+ const skip = sparse
905
+ ? (path: string) => !sparse.writes(path)
906
+ : keptOut && keptOut.size > 0
907
+ ? (path: string) => keptOut.has(path)
908
+ : undefined;
909
+ const plan = skip
910
+ ? {
911
+ ...fullPlan,
912
+ entries: fullPlan.entries.filter((e) => !skip(e.path)),
913
+ gitlinks: fullPlan.gitlinks.filter((e) => !skip(e.path)),
914
+ }
915
+ : fullPlan;
285
916
 
286
- for (let i = 0; i < parts.length; i++) {
287
- const name = parts[i];
288
- const isLast = i === parts.length - 1;
917
+ if (sparse) {
918
+ // apply_sparse_checkout before check_updates: the files leaving the checkout
919
+ const result = new Map<string, { objectId: ObjectId; mode: number }>();
920
+ for (const e of fullPlan.entries) result.set(e.path, e);
921
+ for (const e of fullPlan.gitlinks) result.set(e.path, e);
922
+ const unlink = await sparse.leaving(worktree, (p) => result.get(p), {
923
+ reset: true,
924
+ trust: worktreeModeTrust(workingCopy, worktree),
925
+ });
926
+ await sparse.unlink(worktree, unlink);
927
+ }
289
928
 
290
- const entry = await this.trees.getEntry(currentTreeId, name);
929
+ // Delete the files that were tracked but are not in the target tree first, as git's
930
+ // unpack-trees does: a tracked file or symlink `d` then makes way for `d/x`, and is
931
+ // never written beneath or through; the directories left empty go too (unlink_entry's
932
+ // schedule_dir_for_removal). A skip-worktree entry staying outside a sparse checkout
933
+ // keeps its file.
934
+ for (const path of trackedBefore) {
935
+ if (plan.paths.has(path) || sparse?.leavesAlone(path)) continue;
936
+ await worktree.remove(path);
937
+ await pruneEmptyParents(worktree, path);
938
+ }
291
939
 
292
- if (!entry) {
293
- return undefined;
294
- }
940
+ // a forced checkout: a file or link where a directory must go is unlinked, never
941
+ // written through; links are written as links where the worktree has them
942
+ await writeTreeRestorePlan(worktree, blobs, plan, RESET_HARD, {
943
+ symlinks: worktreeModeTrust(workingCopy, worktree).symlinks,
944
+ replaceInTheWay: true,
945
+ // git's reset --hard overwrites untracked files (UNPACK_RESET_OVERWRITE_UNTRACKED)
946
+ discardUntracked: true,
947
+ });
948
+ return new Set([...plan.entries, ...plan.gitlinks].map((e) => e.path));
949
+ }
295
950
 
296
- if (isLast) {
297
- return { objectId: entry.id, mode: entry.mode };
298
- }
951
+ /**
952
+ * Records in the index the stat of the files a one-way reset just wrote (`paths`): git's
953
+ * `checkout_entry` fills each written entry's stat data in `check_updates`, so a following
954
+ * `diff-files` or sparse update finds them clean. Only stage-0 entries are touched, and the
955
+ * staging's own racy-git smudging still applies when the index is written. Not written here.
956
+ */
957
+ export async function recordWrittenStat(
958
+ staging: Staging,
959
+ worktree: Worktree,
960
+ paths: Iterable<string>,
961
+ ): Promise<void> {
962
+ const list = [...paths];
963
+ if (list.length === 0) return;
964
+ const found = await getWorktreeEntries(worktree, list);
965
+ const editor = staging.createEditor();
966
+ let edits = 0;
967
+ for (let i = 0; i < list.length; i++) {
968
+ const stat = found[i];
969
+ if (!stat || stat.isDirectory) continue;
970
+ edits++;
971
+ editor.add({
972
+ path: list[i] as string,
973
+ apply: (existing) =>
974
+ existing && existing.stage === 0 ? { ...existing, ...entryStatOf(stat) } : existing,
975
+ });
976
+ }
977
+ if (edits > 0) await editor.finish();
978
+ }
299
979
 
300
- currentTreeId = entry.id;
301
- }
980
+ /** What {@link checkFlaggedEntries} found. */
981
+ export interface FlaggedEntries {
982
+ /** The first path whose flagged entry the tree changes or deletes over a changed file. */
983
+ refused?: string;
984
+ /** The skip-worktree entries the tree keeps: their files are left alone. */
985
+ keptOut: Set<string>;
986
+ }
302
987
 
303
- return undefined;
988
+ /**
989
+ * The index entries whose flags cheat (assume-unchanged, skip-worktree) before a one-way
990
+ * reset onto `treeId` (`reset --hard`, `checkout -f`): unpack-trees checks them even when it
991
+ * resets (`verify_uptodate_1`: "CE_VALID and CE_SKIP_WORKTREE cheat"), so one the tree
992
+ * changes or deletes is refused while its file differs from it (by stat, as
993
+ * `ie_match_stat`; a missing file is fine). A skip-worktree entry the tree keeps is not
994
+ * checked out (`oneway_merge`).
995
+ */
996
+ export async function checkFlaggedEntries(
997
+ deps: {
998
+ trees: CommandTrees;
999
+ staging: Staging;
1000
+ workingCopy: WorkingCopy;
1001
+ worktree?: Worktree;
1002
+ },
1003
+ treeId: ObjectId,
1004
+ /** A sparse checkout's run: an entry that stays outside it is not checked (verify_uptodate) */
1005
+ sparse?: SparseUnpack,
1006
+ ): Promise<FlaggedEntries> {
1007
+ const flagged: StagingEntry[] = [];
1008
+ for await (const entry of deps.staging.entries()) {
1009
+ if (entry.stage === 0 && (entry.assumeValid || entry.skipWorktree)) flagged.push(entry);
1010
+ }
1011
+ const keptOut = new Set<string>();
1012
+ if (flagged.length === 0) return { keptOut };
1013
+ const target = await flatTree(deps.trees, treeId);
1014
+ const worktree = deps.worktree;
1015
+ const trust = worktree ? worktreeModeTrust(deps.workingCopy, worktree) : undefined;
1016
+ const indexTime = deps.staging.getUpdateTime();
1017
+ for (const entry of flagged) {
1018
+ if (sparse?.leavesAlone(entry.path)) continue;
1019
+ const t = target.get(entry.path);
1020
+ if (t && t.mode === entry.mode && t.objectId === entry.objectId) {
1021
+ if (entry.skipWorktree) keptOut.add(entry.path);
1022
+ continue;
1023
+ }
1024
+ if (worktree && (await flaggedEntryDiffers(worktree, entry.path, entry, trust, indexTime))) {
1025
+ return { refused: entry.path, keptOut };
1026
+ }
304
1027
  }
1028
+ return { keptOut };
305
1029
  }