@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
@@ -46,6 +46,7 @@ import {
46
46
  attributesIndexOf,
47
47
  cacheTreeOfTree,
48
48
  entryStatOf,
49
+ type FsmonitorState,
49
50
  isIndexUnborn,
50
51
  type StagingEntry,
51
52
  type Worktree,
@@ -85,6 +86,7 @@ import { type CheckoutPathsOutcome, runPathCheckout } from "./checkout-paths.js"
85
86
  import { coreBool, worktreeModeTrust } from "./core-config.js";
86
87
  import { runPostCheckoutHook } from "./git-hooks.js";
87
88
  import { hostEnvironmentOf } from "./git-ident.js";
89
+ import { applyIndexStatUpdates, refreshIndexEntries } from "./index-refresh.js";
88
90
  import { OperationState, updateIndexCacheTree } from "./merge-support.js";
89
91
  import { globalPathspecMagic } from "./pathspec.js";
90
92
  import { PathspecFile } from "./pathspec-file.js";
@@ -105,11 +107,14 @@ import { STASH_REF } from "./stash-list-command.js";
105
107
  import { recursesIntoSubmodules, SubmoduleUnpack } from "./submodule-unpack.js";
106
108
  import { planTreeRestore, restoreCaseOptions, writeTreeRestorePlan } from "./tree-restore.js";
107
109
  import {
110
+ belowRefused,
108
111
  entryNotUptodate,
109
112
  findInTheWay,
110
113
  flaggedEntryDiffers,
114
+ leadingFileOf,
111
115
  overwriteMessage,
112
116
  pruneEmptyParents,
117
+ takeCleanSubdirectory,
113
118
  } from "./worktree-overwrite-checks.js";
114
119
  import { firstInvalidPath, withTreePathRefusal, worktreePathRules } from "./worktree-path-rules.js";
115
120
  import { refuseIfCheckedOut, shortBranchName } from "./worktree-support.js";
@@ -264,6 +269,15 @@ type SwitchPlan =
264
269
  | { kind: "detach"; targetId: ObjectId; logName: string }
265
270
  | { kind: "stay"; targetId: ObjectId; logName: string };
266
271
 
272
+ /**
273
+ * The revision a switch was given as git's `setup_branch_path` reads it (`@` for HEAD, `-`
274
+ * for `@{-1}`): the start point of a branch created, else the name checked out.
275
+ */
276
+ function switchArgument(plan: SwitchPlan, name: string | undefined): string | undefined {
277
+ const arg = plan.kind === "create" ? plan.startName : name;
278
+ return arg === "@" ? "HEAD" : arg === "-" ? "@{-1}" : arg;
279
+ }
280
+
267
281
  /**
268
282
  * Command to checkout branches, commits, or paths.
269
283
  *
@@ -480,6 +494,12 @@ export class CheckoutCommand extends GitCommand<CheckoutResult> {
480
494
  return this;
481
495
  }
482
496
 
497
+ /** The index's file system monitor state for a refresh, when the monitor is on. */
498
+ private async fsmonitorOf(): Promise<{ fsmonitor?: FsmonitorState }> {
499
+ const run = await this.fsmonitorRefresh(this.staging);
500
+ return run ? { fsmonitor: run.state } : {};
501
+ }
502
+
483
503
  /** Whether this switch skips merge_working_tree (see {@link setOnlyMergeOnSwitchingBranches}). */
484
504
  private skipsMergeWorkingTree(): boolean {
485
505
  if (!this.onlyMergeOnSwitchingBranches || this.orphan) return false;
@@ -999,6 +1019,8 @@ export class CheckoutCommand extends GitCommand<CheckoutResult> {
999
1019
  sparse,
1000
1020
  undefined,
1001
1021
  new Set(fsmKept.keys()),
1022
+ // reset_head's init_checkout_metadata: HEAD's commit, no ref
1023
+ { treeish: headId },
1002
1024
  );
1003
1025
  // check_updates: the entries written carry the stat of their new files
1004
1026
  await recordWrittenStat(this.staging, worktree, written);
@@ -1016,11 +1038,18 @@ export class CheckoutCommand extends GitCommand<CheckoutResult> {
1016
1038
  * checkout do before the write).
1017
1039
  */
1018
1040
  private async writeSwitchedIndex(): Promise<void> {
1019
- await updateIndexCacheTree(this.staging, this.trees, this.objectFormat);
1041
+ // an index no tree can hold: verify_cache's lines, once from unpack-trees' own
1042
+ // cache_tree_update and once from merge_working_tree's, and the switch goes on
1043
+ await updateIndexCacheTree(this.staging, this.trees, this.objectFormat, (lines) =>
1044
+ this.cacheTreeLines.push(...lines, ...lines),
1045
+ );
1020
1046
  markIndexUpdate(this.staging, { workdir: true });
1021
1047
  await this.staging.write();
1022
1048
  }
1023
1049
 
1050
+ /** verify_cache's lines of the switch's index write (stderr, after the sparse lines) */
1051
+ private cacheTreeLines: string[] = [];
1052
+
1024
1053
  /** The switch an autostash switch makes again: its caller runs post-checkout once. */
1025
1054
  private noPostCheckout = false;
1026
1055
  private withoutPostCheckout(): this {
@@ -1103,6 +1132,7 @@ export class CheckoutCommand extends GitCommand<CheckoutResult> {
1103
1132
  worktree: this.worktreeAccess,
1104
1133
  abbreviate: (id: ObjectId) => this.abbreviateObjectId(id),
1105
1134
  resolveTree: (rev: string) => this.resolveSourceTree(rev),
1135
+ checkoutRefOf: (rev: string, id: ObjectId) => this.checkoutRefOf(rev, id),
1106
1136
  };
1107
1137
  }
1108
1138
 
@@ -1248,7 +1278,18 @@ export class CheckoutCommand extends GitCommand<CheckoutResult> {
1248
1278
  // switch --orphan switches to the empty tree)
1249
1279
  const keepAll =
1250
1280
  this.orphan && !this.orphanFromEmptyTree && !orphanCheckout && orphanStart === undefined;
1251
- if (!this.force && !keepAll && unmerged.size > 0) {
1281
+ // merge_working_tree's refresh_index(REFRESH_QUIET) before the two-way merge (orphans
1282
+ // included): an entry whose stat moved but whose content did not takes its file's
1283
+ // current stat; an unmerged path prints `<path>: needs merge` on stdout
1284
+ const refresh =
1285
+ !this.force && worktree
1286
+ ? await refreshIndexEntries(this.staging, worktree, {
1287
+ trust: worktreeModeTrust(this.workingCopy, worktree),
1288
+ ...(await this.fsmonitorOf()),
1289
+ })
1290
+ : undefined;
1291
+ // (checkout --orphan too: git refuses before it keeps index and worktree)
1292
+ if (!this.force && unmerged.size > 0) {
1252
1293
  return {
1253
1294
  status: CheckoutStatus.CONFLICTS,
1254
1295
  updated: [],
@@ -1256,6 +1297,9 @@ export class CheckoutCommand extends GitCommand<CheckoutResult> {
1256
1297
  conflicts: [...unmerged].sort(),
1257
1298
  ref: null,
1258
1299
  message: "error: you need to resolve your current index first",
1300
+ ...(refresh && refresh.unmerged.length > 0
1301
+ ? { output: refresh.unmerged.map((path) => `${path}: needs merge`) }
1302
+ : {}),
1259
1303
  };
1260
1304
  }
1261
1305
 
@@ -1270,6 +1314,47 @@ export class CheckoutCommand extends GitCommand<CheckoutResult> {
1270
1314
  const trust = worktree ? worktreeModeTrust(this.workingCopy, worktree) : undefined;
1271
1315
  const ignoreCase = coreBool(this.workingCopy, "ignorecase", false);
1272
1316
  const initial = unborn && !keepAll;
1317
+ const indexTime = this.staging.getUpdateTime();
1318
+ /**
1319
+ * Index entries verify_clean_subdirectory took out (see {@link takeCleanSubdirectory}):
1320
+ * removed, their own paths merged as if the index lacked them
1321
+ */
1322
+ const consumed = new Set<string>();
1323
+ /** Directories deleted_entry's verify_absent checks for untracked files */
1324
+ const absentDirs: string[] = [];
1325
+ /** Paths whose merge failed: git's traverse_trees enters no subtree of theirs */
1326
+ const refused = new Set<string>();
1327
+ /** The paths each refusal list holds (a path is listed once) */
1328
+ const listed = new Map<string[], Set<string>>();
1329
+ const refuse = (list: string[], path: string, at = path) => {
1330
+ let seen = listed.get(list);
1331
+ if (!seen) {
1332
+ seen = new Set(list);
1333
+ listed.set(list, seen);
1334
+ }
1335
+ if (!seen.has(at)) {
1336
+ seen.add(at);
1337
+ list.push(at);
1338
+ }
1339
+ refused.add(path);
1340
+ };
1341
+ /** `switched` as a set: a path verify_clean_subdirectory took out may come up again */
1342
+ const changing = new Set<string>();
1343
+ const change = (path: string) => {
1344
+ if (changing.has(path)) return;
1345
+ changing.add(path);
1346
+ switched.push(path);
1347
+ };
1348
+ /** Whether the switch so far removes the index entry at `path` (CE_REMOVE in its result) */
1349
+ const removesPath = (path: string) => changing.has(path) && !target.has(path);
1350
+ /** verify_absent's directory check of `path`; whether it passed */
1351
+ const cleanSubdirectory = async (wt: Worktree, path: string) => {
1352
+ const result = await takeCleanSubdirectory(wt, path, index, consumed, trust, indexTime);
1353
+ for (const p of result.taken) change(p);
1354
+ if (result.notUptodate === undefined) return true;
1355
+ refuse(local, path, result.notUptodate);
1356
+ return false;
1357
+ };
1273
1358
  const paths = [...new Set([...head.keys(), ...target.keys()])].sort();
1274
1359
  for (const path of keepAll ? [] : paths) {
1275
1360
  const h = head.get(path);
@@ -1284,7 +1369,8 @@ export class CheckoutCommand extends GitCommand<CheckoutResult> {
1284
1369
  continue;
1285
1370
  }
1286
1371
  if (!this.force && sameSide(h, t)) continue;
1287
- const i = index.get(path);
1372
+ if (!this.force && belowRefused(path, refused)) continue;
1373
+ const i = consumed.has(path) ? undefined : index.get(path);
1288
1374
  if (this.force) {
1289
1375
  // oneway_merge leaves a skip-worktree entry the target keeps (and its file) alone, as
1290
1376
  // the sparse checkout does whatever stays outside it
@@ -1299,16 +1385,35 @@ export class CheckoutCommand extends GitCommand<CheckoutResult> {
1299
1385
  continue;
1300
1386
  }
1301
1387
  if (sameSide(i, t)) {
1302
- // kept; but a staged deletion the target also makes leaves the file untracked in
1303
- // the worktree, and the switch would remove it (git refuses)
1304
- if (h && !i && !t && worktree && (await this.untrackedFileAt(worktree, path))) {
1305
- untrackedRemoved.push(path);
1388
+ // kept; but a staged deletion the target also makes is deleted_entry's verify_absent:
1389
+ // an untracked file there would be removed (git refuses), a directory loses its
1390
+ // entries, a file among the leading directories would be removed too
1391
+ if (h && !i && !t && worktree && !quiet(path)) {
1392
+ const there = await worktree.getEntry(path);
1393
+ if (there?.isDirectory) {
1394
+ if (h.mode !== FileMode.GITLINK && (await cleanSubdirectory(worktree, path))) {
1395
+ absentDirs.push(path);
1396
+ }
1397
+ } else if (there) {
1398
+ if (!consumed.has(path) && (await this.untrackedFileAt(worktree, path))) {
1399
+ refuse(untrackedRemoved, path);
1400
+ }
1401
+ } else {
1402
+ const leading = await leadingFileOf(worktree, path);
1403
+ if (
1404
+ leading !== undefined &&
1405
+ !(index.has(leading) && (consumed.has(leading) || removesPath(leading))) &&
1406
+ !(await worktree.isIgnored(leading))
1407
+ ) {
1408
+ refuse(untrackedRemoved, path, leading);
1409
+ }
1410
+ }
1306
1411
  }
1307
1412
  continue;
1308
1413
  }
1309
1414
  if (!sameSide(i, h)) {
1310
1415
  // staged changes (or a staged deletion) the switch would lose
1311
- if (i !== undefined || t !== undefined) local.push(path);
1416
+ if (i !== undefined || t !== undefined) refuse(local, path);
1312
1417
  continue;
1313
1418
  }
1314
1419
  if (subs && worktree && !quiet(path)) {
@@ -1317,15 +1422,15 @@ export class CheckoutCommand extends GitCommand<CheckoutResult> {
1317
1422
  if (!t && (await subs.isSubmodule(path, i)) && (await subs.exists(path))) {
1318
1423
  await subs.refuses(path, (h ?? i).objectId, null);
1319
1424
  }
1320
- const refused = await subs.notUptodate(path, i);
1321
- if (refused) {
1322
- local.push(path);
1425
+ const notUptodate = await subs.notUptodate(path, i);
1426
+ if (notUptodate) {
1427
+ refuse(local, path);
1323
1428
  continue;
1324
1429
  }
1325
- if (refused === false) {
1430
+ if (notUptodate === false) {
1326
1431
  if (t && t.mode !== FileMode.GITLINK) await subs.fileReplacesRefuses(path, i);
1327
1432
  if (t) await subs.mergedRefuses(path, i, t);
1328
- switched.push(path);
1433
+ change(path);
1329
1434
  continue;
1330
1435
  }
1331
1436
  } else if (i === undefined && t) {
@@ -1338,13 +1443,19 @@ export class CheckoutCommand extends GitCommand<CheckoutResult> {
1338
1443
  i !== undefined &&
1339
1444
  worktree &&
1340
1445
  !quiet(path) &&
1341
- (await entryNotUptodate(worktree, path, i, trust, this.staging.getUpdateTime()))
1446
+ (await entryNotUptodate(worktree, path, i, trust, indexTime))
1342
1447
  ) {
1343
- local.push(path);
1448
+ refuse(local, path);
1344
1449
  continue;
1345
1450
  }
1346
1451
  if (subs && i !== undefined && t && !quiet(path)) await subs.mergedRefuses(path, i, t);
1347
- switched.push(path);
1452
+ // merged_entry's verify_absent of a new file: a directory here loses the index
1453
+ // entries below it
1454
+ if (i === undefined && t && worktree && !quiet(path) && t.mode !== FileMode.GITLINK) {
1455
+ const there = await worktree.getEntry(path);
1456
+ if (there?.isDirectory && !(await cleanSubdirectory(worktree, path))) continue;
1457
+ }
1458
+ change(path);
1348
1459
  }
1349
1460
 
1350
1461
  // what stands where the switch writes (git's verify_absent, check_leading_path and
@@ -1352,8 +1463,12 @@ export class CheckoutCommand extends GitCommand<CheckoutResult> {
1352
1463
  // component, untracked files in a directory a file replaces
1353
1464
  if (worktree && !this.force) {
1354
1465
  const found = await findInTheWay(worktree, {
1355
- writes: switched.filter((p) => target.has(p) && writes(p) && !submodulePaths.has(p)),
1356
- removes: new Set(switched.filter((p) => !target.has(p))),
1466
+ writes: [
1467
+ ...switched.filter((p) => target.has(p) && writes(p) && !submodulePaths.has(p)),
1468
+ // deleted_entry's directories, checked as a file written there would check them
1469
+ ...absentDirs,
1470
+ ],
1471
+ removes: new Set([...switched.filter((p) => !target.has(p)), ...consumed]),
1357
1472
  index,
1358
1473
  ...(await restoreCaseOptions(worktree, ignoreCase)),
1359
1474
  caseVariantsExpendable: true,
@@ -1418,8 +1533,8 @@ export class CheckoutCommand extends GitCommand<CheckoutResult> {
1418
1533
  // git 2.55+ `checkout -m`: a two-way merge that fails (local changes, untracked files
1419
1534
  // in the way) falls back to an autostash, run by call() outside this worktree batch;
1420
1535
  // with nothing to stash the refusal stands
1421
- const refused = local.length + untracked.length + untrackedRemoved.length + lostDirs.length;
1422
- if (this.merge && headId && refused > 0 && this.patchCompatibility === "2.43") {
1536
+ const refusals = local.length + untracked.length + untrackedRemoved.length + lostDirs.length;
1537
+ if (this.merge && headId && refusals > 0 && this.patchCompatibility === "2.43") {
1423
1538
  // git 2.43's merge_working_tree: a failed two-way merge under `-m` dies when the index
1424
1539
  // holds changes against HEAD (repo_index_has_changes), an unborn index's missing
1425
1540
  // entries included (staged deletions of every HEAD file)
@@ -1432,7 +1547,7 @@ export class CheckoutCommand extends GitCommand<CheckoutResult> {
1432
1547
  );
1433
1548
  }
1434
1549
  }
1435
- if (this.merge && headId && refused > 0) {
1550
+ if (this.merge && headId && refusals > 0) {
1436
1551
  const left = await this.getCurrentBranch();
1437
1552
  // the base's label: the branch left, else its commit uniquely abbreviated
1438
1553
  // (strbuf_add_unique_abbrev, DEFAULT_ABBREV)
@@ -1572,6 +1687,10 @@ export class CheckoutCommand extends GitCommand<CheckoutResult> {
1572
1687
  ...(this.force && !this.protectUntracked ? { discardUntracked: true } : {}),
1573
1688
  attributes: { direction: "checkout", index: attributesIndexOf(result) },
1574
1689
  progress,
1690
+ // merge_working_tree's init_checkout_metadata: the name given and its commit
1691
+ ...(targetId
1692
+ ? { metadata: await this.checkoutRefOf(switchArgument(switchTo, this.name), targetId) }
1693
+ : {}),
1575
1694
  });
1576
1695
  updated.push(...only.entries.map((e) => e.path));
1577
1696
  for (const e of [...only.entries, ...only.gitlinks]) written.add(e.path);
@@ -1589,6 +1708,14 @@ export class CheckoutCommand extends GitCommand<CheckoutResult> {
1589
1708
  // entries (with the stat of the files just written), every other path keeps its own.
1590
1709
  // git's switch writes a new index (unpack-trees): no resolve-undo records survive it
1591
1710
  this.staging.clearResolveUndo?.();
1711
+ // the refresh's stats, for the entries the switch keeps (written with this index only:
1712
+ // a refused switch rolls the lock back, as git does)
1713
+ if (refresh) {
1714
+ await applyIndexStatUpdates(
1715
+ this.staging,
1716
+ refresh.updates.filter((update) => !switching.has(update.path)),
1717
+ );
1718
+ }
1592
1719
  if (targetTreeId && this.force) {
1593
1720
  // oneway_merge: an unchanged entry keeps its flags and stat, a changed one its
1594
1721
  // skip-worktree bit
@@ -1644,6 +1771,7 @@ export class CheckoutCommand extends GitCommand<CheckoutResult> {
1644
1771
  );
1645
1772
  pushSparseWarnings(sparseWarnings, sparse, outcome, true);
1646
1773
  }
1774
+ sparseWarnings.push(...this.cacheTreeLines.splice(0));
1647
1775
 
1648
1776
  return this.updateRefsForSwitch(switchTo, updated, removed, sparseWarnings);
1649
1777
  }
@@ -499,7 +499,8 @@ class CheckoutIndexRun {
499
499
  } else if (!link) {
500
500
  // smudged with the entry's own attributes, wherever it is written
501
501
  const conversion = await worktree.contentFilter?.checkout(ce.path);
502
- if (conversion) content = await conversion.apply(blob);
502
+ // checkout_entry's metadata: the blob, for a long-running filter process
503
+ if (conversion) content = await conversion.apply(blob, { metadata: { blob: ce.objectId } });
503
504
  }
504
505
  if (path !== undefined) await this.createDirectories(path);
505
506
  const target = path ?? (await this.tempName(link));
@@ -41,6 +41,7 @@ import {
41
41
  } from "./pathspec.js";
42
42
  import { PathspecAttributes } from "./pathspec-attributes.js";
43
43
  import { recursesIntoSubmodules, SubmoduleUnpack } from "./submodule-unpack.js";
44
+ import type { CheckoutRef } from "./tree-restore.js";
44
45
  import {
45
46
  pruneEmptyParents,
46
47
  removeDirectoryIfEmpty,
@@ -68,6 +69,12 @@ export interface CheckoutPathsOptions {
68
69
  reportUnmatched?: boolean;
69
70
  /** The tree checked out of (`opts->source_tree`); none: the index */
70
71
  sourceTree?: ObjectId;
72
+ /**
73
+ * git's checkout metadata of the source (`checkout_paths`' `init_checkout_metadata`: the
74
+ * ref the tree-ish names and its commit), handed with each file's blob to a long-running
75
+ * filter process
76
+ */
77
+ sourceMetadata?: CheckoutRef;
71
78
  /** Update the index (`checkout_index`) */
72
79
  checkoutIndex: boolean;
73
80
  /** Update the worktree (`checkout_worktree`) */
@@ -157,6 +164,8 @@ export interface PathCheckoutRequest {
157
164
  export async function runPathCheckout(
158
165
  ctx: CheckoutPathsContext & {
159
166
  resolveTree(rev: string): Promise<{ id: ObjectId; tree: ObjectId | undefined }>;
167
+ /** git's checkout metadata of the source `rev` at `id` (see `GitCommand.checkoutRefOf`) */
168
+ checkoutRefOf?(rev: string, id: ObjectId): Promise<CheckoutRef>;
160
169
  },
161
170
  req: PathCheckoutRequest,
162
171
  ): Promise<CheckoutPathsOutcome> {
@@ -199,6 +208,7 @@ export async function runPathCheckout(
199
208
  }
200
209
  // the source tree, resolved before checkout_paths runs
201
210
  let sourceTree: ObjectId | undefined;
211
+ let sourceMetadata: CheckoutRef | undefined;
202
212
  if (from !== undefined) {
203
213
  let resolved: { id: ObjectId; tree: ObjectId | undefined };
204
214
  try {
@@ -218,6 +228,7 @@ export async function runPathCheckout(
218
228
  throw new RefNotFoundError(from, `fatal: unable to read tree (${resolved.id})`);
219
229
  }
220
230
  sourceTree = resolved.tree;
231
+ sourceMetadata = await ctx.checkoutRefOf?.(from === "@" ? "HEAD" : from, resolved.id);
221
232
  }
222
233
  if (ignoreUnmerged && req.merge) {
223
234
  throw fail(
@@ -262,6 +273,7 @@ export async function runPathCheckout(
262
273
  originals,
263
274
  reportUnmatched: !req.allPaths,
264
275
  ...(sourceTree ? { sourceTree } : {}),
276
+ ...(sourceMetadata ? { sourceMetadata } : {}),
265
277
  checkoutIndex,
266
278
  checkoutWorktree,
267
279
  overlay: req.overlay ?? !isRestore,
@@ -668,6 +680,7 @@ async function checkoutWorktree(
668
680
  createParents: true,
669
681
  replaceInTheWay: true,
670
682
  discardUntracked: true,
683
+ metadata: { ...o.sourceMetadata, blob: objectId },
671
684
  });
672
685
  return true;
673
686
  };
@@ -375,6 +375,15 @@ export class CherryPickCommand extends GitCommand<CherryPickResult> {
375
375
  return made.id;
376
376
  }
377
377
 
378
+ /** git sets `warn_on_auto_comment_char`: 2.5x warns of `core.commentChar=auto` here. */
379
+ protected override autoCommentCharWarningEntryPoints(): readonly string[] {
380
+ return ["call"];
381
+ }
382
+
383
+ protected override gitCompatibility(): "2.43" | "2.56" {
384
+ return this.compatibility ?? this.hooks.compatibility;
385
+ }
386
+
378
387
  async call(): Promise<CherryPickResult> {
379
388
  this.checkCallable();
380
389
  this.setCallable(false);
@@ -10,6 +10,14 @@ import { wildmatch } from "@statewalker/vcs-working-tree";
10
10
 
11
11
  import { quotePath } from "../results/quote-path.js";
12
12
  import type { PatchRequest, PatchSelector } from "./add-patch/index.js";
13
+ import {
14
+ COL_COLUMN,
15
+ COL_DENSE,
16
+ COL_ENABLED,
17
+ COL_PLAIN,
18
+ COL_ROW,
19
+ printColumns,
20
+ } from "./column/index.js";
13
21
 
14
22
  /** What `git clean -i` printed. */
15
23
  export interface CleanInteractiveResult {
@@ -56,74 +64,11 @@ export function parseColumnLayout(values: readonly string[]): ColumnLayout {
56
64
  return out;
57
65
  }
58
66
 
59
- /** utf8_strnwidth: the display width (one column per character here). */
60
- const itemLength = (s: string) => [...s].length;
61
-
62
- /**
63
- * column.c's `print_columns` with the layout always enabled: `indent` before each line,
64
- * `padding` spaces between cells, `width` the terminal's columns less one.
65
- */
66
- export function printColumns(
67
- list: readonly string[],
68
- layout: ColumnLayout,
69
- options: { indent: string; padding: number; width: number },
70
- ): string {
71
- if (list.length === 0) return "";
72
- const { indent, padding } = options;
73
- if (layout.layout === "plain") return list.map((s) => `${indent}${s}\n`).join("");
74
- const n = list.length;
75
- const len = list.map(itemLength);
76
- const column = layout.layout === "column";
77
- let initialWidth = Math.max(...len) + padding;
78
- let cols = Math.floor((options.width - indent.length) / initialWidth);
79
- if (cols === 0) cols = 1;
80
- let rows = Math.ceil(n / cols);
81
- const linear = (x: number, y: number) => (column ? x * rows + y : y * cols + x);
82
- let width: number[] | undefined;
83
- const computeWidths = () => {
84
- const w: number[] = [];
85
- for (let x = 0; x < cols; x++) {
86
- w[x] = linear(x, 0);
87
- for (let y = 0; y < rows; y++) {
88
- const i = linear(x, y);
89
- if (i < n && len[w[x] as number] < len[i]) w[x] = i;
90
- }
91
- }
92
- return w;
93
- };
94
- if (layout.dense) {
95
- while (rows > 1) {
96
- const oldRows = rows;
97
- const oldCols = cols;
98
- rows--;
99
- cols = Math.ceil(n / rows);
100
- const w = computeWidths();
101
- let total = indent.length;
102
- for (let x = 0; x < cols; x++) total += len[w[x] as number] + padding;
103
- if (total > options.width) {
104
- rows = oldRows;
105
- cols = oldCols;
106
- break;
107
- }
108
- }
109
- width = computeWidths();
110
- }
111
- initialWidth = Math.max(...len) + padding;
112
- let out = "";
113
- for (let y = 0; y < rows; y++) {
114
- for (let x = 0; x < cols; x++) {
115
- const i = linear(x, y);
116
- if (i >= n) break;
117
- let l = len[i] as number;
118
- if (width && len[width[x] as number] < initialWidth) {
119
- l += initialWidth - len[width[x] as number];
120
- l -= padding;
121
- }
122
- const newline = column ? i + rows >= n : x === cols - 1 || i === n - 1;
123
- out += `${x === 0 ? indent : ""}${list[i]}${newline ? "\n" : " ".repeat(Math.max(0, initialWidth - l))}`;
124
- }
125
- }
126
- return out;
67
+ /** The finalized `colopts` of a layout git clean always uses (column_active). */
68
+ function layoutColopts(layout: ColumnLayout): number {
69
+ const bits =
70
+ layout.layout === "row" ? COL_ROW : layout.layout === "plain" ? COL_PLAIN : COL_COLUMN;
71
+ return COL_ENABLED | bits | (layout.dense ? COL_DENSE : 0);
127
72
  }
128
73
 
129
74
  interface MenuItem {
@@ -187,11 +132,12 @@ function firstPieceOf(input: string): string {
187
132
  class CleanInteractiveSession {
188
133
  private out = "";
189
134
  private del: string[];
190
- private readonly width: number;
135
+ /** term_columns(); git's pretty_print_dels and menus leave copts.width 0 (term_columns - 1) */
136
+ private readonly termColumns: number;
191
137
 
192
138
  constructor(private readonly options: CleanInteractiveOptions) {
193
139
  this.del = [...options.items];
194
- this.width = (options.columns ?? 80) - 1;
140
+ this.termColumns = options.columns ?? 80;
195
141
  }
196
142
 
197
143
  private quote(item: string): string {
@@ -201,8 +147,8 @@ class CleanInteractiveSession {
201
147
  private prettyPrintDels(): void {
202
148
  this.out += printColumns(
203
149
  this.del.map((item) => this.quote(item)),
204
- this.options.layout ?? { layout: "column", dense: false },
205
- { indent: " ", padding: 2, width: this.width },
150
+ layoutColopts(this.options.layout ?? { layout: "column", dense: false }),
151
+ { indent: " ", padding: 2, termColumns: this.termColumns },
206
152
  );
207
153
  }
208
154
 
@@ -366,8 +312,8 @@ class CleanInteractiveSession {
366
312
  this.out += printColumns(
367
313
  titles.map((_, i) => label(i, chosen[i] === 1)),
368
314
  // pretty_print_menus: always in rows
369
- { layout: "row", dense: false },
370
- { indent: " ", padding: 2, width: this.width },
315
+ COL_ENABLED | COL_ROW,
316
+ { indent: " ", padding: 2, termColumns: this.termColumns },
371
317
  );
372
318
  const prompt = `${opts.prompt}${opts.singleton ? "> " : ">> "}`;
373
319
  this.out += prompt;
@@ -2038,6 +2038,14 @@ export class CloneCommand extends TransportCommand<CloneResult> {
2038
2038
  );
2039
2039
  }
2040
2040
 
2041
+ /** The full name of the branch HEAD names (`refs/heads/<name>`), none when detached. */
2042
+ private async headBranchRef(): Promise<string | undefined> {
2043
+ const head = await this.refsStore.get("HEAD").catch(() => undefined);
2044
+ return head && "target" in head && head.target.startsWith("refs/heads/")
2045
+ ? head.target
2046
+ : undefined;
2047
+ }
2048
+
2041
2049
  /** The branch the local HEAD names (`init.defaultBranch` of the new repository), if any. */
2042
2050
  private async localHeadBranch(): Promise<string | undefined> {
2043
2051
  const head = await this.refsStore.get("HEAD");
@@ -2090,6 +2098,11 @@ export class CloneCommand extends TransportCommand<CloneResult> {
2090
2098
  pathRules: worktreePathRules(this.workingCopy, worktree),
2091
2099
  ...(sparse ? { writes: (path: string) => sparse.writes(path) } : {}),
2092
2100
  ...(this.progress ? { progress: this.progress } : {}),
2101
+ // clone's checkout(): HEAD's branch (none when detached) and its commit
2102
+ metadata: {
2103
+ ...(await this.headBranchRef().then((ref) => (ref ? { ref } : {}))),
2104
+ treeish: commitId,
2105
+ },
2093
2106
  },
2094
2107
  commit.tree,
2095
2108
  CLONE,
@@ -0,0 +1,63 @@
1
+ /**
2
+ * The column settings of a command as git reads them: `column.ui` and `column.<command>`
3
+ * in the configuration's order (git_column_config), then the command line's `--column`.
4
+ *
5
+ * @module
6
+ */
7
+
8
+ import type { WorkingCopy } from "@statewalker/vcs-working-tree";
9
+
10
+ import { InvalidConfigError } from "../../errors/index.js";
11
+ import { RemoteConfigStore } from "../../remote-config/index.js";
12
+ import { hostEnvironmentOf } from "../git-ident.js";
13
+ import {
14
+ applyColumnOption,
15
+ finalizeColopts,
16
+ readColumnConfig,
17
+ termColumns,
18
+ } from "./column-layout.js";
19
+
20
+ /**
21
+ * `colopts` from `column.ui` and `column.<command>` (none: `column.ui` alone).
22
+ *
23
+ * @throws InvalidConfigError with git's lines for a value git refuses (exit 128)
24
+ */
25
+ export function columnConfigOf(workingCopy: WorkingCopy, command?: string): number {
26
+ if (!workingCopy.config) return 0;
27
+ const config = RemoteConfigStore.from(workingCopy);
28
+ const keys = command === undefined ? ["column.ui"] : ["column.ui", `column.${command}`];
29
+ const entries = (
30
+ config.entriesWithOriginFor(keys) ??
31
+ keys.flatMap((key) => config.valuesWithOrigin(key).map((where) => ({ key, ...where })))
32
+ ).map(({ key, text, file, line }) => ({
33
+ key: key.toLowerCase(),
34
+ value: text,
35
+ ...(file !== undefined ? { file } : {}),
36
+ ...(line !== undefined ? { line } : {}),
37
+ }));
38
+ const read = readColumnConfig(entries, command);
39
+ if ("message" in read) throw new InvalidConfigError(read.key, read.message);
40
+ return read.colopts;
41
+ }
42
+
43
+ /**
44
+ * A listing's finalized `colopts`: the configuration's, then `option` (`--column`,
45
+ * `--column=<options>`, `--no-column`), `auto` off (no terminal).
46
+ *
47
+ * @throws InvalidConfigError for a bad configured value, ColumnOptionError for a bad option
48
+ */
49
+ export function columnSettingsOf(
50
+ workingCopy: WorkingCopy,
51
+ command: string,
52
+ option: string | boolean | undefined,
53
+ ): number {
54
+ let colopts = columnConfigOf(workingCopy, command);
55
+ if (option !== undefined) colopts = applyColumnOption(colopts, option);
56
+ return finalizeColopts(colopts);
57
+ }
58
+
59
+ /** term_columns: the explicit width, else the host's `$COLUMNS`, else 80. */
60
+ export function terminalColumnsOf(workingCopy: WorkingCopy, explicit?: number): number {
61
+ if (explicit !== undefined && explicit > 0) return explicit;
62
+ return termColumns(hostEnvironmentOf(workingCopy)?.columns);
63
+ }