@statewalker/vcs-commands 0.4.0 → 0.6.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 (561) hide show
  1. package/README.md +123 -8
  2. package/dist/commands/add-command.d.ts +265 -34
  3. package/dist/commands/add-command.d.ts.map +1 -1
  4. package/dist/commands/add-patch/add-interactive.d.ts +46 -0
  5. package/dist/commands/add-patch/add-interactive.d.ts.map +1 -0
  6. package/dist/commands/add-patch/add-patch.d.ts +139 -0
  7. package/dist/commands/add-patch/add-patch.d.ts.map +1 -0
  8. package/dist/commands/add-patch/index.d.ts +6 -0
  9. package/dist/commands/add-patch/index.d.ts.map +1 -0
  10. package/dist/commands/add-patch/patch-backend.d.ts +80 -0
  11. package/dist/commands/add-patch/patch-backend.d.ts.map +1 -0
  12. package/dist/commands/add-patch/patch-modes.d.ts +71 -0
  13. package/dist/commands/add-patch/patch-modes.d.ts.map +1 -0
  14. package/dist/commands/add-patch/patch-session.d.ts +49 -0
  15. package/dist/commands/add-patch/patch-session.d.ts.map +1 -0
  16. package/dist/commands/am/am-command.d.ts +175 -0
  17. package/dist/commands/am/am-command.d.ts.map +1 -0
  18. package/dist/commands/am/index.d.ts +3 -0
  19. package/dist/commands/am/index.d.ts.map +1 -0
  20. package/dist/commands/am/mailinfo.d.ts +58 -0
  21. package/dist/commands/am/mailinfo.d.ts.map +1 -0
  22. package/dist/commands/am/patch-format.d.ts +24 -0
  23. package/dist/commands/am/patch-format.d.ts.map +1 -0
  24. package/dist/commands/apply/apply-command.d.ts +153 -0
  25. package/dist/commands/apply/apply-command.d.ts.map +1 -0
  26. package/dist/commands/apply/apply-engine.d.ts +195 -0
  27. package/dist/commands/apply/apply-engine.d.ts.map +1 -0
  28. package/dist/commands/apply/apply-parse.d.ts +86 -0
  29. package/dist/commands/apply/apply-parse.d.ts.map +1 -0
  30. package/dist/commands/apply/apply-types.d.ts +70 -0
  31. package/dist/commands/apply/apply-types.d.ts.map +1 -0
  32. package/dist/commands/apply/index.d.ts +6 -0
  33. package/dist/commands/apply/index.d.ts.map +1 -0
  34. package/dist/commands/apply/latin1.d.ts +32 -0
  35. package/dist/commands/apply/latin1.d.ts.map +1 -0
  36. package/dist/commands/apply/whitespace.d.ts +58 -0
  37. package/dist/commands/apply/whitespace.d.ts.map +1 -0
  38. package/dist/commands/attributes-source.d.ts +26 -0
  39. package/dist/commands/attributes-source.d.ts.map +1 -0
  40. package/dist/commands/backfill-command.d.ts +110 -0
  41. package/dist/commands/backfill-command.d.ts.map +1 -0
  42. package/dist/commands/bisect/bisect-checkout.d.ts +64 -0
  43. package/dist/commands/bisect/bisect-checkout.d.ts.map +1 -0
  44. package/dist/commands/bisect/bisect-command.d.ts +201 -0
  45. package/dist/commands/bisect/bisect-command.d.ts.map +1 -0
  46. package/dist/commands/bisect/bisect-engine.d.ts +219 -0
  47. package/dist/commands/bisect/bisect-engine.d.ts.map +1 -0
  48. package/dist/commands/bisect/bisect-graph.d.ts +127 -0
  49. package/dist/commands/bisect/bisect-graph.d.ts.map +1 -0
  50. package/dist/commands/bisect/bisect-quote.d.ts +27 -0
  51. package/dist/commands/bisect/bisect-quote.d.ts.map +1 -0
  52. package/dist/commands/bisect/index.d.ts +5 -0
  53. package/dist/commands/bisect/index.d.ts.map +1 -0
  54. package/dist/commands/blame-command.d.ts +122 -131
  55. package/dist/commands/blame-command.d.ts.map +1 -1
  56. package/dist/commands/branch-command.d.ts +52 -2
  57. package/dist/commands/branch-command.d.ts.map +1 -1
  58. package/dist/commands/branch-tracking.d.ts +98 -0
  59. package/dist/commands/branch-tracking.d.ts.map +1 -0
  60. package/dist/commands/checkout-command.d.ts +299 -34
  61. package/dist/commands/checkout-command.d.ts.map +1 -1
  62. package/dist/commands/checkout-paths.d.ts +124 -0
  63. package/dist/commands/checkout-paths.d.ts.map +1 -0
  64. package/dist/commands/cherry-pick-command.d.ts +50 -42
  65. package/dist/commands/cherry-pick-command.d.ts.map +1 -1
  66. package/dist/commands/clean-command.d.ts +67 -4
  67. package/dist/commands/clean-command.d.ts.map +1 -1
  68. package/dist/commands/clone-command.d.ts +179 -7
  69. package/dist/commands/clone-command.d.ts.map +1 -1
  70. package/dist/commands/commit-command.d.ts +311 -17
  71. package/dist/commands/commit-command.d.ts.map +1 -1
  72. package/dist/commands/core-config.d.ts +93 -0
  73. package/dist/commands/core-config.d.ts.map +1 -0
  74. package/dist/commands/date-format.d.ts +58 -0
  75. package/dist/commands/date-format.d.ts.map +1 -0
  76. package/dist/commands/describe-command.d.ts.map +1 -1
  77. package/dist/commands/diff-command.d.ts +377 -30
  78. package/dist/commands/diff-command.d.ts.map +1 -1
  79. package/dist/commands/diff-textconv.d.ts +40 -0
  80. package/dist/commands/diff-textconv.d.ts.map +1 -0
  81. package/dist/commands/fetch-command.d.ts +244 -23
  82. package/dist/commands/fetch-command.d.ts.map +1 -1
  83. package/dist/commands/format-patch-command.d.ts +164 -0
  84. package/dist/commands/format-patch-command.d.ts.map +1 -0
  85. package/dist/commands/fsck/fetch-fsck.d.ts +60 -0
  86. package/dist/commands/fsck/fetch-fsck.d.ts.map +1 -0
  87. package/dist/commands/fsck/fsck-command.d.ts +225 -0
  88. package/dist/commands/fsck/fsck-command.d.ts.map +1 -0
  89. package/dist/commands/fsck/fsck-loose.d.ts +68 -0
  90. package/dist/commands/fsck/fsck-loose.d.ts.map +1 -0
  91. package/dist/commands/fsck/fsck-msg-ids.d.ts +122 -0
  92. package/dist/commands/fsck/fsck-msg-ids.d.ts.map +1 -0
  93. package/dist/commands/fsck/fsck-object-checks.d.ts +148 -0
  94. package/dist/commands/fsck/fsck-object-checks.d.ts.map +1 -0
  95. package/dist/commands/fsck/fsck-object-table.d.ts +132 -0
  96. package/dist/commands/fsck/fsck-object-table.d.ts.map +1 -0
  97. package/dist/commands/fsck/fsck-pack.d.ts +115 -0
  98. package/dist/commands/fsck/fsck-pack.d.ts.map +1 -0
  99. package/dist/commands/fsck/index.d.ts +6 -0
  100. package/dist/commands/fsck/index.d.ts.map +1 -0
  101. package/dist/commands/fsck/verify-pack-command.d.ts +81 -0
  102. package/dist/commands/fsck/verify-pack-command.d.ts.map +1 -0
  103. package/dist/commands/gc-command.d.ts +43 -0
  104. package/dist/commands/gc-command.d.ts.map +1 -1
  105. package/dist/commands/git-date.d.ts +66 -0
  106. package/dist/commands/git-date.d.ts.map +1 -0
  107. package/dist/commands/git-describe.d.ts +67 -0
  108. package/dist/commands/git-describe.d.ts.map +1 -0
  109. package/dist/commands/git-hooks.d.ts +416 -0
  110. package/dist/commands/git-hooks.d.ts.map +1 -0
  111. package/dist/commands/git-ident.d.ts +128 -0
  112. package/dist/commands/git-ident.d.ts.map +1 -0
  113. package/dist/commands/hook-command.d.ts +96 -0
  114. package/dist/commands/hook-command.d.ts.map +1 -0
  115. package/dist/commands/index-adder.d.ts +231 -0
  116. package/dist/commands/index-adder.d.ts.map +1 -0
  117. package/dist/commands/index-host.d.ts +86 -0
  118. package/dist/commands/index-host.d.ts.map +1 -0
  119. package/dist/commands/index.d.ts +55 -0
  120. package/dist/commands/index.d.ts.map +1 -1
  121. package/dist/commands/index.js +3 -2
  122. package/dist/commands/init-command.d.ts +12 -1
  123. package/dist/commands/init-command.d.ts.map +1 -1
  124. package/dist/commands/local-clone.d.ts +60 -0
  125. package/dist/commands/local-clone.d.ts.map +1 -0
  126. package/dist/commands/local-transport.d.ts +117 -0
  127. package/dist/commands/local-transport.d.ts.map +1 -0
  128. package/dist/commands/log-command.d.ts +216 -24
  129. package/dist/commands/log-command.d.ts.map +1 -1
  130. package/dist/commands/log-graph.d.ts +120 -0
  131. package/dist/commands/log-graph.d.ts.map +1 -0
  132. package/dist/commands/log-output.d.ts +323 -0
  133. package/dist/commands/log-output.d.ts.map +1 -0
  134. package/dist/commands/ls-remote-command.d.ts +23 -7
  135. package/dist/commands/ls-remote-command.d.ts.map +1 -1
  136. package/dist/commands/mailmap.d.ts +31 -0
  137. package/dist/commands/mailmap.d.ts.map +1 -0
  138. package/dist/commands/merge-bases.d.ts +85 -0
  139. package/dist/commands/merge-bases.d.ts.map +1 -0
  140. package/dist/commands/merge-command.d.ts +209 -74
  141. package/dist/commands/merge-command.d.ts.map +1 -1
  142. package/dist/commands/merge-config.d.ts +13 -0
  143. package/dist/commands/merge-config.d.ts.map +1 -0
  144. package/dist/commands/merge-drivers.d.ts +130 -0
  145. package/dist/commands/merge-drivers.d.ts.map +1 -0
  146. package/dist/commands/merge-support.d.ts +252 -0
  147. package/dist/commands/merge-support.d.ts.map +1 -0
  148. package/dist/commands/message-cleanup.d.ts +86 -0
  149. package/dist/commands/message-cleanup.d.ts.map +1 -0
  150. package/dist/commands/mv-command.d.ts +94 -0
  151. package/dist/commands/mv-command.d.ts.map +1 -0
  152. package/dist/commands/notes-command.d.ts +256 -0
  153. package/dist/commands/notes-command.d.ts.map +1 -0
  154. package/dist/commands/notes-commands.d.ts +41 -0
  155. package/dist/commands/notes-commands.d.ts.map +1 -0
  156. package/dist/commands/notes-merge-command.d.ts +105 -0
  157. package/dist/commands/notes-merge-command.d.ts.map +1 -0
  158. package/dist/commands/notes-support.d.ts +125 -0
  159. package/dist/commands/notes-support.d.ts.map +1 -0
  160. package/dist/commands/notes-tree.d.ts +106 -0
  161. package/dist/commands/notes-tree.d.ts.map +1 -0
  162. package/dist/commands/object-id-input.d.ts +20 -0
  163. package/dist/commands/object-id-input.d.ts.map +1 -0
  164. package/dist/commands/octopus-merge.d.ts +59 -0
  165. package/dist/commands/octopus-merge.d.ts.map +1 -0
  166. package/dist/commands/ort-merge.d.ts +126 -0
  167. package/dist/commands/ort-merge.d.ts.map +1 -0
  168. package/dist/commands/ort-recursive.d.ts +53 -0
  169. package/dist/commands/ort-recursive.d.ts.map +1 -0
  170. package/dist/commands/pack-refs-command.d.ts +20 -0
  171. package/dist/commands/pack-refs-command.d.ts.map +1 -1
  172. package/dist/commands/patch-id.d.ts +41 -0
  173. package/dist/commands/patch-id.d.ts.map +1 -0
  174. package/dist/commands/pathspec-attributes.d.ts +64 -0
  175. package/dist/commands/pathspec-attributes.d.ts.map +1 -0
  176. package/dist/commands/pathspec.d.ts +324 -0
  177. package/dist/commands/pathspec.d.ts.map +1 -0
  178. package/dist/commands/post-index-change.d.ts +33 -0
  179. package/dist/commands/post-index-change.d.ts.map +1 -0
  180. package/dist/commands/pretty-format.d.ts +222 -0
  181. package/dist/commands/pretty-format.d.ts.map +1 -0
  182. package/dist/commands/promisor-remote.d.ts +80 -0
  183. package/dist/commands/promisor-remote.d.ts.map +1 -0
  184. package/dist/commands/pull-command.d.ts +41 -8
  185. package/dist/commands/pull-command.d.ts.map +1 -1
  186. package/dist/commands/push-command.d.ts +24 -8
  187. package/dist/commands/push-command.d.ts.map +1 -1
  188. package/dist/commands/read-tree-command.d.ts +112 -0
  189. package/dist/commands/read-tree-command.d.ts.map +1 -0
  190. package/dist/commands/rebase-command.d.ts +507 -75
  191. package/dist/commands/rebase-command.d.ts.map +1 -1
  192. package/dist/commands/rebase-todo.d.ts +130 -0
  193. package/dist/commands/rebase-todo.d.ts.map +1 -0
  194. package/dist/commands/ref-decoration-filter.d.ts +53 -0
  195. package/dist/commands/ref-decoration-filter.d.ts.map +1 -0
  196. package/dist/commands/reflog-messages.d.ts +98 -0
  197. package/dist/commands/reflog-messages.d.ts.map +1 -0
  198. package/dist/commands/remote-command.d.ts +146 -6
  199. package/dist/commands/remote-command.d.ts.map +1 -1
  200. package/dist/commands/remote-transport.d.ts +120 -0
  201. package/dist/commands/remote-transport.d.ts.map +1 -0
  202. package/dist/commands/reset-command.d.ts +161 -7
  203. package/dist/commands/reset-command.d.ts.map +1 -1
  204. package/dist/commands/restore-command.d.ts +103 -0
  205. package/dist/commands/restore-command.d.ts.map +1 -0
  206. package/dist/commands/rev-list-command.d.ts +78 -0
  207. package/dist/commands/rev-list-command.d.ts.map +1 -0
  208. package/dist/commands/rev-parse-command.d.ts +80 -0
  209. package/dist/commands/rev-parse-command.d.ts.map +1 -0
  210. package/dist/commands/revert-command.d.ts +46 -38
  211. package/dist/commands/revert-command.d.ts.map +1 -1
  212. package/dist/commands/revision-filenames.d.ts +95 -0
  213. package/dist/commands/revision-filenames.d.ts.map +1 -0
  214. package/dist/commands/revision-range.d.ts +67 -0
  215. package/dist/commands/revision-range.d.ts.map +1 -0
  216. package/dist/commands/revision-resolver.d.ts +321 -0
  217. package/dist/commands/revision-resolver.d.ts.map +1 -0
  218. package/dist/commands/rm-command.d.ts +69 -7
  219. package/dist/commands/rm-command.d.ts.map +1 -1
  220. package/dist/commands/sequencer-pick.d.ts +191 -0
  221. package/dist/commands/sequencer-pick.d.ts.map +1 -0
  222. package/dist/commands/sequencer-support.d.ts +125 -0
  223. package/dist/commands/sequencer-support.d.ts.map +1 -0
  224. package/dist/commands/serve-repository.d.ts +52 -0
  225. package/dist/commands/serve-repository.d.ts.map +1 -0
  226. package/dist/commands/sparse-checkout-command.d.ts +190 -0
  227. package/dist/commands/sparse-checkout-command.d.ts.map +1 -0
  228. package/dist/commands/sparse-checkout-support.d.ts +268 -0
  229. package/dist/commands/sparse-checkout-support.d.ts.map +1 -0
  230. package/dist/commands/stash-apply-command.d.ts +69 -13
  231. package/dist/commands/stash-apply-command.d.ts.map +1 -1
  232. package/dist/commands/stash-create-command.d.ts +214 -26
  233. package/dist/commands/stash-create-command.d.ts.map +1 -1
  234. package/dist/commands/stash-drop-command.d.ts +10 -2
  235. package/dist/commands/stash-drop-command.d.ts.map +1 -1
  236. package/dist/commands/stash-list-command.d.ts +2 -4
  237. package/dist/commands/stash-list-command.d.ts.map +1 -1
  238. package/dist/commands/stash-working-tree.d.ts +95 -0
  239. package/dist/commands/stash-working-tree.d.ts.map +1 -0
  240. package/dist/commands/status-command.d.ts +320 -28
  241. package/dist/commands/status-command.d.ts.map +1 -1
  242. package/dist/commands/status-format.d.ts +155 -0
  243. package/dist/commands/status-format.d.ts.map +1 -0
  244. package/dist/commands/status-header.d.ts +64 -0
  245. package/dist/commands/status-header.d.ts.map +1 -0
  246. package/dist/commands/strerror.d.ts +7 -0
  247. package/dist/commands/strerror.d.ts.map +1 -0
  248. package/dist/commands/submodule-config.d.ts +38 -0
  249. package/dist/commands/submodule-config.d.ts.map +1 -0
  250. package/dist/commands/submodule-summary-command.d.ts +80 -0
  251. package/dist/commands/submodule-summary-command.d.ts.map +1 -0
  252. package/dist/commands/submodule-summary.d.ts +150 -0
  253. package/dist/commands/submodule-summary.d.ts.map +1 -0
  254. package/dist/commands/switch-command.d.ts +132 -0
  255. package/dist/commands/switch-command.d.ts.map +1 -0
  256. package/dist/commands/tag-command.d.ts +23 -2
  257. package/dist/commands/tag-command.d.ts.map +1 -1
  258. package/dist/commands/tracking-info.d.ts +64 -0
  259. package/dist/commands/tracking-info.d.ts.map +1 -0
  260. package/dist/commands/trailers.d.ts +73 -0
  261. package/dist/commands/trailers.d.ts.map +1 -0
  262. package/dist/commands/tree-restore.d.ts +137 -6
  263. package/dist/commands/tree-restore.d.ts.map +1 -1
  264. package/dist/commands/untracked-cache-support.d.ts +53 -0
  265. package/dist/commands/untracked-cache-support.d.ts.map +1 -0
  266. package/dist/commands/worktree-add-command.d.ts +108 -0
  267. package/dist/commands/worktree-add-command.d.ts.map +1 -0
  268. package/dist/commands/worktree-list-command.d.ts +69 -0
  269. package/dist/commands/worktree-list-command.d.ts.map +1 -0
  270. package/dist/commands/worktree-lock-command.d.ts +44 -0
  271. package/dist/commands/worktree-lock-command.d.ts.map +1 -0
  272. package/dist/commands/worktree-overwrite-checks.d.ts +204 -0
  273. package/dist/commands/worktree-overwrite-checks.d.ts.map +1 -0
  274. package/dist/commands/worktree-prune-command.d.ts +48 -0
  275. package/dist/commands/worktree-prune-command.d.ts.map +1 -0
  276. package/dist/commands/worktree-remove-command.d.ts +59 -0
  277. package/dist/commands/worktree-remove-command.d.ts.map +1 -0
  278. package/dist/commands/worktree-repair-command.d.ts +35 -0
  279. package/dist/commands/worktree-repair-command.d.ts.map +1 -0
  280. package/dist/commands/worktree-support.d.ts +64 -0
  281. package/dist/commands/worktree-support.d.ts.map +1 -0
  282. package/dist/commands-DnmlfwGV.js +61620 -0
  283. package/dist/core-commands/add.command.impl.d.ts.map +1 -1
  284. package/dist/core-commands/index.d.ts +0 -3
  285. package/dist/core-commands/index.d.ts.map +1 -1
  286. package/dist/errors/add-errors.d.ts +55 -0
  287. package/dist/errors/add-errors.d.ts.map +1 -1
  288. package/dist/errors/checkout-errors.d.ts +29 -0
  289. package/dist/errors/checkout-errors.d.ts.map +1 -1
  290. package/dist/errors/command-errors.d.ts +77 -0
  291. package/dist/errors/command-errors.d.ts.map +1 -1
  292. package/dist/errors/commit-errors.d.ts +9 -0
  293. package/dist/errors/commit-errors.d.ts.map +1 -1
  294. package/dist/errors/git-api-error.d.ts +59 -2
  295. package/dist/errors/git-api-error.d.ts.map +1 -1
  296. package/dist/errors/index.d.ts +1 -0
  297. package/dist/errors/index.d.ts.map +1 -1
  298. package/dist/errors/index.js +371 -19
  299. package/dist/errors/rebase-errors.d.ts +9 -0
  300. package/dist/errors/rebase-errors.d.ts.map +1 -1
  301. package/dist/errors/ref-errors.d.ts +32 -0
  302. package/dist/errors/ref-errors.d.ts.map +1 -1
  303. package/dist/errors/transport-errors.d.ts +12 -2
  304. package/dist/errors/transport-errors.d.ts.map +1 -1
  305. package/dist/errors/worktree-errors.d.ts +35 -0
  306. package/dist/errors/worktree-errors.d.ts.map +1 -0
  307. package/dist/git-command-DxvwPrPB.js +7612 -0
  308. package/dist/git-command.d.ts +422 -32
  309. package/dist/git-command.d.ts.map +1 -1
  310. package/dist/git.d.ts +326 -5
  311. package/dist/git.d.ts.map +1 -1
  312. package/dist/index.d.ts +1 -1
  313. package/dist/index.d.ts.map +1 -1
  314. package/dist/index.js +5 -5
  315. package/dist/remote-config/index.d.ts +1 -0
  316. package/dist/remote-config/index.d.ts.map +1 -1
  317. package/dist/remote-config/remote-config-store.d.ts +123 -3
  318. package/dist/remote-config/remote-config-store.d.ts.map +1 -1
  319. package/dist/remote-config/remote-refs.d.ts +41 -0
  320. package/dist/remote-config/remote-refs.d.ts.map +1 -0
  321. package/dist/rename/detect-renames.d.ts +148 -0
  322. package/dist/rename/detect-renames.d.ts.map +1 -0
  323. package/dist/rename/git-similarity.d.ts +44 -0
  324. package/dist/rename/git-similarity.d.ts.map +1 -0
  325. package/dist/rename/index.d.ts +2 -0
  326. package/dist/rename/index.d.ts.map +1 -1
  327. package/dist/results/binary-patch.d.ts +11 -0
  328. package/dist/results/binary-patch.d.ts.map +1 -0
  329. package/dist/results/blame-format.d.ts +55 -0
  330. package/dist/results/blame-format.d.ts.map +1 -0
  331. package/dist/results/cherry-pick-result.d.ts +10 -0
  332. package/dist/results/cherry-pick-result.d.ts.map +1 -1
  333. package/dist/results/clone-result.d.ts +16 -0
  334. package/dist/results/clone-result.d.ts.map +1 -1
  335. package/dist/results/combined-diff.d.ts +77 -0
  336. package/dist/results/combined-diff.d.ts.map +1 -0
  337. package/dist/results/diff-entry.d.ts +32 -0
  338. package/dist/results/diff-entry.d.ts.map +1 -1
  339. package/dist/results/diff-formatter.d.ts +34 -60
  340. package/dist/results/diff-formatter.d.ts.map +1 -1
  341. package/dist/results/diff-order.d.ts +25 -0
  342. package/dist/results/diff-order.d.ts.map +1 -0
  343. package/dist/results/diff-output.d.ts +249 -0
  344. package/dist/results/diff-output.d.ts.map +1 -0
  345. package/dist/results/fetch-result.d.ts +24 -1
  346. package/dist/results/fetch-result.d.ts.map +1 -1
  347. package/dist/results/index.d.ts +5 -0
  348. package/dist/results/index.d.ts.map +1 -1
  349. package/dist/results/index.js +2 -252
  350. package/dist/results/merge-result.d.ts +15 -1
  351. package/dist/results/merge-result.d.ts.map +1 -1
  352. package/dist/results/pull-result.d.ts +12 -3
  353. package/dist/results/pull-result.d.ts.map +1 -1
  354. package/dist/results/push-result.d.ts +42 -0
  355. package/dist/results/push-result.d.ts.map +1 -1
  356. package/dist/results/quote-path.d.ts +27 -0
  357. package/dist/results/quote-path.d.ts.map +1 -0
  358. package/dist/results/rebase-result.d.ts +28 -1
  359. package/dist/results/rebase-result.d.ts.map +1 -1
  360. package/dist/results/revert-result.d.ts +10 -0
  361. package/dist/results/revert-result.d.ts.map +1 -1
  362. package/dist/results/stash-result.d.ts +5 -0
  363. package/dist/results/stash-result.d.ts.map +1 -1
  364. package/dist/results/status-result.d.ts +143 -18
  365. package/dist/results/status-result.d.ts.map +1 -1
  366. package/dist/results-BZGa2Z3I.js +2934 -0
  367. package/dist/transport-command.d.ts +56 -1
  368. package/dist/transport-command.d.ts.map +1 -1
  369. package/package.json +15 -10
  370. package/src/commands/add-command.ts +1291 -224
  371. package/src/commands/add-patch/add-interactive.ts +941 -0
  372. package/src/commands/add-patch/add-patch.ts +1169 -0
  373. package/src/commands/add-patch/index.ts +5 -0
  374. package/src/commands/add-patch/patch-backend.ts +239 -0
  375. package/src/commands/add-patch/patch-modes.ts +249 -0
  376. package/src/commands/add-patch/patch-session.ts +159 -0
  377. package/src/commands/am/am-command.ts +1111 -0
  378. package/src/commands/am/index.ts +2 -0
  379. package/src/commands/am/mailinfo.ts +1015 -0
  380. package/src/commands/am/patch-format.ts +121 -0
  381. package/src/commands/apply/apply-command.ts +832 -0
  382. package/src/commands/apply/apply-engine.ts +1603 -0
  383. package/src/commands/apply/apply-parse.ts +1209 -0
  384. package/src/commands/apply/apply-types.ts +112 -0
  385. package/src/commands/apply/index.ts +5 -0
  386. package/src/commands/apply/latin1.ts +171 -0
  387. package/src/commands/apply/whitespace.ts +260 -0
  388. package/src/commands/attributes-source.ts +96 -0
  389. package/src/commands/backfill-command.ts +694 -0
  390. package/src/commands/bisect/bisect-checkout.ts +217 -0
  391. package/src/commands/bisect/bisect-command.ts +788 -0
  392. package/src/commands/bisect/bisect-engine.ts +1079 -0
  393. package/src/commands/bisect/bisect-graph.ts +595 -0
  394. package/src/commands/bisect/bisect-quote.ts +92 -0
  395. package/src/commands/bisect/index.ts +4 -0
  396. package/src/commands/blame-command.ts +711 -986
  397. package/src/commands/branch-command.ts +354 -32
  398. package/src/commands/branch-tracking.ts +331 -0
  399. package/src/commands/checkout-command.ts +1426 -297
  400. package/src/commands/checkout-paths.ts +784 -0
  401. package/src/commands/cherry-pick-command.ts +156 -396
  402. package/src/commands/clean-command.ts +532 -85
  403. package/src/commands/clone-command.ts +826 -55
  404. package/src/commands/commit-command.ts +1781 -166
  405. package/src/commands/core-config.ts +196 -0
  406. package/src/commands/date-format.ts +668 -0
  407. package/src/commands/describe-command.ts +2 -0
  408. package/src/commands/diff-command.ts +1898 -110
  409. package/src/commands/diff-textconv.ts +50 -0
  410. package/src/commands/fetch-command.ts +1038 -79
  411. package/src/commands/format-patch-command.ts +969 -0
  412. package/src/commands/fsck/fetch-fsck.ts +229 -0
  413. package/src/commands/fsck/fsck-command.ts +3347 -0
  414. package/src/commands/fsck/fsck-loose.ts +287 -0
  415. package/src/commands/fsck/fsck-msg-ids.ts +176 -0
  416. package/src/commands/fsck/fsck-object-checks.ts +1044 -0
  417. package/src/commands/fsck/fsck-object-table.ts +363 -0
  418. package/src/commands/fsck/fsck-pack.ts +604 -0
  419. package/src/commands/fsck/index.ts +5 -0
  420. package/src/commands/fsck/verify-pack-command.ts +249 -0
  421. package/src/commands/gc-command.ts +147 -1
  422. package/src/commands/git-date.ts +895 -0
  423. package/src/commands/git-describe.ts +316 -0
  424. package/src/commands/git-hooks.ts +1472 -0
  425. package/src/commands/git-ident.ts +344 -0
  426. package/src/commands/hook-command.ts +247 -0
  427. package/src/commands/index-adder.ts +706 -0
  428. package/src/commands/index-host.ts +291 -0
  429. package/src/commands/index.ts +83 -0
  430. package/src/commands/init-command.ts +60 -11
  431. package/src/commands/local-clone.ts +183 -0
  432. package/src/commands/local-transport.ts +762 -0
  433. package/src/commands/log-command.ts +1915 -170
  434. package/src/commands/log-graph.ts +671 -0
  435. package/src/commands/log-output.ts +1359 -0
  436. package/src/commands/ls-remote-command.ts +101 -58
  437. package/src/commands/mailmap.ts +129 -0
  438. package/src/commands/merge-bases.ts +296 -0
  439. package/src/commands/merge-command.ts +1386 -491
  440. package/src/commands/merge-config.ts +25 -0
  441. package/src/commands/merge-drivers.ts +306 -0
  442. package/src/commands/merge-support.ts +1198 -0
  443. package/src/commands/message-cleanup.ts +275 -0
  444. package/src/commands/mv-command.ts +976 -0
  445. package/src/commands/notes-command.ts +890 -0
  446. package/src/commands/notes-commands.ts +87 -0
  447. package/src/commands/notes-merge-command.ts +768 -0
  448. package/src/commands/notes-support.ts +402 -0
  449. package/src/commands/notes-tree.ts +602 -0
  450. package/src/commands/object-id-input.ts +27 -0
  451. package/src/commands/octopus-merge.ts +377 -0
  452. package/src/commands/ort-merge.ts +1660 -0
  453. package/src/commands/ort-recursive.ts +160 -0
  454. package/src/commands/pack-refs-command.ts +39 -22
  455. package/src/commands/patch-id.ts +196 -0
  456. package/src/commands/pathspec-attributes.ts +162 -0
  457. package/src/commands/pathspec.ts +1199 -0
  458. package/src/commands/post-index-change.ts +62 -0
  459. package/src/commands/pretty-format.ts +1431 -0
  460. package/src/commands/promisor-remote.ts +298 -0
  461. package/src/commands/pull-command.ts +207 -22
  462. package/src/commands/push-command.ts +236 -23
  463. package/src/commands/read-tree-command.ts +857 -0
  464. package/src/commands/rebase-command.ts +3808 -371
  465. package/src/commands/rebase-todo.ts +584 -0
  466. package/src/commands/ref-decoration-filter.ts +118 -0
  467. package/src/commands/reflog-messages.ts +177 -0
  468. package/src/commands/remote-command.ts +500 -19
  469. package/src/commands/remote-transport.ts +383 -0
  470. package/src/commands/reset-command.ts +828 -91
  471. package/src/commands/restore-command.ts +350 -0
  472. package/src/commands/rev-list-command.ts +167 -0
  473. package/src/commands/rev-parse-command.ts +277 -0
  474. package/src/commands/revert-command.ts +152 -399
  475. package/src/commands/revision-filenames.ts +254 -0
  476. package/src/commands/revision-range.ts +222 -0
  477. package/src/commands/revision-resolver.ts +1379 -0
  478. package/src/commands/rm-command.ts +613 -67
  479. package/src/commands/sequencer-pick.ts +869 -0
  480. package/src/commands/sequencer-support.ts +869 -0
  481. package/src/commands/serve-repository.ts +125 -0
  482. package/src/commands/sparse-checkout-command.ts +1389 -0
  483. package/src/commands/sparse-checkout-support.ts +793 -0
  484. package/src/commands/stash-apply-command.ts +692 -124
  485. package/src/commands/stash-create-command.ts +752 -89
  486. package/src/commands/stash-drop-command.ts +67 -6
  487. package/src/commands/stash-list-command.ts +10 -4
  488. package/src/commands/stash-working-tree.ts +387 -0
  489. package/src/commands/status-command.ts +1426 -97
  490. package/src/commands/status-format.ts +775 -0
  491. package/src/commands/status-header.ts +330 -0
  492. package/src/commands/strerror.ts +29 -0
  493. package/src/commands/submodule-config.ts +94 -0
  494. package/src/commands/submodule-summary-command.ts +334 -0
  495. package/src/commands/submodule-summary.ts +446 -0
  496. package/src/commands/switch-command.ts +402 -0
  497. package/src/commands/tag-command.ts +129 -41
  498. package/src/commands/tracking-info.ts +201 -0
  499. package/src/commands/trailers.ts +417 -0
  500. package/src/commands/tree-restore.ts +344 -15
  501. package/src/commands/untracked-cache-support.ts +194 -0
  502. package/src/commands/worktree-add-command.ts +458 -0
  503. package/src/commands/worktree-list-command.ts +208 -0
  504. package/src/commands/worktree-lock-command.ts +96 -0
  505. package/src/commands/worktree-overwrite-checks.ts +641 -0
  506. package/src/commands/worktree-prune-command.ts +99 -0
  507. package/src/commands/worktree-remove-command.ts +186 -0
  508. package/src/commands/worktree-repair-command.ts +59 -0
  509. package/src/commands/worktree-support.ts +214 -0
  510. package/src/core-commands/add.command.impl.ts +9 -5
  511. package/src/core-commands/index.ts +0 -8
  512. package/src/errors/add-errors.ts +45 -0
  513. package/src/errors/checkout-errors.ts +46 -2
  514. package/src/errors/command-errors.ts +101 -1
  515. package/src/errors/commit-errors.ts +18 -2
  516. package/src/errors/git-api-error.ts +82 -2
  517. package/src/errors/index.ts +1 -0
  518. package/src/errors/merge-errors.ts +2 -2
  519. package/src/errors/rebase-errors.ts +12 -0
  520. package/src/errors/ref-errors.ts +56 -2
  521. package/src/errors/remote-errors.ts +2 -2
  522. package/src/errors/stash-errors.ts +1 -1
  523. package/src/errors/transport-errors.ts +20 -4
  524. package/src/errors/worktree-errors.ts +49 -0
  525. package/src/git-command.ts +1218 -118
  526. package/src/git.ts +552 -11
  527. package/src/index.ts +1 -1
  528. package/src/remote-config/index.ts +1 -0
  529. package/src/remote-config/remote-config-store.ts +326 -16
  530. package/src/remote-config/remote-refs.ts +119 -0
  531. package/src/rename/detect-renames.ts +711 -0
  532. package/src/rename/git-similarity.ts +116 -0
  533. package/src/rename/index.ts +2 -0
  534. package/src/results/binary-patch.ts +401 -0
  535. package/src/results/blame-format.ts +239 -0
  536. package/src/results/cherry-pick-result.ts +10 -0
  537. package/src/results/clone-result.ts +18 -0
  538. package/src/results/combined-diff.ts +585 -0
  539. package/src/results/diff-entry.ts +35 -0
  540. package/src/results/diff-formatter.ts +152 -288
  541. package/src/results/diff-order.ts +64 -0
  542. package/src/results/diff-output.ts +1051 -0
  543. package/src/results/fetch-result.ts +24 -1
  544. package/src/results/index.ts +5 -0
  545. package/src/results/merge-result.ts +15 -1
  546. package/src/results/pull-result.ts +12 -3
  547. package/src/results/push-result.ts +43 -0
  548. package/src/results/quote-path.ts +103 -0
  549. package/src/results/rebase-result.ts +37 -0
  550. package/src/results/revert-result.ts +10 -0
  551. package/src/results/stash-result.ts +6 -0
  552. package/src/results/status-result.ts +288 -27
  553. package/src/transport-command.ts +139 -2
  554. package/dist/commands-BpeXZTC3.js +0 -10278
  555. package/dist/core-commands/checkout.command.d.ts +0 -103
  556. package/dist/core-commands/checkout.command.d.ts.map +0 -1
  557. package/dist/core-commands/checkout.command.impl.d.ts +0 -110
  558. package/dist/core-commands/checkout.command.impl.d.ts.map +0 -1
  559. package/dist/status-result-BapZoQaR.js +0 -411
  560. package/src/core-commands/checkout.command.impl.ts +0 -564
  561. package/src/core-commands/checkout.command.ts +0 -125
