@statewalker/vcs-commands 0.7.0 → 0.8.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 (410) hide show
  1. package/dist/commands/add-command.d.ts +38 -0
  2. package/dist/commands/add-command.d.ts.map +1 -1
  3. package/dist/commands/am/am-command.d.ts +55 -1
  4. package/dist/commands/am/am-command.d.ts.map +1 -1
  5. package/dist/commands/am/index.d.ts +1 -0
  6. package/dist/commands/am/index.d.ts.map +1 -1
  7. package/dist/commands/am/mailsplit.d.ts +88 -0
  8. package/dist/commands/am/mailsplit.d.ts.map +1 -0
  9. package/dist/commands/apply/apply-command.d.ts.map +1 -1
  10. package/dist/commands/apply/apply-engine.d.ts.map +1 -1
  11. package/dist/commands/apply/apply-parse.d.ts.map +1 -1
  12. package/dist/commands/bisect/bisect-command.d.ts +2 -0
  13. package/dist/commands/bisect/bisect-command.d.ts.map +1 -1
  14. package/dist/commands/branch-command.d.ts +148 -18
  15. package/dist/commands/branch-command.d.ts.map +1 -1
  16. package/dist/commands/branch-info-command.d.ts +55 -0
  17. package/dist/commands/branch-info-command.d.ts.map +1 -0
  18. package/dist/commands/branch-tracking.d.ts +106 -17
  19. package/dist/commands/branch-tracking.d.ts.map +1 -1
  20. package/dist/commands/branch-upstream-command.d.ts +83 -0
  21. package/dist/commands/branch-upstream-command.d.ts.map +1 -0
  22. package/dist/commands/checkout-command.d.ts +19 -3
  23. package/dist/commands/checkout-command.d.ts.map +1 -1
  24. package/dist/commands/cherry-pick-command.d.ts +59 -0
  25. package/dist/commands/cherry-pick-command.d.ts.map +1 -1
  26. package/dist/commands/clean-command.d.ts +12 -0
  27. package/dist/commands/clean-command.d.ts.map +1 -1
  28. package/dist/commands/clone-command.d.ts.map +1 -1
  29. package/dist/commands/commit-command.d.ts +191 -5
  30. package/dist/commands/commit-command.d.ts.map +1 -1
  31. package/dist/commands/commit-reuse.d.ts +33 -0
  32. package/dist/commands/commit-reuse.d.ts.map +1 -0
  33. package/dist/commands/config-command.d.ts +236 -0
  34. package/dist/commands/config-command.d.ts.map +1 -0
  35. package/dist/commands/config-value-types.d.ts +91 -0
  36. package/dist/commands/config-value-types.d.ts.map +1 -0
  37. package/dist/commands/core-config.d.ts +20 -0
  38. package/dist/commands/core-config.d.ts.map +1 -1
  39. package/dist/commands/diff-color-config.d.ts +73 -0
  40. package/dist/commands/diff-color-config.d.ts.map +1 -0
  41. package/dist/commands/diff-command.d.ts +252 -5
  42. package/dist/commands/diff-command.d.ts.map +1 -1
  43. package/dist/commands/fetch-command.d.ts +20 -0
  44. package/dist/commands/fetch-command.d.ts.map +1 -1
  45. package/dist/commands/fmt-merge-msg-command.d.ts +124 -0
  46. package/dist/commands/fmt-merge-msg-command.d.ts.map +1 -0
  47. package/dist/commands/fork-point.d.ts +38 -0
  48. package/dist/commands/fork-point.d.ts.map +1 -0
  49. package/dist/commands/format-patch-command.d.ts +41 -1
  50. package/dist/commands/format-patch-command.d.ts.map +1 -1
  51. package/dist/commands/fsck/fetch-fsck.d.ts +51 -0
  52. package/dist/commands/fsck/fetch-fsck.d.ts.map +1 -1
  53. package/dist/commands/gc-command.d.ts +8 -0
  54. package/dist/commands/gc-command.d.ts.map +1 -1
  55. package/dist/commands/git-describe.d.ts +4 -0
  56. package/dist/commands/git-describe.d.ts.map +1 -1
  57. package/dist/commands/git-hooks.d.ts +35 -0
  58. package/dist/commands/git-hooks.d.ts.map +1 -1
  59. package/dist/commands/grep/grep-command.d.ts +210 -0
  60. package/dist/commands/grep/grep-command.d.ts.map +1 -0
  61. package/dist/commands/grep/grep-engine.d.ts +218 -0
  62. package/dist/commands/grep/grep-engine.d.ts.map +1 -0
  63. package/dist/commands/grep/index.d.ts +3 -0
  64. package/dist/commands/grep/index.d.ts.map +1 -0
  65. package/dist/commands/index-adder.d.ts +13 -2
  66. package/dist/commands/index-adder.d.ts.map +1 -1
  67. package/dist/commands/index.d.ts +26 -0
  68. package/dist/commands/index.d.ts.map +1 -1
  69. package/dist/commands/index.js +3 -3
  70. package/dist/commands/interpret-trailers-command.d.ts +90 -0
  71. package/dist/commands/interpret-trailers-command.d.ts.map +1 -0
  72. package/dist/commands/local-transport.d.ts +36 -5
  73. package/dist/commands/local-transport.d.ts.map +1 -1
  74. package/dist/commands/log-command.d.ts +296 -11
  75. package/dist/commands/log-command.d.ts.map +1 -1
  76. package/dist/commands/log-graph.d.ts +26 -1
  77. package/dist/commands/log-graph.d.ts.map +1 -1
  78. package/dist/commands/log-output.d.ts +133 -5
  79. package/dist/commands/log-output.d.ts.map +1 -1
  80. package/dist/commands/ls-remote-command.d.ts +2 -0
  81. package/dist/commands/ls-remote-command.d.ts.map +1 -1
  82. package/dist/commands/mailmap.d.ts +30 -0
  83. package/dist/commands/mailmap.d.ts.map +1 -1
  84. package/dist/commands/merge-base-command.d.ts +60 -0
  85. package/dist/commands/merge-base-command.d.ts.map +1 -0
  86. package/dist/commands/merge-bases.d.ts +23 -0
  87. package/dist/commands/merge-bases.d.ts.map +1 -1
  88. package/dist/commands/merge-command.d.ts +96 -9
  89. package/dist/commands/merge-command.d.ts.map +1 -1
  90. package/dist/commands/merge-support.d.ts.map +1 -1
  91. package/dist/commands/mv-command.d.ts +4 -0
  92. package/dist/commands/mv-command.d.ts.map +1 -1
  93. package/dist/commands/name-rev.d.ts +48 -0
  94. package/dist/commands/name-rev.d.ts.map +1 -0
  95. package/dist/commands/notes-command.d.ts.map +1 -1
  96. package/dist/commands/pathspec-file.d.ts +39 -0
  97. package/dist/commands/pathspec-file.d.ts.map +1 -0
  98. package/dist/commands/pathspec.d.ts +3 -0
  99. package/dist/commands/pathspec.d.ts.map +1 -1
  100. package/dist/commands/pretty-format.d.ts +43 -3
  101. package/dist/commands/pretty-format.d.ts.map +1 -1
  102. package/dist/commands/promisor-remote.d.ts.map +1 -1
  103. package/dist/commands/pull-command.d.ts +10 -0
  104. package/dist/commands/pull-command.d.ts.map +1 -1
  105. package/dist/commands/push-command.d.ts +160 -9
  106. package/dist/commands/push-command.d.ts.map +1 -1
  107. package/dist/commands/read-tree-command.d.ts +6 -0
  108. package/dist/commands/read-tree-command.d.ts.map +1 -1
  109. package/dist/commands/rebase-command.d.ts +168 -6
  110. package/dist/commands/rebase-command.d.ts.map +1 -1
  111. package/dist/commands/ref-filter/for-each-ref-command.d.ts +121 -0
  112. package/dist/commands/ref-filter/for-each-ref-command.d.ts.map +1 -0
  113. package/dist/commands/ref-filter/index.d.ts +8 -0
  114. package/dist/commands/ref-filter/index.d.ts.map +1 -0
  115. package/dist/commands/ref-filter/ref-atoms.d.ts +88 -0
  116. package/dist/commands/ref-filter/ref-atoms.d.ts.map +1 -0
  117. package/dist/commands/ref-filter/ref-filter.d.ts +178 -0
  118. package/dist/commands/ref-filter/ref-filter.d.ts.map +1 -0
  119. package/dist/commands/ref-filter/ref-format.d.ts +222 -0
  120. package/dist/commands/ref-filter/ref-format.d.ts.map +1 -0
  121. package/dist/commands/ref-filter/ref-listing-command.d.ts +56 -0
  122. package/dist/commands/ref-filter/ref-listing-command.d.ts.map +1 -0
  123. package/dist/commands/ref-filter/ref-quote.d.ts +20 -0
  124. package/dist/commands/ref-filter/ref-quote.d.ts.map +1 -0
  125. package/dist/commands/ref-filter/version-compare.d.ts +20 -0
  126. package/dist/commands/ref-filter/version-compare.d.ts.map +1 -0
  127. package/dist/commands/reflog-command.d.ts +120 -0
  128. package/dist/commands/reflog-command.d.ts.map +1 -1
  129. package/dist/commands/reflog-walk.d.ts +72 -0
  130. package/dist/commands/reflog-walk.d.ts.map +1 -0
  131. package/dist/commands/remote-command.d.ts +138 -29
  132. package/dist/commands/remote-command.d.ts.map +1 -1
  133. package/dist/commands/remote-transport.d.ts +7 -1
  134. package/dist/commands/remote-transport.d.ts.map +1 -1
  135. package/dist/commands/reset-command.d.ts +2 -3
  136. package/dist/commands/reset-command.d.ts.map +1 -1
  137. package/dist/commands/restore-command.d.ts +2 -3
  138. package/dist/commands/restore-command.d.ts.map +1 -1
  139. package/dist/commands/rev-filter/commit-filter.d.ts +95 -0
  140. package/dist/commands/rev-filter/commit-filter.d.ts.map +1 -0
  141. package/dist/commands/rev-filter/commit-grep.d.ts +91 -0
  142. package/dist/commands/rev-filter/commit-grep.d.ts.map +1 -0
  143. package/dist/commands/rev-filter/index.d.ts +3 -0
  144. package/dist/commands/rev-filter/index.d.ts.map +1 -0
  145. package/dist/commands/rev-list-command.d.ts +154 -2
  146. package/dist/commands/rev-list-command.d.ts.map +1 -1
  147. package/dist/commands/revert-command.d.ts +32 -0
  148. package/dist/commands/revert-command.d.ts.map +1 -1
  149. package/dist/commands/revision-range.d.ts +32 -1
  150. package/dist/commands/revision-range.d.ts.map +1 -1
  151. package/dist/commands/revision-resolver.d.ts +15 -0
  152. package/dist/commands/revision-resolver.d.ts.map +1 -1
  153. package/dist/commands/rm-command.d.ts +70 -2
  154. package/dist/commands/rm-command.d.ts.map +1 -1
  155. package/dist/commands/sequencer-pick.d.ts +84 -4
  156. package/dist/commands/sequencer-pick.d.ts.map +1 -1
  157. package/dist/commands/sequencer-support.d.ts +2 -0
  158. package/dist/commands/sequencer-support.d.ts.map +1 -1
  159. package/dist/commands/serve-repository.d.ts +7 -0
  160. package/dist/commands/serve-repository.d.ts.map +1 -1
  161. package/dist/commands/show-command.d.ts +130 -0
  162. package/dist/commands/show-command.d.ts.map +1 -0
  163. package/dist/commands/show-commit.d.ts +11 -0
  164. package/dist/commands/show-commit.d.ts.map +1 -0
  165. package/dist/commands/signature-check.d.ts +164 -0
  166. package/dist/commands/signature-check.d.ts.map +1 -0
  167. package/dist/commands/signing.d.ts +160 -0
  168. package/dist/commands/signing.d.ts.map +1 -0
  169. package/dist/commands/sparse-checkout-command.d.ts.map +1 -1
  170. package/dist/commands/sparse-index-view.d.ts +45 -0
  171. package/dist/commands/sparse-index-view.d.ts.map +1 -0
  172. package/dist/commands/ssh-signer.d.ts +29 -0
  173. package/dist/commands/ssh-signer.d.ts.map +1 -0
  174. package/dist/commands/ssh-verifier.d.ts +42 -0
  175. package/dist/commands/ssh-verifier.d.ts.map +1 -0
  176. package/dist/commands/stash-apply-command.d.ts +5 -0
  177. package/dist/commands/stash-apply-command.d.ts.map +1 -1
  178. package/dist/commands/stash-branch-command.d.ts +34 -0
  179. package/dist/commands/stash-branch-command.d.ts.map +1 -0
  180. package/dist/commands/stash-create-command.d.ts +17 -0
  181. package/dist/commands/stash-create-command.d.ts.map +1 -1
  182. package/dist/commands/stash-info.d.ts +93 -0
  183. package/dist/commands/stash-info.d.ts.map +1 -0
  184. package/dist/commands/stash-list-command.d.ts +16 -0
  185. package/dist/commands/stash-list-command.d.ts.map +1 -1
  186. package/dist/commands/stash-pop-command.d.ts +39 -0
  187. package/dist/commands/stash-pop-command.d.ts.map +1 -0
  188. package/dist/commands/stash-show-command.d.ts +48 -0
  189. package/dist/commands/stash-show-command.d.ts.map +1 -0
  190. package/dist/commands/stash-store-command.d.ts +29 -0
  191. package/dist/commands/stash-store-command.d.ts.map +1 -0
  192. package/dist/commands/stash-working-tree.d.ts.map +1 -1
  193. package/dist/commands/status-command.d.ts.map +1 -1
  194. package/dist/commands/status-header.d.ts +5 -0
  195. package/dist/commands/status-header.d.ts.map +1 -1
  196. package/dist/commands/submodule-add-command.d.ts +89 -0
  197. package/dist/commands/submodule-add-command.d.ts.map +1 -0
  198. package/dist/commands/submodule-auth.d.ts +90 -0
  199. package/dist/commands/submodule-auth.d.ts.map +1 -0
  200. package/dist/commands/submodule-commands.d.ts +375 -0
  201. package/dist/commands/submodule-commands.d.ts.map +1 -0
  202. package/dist/commands/submodule-model.d.ts +288 -0
  203. package/dist/commands/submodule-model.d.ts.map +1 -0
  204. package/dist/commands/submodule-update-command.d.ts +198 -0
  205. package/dist/commands/submodule-update-command.d.ts.map +1 -0
  206. package/dist/commands/switch-command.d.ts.map +1 -1
  207. package/dist/commands/tag-command.d.ts +259 -10
  208. package/dist/commands/tag-command.d.ts.map +1 -1
  209. package/dist/commands/trailers.d.ts +218 -17
  210. package/dist/commands/trailers.d.ts.map +1 -1
  211. package/dist/commands/tree-restore.d.ts +7 -0
  212. package/dist/commands/tree-restore.d.ts.map +1 -1
  213. package/dist/commands/verify-command.d.ts +92 -0
  214. package/dist/commands/verify-command.d.ts.map +1 -0
  215. package/dist/commands/worktree-add-command.d.ts +79 -7
  216. package/dist/commands/worktree-add-command.d.ts.map +1 -1
  217. package/dist/commands/worktree-path-rules.d.ts +66 -0
  218. package/dist/commands/worktree-path-rules.d.ts.map +1 -0
  219. package/dist/commands/worktree-remove-command.d.ts +10 -3
  220. package/dist/commands/worktree-remove-command.d.ts.map +1 -1
  221. package/dist/commands/worktree-repair-command.d.ts +15 -2
  222. package/dist/commands/worktree-repair-command.d.ts.map +1 -1
  223. package/dist/commands/worktree-support.d.ts +5 -0
  224. package/dist/commands/worktree-support.d.ts.map +1 -1
  225. package/dist/{commands-DIJ91NnD.js → commands-ISM52N0n.js} +70736 -54492
  226. package/dist/errors/checkout-errors.d.ts +19 -0
  227. package/dist/errors/checkout-errors.d.ts.map +1 -1
  228. package/dist/errors/command-errors.d.ts.map +1 -1
  229. package/dist/errors/index.js +57 -3
  230. package/dist/errors/ref-errors.d.ts +19 -0
  231. package/dist/errors/ref-errors.d.ts.map +1 -1
  232. package/dist/errors/worktree-errors.d.ts +6 -1
  233. package/dist/errors/worktree-errors.d.ts.map +1 -1
  234. package/dist/{git-command-BGiOJ8Zk.js → fsck-DLRpbwTj.js} +6230 -71
  235. package/dist/git-command.d.ts +27 -1
  236. package/dist/git-command.d.ts.map +1 -1
  237. package/dist/git.d.ts +267 -1
  238. package/dist/git.d.ts.map +1 -1
  239. package/dist/index.js +5 -5
  240. package/dist/remote-config/index.d.ts +1 -1
  241. package/dist/remote-config/index.d.ts.map +1 -1
  242. package/dist/remote-config/remote-config-store.d.ts +55 -0
  243. package/dist/remote-config/remote-config-store.d.ts.map +1 -1
  244. package/dist/results/combined-diff.d.ts +3 -0
  245. package/dist/results/combined-diff.d.ts.map +1 -1
  246. package/dist/results/diff-check.d.ts +38 -0
  247. package/dist/results/diff-check.d.ts.map +1 -0
  248. package/dist/results/diff-color.d.ts +135 -0
  249. package/dist/results/diff-color.d.ts.map +1 -0
  250. package/dist/results/diff-output.d.ts +85 -1
  251. package/dist/results/diff-output.d.ts.map +1 -1
  252. package/dist/results/diff-pickaxe.d.ts +67 -0
  253. package/dist/results/diff-pickaxe.d.ts.map +1 -0
  254. package/dist/results/diff-words.d.ts +55 -0
  255. package/dist/results/diff-words.d.ts.map +1 -0
  256. package/dist/results/index.d.ts +4 -0
  257. package/dist/results/index.d.ts.map +1 -1
  258. package/dist/results/index.js +2 -2
  259. package/dist/results/push-result.d.ts +7 -0
  260. package/dist/results/push-result.d.ts.map +1 -1
  261. package/dist/results/rebase-result.d.ts +2 -0
  262. package/dist/results/rebase-result.d.ts.map +1 -1
  263. package/dist/results/stash-result.d.ts +6 -0
  264. package/dist/results/stash-result.d.ts.map +1 -1
  265. package/dist/{results-WVlBhVb1.js → results-TB2IJ64h.js} +2168 -403
  266. package/dist/whitespace/index.d.ts +2 -0
  267. package/dist/whitespace/index.d.ts.map +1 -0
  268. package/dist/whitespace/whitespace-rule.d.ts +94 -0
  269. package/dist/whitespace/whitespace-rule.d.ts.map +1 -0
  270. package/package.json +12 -12
  271. package/src/commands/add-command.ts +178 -17
  272. package/src/commands/am/am-command.ts +262 -42
  273. package/src/commands/am/index.ts +1 -0
  274. package/src/commands/am/mailsplit.ts +326 -0
  275. package/src/commands/apply/apply-command.ts +6 -6
  276. package/src/commands/apply/apply-engine.ts +1 -1
  277. package/src/commands/apply/apply-parse.ts +7 -8
  278. package/src/commands/bisect/bisect-command.ts +18 -5
  279. package/src/commands/branch-command.ts +528 -53
  280. package/src/commands/branch-info-command.ts +150 -0
  281. package/src/commands/branch-tracking.ts +335 -60
  282. package/src/commands/branch-upstream-command.ts +218 -0
  283. package/src/commands/checkout-command.ts +69 -43
  284. package/src/commands/cherry-pick-command.ts +143 -0
  285. package/src/commands/clean-command.ts +34 -3
  286. package/src/commands/clone-command.ts +2 -1
  287. package/src/commands/commit-command.ts +782 -64
  288. package/src/commands/commit-reuse.ts +94 -0
  289. package/src/commands/config-command.ts +1256 -0
  290. package/src/commands/config-value-types.ts +358 -0
  291. package/src/commands/core-config.ts +40 -0
  292. package/src/commands/diff-color-config.ts +274 -0
  293. package/src/commands/diff-command.ts +1009 -49
  294. package/src/commands/fetch-command.ts +142 -8
  295. package/src/commands/fmt-merge-msg-command.ts +715 -0
  296. package/src/commands/fork-point.ts +63 -0
  297. package/src/commands/format-patch-command.ts +314 -46
  298. package/src/commands/fsck/fetch-fsck.ts +172 -18
  299. package/src/commands/gc-command.ts +31 -1
  300. package/src/commands/git-describe.ts +31 -11
  301. package/src/commands/git-hooks.ts +81 -0
  302. package/src/commands/grep/grep-command.ts +1077 -0
  303. package/src/commands/grep/grep-engine.ts +1024 -0
  304. package/src/commands/grep/index.ts +2 -0
  305. package/src/commands/index-adder.ts +46 -7
  306. package/src/commands/index.ts +26 -0
  307. package/src/commands/interpret-trailers-command.ts +256 -0
  308. package/src/commands/local-transport.ts +109 -10
  309. package/src/commands/log-command.ts +1246 -210
  310. package/src/commands/log-graph.ts +123 -26
  311. package/src/commands/log-output.ts +280 -21
  312. package/src/commands/ls-remote-command.ts +5 -0
  313. package/src/commands/mailmap.ts +119 -0
  314. package/src/commands/merge-base-command.ts +170 -0
  315. package/src/commands/merge-bases.ts +63 -8
  316. package/src/commands/merge-command.ts +330 -82
  317. package/src/commands/merge-support.ts +14 -1
  318. package/src/commands/mv-command.ts +6 -3
  319. package/src/commands/name-rev.ts +171 -0
  320. package/src/commands/notes-command.ts +11 -1
  321. package/src/commands/pathspec-file.ts +72 -0
  322. package/src/commands/pathspec.ts +14 -2
  323. package/src/commands/pretty-format.ts +103 -19
  324. package/src/commands/promisor-remote.ts +10 -1
  325. package/src/commands/pull-command.ts +26 -7
  326. package/src/commands/push-command.ts +682 -65
  327. package/src/commands/read-tree-command.ts +28 -1
  328. package/src/commands/rebase-command.ts +933 -129
  329. package/src/commands/ref-filter/for-each-ref-command.ts +298 -0
  330. package/src/commands/ref-filter/index.ts +7 -0
  331. package/src/commands/ref-filter/ref-atoms.ts +581 -0
  332. package/src/commands/ref-filter/ref-filter.ts +651 -0
  333. package/src/commands/ref-filter/ref-format.ts +1070 -0
  334. package/src/commands/ref-filter/ref-listing-command.ts +421 -0
  335. package/src/commands/ref-filter/ref-quote.ts +69 -0
  336. package/src/commands/ref-filter/version-compare.ts +177 -0
  337. package/src/commands/reflog-command.ts +492 -2
  338. package/src/commands/reflog-walk.ts +234 -0
  339. package/src/commands/remote-command.ts +449 -69
  340. package/src/commands/remote-transport.ts +9 -1
  341. package/src/commands/reset-command.ts +36 -31
  342. package/src/commands/restore-command.ts +12 -41
  343. package/src/commands/rev-filter/commit-filter.ts +159 -0
  344. package/src/commands/rev-filter/commit-grep.ts +444 -0
  345. package/src/commands/rev-filter/index.ts +2 -0
  346. package/src/commands/rev-list-command.ts +402 -15
  347. package/src/commands/revert-command.ts +82 -0
  348. package/src/commands/revision-range.ts +204 -4
  349. package/src/commands/revision-resolver.ts +23 -8
  350. package/src/commands/rm-command.ts +282 -21
  351. package/src/commands/sequencer-pick.ts +498 -85
  352. package/src/commands/sequencer-support.ts +20 -2
  353. package/src/commands/serve-repository.ts +18 -3
  354. package/src/commands/show-command.ts +490 -0
  355. package/src/commands/show-commit.ts +24 -0
  356. package/src/commands/signature-check.ts +657 -0
  357. package/src/commands/signing.ts +385 -0
  358. package/src/commands/sparse-checkout-command.ts +2 -9
  359. package/src/commands/sparse-checkout-support.ts +2 -2
  360. package/src/commands/sparse-index-view.ts +135 -0
  361. package/src/commands/ssh-signer.ts +199 -0
  362. package/src/commands/ssh-verifier.ts +523 -0
  363. package/src/commands/stash-apply-command.ts +16 -4
  364. package/src/commands/stash-branch-command.ts +88 -0
  365. package/src/commands/stash-create-command.ts +28 -0
  366. package/src/commands/stash-info.ts +243 -0
  367. package/src/commands/stash-list-command.ts +33 -0
  368. package/src/commands/stash-pop-command.ts +83 -0
  369. package/src/commands/stash-show-command.ts +141 -0
  370. package/src/commands/stash-store-command.ts +82 -0
  371. package/src/commands/stash-working-tree.ts +2 -2
  372. package/src/commands/status-command.ts +5 -2
  373. package/src/commands/status-header.ts +41 -7
  374. package/src/commands/submodule-add-command.ts +509 -0
  375. package/src/commands/submodule-auth.ts +276 -0
  376. package/src/commands/submodule-commands.ts +1517 -0
  377. package/src/commands/submodule-model.ts +930 -0
  378. package/src/commands/submodule-update-command.ts +1092 -0
  379. package/src/commands/switch-command.ts +3 -1
  380. package/src/commands/tag-command.ts +876 -64
  381. package/src/commands/trailers.ts +837 -100
  382. package/src/commands/tree-restore.ts +38 -10
  383. package/src/commands/verify-command.ts +235 -0
  384. package/src/commands/worktree-add-command.ts +268 -24
  385. package/src/commands/worktree-path-rules.ts +183 -0
  386. package/src/commands/worktree-remove-command.ts +39 -5
  387. package/src/commands/worktree-repair-command.ts +52 -5
  388. package/src/commands/worktree-support.ts +22 -1
  389. package/src/errors/checkout-errors.ts +29 -0
  390. package/src/errors/command-errors.ts +2 -1
  391. package/src/errors/ref-errors.ts +23 -0
  392. package/src/errors/worktree-errors.ts +8 -1
  393. package/src/git-command.ts +66 -1
  394. package/src/git.ts +404 -1
  395. package/src/remote-config/index.ts +2 -0
  396. package/src/remote-config/remote-config-store.ts +101 -0
  397. package/src/results/combined-diff.ts +38 -18
  398. package/src/results/diff-check.ts +185 -0
  399. package/src/results/diff-color.ts +868 -0
  400. package/src/results/diff-output.ts +195 -30
  401. package/src/results/diff-pickaxe.ts +304 -0
  402. package/src/results/diff-words.ts +395 -0
  403. package/src/results/index.ts +4 -0
  404. package/src/results/push-result.ts +7 -0
  405. package/src/results/rebase-result.ts +3 -0
  406. package/src/results/stash-result.ts +7 -0
  407. package/src/whitespace/index.ts +1 -0
  408. package/src/{commands/apply/whitespace.ts → whitespace/whitespace-rule.ts} +173 -23
  409. package/dist/commands/apply/whitespace.d.ts +0 -58
  410. package/dist/commands/apply/whitespace.d.ts.map +0 -1
