@statewalker/vcs-commands 0.8.0 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (297) hide show
  1. package/dist/commands/add-command.d.ts +32 -0
  2. package/dist/commands/add-command.d.ts.map +1 -1
  3. package/dist/commands/add-patch/add-patch.d.ts +7 -0
  4. package/dist/commands/add-patch/add-patch.d.ts.map +1 -1
  5. package/dist/commands/add-patch/patch-backend.d.ts.map +1 -1
  6. package/dist/commands/am/am-command.d.ts +47 -0
  7. package/dist/commands/am/am-command.d.ts.map +1 -1
  8. package/dist/commands/apply/apply-command.d.ts +2 -0
  9. package/dist/commands/apply/apply-command.d.ts.map +1 -1
  10. package/dist/commands/apply/apply-parse.d.ts +7 -0
  11. package/dist/commands/apply/apply-parse.d.ts.map +1 -1
  12. package/dist/commands/apply/index.d.ts +1 -1
  13. package/dist/commands/apply/index.d.ts.map +1 -1
  14. package/dist/commands/blame-command.d.ts +303 -8
  15. package/dist/commands/blame-command.d.ts.map +1 -1
  16. package/dist/commands/blame-ignore.d.ts +48 -0
  17. package/dist/commands/blame-ignore.d.ts.map +1 -0
  18. package/dist/commands/check-mailmap-command.d.ts +49 -0
  19. package/dist/commands/check-mailmap-command.d.ts.map +1 -0
  20. package/dist/commands/checkout-command.d.ts +7 -0
  21. package/dist/commands/checkout-command.d.ts.map +1 -1
  22. package/dist/commands/checkout-paths.d.ts +4 -0
  23. package/dist/commands/checkout-paths.d.ts.map +1 -1
  24. package/dist/commands/cherry-command.d.ts +61 -0
  25. package/dist/commands/cherry-command.d.ts.map +1 -0
  26. package/dist/commands/cherry-pick-command.d.ts +23 -1
  27. package/dist/commands/cherry-pick-command.d.ts.map +1 -1
  28. package/dist/commands/clean-command.d.ts +32 -0
  29. package/dist/commands/clean-command.d.ts.map +1 -1
  30. package/dist/commands/clean-interactive.d.ts +56 -0
  31. package/dist/commands/clean-interactive.d.ts.map +1 -0
  32. package/dist/commands/clone-command.d.ts +116 -2
  33. package/dist/commands/clone-command.d.ts.map +1 -1
  34. package/dist/commands/commit-command.d.ts +50 -2
  35. package/dist/commands/commit-command.d.ts.map +1 -1
  36. package/dist/commands/describe-command.d.ts +71 -64
  37. package/dist/commands/describe-command.d.ts.map +1 -1
  38. package/dist/commands/diff-command.d.ts +118 -6
  39. package/dist/commands/diff-command.d.ts.map +1 -1
  40. package/dist/commands/fetch-command.d.ts +60 -0
  41. package/dist/commands/fetch-command.d.ts.map +1 -1
  42. package/dist/commands/fetch-multiple-command.d.ts +193 -0
  43. package/dist/commands/fetch-multiple-command.d.ts.map +1 -0
  44. package/dist/commands/format-patch-command.d.ts +28 -2
  45. package/dist/commands/format-patch-command.d.ts.map +1 -1
  46. package/dist/commands/git-describe.d.ts +77 -4
  47. package/dist/commands/git-describe.d.ts.map +1 -1
  48. package/dist/commands/git-hooks.d.ts +15 -1
  49. package/dist/commands/git-hooks.d.ts.map +1 -1
  50. package/dist/commands/index.d.ts +12 -0
  51. package/dist/commands/index.d.ts.map +1 -1
  52. package/dist/commands/index.js +5 -3
  53. package/dist/commands/init-command.d.ts +89 -0
  54. package/dist/commands/init-command.d.ts.map +1 -1
  55. package/dist/commands/line-log.d.ts +161 -0
  56. package/dist/commands/line-log.d.ts.map +1 -0
  57. package/dist/commands/log-command.d.ts +235 -6
  58. package/dist/commands/log-command.d.ts.map +1 -1
  59. package/dist/commands/log-graph.d.ts +4 -2
  60. package/dist/commands/log-graph.d.ts.map +1 -1
  61. package/dist/commands/log-output.d.ts +66 -1
  62. package/dist/commands/log-output.d.ts.map +1 -1
  63. package/dist/commands/mailmap.d.ts +24 -1
  64. package/dist/commands/mailmap.d.ts.map +1 -1
  65. package/dist/commands/merge-command.d.ts +51 -1
  66. package/dist/commands/merge-command.d.ts.map +1 -1
  67. package/dist/commands/merge-drivers.d.ts +2 -0
  68. package/dist/commands/merge-drivers.d.ts.map +1 -1
  69. package/dist/commands/merge-strategy-options.d.ts +69 -0
  70. package/dist/commands/merge-strategy-options.d.ts.map +1 -0
  71. package/dist/commands/merge-support.d.ts +10 -0
  72. package/dist/commands/merge-support.d.ts.map +1 -1
  73. package/dist/commands/message-cleanup.d.ts +2 -0
  74. package/dist/commands/message-cleanup.d.ts.map +1 -1
  75. package/dist/commands/name-rev-command.d.ts +65 -0
  76. package/dist/commands/name-rev-command.d.ts.map +1 -0
  77. package/dist/commands/name-rev.d.ts +110 -22
  78. package/dist/commands/name-rev.d.ts.map +1 -1
  79. package/dist/commands/octopus-merge.d.ts +26 -1
  80. package/dist/commands/octopus-merge.d.ts.map +1 -1
  81. package/dist/commands/ort-merge.d.ts +16 -0
  82. package/dist/commands/ort-merge.d.ts.map +1 -1
  83. package/dist/commands/ort-recursive.d.ts.map +1 -1
  84. package/dist/commands/patch-id.d.ts +58 -0
  85. package/dist/commands/patch-id.d.ts.map +1 -1
  86. package/dist/commands/pull-command.d.ts +182 -38
  87. package/dist/commands/pull-command.d.ts.map +1 -1
  88. package/dist/commands/push-command.d.ts +65 -0
  89. package/dist/commands/push-command.d.ts.map +1 -1
  90. package/dist/commands/range-diff/index.d.ts +4 -0
  91. package/dist/commands/range-diff/index.d.ts.map +1 -0
  92. package/dist/commands/range-diff/linear-assignment.d.ts +27 -0
  93. package/dist/commands/range-diff/linear-assignment.d.ts.map +1 -0
  94. package/dist/commands/range-diff/range-diff-command.d.ts +121 -0
  95. package/dist/commands/range-diff/range-diff-command.d.ts.map +1 -0
  96. package/dist/commands/range-diff/range-diff.d.ts +106 -0
  97. package/dist/commands/range-diff/range-diff.d.ts.map +1 -0
  98. package/dist/commands/read-tree-command.d.ts +14 -0
  99. package/dist/commands/read-tree-command.d.ts.map +1 -1
  100. package/dist/commands/rebase-command.d.ts +21 -2
  101. package/dist/commands/rebase-command.d.ts.map +1 -1
  102. package/dist/commands/remerge-diff.d.ts +59 -0
  103. package/dist/commands/remerge-diff.d.ts.map +1 -0
  104. package/dist/commands/remote-command.d.ts +41 -0
  105. package/dist/commands/remote-command.d.ts.map +1 -1
  106. package/dist/commands/remote-show-command.d.ts +204 -0
  107. package/dist/commands/remote-show-command.d.ts.map +1 -0
  108. package/dist/commands/reset-command.d.ts +19 -1
  109. package/dist/commands/reset-command.d.ts.map +1 -1
  110. package/dist/commands/restore-command.d.ts +7 -0
  111. package/dist/commands/restore-command.d.ts.map +1 -1
  112. package/dist/commands/rev-list-command.d.ts +75 -3
  113. package/dist/commands/rev-list-command.d.ts.map +1 -1
  114. package/dist/commands/revert-command.d.ts +22 -1
  115. package/dist/commands/revert-command.d.ts.map +1 -1
  116. package/dist/commands/revision-range.d.ts +2 -0
  117. package/dist/commands/revision-range.d.ts.map +1 -1
  118. package/dist/commands/sequencer-pick.d.ts +102 -1
  119. package/dist/commands/sequencer-pick.d.ts.map +1 -1
  120. package/dist/commands/sequencer-support.d.ts +10 -1
  121. package/dist/commands/sequencer-support.d.ts.map +1 -1
  122. package/dist/commands/shortlog-command.d.ts +109 -0
  123. package/dist/commands/shortlog-command.d.ts.map +1 -0
  124. package/dist/commands/shortlog.d.ts +151 -0
  125. package/dist/commands/shortlog.d.ts.map +1 -0
  126. package/dist/commands/status-command.d.ts +31 -2
  127. package/dist/commands/status-command.d.ts.map +1 -1
  128. package/dist/commands/submodule-commands.d.ts +90 -2
  129. package/dist/commands/submodule-commands.d.ts.map +1 -1
  130. package/dist/commands/submodule-fetch.d.ts +149 -0
  131. package/dist/commands/submodule-fetch.d.ts.map +1 -0
  132. package/dist/commands/submodule-model.d.ts +8 -0
  133. package/dist/commands/submodule-model.d.ts.map +1 -1
  134. package/dist/commands/submodule-unpack.d.ts +120 -0
  135. package/dist/commands/submodule-unpack.d.ts.map +1 -0
  136. package/dist/commands/submodule-update-command.d.ts +8 -0
  137. package/dist/commands/submodule-update-command.d.ts.map +1 -1
  138. package/dist/commands/subtree-shift.d.ts +27 -0
  139. package/dist/commands/subtree-shift.d.ts.map +1 -0
  140. package/dist/commands/switch-command.d.ts +3 -0
  141. package/dist/commands/switch-command.d.ts.map +1 -1
  142. package/dist/commands/tree-restore.d.ts.map +1 -1
  143. package/dist/commands/worktree-overwrite-checks.d.ts +2 -0
  144. package/dist/commands/worktree-overwrite-checks.d.ts.map +1 -1
  145. package/dist/{commands-ISM52N0n.js → commands-CNvli5bl.js} +39426 -61169
  146. package/dist/errors/command-errors.d.ts +25 -0
  147. package/dist/errors/command-errors.d.ts.map +1 -1
  148. package/dist/errors/index.js +29 -1
  149. package/dist/fsck-CPeDh9fh.js +5138 -0
  150. package/dist/git-command.d.ts +31 -1
  151. package/dist/git-command.d.ts.map +1 -1
  152. package/dist/git.d.ts +97 -1
  153. package/dist/git.d.ts.map +1 -1
  154. package/dist/guarded-transport-command.d.ts +82 -0
  155. package/dist/guarded-transport-command.d.ts.map +1 -0
  156. package/dist/index.d.ts +1 -0
  157. package/dist/index.d.ts.map +1 -1
  158. package/dist/index.js +6 -5
  159. package/dist/remote-transport-CCmBadm-.js +1606 -0
  160. package/dist/rename/detect-renames.d.ts +20 -0
  161. package/dist/rename/detect-renames.d.ts.map +1 -1
  162. package/dist/rename/diffcore-break.d.ts +51 -0
  163. package/dist/rename/diffcore-break.d.ts.map +1 -0
  164. package/dist/rename/index.d.ts +1 -0
  165. package/dist/rename/index.d.ts.map +1 -1
  166. package/dist/results/blame-format.d.ts +62 -1
  167. package/dist/results/blame-format.d.ts.map +1 -1
  168. package/dist/results/clone-result.d.ts +9 -0
  169. package/dist/results/clone-result.d.ts.map +1 -1
  170. package/dist/results/diff-dirstat.d.ts +36 -0
  171. package/dist/results/diff-dirstat.d.ts.map +1 -0
  172. package/dist/results/diff-entry.d.ts +10 -0
  173. package/dist/results/diff-entry.d.ts.map +1 -1
  174. package/dist/results/diff-formatter.d.ts.map +1 -1
  175. package/dist/results/diff-output.d.ts +18 -0
  176. package/dist/results/diff-output.d.ts.map +1 -1
  177. package/dist/results/fetch-result.d.ts +12 -1
  178. package/dist/results/fetch-result.d.ts.map +1 -1
  179. package/dist/results/index.d.ts +2 -0
  180. package/dist/results/index.d.ts.map +1 -1
  181. package/dist/results/index.js +2 -2
  182. package/dist/results/init-result.d.ts +8 -1
  183. package/dist/results/init-result.d.ts.map +1 -1
  184. package/dist/results/line-range-hunks.d.ts +27 -0
  185. package/dist/results/line-range-hunks.d.ts.map +1 -0
  186. package/dist/results/merge-result.d.ts +8 -1
  187. package/dist/results/merge-result.d.ts.map +1 -1
  188. package/dist/results/pull-result.d.ts +11 -0
  189. package/dist/results/pull-result.d.ts.map +1 -1
  190. package/dist/results/push-result.d.ts +5 -0
  191. package/dist/results/push-result.d.ts.map +1 -1
  192. package/dist/results/status-result.d.ts +1 -1
  193. package/dist/results/status-result.d.ts.map +1 -1
  194. package/dist/results-BDuEgdLU.js +46847 -0
  195. package/dist/transport-command.d.ts +14 -0
  196. package/dist/transport-command.d.ts.map +1 -1
  197. package/package.json +12 -12
  198. package/src/commands/add-command.ts +115 -0
  199. package/src/commands/add-patch/add-patch.ts +8 -0
  200. package/src/commands/add-patch/patch-backend.ts +20 -2
  201. package/src/commands/am/am-command.ts +138 -4
  202. package/src/commands/apply/apply-command.ts +52 -9
  203. package/src/commands/apply/apply-parse.ts +10 -0
  204. package/src/commands/apply/index.ts +8 -1
  205. package/src/commands/blame-command.ts +1450 -51
  206. package/src/commands/blame-ignore.ts +307 -0
  207. package/src/commands/check-mailmap-command.ts +129 -0
  208. package/src/commands/checkout-command.ts +97 -12
  209. package/src/commands/checkout-paths.ts +28 -0
  210. package/src/commands/cherry-command.ts +187 -0
  211. package/src/commands/cherry-pick-command.ts +42 -1
  212. package/src/commands/clean-command.ts +92 -12
  213. package/src/commands/clean-interactive.ts +522 -0
  214. package/src/commands/clone-command.ts +596 -44
  215. package/src/commands/commit-command.ts +180 -47
  216. package/src/commands/describe-command.ts +341 -254
  217. package/src/commands/diff-command.ts +616 -56
  218. package/src/commands/fetch-command.ts +353 -6
  219. package/src/commands/fetch-multiple-command.ts +665 -0
  220. package/src/commands/format-patch-command.ts +189 -77
  221. package/src/commands/git-describe.ts +456 -217
  222. package/src/commands/git-hooks.ts +42 -3
  223. package/src/commands/index.ts +17 -0
  224. package/src/commands/init-command.ts +603 -49
  225. package/src/commands/line-log.ts +931 -0
  226. package/src/commands/log-command.ts +1414 -177
  227. package/src/commands/log-graph.ts +6 -3
  228. package/src/commands/log-output.ts +173 -10
  229. package/src/commands/mailmap.ts +41 -5
  230. package/src/commands/merge-command.ts +274 -16
  231. package/src/commands/merge-drivers.ts +3 -0
  232. package/src/commands/merge-strategy-options.ts +224 -0
  233. package/src/commands/merge-support.ts +101 -21
  234. package/src/commands/message-cleanup.ts +1 -1
  235. package/src/commands/name-rev-command.ts +184 -0
  236. package/src/commands/name-rev.ts +700 -109
  237. package/src/commands/octopus-merge.ts +35 -11
  238. package/src/commands/ort-merge.ts +41 -7
  239. package/src/commands/ort-recursive.ts +40 -2
  240. package/src/commands/patch-id.ts +109 -0
  241. package/src/commands/pull-command.ts +718 -224
  242. package/src/commands/push-command.ts +353 -3
  243. package/src/commands/range-diff/index.ts +3 -0
  244. package/src/commands/range-diff/linear-assignment.ts +203 -0
  245. package/src/commands/range-diff/range-diff-command.ts +433 -0
  246. package/src/commands/range-diff/range-diff.ts +617 -0
  247. package/src/commands/read-tree-command.ts +74 -3
  248. package/src/commands/rebase-command.ts +141 -65
  249. package/src/commands/remerge-diff.ts +241 -0
  250. package/src/commands/remote-command.ts +98 -10
  251. package/src/commands/remote-show-command.ts +836 -0
  252. package/src/commands/reset-command.ts +78 -3
  253. package/src/commands/restore-command.ts +15 -0
  254. package/src/commands/rev-list-command.ts +187 -11
  255. package/src/commands/revert-command.ts +41 -1
  256. package/src/commands/revision-range.ts +3 -1
  257. package/src/commands/sequencer-pick.ts +323 -29
  258. package/src/commands/sequencer-support.ts +164 -2
  259. package/src/commands/shortlog-command.ts +354 -0
  260. package/src/commands/shortlog.ts +361 -0
  261. package/src/commands/show-command.ts +2 -1
  262. package/src/commands/status-command.ts +115 -25
  263. package/src/commands/status-format.ts +1 -1
  264. package/src/commands/submodule-commands.ts +321 -3
  265. package/src/commands/submodule-fetch.ts +789 -0
  266. package/src/commands/submodule-model.ts +9 -1
  267. package/src/commands/submodule-unpack.ts +265 -0
  268. package/src/commands/submodule-update-command.ts +39 -5
  269. package/src/commands/subtree-shift.ts +215 -0
  270. package/src/commands/switch-command.ts +9 -0
  271. package/src/commands/tree-restore.ts +6 -1
  272. package/src/commands/worktree-overwrite-checks.ts +5 -0
  273. package/src/errors/command-errors.ts +35 -0
  274. package/src/git-command.ts +87 -1
  275. package/src/git.ts +146 -0
  276. package/src/guarded-transport-command.ts +171 -0
  277. package/src/index.ts +1 -0
  278. package/src/rename/detect-renames.ts +42 -8
  279. package/src/rename/diffcore-break.ts +166 -0
  280. package/src/rename/index.ts +1 -0
  281. package/src/results/blame-format.ts +268 -43
  282. package/src/results/clone-result.ts +6 -0
  283. package/src/results/diff-dirstat.ts +117 -0
  284. package/src/results/diff-entry.ts +12 -0
  285. package/src/results/diff-formatter.ts +1 -0
  286. package/src/results/diff-output.ts +127 -2
  287. package/src/results/fetch-result.ts +12 -1
  288. package/src/results/index.ts +2 -0
  289. package/src/results/init-result.ts +10 -1
  290. package/src/results/line-range-hunks.ts +126 -0
  291. package/src/results/merge-result.ts +9 -0
  292. package/src/results/pull-result.ts +7 -0
  293. package/src/results/push-result.ts +5 -0
  294. package/src/results/status-result.ts +2 -2
  295. package/src/transport-command.ts +34 -3
  296. package/dist/fsck-DLRpbwTj.js +0 -13405
  297. package/dist/results-TB2IJ64h.js +0 -4700
