@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
@@ -14,9 +14,10 @@
14
14
  * @module
15
15
  */
16
16
  import type { ObjectId } from "@statewalker/vcs-core";
17
+ import { encodeGitPath } from "@statewalker/vcs-utils";
17
18
 
18
19
  import { GitApiError, RefNotFoundError } from "../errors/index.js";
19
- import { GitCommand } from "../git-command.js";
20
+ import { RefFormat, RefListingCommand, refKindOf } from "./ref-filter/index.js";
20
21
  import { type SignatureCheck, verifyCommitBytes, verifyTagBytes } from "./signature-check.js";
21
22
 
22
23
  /** What `git verify-commit` / `git verify-tag` printed and its exit status. */
@@ -33,17 +34,50 @@ export interface VerifyResult {
33
34
 
34
35
  /** One object's verification as the command's loop runs it. */
35
36
  interface VerifyOutput {
37
+ /** stdout as written to the file descriptor, in order */
36
38
  out: Uint8Array[];
39
+ /** stdio's buffer: what `fputs`/`fwrite` wrote and stdout has not got yet */
40
+ stdio: Uint8Array[];
37
41
  err: string[];
38
42
  checks: { name: string; id?: ObjectId; check?: SignatureCheck }[];
39
43
  }
40
44
 
45
+ /** glibc's stdout buffer over a pipe (its st_blksize) */
46
+ const STDIO_BUFFER = 4096;
47
+
48
+ /**
49
+ * A write through stdio (`fputs`, `fwrite`, `putchar`): held in the buffer, which reaches
50
+ * stdout in whole buffers as it fills and the rest at exit, after any `write_in_full` made in
51
+ * between (git writes a tag without signature that way).
52
+ */
53
+ function writeStdio(output: VerifyOutput, bytes: Uint8Array): void {
54
+ output.stdio.push(bytes);
55
+ const size = output.stdio.reduce((n, b) => n + b.length, 0);
56
+ if (size < STDIO_BUFFER) return;
57
+ const all = concatBytes(output.stdio);
58
+ const cut = size - (size % STDIO_BUFFER);
59
+ output.out.push(all.subarray(0, cut));
60
+ output.stdio = cut < size ? [all.subarray(cut)] : [];
61
+ }
62
+
63
+ function concatBytes(chunks: readonly Uint8Array[]): Uint8Array {
64
+ const bytes = new Uint8Array(chunks.reduce((n, b) => n + b.length, 0));
65
+ let at = 0;
66
+ for (const b of chunks) {
67
+ bytes.set(b, at);
68
+ at += b.length;
69
+ }
70
+ return bytes;
71
+ }
72
+
41
73
  const TYPE_NAMES = new Set(["commit", "tree", "blob", "tag"]);
42
74
 
43
- abstract class VerifyCommandBase extends GitCommand<VerifyResult> {
75
+ abstract class VerifyCommandBase extends RefListingCommand<VerifyResult> {
44
76
  protected readonly names: string[] = [];
45
77
  protected verbose = false;
46
78
  protected raw = false;
79
+ /** GPG_VERIFY_OMIT_STATUS: nothing of a check printed (verify-tag `--format`) */
80
+ protected omitStatus = false;
47
81
 
48
82
  /** `-v` / `--verbose`: the object's contents on stdout. */
49
83
  setVerbose(verbose: boolean): this {
@@ -94,7 +128,8 @@ abstract class VerifyCommandBase extends GitCommand<VerifyResult> {
94
128
 
95
129
  /** gpg-interface.c's `print_signature_buffer` */
96
130
  protected print(check: SignatureCheck, output: VerifyOutput): void {
97
- if (this.verbose && check.payload) output.out.push(check.payload);
131
+ if (this.omitStatus) return;
132
+ if (this.verbose && check.payload) writeStdio(output, check.payload);
98
133
  const text = this.raw ? check.status : check.output;
99
134
  if (text) output.err.push(text);
100
135
  }
@@ -107,18 +142,14 @@ abstract class VerifyCommandBase extends GitCommand<VerifyResult> {
107
142
  if (this.names.length === 0) {
108
143
  throw new GitApiError(this.usage(), { exitCode: 129 });
109
144
  }
110
- const output: VerifyOutput = { out: [], err: [], checks: [] };
145
+ const output: VerifyOutput = { out: [], stdio: [], err: [], checks: [] };
146
+ await this.prepare();
111
147
  let failed = false;
112
148
  for (const name of this.names) {
113
149
  if (!(await this.verifyOne(name, output))) failed = true;
114
150
  }
115
- const size = output.out.reduce((n, b) => n + b.length, 0);
116
- const stdout = new Uint8Array(size);
117
- let at = 0;
118
- for (const b of output.out) {
119
- stdout.set(b, at);
120
- at += b.length;
121
- }
151
+ // stdio's buffer flushed at exit
152
+ const stdout = concatBytes([...output.out, ...output.stdio]);
122
153
  return {
123
154
  exitCode: failed ? 1 : 0,
124
155
  stdout,
@@ -129,6 +160,9 @@ abstract class VerifyCommandBase extends GitCommand<VerifyResult> {
129
160
 
130
161
  protected abstract usage(): string;
131
162
 
163
+ /** What runs once before the objects are checked (the format verified). */
164
+ protected async prepare(): Promise<void> {}
165
+
132
166
  /** The check's own lines (git's `error()`/`warning()` on the way), with newlines. */
133
167
  protected messages(check: SignatureCheck, output: VerifyOutput): void {
134
168
  for (const line of check.messages) output.err.push(`${line}\n`);
@@ -192,6 +226,9 @@ export class VerifyCommitCommand extends VerifyCommandBase {
192
226
  * signature `error: no signature found` (`-v` prints the tag first). Exit 1 when any fails.
193
227
  */
194
228
  export class VerifyTagCommand extends VerifyCommandBase {
229
+ private format?: string;
230
+ private refFormat?: RefFormat;
231
+
195
232
  /** A tag to verify (any revision naming a tag object). */
196
233
  addTag(name: string): this {
197
234
  this.checkCallable();
@@ -199,6 +236,39 @@ export class VerifyTagCommand extends VerifyCommandBase {
199
236
  return this;
200
237
  }
201
238
 
239
+ /**
240
+ * `--format=<format>`: each tag whose signature is good printed through the ref-filter
241
+ * format (`%(refname)` is the name as given), and nothing of the checks themselves, not
242
+ * even with `-v` or `--raw` (git's GPG_VERIFY_OMIT_STATUS); a tag without signature still
243
+ * goes to stdout under `-v`.
244
+ */
245
+ setFormat(format: string | undefined): this {
246
+ this.checkCallable();
247
+ this.format = format;
248
+ return this;
249
+ }
250
+
251
+ /** verify_ref_format, before any tag is read. */
252
+ protected override async prepare(): Promise<void> {
253
+ if (this.format === undefined) return;
254
+ this.refFormat = new RefFormat(this.format, this.formatSource());
255
+ this.omitStatus = true;
256
+ }
257
+
258
+ /** pretty_print_ref: the tag as a ref named `name`, the expanded format and a newline. */
259
+ private async prettyPrint(name: string, id: ObjectId, output: VerifyOutput): Promise<void> {
260
+ const format = this.refFormat;
261
+ if (!format) return;
262
+ const line = await format.format({
263
+ refname: name,
264
+ objectId: id,
265
+ flags: { symref: false, packed: false },
266
+ kind: refKindOf(name),
267
+ });
268
+ for (const message of format.messages.splice(0)) output.err.push(`${message}\n`);
269
+ writeStdio(output, encodeGitPath(`${line}\n`));
270
+ }
271
+
202
272
  protected usage(): string {
203
273
  return "usage: git verify-tag [-v | --verbose] [--format=<format>] [--raw] <tag>...";
204
274
  }
@@ -230,6 +300,8 @@ export class VerifyTagCommand extends VerifyCommandBase {
230
300
  this.messages(check, output);
231
301
  this.print(check, output);
232
302
  output.checks.push({ name, id, check });
233
- return !check.failed;
303
+ if (check.failed) return false;
304
+ await this.prettyPrint(name, id, output);
305
+ return true;
234
306
  }
235
307
  }
@@ -676,6 +676,8 @@ export class WorktreeAddCommand extends GitCommand<WorktreeAddResult> {
676
676
  symlinks: worktreeModeTrust(workingCopy, worktree).symlinks,
677
677
  ignoreCase: coreBool(workingCopy, "ignorecase", false),
678
678
  pathRules: worktreePathRules(workingCopy, worktree),
679
+ // the child `git reset --hard`'s metadata: HEAD's commit, no ref
680
+ metadata: { treeish: headId },
679
681
  },
680
682
  commit.tree,
681
683
  "worktree add",
@@ -6,7 +6,7 @@
6
6
  */
7
7
 
8
8
  import { FileMode, type ObjectId } from "@statewalker/vcs-core";
9
- import { foldAsciiCase } from "@statewalker/vcs-utils/encoding";
9
+ import { compareGitPaths, foldAsciiCase } from "@statewalker/vcs-utils/encoding";
10
10
  import {
11
11
  basicStatMatches,
12
12
  IndexPathLookup,
@@ -29,11 +29,12 @@ export interface CheckedEntry {
29
29
  /**
30
30
  * Whether the worktree file at `path` no longer holds the index entry (git's
31
31
  * `verify_uptodate`): changed content, type, or executable bit where the worktree shows it.
32
- * A missing file is no local change, but one beneath a symbolically linked directory is. With `indexTime` (the index file's mtime, as the
33
- * caller's index was last read or written: git's `istate->timestamp`), a stat that matches
34
- * as git's `ie_match_stat` compares it, on an entry older than the index (not racy),
35
- * settles it without reading the file, as in git; a racy entry is read. A caller that
36
- * rewrites the index where git does (`write_index_as_tree`) passes the new file's time.
32
+ * A missing file is no local change, but one beneath a symbolically linked directory or a
33
+ * file is. With `indexTime` (the index file's mtime, as the caller's index was last read or
34
+ * written: git's `istate->timestamp`), a stat that matches as git's `ie_match_stat` compares
35
+ * it, on an entry older than the index (not racy), settles it without reading the file, as
36
+ * in git; a racy entry is read. A caller that rewrites the index where git does
37
+ * (`write_index_as_tree`) passes the new file's time.
37
38
  */
38
39
  export async function worktreeDiffers(
39
40
  worktree: Worktree,
@@ -45,19 +46,23 @@ export async function worktreeDiffers(
45
46
  const current = await worktree.getEntry(path);
46
47
  if (!current) {
47
48
  // git's lstat follows a symbolic link on a leading directory to whatever the file there
48
- // is, never the one the index recorded: a change (the worktree never looks beyond links)
49
- return entry.mode !== FileMode.GITLINK && (await beneathSymlink(worktree, path));
49
+ // is, never the one the index recorded: a change (the worktree never looks beyond links);
50
+ // so is a file among the leading components (verify_uptodate_1 takes only ENOENT as a
51
+ // file deleted, ENOTDIR is a change)
52
+ return entry.mode !== FileMode.GITLINK && (await leadingPathBlocked(worktree, path));
50
53
  }
51
54
  return differsFrom(worktree, path, entry, current, trust, indexTime);
52
55
  }
53
56
 
54
- /** Whether a leading directory of `path` is a symbolic link. */
55
- async function beneathSymlink(worktree: Worktree, path: string): Promise<boolean> {
57
+ /**
58
+ * Whether `path` is missing for another reason than ENOENT: a leading directory of it is a
59
+ * symbolic link, or a file (ENOTDIR).
60
+ */
61
+ async function leadingPathBlocked(worktree: Worktree, path: string): Promise<boolean> {
56
62
  for (let k = path.indexOf("/"); k > 0; k = path.indexOf("/", k + 1)) {
57
63
  const entry = await worktree.getEntry(path.slice(0, k)).catch(() => undefined);
58
64
  if (!entry) return false;
59
- if (entry.mode === FileMode.SYMLINK) return true;
60
- if (!entry.isDirectory) return false;
65
+ if (entry.mode === FileMode.SYMLINK || !entry.isDirectory) return true;
61
66
  }
62
67
  return false;
63
68
  }
@@ -477,7 +482,7 @@ export function overwriteMessage(
477
482
  * before overwriting or removing its file: `ie_match_stat` with `CE_MATCH_IGNORE_VALID`, so
478
483
  * a stat that no longer matches is a change (the content is not compared), and a matching
479
484
  * one on a racy entry has its content checked. A missing file is no change, but one
480
- * beneath a symbolically linked directory is.
485
+ * beneath a symbolically linked directory or a file is.
481
486
  */
482
487
  export async function flaggedEntryDiffers(
483
488
  worktree: Worktree,
@@ -493,7 +498,7 @@ export async function flaggedEntryDiffers(
493
498
  // git's lstat follows a symbolic link among the leading directories to whatever is
494
499
  // there, never the file the index recorded: a change, as for an unflagged entry (the
495
500
  // switch then never writes through the link)
496
- return entry.mode !== FileMode.GITLINK && (await beneathSymlink(worktree, path));
501
+ return entry.mode !== FileMode.GITLINK && (await leadingPathBlocked(worktree, path));
497
502
  }
498
503
  if (current.isDirectory) return entry.mode !== FileMode.GITLINK;
499
504
  if (entry.mode === FileMode.GITLINK) return false;
@@ -534,6 +539,62 @@ export async function entryNotUptodate(
534
539
  return worktreeDiffers(worktree, path, entry, trust, indexTime);
535
540
  }
536
541
 
542
+ /**
543
+ * git's `verify_clean_subdirectory` for a two-way switch that finds a directory at `path`
544
+ * where it writes a new file or deletes one the index lacks (`verify_absent`): the stage-0
545
+ * index entries below it are checked in index order (`verify_uptodate`), and each clean one
546
+ * is taken out of the switch (removed with its file, its own path then merged as if the
547
+ * index lacked it). The first local change stops the check: the switch refuses it.
548
+ *
549
+ * @param taken entries taken out so far (added to)
550
+ * @returns the entries taken by this call, or the entry whose local change refuses
551
+ */
552
+ export async function takeCleanSubdirectory(
553
+ worktree: Worktree,
554
+ path: string,
555
+ index: ReadonlyMap<string, CheckedEntry>,
556
+ taken: Set<string>,
557
+ trust?: WorktreeModeTrust,
558
+ indexTime?: number,
559
+ ): Promise<{ taken: string[]; notUptodate?: string }> {
560
+ const below = [...index.keys()].filter((p) => p.startsWith(`${path}/`) && !taken.has(p));
561
+ below.sort(compareGitPaths);
562
+ const out: string[] = [];
563
+ for (const p of below) {
564
+ if (await entryNotUptodate(worktree, p, index.get(p) as CheckedEntry, trust, indexTime)) {
565
+ return { taken: out, notUptodate: p };
566
+ }
567
+ taken.add(p);
568
+ out.push(p);
569
+ }
570
+ return { taken: out };
571
+ }
572
+
573
+ /**
574
+ * The first leading directory of `path` that is a file or a link in the worktree (git's
575
+ * `check_leading_path`), whose removal a switch deleting `path` must check too.
576
+ */
577
+ export async function leadingFileOf(worktree: Worktree, path: string): Promise<string | undefined> {
578
+ for (let k = path.indexOf("/"); k > 0; k = path.indexOf("/", k + 1)) {
579
+ const entry = await worktree.getEntry(path.slice(0, k));
580
+ if (!entry) return undefined;
581
+ if (!entry.isDirectory) return path.slice(0, k);
582
+ }
583
+ return undefined;
584
+ }
585
+
586
+ /**
587
+ * Whether a leading directory of `path` was refused: git's traverse_trees never enters the
588
+ * subtree of a path whose merge failed, so nothing below it is checked or reported.
589
+ */
590
+ export function belowRefused(path: string, refused: ReadonlySet<string>): boolean {
591
+ if (refused.size === 0) return false;
592
+ for (let k = path.indexOf("/"); k > 0; k = path.indexOf("/", k + 1)) {
593
+ if (refused.has(path.slice(0, k))) return true;
594
+ }
595
+ return false;
596
+ }
597
+
537
598
  /** What {@link statThroughLeadingLinks} found beyond a link. */
538
599
  export interface LinkedStat {
539
600
  /** The entry the path reaches through the link(s); undefined when nothing is there */
@@ -21,19 +21,47 @@ export const EMPTY_AMEND_ADVICE =
21
21
  "it empty. You can repeat your command with --allow-empty, or you can\n" +
22
22
  'remove the commit entirely with "git reset HEAD^".\n';
23
23
 
24
+ /**
25
+ * builtin/commit.c's `empty_cherry_pick_advice`: what `git commit` prints on stderr when it
26
+ * refuses an empty commit while a cherry-pick or a rebase pick is in progress, followed by
27
+ * {@link EMPTY_CHERRY_PICK_ADVICE_SINGLE} or {@link EMPTY_REBASE_PICK_ADVICE} (the same text
28
+ * in 2.43 and 2.5x).
29
+ */
30
+ export const EMPTY_CHERRY_PICK_ADVICE =
31
+ "The previous cherry-pick is now empty, possibly due to conflict resolution.\n" +
32
+ "If you wish to commit it anyway, use:\n" +
33
+ "\n" +
34
+ " git commit --allow-empty\n" +
35
+ "\n";
36
+
37
+ /**
38
+ * builtin/commit.c's `empty_cherry_pick_advice_single`, after {@link EMPTY_CHERRY_PICK_ADVICE}
39
+ * during a cherry-pick. git's `empty_cherry_pick_advice_multi` is never printed:
40
+ * sequencer_determine_whence overwrites `FROM_CHERRY_PICK_MULTI` with
41
+ * `FROM_CHERRY_PICK_SINGLE`, so a sequence of picks gets this text too.
42
+ */
43
+ export const EMPTY_CHERRY_PICK_ADVICE_SINGLE = "Otherwise, please use 'git cherry-pick --skip'\n";
44
+
45
+ /**
46
+ * builtin/commit.c's `empty_rebase_pick_advice`, after {@link EMPTY_CHERRY_PICK_ADVICE} during
47
+ * a rebase stopped at a pick (CHERRY_PICK_HEAD the same commit as REBASE_HEAD).
48
+ */
49
+ export const EMPTY_REBASE_PICK_ADVICE = "Otherwise, please use 'git rebase --skip'\n";
50
+
24
51
  /**
25
52
  * Thrown when trying to create an empty commit without allow-empty.
26
53
  *
27
54
  * git's prepare_to_commit refuses it with exit status 1, printing the status of what would
28
- * be committed on stdout ({@link stdout}, `git commit --dry-run`'s text) and, when amending,
29
- * {@link EMPTY_AMEND_ADVICE} on stderr ({@link stderr}, also the message then).
55
+ * be committed on stdout ({@link stdout}, `git commit --dry-run`'s text) and on stderr
56
+ * ({@link stderr}, also the message then) {@link EMPTY_AMEND_ADVICE} when amending, else
57
+ * {@link EMPTY_CHERRY_PICK_ADVICE} and its sequel during a cherry-pick or a rebase pick.
30
58
  *
31
59
  * Based on JGit's EmptyCommitException.
32
60
  */
33
61
  export class EmptyCommitError extends GitApiError {
34
62
  /** git's stdout: the status run_status prints before the refusal (when computed) */
35
63
  readonly stdout?: string;
36
- /** git's stderr: the amend advice, or nothing */
64
+ /** git's stderr: the amend or empty cherry-pick advice, or nothing */
37
65
  readonly stderr: string;
38
66
 
39
67
  constructor(message?: string, output?: { stdout?: string; stderr?: string }) {
@@ -29,6 +29,13 @@ export class GitApiError extends Error {
29
29
  */
30
30
  messages?: string[];
31
31
 
32
+ /**
33
+ * What git printed on stderr before this failure, line by line: git 2.5x's
34
+ * `core.commentChar=auto` deprecation warning and its advice (commit, merge, rebase,
35
+ * revert, cherry-pick). Absent when it printed nothing first.
36
+ */
37
+ warnings?: readonly string[];
38
+
32
39
  constructor(message: string, options?: GitApiErrorOptions) {
33
40
  super(message, options);
34
41
  this.name = "GitApiError";
@@ -53,7 +53,10 @@ import {
53
53
  type Worktree,
54
54
  } from "@statewalker/vcs-working-tree";
55
55
  import { attributesSourceResolver } from "./commands/attributes-source.js";
56
- import { checkAutoCommentChar } from "./commands/comment-char-config.js";
56
+ import {
57
+ checkAutoCommentChar,
58
+ enterAutoCommentCharWarning,
59
+ } from "./commands/comment-char-config.js";
57
60
  import {
58
61
  configLoadError,
59
62
  createIdAbbreviator,
@@ -91,7 +94,9 @@ import {
91
94
  import { type ResolveOptions, RevisionResolver } from "./commands/revision-resolver.js";
92
95
  import { type SignRequest, signCommit } from "./commands/signing.js";
93
96
  import { readSparseCheckoutPatterns } from "./commands/sparse-checkout-support.js";
97
+ import type { CheckoutRef } from "./commands/tree-restore.js";
94
98
  import {
99
+ GitApiError,
95
100
  InvalidConfigError,
96
101
  NoHeadError,
97
102
  NotACommitError,
@@ -372,6 +377,76 @@ export abstract class GitCommand<T> {
372
377
  const promisor = promisorOf(workingCopy);
373
378
  if (promisor && !promisor.fetcher) promisor.setFetcher(createPromisorFetcher(workingCopy));
374
379
  this.releaseHooksAfterCalls();
380
+ this.warnOfAutoCommentChar();
381
+ this.holdFilterProcessesDuringCalls();
382
+ }
383
+
384
+ /**
385
+ * Each entry point keeps the worktree's long-running filter processes
386
+ * (`filter.<driver>.process`) running until it ends, then shuts them down (unless an outer
387
+ * call still holds them): git starts such a process once per command run and stops it at
388
+ * its exit, whatever the number of files filtered.
389
+ */
390
+ private holdFilterProcessesDuringCalls(): void {
391
+ this.aroundEntryPoints(() => {
392
+ let worktree: Worktree | undefined;
393
+ try {
394
+ worktree = this._workingCopy.worktree;
395
+ } catch {
396
+ // a bare repository's working copy refuses its worktree
397
+ return undefined;
398
+ }
399
+ return worktree?.contentFilter?.holdProcesses?.();
400
+ });
401
+ }
402
+
403
+ /**
404
+ * The entry points that give git 2.5x's `core.commentChar=auto` deprecation warning (the
405
+ * commands setting `warn_on_auto_comment_char`: commit, merge, rebase, revert,
406
+ * cherry-pick); none by default.
407
+ */
408
+ protected autoCommentCharWarningEntryPoints(): readonly string[] {
409
+ return [];
410
+ }
411
+
412
+ /** The git version whose rules this command follows (default the hook runner's). */
413
+ protected gitCompatibility(): "2.43" | "2.56" {
414
+ return this.hooks.compatibility;
415
+ }
416
+
417
+ /**
418
+ * Wraps {@link autoCommentCharWarningEntryPoints}: the warning's lines go in front of the
419
+ * result's `warnings` (git prints them as the configuration is first read), or of a
420
+ * {@link GitApiError}'s `warnings` when the call fails; an inner call (a command this one
421
+ * runs) adds none, as git's children see `GIT_AUTO_COMMENT_CHAR_CONFIG_WARNING_GIVEN`.
422
+ */
423
+ private warnOfAutoCommentChar(): void {
424
+ const names = this.autoCommentCharWarningEntryPoints();
425
+ if (names.length === 0) return;
426
+ const self = this as unknown as Record<string, unknown>;
427
+ for (const name of names) {
428
+ const method = self[name];
429
+ if (typeof method !== "function") continue;
430
+ self[name] = async (...args: unknown[]) => {
431
+ const { lines, leave } = enterAutoCommentCharWarning(
432
+ this._workingCopy,
433
+ this.gitCompatibility(),
434
+ );
435
+ try {
436
+ const result = await (method as (...a: unknown[]) => Promise<unknown>).apply(this, args);
437
+ if (!lines || !result || typeof result !== "object") return result;
438
+ const earlier = (result as { warnings?: string[] }).warnings ?? [];
439
+ return { ...(result as object), warnings: [...lines, ...earlier] };
440
+ } catch (error) {
441
+ if (lines && error instanceof GitApiError) {
442
+ error.warnings = [...lines, ...(error.warnings ?? [])];
443
+ }
444
+ throw error;
445
+ } finally {
446
+ leave();
447
+ }
448
+ };
449
+ }
375
450
  }
376
451
 
377
452
  /**
@@ -405,7 +480,7 @@ export abstract class GitCommand<T> {
405
480
  * function it returns runs when that call ends, whatever the outcome (subclasses scope
406
481
  * state to their calls with it: a transport command's promisor fetcher).
407
482
  */
408
- protected aroundEntryPoints(enter: () => (() => void) | undefined): void {
483
+ protected aroundEntryPoints(enter: () => (() => void | Promise<void>) | undefined): void {
409
484
  const self = this as unknown as Record<string, unknown>;
410
485
  for (const name of entryPointNames(Object.getPrototypeOf(this))) {
411
486
  const method = self[name];
@@ -416,13 +491,14 @@ export abstract class GitCommand<T> {
416
491
  try {
417
492
  result = (method as (...a: unknown[]) => unknown).apply(this, args);
418
493
  } catch (error) {
419
- leave?.();
494
+ void Promise.resolve(leave?.()).catch(() => {});
420
495
  throw error;
421
496
  }
422
497
  if (leave && result && typeof (result as Promise<unknown>).finally === "function") {
498
+ // a leave returning a promise is awaited before the call settles
423
499
  return (result as Promise<unknown>).finally(leave);
424
500
  }
425
- leave?.();
501
+ void Promise.resolve(leave?.()).catch(() => {});
426
502
  return result;
427
503
  };
428
504
  }
@@ -1558,6 +1634,31 @@ export abstract class GitCommand<T> {
1558
1634
  }
1559
1635
  }
1560
1636
 
1637
+ /**
1638
+ * git's checkout metadata (`init_checkout_metadata`) of a checkout of `name` (the revision
1639
+ * as given) at `id`: the ref the name names (`repo_dwim_ref`; with `fullRefsOnly` only one
1640
+ * under `refs/`, as `git reset` keeps it), and `id` peeled to its commit (else `id` as it
1641
+ * is: a tree). A long-running filter process is told them with each file's blob.
1642
+ */
1643
+ protected async checkoutRefOf(
1644
+ name: string | undefined,
1645
+ id: ObjectId | undefined,
1646
+ options: { fullRefsOnly?: boolean } = {},
1647
+ ): Promise<CheckoutRef> {
1648
+ const resolver = this.revisionResolver();
1649
+ let ref: string | undefined;
1650
+ if (name !== undefined) {
1651
+ ref = (await resolver.dwimRef(name).catch(() => []))[0]?.ref;
1652
+ if (ref !== undefined && options.fullRefsOnly && !ref.startsWith("refs/")) ref = undefined;
1653
+ }
1654
+ let treeish = id;
1655
+ if (id !== undefined) {
1656
+ const peeled = await resolver.peelTags(id).catch(() => undefined);
1657
+ if (peeled?.type === "commit") treeish = peeled.id;
1658
+ }
1659
+ return { ...(ref !== undefined ? { ref } : {}), ...(treeish ? { treeish } : {}) };
1660
+ }
1661
+
1561
1662
  /**
1562
1663
  * A resolver for git's revision syntax over this command's stores (see
1563
1664
  * {@link RevisionResolver}); its `warnings` hold what git would print.