@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
@@ -16,8 +16,12 @@ import type { CompatObjects, GitObjects, ObjectId } from "@statewalker/vcs-core"
16
16
  import { ObjectInfoError } from "@statewalker/vcs-transport";
17
17
  import { parseGitBool } from "@statewalker/vcs-utils";
18
18
  import { decodeGitPath } from "@statewalker/vcs-utils/encoding";
19
+ import { FilterDriverError } from "@statewalker/vcs-working-tree";
20
+ import { GitApiError } from "../../errors/index.js";
19
21
  import { RemoteConfigStore } from "../../remote-config/index.js";
20
22
  import { quotePath } from "../../results/quote-path.js";
23
+ import { DiffCommand } from "../diff-command.js";
24
+ import { type ObjectDiskInfo, objectDiskInfoOf } from "../object-disk-info.js";
21
25
  import { PlumbingCommand, PlumbingError } from "../plumbing-command.js";
22
26
  import { concatBytes, objectTypeOfMode } from "../plumbing-shared.js";
23
27
  import {
@@ -36,8 +40,11 @@ import {
36
40
  parseBatchFormat,
37
41
  } from "./batch-format.js";
38
42
 
39
- /** `-t`, `-s`, `-e`, `-p`. */
40
- export type CatFileMode = "type" | "size" | "exists" | "pretty";
43
+ /**
44
+ * `-t`, `-s`, `-e`, `-p`, `--textconv` (the path's textconv driver over the blob, else `-p`)
45
+ * and `--filters` (the blob as checkout writes it to the worktree).
46
+ */
47
+ export type CatFileMode = "type" | "size" | "exists" | "pretty" | "textconv" | "filters";
41
48
 
42
49
  /** `--batch` (contents), `--batch-check` (info), `--batch-command` (command). */
43
50
  export type CatFileBatchMode = "contents" | "info" | "command";
@@ -48,6 +55,7 @@ export type CatFileInput = string | Uint8Array | AsyncIterable<Uint8Array> | Ite
48
55
  const OBJECT_TYPES = new Set(["blob", "tree", "commit", "tag"]);
49
56
  const S_IFMT = 0o170000;
50
57
  const S_IFGITLINK = 0o160000;
58
+ const S_IFREG = 0o100000;
51
59
  const encoder = new TextEncoder();
52
60
  const MAILMAP_HEADERS = ["author ", "committer ", "tagger "].map((h) => encoder.encode(h));
53
61
  /** git's `MAXREPLACEDEPTH` */
@@ -71,16 +79,27 @@ interface ObjectInfo {
71
79
  * `object-info` through {@link setRemoteObjectInfo}'s command: only the atoms the server
72
80
  * answered expand (`%(objectname)` always), and an object it lacks prints `<id> missing`.
73
81
  *
74
- * Not implemented: `--textconv`, `--filters`, `--path`, `--follow-symlinks`, `--filter`
75
- * (2.5x), and the `%(objectsize:disk)` and `%(deltabase)` atoms (refused: the stores report
76
- * neither; git's `remote-object-info` would print them empty). `--unordered` lists objects in
82
+ * `--textconv` and `--filters` (git's `textconv_object` and `filter_object`) convert a blob for
83
+ * the path its name reads (`<rev>:<path>`, `:<path>`) or {@link setPath} gives, with the mode
84
+ * of its entry (a symbolic link is left as it is); textconv goes through the driver's cache
85
+ * (`diff.<driver>.cachetextconv`) and needs a host textconv runner, without which the blob is
86
+ * printed as `-p` prints it. In the batch modes the path is each line's rest (the header keeps
87
+ * the object's own size, as git's) and a converted blob is held whole, as git holds it.
88
+ *
89
+ * `%(objectsize:disk)` and `%(deltabase)` read the object's pack entry header or loose file
90
+ * (`objectDiskInfoOf`); a `remote-object-info` line prints them empty, as git.
91
+ *
92
+ * Not implemented: `--follow-symlinks`, `--filter` (2.5x). `--unordered` lists objects in
77
93
  * the store's listing order, not pack order. The promisor-remote warning of
78
94
  * `--batch-all-objects` is not printed.
79
95
  */
80
96
  export class CatFileCommand extends PlumbingCommand {
81
97
  private mode?: CatFileMode;
98
+ /** The on-disk measures, for `%(objectsize:disk)` and `%(deltabase)` */
99
+ private diskInfo?: Promise<ObjectDiskInfo>;
82
100
  private type?: string;
83
101
  private object?: string;
102
+ private path?: string;
84
103
  private batch?: CatFileBatchMode;
85
104
  private format?: string;
86
105
  private buffer?: boolean;
@@ -96,6 +115,7 @@ export class CatFileCommand extends PlumbingCommand {
96
115
  setMode(mode: CatFileMode): this {
97
116
  this.checkCallable();
98
117
  this.mode = mode;
118
+ this.modeSetLast = true;
99
119
  return this;
100
120
  }
101
121
 
@@ -106,6 +126,13 @@ export class CatFileCommand extends PlumbingCommand {
106
126
  return this;
107
127
  }
108
128
 
129
+ /** `--path=<path>`: the path `--textconv`/`--filters` convert for (ignored in batch modes). */
130
+ setPath(path: string): this {
131
+ this.checkCallable();
132
+ this.path = path;
133
+ return this;
134
+ }
135
+
109
136
  /** The object named on the command line. */
110
137
  setObject(name: string): this {
111
138
  this.checkCallable();
@@ -149,9 +176,13 @@ export class CatFileCommand extends PlumbingCommand {
149
176
  setBatchAllObjects(all: boolean): this {
150
177
  this.checkCallable();
151
178
  this.allObjects = all;
179
+ if (all) this.modeSetLast = false;
152
180
  return this;
153
181
  }
154
182
 
183
+ /** Whether {@link setMode} came after {@link setBatchAllObjects} (both git's cmdmodes) */
184
+ private modeSetLast = false;
185
+
155
186
  /** `--unordered` (with `--batch-all-objects`): the store's order, not sorted by id. */
156
187
  setUnordered(unordered: boolean): this {
157
188
  this.checkCallable();
@@ -205,9 +236,27 @@ export class CatFileCommand extends PlumbingCommand {
205
236
  /** The option checks of cmd_cat_file that the setters can still break. */
206
237
  private checkOptions(): void {
207
238
  const usage = (message: string) => new PlumbingError(`fatal: ${message}`, 129);
239
+ const transform = this.mode === "textconv" || this.mode === "filters";
240
+ if (this.path !== undefined && !transform) {
241
+ throw usage("'--path=<path|tree-ish>' needs '--filters' or '--textconv'");
242
+ }
243
+ if (transform && this.allObjects) {
244
+ // OPT_CMDMODE: --batch-all-objects is a cmdmode too, refused by parse_options
245
+ const [first, second] = this.modeSetLast
246
+ ? ["--batch-all-objects", `--${this.mode}`]
247
+ : [`--${this.mode}`, "--batch-all-objects"];
248
+ throw new PlumbingError(
249
+ this.compatibility === "2.43"
250
+ ? `error: ${second} is incompatible with ${first}`
251
+ : `error: options '${second}' and '${first}' cannot be used together`,
252
+ 129,
253
+ );
254
+ }
208
255
  if (this.batch) {
209
- if (this.mode) throw usage(`'-${modeLetter(this.mode)}' is incompatible with batch mode`);
210
- if (this.object !== undefined || this.type !== undefined) {
256
+ if (this.mode && !transform)
257
+ throw usage(`'-${modeLetter(this.mode)}' is incompatible with batch mode`);
258
+ // with --textconv/--filters git takes the transform branch first and ignores arguments
259
+ if (!transform && (this.object !== undefined || this.type !== undefined)) {
211
260
  throw usage("batch modes take no arguments");
212
261
  }
213
262
  return;
@@ -224,6 +273,9 @@ export class CatFileCommand extends PlumbingCommand {
224
273
  : undefined;
225
274
  if (batchOption) throw usage(`'${batchOption}' requires a batch mode`);
226
275
  if (this.mode) {
276
+ if (this.object === undefined && transform) {
277
+ throw usage(`<rev> required with '--${this.mode}'`);
278
+ }
227
279
  if (this.object === undefined) {
228
280
  throw usage(`<object> required with '-${modeLetter(this.mode)}'`);
229
281
  }
@@ -233,6 +285,13 @@ export class CatFileCommand extends PlumbingCommand {
233
285
  }
234
286
  }
235
287
 
288
+ /** The batch modes' transform (`--textconv`, `--filters`) */
289
+ private get transformMode(): "textconv" | "filters" | undefined {
290
+ return this.batch && (this.mode === "textconv" || this.mode === "filters")
291
+ ? this.mode
292
+ : undefined;
293
+ }
294
+
236
295
  private get objects(): GitObjects {
237
296
  const objects = this._workingCopy.history?.objects;
238
297
  if (!objects) throw new Error("WorkingCopy.history is required for commands");
@@ -300,15 +359,23 @@ export class CatFileCommand extends PlumbingCommand {
300
359
  private async catOne(name: string): Promise<number> {
301
360
  const resolver = this.revisionResolver();
302
361
  let id: ObjectId | undefined;
362
+ const transform = this.mode === "textconv" || this.mode === "filters";
303
363
  try {
304
364
  // GET_OID_HASH_ANY: an id of the compatibility format (full or abbreviated) names the
305
365
  // object as that format sees it (its storage object converted)
306
- id = await resolver.resolve(name, { onlyToDie: true, hashAny: true });
366
+ id = await resolver.resolve(name, {
367
+ onlyToDie: true,
368
+ hashAny: true,
369
+ requirePath: transform && this.path === undefined,
370
+ });
307
371
  } finally {
308
372
  for (const line of resolver.warnings) this.warn(line);
309
373
  resolver.warnings.length = 0;
310
374
  }
311
375
  if (id === undefined) throw new PlumbingError(`fatal: Not a valid object name ${name}`);
376
+ // GET_OID_RECORD_PATH: the path and mode the name read (a mode it did not read: 0100644)
377
+ const path = this.path ?? resolver.lastPath ?? "";
378
+ const mode = resolver.lastMode ?? 0o100644;
312
379
  const compat = this.compatIdOf(id);
313
380
  if (compat) return this.catOneCompat(id, compat);
314
381
  const couldNotGetInfo = () =>
@@ -336,6 +403,25 @@ export class CatFileCommand extends PlumbingCommand {
336
403
  return (await this.objects.has(id)) ? 0 : 1;
337
404
  case "pretty":
338
405
  return this.pretty(name, await this.replaced(id));
406
+ case "filters": {
407
+ const object = await this.read(await this.replaced(id));
408
+ if (!object) {
409
+ this.warn(`error: cannot read object ${id} '${path}'`);
410
+ return 255;
411
+ }
412
+ await this.write(
413
+ object.type === "blob" ? await this.filtered(path, mode, id, object.bytes) : object.bytes,
414
+ );
415
+ return 0;
416
+ }
417
+ case "textconv": {
418
+ const converted = await this.textconv(path, mode, await this.replaced(id), id);
419
+ if (converted) {
420
+ await this.write(converted);
421
+ return 0;
422
+ }
423
+ return this.pretty(name, await this.replaced(id));
424
+ }
339
425
  default:
340
426
  return this.catTyped(name, id, this.type as string);
341
427
  }
@@ -406,6 +492,67 @@ export class CatFileCommand extends PlumbingCommand {
406
492
  }
407
493
  }
408
494
 
495
+ /**
496
+ * filter_object's conversion of a blob: `convert_to_working_tree` for `path` when `mode` is
497
+ * a regular file's (smudge filter, `eol`, `ident`, `working-tree-encoding`).
498
+ */
499
+ private async filtered(
500
+ path: string,
501
+ mode: number,
502
+ id: ObjectId,
503
+ bytes: Uint8Array,
504
+ ): Promise<Uint8Array> {
505
+ if ((mode & S_IFMT) !== S_IFREG) return bytes;
506
+ const filter = this.worktreeAccess?.contentFilter;
507
+ if (!filter) return bytes;
508
+ try {
509
+ const conversion = await filter.checkout(path);
510
+ if (!conversion) return bytes;
511
+ return await conversion.apply(bytes, {
512
+ onWarning: (message) => this.warn(message),
513
+ metadata: { blob: id },
514
+ });
515
+ } catch (error) {
516
+ if (
517
+ error instanceof FilterDriverError ||
518
+ (error instanceof Error &&
519
+ error.message === "true/false are no valid working-tree-encodings")
520
+ ) {
521
+ throw new PlumbingError(`fatal: ${(error as Error).message}`);
522
+ }
523
+ throw error;
524
+ }
525
+ }
526
+
527
+ /** The diff command whose textconv caches this run shares (git's per-process caches) */
528
+ private textconvDiff?: DiffCommand;
529
+
530
+ /**
531
+ * textconv_object: the output of `path`'s textconv driver over the blob `target` (read for
532
+ * `id`, the name the cache is keyed by), or undefined when no driver applies.
533
+ */
534
+ private async textconv(
535
+ path: string,
536
+ mode: number,
537
+ target: ObjectId,
538
+ id: ObjectId,
539
+ ): Promise<Uint8Array | undefined> {
540
+ this.textconvDiff ??= new DiffCommand(this._workingCopy);
541
+ const read = async () => {
542
+ const object = await this.read(target);
543
+ if (!object) throw new PlumbingError(`fatal: unable to read ${id}`);
544
+ return object.bytes;
545
+ };
546
+ try {
547
+ return await this.textconvDiff.textconvBlob(path, mode, read, id);
548
+ } catch (error) {
549
+ if (error instanceof GitApiError) throw error;
550
+ // fill_textconv: run_textconv fails without a line of its own (finish_command's
551
+ // status), then the death
552
+ throw new PlumbingError("fatal: unable to read files to diff");
553
+ }
554
+ }
555
+
409
556
  /** `-p` */
410
557
  private async pretty(name: string, id: ObjectId): Promise<number> {
411
558
  const info = await this.info(id);
@@ -491,11 +638,9 @@ export class CatFileCommand extends PlumbingCommand {
491
638
  /** batch_objects */
492
639
  private async runBatch(): Promise<number> {
493
640
  const compatibility = this.compatibility;
494
- // --batch-command defers %(objectsize:disk)/%(deltabase) to the first local object: a
495
- // remote-object-info line prints them empty, as git
496
- const format = parseBatchFormat(this.format ?? DEFAULT_BATCH_FORMAT, compatibility, {
497
- deferUnsupported: this.batch === "command",
498
- });
641
+ // a remote-object-info line of --batch-command prints %(objectsize:disk)/%(deltabase)
642
+ // empty, as git
643
+ const format = parseBatchFormat(this.format ?? DEFAULT_BATCH_FORMAT, compatibility);
499
644
  const plain = this.format === undefined || this.format === DEFAULT_BATCH_FORMAT;
500
645
  const state: BatchState = {
501
646
  format,
@@ -525,7 +670,7 @@ export class CatFileCommand extends PlumbingCommand {
525
670
  for await (const line of lines) {
526
671
  let name = line;
527
672
  let rest: string | undefined;
528
- if (format.splitOnWhitespace) {
673
+ if (format.splitOnWhitespace || this.transformMode) {
529
674
  const split = /[ \t]/.exec(line);
530
675
  if (split) {
531
676
  name = line.slice(0, split.index);
@@ -731,6 +876,16 @@ export class CatFileCommand extends PlumbingCommand {
731
876
  await this.write(state.delim);
732
877
  }
733
878
 
879
+ /** `disk_sizep` and `delta_base_oid` of the object info batch_object_write asks for. */
880
+ private async onDisk(id: ObjectId, data: BatchObjectData): Promise<void> {
881
+ this.diskInfo ??= objectDiskInfoOf(this._workingCopy);
882
+ const info = await this.diskInfo;
883
+ const diskSize = await info.diskSize(id);
884
+ const deltaBase = await info.deltaBase(id);
885
+ if (diskSize !== undefined) data.diskSize = diskSize;
886
+ if (deltaBase !== undefined) data.deltaBase = deltaBase;
887
+ }
888
+
734
889
  /** batch_object_write */
735
890
  private async batchObjectWrite(
736
891
  state: BatchState,
@@ -753,6 +908,7 @@ export class CatFileCommand extends PlumbingCommand {
753
908
  }
754
909
  data.type = info.type;
755
910
  data.size = info.size;
911
+ if (state.format.needsDisk) await this.onDisk(target, data);
756
912
  let content: Uint8Array | undefined;
757
913
  if (this.useMailmap && (info.type === "commit" || info.type === "tag")) {
758
914
  const object = await this.read(target);
@@ -765,7 +921,17 @@ export class CatFileCommand extends PlumbingCommand {
765
921
  : `${expandBatchFormat(state.format, data)}${state.delim}`;
766
922
  await this.write(header);
767
923
  if (!state.contents) return;
768
- if (info.type === "blob") {
924
+ if (info.type === "blob" && this.transformMode) {
925
+ // print_object_or_die: the line's rest is the path, the blob held whole
926
+ if (data.rest === undefined) throw new PlumbingError(`fatal: missing path for '${data.id}'`);
927
+ const object = await this.read(target);
928
+ if (!object) throw new PlumbingError(`fatal: could not convert '${data.id}' ${data.rest}`);
929
+ const converted =
930
+ this.transformMode === "filters"
931
+ ? await this.filtered(data.rest, 0o100644, data.id, object.bytes)
932
+ : ((await this.textconv(data.rest, 0o100644, target, data.id)) ?? object.bytes);
933
+ await this.write(converted);
934
+ } else if (info.type === "blob") {
769
935
  await this.streamBlob(target);
770
936
  } else {
771
937
  if (!content) {
@@ -10,7 +10,13 @@
10
10
  * ```
11
11
  */
12
12
 
13
- import { expandUserPath, type IgnoreMatch, xdgConfigPath } from "@statewalker/vcs-working-tree";
13
+ import {
14
+ expandUserPath,
15
+ type IgnoreMatch,
16
+ PrepExcludeError,
17
+ rawPathSteps,
18
+ xdgConfigPath,
19
+ } from "@statewalker/vcs-working-tree";
14
20
 
15
21
  import { GitCommand } from "../git-command.js";
16
22
  import { quotePath } from "../results/quote-path.js";
@@ -142,7 +148,9 @@ export class CheckIgnoreCommand extends GitCommand<PlumbingTextOutput> {
142
148
  * refused), PATHSPEC_SYMLINK_LEADING_PATH, then die_path_inside_submodule: the path
143
149
  * from the top, or git's death.
144
150
  */
145
- const parse = async (original: string): Promise<{ path: string } | { death: string }> => {
151
+ const parse = async (
152
+ original: string,
153
+ ): Promise<{ path: string; asWritten: boolean } | { death: string }> => {
146
154
  if (original === "") return { death: EMPTY };
147
155
  let parsed: { magic: Set<string>; rest: string };
148
156
  try {
@@ -155,22 +163,37 @@ export class CheckIgnoreCommand extends GitCommand<PlumbingTextOutput> {
155
163
  if (magic.has("literal") && magic.has("glob")) {
156
164
  return { death: `${original}: 'literal' and 'glob' are incompatible` };
157
165
  }
158
- const full = prefixPath(magic.has("top") ? "" : this.prefix, rest, top);
166
+ // init_pathspec_item: a `:/` element is taken as written (`match = xstrdup(copyfrom)`:
167
+ // no prefix_path_gently, so no normalisation and no "outside repository" death)
168
+ const asWritten = magic.has("top");
169
+ const full = asWritten ? rest : prefixPath(this.prefix, rest, top);
159
170
  if (full === undefined) {
160
171
  return { death: `${original}: '${rest}' is outside repository at '${top ?? ""}'` };
161
172
  }
162
173
  const unsupported = unsupportedPathspecMagic(original, magic, ["top"]);
163
174
  if (unsupported) return { death: unsupported };
175
+ const beyondLink = { death: `pathspec '${original}' is beyond a symbolic link` };
176
+ // PATHSPEC_SYMLINK_LEADING_PATH: has_symlink_leading_path's lstat of each leading
177
+ // component, stopping at one that is missing or no directory
178
+ if (asWritten) {
179
+ const slash = full.lastIndexOf("/");
180
+ for (const step of rawPathSteps(slash < 0 ? "" : full.slice(0, slash), top)) {
181
+ if (step.name === "." || step.name === ".." || step.name === "") continue;
182
+ if (step.above || step.inside === "") continue;
183
+ if (step.inside === undefined) break;
184
+ const entry = await worktree.getEntry(step.inside).catch(() => undefined);
185
+ if (entry && (entry.mode & S_IFMT) === S_IFLNK) return beyondLink;
186
+ if (!entry?.isDirectory) break;
187
+ }
188
+ return { path: full, asWritten };
189
+ }
164
190
  const path = full.replace(/\/+$/, "");
165
- // PATHSPEC_SYMLINK_LEADING_PATH
166
191
  const parts = path.split("/");
167
192
  for (let k = 1; k < parts.length; k++) {
168
193
  const entry = await worktree.getEntry(parts.slice(0, k).join("/")).catch(() => undefined);
169
- if (entry && (entry.mode & S_IFMT) === S_IFLNK) {
170
- return { death: `pathspec '${original}' is beyond a symbolic link` };
171
- }
194
+ if (entry && (entry.mode & S_IFMT) === S_IFLNK) return beyondLink;
172
195
  }
173
- return { path: full };
196
+ return { path: full, asWritten };
174
197
  };
175
198
  const insideSubmodule = (original: string, full: string): string | undefined => {
176
199
  if (!staging) return undefined;
@@ -183,32 +206,53 @@ export class CheckIgnoreCommand extends GitCommand<PlumbingTextOutput> {
183
206
  }
184
207
  return undefined;
185
208
  };
186
- const checkOne = async (original: string, full: string): Promise<void> => {
187
- const path = full.replace(/\/+$/, "");
209
+ /** One path of check_ignore's loop; git's death in prep_exclude as its message. */
210
+ const checkOne = async (
211
+ original: string,
212
+ full: string,
213
+ asWritten: boolean,
214
+ ): Promise<string | undefined> => {
188
215
  let match: IgnoreMatch | undefined;
189
- if (!staging || !this.seenInIndex(full, index)) {
190
- match = await worktree.ignoreMatch?.(path);
216
+ // no index entry has a `.` or `..` component (verify_path), so match_pathspec of such
217
+ // an element as written finds none
218
+ const seen =
219
+ !!staging &&
220
+ !(asWritten && full.split("/").some((p) => p === "." || p === "..")) &&
221
+ this.seenInIndex(full, index);
222
+ if (!seen) {
223
+ try {
224
+ match = asWritten
225
+ ? await worktree.ignoreMatch?.(full, false, { asWritten, hostTop: top })
226
+ : await worktree.ignoreMatch?.(full.replace(/\/+$/, ""));
227
+ } catch (error) {
228
+ if (error instanceof PrepExcludeError) return error.message;
229
+ throw error;
230
+ }
191
231
  if (!this.verbose && match?.negated) match = undefined;
192
232
  }
193
233
  if (!this.quiet && (match || this.nonMatching))
194
234
  stdout += this.line(original, match, sources, quoteFully);
195
235
  if (match) ignored++;
236
+ return undefined;
196
237
  };
197
238
  /** check_ignore of the paths of one call: every element parsed before any output. */
198
239
  const checkAll = async (originals: string[]): Promise<string | undefined> => {
199
240
  if (originals.includes("")) return EMPTY;
200
- const paths: string[] = [];
241
+ const paths: { path: string; asWritten: boolean }[] = [];
201
242
  for (const original of originals) {
202
243
  const parsed = await parse(original);
203
244
  if ("death" in parsed) return parsed.death;
204
- paths.push(parsed.path);
245
+ paths.push(parsed);
246
+ }
247
+ for (let i = 0; i < originals.length; i++) {
248
+ const death = insideSubmodule(originals[i] as string, paths[i]?.path as string);
249
+ if (death) return death;
205
250
  }
206
251
  for (let i = 0; i < originals.length; i++) {
207
- const death = insideSubmodule(originals[i] as string, paths[i] as string);
252
+ const { path, asWritten } = paths[i] as { path: string; asWritten: boolean };
253
+ const death = await checkOne(originals[i] as string, path, asWritten);
208
254
  if (death) return death;
209
255
  }
210
- for (let i = 0; i < originals.length; i++)
211
- await checkOne(originals[i] as string, paths[i] as string);
212
256
  return undefined;
213
257
  };
214
258