@@ -1,28 +1,62 @@
1
1
  import type { ObjectId } from "@statewalker/vcs-core";
2
2
  // Import from the package root only: vcs-core ships a single runtime file
3
3
  // (dist/index.js); its subpaths resolve for types but not at runtime.
4
- import { isSymbolicRef } from "@statewalker/vcs-core";
5
4
  import {
5
+ type FilesApi,
6
+ historyWithoutLazyFetch,
7
+ isSymbolicRef,
8
+ parseCoreAbbrev,
9
+ } from "@statewalker/vcs-core";
10
+ import { writeCommitGraph } from "@statewalker/vcs-store-files";
11
+ import {
12
+ anonymizeUrl,
6
13
  createRepositoryFacade,
7
14
  createTransportRefStore,
8
15
  expandFromDestination,
16
+ FetchCheckError,
17
+ type FetchClientResult,
18
+ type FetchDisplayEntry,
19
+ type FetchHeadEntry,
9
20
  type FetchRefUpdate,
21
+ fetchFromConnection,
22
+ fetchRefcolWidth,
23
+ fetchUpdateDisplay,
24
+ formatFetchDisplay,
25
+ formatFetchHead,
10
26
  matchDestination,
11
27
  matchSource,
12
28
  parseRefSpec,
13
29
  type RefSpec,
14
30
  type TagMode,
15
- fetch as transportFetch,
31
+ type FetchOptions as TransportFetchOptions,
32
+ transportSummaryWidth,
33
+ ZERO_OID,
16
34
  } from "@statewalker/vcs-transport";
