@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
@@ -193,6 +193,52 @@ function versionOrigin(config: RemoteConfigStore): string | undefined {
193
193
  }
194
194
  }
195
195
 
196
+ /**
197
+ * `index.recordEndOfIndexEntries`, `index.recordOffsetTable` and `index.threads` as git's
198
+ * `do_write_index` reads them: two booleans and git's `git_config_get_index_threads` (a
199
+ * boolean or an integer: true is 0, threads by the entries and processors; false is 1, none),
200
+ * with the processors online (`online_cpus`, `navigator.hardwareConcurrency`). A value git
201
+ * cannot parse (it dies) is left unset.
202
+ *
203
+ * @example
204
+ * ```typescript
205
+ * indexOffsetSettingsOf((key) => (key === "index.threads" ? "true" : undefined));
206
+ * // { threads: 0, onlineCpus: 8 }
207
+ * ```
208
+ */
209
+ export function indexOffsetSettingsOf(value: (key: string) => string | undefined): {
210
+ recordEndOfIndexEntries?: boolean;
211
+ recordOffsetTable?: boolean;
212
+ threads?: number;
213
+ onlineCpus?: number;
214
+ } {
215
+ const out: ReturnType<typeof indexOffsetSettingsOf> = {};
216
+ const eoie = parseGitBool(value("index.recordEndOfIndexEntries"));
217
+ if (eoie !== undefined) out.recordEndOfIndexEntries = eoie;
218
+ const ieot = parseGitBool(value("index.recordOffsetTable"));
219
+ if (ieot !== undefined) out.recordOffsetTable = ieot;
220
+ const threads = value("index.threads");
221
+ if (threads !== undefined) {
222
+ // git_config_bool_or_int: git_parse_maybe_bool_text first, then an int
223
+ const lower = threads.toLowerCase();
224
+ if (lower === "" || lower === "false" || lower === "no" || lower === "off") out.threads = 1;
225
+ else if (lower === "true" || lower === "yes" || lower === "on") out.threads = 0;
226
+ else {
227
+ const n = parseGitInt(threads);
228
+ if (n !== undefined) out.threads = n;
229
+ }
230
+ if (out.threads === 0) out.onlineCpus = onlineCpus();
231
+ }
232
+ return out;
233
+ }
234
+
235
+ /** git's `online_cpus`: the processors the runtime reports, else 1. */
236
+ function onlineCpus(): number {
237
+ const cpus = (globalThis as { navigator?: { hardwareConcurrency?: number } }).navigator
238
+ ?.hardwareConcurrency;
239
+ return typeof cpus === "number" && cpus > 0 ? cpus : 1;
240
+ }
241
+
196
242
  /** The settings of the next write of `staging`, from the working copy's configuration. */
