@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
@@ -30,6 +30,7 @@ import {
30
30
  } from "./merge-support.js";
31
31
  import { resetMerge } from "./sequencer-support.js";
32
32
  import { pushSparseWarnings, SparseUnpack } from "./sparse-checkout-support.js";
33
+ import { recursesIntoSubmodules, SubmoduleUnpack } from "./submodule-unpack.js";
33
34
  import { restoreCaseOptions, writeTreeRestorePlan } from "./tree-restore.js";
34
35
  import {
35
36
  type CheckedEntry,
@@ -89,6 +90,9 @@ export class ReadTreeCommand extends GitCommand<ReadTreeResult> {
89
90
  private trivial = false;
90
91
  private aggressive = false;
91
92
  private skipSparseCheckout = false;
93
+ private recurseSubmodules?: boolean;
94
+ private dryRun = false;
95
+ private superPrefix = "";
92
96
 
93
97
  /** A tree-ish to read (up to eight). */
94
98
  addTree(treeish: string): this {
@@ -162,6 +166,30 @@ export class ReadTreeCommand extends GitCommand<ReadTreeResult> {
162
166
  return this;
163
167
  }
164
168
 
169
+ /**
170
+ * `--[no-]recurse-submodules` (default `submodule.recurse`): the active submodules' worktrees
171
+ * are checked and moved with the superproject's (unpack-trees' `check_submodule_move_head`,
172
+ * entry.c's `submodule_move_head`).
173
+ */
174
+ setRecurseSubmodules(recurse: boolean): this {
175
+ this.checkCallable();
176
+ this.recurseSubmodules = recurse;
177
+ return this;
178
+ }
179
+
180
+ /** `-n` / `--dry-run`: everything checked, neither the index nor the worktree written. */
181
+ setDryRun(dryRun: boolean): this {
182
+ this.checkCallable();
183
+ this.dryRun = dryRun;
184
+ return this;
185
+ }
186
+
187
+ /** @internal git's `--super-prefix`: the submodule's path in its superproject, in messages. */
188
+ setSuperPrefix(prefix: string): this {
189
+ this.superPrefix = prefix;
190
+ return this;
191
+ }
192
+
165
193
  /** `--no-sparse-checkout`: the sparse-checkout patterns are not applied. */
166
194
  setSkipSparseCheckout(skip: boolean): this {
167
195
  this.checkCallable();
@@ -172,6 +200,18 @@ export class ReadTreeCommand extends GitCommand<ReadTreeResult> {
172
200
  async call(): Promise<ReadTreeResult> {
173
201
  // a tree entry the decoder refuses (`..`, `/` in a name, an empty name): git's message
174
202
  const trees: ObjectId[] = [];
203
+ if (this.dryRun) {
204
+ // -n: nothing the run changed in memory outlives it
205
+ try {
206
+ return await this.callChecked(trees);
207
+ } finally {
208
+ await this.staging.read();
209
+ }
210
+ }
211
+ return this.callChecked(trees);
212
+ }
213
+
214
+ private callChecked(trees: ObjectId[]): Promise<ReadTreeResult> {
175
215
  return withTreePathRefusal(
176
216
  this.trees,
177
217
  () => trees,
@@ -252,8 +292,28 @@ export class ReadTreeCommand extends GitCommand<ReadTreeResult> {
252
292
  sparseWarnings: result.warnings,
253
293
  };
254
294
  const refused = (message: string | undefined, paths: string[] = []) => {
255
- if (message) throw new ReadTreeFailedError(message, paths);
295
+ if (!message) return;
296
+ // --super-prefix: the paths as the superproject names them
297
+ let text = message;
298
+ if (this.superPrefix) {
299
+ for (const p of new Set(paths)) {
300
+ text = text.split(`'${p}'`).join(`'${this.superPrefix}${p}'`);
301
+ }
302
+ }
303
+ throw new ReadTreeFailedError(text, paths);
256
304
  };
305
+ // unpack-trees' submodule support (only for the merges that update or check the worktree)
306
+ const submodules =
307
+ merge && !prefixSet && treeIds.length <= 2 && !this.indexOnly
308
+ ? await SubmoduleUnpack.start(this.workingCopy, {
309
+ recurse: recursesIntoSubmodules(this.workingCopy, this.recurseSubmodules),
310
+ reset: this.reset,
311
+ superPrefix: this.superPrefix,
312
+ })
313
+ : undefined;
314
+ // -n keeps o->update: the checks an update makes still run, nothing is written
315
+ const update = this.update;
316
+ const dryRunOptions = this.dryRun ? { writeIndex: false, checkOnly: true } : {};
257
317
 
258
318
  if (!merge) {
259
319
  await this.readWithoutMerge(treeIds);
@@ -264,7 +324,9 @@ export class ReadTreeCommand extends GitCommand<ReadTreeResult> {
264
324
  const tree = treeIds[0] as ObjectId;
265
325
  const refusal = await resetMerge(sequencerCtx, tree, tree, {
266
326
  hard: this.reset,
267
- update: this.update,
327
+ update,
328
+ submodules,
329
+ ...dryRunOptions,
268
330
  overwriteUntracked: this.reset,
269
331
  skipSparseCheckout: this.skipSparseCheckout,
270
332
  targetTree: tree,
@@ -280,7 +342,9 @@ export class ReadTreeCommand extends GitCommand<ReadTreeResult> {
280
342
  {
281
343
  action: "merge",
282
344
  operation: "read-tree",
283
- update: this.update,
345
+ update,
346
+ submodules,
347
+ ...dryRunOptions,
284
348
  skipSparseCheckout: this.skipSparseCheckout,
285
349
  plainErrors: true,
286
350
  initialCheckout: await isIndexUnborn(this.staging),
@@ -293,6 +357,7 @@ export class ReadTreeCommand extends GitCommand<ReadTreeResult> {
293
357
 
294
358
  // read-tree starts from no cache-tree and resolve-undo (cache_tree_free,
295
359
  // resolve_undo_clear_index); one tree read whole primes it
360
+ if (this.dryRun) return result;
296
361
  this.staging.clearResolveUndo?.();
297
362
  if (treeIds.length === 1 && !prefixSet) {
298
363
  this.staging.setCacheTree?.(await cacheTreeOfTree(this.trees, treeIds[0] as ObjectId));
@@ -415,6 +480,7 @@ export class ReadTreeCommand extends GitCommand<ReadTreeResult> {
415
480
  }
416
481
  }
417
482
  const checking = traversalOrder(target.keys());
483
+ // -n keeps o->update: the checks run, nothing is written
418
484
  const worktree = this.update ? ctx.worktree : undefined;
419
485
  const sparse = worktree && !this.skipSparseCheckout ? await SparseUnpack.start(ctx) : undefined;
420
486
  const trust = worktree ? worktreeModeTrust(this.workingCopy, worktree) : undefined;
@@ -454,6 +520,8 @@ export class ReadTreeCommand extends GitCommand<ReadTreeResult> {
454
520
  const stage0 = new Set<string>(paths);
455
521
  for (const p of index.keys()) if (!dropped.has(p)) stage0.add(p);
456
522
  assertNoStageZeroClash(stage0);
523
+ // -n: every check made, neither worktree nor index written
524
+ if (this.dryRun) return;
457
525
 
458
526
  const writing = new Set(paths.filter((p) => !sparse || sparse.writes(p)));
459
527
  if (worktree) {
@@ -555,6 +623,7 @@ export class ReadTreeCommand extends GitCommand<ReadTreeResult> {
555
623
  const indexEntries = new Map<string, StagingEntry>();
556
624
  for (const e of await this.entryList()) if (e.stage === 0) indexEntries.set(e.path, e);
557
625
  const checkedWorktree = ctx.worktree;
626
+ // -n keeps o->update: the checks run, nothing is written
558
627
  const worktree = this.update ? checkedWorktree : undefined;
559
628
  const sparse = worktree && !this.skipSparseCheckout ? await SparseUnpack.start(ctx) : undefined;
560
629
  const quiet = (p: string) => sparse?.leavesAlone(p) === true;
@@ -735,6 +804,8 @@ export class ReadTreeCommand extends GitCommand<ReadTreeResult> {
735
804
  for (const p of indexEntries.keys()) if (!changes.has(p)) stage0.add(p);
736
805
  for (const [p, list] of changes) if (list.some((e) => !e.stage)) stage0.add(p);
737
806
  assertNoStageZeroClash(stage0);
807
+ // -n: every check made, neither worktree nor index written
808
+ if (this.dryRun) return;
738
809
 
739
810
  // the worktree: removals first, then the files written
740
811
  sparse?.conflict(conflicted);
@@ -23,7 +23,7 @@ import {
23
23
  import { GitCommand } from "../git-command.js";
24
24
  import { RemoteConfigStore } from "../remote-config/index.js";
25
25
  import {
26
- type ContentMergeStrategy,
26
+ ContentMergeStrategy,
27
27
  FastForwardMode,
28
28
  type MergeResult,
29
29
  MergeStatus,
@@ -48,6 +48,7 @@ import { commitsBaseSource, MergeBaseGraph } from "./merge-bases.js";
48
48
  import { favorOf, MergeCommand } from "./merge-command.js";
49
49
  import { configBool, configValue, conflictStyleOf } from "./merge-config.js";
50
50
  import { ortConfigOptions } from "./merge-drivers.js";
51
+ import { quoteStrategyOptions, splitStrategyOptions } from "./merge-strategy-options.js";
51
52
  import {
52
53
  conflictsComment,
53
54
  FlatTreeCache,
@@ -64,8 +65,8 @@ import {
64
65
  import { CleanupMode, commentPrefixOf, stripspace } from "./message-cleanup.js";
65
66
  import { copyNotesForAmend, copyNotesForRebase } from "./notes-support.js";
66
67
  import { ortResultEntries } from "./ort-merge.js";
67
- import { mergeBaseTree, mergeStoredTrees, storedBase } from "./ort-recursive.js";
68
- import { type PatchIdTrees, patchId } from "./patch-id.js";
68
+ import { mergeBaseTree, mergeStoredTrees } from "./ort-recursive.js";
69
+ import { PatchIds, type PatchIdTrees } from "./patch-id.js";
69
70
  import { formatCommitPretty, loadRefDecorations, type RefDecorations } from "./pretty-format.js";
70
71
  import {
71
72
  addExecCommands,
@@ -90,7 +91,7 @@ import {
90
91
  } from "./rebase-todo.js";
91
92
  import { reflogMessages, updateHeadExpecting } from "./reflog-messages.js";
92
93
  import { revisionMergeBases } from "./rev-parse-command.js";
93
- import { expandCommitId } from "./sequencer-pick.js";
94
+ import { expandCommitId, mergePickChange } from "./sequencer-pick.js";
94
95
  import {
95
96
  AUTOSTASH_SAVED_LINES,
96
97
  applyAutostash,
@@ -309,7 +310,12 @@ export class RebaseCommand extends GitCommand<RebaseResult> {
309
310
  private upstreamCommit?: ObjectId;
310
311
  private upstreamCommitName?: string;
311
312
  private strategy = MergeStrategy.RECURSIVE;
313
+ private strategyGiven = false;
312
314
  private contentStrategy?: ContentMergeStrategy;
315
+ /** `-X <option>`s */
316
+ private strategyOptions: string[] = [];
317
+ /** The run's `-s` and `-X` (rebase-merge/strategy, strategy_opts), once read */
318
+ private runStrategyState?: { strategy?: string; xopts: string[] };
313
319
  private preserveMerges = false;
314
320
  private interactiveHandler?: InteractiveHandler;
315
321
  /** Whose messages to give where git 2.43 and 2.5x differ (default: the hooks') */
@@ -542,16 +548,70 @@ export class RebaseCommand extends GitCommand<RebaseResult> {
542
548
  }
543
549
 
544
550
  /**
545
- * Set the merge strategy (only git's merge-ort is run; kept for compatibility).
551
+ * Set the merge strategy (`-s`): merge-ort (RECURSIVE, ORT), RESOLVE (git-merge-resolve)
552
+ * or SUBTREE (git merge-subtree) for each pick; kept in `rebase-merge/strategy`.
546
553
  *
547
554
  * @param strategy Merge strategy
548
555
  */
549
556
  setStrategy(strategy: MergeStrategy): this {
550
557
  this.checkCallable();
551
558
  this.strategy = strategy;
559
+ this.strategyGiven = true;
552
560
  return this;
553
561
  }
554
562
 
563
+ /**
564
+ * The `-X <option>`s of each pick (see `MergeCommand.setStrategyOptions`), kept in
565
+ * `rebase-merge/strategy_opts`; with no `-s`, the strategy is `ort` (builtin/rebase.c).
566
+ */
567
+ setStrategyOptions(options: readonly string[]): this {
568
+ this.checkCallable();
569
+ this.strategyOptions = [...options];
570
+ return this;
571
+ }
572
+
573
+ /** Adds one `-X <option>` (see {@link setStrategyOptions}). */
574
+ addStrategyOption(option: string): this {
575
+ this.checkCallable();
576
+ this.strategyOptions.push(option);
577
+ return this;
578
+ }
579
+
580
+ /** The `-X` options as given: `-X ours`/`-X theirs` of the content strategy first. */
581
+ private givenStrategyOptions(): string[] {
582
+ const favor =
583
+ this.contentStrategy === ContentMergeStrategy.OURS
584
+ ? ["ours"]
585
+ : this.contentStrategy === ContentMergeStrategy.THEIRS
586
+ ? ["theirs"]
587
+ : [];
588
+ return [...favor, ...this.strategyOptions];
589
+ }
590
+
591
+ /** The run's `-s` (`ort` when only `-X` was given) as builtin/rebase.c settles it. */
592
+ private givenStrategyName(): string | undefined {
593
+ if (this.strategyGiven) return this.strategy;
594
+ return this.givenStrategyOptions().length > 0 ? "ort" : undefined;
595
+ }
596
+
597
+ /** The run's `-s` and `-X`: read back from `rebase-merge/` (read_strategy_opts), else given. */
598
+ private async runStrategy(
599
+ state: OperationState,
600
+ ): Promise<{ strategy: string | undefined; xopts: string[] }> {
601
+ if (!this.runStrategyState) {
602
+ const strategy = (await state.read(`${DIR}/strategy`))?.trim();
603
+ const opts = await state.read(`${DIR}/strategy_opts`);
604
+ this.runStrategyState =
605
+ strategy !== undefined || opts !== undefined
606
+ ? {
607
+ ...(strategy ? { strategy } : {}),
608
+ xopts: opts !== undefined ? splitStrategyOptions(opts.trim()) : [],
609
+ }
610
+ : { strategy: this.givenStrategyName(), xopts: this.givenStrategyOptions() };
611
+ }
612
+ return { strategy: this.runStrategyState.strategy, xopts: this.runStrategyState.xopts };
613
+ }
614
+
555
615
  /**
556
616
  * Get the merge strategy.
557
617
  */
@@ -1431,6 +1491,13 @@ export class RebaseCommand extends GitCommand<RebaseResult> {
1431
1491
  await state.write(`${DIR}/head-name`, `${headName}\n`);
1432
1492
  await state.write(`${DIR}/onto`, `${onto}\n`);
1433
1493
  await state.write(`${DIR}/orig-head`, `${origHead}\n`);
1494
+ // write_basic_state: strategy, strategy_opts
1495
+ const strategyName = this.givenStrategyName();
1496
+ if (strategyName) await state.write(`${DIR}/strategy`, `${strategyName}\n`);
1497
+ const xopts = this.givenStrategyOptions();
1498
+ if (xopts.length > 0) {
1499
+ await state.write(`${DIR}/strategy_opts`, `${quoteStrategyOptions(xopts)}\n`);
1500
+ }
1434
1501
  // write_basic_state: gpg_sign_opt (`-S<key>`) when the run signs
1435
1502
  const sign = signRequestOf(this.workingCopy, this.sign);
1436
1503
  this.runSign = { key: sign };
@@ -1989,34 +2056,48 @@ export class RebaseCommand extends GitCommand<RebaseResult> {
1989
2056
  const short = await this.abbreviateObjectId(item.id);
1990
2057
  const label = `${short} (${subject})`;
1991
2058
  const baseLabel = parentId ? `parent of ${label}` : "(empty tree)";
1992
- // the trees as merge-ort reads them: what all three hold alike is never read
1993
- const merge = await mergeStoredTrees(
1994
- this.context(worktree),
1995
- storedBase(parentTreeId, baseLabel, () => flats.get(parentTreeId)),
1996
- headTreeId,
1997
- commit.tree,
2059
+ // the trees as merge-ort reads them: what all three hold alike is never read; `-s`
2060
+ // and `-X` as the sequencer gives them to the pick
2061
+ const { strategy, xopts } = await this.runStrategy(state);
2062
+ const merge = await mergePickChange(
1998
2063
  {
1999
- oursLabel: "HEAD",
2000
- theirsLabel: label,
2064
+ ...this.context(worktree),
2065
+ commits: this.commits,
2066
+ flats,
2067
+ abbreviate: (id) => this.abbreviateObjectId(id),
2068
+ },
2069
+ {
2070
+ action: "pick",
2071
+ headId,
2072
+ headTreeId,
2073
+ base: parentTreeId,
2074
+ theirs: commit.tree,
2001
2075
  baseLabel,
2002
- style: conflictStyleOf(this.workingCopy),
2003
- favor: favorOf(this.contentStrategy),
2004
- ignoreCase: coreBool(this.workingCopy, "ignorecase", false),
2005
- ...ortConfigOptions(this.workingCopy, worktree),
2076
+ theirsLabel: label,
2077
+ pickId: item.id,
2078
+ parentId,
2079
+ strategy,
2080
+ xopts,
2081
+ oursLabel: "HEAD",
2082
+ favor: this.contentStrategy === ContentMergeStrategy.UNION ? "union" : undefined,
2083
+ compatibility: this.compatibility ?? this.hooks.compatibility ?? "2.56",
2006
2084
  },
2007
- (id) => flats.get(id),
2008
2085
  );
2009
- const target = await ortResultEntries(this.blobs, merge);
2010
- // only the directories the pick changes are stored again
2011
- const treeId = await storeFlatTreeOver(this.trees, headTreeId, merge.ours, target);
2012
- const conflicts = [...merge.conflicts.values()];
2086
+ if ("failed" in merge) {
2087
+ output.push(...(merge.output ?? []));
2088
+ return {
2089
+ kind: "reschedule",
2090
+ result: { status: RebaseStatus.FAILED, currentCommit: item.id, message: merge.failed },
2091
+ };
2092
+ }
2093
+ const { treeId, conflicts } = merge;
2013
2094
  // only the paths HEAD and the result differ on are switched
2014
- const delta = await treeDelta(this.trees, headTreeId, treeId);
2095
+ const delta = merge.delta ?? (await treeDelta(this.trees, headTreeId, treeId));
2015
2096
  const refused = await switchTrees(this.context(worktree), delta.from, delta.to, {
2016
2097
  action: "merge",
2017
2098
  operation: "rebase",
2018
2099
  conflicts,
2019
- targetTree: treeId,
2100
+ ...(merge.delta ? {} : { targetTree: treeId }),
2020
2101
  });
2021
2102
  if (refused) {
2022
2103
  // nothing written: the pick is rescheduled (git keeps the author and REBASE_HEAD)
@@ -2031,13 +2112,18 @@ export class RebaseCommand extends GitCommand<RebaseResult> {
2031
2112
  },
2032
2113
  };
2033
2114
  }
2034
- // the sequencer shows merge-ort's messages of a rebase only when the pick conflicts
2035
- if (conflicts.length > 0 || !merge.clean) output.push(...merge.messages);
2036
- await state.setRef("AUTO_MERGE", treeId);
2115
+ // the sequencer shows merge-ort's messages of a rebase only when the pick conflicts (an
2116
+ // external strategy prints its own)
2117
+ if (merge.external || conflicts.length > 0 || !merge.clean) output.push(...merge.messages);
2118
+ if (merge.autoMerge) await state.setRef("AUTO_MERGE", treeId);
2037
2119
  const merged = pickedMessage.endsWith("\n") ? pickedMessage : `${pickedMessage}\n`;
2038
2120
  if (conflicts.length > 0 || !merge.clean) {
2039
2121
  const paths = [...new Set(conflicts.map((c) => c.stagePath))].sort(compareGitPaths);
2040
- await state.write("MERGE_MSG", `${merged}${conflictsComment(paths, true)}`);
2122
+ // do_recursive_merge adds the conflicts hint; another strategy's MERGE_MSG has none
2123
+ await state.write(
2124
+ "MERGE_MSG",
2125
+ merge.external ? merged : `${merged}${conflictsComment(paths, true)}`,
2126
+ );
2041
2127
  if (!fixup) {
2042
2128
  // do_pick_commit writes CHERRY_PICK_HEAD after a conflicted merge too; the rebase
2043
2129
  // stopping there deletes it again (REBASE_HEAD names the commit instead)
@@ -2045,9 +2131,13 @@ export class RebaseCommand extends GitCommand<RebaseResult> {
2045
2131
  }
2046
2132
  return {
2047
2133
  kind: "conflicts",
2048
- conflicts: [...new Set(merge.conflicts.keys())].sort(),
2049
- // git 2.43 writes the message and a blank line (2.5x the conflict list after it)
2050
- message: `${merged}\n`,
2134
+ conflicts: [...new Set(merge.conflictPaths)].sort(),
2135
+ // git 2.43 writes the message and a blank line (2.5x the conflict list after it, which
2136
+ // another strategy than merge-ort does not add)
2137
+ message:
2138
+ !merge.external || (this.compatibility ?? this.hooks.compatibility) === "2.43"
2139
+ ? `${merged}\n`
2140
+ : merged,
2051
2141
  lines: [`error: could not apply ${short}... ${subject}`, ...this.mergeConflictAdvice()],
2052
2142
  };
2053
2143
  }
@@ -4605,41 +4695,27 @@ export class RebaseCommand extends GitCommand<RebaseResult> {
4605
4695
  },
4606
4696
  };
4607
4697
  const loadTree = (id: ObjectId) => this.trees.loadTree(id);
4608
- const patchIdOf = async (id: ObjectId, headerOnly: boolean) => {
4609
- const commit = await this.loadCommit(id);
4610
- if (!commit || commit.parents.length > 1) return undefined;
4611
- const parentTree = commit.parents[0]
4612
- ? (await this.loadCommit(commit.parents[0]))?.tree
4613
- : undefined;
4614
- return patchId(trees, this.blobs, parentTree, commit.tree, {
4615
- headerOnly,
4616
- objectFormat: this.objectFormat,
4617
- });
4618
- };
4619
- const full = new Map<ObjectId, string | undefined>();
4620
- const fullOf = async (id: ObjectId) => {
4621
- if (!full.has(id)) full.set(id, await patchIdOf(id, false));
4622
- return full.get(id);
4623
- };
4624
- // HEAD's side by header id
4625
- const byHeader = new Map<string, ObjectId[]>();
4626
- for (const id of range) {
4627
- const header = await patchIdOf(id, true);
4628
- if (!header) continue;
4629
- const list = byHeader.get(header) ?? [];
4630
- list.push(id);
4631
- byHeader.set(header, list);
4632
- }
4633
- if (byHeader.size === 0) return skipped;
4698
+ // HEAD's side added, upstream's looked up (patch-ids.c)
4699
+ const ids = new PatchIds<ObjectId>({
4700
+ trees,
4701
+ blobs: this.blobs,
4702
+ objectFormat: this.objectFormat,
4703
+ change: async (id) => {
4704
+ const commit = await this.loadCommit(id);
4705
+ if (!commit || commit.parents.length > 1) return undefined;
4706
+ const parentTree = commit.parents[0]
4707
+ ? (await this.loadCommit(commit.parents[0]))?.tree
4708
+ : undefined;
4709
+ return { ...(parentTree ? { parentTree } : {}), tree: commit.tree };
4710
+ },
4711
+ });
4712
+ let added = 0;
4713
+ for (const id of range) if (await ids.add(id)) added++;
4714
+ if (added === 0) return skipped;
4715
+ const empty = this.objectFormat.nullId;
4634
4716
  for (const id of left) {
4635
- const header = await patchIdOf(id, true);
4636
- const candidates = header ? byHeader.get(header) : undefined;
4637
- if (!candidates) continue;
4638
- const mine = await fullOf(id);
4639
- if (!mine) continue;
4640
- for (const c of candidates) {
4641
- if (!skipped.has(c) && (await fullOf(c)) === mine) skipped.add(c);
4642
- }
4717
+ // make_script never skips a commit empty from the start
4718
+ for (const c of await ids.matches(id)) if ((await ids.fullId(c)) !== empty) skipped.add(c);
4643
4719
  }
4644
4720
  return skipped;
4645
4721
  }