@statewalker/vcs-commands 0.7.0 → 0.9.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 (568) hide show
  1. package/dist/commands/add-command.d.ts +70 -0
  2. package/dist/commands/add-command.d.ts.map +1 -1
  3. package/dist/commands/add-patch/add-patch.d.ts +7 -0
  4. package/dist/commands/add-patch/add-patch.d.ts.map +1 -1
  5. package/dist/commands/add-patch/patch-backend.d.ts.map +1 -1
  6. package/dist/commands/am/am-command.d.ts +102 -1
  7. package/dist/commands/am/am-command.d.ts.map +1 -1
  8. package/dist/commands/am/index.d.ts +1 -0
  9. package/dist/commands/am/index.d.ts.map +1 -1
  10. package/dist/commands/am/mailsplit.d.ts +88 -0
  11. package/dist/commands/am/mailsplit.d.ts.map +1 -0
  12. package/dist/commands/apply/apply-command.d.ts +2 -0
  13. package/dist/commands/apply/apply-command.d.ts.map +1 -1
  14. package/dist/commands/apply/apply-engine.d.ts.map +1 -1
  15. package/dist/commands/apply/apply-parse.d.ts +7 -0
  16. package/dist/commands/apply/apply-parse.d.ts.map +1 -1
  17. package/dist/commands/apply/index.d.ts +1 -1
  18. package/dist/commands/apply/index.d.ts.map +1 -1
  19. package/dist/commands/bisect/bisect-command.d.ts +2 -0
  20. package/dist/commands/bisect/bisect-command.d.ts.map +1 -1
  21. package/dist/commands/blame-command.d.ts +303 -8
  22. package/dist/commands/blame-command.d.ts.map +1 -1
  23. package/dist/commands/blame-ignore.d.ts +48 -0
  24. package/dist/commands/blame-ignore.d.ts.map +1 -0
  25. package/dist/commands/branch-command.d.ts +148 -18
  26. package/dist/commands/branch-command.d.ts.map +1 -1
  27. package/dist/commands/branch-info-command.d.ts +55 -0
  28. package/dist/commands/branch-info-command.d.ts.map +1 -0
  29. package/dist/commands/branch-tracking.d.ts +106 -17
  30. package/dist/commands/branch-tracking.d.ts.map +1 -1
  31. package/dist/commands/branch-upstream-command.d.ts +83 -0
  32. package/dist/commands/branch-upstream-command.d.ts.map +1 -0
  33. package/dist/commands/check-mailmap-command.d.ts +49 -0
  34. package/dist/commands/check-mailmap-command.d.ts.map +1 -0
  35. package/dist/commands/checkout-command.d.ts +26 -3
  36. package/dist/commands/checkout-command.d.ts.map +1 -1
  37. package/dist/commands/checkout-paths.d.ts +4 -0
  38. package/dist/commands/checkout-paths.d.ts.map +1 -1
  39. package/dist/commands/cherry-command.d.ts +61 -0
  40. package/dist/commands/cherry-command.d.ts.map +1 -0
  41. package/dist/commands/cherry-pick-command.d.ts +82 -1
  42. package/dist/commands/cherry-pick-command.d.ts.map +1 -1
  43. package/dist/commands/clean-command.d.ts +44 -0
  44. package/dist/commands/clean-command.d.ts.map +1 -1
  45. package/dist/commands/clean-interactive.d.ts +56 -0
  46. package/dist/commands/clean-interactive.d.ts.map +1 -0
  47. package/dist/commands/clone-command.d.ts +116 -2
  48. package/dist/commands/clone-command.d.ts.map +1 -1
  49. package/dist/commands/commit-command.d.ts +239 -5
  50. package/dist/commands/commit-command.d.ts.map +1 -1
  51. package/dist/commands/commit-reuse.d.ts +33 -0
  52. package/dist/commands/commit-reuse.d.ts.map +1 -0
  53. package/dist/commands/config-command.d.ts +236 -0
  54. package/dist/commands/config-command.d.ts.map +1 -0
  55. package/dist/commands/config-value-types.d.ts +91 -0
  56. package/dist/commands/config-value-types.d.ts.map +1 -0
  57. package/dist/commands/core-config.d.ts +20 -0
  58. package/dist/commands/core-config.d.ts.map +1 -1
  59. package/dist/commands/describe-command.d.ts +71 -64
  60. package/dist/commands/describe-command.d.ts.map +1 -1
  61. package/dist/commands/diff-color-config.d.ts +73 -0
  62. package/dist/commands/diff-color-config.d.ts.map +1 -0
  63. package/dist/commands/diff-command.d.ts +369 -10
  64. package/dist/commands/diff-command.d.ts.map +1 -1
  65. package/dist/commands/fetch-command.d.ts +80 -0
  66. package/dist/commands/fetch-command.d.ts.map +1 -1
  67. package/dist/commands/fetch-multiple-command.d.ts +193 -0
  68. package/dist/commands/fetch-multiple-command.d.ts.map +1 -0
  69. package/dist/commands/fmt-merge-msg-command.d.ts +124 -0
  70. package/dist/commands/fmt-merge-msg-command.d.ts.map +1 -0
  71. package/dist/commands/fork-point.d.ts +38 -0
  72. package/dist/commands/fork-point.d.ts.map +1 -0
  73. package/dist/commands/format-patch-command.d.ts +69 -3
  74. package/dist/commands/format-patch-command.d.ts.map +1 -1
  75. package/dist/commands/fsck/fetch-fsck.d.ts +51 -0
  76. package/dist/commands/fsck/fetch-fsck.d.ts.map +1 -1
  77. package/dist/commands/gc-command.d.ts +8 -0
  78. package/dist/commands/gc-command.d.ts.map +1 -1
  79. package/dist/commands/git-describe.d.ts +81 -4
  80. package/dist/commands/git-describe.d.ts.map +1 -1
  81. package/dist/commands/git-hooks.d.ts +50 -1
  82. package/dist/commands/git-hooks.d.ts.map +1 -1
  83. package/dist/commands/grep/grep-command.d.ts +210 -0
  84. package/dist/commands/grep/grep-command.d.ts.map +1 -0
  85. package/dist/commands/grep/grep-engine.d.ts +218 -0
  86. package/dist/commands/grep/grep-engine.d.ts.map +1 -0
  87. package/dist/commands/grep/index.d.ts +3 -0
  88. package/dist/commands/grep/index.d.ts.map +1 -0
  89. package/dist/commands/index-adder.d.ts +13 -2
  90. package/dist/commands/index-adder.d.ts.map +1 -1
  91. package/dist/commands/index.d.ts +38 -0
  92. package/dist/commands/index.d.ts.map +1 -1
  93. package/dist/commands/index.js +5 -3
  94. package/dist/commands/init-command.d.ts +89 -0
  95. package/dist/commands/init-command.d.ts.map +1 -1
  96. package/dist/commands/interpret-trailers-command.d.ts +90 -0
  97. package/dist/commands/interpret-trailers-command.d.ts.map +1 -0
  98. package/dist/commands/line-log.d.ts +161 -0
  99. package/dist/commands/line-log.d.ts.map +1 -0
  100. package/dist/commands/local-transport.d.ts +36 -5
  101. package/dist/commands/local-transport.d.ts.map +1 -1
  102. package/dist/commands/log-command.d.ts +527 -13
  103. package/dist/commands/log-command.d.ts.map +1 -1
  104. package/dist/commands/log-graph.d.ts +30 -3
  105. package/dist/commands/log-graph.d.ts.map +1 -1
  106. package/dist/commands/log-output.d.ts +199 -6
  107. package/dist/commands/log-output.d.ts.map +1 -1
  108. package/dist/commands/ls-remote-command.d.ts +2 -0
  109. package/dist/commands/ls-remote-command.d.ts.map +1 -1
  110. package/dist/commands/mailmap.d.ts +53 -0
  111. package/dist/commands/mailmap.d.ts.map +1 -1
  112. package/dist/commands/merge-base-command.d.ts +60 -0
  113. package/dist/commands/merge-base-command.d.ts.map +1 -0
  114. package/dist/commands/merge-bases.d.ts +23 -0
  115. package/dist/commands/merge-bases.d.ts.map +1 -1
  116. package/dist/commands/merge-command.d.ts +147 -10
  117. package/dist/commands/merge-command.d.ts.map +1 -1
  118. package/dist/commands/merge-drivers.d.ts +2 -0
  119. package/dist/commands/merge-drivers.d.ts.map +1 -1
  120. package/dist/commands/merge-strategy-options.d.ts +69 -0
  121. package/dist/commands/merge-strategy-options.d.ts.map +1 -0
  122. package/dist/commands/merge-support.d.ts +10 -0
  123. package/dist/commands/merge-support.d.ts.map +1 -1
  124. package/dist/commands/message-cleanup.d.ts +2 -0
  125. package/dist/commands/message-cleanup.d.ts.map +1 -1
  126. package/dist/commands/mv-command.d.ts +4 -0
  127. package/dist/commands/mv-command.d.ts.map +1 -1
  128. package/dist/commands/name-rev-command.d.ts +65 -0
  129. package/dist/commands/name-rev-command.d.ts.map +1 -0
  130. package/dist/commands/name-rev.d.ts +136 -0
  131. package/dist/commands/name-rev.d.ts.map +1 -0
  132. package/dist/commands/notes-command.d.ts.map +1 -1
  133. package/dist/commands/octopus-merge.d.ts +26 -1
  134. package/dist/commands/octopus-merge.d.ts.map +1 -1
  135. package/dist/commands/ort-merge.d.ts +16 -0
  136. package/dist/commands/ort-merge.d.ts.map +1 -1
  137. package/dist/commands/ort-recursive.d.ts.map +1 -1
  138. package/dist/commands/patch-id.d.ts +58 -0
  139. package/dist/commands/patch-id.d.ts.map +1 -1
  140. package/dist/commands/pathspec-file.d.ts +39 -0
  141. package/dist/commands/pathspec-file.d.ts.map +1 -0
  142. package/dist/commands/pathspec.d.ts +3 -0
  143. package/dist/commands/pathspec.d.ts.map +1 -1
  144. package/dist/commands/pretty-format.d.ts +43 -3
  145. package/dist/commands/pretty-format.d.ts.map +1 -1
  146. package/dist/commands/promisor-remote.d.ts.map +1 -1
  147. package/dist/commands/pull-command.d.ts +186 -32
  148. package/dist/commands/pull-command.d.ts.map +1 -1
  149. package/dist/commands/push-command.d.ts +225 -9
  150. package/dist/commands/push-command.d.ts.map +1 -1
  151. package/dist/commands/range-diff/index.d.ts +4 -0
  152. package/dist/commands/range-diff/index.d.ts.map +1 -0
  153. package/dist/commands/range-diff/linear-assignment.d.ts +27 -0
  154. package/dist/commands/range-diff/linear-assignment.d.ts.map +1 -0
  155. package/dist/commands/range-diff/range-diff-command.d.ts +121 -0
  156. package/dist/commands/range-diff/range-diff-command.d.ts.map +1 -0
  157. package/dist/commands/range-diff/range-diff.d.ts +106 -0
  158. package/dist/commands/range-diff/range-diff.d.ts.map +1 -0
  159. package/dist/commands/read-tree-command.d.ts +20 -0
  160. package/dist/commands/read-tree-command.d.ts.map +1 -1
  161. package/dist/commands/rebase-command.d.ts +189 -8
  162. package/dist/commands/rebase-command.d.ts.map +1 -1
  163. package/dist/commands/ref-filter/for-each-ref-command.d.ts +121 -0
  164. package/dist/commands/ref-filter/for-each-ref-command.d.ts.map +1 -0
  165. package/dist/commands/ref-filter/index.d.ts +8 -0
  166. package/dist/commands/ref-filter/index.d.ts.map +1 -0
  167. package/dist/commands/ref-filter/ref-atoms.d.ts +88 -0
  168. package/dist/commands/ref-filter/ref-atoms.d.ts.map +1 -0
  169. package/dist/commands/ref-filter/ref-filter.d.ts +178 -0
  170. package/dist/commands/ref-filter/ref-filter.d.ts.map +1 -0
  171. package/dist/commands/ref-filter/ref-format.d.ts +222 -0
  172. package/dist/commands/ref-filter/ref-format.d.ts.map +1 -0
  173. package/dist/commands/ref-filter/ref-listing-command.d.ts +56 -0
  174. package/dist/commands/ref-filter/ref-listing-command.d.ts.map +1 -0
  175. package/dist/commands/ref-filter/ref-quote.d.ts +20 -0
  176. package/dist/commands/ref-filter/ref-quote.d.ts.map +1 -0
  177. package/dist/commands/ref-filter/version-compare.d.ts +20 -0
  178. package/dist/commands/ref-filter/version-compare.d.ts.map +1 -0
  179. package/dist/commands/reflog-command.d.ts +120 -0
  180. package/dist/commands/reflog-command.d.ts.map +1 -1
  181. package/dist/commands/reflog-walk.d.ts +72 -0
  182. package/dist/commands/reflog-walk.d.ts.map +1 -0
  183. package/dist/commands/remerge-diff.d.ts +59 -0
  184. package/dist/commands/remerge-diff.d.ts.map +1 -0
  185. package/dist/commands/remote-command.d.ts +179 -29
  186. package/dist/commands/remote-command.d.ts.map +1 -1
  187. package/dist/commands/remote-show-command.d.ts +204 -0
  188. package/dist/commands/remote-show-command.d.ts.map +1 -0
  189. package/dist/commands/remote-transport.d.ts +7 -1
  190. package/dist/commands/remote-transport.d.ts.map +1 -1
  191. package/dist/commands/reset-command.d.ts +21 -4
  192. package/dist/commands/reset-command.d.ts.map +1 -1
  193. package/dist/commands/restore-command.d.ts +9 -3
  194. package/dist/commands/restore-command.d.ts.map +1 -1
  195. package/dist/commands/rev-filter/commit-filter.d.ts +95 -0
  196. package/dist/commands/rev-filter/commit-filter.d.ts.map +1 -0
  197. package/dist/commands/rev-filter/commit-grep.d.ts +91 -0
  198. package/dist/commands/rev-filter/commit-grep.d.ts.map +1 -0
  199. package/dist/commands/rev-filter/index.d.ts +3 -0
  200. package/dist/commands/rev-filter/index.d.ts.map +1 -0
  201. package/dist/commands/rev-list-command.d.ts +226 -2
  202. package/dist/commands/rev-list-command.d.ts.map +1 -1
  203. package/dist/commands/revert-command.d.ts +54 -1
  204. package/dist/commands/revert-command.d.ts.map +1 -1
  205. package/dist/commands/revision-range.d.ts +34 -1
  206. package/dist/commands/revision-range.d.ts.map +1 -1
  207. package/dist/commands/revision-resolver.d.ts +15 -0
  208. package/dist/commands/revision-resolver.d.ts.map +1 -1
  209. package/dist/commands/rm-command.d.ts +70 -2
  210. package/dist/commands/rm-command.d.ts.map +1 -1
  211. package/dist/commands/sequencer-pick.d.ts +186 -5
  212. package/dist/commands/sequencer-pick.d.ts.map +1 -1
  213. package/dist/commands/sequencer-support.d.ts +12 -1
  214. package/dist/commands/sequencer-support.d.ts.map +1 -1
  215. package/dist/commands/serve-repository.d.ts +7 -0
  216. package/dist/commands/serve-repository.d.ts.map +1 -1
  217. package/dist/commands/shortlog-command.d.ts +109 -0
  218. package/dist/commands/shortlog-command.d.ts.map +1 -0
  219. package/dist/commands/shortlog.d.ts +151 -0
  220. package/dist/commands/shortlog.d.ts.map +1 -0
  221. package/dist/commands/show-command.d.ts +130 -0
  222. package/dist/commands/show-command.d.ts.map +1 -0
  223. package/dist/commands/show-commit.d.ts +11 -0
  224. package/dist/commands/show-commit.d.ts.map +1 -0
  225. package/dist/commands/signature-check.d.ts +164 -0
  226. package/dist/commands/signature-check.d.ts.map +1 -0
  227. package/dist/commands/signing.d.ts +160 -0
  228. package/dist/commands/signing.d.ts.map +1 -0
  229. package/dist/commands/sparse-checkout-command.d.ts.map +1 -1
  230. package/dist/commands/sparse-index-view.d.ts +45 -0
  231. package/dist/commands/sparse-index-view.d.ts.map +1 -0
  232. package/dist/commands/ssh-signer.d.ts +29 -0
  233. package/dist/commands/ssh-signer.d.ts.map +1 -0
  234. package/dist/commands/ssh-verifier.d.ts +42 -0
  235. package/dist/commands/ssh-verifier.d.ts.map +1 -0
  236. package/dist/commands/stash-apply-command.d.ts +5 -0
  237. package/dist/commands/stash-apply-command.d.ts.map +1 -1
  238. package/dist/commands/stash-branch-command.d.ts +34 -0
  239. package/dist/commands/stash-branch-command.d.ts.map +1 -0
  240. package/dist/commands/stash-create-command.d.ts +17 -0
  241. package/dist/commands/stash-create-command.d.ts.map +1 -1
  242. package/dist/commands/stash-info.d.ts +93 -0
  243. package/dist/commands/stash-info.d.ts.map +1 -0
  244. package/dist/commands/stash-list-command.d.ts +16 -0
  245. package/dist/commands/stash-list-command.d.ts.map +1 -1
  246. package/dist/commands/stash-pop-command.d.ts +39 -0
  247. package/dist/commands/stash-pop-command.d.ts.map +1 -0
  248. package/dist/commands/stash-show-command.d.ts +48 -0
  249. package/dist/commands/stash-show-command.d.ts.map +1 -0
  250. package/dist/commands/stash-store-command.d.ts +29 -0
  251. package/dist/commands/stash-store-command.d.ts.map +1 -0
  252. package/dist/commands/stash-working-tree.d.ts.map +1 -1
  253. package/dist/commands/status-command.d.ts +31 -2
  254. package/dist/commands/status-command.d.ts.map +1 -1
  255. package/dist/commands/status-header.d.ts +5 -0
  256. package/dist/commands/status-header.d.ts.map +1 -1
  257. package/dist/commands/submodule-add-command.d.ts +89 -0
  258. package/dist/commands/submodule-add-command.d.ts.map +1 -0
  259. package/dist/commands/submodule-auth.d.ts +90 -0
  260. package/dist/commands/submodule-auth.d.ts.map +1 -0
  261. package/dist/commands/submodule-commands.d.ts +463 -0
  262. package/dist/commands/submodule-commands.d.ts.map +1 -0
  263. package/dist/commands/submodule-fetch.d.ts +149 -0
  264. package/dist/commands/submodule-fetch.d.ts.map +1 -0
  265. package/dist/commands/submodule-model.d.ts +296 -0
  266. package/dist/commands/submodule-model.d.ts.map +1 -0
  267. package/dist/commands/submodule-unpack.d.ts +120 -0
  268. package/dist/commands/submodule-unpack.d.ts.map +1 -0
  269. package/dist/commands/submodule-update-command.d.ts +206 -0
  270. package/dist/commands/submodule-update-command.d.ts.map +1 -0
  271. package/dist/commands/subtree-shift.d.ts +27 -0
  272. package/dist/commands/subtree-shift.d.ts.map +1 -0
  273. package/dist/commands/switch-command.d.ts +3 -0
  274. package/dist/commands/switch-command.d.ts.map +1 -1
  275. package/dist/commands/tag-command.d.ts +259 -10
  276. package/dist/commands/tag-command.d.ts.map +1 -1
  277. package/dist/commands/trailers.d.ts +218 -17
  278. package/dist/commands/trailers.d.ts.map +1 -1
  279. package/dist/commands/tree-restore.d.ts +7 -0
  280. package/dist/commands/tree-restore.d.ts.map +1 -1
  281. package/dist/commands/verify-command.d.ts +92 -0
  282. package/dist/commands/verify-command.d.ts.map +1 -0
  283. package/dist/commands/worktree-add-command.d.ts +79 -7
  284. package/dist/commands/worktree-add-command.d.ts.map +1 -1
  285. package/dist/commands/worktree-overwrite-checks.d.ts +2 -0
  286. package/dist/commands/worktree-overwrite-checks.d.ts.map +1 -1
  287. package/dist/commands/worktree-path-rules.d.ts +66 -0
  288. package/dist/commands/worktree-path-rules.d.ts.map +1 -0
  289. package/dist/commands/worktree-remove-command.d.ts +10 -3
  290. package/dist/commands/worktree-remove-command.d.ts.map +1 -1
  291. package/dist/commands/worktree-repair-command.d.ts +15 -2
  292. package/dist/commands/worktree-repair-command.d.ts.map +1 -1
  293. package/dist/commands/worktree-support.d.ts +5 -0
  294. package/dist/commands/worktree-support.d.ts.map +1 -1
  295. package/dist/{commands-DIJ91NnD.js → commands-CNvli5bl.js} +49442 -54941
  296. package/dist/errors/checkout-errors.d.ts +19 -0
  297. package/dist/errors/checkout-errors.d.ts.map +1 -1
  298. package/dist/errors/command-errors.d.ts +25 -0
  299. package/dist/errors/command-errors.d.ts.map +1 -1
  300. package/dist/errors/index.js +85 -3
  301. package/dist/errors/ref-errors.d.ts +19 -0
  302. package/dist/errors/ref-errors.d.ts.map +1 -1
  303. package/dist/errors/worktree-errors.d.ts +6 -1
  304. package/dist/errors/worktree-errors.d.ts.map +1 -1
  305. package/dist/fsck-CPeDh9fh.js +5138 -0
  306. package/dist/git-command.d.ts +58 -2
  307. package/dist/git-command.d.ts.map +1 -1
  308. package/dist/git.d.ts +363 -1
  309. package/dist/git.d.ts.map +1 -1
  310. package/dist/guarded-transport-command.d.ts +82 -0
  311. package/dist/guarded-transport-command.d.ts.map +1 -0
  312. package/dist/index.d.ts +1 -0
  313. package/dist/index.d.ts.map +1 -1
  314. package/dist/index.js +6 -5
  315. package/dist/remote-config/index.d.ts +1 -1
  316. package/dist/remote-config/index.d.ts.map +1 -1
  317. package/dist/remote-config/remote-config-store.d.ts +55 -0
  318. package/dist/remote-config/remote-config-store.d.ts.map +1 -1
  319. package/dist/remote-transport-CCmBadm-.js +1606 -0
  320. package/dist/rename/detect-renames.d.ts +20 -0
  321. package/dist/rename/detect-renames.d.ts.map +1 -1
  322. package/dist/rename/diffcore-break.d.ts +51 -0
  323. package/dist/rename/diffcore-break.d.ts.map +1 -0
  324. package/dist/rename/index.d.ts +1 -0
  325. package/dist/rename/index.d.ts.map +1 -1
  326. package/dist/results/blame-format.d.ts +62 -1
  327. package/dist/results/blame-format.d.ts.map +1 -1
  328. package/dist/results/clone-result.d.ts +9 -0
  329. package/dist/results/clone-result.d.ts.map +1 -1
  330. package/dist/results/combined-diff.d.ts +3 -0
  331. package/dist/results/combined-diff.d.ts.map +1 -1
  332. package/dist/results/diff-check.d.ts +38 -0
  333. package/dist/results/diff-check.d.ts.map +1 -0
  334. package/dist/results/diff-color.d.ts +135 -0
  335. package/dist/results/diff-color.d.ts.map +1 -0
  336. package/dist/results/diff-dirstat.d.ts +36 -0
  337. package/dist/results/diff-dirstat.d.ts.map +1 -0
  338. package/dist/results/diff-entry.d.ts +10 -0
  339. package/dist/results/diff-entry.d.ts.map +1 -1
  340. package/dist/results/diff-formatter.d.ts.map +1 -1
  341. package/dist/results/diff-output.d.ts +103 -1
  342. package/dist/results/diff-output.d.ts.map +1 -1
  343. package/dist/results/diff-pickaxe.d.ts +67 -0
  344. package/dist/results/diff-pickaxe.d.ts.map +1 -0
  345. package/dist/results/diff-words.d.ts +55 -0
  346. package/dist/results/diff-words.d.ts.map +1 -0
  347. package/dist/results/fetch-result.d.ts +12 -1
  348. package/dist/results/fetch-result.d.ts.map +1 -1
  349. package/dist/results/index.d.ts +6 -0
  350. package/dist/results/index.d.ts.map +1 -1
  351. package/dist/results/index.js +2 -2
  352. package/dist/results/init-result.d.ts +8 -1
  353. package/dist/results/init-result.d.ts.map +1 -1
  354. package/dist/results/line-range-hunks.d.ts +27 -0
  355. package/dist/results/line-range-hunks.d.ts.map +1 -0
  356. package/dist/results/merge-result.d.ts +8 -1
  357. package/dist/results/merge-result.d.ts.map +1 -1
  358. package/dist/results/pull-result.d.ts +11 -0
  359. package/dist/results/pull-result.d.ts.map +1 -1
  360. package/dist/results/push-result.d.ts +12 -0
  361. package/dist/results/push-result.d.ts.map +1 -1
  362. package/dist/results/rebase-result.d.ts +2 -0
  363. package/dist/results/rebase-result.d.ts.map +1 -1
  364. package/dist/results/stash-result.d.ts +6 -0
  365. package/dist/results/stash-result.d.ts.map +1 -1
  366. package/dist/results/status-result.d.ts +1 -1
  367. package/dist/results/status-result.d.ts.map +1 -1
  368. package/dist/results-BDuEgdLU.js +46847 -0
  369. package/dist/transport-command.d.ts +14 -0
  370. package/dist/transport-command.d.ts.map +1 -1
  371. package/dist/whitespace/index.d.ts +2 -0
  372. package/dist/whitespace/index.d.ts.map +1 -0
  373. package/dist/whitespace/whitespace-rule.d.ts +94 -0
  374. package/dist/whitespace/whitespace-rule.d.ts.map +1 -0
  375. package/package.json +12 -12
  376. package/src/commands/add-command.ts +293 -17
  377. package/src/commands/add-patch/add-patch.ts +8 -0
  378. package/src/commands/add-patch/patch-backend.ts +20 -2
  379. package/src/commands/am/am-command.ts +400 -46
  380. package/src/commands/am/index.ts +1 -0
  381. package/src/commands/am/mailsplit.ts +326 -0
  382. package/src/commands/apply/apply-command.ts +58 -15
  383. package/src/commands/apply/apply-engine.ts +1 -1
  384. package/src/commands/apply/apply-parse.ts +17 -8
  385. package/src/commands/apply/index.ts +8 -1
  386. package/src/commands/bisect/bisect-command.ts +18 -5
  387. package/src/commands/blame-command.ts +1450 -51
  388. package/src/commands/blame-ignore.ts +307 -0
  389. package/src/commands/branch-command.ts +528 -53
  390. package/src/commands/branch-info-command.ts +150 -0
  391. package/src/commands/branch-tracking.ts +335 -60
  392. package/src/commands/branch-upstream-command.ts +218 -0
  393. package/src/commands/check-mailmap-command.ts +129 -0
  394. package/src/commands/checkout-command.ts +166 -55
  395. package/src/commands/checkout-paths.ts +28 -0
  396. package/src/commands/cherry-command.ts +187 -0
  397. package/src/commands/cherry-pick-command.ts +185 -1
  398. package/src/commands/clean-command.ts +126 -15
  399. package/src/commands/clean-interactive.ts +522 -0
  400. package/src/commands/clone-command.ts +598 -45
  401. package/src/commands/commit-command.ts +925 -74
  402. package/src/commands/commit-reuse.ts +94 -0
  403. package/src/commands/config-command.ts +1256 -0
  404. package/src/commands/config-value-types.ts +358 -0
  405. package/src/commands/core-config.ts +40 -0
  406. package/src/commands/describe-command.ts +341 -254
  407. package/src/commands/diff-color-config.ts +274 -0
  408. package/src/commands/diff-command.ts +1619 -99
  409. package/src/commands/fetch-command.ts +495 -14
  410. package/src/commands/fetch-multiple-command.ts +665 -0
  411. package/src/commands/fmt-merge-msg-command.ts +715 -0
  412. package/src/commands/fork-point.ts +63 -0
  413. package/src/commands/format-patch-command.ts +496 -116
  414. package/src/commands/fsck/fetch-fsck.ts +172 -18
  415. package/src/commands/gc-command.ts +31 -1
  416. package/src/commands/git-describe.ts +460 -201
  417. package/src/commands/git-hooks.ts +123 -3
  418. package/src/commands/grep/grep-command.ts +1077 -0
  419. package/src/commands/grep/grep-engine.ts +1024 -0
  420. package/src/commands/grep/index.ts +2 -0
  421. package/src/commands/index-adder.ts +46 -7
  422. package/src/commands/index.ts +43 -0
  423. package/src/commands/init-command.ts +603 -49
  424. package/src/commands/interpret-trailers-command.ts +256 -0
  425. package/src/commands/line-log.ts +931 -0
  426. package/src/commands/local-transport.ts +109 -10
  427. package/src/commands/log-command.ts +2599 -326
  428. package/src/commands/log-graph.ts +129 -29
  429. package/src/commands/log-output.ts +449 -27
  430. package/src/commands/ls-remote-command.ts +5 -0
  431. package/src/commands/mailmap.ts +155 -0
  432. package/src/commands/merge-base-command.ts +170 -0
  433. package/src/commands/merge-bases.ts +63 -8
  434. package/src/commands/merge-command.ts +601 -95
  435. package/src/commands/merge-drivers.ts +3 -0
  436. package/src/commands/merge-strategy-options.ts +224 -0
  437. package/src/commands/merge-support.ts +115 -22
  438. package/src/commands/message-cleanup.ts +1 -1
  439. package/src/commands/mv-command.ts +6 -3
  440. package/src/commands/name-rev-command.ts +184 -0
  441. package/src/commands/name-rev.ts +762 -0
  442. package/src/commands/notes-command.ts +11 -1
  443. package/src/commands/octopus-merge.ts +35 -11
  444. package/src/commands/ort-merge.ts +41 -7
  445. package/src/commands/ort-recursive.ts +40 -2
  446. package/src/commands/patch-id.ts +109 -0
  447. package/src/commands/pathspec-file.ts +72 -0
  448. package/src/commands/pathspec.ts +14 -2
  449. package/src/commands/pretty-format.ts +103 -19
  450. package/src/commands/promisor-remote.ts +10 -1
  451. package/src/commands/pull-command.ts +734 -221
  452. package/src/commands/push-command.ts +1035 -68
  453. package/src/commands/range-diff/index.ts +3 -0
  454. package/src/commands/range-diff/linear-assignment.ts +203 -0
  455. package/src/commands/range-diff/range-diff-command.ts +433 -0
  456. package/src/commands/range-diff/range-diff.ts +617 -0
  457. package/src/commands/read-tree-command.ts +102 -4
  458. package/src/commands/rebase-command.ts +1074 -194
  459. package/src/commands/ref-filter/for-each-ref-command.ts +298 -0
  460. package/src/commands/ref-filter/index.ts +7 -0
  461. package/src/commands/ref-filter/ref-atoms.ts +581 -0
  462. package/src/commands/ref-filter/ref-filter.ts +651 -0
  463. package/src/commands/ref-filter/ref-format.ts +1070 -0
  464. package/src/commands/ref-filter/ref-listing-command.ts +421 -0
  465. package/src/commands/ref-filter/ref-quote.ts +69 -0
  466. package/src/commands/ref-filter/version-compare.ts +177 -0
  467. package/src/commands/reflog-command.ts +492 -2
  468. package/src/commands/reflog-walk.ts +234 -0
  469. package/src/commands/remerge-diff.ts +241 -0
  470. package/src/commands/remote-command.ts +537 -69
  471. package/src/commands/remote-show-command.ts +836 -0
  472. package/src/commands/remote-transport.ts +9 -1
  473. package/src/commands/reset-command.ts +114 -34
  474. package/src/commands/restore-command.ts +27 -41
  475. package/src/commands/rev-filter/commit-filter.ts +159 -0
  476. package/src/commands/rev-filter/commit-grep.ts +444 -0
  477. package/src/commands/rev-filter/index.ts +2 -0
  478. package/src/commands/rev-list-command.ts +578 -15
  479. package/src/commands/revert-command.ts +123 -1
  480. package/src/commands/revision-range.ts +207 -5
  481. package/src/commands/revision-resolver.ts +23 -8
  482. package/src/commands/rm-command.ts +282 -21
  483. package/src/commands/sequencer-pick.ts +818 -111
  484. package/src/commands/sequencer-support.ts +184 -4
  485. package/src/commands/serve-repository.ts +18 -3
  486. package/src/commands/shortlog-command.ts +354 -0
  487. package/src/commands/shortlog.ts +361 -0
  488. package/src/commands/show-command.ts +491 -0
  489. package/src/commands/show-commit.ts +24 -0
  490. package/src/commands/signature-check.ts +657 -0
  491. package/src/commands/signing.ts +385 -0
  492. package/src/commands/sparse-checkout-command.ts +2 -9
  493. package/src/commands/sparse-checkout-support.ts +2 -2
  494. package/src/commands/sparse-index-view.ts +135 -0
  495. package/src/commands/ssh-signer.ts +199 -0
  496. package/src/commands/ssh-verifier.ts +523 -0
  497. package/src/commands/stash-apply-command.ts +16 -4
  498. package/src/commands/stash-branch-command.ts +88 -0
  499. package/src/commands/stash-create-command.ts +28 -0
  500. package/src/commands/stash-info.ts +243 -0
  501. package/src/commands/stash-list-command.ts +33 -0
  502. package/src/commands/stash-pop-command.ts +83 -0
  503. package/src/commands/stash-show-command.ts +141 -0
  504. package/src/commands/stash-store-command.ts +82 -0
  505. package/src/commands/stash-working-tree.ts +2 -2
  506. package/src/commands/status-command.ts +120 -27
  507. package/src/commands/status-format.ts +1 -1
  508. package/src/commands/status-header.ts +41 -7
  509. package/src/commands/submodule-add-command.ts +509 -0
  510. package/src/commands/submodule-auth.ts +276 -0
  511. package/src/commands/submodule-commands.ts +1835 -0
  512. package/src/commands/submodule-fetch.ts +789 -0
  513. package/src/commands/submodule-model.ts +938 -0
  514. package/src/commands/submodule-unpack.ts +265 -0
  515. package/src/commands/submodule-update-command.ts +1126 -0
  516. package/src/commands/subtree-shift.ts +215 -0
  517. package/src/commands/switch-command.ts +12 -1
  518. package/src/commands/tag-command.ts +876 -64
  519. package/src/commands/trailers.ts +837 -100
  520. package/src/commands/tree-restore.ts +44 -11
  521. package/src/commands/verify-command.ts +235 -0
  522. package/src/commands/worktree-add-command.ts +268 -24
  523. package/src/commands/worktree-overwrite-checks.ts +5 -0
  524. package/src/commands/worktree-path-rules.ts +183 -0
  525. package/src/commands/worktree-remove-command.ts +39 -5
  526. package/src/commands/worktree-repair-command.ts +52 -5
  527. package/src/commands/worktree-support.ts +22 -1
  528. package/src/errors/checkout-errors.ts +29 -0
  529. package/src/errors/command-errors.ts +37 -1
  530. package/src/errors/ref-errors.ts +23 -0
  531. package/src/errors/worktree-errors.ts +8 -1
  532. package/src/git-command.ts +153 -2
  533. package/src/git.ts +550 -1
  534. package/src/guarded-transport-command.ts +171 -0
  535. package/src/index.ts +1 -0
  536. package/src/remote-config/index.ts +2 -0
  537. package/src/remote-config/remote-config-store.ts +101 -0
  538. package/src/rename/detect-renames.ts +42 -8
  539. package/src/rename/diffcore-break.ts +166 -0
  540. package/src/rename/index.ts +1 -0
  541. package/src/results/blame-format.ts +268 -43
  542. package/src/results/clone-result.ts +6 -0
  543. package/src/results/combined-diff.ts +38 -18
  544. package/src/results/diff-check.ts +185 -0
  545. package/src/results/diff-color.ts +868 -0
  546. package/src/results/diff-dirstat.ts +117 -0
  547. package/src/results/diff-entry.ts +12 -0
  548. package/src/results/diff-formatter.ts +1 -0
  549. package/src/results/diff-output.ts +322 -32
  550. package/src/results/diff-pickaxe.ts +304 -0
  551. package/src/results/diff-words.ts +395 -0
  552. package/src/results/fetch-result.ts +12 -1
  553. package/src/results/index.ts +6 -0
  554. package/src/results/init-result.ts +10 -1
  555. package/src/results/line-range-hunks.ts +126 -0
  556. package/src/results/merge-result.ts +9 -0
  557. package/src/results/pull-result.ts +7 -0
  558. package/src/results/push-result.ts +12 -0
  559. package/src/results/rebase-result.ts +3 -0
  560. package/src/results/stash-result.ts +7 -0
  561. package/src/results/status-result.ts +2 -2
  562. package/src/transport-command.ts +34 -3
  563. package/src/whitespace/index.ts +1 -0
  564. package/src/{commands/apply/whitespace.ts → whitespace/whitespace-rule.ts} +173 -23
  565. package/dist/commands/apply/whitespace.d.ts +0 -58
  566. package/dist/commands/apply/whitespace.d.ts.map +0 -1
  567. package/dist/git-command-BGiOJ8Zk.js +0 -7246
  568. package/dist/results-WVlBhVb1.js +0 -2935
