@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
@@ -1,366 +1,13 @@
1
- import { I as __exportAll, m as receiveFsckOf } from "./fsck-C4US3l0B.js";
2
- import { GitApiError, InvalidConfigError, InvalidPathError, ReadTreeFailedError, TransportError as TransportError$1 } from "./errors/index.js";
3
- import { $t as SubmoduleUnpack, As as quoteCStyleBody, Il as hookSettingsFromEntries, In as checkSignatureWith, Jl as coreBool, Lt as resetMerge, Nl as hookHostOf, R as StatusCommand, Sl as worktreePathRules, Tl as LOCAL_REPO_ENV, Wc as SparseUnpack, Xa as signingConfigFromEntries, Xl as worktreeModeTrust, _l as restoreCaseOptions, bn as worktreeAdminWorkingCopy, ca as plainUnpackError, dl as untrackedUnder, en as recursesIntoSubmodules, fa as rewriteIndex, ga as switchTrees, gn as requireWorktrees, hn as repositoryPlaceOf, ia as flatTree, ju as RemoteConfigStore, la as planPathsRestore, nl as entryNotUptodate, ol as pruneEmptyParents, pn as parseExpiry, qc as pushSparseWarnings, ra as firstPlainError, sl as removeCaseVariants, tl as IndexCaseFolding, vl as writeTreeRestorePlan, wl as HookSession, xl as withTreePathRefusal, xn as worktreeUsingBranch, yl as firstInvalidPath, yn as usesBranch, yu as hostEnvironmentOf, za as GitCommand, zl as refTransactionHookOf } from "./results-B0CWLCAp.js";
4
- import { FileMode, historyWithoutLazyFetch } from "@statewalker/vcs-core";
5
- import { compareGitPaths, decodeGitPath, encodeGitPath, parseGitBool, parseGitInt } from "@statewalker/vcs-utils/encoding";
1
+ import { I as __exportAll, m as receiveFsckOf } from "./fsck-BZ508Elg.js";
2
+ import { GitApiError, InvalidPathError, ReadTreeFailedError, TransportError as TransportError$1 } from "./errors/index.js";
3
+ import { $l as firstInvalidPath, Au as worktreeModeTrust, B as StatusCommand, Bl as removeCaseVariants, Fc as LAZY_FETCH_DISABLED_WARNING, Ga as switchTrees, Gl as untrackedUnder, Gn as requireWorktrees, Hn as parseExpiry, Ic as createPromisorFetcher, Jn as usesBranch, La as plainUnpackError, Lc as hasPromisorRemote, Ma as firstPlainError, Ml as IndexCaseFolding, Na as flatTree, On as SubmoduleUnpack, Ou as coreBool, Pl as entryNotUptodate, Ql as writeTreeRestorePlan, Ra as planPathsRestore, To as signingConfigFromEntries, Va as rewriteIndex, Wn as repositoryPlaceOf, Xn as worktreeUsingBranch, Yn as worktreeAdminWorkingCopy, Zl as restoreCaseOptions, au as LOCAL_REPO_ENV, dr as checkSignatureWith, ed as hostEnvironmentOf, fd as RemoteConfigStore, fn as resetMerge, gu as hookSettingsFromEntries, iu as HookSession, kn as recursesIntoSubmodules, mo as GitCommand, nu as worktreePathRules, oc as quoteCStyleBody, pu as hookHostOf, tu as withTreePathRefusal, wl as pushSparseWarnings, xl as SparseUnpack, yu as refTransactionHookOf, zl as pruneEmptyParents } from "./results-rF81cQse.js";
4
+ import { FileMode, historyWithPromisorFetcher, historyWithoutLazyFetch } from "@statewalker/vcs-core";
5
+ import { compareGitPaths, parseGitBool, parseGitInt } from "@statewalker/vcs-utils/encoding";
6
6
  import { attributesIndexOf, cacheTreeOfTree, entryStatOf, isIndexUnborn, repairCacheTree, sparseFilterMatcher } from "@statewalker/vcs-working-tree";
7
7
  import { parseGitInt as parseGitInt$1 } from "@statewalker/vcs-utils";
8
8
  import { readFile as readFile$1 } from "@statewalker/vcs-utils/files";
9
- import { SHA1_OBJECT_FORMAT as SHA1_OBJECT_FORMAT$1, objectFormatByName as objectFormatByName$1 } from "@statewalker/vcs-utils/hash";
10
9
  import { configFilesApiOf, gc, parseExpiryDate, readConfinedFile, updateServerInfo } from "@statewalker/vcs-store-files";