@@ -1,5 +1,6 @@
1
1
  import { isValidRefName, parseCoreAbbrev } from "@statewalker/vcs-core";
2
2
  import {
3
+ countRefspecMatch,
3
4
  createRepositoryFacade,
4
5
  createTransportRefStore,
5
6
  expandFromSource,
@@ -8,8 +9,11 @@ import {
8
9
  mapRejectReason,
9
10
  matchSource,
10
11
  ObjectFormatMismatchError,
12
+ objectSource,
13
+ PushCertificateError,
11
14
  type PushClientResult,
12
15
  type PushCommandResult,
16
+ PushRefspecError,
13
17
  type PushRefUpdate,
14
18
  PushRefusedByHookError,
15
19
  parseRefSpec,
@@ -21,7 +25,9 @@ import { isNullObjectId } from "@statewalker/vcs-utils/hash";
21
25
 
22
26
  import {
23
27
  HookFailedError,
28
+ IncompatibleOptionsError,
24
29
  InvalidArgumentError,
30
+ InvalidConfigError,
25
31
  InvalidRemoteError,
26
32
  NonFastForwardError,
27
33
  PushRejectedException,
@@ -30,8 +36,11 @@ import {
30
36
  import { RemoteConfigStore } from "../remote-config/index.js";
31
37
  import { type PushResult, PushStatus, type RemoteRefUpdate } from "../results/push-result.js";
32
38
  import { TransportCommand } from "../transport-command.js";
39
+ import { endOfSymbolicChain, installTracking, pushTrackingPlan } from "./branch-tracking.js";
40
+ import { hostEnvironmentOf } from "./git-ident.js";
33
41
  import { remoteHookSession } from "./local-transport.js";
34
42
  import { withRemoteReceivePack } from "./remote-transport.js";
43
+ import { SIGNING_FAILED_LINES, SigningFailedError } from "./signing.js";
35
44
 
36
45
  /**
37
46
  * How a server's rejection reason (`ng <ref> <reason>`) lands on the statuses this package
@@ -68,6 +77,7 @@ function toPushStatus(update: PushRefUpdate): PushStatus {
68
77
  case "rejected-fetch-first":
69
78
  return PushStatus.REJECTED_NONFASTFORWARD;
70
79
  case "rejected-stale":
80
+ case "rejected-remote-updated":
71
81
  return PushStatus.REJECTED_REMOTE_CHANGED;
72
82
  case "remote-rejected":
73
83
  return REJECT_REASON_STATUS[mapRejectReason(update.message ?? "")];
@@ -118,10 +128,16 @@ function toPushStatus(update: PushRefUpdate): PushStatus {
118
128
  * ```
119
129
  */
120
130
  export class PushCommand extends TransportCommand<PushResult> {
131
+ /** The remote, once set or resolved in `call` (git's `pushremote_for_branch`) */
121
132
  private remote = "origin";
133
+ private remoteGiven = false;
134
+ /** Whether the remote was set or came from the configuration (git's `explicit`) */
135
+ private remoteExplicit = false;
122
136
  private refSpecs: string[] = [];
123
137
  private force = false;
124
138
  private atomic = false;
139
+ /** `--[no-]signed[=if-asked]` (undefined: `push.gpgSign`) */
140
+ private signed?: boolean | "if-asked";
125
141
  private noVerify = false;
126
142
 
127
143
  /** `--no-verify`: the pre-push hook does not run. */
@@ -141,23 +157,125 @@ export class PushCommand extends TransportCommand<PushResult> {
141
157
  private streamRequestBody?: boolean;
142
158
  /** Leases (an entry without a ref: every other pushed ref at its tracking value) */
143
159
  private leases?: ForceWithLease[];
160
+ /** `-u` / `--set-upstream` */
161
+ private setUpstream = false;
162
+ /** `--[no-]follow-tags` (undefined: `push.followTags`) */
163
+ private followTags?: boolean;
164
+ /** `--[no-]force-if-includes` (undefined: `push.useForceIfIncludes`) */
165
+ private forceIfIncludes?: boolean;
166
+ /** `--mirror` (undefined: `remote.<name>.mirror`) */
167
+ private mirror?: boolean;
168
+ /** `-d` / `--delete` */
169
+ private deleteRefs = false;
170
+ /** Whose messages to give where git 2.43 and 2.5x differ (undefined: the hook runner's) */
171
+ private compatibility?: "2.43" | "2.56";
172
+
173
+ /**
174
+ * `--mirror` (true): every local ref (`refs/*`) is pushed to the same name, forced, and every
175
+ * remote ref without a local one is deleted, as git's `TRANSPORT_PUSH_MIRROR`. Undefined
176
+ * (the default) reads `remote.<name>.mirror` of a configured remote; false is no mirror,
177
+ * whatever that says. A mirror push takes no refspecs, nor `setPushAll`, `setPushTags` or
178
+ * `setDelete` (git's refusals).
179
+ */
180
+ setMirror(mirror: boolean | undefined): this {
181
+ this.checkCallable();
182
+ this.mirror = mirror;
183
+ return this;
184
+ }
185
+
186
+ /** `--mirror` as set (undefined: `remote.<name>.mirror` decides in `call`). */
187
+ isMirror(): boolean | undefined {
188
+ return this.mirror;
189
+ }
190
+
191
+ /**
192
+ * `-d` / `--delete`: each refspec is a remote ref to delete (`main` as `:main`, `tag v1` as
193
+ * `:refs/tags/v1`); a `src:dst` refspec or an empty one is refused, and so is a delete with
194
+ * no refspec, `setPushAll`, `setPushTags` or `setMirror`, as git refuses them.
195
+ */
196
+ setDelete(deleteRefs: boolean): this {
197
+ this.checkCallable();
198
+ this.deleteRefs = deleteRefs;
199
+ return this;
200
+ }
201
+
202
+ /** Whether `setDelete` is on. */
203
+ isDelete(): boolean {
204
+ return this.deleteRefs;
205
+ }
206
+
207
+ /**
208
+ * Whose messages to give where git 2.43 and 2.5x differ (the incompatible options of
209
+ * `--delete`, `--tags`, `--all` and `--mirror`, and when they are checked). Default: the hook
210
+ * runner's compatibility, else 2.56.
211
+ */
212
+ setCompatibility(version: "2.43" | "2.56"): this {
213
+ this.checkCallable();
214
+ this.compatibility = version;
215
+ return this;
216
+ }
217
+
218
+ /**
219
+ * `-u` / `--set-upstream`: each local branch pushed to a remote branch (accepted or already
220
+ * up to date, not deleted) gets that branch of this remote as its upstream
221
+ * (`branch.<name>.remote` = the remote's name, or the URL as given; `.merge` = the remote
222
+ * ref), written as `git branch --set-upstream-to` writes it; git's `branch '<b>' set up to
223
+ * track '<remote>/<branch>'.` lines are {@link PushResult.upstreamMessages}. A dry run
224
+ * writes nothing and tells `Would set upstream of '<b>' to '<branch>' of '<remote>'`.
225
+ */
226
+ setSetUpstream(setUpstream: boolean): this {
227
+ this.checkCallable();
228
+ this.setUpstream = setUpstream;
229
+ return this;
230
+ }
231
+
232
+ /**
233
+ * `--follow-tags` (true) / `--no-follow-tags` (false); undefined (the default) reads
234
+ * `push.followTags`. Also pushes every local annotated tag the remote lacks whose commit
235
+ * the pushed refs reach (or the remote's refs that are not pushed), as git's
236
+ * `add_missing_tags`; lightweight tags and tags of trees or blobs are never followed.
237
+ */
238
+ setFollowTags(followTags: boolean | undefined): this {
239
+ this.checkCallable();
240
+ this.followTags = followTags;
241
+ return this;
242
+ }
243
+
244
+ /**
245
+ * `--force-if-includes` (true) / `--no-force-if-includes` (false); undefined (the default)
246
+ * reads `push.useForceIfIncludes`. With a `--force-with-lease` that expects a
247
+ * remote-tracking value (no explicit value), a ref whose remote value is in no reflog entry
248
+ * of the local ref of the same name, nor reachable from one made since the tracking ref's
249
+ * last update, is refused ("remote ref updated since checkout",
250
+ * {@link PushStatus.REJECTED_REMOTE_CHANGED}). Without a lease it does nothing, as in git.
251
+ */
252
+ setForceIfIncludes(forceIfIncludes: boolean | undefined): this {
253
+ this.checkCallable();
254
+ this.forceIfIncludes = forceIfIncludes;
255
+ return this;
256
+ }
144
257
 
145
258
  /**
146
259
  * Set the remote to push to.
147
260
  *
148
- * Can be either a remote name (e.g., "origin") or a URL.
149
- * Default is "origin".
261
+ * Can be either a remote name (e.g., "origin") or a URL. When none is set, `call` picks
262
+ * the remote as `git push` does (`pushremote_for_branch`): `branch.<current>.pushRemote`,
263
+ * `remote.pushDefault`, `branch.<current>.remote`, the one configured remote, else `origin`
264
+ * (a detached HEAD skips the branch's settings).
150
265
  *
151
266
  * @param remote Remote name or URL
152
267
  */
153
268
  setRemote(remote: string): this {
154
269
  this.checkCallable();
155
270
  this.remote = remote;
271
+ this.remoteGiven = true;
272
+ this.remoteExplicit = true;
156
273
  return this;
157
274
  }
158
275
 
159
276
  /**
160
- * Get the remote being pushed to.
277
+ * Get the remote being pushed to: the one set, or after `call` the one it chose (`origin`
278
+ * before then).
161
279
  */
162
280
  getRemote(): string {
163
281
  return this.remote;
@@ -264,6 +382,37 @@ export class PushCommand extends TransportCommand<PushResult> {
264
382
  return this;
265
383
  }
266
384
 
385
+ /**
386
+ * `--signed` (true), `--no-signed` (false) or `--signed=if-asked`: whether to sign a push
387
+ * certificate; undefined (the default) leaves it to `push.gpgSign` (a boolean or
388
+ * `if-asked`). A server that takes no certificate refuses a signed push (`fatal: the
389
+ * receiving end does not support --signed push`) and gets an `if-asked` one unsigned,
390
+ * with git's warning ({@link PushResult.warnings}). Not signed yet: a certificate
391
+ * the server takes fails as git fails when gpg cannot sign (`error: gpg failed to sign
392
+ * the data:`, `fatal: failed to sign the push certificate`, exit 128:
393
+ * {@link SigningFailedError}), before anything is sent.
394
+ */
395
+ setSigned(signed: boolean | "if-asked" | undefined): this {
396
+ this.checkCallable();
397
+ this.signed = signed;
398
+ return this;
399
+ }
400
+
401
+ /**
402
+ * The push certificate asked for (git's SEND_PACK_PUSH_CERT_*): the option, else
403
+ * `push.gpgSign` (a boolean or `if-asked`, case-insensitive; another value signs nothing).
404
+ */
405
+ private pushCertMode(): "always" | "if-asked" | undefined {
406
+ let value: boolean | "if-asked" | undefined = this.signed;
407
+ if (value === undefined) {
408
+ const raw = RemoteConfigStore.from(this.workingCopy).value("push.gpgSign");
409
+ if (raw !== undefined) {
410
+ value = raw.trim().toLowerCase() === "if-asked" ? "if-asked" : parseGitBool(raw);
411
+ }
412
+ }
413
+ return value === true ? "always" : value === "if-asked" ? "if-asked" : undefined;
414
+ }
415
+
267
416
  /**
268
417
  * Whether atomic push is enabled.
269
418
  */
@@ -373,7 +522,10 @@ export class PushCommand extends TransportCommand<PushResult> {
373
522
  * Set push options associated with the push operation.
374
523
  *
375
524
  * Push options are strings passed to the receive-pack on the server
376
- * side, where they can be used by hooks.
525
+ * side, where they can be used by hooks (`GIT_PUSH_OPTION_COUNT`, `GIT_PUSH_OPTION_<n>`).
526
+ * As git's `-o`: when none are given, `push.pushOption` gives them (each value added in
527
+ * order, an empty value clearing the list). A server that does not advertise them
528
+ * (`receive.advertisePushOptions`) refuses the push before anything is sent.
377
529
  *
378
530
  * @param options Push option strings
379
531
  */
@@ -428,20 +580,83 @@ export class PushCommand extends TransportCommand<PushResult> {
428
580
  async call(): Promise<PushResult> {
429
581
  this.checkCallable();
430
582
  this.setCallable(false);
583
+ const compatibility = this.compatibility ?? this.hooks.compatibility;
584
+
585
+ // git_push_config: push.pushOption is read (and a bad one dies) before anything else;
586
+ // the command line's options replace the configured ones
587
+ const configuredOptions = this.configuredPushOptions();
588
+ const transmitted = this.pushOptions.length > 0 ? this.pushOptions : configuredOptions;
589
+ this.checkOptionCombinations(compatibility);
590
+ if (this.deleteRefs && this.refSpecs.length === 0) {
591
+ throw new InvalidArgumentError(
592
+ "refspecs",
593
+ undefined,
594
+ "--delete doesn't make sense without any refs",
595
+ );
596
+ }
597
+ // 2.43 checks the refspecs given before it looks the remote up
598
+ if (compatibility === "2.43") this.checkRefspecArguments();
431
599
 
600
+ // pushremote_get(NULL): the push remote the configuration names for the current branch
601
+ if (!this.remoteGiven) {
602
+ const ref = await this.getCurrentBranch();
603
+ const branch = ref?.startsWith("refs/heads/") ? ref.slice("refs/heads/".length) : undefined;
604
+ const choice = RemoteConfigStore.from(this.workingCopy).pushRemoteChoiceForBranch(branch);
605
+ this.remote = choice.name;
606
+ this.remoteExplicit = choice.explicit;
607
+ }
432
608
  // pushremote_get: a remote the configuration gives no URL may come from .git/remotes/ or
433
609
  // .git/branches/ (git 2.x)
434
610
  const legacyWarnings = await this.loadLegacyRemote(this.remote);
435
611
  const warnings = legacyWarnings.length > 0 ? { warnings: legacyWarnings } : {};
612
+ // git's push.c: a fallback remote (the one configured, origin) must be configured
613
+ // (remote_get(NULL) gives no remote otherwise); a name given or taken from the
614
+ // configuration is also tried as a URL or path (remotes_remote_get_1's add_url_alias)
615
+ if (
616
+ !this.remoteExplicit &&
617
+ !RemoteConfigStore.from(this.workingCopy).isConfigured(this.remote)
618
+ ) {
619
+ throw new InvalidRemoteError(
620
+ this.remote,
621
+ "No configured push destination.\nEither specify the URL from the command-line or " +
622
+ "configure a remote repository using\n\n git remote add <name> <url>\n\n" +
623
+ "and then push using the remote name\n\n git push <name>" +
624
+ // 2.5x's remote groups
625
+ (compatibility === "2.43"
626
+ ? ""
627
+ : "\n\nTo push to multiple remotes at once, configure a remote group using\n\n" +
628
+ ' git config remotes.<groupname> "<remote1> <remote2>"\n\n' +
629
+ "and then push using the group name\n\n git push <groupname>"),
630
+ );
631
+ }
436
632
  const remoteUrl = await this.resolveRemoteUrl(this.remote);
437
633
  if (!remoteUrl) {
438
634
  throw new InvalidRemoteError(this.remote);
439
635
  }
636
+ // a mirror remote (remote.<name>.mirror) pushes as --mirror; --mirror implies --force
637
+ const mirror = this.mirror ?? this.remoteMirror();
638
+ const checks = this.remoteChecks(compatibility, mirror);
639
+ if (compatibility === "2.43") checks();
640
+ for (const option of transmitted) {
641
+ if (option.includes("\n")) {
642
+ throw new InvalidArgumentError(
643
+ "pushOptions",
644
+ option,
645
+ "push options must not have new line characters",
646
+ );
647
+ }
648
+ }
649
+ if (compatibility !== "2.43") {
650
+ checks();
651
+ this.checkRefspecArguments();
652
+ }
440
653
 
441
654
  // transport_get: the remote's transport is decided (git's errors for one that cannot be
442
655
  // reached) before the refspecs are worked out
443
656
  const resolved = this.resolveRemote(remoteUrl);
444
- const refspecs = await this.buildRefSpecs();
657
+ const defaults = { setUpstream: false };
658
+ const refspecs = await this.buildRefSpecs(mirror, defaults, compatibility);
659
+ const setUpstream = this.setUpstream || defaults.setUpstream;
445
660
  if (refspecs.length === 0) {
446
661
  return {
447
662
  uri: remoteUrl,
@@ -456,34 +671,49 @@ export class PushCommand extends TransportCommand<PushResult> {
456
671
  const remote = await this.openRemote(resolved);
457
672
  const localRemote = remote.kind === "local" ? remote.repository : undefined;
458
673
  const history = this._workingCopy.history;
459
- const tracking = this.trackingRefMapper();
674
+ const tracking = this.trackingRefMapper(remoteUrl, compatibility);
460
675
  const messages: string[] = [];
461
676
  const leases = this.leases;
677
+ const repository = createRepositoryFacade({
678
+ history,
679
+ useBitmaps: this.bitmapsInUse(),
680
+ // send-pack's pack-objects reads core.maxTreeDepth
681
+ maxTreeDepth: this.maxTreeDepth(),
682
+ });
683
+ // builtin/push.c: --force-if-includes counts only with a lease
684
+ const forceIfIncludes =
685
+ leases !== undefined &&
686
+ leases.length > 0 &&
687
+ (this.forceIfIncludes ?? this.configBool("push.useForceIfIncludes") ?? false);
462
688
  const pushOptions: TransportPushOptions = {
463
689
  url: remoteUrl,
464
690
  auth: this.credentials,
465
691
  headers: this.headers,
466
692
  timeout: this.timeout,
467
- repository: createRepositoryFacade({
468
- history,
469
- useBitmaps: this.bitmapsInUse(),
470
- // send-pack's pack-objects reads core.maxTreeDepth
471
- maxTreeDepth: this.maxTreeDepth(),
472
- }),
693
+ repository,
473
694
  refStore: createTransportRefStore(history.refs),
474
695
  refspecs,
475
- force: this.force,
696
+ force: this.force || mirror,
476
697
  atomic: this.atomic,
698
+ ...(this.pushCertMode() ? { signed: this.pushCertMode() } : {}),
477
699
  thin: this.thin,
478
700
  dryRun: this.dryRun,
479
701
  prune: this.prune,
702
+ mirror,
480
703
  streamRequestBody: this.streamRequestBody,
481
- pushOptions: this.pushOptions.length > 0 ? this.pushOptions : undefined,
704
+ pushOptions: transmitted.length > 0 ? transmitted : undefined,
482
705
  forceWithLease: leases,
483
706
  trackingValue: async (remoteRef) => {
484
707
  const local = tracking(remoteRef);
485
708
  return local ? (await history.refs.resolve(local))?.objectId : undefined;
486
709
  },
710
+ ...(forceIfIncludes
711
+ ? {
712
+ includesRemote: (remoteRef: string, remoteOid: string) =>
713
+ this.isReachableInReflog(remoteRef, tracking(remoteRef), remoteOid, repository),
714
+ }
715
+ : {}),
716
+ followTags: this.followTags ?? this.configBool("push.followTags") ?? false,
487
717
  onProgress: (message) => {
488
718
  messages.push(message);
489
719
  this.progressMessageCallback?.(message);
@@ -505,6 +735,8 @@ export class PushCommand extends TransportCommand<PushResult> {
505
735
  localRemote === undefined
506
736
  ? undefined
507
737
  : remoteHookSession(this.workingCopy, localRemote, { localPush: true });
738
+ const environment = hostEnvironmentOf(this.workingCopy);
739
+ const receiveWarnings: string[] = [];
508
740
  // --receive-pack, else remote.<name>.receivepack
509
741
  const receivePack = this.receivePack ?? this.remoteProgram(this.remote, "receivepack");
510
742
  try {
@@ -521,12 +753,51 @@ export class PushCommand extends TransportCommand<PushResult> {
521
753
  ? undefined
522
754
  : remoteHookSession(this.workingCopy, localRemote, { localPush: true }),
523
755
  transactionHooks,
756
+ {
757
+ host: {
758
+ ...(environment ? { environment } : {}),
759
+ compatibility: this.hooks.compatibility,
760
+ },
761
+ // receive-pack's config warnings reach the shared stderr
762
+ onWarning: (line) => receiveWarnings.push(line),
763
+ },
524
764
  );
525
765
  } catch (error) {
766
+ // match_push_refs' refusals: errors (git exits 1 with "failed to push some refs"), or
767
+ // deaths for a refspec or a lease it cannot parse
768
+ if (error instanceof PushRefspecError) {
769
+ if (/^(invalid refspec|cannot parse expected object name) /.test(error.message)) {
770
+ throw new TransportError(`fatal: ${error.message}`, undefined, { cause: error });
771
+ }
772
+ throw new TransportError(
773
+ `error: ${error.message}\nerror: failed to push some refs to '${remoteUrl}'`,
774
+ undefined,
775
+ { cause: error, exitCode: 1 },
776
+ );
777
+ }
778
+ // send_pack dies: --atomic or push options the server does not advertise
779
+ if (
780
+ error instanceof Error &&
781
+ !(error instanceof TransportError) &&
782
+ /^the receiving end does not support (--atomic push|push options)$/.test(error.message)
783
+ ) {
784
+ throw new TransportError(`fatal: ${error.message}`, undefined, { cause: error });
785
+ }
526
786
  // send_pack dies: the remote's repository names objects with another hash
527
787
  if (error instanceof ObjectFormatMismatchError) {
528
788
  throw new TransportError(`fatal: ${error.message}`, undefined, { cause: error });
529
789
  }
790
+ // send_pack dies: no push certificate for this server, or none could be signed
791
+ if (error instanceof PushCertificateError) {
792
+ if (error.reason === "unsupported") {
793
+ throw new TransportError(`fatal: ${error.message}`, undefined, { cause: error });
794
+ }
795
+ throw new SigningFailedError(
796
+ [...SIGNING_FAILED_LINES, `fatal: ${error.message}`].join("\n"),
797
+ "",
798
+ 128,
799
+ );
800
+ }
530
801
  if (error instanceof PushRefusedByHookError) {
531
802
  throw new HookFailedError(
532
803
  "pre-push",
@@ -540,6 +811,9 @@ export class PushCommand extends TransportCommand<PushResult> {
540
811
  if (transactionHooks) this.hooks.append(transactionHooks.output);
541
812
  }
542
813
 
814
+ // transport_push: set_upstreams, before the remote-tracking refs are updated
815
+ const upstreamMessages = setUpstream ? await this.setUpstreams(result.updates) : [];
816
+
543
817
  // git updates the remote-tracking refs of what the server accepted, and of what it had
544
818
  // already (transport.c: update_tracking_ref for ok and up-to-date refs)
545
819
  // receive_status's lines (read with the report), then the tracking refs' errors
@@ -640,11 +914,18 @@ export class PushCommand extends TransportCommand<PushResult> {
640
914
  bytesSent: result.bytesSent,
641
915
  objectCount: result.packObjects,
642
916
  messages,
643
- ...warnings,
917
+ // git's order: the legacy-remote deprecation, receive-pack's startup warnings (a local
918
+ // push), then send-pack's (an unsent push certificate)
919
+ ...(legacyWarnings.length + receiveWarnings.length + (result.warnings?.length ?? 0) > 0
920
+ ? { warnings: [...legacyWarnings, ...receiveWarnings, ...(result.warnings ?? [])] }
921
+ : {}),
644
922
  display: formatPushStatus(result, { dest: remoteUrl }),
645
923
  porcelain: formatPushStatus(result, { dest: remoteUrl, porcelain: true }),
646
924
  ...(trackingErrors.length ? { errors: trackingErrors } : {}),
647
- ...(result.reportFailed ? { failed: true } : {}),
925
+ ...(upstreamMessages.length ? { upstreamMessages } : {}),
926
+ // send_pack left at once (nothing to push to a remote without refs): the receiving end
927
+ // hung up, and git fails
928
+ ...(result.reportFailed || result.noRefsInCommon ? { failed: true } : {}),
648
929
  };
649
930
  }
650
931
 
@@ -659,7 +940,12 @@ export class PushCommand extends TransportCommand<PushResult> {
659
940
  remoteUrl: string,
660
941
  exit: (code: number) => void,
661
942
  ): Promise<boolean> {
662
- const skipped = new Set(["rejected-nonfastforward", "rejected-stale", "up-to-date"]);
943
+ const skipped = new Set([
944
+ "rejected-nonfastforward",
945
+ "rejected-remote-updated",
946
+ "rejected-stale",
947
+ "up-to-date",
948
+ ]);
663
949
  const zero = this.objectFormat.nullId;
664
950
  const stdin = updates
665
951
  .filter((u) => !skipped.has(u.status))
@@ -678,6 +964,75 @@ export class PushCommand extends TransportCommand<PushResult> {
678
964
  return false;
679
965
  }
680
966
 
967
+ /**
968
+ * transport.c's `set_upstreams`: each update accepted or up to date, not a delete, whose
969
+ * local side is a branch (a symbolic ref such as HEAD followed to its branch) and whose
970
+ * remote side is a branch, sets that branch's upstream through `installTracking`; a dry run
971
+ * only says what it would set. git's stdout lines.
972
+ */
973
+ private async setUpstreams(updates: readonly PushRefUpdate[]): Promise<string[]> {
974
+ const lines: string[] = [];
975
+ for (const update of updates) {
976
+ if (update.status !== "ok" && update.status !== "up-to-date") continue;
977
+ if (isNullObjectId(update.newOid)) continue;
978
+ // the peer ref: the local ref matched, else HEAD for a `HEAD` source
979
+ let local = update.localRef ?? (update.source === "HEAD" ? "HEAD" : undefined);
980
+ if (!local) continue;
981
+ const end = await endOfSymbolicChain(this.refsStore, local);
982
+ if (end?.startsWith("refs/heads/")) local = end;
983
+ if (!local.startsWith("refs/heads/") || !update.remoteRef.startsWith("refs/heads/")) {
984
+ continue;
985
+ }
986
+ const branch = local.slice("refs/heads/".length);
987
+ if (this.dryRun) {
988
+ lines.push(
989
+ `Would set upstream of '${branch}' to '${update.remoteRef.slice("refs/heads/".length)}' of '${this.remote}'`,
990
+ );
991
+ continue;
992
+ }
993
+ const plan = pushTrackingPlan(this.workingCopy, this.remote, update.remoteRef);
994
+ lines.push(...(await installTracking(this.workingCopy, branch, plan)));
995
+ }
996
+ return lines;
997
+ }
998
+
999
+ /**
1000
+ * remote.c's `is_reachable_in_reflog` for `--force-if-includes`: whether the remote's value
1001
+ * (peeled to a commit) is the new value of an entry of the local ref's reflog (the local ref
1002
+ * of the remote ref's name), or an ancestor of one of the entries read until one older than
1003
+ * the remote-tracking ref's latest reflog entry.
1004
+ */
1005
+ private async isReachableInReflog(
1006
+ localRef: string,
1007
+ trackingRef: string | undefined,
1008
+ remoteOid: string,
1009
+ repository: ReturnType<typeof createRepositoryFacade>,
1010
+ ): Promise<boolean> {
1011
+ const objects = objectSource(repository);
1012
+ const commit = await objects.peelToCommit(remoteOid);
1013
+ if (!commit) return false;
1014
+ const refs = this.refsStore;
1015
+ // git leaves the date unset without a tracking reflog: nothing stops the walk early
1016
+ const latest = trackingRef
1017
+ ? (await (await refs.getReflog?.(trackingRef))?.getLastEntry())?.who.timestamp
1018
+ : undefined;
1019
+ const since = latest ?? Number.NEGATIVE_INFINITY;
1020
+ const entries = (await (await refs.getReflog?.(localRef))?.getReverseEntries()) ?? [];
1021
+ const collected: string[] = [];
1022
+ for (const entry of entries) {
1023
+ if (entry.newId === commit) return true;
1024
+ const entryCommit = isNullObjectId(entry.newId)
1025
+ ? undefined
1026
+ : await objects.peelToCommit(entry.newId);
1027
+ if (entryCommit) collected.push(entryCommit);
1028
+ if (entry.who.timestamp < since) break;
1029
+ }
1030
+ for (const c of collected) {
1031
+ if (await objects.isAncestor(commit, c)) return true;
1032
+ }
1033
+ return false;
1034
+ }
1035
+
681
1036
  /**
682
1037
  * Push and throw on failure.
683
1038
  */
@@ -719,9 +1074,190 @@ export class PushCommand extends TransportCommand<PushResult> {
719
1074
  }
720
1075
 
721
1076
  /**
722
- * The refspecs to push: the explicit ones, `--all` (every branch), `--tags` (every tag);
723
- * else the remote's configured push refspecs; else what `push.default` says (git's
724
- * builtin/push.c `setup_default_push_refspecs`, default `simple`):
1077
+ * `push.pushOption` in config order (git's `parse_transport_option`): each value added, an
1078
+ * empty one clearing the list; a value-less one dies as git's config reader dies.
1079
+ */
1080
+ private configuredPushOptions(): string[] {
1081
+ const key = "push.pushoption";
1082
+ const out: string[] = [];
1083
+ for (const { text, file, line } of RemoteConfigStore.from(this._workingCopy).valuesWithOrigin(
1084
+ "push.pushOption",
1085
+ )) {
1086
+ if (text === undefined) {
1087
+ const fatal =
1088
+ file !== undefined && line !== undefined
1089
+ ? `fatal: bad config variable '${key}' in file '${file}' at line ${line}`
1090
+ : `fatal: unable to parse '${key}' from command-line config`;
1091
+ throw new InvalidConfigError(key, `error: missing value for '${key}'\n${fatal}`);
1092
+ }
1093
+ if (text === "") out.length = 0;
1094
+ else out.push(text);
1095
+ }
1096
+ return out;
1097
+ }
1098
+
1099
+ /**
1100
+ * The options that cannot go together: 2.5x's `die_for_incompatible_opt4` (`--delete`,
1101
+ * `--tags`, `--all/--branches`, `--mirror`, all named), 2.43's `--delete` with any of the
1102
+ * others (the rest it checks once the remote is known, `remoteChecks`).
1103
+ */
1104
+ private checkOptionCombinations(compatibility: "2.43" | "2.56"): void {
1105
+ if (compatibility === "2.43") {
1106
+ if (this.deleteRefs && (this.pushTags || this.pushAll || this.mirror)) {
1107
+ throw new IncompatibleOptionsError(
1108
+ ["--delete", "--all/--branches/--mirror/--tags"],
1109
+ "options '--delete' and '--all/--branches/--mirror/--tags' cannot be used together",
1110
+ );
1111
+ }
1112
+ return;
1113
+ }
1114
+ const given = [
1115
+ this.deleteRefs && "--delete",
1116
+ this.pushTags && "--tags",
1117
+ this.pushAll && "--all/--branches",
1118
+ this.mirror && "--mirror",
1119
+ ].filter((o): o is string => typeof o === "string");
1120
+ if (given.length < 2) return;
1121
+ const quoted = given.map((o) => `'${o}'`);
1122
+ const list =
1123
+ quoted.length === 2
1124
+ ? `${quoted[0]} and ${quoted[1]}`
1125
+ : `${quoted.slice(0, -1).join(", ")}, and ${quoted.at(-1)}`;
1126
+ throw new IncompatibleOptionsError(given, `options ${list} cannot be used together`);
1127
+ }
1128
+
1129
+ /** `remote.<name>.mirror` of a configured remote (git_config_bool). */
1130
+ private remoteMirror(): boolean {
1131
+ const store = RemoteConfigStore.from(this._workingCopy);
1132
+ if (!store.isConfigured(this.remote)) return false;
1133
+ const value = store.value(`remote.${this.remote}.mirror`);
1134
+ return value === undefined ? false : (parseGitBool(value) ?? false);
1135
+ }
1136
+
1137
+ /**
1138
+ * The checks git makes once the remote is known (a mirror remote counts as `--mirror`):
1139
+ * `--all` or `--mirror` with refspecs, and in 2.43 their combinations with `--tags` and
1140
+ * each other.
1141
+ */
1142
+ private remoteChecks(compatibility: "2.43" | "2.56", mirror: boolean): () => void {
1143
+ const refused = (options: string[], message: string) => {
1144
+ throw new IncompatibleOptionsError(options, message);
1145
+ };
1146
+ const together = (a: string, b: string) =>
1147
+ refused([a, b], `options '${a}' and '${b}' cannot be used together`);
1148
+ return () => {
1149
+ const legacy = compatibility === "2.43";
1150
+ if (this.pushAll) {
1151
+ if (legacy && this.pushTags) together("--all", "--tags");
1152
+ if (this.refSpecs.length > 0) {
1153
+ refused(["--all"], "--all can't be combined with refspecs");
1154
+ }
1155
+ }
1156
+ if (mirror) {
1157
+ if (legacy && this.pushTags) together("--mirror", "--tags");
1158
+ if (this.refSpecs.length > 0) {
1159
+ refused(["--mirror"], "--mirror can't be combined with refspecs");
1160
+ }
1161
+ }
1162
+ if (legacy && this.pushAll && mirror) together("--all", "--mirror");
1163
+ };
1164
+ }
1165
+
1166
+ /** set_refspecs' refusals of the refspecs given: `tag` without a name, `--delete` of `a:b`. */
1167
+ private checkRefspecArguments(): void {
1168
+ const refs = this.refSpecs;
1169
+ for (let i = 0; i < refs.length; i++) {
1170
+ const ref = refs[i] as string;
1171
+ if (ref === "tag") {
1172
+ if (++i >= refs.length) {
1173
+ throw new InvalidArgumentError("refspecs", ref, "tag shorthand without <tag>");
1174
+ }
1175
+ } else if (this.deleteRefs && (ref === "" || ref.includes(":"))) {
1176
+ throw new InvalidArgumentError(
1177
+ "refspecs",
1178
+ ref,
1179
+ "--delete only accepts plain target ref names",
1180
+ );
1181
+ }
1182
+ }
1183
+ }
1184
+
1185
+ /**
1186
+ * git's `set_refspecs`: the refspecs given, `tag <name>` as `refs/tags/<name>`, each a
1187
+ * deletion under `--delete`; a name without `:` that names exactly one local ref goes where
1188
+ * `remote.<name>.push` maps that ref, else (`push.default=upstream`) a branch to its single
1189
+ * upstream (`refspec_append_mapped`).
1190
+ */
1191
+ private async givenRefspecs(): Promise<string[]> {
1192
+ const out: string[] = [];
1193
+ const refs = this.refSpecs;
1194
+ let local: string[] | undefined;
1195
+ for (let i = 0; i < refs.length; i++) {
1196
+ let ref = refs[i] as string;
1197
+ if (ref === "tag") {
1198
+ ref = refs[++i] as string;
1199
+ out.push(this.deleteRefs ? `:refs/tags/${ref}` : `refs/tags/${ref}`);
1200
+ } else if (this.deleteRefs) {
1201
+ out.push(`:${ref}`);
1202
+ } else if (!ref.includes(":")) {
1203
+ local ??= [...(await createTransportRefStore(this._workingCopy.history.refs).listAll())]
1204
+ .map(([name]) => name)
1205
+ .filter((name) => name.startsWith("refs/"));
1206
+ const { count, match } = countRefspecMatch(ref, local);
1207
+ out.push(count === 1 && match ? this.mappedRefspec(ref, match) : ref);
1208
+ } else {
1209
+ out.push(ref);
1210
+ }
1211
+ }
1212
+ return out;
1213
+ }
1214
+
1215
+ /** git's `refspec_append_mapped`: where `ref` (naming the local ref `matched`) is pushed. */
1216
+ private mappedRefspec(ref: string, matched: string): string {
1217
+ const store = RemoteConfigStore.from(this._workingCopy);
1218
+ if (store.isConfigured(this.remote)) {
1219
+ for (const text of store.pushRefspecs(this.remote)) {
1220
+ const spec = parseRefSpec(text);
1221
+ if (spec.negative || !spec.source || !matchSource(spec, matched)) continue;
1222
+ const dst = spec.wildcard
1223
+ ? expandFromSource(spec, matched).destination
1224
+ : (spec.destination ?? spec.source);
1225
+ if (dst) return `${spec.force ? "+" : ""}${matched}:${dst}`;
1226
+ }
1227
+ }
1228
+ if (this.pushDefault() === "upstream" && matched.startsWith("refs/heads/")) {
1229
+ const merges = this.upstreamsOf(matched.slice("refs/heads/".length));
1230
+ if (merges.length === 1) return `${ref}:${merges[0]}`;
1231
+ }
1232
+ return ref;
1233
+ }
1234
+
1235
+ /**
1236
+ * `push.default` as git reads it: `tracking` is `upstream`; undefined when unset (git's
1237
+ * `PUSH_DEFAULT_UNSPECIFIED`, which acts as `simple`).
1238
+ */
1239
+ private pushDefault(): string | undefined {
1240
+ const value = RemoteConfigStore.from(this._workingCopy).value("push.default");
1241
+ return value === "tracking" ? "upstream" : value;
1242
+ }
1243
+
1244
+ /**
1245
+ * A branch's upstream merges (`branch.<name>.merge`), counted only while it has a remote
1246
+ * (`branch.<name>.remote`), as remote.c's `set_merge`.
1247
+ */
1248
+ private upstreamsOf(branch: string): string[] {
1249
+ const store = RemoteConfigStore.from(this._workingCopy);
1250
+ if (!store.value(`branch.${branch}.remote`)) return [];
1251
+ return store.values(`branch.${branch}.merge`);
1252
+ }
1253
+
1254
+ /**
1255
+ * The refspecs to push: `--mirror` (`remote.<name>.push`, else `:` over every ref; see
1256
+ * `PushClientOptions.mirror`),
1257
+ * `--tags`, the refspecs
1258
+ * given (`givenRefspecs`), `--all` (every branch); else the remote's configured push
1259
+ * refspecs; else what `push.default` says (git's builtin/push.c
1260
+ * `setup_default_push_refspecs`, default `simple`):
725
1261
  *
726
1262
  * - `simple`: the current branch to its upstream of the same name when pushing to the
727
1263
  * branch's own remote (refused without an upstream, or with one of another name); to the
@@ -731,20 +1267,34 @@ export class PushCommand extends TransportCommand<PushResult> {
731
1267
  * - `matching`: `:` (the branches both sides have)
732
1268
  * - `nothing`: refused
733
1269
  *
734
- * A detached HEAD is refused, except with `matching`.
1270
+ * A detached HEAD is refused, except with `matching`. Under `push.autoSetupRemote` a branch
1271
+ * without an upstream is pushed to its own name and gets it as its upstream
1272
+ * (`defaults.setUpstream`).
735
1273
  */
736
- private async buildRefSpecs(): Promise<string[]> {
737
- const specs = [...this.refSpecs];
738
- if (this.pushAll) specs.push("refs/heads/*:refs/heads/*");
1274
+ private async buildRefSpecs(
1275
+ mirror: boolean,
1276
+ defaults: { setUpstream: boolean },
1277
+ compatibility: "2.43" | "2.56",
1278
+ ): Promise<string[]> {
1279
+ const store = RemoteConfigStore.from(this.workingCopy);
1280
+ // --mirror: do_push's refspecs (a mirror remote's --tags in 2.5x, else remote.<name>.push),
1281
+ // else ":" over every ref; send_mirror then deletes every remote ref they leave out
1282
+ if (mirror) {
1283
+ if (this.pushTags) return ["refs/tags/*:refs/tags/*"];
1284
+ const configured = store.isConfigured(this.remote) ? store.pushRefspecs(this.remote) : [];
1285
+ return configured.length > 0 ? configured : [":"];
1286
+ }
1287
+ if (this.pushAll) return ["refs/heads/*:refs/heads/*"];
1288
+ const specs: string[] = [];
739
1289
  if (this.pushTags) specs.push("refs/tags/*:refs/tags/*");
1290
+ specs.push(...(await this.givenRefspecs()));
740
1291
  if (specs.length > 0) return specs;
741
1292
 
742
- const store = RemoteConfigStore.from(this.workingCopy);
743
1293
  if (store.isConfigured(this.remote)) {
744
1294
  const configured = store.pushRefspecs(this.remote);
745
1295
  if (configured.length > 0) return configured;
746
1296
  }
747
- const mode = (store.value("push.default") ?? "simple").toLowerCase();
1297
+ const mode = this.pushDefault();
748
1298
  if (mode === "matching") return [":"];
749
1299
  if (mode === "nothing") {
750
1300
  throw new InvalidArgumentError(
@@ -760,61 +1310,128 @@ export class PushCommand extends TransportCommand<PushResult> {
760
1310
  throw new InvalidArgumentError(
761
1311
  "refspecs",
762
1312
  undefined,
763
- "You are not currently on a branch. To push the history leading to the current " +
764
- "(detached HEAD) state now, use git push <remote> HEAD:<name-of-remote-branch>",
1313
+ "You are not currently on a branch.\n" +
1314
+ "To push the history leading to the current (detached HEAD)\n" +
1315
+ "state now, use\n\n" +
1316
+ ` git push ${this.remote} HEAD:<name-of-remote-branch>\n`,
765
1317
  );
766
1318
  }
767
1319
  const branch = ref.slice("refs/heads/".length);
768
- if (mode === "current") return [`${ref}:${ref}`];
769
-
770
- // the branch's remote (git: branch.<name>.remote, else "origin") and upstream
771
- const branchRemote = store.value(`branch.${branch}.remote`) ?? "origin";
772
- const merge = store.value(`branch.${branch}.merge`);
773
- const triangular = this.remote !== branchRemote;
774
- const noUpstream = () =>
775
- new InvalidArgumentError(
776
- "refspecs",
777
- undefined,
778
- `The current branch ${branch} has no upstream branch. To push the current branch and ` +
779
- `set the remote as upstream, use git push --set-upstream ${this.remote} ${branch}`,
780
- );
781
- if (mode === "upstream" || mode === "tracking") {
782
- if (triangular) {
1320
+ const autoUpstream = this.configBool("push.autoSetupRemote") ?? false;
1321
+ const merges = this.upstreamsOf(branch);
1322
+ // get_upstream_ref
1323
+ const upstreamRef = (): string => {
1324
+ if (merges.length === 0 && autoUpstream) return ref;
1325
+ if (merges.length === 0) {
783
1326
  throw new InvalidArgumentError(
784
1327
  "refspecs",
785
1328
  undefined,
786
- `You are pushing to remote '${this.remote}', which is not the upstream of your ` +
787
- `current branch '${branch}', without telling me what to push to update which ` +
788
- "remote branch.",
1329
+ `The current branch ${branch} has no upstream branch.\n` +
1330
+ "To push the current branch and set the remote as upstream, use\n\n" +
1331
+ ` git push --set-upstream ${this.remote} ${branch}\n` +
1332
+ (autoUpstream
1333
+ ? ""
1334
+ : "\nTo have this happen automatically for branches without a tracking\n" +
1335
+ "upstream, see 'push.autoSetupRemote' in 'git help config'.\n"),
789
1336
  );
790
1337
  }
791
- if (!merge) throw noUpstream();
792
- return [`${ref}:${merge}`];
793
- }
794
- // simple (and anything unknown, as git's default)
795
- if (triangular) return [`${ref}:${ref}`];
796
- if (!merge) throw noUpstream();
797
- if (merge !== ref) {
798
- throw new InvalidArgumentError(
799
- "refspecs",
800
- undefined,
801
- "The upstream branch of your current branch does not match\n" +
802
- `the name of your current branch. To push to the upstream branch on the remote, use\n` +
803
- ` git push ${this.remote} HEAD:${merge.replace(/^refs\/heads\//, "")}`,
804
- );
1338
+ if (merges.length !== 1) {
1339
+ throw new InvalidArgumentError(
1340
+ "refspecs",
1341
+ undefined,
1342
+ `The current branch ${branch} has multiple upstream branches, refusing to push.`,
1343
+ );
1344
+ }
1345
+ return merges[0] as string;
1346
+ };
1347
+ // 2.5x: remote_for_branch (branch.<name>.remote, the one configured remote, else
1348
+ // "origin") names the pushed-to remote; 2.43's is_workflow_triangular: the fetch remote
1349
+ // (remote_get(NULL)) exists and is another one
1350
+ // remote_state's remotes are the configured ones and the one pushed to (a URL is made a
1351
+ // remote of its own by remote_get), so pushing to a URL from a repository without
1352
+ // remotes counts that URL as "the one remote"
1353
+ const own = store.value(`branch.${branch}.remote`);
1354
+ const known = new Set(store.configuredNames());
1355
+ known.add(this.remote);
1356
+ const fetchName = own ?? (known.size === 1 ? this.remote : "origin");
1357
+ const fetchValid =
1358
+ own !== undefined || fetchName === this.remote || store.isConfigured(fetchName);
1359
+ const sameRemote =
1360
+ compatibility === "2.43"
1361
+ ? !(fetchValid && fetchName !== this.remote)
1362
+ : this.remote === fetchName;
1363
+ let dst = ref;
1364
+ if (mode === "current") {
1365
+ // the same name
1366
+ } else if (mode === "upstream") {
1367
+ if (!sameRemote) {
1368
+ throw new InvalidArgumentError(
1369
+ "refspecs",
1370
+ undefined,
1371
+ `You are pushing to remote '${this.remote}', which is not the upstream of\n` +
1372
+ `your current branch '${branch}', without telling me what to push\n` +
1373
+ "to update which remote branch.",
1374
+ );
1375
+ }
1376
+ dst = upstreamRef();
1377
+ } else if (sameRemote) {
1378
+ // simple, unspecified (and anything git does not know)
1379
+ const upstream = upstreamRef();
1380
+ if (upstream !== ref) throw this.simpleRefusal(upstream, mode === undefined);
805
1381
  }
806
- return [`${ref}:${ref}`];
1382
+ if (autoUpstream && merges.length === 0) defaults.setUpstream = true;
1383
+ return [`${ref}:${dst}`];
1384
+ }
1385
+
1386
+ /** builtin/push.c's `die_push_simple`: an upstream of another name than the branch. */
1387
+ private simpleRefusal(upstream: string, unspecified: boolean): InvalidArgumentError {
1388
+ const short = upstream.startsWith("refs/heads/")
1389
+ ? upstream.slice("refs/heads/".length)
1390
+ : upstream;
1391
+ const autoSetupMerge = RemoteConfigStore.from(this._workingCopy).value("branch.autoSetupMerge");
1392
+ return new InvalidArgumentError(
1393
+ "refspecs",
1394
+ undefined,
1395
+ "The upstream branch of your current branch does not match\n" +
1396
+ "the name of your current branch. To push to the upstream branch\n" +
1397
+ "on the remote, use\n\n" +
1398
+ ` git push ${this.remote} HEAD:${short}\n\n` +
1399
+ "To push to the branch of the same name on the remote, use\n\n" +
1400
+ ` git push ${this.remote} HEAD\n` +
1401
+ (unspecified
1402
+ ? "\nTo choose either option permanently, see push.default in 'git help config'.\n"
1403
+ : "") +
1404
+ (autoSetupMerge !== "simple"
1405
+ ? "\nTo avoid automatically configuring an upstream branch when its name\n" +
1406
+ "won't match the local branch, see option 'simple' of branch.autoSetupMerge\n" +
1407
+ "in 'git help config'.\n"
1408
+ : ""),
1409
+ );
807
1410
  }
808
1411
 
809
1412
  /**
810
1413
  * The remote-tracking ref of a remote ref (`refs/heads/main` → `refs/remotes/origin/main`)
811
- * through the named remote's fetch refspecs; none for a URL.
1414
+ * through the named remote's fetch refspecs; for a URL, none (2.5x: those of the one remote
1415
+ * pushing to that URL).
812
1416
  */
813
- private trackingRefMapper(): (remoteRef: string) => string | undefined {
1417
+ private trackingRefMapper(
1418
+ remoteUrl: string,
1419
+ compatibility: "2.43" | "2.56",
1420
+ ): (remoteRef: string) => string | undefined {
814
1421
  const store = RemoteConfigStore.from(this.workingCopy);
815
- if (!store.isConfigured(this.remote)) return () => undefined;
1422
+ let tracking = this.remote;
1423
+ if (!store.isConfigured(this.remote)) {
1424
+ // 2.5x's remote_for_push_tracking: a URL that is the push URL of exactly one configured
1425
+ // remote updates that remote's tracking refs
1426
+ if (compatibility === "2.43") return () => undefined;
1427
+ const matches = store
1428
+ .configuredNames()
1429
+ .filter((name) => store.remotePushUrls(name).includes(remoteUrl));
1430
+ if (matches.length !== 1) return () => undefined;
1431
+ tracking = matches[0] as string;
1432
+ }
816
1433
  const specs = store
817
- .read(this.remote)
1434
+ .read(tracking)
818
1435
  .fetchRefspecs.map((spec) => parseRefSpec(spec))
819
1436
  .filter((spec) => !spec.negative && spec.source && spec.destination);
820
1437
  return (remoteRef) => {