@statewalker/vcs-commands 0.8.0 → 0.9.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 (297) hide show
  1. package/dist/commands/add-command.d.ts +32 -0
  2. package/dist/commands/add-command.d.ts.map +1 -1
  3. package/dist/commands/add-patch/add-patch.d.ts +7 -0
  4. package/dist/commands/add-patch/add-patch.d.ts.map +1 -1
  5. package/dist/commands/add-patch/patch-backend.d.ts.map +1 -1
  6. package/dist/commands/am/am-command.d.ts +47 -0
  7. package/dist/commands/am/am-command.d.ts.map +1 -1
  8. package/dist/commands/apply/apply-command.d.ts +2 -0
  9. package/dist/commands/apply/apply-command.d.ts.map +1 -1
  10. package/dist/commands/apply/apply-parse.d.ts +7 -0
  11. package/dist/commands/apply/apply-parse.d.ts.map +1 -1
  12. package/dist/commands/apply/index.d.ts +1 -1
  13. package/dist/commands/apply/index.d.ts.map +1 -1
  14. package/dist/commands/blame-command.d.ts +303 -8
  15. package/dist/commands/blame-command.d.ts.map +1 -1
  16. package/dist/commands/blame-ignore.d.ts +48 -0
  17. package/dist/commands/blame-ignore.d.ts.map +1 -0
  18. package/dist/commands/check-mailmap-command.d.ts +49 -0
  19. package/dist/commands/check-mailmap-command.d.ts.map +1 -0
  20. package/dist/commands/checkout-command.d.ts +7 -0
  21. package/dist/commands/checkout-command.d.ts.map +1 -1
  22. package/dist/commands/checkout-paths.d.ts +4 -0
  23. package/dist/commands/checkout-paths.d.ts.map +1 -1
  24. package/dist/commands/cherry-command.d.ts +61 -0
  25. package/dist/commands/cherry-command.d.ts.map +1 -0
  26. package/dist/commands/cherry-pick-command.d.ts +23 -1
  27. package/dist/commands/cherry-pick-command.d.ts.map +1 -1
  28. package/dist/commands/clean-command.d.ts +32 -0
  29. package/dist/commands/clean-command.d.ts.map +1 -1
  30. package/dist/commands/clean-interactive.d.ts +56 -0
  31. package/dist/commands/clean-interactive.d.ts.map +1 -0
  32. package/dist/commands/clone-command.d.ts +116 -2
  33. package/dist/commands/clone-command.d.ts.map +1 -1
  34. package/dist/commands/commit-command.d.ts +50 -2
  35. package/dist/commands/commit-command.d.ts.map +1 -1
  36. package/dist/commands/describe-command.d.ts +71 -64
  37. package/dist/commands/describe-command.d.ts.map +1 -1
  38. package/dist/commands/diff-command.d.ts +118 -6
  39. package/dist/commands/diff-command.d.ts.map +1 -1
  40. package/dist/commands/fetch-command.d.ts +60 -0
  41. package/dist/commands/fetch-command.d.ts.map +1 -1
  42. package/dist/commands/fetch-multiple-command.d.ts +193 -0
  43. package/dist/commands/fetch-multiple-command.d.ts.map +1 -0
  44. package/dist/commands/format-patch-command.d.ts +28 -2
  45. package/dist/commands/format-patch-command.d.ts.map +1 -1
  46. package/dist/commands/git-describe.d.ts +77 -4
  47. package/dist/commands/git-describe.d.ts.map +1 -1
  48. package/dist/commands/git-hooks.d.ts +15 -1
  49. package/dist/commands/git-hooks.d.ts.map +1 -1
  50. package/dist/commands/index.d.ts +12 -0
  51. package/dist/commands/index.d.ts.map +1 -1
  52. package/dist/commands/index.js +5 -3
  53. package/dist/commands/init-command.d.ts +89 -0
  54. package/dist/commands/init-command.d.ts.map +1 -1
  55. package/dist/commands/line-log.d.ts +161 -0
  56. package/dist/commands/line-log.d.ts.map +1 -0
  57. package/dist/commands/log-command.d.ts +235 -6
  58. package/dist/commands/log-command.d.ts.map +1 -1
  59. package/dist/commands/log-graph.d.ts +4 -2
  60. package/dist/commands/log-graph.d.ts.map +1 -1
  61. package/dist/commands/log-output.d.ts +66 -1
  62. package/dist/commands/log-output.d.ts.map +1 -1
  63. package/dist/commands/mailmap.d.ts +24 -1
  64. package/dist/commands/mailmap.d.ts.map +1 -1
  65. package/dist/commands/merge-command.d.ts +51 -1
  66. package/dist/commands/merge-command.d.ts.map +1 -1
  67. package/dist/commands/merge-drivers.d.ts +2 -0
  68. package/dist/commands/merge-drivers.d.ts.map +1 -1
  69. package/dist/commands/merge-strategy-options.d.ts +69 -0
  70. package/dist/commands/merge-strategy-options.d.ts.map +1 -0
  71. package/dist/commands/merge-support.d.ts +10 -0
  72. package/dist/commands/merge-support.d.ts.map +1 -1
  73. package/dist/commands/message-cleanup.d.ts +2 -0
  74. package/dist/commands/message-cleanup.d.ts.map +1 -1
  75. package/dist/commands/name-rev-command.d.ts +65 -0
  76. package/dist/commands/name-rev-command.d.ts.map +1 -0
  77. package/dist/commands/name-rev.d.ts +110 -22
  78. package/dist/commands/name-rev.d.ts.map +1 -1
  79. package/dist/commands/octopus-merge.d.ts +26 -1
  80. package/dist/commands/octopus-merge.d.ts.map +1 -1
  81. package/dist/commands/ort-merge.d.ts +16 -0
  82. package/dist/commands/ort-merge.d.ts.map +1 -1
  83. package/dist/commands/ort-recursive.d.ts.map +1 -1
  84. package/dist/commands/patch-id.d.ts +58 -0
  85. package/dist/commands/patch-id.d.ts.map +1 -1
  86. package/dist/commands/pull-command.d.ts +182 -38
  87. package/dist/commands/pull-command.d.ts.map +1 -1
  88. package/dist/commands/push-command.d.ts +65 -0
  89. package/dist/commands/push-command.d.ts.map +1 -1
  90. package/dist/commands/range-diff/index.d.ts +4 -0
  91. package/dist/commands/range-diff/index.d.ts.map +1 -0
  92. package/dist/commands/range-diff/linear-assignment.d.ts +27 -0
  93. package/dist/commands/range-diff/linear-assignment.d.ts.map +1 -0
  94. package/dist/commands/range-diff/range-diff-command.d.ts +121 -0
  95. package/dist/commands/range-diff/range-diff-command.d.ts.map +1 -0
  96. package/dist/commands/range-diff/range-diff.d.ts +106 -0
  97. package/dist/commands/range-diff/range-diff.d.ts.map +1 -0
  98. package/dist/commands/read-tree-command.d.ts +14 -0
  99. package/dist/commands/read-tree-command.d.ts.map +1 -1
  100. package/dist/commands/rebase-command.d.ts +21 -2
  101. package/dist/commands/rebase-command.d.ts.map +1 -1
  102. package/dist/commands/remerge-diff.d.ts +59 -0
  103. package/dist/commands/remerge-diff.d.ts.map +1 -0
  104. package/dist/commands/remote-command.d.ts +41 -0
  105. package/dist/commands/remote-command.d.ts.map +1 -1
  106. package/dist/commands/remote-show-command.d.ts +204 -0
  107. package/dist/commands/remote-show-command.d.ts.map +1 -0
  108. package/dist/commands/reset-command.d.ts +19 -1
  109. package/dist/commands/reset-command.d.ts.map +1 -1
  110. package/dist/commands/restore-command.d.ts +7 -0
  111. package/dist/commands/restore-command.d.ts.map +1 -1
  112. package/dist/commands/rev-list-command.d.ts +75 -3
  113. package/dist/commands/rev-list-command.d.ts.map +1 -1
  114. package/dist/commands/revert-command.d.ts +22 -1
  115. package/dist/commands/revert-command.d.ts.map +1 -1
  116. package/dist/commands/revision-range.d.ts +2 -0
  117. package/dist/commands/revision-range.d.ts.map +1 -1
  118. package/dist/commands/sequencer-pick.d.ts +102 -1
  119. package/dist/commands/sequencer-pick.d.ts.map +1 -1
  120. package/dist/commands/sequencer-support.d.ts +10 -1
  121. package/dist/commands/sequencer-support.d.ts.map +1 -1
  122. package/dist/commands/shortlog-command.d.ts +109 -0
  123. package/dist/commands/shortlog-command.d.ts.map +1 -0
  124. package/dist/commands/shortlog.d.ts +151 -0
  125. package/dist/commands/shortlog.d.ts.map +1 -0
  126. package/dist/commands/status-command.d.ts +31 -2
  127. package/dist/commands/status-command.d.ts.map +1 -1
  128. package/dist/commands/submodule-commands.d.ts +90 -2
  129. package/dist/commands/submodule-commands.d.ts.map +1 -1
  130. package/dist/commands/submodule-fetch.d.ts +149 -0
  131. package/dist/commands/submodule-fetch.d.ts.map +1 -0
  132. package/dist/commands/submodule-model.d.ts +8 -0
  133. package/dist/commands/submodule-model.d.ts.map +1 -1
  134. package/dist/commands/submodule-unpack.d.ts +120 -0
  135. package/dist/commands/submodule-unpack.d.ts.map +1 -0
  136. package/dist/commands/submodule-update-command.d.ts +8 -0
  137. package/dist/commands/submodule-update-command.d.ts.map +1 -1
  138. package/dist/commands/subtree-shift.d.ts +27 -0
  139. package/dist/commands/subtree-shift.d.ts.map +1 -0
  140. package/dist/commands/switch-command.d.ts +3 -0
  141. package/dist/commands/switch-command.d.ts.map +1 -1
  142. package/dist/commands/tree-restore.d.ts.map +1 -1
  143. package/dist/commands/worktree-overwrite-checks.d.ts +2 -0
  144. package/dist/commands/worktree-overwrite-checks.d.ts.map +1 -1
  145. package/dist/{commands-ISM52N0n.js → commands-CNvli5bl.js} +39426 -61169
  146. package/dist/errors/command-errors.d.ts +25 -0
  147. package/dist/errors/command-errors.d.ts.map +1 -1
  148. package/dist/errors/index.js +29 -1
  149. package/dist/fsck-CPeDh9fh.js +5138 -0
  150. package/dist/git-command.d.ts +31 -1
  151. package/dist/git-command.d.ts.map +1 -1
  152. package/dist/git.d.ts +97 -1
  153. package/dist/git.d.ts.map +1 -1
  154. package/dist/guarded-transport-command.d.ts +82 -0
  155. package/dist/guarded-transport-command.d.ts.map +1 -0
  156. package/dist/index.d.ts +1 -0
  157. package/dist/index.d.ts.map +1 -1
  158. package/dist/index.js +6 -5
  159. package/dist/remote-transport-CCmBadm-.js +1606 -0
  160. package/dist/rename/detect-renames.d.ts +20 -0
  161. package/dist/rename/detect-renames.d.ts.map +1 -1
  162. package/dist/rename/diffcore-break.d.ts +51 -0
  163. package/dist/rename/diffcore-break.d.ts.map +1 -0
  164. package/dist/rename/index.d.ts +1 -0
  165. package/dist/rename/index.d.ts.map +1 -1
  166. package/dist/results/blame-format.d.ts +62 -1
  167. package/dist/results/blame-format.d.ts.map +1 -1
  168. package/dist/results/clone-result.d.ts +9 -0
  169. package/dist/results/clone-result.d.ts.map +1 -1
  170. package/dist/results/diff-dirstat.d.ts +36 -0
  171. package/dist/results/diff-dirstat.d.ts.map +1 -0
  172. package/dist/results/diff-entry.d.ts +10 -0
  173. package/dist/results/diff-entry.d.ts.map +1 -1
  174. package/dist/results/diff-formatter.d.ts.map +1 -1
  175. package/dist/results/diff-output.d.ts +18 -0
  176. package/dist/results/diff-output.d.ts.map +1 -1
  177. package/dist/results/fetch-result.d.ts +12 -1
  178. package/dist/results/fetch-result.d.ts.map +1 -1
  179. package/dist/results/index.d.ts +2 -0
  180. package/dist/results/index.d.ts.map +1 -1
  181. package/dist/results/index.js +2 -2
  182. package/dist/results/init-result.d.ts +8 -1
  183. package/dist/results/init-result.d.ts.map +1 -1
  184. package/dist/results/line-range-hunks.d.ts +27 -0
  185. package/dist/results/line-range-hunks.d.ts.map +1 -0
  186. package/dist/results/merge-result.d.ts +8 -1
  187. package/dist/results/merge-result.d.ts.map +1 -1
  188. package/dist/results/pull-result.d.ts +11 -0
  189. package/dist/results/pull-result.d.ts.map +1 -1
  190. package/dist/results/push-result.d.ts +5 -0
  191. package/dist/results/push-result.d.ts.map +1 -1
  192. package/dist/results/status-result.d.ts +1 -1
  193. package/dist/results/status-result.d.ts.map +1 -1
  194. package/dist/results-BDuEgdLU.js +46847 -0
  195. package/dist/transport-command.d.ts +14 -0
  196. package/dist/transport-command.d.ts.map +1 -1
  197. package/package.json +12 -12
  198. package/src/commands/add-command.ts +115 -0
  199. package/src/commands/add-patch/add-patch.ts +8 -0
  200. package/src/commands/add-patch/patch-backend.ts +20 -2
  201. package/src/commands/am/am-command.ts +138 -4
  202. package/src/commands/apply/apply-command.ts +52 -9
  203. package/src/commands/apply/apply-parse.ts +10 -0
  204. package/src/commands/apply/index.ts +8 -1
  205. package/src/commands/blame-command.ts +1450 -51
  206. package/src/commands/blame-ignore.ts +307 -0
  207. package/src/commands/check-mailmap-command.ts +129 -0
  208. package/src/commands/checkout-command.ts +97 -12
  209. package/src/commands/checkout-paths.ts +28 -0
  210. package/src/commands/cherry-command.ts +187 -0
  211. package/src/commands/cherry-pick-command.ts +42 -1
  212. package/src/commands/clean-command.ts +92 -12
  213. package/src/commands/clean-interactive.ts +522 -0
  214. package/src/commands/clone-command.ts +596 -44
  215. package/src/commands/commit-command.ts +180 -47
  216. package/src/commands/describe-command.ts +341 -254
  217. package/src/commands/diff-command.ts +616 -56
  218. package/src/commands/fetch-command.ts +353 -6
  219. package/src/commands/fetch-multiple-command.ts +665 -0
  220. package/src/commands/format-patch-command.ts +189 -77
  221. package/src/commands/git-describe.ts +456 -217
  222. package/src/commands/git-hooks.ts +42 -3
  223. package/src/commands/index.ts +17 -0
  224. package/src/commands/init-command.ts +603 -49
  225. package/src/commands/line-log.ts +931 -0
  226. package/src/commands/log-command.ts +1414 -177
  227. package/src/commands/log-graph.ts +6 -3
  228. package/src/commands/log-output.ts +173 -10
  229. package/src/commands/mailmap.ts +41 -5
  230. package/src/commands/merge-command.ts +274 -16
  231. package/src/commands/merge-drivers.ts +3 -0
  232. package/src/commands/merge-strategy-options.ts +224 -0
  233. package/src/commands/merge-support.ts +101 -21
  234. package/src/commands/message-cleanup.ts +1 -1
  235. package/src/commands/name-rev-command.ts +184 -0
  236. package/src/commands/name-rev.ts +700 -109
  237. package/src/commands/octopus-merge.ts +35 -11
  238. package/src/commands/ort-merge.ts +41 -7
  239. package/src/commands/ort-recursive.ts +40 -2
  240. package/src/commands/patch-id.ts +109 -0
  241. package/src/commands/pull-command.ts +718 -224
  242. package/src/commands/push-command.ts +353 -3
  243. package/src/commands/range-diff/index.ts +3 -0
  244. package/src/commands/range-diff/linear-assignment.ts +203 -0
  245. package/src/commands/range-diff/range-diff-command.ts +433 -0
  246. package/src/commands/range-diff/range-diff.ts +617 -0
  247. package/src/commands/read-tree-command.ts +74 -3
  248. package/src/commands/rebase-command.ts +141 -65
  249. package/src/commands/remerge-diff.ts +241 -0
  250. package/src/commands/remote-command.ts +98 -10
  251. package/src/commands/remote-show-command.ts +836 -0
  252. package/src/commands/reset-command.ts +78 -3
  253. package/src/commands/restore-command.ts +15 -0
  254. package/src/commands/rev-list-command.ts +187 -11
  255. package/src/commands/revert-command.ts +41 -1
  256. package/src/commands/revision-range.ts +3 -1
  257. package/src/commands/sequencer-pick.ts +323 -29
  258. package/src/commands/sequencer-support.ts +164 -2
  259. package/src/commands/shortlog-command.ts +354 -0
  260. package/src/commands/shortlog.ts +361 -0
  261. package/src/commands/show-command.ts +2 -1
  262. package/src/commands/status-command.ts +115 -25
  263. package/src/commands/status-format.ts +1 -1
  264. package/src/commands/submodule-commands.ts +321 -3
  265. package/src/commands/submodule-fetch.ts +789 -0
  266. package/src/commands/submodule-model.ts +9 -1
  267. package/src/commands/submodule-unpack.ts +265 -0
  268. package/src/commands/submodule-update-command.ts +39 -5
  269. package/src/commands/subtree-shift.ts +215 -0
  270. package/src/commands/switch-command.ts +9 -0
  271. package/src/commands/tree-restore.ts +6 -1
  272. package/src/commands/worktree-overwrite-checks.ts +5 -0
  273. package/src/errors/command-errors.ts +35 -0
  274. package/src/git-command.ts +87 -1
  275. package/src/git.ts +146 -0
  276. package/src/guarded-transport-command.ts +171 -0
  277. package/src/index.ts +1 -0
  278. package/src/rename/detect-renames.ts +42 -8
  279. package/src/rename/diffcore-break.ts +166 -0
  280. package/src/rename/index.ts +1 -0
  281. package/src/results/blame-format.ts +268 -43
  282. package/src/results/clone-result.ts +6 -0
  283. package/src/results/diff-dirstat.ts +117 -0
  284. package/src/results/diff-entry.ts +12 -0
  285. package/src/results/diff-formatter.ts +1 -0
  286. package/src/results/diff-output.ts +127 -2
  287. package/src/results/fetch-result.ts +12 -1
  288. package/src/results/index.ts +2 -0
  289. package/src/results/init-result.ts +10 -1
  290. package/src/results/line-range-hunks.ts +126 -0
  291. package/src/results/merge-result.ts +9 -0
  292. package/src/results/pull-result.ts +7 -0
  293. package/src/results/push-result.ts +5 -0
  294. package/src/results/status-result.ts +2 -2
  295. package/src/transport-command.ts +34 -3
  296. package/dist/fsck-DLRpbwTj.js +0 -13405
  297. package/dist/results-TB2IJ64h.js +0 -4700