11
- import { ReceivePackDiedError, connectivityErrors, createRepositoryFacade, createTransportRefStore, isGitUrl, openDuplexConnection, openDuplexReceivePackConnection, openReceivePack, openUploadPack, parseGitUrl, protocolVersionFor, pushCertificateEnv, serveOverDuplex, serverSettingsFromConfig } from "@statewalker/vcs-transport";
12
- //#region src/commands/bundle/bundle-format.ts
13
- /**
14
- * git's bundle files (bundle.c, `Documentation/gitformat-bundle.adoc`): a header naming the
15
- * refs the bundle carries and the commits it needs, then a pack.
16
- *
17
- * @example
18
- * ```typescript
19
- * // # v3 git bundle
20
- * // @object-format=sha256
21
- * // -<id> <subject> (a prerequisite)
22
- * // <id> refs/heads/main (a ref)
23
- * // (an empty line, then the pack)
24
- * const header = parseBundleHeader(bytes);
25
- * if (header.ok) for (const ref of header.header.references) console.log(ref.id, ref.name);
26
- * ```
27
- */
28
- /** The first line of a v2 bundle. */
29
- const V2_BUNDLE_SIGNATURE = "# v2 git bundle\n";
30
- /** The first line of a v3 bundle (capabilities may follow). */
31
- const V3_BUNDLE_SIGNATURE = "# v3 git bundle\n";
32
- /** git's sane_ctype isspace: SP, HT, LF, CR */
33
- const SPACE = (c) => c === 32 || c === 9 || c === 10 || c === 13;
34
- const HEX = /^[0-9a-fA-F]$/;
35
- /**
36
- * bundle.c's `read_bundle_header_fd`: the signature, then lines up to an empty one (or the
37
- * end): v3 capabilities (`@object-format=`, `@filter=`), prerequisites (`-<id>` optionally
38
- * followed by a space and a comment) and refs (`<id> <name>`), each line right-trimmed.
39
- * `name` is how a bad signature is reported (git's `report_path`).
40
- *
41
- * @example
42
- * ```typescript
43
- * const parsed = parseBundleHeader(bytes, "repo.bundle");
44
- * if (!parsed.ok) console.error(`error: ${parsed.error}`);
45
- * ```
46
- */
47
- function parseBundleHeader(bytes, name = "<bundle>", defaultFormat = SHA1_OBJECT_FORMAT$1) {
48
- let at = 0;
49
- /** strbuf_getwholeline_fd: the next line with its LF; undefined at the end */
50
- const nextLine = () => {
51
- if (at >= bytes.length) return void 0;
52
- const lf = bytes.indexOf(10, at);
53
- const end = lf < 0 ? bytes.length : lf + 1;
54
- const line = bytes.subarray(at, end);
55
- at = end;
56
- return line;
57
- };
58
- const first = nextLine();
59
- const signature = first ? latin1(first) : "";
60
- const version = signature === "# v2 git bundle\n" ? 2 : signature === "# v3 git bundle\n" ? 3 : 0;
61
- if (version === 0) return {
62
- ok: false,
63
- error: `'${name}' does not look like a v2 or v3 bundle file`,
64
- notABundle: true
65
- };
66
- let objectFormat = defaultFormat;
67
- let filter;
68
- const prerequisites = [];
69
- const references = [];
70
- const fail = (error) => ({
71
- ok: false,
72
- error,
73
- notABundle: false
74
- });
75
- for (let line = nextLine(); line !== void 0; line = nextLine()) {
76
- if (line.length === 0 || line[0] === 10) break;
77
- let end = line.length;
78
- while (end > 0 && SPACE(line[end - 1])) end--;
79
- let text = line.subarray(0, end);
80
- if (version === 3 && text[0] === 64) {
81
- const capability = decodeGitPath(text.subarray(1));
82
- if (capability.startsWith("object-format=")) {
83
- const format = objectFormatByName$1(capability.slice(14));
84
- if (!format) return fail(`unrecognized bundle hash algorithm: ${capability.slice(14)}`);
85
- objectFormat = format;
86
- continue;
87
- }
88
- if (capability.startsWith("filter=")) {
89
- filter = capability.slice(7);
90
- continue;
91
- }
92
- return fail(`unknown capability '${capability}'`);
93
- }
94
- const prereq = text[0] === 45;
95
- if (prereq) text = text.subarray(1);
96
- const hex = objectFormat.hexLength;
97
- let valid = text.length >= hex;
98
- for (let i = 0; valid && i < hex; i++) valid = HEX.test(String.fromCharCode(text[i]));
99
- const rest = text.subarray(hex);
100
- if (valid && rest.length > 0 && !SPACE(rest[0])) valid = false;
101
- if (valid && !prereq && rest.length === 0) valid = false;
102
- if (!valid) return fail(`unrecognized header: ${prereq ? "-" : ""}${decodeGitPath(text)} (${text.length})`);
103
- const id = latin1(text.subarray(0, hex)).toLowerCase();
104
- if (prereq) prerequisites.push({
105
- id,
106
- comment: decodeGitPath(rest.subarray(1)).trim()
107
- });
108
- else references.push({
109
- id,
110
- name: decodeGitPath(rest.subarray(1))
111
- });
112
- }
113
- return {
114
- ok: true,
115
- header: {
116
- version,
117
- objectFormat,
118
- ...filter !== void 0 ? { filter } : {},
119
- prerequisites,
120
- references
121
- },
122
- packOffset: at
123
- };
124
- }
125
- /**
126
- * The header `create_bundle` writes: the signature (v3 with `@object-format=` and, for a
127
- * filtered bundle, `@filter=`), `-<id> <comment>` per prerequisite, `<id> <name>` per ref,
128
- * then the empty line the pack follows.
129
- *
130
- * @example
131
- * ```typescript
132
- * const bytes = encodeBundleHeader({ version: 2, objectFormat: SHA1_OBJECT_FORMAT,
133
- * prerequisites: [], references: [{ id, name: "refs/heads/main" }] });
134
- * ```
135
- */
136
- function encodeBundleHeader(header) {
137
- const parts = [];
138
- const text = (s) => parts.push(encodeGitPath(s));
139
- if (header.version === 2) text(V2_BUNDLE_SIGNATURE);
140
- else {
141
- text(V3_BUNDLE_SIGNATURE);
142
- text(`@object-format=${header.objectFormat.name}\n`);
143
- if (header.filter !== void 0) text(`@filter=${header.filter}\n`);
144
- }
145
- for (const p of header.prerequisites) text(`-${p.id} ${p.comment}\n`);
146
- for (const r of header.references) text(`${r.id} ${r.name}\n`);
147
- text("\n");
148
- let length = 0;
149
- for (const p of parts) length += p.length;
150
- const out = new Uint8Array(length);
151
- let at = 0;
152
- for (const p of parts) {
153
- out.set(p, at);
154
- at += p.length;
155
- }
156
- return out;
157
- }
158
- /**
159
- * bundle.c's `list_refs`: `<id> <name>` per ref, only those named in `names` when any are
160
- * (exact names, as `git bundle list-heads <file> <refname>...` and `unbundle` take them).
161
- * A prerequisite is listed with an empty name (`<id> `), as `git bundle verify` prints it.
162
- */
163
- function listBundleRefs(refs, names = []) {
164
- let out = "";
165
- for (const ref of refs) {
166
- const name = "name" in ref ? ref.name : "";
167
- if (names.length > 0 && !names.includes(name)) continue;
168
- out += `${ref.id} ${name}\n`;
169
- }
170
- return out;
171
- }
172
- function latin1(bytes) {
173
- let s = "";
174
- for (let i = 0; i < bytes.length; i++) s += String.fromCharCode(bytes[i]);
175
- return s;
176
- }
177
- //#endregion
178
- //#region src/commands/bundle/bundle-verify.ts
179
- /**
180
- * bundle.c's reading side without a command: a bundle's bytes read (`read_bundle_header`)
181
- * and checked against a repository (`verify_bundle`), as the bundle commands and the bundle
182
- * transport do.
183
- */
184
- /** The bytes of a {@link BundleInput}, collected. */
185
- async function bundleBytes(input) {
186
- if (input instanceof Uint8Array) return input;
187
- const chunks = [];
188
- let length = 0;
189
- for await (const chunk of input) {
190
- chunks.push(chunk);
191
- length += chunk.length;
192
- }
193
- const out = new Uint8Array(length);
194
- let at = 0;
195
- for (const chunk of chunks) {
196
- out.set(chunk, at);
197
- at += chunk.length;
198
- }
199
- return out;
200
- }
201
- /**
202
- * builtin/bundle.c's `open_bundle` (`read_bundle_header`): the header and the pack, or git's
203
- * `error:` line (the bundle reported as `name`: its path, `<stdin>` for `-`).
204
- */
205
- function openBundle(bytes, name, defaultFormat) {
206
- const parsed = parseBundleHeader(bytes, name, defaultFormat);
207
- if (!parsed.ok) return {
208
- ok: false,
209
- error: `error: ${parsed.error}\n`
210
- };
211
- return {
212
- ok: true,
213
- bundle: {
214
- header: parsed.header,
215
- pack: bytes.subarray(parsed.packOffset)
216
- }
217
- };
218
- }
219
- /**
220
- * bundle.c's `verify_bundle`: every prerequisite must be an object here (each missing one
221
- * on an `error:` line after `Repository lacks these prerequisite commits:`, unless quiet),
222
- * then connected to the refs (`check_connected` of the prerequisites, `--not --all`); with
223
- * `verbose`, what the bundle holds on stdout.
224
- */
225
- async function verifyBundleIn(repository, header, options = {}) {
226
- const objects = historyWithoutLazyFetch(repository.history);
227
- let stderr = "";
228
- let missing = 0;
229
- for (const prerequisite of header.prerequisites) {
230
- if (await objectExists(objects, prerequisite.id)) continue;
231
- missing++;
232
- if (options.quiet) continue;
233
- if (missing === 1) stderr += "error: Repository lacks these prerequisite commits:\n";
234
- stderr += `error: ${prerequisite.id} \n`;
235
- }
236
- if (missing > 0) return {
237
- ok: false,
238
- stdout: "",
239
- stderr
240
- };
241
- let ok = true;
242
- const tips = header.prerequisites.map((p) => p.id);
243
- if (tips.length > 0) {
244
- const facade = createRepositoryFacade({ history: objects });
245
- if (await connectivityErrors(facade, tips, {
246
- known: await repository.refValues(),
247
- shallow: new Set(await repository.shallow())
248
- })) {
249
- ok = false;
250
- stderr += "error: some prerequisite commits exist in the object store, but are not connected to the repository's history\n";
251
- }
252
- }
253
- let stdout = "";
254
- if (options.verbose) {
255
- const refs = header.references;
256
- stdout += refs.length === 1 ? "The bundle contains this ref:\n" : `The bundle contains these ${refs.length} refs:\n`;
257
- stdout += listBundleRefs(refs);
258
- const prereqs = header.prerequisites;
259
- if (prereqs.length === 0) stdout += "The bundle records a complete history.\n";
260
- else {
261
- stdout += prereqs.length === 1 ? "The bundle requires this ref:\n" : `The bundle requires these ${prereqs.length} refs:\n`;
262
- stdout += listBundleRefs(prereqs);
263
- }
264
- stdout += `The bundle uses this hash algorithm: ${header.objectFormat.name}\n`;
265
- if (header.filter !== void 0) stdout += `The bundle uses this filter: ${header.filter}\n`;
266
- }
267
- return {
268
- ok,
269
- stdout,
270
- stderr
271
- };
272
- }
273
- /** git's `parse_object` succeeds: the object is here, whatever its type. */
274
- async function objectExists(history, id) {
275
- const objects = history.objects;
276
- if (objects) return objects.has(id).catch(() => false);
277
- for (const store of [
278
- history.commits,
279
- history.trees,
280
- history.blobs,
281
- history.tags
282
- ]) if (await store.has(id).catch(() => false)) return true;
283
- return false;
284
- }
285
- //#endregion
286
- //#region src/commands/bundle/bundle-transport.ts
287
- /**
288
- * git's bundle transport (transport.c's `bundle_vtable`): a remote URL that is a path to a
289
- * bundle file is read as a repository whose refs are the bundle's and whose only pack is the
290
- * bundle's. Fetch, clone, pull and ls-remote reach it through an upload-pack served in
291
- * process from the bundle: its refs advertised (in git's order: the bundle's refs reversed,
292
- * as `get_refs_from_bundle` prepends each), and any fetch answered with the bundle's pack,
293
- * once the fetching repository has the bundle's prerequisites (`unbundle`'s `verify_bundle`).
294
- */
295
- /**
296
- * A fetch from a bundle the repository lacks the prerequisites of: `verify_bundle`'s lines
297
- * (`git fetch` exits 1; `git clone` adds `fatal: remote transport reported error`, 128).
298
- */
299
- var BundlePrerequisitesError = class extends TransportError$1 {
300
- lines;
301
- constructor(lines) {
302
- super(lines.replace(/\n$/, ""), void 0, { exitCode: 1 });
303
- this.lines = lines;
304
- this.name = "BundlePrerequisitesError";
305
- }
306
- };
307
- /** Bytes per chunk the served pack is cut into. */
308
- const CHUNK = 65536;
309
- /**
310
- * Runs `run` over a connection to an upload-pack serving the bundle (protocol v0). A fetch
311
- * that needs the pack verifies the bundle first: when the repository lacks its prerequisites
312
- * the fetch fails with git's lines (exit 1, as `git fetch` returns).
313
- */
314
- async function withBundleUploadPack(remote, createPair, run) {
315
- const { header, pack } = remote.bundle;
316
- let refused;
317
- const facade = {
318
- objectFormat: header.objectFormat,
319
- importPack: () => Promise.reject(/* @__PURE__ */ new Error("a bundle cannot be written to")),
320
- async *exportPack() {
321
- const verified = await remote.verify();
322
- if (!verified.ok) {
323
- refused = verified.stderr;
324
- throw new Error("bundle prerequisites missing");
325
- }
326
- for (let at = 0; at < pack.length; at += CHUNK) yield pack.subarray(at, at + CHUNK);
327
- },
328
- has: async (oid) => header.references.some((r) => r.id === oid),
329
- async *walkAncestors() {}
330
- };
331
- const [client, server] = createPair();
332
- const serving = serveOverDuplex({
333
- duplex: server,
334
- repository: facade,
335
- refStore: bundleRefStore(header),
336
- service: "git-upload-pack"
337
- }).finally(() => server.close?.());
338
- try {
339
- const connection = await openDuplexConnection(client, { closeDuplex: true });
340
- try {
341
- return await run(connection);
342
- } catch (error) {
343
- if (refused !== void 0) throw new BundlePrerequisitesError(refused);
344
- throw error;
345
- } finally {
346
- await connection.close();
347
- }
348
- } finally {
349
- await client.close?.();
350
- await serving.catch(() => void 0);
351
- }
352
- }
353
- /** The refs a bundle advertises: read-only, in `get_refs_from_bundle`'s (reversed) order. */
354
- function bundleRefStore(header) {
355
- const refs = [...header.references].reverse();
356
- return {
357
- get: async (name) => refs.find((r) => r.name === name)?.id,
358
- update: () => Promise.reject(/* @__PURE__ */ new Error("a bundle cannot be written to")),
359
- listAll: async () => refs.map((r) => [r.name, r.id]),
360
- isRefTip: async (oid) => refs.some((r) => r.id === oid)
361
- };
362
- }
363
- //#endregion
10
+ import { GitNamespaceError, ReceivePackDiedError, createRepositoryFacade, createTransportRefStore, gitNamespacePrefix, openDuplexConnection, openDuplexReceivePackConnection, pushCertificateEnv, serveOverDuplex, serverSettingsFromConfig } from "@statewalker/vcs-transport";
364
11
  //#region src/commands/worktree-prune-command.ts
