@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
@@ -103,6 +103,11 @@ import {
103
103
  saveAutostash,
104
104
  } from "./sequencer-support.js";
105
105
  import { showCommit } from "./show-commit.js";
106
+ import {
107
+ readStoredObjectBytes,
108
+ type SignatureCheck,
109
+ verifyCommitBytes,
110
+ } from "./signature-check.js";
106
111
  import { SigningFailedError, type SignRequest, signRequestOf } from "./signing.js";
107
112
  import {
108
113
  amendWithTrailers,
@@ -374,7 +379,10 @@ export class RebaseCommand extends GitCommand<RebaseResult> {
374
379
  private readonly subjects = new Map<ObjectId, string>();
375
380
  /** The refs' decorations, for `%d` in rebase.instructionFormat (loaded once) */
376
381
  private decorations?: RefDecorations;
377
- /** What loading the decorations printed (`warning: invalid replace ref <name>`) */
382
+ /**
383
+ * What writing the todo list printed: loading the decorations (`warning: invalid replace
384
+ * ref <name>`), the `%G` checks (check_signature's `error:` lines)
385
+ */
378
386
  private decorationWarnings: string[] = [];
379
387
  /** `--exec <command>` (each run after every pick) */
380
388
  private execCommands: string[] = [];
@@ -1013,6 +1021,15 @@ export class RebaseCommand extends GitCommand<RebaseResult> {
1013
1021
  return this;
1014
1022
  }
1015
1023
 
1024
+ /** git sets `warn_on_auto_comment_char`: 2.5x warns of `core.commentChar=auto` here. */
1025
+ protected override autoCommentCharWarningEntryPoints(): readonly string[] {
1026
+ return ["call"];
1027
+ }
1028
+
1029
+ protected override gitCompatibility(): "2.43" | "2.56" {
1030
+ return this.compatibility ?? this.hooks.compatibility;
1031
+ }
1032
+
1016
1033
  async call(): Promise<RebaseResult> {
1017
1034
  this.checkCallable();
1018
1035
  this.setCallable(false);
@@ -1532,6 +1549,8 @@ export class RebaseCommand extends GitCommand<RebaseResult> {
1532
1549
  action: "checkout",
1533
1550
  operation: "rebase",
1534
1551
  targetTree: ontoTreeId,
1552
+ // reset_head of onto, detached (no ref): the commit for the filter process
1553
+ metadata: { treeish: onto },
1535
1554
  });
1536
1555
  if (refused) {
1537
1556
  await unstash();
@@ -1731,6 +1750,8 @@ export class RebaseCommand extends GitCommand<RebaseResult> {
1731
1750
  action: "checkout",
1732
1751
  operation: "rebase",
1733
1752
  targetTree: ontoTreeId,
1753
+ // reset_head of onto, detached (no ref): the commit for the filter process
1754
+ metadata: { treeish: onto },
1734
1755
  });
1735
1756
  if (!refused) {
1736
1757
  await state.setRef("ORIG_HEAD", origHead);
@@ -1784,6 +1805,8 @@ export class RebaseCommand extends GitCommand<RebaseResult> {
1784
1805
  action: "checkout",
1785
1806
  operation: "rebase",
1786
1807
  targetTree: startTreeId,
1808
+ // checkout_onto: the commit for a long-running filter process
1809
+ metadata: { treeish: start },
1787
1810
  });
1788
1811
  if (refused) {
1789
1812
  await state.remove(DIR);
@@ -3862,6 +3885,8 @@ export class RebaseCommand extends GitCommand<RebaseResult> {
3862
3885
  action: "checkout",
3863
3886
  operation: "rebase",
3864
3887
  targetTree: ontoTreeId,
3888
+ // reset_head of onto, detached (no ref): the commit for the filter process
3889
+ metadata: { treeish: onto },
3865
3890
  });
3866
3891
  if (refused) {
3867
3892
  await unstash();
@@ -5048,10 +5073,28 @@ export class RebaseCommand extends GitCommand<RebaseResult> {
5048
5073
  ...(this.decorations ? { decorations: this.decorations } : {}),
5049
5074
  ...(format.includes("%(trailers") ? { trailers: trailerConfigOf(this.workingCopy) } : {}),
5050
5075
  ...(format.includes("%(describe") ? { describe: this.describer() } : {}),
5076
+ ...(format.includes("%G") ? { signature: () => this.instructionSignature(id) } : {}),
5051
5077
  });
5052
5078
  return text.replace(/[ \t]+$/, "");
5053
5079
  }
5054
5080
 
5081
+ /**
5082
+ * The `%G` placeholders of rebase.instructionFormat: the commit's signature checked through
5083
+ * the host's verifier (pretty.c's check_commit_signature, as log's), the check's own error
5084
+ * lines on stderr with the rebase's other messages.
5085
+ */
5086
+ private async instructionSignature(id: ObjectId): Promise<SignatureCheck> {
5087
+ const bytes = await readStoredObjectBytes(this._workingCopy, id);
5088
+ if (!bytes) return { result: "N", trustLevel: "undefined", failed: true, messages: [] };
5089
+ const cwd = await this.hostWorkingDir();
5090
+ const check = await verifyCommitBytes(this._workingCopy, bytes, {
5091
+ objectFormat: this.objectFormat,
5092
+ ...(cwd !== undefined ? { cwd } : {}),
5093
+ });
5094
+ this.decorationWarnings.push(...check.messages);
5095
+ return check;
5096
+ }
5097
+
5055
5098
  /** `%(describe)` of rebase.instructionFormat: git describe over this repository's tags. */
5056
5099
  private describer(): (id: ObjectId, options: DescribeOptions) => Promise<string> {
5057
5100
  const abbreviator = createIdAbbreviator(this._workingCopy);
@@ -5300,6 +5343,8 @@ export class RebaseCommand extends GitCommand<RebaseResult> {
5300
5343
  action: "checkout",
5301
5344
  operation: "rebase",
5302
5345
  targetTree: targetTreeId,
5346
+ // reset_head with the branch: its full name and commit for the filter process
5347
+ metadata: { ...(headName.startsWith("refs/") ? { ref: headName } : {}), treeish: origHead },
5303
5348
  });
5304
5349
  if (refused) {
5305
5350
  return {
@@ -62,8 +62,9 @@ export const DEFAULT_FOR_EACH_REF_FORMAT = "%(objectname) %(objecttype)\t%(refna
62
62
  * names as paths (`refs/heads` matches `refs/heads/x`) or as globs. Sort keys are given in
63
63
  * command-line order (the last one is the primary key), `refname` after them unless
64
64
  * {@link setNoSort}; `-key` reverses and `version:key` compares as versions
65
- * (`versionsort.suffix`). Not supported: `%(objectsize:disk)`, `%(deltabase)` and signature
66
- * verification (`%(signature)` of a signed commit) refuse with a {@link RefFilterError}.
65
+ * (`versionsort.suffix`). `%(signature...)` checks a commit's signature through the host's
66
+ * verifier, as `verify-commit` does (its error lines in `warnings`). `%(objectsize:disk)` and
67
+ * `%(deltabase)` read the object's pack entry header or loose file (`objectDiskInfoOf`).
67
68
  */
68
69
  export class ForEachRefCommand extends RefListingCommand<ForEachRefResult> {
69
70
  private format = DEFAULT_FOR_EACH_REF_FORMAT;
@@ -292,7 +293,7 @@ export class ForEachRefCommand extends RefListingCommand<ForEachRefResult> {
292
293
  output: result.output,
293
294
  lines: result.lines,
294
295
  refs: result.items.map((i: RefFilterItem) => ({ refname: i.refname, objectId: i.objectId })),
295
- warnings: [...baseWarnings, ...result.warnings],
296
+ warnings: [...baseWarnings, ...result.warnings, ...format.messages],
296
297
  };
297
298
  }
298
299
  }
@@ -423,7 +423,6 @@ export async function sortRefs(
423
423
  warnings: string[] = [],
424
424
  ): Promise<void> {
425
425
  if (sorting.length === 0) return;
426
- for (const item of items) for (const key of sorting) await format.value(item, key.atom);
427
426
  let suffixes: string[] | undefined;
428
427
  const compareKey = (key: RefSortKey, a: RefFilterItem, b: RefFilterItem): number => {
429
428
  const va = (a.values as NonNullable<RefFilterItem["values"]>)[key.atom];
@@ -445,15 +444,67 @@ export async function sortRefs(
445
444
  return key.reverse && !detached ? -cmp : cmp;
446
445
  };
447
446
  const first = sorting[0] as RefSortKey;
448
- items.sort((a, b) => {
447
+ // compare_refs: each key's values, `a`'s then `b`'s, computed when first asked (every atom
448
+ // of a ref at once, populate_value: the order git's checks print their errors in)
449
+ const compare = async (a: RefFilterItem, b: RefFilterItem): Promise<number> => {
449
450
  for (const key of sorting) {
451
+ await format.value(a, key.atom);
452
+ await format.value(b, key.atom);
450
453
  const cmp = compareKey(key, a, b);
451
454
  if (cmp) return cmp;
452
455
  }
453
456
  return first.icase
454
457
  ? compareBytesIcase(a.refname, b.refname)
455
458
  : compareBytes(a.refname, b.refname);
456
- });
459
+ };
460
+ const sorted = await mergeSort(items, compare);
461
+ for (let i = 0; i < sorted.length; i++) items[i] = sorted[i] as RefFilterItem;
462
+ }
463
+
464
+ /**
465
+ * compat/qsort_s.c's msort_with_tmp (git's QSORT_S on platforms without an ISO qsort_s):
466
+ * a stable merge sort comparing in the order git does, the left half sorted first.
467
+ */
468
+ async function mergeSort<T>(
469
+ items: readonly T[],
470
+ compare: (a: T, b: T) => Promise<number>,
471
+ ): Promise<T[]> {
472
+ if (items.length <= 1) return [...items];
473
+ const n1 = Math.floor(items.length / 2);
474
+ const left = await mergeSort(items.slice(0, n1), compare);
475
+ const right = await mergeSort(items.slice(n1), compare);
476
+ const out: T[] = [];
477
+ let i = 0;
478
+ let j = 0;
479
+ while (i < left.length && j < right.length) {
480
+ if ((await compare(left[i] as T, right[j] as T)) <= 0) out.push(left[i++] as T);
481
+ else out.push(right[j++] as T);
482
+ }
483
+ while (i < left.length) out.push(left[i++] as T);
484
+ while (j < right.length) out.push(right[j++] as T);
485
+ return out;
486
+ }
487
+
488
+ /**
489
+ * can_do_iterative_format (git 2.47+): refs sorted by `refname` alone (any of its forms, no
490
+ * flag), no `%(ahead-behind)` or `%(is-base)` and no `--[no-]merged` are formatted in the
491
+ * order the ref backends list them (full names, byte order), never sorted by the key, each
492
+ * ref's values computed in that order.
493
+ */
494
+ function formatsIteratively(
495
+ sorting: readonly RefSortKey[],
496
+ format: RefFormat,
497
+ filter: RefFilterOptions,
498
+ ): boolean {
499
+ if (format.compatibility === "2.43") return false;
500
+ if (sorting.length > 1) return false;
501
+ const key = sorting[0];
502
+ if (key) {
503
+ if (key.reverse || key.version || key.icase || key.detachedHeadFirst) return false;
504
+ if (format.atoms[key.atom]?.type !== "refname") return false;
505
+ }
506
+ if (format.atoms.some((a) => a.type === "ahead-behind" || a.type === "is-base")) return false;
507
+ return !filter.merged?.length && !filter.noMerged?.length;
457
508
  }
458
509
 
459
510
  /**
@@ -641,7 +692,11 @@ export async function filterAndFormatRefs(
641
692
  const { items, warnings } = await filterRefs(source, filter);
642
693
  await fillAheadBehind(items, options.aheadBehindBases ?? [], source, warnings);
643
694
  await fillIsBase(items, options.isBaseTips ?? [], source);
644
- await sortRefs(items, sorting, format, source, warnings);
695
+ if (formatsIteratively(sorting, format, filter)) {
696
+ // the ref backends' iteration order: full names, byte by byte (whatever form of
697
+ // `refname` the key asked for)
698
+ items.sort((a, b) => compareBytes(a.refname, b.refname));
699
+ } else await sortRefs(items, sorting, format, source, warnings);
645
700
  const total = options.count && options.count < items.length ? options.count : items.length;
646
701
  const shown = items.slice(0, total);
647
702
  const lines: string[] = [];
@@ -23,6 +23,7 @@ import { RefFilterError } from "../../errors/index.js";
23
23
  import { type DateMode, parseDateMode, type ShowDateContext, showDate } from "../date-format.js";
24
24
  import type { Mailmap } from "../mailmap.js";
25
25
  import { sanitizedSubject } from "../pretty-format.js";
26
+ import type { SignatureCheck } from "../signature-check.js";
26
27
  import { appendTrailers, type TrailerConfig } from "../trailers.js";
27
28
  import { MAX_REF_FILTER_PEEL_DEPTH } from "./peel-limit.js";
28
29
  import { type AtomCmpType, parseAtom, type UsedAtom } from "./ref-atoms.js";
@@ -118,6 +119,18 @@ export interface RefFormatSource {
118
119
  headDescription?(): Promise<string>;
119
120
  /** The clock and local zone dates are shown with */
120
121
  dateContext?: ShowDateContext;
122
+ /**
123
+ * check_commit_signature: a commit's signature (its bytes as stored) checked through the
124
+ * host's verifier, as `verify-commit` checks it; without this, `%(signature)` of a signed
125
+ * commit refuses.
126
+ */
127
+ commitSignature?(bytes: Uint8Array): Promise<SignatureCheck>;
128
+ /**
129
+ * An object's size on disk (its pack entry or loose file) and delta base (the null id when
130
+ * not stored as a delta), for `%(objectsize:disk)` and `%(deltabase)`; undefined when no
131
+ * pack or loose file of the repository holds it. Without this, those atoms refuse.
132
+ */
133
+ objectOnDisk?(id: ObjectId): Promise<{ diskSize: number; deltaBase: ObjectId } | undefined>;
121
134
  }
122
135
 
123
136
  /** How {@link RefFormat} expands its format. */
@@ -432,9 +445,13 @@ export class RefFormat {
432
445
  private readonly quoteStyle: RefQuoteStyle;
433
446
  private readonly useColor: boolean;
434
447
  private readonly peelNested: boolean;
448
+ /** The git version followed (see {@link RefFormatOptions.compatibility}) */
449
+ readonly compatibility: "2.43" | "2.56";
435
450
  private headTarget?: Promise<string | undefined>;
436
451
  private mailmapLoad?: Promise<Mailmap>;
437
452
  private dateModes = new Map<string, DateMode>();
453
+ /** What the signature checks printed on stderr (`error: cannot run gpg: ...`), in order */
454
+ readonly messages: string[] = [];
438
455
 
439
456
  /**
440
457
  * `format` verified as git's verify_ref_format does (atoms parsed, `%(rest)` refused,
@@ -450,6 +467,7 @@ export class RefFormat {
450
467
  this.quoteStyle = options.quoteStyle ?? "none";
451
468
  this.useColor = options.useColor ?? false;
452
469
  this.peelNested = options.compatibility !== "2.43";
470
+ this.compatibility = options.compatibility ?? "2.56";
453
471
  let cp = 0;
454
472
  for (;;) {
455
473
  const sp = findNext(format, cp);
@@ -807,6 +825,20 @@ export class RefFormat {
807
825
  }
808
826
  }
809
827
 
828
+ /** `disk_sizep` and `delta_base_oid` of get_object's object info. */
829
+ private async onDisk(
830
+ id: ObjectId,
831
+ atom: UsedAtom,
832
+ refname: string,
833
+ ): Promise<{ diskSize: number; deltaBase: ObjectId }> {
834
+ if (!this.source.objectOnDisk) {
835
+ throw fatal(`%(${atom.name}) is not supported: this store does not keep objects on disk`);
836
+ }
837
+ const found = await this.source.objectOnDisk(id);
838
+ if (!found) throw fatal(`missing object ${id} for ${refname}`);
839
+ return found;
840
+ }
841
+
810
842
  /** grab_values (and grab_common_values) of one object, the ref's own or the peeled one. */
811
843
  private async grabValues(
812
844
  values: AtomValue[],
@@ -824,12 +856,15 @@ export class RefFormat {
824
856
  if (atom.type === "objecttype") v.s = object.type;
825
857
  else if (atom.type === "objectsize") {
826
858
  if (atom.objectsize === "disk") {
827
- throw fatal(`%(${atom.name}) is not supported: object disk sizes are not available`);
859
+ const { diskSize } = await this.onDisk(id, atom, refname);
860
+ v.value = diskSize;
861
+ v.s = String(diskSize);
862
+ continue;
828
863
  }
829
864
  v.value = object.bytes.length;
830
865
  v.s = String(object.bytes.length);
831
866
  } else if (atom.type === "deltabase") {
832
- throw fatal(`%(${atom.name}) is not supported: delta bases are not available`);
867
+ v.s = (await this.onDisk(id, atom, refname)).deltaBase;
833
868
  } else if (atom.type === "objectname" && deref) v.s = await this.oidText(id, atom);
834
869
  }
835
870
  if (object.type === "tag") {
@@ -862,7 +897,7 @@ export class RefFormat {
862
897
  await this.grabContents(mine, object, buf);
863
898
  await this.grabPerson("author", mine, buf);
864
899
  await this.grabPerson("committer", mine, buf);
865
- this.grabSignature(mine, buf);
900
+ await this.grabSignature(mine, object.bytes, buf);
866
901
  await this.grabDescribe(mine, id, object);
867
902
  } else {
868
903
  await this.grabContents(mine, object, buf);
@@ -992,17 +1027,55 @@ export class RefFormat {
992
1027
  v.value = timestamp;
993
1028
  }
994
1029
 
995
- /** grab_signature for an unsigned commit; a signed one cannot be verified here. */
996
- private grabSignature(values: AtomValue[], buf: string): void {
1030
+ /**
1031
+ * grab_signature: the commit's signature checked once (check_commit_signature) and each
1032
+ * `%(signature...)` atom given its field; an unsigned commit is `N`, trust `undefined`.
1033
+ */
1034
+ private async grabSignature(values: AtomValue[], bytes: Uint8Array, buf: string) {
997
1035
  const atoms = values.filter((v) => v.atom.type === "signature");
998
1036
  if (atoms.length === 0) return;
999
- const header = buf.slice(0, Math.max(buf.indexOf("\n\n"), 0));
1000
- if (/(^|\n)gpgsig(-sha256)? /.test(header)) {
1001
- throw fatal("%(signature) is not supported: signatures cannot be verified");
1037
+ let check: SignatureCheck;
1038
+ if (this.source.commitSignature) {
1039
+ check = await this.source.commitSignature(bytes);
1040
+ for (const line of check.messages) this.messages.push(line);
1041
+ } else {
1042
+ const header = buf.slice(0, Math.max(buf.indexOf("\n\n"), 0));
1043
+ if (/(^|\n)gpgsig(-sha256)? /.test(header)) {
1044
+ throw fatal("%(signature) is not supported: signatures cannot be verified");
1045
+ }
1046
+ check = { result: "N", trustLevel: "undefined", failed: true, messages: [] };
1002
1047
  }
1003
1048
  for (const v of atoms) {
1004
- const option = v.atom.signature;
1005
- v.s = option === "grade" ? "N" : option === "trustlevel" ? "undefined" : "";
1049
+ switch (v.atom.signature) {
1050
+ case "":
1051
+ v.s = check.output ?? "";
1052
+ break;
1053
+ case "signer":
1054
+ v.s = check.signer ?? "";
1055
+ break;
1056
+ case "grade":
1057
+ v.s =
1058
+ check.result === "G"
1059
+ ? check.trustLevel === "undefined" || check.trustLevel === "never"
1060
+ ? "U"
1061
+ : "G"
1062
+ : check.result;
1063
+ break;
1064
+ case "key":
1065
+ v.s = check.key ?? "";
1066
+ break;
1067
+ case "fingerprint":
1068
+ v.s = check.fingerprint ?? "";
1069
+ break;
1070
+ case "primarykeyfingerprint":
1071
+ v.s = check.primaryKeyFingerprint ?? "";
1072
+ break;
1073
+ case "trustlevel":
1074
+ v.s = check.trustLevel;
1075
+ break;
1076
+ default:
1077
+ v.s = "";
1078
+ }
1006
1079
  }
1007
1080
  }
1008
1081
 
@@ -24,6 +24,8 @@ import { applyRefspecs } from "../branch-tracking.js";
24
24
  import { createDescriber } from "../git-describe.js";
25
25
  import { hostEnvironmentOf } from "../git-ident.js";
26
26
  import { type Mailmap, readRepositoryMailmap } from "../mailmap.js";
27
+ import { type ObjectDiskInfo, objectDiskInfoOf } from "../object-disk-info.js";
28
+ import { verifyCommitBytes } from "../signature-check.js";
27
29
  import { trailerConfigOf } from "../trailers.js";
28
30
  import type { ListedRef, RefFilterSource } from "./ref-filter.js";
29
31
  import type { RefFormatObject, RefFormatSource } from "./ref-format.js";
@@ -51,6 +53,26 @@ export abstract class RefListingCommand<T> extends GitCommand<T> {
51
53
  private objectCache = new Map<ObjectId, Promise<RefFormatObject | undefined>>();
52
54
  private replacements?: Promise<ReadonlyMap<ObjectId, ObjectId> | undefined>;
53
55
  private worktreeHeads?: Promise<Map<string, string>>;
56
+ private diskInfo?: Promise<ObjectDiskInfo>;
57
+
58
+ /**
59
+ * An object's on-disk size and delta base, through replace refs as {@link readObjectForFilter}
60
+ * (ref-filter.c's `oid_object_info_extended(..., OBJECT_INFO_LOOKUP_REPLACE)`).
61
+ */
62
+ protected async objectOnDisk(
63
+ id: ObjectId,
64
+ ): Promise<{ diskSize: number; deltaBase: ObjectId } | undefined> {
65
+ this.replacements ??= this.objectReplacements().then((r) =>
66
+ r?.replace.size ? r.replace : undefined,
67
+ );
68
+ const replace = await this.replacements;
69
+ const read = replace ? replacementOf(replace, id) : id;
70
+ this.diskInfo ??= objectDiskInfoOf(this._workingCopy);
71
+ const info = await this.diskInfo;
72
+ const diskSize = await info.diskSize(read);
73
+ const deltaBase = await info.deltaBase(read);
74
+ return diskSize === undefined || deltaBase === undefined ? undefined : { diskSize, deltaBase };
75
+ }
54
76
 
55
77
  /** An object's type and content, through replace refs (git's OBJECT_INFO_LOOKUP_REPLACE). */
56
78
  protected readObjectForFilter(id: ObjectId): Promise<RefFormatObject | undefined> {
@@ -312,6 +334,7 @@ export abstract class RefListingCommand<T> extends GitCommand<T> {
312
334
  let describer: ReturnType<typeof createDescriber> | undefined;
313
335
  return {
314
336
  readObject: (id) => this.readObjectForFilter(id),
337
+ objectOnDisk: (id) => this.objectOnDisk(id),
315
338
  abbreviate: async (id, minLength) => {
316
339
  if (minLength === undefined) return this.abbreviateObjectId(id);
317
340
  const lengths = await this.idAbbreviator().lengths([id], minLength);
@@ -372,6 +395,13 @@ export abstract class RefListingCommand<T> extends GitCommand<T> {
372
395
  });
373
396
  },
374
397
  trailerConfig: () => trailerConfigOf(this._workingCopy),
398
+ commitSignature: async (bytes) => {
399
+ const cwd = await this.hostWorkingDir();
400
+ return verifyCommitBytes(this._workingCopy, bytes, {
401
+ objectFormat: this.objectFormat,
402
+ ...(cwd !== undefined ? { cwd } : {}),
403
+ });
404
+ },
375
405
  };
376
406
  }
377
407
 
@@ -1072,7 +1072,7 @@ export class RemoteSetUrlCommand extends GitCommand<RemoteConfig> {
1072
1072
  const hits = values.filter((v) => matchesUrl(regex, v)).length;
1073
1073
  if (this.deleteMode) {
1074
1074
  if (hits === 0) throw new GitApiError(`fatal: could not unset '${key}'`);
1075
- store.setValues(
1075
+ store.editValues(
1076
1076
  key,
1077
1077
  values.filter((v): v is string => v !== undefined && !matchesUrl(regex, v)),
1078
1078
  );
@@ -1118,7 +1118,7 @@ function replaceMatching(
1118
1118
  store.addValue(key, newValue);
1119
1119
  return;
1120
1120
  }
1121
- store.setValues(
1121
+ store.editValues(
1122
1122
  key,
1123
1123
  values.map((v) => (matchesUrl(regex, v) ? newValue : (v ?? ""))),
1124
1124
  );
@@ -30,7 +30,7 @@ import type {
30
30
  OpenedRepository,
31
31
  WorkingCopy,
32
32
  } from "@statewalker/vcs-working-tree";
33
- import { InvalidConfigError, TransportError } from "../errors/index.js";
33
+ import { GitApiError, InvalidConfigError, TransportError } from "../errors/index.js";
34
34
  import { RemoteConfigStore } from "../remote-config/index.js";
35
35
  import { type BundleRemote, withBundleUploadPack } from "./bundle/bundle-transport.js";
36
36
  import { openBundle, verifyBundleIn } from "./bundle/bundle-verify.js";
@@ -43,6 +43,8 @@ import {
43
43
  withLocalReceivePack,
44
44
  withLocalUploadPack,
45
45
  } from "./local-transport.js";
46
+ import { packObjectsHookOf } from "./serve-repository.js";
47
+ import type { ServedLazyFetchOptions } from "./served-lazy-fetch.js";
46
48
  import { repositoryPlaceOf } from "./worktree-support.js";
47
49
 
48
50
  /** A remote URL resolved to the transport that reaches it. */
@@ -354,6 +356,37 @@ export interface RemoteSessionOptions {
354
356
  alternateAllowed?: (scheme: string) => boolean;
355
357
  /** HTTP: `$GIT_SMART_HTTP` (false: the dumb protocol) */
356
358
  smartHttp?: boolean;
359
+ /**
360
+ * A local remote's hooks, as the upload-pack git's local transport spawns runs them
361
+ * (`remoteHookSession(workingCopy, remote, { localPush: true })`): its
362
+ * `uploadpack.packObjectsHook`, from the system and global files only
363
+ */
364
+ localHooks?: (remote: OpenedRepository) => HookSession | undefined;
365
+ /**
366
+ * `$GIT_NAMESPACE` (the host environment's `namespace`): the ref namespace a local remote's
367
+ * upload-pack and receive-pack serve, as git's spawned ones inherit it
368
+ */
369
+ namespace?: string;
370
+ /**
371
+ * The host environment's `GIT_NO_LAZY_FETCH=0`, which git's spawned upload-pack inherits: a
372
+ * local remote's upload-pack then fetches the absent promisor objects a pack needs from the
373
+ * remote's own promisor remotes (see `localLazyFetchOf`); unset, it refuses them as git's
374
+ */
375
+ localLazyFetch?: ServedLazyFetchOptions;
376
+ }
377
+
378
+ /**
379
+ * What a local remote's upload-pack inherits of the client for its lazy fetch: only under
380
+ * the host environment's `GIT_NO_LAZY_FETCH=0` (git's upload-pack sets it to 1 unless the
381
+ * variable is set), through the client's transports and per-URL credential helper. Static
382
+ * credentials and headers never go: the promisor URLs are the remote repository's config.
383
+ */
384
+ export function localLazyFetchOf(
385
+ environment: GitHostEnvironment | undefined,
386
+ options: Omit<ServedLazyFetchOptions, "environment">,
387
+ ): { localLazyFetch?: ServedLazyFetchOptions } {
388
+ if (environment?.noLazyFetch !== false) return {};
389
+ return { localLazyFetch: { ...options, environment } };
357
390
  }
358
391
 
359
392
  /**
@@ -427,12 +460,33 @@ export async function withRemoteSession<T>(
427
460
  run: (session: GitSession, request: GitConnectRequest) => Promise<T>,
428
461
  ): Promise<T> {
429
462
  const request = connectRequest(remote, service, options);
430
- const session = closingOnce(await remote.connector.connect(request));
463
+ let session: GitSession | undefined;
431
464
  try {
465
+ session = closingOnce(await remote.connector.connect(request));
432
466
  return await run(session, request);
467
+ } catch (error) {
468
+ throw connectorDeath(error);
433
469
  } finally {
434
- if (session.kind === "native") await session.duplex.close?.().catch(() => undefined);
470
+ if (session?.kind === "native") await session.duplex.close?.().catch(() => undefined);
471
+ }
472
+ }
473
+
474
+ /**
475
+ * A connector's or the protocol layer's own death in git's words (a plain transport error
476
+ * whose message is git's `fatal:` lines: a refused ssh host, an `ext::` placeholder, a
477
+ * remote that closed before it spoke) as the command error git's exit status goes with (128);
478
+ * anything else unchanged.
479
+ */
480
+ function connectorDeath(error: unknown): unknown {
481
+ if (
482
+ error instanceof Error &&
483
+ !(error instanceof GitApiError) &&
484
+ error.name === "TransportError" &&
485
+ /^fatal: /m.test(error.message)
486
+ ) {
487
+ return new TransportError(error.message, undefined, { cause: error, exitCode: 128 });
435
488
  }
489
+ return error;
436
490
  }
437
491
 
438
492
  /**
@@ -446,8 +500,16 @@ export async function withRemoteUploadPack<T>(
446
500
  run: (connection: UploadPackConnection) => Promise<T>,
447
501
  ): Promise<T> {
448
502
  if (remote.kind === "local") {
503
+ // git-upload-pack '<path>' reads the system and global files, never the command line's
504
+ // config (connect.c's local_repo_env) nor the repository's
505
+ const packObjectsHook = await packObjectsHookOf(options.localHooks?.(remote.repository), {
506
+ commandLine: false,
507
+ });
449
508
  return withLocalUploadPack(remote.repository, run, {
450
509
  protocolVersion: options.protocolVersion,
510
+ ...(options.localLazyFetch ? { lazyFetch: options.localLazyFetch } : {}),
511
+ ...(options.namespace ? { namespace: options.namespace } : {}),
512
+ ...(packObjectsHook ? { packObjectsHook } : {}),
451
513
  });
452
514
  }
453
515
  if (remote.kind === "bundle") return withBundleUploadPack(remote.remote, createDuplexPair, run);
@@ -488,6 +550,7 @@ export async function withRemoteReceivePack<T>(
488
550
  if (remote.kind === "local") {
489
551
  return withLocalReceivePack(remote.repository, run, hooks, transactionHooks, {
490
552
  protocolVersion: options.protocolVersion,
553
+ ...(options.namespace ? { namespace: options.namespace } : {}),
491
554
  ...local,
492
555
  });
493
556
  }