@statewalker/vcs-commands 0.14.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 (265) 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/remote-archive-command.d.ts +4 -1
  5. package/dist/commands/archive/remote-archive-command.d.ts.map +1 -1
  6. package/dist/commands/branch-command.d.ts +14 -2
  7. package/dist/commands/branch-command.d.ts.map +1 -1
  8. package/dist/commands/cat-file/batch-format.d.ts +8 -12
  9. package/dist/commands/cat-file/batch-format.d.ts.map +1 -1
  10. package/dist/commands/cat-file/cat-file-command.d.ts +39 -5
  11. package/dist/commands/cat-file/cat-file-command.d.ts.map +1 -1
  12. package/dist/commands/check-ignore-command.d.ts.map +1 -1
  13. package/dist/commands/checkout-command.d.ts +4 -0
  14. package/dist/commands/checkout-command.d.ts.map +1 -1
  15. package/dist/commands/checkout-paths.d.ts +9 -0
  16. package/dist/commands/checkout-paths.d.ts.map +1 -1
  17. package/dist/commands/cherry-pick-command.d.ts +3 -0
  18. package/dist/commands/cherry-pick-command.d.ts.map +1 -1
  19. package/dist/commands/clean-interactive.d.ts +0 -9
  20. package/dist/commands/clean-interactive.d.ts.map +1 -1
  21. package/dist/commands/clone-command.d.ts +2 -0
  22. package/dist/commands/clone-command.d.ts.map +1 -1
  23. package/dist/commands/column/column-config.d.ts +23 -0
  24. package/dist/commands/column/column-config.d.ts.map +1 -0
  25. package/dist/commands/column/column-layout.d.ts +129 -0
  26. package/dist/commands/column/column-layout.d.ts.map +1 -0
  27. package/dist/commands/column/index.d.ts +3 -0
  28. package/dist/commands/column/index.d.ts.map +1 -0
  29. package/dist/commands/column-command.d.ts +59 -0
  30. package/dist/commands/column-command.d.ts.map +1 -0
  31. package/dist/commands/comment-char-config.d.ts +15 -0
  32. package/dist/commands/comment-char-config.d.ts.map +1 -1
  33. package/dist/commands/commit-command.d.ts +21 -2
  34. package/dist/commands/commit-command.d.ts.map +1 -1
  35. package/dist/commands/config-command.d.ts +12 -0
  36. package/dist/commands/config-command.d.ts.map +1 -1
  37. package/dist/commands/credential-helper.d.ts +214 -0
  38. package/dist/commands/credential-helper.d.ts.map +1 -0
  39. package/dist/commands/default-branch.d.ts +17 -1
  40. package/dist/commands/default-branch.d.ts.map +1 -1
  41. package/dist/commands/diff-color-config.d.ts +4 -0
  42. package/dist/commands/diff-color-config.d.ts.map +1 -1
  43. package/dist/commands/diff-command.d.ts +12 -0
  44. package/dist/commands/diff-command.d.ts.map +1 -1
  45. package/dist/commands/fast-export/fast-export-command.d.ts +89 -2
  46. package/dist/commands/fast-export/fast-export-command.d.ts.map +1 -1
  47. package/dist/commands/fast-export/fast-import-command.d.ts +113 -8
  48. package/dist/commands/fast-export/fast-import-command.d.ts.map +1 -1
  49. package/dist/commands/fast-export/fast-stream-support.d.ts +0 -9
  50. package/dist/commands/fast-export/fast-stream-support.d.ts.map +1 -1
  51. package/dist/commands/fetch-command.d.ts +21 -0
  52. package/dist/commands/fetch-command.d.ts.map +1 -1
  53. package/dist/commands/git-hooks.d.ts +28 -0
  54. package/dist/commands/git-hooks.d.ts.map +1 -1
  55. package/dist/commands/history-command.d.ts +173 -7
  56. package/dist/commands/history-command.d.ts.map +1 -1
  57. package/dist/commands/index-host.d.ts +19 -0
  58. package/dist/commands/index-host.d.ts.map +1 -1
  59. package/dist/commands/index-refresh.d.ts +36 -0
  60. package/dist/commands/index-refresh.d.ts.map +1 -0
  61. package/dist/commands/index.d.ts +9 -0
  62. package/dist/commands/index.d.ts.map +1 -1
  63. package/dist/commands/index.js +7 -6
  64. package/dist/commands/init-command.d.ts +20 -0
  65. package/dist/commands/init-command.d.ts.map +1 -1
  66. package/dist/commands/local-transport.d.ts +29 -1
  67. package/dist/commands/local-transport.d.ts.map +1 -1
  68. package/dist/commands/log-command.d.ts +7 -0
  69. package/dist/commands/log-command.d.ts.map +1 -1
  70. package/dist/commands/log-output.d.ts +11 -0
  71. package/dist/commands/log-output.d.ts.map +1 -1
  72. package/dist/commands/maintenance-schedule-command.d.ts +122 -0
  73. package/dist/commands/maintenance-schedule-command.d.ts.map +1 -0
  74. package/dist/commands/merge-command.d.ts +2 -0
  75. package/dist/commands/merge-command.d.ts.map +1 -1
  76. package/dist/commands/merge-index-command.d.ts +42 -0
  77. package/dist/commands/merge-index-command.d.ts.map +1 -0
  78. package/dist/commands/merge-one-file.d.ts +129 -0
  79. package/dist/commands/merge-one-file.d.ts.map +1 -0
  80. package/dist/commands/merge-support.d.ts +21 -2
  81. package/dist/commands/merge-support.d.ts.map +1 -1
  82. package/dist/commands/object-disk-info.d.ts +35 -0
  83. package/dist/commands/object-disk-info.d.ts.map +1 -0
  84. package/dist/commands/octopus-merge.d.ts +3 -3
  85. package/dist/commands/octopus-merge.d.ts.map +1 -1
  86. package/dist/commands/promisor-remote.d.ts.map +1 -1
  87. package/dist/commands/pull-command.d.ts +55 -7
  88. package/dist/commands/pull-command.d.ts.map +1 -1
  89. package/dist/commands/push-command.d.ts +18 -1
  90. package/dist/commands/push-command.d.ts.map +1 -1
  91. package/dist/commands/range-diff/range-diff-command.d.ts +37 -1
  92. package/dist/commands/range-diff/range-diff-command.d.ts.map +1 -1
  93. package/dist/commands/rebase-command.d.ts +13 -1
  94. package/dist/commands/rebase-command.d.ts.map +1 -1
  95. package/dist/commands/ref-filter/for-each-ref-command.d.ts +3 -2
  96. package/dist/commands/ref-filter/for-each-ref-command.d.ts.map +1 -1
  97. package/dist/commands/ref-filter/ref-filter.d.ts.map +1 -1
  98. package/dist/commands/ref-filter/ref-format.d.ts +26 -1
  99. package/dist/commands/ref-filter/ref-format.d.ts.map +1 -1
  100. package/dist/commands/ref-filter/ref-listing-command.d.ts +9 -0
  101. package/dist/commands/ref-filter/ref-listing-command.d.ts.map +1 -1
  102. package/dist/commands/remote-transport.d.ts +27 -0
  103. package/dist/commands/remote-transport.d.ts.map +1 -1
  104. package/dist/commands/repack-command.d.ts +18 -2
  105. package/dist/commands/repack-command.d.ts.map +1 -1
  106. package/dist/commands/repo-command.d.ts +2 -7
  107. package/dist/commands/repo-command.d.ts.map +1 -1
  108. package/dist/commands/reset-command.d.ts +4 -1
  109. package/dist/commands/reset-command.d.ts.map +1 -1
  110. package/dist/commands/restore-command.d.ts.map +1 -1
  111. package/dist/commands/rev-list-command.d.ts +65 -0
  112. package/dist/commands/rev-list-command.d.ts.map +1 -1
  113. package/dist/commands/revert-command.d.ts +3 -0
  114. package/dist/commands/revert-command.d.ts.map +1 -1
  115. package/dist/commands/revision-filenames.d.ts.map +1 -1
  116. package/dist/commands/revision-range.d.ts +17 -0
  117. package/dist/commands/revision-range.d.ts.map +1 -1
  118. package/dist/commands/revision-resolver.d.ts +12 -0
  119. package/dist/commands/revision-resolver.d.ts.map +1 -1
  120. package/dist/commands/serve-repository.d.ts +17 -1
  121. package/dist/commands/serve-repository.d.ts.map +1 -1
  122. package/dist/commands/served-lazy-fetch.d.ts +61 -0
  123. package/dist/commands/served-lazy-fetch.d.ts.map +1 -0
  124. package/dist/commands/signing.d.ts +10 -4
  125. package/dist/commands/signing.d.ts.map +1 -1
  126. package/dist/commands/status-color-config.d.ts +33 -0
  127. package/dist/commands/status-color-config.d.ts.map +1 -0
  128. package/dist/commands/status-command.d.ts +15 -0
  129. package/dist/commands/status-command.d.ts.map +1 -1
  130. package/dist/commands/status-format.d.ts +46 -4
  131. package/dist/commands/status-format.d.ts.map +1 -1
  132. package/dist/commands/tag-command.d.ts +15 -1
  133. package/dist/commands/tag-command.d.ts.map +1 -1
  134. package/dist/commands/tree-restore.d.ts +14 -0
  135. package/dist/commands/tree-restore.d.ts.map +1 -1
  136. package/dist/commands/verify-command.d.ts +22 -2
  137. package/dist/commands/verify-command.d.ts.map +1 -1
  138. package/dist/commands/worktree-add-command.d.ts.map +1 -1
  139. package/dist/commands/worktree-overwrite-checks.d.ts +31 -6
  140. package/dist/commands/worktree-overwrite-checks.d.ts.map +1 -1
  141. package/dist/{commands-C9M78Chn.js → commands-DT3VEv50.js} +14879 -16703
  142. package/dist/errors/commit-errors.d.ts +23 -3
  143. package/dist/errors/commit-errors.d.ts.map +1 -1
  144. package/dist/errors/git-api-error.d.ts +6 -0
  145. package/dist/errors/git-api-error.d.ts.map +1 -1
  146. package/dist/errors/index.js +30 -4
  147. package/dist/{fsck-C4US3l0B.js → fsck-BZ508Elg.js} +1 -1
  148. package/dist/git-command.d.ts +33 -1
  149. package/dist/git-command.d.ts.map +1 -1
  150. package/dist/git.d.ts +104 -1
  151. package/dist/git.d.ts.map +1 -1
  152. package/dist/index.js +8 -7
  153. package/dist/{remote-transport-C43eykfK.js → local-transport-D98U6p4d.js} +184 -683
  154. package/dist/{maintenance-run-command-CoJFKr2p.js → maintenance-run-command-DZFnbnbo.js} +2285 -79
  155. package/dist/remote-config/remote-config-store.d.ts +6 -0
  156. package/dist/remote-config/remote-config-store.d.ts.map +1 -1
  157. package/dist/remote-transport-zvSqwpOB.js +4865 -0
  158. package/dist/results/cherry-pick-result.d.ts +4 -3
  159. package/dist/results/cherry-pick-result.d.ts.map +1 -1
  160. package/dist/results/diff-output.d.ts +7 -0
  161. package/dist/results/diff-output.d.ts.map +1 -1
  162. package/dist/results/diff-words.d.ts +14 -3
  163. package/dist/results/diff-words.d.ts.map +1 -1
  164. package/dist/results/index.js +1 -1
  165. package/dist/results/line-prefix-sink.d.ts +50 -0
  166. package/dist/results/line-prefix-sink.d.ts.map +1 -0
  167. package/dist/results/merge-result.d.ts +4 -3
  168. package/dist/results/merge-result.d.ts.map +1 -1
  169. package/dist/results/rebase-result.d.ts +5 -0
  170. package/dist/results/rebase-result.d.ts.map +1 -1
  171. package/dist/results/revert-result.d.ts +4 -3
  172. package/dist/results/revert-result.d.ts.map +1 -1
  173. package/dist/{results-B0CWLCAp.js → results-rF81cQse.js} +1425 -202
  174. package/dist/transport-command.d.ts +10 -0
  175. package/dist/transport-command.d.ts.map +1 -1
  176. package/package.json +12 -12
  177. package/src/commands/add-command.ts +15 -2
  178. package/src/commands/add-patch/patch-backend.ts +6 -44
  179. package/src/commands/archive/remote-archive-command.ts +10 -3
  180. package/src/commands/branch-command.ts +57 -4
  181. package/src/commands/cat-file/batch-format.ts +17 -18
  182. package/src/commands/cat-file/cat-file-command.ts +181 -15
  183. package/src/commands/check-ignore-command.ts +61 -17
  184. package/src/commands/checkout-command.ts +149 -21
  185. package/src/commands/checkout-index-command.ts +2 -1
  186. package/src/commands/checkout-paths.ts +13 -0
  187. package/src/commands/cherry-pick-command.ts +9 -0
  188. package/src/commands/clean-interactive.ts +20 -74
  189. package/src/commands/clone-command.ts +13 -0
  190. package/src/commands/column/column-config.ts +63 -0
  191. package/src/commands/column/column-layout.ts +396 -0
  192. package/src/commands/column/index.ts +2 -0
  193. package/src/commands/column-command.ts +171 -0
  194. package/src/commands/comment-char-config.ts +42 -0
  195. package/src/commands/commit-command.ts +61 -21
  196. package/src/commands/config-command.ts +28 -0
  197. package/src/commands/credential-helper.ts +807 -0
  198. package/src/commands/default-branch.ts +38 -0
  199. package/src/commands/diff-color-config.ts +23 -10
  200. package/src/commands/diff-command.ts +25 -2
  201. package/src/commands/fast-export/fast-export-command.ts +661 -35
  202. package/src/commands/fast-export/fast-import-command.ts +694 -94
  203. package/src/commands/fast-export/fast-stream-support.ts +18 -1
  204. package/src/commands/fetch-command.ts +103 -14
  205. package/src/commands/git-hooks.ts +85 -0
  206. package/src/commands/history-command.ts +952 -20
  207. package/src/commands/index-host.ts +51 -0
  208. package/src/commands/index-refresh.ts +121 -0
  209. package/src/commands/index.ts +9 -0
  210. package/src/commands/init-command.ts +34 -1
  211. package/src/commands/legacy-remotes.ts +4 -20
  212. package/src/commands/local-transport.ts +130 -9
  213. package/src/commands/log-command.ts +39 -1
  214. package/src/commands/log-output.ts +31 -4
  215. package/src/commands/maintenance-schedule-command.ts +418 -0
  216. package/src/commands/merge-command.ts +10 -0
  217. package/src/commands/merge-index-command.ts +202 -0
  218. package/src/commands/merge-one-file.ts +451 -0
  219. package/src/commands/merge-support.ts +127 -11
  220. package/src/commands/object-disk-info.ts +169 -0
  221. package/src/commands/octopus-merge.ts +37 -128
  222. package/src/commands/promisor-remote.ts +14 -3
  223. package/src/commands/pull-command.ts +173 -27
  224. package/src/commands/push-command.ts +50 -5
  225. package/src/commands/range-diff/range-diff-command.ts +86 -3
  226. package/src/commands/rebase-command.ts +46 -1
  227. package/src/commands/ref-filter/for-each-ref-command.ts +4 -3
  228. package/src/commands/ref-filter/ref-filter.ts +59 -4
  229. package/src/commands/ref-filter/ref-format.ts +83 -10
  230. package/src/commands/ref-filter/ref-listing-command.ts +30 -0
  231. package/src/commands/remote-command.ts +2 -2
  232. package/src/commands/remote-transport.ts +66 -3
  233. package/src/commands/repack-command.ts +75 -9
  234. package/src/commands/repo-command.ts +6 -70
  235. package/src/commands/reset-command.ts +11 -1
  236. package/src/commands/restore-command.ts +1 -0
  237. package/src/commands/rev-list-command.ts +205 -3
  238. package/src/commands/revert-command.ts +9 -0
  239. package/src/commands/revision-filenames.ts +32 -4
  240. package/src/commands/revision-range.ts +2 -2
  241. package/src/commands/revision-resolver.ts +21 -1
  242. package/src/commands/serve-repository.ts +34 -8
  243. package/src/commands/served-lazy-fetch.ts +164 -0
  244. package/src/commands/signing.ts +18 -10
  245. package/src/commands/status-color-config.ts +92 -0
  246. package/src/commands/status-command.ts +50 -2
  247. package/src/commands/status-format.ts +198 -50
  248. package/src/commands/tag-command.ts +57 -2
  249. package/src/commands/tree-restore.ts +17 -0
  250. package/src/commands/verify-command.ts +84 -12
  251. package/src/commands/worktree-add-command.ts +2 -0
  252. package/src/commands/worktree-overwrite-checks.ts +75 -14
  253. package/src/errors/commit-errors.ts +31 -3
  254. package/src/errors/git-api-error.ts +7 -0
  255. package/src/git-command.ts +105 -4
  256. package/src/git.ts +153 -0
  257. package/src/remote-config/remote-config-store.ts +16 -0
  258. package/src/results/cherry-pick-result.ts +4 -3
  259. package/src/results/diff-output.ts +8 -0
  260. package/src/results/diff-words.ts +160 -32
  261. package/src/results/line-prefix-sink.ts +102 -0
  262. package/src/results/merge-result.ts +4 -3
  263. package/src/results/rebase-result.ts +5 -0
  264. package/src/results/revert-result.ts +4 -3
  265. package/src/transport-command.ts +48 -2