@@ -0,0 +1,1606 @@
1
+ import { I as __exportAll, m as receiveFsckOf } from "./fsck-CPeDh9fh.js";
2
+ import { GitApiError, InvalidConfigError, InvalidPathError, ReadTreeFailedError, TransportError as TransportError$1 } from "./errors/index.js";
3
+ import { Do as quoteCStyleBody, Ic as hookSettingsFromEntries, Kc as worktreeModeTrust, Kt as SubmoduleUnpack, L as StatusCommand, Mt as resetMerge, Nc as hookHostOf, Po as GitCommand, Sc as worktreePathRules, Tc as LOCAL_REPO_ENV, Wc as coreBool, Ws as SparseUnpack, Xi as firstPlainError, Zi as flatTree, _c as restoreCaseOptions, ca as switchTrees, dc as untrackedUnder, ea as plainUnpackError, fl as hostEnvironmentOf, fn as repositoryPlaceOf, gn as usesBranch, ia as rewriteIndex, nc as entryNotUptodate, oc as pruneEmptyParents, qs as pushSparseWarnings, qt as recursesIntoSubmodules, sc as removeCaseVariants, ta as planPathsRestore, tc as IndexCaseFolding, vc as writeTreeRestorePlan, vn as worktreeUsingBranch, wc as HookSession, wl as RemoteConfigStore, xc as withTreePathRefusal, yc as firstInvalidPath, zc as refTransactionHookOf } from "./results-BDuEgdLU.js";
4
+ import { FileMode, historyWithoutLazyFetch } from "@statewalker/vcs-core";
5
+ import { compareGitPaths, parseGitBool, parseGitInt } from "@statewalker/vcs-utils/encoding";
6
+ import { attributesIndexOf, cacheTreeOfTree, entryStatOf, isIndexUnborn, repairCacheTree, sparseFilterMatcher } from "@statewalker/vcs-working-tree";
7
+ import { readFile as readFile$1 } from "@statewalker/vcs-utils/files";
8
+ import { configFilesApiOf, readConfinedFile } from "@statewalker/vcs-store-files";
9
+ import { ReceivePackDiedError, createRepositoryFacade, createTransportRefStore, isGitUrl, openDuplexConnection, openDuplexReceivePackConnection, openReceivePack, openUploadPack, parseGitUrl, protocolVersionFor, serveOverDuplex, serverSettingsFromConfig } from "@statewalker/vcs-transport";
10
+ //#region src/commands/read-tree-command.ts
11
+ /**
12
+ * `git read-tree` (builtin/read-tree.c over unpack-trees.c): read trees into the index,
13
+ * merging them with it (`-m`: one-, two- and three-way), optionally updating the worktree.
14
+ */
15
+ /** unpack-trees' `MAX_UNPACK_TREES`. */
16
+ const MAX_UNPACK_TREES = 8;
17
+ const same = (a, b) => a === void 0 || b === void 0 ? a === b : a.objectId === b.objectId && a.mode === b.mode;
18
+ /**
19
+ * Read trees into the index (`git read-tree`).
20
+ *
21
+ * ```typescript
22
+ * // the index becomes HEAD's tree (stat data and flags gone)
23
+ * await git.readTree().addTree("HEAD").call();
24
+ *
25
+ * // a fast-forward of the index and the worktree from HEAD to `next`
26
+ * await git.readTree().setMerge(true).setUpdate(true).addTree("HEAD").addTree("next").call();
27
+ *
28
+ * // a three-way merge leaving the conflicts as stages 1-3
29
+ * await git.readTree().setMerge(true).addTree(base).addTree("HEAD").addTree(other).call();
30
+ * ```
31
+ *
32
+ * A refusal is unpack-trees' plain message for the first path refused (`error: Entry 'x'
33
+ * would be overwritten by merge. Cannot merge.`), thrown as {@link ReadTreeFailedError}
34
+ * before anything changed. One tree read without `--prefix` leaves the index's cache-tree
35
+ * primed with it (`prime_cache_tree`); otherwise each directory is valid where its tree is
36
+ * stored (`cache_tree_update` with `WRITE_TREE_REPAIR`), none while conflicts remain.
37
+ */
38
+ var ReadTreeCommand = class extends GitCommand {
39
+ treeishes = [];
40
+ merge = false;
41
+ reset = false;
42
+ prefix;
43
+ update = false;
44
+ indexOnly = false;
45
+ empty = false;
46
+ trivial = false;
47
+ aggressive = false;
48
+ skipSparseCheckout = false;
49
+ recurseSubmodules;
50
+ dryRun = false;
51
+ superPrefix = "";
52
+ /** A tree-ish to read (up to eight). */
53
+ addTree(treeish) {
54
+ this.checkCallable();
55
+ this.treeishes.push(treeish);
56
+ return this;
57
+ }
58
+ /** `-m`: merge the trees with the index (one-, two- or three-way by their number). */
59
+ setMerge(merge) {
60
+ this.checkCallable();
61
+ this.merge = merge;
62
+ return this;
63
+ }
64
+ /** `--reset`: as `-m`, unmerged entries discarded and local changes no refusal. */
65
+ setReset(reset) {
66
+ this.checkCallable();
67
+ this.reset = reset;
68
+ return this;
69
+ }
70
+ /** `--prefix=<dir>/`: the tree read under `<dir>/` (bound into the index, which keeps the rest). */
71
+ setPrefix(prefix) {
72
+ this.checkCallable();
73
+ this.prefix = prefix;
74
+ return this;
75
+ }
76
+ /** `-u`: the worktree updated with the merge's result. */
77
+ setUpdate(update) {
78
+ this.checkCallable();
79
+ this.update = update;
80
+ return this;
81
+ }
82
+ /** `-i`: the worktree is not looked at (no up-to-date check). */
83
+ setIndexOnly(indexOnly) {
84
+ this.checkCallable();
85
+ this.indexOnly = indexOnly;
86
+ return this;
87
+ }
88
+ /** `--empty`: empty the index. */
89
+ setEmpty(empty) {
90
+ this.checkCallable();
91
+ this.empty = empty;
92
+ return this;
93
+ }
94
+ /** `--trivial`: a three-way merge only where no path needs a file-level merge. */
95
+ setTrivial(trivial) {
96
+ this.checkCallable();
97
+ this.trivial = trivial;
98
+ return this;
99
+ }
100
+ /** `--aggressive`: a three-way merge also resolving deletions and identical additions. */
101
+ setAggressive(aggressive) {
102
+ this.checkCallable();
103
+ this.aggressive = aggressive;
104
+ return this;
105
+ }
106
+ /**
107
+ * `-v`: accepted for parity. git shows only a delayed progress meter ("Updating files"),
108
+ * which an update shorter than two seconds never prints; nothing is reported here.
109
+ */
110
+ setVerbose(_verbose) {
111
+ this.checkCallable();
112
+ return this;
113
+ }
114
+ /**
115
+ * `--[no-]recurse-submodules` (default `submodule.recurse`): the active submodules' worktrees
116
+ * are checked and moved with the superproject's (unpack-trees' `check_submodule_move_head`,
117
+ * entry.c's `submodule_move_head`).
118
+ */
119
+ setRecurseSubmodules(recurse) {
120
+ this.checkCallable();
121
+ this.recurseSubmodules = recurse;
122
+ return this;
123
+ }
124
+ /** `-n` / `--dry-run`: everything checked, neither the index nor the worktree written. */
125
+ setDryRun(dryRun) {
126
+ this.checkCallable();
127
+ this.dryRun = dryRun;
128
+ return this;
129
+ }
130
+ /** @internal git's `--super-prefix`: the submodule's path in its superproject, in messages. */
131
+ setSuperPrefix(prefix) {
132
+ this.superPrefix = prefix;
133
+ return this;
134
+ }
135
+ /** `--no-sparse-checkout`: the sparse-checkout patterns are not applied. */
136
+ setSkipSparseCheckout(skip) {
137
+ this.checkCallable();
138
+ this.skipSparseCheckout = skip;
139
+ return this;
140
+ }
141
+ async call() {
142
+ const trees = [];
143
+ if (this.dryRun) try {
144
+ return await this.callChecked(trees);
145
+ } finally {
146
+ await this.staging.read();
147
+ }
148
+ return this.callChecked(trees);
149
+ }
150
+ callChecked(trees) {
151
+ return withTreePathRefusal(this.trees, () => trees, worktreePathRules(this.workingCopy, this.update ? this.worktreeAccess : void 0), () => this.callOnce(trees), (refusal) => refusal instanceof InvalidPathError ? new ReadTreeFailedError(refusal.message, [refusal.path]) : refusal);
152
+ }
153
+ /** {@link call}, collecting the trees it reads into `read`. */
154
+ async callOnce(read) {
155
+ this.checkCallable();
156
+ this.setCallable(false);
157
+ const fatal = (message) => {
158
+ throw new ReadTreeFailedError(`fatal: ${message}`);
159
+ };
160
+ const result = {
161
+ warnings: [],
162
+ unmerged: []
163
+ };
164
+ const prefixSet = this.prefix !== void 0;
165
+ if (Number(this.merge) + Number(this.reset) + Number(prefixSet) > 1) fatal("Which one? -m, --reset, or --prefix?");
166
+ if (this.prefix?.startsWith("/")) fatal("Invalid prefix, prefix cannot start with '/'");
167
+ await this.readCurrentIndex();
168
+ let merge = this.merge;
169
+ let unmergedIndex = false;
170
+ for await (const e of this.staging.entries()) if (e.stage !== 0) {
171
+ unmergedIndex = true;
172
+ break;
173
+ }
174
+ if (this.reset || merge || prefixSet) {
175
+ if (unmergedIndex && (prefixSet || merge)) fatal("You need to resolve your current index first");
176
+ merge = true;
177
+ }
178
+ const treeIds = [];
179
+ for (const name of this.treeishes) {
180
+ if (treeIds.length >= MAX_UNPACK_TREES) fatal(`I cannot read more than ${MAX_UNPACK_TREES} trees`);
181
+ const id = await this.resolveRevision(name).catch(() => void 0);
182
+ const tree = id ? await this.revisionResolver().peelToType(id, "tree") : void 0;
183
+ if (!id) fatal(`Not a valid object name ${name}`);
184
+ if (!tree) fatal(`failed to unpack tree object ${name}`);
185
+ treeIds.push(tree);
186
+ read.push(tree);
187
+ }
188
+ if (treeIds.length === 0 && !this.empty && !merge) result.warnings.push("warning: read-tree: emptying the index with no arguments is deprecated; use --empty");
189
+ else if (treeIds.length > 0 && this.empty) fatal("passing trees as arguments contradicts --empty");
190
+ if (this.update && this.indexOnly) fatal("-u and -i at the same time makes no sense");
191
+ if ((this.update || this.indexOnly) && !merge) fatal(`${this.update ? "-u" : "-i"} is meaningless without -m, --reset, or --prefix`);
192
+ if (merge && treeIds.length === 0) fatal("you must specify at least one tree to merge");
193
+ const checked = this.indexOnly ? void 0 : this.worktreeAccess;
194
+ const sequencerCtx = {
195
+ workingCopy: this.workingCopy,
196
+ worktree: checked,
197
+ staging: this.staging,
198
+ blobs: this.blobs,
199
+ trees: this.trees,
200
+ commits: this.commits,
201
+ refs: this.refsStore,
202
+ sparseWarnings: result.warnings
203
+ };
204
+ const refused = (message, paths = []) => {
205
+ if (!message) return;
206
+ let text = message;
207
+ if (this.superPrefix) for (const p of new Set(paths)) text = text.split(`'${p}'`).join(`'${this.superPrefix}${p}'`);
208
+ throw new ReadTreeFailedError(text, paths);
209
+ };
210
+ const submodules = merge && !prefixSet && treeIds.length <= 2 && !this.indexOnly ? await SubmoduleUnpack.start(this.workingCopy, {
211
+ recurse: recursesIntoSubmodules(this.workingCopy, this.recurseSubmodules),
212
+ reset: this.reset,
213
+ superPrefix: this.superPrefix
214
+ }) : void 0;
215
+ const update = this.update;
216
+ const dryRunOptions = this.dryRun ? {
217
+ writeIndex: false,
218
+ checkOnly: true
219
+ } : {};
220
+ if (!merge) await this.readWithoutMerge(treeIds);
221
+ else if (prefixSet) {
222
+ const prefix = this.prefix.replace(/\/*$/, "/");
223
+ await this.bindMerge(sequencerCtx, treeIds, prefix === "/" ? "" : prefix, result);
224
+ } else if (treeIds.length === 1) {
225
+ const tree = treeIds[0];
226
+ const refusal = await resetMerge(sequencerCtx, tree, tree, {
227
+ hard: this.reset,
228
+ update,
229
+ submodules,
230
+ ...dryRunOptions,
231
+ overwriteUntracked: this.reset,
232
+ skipSparseCheckout: this.skipSparseCheckout,
233
+ targetTree: tree,
234
+ plain: true
235
+ });
236
+ refused(refusal?.message, refusal?.paths);
237
+ } else if (treeIds.length === 2) {
238
+ const [h, m] = treeIds;
239
+ const refusal = await switchTrees(sequencerCtx, await flatTree(this.trees, h), await flatTree(this.trees, m), {
240
+ action: "merge",
241
+ operation: "read-tree",
242
+ update,
243
+ submodules,
244
+ ...dryRunOptions,
245
+ skipSparseCheckout: this.skipSparseCheckout,
246
+ plainErrors: true,
247
+ initialCheckout: await isIndexUnborn(this.staging)
248
+ });
249
+ refused(refusal?.message, refusal?.paths);
250
+ } else await this.threewayMerge(sequencerCtx, treeIds, result);
251
+ if (this.dryRun) return result;
252
+ this.staging.clearResolveUndo?.();
253
+ if (treeIds.length === 1 && !prefixSet) this.staging.setCacheTree?.(await cacheTreeOfTree(this.trees, treeIds[0]));
254
+ else this.staging.setCacheTree?.(await this.repairedCacheTree());
255
+ await this.staging.write();
256
+ for await (const e of this.staging.entries()) if (e.stage !== 0 && result.unmerged[result.unmerged.length - 1] !== e.path) result.unmerged.push(e.path);
257
+ return result;
258
+ }
259
+ /** `cache_tree_update(WRITE_TREE_SILENT | WRITE_TREE_REPAIR)` of the index as it is. */
260
+ async repairedCacheTree() {
261
+ const entries = await this.entryList();
262
+ const trees = this.trees;
263
+ return repairCacheTree({ has: async (id) => id === this.objectFormat.emptyTreeId || await trees.has(id) }, entries, this.objectFormat);
264
+ }
265
+ async entryList() {
266
+ const list = this.staging.entryList?.();
267
+ if (list) return list;
268
+ const out = [];
269
+ for await (const e of this.staging.entries()) out.push(e);
270
+ return out;
271
+ }
272
+ /**
273
+ * unpack-trees without `-m`: the index is the trees' entries, at stage 0, without stat
274
+ * data or flags, added in `traverse_trees` order (at each name the trees' files in their
275
+ * order, then what a directory of that name holds), each with `add_index_entry`'s
276
+ * `OK_TO_REPLACE`: a later tree's entry replaces an earlier one's, a directory's files
277
+ * replace a file of its name, whichever tree holds which.
278
+ */
279
+ async readWithoutMerge(treeIds) {
280
+ const flat = await Promise.all(treeIds.map((id) => flatTree(this.trees, id)));
281
+ const all = /* @__PURE__ */ new Set();
282
+ for (const m of flat) for (const p of m.keys()) all.add(p);
283
+ const entries = /* @__PURE__ */ new Map();
284
+ for (const path of traversalOrder(all)) for (const m of flat) {
285
+ const e = m.get(path);
286
+ if (!e) continue;
287
+ for (let at = path.indexOf("/"); at >= 0; at = path.indexOf("/", at + 1)) entries.delete(path.slice(0, at));
288
+ entries.set(path, e);
289
+ }
290
+ const invalid = firstInvalidPath(entries, /* @__PURE__ */ new Map(), worktreePathRules(this.workingCopy, this.update ? this.worktreeAccess : void 0));
291
+ if (invalid !== void 0) throw new ReadTreeFailedError(`error: invalid path '${invalid}'`, [invalid]);
292
+ assertNoStageZeroClash(new Set(entries.keys()));
293
+ const builder = this.staging.createBuilder();
294
+ for (const path of [...entries.keys()].sort(compareGitPaths)) {
295
+ const e = entries.get(path);
296
+ builder.add({
297
+ path,
298
+ objectId: e.objectId,
299
+ mode: e.mode,
300
+ size: 0,
301
+ mtime: 0
302
+ });
303
+ }
304
+ await builder.finish();
305
+ }
306
+ /**
307
+ * `bind_merge` (`--prefix=<dir>/`): the tree's entries under `<dir>/`, every index entry
308
+ * kept; a path both have is refused ("Entry 'x' overlaps with 'x'. Cannot bind."). The
309
+ * entries are added in `traverse_trees` order with `add_index_entry`'s `OK_TO_REPLACE`, so
310
+ * where a file and a directory clash the directory's entries, added after, win: an index
311
+ * file in place of a bound leading directory is dropped, and so is a bound file with index
312
+ * entries beneath it. With `-u` the new files are written: a file in the way is refused
313
+ * first, tracked or not ("Untracked working tree file 'a' would be overwritten by merge.",
314
+ * as `check_ok_to_remove` finds it kept in the result); where a bound file finds a
315
+ * directory, its tracked files must be up to date and go (`verify_clean_subdirectory` marks
316
+ * them removed), and the bound file is written in its place.
317
+ */
318
+ async bindMerge(ctx, treeIds, prefix, result) {
319
+ if (treeIds.length !== 1) throw new ReadTreeFailedError(`error: Cannot do a bind merge of ${treeIds.length} trees`);
320
+ const tree = await flatTree(this.trees, treeIds[0]);
321
+ const index = /* @__PURE__ */ new Map();
322
+ for (const e of await this.entryList()) index.set(e.path, e);
323
+ const target = /* @__PURE__ */ new Map();
324
+ for (const [p, e] of tree) target.set(`${prefix}${p}`, e);
325
+ const targetDirs = directoriesOf(target);
326
+ const dropped = /* @__PURE__ */ new Set();
327
+ const beneath = /* @__PURE__ */ new Map();
328
+ for (const p of index.keys()) {
329
+ if (targetDirs.has(p)) dropped.add(p);
330
+ for (let at = p.indexOf("/"); at >= 0; at = p.indexOf("/", at + 1)) {
331
+ const dir = p.slice(0, at);
332
+ if (target.has(dir)) {
333
+ const list = beneath.get(dir) ?? [];
334
+ list.push(p);
335
+ beneath.set(dir, list);
336
+ break;
337
+ }
338
+ }
339
+ }
340
+ const checking = traversalOrder(target.keys());
341
+ const worktree = this.update ? ctx.worktree : void 0;
342
+ const sparse = worktree && !this.skipSparseCheckout ? await SparseUnpack.start(ctx) : void 0;
343
+ const trust = worktree ? worktreeModeTrust(this.workingCopy, worktree) : void 0;
344
+ const indexTime = this.staging.getUpdateTime();
345
+ const removing = [];
346
+ const folding = await this.caseFolding(worktree, index);
347
+ const caseVariants = [];
348
+ for (const path of checking) {
349
+ if (index.has(path)) throw new ReadTreeFailedError(`error: Entry '${path}' overlaps with '${path}'. Cannot bind.`, [path]);
350
+ if (!worktree || sparse?.leavesAlone(path)) continue;
351
+ const entry = await worktree.getEntry(path).catch(() => void 0);
352
+ if (entry?.isDirectory && entry.mode !== FileMode.GITLINK) {
353
+ const under = beneath.get(path) ?? [];
354
+ for (const old of under) {
355
+ const e = index.get(old);
356
+ if (await entryNotUptodate(worktree, old, e, trust, indexTime)) throw new ReadTreeFailedError(plainUnpackError("notUptodate", old), [old]);
357
+ removing.push(old);
358
+ dropped.add(old);
359
+ }
360
+ beneath.delete(path);
361
+ }
362
+ const error = await verifyAbsent(worktree, path, (p) => index.has(p), "untracked", {
363
+ folding,
364
+ caseVariants
365
+ });
366
+ if (error) throw new ReadTreeFailedError(error, [path]);
367
+ }
368
+ const paths = checking.filter((p) => !beneath.has(p));
369
+ const stage0 = new Set(paths);
370
+ for (const p of index.keys()) if (!dropped.has(p)) stage0.add(p);
371
+ assertNoStageZeroClash(stage0);
372
+ if (this.dryRun) return;
373
+ const writing = new Set(paths.filter((p) => !sparse || sparse.writes(p)));
374
+ if (worktree) {
375
+ if (sparse) {
376
+ const unlink = await sparse.leaving(worktree, (p) => (beneath.has(p) ? void 0 : target.get(p)) ?? (dropped.has(p) ? void 0 : index.get(p)), { trust });
377
+ await sparse.unlink(worktree, unlink);
378
+ }
379
+ for (const old of removing) {
380
+ const entry = await worktree.getEntry(old).catch(() => void 0);
381
+ if (entry && !entry.isDirectory) {
382
+ await worktree.remove(old);
383
+ await pruneEmptyParents(worktree, old);
384
+ }
385
+ }
386
+ await removeCaseVariants(worktree, caseVariants);
387
+ if (writing.size > 0) await this.writeFiles(ctx, worktree, target, writing, index);
388
+ }
389
+ const changes = /* @__PURE__ */ new Map();
390
+ for (const p of dropped) changes.set(p, []);
391
+ for (const path of paths) {
392
+ const e = target.get(path);
393
+ const stat = worktree && writing.has(path) ? await worktree.getEntry(path) : void 0;
394
+ changes.set(path, [{
395
+ path,
396
+ objectId: e.objectId,
397
+ mode: e.mode,
398
+ ...entryStatOf(stat && !stat.isDirectory ? stat : {})
399
+ }]);
400
+ }
401
+ await rewriteIndex(this.staging, changes);
402
+ if (sparse && worktree) {
403
+ const outcome = await sparse.finish(ctx, { written: writing });
404
+ pushSparseWarnings(result.warnings, sparse, outcome, false);
405
+ }
406
+ }
407
+ /** The source index's case-folding lookups under `core.ignorecase` (undefined: off). */
408
+ async caseFolding(worktree, index) {
409
+ if (!worktree || !coreBool(this.workingCopy, "ignorecase", false)) return void 0;
410
+ return new IndexCaseFolding(index, await restoreCaseOptions(worktree, true));
411
+ }
412
+ /** The files of `writing` written from `target` (smudged with the result's attributes). */
413
+ async writeFiles(ctx, worktree, target, writing, index) {
414
+ const plan = await planPathsRestore(ctx, target, void 0, writing, "read-tree");
415
+ const attributes = /* @__PURE__ */ new Map();
416
+ for (const [p, e] of index) if (p.endsWith(".gitattributes")) attributes.set(p, e.objectId);
417
+ for (const p of writing) if (p.endsWith(".gitattributes")) attributes.set(p, target.get(p).objectId);
418
+ await writeTreeRestorePlan(worktree, ctx.blobs, plan, "read-tree", {
419
+ symlinks: worktreeModeTrust(this.workingCopy, worktree).symlinks,
420
+ gitlinks: true,
421
+ replaceInTheWay: true,
422
+ attributes: {
423
+ direction: "checkout",
424
+ index: attributesIndexOf(attributes)
425
+ }
426
+ });
427
+ }
428
+ /**
429
+ * `threeway_merge` over `<base>... <head> <remote>`: the trivial cases resolved (the
430
+ * index must hold the head's entry, or the result's where `#14ALT`/`#2ALT` allow it),
431
+ * the rest left as stages 1 (the first base), 2 and 3, the worktree untouched there.
432
+ * `--aggressive` resolves deletions on one side with the other unchanged, deletions on
433
+ * both, and identical additions. `--trivial` fails where a file-level merge is needed.
434
+ *
435
+ * A path that is a file in some trees and a directory in others is unpack-trees'
436
+ * file/directory conflict: the trees holding the directory (or a file in place of one of
437
+ * the path's leading directories) stand as `df_conflict_entry` there, which matches
438
+ * nothing, is no stage, and keeps `#14`/`#2ALT` (a conflicting head) and `#13`/`#3ALT`
439
+ * (a conflicting remote) from resolving. Every check runs before anything is written.
440
+ */
441
+ async threewayMerge(ctx, treeIds, result) {
442
+ const flat = await Promise.all(treeIds.map((id) => flatTree(this.trees, id)));
443
+ const dirs = flat.map(directoriesOf);
444
+ const bases = flat.slice(0, -2);
445
+ const indexEntries = /* @__PURE__ */ new Map();
446
+ for (const e of await this.entryList()) if (e.stage === 0) indexEntries.set(e.path, e);
447
+ const checkedWorktree = ctx.worktree;
448
+ const worktree = this.update ? checkedWorktree : void 0;
449
+ const sparse = worktree && !this.skipSparseCheckout ? await SparseUnpack.start(ctx) : void 0;
450
+ const quiet = (p) => sparse?.leavesAlone(p) === true;
451
+ const trust = checkedWorktree ? worktreeModeTrust(this.workingCopy, checkedWorktree) : void 0;
452
+ const indexTime = this.staging.getUpdateTime();
453
+ const folding = await this.caseFolding(worktree, indexEntries);
454
+ const caseVariants = [];
455
+ const paths = new Set(indexEntries.keys());
456
+ for (const m of flat) for (const p of m.keys()) paths.add(p);
457
+ const sorted = traversalOrder(paths);
458
+ /** The entry tree `k` stands with at `path` (df_conflict_entry, a file, or none). */
459
+ const stageOf = (k, path, anyTree) => {
460
+ const m = flat[k];
461
+ const e = m.get(path);
462
+ if (e) return e;
463
+ if (!anyTree) return void 0;
464
+ if (dirs[k].has(path)) return DF_CONFLICT;
465
+ for (let at = path.indexOf("/"); at >= 0; at = path.indexOf("/", at + 1)) if (m.has(path.slice(0, at))) return DF_CONFLICT;
466
+ };
467
+ const changes = /* @__PURE__ */ new Map();
468
+ const writes = /* @__PURE__ */ new Set();
469
+ const removes = /* @__PURE__ */ new Set();
470
+ const conflicted = [];
471
+ let nontrivial = false;
472
+ const fail = (message, path) => {
473
+ throw new ReadTreeFailedError(message, [path]);
474
+ };
475
+ const verifyUptodate = async (old) => {
476
+ if (!checkedWorktree || quiet(old.path)) return;
477
+ if (await entryNotUptodate(checkedWorktree, old.path, old, trust, indexTime)) fail(`error: Entry '${old.path}' not uptodate. Cannot merge.`, old.path);
478
+ };
479
+ const removedHere = (p) => removes.has(p);
480
+ const absent = async (path, kind) => {
481
+ if (!worktree || quiet(path)) return;
482
+ const error = await verifyAbsent(worktree, path, (p) => indexEntries.has(p), kind, {
483
+ leadingOk: removedHere,
484
+ folding,
485
+ caseVariants
486
+ });
487
+ if (error) fail(error, path);
488
+ };
489
+ const absentIfDirectory = async (path, old) => {
490
+ if (!worktree || quiet(path) || old.skipWorktree || sparse?.outside(path)) return;
491
+ const entry = await worktree.getEntry(path).catch(() => void 0);
492
+ if (!entry?.isDirectory || entry.mode === FileMode.GITLINK) return;
493
+ if (await untrackedUnder(worktree, path, (p) => indexEntries.has(p))) fail(plainUnpackError("lostDir", path), path);
494
+ };
495
+ const mergedEntry = async (ce, old, path) => {
496
+ if (!old) {
497
+ await absent(path, "untracked");
498
+ changes.set(path, [{
499
+ path,
500
+ objectId: ce.objectId,
501
+ mode: ce.mode,
502
+ size: 0,
503
+ mtime: 0
504
+ }]);
505
+ writes.add(path);
506
+ return;
507
+ }
508
+ if (same(old, ce)) return;
509
+ await verifyUptodate(old);
510
+ changes.set(path, [{
511
+ path,
512
+ objectId: ce.objectId,
513
+ mode: ce.mode,
514
+ size: 0,
515
+ mtime: 0,
516
+ ...old.skipWorktree ? { skipWorktree: true } : {}
517
+ }]);
518
+ writes.add(path);
519
+ };
520
+ const deletedEntry = async (old, path) => {
521
+ await absentIfDirectory(path, old);
522
+ await verifyUptodate(old);
523
+ changes.set(path, []);
524
+ removes.add(path);
525
+ };
526
+ for (const path of sorted) {
527
+ const index = indexEntries.get(path);
528
+ const anyTree = flat.some((m) => m.has(path)) || dirs.some((d) => d.has(path));
529
+ const stages = bases.map((_, k) => stageOf(k, path, anyTree));
530
+ let h = stageOf(flat.length - 2, path, anyTree);
531
+ let r = stageOf(flat.length - 1, path, anyTree);
532
+ const anyAncMissing = stages.some((s) => !s || s === DF_CONFLICT);
533
+ const noAncExists = stages.every((s) => !s || s === DF_CONFLICT);
534
+ const dfHead = h === DF_CONFLICT;
535
+ const dfRemote = r === DF_CONFLICT;
536
+ if (dfHead) h = void 0;
537
+ if (dfRemote) r = void 0;
538
+ let headMatch = 0;
539
+ let remoteMatch = 0;
540
+ if (!same(r, h)) stages.forEach((s, k) => {
541
+ if (same(s, h)) headMatch = k + 1;
542
+ if (same(s, r)) remoteMatch = k + 1;
543
+ });
544
+ if (r && !dfHead && headMatch && !remoteMatch) {
545
+ if (index && !same(index, r) && !same(index, h)) fail(`error: Entry '${path}' would be overwritten by merge. Cannot merge.`, path);
546
+ await mergedEntry(r, index, path);
547
+ continue;
548
+ }
549
+ if (index && !same(index, h)) fail(`error: Entry '${path}' would be overwritten by merge. Cannot merge.`, path);
550
+ if (h) {
551
+ if (same(h, r)) {
552
+ await mergedEntry(h, index, path);
553
+ continue;
554
+ }
555
+ if (!dfRemote && remoteMatch && !headMatch) {
556
+ await mergedEntry(h, index, path);
557
+ continue;
558
+ }
559
+ }
560
+ if (!h && !r && anyAncMissing) continue;
561
+ if (this.aggressive) {
562
+ const headDeleted = !h;
563
+ const remoteDeleted = !r;
564
+ const ce = index ?? h ?? r ?? stages.find((s) => s && s !== DF_CONFLICT);
565
+ if (headDeleted && remoteDeleted || headDeleted && r && remoteMatch || remoteDeleted && h && headMatch) {
566
+ if (index) {
567
+ await deletedEntry(index, path);
568
+ continue;
569
+ }
570
+ if (ce && !headDeleted) await absent(path, "untrackedRemoved");
571
+ continue;
572
+ }
573
+ if (noAncExists && h && r && same(h, r)) {
574
+ await mergedEntry(h, index, path);
575
+ continue;
576
+ }
577
+ }
578
+ if (index) await verifyUptodate(index);
579
+ nontrivial = true;
580
+ const list = [];
581
+ if (!headMatch || !remoteMatch) {
582
+ const base = stages.find((s) => s !== void 0 && s !== DF_CONFLICT);
583
+ if (base) list.push({
584
+ path,
585
+ objectId: base.objectId,
586
+ mode: base.mode,
587
+ stage: 1
588
+ });
589
+ }
590
+ if (h) list.push({
591
+ path,
592
+ objectId: h.objectId,
593
+ mode: h.mode,
594
+ stage: 2
595
+ });
596
+ if (r) list.push({
597
+ path,
598
+ objectId: r.objectId,
599
+ mode: r.mode,
600
+ stage: 3
601
+ });
602
+ for (const e of list) Object.assign(e, {
603
+ size: 0,
604
+ mtime: 0
605
+ });
606
+ changes.set(path, list);
607
+ conflicted.push(path);
608
+ }
609
+ if (this.trivial && nontrivial) throw new ReadTreeFailedError("error: Merge requires file-level merging");
610
+ const stage0 = /* @__PURE__ */ new Set();
611
+ for (const p of indexEntries.keys()) if (!changes.has(p)) stage0.add(p);
612
+ for (const [p, list] of changes) if (list.some((e) => !e.stage)) stage0.add(p);
613
+ assertNoStageZeroClash(stage0);
614
+ if (this.dryRun) return;
615
+ sparse?.conflict(conflicted);
616
+ const target = /* @__PURE__ */ new Map();
617
+ for (const path of writes) {
618
+ const e = changes.get(path)?.[0];
619
+ if (e) target.set(path, e);
620
+ }
621
+ const writing = new Set([...writes].filter((p) => !sparse || sparse.writes(p)));
622
+ if (worktree) {
623
+ if (sparse) {
624
+ const unlink = await sparse.leaving(worktree, (p) => removes.has(p) ? void 0 : target.get(p) ?? indexEntries.get(p), { trust });
625
+ await sparse.unlink(worktree, unlink);
626
+ }
627
+ for (const path of removes) {
628
+ if (quiet(path)) continue;
629
+ const entry = await worktree.getEntry(path);
630
+ if (entry && !entry.isDirectory) {
631
+ await worktree.remove(path);
632
+ await pruneEmptyParents(worktree, path);
633
+ }
634
+ }
635
+ await removeCaseVariants(worktree, caseVariants);
636
+ if (writing.size > 0) await this.writeFiles(ctx, worktree, target, writing, indexEntries);
637
+ for (const path of writing) {
638
+ const stat = await worktree.getEntry(path);
639
+ const e = changes.get(path)?.[0];
640
+ if (e && stat && !stat.isDirectory) Object.assign(e, entryStatOf(stat));
641
+ }
642
+ }
643
+ await rewriteIndex(this.staging, changes);
644
+ if (sparse && worktree) {
645
+ const outcome = await sparse.finish(ctx, { written: worktree ? writing : /* @__PURE__ */ new Set() });
646
+ pushSparseWarnings(result.warnings, sparse, outcome, false);
647
+ }
648
+ }
649
+ };
650
+ /** unpack-trees' `df_conflict_entry`: mode 0, no id; matches only itself, never a stage. */
651
+ const DF_CONFLICT = Object.freeze({
652
+ objectId: "",
653
+ mode: 0
654
+ });
655
+ /** The directories a flat tree holds (every leading path of its files). */
656
+ function directoriesOf(tree) {
657
+ const out = /* @__PURE__ */ new Set();
658
+ for (const p of tree.keys()) for (let at = p.indexOf("/"); at >= 0; at = p.indexOf("/", at + 1)) out.add(p.slice(0, at));
659
+ return out;
660
+ }
661
+ /**
662
+ * `paths` in `traverse_trees` order: the index's (a directory named as `<name>/`), except
663
+ * that a directory some path also names as a file comes right after that file (unpack-trees
664
+ * looks ahead for it), before the names that sort between the two.
665
+ */
666
+ function traversalOrder(paths) {
667
+ const all = new Set(paths);
668
+ const keys = /* @__PURE__ */ new Map();
669
+ const keyOf = (path) => {
670
+ let key = keys.get(path);
671
+ if (!key) {
672
+ const parts = path.split("/");
673
+ key = parts.map((part, k) => k < parts.length - 1 && !all.has(parts.slice(0, k + 1).join("/")) ? `${part}/` : part);
674
+ keys.set(path, key);
675
+ }
676
+ return key;
677
+ };
678
+ return [...all].sort((a, b) => {
679
+ const x = keyOf(a);
680
+ const y = keyOf(b);
681
+ for (let k = 0; k < Math.min(x.length, y.length); k++) {
682
+ const c = compareGitPaths(x[k], y[k]);
683
+ if (c !== 0) return c;
684
+ }
685
+ return x.length - y.length;
686
+ });
687
+ }
688
+ /**
689
+ * The last guard before an index is written: no stage-0 path may also be a leading
690
+ * directory of another (git's `add_index_entry` never leaves one; a tree written from such an
691
+ * index would hold two entries of one name).
692
+ */
693
+ function assertNoStageZeroClash(paths) {
694
+ for (const path of paths) for (let at = path.indexOf("/"); at >= 0; at = path.indexOf("/", at + 1)) {
695
+ const dir = path.slice(0, at);
696
+ if (paths.has(dir)) throw new ReadTreeFailedError(`fatal: BUG: the index would hold both '${dir}' and '${path}'`, [dir, path]);
697
+ }
698
+ }
699
+ /**
700
+ * unpack-trees' `verify_absent` of a path the merge adds (or, `untrackedRemoved`, removes)
701
+ * with no index entry there: an untracked file or link in the way (ignored files are
702
+ * expendable: `preserve_ignored` is off with `-u`), or a directory holding untracked files.
703
+ * A file in place of a leading directory is in the way even when tracked, unless the merge
704
+ * removes its entry (`leadingOk`: `check_ok_to_remove` finds it `CE_REMOVE` in the result).
705
+ * Returns git's plain message, or undefined.
706
+ */
707
+ async function verifyAbsent(worktree, path, tracked, kind, options = {}) {
708
+ const parts = path.split("/");
709
+ for (let k = 1; k < parts.length; k++) {
710
+ const prefix = parts.slice(0, k).join("/");
711
+ const entry = await worktree.getEntry(prefix).catch(() => void 0);
712
+ if (!entry) return void 0;
713
+ if (entry.isDirectory) continue;
714
+ if (options.leadingOk?.(prefix) || await worktree.isIgnored(prefix)) return void 0;
715
+ if (await options.folding?.exists(worktree, prefix, entry)) return void 0;
716
+ return firstPlainError({ [kind]: [prefix] });
717
+ }
718
+ const entry = await worktree.getEntry(path).catch(() => void 0);
719
+ if (!entry) return void 0;
720
+ if (entry.isDirectory) {
721
+ if (entry.mode === FileMode.GITLINK) return void 0;
722
+ const variants = options.caseVariants ? options.folding?.variants() : void 0;
723
+ if (await untrackedUnder(worktree, path, tracked, false, variants)) return firstPlainError({ lostDir: [path] });
724
+ if (variants) options.caseVariants?.push(...variants.found);
725
+ return;
726
+ }
727
+ if (await worktree.isIgnored(path)) return void 0;
728
+ if (await options.folding?.exists(worktree, path, entry)) return void 0;
729
+ return firstPlainError({ [kind]: [path] });
730
+ }
731
+ //#endregion
732
+ //#region src/commands/local-transport.ts
733
+ /**
734
+ * git's local transport: a repository named by a path (or a `file://` URL) is opened through
735
+ * the working copy's storage and served by upload-pack (or receive-pack) in process, over an
736
+ * in-memory duplex, where git spawns `git-upload-pack '<path>'`. Which transport a URL takes
737
+ * is decided in `remote-transport.ts` (`resolveRemote`).
738
+ */
739
+ /** The client's lines when the remote end of a local transport died. */
740
+ 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.";
741
+ const NOT_A_REPOSITORY = (path) => `fatal: '${path}' does not appear to be a git repository\n${COULD_NOT_READ}`;
742
+ /**
743
+ * A connected pair of in-memory duplex streams: what one side writes, the other reads. `end`
744
+ * half-closes a side (the other one reads to its end and can still answer); `close` ends it.
745
+ */
746
+ function createDuplexPair() {
747
+ const make = () => {
748
+ const queue = [];
749
+ let ended = false;
750
+ let wake;
751
+ const push = (chunk) => {
752
+ if (chunk === null) ended = true;
753
+ else queue.push(chunk);
754
+ wake?.();
755
+ wake = void 0;
756
+ };
757
+ async function* read() {
758
+ while (true) {
759
+ const next = queue.shift();
760
+ if (next) {
761
+ yield next;
762
+ continue;
763
+ }
764
+ if (ended) return;
765
+ await new Promise((resolve) => {
766
+ wake = resolve;
767
+ });
768
+ }
769
+ }
770
+ return {
771
+ push,
772
+ read
773
+ };
774
+ };
775
+ const a = make();
776
+ const b = make();
777
+ let aClosed = false;
778
+ let bClosed = false;
779
+ const endLeft = async () => {
780
+ if (aClosed) return;
781
+ aClosed = true;
782
+ b.push(null);
783
+ };
784
+ const endRight = async () => {
785
+ if (bClosed) return;
786
+ bClosed = true;
787
+ a.push(null);
788
+ };
789
+ return [{
790
+ [Symbol.asyncIterator]: () => a.read()[Symbol.asyncIterator](),
791
+ write: (data) => {
792
+ if (!aClosed) b.push(data.slice());
793
+ },
794
+ end: endLeft,
795
+ close: endLeft
796
+ }, {
797
+ [Symbol.asyncIterator]: () => b.read()[Symbol.asyncIterator](),
798
+ write: (data) => {
799
+ if (!bClosed) a.push(data.slice());
800
+ },
801
+ end: endRight,
802
+ close: endRight
803
+ }];
804
+ }
805
+ /**
806
+ * Opens the repository a local remote names (see `Worktree.openRepository`), or throws
807
+ * git's "does not appear to be a git repository" lines (exit 128).
808
+ */
809
+ async function openLocalRemote(workingCopy, path) {
810
+ const opened = await repositoryPlaceOf(workingCopy)?.openRepository?.(path, {
811
+ checkOwnership: false,
812
+ commandLineConfig: false
813
+ }).catch(() => void 0);
814
+ if (!opened) throw new TransportError$1(NOT_A_REPOSITORY(path));
815
+ return opened;
816
+ }
817
+ /**
818
+ * Runs `run` over a connection to upload-pack serving a local repository (opened by
819
+ * {@link openLocalRemote}) with protocol v2, git's default `protocol.version` (v0 when the
820
+ * option says 0, v1 when it says 1), as git's local transport runs `git-upload-pack '<path>'`,
821
+ * in process.
822
+ */
823
+ async function withLocalUploadPack(remote, run, options = {}) {
824
+ const head = await remote.history.refs.get("HEAD").catch(() => void 0);
825
+ const settings = serverSettingsOf(remote);
826
+ const [client, server] = createDuplexPair();
827
+ const serving = (async () => serveOverDuplex({
828
+ duplex: server,
829
+ repository: createRepositoryFacade({
830
+ history: historyWithoutLazyFetch(remote.history),
831
+ useBitmaps: servedUseBitmaps(remote),
832
+ sparseFilterPatterns: sparseFilterMatcher,
833
+ maxTreeDepth: servedMaxTreeDepth(remote)
834
+ }),
835
+ refStore: createTransportRefStore(remote.history.refs),
836
+ service: "git-upload-pack",
837
+ ...(options.protocolVersion ?? 2) === 2 ? { protocolVersion: "2" } : {},
838
+ ...options.protocolVersion === 1 ? { announceVersion1: true } : {},
839
+ uploadPackHideRefs: settings.uploadPackHideRefs,
840
+ ...settings.uploadPackFilter ? { uploadPackFilter: settings.uploadPackFilter } : {},
841
+ ...head && "target" in head ? { currentBranch: head.target } : {}
842
+ }))().finally(() => server.close?.());
843
+ try {
844
+ const connection = await openDuplexConnection(client, { closeDuplex: true });
845
+ try {
846
+ return await run(connection);
847
+ } catch (error) {
848
+ throw packFailure(error) ?? error;
849
+ } finally {
850
+ await connection.close();
851
+ }
852
+ } finally {
853
+ await client.close?.();
854
+ await serving.catch(() => void 0);
855
+ }
856
+ }
857
+ /**
858
+ * The lines git prints when upload-pack's pack-objects fails on an object it cannot read
859
+ * (upload-pack.c's create_pack_file): its own error and death (upload-pack's stderr, which
860
+ * the local transport shares), the abort message it sends on band 3, then the client's
861
+ * deaths. The pack failure reaches the client as a band-3 `ERR <reason>` (`sendPackStream`).
862
+ */
863
+ function packFailure(error) {
864
+ const message = error instanceof Error ? error.message : "";
865
+ if (!(error instanceof Error) || error.name !== "ServerError" || !message.startsWith("ERR ")) return;
866
+ const abort = "aborting due to possible repository corruption on the remote side.";
867
+ return new TransportError$1([
868
+ "error: git upload-pack: git-pack-objects died with error.",
869
+ `fatal: git upload-pack: ${abort}`,
870
+ `remote: ${abort}`,
871
+ "fatal: early EOF",
872
+ "fatal: fetch-pack: invalid index-pack output"
873
+ ].join("\n"), void 0, { cause: error });
874
+ }
875
+ /** git's defaults, for a repository whose configuration cannot be read. */
876
+ const DEFAULT_SETTINGS = {
877
+ allowDeletes: true,
878
+ allowNonFastForward: true,
879
+ denyCurrentBranch: "unconfigured",
880
+ denyDeleteCurrent: "unconfigured",
881
+ shallowUpdate: false,
882
+ advertisePushOptions: false,
883
+ uploadPackHideRefs: [],
884
+ receivePackHideRefs: []
885
+ };
886
+ /**
887
+ * The served repository's `pack.useBitmaps` (default true): its pack-objects (upload-pack's)
888
+ * lists through a bitmap only while it allows.
889
+ */
890
+ function servedUseBitmaps(remote) {
891
+ const value = remote.config?.getAll("pack.useBitmaps").at(-1);
892
+ if (value === void 0 || value === null) return true;
893
+ return parseGitBool(String(value)) ?? true;
894
+ }
895
+ /**
896
+ * The served repository's `core.maxTreeDepth` (git's repo settings, default 2048): its
897
+ * pack-objects dies on a deeper tree. Undefined when unset or unreadable (the default then).
898
+ */
899
+ function servedMaxTreeDepth(remote) {
900
+ const value = remote.config?.getAll("core.maxTreeDepth").at(-1);
901
+ if (value === void 0 || value === null) return void 0;
902
+ return parseGitInt(value);
903
+ }
904
+ /** What git's upload-pack and receive-pack read from the served repository's config. */
905
+ function serverSettingsOf(remote) {
906
+ const config = remote.config;
907
+ if (!config) return DEFAULT_SETTINGS;
908
+ const listWithOrigin = config.listWithOrigin?.bind(config);
909
+ if (!listWithOrigin) return serverSettingsFromConfig(config);
910
+ const gitDir = `${remote.gitDir.replace(/^\/+/, "").replace(/\/+$/, "")}/`;
911
+ return serverSettingsFromConfig({
912
+ getAll: (key) => config.getAll(key),
913
+ list: () => config.list(),
914
+ listWithOrigin: () => listWithOrigin().map((e) => e.file?.replace(/^\/+/, "").startsWith(gitDir) ? {
915
+ ...e,
916
+ file: e.file.replace(/^\/+/, "").slice(gitDir.length)
917
+ } : e)
918
+ });
919
+ }
920
+ /**
921
+ * The branches the HEAD of a non-bare worktree of the repository uses, the main one and
922
+ * every linked one (git's `find_shared_symref(get_worktrees(), "HEAD", ref)`, a worktree
923
+ * being rebased or bisected on a branch included); undefined without the worktree list.
924
+ */
925
+ async function checkedOutBranches(worktrees) {
926
+ if (!worktrees) return void 0;
927
+ const list = await worktrees.list().catch(() => void 0);
928
+ if (!list) return void 0;
929
+ const out = /* @__PURE__ */ new Set();
930
+ for (const wt of list) for (const ref of [
931
+ wt.headRef,
932
+ wt.rebasing,
933
+ wt.bisecting
934
+ ]) if (ref !== void 0 && usesBranch(wt, ref)) out.add(ref);
935
+ return [...out];
936
+ }
937
+ /**
938
+ * receive.denyCurrentBranch=updateInstead (receive-pack.c's `update_worktree`, without the
939
+ * push-to-checkout hook: `push_to_deploy`): the worktree that has `ref` checked out is
940
+ * refused while it has unstaged or staged changes, else brought to `newOid` by
941
+ * `read-tree -u -m`; the ref itself is updated afterwards by receive-pack.
942
+ *
943
+ * @returns the refusal reason, as git reports it; undefined when the worktree was updated
944
+ */
945
+ async function pushToDeploy(worktrees, ref, newOid) {
946
+ const wt = await worktreeUsingBranch(worktrees, ref);
947
+ if (!wt) return "denyCurrentBranch = updateInstead needs a worktree";
948
+ let workingCopy;
949
+ try {
950
+ workingCopy = await worktrees.open(wt);
951
+ } catch {
952
+ return "Up-to-date check failed";
953
+ }
954
+ const status = await new StatusCommand(workingCopy).setUntrackedFiles("no").setIgnoreSubmodules("all").call();
955
+ if (status.modified.size > 0 || status.missing.size > 0 || status.conflicting.size > 0) return "Working directory has unstaged changes";
956
+ if (status.added.size > 0 || status.changed.size > 0 || status.removed.size > 0) return "Working directory has staged changes";
957
+ try {
958
+ await new ReadTreeCommand(workingCopy).addTree(newOid).setMerge(true).setUpdate(true).call();
959
+ } catch {
960
+ return "Could not update working tree to new HEAD";
961
+ }
962
+ }
963
+ /**
964
+ * Runs `run` over a connection to receive-pack serving a local repository (opened by
965
+ * {@link openLocalRemote}), as git's local transport runs `git-receive-pack '<path>'`, in
966
+ * process: the pushed objects go into that repository and its refs are updated there, under
967
+ * the settings git's receive-pack reads from that repository's config (see
968
+ * `serverSettingsFromConfig`: deletes, forced updates, the current branch, hidden refs,
969
+ * shallow updates). A branch checked out in any non-bare worktree of it, linked ones
970
+ * included, is the current branch `receive.denyCurrentBranch` rules on.
971
+ */
972
+ async function withLocalReceivePack(remote, run, hooks, transactionHooks = hooks, options = {}) {
973
+ try {
974
+ await remote.checkOwnership?.();
975
+ } catch (error) {
976
+ if (error instanceof Error && error.name === "DubiousOwnershipError") throw new TransportError$1(`${error.message}\n${COULD_NOT_READ}`);
977
+ throw error;
978
+ }
979
+ const receiveHooks = hooks?.enabled ? scriptReceiveHooks(hooks) : void 0;
980
+ return withReceiveTransactionHook(remote, transactionHooks, () => receiveOver(remote, run, hooks, receiveHooks, options.protocolVersion === 1, options));
981
+ }
982
+ /**
983
+ * The receive-side reference-transaction hooks installed on a ref store, oldest first, and
984
+ * the hook the store had before the first of them: overlapping receive-packs on one store
985
+ * (two served pushes at once) each put theirs in and take theirs out, whatever the order
986
+ * they end in, and the last one out puts back the store's own.
987
+ */
988
+ const receiveTransactionHooks = /* @__PURE__ */ new WeakMap();
989
+ /**
990
+ * Runs `body` with the reference-transaction hook of `hooks` (a receiving repository's
991
+ * session) installed on `remote`'s ref store, as git's receive-pack runs it: in the git
992
+ * directory with `GIT_DIR=.` and no `GIT_PREFIX`. The hook that was there before is put
993
+ * back after (once every overlapping receive on the store has ended). Without a hook
994
+ * runner, or a ref store that cannot take one, `body` alone.
995
+ */
996
+ async function withReceiveTransactionHook(remote, hooks, body) {
997
+ const store = remote.history.refs;
998
+ if (!hooks?.enabled || store.setTransactionHook === void 0) return body();
999
+ const transactionHook = refTransactionHookOf(hooks, {
1000
+ env: { GIT_DIR: "." },
1001
+ prefix: false
1002
+ });
1003
+ let installed = receiveTransactionHooks.get(store);
1004
+ if (!installed) {
1005
+ installed = {
1006
+ active: [],
1007
+ previous: store.getTransactionHook?.()
1008
+ };
1009
+ receiveTransactionHooks.set(store, installed);
1010
+ }
1011
+ installed.active.push(transactionHook);
1012
+ store.setTransactionHook(transactionHook);
1013
+ try {
1014
+ return await body();
1015
+ } finally {
1016
+ const { active, previous } = installed;
1017
+ active.splice(active.indexOf(transactionHook), 1);
1018
+ const current = store.getTransactionHook?.();
1019
+ const ours = current === transactionHook || current === void 0;
1020
+ if (active.length === 0) {
1021
+ receiveTransactionHooks.delete(store);
1022
+ if (ours) store.setTransactionHook(previous);
1023
+ } else if (ours) store.setTransactionHook(active[active.length - 1]);
1024
+ }
1025
+ }
1026
+ /**
1027
+ * receive-pack's `receive.fsckObjects` / `transfer.fsckObjects` settings of the repository it
1028
+ * serves (`receiveFsckOf`): skip lists named by a relative path are read from its git
1029
+ * directory (receive-pack's working directory), absolute ones from the host; with
1030
+ * `confineFiles` (a served repository) only files inside its own git directories, where their
1031
+ * links lead and capped as confined includes (`readConfinedFile`), anything else unreadable.
1032
+ */
1033
+ function receiveFsckSettingsOf(remote, host = {}) {
1034
+ const config = remote.config;
1035
+ if (!config) return { warnings: [] };
1036
+ const gitDir = remote.gitDir.replace(/^\/+/, "").replace(/\/+$/, "");
1037
+ const files = remote.files;
1038
+ const environment = host.environment;
1039
+ const listWithOrigin = config.listWithOrigin?.bind(config);
1040
+ const entries = () => listWithOrigin ? listWithOrigin().map((e) => e.file?.replace(/^\/+/, "").startsWith(`${gitDir}/`) ? {
1041
+ ...e,
1042
+ file: e.file.replace(/^\/+/, "").slice(gitDir.length + 1)
1043
+ } : e) : config.list();
1044
+ if (host.confineFiles) {
1045
+ const roots = [gitDir];
1046
+ const common = remote.commonDir?.replace(/^\/+/, "").replace(/\/+$/, "");
1047
+ if (common !== void 0 && common !== gitDir) roots.push(common);
1048
+ const confined = files ? configFilesApiOf(files) : void 0;
1049
+ return receiveFsckOf({
1050
+ entries,
1051
+ compatibility: host.compatibility ?? "2.56",
1052
+ readFile: async (path) => confined ? readConfinedFile(confined, path, {
1053
+ baseDir: gitDir,
1054
+ roots
1055
+ }).catch(() => void 0) : void 0
1056
+ });
1057
+ }
1058
+ return receiveFsckOf({
1059
+ entries,
1060
+ compatibility: host.compatibility ?? "2.56",
1061
+ ...environment?.home ? { home: environment.home } : {},
1062
+ readFile: async (path) => {
1063
+ if (path.startsWith("/") && environment) return environment.readFile(path);
1064
+ if (!files) return void 0;
1065
+ const full = path.startsWith("/") ? path : `${gitDir}/${path}`;
1066
+ if ((await files.stats(full).catch(() => void 0))?.kind !== "file") return void 0;
1067
+ return readFile$1(files, full);
1068
+ }
1069
+ });
1070
+ }
1071
+ /**
1072
+ * The settings git's receive-pack takes from the repository it serves: the policies and hidden
1073
+ * refs of its config (`serverSettingsFromConfig`), its current branch and the branches its
1074
+ * worktrees have checked out, `updateInstead` (push-to-checkout, push-to-deploy), the fsck of
1075
+ * pushed objects (`receive.fsckObjects`, {@link receiveFsckSettingsOf}) and, with hooks,
1076
+ * pre-receive / update / post-receive run as git's receive-pack runs them.
1077
+ */
1078
+ async function receivePackSettingsOf(remote, hooks, receiveHooks = hooks?.enabled ? scriptReceiveHooks(hooks) : void 0, host = {}) {
1079
+ const head = await remote.history.refs.get("HEAD").catch(() => void 0);
1080
+ const settings = serverSettingsOf(remote);
1081
+ const fsck = receiveFsckSettingsOf(remote, {
1082
+ compatibility: hooks?.compatibility,
1083
+ ...host
1084
+ });
1085
+ const configError = settings.receivePackConfigError ?? fsck.configError;
1086
+ const checkedOut = await checkedOutBranches(remote.worktrees);
1087
+ const worktrees = remote.worktrees;
1088
+ return {
1089
+ bare: remote.bare,
1090
+ ...head && "target" in head ? { currentBranch: head.target } : {},
1091
+ allowDeletes: settings.allowDeletes,
1092
+ allowNonFastForward: settings.allowNonFastForward,
1093
+ denyCurrentBranch: settings.denyCurrentBranch,
1094
+ denyDeleteCurrent: settings.denyDeleteCurrent,
1095
+ shallowUpdate: settings.shallowUpdate,
1096
+ advertisePushOptions: settings.advertisePushOptions,
1097
+ uploadPackHideRefs: settings.uploadPackHideRefs,
1098
+ receivePackHideRefs: settings.receivePackHideRefs,
1099
+ ...receiveHooks ? {
1100
+ hooks: receiveHooks,
1101
+ relayPostReceive: true
1102
+ } : {},
1103
+ publishBeforeUpdate: true,
1104
+ preReceiveSeesRefused: true,
1105
+ ...settings.procReceiveRefs?.length ? { procReceiveRefs: settings.procReceiveRefs } : {},
1106
+ ...configError !== void 0 ? { receivePackConfigError: configError } : {},
1107
+ ...fsck.fsckObjects ? { fsckObjects: fsck.fsckObjects } : {},
1108
+ ...hooks?.enabled && hooks.compatibility !== "2.43" ? { batchNonAtomic: true } : {},
1109
+ ...hooks?.enabled && hooks.compatibility === "2.43" ? { interleaveUpdateHook: true } : {},
1110
+ ...checkedOut ? { checkedOutBranches: checkedOut } : {},
1111
+ ...worktrees ? { updateWorktree: async (ref, newOid, ctx) => {
1112
+ const verdict = await pushToCheckout(hooks, worktrees, ref, newOid, ctx);
1113
+ return verdict === null ? pushToDeploy(worktrees, ref, newOid) : verdict;
1114
+ } } : {}
1115
+ };
1116
+ }
1117
+ async function receiveOver(remote, run, hooks, receiveHooks, version1, options = {}) {
1118
+ const [client, server] = createDuplexPair();
1119
+ const host = options.host ?? {};
1120
+ const settings = await receivePackSettingsOf(remote, hooks, receiveHooks, host);
1121
+ if (options.onWarning) for (const line of receiveFsckSettingsOf(remote, host).warnings) options.onWarning(line);
1122
+ const serving = serveOverDuplex({
1123
+ ...settings,
1124
+ duplex: server,
1125
+ repository: createRepositoryFacade({
1126
+ history: historyWithoutLazyFetch(remote.history),
1127
+ useBitmaps: servedUseBitmaps(remote),
1128
+ sparseFilterPatterns: sparseFilterMatcher,
1129
+ maxTreeDepth: servedMaxTreeDepth(remote)
1130
+ }),
1131
+ refStore: createTransportRefStore(remote.history.refs),
1132
+ service: "git-receive-pack",
1133
+ ...version1 ? { announceVersion1: true } : {}
1134
+ }).finally(() => server.close?.());
1135
+ const died = async (cause) => {
1136
+ await client.close?.();
1137
+ const served = await serving.catch(() => void 0);
1138
+ if (!served?.error?.startsWith("fatal: ")) return void 0;
1139
+ return new TransportError$1(`${served.error}\nsend-pack: unexpected disconnect while reading sideband packet\nfatal: the remote end hung up unexpectedly`, void 0, cause === void 0 ? void 0 : { cause });
1140
+ };
1141
+ try {
1142
+ const connection = await openDuplexReceivePackConnection(client, { closeDuplex: true });
1143
+ let value;
1144
+ try {
1145
+ value = await run(connection);
1146
+ } finally {
1147
+ await connection.close();
1148
+ }
1149
+ const death = await died();
1150
+ if (death) throw death;
1151
+ return value;
1152
+ } catch (error) {
1153
+ const early = settings.receivePackConfigError;
1154
+ if (early !== void 0) {
1155
+ await client.close?.();
1156
+ await serving.catch(() => void 0);
1157
+ throw new TransportError$1(`${early}\nfatal: Could not read from remote repository.\n\nPlease make sure you have the correct access rights
1158
+ and the repository exists.`, void 0, { cause: error });
1159
+ }
1160
+ if (error instanceof TransportError$1) throw error;
1161
+ throw await died(error) ?? error;
1162
+ } finally {
1163
+ await client.close?.();
1164
+ await serving.catch(() => void 0);
1165
+ }
1166
+ }
1167
+ /**
1168
+ * The hooks of a repository a local push reaches (git's receive-pack runs them there): found
1169
+ * in its git directory (or its `core.hooksPath`), run in its git directory, through the host
1170
+ * environment of the working copy pushing. Undefined without a runner or a FilesApi.
1171
+ *
1172
+ * With `localPush` (a push to a path: git's connect.c starts receive-pack with
1173
+ * `local_repo_env` cleared), the hooks run without the pushing side's repository variables
1174
+ * ({@link LOCAL_REPO_ENV}: `GIT_ALTERNATE_OBJECT_DIRECTORIES`, `GIT_DIR`, `GIT_INDEX_FILE`,
1175
+ * `GIT_CONFIG_COUNT`, ...), so a quarantined pre-receive's alternates name the receiving
1176
+ * repository's objects alone. Without it (a served push over HTTP or git://, where the
1177
+ * server's own environment is receive-pack's) the host's variables reach them.
1178
+ */
1179
+ function remoteHookSession(workingCopy, remote, options = {}) {
1180
+ const local = hookHostOf(workingCopy);
1181
+ if (!local.environment()?.hookRunner) return void 0;
1182
+ let files;
1183
+ try {
1184
+ files = repositoryPlaceOf(workingCopy)?.getFiles?.();
1185
+ } catch {
1186
+ files = void 0;
1187
+ }
1188
+ if (!files) return void 0;
1189
+ const gitDir = remote.gitDir.replace(/^\/+/, "").replace(/\/+$/, "");
1190
+ const top = !remote.bare && gitDir.endsWith("/.git") ? gitDir.slice(0, -5) : gitDir;
1191
+ const setting = (key) => {
1192
+ const values = remote.config?.getAll(key) ?? [];
1193
+ const last = values[values.length - 1];
1194
+ return last === null ? "" : last;
1195
+ };
1196
+ return new HookSession({
1197
+ layout: async () => ({
1198
+ files,
1199
+ top,
1200
+ gitDir,
1201
+ cwd: gitDir,
1202
+ bare: remote.bare
1203
+ }),
1204
+ configValue: setting,
1205
+ environment: () => local.environment(),
1206
+ ...options.localPush ? { unsetEnv: LOCAL_REPO_ENV } : {},
1207
+ hookSettings: () => {
1208
+ const config = remote.config;
1209
+ if (!config) return [];
1210
+ return hookSettingsFromEntries(config.listWithOrigin?.() ?? config.list());
1211
+ }
1212
+ });
1213
+ }
1214
+ /**
1215
+ * receive-pack's `push_to_checkout` (`receive.denyCurrentBranch=updateInstead`): when the
1216
+ * push-to-checkout hook exists it updates the worktree in place of git's own push-to-deploy,
1217
+ * told the pushed commit, with `GIT_DIR` and `GIT_WORK_TREE` the worktree's (absolute):
1218
+ * undefined when it accepts, git's "push-to-checkout hook declined" when it refuses; null
1219
+ * when there is no hook (push-to-deploy decides).
1220
+ */
1221
+ async function pushToCheckout(hooks, worktrees, ref, newOid, ctx) {
1222
+ if (!hooks?.enabled || !await hooks.exists("push-to-checkout")) return null;
1223
+ const wt = await worktreeUsingBranch(worktrees, ref);
1224
+ if (!wt || wt.bare) return "denyCurrentBranch = updateInstead needs a worktree";
1225
+ const gitDir = await hooks.hostGitDir();
1226
+ const env = {
1227
+ ...hookClientEnv(hooks, ctx),
1228
+ GIT_WORK_TREE: wt.path
1229
+ };
1230
+ if (gitDir) env.GIT_DIR = wt.id ? `${gitDir}/worktrees/${wt.id}` : `${gitDir}/.`;
1231
+ const result = await hooks.run("push-to-checkout", {
1232
+ args: [newOid],
1233
+ env,
1234
+ prefix: false
1235
+ });
1236
+ return result && result.exitCode !== 0 ? "push-to-checkout hook declined" : void 0;
1237
+ }
1238
+ /**
1239
+ * tmp-objdir.c's `tmp_objdir_env` for a hook run while the push's objects are quarantined
1240
+ * (`ctx.quarantinePath`: pre-receive, as git's receive-pack hands `odb_transaction_env` to
1241
+ * it): `GIT_QUARANTINE_PATH` and `GIT_OBJECT_DIRECTORY` name the quarantine,
1242
+ * `GIT_ALTERNATE_OBJECT_DIRECTORIES` the repository's objects, appended to the host's own
1243
+ * (`env_append`: after a `:`, C-quoted when the directory holds a `:` or starts with `"`),
1244
+ * absolute where the repository's files have a host path, so native git run by the hook
1245
+ * reads the pushed objects. Nothing once the objects are published.
1246
+ */
1247
+ async function quarantineEnv(hooks, ctx) {
1248
+ const quarantine = ctx.quarantinePath;
1249
+ if (quarantine === void 0) return {};
1250
+ const objects = await hooks.commonGitFile("objects");
1251
+ const trim = (p) => p.replace(/^\/+|\/+$/g, "");
1252
+ const host = await hooks.hostGitDir();
1253
+ const below = objects && trim(quarantine).startsWith(`${trim(objects.path)}/`);
1254
+ const path = host && objects && below ? `${host}/./objects/${trim(quarantine).slice(trim(objects.path).length + 1)}` : await hooks.hookPathOf(quarantine);
1255
+ const env = {
1256
+ GIT_QUARANTINE_PATH: path,
1257
+ GIT_OBJECT_DIRECTORY: path
1258
+ };
1259
+ if (objects) {
1260
+ const dir = host && below ? `${host}/./objects` : await hooks.hookPathOf(objects.path);
1261
+ const value = dir.includes(":") || dir.startsWith("\"") ? `"${quoteCStyleBody(dir) ?? dir}"` : dir;
1262
+ const old = hooks.hostAlternateObjectDirectories;
1263
+ env.GIT_ALTERNATE_OBJECT_DIRECTORIES = old === void 0 ? value : `${old}:${value}`;
1264
+ }
1265
+ return env;
1266
+ }
1267
+ /**
1268
+ * The variables git's http-backend hands receive-pack, and so every hook it runs
1269
+ * (http-backend.c `run_service`), for a push served over smart HTTP: the web server's
1270
+ * `REMOTE_USER` and `REMOTE_ADDR` (inherited), and, where the host sets none,
1271
+ * `GIT_COMMITTER_NAME=<user>` and `GIT_COMMITTER_EMAIL=<user>@http.<addr>` (`anonymous` and
1272
+ * `(none)` when unknown). Nothing for a push not over HTTP.
1273
+ */
1274
+ function httpBackendEnv(hooks, client) {
1275
+ if (!client?.http) return {};
1276
+ const env = {};
1277
+ if (client.remoteUser) env.REMOTE_USER = client.remoteUser;
1278
+ if (client.remoteAddr) env.REMOTE_ADDR = client.remoteAddr;
1279
+ const user = client.remoteUser || "anonymous";
1280
+ const addr = client.remoteAddr || "(none)";
1281
+ const committer = hooks.hostCommitter;
1282
+ if (committer.name === void 0) env.GIT_COMMITTER_NAME = user;
1283
+ if (committer.email === void 0) env.GIT_COMMITTER_EMAIL = `${user}@http.${addr}`;
1284
+ return env;
1285
+ }
1286
+ /** {@link httpBackendEnv} of a push its hook context describes (HTTP: it has a request). */
1287
+ function hookClientEnv(hooks, ctx) {
1288
+ return httpBackendEnv(hooks, ctx?.request ? {
1289
+ http: true,
1290
+ ...ctx.remoteUser !== void 0 ? { remoteUser: ctx.remoteUser } : {},
1291
+ ...ctx.remoteAddr !== void 0 ? { remoteAddr: ctx.remoteAddr } : {}
1292
+ } : void 0);
1293
+ }
1294
+ /**
1295
+ * receive-pack's hooks as scripts (builtin/receive-pack.c `run_receive_hook`,
1296
+ * `run_update_hook`, `run_update_post_hook`, `run_proc_receive_hook`): pre-receive and
1297
+ * post-receive read `<old> <new> <ref>` lines on stdin (with `GIT_PUSH_OPTION_COUNT` and the
1298
+ * options; post-receive the proc-receive hook's reports in place of their commands), update
1299
+ * is told one ref, post-update the refs that moved, proc-receive is started and talked to
1300
+ * over its stdin and stdout (found as `find_hook` finds it: no configured hook); each runs
1301
+ * with `GIT_DIR=.` and its output goes to the pushing user (side-band, git's "remote: "
1302
+ * lines).
1303
+ */
1304
+ function scriptReceiveHooks(hooks) {
1305
+ const lines = (commands) => commands.map((c) => `${c.oldOid} ${c.newOid} ${c.refName}\n`).join("");
1306
+ const optionEnv = (ctx) => {
1307
+ const env = { GIT_PUSH_OPTION_COUNT: String(ctx.pushOptions.length) };
1308
+ ctx.pushOptions.forEach((option, i) => {
1309
+ env[`GIT_PUSH_OPTION_${i}`] = option;
1310
+ });
1311
+ return env;
1312
+ };
1313
+ const run = async (name, ctx, options) => {
1314
+ const result = await hooks.run(name, {
1315
+ ...options,
1316
+ env: {
1317
+ ...hookClientEnv(hooks, ctx),
1318
+ GIT_DIR: ".",
1319
+ ...await quarantineEnv(hooks, ctx),
1320
+ ...options.env ?? {}
1321
+ },
1322
+ prefix: false
1323
+ }).catch((error) => {
1324
+ if (error instanceof GitApiError && error.message.startsWith("fatal: ")) throw new ReceivePackDiedError(error.message.slice(7));
1325
+ throw error;
1326
+ });
1327
+ if (result?.stderr) await ctx.message(result.stderr);
1328
+ return result;
1329
+ };
1330
+ return {
1331
+ preReceive: async (commands, ctx) => {
1332
+ const result = await run("pre-receive", ctx, {
1333
+ stdin: lines(commands),
1334
+ env: optionEnv(ctx)
1335
+ });
1336
+ return !result || result.exitCode === 0;
1337
+ },
1338
+ update: async (refName, oldOid, newOid, ctx) => {
1339
+ const result = await run("update", ctx, { args: [
1340
+ refName,
1341
+ oldOid,
1342
+ newOid
1343
+ ] });
1344
+ return !result || result.exitCode === 0;
1345
+ },
1346
+ postReceive: async (commands, ctx) => {
1347
+ await run("post-receive", ctx, {
1348
+ stdin: lines(commands),
1349
+ env: optionEnv(ctx)
1350
+ });
1351
+ const refs = commands.filter((c) => !c.report).map((c) => c.pushedRef ?? c.refName);
1352
+ if (refs.length > 0) await run("post-update", ctx, { args: refs });
1353
+ },
1354
+ procReceive: (ctx) => hooks.start("proc-receive", {
1355
+ env: {
1356
+ ...hookClientEnv(hooks, ctx),
1357
+ GIT_DIR: "."
1358
+ },
1359
+ prefix: false,
1360
+ onStderr: (text) => ctx.message(text)
1361
+ })
1362
+ };
1363
+ }
1364
+ //#endregion
1365
+ //#region src/commands/remote-transport.ts
1366
+ /**
1367
+ * How a remote command reaches a remote, as git's `transport_get` and `git_connect` decide:
1368
+ * the URL (already rewritten by `url.<base>.insteadOf`, see `RemoteConfigStore`) is checked
1369
+ * against `protocol.allow`; a path or `file://` URL is git's local transport (served in
1370
+ * process, see `local-transport.ts`); anything else goes to the connector the transport
1371
+ * registry names for it (smart HTTP by default).
1372
+ */
1373
+ var remote_transport_exports = /* @__PURE__ */ __exportAll({
1374
+ checkTransportAllowed: () => checkTransportAllowed,
1375
+ isTransportAllowed: () => isTransportAllowed,
1376
+ openResolvedRemote: () => openResolvedRemote,
1377
+ prepareRemote: () => prepareRemote,
1378
+ protocolVersionOf: () => protocolVersionOf,
1379
+ remoteContextOf: () => remoteContextOf,
1380
+ resolveRemote: () => resolveRemote,
1381
+ withRemoteReceivePack: () => withRemoteReceivePack,
1382
+ withRemoteSession: () => withRemoteSession,
1383
+ withRemoteUploadPack: () => withRemoteUploadPack
1384
+ });
1385
+ const NO_PATH = "fatal: no path specified; see 'git help pull' for valid url syntax";
1386
+ /** transport.c's `parse_protocol_config`. */
1387
+ function parsePolicy(key, value) {
1388
+ const lower = value.toLowerCase();
1389
+ if (lower === "always" || lower === "never" || lower === "user") return lower;
1390
+ throw new InvalidConfigError(key, `fatal: unknown value for config '${key}': ${value}`);
1391
+ }
1392
+ /**
1393
+ * transport.c's `is_transport_allowed`: `GIT_ALLOW_PROTOCOL` when set (the only transports
1394
+ * allowed); else `protocol.<type>.allow`, then `protocol.allow`, then git's defaults (http,
1395
+ * https, git and ssh always; ext never; any other, `file` included, only when
1396
+ * `GIT_PROTOCOL_FROM_USER` is not false).
1397
+ *
1398
+ * @example
1399
+ * ```ts
1400
+ * isTransportAllowed("ext", store); // false
1401
+ * isTransportAllowed("file", store, { protocolFromUser: false } as GitHostEnvironment); // false
1402
+ * ```
1403
+ */
1404
+ function isTransportAllowed(type, config, environment) {
1405
+ if (environment?.allowProtocol !== void 0) return environment.allowProtocol.split(":").includes(type);
1406
+ const key = `protocol.${type}.allow`;
1407
+ const own = config.value(key);
1408
+ const fallback = config.value("protocol.allow");
1409
+ let policy;
1410
+ if (own !== void 0) policy = parsePolicy(key, own);
1411
+ else if (fallback !== void 0) policy = parsePolicy("protocol.allow", fallback);
1412
+ else if ([
1413
+ "http",
1414
+ "https",
1415
+ "git",
1416
+ "ssh"
1417
+ ].includes(type)) policy = "always";
1418
+ else if (type === "ext") policy = "never";
1419
+ else policy = "user";
1420
+ if (policy === "user") return environment?.protocolFromUser ?? true;
1421
+ return policy === "always";
1422
+ }
1423
+ /** transport.c's `transport_check_allowed`: git's "transport '<type>' not allowed". */
1424
+ function checkTransportAllowed(type, config, environment) {
1425
+ if (!isTransportAllowed(type, config, environment)) throw new TransportError$1(`fatal: transport '${type}' not allowed`);
1426
+ }
1427
+ /**
1428
+ * `protocol.version` (git's `get_protocol_version_config`): 0, 1 or 2, default 2; any other
1429
+ * value is git's "unknown value for config 'protocol.version'".
1430
+ */
1431
+ function protocolVersionOf(config) {
1432
+ const value = config.value("protocol.version");
1433
+ if (value === void 0) return 2;
1434
+ if (value === "0" || value === "1" || value === "2") return Number(value);
1435
+ throw new InvalidConfigError("protocol.version", `fatal: unknown value for config 'protocol.version': ${value}`);
1436
+ }
1437
+ /**
1438
+ * Resolves a remote URL (already rewritten by `insteadOf`) to its transport, in git's order
1439
+ * (transport_get, then git_connect): a `<helper>::<address>` URL goes to the connector for
1440
+ * the helper; `rsync:` is refused; a path or `file://` URL is the local transport (its path
1441
+ * checked first, then `protocol.file.allow`); `ssh`/`git` URLs (path, then
1442
+ * `protocol.<scheme>.allow`) and any other `<scheme>://` (`protocol.<scheme>.allow`) go to
1443
+ * the registry's connector. Without one, git's words: "unable to find remote helper" where
1444
+ * git would run a remote helper, ours for ssh and git:// (git would connect directly).
1445
+ *
1446
+ * @throws TransportError git's lines (exit 128)
1447
+ */
1448
+ function resolveRemote(url, context) {
1449
+ const { config, environment, transports } = context;
1450
+ const parsed = parseGitUrl(url);
1451
+ const viaConnector = (type) => {
1452
+ checkTransportAllowed(type, config, environment);
1453
+ const connector = transports.resolve(parsed);
1454
+ return connector ? {
1455
+ kind: "connector",
1456
+ url,
1457
+ parsed,
1458
+ connector
1459
+ } : void 0;
1460
+ };
1461
+ const helperMissing = (helper) => new TransportError$1(`fatal: unable to find remote helper for '${helper}'`);
1462
+ if (parsed.address !== void 0) return viaConnector(parsed.scheme) ?? throwError(helperMissing(parsed.scheme));
1463
+ if (url.startsWith("rsync:")) throw new TransportError$1("fatal: git-over-rsync is no longer supported");
1464
+ if (!(!isGitUrl(url) || /^(?:file|git|ssh|git\+ssh|ssh\+git):\/\//.test(url) || url === "")) {
1465
+ const scheme = url.slice(0, url.indexOf(":"));
1466
+ return viaConnector(scheme) ?? throwError(helperMissing(scheme));
1467
+ }
1468
+ if (!parsed.path && !parsed.scpLike) throw new TransportError$1(NO_PATH);
1469
+ if (parsed.scheme === "ssh" || parsed.local) checkNotAnOption("pathname", parsed.path);
1470
+ if (parsed.scheme === "file") {
1471
+ checkTransportAllowed("file", config, environment);
1472
+ return {
1473
+ kind: "local",
1474
+ url,
1475
+ path: parsed.path
1476
+ };
1477
+ }
1478
+ if (parsed.scheme === "ssh") {
1479
+ checkTransportAllowed("ssh", config, environment);
1480
+ checkNotAnOption("hostname", `${parsed.user !== void 0 ? `${parsed.user}@` : ""}${parsed.host ?? ""}`);
1481
+ }
1482
+ return viaConnector(parsed.scheme) ?? throwError(new TransportError$1(`fatal: cannot connect to '${url}': only http(s) and local repositories are reachable here`));
1483
+ }
1484
+ /**
1485
+ * connect.c's `looks_like_command_line_option` checks: git's "strange hostname '<host>'
1486
+ * blocked" (and pathname), so a remote URL cannot smuggle an option into the command git
1487
+ * runs (`ssh -oProxyCommand=...`).
1488
+ *
1489
+ * @throws TransportError git's line (exit 128)
1490
+ */
1491
+ function checkNotAnOption(what, value) {
1492
+ if (value.startsWith("-")) throw new TransportError$1(`fatal: strange ${what} '${value}' blocked`);
1493
+ }
1494
+ function throwError(error) {
1495
+ throw error;
1496
+ }
1497
+ /**
1498
+ * {@link resolveRemote}, then a local remote's repository opened (git's "does not appear to
1499
+ * be a git repository" when it cannot be).
1500
+ */
1501
+ async function prepareRemote(workingCopy, url, transports) {
1502
+ return openResolvedRemote(workingCopy, resolveRemote(url, remoteContextOf(workingCopy, transports)));
1503
+ }
1504
+ /** A resolved remote with its local repository opened ({@link prepareRemote}'s second half). */
1505
+ async function openResolvedRemote(workingCopy, resolved) {
1506
+ if (resolved.kind !== "local") return resolved;
1507
+ return {
1508
+ ...resolved,
1509
+ repository: await openLocalRemote(workingCopy, resolved.path)
1510
+ };
1511
+ }
1512
+ /** The resolution context of a working copy: its configuration and host environment. */
1513
+ function remoteContextOf(workingCopy, transports) {
1514
+ const environment = hostEnvironmentOf(workingCopy);
1515
+ return {
1516
+ config: RemoteConfigStore.from(workingCopy),
1517
+ ...environment ? { environment } : {},
1518
+ transports
1519
+ };
1520
+ }
1521
+ function connectRequest(remote, service, options) {
1522
+ return {
1523
+ url: remote.parsed,
1524
+ service,
1525
+ protocolVersion: protocolVersionFor(service, options.protocolVersion),
1526
+ ...options.program !== void 0 ? { program: options.program } : {},
1527
+ ...options.credentials ? { credentials: options.credentials } : {},
1528
+ ...options.headers ? { headers: options.headers } : {},
1529
+ ...options.timeout !== void 0 ? { timeout: options.timeout } : {},
1530
+ ...options.signal ? { signal: options.signal } : {}
1531
+ };
1532
+ }
1533
+ /**
1534
+ * A native session whose stream closes once: the connection opened over it closes the stream
1535
+ * (`closeDuplex`), and {@link withRemoteSession} closes it again for a `run` that opened none
1536
+ * or failed before; the second close does nothing.
1537
+ */
1538
+ function closingOnce(session) {
1539
+ if (session.kind !== "native") return session;
1540
+ const inner = session.duplex;
1541
+ let closing;
1542
+ const duplex = {
1543
+ [Symbol.asyncIterator]: () => inner[Symbol.asyncIterator](),
1544
+ write: (data) => inner.write(data),
1545
+ ...inner.end ? { end: () => inner.end?.() ?? Promise.resolve() } : {},
1546
+ close: () => {
1547
+ closing ??= inner.close?.() ?? Promise.resolve();
1548
+ return closing;
1549
+ }
1550
+ };
1551
+ return {
1552
+ ...session,
1553
+ duplex
1554
+ };
1555
+ }
1556
+ /**
1557
+ * Runs `run` over a session the remote's connector opens for `service` (the request's
1558
+ * protocol version as git_connect asks for it: v0 for receive-pack when v2 is configured); a
1559
+ * native session's stream is closed afterwards, once, whether or not `run` closed it.
1560
+ */
1561
+ async function withRemoteSession(remote, service, options, run) {
1562
+ const request = connectRequest(remote, service, options);
1563
+ const session = closingOnce(await remote.connector.connect(request));
1564
+ try {
1565
+ return await run(session, request);
1566
+ } finally {
1567
+ if (session.kind === "native") await session.duplex.close?.().catch(() => void 0);
1568
+ }
1569
+ }
1570
+ /**
1571
+ * Runs `run` over a connection to upload-pack of a remote: in process for a local one
1572
+ * (`withLocalUploadPack`, protocol v2 unless `protocol.version` says otherwise), else over
1573
+ * the session its connector opens (`openUploadPack`).
1574
+ */
1575
+ async function withRemoteUploadPack(remote, options, run) {
1576
+ if (remote.kind === "local") return withLocalUploadPack(remote.repository, run, { protocolVersion: options.protocolVersion });
1577
+ return withRemoteSession(remote, "git-upload-pack", options, async (session, request) => {
1578
+ const connection = await openUploadPack(session, request, { ...options.gzipRequests !== void 0 ? { gzipRequests: options.gzipRequests } : {} });
1579
+ try {
1580
+ return await run(connection);
1581
+ } finally {
1582
+ await connection.close();
1583
+ }
1584
+ });
1585
+ }
1586
+ /**
1587
+ * Runs `run` over a connection to receive-pack of a remote: in process for a local one
1588
+ * (`withLocalReceivePack`, with the remote repository's hooks), else over the session its
1589
+ * connector opens (`openReceivePack`).
1590
+ */
1591
+ async function withRemoteReceivePack(remote, options, run, hooks, transactionHooks, local = {}) {
1592
+ if (remote.kind === "local") return withLocalReceivePack(remote.repository, run, hooks, transactionHooks, {
1593
+ protocolVersion: options.protocolVersion,
1594
+ ...local
1595
+ });
1596
+ return withRemoteSession(remote, "git-receive-pack", options, async (session, request) => {
1597
+ const connection = await openReceivePack(session, request, { ...options.streamRequestBody !== void 0 ? { streamRequestBody: options.streamRequestBody } : {} });
1598
+ try {
1599
+ return await run(connection);
1600
+ } finally {
1601
+ await connection.close();
1602
+ }
1603
+ });
1604
+ }
1605
+ //#endregion
1606
+ export { ReadTreeCommand as _, remote_transport_exports as a, withRemoteUploadPack as c, receiveFsckSettingsOf as d, receivePackSettingsOf as f, withReceiveTransactionHook as g, servedUseBitmaps as h, remoteContextOf as i, httpBackendEnv as l, servedMaxTreeDepth as m, prepareRemote as n, resolveRemote as o, remoteHookSession as p, protocolVersionOf as r, withRemoteReceivePack as s, openResolvedRemote as t, quarantineEnv as u };