@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
@@ -0,0 +1,102 @@
1
+ /**
2
+ * Where diff.c's `diff_line_prefix` (the graph's padding under `log --graph`) goes in a diff
3
+ * output: a sink recording a position before every line pushed to it, except in the bytes a
4
+ * writer marks as placing the prefix itself (git's word diff writes it only where
5
+ * `fn_out_diff_words_write_helper` and `color_words_output_graph_prefix` put it). The log
6
+ * inserts the prefix afterwards ({@link insertLinePrefix}), once its graph has printed the
7
+ * commit's header and the padding is known.
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * const sink = new LinePrefixSink();
12
+ * sink.text("diff --git a/f b/f\n");
13
+ * sink.push(markLinePrefix(encodeGitPath("-old\n"), { before: 0, own: true }));
14
+ * insertLinePrefix(sink.bytes(), sink.points, encodeGitPath("| ")); // "| diff --git a/f b/f\n-old\n"
15
+ * ```
16
+ *
17
+ * Marks follow the chunk itself (a `WeakMap` of arrays), so they survive a sink that holds
18
+ * chunks before passing them on unchanged (`MovedLineBuffer`), but not one that joins them.
19
+ *
20
+ * @module
21
+ */
22
+
23
+ import { ByteSink } from "@statewalker/vcs-utils";
24
+
25
+ /** Where a marked chunk has the line prefix */
26
+ export interface LinePrefixMark {
27
+ /** How many prefixes go right before the chunk */
28
+ before: number;
29
+ /** The chunk places its prefixes itself: none at its line starts */
30
+ own: boolean;
31
+ }
32
+
33
+ const MARKS = new WeakMap<Uint8Array, LinePrefixMark>();
34
+
35
+ /**
36
+ * Marks `bytes` for a {@link LinePrefixSink}. The mark belongs to the array object: mark a
37
+ * view of its own (`bytes.subarray(0)`) for each push of shared bytes.
38
+ */
39
+ export function markLinePrefix(bytes: Uint8Array, mark: LinePrefixMark): Uint8Array {
40
+ MARKS.set(bytes, mark);
41
+ return bytes;
42
+ }
43
+
44
+ /** A byte sink recording where the line prefix goes: each line start, marked chunks aside */
45
+ export class LinePrefixSink extends ByteSink {
46
+ /** The offsets in the output where a prefix goes, ascending (one offset may repeat) */
47
+ readonly points: number[] = [];
48
+ private offset = 0;
49
+ private atLineStart = true;
50
+
51
+ /**
52
+ * A prefix at the current end of the output, written straight to the file (diff.c's
53
+ * `fputs(line_prefix)`): ahead of what a `MovedLineBuffer` still holds
54
+ */
55
+ addPoint(): void {
56
+ this.points.push(this.offset);
57
+ }
58
+
59
+ override push(bytes: Uint8Array): void {
60
+ if (bytes.length === 0) return;
61
+ const mark = MARKS.get(bytes);
62
+ for (let i = 0; i < (mark?.before ?? 0); i++) this.points.push(this.offset);
63
+ if (mark?.own) {
64
+ super.push(bytes);
65
+ this.offset += bytes.length;
66
+ // whatever git writes next through emit_line_0 (a context line, a hunk header, the
67
+ // next file's header) starts with the prefix
68
+ this.atLineStart = true;
69
+ return;
70
+ }
71
+ super.push(bytes);
72
+ let at = 0;
73
+ while (at < bytes.length) {
74
+ if (this.atLineStart) this.points.push(this.offset + at);
75
+ const nl = bytes.indexOf(0x0a, at);
76
+ this.atLineStart = nl >= 0;
77
+ at = nl < 0 ? bytes.length : nl + 1;
78
+ }
79
+ this.offset += bytes.length;
80
+ }
81
+ }
82
+
83
+ /** `bytes` with `prefix` inserted at each of `points` (ascending offsets) */
84
+ export function insertLinePrefix(
85
+ bytes: Uint8Array,
86
+ points: readonly number[],
87
+ prefix: Uint8Array,
88
+ ): Uint8Array {
89
+ if (points.length === 0 || prefix.length === 0) return bytes;
90
+ const out = new Uint8Array(bytes.length + points.length * prefix.length);
91
+ let size = 0;
92
+ let from = 0;
93
+ for (const point of points) {
94
+ out.set(bytes.subarray(from, point), size);
95
+ size += point - from;
96
+ out.set(prefix, size);
97
+ size += prefix.length;
98
+ from = point;
99
+ }
100
+ out.set(bytes.subarray(from), size);
101
+ return out;
102
+ }
@@ -136,9 +136,10 @@ export interface MergeResult {
136
136
  */
137
137
  readonly output?: string[];
138
138
  /**
139
- * What the sparse checkout printed on stderr while the result was written, line by line:
140
- * the patterns' warnings, git's "The following paths are not up to date and were left
141
- * despite sparse patterns:" block. Absent when there was nothing to say.
139
+ * Warnings git printed on stderr, line by line: first git 2.5x's `core.commentChar=auto`
140
+ * deprecation warning and its advice, then what the sparse checkout printed while the
141
+ * result was written (the patterns' warnings, git's "The following paths are not up to
142
+ * date and were left despite sparse patterns:" block). Absent when there was nothing to say.
142
143
  */
143
144
  readonly warnings?: string[];
144
145
  /**
@@ -173,6 +173,11 @@ export interface RebaseResult {
173
173
  * said nothing.
174
174
  */
175
175
  readonly rerereOutput?: string[];
176
+ /**
177
+ * What git printed on stderr as it started, line by line: git 2.5x's
178
+ * `core.commentChar=auto` deprecation warning and its advice. Absent when it said nothing.
179
+ */
180
+ readonly warnings?: string[];
176
181
  }
