@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
@@ -93,7 +93,7 @@ export interface ParsedRevisionArgs {
93
93
  }
94
94
 
95
95
  /** The state of a revision parse that options share (git's `rev_info`). */
96
- interface RevisionArgState {
96
+ export interface RevisionArgState {
97
97
  /** `--exclude=` patterns, for the next ref option */
98
98
  excludes: string[];
99
99
  inputGiven: boolean;
@@ -112,7 +112,7 @@ const hasGlobSpecials = (text: string) => /[*?[\\]/.test(text);
112
112
  * `main` for `--branches`, `refs/heads/main` for `--all` and `--glob`), and clears the
113
113
  * patterns.
114
114
  */
115
- async function handleRefOption(
115
+ export async function handleRefOption(
116
116
  args: readonly string[],
117
117
  at: number,
118
118
  exclude: boolean,
@@ -127,6 +127,12 @@ export interface ResolveOptions {
127
127
  * length), the storage and mapped compatibility ids disambiguated together
128
128
  */
129
129
  hashAny?: boolean;
130
+ /**
131
+ * git's `GET_OID_REQUIRE_PATH` (`cat-file --textconv`/`--filters` without `--path`): a name
132
+ * that reads no path (`HEAD`, an id) dies `<object>:<path> required, only <object> '<name>'
133
+ * given`
134
+ */
135
+ requirePath?: boolean;
130
136
  }
131
137
 
132
138
  /** git's `get_short_oid` result. */
@@ -206,6 +212,12 @@ export class RevisionResolver {
206
212
  * name that read no entry (`S_IFINVALID`), `<rev>:` (the tree itself) included
207
213
  */
208
214
  lastMode: number | undefined;
215
+ /**
216
+ * The path the last {@link resolve} read an entry at (git's `GET_OID_RECORD_PATH`
217
+ * `object_context.path`: `<rev>:<path>`'s and `:<path>`'s path from the top, "" for
218
+ * `<rev>:`); undefined for a name that reads no path
219
+ */
220
+ lastPath: string | undefined;
209
221
  private config?: RemoteConfigStore;
210
222
  private disambiguateChecked = false;
211
223
  /**
@@ -241,8 +253,14 @@ export class RevisionResolver {
241
253
  async resolve(name: string, options: ResolveOptions = {}): Promise<ObjectId | undefined> {
242
254
  this.checkDisambiguateConfig(name);
243
255
  this.lastMode = undefined;
256
+ this.lastPath = undefined;
244
257
  const direct = await this.oid1(name, options);
245
- if (direct !== undefined) return direct;
258
+ if (direct !== undefined) {
259
+ if (options.requirePath) {
260
+ this.die(name, `fatal: <object>:<path> required, only <object> '${name}' given`);
261
+ }
262
+ return direct;
263
+ }
246
264
  if (name.startsWith(":")) {
247
265
  if (!options.onlyToDie && name.length > 2 && name[1] === "/") {
248
266
  return this.oneline(name.slice(2), await this.allRefCommits());
@@ -254,6 +272,7 @@ export class RevisionResolver {
254
272
  path = name.slice(3);
255
273
  }
256
274
  const resolved = this.relativePath(path, name);
275
+ this.lastPath = resolved;
257
276
  const found = await this.indexEntry(resolved, stage);
258
277
  if (found === undefined && options.onlyToDie && name.length > 1 && name[1] !== "/") {
259
278
  await this.diagnoseIndexPath(name, stage, resolved);
@@ -277,6 +296,7 @@ export class RevisionResolver {
277
296
  return undefined;
278
297
  }
279
298
  const filename = this.relativePath(name.slice(i + 1), name);
299
+ this.lastPath = filename;
280
300
  const tree = await this.peelToType(treeish, "tree");
281
301
  const found = tree === undefined ? undefined : await this.treeEntry(tree, filename);
282
302
  if (found === undefined && options.onlyToDie) {
@@ -29,6 +29,7 @@ import {
29
29
  servedUseBitmaps,
30
30
  withReceiveTransactionHook,
31
31
  } from "./local-transport.js";
32
+ import { type ServedLazyFetchOptions, uploadPackHistory } from "./served-lazy-fetch.js";
32
33
 
33
34
  /** Options of {@link servedRepositoryOf}. */
34
35
  export interface ServedRepositoryOptions {
@@ -40,9 +41,10 @@ export interface ServedRepositoryOptions {
40
41
  */
41
42
  hooks?: HookSession;
42
43
  /**
43
- * Where receive-pack runs (`ReceivePackHost`): whose fsck messages to give (default the
44
- * hooks' runner's compatibility). A served repository's `receive.fsck.skipList` is always
45
- * read confined to its own git directories (`confineFiles`), never from the host
44
+ * Where receive-pack runs (`ReceivePackHost`): whose fsck messages to give and whose v2
45
+ * upload-pack ACKs (2.43: every have held), by default the hooks' runner's compatibility. A
46
+ * served repository's `receive.fsck.skipList` is always read confined to its own git
47
+ * directories (`confineFiles`), never from the host
46
48
  */
47
49
  host?: ReceivePackHost;
48
50
  /**
@@ -52,6 +54,15 @@ export interface ServedRepositoryOptions {
52
54
  * host's hook runner in the git directory (`packObjectsHookOf`); `false` runs none
53
55
  */
54
56
  packObjectsHook?: "protected" | false;
57
+ /**
58
+ * Lets upload-pack fetch the absent promisor objects a pack needs from the served
59
+ * repository's own promisor remotes, through these transports, as git's upload-pack does
60
+ * when its environment sets `GIT_NO_LAZY_FETCH=0`. Off by default, as git's (`could not
61
+ * fetch <id> from promisor remote`); never read from the repository's config. The fetch
62
+ * carries no static credentials or headers: the promisor URLs are the repository's
63
+ * configuration.
64
+ */
65
+ lazyFetch?: ServedLazyFetchOptions;
55
66
  }
56
67
 
57
68
  /** What the served repository's config decides: left to `serveGitService`'s layering. */
@@ -126,20 +137,33 @@ export async function servedRepositoryOf(
126
137
  settings.receivePackConfigError = fsckError;
127
138
  }
128
139
  const hooks = options.hooks;
140
+ // v2 upload-pack's ACKs: git before 2.45 acknowledges every have it holds
141
+ if ((options.host?.compatibility ?? hooks?.compatibility) === "2.43") {
142
+ settings.acknowledgeEveryHave = true;
143
+ }
129
144
  if (options.packObjectsHook !== false && hooks) {
130
145
  const hook = await packObjectsHookOf(hooks);
131
146
  if (hook) settings.packObjectsHook = hook;
132
147
  }
133
- return {
134
- repository: createRepositoryFacade({
135
- history: historyWithoutLazyFetch(remote.history),
148
+ const facadeOf = (history: typeof remote.history) =>
149
+ createRepositoryFacade({
150
+ history,
136
151
  // git's pack.useBitmaps (pack-objects reads it from the served repository)
137
152
  useBitmaps: servedUseBitmaps(remote),
138
153
  // a sparse:oid filter's patterns
139
154
  sparseFilterPatterns: sparseFilterMatcher,
140
155
  // core.maxTreeDepth (pack-objects' walk)
141
156
  maxTreeDepth: servedMaxTreeDepth(remote),
142
- }),
157
+ });
158
+ // receive-pack never fetches lazily (rev-list --exclude-promisor-objects): the history's
159
+ // view without lazy fetch
160
+ const plain = historyWithoutLazyFetch(remote.history);
161
+ // upload-pack: a view of its own refusing absent promisor objects as git's under its
162
+ // GIT_NO_LAZY_FETCH, or fetching them when the operator opted in (`lazyFetch`)
163
+ const forUploadPack = await uploadPackHistory(remote, options.lazyFetch, hooks?.hostEnvironment);
164
+ return {
165
+ repository: facadeOf(plain),
166
+ ...(forUploadPack !== plain ? { uploadPackRepository: facadeOf(forUploadPack) } : {}),
143
167
  refStore: createTransportRefStore(remote.history.refs),
144
168
  config: remote.config ?? EMPTY_CONFIG,
145
169
  settings: settings as GitServeSettings,
@@ -153,14 +177,15 @@ export async function servedRepositoryOf(
153
177
  return uploadArchive ? { uploadArchive } : {};
154
178
  })(),
155
179
  around: <T>(service: string, serve: () => Promise<T>, client?: ServedRequestContext) => {
156
- // a served partial clone never fetches lazily (upload-pack's GIT_NO_LAZY_FETCH,
157
- // receive-pack's rev-list --exclude-promisor-objects): the facade reads through the
158
- // history's view without lazy fetch
159
180
  if (service !== "git-receive-pack") return serve();
160
181
  if (!hooks?.enabled) return serve();
161
182
  // the client's variables (http-backend's REMOTE_USER, ...) reach the
162
183
  // reference-transaction hook too, as every child of receive-pack inherits them
163
- const env = httpBackendEnv(hooks, client);
184
+ // (GIT_NAMESPACE too, when the push is served in a namespace)
185
+ const env: Record<string, string> = {
186
+ ...(client?.namespace ? { GIT_NAMESPACE: client.namespace } : {}),
187
+ ...httpBackendEnv(hooks, client),
188
+ };
164
189
  const session = Object.keys(env).length > 0 ? hooks.withEnv(env) : hooks;
165
190
  return withReceiveTransactionHook(remote, session, serve);
166
191
  },
@@ -175,6 +200,10 @@ export async function servedRepositoryOf(
175
200
  * pack-objects ...` through the shell, in the git directory). Undefined when none is set or
176
201
  * no runner can start it.
177
202
  *
203
+ * With `commandLine: false` the command line's entries (scope `command`) do not count: git's
204
+ * local transport starts `git-upload-pack '<path>'` with connect.c's `local_repo_env` cleared
205
+ * (`GIT_CONFIG_PARAMETERS`, `GIT_CONFIG_COUNT`), so only the system and global files reach it.
206
+ *
178
207
  * @example
179
208
  * ```ts
180
209
  * // ~/.gitconfig: [uploadpack] packObjectsHook = /srv/bin/pack-cache
@@ -183,11 +212,13 @@ export async function servedRepositoryOf(
183
212
  */
184
213
  export async function packObjectsHookOf(
185
214
  hooks: HookSession | undefined,
215
+ options: { commandLine?: boolean } = {},
186
216
  ): Promise<PackObjectsHook | undefined> {
187
217
  const environment = hooks?.hostEnvironment;
188
218
  if (!hooks?.enabled || !environment) return undefined;
189
219
  let command: string | undefined;
190
220
  for (const entry of await readProtectedConfig(environment)) {
221
+ if (options.commandLine === false && entry.scope === "command") continue;
191
222
  if (entry.key.toLowerCase() === "uploadpack.packobjectshook") command = entry.value;
192
223
  }
193
224
  if (!command) return undefined;
@@ -0,0 +1,164 @@
1
+ /**
2
+ * The lazy fetch of a served partial clone while upload-pack builds a pack (git's
3
+ * upload-pack, whose pack-objects reads an absent promisor object through
4
+ * promisor_remote_get_direct).
5
+ *
6
+ * Since git 2.45 (and the 2.43.4 backport) upload-pack sets `GIT_NO_LAZY_FETCH=1` unless its
7
+ * environment already sets the variable, so by default a pack that needs an absent promisor
8
+ * object fails: pack-objects prints `warning: lazy fetching disabled; some objects may not be
9
+ * available` and dies `could not fetch <id> from promisor remote`. Ours does the same unless
10
+ * lazy fetching is opted in: the operator's `servedRepositoryOf(opened, { lazyFetch })`, or a
11
+ * local remote's upload-pack when the client's host environment says `GIT_NO_LAZY_FETCH=0`
12
+ * (git's child inherits it). Then the absent object is fetched from the served repository's
13
+ * own promisor remotes, through the transports given, and the pack holds it.
14
+ *
15
+ * Promisor URLs come from the served repository's configuration, which is repository content:
16
+ * the fetch never carries static credentials or headers, only a per-URL credential helper.
17
+ *
18
+ * @example
19
+ * ```ts
20
+ * const served = await servedRepositoryOf(opened, {
21
+ * lazyFetch: { transports: createDefaultTransports() },
22
+ * });
23
+ * ```
24
+ */
25
+
26
+ import {
27
+ type History,
28
+ historyWithoutLazyFetch,
29
+ historyWithPromisorFetcher,
30
+ type ObjectId,
31
+ type PromisorFetcher,
32
+ } from "@statewalker/vcs-core";
33
+ import type { GitTransportRegistry, HttpCredentialHelper } from "@statewalker/vcs-transport";
34
+ import type {
35
+ GitHostEnvironment,
36
+ OpenedRepository,
37
+ WorkingCopy,
38
+ } from "@statewalker/vcs-working-tree";
39
+ import { RemoteConfigStore } from "../remote-config/index.js";
40
+ import {
41
+ createPromisorFetcher,
42
+ hasPromisorRemote,
43
+ LAZY_FETCH_DISABLED_WARNING,
44
+ } from "./promisor-remote.js";
45
+ import { worktreeAdminWorkingCopy } from "./worktree-support.js";
46
+
47
+ /**
48
+ * How a served repository fetches its absent promisor objects (see the module
49
+ * documentation). Static credentials and headers are deliberately not among them.
50
+ */
51
+ export interface ServedLazyFetchOptions {
52
+ /** The transports the promisor remotes are reached through (default: smart HTTP) */
53
+ transports?: GitTransportRegistry;
54
+ /** Asked for HTTP credentials after a 401, per URL */
55
+ credentialHelper?: HttpCredentialHelper;
56
+ timeout?: number;
57
+ /** git's `warning:` lines of the HTTP client */
58
+ warningCallback?: (line: string) => void;
59
+ /**
60
+ * The host environment the fetch runs in (its file reads, hook runner and git version);
61
+ * by default the served repository's hooks' environment
62
+ */
63
+ environment?: GitHostEnvironment;
64
+ }
65
+
66
+ /**
67
+ * The history upload-pack reads for `remote`, as git's upload-pack reads it: a view of its
68
+ * own whose absent promisor objects are refused with git's warning and death
69
+ * (`GIT_NO_LAZY_FETCH=1`), or, when `lazyFetch` opts in, fetched from the repository's
70
+ * promisor remotes through its transports. The store's promisor and fetcher are left as
71
+ * they are, so receive-pack and every other reader of the store are untouched. A repository
72
+ * without worktrees or promisor remotes, or without promisor packs unless `lazyFetch` is
73
+ * given, is read through its view without lazy fetch.
74
+ *
75
+ * @example
76
+ * ```ts
77
+ * const history = await uploadPackHistory(opened, { transports }, hooks.hostEnvironment);
78
+ * ```
79
+ */
80
+ export async function uploadPackHistory(
81
+ remote: OpenedRepository,
82
+ lazyFetch: ServedLazyFetchOptions | undefined,
83
+ environment: GitHostEnvironment | undefined,
84
+ ): Promise<History> {
85
+ const plain = historyWithoutLazyFetch(remote.history);
86
+ const promisor = (() => {
87
+ try {
88
+ return remote.history.objects?.promisor;
89
+ } catch {
90
+ return undefined;
91
+ }
92
+ })();
93
+ if (!promisor || !remote.worktrees) return plain;
94
+ // not a partial clone: nothing to refuse (git's refusal dies only for promisor objects)
95
+ if (!lazyFetch && (await promisor.promisorPacks().catch(() => [])).length === 0) return plain;
96
+ let view: History | undefined;
97
+ const workingCopy = await servedWorkingCopy(
98
+ remote,
99
+ () => view ?? plain,
100
+ lazyFetch?.environment ?? environment,
101
+ ).catch(() => undefined);
102
+ if (!workingCopy || !hasPromisorRemote(RemoteConfigStore.from(workingCopy))) return plain;
103
+ // never the operator's or a client's static credentials: the promisor URL is the served
104
+ // repository's configuration
105
+ const fetcher = lazyFetch
106
+ ? createPromisorFetcher(workingCopy, {
107
+ ...(lazyFetch.transports ? { transports: lazyFetch.transports } : {}),
108
+ ...(lazyFetch.credentialHelper ? { credentialHelper: lazyFetch.credentialHelper } : {}),
109
+ ...(lazyFetch.timeout !== undefined ? { timeout: lazyFetch.timeout } : {}),
110
+ ...(lazyFetch.warningCallback ? { warningCallback: lazyFetch.warningCallback } : {}),
111
+ })
112
+ : refusingFetcher(() => view?.objects?.promisor?.warnings);
113
+ view = historyWithPromisorFetcher(remote.history, fetcher);
114
+ return view ?? plain;
115
+ }
116
+
117
+ /**
118
+ * upload-pack's `GIT_NO_LAZY_FETCH=1`: every read of an absent object still asks (git's
119
+ * pack-objects reads with `fetch_if_missing`), fetch_objects refuses with its warning (once
120
+ * per upload-pack process: a refusal of a promisor object is its death), and
121
+ * promisor_remote_get_direct dies for a promisor object.
122
+ */
123
+ function refusingFetcher(warnings: () => string[] | undefined): PromisorFetcher {
124
+ return {
125
+ hasPromisorRemote: () => true,
126
+ invalidate: () => {},
127
+ fetchIfMissing: () => true,
128
+ async fetch(ids: readonly ObjectId[]) {
129
+ warnings()?.push(LAZY_FETCH_DISABLED_WARNING);
130
+ return ids;
131
+ },
132
+ };
133
+ }
134
+
135
+ /**
136
+ * The served repository as a working copy the promisor fetcher reads (its configuration,
137
+ * remotes, local paths), over the history `history` gives (upload-pack's view: the fetch's
138
+ * warnings go to its promisor, its objects to the store) and in `environment`.
139
+ */
140
+ async function servedWorkingCopy(
141
+ remote: OpenedRepository,
142
+ history: () => History,
143
+ environment: GitHostEnvironment | undefined,
144
+ ): Promise<WorkingCopy | undefined> {
145
+ const worktrees = remote.worktrees;
146
+ if (!worktrees) return undefined;
147
+ const base = worktreeAdminWorkingCopy(await worktrees.openAdmin());
148
+ const own = <O extends object>(target: O, key: string | symbol): unknown => {
149
+ const value = Reflect.get(target, key, target);
150
+ return typeof value === "function" ? value.bind(target) : value;
151
+ };
152
+ const config = environment
153
+ ? new Proxy(base.config, {
154
+ get: (target, key) => (key === "environment" ? environment : own(target, key)),
155
+ })
156
+ : base.config;
157
+ return new Proxy(base, {
158
+ get: (target, key) => {
159
+ if (key === "history") return history();
160
+ if (key === "config") return config;
161
+ return own(target, key);
162
+ },
163
+ });
164
+ }
@@ -11,8 +11,9 @@
11
11
  * `commit_tree_extended` / `add_header_signature` do. `commit -S` and `tag -s`/`-u` sign (the
12
12
  * tag's signature appended to its message, builtin/tag.c's `do_sign`), and so do the
13
13
  * commands that write commits for the user: rebase, cherry-pick, revert, merge and am
14
- * (statewalker/statewalker-root#319, each through {@link signCommit}); push certificates
15
- * still refuse.
14
+ * (statewalker/statewalker-root#319, each through {@link signCommit}). `push --signed` signs
15
+ * its push certificate too (send-pack's `generate_push_cert`): `PushCommand`'s push
16
+ * certificate signer hands the certificate to {@link signPayload}.
16
17
  *
17
18
  * Without a signer every request to sign fails as native git fails when its signing program
18
19
  * cannot sign (gpg-interface.c `sign_buffer_gpg`: `error: gpg failed to sign the data:` with
@@ -46,6 +47,7 @@ import {
46
47
  import { GitApiError, InvalidConfigError } from "../errors/index.js";
47
48
  import { type ConfigValueWhere, RemoteConfigStore } from "../remote-config/index.js";
48
49
  import { hostEnvironmentOf } from "./git-ident.js";
50
+ import { splitCmdline } from "./split-cmdline.js";
49
51
 
50
52
  /**
51
53
  * A request to sign: the key to sign with (`""`: the default key, git's `-S` without a key
@@ -492,11 +494,90 @@ function sshPublicKeyBlob(text: string): Uint8Array | undefined {
492
494
  return field ? base64Bytes(field) : undefined;
493
495
  }
494
496
 
497
+ /**
498
+ * Where {@link signingKeyIdOf} runs `gpg.ssh.defaultKeyCommand` and reads a relative key path
499
+ * (a command's {@link HookSession}).
500
+ */
501
+ export interface SigningKeyHost {
502
+ /**
503
+ * Runs an argv without a shell in the directory git runs in (the worktree top), as git's
504
+ * `pipe_command` with `use_shell = 0` runs it (`HookSession.runArgv`): `startError` is git's
505
+ * line for a program it cannot start
506
+ */
507
+ runArgv(
508
+ name: string,
509
+ argv: readonly string[],
510
+ ): Promise<{ exitCode: number; stdout: string; stderr: string; startError?: string } | undefined>;
511
+ /** That directory on the host, where the repository's files have one */
512
+ hostWorkingDirectory(): Promise<string | undefined>;
513
+ }
514
+
515
+ /** How {@link signingKeyIdOf} finds the key. */
516
+ export interface SigningKeyIdOptions {
517
+ /** Runs `gpg.ssh.defaultKeyCommand`, resolves a relative key path; without it neither is */
518
+ host?: SigningKeyHost;
519
+ /**
520
+ * The git version followed: 2.43 (up to 2.51) keeps the space after an ssh fingerprint
521
+ * (`strbuf_split_max`), 2.52+ cuts the fingerprint at it. Default 2.56
522
+ */
523
+ compatibility?: "2.43" | "2.56";
524
+ }
525
+
526
+ /** gpg-interface.c's `is_literal_ssh_key`: the key itself rather than a file naming it. */
527
+ function isLiteralSshKey(key: string): boolean {
528
+ return key.startsWith("key::") || key.startsWith("ssh-");
529
+ }
530
+
531
+ /**
532
+ * gpg-interface.c's `get_default_ssh_signing_key` (as `get_signing_key_id` runs it): the
533
+ * first line of `command`'s output, newline kept, when it is a literal key. git goes on with
534
+ * a NULL key when it is not and crashes in `get_ssh_key_fingerprint` (SIGSEGV) after its
535
+ * warning: that is thrown with exit status 139.
536
+ */
537
+ async function defaultSshSigningKey(
538
+ command: string,
539
+ sign: string,
540
+ host: SigningKeyHost | undefined,
541
+ ): Promise<string> {
542
+ const argv = splitCmdline(command);
543
+ if (typeof argv === "string") {
544
+ throw new SigningFailedError(
545
+ `fatal: malformed build-time gpg.ssh.defaultKeyCommand: ${argv}`,
546
+ sign,
547
+ 128,
548
+ );
549
+ }
550
+ const program = argv[0] ?? "";
551
+ const messages: string[] = [];
552
+ // pipe_command of an empty program: execvp("") fails, start_command names no program
553
+ let ran: { exitCode: number; stdout: string; stderr: string; startError?: string } | undefined;
554
+ if (program === "") messages.push("error: cannot run : No such file or directory");
555
+ else {
556
+ // pipe_command with use_shell = 0: execvp of the split words, no shell
557
+ ran = await host?.runArgv("gpg.ssh.defaultKeyCommand", argv);
558
+ if (ran?.startError !== undefined) messages.push(ran.startError);
559
+ }
560
+ const stdout = ran?.stdout ?? "";
561
+ const stderr = ran?.stderr ?? "";
562
+ if (ran?.exitCode === 0) {
563
+ const nl = stdout.indexOf("\n");
564
+ const first = nl < 0 ? stdout : stdout.slice(0, nl + 1);
565
+ if (first !== "" && isLiteralSshKey(first)) return first;
566
+ messages.push(
567
+ `warning: gpg.ssh.defaultKeyCommand succeeded but returned no keys: ${stderr} ${stdout}`,
568
+ );
569
+ } else messages.push(`warning: gpg.ssh.defaultKeyCommand failed: ${stderr} ${stdout}`);
570
+ throw new SigningFailedError(messages.join("\n"), sign, 139);
571
+ }
572
+
495
573
  /**
496
574
  * gpg-interface.c's `get_signing_key_id()` for `sign` (`""`: the default key): the key of an
497
575
  * openpgp or x509 signature (`user.signingKey`, else the committer as `Name <email>`), the
498
576
  * SHA-256 fingerprint of an ssh key (`ssh-keygen -lf`'s `SHA256:...`, for a literal key, a
499
- * public key file or an OpenSSH private key file).
577
+ * public key file or an OpenSSH private key file). Without a key, ssh's comes from
578
+ * `gpg.ssh.defaultKeyCommand` (`get_default_ssh_signing_key`), run through `options.host`. A
579
+ * key file is read as `ssh-keygen -lf <key>` reads it in the directory git runs in: a relative
580
+ * path from the worktree top, `~/` not expanded (git passes the key as configured).
500
581
  *
501
582
  * @throws SigningFailedError as git dies when it cannot fingerprint an ssh key (`fatal: failed
502
583
  * to get the ssh fingerprint for key '<key>'`), or has none
@@ -505,34 +586,44 @@ export async function signingKeyIdOf(
505
586
  workingCopy: WorkingCopy,
506
587
  sign: string,
507
588
  committer: Pick<PersonIdent, "name" | "email">,
589
+ options: SigningKeyIdOptions = {},
508
590
  ): Promise<string> {
509
591
  const config = signingConfigOf(workingCopy);
510
- const key = sign !== "" ? sign : config.signingKey;
592
+ let key = sign !== "" ? sign : config.signingKey;
511
593
  if (config.format !== "ssh") return key ?? `${committer.name} <${committer.email}>`;
512
594
  if (key === undefined) {
513
- throw new SigningFailedError(
514
- "fatal: either user.signingkey or gpg.ssh.defaultKeyCommand needs to be configured",
515
- sign,
516
- 128,
517
- );
595
+ if (config.defaultKeyCommand === undefined) {
596
+ throw new SigningFailedError(
597
+ "fatal: either user.signingkey or gpg.ssh.defaultKeyCommand needs to be configured",
598
+ sign,
599
+ 128,
600
+ );
601
+ }
602
+ key = await defaultSshSigningKey(config.defaultKeyCommand, sign, options.host);
518
603
  }
519
604
  let text: string | undefined;
520
605
  if (key.startsWith("key::")) text = key.slice(5);
521
606
  else if (key.startsWith("ssh-")) text = key;
522
607
  else {
523
608
  const environment = hostEnvironmentOf(workingCopy);
524
- const path = expandUserPath(key, environment) ?? key;
609
+ let path = key;
610
+ if (!path.startsWith("/")) {
611
+ const cwd = await options.host?.hostWorkingDirectory().catch(() => undefined);
612
+ if (cwd !== undefined) path = `${cwd.replace(/\/+$/, "")}/${path}`;
613
+ }
525
614
  const bytes = await environment?.readFile(path).catch(() => undefined);
526
615
  text = bytes ? new TextDecoder().decode(bytes) : undefined;
527
616
  }
528
617
  const blob = text === undefined ? undefined : sshPublicKeyBlob(text);
529
618
  if (!blob) {
619
+ // die_errno after ssh-keygen failed: errno is still 0
530
620
  throw new SigningFailedError(
531
- `fatal: failed to get the ssh fingerprint for key '${key}'`,
621
+ `fatal: failed to get the ssh fingerprint for key '${key}': Success`,
532
622
  sign,
533
623
  128,
534
624
  );
535
625
  }
536
626
  const digest = createSha256().update(blob).digest();
537
- return `SHA256:${btoa(String.fromCharCode(...digest)).replace(/=+$/, "")}`;
627
+ const fingerprint = `SHA256:${btoa(String.fromCharCode(...digest)).replace(/=+$/, "")}`;
628
+ return options.compatibility === "2.43" ? `${fingerprint} ` : fingerprint;
538
629
  }
@@ -0,0 +1,32 @@
1
+ /**
2
+ * alias.c's split_cmdline: words split on whitespace, quotes removed, a backslash escaping
3
+ * the next character outside single quotes; split_cmdline_strerror's text on an error.
4
+ */
5
+ export function splitCmdline(line: string): string[] | string {
6
+ // one word to begin with; every whitespace run ends one and starts the next (a trailing
7
+ // run leaves an empty last word, as git's)
8
+ const args: string[] = [];
9
+ let current = "";
10
+ let quoted = "";
11
+ for (let i = 0; i < line.length; i++) {
12
+ const c = line[i] as string;
13
+ if (!quoted && /[ \t\n\r]/.test(c)) {
14
+ args.push(current);
15
+ current = "";
16
+ while (i + 1 < line.length && /[ \t\n\r]/.test(line[i + 1] as string)) i++;
17
+ } else if (!quoted && (c === "'" || c === '"')) {
18
+ quoted = c;
19
+ } else if (c === quoted) {
20
+ quoted = "";
21
+ } else {
22
+ if (c === "\\" && quoted !== "'") {
23
+ i++;
24
+ if (i >= line.length) return "cmdline ends with \\";
25
+ }
26
+ current += line[i];
27
+ }
28
+ }
29
+ if (quoted) return "unclosed quote";
30
+ args.push(current);
31
+ return args;
32
+ }
@@ -0,0 +1,92 @@
1
+ /**
2
+ * The colors of `git status` (and `git commit --dry-run`) as builtin/commit.c's
3
+ * `git_status_config` reads them: `color.status` or `status.color` (a color bool, the last
4
+ * one read wins), else `color.ui`; the slots through `color.status.<slot>` or
5
+ * `status.color.<slot>` (`header`, `updated` or `added`, `changed`, `untracked`,
6
+ * `noBranch`, `unmerged`, `localBranch`, `remoteBranch`, `branch`), each parsed as git's
7
+ * colors. A slot git does not know is ignored, a known one without a value or with a value
8
+ * git refuses dies as git dies. Without a terminal `auto` means no color.
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * const colors = readStatusColors(workingCopy); // undefined: no color
13
+ * formatStatusText(status, header, { format: "short", colors });
14
+ * ```
15
+ *
16
+ * @module
17
+ */
18
+
19
+ import type { WorkingCopy } from "@statewalker/vcs-working-tree";
20
+
21
+ import { InvalidConfigError } from "../errors/index.js";
22
+ import { RemoteConfigStore } from "../remote-config/index.js";
23
+ import { parseGitColor } from "./config-value-types.js";
24
+ import { badConfigVariableLine, readColorBool } from "./diff-color-config.js";
25
+ import { DEFAULT_STATUS_COLORS, type StatusColors } from "./status-format.js";
26
+
27
+ /** builtin/commit.c's `color_status_slots` (and `added`), by lowercased name */
28
+ const STATUS_SLOTS: Record<string, keyof StatusColors> = {
29
+ header: "header",
30
+ updated: "updated",
31
+ added: "updated",
32
+ changed: "changed",
33
+ untracked: "untracked",
34
+ nobranch: "noBranch",
35
+ unmerged: "unmerged",
36
+ localbranch: "localBranch",
37
+ remotebranch: "remoteBranch",
38
+ branch: "branch",
39
+ };
40
+
41
+ /** What the caller says about colors (each unset: the configuration's) */
42
+ export interface StatusColorOptions {
43
+ /** A color option: true is `always`, false `never` */
44
+ color?: boolean | "always" | "never" | "auto";
45
+ /** 2.43 knows no `#rgb` colors (default 2.56) */
46
+ compatibility?: "2.43" | "2.56";
47
+ }
48
+
49
+ /**
50
+ * The palette of status's human formats, or undefined for no color.
51
+ *
52
+ * @throws InvalidConfigError for a value git refuses (exit 128)
53
+ */
54
+ export function readStatusColors(
55
+ workingCopy: WorkingCopy,
56
+ options: StatusColorOptions = {},
57
+ ): StatusColors | undefined {
58
+ const compatibility = options.compatibility ?? "2.56";
59
+ const colors: StatusColors = { ...DEFAULT_STATUS_COLORS };
60
+ let ui: "never" | "always" | "auto" | undefined;
61
+ let status: "never" | "always" | "auto" | undefined;
62
+ const entries = workingCopy.config
63
+ ? (RemoteConfigStore.from(workingCopy).allEntriesWithOrigin() ?? [])
64
+ : [];
65
+ for (const { key, text, file, line } of entries) {
66
+ if (key === "color.ui") ui = readColorBool(key, text);
67
+ else if (key === "color.status" || key === "status.color") status = readColorBool(key, text);
68
+ else if (key.startsWith("color.status.") || key.startsWith("status.color.")) {
69
+ const slot = STATUS_SLOTS[key.slice(13).toLowerCase()];
70
+ if (!slot) continue;
71
+ if (text === undefined) {
72
+ throw new InvalidConfigError(
73
+ key,
74
+ `error: missing value for '${key}'\n${badConfigVariableLine(key, file, line)}`,
75
+ );
76
+ }
77
+ const color = parseGitColor(text, compatibility);
78
+ if (color === undefined) {
79
+ throw new InvalidConfigError(
80
+ key,
81
+ `error: invalid color value: ${text}\n${badConfigVariableLine(key, file, line)}`,
82
+ );
83
+ }
84
+ colors[slot] = color;
85
+ }
86
+ }
87
+ let want = status ?? ui ?? "auto";
88
+ if (options.color !== undefined) {
89
+ want = options.color === true ? "always" : options.color === false ? "never" : options.color;
90
+ }
91
+ return want === "always" ? colors : undefined;
92
+ }