17
-
18
- import { InvalidArgumentError, InvalidRemoteError } from "../errors/index.js";
19
- import { RemoteConfigStore } from "../remote-config/index.js";
35
+ import { parseGitBool } from "@statewalker/vcs-utils";
36
+ import type { WorktreeAdmin } from "@statewalker/vcs-working-tree";
37
+ import {
38
+ FetchIntoCheckedOutBranchError,
39
+ InvalidArgumentError,
40
+ InvalidRemoteError,
41
+ TransportError,
42
+ } from "../errors/index.js";
43
+ import { deleteRefs, RemoteConfigStore } from "../remote-config/index.js";
20
44
  import {
21
45
  type FetchResult,
22
46
  RefUpdateStatus,
23
47
  type TrackingRefUpdate,
24
48
  } from "../results/fetch-result.js";
25
49
  import { TransportCommand } from "../transport-command.js";
50
+ import { fetchFsckOf } from "./fsck/index.js";
51
+ import { hostEnvironmentOf } from "./git-ident.js";
52
+ import {
53
+ hasPromisorRemote,
54
+ promisorOf,
55
+ promisorRemotes,
56
+ registerPartialClone,
57
+ } from "./promisor-remote.js";
58
+ import { withRemoteUploadPack } from "./remote-transport.js";
59
+ import { worktreeUsingBranch } from "./worktree-support.js";
26
60
 