177
182
 
178
183
  /**
@@ -37,9 +37,10 @@ export interface RevertResult {
37
37
  /** What is printed on stdout: merge-ort's `Auto-merging f`, `CONFLICT (...)` lines */
38
38
  readonly output?: string[];
39
39
  /**
40
- * What the sparse checkout printed on stderr while the result was written, line by line:
41
- * the patterns' warnings, git's "The following paths are not up to date and were left
42
- * despite sparse patterns:" block. Absent when there was nothing to say.
40
+ * Warnings git printed on stderr, line by line: first git 2.5x's `core.commentChar=auto`
41
+ * deprecation warning and its advice, then what the sparse checkout printed while the
42
+ * result was written (the patterns' warnings, git's "The following paths are not up to
43
+ * date and were left despite sparse patterns:" block). Absent when there was nothing to say.
43
44
  */
44
45
  readonly warnings?: string[];
45
46
  /**
@@ -13,12 +13,16 @@ import {
13
13
  createBundleUriHost,
14
14
  fetchBundleUri,
15
15
  } from "./commands/bundle/index.js";
16
+ import { configuresCredentialHelper, credentialHelperOf } from "./commands/credential-helper.js";
17
+ import { hookRunnerOf } from "./commands/git-hooks.js";
16
18
  import { hostEnvironmentOf } from "./commands/git-ident.js";
17
19
  import { httpClientSettingsOf } from "./commands/http-config.js";
20
+ import { remoteHookSession } from "./commands/local-transport.js";
18
21
  import { createPromisorFetcher, promisorOf } from "./commands/promisor-remote.js";
19
22
  import {
20
23
  bundleRemoteOf,
21
24
  httpSessionSettings,
25
+ localLazyFetchOf,
22
26
  openResolvedRemote,
23
27
  type PreparedRemote,
24
28
  prepareRemote,
@@ -82,6 +86,8 @@ export abstract class TransportCommand<T> extends GitCommand<T> {
82
86
  protected credentialHelper?: HttpCredentialHelper;
83
87
  /** git's `warning:` lines of the HTTP client */
84
88
  protected warningCallback?: (line: string) => void;
89
+ /** The helper built from `credential.helper` for this command (see {@link httpCredentialHelper}) */
90
+ private configCredentialHelper?: HttpCredentialHelper | null;
85
91
 