365
12
  /**
366
13
  * Prune the administrative files of worktrees that are gone.
@@ -1497,6 +1144,106 @@ async function verifyAbsent(worktree, path, tracked, kind, options = {}) {
1497
1144
  return firstPlainError({ [kind]: [path] });
1498
1145
  }
1499
1146
  //#endregion
1147
+ //#region src/commands/served-lazy-fetch.ts
1148
+ /**
1149
+ * The lazy fetch of a served partial clone while upload-pack builds a pack (git's
1150
+ * upload-pack, whose pack-objects reads an absent promisor object through
1151
+ * promisor_remote_get_direct).
1152
+ *
1153
+ * Since git 2.45 (and the 2.43.4 backport) upload-pack sets `GIT_NO_LAZY_FETCH=1` unless its
1154
+ * environment already sets the variable, so by default a pack that needs an absent promisor
1155
+ * object fails: pack-objects prints `warning: lazy fetching disabled; some objects may not be
1156
+ * available` and dies `could not fetch <id> from promisor remote`. Ours does the same unless
1157
+ * lazy fetching is opted in: the operator's `servedRepositoryOf(opened, { lazyFetch })`, or a
1158
+ * local remote's upload-pack when the client's host environment says `GIT_NO_LAZY_FETCH=0`
1159
+ * (git's child inherits it). Then the absent object is fetched from the served repository's
1160
+ * own promisor remotes, through the transports given, and the pack holds it.
1161
+ *
1162
+ * Promisor URLs come from the served repository's configuration, which is repository content:
1163
+ * the fetch never carries static credentials or headers, only a per-URL credential helper.
1164
+ *
1165
+ * @example
1166
+ * ```ts
1167
+ * const served = await servedRepositoryOf(opened, {
1168
+ * lazyFetch: { transports: createDefaultTransports() },
1169
+ * });
1170
+ * ```
1171
+ */
1172
+ /**
1173
+ * The history upload-pack reads for `remote`, as git's upload-pack reads it: a view of its
1174
+ * own whose absent promisor objects are refused with git's warning and death
1175
+ * (`GIT_NO_LAZY_FETCH=1`), or, when `lazyFetch` opts in, fetched from the repository's
1176
+ * promisor remotes through its transports. The store's promisor and fetcher are left as
1177
+ * they are, so receive-pack and every other reader of the store are untouched. A repository
1178
+ * without worktrees or promisor remotes, or without promisor packs unless `lazyFetch` is
1179
+ * given, is read through its view without lazy fetch.
1180
+ *
1181
+ * @example
1182
+ * ```ts
1183
+ * const history = await uploadPackHistory(opened, { transports }, hooks.hostEnvironment);
1184
+ * ```
1185
+ */
1186
+ async function uploadPackHistory(remote, lazyFetch, environment) {
1187
+ const plain = historyWithoutLazyFetch(remote.history);
1188
+ const promisor = (() => {
1189
+ try {
1190
+ return remote.history.objects?.promisor;
1191
+ } catch {
1192
+ return;
1193
+ }
1194
+ })();
1195
+ if (!promisor || !remote.worktrees) return plain;
1196
+ if (!lazyFetch && (await promisor.promisorPacks().catch(() => [])).length === 0) return plain;
1197
+ let view;
1198
+ const workingCopy = await servedWorkingCopy(remote, () => view ?? plain, lazyFetch?.environment ?? environment).catch(() => void 0);
1199
+ if (!workingCopy || !hasPromisorRemote(RemoteConfigStore.from(workingCopy))) return plain;
1200
+ const fetcher = lazyFetch ? createPromisorFetcher(workingCopy, {
1201
+ ...lazyFetch.transports ? { transports: lazyFetch.transports } : {},
1202
+ ...lazyFetch.credentialHelper ? { credentialHelper: lazyFetch.credentialHelper } : {},
1203
+ ...lazyFetch.timeout !== void 0 ? { timeout: lazyFetch.timeout } : {},
1204
+ ...lazyFetch.warningCallback ? { warningCallback: lazyFetch.warningCallback } : {}
1205
+ }) : refusingFetcher(() => view?.objects?.promisor?.warnings);
1206
+ view = historyWithPromisorFetcher(remote.history, fetcher);
1207
+ return view ?? plain;
1208
+ }
1209
+ /**
1210
+ * upload-pack's `GIT_NO_LAZY_FETCH=1`: every read of an absent object still asks (git's
1211
+ * pack-objects reads with `fetch_if_missing`), fetch_objects refuses with its warning (once
1212
+ * per upload-pack process: a refusal of a promisor object is its death), and
1213
+ * promisor_remote_get_direct dies for a promisor object.
1214
+ */
1215
+ function refusingFetcher(warnings) {
1216
+ return {
1217
+ hasPromisorRemote: () => true,
1218
+ invalidate: () => {},
1219
+ fetchIfMissing: () => true,
1220
+ async fetch(ids) {
1221
+ warnings()?.push(LAZY_FETCH_DISABLED_WARNING);
1222
+ return ids;
1223
+ }
1224
+ };
1225
+ }
1226
+ /**
1227
+ * The served repository as a working copy the promisor fetcher reads (its configuration,
1228
+ * remotes, local paths), over the history `history` gives (upload-pack's view: the fetch's
1229
+ * warnings go to its promisor, its objects to the store) and in `environment`.
1230
+ */
1231
+ async function servedWorkingCopy(remote, history, environment) {
1232
+ const worktrees = remote.worktrees;
1233
+ if (!worktrees) return void 0;
1234
+ const base = worktreeAdminWorkingCopy(await worktrees.openAdmin());
1235
+ const own = (target, key) => {
1236
+ const value = Reflect.get(target, key, target);
1237
+ return typeof value === "function" ? value.bind(target) : value;
1238
+ };
1239
+ const config = environment ? new Proxy(base.config, { get: (target, key) => key === "environment" ? environment : own(target, key) }) : base.config;
1240
+ return new Proxy(base, { get: (target, key) => {
1241
+ if (key === "history") return history();
1242
+ if (key === "config") return config;
1243
+ return own(target, key);
1244
+ } });
1245
+ }
1246
+ //#endregion
1500
1247
  //#region src/commands/local-transport.ts