27
61
  /**
28
62
  * Tag fetching option.
@@ -73,18 +107,37 @@ export enum TagOption {
73
107
  */
74
108
  export class FetchCommand extends TransportCommand<FetchResult> {
75
109
  private remote = "origin";
110
+ /** Whether the remote was named (it is then in the reflog action, as on git's command line). */
111
+ private remoteGiven = false;
76
112
  private refSpecs: string[] = [];
77
- private removeDeletedRefs = false;
113
+ private updateHeadOk = false;
114
+ private removeDeletedRefs?: boolean;
115
+ private pruneTags?: boolean;
116
+ private refmap?: string[];
78
117
  private tagOption: TagOption = TagOption.AUTO_FOLLOW;
118
+ private tagOptionSet = false;
119
+ private writeFetchHead = true;
120
+ private appendFetchHead = false;
121
+ private verbose = false;
122
+ private porcelain = false;
79
123
  private thin = true;
80
124
  private depth?: number;
125
+ private uploadPack?: string;
81
126
  private dryRun = false;
127
+ private writeCommitGraphOption?: boolean;
128
+ private repositoryFiles?: { files: FilesApi; gitDir?: string };
82
129
  private forceUpdate = false;
83
- private checkFetchedObjects = false;
130
+ private atomic = false;
131
+ private checkFetchedObjects?: boolean;
132
+ private compatibility?: "2.43" | "2.56";
84
133
  private initialBranch?: string;
85
134
  private shallowSince?: Date;
86
135
  private shallowExcludes: string[] = [];
87
136
  private unshallow = false;
137
+ private updateShallow = false;
138
+ /** `--filter=<spec>` (a string), `--no-filter` (false), or neither */
139
+ private filterSpec?: string | false;
140
+ private refetch = false;
88
141
 
89
142
  /**
90
143
  * Set the remote to fetch from.
@@ -97,6 +150,7 @@ export class FetchCommand extends TransportCommand<FetchResult> {
97
150
  setRemote(remote: string): this {
98
151
  this.checkCallable();
99
152
  this.remote = remote;
153
+ this.remoteGiven = true;
100
154
  return this;
101
155
  }
102
156
 
@@ -134,7 +188,11 @@ export class FetchCommand extends TransportCommand<FetchResult> {
134
188
  /**
135
189
  * Set whether to remove refs that no longer exist on the remote.
136
190
  *
137
- * Equivalent to `git fetch --prune`.
191
+ * Equivalent to `git fetch --prune` (true) and `--no-prune` (false). Unset, the
192
+ * remote's `remote.<name>.prune`, else `fetch.prune`, decides, as in git; neither set,
193
+ * nothing is pruned. The remote-tracking refs the refspecs map from a ref the remote no
194
+ * longer has are deleted before anything is fetched (so `foo` can become `foo/bar`); the
195
+ * command-line refspecs are used when given, else the configured ones.
138
196
  *
139
197
  * @param remove Whether to prune deleted refs
140
198
  */
@@ -145,15 +203,143 @@ export class FetchCommand extends TransportCommand<FetchResult> {
145
203
  }
146
204
 
147
205
  /**
148
- * Whether to remove deleted refs.
206
+ * Whether to remove deleted refs, as set with {@link setRemoveDeletedRefs} (false when
207
+ * unset: the configuration is read when the fetch runs).
149
208
  */
150
209
  isRemoveDeletedRefs(): boolean {
151
- return this.removeDeletedRefs;
210
+ return this.removeDeletedRefs ?? false;
211
+ }
212
+
213
+ /**
214
+ * Set whether local tags the remote no longer has are pruned too (`git fetch
215
+ * --prune-tags` / `--no-prune-tags`). Unset, `remote.<name>.pruneTags`, else
216
+ * `fetch.pruneTags`, decides.
217
+ *
218
+ * As in git, this adds `refs/tags/*:refs/tags/*` to the refspecs (so every remote tag is
219
+ * fetched), and only when no refspec is given: to the remote's configured refspecs, or for
220
+ * a URL to the refspecs of the fetch. Tags are pruned only when pruning is on.
221
+ */
222
+ setPruneTags(pruneTags: boolean): this {
223
+ this.checkCallable();
224
+ this.pruneTags = pruneTags;
225
+ return this;
226
+ }
227
+
228
+ /**
229
+ * Set the refspecs that map the refs named on the command line to remote-tracking refs
230
+ * (`git fetch --refmap=<refspec>`), in place of the remote's `remote.<name>.fetch`.
231
+ *
232
+ * With explicit refspecs ({@link setRefSpecs}), git also updates the remote-tracking
233
+ * ref each fetched ref maps to through the configured refspecs (`git fetch origin main`
234
+ * moves `refs/remotes/origin/main`); a refmap replaces those, and an empty one
235
+ * (`setRefmap()`, git's `--refmap=`) turns the update off. Without explicit refspecs a
236
+ * refmap is an error, as in git.
237
+ */
238
+ setRefmap(...refspecs: string[]): this {
239
+ this.checkCallable();
240
+ this.refmap = refspecs;
241
+ return this;
152
242
  }
153
243
 
244
+ /**
245
+ * Set how tags are fetched (`--tags`, `--no-tags`, or auto-follow).
246
+ *
247
+ * Unset, a configured remote's `remote.<name>.tagOpt` (`--tags`, `--no-tags`) decides, as
248
+ * in git; otherwise tags are auto-followed.
249
+ */
154
250
  setTagOpt(option: TagOption): this {
155
251
  this.checkCallable();
156
252
  this.tagOption = option;
253
+ this.tagOptionSet = true;
254
+ return this;
255
+ }
256
+
257
+ /**
258
+ * Set whether the fetch writes `FETCH_HEAD` (default true; `--no-write-fetch-head`).
259
+ *
260
+ * Written through the checkout's `writeFetchHead`; a checkout without it keeps none.
261
+ */
262
+ setWriteFetchHead(write: boolean): this {
263
+ this.checkCallable();
264
+ this.writeFetchHead = write;
265
+ return this;
266
+ }
267
+
268
+ /** Whether the fetch writes `FETCH_HEAD`. */
269
+ isWriteFetchHead(): boolean {
270
+ return this.writeFetchHead;
271
+ }
272
+
273
+ /**
274
+ * Set whether the fetched refs are added after what `FETCH_HEAD` holds instead of
275
+ * replacing it (`git fetch --append`).
276
+ */
277
+ setAppend(append: boolean): this {
278
+ this.checkCallable();
279
+ this.appendFetchHead = append;
280
+ return this;
281
+ }
282
+
283
+ /** Whether `FETCH_HEAD` is appended to. */
284
+ isAppend(): boolean {
285
+ return this.appendFetchHead;
286
+ }
287
+
288
+ /**
289
+ * Set whether refs already up to date are reported too (`git fetch -v`): their lines,
290
+ * ` = [up to date] main -> origin/main`, join {@link FetchResult.display} in
291
+ * git's order, and the remote column is as wide as their names need.
292
+ */
293
+ setVerbose(verbose: boolean): this {
294
+ this.checkCallable();
295
+ this.verbose = verbose;
296
+ return this;
297
+ }
298
+
299
+ /** Whether up-to-date refs are reported (`-v`). */
300
+ isVerbose(): boolean {
301
+ return this.verbose;
302
+ }
303
+
304
+ /**
305
+ * Set whether the ref lines are git's machine-readable ones (`git fetch --porcelain`,
306
+ * printed on stdout): {@link FetchResult.display} then holds `<flag> <old-id> <new-id>
307
+ * <local-ref>` per ref, full ids (zeros for none) and full ref names, without the
308
+ * `From <url>` line; `fetch.output` does not apply.
309
+ */
310
+ setPorcelain(porcelain: boolean): this {
311
+ this.checkCallable();
312
+ this.porcelain = porcelain;
313
+ return this;
314
+ }
315
+
316
+ /** Whether the ref lines are porcelain ones (`--porcelain`). */
317
+ isPorcelain(): boolean {
318
+ return this.porcelain;
319
+ }
320
+
321
+ /**
322
+ * Partial fetch (`git fetch --filter=<spec>`), or `false` for `--no-filter`. Unset, a
323
+ * fetch from a promisor remote of a partial clone uses its `remote.<name>.partialclonefilter`
324
+ * (git's fetch_one_setup_partial); a filter given registers the remote as a promisor remote
325
+ * first when it is not one with a filter (partial_clone_register:
326
+ * `core.repositoryformatversion = 1`, `remote.<name>.promisor`, `.partialclonefilter`). A
327
+ * pack fetched under a filter is kept as a promisor pack.
328
+ */
329
+ setFilter(spec: string | false): this {
330
+ this.checkCallable();
331
+ this.filterSpec = spec;
332
+ return this;
333
+ }
334
+
335
+ /**
336
+ * `git fetch --refetch`: everything the refspecs select is fetched again, as a fresh clone
337
+ * would (no local commit offered as a `have`, no tip counted as here), under the filter in
338
+ * use: how a partial clone changes its filter.
339
+ */
340
+ setRefetch(refetch: boolean): this {
341
+ this.checkCallable();
342
+ this.refetch = refetch;
157
343
  return this;
158
344
  }
159
345
 
@@ -189,6 +375,45 @@ export class FetchCommand extends TransportCommand<FetchResult> {
189
375
  return this;
190
376
  }
191
377
 
378
+ /**
379
+ * Set the program the remote runs for upload-pack (git's `--upload-pack`, over
380
+ * `remote.<name>.uploadpack`): what an ssh connector runs, and what git:// names in its
381
+ * request line.
382
+ *
383
+ * @param uploadPack Path to git-upload-pack on the remote
384
+ */
385
+ setUploadPack(uploadPack: string): this {
386
+ this.checkCallable();
387
+ this.uploadPack = uploadPack;
388
+ return this;
389
+ }
390
+
391
+ /**
392
+ * `--[no-]write-commit-graph`: after the fetch, write a split commit-graph of everything the
393
+ * refs reach, as git does with `fetch.writeCommitGraph` (which this overrides). It needs the
394
+ * repository's files (`setRepositoryFiles`).
395
+ */
396
+ setWriteCommitGraph(write: boolean): this {
397
+ this.checkCallable();
398
+ this.writeCommitGraphOption = write;
399
+ return this;
400
+ }
401
+
402
+ /**
403
+ * The files of the repository (a files backend), where `fetch.writeCommitGraph` writes the
404
+ * commit-graph. Without them no graph is written.
405
+ *
406
+ * @example
407
+ * ```typescript
408
+ * await git.fetch().setRepositoryFiles({ files }).setWriteCommitGraph(true).call();
409
+ * ```
410
+ */
411
+ setRepositoryFiles(repository: { files: FilesApi; gitDir?: string }): this {
412
+ this.checkCallable();
413
+ this.repositoryFiles = repository;
414
+ return this;
415
+ }
416
+
192
417
  /**
193
418
  * Set dry run mode.
194
419
  *
@@ -209,6 +434,17 @@ export class FetchCommand extends TransportCommand<FetchResult> {
209
434
  return this.dryRun;
210
435
  }
211
436
 
437
+ /**
438
+ * Let the fetch write a branch a worktree has checked out (`git fetch --update-head-ok`,
439
+ * which `git pull` passes). Without it a fetch whose refspecs would write such a branch
440
+ * fails before fetching anything (`FetchIntoCheckedOutBranchError`).
441
+ */
442
+ setUpdateHeadOk(ok: boolean): this {
443
+ this.checkCallable();
444
+ this.updateHeadOk = ok;
445
+ return this;
446
+ }
447
+
212
448
  /**
213
449
  * Set force update mode.
214
450
  *
@@ -222,6 +458,16 @@ export class FetchCommand extends TransportCommand<FetchResult> {
222
458
  return this;
223
459
  }
224
460
 
461
+ /**
462
+ * Update the local refs in one transaction, all or none (`git fetch --atomic`). Each ref
463
+ * is still logged with its own reflog message, as git's transaction logs it.
464
+ */
465
+ setAtomic(atomic: boolean): this {
466
+ this.checkCallable();
467
+ this.atomic = atomic;
468
+ return this;
469
+ }
470
+
225
471
  /**
226
472
  * Whether force update mode is enabled.
227
473
  */
@@ -230,9 +476,18 @@ export class FetchCommand extends TransportCommand<FetchResult> {
230
476
  }
231
477
 
232
478
  /**
233
- * Set whether to check received objects for validity.
479
+ * Set whether to check received objects for validity, over `fetch.fsckObjects` (else
480
+ * `transfer.fsckObjects`), which decide when this is not set.
234
481
  *
235
- * If true, objects received will be verified.
482
+ * Checked, each received object passes fsck as git's `index-pack --strict` runs it
483
+ * (`fetch.fsck.<msg-id>` severities, `fetch.fsck.skipList`), and every object it names came
484
+ * with the pack or is here; otherwise the fetch fails with `FetchCheckError` (git's
485
+ * `error: object <id>: <msg-id>: <message>`, `fatal: fsck error in packed object`, `fatal:
486
+ * index-pack failed`), leaving no ref and no received object behind.
487
+ *
488
+ * Whatever this says, the new ref tips must be connected (git's check_connected): a
489
+ * remote that does not send every object they need fails the fetch (`error: <url> did not
490
+ * send all necessary objects`, exit 1) before any ref is written.
236
491
  *
237
492
  * @param check Whether to check objects
238
493
  */
@@ -243,10 +498,22 @@ export class FetchCommand extends TransportCommand<FetchResult> {
243
498
  }
244
499
 
245
500
  /**
246
- * Whether to check received objects for validity.
501
+ * Whether to check received objects for validity, as set with {@link setCheckFetchedObjects}
502
+ * (false when unset: the configuration is read when the fetch runs).
247
503
  */
248
504
  isCheckFetchedObjects(): boolean {
249
- return this.checkFetchedObjects;
505
+ return this.checkFetchedObjects ?? false;
506
+ }
507
+
508
+ /**
509
+ * Whose output to give where git 2.43 and 2.5x differ (2.43 prints an empty line after
510
+ * `error: <url> did not send all necessary objects`; fsck of a tag's `gpgsig` header).
511
+ * Default: the hook runner's compatibility, else 2.56.
512
+ */
513
+ setCompatibility(version: "2.43" | "2.56"): this {
514
+ this.checkCallable();
515
+ this.compatibility = version;
516
+ return this;
250
517
  }
251
518
 
252
519
  /**
@@ -327,6 +594,18 @@ export class FetchCommand extends TransportCommand<FetchResult> {
327
594
  return this;
328
595
  }
329
596
 
597
+ /**
598
+ * `git fetch --update-shallow`: from a shallow remote, the shallow commits the fetched
599
+ * history needs are added to `.git/shallow`. Without it, each ref whose new history needs
600
+ * one is left alone, as git leaves it (`warning: rejected <ref> because shallow roots are
601
+ * not allowed to be updated` for one that would have been merged).
602
+ */
603
+ setUpdateShallow(updateShallow: boolean): this {
604
+ this.checkCallable();
605
+ this.updateShallow = updateShallow;
606
+ return this;
607
+ }
608
+
330
609
  /**
331
610
  * Whether unshallow mode is enabled.
332
611
  */
@@ -334,6 +613,35 @@ export class FetchCommand extends TransportCommand<FetchResult> {
334
613
  return this.unshallow;
335
614
  }
336
615
 
616
+ /**
617
+ * The options as git's reflog action spells the command line (`GIT_REFLOG_ACTION` is
618
+ * `fetch` and its arguments), in a fixed order since our options have none:
619
+ * `--atomic --force --prune --prune-tags --tags --depth=<n> --unshallow --append
620
+ * --no-write-fetch-head --refmap=<spec>` (and their `--no-` forms where set to false).
621
+ */
622
+ private commandLineOptions(): string[] {
623
+ const flag = (value: boolean | undefined, name: string) =>
624
+ value === true ? [`--${name}`] : value === false ? [`--no-${name}`] : [];
625
+ return [
626
+ ...(this.verbose ? ["-v"] : []),
627
+ ...(this.porcelain ? ["--porcelain"] : []),
628
+ ...(this.atomic ? ["--atomic"] : []),
629
+ ...(this.forceUpdate ? ["--force"] : []),
630
+ ...flag(this.removeDeletedRefs, "prune"),
631
+ ...flag(this.pruneTags, "prune-tags"),
632
+ ...(this.tagOptionSet && this.tagOption === TagOption.FETCH_TAGS ? ["--tags"] : []),
633
+ ...(this.tagOptionSet && this.tagOption === TagOption.NO_TAGS ? ["--no-tags"] : []),
634
+ ...(this.depth !== undefined ? [`--depth=${this.depth}`] : []),
635
+ ...(this.unshallow ? ["--unshallow"] : []),
636
+ ...(this.appendFetchHead ? ["--append"] : []),
637
+ ...(this.writeFetchHead ? [] : ["--no-write-fetch-head"]),
638
+ ...(this.refmap ?? []).map((spec) => `--refmap=${spec}`),
639
+ ...(typeof this.filterSpec === "string" ? [`--filter=${this.filterSpec}`] : []),
640
+ ...(this.filterSpec === false ? ["--no-filter"] : []),
641
+ ...(this.refetch ? ["--refetch"] : []),
642
+ ];
643
+ }
644
+
337
645
  /**
338
646
  * Execute the fetch operation.
339
647
  *
@@ -356,131 +664,723 @@ export class FetchCommand extends TransportCommand<FetchResult> {
356
664
  throw new InvalidRemoteError(this.remote);
357
665
  }
358
666
 
667
+ const store = RemoteConfigStore.from(this.workingCopy);
668
+ // git's remote_is_configured: a remote name with a config section, not a URL
669
+ const viaConfig = store.isConfigured(this.remote);
670
+ const prune =
671
+ this.removeDeletedRefs ??
672
+ configBool(store.value(`remote.${this.remote}.prune`)) ??
673
+ configBool(store.value("fetch.prune")) ??
674
+ false;
675
+ const pruneTags =
676
+ this.pruneTags ??
677
+ configBool(store.value(`remote.${this.remote}.pruneTags`)) ??
678
+ configBool(store.value("fetch.pruneTags")) ??
679
+ false;
680
+ const configured = viaConfig ? store.configuredFetchRefspecs(this.remote) : [];
681
+ const explicitSpecs = [...this.refSpecs];
682
+ // fetch.c fetch_one: --prune-tags (only without command-line refspecs) adds the tag
683
+ // refspec to the configured ones, or for a URL to those of the fetch
684
+ if (pruneTags && this.refSpecs.length === 0) {
685
+ if (viaConfig) configured.push(TAG_REFSPEC);
686
+ else explicitSpecs.push(TAG_REFSPEC);
687
+ }
688
+
359
689
  // git: without a refspec the remote's HEAD is fetched, and no ref is written (nor any
360
690
  // tag); explicit refspecs must name refs the remote has, configured ones may not
361
- const fromConfig = this.refSpecs.length === 0;
362
- const configured = this.effectiveRefSpecs();
363
- const refspecs = configured.length > 0 ? configured : ["HEAD"];
691
+ const fromConfig = explicitSpecs.length === 0;
692
+ if (fromConfig && this.refmap !== undefined) {
693
+ throw new InvalidArgumentError(
694
+ "refmap",
695
+ this.refmap,
696
+ "--refmap option is only meaningful with command-line refspec(s)",
697
+ );
698
+ }
699
+ // git's has_merge (branch_has_merge_config): the current branch has an upstream, on
700
+ // whichever remote
701
+ const upstream = fromConfig ? await this.upstreamConfig() : undefined;
702
+ const upstreamHere = upstream?.remote === this.remote;
703
+ // git (fetch.c get_ref_map): the remote's configured refspecs, or with none the current
704
+ // branch's upstream refs when this remote is its upstream; else the remote HEAD
705
+ const useConfig = fromConfig && (configured.length > 0 || upstreamHere);
706
+ const given = !fromConfig ? explicitSpecs : useConfig ? configured : ["HEAD"];
707
+ // add_merge_config: fetching the current branch's upstream remote also takes the
708
+ // branch's `branch.<name>.merge` refs, for FETCH_HEAD
709
+ const mergeRefs = useConfig && upstream && upstreamHere ? upstream.merge : [];
710
+ const refspecs = [...given, ...mergeRefs];
364
711
  const history = this._workingCopy.history;
712
+ // get_ref_map: refs named on the command line also update the remote-tracking refs the
713
+ // refmap (or the remote's configured refspecs) maps them to
714
+ const opportunistic = fromConfig
715
+ ? []
716
+ : (this.refmap ?? configured).filter((spec) => spec !== "");
717
+ // do_fetch: refs/remotes/<name>/HEAD follows the remote HEAD on a configured fetch
718
+ const followHead = fromConfig && configured.length > 0 ? this.followRemoteHead(store) : null;
719
+ const messages: string[] = [];
720
+ const errors: string[] = [];
721
+ const trackingUpdates: TrackingRefUpdate[] = [];
722
+
723
+ // transport_get: git's local transport (upload-pack of the repository at the path, in
724
+ // process), or the connector the transport registry names (smart HTTP by default);
725
+ // anything else fails in git's words. The remote is reached before FETCH_HEAD is touched
726
+ // (transport_get_remote_refs comes first in do_fetch)
727
+ const remote = await this.prepareRemote(remoteUrl);
728
+
729
+ // git truncates FETCH_HEAD when the fetch starts: a failed fetch leaves it empty
730
+ // a bare repository writes FETCH_HEAD in its git directory (no checkout to ask)
731
+ const checkout =
732
+ "checkout" in this._workingCopy
733
+ ? this._workingCopy.checkout
734
+ : (this._workingCopy as Partial<Pick<WorktreeAdmin, "bareRepository">>).bareRepository;
735
+ const writesFetchHead = !this.dryRun && this.writeFetchHead && !!checkout?.writeFetchHead;
736
+ if (writesFetchHead && !this.appendFetchHead) await checkout.writeFetchHead?.("");
737
+
738
+ // fetch_one_setup_partial: the filter given (the remote registered as a promisor remote),
739
+ // else a promisor remote's own filter
740
+ let filter: string | undefined;
741
+ if (this.filterSpec !== false && !this.dryRun) {
742
+ if (typeof this.filterSpec === "string") {
743
+ filter = this.filterSpec;
744
+ if (viaConfig) {
745
+ registerPartialClone(store, this.remote, filter);
746
+ await store.save();
747
+ promisorOf(this._workingCopy)?.fetcher?.invalidate?.();
748
+ }
749
+ } else if (hasPromisorRemote(store)) {
750
+ filter = promisorRemotes(store).find((r) => r.name === this.remote)?.partialCloneFilter;
751
+ }
752
+ } else if (typeof this.filterSpec === "string") filter = this.filterSpec;
365
753
 
366
- const result = await transportFetch({
754
+ // fetch.fsckObjects / transfer.fsckObjects: index-pack --strict over each received pack
755
+ const compatibility = this.compatibility ?? this.hooks.compatibility;
756
+ const environment = hostEnvironmentOf(this.workingCopy);
757
+ const fsckWarnings: string[] = [];
758
+ const fsck = await fetchFsckOf(
759
+ {
760
+ value: (key) => store.value(key),
761
+ entries: (prefix) => store.entriesWithPrefix(prefix),
762
+ warnings: fsckWarnings,
763
+ compatibility,
764
+ ...(environment
765
+ ? { readFile: (path: string) => environment.readFile(path), home: environment.home }
766
+ : {}),
767
+ baseDir: await this.hostWorkingDir(),
768
+ },
769
+ this.checkFetchedObjects,
770
+ );
771
+
772
+ const fetchOptions: TransportFetchOptions = {
367
773
  url: remoteUrl,
368
774
  auth: this.credentials,
369
775
  headers: this.headers,
370
776
  timeout: this.timeout,
371
- repository: createRepositoryFacade({ history }),
777
+ gzipRequests: this.gzipRequests,
778
+ repository: createRepositoryFacade({ history: historyWithoutLazyFetch(history) }),
372
779
  refStore: createTransportRefStore(history.refs),
373
780
  refspecs,
374
- missingRefsOk: fromConfig && configured.length > 0,
375
- tags: toTagMode(this.tagOption),
781
+ opportunisticRefspecs: opportunistic.length > 0 ? opportunistic : undefined,
782
+ // fetch.c do_fetch: a branch a worktree has checked out is not fetched into (the
783
+ // whole fetch dies first, unless --update-head-ok); stale refs are pruned before
784
+ // anything is fetched, with command-line refspecs by those, else by the configured ones.
785
+ // With --atomic, prune_refs queues the deletions into the one transaction: a refused
786
+ // update or a failed commit leaves the stale refs too
787
+ beforeFetch: async (remoteRefs, refMap) => {
788
+ // check_not_current_branch over git's ref map: the refs the refspecs took and their
789
+ // opportunistic updates, not every advertised ref the configured refspecs would map
790
+ if (!this.updateHeadOk) await this.refuseCheckedOutBranch(refMap);
791
+ if (!prune) return;
792
+ const names = new Set(remoteRefs.filter((r) => r.oid).map((r) => r.name));
793
+ const pruneSpecs = (fromConfig ? configured : explicitSpecs).map((s) => parseRefSpec(s));
794
+ const defer = this.atomic && !this.dryRun;
795
+ const pruned = await this.pruneDeletedRefs(names, pruneSpecs, messages, errors, defer);
796
+ trackingUpdates.push(...pruned);
797
+ return defer ? { deletes: pruned.map((u) => u.localRef) } : undefined;
798
+ },
799
+ missingRefsOk: useConfig,
800
+ tags: toTagMode(this.effectiveTagOption()),
376
801
  depth: this.depth,
377
802
  deepenSince: this.shallowSince,
378
803
  deepenNot: this.shallowExcludes.length > 0 ? this.shallowExcludes : undefined,
379
804
  unshallow: this.unshallow || undefined,
805
+ updateShallow: this.updateShallow || undefined,
380
806
  force: this.forceUpdate,
807
+ atomic: this.atomic || undefined,
381
808
  dryRun: this.dryRun,
382
809
  onProgress: this.progressMessageCallback,
383
- reflogMessage: `fetch: ${remoteUrl}`,
810
+ // git's "fetch <args>: <what>" per ref; the action from the options, the remote and
811
+ // the refspecs given (git's argv)
812
+ reflogAction: this.reflogAction(
813
+ [
814
+ "fetch",
815
+ ...this.commandLineOptions(),
816
+ ...(this.remoteGiven || this.refSpecs.length > 0 ? [this.remote] : []),
817
+ ...this.refSpecs,
818
+ ].join(" "),
819
+ ),
820
+ reflogIdent: this.reflogLine("").ident,
821
+ abbrev: parseCoreAbbrev(store.value("core.abbrev")) ?? -1,
822
+ ...(fsck ? { fsckObjects: fsck } : {}),
823
+ ...(filter ? { filter } : {}),
824
+ ...(this.refetch ? { refetch: true } : {}),
825
+ };
826
+ // --upload-pack, else remote.<name>.uploadpack (transport_get)
827
+ const uploadPack = this.uploadPack ?? this.remoteProgram(this.remote, "uploadpack");
828
+ const sessionOptions = {
829
+ ...this.remoteSessionOptions(),
830
+ ...(uploadPack !== undefined ? { program: uploadPack } : {}),
831
+ };
832
+ // git's fetch runs with fetch_if_missing = 0: its walks read through the history's view
833
+ // without lazy fetch (the facade above), never a store-wide switch
834
+ const result = await withRemoteUploadPack(remote, sessionOptions, (connection) =>
835
+ fetchFromConnection(connection, fetchOptions),
836
+ ).catch((error: unknown) => {
837
+ // git dies on a source that names no remote ref (a hidden one included)
838
+ const message = error instanceof Error ? error.message : "";
839
+ if (message.startsWith("couldn't find remote ref ")) {
840
+ throw new TransportError(`fatal: ${message}`, undefined, { cause: error });
841
+ }
842
+ if (error instanceof FetchCheckError) {
843
+ // fetch-pack ran: its start-up warnings came first
844
+ const lines = [...fsckWarnings, ...error.lines];
845
+ // store_updated_refs: the ref tips' check failed; nothing is written
846
+ if (error.check === "refs") {
847
+ lines.push(`error: ${anonymizeUrl(remoteUrl)} did not send all necessary objects`);
848
+ if (compatibility === "2.43") lines.push("");
849
+ }
850
+ throw new FetchCheckError(error.check, lines, error.exitCode);
851
+ }
852
+ throw error;
384
853
  });
854
+ // fetch-pack's start-up warnings (when it ran), then index-pack's fsck warnings
855
+ if (result.imports.length > 0) messages.push(...fsckWarnings);
856
+ messages.push(...(result.packCheckMessages ?? []));
385
857
 
386
858
  const advertisedRefs = new Map<string, ObjectId>();
387
859
  for (const ref of result.remoteRefs) {
388
860
  if (ref.oid) advertisedRefs.set(ref.name, ref.oid);
389
861
  }
390
- const trackingUpdates = result.refUpdates.map(toTrackingRefUpdate);
862
+ trackingUpdates.push(...result.refUpdates.map(toTrackingRefUpdate));
863
+ // a failed --atomic transaction: git's error after the ref lines
864
+ if (result.refTransactionError !== undefined) errors.push(result.refTransactionError);
391
865
 
392
- // Handle prune
393
- if (!this.dryRun && this.removeDeletedRefs) {
394
- const parsed = refspecs.map((s) => parseRefSpec(s));
395
- trackingUpdates.push(
396
- ...(await this.pruneDeletedRefs(new Set(advertisedRefs.keys()), parsed)),
397
- );
866
+ const marked = await this.fetchHeadEntries(result, {
867
+ given: given.length,
868
+ merge: mergeRefs,
869
+ // explicit refspecs (and the HEAD of an unconfigured remote) are all to merge;
870
+ // configured ones only when the first names one ref and no upstream is set
871
+ explicit: !useConfig,
872
+ firstIsExact: given.length > 0 && !parseRefSpec(given[0]).wildcard,
873
+ hasMerge: upstream !== undefined,
874
+ });
875
+ // store_updated_refs: a ref rejected for the shallow commits it needs is skipped, with
876
+ // git's warning when it is for merge
877
+ for (const e of marked) {
878
+ if (e.shallowRejected && !e.notForMerge) {
879
+ messages.push(
880
+ `warning: rejected ${e.localRef ?? e.remoteRef} because shallow roots are not allowed to be updated`,
881
+ );
882
+ }
883
+ }
884
+ const entries: FetchHeadEntry[] = marked
885
+ .filter((e) => !e.shallowRejected)
886
+ .map(({ oid, remoteRef, notForMerge }) => ({ oid, remoteRef, notForMerge }));
887
+ // do_fetch: a ref update refused (non-fast-forward, a tag it would clobber) jumps to the
888
+ // cleanup, past set_head (git 2.48+): the remote HEAD is not followed. FETCH_HEAD has its
889
+ // lines all the same (append_fetch_head writes each as the refs are stored), except with
890
+ // --atomic, where they wait for commit_fetch_head, which a refused or failed update skips:
891
+ // FETCH_HEAD stays as truncated. A failed --atomic transaction (the ref store refused it)
892
+ // jumps to the cleanup as well, past set_head; without --atomic the fetch goes on
893
+ const atomicFailed = this.atomic && result.refUpdates.some((u) => u.status === "rejected");
894
+ const refused = refusedUpdate(result) || atomicFailed;
895
+ if (writesFetchHead && checkout?.writeFetchHead && !atomicFailed) {
896
+ // after the truncation above, every fetch adds its lines
897
+ await checkout.writeFetchHead(formatFetchHead(entries, remoteUrl), { append: true });
898
+ }
899
+ const display = await this.displayLines(remoteUrl, trackingUpdates, result, entries, {
900
+ verbose: this.verbose,
901
+ porcelain: this.porcelain,
902
+ compact: !this.porcelain && store.value("fetch.output") === "compact",
903
+ });
904
+
905
+ if (followHead && !refused) {
906
+ // git: "way too many cases where this can go wrong ... fail silently"
907
+ try {
908
+ await this.setRemoteHead(result.remoteRefs, followHead, store, messages);
909
+ } catch {
910
+ // the refs are updated; refs/remotes/<name>/HEAD is left as it was
911
+ }
398
912
  }
399
913
 
914
+ // fetch.c: after the fetch (and its submodules), a split graph of what the refs reach
915
+ // (write_commit_graph_reachable with COMMIT_GRAPH_WRITE_SPLIT), on --write-commit-graph
916
+ // or fetch.writeCommitGraph
917
+ const commitGraphHashes = await this.writeCommitGraphAfterFetch(store, messages);
918
+
400
919
  return {
401
920
  uri: remoteUrl,
402
921
  advertisedRefs,
403
922
  trackingRefUpdates: trackingUpdates,
923
+ ...(commitGraphHashes ? { commitGraph: commitGraphHashes } : {}),
404
924
  defaultBranch: result.defaultBranch,
405
925
  bytesReceived: result.packBytes,
406
926
  isEmpty: result.isEmpty,
407
- messages: [],
927
+ messages,
928
+ display,
929
+ ...(errors.length > 0 ? { errors } : {}),
408
930
  };
409
931
  }
410
932
 
411
933
  /**
412
- * The refspecs this fetch runs with.
413
- *
414
- * Explicit refspecs win; otherwise a configured remote contributes its
415
- * `remote.<name>.fetch` lines, which is what makes `fetch().setRemote("origin")`
416
- * update tracking refs without being told how. A remote given as a bare URL
417
- * has no config and so still needs its refspecs spelled out.
934
+ * git's check_not_current_branch: the first branch of the ref map (the refs the refspecs
935
+ * took, then their opportunistic updates) that a worktree has checked out makes the fetch
936
+ * die, naming that worktree's path.
937
+ */
938
+ private async refuseCheckedOutBranch(refMap: readonly { localRef?: string }[]): Promise<void> {
939
+ const worktrees = this._workingCopy.worktrees;
940
+ if (!worktrees) return;
941
+ const branches = refMap
942
+ .map((p) => p.localRef)
943
+ .filter((ref): ref is string => ref?.startsWith("refs/heads/") ?? false);
944
+ for (const ref of new Set(branches)) {
945
+ const wt = await worktreeUsingBranch(worktrees, ref);
946
+ if (wt) throw new FetchIntoCheckedOutBranchError(ref, wt.path);
947
+ }
948
+ }
949
+
950
+ /**
951
+ * The lines git prints on stderr for the refs (fetch.c display_ref_update, full format):
952
+ * `From <url>`, the pruned refs (their summary column as wide as their own ids need), then
953
+ * the refs written or refused, in git's order: those to merge, the others the refspecs and
954
+ * tag following took, the opportunistic updates, the tags found in the fetched history;
955
+ * a ref fetched only into `FETCH_HEAD` as ` * branch <ref> -> FETCH_HEAD`. Refs already up
956
+ * to date are left out unless `verbose` (`-v`: ` = [up to date] …`). With `fetch.output`
957
+ * `compact`, a shared tail is written `*`; `porcelain` gives `--porcelain`'s lines (see
958
+ * {@link porcelainLine}).
959
+ */
960
+ private async displayLines(
961
+ url: string,
962
+ tracking: readonly TrackingRefUpdate[],
963
+ result: FetchClientResult,
964
+ entries: readonly { remoteRef: string; notForMerge: boolean }[],
965
+ format: { verbose: boolean; porcelain: boolean; compact: boolean },
966
+ ): Promise<string[]> {
967
+ const { verbose, porcelain, compact } = format;
968
+ const fetchedLocal = new Set(result.fetched.map((f) => f.localRef).filter((l) => l));
969
+ const backfilled = new Set(result.backfilledTags);
970
+ // refcol_width, once for every line: the ref map's refs written to a local ref (not the
971
+ // backfilled tags, not the pruned refs)
972
+ const refcolWidth = fetchRefcolWidth(
973
+ result.refUpdates
974
+ .filter((u) => !backfilled.has(u.localRef))
975
+ .map((u) => ({
976
+ remote: u.remoteRef,
977
+ local: u.localRef,
978
+ oldOid: u.oldOid,
979
+ newOid: u.newOid,
980
+ })),
981
+ { verbose, compact },
982
+ );
983
+ // the prune's lines come first, with their own summary width (transport_summary_width of
984
+ // the stale refs: each one's absent old value and its value here)
985
+ const lines: string[] = [];
986
+ const pruned = tracking.filter((u) => u.status === RefUpdateStatus.DELETED);
987
+ if (pruned.length > 0) {
988
+ const ids = pruned.flatMap((u) => [ZERO_OID, u.oldObjectId ?? ZERO_OID]);
989
+ const width = transportSummaryWidth(ids, await this.idAbbreviator().lengths(ids));
990
+ const prunedEntries = pruned.map((u) => ({
991
+ code: "-",
992
+ summary: "[deleted]",
993
+ remote: "(none)",
994
+ local: u.localRef,
995
+ // prune_refs passes the stale ref's value as the old id, none as the new one
996
+ oldOid: u.oldObjectId ?? ZERO_OID,
997
+ newOid: ZERO_OID,
998
+ }));
999
+ if (porcelain) lines.push(...prunedEntries.map(porcelainLine));
1000
+ else {
1001
+ lines.push(
1002
+ ...formatFetchDisplay(prunedEntries, { url, summaryWidth: width, refcolWidth, compact }),
1003
+ );
1004
+ }
1005
+ }
1006
+ const shown: FetchDisplayEntry[] = [];
1007
+ const toMerge = new Set(entries.filter((e) => !e.notForMerge).map((e) => e.remoteRef));
1008
+ const byLocal = new Map(result.refUpdates.map((u) => [u.localRef, u]));
1009
+ const taken = new Set<string>();
1010
+ const lineOf = (u: FetchRefUpdate | undefined) => {
1011
+ if (!u || taken.has(u.localRef)) return;
1012
+ taken.add(u.localRef);
1013
+ const entry = fetchUpdateDisplay(u, verbose);
1014
+ if (entry) shown.push(entry);
1015
+ };
1016
+ for (const merge of [true, false]) {
1017
+ for (const f of result.fetched) {
1018
+ if (f.shallowRejected || toMerge.has(f.remoteRef) !== merge) continue;
1019
+ if (f.localRef) {
1020
+ if (!backfilled.has(f.localRef)) lineOf(byLocal.get(f.localRef));
1021
+ } else if (
1022
+ (this.writeFetchHead || this.dryRun) &&
1023
+ // add_merge_config marks a ref the refspecs took already; only one they did not
1024
+ // take gets an entry of its own
1025
+ !result.fetched.some((o) => o.localRef && o.remoteRef === f.remoteRef)
1026
+ ) {
1027
+ shown.push({
1028
+ code: "*",
1029
+ summary: fetchHeadKind(f.remoteRef),
1030
+ remote: f.remoteRef,
1031
+ local: "FETCH_HEAD",
1032
+ oldOid: ZERO_OID,
1033
+ newOid: f.oid,
1034
+ });
1035
+ }
1036
+ }
1037
+ }
1038
+ for (const u of result.refUpdates) if (!fetchedLocal.has(u.localRef)) lineOf(u);
1039
+ for (const tag of result.backfilledTags) lineOf(byLocal.get(tag));
1040
+ // git 2.5x (do_fetch): a ref update refused (non-fast-forward, a tag it would clobber)
1041
+ // jumps to the cleanup before transport_summary_width is computed, so every line is
1042
+ // printed with a summary width of 0 (2.43 printed them as they come, padded)
1043
+ if (porcelain) return [...lines, ...shown.map(porcelainLine)];
1044
+ const summaryWidth = refusedUpdate(result) ? 0 : result.summaryWidth;
1045
+ const main = formatFetchDisplay(shown, { url, summaryWidth, refcolWidth, compact });
1046
+ // the URL line once, before whichever line comes first
1047
+ return lines.length > 0 ? [...lines, ...main.slice(1)] : main;
1048
+ }
1049
+
1050
+ /**
1051
+ * git's write of the commit-graph at the end of a fetch: when `--write-commit-graph` or
1052
+ * `fetch.writeCommitGraph` asks and the repository's files are known, a split layer of the
1053
+ * commits the refs reach (merged with the layers below as `--split` merges them; existing
1054
+ * changed-path filters are kept). Its warnings join `messages` as git prints them. The
1055
+ * layer hashes of the chain written, base first; undefined when nothing was written.
1056
+ */
1057
+ private async writeCommitGraphAfterFetch(
1058
+ store: RemoteConfigStore,
1059
+ messages: string[],
1060
+ ): Promise<string[] | undefined> {
1061
+ const write =
1062
+ this.writeCommitGraphOption ?? configBool(store.value("fetch.writeCommitGraph")) ?? false;
1063
+ const repository = this.repositoryFiles;
1064
+ const history = this._workingCopy.history;
1065
+ if (!write || !repository || !history.objects) return undefined;
1066
+ const environment = hostEnvironmentOf(this._workingCopy);
1067
+ const result = await writeCommitGraph({
1068
+ files: repository.files,
1069
+ gitDir: repository.gitDir,
1070
+ objects: history.objects,
1071
+ refs: history.refs,
1072
+ commitGraph: history.commitGraph,
1073
+ split: true,
1074
+ ...(environment ? { environment } : {}),
1075
+ });
1076
+ for (const warning of result.warnings) messages.push(`warning: ${warning}`);
1077
+ return result.written ? result.hashes : undefined;
1078
+ }
1079
+
1080
+ /**
1081
+ * How `refs/remotes/<name>/HEAD` follows the remote HEAD (git 2.48+): the remote's
1082
+ * `remote.<name>.followRemoteHEAD`, else `fetch.followRemoteHEAD`, else `create`; an
1083
+ * unrecognized value is ignored, as git warns and ignores it. Null for `never`.
418
1084
  */
419
- private effectiveRefSpecs(): string[] {
420
- if (this.refSpecs.length > 0) return this.refSpecs;
1085
+ private followRemoteHead(store: RemoteConfigStore): FollowRemoteHead | null {
1086
+ const mode = parseFollowRemoteHead(
1087
+ store.value(`remote.${this.remote}.followRemoteHEAD`),
1088
+ true,
1089
+ ) ??
1090
+ parseFollowRemoteHead(store.value("fetch.followRemoteHEAD"), false) ?? {
1091
+ mode: "create",
1092
+ };
1093
+ return mode.mode === "never" ? null : mode;
1094
+ }
1095
+
1096
+ /**
1097
+ * git's set_head (fetch.c): the one branch the remote HEAD names (its symref, or else the
1098
+ * only branch at its commit) becomes `refs/remotes/<name>/HEAD`, if that tracking ref
1099
+ * exists here: created when missing (`create`, `warn`), or always set (`always`). In a
1100
+ * bare repository mirroring the remote (`remote.<name>.mirror`), HEAD itself is set to
1101
+ * the branch. `warn` reports a local HEAD that differs, in git's words, into `messages`.
1102
+ * As in git, failures are silent and a dry run is no exception.
1103
+ */
1104
+ private async setRemoteHead(
1105
+ remoteRefs: readonly { name: string; oid?: string; symref?: string }[],
1106
+ follow: FollowRemoteHead,
1107
+ store: RemoteConfigStore,
1108
+ messages: string[],
1109
+ ): Promise<void> {
1110
+ const head = remoteRefs.find((r) => r.name === "HEAD");
1111
+ if (!head) return;
1112
+ const branches = remoteRefs.filter((r) => r.oid && r.name.startsWith("refs/heads/"));
1113
+ const heads = head.symref
1114
+ ? branches.filter((r) => r.name === head.symref)
1115
+ : branches.filter((r) => r.oid === head.oid);
1116
+ if (heads.length !== 1) return;
1117
+ const headName = heads[0].name.slice("refs/heads/".length);
1118
+ const remote = this.remote;
1119
+ const baremirror =
1120
+ configBool(store.value("core.bare")) === true &&
1121
+ configBool(store.value(`remote.${remote}.mirror`)) === true;
1122
+ const createOnly = follow.mode === "always" ? false : !baremirror;
1123
+ const name = baremirror ? "HEAD" : `refs/remotes/${remote}/HEAD`;
1124
+ const target = baremirror ? `refs/heads/${headName}` : `refs/remotes/${remote}/${headName}`;
1125
+ if (!baremirror && !(await this.refsStore.resolve(target))?.objectId) return;
1126
+ const previous = await this.refsStore.get(name);
1127
+ // refs_update_symref_extended(..., "fetch", ...): logged with the literal "fetch"
1128
+ if (!createOnly || !previous) {
1129
+ await this.refsStore.setSymbolic(name, target, this.reflogLine("fetch"));
1130
+ }
1131
+ if (follow.mode !== "warn" || follow.noWarnBranch === headName || !previous) return;
1132
+ // warn_set_head
1133
+ const prefix = `refs/remotes/${remote}/`;
1134
+ let warning: string | undefined;
1135
+ if (isSymbolicRef(previous)) {
1136
+ const was = previous.target.startsWith(prefix) ? previous.target.slice(prefix.length) : "";
1137
+ if (was && was !== headName) {
1138
+ warning = `'HEAD' at '${remote}' is '${headName}', but we have '${was}' locally.`;
1139
+ }
1140
+ } else {
1141
+ warning = `'HEAD' at '${remote}' is '${headName}', but we have a detached HEAD pointing to '${previous.objectId}' locally.`;
1142
+ }
1143
+ if (!warning) return;
1144
+ messages.push(warning);
1145
+ // set_head_advice_msg, unless advice.fetchRemoteHEADWarn is false
1146
+ if (configBool(store.value("advice.fetchRemoteHEADWarn")) === false) return;
1147
+ const advice = [
1148
+ `Run 'git remote set-head ${remote} ${headName}' to follow the change, or modify`,
1149
+ `either of the 'remote.${remote}.followRemoteHEAD' or 'fetch.followRemoteHEAD'`,
1150
+ "configuration variables to handle the situation differently.",
1151
+ "",
1152
+ "Using this specific setting",
1153
+ "",
1154
+ ` git config set remote.${remote}.followRemoteHEAD warn-if-not-${headName}`,
1155
+ "",
1156
+ "will suppress the warning until the remote changes HEAD to something else.",
1157
+ 'Disable this message with "git config set advice.fetchRemoteHEADWarn false"',
1158
+ ];
1159
+ messages.push(...advice.map((line) => (line ? `hint: ${line}` : "hint:")));
1160
+ }
1161
+
1162
+ /** The tag option given, else the remote's `remote.<name>.tagOpt`, else auto-follow. */
1163
+ private effectiveTagOption(): TagOption {
1164
+ if (this.tagOptionSet) return this.tagOption;
1165
+ const tagOpt = RemoteConfigStore.from(this.workingCopy).value(`remote.${this.remote}.tagOpt`);
1166
+ if (tagOpt === "--no-tags") return TagOption.NO_TAGS;
1167
+ if (tagOpt === "--tags") return TagOption.FETCH_TAGS;
1168
+ return this.tagOption;
1169
+ }
1170
+
1171
+ /**
1172
+ * The current branch's upstream: its `branch.<name>.remote` and `branch.<name>.merge`
1173
+ * refs, when both are set (git's branch_has_merge_config); undefined on a detached HEAD
1174
+ * or without upstream configuration.
1175
+ */
1176
+ private async upstreamConfig(): Promise<{ remote: string; merge: string[] } | undefined> {
1177
+ const head = await this.refsStore.get("HEAD");
1178
+ if (!head || !isSymbolicRef(head) || !head.target.startsWith("refs/heads/")) return undefined;
1179
+ const branch = head.target.slice("refs/heads/".length);
421
1180
  const store = RemoteConfigStore.from(this.workingCopy);
422
- return store.isConfigured(this.remote) ? store.read(this.remote).fetchRefspecs : [];
1181
+ const remote = store.value(`branch.${branch}.remote`);
1182
+ const merge = store.values(`branch.${branch}.merge`);
1183
+ return remote !== undefined && merge.length > 0 ? { remote, merge } : undefined;
423
1184
  }
424
1185
 
425
1186
  /**
426
- * Resolve remote name to URL.
427
- *
428
- * A named remote resolves through `remote.<name>.url` in the working copy
429
- * configuration. An unconfigured name is passed through unchanged, so a URL
430
- * given straight to {@link setRemote} still works.
1187
+ * The `FETCH_HEAD` lines of a fetch, marked as git's get_ref_map marks them: refs from
1188
+ * explicit refspecs (or the HEAD of an unconfigured remote) are to merge; with configured
1189
+ * refspecs, the refs the current branch's `branch.<name>.merge` names (fetched for this
1190
+ * alone when no refspec took them), or else the first ref when the first refspec names
1191
+ * one ref. Tags (`--tags`, auto-follow), the rest, and anything that does not peel to a
1192
+ * commit are `not-for-merge`.
431
1193
  */
432
- private async resolveRemoteUrl(remote: string): Promise<string | undefined> {
433
- // If it looks like a URL, use it directly
434
- if (remote.includes("://") || remote.includes("@")) {
435
- return remote;
1194
+ private async fetchHeadEntries(
1195
+ result: FetchClientResult,
1196
+ marks: {
1197
+ given: number;
1198
+ merge: string[];
1199
+ explicit: boolean;
1200
+ firstIsExact: boolean;
1201
+ hasMerge: boolean;
1202
+ },
1203
+ ): Promise<Array<FetchHeadEntry & { localRef?: string; shallowRejected?: boolean }>> {
1204
+ const mergeSpec = (index: number | undefined) =>
1205
+ index !== undefined && index >= marks.given && index < marks.given + marks.merge.length
1206
+ ? index - marks.given
1207
+ : undefined;
1208
+ const entries: (FetchHeadEntry & {
1209
+ refspec?: number;
1210
+ localRef?: string;
1211
+ shallowRejected?: boolean;
1212
+ })[] = [];
1213
+ for (const fetched of result.fetched) {
1214
+ if (mergeSpec(fetched.refspec) !== undefined) continue;
1215
+ const fromGiven = fetched.refspec !== undefined && fetched.refspec < marks.given;
1216
+ entries.push({
1217
+ oid: fetched.oid,
1218
+ remoteRef: fetched.remoteRef,
1219
+ notForMerge: !(marks.explicit && fromGiven),
1220
+ refspec: fetched.refspec,
1221
+ localRef: fetched.localRef,
1222
+ ...(fetched.shallowRejected ? { shallowRejected: true } : {}),
1223
+ });
1224
+ }
1225
+ if (!marks.explicit) {
1226
+ if (!marks.hasMerge && marks.firstIsExact && entries[0]?.refspec === 0) {
1227
+ entries[0].notForMerge = false;
1228
+ }
1229
+ // each merge ref marks the first ref a configured refspec took that it names...
1230
+ const matched = new Set<number>();
1231
+ for (const [k, ref] of marks.merge.entries()) {
1232
+ const match = entries.find(
1233
+ (e) =>
1234
+ e.refspec !== undefined && e.refspec < marks.given && refNameMatches(ref, e.remoteRef),
1235
+ );
1236
+ if (match) {
1237
+ match.notForMerge = false;
1238
+ matched.add(k);
1239
+ }
1240
+ }
1241
+ // ...or else is listed itself, after the refs the configured refspecs took
1242
+ const extra: typeof entries = [];
1243
+ for (const fetched of result.fetched) {
1244
+ const k = mergeSpec(fetched.refspec);
1245
+ if (k === undefined || matched.has(k)) continue;
1246
+ extra.push({
1247
+ oid: fetched.oid,
1248
+ remoteRef: fetched.remoteRef,
1249
+ notForMerge: false,
1250
+ localRef: fetched.localRef,
1251
+ ...(fetched.shallowRejected ? { shallowRejected: true } : {}),
1252
+ });
1253
+ }
1254
+ const tagsAt = entries.findIndex((e) => e.refspec === undefined || e.refspec >= marks.given);
1255
+ entries.splice(tagsAt < 0 ? entries.length : tagsAt, 0, ...extra);
436
1256
  }
1257
+ for (const entry of entries) {
1258
+ if (!entry.notForMerge && !(await this.peelsToCommit(entry.oid))) entry.notForMerge = true;
1259
+ }
1260
+ return entries.map(({ oid, remoteRef, notForMerge, localRef, shallowRejected }) => ({
1261
+ oid,
1262
+ remoteRef,
1263
+ notForMerge,
1264
+ ...(localRef !== undefined ? { localRef } : {}),
1265
+ ...(shallowRejected ? { shallowRejected } : {}),
1266
+ }));
1267
+ }
1268
+
1269
+ /** Whether `id` is a commit, or a tag (chain) of one (git's lookup_commit_reference_gently). */
1270
+ private async peelsToCommit(id: ObjectId): Promise<boolean> {
1271
+ // parse_object reads through replace refs
1272
+ const commits = this.commits;
1273
+ const tags = this.tagsStore;
1274
+ let current: ObjectId | undefined = id;
1275
+ for (let i = 0; current && i < 16; i++) {
1276
+ if (await commits.has(current)) return true;
1277
+ if (!tags || !(await tags.has(current))) return false;
1278
+ current = await tags.getTarget(current);
1279
+ }
1280
+ return false;
1281
+ }
437
1282
 
438
- return RemoteConfigStore.from(this.workingCopy).urlFor(remote) ?? remote;
1283
+ /**
1284
+ * Resolve remote name to URL, as git's `remote_get`: a remote whose configuration gives it
1285
+ * a URL uses that (`remote.<name>.url`); anything else is a URL or path itself. Either is
1286
+ * rewritten by `url.<base>.insteadOf`.
1287
+ */
1288
+ private async resolveRemoteUrl(remote: string): Promise<string | undefined> {
1289
+ return RemoteConfigStore.from(this.workingCopy).remoteUrlOf(remote);
439
1290
  }
440
1291
 
441
1292
  /**
442
- * Prune local refs that a refspec maps from a remote ref that no longer exists (git's
443
- * `--prune`): for each refspec with a destination, the local refs matching the
444
- * destination whose source is not among the remote refs are deleted, unless a negative
445
- * refspec excludes that source (git's query_matches_negative_refspec).
1293
+ * The stale remote-tracking refs (git's get_stale_heads): every local ref that the
1294
+ * refspecs map from remote refs (all of the matching refspecs: overlapping ones count
1295
+ * together), none of which the remote has, unless a negative refspec excludes it or it is
1296
+ * a symbolic ref. They are deleted (reflogs too) in one batch, logged `fetch: prune`, and
1297
+ * reported as deleted; a dry run reports them only, `defer` leaves the deletion to the
1298
+ * --atomic transaction. The symbolic refs left dangling are
1299
+ * named in `messages` as git does. A refused delete does not stop the fetch: as in git
1300
+ * (which then exits 1), the error goes into `errors` and nothing is reported deleted.
446
1301
  */
447
1302
  private async pruneDeletedRefs(
448
1303
  remoteRefNames: Set<string>,
449
1304
  specs: RefSpec[],
1305
+ messages: string[],
1306
+ errors: string[],
1307
+ /** Leave the deletion to the caller (the --atomic transaction) */
1308
+ defer = false,
450
1309
  ): Promise<TrackingRefUpdate[]> {
451
- const updates: TrackingRefUpdate[] = [];
452
- const done = new Set<string>();
453
1310
  const negative = specs.filter((s) => s.negative && s.source);
454
- for (const spec of specs) {
455
- if (spec.negative || !spec.source || !spec.destination) continue;
456
- const prefix = spec.wildcard
457
- ? spec.destination.slice(0, spec.destination.indexOf("*"))
458
- : spec.destination;
459
- for await (const ref of this.refsStore.list(prefix)) {
460
- if (isSymbolicRef(ref) || done.has(ref.name)) continue;
461
- let source: string | null;
1311
+ const mapping = specs.filter((s) => !s.negative && s.source && s.destination);
1312
+ const stale: { name: string; objectId: ObjectId; source: string }[] = [];
1313
+ for await (const ref of this.refsStore.list("refs/")) {
1314
+ const sources: string[] = [];
1315
+ for (const spec of mapping) {
462
1316
  if (spec.wildcard) {
463
1317
  if (!matchDestination(spec, ref.name)) continue;
464
- source = expandFromDestination(spec, ref.name).source;
465
- } else {
466
- if (ref.name !== spec.destination) continue;
467
- source = spec.source;
1318
+ const source = expandFromDestination(spec, ref.name).source;
1319
+ if (source) sources.push(source);
1320
+ } else if (ref.name === spec.destination && spec.source) {
1321
+ sources.push(spec.source);
468
1322
  }
469
- if (!source || remoteRefNames.has(source)) continue;
470
- if (negative.some((n) => matchSource(n, source))) continue;
471
- done.add(ref.name);
472
- await this.refsStore.delete(ref.name);
473
- updates.push({
474
- localRef: ref.name,
475
- remoteRef: source,
476
- oldObjectId: ref.objectId,
477
- newObjectId: "", // Empty indicates deletion
478
- status: RefUpdateStatus.DELETED,
479
- });
480
1323
  }
1324
+ if (sources.length === 0 || isSymbolicRef(ref) || !ref.objectId) continue;
1325
+ if (sources.some((src) => negative.some((n) => matchSource(n, src)))) continue;
1326
+ if (sources.some((src) => remoteRefNames.has(src))) continue;
1327
+ stale.push({ name: ref.name, objectId: ref.objectId, source: sources[0] });
481
1328
  }
482
- return updates;
1329
+ if (stale.length === 0) return [];
1330
+ // refs_warn_dangling_symrefs: listed before the deletion, as the targets go
1331
+ const dangling = await this.danglingSymrefs(new Set(stale.map((r) => r.name)));
1332
+ if (!this.dryRun && !defer) {
1333
+ try {
1334
+ await deleteRefs(
1335
+ this.refsStore,
1336
+ stale.map((r) => r.name),
1337
+ "fetch: prune",
1338
+ { legacy: this.hooks.compatibility === "2.43" },
1339
+ );
1340
+ } catch (error) {
1341
+ errors.push(error instanceof Error ? error.message : String(error));
1342
+ return [];
1343
+ }
1344
+ }
1345
+ for (const { name, target } of dangling) {
1346
+ messages.push(
1347
+ this.dryRun
1348
+ ? ` ${name} will become dangling after ${target} is deleted`
1349
+ : ` ${name} has become dangling after ${target} was deleted`,
1350
+ );
1351
+ }
1352
+ return stale.map((ref) => ({
1353
+ localRef: ref.name,
1354
+ remoteRef: ref.source,
1355
+ oldObjectId: ref.objectId,
1356
+ newObjectId: "", // Empty indicates deletion
1357
+ status: RefUpdateStatus.DELETED,
1358
+ summary: "[deleted]",
1359
+ }));
483
1360
  }
1361
+
1362
+ /** The symbolic refs whose chain ends at one of `names` (git's warn_if_dangling_symref). */
1363
+ private async danglingSymrefs(names: Set<string>): Promise<{ name: string; target: string }[]> {
1364
+ const found: { name: string; target: string }[] = [];
1365
+ for await (const ref of this.refsStore.list("refs/")) {
1366
+ if (!isSymbolicRef(ref)) continue;
1367
+ let target = ref.target;
1368
+ for (let i = 0; i < 5; i++) {
1369
+ const next = await this.refsStore.get(target);
1370
+ if (!next || !isSymbolicRef(next)) break;
1371
+ target = next.target;
1372
+ }
1373
+ if (names.has(target)) found.push({ name: ref.name, target });
1374
+ }
1375
+ return found.sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0));
1376
+ }
1377
+ }
1378
+
1379
+ /** fetch.c's kind of a ref fetched into `FETCH_HEAD` only: `branch`, `tag`, … (`branch` else). */
1380
+ function fetchHeadKind(name: string): string {
1381
+ if (name.startsWith("refs/tags/")) return "tag";
1382
+ if (name.startsWith("refs/remotes/")) return "remote-tracking branch";
1383
+ return "branch";
484
1384
  }
485
1385
 
486
1386
  /** The transport's tag mode for a {@link TagOption}. */
@@ -519,3 +1419,62 @@ export function toTrackingRefUpdate(update: FetchRefUpdate): TrackingRefUpdate {
519
1419
  reason: update.reason,
520
1420
  };
521
1421
  }
1422
+
1423
+ /** git's TAG_REFSPEC, which `--prune-tags` adds. */
1424
+ const TAG_REFSPEC = "refs/tags/*:refs/tags/*";
1425
+
1426
+ /** How `refs/remotes/<name>/HEAD` follows the remote HEAD (`remote.<name>.followRemoteHEAD`). */
1427
+ interface FollowRemoteHead {
1428
+ mode: "never" | "create" | "warn" | "always";
1429
+ /** `warn-if-not-<branch>`: no warning while the remote HEAD is this branch */
1430
+ noWarnBranch?: string;
1431
+ }
1432
+
1433
+ /**
1434
+ * A `followRemoteHEAD` value; undefined when unset or unrecognized. `warn-if-not-<branch>`
1435
+ * is read from `remote.<name>.followRemoteHEAD` only, as git's remote.c does.
1436
+ */
1437
+ function parseFollowRemoteHead(
1438
+ value: string | undefined,
1439
+ perRemote: boolean,
1440
+ ): FollowRemoteHead | undefined {
1441
+ if (value === "never" || value === "create" || value === "warn" || value === "always") {
1442
+ return { mode: value };
1443
+ }
1444
+ if (perRemote && value?.startsWith("warn-if-not-")) {
1445
+ return { mode: "warn", noWarnBranch: value.slice("warn-if-not-".length) };
1446
+ }
1447
+ return undefined;
1448
+ }
1449
+
1450
+ /** A git boolean config value; undefined when unset or not a boolean. */
1451
+ const configBool = (value: string | undefined): boolean | undefined => parseGitBool(value);
1452
+
1453
+ /** git's refname_match: `ref` (`main`, `heads/main`, `refs/heads/main`) names `fullName`. */
1454
+ function refNameMatches(ref: string, fullName: string): boolean {
1455
+ return [
1456
+ ref,
1457
+ `refs/${ref}`,
1458
+ `refs/tags/${ref}`,
1459
+ `refs/heads/${ref}`,
1460
+ `refs/remotes/${ref}`,
1461
+ `refs/remotes/${ref}/HEAD`,
1462
+ ].includes(fullName);
1463
+ }
1464
+
1465
+ /**
1466
+ * Whether a ref update was refused as git's update_local_ref refuses one (a non-fast-forward,
1467
+ * a tag it would clobber), not by the ref store: git 2.5x's do_fetch then goes to its
1468
+ * cleanup.
1469
+ */
1470
+ function refusedUpdate(result: FetchClientResult): boolean {
1471
+ return result.refUpdates.some((u) => u.status === "rejected" && u.storeError === undefined);
1472
+ }
1473
+
1474
+ /**
1475
+ * A ref line of `git fetch --porcelain` (display_ref_update's porcelain format): the flag,
1476
+ * the old and new ids in full (zeros for none), the local ref's full name.
1477
+ */
1478
+ function porcelainLine(entry: FetchDisplayEntry): string {
1479
+ return `${entry.code} ${entry.oldOid ?? ZERO_OID} ${entry.newOid ?? ZERO_OID} ${entry.local}`;
1480
+ }