86
92
  constructor(workingCopy: WorkingCopy) {
87
93
  super(workingCopy);
@@ -239,6 +245,24 @@ export abstract class TransportCommand<T> extends GitCommand<T> {
239
245
  return this;
240
246
  }
241
247
 
248
+ /**
249
+ * The credential helper this command's HTTP requests ask: the one given to
250
+ * {@link setCredentialHelper}, else, when the configuration names a `credential.helper`
251
+ * and the host has a hook runner, git's helpers of that configuration (credential.c through
252
+ * {@link credentialHelperOf}: their stderr in the hook output), as git's transports read
253
+ * them; else none.
254
+ */
255
+ protected httpCredentialHelper(): HttpCredentialHelper | undefined {
256
+ if (this.credentialHelper) return this.credentialHelper;
257
+ if (this.configCredentialHelper === undefined) {
258
+ this.configCredentialHelper =
259
+ hookRunnerOf(this._workingCopy) && configuresCredentialHelper(this._workingCopy)
260
+ ? credentialHelperOf(this._workingCopy, { hooks: this.hooks })
261
+ : null;
262
+ }
263
+ return this.configCredentialHelper ?? undefined;
264
+ }
265
+
242
266
  /**
243
267
  * Receives the `warning:` lines git's HTTP client prints on stderr (`rate limited, waiting
244
268
  * <n> seconds before retry`).
@@ -356,8 +380,23 @@ export abstract class TransportCommand<T> extends GitCommand<T> {
356
380
  ...(this.gzipRequests !== undefined ? { gzipRequests: this.gzipRequests } : {}),
357
381
  protocolVersion: protocolVersionOf(RemoteConfigStore.from(this._workingCopy)),
358
382
  httpSettings: (url) => this.httpSettingsFor(url),
359
- ...(this.credentialHelper ? { credentialHelper: this.credentialHelper } : {}),
383
+ ...credentialHelperOption(this.httpCredentialHelper()),
360
384
  ...httpSessionSettings(this._workingCopy),
385
+ // a local remote's upload-pack runs the protected uploadpack.packObjectsHook through
386
+ // this host's runner, in the remote's git directory, with local_repo_env cleared
387
+ localHooks: (remote) => remoteHookSession(this._workingCopy, remote, { localPush: true }),
388
+ // GIT_NAMESPACE: what a local remote's upload-pack and receive-pack serve
389
+ ...(() => {
390
+ const namespace = hostEnvironmentOf(this._workingCopy)?.namespace;
391
+ return namespace ? { namespace } : {};
392
+ })(),
393
+ // GIT_NO_LAZY_FETCH=0: a local remote's upload-pack fetches what it lacks
394
+ ...localLazyFetchOf(hostEnvironmentOf(this._workingCopy), {
395
+ transports: this.getTransports(),
396
+ ...(this.credentialHelper ? { credentialHelper: this.credentialHelper } : {}),
397
+ ...(this.timeout !== undefined ? { timeout: this.timeout } : {}),
398
+ ...(this.warningCallback ? { warningCallback: this.warningCallback } : {}),
399
+ }),
361
400
  };
362
401
  }
363
402
 
@@ -441,7 +480,7 @@ export abstract class TransportCommand<T> extends GitCommand<T> {
441
480
  ...(options.remoteUrl !== undefined ? { remoteUrl: options.remoteUrl } : {}),
442
481
  ...(this.credentials ? { credentials: this.credentials } : {}),
443
482
  ...(this.headers ? { headers: this.headers } : {}),
444
- ...(this.credentialHelper ? { credentialHelper: this.credentialHelper } : {}),
483
+ ...credentialHelperOption(this.httpCredentialHelper()),
445
484
  httpSettings: (url) => this.httpSettingsFor(url),
446
485
  configValue: (key) => store.value(key),
447
486
  setConfigValue:
@@ -505,3 +544,10 @@ export abstract class TransportCommand<T> extends GitCommand<T> {
505
544
  };
506
545
  }
507
546
  }
547
+
548
+ /** The `credentialHelper` option of a session or host, when there is one. */
549
+ function credentialHelperOption(helper: HttpCredentialHelper | undefined): {
550
+ credentialHelper?: HttpCredentialHelper;
551
+ } {
552
+ return helper ? { credentialHelper: helper } : {};
553
+ }