1501
1248
  /**
1502
1249
  * git's local transport: a repository named by a path (or a `file://` URL) is opened through
@@ -1504,6 +1251,21 @@ async function verifyAbsent(worktree, path, tracked, kind, options = {}) {
1504
1251
  * in-memory duplex, where git spawns `git-upload-pack '<path>'`. Which transport a URL takes
1505
1252
  * is decided in `remote-transport.ts` (`resolveRemote`).
1506
1253
  */
1254
+ var local_transport_exports = /* @__PURE__ */ __exportAll({
1255
+ createDuplexPair: () => createDuplexPair,
1256
+ httpBackendEnv: () => httpBackendEnv,
1257
+ openLocalRemote: () => openLocalRemote,
1258
+ pushToDeploy: () => pushToDeploy,
1259
+ quarantineEnv: () => quarantineEnv,
1260
+ receiveFsckSettingsOf: () => receiveFsckSettingsOf,
1261
+ receivePackSettingsOf: () => receivePackSettingsOf,
1262
+ remoteHookSession: () => remoteHookSession,
1263
+ servedMaxTreeDepth: () => servedMaxTreeDepth,
1264
+ servedUseBitmaps: () => servedUseBitmaps,
1265
+ withLocalReceivePack: () => withLocalReceivePack,
1266
+ withLocalUploadPack: () => withLocalUploadPack,
1267
+ withReceiveTransactionHook: () => withReceiveTransactionHook
1268
+ });
1507
1269
  /** The client's lines when the remote end of a local transport died. */
1508
1270
  const COULD_NOT_READ = "fatal: Could not read from remote repository.\n\nPlease make sure you have the correct access rights\nand the repository exists.";
1509
1271
  const NOT_A_REPOSITORY = (path) => `fatal: '${path}' does not appear to be a git repository\n${COULD_NOT_READ}`;
