@statewalker/vcs-commands 0.13.0 → 0.15.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 (304) hide show
  1. package/dist/commands/add-command.d.ts.map +1 -1
  2. package/dist/commands/add-patch/patch-backend.d.ts +1 -1
  3. package/dist/commands/add-patch/patch-backend.d.ts.map +1 -1
  4. package/dist/commands/archive/archive-command.d.ts +6 -2
  5. package/dist/commands/archive/archive-command.d.ts.map +1 -1
  6. package/dist/commands/archive/remote-archive-command.d.ts +27 -2
  7. package/dist/commands/archive/remote-archive-command.d.ts.map +1 -1
  8. package/dist/commands/archive/upload-archive-writer.d.ts +11 -5
  9. package/dist/commands/archive/upload-archive-writer.d.ts.map +1 -1
  10. package/dist/commands/branch-command.d.ts +14 -2
  11. package/dist/commands/branch-command.d.ts.map +1 -1
  12. package/dist/commands/bundle/bundle-format.d.ts +6 -1
  13. package/dist/commands/bundle/bundle-format.d.ts.map +1 -1
  14. package/dist/commands/bundle/bundle-uri-host.d.ts +12 -1
  15. package/dist/commands/bundle/bundle-uri-host.d.ts.map +1 -1
  16. package/dist/commands/bundle/bundle-uri.d.ts +7 -1
  17. package/dist/commands/bundle/bundle-uri.d.ts.map +1 -1
  18. package/dist/commands/bundle/bundle-verify.d.ts +4 -1
  19. package/dist/commands/bundle/bundle-verify.d.ts.map +1 -1
  20. package/dist/commands/cat-file/batch-format.d.ts +8 -12
  21. package/dist/commands/cat-file/batch-format.d.ts.map +1 -1
  22. package/dist/commands/cat-file/cat-file-command.d.ts +39 -5
  23. package/dist/commands/cat-file/cat-file-command.d.ts.map +1 -1
  24. package/dist/commands/check-ignore-command.d.ts.map +1 -1
  25. package/dist/commands/checkout-command.d.ts +4 -0
  26. package/dist/commands/checkout-command.d.ts.map +1 -1
  27. package/dist/commands/checkout-paths.d.ts +9 -0
  28. package/dist/commands/checkout-paths.d.ts.map +1 -1
  29. package/dist/commands/cherry-pick-command.d.ts +3 -0
  30. package/dist/commands/cherry-pick-command.d.ts.map +1 -1
  31. package/dist/commands/clean-interactive.d.ts +0 -9
  32. package/dist/commands/clean-interactive.d.ts.map +1 -1
  33. package/dist/commands/clone-command.d.ts +17 -0
  34. package/dist/commands/clone-command.d.ts.map +1 -1
  35. package/dist/commands/column/column-config.d.ts +23 -0
  36. package/dist/commands/column/column-config.d.ts.map +1 -0
  37. package/dist/commands/column/column-layout.d.ts +129 -0
  38. package/dist/commands/column/column-layout.d.ts.map +1 -0
  39. package/dist/commands/column/index.d.ts +3 -0
  40. package/dist/commands/column/index.d.ts.map +1 -0
  41. package/dist/commands/column-command.d.ts +59 -0
  42. package/dist/commands/column-command.d.ts.map +1 -0
  43. package/dist/commands/comment-char-config.d.ts +15 -0
  44. package/dist/commands/comment-char-config.d.ts.map +1 -1
  45. package/dist/commands/commit-command.d.ts +30 -2
  46. package/dist/commands/commit-command.d.ts.map +1 -1
  47. package/dist/commands/config-command.d.ts +12 -0
  48. package/dist/commands/config-command.d.ts.map +1 -1
  49. package/dist/commands/credential-helper.d.ts +214 -0
  50. package/dist/commands/credential-helper.d.ts.map +1 -0
  51. package/dist/commands/default-branch.d.ts +33 -3
  52. package/dist/commands/default-branch.d.ts.map +1 -1
  53. package/dist/commands/diff-color-config.d.ts +4 -0
  54. package/dist/commands/diff-color-config.d.ts.map +1 -1
  55. package/dist/commands/diff-command.d.ts +12 -0
  56. package/dist/commands/diff-command.d.ts.map +1 -1
  57. package/dist/commands/fast-export/fast-export-command.d.ts +89 -2
  58. package/dist/commands/fast-export/fast-export-command.d.ts.map +1 -1
  59. package/dist/commands/fast-export/fast-import-command.d.ts +113 -8
  60. package/dist/commands/fast-export/fast-import-command.d.ts.map +1 -1
  61. package/dist/commands/fast-export/fast-stream-support.d.ts +0 -9
  62. package/dist/commands/fast-export/fast-stream-support.d.ts.map +1 -1
  63. package/dist/commands/fetch-command.d.ts +23 -1
  64. package/dist/commands/fetch-command.d.ts.map +1 -1
  65. package/dist/commands/fsck/fsck-object-checks.d.ts.map +1 -1
  66. package/dist/commands/git-hooks.d.ts +31 -3
  67. package/dist/commands/git-hooks.d.ts.map +1 -1
  68. package/dist/commands/history-command.d.ts +173 -7
  69. package/dist/commands/history-command.d.ts.map +1 -1
  70. package/dist/commands/index-host.d.ts +19 -0
  71. package/dist/commands/index-host.d.ts.map +1 -1
  72. package/dist/commands/index-refresh.d.ts +36 -0
  73. package/dist/commands/index-refresh.d.ts.map +1 -0
  74. package/dist/commands/index.d.ts +9 -0
  75. package/dist/commands/index.d.ts.map +1 -1
  76. package/dist/commands/index.js +7 -6
  77. package/dist/commands/init-command.d.ts +20 -0
  78. package/dist/commands/init-command.d.ts.map +1 -1
  79. package/dist/commands/local-transport.d.ts +40 -2
  80. package/dist/commands/local-transport.d.ts.map +1 -1
  81. package/dist/commands/log-command.d.ts +7 -0
  82. package/dist/commands/log-command.d.ts.map +1 -1
  83. package/dist/commands/log-output.d.ts +11 -0
  84. package/dist/commands/log-output.d.ts.map +1 -1
  85. package/dist/commands/ls-tree-command.d.ts +10 -0
  86. package/dist/commands/ls-tree-command.d.ts.map +1 -1
  87. package/dist/commands/maintenance-schedule-command.d.ts +122 -0
  88. package/dist/commands/maintenance-schedule-command.d.ts.map +1 -0
  89. package/dist/commands/merge-command.d.ts +13 -1
  90. package/dist/commands/merge-command.d.ts.map +1 -1
  91. package/dist/commands/merge-index-command.d.ts +42 -0
  92. package/dist/commands/merge-index-command.d.ts.map +1 -0
  93. package/dist/commands/merge-one-file.d.ts +129 -0
  94. package/dist/commands/merge-one-file.d.ts.map +1 -0
  95. package/dist/commands/merge-support.d.ts +40 -4
  96. package/dist/commands/merge-support.d.ts.map +1 -1
  97. package/dist/commands/object-disk-info.d.ts +35 -0
  98. package/dist/commands/object-disk-info.d.ts.map +1 -0
  99. package/dist/commands/octopus-merge.d.ts +3 -3
  100. package/dist/commands/octopus-merge.d.ts.map +1 -1
  101. package/dist/commands/plumbing-input.d.ts.map +1 -1
  102. package/dist/commands/promisor-remote-reply.d.ts +31 -4
  103. package/dist/commands/promisor-remote-reply.d.ts.map +1 -1
  104. package/dist/commands/promisor-remote.d.ts +8 -1
  105. package/dist/commands/promisor-remote.d.ts.map +1 -1
  106. package/dist/commands/pull-command.d.ts +55 -7
  107. package/dist/commands/pull-command.d.ts.map +1 -1
  108. package/dist/commands/push-command.d.ts +18 -1
  109. package/dist/commands/push-command.d.ts.map +1 -1
  110. package/dist/commands/range-diff/range-diff-command.d.ts +37 -1
  111. package/dist/commands/range-diff/range-diff-command.d.ts.map +1 -1
  112. package/dist/commands/rebase-command.d.ts +13 -1
  113. package/dist/commands/rebase-command.d.ts.map +1 -1
  114. package/dist/commands/ref-filter/for-each-ref-command.d.ts +3 -2
  115. package/dist/commands/ref-filter/for-each-ref-command.d.ts.map +1 -1
  116. package/dist/commands/ref-filter/index.d.ts +1 -0
  117. package/dist/commands/ref-filter/index.d.ts.map +1 -1
  118. package/dist/commands/ref-filter/peel-limit.d.ts +8 -0
  119. package/dist/commands/ref-filter/peel-limit.d.ts.map +1 -0
  120. package/dist/commands/ref-filter/ref-filter.d.ts.map +1 -1
  121. package/dist/commands/ref-filter/ref-format.d.ts +26 -1
  122. package/dist/commands/ref-filter/ref-format.d.ts.map +1 -1
  123. package/dist/commands/ref-filter/ref-listing-command.d.ts +9 -0
  124. package/dist/commands/ref-filter/ref-listing-command.d.ts.map +1 -1
  125. package/dist/commands/remote-transport.d.ts +27 -0
  126. package/dist/commands/remote-transport.d.ts.map +1 -1
  127. package/dist/commands/repack-command.d.ts +18 -2
  128. package/dist/commands/repack-command.d.ts.map +1 -1
  129. package/dist/commands/repo-command.d.ts +2 -7
  130. package/dist/commands/repo-command.d.ts.map +1 -1
  131. package/dist/commands/reset-command.d.ts +4 -1
  132. package/dist/commands/reset-command.d.ts.map +1 -1
  133. package/dist/commands/restore-command.d.ts.map +1 -1
  134. package/dist/commands/rev-list-command.d.ts +65 -0
  135. package/dist/commands/rev-list-command.d.ts.map +1 -1
  136. package/dist/commands/revert-command.d.ts +3 -0
  137. package/dist/commands/revert-command.d.ts.map +1 -1
  138. package/dist/commands/revision-filenames.d.ts.map +1 -1
  139. package/dist/commands/revision-range.d.ts +17 -0
  140. package/dist/commands/revision-range.d.ts.map +1 -1
  141. package/dist/commands/revision-resolver.d.ts +12 -0
  142. package/dist/commands/revision-resolver.d.ts.map +1 -1
  143. package/dist/commands/serve-repository.d.ts +21 -4
  144. package/dist/commands/serve-repository.d.ts.map +1 -1
  145. package/dist/commands/served-lazy-fetch.d.ts +61 -0
  146. package/dist/commands/served-lazy-fetch.d.ts.map +1 -0
  147. package/dist/commands/signing.d.ts +37 -4
  148. package/dist/commands/signing.d.ts.map +1 -1
  149. package/dist/commands/split-cmdline.d.ts +6 -0
  150. package/dist/commands/split-cmdline.d.ts.map +1 -0
  151. package/dist/commands/status-color-config.d.ts +33 -0
  152. package/dist/commands/status-color-config.d.ts.map +1 -0
  153. package/dist/commands/status-command.d.ts +15 -0
  154. package/dist/commands/status-command.d.ts.map +1 -1
  155. package/dist/commands/status-format.d.ts +46 -4
  156. package/dist/commands/status-format.d.ts.map +1 -1
  157. package/dist/commands/tag-command.d.ts +15 -1
  158. package/dist/commands/tag-command.d.ts.map +1 -1
  159. package/dist/commands/tree-restore.d.ts +14 -0
  160. package/dist/commands/tree-restore.d.ts.map +1 -1
  161. package/dist/commands/verify-command.d.ts +22 -2
  162. package/dist/commands/verify-command.d.ts.map +1 -1
  163. package/dist/commands/worktree-add-command.d.ts.map +1 -1
  164. package/dist/commands/worktree-overwrite-checks.d.ts +31 -6
  165. package/dist/commands/worktree-overwrite-checks.d.ts.map +1 -1
  166. package/dist/{commands-CPceUCP2.js → commands-DT3VEv50.js} +15168 -16842
  167. package/dist/errors/commit-errors.d.ts +37 -1
  168. package/dist/errors/commit-errors.d.ts.map +1 -1
  169. package/dist/errors/git-api-error.d.ts +6 -0
  170. package/dist/errors/git-api-error.d.ts.map +1 -1
  171. package/dist/errors/index.js +44 -3
  172. package/dist/{fsck-tbrPZX2q.js → fsck-BZ508Elg.js} +2 -2
  173. package/dist/git-command.d.ts +33 -1
  174. package/dist/git-command.d.ts.map +1 -1
  175. package/dist/git.d.ts +104 -1
  176. package/dist/git.d.ts.map +1 -1
  177. package/dist/index.js +8 -7
  178. package/dist/{remote-transport-C0OSJtor.js → local-transport-D98U6p4d.js} +228 -692
  179. package/dist/{maintenance-run-command-UiSIaeP8.js → maintenance-run-command-DZFnbnbo.js} +2366 -108
  180. package/dist/remote-config/remote-config-store.d.ts +6 -0
  181. package/dist/remote-config/remote-config-store.d.ts.map +1 -1
  182. package/dist/remote-transport-zvSqwpOB.js +4865 -0
  183. package/dist/results/cherry-pick-result.d.ts +4 -3
  184. package/dist/results/cherry-pick-result.d.ts.map +1 -1
  185. package/dist/results/diff-output.d.ts +7 -0
  186. package/dist/results/diff-output.d.ts.map +1 -1
  187. package/dist/results/diff-words.d.ts +14 -3
  188. package/dist/results/diff-words.d.ts.map +1 -1
  189. package/dist/results/index.js +1 -1
  190. package/dist/results/line-prefix-sink.d.ts +50 -0
  191. package/dist/results/line-prefix-sink.d.ts.map +1 -0
  192. package/dist/results/merge-result.d.ts +4 -3
  193. package/dist/results/merge-result.d.ts.map +1 -1
  194. package/dist/results/rebase-result.d.ts +5 -0
  195. package/dist/results/rebase-result.d.ts.map +1 -1
  196. package/dist/results/revert-result.d.ts +4 -3
  197. package/dist/results/revert-result.d.ts.map +1 -1
  198. package/dist/{results-CkS1p1CH.js → results-rF81cQse.js} +1788 -247
  199. package/dist/transport-command.d.ts +13 -0
  200. package/dist/transport-command.d.ts.map +1 -1
  201. package/package.json +21 -13
  202. package/src/commands/add-command.ts +15 -2
  203. package/src/commands/add-patch/patch-backend.ts +6 -44
  204. package/src/commands/archive/archive-command.ts +7 -3
  205. package/src/commands/archive/remote-archive-command.ts +45 -4
  206. package/src/commands/archive/upload-archive-writer.ts +34 -22
  207. package/src/commands/branch-command.ts +57 -4
  208. package/src/commands/bundle/bundle-format.ts +10 -2
  209. package/src/commands/bundle/bundle-uri-host.ts +71 -11
  210. package/src/commands/bundle/bundle-uri.ts +11 -4
  211. package/src/commands/bundle/bundle-verify.ts +4 -1
  212. package/src/commands/cat-file/batch-format.ts +17 -18
  213. package/src/commands/cat-file/cat-file-command.ts +182 -48
  214. package/src/commands/check-ignore-command.ts +110 -21
  215. package/src/commands/checkout-command.ts +149 -21
  216. package/src/commands/checkout-index-command.ts +2 -1
  217. package/src/commands/checkout-paths.ts +13 -0
  218. package/src/commands/cherry-pick-command.ts +9 -0
  219. package/src/commands/clean-interactive.ts +20 -74
  220. package/src/commands/clone-command.ts +102 -11
  221. package/src/commands/column/column-config.ts +63 -0
  222. package/src/commands/column/column-layout.ts +396 -0
  223. package/src/commands/column/index.ts +2 -0
  224. package/src/commands/column-command.ts +171 -0
  225. package/src/commands/comment-char-config.ts +42 -0
  226. package/src/commands/commit-command.ts +93 -18
  227. package/src/commands/config-command.ts +28 -0
  228. package/src/commands/credential-helper.ts +807 -0
  229. package/src/commands/default-branch.ts +57 -5
  230. package/src/commands/diff-color-config.ts +23 -10
  231. package/src/commands/diff-command.ts +25 -2
  232. package/src/commands/fast-export/fast-export-command.ts +661 -35
  233. package/src/commands/fast-export/fast-import-command.ts +694 -94
  234. package/src/commands/fast-export/fast-stream-support.ts +18 -1
  235. package/src/commands/fetch-command.ts +116 -16
  236. package/src/commands/fsck/fsck-object-checks.ts +3 -1
  237. package/src/commands/git-hooks.ts +96 -5
  238. package/src/commands/history-command.ts +952 -20
  239. package/src/commands/index-host.ts +51 -0
  240. package/src/commands/index-refresh.ts +121 -0
  241. package/src/commands/index.ts +9 -0
  242. package/src/commands/init-command.ts +57 -4
  243. package/src/commands/legacy-remotes.ts +4 -20
  244. package/src/commands/local-transport.ts +183 -18
  245. package/src/commands/log-command.ts +39 -1
  246. package/src/commands/log-output.ts +31 -4
  247. package/src/commands/ls-tree-command.ts +20 -12
  248. package/src/commands/maintenance-schedule-command.ts +418 -0
  249. package/src/commands/merge-command.ts +42 -8
  250. package/src/commands/merge-index-command.ts +202 -0
  251. package/src/commands/merge-one-file.ts +451 -0
  252. package/src/commands/merge-support.ts +169 -15
  253. package/src/commands/object-disk-info.ts +169 -0
  254. package/src/commands/octopus-merge.ts +37 -128
  255. package/src/commands/plumbing-input.ts +3 -1
  256. package/src/commands/promisor-remote-reply.ts +338 -56
  257. package/src/commands/promisor-remote.ts +39 -6
  258. package/src/commands/pull-command.ts +173 -27
  259. package/src/commands/push-command.ts +55 -6
  260. package/src/commands/range-diff/range-diff-command.ts +86 -3
  261. package/src/commands/read-tree-command.ts +2 -2
  262. package/src/commands/rebase-command.ts +46 -1
  263. package/src/commands/ref-filter/for-each-ref-command.ts +4 -3
  264. package/src/commands/ref-filter/index.ts +1 -0
  265. package/src/commands/ref-filter/peel-limit.ts +7 -0
  266. package/src/commands/ref-filter/ref-filter.ts +68 -7
  267. package/src/commands/ref-filter/ref-format.ts +85 -11
  268. package/src/commands/ref-filter/ref-listing-command.ts +30 -0
  269. package/src/commands/remote-command.ts +2 -2
  270. package/src/commands/remote-transport.ts +66 -3
  271. package/src/commands/repack-command.ts +75 -9
  272. package/src/commands/repo-command.ts +6 -70
  273. package/src/commands/reset-command.ts +11 -1
  274. package/src/commands/restore-command.ts +1 -0
  275. package/src/commands/rev-list-command.ts +205 -3
  276. package/src/commands/revert-command.ts +9 -0
  277. package/src/commands/revision-filenames.ts +32 -4
  278. package/src/commands/revision-range.ts +2 -2
  279. package/src/commands/revision-resolver.ts +21 -1
  280. package/src/commands/serve-repository.ts +42 -11
  281. package/src/commands/served-lazy-fetch.ts +164 -0
  282. package/src/commands/signing.ts +103 -12
  283. package/src/commands/split-cmdline.ts +32 -0
  284. package/src/commands/status-color-config.ts +92 -0
  285. package/src/commands/status-command.ts +50 -2
  286. package/src/commands/status-format.ts +198 -50
  287. package/src/commands/tag-command.ts +57 -2
  288. package/src/commands/tree-restore.ts +17 -0
  289. package/src/commands/verify-command.ts +84 -12
  290. package/src/commands/worktree-add-command.ts +2 -0
  291. package/src/commands/worktree-overwrite-checks.ts +75 -14
  292. package/src/errors/commit-errors.ts +52 -2
  293. package/src/errors/git-api-error.ts +7 -0
  294. package/src/git-command.ts +105 -4
  295. package/src/git.ts +153 -0
  296. package/src/remote-config/remote-config-store.ts +16 -0
  297. package/src/results/cherry-pick-result.ts +4 -3
  298. package/src/results/diff-output.ts +8 -0
  299. package/src/results/diff-words.ts +160 -32
  300. package/src/results/line-prefix-sink.ts +102 -0
  301. package/src/results/merge-result.ts +4 -3
  302. package/src/results/rebase-result.ts +5 -0
  303. package/src/results/revert-result.ts +4 -3
  304. package/src/transport-command.ts +79 -3