197
243
  export async function indexSettingsOf(
198
244
  workingCopy: WorkingCopy,
@@ -215,6 +261,11 @@ export async function indexSettingsOf(
215
261
  if (skipHash === undefined ? manyFilesOn : (parseGitBool(skipHash) ?? manyFilesOn)) {
216
262
  settings.skipHash = true;
217
263
  }
264
+ // do_write_index's EOIE and IEOT (record_eoie, record_ieot, git_config_get_index_threads)
265
+ Object.assign(
266
+ settings,
267
+ indexOffsetSettingsOf((key) => configValueOf(config, key)),
268
+ );
218
269
  // tweak_fsmonitor's remove_fsmonitor: with the monitor off, no FSMN is written
219
270
  if (fsmonitorModeOf(configValueOf(config, "core.fsmonitor")).kind === "disabled") {
220
271
  settings.fsmonitor = false;
@@ -0,0 +1,121 @@
1
+ /**
2
+ * git's `refresh_index(REFRESH_QUIET)` over a staging area's entries (read-cache.c's
3
+ * `refresh_cache_ent` for each one):
4
+ *
5
+ * ```ts
6
+ * const refresh = await refreshIndexEntries(staging, worktree, { trust, fsmonitor });
7
+ * if (refresh.unmerged.length > 0) refuse();
8
+ * await applyIndexStatUpdates(staging, refresh.updates); // in memory, written with the index
9
+ * ```
10
+ *
11
+ * An entry whose stat no longer matches its file but whose content still does takes the
12
+ * file's current stat; a changed entry is left as it is and nothing is printed. Unmerged
13
+ * paths are reported once each. Skip-worktree and assume-unchanged entries, the ones the
14
+ * file system monitor holds valid, intent-to-add entries and gitlinks are never stat'ed.
15
+ */
16
+
17
+ import { FileMode } from "@statewalker/vcs-core";
18
+ import {
19
+ applyStatUpdate,
20
+ compareWithWorktree,
21
+ type FsmonitorState,
22
+ type IndexStatUpdate,
23
+ type Staging,
24
+ type StagingEntry,
25
+ statUpdateOf,
26
+ type Worktree,
27
+ type WorktreeModeTrust,
28
+ withWorktreeEntries,
29
+ } from "@statewalker/vcs-working-tree";
30
+
31
+ export interface IndexRefreshOptions {
32
+ /** What the worktree's modes and stat fields can be trusted for (`worktreeModeTrust`) */
33
+ trust: WorktreeModeTrust;
34
+ /**
35
+ * The index's file system monitor state: a valid entry is taken as up to date unseen,
36
+ * and an entry found up to date by its stat is marked valid (`mark_fsmonitor_valid`)
37
+ */
38
+ fsmonitor?: FsmonitorState;
39
+ }
40
+
41
+ export interface IndexRefreshResult {
42
+ /** The fresh stats of the entries proved clean by reading them */
43
+ updates: IndexStatUpdate[];
44
+ /** The unmerged paths, once each, in index order */
45
+ unmerged: string[];
46
+ }
47
+
48
+ /** `refresh_index(REFRESH_QUIET)`: what the refresh would store (see the module comment). */
49
+ export async function refreshIndexEntries(
50
+ staging: Staging,
51
+ worktree: Worktree,
52
+ options: IndexRefreshOptions,
53
+ ): Promise<IndexRefreshResult> {
54
+ const { trust, fsmonitor } = options;
55
+ const entries: StagingEntry[] = [];
56
+ for await (const entry of staging.entryList?.() ?? staging.entries()) entries.push(entry);
57
+ const indexTime = staging.getUpdateTime();
58
+ // refresh_cache_ent passes over what it cannot or need not stat
59
+ const stated = (entry: StagingEntry) =>
60
+ entry.stage === 0 &&
61
+ !entry.skipWorktree &&
62
+ !entry.assumeValid &&
63
+ !entry.intentToAdd &&
64
+ entry.mode !== FileMode.GITLINK &&
65
+ !fsmonitor?.isValid(entry);
66
+ const updates: IndexStatUpdate[] = [];
67
+ const unmerged: string[] = [];
68
+ for await (const { item: entry, current } of withWorktreeEntries(worktree, entries, stated)) {
69
+ if (entry.stage !== 0) {
70
+ if (unmerged[unmerged.length - 1] !== entry.path) unmerged.push(entry.path);
71
+ continue;
72
+ }
73
+ if (!stated(entry)) continue;
74
+ const compared = await compareWithWorktree(worktree, entry, { trust, indexTime }, current);
75
+ if (compared.kind) continue;
76
+ const update = statUpdateOf(entry, compared);
77
+ if (update && !update.smudge) {
78
+ // replaced (its stat stored): no longer fsmonitor-valid (replace_index_entry)
79
+ if (!sameStatAsEntry(entry, update)) {
80
+ updates.push(update);
81
+ continue;
82
+ }
83
+ }
84
+ // up to date as it is: mark_fsmonitor_valid
85
+ fsmonitor?.markValid(entry);
86
+ }
87
+ return { updates, unmerged };
88
+ }
89
+
90
+ /** Stores the stats of a refresh in the staging area, in memory (compare-and-set per entry). */
91
+ export async function applyIndexStatUpdates(
92
+ staging: Staging,
93
+ updates: readonly IndexStatUpdate[],
94
+ ): Promise<void> {
95
+ if (updates.length === 0) return;
96
+ const now = Date.now();
97
+ const editor = staging.createEditor();
98
+ for (const update of updates) {
99
+ editor.add({
100
+ path: update.path,
101
+ apply: (existing) => applyStatUpdate(existing, update, now) ?? existing,
102
+ });
103
+ }
104
+ await editor.finish();
105
+ }
106
+
107
+ /** Whether a stat update would store exactly what the entry holds. */
108
+ function sameStatAsEntry(entry: StagingEntry, update: IndexStatUpdate): boolean {
109
+ const same = (a: number | undefined, b: number | undefined) => b === undefined || a === b;
110
+ return (
111
+ entry.size === update.size &&
112
+ entry.mtime === update.mtime &&
113
+ same(entry.mtimeNs, update.mtimeNs) &&
114
+ same(entry.ctime, update.ctime) &&
115
+ same(entry.ctimeNs, update.ctimeNs) &&
116
+ same(entry.dev, update.dev) &&
117
+ same(entry.ino, update.ino) &&
118
+ same(entry.uid, update.uid) &&
119
+ same(entry.gid, update.gid)
120
+ );
121
+ }
@@ -24,9 +24,12 @@ export * from "./cherry-pick-command.js";
24
24
  export * from "./clean-command.js";
25
25
  export * from "./clean-interactive.js";
26
26
  export * from "./clone-command.js";
27
+ export * from "./column/index.js";
28
+ export * from "./column-command.js";
27
29
  export * from "./comment-char-config.js";
28
30
  export * from "./commit-command.js";
29
31
  export * from "./config-command.js";
32
+ export * from "./credential-helper.js";
30
33
  export * from "./daemon-access-hook.js";
31
34
  export * from "./date-format.js";
32
35
  export * from "./default-branch.js";
@@ -71,6 +74,7 @@ export * from "./ls-remote-command.js";
71
74
  export * from "./ls-tree-command.js";
72
75
  export * from "./mailmap.js";
73
76
  export * from "./maintenance-run-command.js";
77
+ export * from "./maintenance-schedule-command.js";
74
78
  export * from "./merge-base-command.js";
75
79
  export * from "./merge-command.js";
76
80
  export {
@@ -85,6 +89,8 @@ export {
85
89
  type MergeDriverResult,
86
90
  mergeDriversOf,
87
91
  } from "./merge-drivers.js";
92
+ export * from "./merge-index-command.js";
93
+ export * from "./merge-one-file.js";
88
94
  export {
89
95
  applyStrategyOption,
90
96
  type MergeStrategyOptions,
@@ -108,6 +114,7 @@ export {
108
114
  combineNotesOverwrite,
109
115
  NotesTree,
110
116
  } from "./notes-tree.js";
117
+ export * from "./object-disk-info.js";
111
118
  export * from "./object-store/index.js";
112
119
  export * from "./pack-refs-command.js";
113
120
  export { type PatchIdTextOptions, patchIdsOfPatchText } from "./patch-id.js";
@@ -154,6 +161,7 @@ export * from "./revision-resolver.js";
154
161
  export * from "./rm-command.js";
155
162
  export { SequencerOperation } from "./sequencer-pick.js";
156
163
  export * from "./serve-repository.js";
164
+ export * from "./served-lazy-fetch.js";
157
165
  export * from "./shortlog.js";
158
166
  export * from "./shortlog-command.js";
159
167
  export * from "./show-branch-command.js";
@@ -175,6 +183,7 @@ export * from "./stash-pop-command.js";
175
183
  export * from "./stash-show-command.js";
176
184
  export * from "./stash-store-command.js";
177
185
  export * from "./stash-working-tree.js";
186
+ export * from "./status-color-config.js";
178
187
  export * from "./status-command.js";
179
188
  export * from "./status-format.js";
180
189
  export * from "./stripspace-command.js";
@@ -59,6 +59,7 @@ import {
59
59
  defaultRefFormat,
60
60
  InvalidInitialBranchError,
61
61
  isValidBranchName,
62
+ type NewRepositoryConfig,
62
63
  } from "./default-branch.js";
63
64
 
64
65
  /**
@@ -119,8 +120,38 @@ export class InitCommand {
119
120
  private template?: { path: string; files?: FilesApi };
120
121
  /** `--shared` as git_config_perm reads it; undefined: core.sharedRepository decides */
121
122
  private shared?: number;
123
+ /** The git version whose hint is given; undefined: the hook runner's, else 2.56 */
124
+ private compatibility?: "2.43" | "2.56";
125
+ /** `-q`: no default-branch hint */
126
+ private quiet = false;
122
127
  private callable = true;
123
128
 
129
+ /**
130
+ * Follow git `version` where versions differ (`setCompatibility("2.43")`): 2.43 hints
131
+ * about the default branch in its own words whatever `advice.defaultBranchName` says,
132
+ * 2.5x reads the setting. Default: the hook runner's compatibility, else 2.56.
133
+ *
134
+ * @param version The git version to follow
135
+ * @returns this for method chaining
136
+ */
137
+ setCompatibility(version: "2.43" | "2.56"): this {
138
+ this.checkCallable();
139
+ this.compatibility = version;
140
+ return this;
141
+ }
142
+
143
+ /**
144
+ * `git init -q`: no default-branch hint ({@link InitResult.hints} undefined) in any version.
145
+ *
146
+ * @param quiet Whether to be quiet
147
+ * @returns this for method chaining
148
+ */
149
+ setQuiet(quiet: boolean): this {
150
+ this.checkCallable();
151
+ this.quiet = quiet;
152
+ return this;
153
+ }
154
+
124
155
  /**
125
156
  * Put the repository at `path` (`git init --separate-git-dir <path>`, a path of the
126
157
  * FilesApi) and write a gitfile in its place (`<directory>/.git`: `gitdir: <path>`, the
@@ -388,14 +419,19 @@ export class InitCommand {
388
419
  let initialBranch = "";
389
420
  let hints: string[] | undefined;
390
421
  const warnings: string[] = [];
391
- const chooseBranch = async () => {
422
+ // `config`: the new repository's (git reads init.defaultBranch once its templates are
423
+ // copied, `includeIf "gitdir:"` matching its git directory); none in memory
424
+ const chooseBranch = async (config?: NewRepositoryConfig) => {
392
425
  if (this.initialBranch !== undefined && !isValidBranchName(this.initialBranch)) {
393
426
  throw new InvalidInitialBranchError(this.initialBranch);
394
427
  }
395
428
  const chosen =
396
429
  this.initialBranch !== undefined
397
430
  ? { name: this.initialBranch }
398
- : await defaultInitialBranch(this.environment);
431
+ : await defaultInitialBranch(this.environment, config, {
432
+ quiet: this.quiet,
433
+ ...(this.compatibility ? { compatibility: this.compatibility } : {}),
434
+ });
399
435
  initialBranch = chosen.name;
400
436
  hints = chosen.hint;
401
437
  };
@@ -478,8 +514,10 @@ export class InitCommand {
478
514
  throw new ReinitializeHashError();
479
515
  }
480
516
  }
481
- if (!hasHead) await chooseBranch();
482
- else if (this.initialBranch !== undefined) {
517
+ // --initial-branch is checked before anything is written; the configured default once
518
+ // the templates are in place (below)
519
+ if (!hasHead && this.initialBranch !== undefined) await chooseBranch();
520
+ else if (hasHead && this.initialBranch !== undefined) {
483
521
  warnings.push(`warning: re-init: ignored --initial-branch=${this.initialBranch}`);
484
522
  }
485
523
  // the ref storage of a repository created here (an existing one keeps its own)
@@ -500,6 +538,21 @@ export class InitCommand {
500
538
  await this.copyTemplates(sharedFiles, dir, warnings);
501
539
  shared = this.shared ?? (await this.configuredShared(repoFiles, dir));
502
540
  if (shared) await adjustSharedPerm(repoFiles, dir, shared);
541
+ // repo_default_branch_name after the templates (2.43's create_default_files, 2.5x's
542
+ // create_reference_database): the whole configuration of the new repository, its
543
+ // `includeIf "gitdir:"` conditions matched against its git directory as the host names it
544
+ if (!hasHead && this.initialBranch === undefined) {
545
+ const newConfig = await createWorkingCopyConfig(
546
+ configFilesApiOf(repoFiles, { readOnly: "init reads the configuration only" }),
547
+ dir,
548
+ undefined,
549
+ {
550
+ ...(this.environment ? { environment: this.environment } : {}),
551
+ gitDirPath: await this.hostPath(repoFiles, dir),
552
+ },
553
+ );
554
+ await chooseBranch(newConfig);
555
+ }
503
556
 
504
557
  // the config, set as create_default_files and init_db set it
505
558
  const configPath = `${dir}/config`;
@@ -23,7 +23,7 @@ import type { FilesApi } from "@statewalker/vcs-utils/files";
23
23
  import type { WorkingCopy } from "@statewalker/vcs-working-tree";
24
24
 
25
25
  import { type LegacyRemote, RemoteConfigStore, setLegacyRemote } from "../remote-config/index.js";
26
- import { defaultBranchHint } from "./default-branch.js";
26
+ import { defaultBranchHint, defaultBranchHint243 } from "./default-branch.js";
27
27
  import { commonGitFileOf } from "./git-hooks.js";
28
28
  import { hostEnvironmentOf } from "./git-ident.js";
29
29
 
@@ -173,27 +173,11 @@ function defaultBranchName(
173
173
  const configured = store.value("init.defaultBranch");
174
174
  if (configured !== undefined && configured !== "") return { name: configured };
175
175
  const name = "master";
176
+ // 2.43 calls advise(), whatever advice.defaultBranchName says; 2.5x advise_if_enabled()
177
+ if (compatibility === "2.43") return { name, hint: defaultBranchHint243(name).join("\n") };
176
178
  const advice = store.value("advice.defaultBranchName");
177
179
  if (advice !== undefined && parseGitBool(advice) === false) return { name };
178
- const hint =
179
- compatibility === "2.43" ? defaultBranchHint243(name) : defaultBranchHint(name, false);
180
- return { name, hint: hint.join("\n") };
181
- }
182
-
183
- /** git 2.43's `default_branch_name_advice` (an empty line is `hint: `, with its space). */
184
- function defaultBranchHint243(name: string): string[] {
185
- return [
186
- `Using '${name}' as the name for the initial branch. This default branch name`,
187
- "is subject to change. To configure the initial branch name to use in all",
188
- "of your new repositories, which will suppress this warning, call:",
189
- "",
190
- "\tgit config --global init.defaultBranch <name>",
191
- "",
192
- "Names commonly chosen instead of 'master' are 'main', 'trunk' and",
193
- "'development'. The just-created branch can be renamed via this command:",
194
- "",
195
- "\tgit branch -m <name>",
196
- ].map((line) => `hint: ${line}`);
180
+ return { name, hint: defaultBranchHint(name, false).join("\n") };
197
181
  }
198
182
 
199
183
  /**