@@ -1618,19 +1380,37 @@ async function openLocalRemote(workingCopy, path) {
1618
1380
  return opened;
1619
1381
  }
1620
1382
  /**
1383
+ * The death of a local upload-pack or receive-pack started under a `GIT_NAMESPACE` git
1384
+ * refuses (`get_git_namespace`'s `bad git namespace path "<ns>"`), as a git 2.5x client shows
1385
+ * it: then its own death, which for a v2 fetch is its ls-refs reader's (`v2`).
1386
+ */
1387
+ function checkLocalNamespace(namespace, v2 = false) {
1388
+ try {
1389
+ gitNamespacePrefix(namespace);
1390
+ } catch (error) {
1391
+ if (error instanceof GitNamespaceError) {
1392
+ const client = v2 ? "fatal: expected flush after ref listing" : COULD_NOT_READ;
1393
+ throw new TransportError$1(`fatal: ${error.message}\n${client}`);
1394
+ }
1395
+ throw error;
1396
+ }
1397
+ }
1398
+ /**
1621
1399
  * Runs `run` over a connection to upload-pack serving a local repository (opened by
1622
1400
  * {@link openLocalRemote}) with protocol v2, git's default `protocol.version` (v0 when the
1623
1401
  * option says 0, v1 when it says 1), as git's local transport runs `git-upload-pack '<path>'`,
1624
1402
  * in process.
1625
1403
  */