@@ -43,9 +43,11 @@ import type { CommandRefs, CommandTrees } from "../git-command.js";
43
43
  import { coreBool, worktreeModeTrust } from "./core-config.js";
44
44
  import type { OrtConflict } from "./ort-merge.js";
45
45
  import { markIndexUpdate } from "./post-index-change.js";
46
+ import type { RevisionResolver } from "./revision-resolver.js";
46
47
  import { pushSparseWarnings, SparseUnpack } from "./sparse-checkout-support.js";
47
48
  import type { SubmoduleUnpack } from "./submodule-unpack.js";
48
49
  import {
50
+ type CheckoutRef,
49
51
  planFlatRestore,
50
52
  planTreeRestore,
51
53
  restoreCaseOptions,
@@ -53,31 +55,54 @@ import {
53
55
  writeTreeRestorePlan,
54
56
  } from "./tree-restore.js";
55
57
  import {
58
+ belowRefused,
56
59
  type CheckedEntry,
57
60
  entryNotUptodate,
58
61
  findInTheWay,
62
+ leadingFileOf,
59
63
  overwriteMessage,
60
64
  pruneEmptyParents,
61
65
  removeCaseVariants,
66
+ takeCleanSubdirectory,
62
67
  } from "./worktree-overwrite-checks.js";
63
68
  import { firstInvalidPath, worktreePathRules } from "./worktree-path-rules.js";
64
69
 
65
70
  const sameEntry = (a: CheckedEntry | undefined, b: CheckedEntry | undefined) =>
66
71
  a === undefined || b === undefined ? a === b : a.objectId === b.objectId && a.mode === b.mode;
67
72
 
68
- /** The blobs, links and gitlinks of a tree, by path (none for no tree). */
73
+ /**
74
+ * The blobs, links and gitlinks of a tree, by path (none for no tree).
75
+ *
76
+ * @param options.asIndex The entries as unpack-trees adds them to an index
77
+ * (`add_index_entry`'s `OK_TO_REPLACE`): a file the directory of its name follows in the
78
+ * same tree (a crafted tree holding both, which fsck calls `duplicateEntries`) is dropped
79
+ * once a file of that directory is read, so the map never holds a file/directory clash
80
+ * (webrun-vcs#247)
81
+ */
69
82
  export async function flatTree(
70
83
  trees: CommandTrees,
71
84
  treeId: ObjectId | undefined,
85
+ options?: { asIndex?: boolean },
72
86
  ): Promise<Map<string, CheckedEntry>> {
73
87
  const out = new Map<string, CheckedEntry>();
74
88
  if (!treeId) return out;
75
- const walk = async (id: ObjectId, prefix: string): Promise<void> => {
89
+ const asIndex = options?.asIndex === true;
90
+ const walk = async (id: ObjectId, prefix: string): Promise<boolean> => {
91
+ let added = false;
76
92
  for await (const entry of trees.loadTree(id)) {
77
93
  const path = prefix ? `${prefix}/${entry.name}` : entry.name;
78
- if (entry.mode === FileMode.TREE) await walk(entry.id, path);
79
- else out.set(path, { objectId: entry.id, mode: entry.mode });
94
+ if (entry.mode === FileMode.TREE) {
95
+ // an empty directory adds nothing, so a file of its name stays
96
+ if (await walk(entry.id, path)) {
97
+ if (asIndex) out.delete(path);
98
+ added = true;
99
+ }
100
+ } else {
101
+ out.set(path, { objectId: entry.id, mode: entry.mode });
102
+ added = true;
103
+ }
80
104
  }
105
+ return added;
81
106
  };
82
107
  await walk(treeId, "");
83
108
  return out;
@@ -528,11 +553,24 @@ export async function updateIndexCacheTree(
528
553
  trees: CommandTrees,
529
554
  /** the repository's object format, the cache-tree's trees are hashed in */
530
555
  format: ObjectFormat,
556
+ /**
557
+ * An index no tree can hold (a file and a directory of one name) leaves the cache-tree as
558
+ * it is and gives verify_cache's lines here, as git's cache_tree_update fails and the
559
+ * command goes on (checkout); without it the update throws
560
+ */
561
+ onClash?: (lines: string[]) => void,
531
562
  ): Promise<void> {
532
563
  if (!staging.getCacheTree || !staging.setCacheTree) return;
533
564
  if (await staging.hasConflicts()) return;
534
565
  const previous = staging.getCacheTree();
535
566
  if (previous && cacheTreeFullyValid(previous)) return;
567
+ if (onClash) {
568
+ const lines = verifyCacheLines(await indexEntryList(staging));
569
+ if (lines.length > 0) {
570
+ onClash(lines);
571
+ return;
572
+ }
573
+ }
536
574
  const treeId = await staging.writeTree(trees);
537
575
  const cacheTree = await updateCacheTree(trees, treeId, previous, format);
538
576
  for (const entry of await indexEntryList(staging)) {
@@ -543,6 +581,27 @@ export async function updateIndexCacheTree(
543
581
  staging.setCacheTree(cacheTree);
544
582
  }
545
583
 
584
+ /**
585
+ * What git's `verify_cache` prints for an index of stage-0 entries holding a path and a path
586
+ * below it: one "You have both" line per such neighbouring pair in index order, at most ten,
587
+ * then "...".
588
+ */
589
+ export function verifyCacheLines(entries: readonly { path: string }[]): string[] {
590
+ const lines: string[] = [];
591
+ for (let i = 0; i + 1 < entries.length; i++) {
592
+ const name = (entries[i] as { path: string }).path;
593
+ const next = (entries[i + 1] as { path: string }).path;
594
+ if (next.length > name.length && next.startsWith(name) && next[name.length] === "/") {
595
+ if (lines.length === 10) {
596
+ lines.push("...");
597
+ break;
598
+ }
599
+ lines.push(`You have both ${name} and ${next}`);
600
+ }
601
+ }
602
+ return lines;
603
+ }
604
+
546
605
  /** Every index entry in the index's order, at once where the staging can give them so. */
547
606
  async function indexEntryList(staging: Staging): Promise<readonly IndexEntryInput[]> {
548
607
  const list = staging.entryList?.();
@@ -871,6 +930,11 @@ export async function switchTrees(
871
930
  export interface SwitchTreesOptions {
872
931
  /** Names the operation in git's refusal messages */
873
932
  action: "merge" | "checkout";
933
+ /**
934
+ * git's checkout metadata of the switch (unpack-trees' `o->meta`: the ref and commit
935
+ * checked out), handed with each file's blob to a long-running filter process
936
+ */
937
+ metadata?: CheckoutRef;
874
938
  /** Names the operation in restore failures */
875
939
  operation: string;
876
940
  /** The conflicts to stage */
@@ -971,17 +1035,60 @@ async function switchTreesWith(
971
1035
  const subs = options.submodules;
972
1036
  /** Paths whose submodule checks replace the untracked-file checks (verify_absent_1) */
973
1037
  const submodulePaths = new Set<string>();
1038
+ /**
1039
+ * Index entries git's verify_clean_subdirectory took out of the switch: the entries below a
1040
+ * directory that a new file replaces or a deletion removes (no index entry at the
1041
+ * directory's own path). Each is removed, and its own path merged as if the index lacked it.
1042
+ */
1043
+ const consumed = new Set<string>();
1044
+ /** Directories deleted_entry's verify_absent checks for untracked files */
1045
+ const absentDirs: string[] = [];
1046
+ /** Paths whose merge failed: traverse_trees enters no subtree of theirs */
1047
+ const refused = new Set<string>();
1048
+ /** The paths each refusal list holds (a path is listed once) */
1049
+ const listed = new Map<string[], Set<string>>();
1050
+ const refuse = (list: string[], path: string, at = path) => {
1051
+ let seen = listed.get(list);
1052
+ if (!seen) {
1053
+ seen = new Set(list);
1054
+ listed.set(list, seen);
1055
+ }
1056
+ if (!seen.has(at)) {
1057
+ seen.add(at);
1058
+ list.push(at);
1059
+ }
1060
+ refused.add(path);
1061
+ };
1062
+ /**
1063
+ * verify_absent of `path` (no index entry there) finding a directory: the clean index
1064
+ * entries below it are taken out, a local change refuses `path`. Whether it passed.
1065
+ */
1066
+ const cleanSubdirectory = async (path: string) => {
1067
+ const result = await takeCleanSubdirectory(
1068
+ checked as Worktree,
1069
+ path,
1070
+ index,
1071
+ consumed,
1072
+ trust,
1073
+ indexTime,
1074
+ );
1075
+ removes.push(...result.taken);
1076
+ if (result.notUptodate === undefined) return true;
1077
+ refuse(local, path, result.notUptodate);
1078
+ return false;
1079
+ };
974
1080
  const paths = [...new Set([...head.keys(), ...target.keys()])].sort();
975
1081
  for (const path of paths) {
1082
+ if (belowRefused(path, refused)) continue;
976
1083
  const h = head.get(path);
977
1084
  const t = target.get(path);
978
- const i = index.get(path);
1085
+ const i = consumed.has(path) ? undefined : index.get(path);
979
1086
  if (sameEntry(h, t) && !(options.initialCheckout && t && !i)) continue;
980
1087
  if (i) {
981
1088
  if (t && sameEntry(i, t)) continue;
982
1089
  if (!sameEntry(i, h)) {
983
1090
  // a staged change the switch would lose (reject_merge)
984
- staged.push(path);
1091
+ refuse(staged, path);
985
1092
  continue;
986
1093
  }
987
1094
  if (subs && checked && !quiet(path) && i.mode === FileMode.GITLINK) {
@@ -989,12 +1096,12 @@ async function switchTreesWith(
989
1096
  if (!t && update && (await subs.isSubmodule(path, i)) && (await subs.exists(path))) {
990
1097
  await subs.refuses(path, (h ?? i).objectId, null);
991
1098
  }
992
- const refused = await subs.notUptodate(path, i);
993
- if (refused) {
994
- local.push(path);
1099
+ const notUptodate = await subs.notUptodate(path, i);
1100
+ if (notUptodate) {
1101
+ refuse(local, path);
995
1102
  continue;
996
1103
  }
997
- if (refused === false) {
1104
+ if (notUptodate === false) {
998
1105
  if (t && t.mode !== FileMode.GITLINK) await subs.fileReplacesRefuses(path, i);
999
1106
  if (t) await subs.mergedRefuses(path, i, t);
1000
1107
  (t ? updates : removes).push(path);
@@ -1002,7 +1109,7 @@ async function switchTreesWith(
1002
1109
  }
1003
1110
  }
1004
1111
  if (checked && !quiet(path) && (await entryNotUptodate(checked, path, i, trust, indexTime))) {
1005
- local.push(path);
1112
+ refuse(local, path);
1006
1113
  continue;
1007
1114
  }
1008
1115
  if (subs && t && !quiet(path)) await subs.mergedRefuses(path, i, t);
@@ -1012,7 +1119,7 @@ async function switchTreesWith(
1012
1119
  if (t) {
1013
1120
  // a staged deletion of a path the target changes (none in an initial checkout)
1014
1121
  if (h && !options.initialCheckout) {
1015
- staged.push(path);
1122
+ refuse(staged, path);
1016
1123
  continue;
1017
1124
  }
1018
1125
  if (subs && !quiet(path)) {
@@ -1021,11 +1128,39 @@ async function switchTreesWith(
1021
1128
  if (absent !== undefined) submodulePaths.add(path);
1022
1129
  if (!absent) await subs.mergedRefuses(path, undefined, t);
1023
1130
  }
1131
+ // merged_entry's verify_absent: a directory here loses the index entries below it
1132
+ if (worktree && !quiet(path) && t.mode !== FileMode.GITLINK) {
1133
+ const there = await worktree.getEntry(path);
1134
+ if (there?.isDirectory && !(await cleanSubdirectory(path))) continue;
1135
+ }
1024
1136
  updates.push(path);
1025
1137
  continue;
1026
1138
  }
1027
- // a deletion already staged: an untracked file there would be removed
1028
- if (worktree && (await untrackedFileAt(worktree, path))) untrackedRemoved.push(path);
1139
+ if (!worktree || quiet(path)) continue;
1140
+ // a deletion already staged (deleted_entry's verify_absent)
1141
+ const there = await worktree.getEntry(path);
1142
+ if (there?.isDirectory) {
1143
+ if (h?.mode !== FileMode.GITLINK && (await cleanSubdirectory(path))) absentDirs.push(path);
1144
+ continue;
1145
+ }
1146
+ if (there) {
1147
+ // an untracked file there would be removed (check_ok_to_remove: not a file the result
1148
+ // removes, as one verify_clean_subdirectory took out)
1149
+ if (!consumed.has(path) && (await untrackedFileAt(worktree, path))) {
1150
+ refuse(untrackedRemoved, path);
1151
+ }
1152
+ continue;
1153
+ }
1154
+ // a file among its leading directories is removed too (check_leading_path, then
1155
+ // check_ok_to_remove): only an ignored one, or one the switch deletes, may go
1156
+ const leading = await leadingFileOf(worktree, path);
1157
+ if (
1158
+ leading !== undefined &&
1159
+ !(index.has(leading) && (consumed.has(leading) || removes.includes(leading))) &&
1160
+ !(await worktree.isIgnored(leading))
1161
+ ) {
1162
+ refuse(untrackedRemoved, path, leading);
1163
+ }
1029
1164
  }
1030
1165
  // a dirty file the target deletes is reported as a local change only (git's
1031
1166
  // verify_clean_subdirectory counts tracked files under a replaced directory as such)
@@ -1034,7 +1169,8 @@ async function switchTreesWith(
1034
1169
  const writing = new Set(updates.filter((p) => !sparse || sparse.writes(p)));
1035
1170
  const found = worktree
1036
1171
  ? await findInTheWay(worktree, {
1037
- writes: [...writing].filter((p) => !submodulePaths.has(p)),
1172
+ // deleted_entry's directories are checked as a file written there would check them
1173
+ writes: [...[...writing].filter((p) => !submodulePaths.has(p)), ...absentDirs],
1038
1174
  removes: new Set(deleting),
1039
1175
  index,
1040
1176
  ...(await restoreCaseOptions(worktree, ignoreCase)),
@@ -1177,6 +1313,7 @@ async function switchTreesWith(
1177
1313
  replaceInTheWay: true,
1178
1314
  attributes: { direction: "checkout", index: attributesIndexOf(result) },
1179
1315
  progress,
1316
+ ...(options.metadata ? { metadata: options.metadata } : {}),
1180
1317
  },
1181
1318
  );
1182
1319
  }
@@ -1334,3 +1471,20 @@ export function subjectOf(message: string): string {
1334
1471
  for (; i < lines.length && lines[i] !== ""; i++) subject.push(lines[i] as string);
1335
1472
  return subject.join(" ");
1336
1473
  }
1474
+
1475
+ /**
1476
+ * MERGE_HEAD's entries as commits (git's `read_merge_heads` → `lookup_commit_reference`): a
1477
+ * merged annotated tag is written by its own id (`write_merge_heads`) and peeled when read;
1478
+ * an entry that peels to no commit is kept as written.
1479
+ */
1480
+ export async function peelMergeHeads(
1481
+ resolver: Pick<RevisionResolver, "peelTags">,
1482
+ ids: ObjectId[],
1483
+ ): Promise<ObjectId[]> {
1484
+ const out: ObjectId[] = [];
1485
+ for (const id of ids) {
1486
+ const peeled = await resolver.peelTags(id).catch(() => undefined);
1487
+ out.push(peeled?.type === "commit" ? peeled.id : id);
1488
+ }
1489
+ return out;
1490
+ }
@@ -0,0 +1,169 @@
1
+ /**
2
+ * What an object takes on disk, as git's `odb_read_object_info_extended` reports it through
3
+ * `disk_sizep`: a packed object's entry (from its offset to the next entry's, or to the pack's
4
+ * trailer for the last), else its loose file's size. Packs are asked first (the repository's
5
+ * own in the pack set's lookup order, then its alternates'), then the loose files (its own,
6
+ * then its alternates'), as git's `oid_object_info_extended` looks objects up.
7
+ *
8
+ * `git repo structure` (its disk sizes), `git rev-list --disk-usage`, and the
9
+ * `%(objectsize:disk)`/`%(deltabase)` atoms of `cat-file` and the ref filter share it.
10
+ */
11
+
12
+ import {
13
+ joinPath,
14
+ type ObjectId,
15
+ objectFormatOf,
16
+ type Pack,
17
+ packNameOf,
18
+ } from "@statewalker/vcs-core";
19
+ import type { WorkingCopy } from "@statewalker/vcs-working-tree";
20
+ import { commonGitFileOf } from "./git-hooks.js";
21
+
22
+ interface OffsetPack extends Pack {
23
+ indexOf?(id: ObjectId): number;
24
+ offsetAt?(i: number): number;
25
+ }
26
+
27
+ /** The on-disk measures of a repository's objects. */
28
+ export interface ObjectDiskInfo {
29
+ /** The bytes `id` takes on disk; undefined when neither a pack nor a loose file holds it. */
30
+ diskSize(id: ObjectId): Promise<number | undefined>;
31
+ /**
32
+ * `delta_base_oid`: the base of `id`'s pack entry when it is stored as a delta (an
33
+ * OFS_DELTA's base named through the idx, a REF_DELTA's as written), read from the entry's
34
+ * header (the delta is never applied); the format's null id for a whole entry or a loose
35
+ * object; undefined when neither a pack nor a loose file holds it.
36
+ */
37
+ deltaBase(id: ObjectId): Promise<ObjectId | undefined>;
38
+ }
39
+
40
+ /**
41
+ * The on-disk measures of the objects of `workingCopy`'s object directory and its alternates.
42
+ *
43
+ * @example
44
+ * ```typescript
45
+ * const info = await objectDiskInfoOf(workingCopy);
46
+ * const bytes = (await info.diskSize(id)) ?? 0;
47
+ * ```
48
+ */
49
+ export async function objectDiskInfoOf(workingCopy: WorkingCopy): Promise<ObjectDiskInfo> {
50
+ const objectsFile = await commonGitFileOf(workingCopy, "objects");
51
+ const packSet = workingCopy.history.packs;
52
+ const packs: OffsetPack[] = [];
53
+ /** The objects directory of each pack and of each loose source, own first */
54
+ const packDirs = new Map<OffsetPack, string>();
55
+ const looseDirs: string[] = [];
56
+ /**
57
+ * Reads the pack lists (again): a lazy fetch of a partial clone installs a new pack while a
58
+ * command runs, as git's `reprepare_packed_git` after a miss.
59
+ */
60
+ const loadPacks = async (rescan = false): Promise<void> => {
61
+ const add = (pack: OffsetPack, dir: string) => {
62
+ if (packDirs.has(pack)) return;
63
+ packs.push(pack);
64
+ packDirs.set(pack, dir);
65
+ };
66
+ if (!objectsFile) return;
67
+ if (rescan) await packSet?.refresh().catch(() => false);
68
+ for (const pack of ((await packSet?.packs().catch(() => [])) ?? []) as OffsetPack[]) {
69
+ add(pack, objectsFile.path);
70
+ }
71
+ const alternates =
72
+ (await workingCopy.history.objects?.alternates?.list().catch(() => [])) ?? [];
73
+ for (const alternate of alternates) {
74
+ if (rescan) await alternate.packs.refresh().catch(() => false);
75
+ for (const pack of ((await alternate.packs.packs().catch(() => [])) ?? []) as OffsetPack[]) {
76
+ add(pack, alternate.objectsDir);
77
+ }
78
+ if (!looseDirs.includes(alternate.objectsDir)) looseDirs.push(alternate.objectsDir);
79
+ }
80
+ };
81
+ if (objectsFile) looseDirs.push(objectsFile.path);
82
+ await loadPacks();
83
+ const format = objectFormatOf(workingCopy.history.objects);
84
+ const trailer = format.rawLength;
85
+ const sorted = new Map<OffsetPack, Float64Array>();
86
+ const packSizes = new Map<OffsetPack, number>();
87
+ const offsetsOf = (pack: OffsetPack): Float64Array => {
88
+ let offsets = sorted.get(pack);
89
+ if (!offsets) {
90
+ offsets = new Float64Array(pack.count);
91
+ for (let i = 0; i < pack.count; i++) offsets[i] = pack.offsetAt?.(i) ?? 0;
92
+ offsets.sort();
93
+ sorted.set(pack, offsets);
94
+ }
95
+ return offsets;
96
+ };
97
+ const packSizeOf = async (pack: OffsetPack): Promise<number> => {
98
+ let size = packSizes.get(pack);
99
+ if (size === undefined) {
100
+ size = 0;
101
+ const dir = packDirs.get(pack);
102
+ if (objectsFile && dir !== undefined) {
103
+ const path = joinPath(dir, "pack", `${packNameOf(pack)}.pack`);
104
+ size = (await objectsFile.files.stats(path))?.size ?? 0;
105
+ }
106
+ packSizes.set(pack, size);
107
+ }
108
+ return size;
109
+ };
110
+ /** The pack holding `id` (the first in lookup order) and the entry's offset. */
111
+ const packedIn = (id: ObjectId): { pack: OffsetPack; offset: number } | undefined => {
112
+ for (const pack of packs) {
113
+ if (!pack.has(id) || !pack.indexOf || !pack.offsetAt) continue;
114
+ const index = pack.indexOf(id);
115
+ if (index < 0) continue;
116
+ return { pack, offset: pack.offsetAt(index) };
117
+ }
118
+ return undefined;
119
+ };
120
+ const looseSize = async (id: ObjectId): Promise<number | undefined> => {
121
+ for (const dir of looseDirs) {
122
+ const path = joinPath(dir, id.slice(0, 2), id.slice(2));
123
+ const stats = await objectsFile?.files.stats(path).catch(() => undefined);
124
+ if (stats?.kind === "file") return stats.size;
125
+ }
126
+ return undefined;
127
+ };
128
+ type Located = { packed: { pack: OffsetPack; offset: number } } | { loose: number } | undefined;
129
+ /** Where `id` is stored: packs first, then loose files, the pack lists reread on a miss. */
130
+ const locate = async (id: ObjectId): Promise<Located> => {
131
+ for (let pass = 0; pass < 2; pass++) {
132
+ const packed = packedIn(id);
133
+ if (packed) return { packed };
134
+ const loose = await looseSize(id);
135
+ if (loose !== undefined) return { loose };
136
+ if (pass === 0) await loadPacks(true);
137
+ }
138
+ return undefined;
139
+ };
140
+ return {
141
+ async diskSize(id) {
142
+ const where = await locate(id);
143
+ if (!where) return undefined;
144
+ if ("loose" in where) return where.loose;
145
+ const { pack, offset } = where.packed;
146
+ const offsets = offsetsOf(pack);
147
+ let lo = 0;
148
+ let hi = offsets.length;
149
+ while (lo < hi) {
150
+ const mid = (lo + hi) >> 1;
151
+ if ((offsets[mid] as number) <= offset) lo = mid + 1;
152
+ else hi = mid;
153
+ }
154
+ // the last entry ends at the trailer (the pack's checksum, one raw id long)
155
+ const next =
156
+ lo < offsets.length ? (offsets[lo] as number) : (await packSizeOf(pack)) - trailer;
157
+ return next - offset;
158
+ },
159
+ async deltaBase(id) {
160
+ const where = await locate(id);
161
+ if (!where) return undefined;
162
+ if ("packed" in where) {
163
+ const entry = await where.packed.pack.entry(id);
164
+ if (entry && (entry.kind === 6 || entry.kind === 7)) return entry.baseId;
165
+ }
166
+ return format.nullId;
167
+ },
168
+ };
169
+ }
@@ -10,14 +10,14 @@
10
10
  * the strategy gave up, leaves everything as it was (git's restore_state).
11
11
  */
12
12
 
13
- import { type Blobs, EMPTY_BLOB_ID, type ObjectId } from "@statewalker/vcs-core";
14
- import { type ConflictStyle, mergeLines } from "@statewalker/vcs-utils";
13
+ import type { Blobs, ObjectId } from "@statewalker/vcs-core";
14
+ import type { ConflictStyle } from "@statewalker/vcs-utils";
15
15
 
16
16
  import type { CommandCommits, CommandTrees } from "../git-command.js";
17
- import { isBinaryContent } from "../rename/index.js";
18
17
  import { commitsBaseSource, MergeBaseGraph } from "./merge-bases.js";
18
+ import { planOneFile } from "./merge-one-file.js";
19
19
  import { flatTree } from "./merge-support.js";
20
- import { type OrtConflict, readBlob } from "./ort-merge.js";
20
+ import type { OrtConflict } from "./ort-merge.js";
21
21
  import type { CheckedEntry } from "./worktree-overwrite-checks.js";
22
22
 
23
23
  /** A head to merge and the name git's messages give it (as the user named it). */
@@ -263,140 +263,49 @@ async function mergeOneFile(
263
263
  tempName: () => string,
264
264
  ): Promise<boolean> {
265
265
  const { path, base: o, ours: a, theirs: b } = s;
266
- const leave = () => {
266
+ const plan = await planOneFile(
267
+ { blobs: ctx.blobs, style: ctx.style, tempName },
268
+ {
269
+ path,
270
+ ids: [o?.objectId ?? "", a?.objectId ?? "", b?.objectId ?? ""],
271
+ modes: [octal(o), octal(a), octal(b)],
272
+ },
273
+ );
274
+ output.push(...plan.output);
275
+ const leave = (tree?: CheckedEntry) => {
267
276
  conflicts.push({
268
277
  stagePath: path,
269
278
  mode: (a ?? b ?? o)?.mode ?? 0,
270
279
  ...(o ? { base: o } : {}),
271
280
  ...(a ? { ours: a } : {}),
272
281
  ...(b ? { theirs: b } : {}),
273
- ...(a ? { tree: a } : {}),
282
+ ...((tree ?? a) ? { tree: tree ?? a } : {}),
274
283
  });
275
- // the worktree keeps what it had (ours)
276
- if (a) worktree.set(path, a);
284
+ // the worktree keeps what it had (ours), or holds the merge's result
285
+ const kept = tree ?? a;
286
+ if (kept) worktree.set(path, kept);
277
287
  return false;
278
288
  };
279
- const [m1, m2, m3] = [octal(o), octal(a), octal(b)];
280
- // deleted in both, or deleted in one and unchanged in the other
281
- if (
282
- o &&
283
- ((!a && !b) || (!a && b?.objectId === o.objectId) || (!b && a?.objectId === o.objectId))
284
- ) {
285
- if ((!a && m1 !== m3) || (!b && m1 !== m2)) {
286
- errors.push(
287
- `ERROR: File ${path} deleted on one branch but had its`,
288
- "ERROR: permissions changed on the other.",
289
- );
290
- return leave();
291
- }
292
- if (a) output.push(`Removing ${path}`);
293
- return true;
294
- }
295
- if (!o && a && !b) {
296
- index.set(path, a);
297
- return true;
298
- }
299
- if (!o && !a && b) {
300
- output.push(`Adding ${path}`);
301
- index.set(path, b);
302
- return true;
303
- }
304
- if (!o && a && b && a.objectId === b.objectId) {
305
- if (m2 !== m3) {
306
- errors.push(
307
- `ERROR: File ${path} added identically in both branches,`,
308
- `ERROR: but permissions conflict ${m2}->${m3}.`,
309
- );
310
- return leave();
311
- }
312
- output.push(`Adding ${path}`);
313
- index.set(path, a);
314
- return true;
315
- }
316
- if (a && b) {
317
- if (m2 === "120000" || m3 === "120000") {
318
- errors.push(`ERROR: ${path}: Not merging symbolic link changes.`);
289
+ switch (plan.kind) {
290
+ case "fail":
291
+ errors.push(...plan.errors);
319
292
  return leave();
293
+ case "remove":
294
+ return true;
295
+ case "add":
296
+ index.set(path, { objectId: plan.id, mode: Number.parseInt(plan.mode, 8) });
297
+ return true;
298
+ case "merge": {
299
+ errors.push(...plan.errors);
300
+ const objectId = plan.contentId ?? (await ctx.blobs.store([plan.content]));
301
+ // the worktree file: ours (its mode), holding the merge's result
302
+ const result = { objectId, mode: (a as CheckedEntry).mode };
303
+ if (plan.message) {
304
+ errors.push(`ERROR: ${plan.message} in ${path}`);
305
+ return leave(result);
306
+ }
307
+ index.set(path, result);
308
+ return true;
320
309
  }
321
- if (m2 === "160000" || m3 === "160000") {
322
- errors.push(`ERROR: ${path}: Not merging conflicting submodule changes.`);
323
- return leave();
324
- }
325
- const [n1, n2] = [tempName(), tempName()];
326
- output.push(o ? `Auto-merging ${path}` : `Added ${path} in both, but differently.`);
327
- const emptyBlob = ctx.blobs.objectFormat?.emptyBlobId ?? EMPTY_BLOB_ID;
328
- if (!o && !(await ctx.blobs.has(emptyBlob))) {
329
- // the script's base is the empty blob, which `hash-object` never stored: unpack-file
330
- // and merge-file fail, ours stays in the worktree
331
- errors.push(
332
- `fatal: unable to read blob object ${emptyBlob}`,
333
- "error: Could not stat : No such file or directory",
334
- `ERROR: content conflict in ${path}`,
335
- );
336
- return leave();
337
- }
338
- const nO = tempName();
339
- const contents = {
340
- ours: await readBlob(ctx.blobs, a.objectId),
341
- base: o ? await readBlob(ctx.blobs, o.objectId) : new Uint8Array(0),
342
- theirs: await readBlob(ctx.blobs, b.objectId),
343
- };
344
- // `git merge-file` reads its three files in order and stops at the first binary one
345
- // ("Cannot merge binary files: <its temporary name>"), leaving ours in the worktree
346
- const binary = (
347
- [
348
- [contents.ours, n1],
349
- [contents.base, nO],
350
- [contents.theirs, n2],
351
- ] as const
352
- ).find(([content]) => isBinaryContent(content));
353
- if (binary) {
354
- errors.push(`error: Cannot merge binary files: ${binary[1]}`);
355
- let msg = "content conflict";
356
- if (m2 !== m3) msg = `${msg}, permissions conflict: ${m1}->${m2},${m3}`;
357
- errors.push(`ERROR: ${msg} in ${path}`);
358
- conflicts.push({
359
- stagePath: path,
360
- mode: a.mode,
361
- ...(o ? { base: o } : {}),
362
- ours: a,
363
- theirs: b,
364
- tree: a,
365
- });
366
- worktree.set(path, a);
367
- return false;
368
- }
369
- const merged = mergeLines(contents.base, contents.ours, contents.theirs, {
370
- oursLabel: n1,
371
- baseLabel: nO,
372
- theirsLabel: n2,
373
- style: ctx.style,
374
- algorithm: "myers",
375
- level: "zealous-alnum",
376
- });
377
- const objectId = await ctx.blobs.store([merged.content]);
378
- // the worktree file: ours (its mode), holding the merge's result
379
- const result = { objectId, mode: a.mode };
380
- let msg = merged.conflicts > 0 || !o ? "content conflict" : "";
381
- if (m2 !== m3) msg = `${msg ? `${msg}, ` : ""}permissions conflict: ${m1}->${m2},${m3}`;
382
- if (msg) {
383
- errors.push(`ERROR: ${msg} in ${path}`);
384
- conflicts.push({
385
- stagePath: path,
386
- mode: a.mode,
387
- ...(o ? { base: o } : {}),
388
- ours: a,
389
- theirs: b,
390
- tree: result,
391
- });
392
- worktree.set(path, result);
393
- return false;
394
- }
395
- index.set(path, result);
396
- return true;
397
310
  }
398
- errors.push(
399
- `ERROR: ${path}: Not handling case ${o?.objectId ?? ""} -> ${a?.objectId ?? ""} -> ${b?.objectId ?? ""}`,
400
- );
401
- return leave();
402
311
  }
@@ -31,7 +31,9 @@ export function inputRecords(
31
31
  if (!nul && line[0] === 0x22) {
32
32
  const unquoted = unquoteGitPath(line, 0);
33
33
  if (!unquoted) return { records, badlyQuoted: true };
34
- records.push(unquoted.path);
34
+ // the caller reads the strbuf as a C string: an unquoted `\000` ends the path
35
+ const nul = unquoted.path.indexOf("\0");
36
+ records.push(nul < 0 ? unquoted.path : unquoted.path.slice(0, nul));
35
37
  } else records.push(decodeGitPath(line));
36
38
  }
37
39
  return { records, badlyQuoted: false };