@@ -24,6 +24,7 @@ import { parseGitBool, parseGitInt } from "@statewalker/vcs-utils/encoding";
24
24
  import { isNullObjectId } from "@statewalker/vcs-utils/hash";
25
25
 
26
26
  import {
27
+ GitApiError,
27
28
  HookFailedError,
28
29
  IncompatibleOptionsError,
29
30
  InvalidArgumentError,
@@ -41,6 +42,12 @@ import { hostEnvironmentOf } from "./git-ident.js";
41
42
  import { remoteHookSession } from "./local-transport.js";
42
43
  import { withRemoteReceivePack } from "./remote-transport.js";
43
44
  import { SIGNING_FAILED_LINES, SigningFailedError } from "./signing.js";
45
+ import {
46
+ createSubmoduleAuthPolicy,
47
+ guardSubmoduleTransports,
48
+ strictUrlOrigin,
49
+ } from "./submodule-auth.js";
50
+ import { findUnpushedSubmodules, SubmoduleFetchRepository } from "./submodule-fetch.js";
44
51
 
45
52
  /**
46
53
  * How a server's rejection reason (`ng <ref> <reason>`) lands on the statuses this package
@@ -139,6 +146,36 @@ export class PushCommand extends TransportCommand<PushResult> {
139
146
  /** `--[no-]signed[=if-asked]` (undefined: `push.gpgSign`) */
140
147
  private signed?: boolean | "if-asked";
141
148
  private noVerify = false;
149
+ /** `--recurse-submodules=<mode>`; unset: the configuration's */
150
+ private recurseSubmodules?: PushRecurseSubmodules;
151
+ /** `--recurse-submodules=only-is-on-demand`: a superproject's push of this submodule */
152
+ private recurseFromSuperproject = false;
153
+
154
+ /**
155
+ * `--recurse-submodules=check|on-demand|only|no` (`--no-recurse-submodules` is `no`):
156
+ * before the refs are sent, the submodules whose recorded commits (in the commits pushed,
157
+ * not on the remote's tracking refs) are on none of the submodule's remote-tracking refs
158
+ * are `check`ed (the push dies listing them), pushed first (`on-demand`: `git push` in each,
159
+ * to the remote and refspecs given here when the remote is configured; then checked again
160
+ * unless a dry run), or pushed alone (`only`: the superproject's refs are not sent). Unset,
161
+ * `push.recurseSubmodules` and `submodule.recurse` (on-demand or no) decide, in config
162
+ * order. What the submodules' pushes printed is {@link PushResult.submoduleOutput}.
163
+ * A bare repository never recurses.
164
+ */
165
+ setRecurseSubmodules(mode: PushRecurseSubmodules | boolean): this {
166
+ this.checkCallable();
167
+ // option_parse_recurse_submodules: true, `yes` and other spellings die
168
+ this.recurseSubmodules =
169
+ mode === false ? "no" : parsePushRecurseSubmodules("recurse-submodules", String(mode));
170
+ return this;
171
+ }
172
+
173
+ /** @internal `--recurse-submodules=only-is-on-demand`: run by a superproject's push. */
174
+ setRecurseFromSuperproject(child: boolean): this {
175
+ this.checkCallable();
176
+ this.recurseFromSuperproject = child;
177
+ return this;
178
+ }
142
179
 
143
180
  /** `--no-verify`: the pre-push hook does not run. */
144
181
  setNoVerify(noVerify: boolean): this {
@@ -585,6 +622,8 @@ export class PushCommand extends TransportCommand<PushResult> {
585
622
  // git_push_config: push.pushOption is read (and a bad one dies) before anything else;
586
623
  // the command line's options replace the configured ones
587
624
  const configuredOptions = this.configuredPushOptions();
625
+ const submoduleWarnings: string[] = [];
626
+ const recurse = this.pushRecursion(submoduleWarnings);
588
627
  const transmitted = this.pushOptions.length > 0 ? this.pushOptions : configuredOptions;
589
628
  this.checkOptionCombinations(compatibility);
590
629
  if (this.deleteRefs && this.refSpecs.length === 0) {
@@ -685,6 +724,10 @@ export class PushCommand extends TransportCommand<PushResult> {
685
724
  leases !== undefined &&
686
725
  leases.length > 0 &&
687
726
  (this.forceIfIncludes ?? this.configBool("push.useForceIfIncludes") ?? false);
727
+ // transport_push: the submodules (not of a bare repository) once the hook passed
728
+ const recurseOnPush =
729
+ recurse !== undefined && new SubmoduleFetchRepository(this.workingCopy).hasWorktree();
730
+ const submoduleOutput = { text: submoduleWarnings.map((w) => `${w}\n`).join("") };
688
731
  const pushOptions: TransportPushOptions = {
689
732
  url: remoteUrl,
690
733
  auth: this.credentials,
@@ -719,10 +762,28 @@ export class PushCommand extends TransportCommand<PushResult> {
719
762
  this.progressMessageCallback?.(message);
720
763
  },
721
764
  abbrev: parseCoreAbbrev(RemoteConfigStore.from(this._workingCopy).value("core.abbrev")) ?? -1,
722
- ...(!this.noVerify && this.hooks.enabled
765
+ ...((!this.noVerify && this.hooks.enabled) || recurseOnPush
723
766
  ? {
724
- prePush: (updates) =>
725
- this.runPrePush(updates, remoteUrl, (code) => (prePushExit = code)),
767
+ prePush: async (updates) => {
768
+ if (
769
+ !this.noVerify &&
770
+ this.hooks.enabled &&
771
+ !(await this.runPrePush(updates, remoteUrl, (code) => (prePushExit = code)))
772
+ ) {
773
+ return false;
774
+ }
775
+ if (recurseOnPush) {
776
+ await this.pushSubmodulesFirst(
777
+ recurse,
778
+ updates,
779
+ refspecs,
780
+ transmitted,
781
+ remoteUrl,
782
+ submoduleOutput,
783
+ );
784
+ }
785
+ return true;
786
+ },
726
787
  }
727
788
  : {}),
728
789
  };
@@ -798,6 +859,26 @@ export class PushCommand extends TransportCommand<PushResult> {
798
859
  128,
799
860
  );
800
861
  }
862
+ // --recurse-submodules=only: the submodules pushed, nothing sent for the superproject
863
+ if (error instanceof SubmodulesOnlyPushed) {
864
+ return {
865
+ uri: remoteUrl,
866
+ remoteUpdates: [],
867
+ bytesSent: 0,
868
+ objectCount: 0,
869
+ messages,
870
+ ...warnings,
871
+ display: this.quietOutput ? [] : ["Everything up-to-date"],
872
+ ...(submoduleOutput.text ? { submoduleOutput: submoduleOutput.text } : {}),
873
+ };
874
+ }
875
+ if (
876
+ error instanceof GitApiError &&
877
+ submoduleOutput.text &&
878
+ !error.message.startsWith(submoduleOutput.text)
879
+ ) {
880
+ error.message = `${submoduleOutput.text}${error.message}`;
881
+ }
801
882
  if (error instanceof PushRefusedByHookError) {
802
883
  throw new HookFailedError(
803
884
  "pre-push",
@@ -926,9 +1007,232 @@ export class PushCommand extends TransportCommand<PushResult> {
926
1007
  // send_pack left at once (nothing to push to a remote without refs): the receiving end
927
1008
  // hung up, and git fails
928
1009
  ...(result.reportFailed || result.noRefsInCommon ? { failed: true } : {}),
1010
+ ...(submoduleOutput.text ? { submoduleOutput: submoduleOutput.text } : {}),
929
1011
  };
930
1012
  }
931
1013
 
1014
+ /**
1015
+ * builtin/push.c's `recurse_submodules`: `push.recurseSubmodules` and `submodule.recurse`
1016
+ * in config order, then the command line; undefined for none (`no`). A superproject's push
1017
+ * of this submodule takes `only` as `on-demand`, with git's warning.
1018
+ */
1019
+ private pushRecursion(warnings: string[]): Exclude<PushRecurseSubmodules, "no"> | undefined {
1020
+ let mode: PushRecurseSubmodules | undefined;
1021
+ const store = RemoteConfigStore.from(this._workingCopy);
1022
+ for (const entry of store.entriesWithOriginFor([
1023
+ "push.recursesubmodules",
1024
+ "submodule.recurse",
1025
+ ]) ?? []) {
1026
+ if (entry.key === "submodule.recurse") {
1027
+ const bool = entry.text === undefined ? true : parseGitBool(entry.text);
1028
+ if (bool === undefined) {
1029
+ throw new GitApiError(
1030
+ `fatal: bad boolean config value '${entry.text}' for 'submodule.recurse'`,
1031
+ { exitCode: 128 },
1032
+ );
1033
+ }
1034
+ mode = bool ? "on-demand" : "no";
1035
+ } else mode = parsePushRecurseSubmodules("push.recursesubmodules", entry.text);
1036
+ }
1037
+ if (this.recurseFromSuperproject) {
1038
+ if (mode === "only") {
1039
+ warnings.push(
1040
+ "warning: recursing into submodule with push.recurseSubmodules=only; using on-demand instead",
1041
+ );
1042
+ mode = "on-demand";
1043
+ }
1044
+ } else if (this.recurseSubmodules !== undefined) mode = this.recurseSubmodules;
1045
+ return mode === undefined || mode === "no" ? undefined : mode;
1046
+ }
1047
+
1048
+ /** git's `-q`: never set here (the report is the caller's to print) */
1049
+ private readonly quietOutput = false;
1050
+
1051
+ /**
1052
+ * transport.c's submodule steps of `transport_push`: `push_unpushed_submodules` for
1053
+ * on-demand and only, then the `find_unpushed_submodules` check for check (and on-demand
1054
+ * and only unless a dry run); `only` then stops the push ({@link SubmodulesOnlyPushed}).
1055
+ */
1056
+ private async pushSubmodulesFirst(
1057
+ mode: Exclude<PushRecurseSubmodules, "no">,
1058
+ updates: readonly PushRefUpdate[],
1059
+ refspecs: readonly string[],
1060
+ pushOptions: readonly string[],
1061
+ remoteUrl: string,
1062
+ output: { text: string },
1063
+ ): Promise<void> {
1064
+ const commits = updates.map((u) => u.newOid).filter((id) => id && !isNullObjectId(id));
1065
+ const store = RemoteConfigStore.from(this._workingCopy);
1066
+ const configured = store.isConfigured(this.remote);
1067
+ const remoteName = configured ? this.remote : remoteUrl;
1068
+ const warn = (line: string) => {
1069
+ output.text += `${line}\n`;
1070
+ };
1071
+ const die = (message: string): never => {
1072
+ throw new GitApiError(`${output.text}${message}`, { exitCode: 128 });
1073
+ };
1074
+ if (mode === "on-demand" || mode === "only") {
1075
+ const needs = await findUnpushedSubmodules(this.workingCopy, commits, remoteName, warn);
1076
+ if (needs.length > 0) {
1077
+ if (configured) {
1078
+ const head = await this.refsStore.get("HEAD").catch(() => undefined);
1079
+ const headName =
1080
+ head && "target" in head && typeof head.target === "string" ? head.target : "HEAD";
1081
+ for (const path of needs) {
1082
+ const refusal = await this.submodulePushCheck(path, headName, refspecs);
1083
+ if (refusal !== undefined) {
1084
+ output.text += `${refusal}\n`;
1085
+ die(`fatal: process for submodule '${path}' failed`);
1086
+ }
1087
+ }
1088
+ }
1089
+ let ok = true;
1090
+ for (const path of needs) {
1091
+ output.text += `Pushing submodule '${path}'\n`;
1092
+ if (!(await this.pushSubmodule(path, configured, refspecs, pushOptions, output))) {
1093
+ output.text += `Unable to push submodule '${path}'\n`;
1094
+ ok = false;
1095
+ }
1096
+ }
1097
+ if (!ok) die("fatal: failed to push all needed submodules");
1098
+ }
1099
+ }
1100
+ if (mode === "check" || !this.dryRun) {
1101
+ const needs = await findUnpushedSubmodules(this.workingCopy, commits, remoteName, warn);
1102
+ if (needs.length > 0) {
1103
+ die(
1104
+ [
1105
+ "The following submodule paths contain changes that can",
1106
+ "not be found on any remote:",
1107
+ ...needs.map((p) => ` ${p}`),
1108
+ "",
1109
+ "Please try",
1110
+ "",
1111
+ "\tgit push --recurse-submodules=on-demand",
1112
+ "",
1113
+ "or cd to the path and use",
1114
+ "",
1115
+ "\tgit push",
1116
+ "",
1117
+ "to push them to a remote.",
1118
+ "",
1119
+ "fatal: Aborting.",
1120
+ ].join("\n"),
1121
+ );
1122
+ }
1123
+ }
1124
+ if (mode === "only") throw new SubmodulesOnlyPushed();
1125
+ }
1126
+
1127
+ /** The submodule's repository at `path` (populated). */
1128
+ private async openSubmodulePath(path: string) {
1129
+ return this.worktreeAccess?.openGitlink?.(path).catch(() => undefined);
1130
+ }
1131
+
1132
+ /**
1133
+ * submodule.c's `push_submodule`: `git push --recurse-submodules=only-is-on-demand
1134
+ * [--dry-run] [--push-option=...] [<remote> <refspec>...]` in the submodule, when it has
1135
+ * remote-tracking refs; false when that push failed.
1136
+ */
1137
+ private async pushSubmodule(
1138
+ path: string,
1139
+ configured: boolean,
1140
+ refspecs: readonly string[],
1141
+ pushOptions: readonly string[],
1142
+ output: { text: string },
1143
+ ): Promise<boolean> {
1144
+ const inner = await this.openSubmodulePath(path);
1145
+ if (!inner) return true;
1146
+ const remotes = await new SubmoduleFetchRepository(inner).refTipsUnder("refs/remotes/");
1147
+ if (remotes.length === 0) return true;
1148
+ const child = new PushCommand(inner).setRecurseFromSuperproject(true);
1149
+ // git's child `git push` runs in the submodule: its own hooks (the submodule's hooks
1150
+ // directory, its directory as cwd), their output relayed where the child prints it
1151
+ child.setTransports(this.submoduleTransports());
1152
+ if (this.timeout !== undefined) child.setTimeout(this.timeout);
1153
+ if (this.dryRun) child.setDryRun(true);
1154
+ if (pushOptions.length > 0) child.setPushOptions([...pushOptions]);
1155
+ if (configured) {
1156
+ child.setRemote(this.remote);
1157
+ if (refspecs.length > 0) child.setRefSpecs(...refspecs);
1158
+ }
1159
+ if (this.compatibility) child.setCompatibility(this.compatibility);
1160
+ try {
1161
+ const result = await child.call();
1162
+ output.text += `${child.getHookOutput()}${pushOutputText(result)}`;
1163
+ this.hooks.appendStdout(child.getHookStdout());
1164
+ return pushSucceeded(result);
1165
+ } catch (error) {
1166
+ if (!(error instanceof Error)) throw error;
1167
+ output.text += `${child.getHookOutput()}${error.message.replace(/\n$/, "")}\n`;
1168
+ this.hooks.appendStdout(child.getHookStdout());
1169
+ return false;
1170
+ }
1171
+ }
1172
+
1173
+ /**
1174
+ * The transports a submodule's push goes through: a submodule's URL is repository content,
1175
+ * so this push's credentials and headers go only to its own remote's origin.
1176
+ */
1177
+ private submoduleTransports() {
1178
+ const transports = this.getTransports();
1179
+ if (!this.credentials && !this.headers) return transports;
1180
+ const url = RemoteConfigStore.from(this._workingCopy).remoteUrlOf(this.remote);
1181
+ const origin = strictUrlOrigin(url);
1182
+ return guardSubmoduleTransports(
1183
+ transports,
1184
+ createSubmoduleAuthPolicy({
1185
+ ...(this.credentials ? { credentials: this.credentials } : {}),
1186
+ ...(this.headers ? { headers: this.headers } : {}),
1187
+ origins: origin !== undefined ? [origin] : [],
1188
+ }),
1189
+ );
1190
+ }
1191
+
1192
+ /**
1193
+ * `git submodule--helper push-check <head> <remote> <refspec>...` in the submodule: its
1194
+ * `fatal:` line when the remote is not configured there or a refspec's source names no
1195
+ * single ref (`HEAD` only when the submodule is on the superproject's branch).
1196
+ */
1197
+ private async submodulePushCheck(
1198
+ path: string,
1199
+ superHead: string,
1200
+ refspecs: readonly string[],
1201
+ ): Promise<string | undefined> {
1202
+ const inner = await this.openSubmodulePath(path);
1203
+ if (!inner) return undefined;
1204
+ const repo = new SubmoduleFetchRepository(inner);
1205
+ const head = await repo.headRef();
1206
+ if (head === undefined) return "fatal: Failed to resolve HEAD as a valid ref.";
1207
+ if (!RemoteConfigStore.from(inner).isConfigured(this.remote)) {
1208
+ return `fatal: remote '${this.remote}' not configured`;
1209
+ }
1210
+ const names = [...(await repo.refTips()).keys()];
1211
+ for (const raw of refspecs) {
1212
+ const spec = raw.startsWith("+") ? raw.slice(1) : raw;
1213
+ if (spec === ":" || spec.includes("*")) continue;
1214
+ const colon = spec.indexOf(":");
1215
+ const src = colon < 0 ? spec : spec.slice(0, colon);
1216
+ if (src === "") continue;
1217
+ const candidates = [
1218
+ src,
1219
+ `refs/${src}`,
1220
+ `refs/tags/${src}`,
1221
+ `refs/heads/${src}`,
1222
+ `refs/remotes/${src}`,
1223
+ `refs/remotes/${src}/HEAD`,
1224
+ ];
1225
+ const count = new Set(candidates.filter((c) => names.includes(c))).size;
1226
+ if (count === 1) continue;
1227
+ if (count === 0 && src === "HEAD") {
1228
+ if (head !== "HEAD" && head === superHead) continue;
1229
+ return "fatal: HEAD does not match the named branch in the superproject";
1230
+ }
1231
+ return `fatal: src refspec '${src}' must name a ref`;
1232
+ }
1233
+ return undefined;
1234
+ }
1235
+
932
1236
  /**
933
1237
  * transport.c's pre-push hook: told the remote's name (its URL when pushed to by URL) and
934
1238
  * URL, with a `<local ref> <local id> <remote ref> <remote id>` line on stdin for each ref
@@ -1459,3 +1763,49 @@ function refNameIsSafe(name: string): boolean {
1459
1763
  }
1460
1764
  return /^[A-Z_]+$/.test(name);
1461
1765
  }
1766
+
1767
+ /** `--recurse-submodules=only` stopped the push once the submodules were pushed. */
1768
+ class SubmodulesOnlyPushed extends Error {}
1769
+
1770
+ /**
1771
+ * builtin/push.c's `--recurse-submodules` modes (git's `RECURSE_SUBMODULES_CHECK`,
1772
+ * `_ON_DEMAND`, `_ONLY`, `_OFF`).
1773
+ */
1774
+ export type PushRecurseSubmodules = "check" | "on-demand" | "only" | "no";
1775
+
1776
+ /**
1777
+ * submodule-config.c's `parse_push_recurse_submodules_arg`: false, `on-demand`, `check` or
1778
+ * `only`; true (there is no plain "on" for a push) and anything else die.
1779
+ */
1780
+ export function parsePushRecurseSubmodules(
1781
+ key: string,
1782
+ value: string | undefined,
1783
+ ): PushRecurseSubmodules {
1784
+ const bool = value === undefined ? true : parseGitBool(value);
1785
+ if (bool === false) return "no";
1786
+ if (bool === undefined && (value === "on-demand" || value === "check" || value === "only")) {
1787
+ return value;
1788
+ }
1789
+ throw new GitApiError(`fatal: bad ${key} argument: ${value ?? "true"}`, { exitCode: 128 });
1790
+ }
1791
+
1792
+ /** What a push prints on stderr: its warnings, its report, its errors, its submodules'. */
1793
+ export function pushOutputText(result: PushResult): string {
1794
+ const lines = [
1795
+ ...(result.warnings ?? []),
1796
+ ...(result.display ?? []),
1797
+ ...(result.errors ?? []),
1798
+ ...(pushSucceeded(result) ? [] : [`error: failed to push some refs to '${result.uri}'`]),
1799
+ ];
1800
+ return `${result.submoduleOutput ?? ""}${lines.map((l) => `${l}\n`).join("")}`;
1801
+ }
1802
+
1803
+ /** Whether git's push exits 0: every ref pushed or up to date, the report sound. */
1804
+ export function pushSucceeded(result: PushResult): boolean {
1805
+ return (
1806
+ !result.failed &&
1807
+ result.remoteUpdates.every(
1808
+ (u) => u.status === PushStatus.OK || u.status === PushStatus.UP_TO_DATE,
1809
+ )
1810
+ );
1811
+ }
@@ -0,0 +1,3 @@
1
+ export * from "./linear-assignment.js";
2
+ export * from "./range-diff.js";
3
+ export * from "./range-diff-command.js";
@@ -0,0 +1,203 @@
1
+ /**
2
+ * git's linear-assignment.c: the Jonker-Volgenant shortest augmenting path solver of the
3
+ * linear assignment problem (Jonker, R., & Volgenant, A. (1987). A shortest augmenting path
4
+ * algorithm for dense and sparse linear assignment problems. Computing, 38(4), 325-340),
5
+ * step for step as git runs it, so that ties end in git's pairing.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * // two columns, two rows: column 0 costs 1 in row 0 and 2 in row 1
10
+ * const { columnToRow } = computeAssignment(2, 2, [1, 5, 2, 1]);
11
+ * // columnToRow: [0, 1]
12
+ * ```
13
+ */
14
+
15
+ /** git's `INT_MAX` */
16
+ const INT_MAX = 2147483647;
17
+
18
+ /** The pairing found: the row of each column and the column of each row. */
19
+ export interface Assignment {
20
+ columnToRow: Int32Array;
21
+ rowToColumn: Int32Array;
22
+ }
23
+
24
+ /**
25
+ * `compute_assignment`: the assignment of columns to rows of least total cost. `cost` is the
26
+ * cost matrix, the cost of assigning column `j` to row `i` at `cost[j + columnCount * i]`.
27
+ * With fewer than two columns every column and row is paired with 0, as git leaves them.
28
+ *
29
+ * @throws Error where git hits its `BUG("negative j")`
30
+ */
31
+ export function computeAssignment(
32
+ columnCount: number,
33
+ rowCount: number,
34
+ cost: ArrayLike<number>,
35
+ ): Assignment {
36
+ const column2row = new Int32Array(columnCount);
37
+ const row2column = new Int32Array(rowCount);
38
+ if (columnCount < 2) return { columnToRow: column2row, rowToColumn: row2column };
39
+ const COST = (column: number, row: number) => cost[column + columnCount * row] as number;
40
+
41
+ column2row.fill(-1);
42
+ row2column.fill(-1);
43
+ const v = new Int32Array(columnCount);
44
+
45
+ // column reduction
46
+ for (let j = columnCount - 1; j >= 0; j--) {
47
+ let i1 = 0;
48
+ for (let i = 1; i < rowCount; i++) if (COST(j, i1) > COST(j, i)) i1 = i;
49
+ v[j] = COST(j, i1);
50
+ if (row2column[i1] === -1) {
51
+ // row i1 unassigned
52
+ row2column[i1] = j;
53
+ column2row[j] = i1;
54
+ } else {
55
+ if ((row2column[i1] as number) >= 0) row2column[i1] = -2 - (row2column[i1] as number);
56
+ column2row[j] = -1;
57
+ }
58
+ }
59
+
60
+ // reduction transfer
61
+ const freeRow = new Int32Array(rowCount);
62
+ let freeCount = 0;
63
+ for (let i = 0; i < rowCount; i++) {
64
+ const j1 = row2column[i] as number;
65
+ if (j1 === -1) freeRow[freeCount++] = i;
66
+ else if (j1 < -1) row2column[i] = -2 - j1;
67
+ else {
68
+ const other = j1 === 0 ? 1 : 0;
69
+ let min = COST(other, i) - (v[other] as number);
70
+ for (let j = 1; j < columnCount; j++)
71
+ if (j !== j1 && min > COST(j, i) - (v[j] as number)) min = COST(j, i) - (v[j] as number);
72
+ v[j1] = (v[j1] as number) - min;
73
+ }
74
+ }
75
+
76
+ if (freeCount === (columnCount < rowCount ? rowCount - columnCount : 0)) {
77
+ return { columnToRow: column2row, rowToColumn: row2column };
78
+ }
79
+
80
+ // augmenting row reduction
81
+ for (let phase = 0; phase < 2; phase++) {
82
+ let k = 0;
83
+ const savedFreeCount = freeCount;
84
+ freeCount = 0;
85
+ while (k < savedFreeCount) {
86
+ let j1 = 0;
87
+ const i = freeRow[k++] as number;
88
+ let u1 = COST(j1, i) - (v[j1] as number);
89
+ let j2 = -1;
90
+ let u2 = INT_MAX;
91
+ for (let j = 1; j < columnCount; j++) {
92
+ const c = COST(j, i) - (v[j] as number);
93
+ if (u2 > c) {
94
+ if (u1 < c) {
95
+ u2 = c;
96
+ j2 = j;
97
+ } else {
98
+ u2 = u1;
99
+ u1 = c;
100
+ j2 = j1;
101
+ j1 = j;
102
+ }
103
+ }
104
+ }
105
+ if (j2 < 0) {
106
+ j2 = j1;
107
+ u2 = u1;
108
+ }
109
+
110
+ let i0 = column2row[j1] as number;
111
+ if (u1 < u2) v[j1] = (v[j1] as number) - (u2 - u1);
112
+ else if (i0 >= 0) {
113
+ j1 = j2;
114
+ i0 = column2row[j1] as number;
115
+ }
116
+
117
+ if (i0 >= 0) {
118
+ if (u1 < u2) freeRow[--k] = i0;
119
+ else freeRow[freeCount++] = i0;
120
+ }
121
+ row2column[i] = j1;
122
+ column2row[j1] = i;
123
+ }
124
+ }
125
+
126
+ // augmentation
127
+ const savedFreeCount = freeCount;
128
+ const d = new Int32Array(columnCount);
129
+ const pred = new Int32Array(columnCount);
130
+ const col = new Int32Array(columnCount);
131
+ for (freeCount = 0; freeCount < savedFreeCount; freeCount++) {
132
+ const i1 = freeRow[freeCount] as number;
133
+ let low = 0;
134
+ let up = 0;
135
+ let last = 0;
136
+ let min = 0;
137
+ let i = 0;
138
+
139
+ for (let j = 0; j < columnCount; j++) {
140
+ d[j] = COST(j, i1) - (v[j] as number);
141
+ pred[j] = i1;
142
+ col[j] = j;
143
+ }
144
+
145
+ let j = -1;
146
+ update: do {
147
+ last = low;
148
+ min = d[col[up++] as number] as number;
149
+ for (let k = up; k < columnCount; k++) {
150
+ j = col[k] as number;
151
+ const c = d[j] as number;
152
+ if (c <= min) {
153
+ if (c < min) {
154
+ up = low;
155
+ min = c;
156
+ }
157
+ col[k] = col[up] as number;
158
+ col[up++] = j;
159
+ }
160
+ }
161
+ // (git leaves j at the last column scanned when it finds a free one here)
162
+ for (let k = low; k < up; k++) if (column2row[col[k] as number] === -1) break update;
163
+
164
+ // scan a row
165
+ do {
166
+ const j1 = col[low++] as number;
167
+ i = column2row[j1] as number;
168
+ const u1 = COST(j1, i) - (v[j1] as number) - min;
169
+ for (let k = up; k < columnCount; k++) {
170
+ j = col[k] as number;
171
+ const c = COST(j, i) - (v[j] as number) - u1;
172
+ if (c < (d[j] as number)) {
173
+ d[j] = c;
174
+ pred[j] = i;
175
+ if (c === min) {
176
+ if (column2row[j] === -1) break update;
177
+ col[k] = col[up] as number;
178
+ col[up++] = j;
179
+ }
180
+ }
181
+ }
182
+ } while (low !== up);
183
+ } while (low === up);
184
+
185
+ // updating of the column pieces
186
+ for (let k = 0; k < last; k++) {
187
+ const j1 = col[k] as number;
188
+ v[j1] = (v[j1] as number) + (d[j1] as number) - min;
189
+ }
190
+
191
+ // augmentation
192
+ do {
193
+ if (j < 0) throw new Error(`BUG: negative j: ${j}`);
194
+ i = pred[j] as number;
195
+ column2row[j] = i;
196
+ const swap = row2column[i] as number;
197
+ row2column[i] = j;
198
+ j = swap;
199
+ } while (i1 !== i);
200
+ }
201
+
202
+ return { columnToRow: column2row, rowToColumn: row2column };
203
+ }