1626
1404
  async function withLocalUploadPack(remote, run, options = {}) {
1405
+ checkLocalNamespace(options.namespace, (options.protocolVersion ?? 2) === 2);
1627
1406
  const head = await remote.history.refs.get("HEAD").catch(() => void 0);
1628
1407
  const settings = serverSettingsOf(remote);
1629
1408
  const [client, server] = createDuplexPair();
1409
+ const history = await uploadPackHistory(remote, options.lazyFetch, options.lazyFetch?.environment);
1630
1410
  const serving = (async () => serveOverDuplex({
1631
1411
  duplex: server,
1632
1412
  repository: createRepositoryFacade({
1633
- history: historyWithoutLazyFetch(remote.history),
1413
+ history,
1634
1414
  useBitmaps: servedUseBitmaps(remote),
1635
1415
  sparseFilterPatterns: sparseFilterMatcher,
1636
1416
  maxTreeDepth: servedMaxTreeDepth(remote)
@@ -1649,14 +1429,16 @@ async function withLocalUploadPack(remote, run, options = {}) {
1649
1429
  ...settings.advertiseSID ? { advertiseSID: true } : {},
1650
1430
  ...settings.advertiseObjectInfo ? { advertiseObjectInfo: true } : {},
1651
1431
  ...settings.promisorRemoteInfo !== void 0 ? { promisorRemoteInfo: settings.promisorRemoteInfo } : {},
1652
- ...head && "target" in head ? { currentBranch: head.target } : {}
1432
+ ...options.packObjectsHook ? { packObjectsHook: options.packObjectsHook } : {},
1433
+ ...head && "target" in head ? { currentBranch: head.target } : {},
1434
+ ...options.namespace ? { namespace: options.namespace } : {}
1653
1435
  }))().finally(() => server.close?.());
1654
1436
  try {
1655
1437
  const connection = await openDuplexConnection(client, { closeDuplex: true });
1656
1438
  try {
1657
1439
  return await run(connection);
1658
1440
  } catch (error) {
1659
- throw packFailure(error) ?? error;
1441
+ throw packFailure(error) ?? await packObjectsDeath(error, serving) ?? error;
1660
1442
  } finally {
1661
1443
  await connection.close();
1662
1444
  }
@@ -1666,6 +1448,27 @@ async function withLocalUploadPack(remote, run, options = {}) {
1666
1448
  }
1667
1449
  }
1668
1450
  /**
1451
+ * pack-objects died before the pack's first byte (its stderr already relayed on the
1452
+ * progress band, upload-pack's abort on band 3: `PackObjectsError`): the lines git's local
1453
+ * transport prints after that, upload-pack's own (on the shared stderr: create_pack_file's
1454
+ * error, a failed `uploadpack.packObjectsHook`'s own, then its death), the abort as the client
1455
+ * shows it, and index-pack finding no pack.
1456
+ */
1457
+ async function packObjectsDeath(error, serving) {
1458
+ const abort = "aborting due to possible repository corruption on the remote side.";
1459
+ if (!(error instanceof Error) || error.name !== "ServerError") return void 0;
1460
+ if (!error.message.startsWith(abort)) return void 0;
1461
+ const reported = (await serving.catch(() => void 0))?.error;
1462
+ if (reported === void 0) return void 0;
1463
+ const died = reported.startsWith("fatal: ") ? "error: git upload-pack: git-pack-objects died with error." : `error: ${reported}`;
1464
+ return new TransportError$1([
1465
+ died,
1466
+ `fatal: git upload-pack: ${abort}`,
1467
+ `remote: ${abort}`,
1468
+ "fatal: protocol error: bad pack header"
1469
+ ].join("\n"), void 0, { cause: error });
1470
+ }
1471
+ /**
1669
1472
  * The lines git prints when upload-pack's pack-objects fails on an object it cannot read
1670
1473
  * (upload-pack.c's create_pack_file): its own error and death (upload-pack's stderr, which
1671
1474
  * the local transport shares), the abort message it sends on band 3, then the client's
@@ -1807,6 +1610,7 @@ async function pushToDeploy(worktrees, ref, newOid) {
1807
1610
  * included, is the current branch `receive.denyCurrentBranch` rules on.
1808
1611
  */
1809
1612
  async function withLocalReceivePack(remote, run, hooks, transactionHooks = hooks, options = {}) {
1613
+ checkLocalNamespace(options.namespace);
1810
1614
  try {
1811
1615
  await remote.checkOwnership?.();
1812
1616
  } catch (error) {
@@ -1814,7 +1618,7 @@ async function withLocalReceivePack(remote, run, hooks, transactionHooks = hooks
1814
1618
  throw error;
1815
1619
  }
1816
1620
  const receiveHooks = hooks?.enabled ? scriptReceiveHooks(hooks) : void 0;
1817
- return withReceiveTransactionHook(remote, transactionHooks, () => receiveOver(remote, run, hooks, receiveHooks, options.protocolVersion === 1, options));
1621
+ return withReceiveTransactionHook(remote, options.namespace && transactionHooks ? transactionHooks.withEnv({ GIT_NAMESPACE: options.namespace }) : transactionHooks, () => receiveOver(remote, run, hooks, receiveHooks, options.protocolVersion === 1, options));
1818
1622
  }
1819
1623
  /**
1820
1624
  * The receive-side reference-transaction hooks installed on a ref store, oldest first, and
@@ -1934,6 +1738,7 @@ async function receivePackSettingsOf(remote, hooks, receiveHooks = hooks?.enable
1934
1738
  ...settings.advertiseSID ? { advertiseSID: true } : {},
1935
1739
  ...settings.advertiseAtomic !== void 0 ? { advertiseAtomic: settings.advertiseAtomic } : {},
1936
1740
  ...settings.maxInputSize !== void 0 ? { maxInputSize: settings.maxInputSize } : {},
1741
+ ...host.maxObjectSize !== void 0 ? { maxObjectSize: host.maxObjectSize } : {},
1937
1742
  ...settings.certNonceSeed !== void 0 ? { certNonceSeed: settings.certNonceSeed } : {},
1938
1743
  ...settings.certNonceSlop !== void 0 ? { certNonceSlop: settings.certNonceSlop } : {},
1939
1744
  pushCertificates: { verify: pushCertVerifierOf(remote, hooks) },
@@ -2004,7 +1809,7 @@ function afterPushOf(remote, hooks) {
2004
1809
  const result = await new GarbageCollectCommand(workingCopy).setAuto(true).setQuiet(true).call();
2005
1810
  lines = [...result.errors ?? [], ...result.warnings ?? []];
2006
1811
  } else {
2007
- const { MaintenanceRunCommand } = await import("./maintenance-run-command-CoJFKr2p.js").then((n) => n.r);
1812
+ const { MaintenanceRunCommand } = await import("./maintenance-run-command-DZFnbnbo.js").then((n) => n.r);
2008
1813
  lines = (await new MaintenanceRunCommand(workingCopy).setAuto(true).setQuiet(true).call()).stderr.split("\n").filter((l) => l.length > 0);
2009
1814
  }
2010
1815
  if (lines.length > 0) await ctx.message(`${lines.join("\n")}\n`);
@@ -2051,7 +1856,8 @@ async function receiveOver(remote, run, hooks, receiveHooks, version1, options =
2051
1856
  }),
2052
1857
  refStore: createTransportRefStore(remote.history.refs),
2053
1858
  service: "git-receive-pack",
2054
- ...version1 ? { announceVersion1: true } : {}
1859
+ ...version1 ? { announceVersion1: true } : {},
1860
+ ...options.namespace ? { namespace: options.namespace } : {}
2055
1861
  }).finally(() => server.close?.());
2056
1862
  const died = async (cause) => {
2057
1863
  await client.close?.();
@@ -2204,8 +2010,19 @@ function httpBackendEnv(hooks, client) {
2204
2010
  if (committer.email === void 0) env.GIT_COMMITTER_EMAIL = `${user}@http.${addr}`;
2205
2011
  return env;
2206
2012
  }
2207
- /** {@link httpBackendEnv} of a push its hook context describes (HTTP: it has a request). */
2013
+ /**
2014
+ * The variables receive-pack's hooks inherit from it for a push its hook context describes:
2015
+ * `GIT_NAMESPACE` when the push is served in a namespace, and {@link httpBackendEnv} for one
2016
+ * over HTTP (it has a request).
2017
+ */
2208
2018
  function hookClientEnv(hooks, ctx) {
2019
+ return {
2020
+ ...ctx?.namespace ? { GIT_NAMESPACE: ctx.namespace } : {},
2021
+ ...httpEnvOf(hooks, ctx)
2022
+ };
2023
+ }
2024
+ /** {@link httpBackendEnv} of a push its hook context describes (HTTP: it has a request). */
2025
+ function httpEnvOf(hooks, ctx) {
2209
2026
  return httpBackendEnv(hooks, ctx?.request ? {
2210
2027
  http: true,
2211
2028
  ...ctx.remoteUser !== void 0 ? { remoteUser: ctx.remoteUser } : {},
@@ -2321,320 +2138,4 @@ function scriptReceiveHooks(hooks) {
2321
2138
  };
2322
2139
  }
2323
2140
  //#endregion
2324
- //#region src/commands/remote-transport.ts
2325
- /**
2326
- * How a remote command reaches a remote, as git's `transport_get` and `git_connect` decide:
2327
- * the URL (already rewritten by `url.<base>.insteadOf`, see `RemoteConfigStore`) is checked
2328
- * against `protocol.allow`; a path or `file://` URL is git's local transport (served in
2329
- * process, see `local-transport.ts`); anything else goes to the connector the transport
2330
- * registry names for it (smart HTTP by default).
2331
- */
2332
- var remote_transport_exports = /* @__PURE__ */ __exportAll({
2333
- bundleRemoteOf: () => bundleRemoteOf,
2334
- checkTransportAllowed: () => checkTransportAllowed,
2335
- httpSessionSettings: () => httpSessionSettings,
2336
- isTransportAllowed: () => isTransportAllowed,
2337
- openBundleRemote: () => openBundleRemote,
2338
- openResolvedRemote: () => openResolvedRemote,
2339
- prepareRemote: () => prepareRemote,
2340
- protocolVersionOf: () => protocolVersionOf,
2341
- remoteContextOf: () => remoteContextOf,
2342
- resolveRemote: () => resolveRemote,
2343
- withRemoteReceivePack: () => withRemoteReceivePack,
2344
- withRemoteSession: () => withRemoteSession,
2345
- withRemoteUploadPack: () => withRemoteUploadPack
2346
- });
2347
- const NO_PATH = "fatal: no path specified; see 'git help pull' for valid url syntax";
2348
- /** transport.c's `parse_protocol_config`. */
2349
- function parsePolicy(key, value) {
2350
- const lower = value.toLowerCase();
2351
- if (lower === "always" || lower === "never" || lower === "user") return lower;
2352
- throw new InvalidConfigError(key, `fatal: unknown value for config '${key}': ${value}`);
2353
- }
2354
- /**
2355
- * transport.c's `is_transport_allowed`: `GIT_ALLOW_PROTOCOL` when set (the only transports
2356
- * allowed); else `protocol.<type>.allow`, then `protocol.allow`, then git's defaults (http,
2357
- * https, git and ssh always; ext never; any other, `file` included, only when
2358
- * `GIT_PROTOCOL_FROM_USER` is not false).
2359
- *
2360
- * @example
2361
- * ```ts
2362
- * isTransportAllowed("ext", store); // false
2363
- * isTransportAllowed("file", store, { protocolFromUser: false } as GitHostEnvironment); // false
2364
- * ```
2365
- */
2366
- function isTransportAllowed(type, config, environment) {
2367
- if (environment?.allowProtocol !== void 0) return environment.allowProtocol.split(":").includes(type);
2368
- const key = `protocol.${type}.allow`;
2369
- const own = config.value(key);
2370
- const fallback = config.value("protocol.allow");
2371
- let policy;
2372
- if (own !== void 0) policy = parsePolicy(key, own);
2373
- else if (fallback !== void 0) policy = parsePolicy("protocol.allow", fallback);
2374
- else if ([
2375
- "http",
2376
- "https",
2377
- "git",
2378
- "ssh"
2379
- ].includes(type)) policy = "always";
2380
- else if (type === "ext") policy = "never";
2381
- else policy = "user";
2382
- if (policy === "user") return environment?.protocolFromUser ?? true;
2383
- return policy === "always";
2384
- }
2385
- /** transport.c's `transport_check_allowed`: git's "transport '<type>' not allowed". */
2386
- function checkTransportAllowed(type, config, environment) {
2387
- if (!isTransportAllowed(type, config, environment)) throw new TransportError$1(`fatal: transport '${type}' not allowed`);
2388
- }
2389
- /**
2390
- * `protocol.version` (git's `get_protocol_version_config`): 0, 1 or 2, default 2; any other
2391
- * value is git's "unknown value for config 'protocol.version'".
2392
- */
2393
- function protocolVersionOf(config) {
2394
- const value = config.value("protocol.version");
2395
- if (value === void 0) return 2;
2396
- if (value === "0" || value === "1" || value === "2") return Number(value);
2397
- throw new InvalidConfigError("protocol.version", `fatal: unknown value for config 'protocol.version': ${value}`);
2398
- }
2399
- /**
2400
- * Resolves a remote URL (already rewritten by `insteadOf`) to its transport, in git's order
2401
- * (transport_get, then git_connect): a `<helper>::<address>` URL goes to the connector for
2402
- * the helper; `rsync:` is refused; a path or `file://` URL is the local transport (its path
2403
- * checked first, then `protocol.file.allow`); `ssh`/`git` URLs (path, then
2404
- * `protocol.<scheme>.allow`) and any other `<scheme>://` (`protocol.<scheme>.allow`) go to
2405
- * the registry's connector. Without one, git's words: "unable to find remote helper" where
2406
- * git would run a remote helper, ours for ssh and git:// (git would connect directly).
2407
- *
2408
- * @throws TransportError git's lines (exit 128)
2409
- */
2410
- function resolveRemote(url, context) {
2411
- const { config, environment, transports } = context;
2412
- const parsed = parseGitUrl(url);
2413
- const viaConnector = (type) => {
2414
- checkTransportAllowed(type, config, environment);
2415
- const connector = transports.resolve(parsed);
2416
- return connector ? {
2417
- kind: "connector",
2418
- url,
2419
- parsed,
2420
- connector
2421
- } : void 0;
2422
- };
2423
- const helperMissing = (helper) => new TransportError$1(`fatal: unable to find remote helper for '${helper}'`);
2424
- if (parsed.address !== void 0) return viaConnector(parsed.scheme) ?? throwError(helperMissing(parsed.scheme));
2425
- if (url.startsWith("rsync:")) throw new TransportError$1("fatal: git-over-rsync is no longer supported");
2426
- if (!(!isGitUrl(url) || /^(?:file|git|ssh|git\+ssh|ssh\+git):\/\//.test(url) || url === "")) {
2427
- const scheme = url.slice(0, url.indexOf(":"));
2428
- return viaConnector(scheme) ?? throwError(helperMissing(scheme));
2429
- }
2430
- if (!parsed.path && !parsed.scpLike) throw new TransportError$1(NO_PATH);
2431
- if (parsed.scheme === "ssh" || parsed.local) checkNotAnOption("pathname", parsed.path);
2432
- if (parsed.scheme === "file") {
2433
- checkTransportAllowed("file", config, environment);
2434
- return {
2435
- kind: "local",
2436
- url,
2437
- path: parsed.path
2438
- };
2439
- }
2440
- if (parsed.scheme === "ssh") {
2441
- checkTransportAllowed("ssh", config, environment);
2442
- checkNotAnOption("hostname", `${parsed.user !== void 0 ? `${parsed.user}@` : ""}${parsed.host ?? ""}`);
2443
- }
2444
- return viaConnector(parsed.scheme) ?? throwError(new TransportError$1(`fatal: cannot connect to '${url}': only http(s) and local repositories are reachable here`));
2445
- }
2446
- /**
2447
- * connect.c's `looks_like_command_line_option` checks: git's "strange hostname '<host>'
2448
- * blocked" (and pathname), so a remote URL cannot smuggle an option into the command git
2449
- * runs (`ssh -oProxyCommand=...`).
2450
- *
2451
- * @throws TransportError git's line (exit 128)
2452
- */
2453
- function checkNotAnOption(what, value) {
2454
- if (value.startsWith("-")) throw new TransportError$1(`fatal: strange ${what} '${value}' blocked`);
2455
- }
2456
- function throwError(error) {
2457
- throw error;
2458
- }
2459
- /**
2460
- * {@link resolveRemote}, then a local remote's repository opened (git's "does not appear to
2461
- * be a git repository" when it cannot be).
2462
- */
2463
- async function prepareRemote(workingCopy, url, transports) {
2464
- return openResolvedRemote(workingCopy, resolveRemote(url, remoteContextOf(workingCopy, transports)));
2465
- }
2466
- /** A resolved remote with its local repository opened ({@link prepareRemote}'s second half). */
2467
- async function openResolvedRemote(workingCopy, resolved) {
2468
- if (resolved.kind !== "local") return resolved;
2469
- const bundle = await openBundleRemote(workingCopy, resolved.url, resolved.path);
2470
- if (bundle) return {
2471
- kind: "bundle",
2472
- url: resolved.url,
2473
- path: resolved.path,
2474
- remote: bundle
2475
- };
2476
- return {
2477
- ...resolved,
2478
- repository: await openLocalRemote(workingCopy, resolved.path)
2479
- };
2480
- }
2481
- /**
2482
- * transport_get's `url_is_local_not_ssh(url) && is_file(url) && is_bundle(url, 1)`: a path
2483
- * (not a `file://` URL) to a regular file whose header reads as a bundle's, with what checks
2484
- * it against `workingCopy` (the repository fetching); undefined for anything else.
2485
- */
2486
- async function openBundleRemote(workingCopy, url, path) {
2487
- if (/^file:/i.test(url)) return void 0;
2488
- const bytes = await repositoryPlaceOf(workingCopy)?.readLocalFile?.(path).catch(() => void 0);
2489
- if (!bytes) return void 0;
2490
- return bundleRemoteOf(workingCopy, bytes, path);
2491
- }
2492
- /**
2493
- * A bundle's bytes as a remote of `workingCopy` (the repository fetching): undefined when
2494
- * they do not read as a bundle. `name` is how git reports it (its path as given).
2495
- */
2496
- function bundleRemoteOf(workingCopy, bytes, name) {
2497
- const opened = openBundle(bytes, name);
2498
- if (!opened.ok) return void 0;
2499
- const history = workingCopy.history;
2500
- return {
2501
- bundle: opened.bundle,
2502
- verify: () => verifyBundleIn({
2503
- history,
2504
- refValues: () => refValuesOf(history.refs),
2505
- shallow: async () => await history.refs.getShallow?.().catch(() => void 0) ?? []
2506
- }, opened.bundle.header)
2507
- };
2508
- }
2509
- /** Every ref's value and HEAD's (what `rev-list --all` starts from). */
2510
- async function refValuesOf(refs) {
2511
- const out = /* @__PURE__ */ new Set();
2512
- for await (const ref of refs.list()) {
2513
- const id = "objectId" in ref && ref.objectId ? ref.objectId : (await refs.resolve(ref.name).catch(() => void 0))?.objectId;
2514
- if (id) out.add(id);
2515
- }
2516
- const head = (await refs.resolve("HEAD").catch(() => void 0))?.objectId;
2517
- if (head) out.add(head);
2518
- return [...out];
2519
- }
2520
- /** The resolution context of a working copy: its configuration and host environment. */
2521
- function remoteContextOf(workingCopy, transports) {
2522
- const environment = hostEnvironmentOf(workingCopy);
2523
- return {
2524
- config: RemoteConfigStore.from(workingCopy),
2525
- ...environment ? { environment } : {},
2526
- transports
2527
- };
2528
- }
2529
- /**
2530
- * The dumb-HTTP settings a session takes from the configuration and the environment
2531
- * (`http.followRedirects` and the other `http.*` keys come with `httpSettings`): which
2532
- * alternates a dumb fetch may use (http-walker's `is_transport_allowed(<scheme>, 0)`: as a
2533
- * transport not from the user) and `$GIT_SMART_HTTP`.
2534
- */
2535
- function httpSessionSettings(workingCopy) {
2536
- const config = RemoteConfigStore.from(workingCopy);
2537
- const environment = hostEnvironmentOf(workingCopy);
2538
- const notFromUser = {
2539
- ...environment,
2540
- protocolFromUser: false
2541
- };
2542
- return {
2543
- alternateAllowed: (scheme) => isTransportAllowed(scheme, config, notFromUser),
2544
- ...environment?.smartHttp === false ? { smartHttp: false } : {}
2545
- };
2546
- }
2547
- function connectRequest(remote, service, options) {
2548
- return {
2549
- url: remote.parsed,
2550
- service,
2551
- protocolVersion: protocolVersionFor(service, options.protocolVersion),
2552
- ...options.program !== void 0 ? { program: options.program } : {},
2553
- ...options.credentials ? { credentials: options.credentials } : {},
2554
- ...options.headers ? { headers: options.headers } : {},
2555
- ...options.timeout !== void 0 ? { timeout: options.timeout } : {},
2556
- ...options.signal ? { signal: options.signal } : {},
2557
- ...options.httpSettings ? { http: options.httpSettings(remote.url) } : {},
2558
- ...options.credentialHelper ? { credentialHelper: options.credentialHelper } : {}
2559
- };
2560
- }
2561
- /**
2562
- * A native session whose stream closes once: the connection opened over it closes the stream
2563
- * (`closeDuplex`), and {@link withRemoteSession} closes it again for a `run` that opened none
2564
- * or failed before; the second close does nothing.
2565
- */
2566
- function closingOnce(session) {
2567
- if (session.kind !== "native") return session;
2568
- const inner = session.duplex;
2569
- let closing;
2570
- const duplex = {
2571
- [Symbol.asyncIterator]: () => inner[Symbol.asyncIterator](),
2572
- write: (data) => inner.write(data),
2573
- ...inner.end ? { end: () => inner.end?.() ?? Promise.resolve() } : {},
2574
- close: () => {
2575
- closing ??= inner.close?.() ?? Promise.resolve();
2576
- return closing;
2577
- }
2578
- };
2579
- return {
2580
- ...session,
2581
- duplex
2582
- };
2583
- }
2584
- /**
2585
- * Runs `run` over a session the remote's connector opens for `service` (the request's
2586
- * protocol version as git_connect asks for it: v0 for receive-pack when v2 is configured); a
2587
- * native session's stream is closed afterwards, once, whether or not `run` closed it.
2588
- */
2589
- async function withRemoteSession(remote, service, options, run) {
2590
- const request = connectRequest(remote, service, options);
2591
- const session = closingOnce(await remote.connector.connect(request));
2592
- try {
2593
- return await run(session, request);
2594
- } finally {
2595
- if (session.kind === "native") await session.duplex.close?.().catch(() => void 0);
2596
- }
2597
- }
2598
- /**
2599
- * Runs `run` over a connection to upload-pack of a remote: in process for a local one
2600
- * (`withLocalUploadPack`, protocol v2 unless `protocol.version` says otherwise), else over
2601
- * the session its connector opens (`openUploadPack`).
2602
- */
2603
- async function withRemoteUploadPack(remote, options, run) {
2604
- if (remote.kind === "local") return withLocalUploadPack(remote.repository, run, { protocolVersion: options.protocolVersion });
2605
- if (remote.kind === "bundle") return withBundleUploadPack(remote.remote, createDuplexPair, run);
2606
- return withRemoteSession(remote, "git-upload-pack", options, async (session, request) => {
2607
- const connection = await openUploadPack(session, request, {
2608
- ...options.gzipRequests !== void 0 ? { gzipRequests: options.gzipRequests } : {},
2609
- ...options.alternateAllowed ? { alternateAllowed: options.alternateAllowed } : {},
2610
- ...options.smartHttp === false ? { smartHttp: false } : {}
2611
- });
2612
- try {
2613
- return await run(connection);
2614
- } finally {
2615
- await connection.close();
2616
- }
2617
- });
2618
- }
2619
- /**
2620
- * Runs `run` over a connection to receive-pack of a remote: in process for a local one
2621
- * (`withLocalReceivePack`, with the remote repository's hooks), else over the session its
2622
- * connector opens (`openReceivePack`).
2623
- */
2624
- async function withRemoteReceivePack(remote, options, run, hooks, transactionHooks, local = {}) {
2625
- if (remote.kind === "bundle") throw new TransportError$1(`error: failed to push some refs to '${remote.url}'`, void 0, { exitCode: 1 });
2626
- if (remote.kind === "local") return withLocalReceivePack(remote.repository, run, hooks, transactionHooks, {
2627
- protocolVersion: options.protocolVersion,
2628
- ...local
2629
- });
2630
- return withRemoteSession(remote, "git-receive-pack", options, async (session, request) => {
2631
- const connection = await openReceivePack(session, request, { ...options.streamRequestBody !== void 0 ? { streamRequestBody: options.streamRequestBody } : {} });
2632
- try {
2633
- return await run(connection);
2634
- } finally {
2635
- await connection.close();
2636
- }
2637
- });
2638
- }
2639
- //#endregion
2640
- export { V3_BUNDLE_SIGNATURE as A, WorktreePruneCommand as C, openBundle as D, bundleBytes as E, listBundleRefs as M, parseBundleHeader as N, verifyBundleIn as O, GarbageCollectCommand as S, withBundleUploadPack as T, remoteHookSession as _, protocolVersionOf as a, withReceiveTransactionHook as b, resolveRemote as c, withRemoteUploadPack as d, createDuplexPair as f, receivePackSettingsOf as g, receiveFsckSettingsOf as h, prepareRemote as i, encodeBundleHeader as j, V2_BUNDLE_SIGNATURE as k, withRemoteReceivePack as l, quarantineEnv as m, httpSessionSettings as n, remoteContextOf as o, httpBackendEnv as p, openResolvedRemote as r, remote_transport_exports as s, bundleRemoteOf as t, withRemoteSession as u, servedMaxTreeDepth as v, BundlePrerequisitesError as w, ReadTreeCommand as x, servedUseBitmaps as y };
2141
+ export { WorktreePruneCommand as _, quarantineEnv as a, remoteHookSession as c, withLocalReceivePack as d, withLocalUploadPack as f, GarbageCollectCommand as g, ReadTreeCommand as h, openLocalRemote as i, servedMaxTreeDepth as l, uploadPackHistory as m, httpBackendEnv as n, receiveFsckSettingsOf as o, withReceiveTransactionHook as p, local_transport_exports as r, receivePackSettingsOf as s, createDuplexPair as t, servedUseBitmaps as u };