@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
@@ -28,13 +28,17 @@ import { authorIdentOf, committerIdentOf } from "./git-ident.js";
28
28
  import { UNMERGED_FILES_MESSAGE } from "./merge-command.js";
29
29
  import { conflictStyleOf } from "./merge-config.js";
30
30
  import { ortConfigOptions } from "./merge-drivers.js";
31
+ import { parseStrategyOptions, strategyOrtOptions } from "./merge-strategy-options.js";
31
32
  import {
32
33
  conflictsComment,
33
34
  FlatTreeCache,
35
+ flatTree,
36
+ indexChanges,
34
37
  indexChangesFromTree,
35
38
  type MergeWriteContext,
36
39
  type OperationState,
37
40
  readIndex,
41
+ storeFlatTree,
38
42
  storeFlatTreeOver,
39
43
  subjectOf,
40
44
  switchTrees,
@@ -42,7 +46,8 @@ import {
42
46
  writeIndexAsTree,
43
47
  } from "./merge-support.js";
44
48
  import { stripspace } from "./message-cleanup.js";
45
- import { ortResultEntries } from "./ort-merge.js";
49
+ import { octopusMerge } from "./octopus-merge.js";
50
+ import { type OrtConflict, ortResultEntries } from "./ort-merge.js";
46
51
  import { mergeStoredTrees, storedBase } from "./ort-recursive.js";
47
52
  import { reflogLine, reflogMessages, updateHead } from "./reflog-messages.js";
48
53
  import {
@@ -53,6 +58,7 @@ import {
53
58
  } from "./sequencer-support.js";
54
59
  import { SigningFailedError, type SignRequest, signCommit, signRequestOf } from "./signing.js";
55
60
  import { appendSignoff, signoffLine, trailerConfigOf, trailerLinesOf } from "./trailers.js";
61
+ import type { CheckedEntry } from "./worktree-overwrite-checks.js";
56
62
 
57
63
  /** What the sequencer does with each commit. */
58
64
  export type PickAction = "pick" | "revert";
@@ -117,6 +123,16 @@ export interface PickOptions {
117
123
  noCommit?: boolean;
118
124
  mainline?: number;
119
125
  favor?: "ours" | "theirs" | "union";
126
+ /**
127
+ * `-s <strategy>` (git's opts->strategy): `ort`/`recursive` (merge-ort, as without one),
128
+ * `resolve` (git-merge-resolve) or `subtree` (git merge-subtree); a revert always runs
129
+ * merge-ort. Saved in `sequencer/opts` (`options.strategy`).
130
+ */
131
+ strategy?: string;
132
+ /** `-X <option>`s (saved in `sequencer/opts` as `options.strategy-option`) */
133
+ strategyOptions?: string[];
134
+ /** The git version to follow where they differ (default: the hook runner's) */
135
+ compatibility?: "2.43" | "2.56";
120
136
  /** The label of HEAD in conflict markers (default `HEAD`) */
121
137
  oursLabel?: string;
122
138
  /**
@@ -276,6 +292,10 @@ export class PickSequencer {
276
292
  private readonly flags: PickFlags;
277
293
  /** commit.cleanup (git's default_msg_cleanup with explicit_cleanup), or saved in the opts */
278
294
  private cleanup: SequencerCleanup | undefined;
295
+ /** `-s` (git's opts->strategy), or saved in the opts */
296
+ private strategy: string | undefined;
297
+ /** `-X` options (git's opts->xopts), or saved in the opts */
298
+ private xopts: string[];
279
299
 
280
300
  constructor(
281
301
  private readonly deps: SequencerDeps,
@@ -299,6 +319,13 @@ export class PickSequencer {
299
319
  allowFf: !!options.allowFf,
300
320
  };
301
321
  this.cleanup = configuredCleanup(deps.workingCopy);
322
+ this.strategy = options.strategy;
323
+ this.xopts = [...(options.strategyOptions ?? [])];
324
+ }
325
+
326
+ /** The git version to follow where they differ */
327
+ private get compatibility(): "2.43" | "2.56" {
328
+ return this.options.compatibility ?? this.deps.hooks?.compatibility ?? "2.56";
302
329
  }
303
330
 
304
331
  private config(key: string): string | undefined {
@@ -371,7 +398,11 @@ export class PickSequencer {
371
398
  flag("record-origin", f.recordOrigin);
372
399
  flag("allow-ff", f.allowFf);
373
400
  if (f.mainline) opts.push(`\tmainline = ${f.mainline}\n`);
374
- if (this.sign !== undefined) opts.push(`\tgpg-sign = ${this.sign}\n`);
401
+ if (this.strategy) opts.push(`\tstrategy = ${configValueText(this.strategy)}\n`);
402
+ if (this.sign !== undefined) {
403
+ opts.push(`\tgpg-sign = ${configValueText(String(this.sign))}\n`);
404
+ }
405
+ for (const x of this.xopts) opts.push(`\tstrategy-option = ${configValueText(x)}\n`);
375
406
  if (this.cleanup) opts.push(`\tdefault-msg-cleanup = ${this.cleanup}\n`);
376
407
  if (opts.length > 0) await state.write("sequencer/opts", `[options]\n${opts.join("")}`);
377
408
  }
@@ -423,6 +454,21 @@ export class PickSequencer {
423
454
  return { status: "ok", newHead, picked, output };
424
455
  }
425
456
 
457
+ /** The merge of a pick: {@link mergePickChange} with this run's strategy and options. */
458
+ private mergePick(p: Omit<PickMergeArgs, "strategy" | "xopts" | "oursLabel" | "favor">) {
459
+ return mergePickChange(
460
+ { ...this.deps, flats: this.flats, abbreviate: (id) => this.abbreviator.abbreviate(id) },
461
+ {
462
+ ...p,
463
+ strategy: this.strategy,
464
+ xopts: this.xopts,
465
+ oursLabel: this.options.oursLabel ?? "HEAD",
466
+ favor: this.options.favor,
467
+ compatibility: this.compatibility,
468
+ },
469
+ );
470
+ }
471
+
426
472
  /** One commit's change merged into HEAD (do_pick_commit). */
427
473
  private async pickOne(item: TodoItem, output: string[]): Promise<PickOutcome> {
428
474
  const { deps, flags } = this;
@@ -487,49 +533,60 @@ export class PickSequencer {
487
533
  action === "pick"
488
534
  ? [parentTreeId, commit.tree, parentLabel, label]
489
535
  : [commit.tree, parentTreeId, label, parentLabel];
490
- const flats = this.flats;
491
- const merge = await mergeStoredTrees(
492
- deps,
493
- storedBase(base, baseLabel, () => flats.get(base)),
536
+ const merged = await this.mergePick({
537
+ action,
538
+ headId,
494
539
  headTreeId,
540
+ base,
495
541
  theirs,
496
- {
497
- oursLabel: this.options.oursLabel ?? "HEAD",
498
- theirsLabel,
499
- baseLabel,
500
- style: conflictStyleOf(deps.workingCopy),
501
- favor: this.options.favor,
502
- ignoreCase: coreBool(deps.workingCopy, "ignorecase", false),
503
- ...ortConfigOptions(deps.workingCopy, deps.worktree),
504
- },
505
- (id) => flats.get(id),
506
- );
507
- const target = await ortResultEntries(deps.blobs, merge);
508
- // only the directories the pick changes are stored again
509
- const treeId = await storeFlatTreeOver(deps.trees, headTreeId, merge.ours, target);
510
- const conflicts = [...merge.conflicts.values()];
542
+ baseLabel,
543
+ theirsLabel,
544
+ pickId: item.id,
545
+ parentId,
546
+ });
547
+ if ("failed" in merged) {
548
+ if (!merged.strategyFailed) return this.fail(merged.failed, merged.output ?? []);
549
+ // do_pick_commit wrote MERGE_MSG before running the strategy; no CHERRY_PICK_HEAD
550
+ await deps.state.write("MERGE_MSG", await this.messageFor(action, item.id, commit, parentId));
551
+ const short = await this.abbreviator.abbreviate(item.id);
552
+ const verb = action === "pick" ? "apply" : "revert";
553
+ const lines = [
554
+ ...(merged.failed ? [merged.failed] : []),
555
+ `error: could not ${verb} ${short}... ${subjectOf(commit.message)}`,
556
+ // git 2.43's sequencer returns the error without dying
557
+ ...(this.compatibility === "2.43" ? [] : [`fatal: ${name} failed`]),
558
+ ];
559
+ return this.fail(lines.join("\n"), merged.output ?? []);
560
+ }
561
+ const { treeId, conflicts, clean } = merged;
511
562
  // only the paths HEAD and the result differ on are switched
512
- const delta = await treeDelta(deps.trees, headTreeId, treeId);
563
+ const delta = merged.delta ?? (await treeDelta(deps.trees, headTreeId, treeId));
513
564
  const refused = await switchTrees(deps, delta.from, delta.to, {
514
565
  action: "merge",
515
566
  operation: name,
516
567
  conflicts,
517
- targetTree: treeId,
568
+ ...(merged.delta ? {} : { targetTree: treeId }),
518
569
  });
519
570
  if (refused) {
520
- return this.fail(`${refused.message}\nfatal: ${name} failed`);
571
+ return this.fail(`${refused.message}\nfatal: ${name} failed`, merged.refusedOutput ?? []);
521
572
  }
522
- output.push(...merge.messages);
523
- await deps.state.setRef("AUTO_MERGE", treeId);
573
+ output.push(...merged.messages);
574
+ // merge-ort records its result tree (git-merge-resolve does not)
575
+ if (merged.autoMerge) await deps.state.setRef("AUTO_MERGE", treeId);
576
+ const ort = !merged.external;
524
577
  const message = await this.messageFor(action, item.id, commit, parentId);
525
578
 
526
- if (conflicts.length > 0 || !merge.clean) {
579
+ if (conflicts.length > 0 || !clean) {
527
580
  const paths = [...new Set(conflicts.map((c) => c.stagePath))].sort(compareGitPaths);
528
581
  // git records REVERT_HEAD for a revert -n too (do_pick_commit), never CHERRY_PICK_HEAD
529
582
  if (!flags.noCommit || action === "revert") {
530
583
  await deps.state.setRef(HEAD_REF[action], item.id);
531
584
  }
532
- await deps.state.write("MERGE_MSG", `${message}${conflictsComment(paths, true)}`);
585
+ // do_recursive_merge adds the conflicts hint; another strategy's MERGE_MSG has none
586
+ await deps.state.write(
587
+ "MERGE_MSG",
588
+ ort ? `${message}${conflictsComment(paths, true)}` : message,
589
+ );
533
590
  const advice = flags.noCommit
534
591
  ? [
535
592
  "hint: after resolving the conflicts, mark the corrected paths",
@@ -549,6 +606,8 @@ export class PickSequencer {
549
606
  picked: [],
550
607
  output,
551
608
  message: [
609
+ // git-merge-one-file's stderr (`ERROR: content conflict in f`, ...)
610
+ ...(merged.errors ?? []),
552
611
  `error: could not ${action === "pick" ? "apply" : "revert"} ${short}... ${subject}`,
553
612
  ...advice,
554
613
  ].join("\n"),
@@ -845,6 +904,7 @@ export class PickSequencer {
845
904
  const text = await this.deps.state.read("sequencer/opts");
846
905
  if (text === undefined) return;
847
906
  let section = "";
907
+ let xoptsRead = false;
848
908
  for (const raw of text.split("\n")) {
849
909
  const line = raw.trim();
850
910
  const header = /^\[\s*([^\]\s]+)\s*\]/.exec(line);
@@ -855,7 +915,8 @@ export class PickSequencer {
855
915
  const entry = /^([A-Za-z][A-Za-z0-9-]*)\s*=\s*(.*)$/.exec(line);
856
916
  if (section !== "options" || !entry) continue;
857
917
  const name = entry[1].toLowerCase();
858
- const text = entry[2].replace(/^"(.*)"$/, "$1");
918
+ const text = parseConfigValueText(entry[2]);
919
+ if (text === undefined) continue;
859
920
  if (name === "gpg-sign") {
860
921
  this.sign = text;
861
922
  continue;
@@ -869,6 +930,16 @@ export class PickSequencer {
869
930
  this.cleanup = cleanupOf(text) ?? this.cleanup;
870
931
  continue;
871
932
  }
933
+ if (name === "strategy") {
934
+ this.strategy = text;
935
+ continue;
936
+ }
937
+ if (name === "strategy-option") {
938
+ if (!xoptsRead) this.xopts = [];
939
+ xoptsRead = true;
940
+ this.xopts.push(text);
941
+ continue;
942
+ }
872
943
  const value = parseGitBool(text);
873
944
  if (value === undefined) continue;
874
945
  if (name === "edit") this.edit = value;
@@ -1285,3 +1356,226 @@ function shortDate(ident: PersonIdent | undefined): string {
1285
1356
  const pad = (n: number) => String(n).padStart(2, "0");
1286
1357
  return `${d.getUTCFullYear()}-${pad(d.getUTCMonth() + 1)}-${pad(d.getUTCDate())}`;
1287
1358
  }
1359
+
1360
+ /** What {@link mergePickChange} reads and writes with. */
1361
+ export interface PickMergeContext {
1362
+ workingCopy: SequencerDeps["workingCopy"];
1363
+ worktree?: Worktree;
1364
+ staging: SequencerDeps["staging"];
1365
+ blobs: SequencerDeps["blobs"];
1366
+ trees: CommandTrees;
1367
+ commits: CommandCommits;
1368
+ flats: FlatTreeCache;
1369
+ abbreviate: (id: ObjectId) => Promise<string>;
1370
+ }
1371
+
1372
+ /** The pick {@link mergePickChange} merges. */
1373
+ export interface PickMergeArgs {
1374
+ action: PickAction;
1375
+ headId: ObjectId | undefined;
1376
+ /** HEAD's tree (undefined: the empty tree of an unborn branch) */
1377
+ headTreeId: ObjectId | undefined;
1378
+ base: ObjectId | undefined;
1379
+ theirs: ObjectId | undefined;
1380
+ baseLabel: string;
1381
+ theirsLabel: string;
1382
+ pickId: ObjectId;
1383
+ parentId: ObjectId | undefined;
1384
+ /** `-s` (undefined: merge-ort) */
1385
+ strategy: string | undefined;
1386
+ /** `-X` options */
1387
+ xopts: readonly string[];
1388
+ /** HEAD's label in merge-ort's markers */
1389
+ oursLabel: string;
1390
+ /** `-X ours` / `-X theirs` / union given apart from the options */
1391
+ favor?: "ours" | "theirs" | "union";
1392
+ /** The git version whose behaviour to follow where they differ (default 2.56) */
1393
+ compatibility?: "2.43" | "2.56";
1394
+ }
1395
+
1396
+ /** What {@link mergePickChange} found: the result to switch to, or git's failure. */
1397
+ export type PickMergeResult =
1398
+ | {
1399
+ treeId: ObjectId;
1400
+ conflicts: OrtConflict[];
1401
+ /** The paths the conflicts are about (merge-ort's keys; a file moved aside's own path) */
1402
+ conflictPaths: string[];
1403
+ clean: boolean;
1404
+ /** What the strategy printed (merge-ort's messages, git-merge-resolve's stdout) */
1405
+ messages: string[];
1406
+ /** Whether to record AUTO_MERGE (merge-ort's result tree) */
1407
+ autoMerge: boolean;
1408
+ /** Whether the strategy ran as git's child command (resolve, subtree) */
1409
+ external: boolean;
1410
+ /** What git-merge-one-file printed on stderr */
1411
+ errors?: string[];
1412
+ /** The switch to make, when it is not HEAD's tree to `treeId` */
1413
+ delta?: { from: Map<string, CheckedEntry>; to: Map<string, CheckedEntry> };
1414
+ /** What was printed before a refused switch */
1415
+ refusedOutput?: string[];
1416
+ }
1417
+ | {
1418
+ failed: string;
1419
+ /** The strategy gave up (exit 2): the pick fails as do_pick_commit's res -1 */
1420
+ strategyFailed?: boolean;
1421
+ output?: string[];
1422
+ };
1423
+
1424
+ /**
1425
+ * The merge of a pick (do_pick_commit): merge-ort (do_recursive_merge, with the `-X`
1426
+ * options) unless `-s` names another strategy; `subtree` is git merge-subtree (merge-ort
1427
+ * with the shift, the commits' full ids as labels), `resolve` git-merge-resolve
1428
+ * (`read-tree -m --aggressive` and git-merge-one-file). Nothing is written but blobs and
1429
+ * trees: the caller switches to the result.
1430
+ */
1431
+ export async function mergePickChange(
1432
+ ctx: PickMergeContext,
1433
+ p: PickMergeArgs,
1434
+ ): Promise<PickMergeResult> {
1435
+ const strategy = p.strategy;
1436
+ const ort =
1437
+ strategy === undefined ||
1438
+ strategy === "recursive" ||
1439
+ strategy === "ort" ||
1440
+ p.action === "revert";
1441
+ if (!ort && strategy === "resolve" && p.headId) {
1442
+ // git-merge-resolve refuses an index that differs from HEAD's commit (`git diff-index
1443
+ // --cached HEAD`), whatever tree the sequencer merges onto (`--no-commit`: the index's)
1444
+ const headFlat = await flatTree(ctx.trees, p.headTreeId);
1445
+ const headCommitFlat = await flatTree(ctx.trees, await ctx.commits.getTree(p.headId));
1446
+ const { index } = await readIndex(ctx.staging);
1447
+ const outcome = await octopusMerge(
1448
+ {
1449
+ commits: ctx.commits,
1450
+ trees: ctx.trees,
1451
+ blobs: ctx.blobs,
1452
+ style: conflictStyleOf(ctx.workingCopy),
1453
+ },
1454
+ p.headId,
1455
+ [{ id: p.pickId, name: p.pickId }],
1456
+ indexChanges(index, headCommitFlat),
1457
+ { resolve: true, bases: p.parentId ? [p.parentId] : [] },
1458
+ );
1459
+ if (outcome.status === 2) {
1460
+ // the strategy did not handle the merge: do_pick_commit's "could not apply" (no hints)
1461
+ return { failed: outcome.errors.join("\n"), strategyFailed: true, output: outcome.output };
1462
+ }
1463
+ const target = new Map(outcome.index);
1464
+ for (const [path, entry] of outcome.worktree) target.set(path, entry);
1465
+ const treeId = await storeFlatTree(ctx.trees, outcome.index);
1466
+ return {
1467
+ treeId,
1468
+ conflicts: outcome.conflicts,
1469
+ conflictPaths: outcome.conflicts.map((c) => c.stagePath),
1470
+ clean: outcome.status === 0,
1471
+ messages: outcome.output,
1472
+ errors: outcome.errors,
1473
+ autoMerge: false,
1474
+ external: true,
1475
+ delta: { from: headFlat, to: target },
1476
+ refusedOutput: outcome.output.slice(0, outcome.steps[0]?.output ?? 0),
1477
+ };
1478
+ }
1479
+ if (!ort && strategy !== "subtree") {
1480
+ return { failed: `fatal: merge strategy '${strategy}' is not supported here` };
1481
+ }
1482
+ // do_recursive_merge reads the options without checking them (merge-subtree dies on an
1483
+ // unknown one, before merging)
1484
+ const xopts = parseStrategyOptions(p.xopts, ort);
1485
+ const subtree = !ort;
1486
+ const flats = ctx.flats;
1487
+ const labels = subtree
1488
+ ? {
1489
+ oursLabel: p.headId ?? "HEAD",
1490
+ theirsLabel: p.pickId,
1491
+ baseLabel: p.parentId ? await ctx.abbreviate(p.parentId) : "empty tree",
1492
+ }
1493
+ : {
1494
+ oursLabel: p.oursLabel,
1495
+ theirsLabel: p.theirsLabel,
1496
+ baseLabel: p.baseLabel,
1497
+ };
1498
+ const subtreeShift = xopts.subtreeShift ?? (subtree ? "" : undefined);
1499
+ const merge = await mergeStoredTrees(
1500
+ ctx,
1501
+ storedBase(p.base, labels.baseLabel, () => flats.get(p.base)),
1502
+ p.headTreeId,
1503
+ p.theirs,
1504
+ {
1505
+ ...labels,
1506
+ style: conflictStyleOf(ctx.workingCopy),
1507
+ favor: p.favor ?? xopts.favor,
1508
+ ignoreCase: coreBool(ctx.workingCopy, "ignorecase", false),
1509
+ ...ortConfigOptions(ctx.workingCopy, ctx.worktree, {
1510
+ ...(xopts.renormalize !== undefined ? { renormalize: xopts.renormalize } : {}),
1511
+ }),
1512
+ // merge-subtree runs with init_basic_merge_options (no diff.algorithm)
1513
+ ...strategyOrtOptions(subtree ? undefined : ctx.workingCopy, xopts),
1514
+ ...(subtreeShift !== undefined ? { subtreeShift } : {}),
1515
+ },
1516
+ (id) => flats.get(id),
1517
+ );
1518
+ const target = await ortResultEntries(ctx.blobs, merge);
1519
+ // only the directories the pick changes are stored again
1520
+ const treeId = await storeFlatTreeOver(ctx.trees, p.headTreeId, merge.ours, target);
1521
+ return {
1522
+ treeId,
1523
+ conflicts: [...merge.conflicts.values()],
1524
+ conflictPaths: [...merge.conflicts.keys()],
1525
+ clean: merge.clean,
1526
+ messages: merge.messages,
1527
+ // merge-subtree runs as a child: git 2.5x's (merge-ort's merge_switch_to_result) records
1528
+ // AUTO_MERGE, 2.43's (merge-recursive) never
1529
+ autoMerge: ort || p.compatibility !== "2.43",
1530
+ external: !ort,
1531
+ };
1532
+ }
1533
+
1534
+ /**
1535
+ * config.c's write_pair: a value as `git config` writes it (quoted when it starts or ends
1536
+ * with a space or holds `;`, `#` or CR; `\n`, `\t`, `"` and `\` escaped).
1537
+ */
1538
+ export function configValueText(value: string): string {
1539
+ const quote = value.startsWith(" ") || value.endsWith(" ") || /[;#\r]/.test(value) ? '"' : "";
1540
+ const body = value.replace(/[\n\t"\\]/g, (c) =>
1541
+ c === "\n" ? "\\n" : c === "\t" ? "\\t" : `\\${c}`,
1542
+ );
1543
+ return `${quote}${body}${quote}`;
1544
+ }
1545
+
1546
+ /**
1547
+ * config.c's parse_value of the text after a variable's `=` on one line: blanks around it
1548
+ * dropped, `"..."` keeping them, escapes undone, an unquoted `;` or `#` starting a comment;
1549
+ * undefined where git refuses the line.
1550
+ */
1551
+ export function parseConfigValueText(text: string): string | undefined {
1552
+ let quote = false;
1553
+ let value = "";
1554
+ let trimLength = 0;
1555
+ for (let i = 0; i < text.length; i++) {
1556
+ let c = text[i];
1557
+ if ((c === " " || c === "\t") && !quote) {
1558
+ if (!trimLength) trimLength = value.length;
1559
+ if (value.length) value += c;
1560
+ continue;
1561
+ }
1562
+ if (!quote && (c === ";" || c === "#")) break;
1563
+ trimLength = 0;
1564
+ if (c === "\\") {
1565
+ c = text[++i] ?? "";
1566
+ if (c === "t") c = "\t";
1567
+ else if (c === "b") c = "\b";
1568
+ else if (c === "n") c = "\n";
1569
+ else if (c !== "\\" && c !== '"') return undefined;
1570
+ value += c;
1571
+ continue;
1572
+ }
1573
+ if (c === '"') {
1574
+ quote = !quote;
1575
+ continue;
1576
+ }
1577
+ value += c;
1578
+ }
1579
+ if (quote) return undefined;
1580
+ return trimLength ? value.slice(0, trimLength) : value;
1581
+ }