@@ -33,6 +33,15 @@ import {
33
33
  import { GitCommand } from "../git-command.js";
34
34
  import { RemoteConfigStore } from "../remote-config/index.js";
35
35
  import { AddCommand } from "./add-command.js";
36
+ import {
37
+ type PatchCompatibility,
38
+ type PatchOptions,
39
+ type PatchResult,
40
+ type PatchSelector,
41
+ patchModeFor,
42
+ runPatchSelection,
43
+ type TemporaryIndex,
44
+ } from "./add-patch/index.js";
36
45
  import {
37
46
  amendCommitText,
38
47
  autosquashSubject,
@@ -54,10 +63,10 @@ import {
54
63
  } from "./git-ident.js";
55
64
  import { IndexAdder, readGitlinkHead } from "./index-adder.js";
56
65
  import { reencodedCommitParts } from "./log-output.js";
57
- import { readRepositoryMailmap } from "./mailmap.js";
58
66
  import {
59
67
  flatTree,
60
68
  OperationState,
69
+ rewriteIndex,
61
70
  updateIndexCacheTree,
62
71
  writeIndexAsTree,
63
72
  } from "./merge-support.js";
@@ -163,6 +172,8 @@ export interface CommitResult extends Commit {
163
172
  * ```
164
173
  */
165
174
  export class CommitCommand extends GitCommand<CommitResult> {
175
+ /** git's `error:` lines that do not stop the commit ({@link getWarnings}) */
176
+ private readonly stderrLines: string[] = [];
166
177
  private message?: string;
167
178
  private author?: PersonIdent;
168
179
  private committer?: PersonIdent;
@@ -215,6 +226,12 @@ export class CommitCommand extends GitCommand<CommitResult> {
215
226
  private squashFrom?: string;
216
227
  /** --fixup, parsed when the commit runs */
217
228
  private fixup?: { kind: FixupKind; target: string };
229
+ /** `-p` / `--patch` */
230
+ private patch = false;
231
+ private patchSelector?: PatchSelector;
232
+ private patchOptions: PatchOptions = {};
233
+ private patchCompatibility: PatchCompatibility = "2.56";
234
+ private patchResult?: PatchResult;
218
235
 
219
236
  /**
220
237
  * Set the commit message, as git's `commit -m` takes it: its last line is ended and it is
@@ -535,6 +552,59 @@ export class CommitCommand extends GitCommand<CommitResult> {
535
552
  return this;
536
553
  }
537
554
 
555
+ /**
556
+ * `git commit -p` (`--patch`): the changes between the index and the worktree are offered
557
+ * hunk by hunk as `git add -p` offers them, and the selected hunks are committed along
558
+ * with what is staged already. As git's prepare_index for `--interactive`: the index lock
559
+ * is taken and the refreshed index written into it, the hunks are applied to that
560
+ * temporary index (`GIT_INDEX_FILE` at the lock), and the commit is made from it; the lock
561
+ * becomes the index once HEAD has moved, and on any failure (nothing selected: "no changes
562
+ * added to commit") the index stays as it was. The paths of {@link setOnly} limit the
563
+ * hunks offered. The prompts are answered by {@link setPatchSelector}; what patch mode
564
+ * printed is {@link getPatchResult}'s. Refused with {@link setAll} and
565
+ * {@link setInclude}.
566
+ *
567
+ * @example
568
+ * ```typescript
569
+ * const answers = ["y", "n"];
570
+ * const commit = git.commit().setMessage("Part").setPatch(true)
571
+ * .setPatchSelector(() => answers.shift());
572
+ * await commit.call();
573
+ * process.stdout.write(commit.getPatchResult()?.output ?? "");
574
+ * ```
575
+ */
576
+ setPatch(patch: boolean): this {
577
+ this.checkCallable();
578
+ this.patch = patch;
579
+ return this;
580
+ }
581
+
582
+ /** Answers the prompts of {@link setPatch} (git's reads from standard input and its editor). */
583
+ setPatchSelector(selector: PatchSelector): this {
584
+ this.checkCallable();
585
+ this.patchSelector = selector;
586
+ return this;
587
+ }
588
+
589
+ /** `-U<n>` and `--inter-hunk-context=<n>` of {@link setPatch}. */
590
+ setPatchOptions(options: PatchOptions): this {
591
+ this.checkCallable();
592
+ this.patchOptions = { ...options };
593
+ return this;
594
+ }
595
+
596
+ /** The git version whose patch-mode prompts {@link setPatch} reproduces (default 2.56). */
597
+ setCompatibility(version: PatchCompatibility): this {
598
+ this.checkCallable();
599
+ this.patchCompatibility = version;
600
+ return this;
601
+ }
602
+
603
+ /** What {@link setPatch}'s selection printed and applied; read after {@link call}. */
604
+ getPatchResult(): PatchResult | undefined {
605
+ return this.patchResult;
606
+ }
607
+
538
608
  /**
539
609
  * Set whether to auto-stage modified tracked files before committing.
540
610
  *
@@ -1258,6 +1328,7 @@ export class CommitCommand extends GitCommand<CommitResult> {
1258
1328
  // the index as it is now: one another writer replaced is read again (git reads the
1259
1329
  // index at its start), unless this instance holds unwritten edits (refused)
1260
1330
  await this.readCurrentIndex();
1331
+ if (this.patch) return this.commitPatch();
1261
1332
  this.applyPathspecFile();
1262
1333
  if (this.include) return this.commitIncluded();
1263
1334
  // `--fixup=reword:` is a partial commit of no path: HEAD's tree (git sets `only`)
@@ -1279,6 +1350,85 @@ export class CommitCommand extends GitCommand<CommitResult> {
1279
1350
  }
1280
1351
  }
1281
1352
 
1353
+ /**
1354
+ * `-p` (git's prepare_index for `interactive`): the option checks, then the index lock held
1355
+ * and the hunks selected into the index it holds (`interactive_add` with `GIT_INDEX_FILE`
1356
+ * at the lock), then the commit from it.
1357
+ */
1358
+ private async commitPatch(): Promise<CommitResult> {
1359
+ // parse_and_validate_options: -i, -o, -a and --interactive/-p exclude each other
1360
+ if (this.include || this.all) {
1361
+ const other = this.include ? "-i/--include" : "-a/--all";
1362
+ throw new IncompatibleOptionsError(
1363
+ [other, "--interactive/-p/--patch"],
1364
+ `fatal: options '${other}' and '--interactive/-p/--patch' cannot be used together`,
1365
+ );
1366
+ }
1367
+ if (this.pathspecFile.given) {
1368
+ throw new IncompatibleOptionsError(
1369
+ ["--pathspec-from-file", "--interactive/--patch"],
1370
+ "fatal: options '--pathspec-from-file' and '--interactive/--patch' cannot be used together",
1371
+ );
1372
+ }
1373
+ const index = await this.holdIndex();
1374
+ try {
1375
+ // refresh_cache_or_die: an unmerged entry dies before anything is asked
1376
+ if (await this.staging.hasConflicts())
1377
+ throw unmergedPathsError(await this.staging.getConflictedPaths());
1378
+ const temporary: TemporaryIndex = new Map();
1379
+ const entries = new Map<string, StagingEntry>();
1380
+ for await (const entry of this.staging.entries()) {
1381
+ if (entry.stage !== 0) continue;
1382
+ entries.set(entry.path, entry);
1383
+ const { path: _p, mode, objectId, stage: _s, ...carried } = entry;
1384
+ temporary.set(entry.path, { mode, objectId, carried });
1385
+ }
1386
+ this.patchResult = await runPatchSelection(this.workingCopy, {
1387
+ hookSource: this,
1388
+ ...this.patchOptions,
1389
+ mode: patchModeFor("add"),
1390
+ selector: this.patchSelector,
1391
+ paths: this.onlyPaths,
1392
+ compatibility: this.patchCompatibility,
1393
+ temporaryIndex: temporary,
1394
+ });
1395
+ // the temporary index read back into the held index: entries apply rewrote (no stat
1396
+ // data, as `apply --cached` writes them), and the paths it removed
1397
+ const changes = new Map<string, StagingEntry[]>();
1398
+ for (const [path, entry] of temporary) {
1399
+ const old = entries.get(path);
1400
+ // an entry apply rewrote with the same blob (an empty intent-to-add file staged)
1401
+ // loses its intent-to-add flag, so it is no longer the entry it was
1402
+ if (
1403
+ old &&
1404
+ old.mode === entry.mode &&
1405
+ old.objectId === entry.objectId &&
1406
+ !!old.intentToAdd === !!entry.carried?.intentToAdd
1407
+ ) {
1408
+ continue;
1409
+ }
1410
+ changes.set(path, [
1411
+ {
1412
+ path,
1413
+ mode: entry.mode,
1414
+ objectId: entry.objectId,
1415
+ stage: 0,
1416
+ size: 0,
1417
+ mtime: 0,
1418
+ } as StagingEntry,
1419
+ ]);
1420
+ }
1421
+ for (const path of entries.keys()) if (!temporary.has(path)) changes.set(path, []);
1422
+ if (changes.size > 0) {
1423
+ await rewriteIndex(this.staging, changes, { upToDate: false, write: false });
1424
+ }
1425
+ return await this.withOneIndexWrite("first", () => this.commitWith(false, index));
1426
+ } catch (error) {
1427
+ await index.release();
1428
+ throw error;
1429
+ }
1430
+ }
1431
+
1282
1432
  /**
1283
1433
  * `-i <paths>` (git's prepare_index for `also`): the option checks of
1284
1434
  * parse_and_validate_options and prepare_index, then the index lock held from before the
@@ -1328,29 +1478,6 @@ export class CommitCommand extends GitCommand<CommitResult> {
1328
1478
  if (this.forceDate) this.forcedDate();
1329
1479
  }
1330
1480
 
1331
- /** A blob's bytes, undefined when it cannot be read. */
1332
- private async readBlobBytes(id: ObjectId): Promise<Uint8Array | undefined> {
1333
- try {
1334
- const content = await this.blobs.load(id);
1335
- if (!content) return undefined;
1336
- const chunks: Uint8Array[] = [];
1337
- let size = 0;
1338
- for await (const c of content) {
1339
- chunks.push(c);
1340
- size += c.length;
1341
- }
1342
- const out = new Uint8Array(size);
1343
- let at = 0;
1344
- for (const c of chunks) {
1345
- out.set(c, at);
1346
- at += c.length;
1347
- }
1348
- return out;
1349
- } catch {
1350
- return undefined;
1351
- }
1352
- }
1353
-
1354
1481
  /**
1355
1482
  * `--date` (parse_force_date): the date as `parse_date` reads it, else as `approxidate`
1356
1483
  * does, refused as git refuses it.
@@ -1367,6 +1494,14 @@ export class CommitCommand extends GitCommand<CommitResult> {
1367
1494
  return date;
1368
1495
  }
1369
1496
 
1497
+ /**
1498
+ * git's `error:` lines that did not stop the command (the mailmap's, read for an
1499
+ * `--author` that is no `Name <email>`), in order; also after a failure.
1500
+ */
1501
+ getWarnings(): string[] {
1502
+ return [...this.stderrLines];
1503
+ }
1504
+
1370
1505
  /**
1371
1506
  * builtin/commit.c's find_author_by_nickname: the first commit of `rev-list --all -i
1372
1507
  * --author=<name>` (newest first, the mailmap applied before matching) gives `%aN <%aE>`.
@@ -1382,18 +1517,10 @@ export class CommitCommand extends GitCommand<CommitResult> {
1382
1517
  `fatal: '${name}': ${error instanceof Error ? error.message : String(error)}`,
1383
1518
  );
1384
1519
  }
1385
- const config = RemoteConfigStore.from(this.workingCopy);
1386
- const mailmap = await readRepositoryMailmap({
1387
- config: (key) => config.value(key),
1388
- worktree: this.worktreeAccess,
1389
- environment: hostEnvironmentOf(this.workingCopy),
1390
- readBlobNamed: async (blob) => {
1391
- const id = await this.revisionResolver()
1392
- .resolve(blob)
1393
- .catch(() => undefined);
1394
- return id ? this.readBlobBytes(id) : undefined;
1395
- },
1396
- });
1520
+ // rev.mailmap's read; pretty.c reads it again for the `%aN <%aE>` of the match
1521
+ const mailmapErrors: string[] = [];
1522
+ const mailmap = await this.readMailmap((line) => mailmapErrors.push(line));
1523
+ this.stderrLines.push(...mailmapErrors);
1397
1524
  const encoder = new TextEncoder();
1398
1525
  // revision.c's walk of --all: refs under refs/ in name order, then HEAD, tags peeled;
1399
1526
  // commits come out by commit date, newest first
@@ -1437,6 +1564,7 @@ export class CommitCommand extends GitCommand<CommitResult> {
1437
1564
  if (!next) break;
1438
1565
  const who = mailmap.map(next.commit.author.name, next.commit.author.email);
1439
1566
  if (pattern.test(encoder.encode(`${who.name} <${who.email}>`))) {
1567
+ this.stderrLines.push(...mailmapErrors);
1440
1568
  return `${who.name} <${who.email}>`;
1441
1569
  }
1442
1570
  for (const parent of next.commit.parents) await put(parent);
@@ -1517,7 +1645,8 @@ export class CommitCommand extends GitCommand<CommitResult> {
1517
1645
  `fatal: reword option of '--fixup' and path '${path}' cannot be used together`,
1518
1646
  );
1519
1647
  }
1520
- if (this.all || this.include) {
1648
+ // check_fixup_reword_options: patch_interactive || interactive || all || also || only
1649
+ if (this.all || this.include || this.patch) {
1521
1650
  throw new IncompatibleOptionsError(
1522
1651
  ["--fixup", "--all"],
1523
1652
  "fatal: reword option of '--fixup' and '--patch/--interactive/--all/--include/--only' cannot be used together",
@@ -1668,16 +1797,7 @@ export class CommitCommand extends GitCommand<CommitResult> {
1668
1797
  // Check for conflicts (a partial commit records HEAD and the named paths: other
1669
1798
  // unmerged paths stay in the index, as git's)
1670
1799
  if (!partial && (await this.staging.hasConflicts())) {
1671
- const conflictPaths = await this.staging.getConflictedPaths();
1672
- throw new UnmergedPathsError(
1673
- conflictPaths,
1674
- [
1675
- "error: Committing is not possible because you have unmerged files.",
1676
- "hint: Fix them up in the work tree, and then use 'git add/rm <file>'",
1677
- "hint: as appropriate to mark resolution and make a commit.",
1678
- "fatal: Exiting because of an unresolved conflict.",
1679
- ].join("\n"),
1680
- );
1800
+ throw unmergedPathsError(await this.staging.getConflictedPaths());
1681
1801
  }
1682
1802
 
1683
1803
  // a merge, cherry-pick or revert in progress (git's whence: MERGE_HEAD,
@@ -2719,6 +2839,19 @@ export class CommitCommand extends GitCommand<CommitResult> {
2719
2839
  }
2720
2840
  }
2721
2841
 
2842
+ /** git's `die_resolve_conflict("commit")`. */
2843
+ function unmergedPathsError(paths: string[]): UnmergedPathsError {
2844
+ return new UnmergedPathsError(
2845
+ paths,
2846
+ [
2847
+ "error: Committing is not possible because you have unmerged files.",
2848
+ "hint: Fix them up in the work tree, and then use 'git add/rm <file>'",
2849
+ "hint: as appropriate to mark resolution and make a commit.",
2850
+ "fatal: Exiting because of an unresolved conflict.",
2851
+ ].join("\n"),
2852
+ );
2853
+ }
2854
+
2722
2855
  /** git's "paths '<first> ...' with -a does not make sense". */
2723
2856
  function pathsWithAllError(paths: readonly string[]): IncompatibleOptionsError {
2724
2857
  return new IncompatibleOptionsError(