@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
@@ -0,0 +1,241 @@
1
+ /**
2
+ * `--remerge-diff` (log-tree.c's do_remerge_diff): a merge's parents merged again by
3
+ * merge-ort in memory, conflict markers and all, so the merge can be shown as the diff from
4
+ * that automatic result to the recorded one, with merge-ort's conflict messages as
5
+ * `remerge CONFLICT` headers.
6
+ *
7
+ * git writes the re-merge's blobs and trees into a temporary object directory
8
+ * (`tmp_objdir`) it discards after each merge. Here they go to an in-memory overlay
9
+ * ({@link remergeObjectsView}) over the repository's stores: reads see the overlay first,
10
+ * then the repository; writes stay in the overlay, which is dropped with the view.
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * const view = remergeObjectsView(history);
15
+ * const { treeId, pathMessages } = await new RemergeTreeCommand(workingCopy)
16
+ * .setObjectsView(view)
17
+ * .setParents(first, second)
18
+ * .call();
19
+ * // diff treeId against the merge's tree through the same view
20
+ * ```
21
+ */
22
+
23
+ import {
24
+ type BlobContent,
25
+ type Blobs,
26
+ createMemoryHistory,
27
+ type History,
28
+ type ObjectId,
29
+ objectFormatOf,
30
+ overlayMethods,
31
+ type Trees,
32
+ } from "@statewalker/vcs-core";
33
+
34
+ import { GitCommand } from "../git-command.js";
35
+ import { commitsBaseSource, MergeBaseGraph } from "./merge-bases.js";
36
+ import { conflictStyleOf } from "./merge-config.js";
37
+ import { ortConfigOptions } from "./merge-drivers.js";
38
+ import { storeFlatTreeOver, subjectOf } from "./merge-support.js";
39
+ import { ortResultEntries } from "./ort-merge.js";
40
+ import { mergeBaseTree, mergeStoredTrees } from "./ort-recursive.js";
41
+
42
+ /**
43
+ * `history` with its blobs and trees read through an in-memory store first and written only
44
+ * to it: what is stored through the view never reaches `history`. Other stores (commits,
45
+ * refs, tags) are `history`'s own.
46
+ */
47
+ export function remergeObjectsView(history: History): History {
48
+ const memory = createMemoryHistory({ objectFormat: objectFormatOf(history) });
49
+ const top = { blobs: memory.blobs as Blobs, trees: memory.trees as Trees };
50
+ const base = { blobs: history.blobs as Blobs, trees: history.trees as Trees };
51
+ const blobs = overlayMethods(base.blobs, {
52
+ store: (content: BlobContent | Iterable<Uint8Array>, size?: number) =>
53
+ top.blobs.store(content, size),
54
+ load: async (id: ObjectId) =>
55
+ (await top.blobs.has(id)) ? top.blobs.load(id) : base.blobs.load(id),
56
+ has: async (id: ObjectId) => (await top.blobs.has(id)) || base.blobs.has(id),
57
+ size: async (id: ObjectId) =>
58
+ (await top.blobs.has(id)) ? top.blobs.size(id) : base.blobs.size(id),
59
+ // a partial clone's batch fetch (diff's patches, merge-ort's content merges, rename
60
+ // detection): only the ids the overlay lacks are the promisor's to send; the re-merge's
61
+ // own blobs exist nowhere else
62
+ ...(base.blobs.prefetch
63
+ ? {
64
+ prefetch: async (ids: Iterable<ObjectId>) => {
65
+ const absent: ObjectId[] = [];
66
+ for (const id of ids) if (!(await top.blobs.has(id))) absent.push(id);
67
+ if (absent.length > 0) await base.blobs.prefetch?.(absent);
68
+ },
69
+ }
70
+ : {}),
71
+ ...(base.blobs.mayFetch ? { mayFetch: () => base.blobs.mayFetch?.() ?? false } : {}),
72
+ open: async (id: ObjectId) => {
73
+ if (await top.blobs.has(id)) {
74
+ if (top.blobs.open) return top.blobs.open(id);
75
+ const content = await top.blobs.load(id);
76
+ return content ? { size: await top.blobs.size(id), content } : undefined;
77
+ }
78
+ if (base.blobs.open) return base.blobs.open(id);
79
+ const content = await base.blobs.load(id);
80
+ return content ? { size: await base.blobs.size(id), content } : undefined;
81
+ },
82
+ });
83
+ const loadTree = async (id: ObjectId) =>
84
+ (await top.trees.has(id)) ? top.trees.load(id) : base.trees.load(id);
85
+ const storeTree = (tree: Parameters<Trees["store"]>[0]) => top.trees.store(tree);
86
+ // the commands' legacy names (`storeTree`, `loadTree`) are given here too: the base store
87
+ // may carry them already, bound to itself
88
+ const trees = overlayMethods(base.trees as Trees & Record<"storeTree" | "loadTree", unknown>, {
89
+ store: storeTree,
90
+ storeTree,
91
+ load: loadTree,
92
+ loadTree: async function* (id: ObjectId) {
93
+ const entries = await loadTree(id);
94
+ if (entries) yield* entries;
95
+ },
96
+ has: async (id: ObjectId) => (await top.trees.has(id)) || base.trees.has(id),
97
+ getEntry: async (treeId: ObjectId, name: string) =>
98
+ (await top.trees.has(treeId))
99
+ ? top.trees.getEntry(treeId, name)
100
+ : base.trees.getEntry(treeId, name),
101
+ ...(base.trees.entries
102
+ ? {
103
+ entries: async (id: ObjectId) => {
104
+ if (!(await top.trees.has(id))) return base.trees.entries?.(id);
105
+ if (top.trees.entries) return top.trees.entries(id);
106
+ const loaded = await top.trees.load(id);
107
+ if (!loaded) return undefined;
108
+ const out = [];
109
+ for await (const e of loaded) out.push(e);
110
+ return out;
111
+ },
112
+ }
113
+ : {}),
114
+ ...(base.trees.raw
115
+ ? {
116
+ raw: async (id: ObjectId) =>
117
+ (await top.trees.has(id)) ? top.trees.raw?.(id) : base.trees.raw?.(id),
118
+ }
119
+ : {}),
120
+ });
121
+ return overlayMethods(history, { blobs, trees });
122
+ }
123
+
124
+ /** What {@link RemergeTreeCommand} found. */
125
+ export interface RemergeResult {
126
+ /** merge-ort's result tree (conflicted files with their markers), in the view */
127
+ treeId: ObjectId;
128
+ /**
129
+ * merge-ort's conflict messages by the path they are about (no omittable hints), as
130
+ * `--remerge-diff` shows them: `remerge ` first, each newline followed by a space
131
+ */
132
+ pathMessages: Map<string, string[]>;
133
+ }
134
+
135
+ /**
136
+ * do_remerge_diff's merge: the two parents merged as merge_incore_recursive merges them
137
+ * (their merge bases, a virtual one for several), sides named `<abbrev> (<subject>)`. Run it
138
+ * over a {@link remergeObjectsView} (`setObjectsView`): it stores the merge's blobs and trees.
139
+ */
140
+ export class RemergeTreeCommand extends GitCommand<RemergeResult> {
141
+ private parents?: [ObjectId, ObjectId];
142
+ private parentless?: ReadonlySet<ObjectId>;
143
+
144
+ /**
145
+ * Commits read as having no parents in the merge-base computation (git 2.43's log freed
146
+ * the parents of the commits it had shown)
147
+ */
148
+ setParentlessCommits(ids: ReadonlySet<ObjectId>): this {
149
+ this.checkCallable();
150
+ this.parentless = new Set(ids);
151
+ return this;
152
+ }
153
+
154
+ /** The merge's first and second parent */
155
+ setParents(first: ObjectId, second: ObjectId): this {
156
+ this.checkCallable();
157
+ this.parents = [first, second];
158
+ return this;
159
+ }
160
+
161
+ async call(): Promise<RemergeResult> {
162
+ this.checkCallable();
163
+ this.setCallable(false);
164
+ const parents = this.parents;
165
+ if (!parents) throw new Error("RemergeTreeCommand: setParents first");
166
+ const [p1, p2] = parents;
167
+ const c1 = await this.commits.load(p1);
168
+ const c2 = await this.commits.load(p2);
169
+ if (!c1 || !c2) throw new Error(`could not parse commit ${c1 ? p2 : p1}`);
170
+ // repo_format_commit_message(..., "%h (%s)") with DEFAULT_ABBREV
171
+ const label = async (id: ObjectId, message: string) =>
172
+ `${await this.abbreviateObjectId(id)} (${subjectOf(message)})`;
173
+ const oursLabel = await label(p1, c1.message);
174
+ const theirsLabel = await label(p2, c2.message);
175
+ // init_ui_merge_options: merge.* and diff.renames as configured, git_xmerge_config's style
176
+ const common = {
177
+ style: conflictStyleOf(this.workingCopy),
178
+ ...ortConfigOptions(this.workingCopy, undefined),
179
+ };
180
+ const parentless = this.parentless;
181
+ const commits =
182
+ parentless && parentless.size > 0
183
+ ? overlayMethods(this.commits, {
184
+ load: async (id: ObjectId) => {
185
+ const commit = await this.commits.load(id);
186
+ return commit && parentless.has(id) ? { ...commit, parents: [] } : commit;
187
+ },
188
+ // no commit-graph: its headers would give the parents back
189
+ headerReader: undefined,
190
+ })
191
+ : this.commits;
192
+ let bases: ObjectId[];
193
+ if (commits === this.commits) bases = await this.commits.findMergeBase(p1, p2);
194
+ else {
195
+ const graph = new MergeBaseGraph(commitsBaseSource(commits, async () => new Map()));
196
+ bases = (await graph.mergeBases(graph.commit(p1), graph.commit(p2))).flatMap((n) =>
197
+ n.id ? [n.id] : [],
198
+ );
199
+ }
200
+ const base = await mergeBaseTree(
201
+ {
202
+ commits,
203
+ trees: this.trees,
204
+ blobs: this.blobs,
205
+ abbreviate: (id) => this.abbreviateObjectId(id),
206
+ },
207
+ p1,
208
+ p2,
209
+ bases,
210
+ common,
211
+ );
212
+ const merge = await mergeStoredTrees(
213
+ { trees: this.trees, blobs: this.blobs },
214
+ base,
215
+ c1.tree,
216
+ c2.tree,
217
+ {
218
+ ...common,
219
+ oursLabel,
220
+ theirsLabel,
221
+ baseLabel: base.label,
222
+ },
223
+ );
224
+ const target = await ortResultEntries(this.blobs, merge);
225
+ const treeId = await storeFlatTreeOver(this.trees, c1.tree, merge.ours, target);
226
+ // path_msg under record_conflict_msgs_as_headers: the prefix, a space after each newline
227
+ const pathMessages = new Map<string, string[]>();
228
+ for (const [path, texts] of merge.pathMessages ?? []) {
229
+ pathMessages.set(
230
+ path,
231
+ texts.map((t) => `remerge ${t.replaceAll("\n", "\n ")}`),
232
+ );
233
+ }
234
+ return { treeId, pathMessages };
235
+ }
236
+
237
+ /** The re-merge stores its objects only in its view */
238
+ protected override writesNoObjects(): boolean {
239
+ return true;
240
+ }
241
+ }
@@ -7,7 +7,12 @@ import {
7
7
  type RefSpec,
8
8
  type RemoteRef as TransportRemoteRef,
9
9
  } from "@statewalker/vcs-transport";