@@ -47,6 +47,7 @@ import type { RevisionResolver } from "./revision-resolver.js";
47
47
  import { pushSparseWarnings, SparseUnpack } from "./sparse-checkout-support.js";
48
48
  import type { SubmoduleUnpack } from "./submodule-unpack.js";
49
49
  import {
50
+ type CheckoutRef,
50
51
  planFlatRestore,
51
52
  planTreeRestore,
52
53
  restoreCaseOptions,
@@ -54,12 +55,15 @@ import {
54
55
  writeTreeRestorePlan,
55
56
  } from "./tree-restore.js";
56
57
  import {
58
+ belowRefused,
57
59
  type CheckedEntry,
58
60
  entryNotUptodate,
59
61
  findInTheWay,
62
+ leadingFileOf,
60
63
  overwriteMessage,
61
64
  pruneEmptyParents,
62
65
  removeCaseVariants,
66
+ takeCleanSubdirectory,
63
67
  } from "./worktree-overwrite-checks.js";
64
68
  import { firstInvalidPath, worktreePathRules } from "./worktree-path-rules.js";
65
69
 
@@ -549,11 +553,24 @@ export async function updateIndexCacheTree(
549
553
  trees: CommandTrees,
550
554
  /** the repository's object format, the cache-tree's trees are hashed in */
551
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,
552
562
  ): Promise<void> {
553
563
  if (!staging.getCacheTree || !staging.setCacheTree) return;
554
564
  if (await staging.hasConflicts()) return;
555
565
  const previous = staging.getCacheTree();
556
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
+ }
557
574
  const treeId = await staging.writeTree(trees);
558
575
  const cacheTree = await updateCacheTree(trees, treeId, previous, format);
559
576
  for (const entry of await indexEntryList(staging)) {
@@ -564,6 +581,27 @@ export async function updateIndexCacheTree(
564
581
  staging.setCacheTree(cacheTree);
565
582
  }
566
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
+
567
605
  /** Every index entry in the index's order, at once where the staging can give them so. */
568
606
  async function indexEntryList(staging: Staging): Promise<readonly IndexEntryInput[]> {
569
607
  const list = staging.entryList?.();
@@ -892,6 +930,11 @@ export async function switchTrees(
892
930
  export interface SwitchTreesOptions {
893
931
  /** Names the operation in git's refusal messages */
894
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;
895
938
  /** Names the operation in restore failures */
896
939
  operation: string;
897
940
  /** The conflicts to stage */
@@ -992,17 +1035,60 @@ async function switchTreesWith(
992
1035
  const subs = options.submodules;
993
1036
  /** Paths whose submodule checks replace the untracked-file checks (verify_absent_1) */
994
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
+ };
995
1080
  const paths = [...new Set([...head.keys(), ...target.keys()])].sort();
996
1081
  for (const path of paths) {
1082
+ if (belowRefused(path, refused)) continue;
997
1083
  const h = head.get(path);
998
1084
  const t = target.get(path);
999
- const i = index.get(path);
1085
+ const i = consumed.has(path) ? undefined : index.get(path);
1000
1086
  if (sameEntry(h, t) && !(options.initialCheckout && t && !i)) continue;
1001
1087
  if (i) {
1002
1088
  if (t && sameEntry(i, t)) continue;
1003
1089
  if (!sameEntry(i, h)) {
1004
1090
  // a staged change the switch would lose (reject_merge)
1005
- staged.push(path);
1091
+ refuse(staged, path);
1006
1092
  continue;
1007
1093
  }
1008
1094
  if (subs && checked && !quiet(path) && i.mode === FileMode.GITLINK) {
@@ -1010,12 +1096,12 @@ async function switchTreesWith(
1010
1096
  if (!t && update && (await subs.isSubmodule(path, i)) && (await subs.exists(path))) {
1011
1097
  await subs.refuses(path, (h ?? i).objectId, null);
1012
1098
  }
1013
- const refused = await subs.notUptodate(path, i);
1014
- if (refused) {
1015
- local.push(path);
1099
+ const notUptodate = await subs.notUptodate(path, i);
1100
+ if (notUptodate) {
1101
+ refuse(local, path);
1016
1102
  continue;
1017
1103
  }
1018
- if (refused === false) {
1104
+ if (notUptodate === false) {
1019
1105
  if (t && t.mode !== FileMode.GITLINK) await subs.fileReplacesRefuses(path, i);
1020
1106
  if (t) await subs.mergedRefuses(path, i, t);
1021
1107
  (t ? updates : removes).push(path);
@@ -1023,7 +1109,7 @@ async function switchTreesWith(
1023
1109
  }
1024
1110
  }
1025
1111
  if (checked && !quiet(path) && (await entryNotUptodate(checked, path, i, trust, indexTime))) {
1026
- local.push(path);
1112
+ refuse(local, path);
1027
1113
  continue;
1028
1114
  }
1029
1115
  if (subs && t && !quiet(path)) await subs.mergedRefuses(path, i, t);
@@ -1033,7 +1119,7 @@ async function switchTreesWith(
1033
1119
  if (t) {
1034
1120
  // a staged deletion of a path the target changes (none in an initial checkout)
1035
1121
  if (h && !options.initialCheckout) {
1036
- staged.push(path);
1122
+ refuse(staged, path);
1037
1123
  continue;
1038
1124
  }
1039
1125
  if (subs && !quiet(path)) {
@@ -1042,11 +1128,39 @@ async function switchTreesWith(
1042
1128
  if (absent !== undefined) submodulePaths.add(path);
1043
1129
  if (!absent) await subs.mergedRefuses(path, undefined, t);
1044
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
+ }
1045
1136
  updates.push(path);
1046
1137
  continue;
1047
1138
  }
1048
- // a deletion already staged: an untracked file there would be removed
1049
- 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
+ }
1050
1164
  }
1051
1165
  // a dirty file the target deletes is reported as a local change only (git's
1052
1166
  // verify_clean_subdirectory counts tracked files under a replaced directory as such)
@@ -1055,7 +1169,8 @@ async function switchTreesWith(
1055
1169
  const writing = new Set(updates.filter((p) => !sparse || sparse.writes(p)));
1056
1170
  const found = worktree
1057
1171
  ? await findInTheWay(worktree, {
1058
- 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],
1059
1174
  removes: new Set(deleting),
1060
1175
  index,
1061
1176
  ...(await restoreCaseOptions(worktree, ignoreCase)),
@@ -1198,6 +1313,7 @@ async function switchTreesWith(
1198
1313
  replaceInTheWay: true,
1199
1314
  attributes: { direction: "checkout", index: attributesIndexOf(result) },
1200
1315
  progress,
1316
+ ...(options.metadata ? { metadata: options.metadata } : {}),
1201
1317
  },
1202
1318
  );
1203
1319
  }
@@ -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
  }
@@ -208,9 +208,9 @@ export function createPromisorFetcher(
208
208
  });
209
209
  // loaded when first needed: GitCommand installs this fetcher, and the transport's
210
210
  // modules (local remotes run commands) import GitCommand
211
- const { prepareRemote, protocolVersionOf, withRemoteUploadPack } = await import(
212
- "./remote-transport.js"
213
- );
211
+ const { localLazyFetchOf, prepareRemote, protocolVersionOf, withRemoteUploadPack } =
212
+ await import("./remote-transport.js");
213
+ const { remoteHookSession } = await import("./local-transport.js");
214
214
  const prepared = await prepareRemote(
215
215
  workingCopy,
216
216
  url,
@@ -233,6 +233,17 @@ export function createPromisorFetcher(
233
233
  : settings;
234
234
  },
235
235
  ...(options.credentialHelper ? { credentialHelper: options.credentialHelper } : {}),
236
+ // a local promisor's upload-pack runs the protected uploadpack.packObjectsHook
237
+ localHooks: (remote) => remoteHookSession(workingCopy, remote, { localPush: true }),
238
+ // the child fetch's local upload-pack inherits GIT_NAMESPACE
239
+ ...(environment?.namespace ? { namespace: environment.namespace } : {}),
240
+ // and its GIT_NO_LAZY_FETCH=0: a local promisor's upload-pack fetches what it lacks
241
+ ...localLazyFetchOf(environment, {
242
+ transports: options.transports ?? createDefaultTransports(),
243
+ ...(options.credentialHelper ? { credentialHelper: options.credentialHelper } : {}),
244
+ ...(options.timeout !== undefined ? { timeout: options.timeout } : {}),
245
+ ...(options.warningCallback ? { warningCallback: options.warningCallback } : {}),
246
+ }),
236
247
  },
237
248
  async (connection) => {
238
249
  try {