10
- import { compilePosixRegex, type PosixRegex, PosixRegexError } from "@statewalker/vcs-utils";
10
+ import {
11
+ compilePosixRegex,
12
+ type PosixRegex,
13
+ PosixRegexError,
14
+ parseGitBool,
15
+ } from "@statewalker/vcs-utils";
11
16
 
12
17
  import {
13
18
  GitApiError,
@@ -325,16 +330,8 @@ export class RemoteAddCommand extends TransportCommand<RemoteConfig> {
325
330
  /** git's fetch_remote: `Updating <name>`, then `git fetch <name>` as a child. */
326
331
  private async fetchRemote(name: string): Promise<void> {
327
332
  this.messages.push(`Updating ${name}`);
328
- const fetch = new FetchCommand(this._workingCopy).shareHooksOf(this);
329
- fetch.setTransports(this.getTransports());
333
+ const fetch = this.configureChild(new FetchCommand(this._workingCopy));
330
334
  fetch.setRemote(name);
331
- if (this.credentials) fetch.setCredentials(this.credentials);
332
- if (this.headers) fetch.setHeaders(this.headers);
333
- if (this.timeout) fetch.setTimeout(this.timeout);
334
- if (this.progressCallback) fetch.setProgressMonitor(this.progressCallback);
335
- if (this.progressMessageCallback) {
336
- fetch.setProgressMessageCallback(this.progressMessageCallback);
337
- }
338
335
  try {
339
336
  this.fetchResult = await fetch.call();
340
337
  } catch (cause) {
@@ -1274,3 +1271,94 @@ export class RemoteSetHeadCommand extends TransportCommand<string | undefined> {
1274
1271
  return matches.map((r) => r.name.slice("refs/heads/".length));
1275
1272
  }
1276
1273
  }
1274
+
1275
+ /**
1276
+ * Change the branches a remote's fetch tracks: `git remote set-branches [--add] <name>
1277
+ * <branch>...`.
1278
+ *
1279
+ * As builtin/remote.c `set_branches`: every `remote.<name>.fetch` is removed (unless
1280
+ * {@link setAdd}), then one `+refs/heads/<branch>:refs/remotes/<name>/<branch>` added per
1281
+ * branch, a pattern written as given (`feat/*`); a remote with `remote.<name>.mirror` gets
1282
+ * `+refs/<branch>:refs/<branch>`. The remote must be configured in the repository.
1283
+ *
1284
+ * @example
1285
+ * ```typescript
1286
+ * await git.remoteSetBranches().setRemoteName("origin").setBranches("main", "next").call();
1287
+ * await git.remoteSetBranches().setRemoteName("origin").setBranches("topic").setAdd(true).call();
1288
+ * ```
1289
+ */
1290
+ export class RemoteSetBranchesCommand extends GitCommand<RemoteConfig> {
1291
+ /** git's command reads no core settings: an unparsable `core.whitespace` does not stop it */
1292
+ protected override readsCoreConfig(): boolean {
1293
+ return false;
1294
+ }
1295
+
1296
+ private remoteName?: string;
1297
+ private branches: string[] = [];
1298
+ private addMode = false;
1299
+ private messages: string[] = [];
1300
+
1301
+ /** The remote whose fetch refspecs change. */
1302
+ setRemoteName(name: string): this {
1303
+ this.checkCallable();
1304
+ this.remoteName = name;
1305
+ return this;
1306
+ }
1307
+
1308
+ /** The branches (or patterns) to track. */
1309
+ setBranches(...branches: string[]): this {
1310
+ this.checkCallable();
1311
+ this.branches = [...branches];
1312
+ return this;
1313
+ }
1314
+
1315
+ /** Add the branches to the ones tracked (`--add`) instead of replacing them. */
1316
+ setAdd(add: boolean): this {
1317
+ this.checkCallable();
1318
+ this.addMode = add;
1319
+ return this;
1320
+ }
1321
+
1322
+ /** git 2.5x's warnings reading a legacy remote file. Empty before {@link call}. */
1323
+ getMessages(): string[] {
1324
+ return [...this.messages];
1325
+ }
1326
+
1327
+ /**
1328
+ * @returns the remote as configured now
1329
+ * @throws MissingArgumentError without a remote (git: "no remote specified" and its usage,
1330
+ * exit 129)
1331
+ * @throws RemoteNotFoundError (exit 2) when the repository does not configure the remote
1332
+ * (git: "No such remote '<name>'")
1333
+ * @throws GitApiError (exit 1, no message) without {@link setAdd} when the remote has no
1334
+ * fetch refspec to remove: git's config write finds nothing to replace, and nothing changes
1335
+ */
1336
+ async call(): Promise<RemoteConfig> {
1337
+ this.checkCallable();
1338
+ this.setCallable(false);
1339
+ const name = this.remoteName;
1340
+ if (!name) throw new MissingArgumentError("remoteName", "error: no remote specified");
1341
+ this.messages.push(...(await this.loadLegacyRemote(name)));
1342
+ const store = RemoteConfigStore.from(this.workingCopy);
1343
+ if (!store.isConfiguredInRepo(name)) {
1344
+ throw new RemoteNotFoundError(name, `error: No such remote '${name}'`);
1345
+ }
1346
+ const key = `remote.${name}.fetch`;
1347
+ if (!this.addMode) {
1348
+ // remove_all_fetch_refspecs: git_config_set_multivar_gently(key, NULL, NULL, MULTI_REPLACE)
1349
+ if (store.localValues(key).length === 0) throw new GitApiError("", { exitCode: 1 });
1350
+ store.unset(key);
1351
+ }
1352
+ const mirror = parseGitBool(store.value(`remote.${name}.mirror`)) === true;
1353
+ for (const branch of this.branches) {
1354
+ store.addValue(
1355
+ key,
1356
+ mirror
1357
+ ? `+refs/${branch}:refs/${branch}`
1358
+ : `+refs/heads/${branch}:refs/remotes/${name}/${branch}`,
1359
+ );
1360
+ }
1361
+ await store.save();
1362
+ return store.read(name);
1363
+ }
1364
+ }