@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
@@ -3,37 +3,64 @@ import { parseGitBool } from "@statewalker/vcs-utils";
3
3
  import { type Checkout, isIndexUnborn } from "@statewalker/vcs-working-tree";
4
4
 
5
5
  import { GitApiError, NoHeadError } from "../errors/index.js";
6
+ import { GuardedTransportCommand } from "../guarded-transport-command.js";
6
7
  import { RemoteConfigStore } from "../remote-config/index.js";
7
- import { FastForwardMode, isMergeSuccessful, type MergeStrategy } from "../results/merge-result.js";
8
+ import type { FetchResult } from "../results/fetch-result.js";
9
+ import {
10
+ FastForwardMode,
11
+ isMergeSuccessful,
12
+ type MergeResult,
13
+ type MergeStrategy,
14
+ } from "../results/merge-result.js";
8
15
  import type { PullResult } from "../results/pull-result.js";
9
16
  import { isRebaseSuccessful, RebaseStatus } from "../results/rebase-result.js";
10
- import { TransportCommand } from "../transport-command.js";
17
+ import type { CommitEditor } from "./commit-command.js";
11
18
  import { FetchCommand, TagOption } from "./fetch-command.js";
19
+ import { FetchMultipleCommand } from "./fetch-multiple-command.js";
12
20
  import { commitsBaseSource, MergeBaseGraph } from "./merge-bases.js";
13
21
  import { MergeCommand } from "./merge-command.js";
14
22
  import { configValue } from "./merge-config.js";
23
+ import { OperationState, readIndex } from "./merge-support.js";
24
+ import { type CleanupMode, parseCleanupMode } from "./message-cleanup.js";
15
25
  import { RebaseCommand } from "./rebase-command.js";
26
+ import { SubmoduleCommandError, type SubmoduleCommandResult } from "./submodule-commands.js";
27
+ import { type FetchRecurseSubmodules, submoduleTouchesInRange } from "./submodule-fetch.js";
28
+ import { SubmoduleUpdateCommand } from "./submodule-update-command.js";
29
+
30
+ /** One `FETCH_HEAD` entry to merge (pull.c's get_merge_heads). */
31
+ interface MergeHead {
32
+ objectId: ObjectId;
33
+ description: string;
34
+ }
16
35
 
17
36
  /**
18
37
  * Pull changes from a remote repository.
19
38
  *
20
- * Equivalent to `git pull` (fetch + merge).
39
+ * Equivalent to `git pull`: git's fetch (`git fetch [<remote> [<refspec>...]]`, the
40
+ * configured refspecs when none is given), then the `FETCH_HEAD` entries marked for merge
41
+ * merged into the current branch (`git merge FETCH_HEAD`), rebased onto (`--rebase`,
42
+ * `pull.rebase`), or branched off on an unborn branch (pull.c's `pull_into_void`). The
43
+ * options pull passes to git's merge, rebase and fetch are passed on the same way.
21
44
  *
22
- * Based on JGit's PullCommand.
45
+ * Credentials and headers follow `GuardedTransportCommand`'s rule: {@link setCredentials} and
46
+ * {@link setHeaders} go only to the origins named with `addCredentialOrigin`, else to the
47
+ * default remote's origin (`branch.<name>.remote`, a name or a URL) while every remote the
48
+ * pull reaches has it, or to the URL given to {@link setRemote} when it names no configured
49
+ * remote; per-URL providers
50
+ * (`setCredentialsForUrl`, `setHeadersForUrl`) answer for their URL's origin; a redirect to
51
+ * another origin carries none. `--all` runs `FetchMultipleCommand` (git's fetch_multiple).
23
52
  *
24
53
  * @example
25
54
  * ```typescript
26
- * // Pull from default remote/branch
55
+ * // Pull the current branch's upstream (branch.<name>.remote / .merge)
27
56
  * const result = await git.pull().call();
28
57
  *
29
- * // Pull from specific remote
58
+ * // git pull --no-rebase --squash upstream main
30
59
  * const result = await git.pull()
31
60
  * .setRemote("upstream")
32
- * .call();
33
- *
34
- * // Pull specific branch
35
- * const result = await git.pull()
36
- * .setRemoteBranchName("develop")
61
+ * .setRemoteBranchName("main")
62
+ * .setRebase(false)
63
+ * .setSquash(true)
37
64
  * .call();
38
65
  *
39
66
  * // Pull with rebase (`git pull --rebase`; without the option, pull.rebase decides)
@@ -42,15 +69,44 @@ import { RebaseCommand } from "./rebase-command.js";
42
69
  * .call();
43
70
  * ```
44
71
  */
45
- export class PullCommand extends TransportCommand<PullResult> {
72
+ export class PullCommand extends GuardedTransportCommand<PullResult> {
46
73
  private remote = "origin";
47
74
  /** Whether the remote was named (it is then in the reflog action). */
48
75
  private remoteGiven = false;
49
- private remoteBranchName?: string;
76
+ /** The refspecs after the remote (`git pull <remote> <refspec>...`) */
77
+ private refSpecs: string[] = [];
50
78
  /** `--rebase` / `--no-rebase`; undefined: branch.<name>.rebase, then pull.rebase */
51
79
  private rebase?: boolean;
52
80
  /** `--verify-signatures` / `--no-verify-signatures`, passed to the merge */
53
81
  private verifySignatures?: boolean;
82
+ /** `--autostash` / `--no-autostash`; undefined: pull.autoStash, then rebase.autoStash */
83
+ private autoStash?: boolean;
84
+ private strategy?: MergeStrategy;
85
+ private strategyOptions: string[] = [];
86
+ private fastForwardMode?: FastForwardMode;
87
+ private tagOption?: TagOption;
88
+ private repositoryFiles?: { files: FilesApi; gitDir?: string };
89
+ // options passed to git-merge
90
+ private squash?: boolean;
91
+ private commit?: boolean;
92
+ private edit?: boolean;
93
+ private editor?: CommitEditor;
94
+ private log?: boolean | number;
95
+ private signoff?: boolean;
96
+ private cleanupMode?: CleanupMode;
97
+ private cleanupArg?: string;
98
+ private noVerify?: boolean;
99
+ private allowUnrelatedHistories = false;
100
+ // options passed to git-fetch
101
+ private all = false;
102
+ private prune?: boolean;
103
+ private depth?: number;
104
+ private deepen?: number;
105
+ private unshallow = false;
106
+ private force = false;
107
+ private compatibility?: "2.43" | "2.56";
108
+ private dryRun = false;
109
+ private recurseSubmodules?: FetchRecurseSubmodules;
54
110
 
55
111
  /**
56
112
  * `--verify-signatures` (true) / `--no-verify-signatures` (false), passed to the merge as
@@ -64,12 +120,6 @@ export class PullCommand extends TransportCommand<PullResult> {
64
120
  this.verifySignatures = verify;
65
121
  return this;
66
122
  }
67
- /** `--autostash` / `--no-autostash`; undefined: pull.autoStash, then rebase.autoStash */
68
- private autoStash?: boolean;
69
- private strategy?: MergeStrategy;
70
- private fastForwardMode?: FastForwardMode;
71
- private tagOption?: TagOption;
72
- private repositoryFiles?: { files: FilesApi; gitDir?: string };
73
123
 
74
124
  /**
75
125
  * The files of the repository, for the fetch to write the commit-graph
@@ -82,9 +132,8 @@ export class PullCommand extends TransportCommand<PullResult> {
82
132
  }
83
133
 
84
134
  /**
85
- * Set the remote to pull from.
86
- *
87
- * Default is "origin".
135
+ * Set the remote to pull from: a configured remote's name, a path or a URL (git's
136
+ * `<repository>`). Default: the current branch's `branch.<name>.remote`, else `origin`.
88
137
  *
89
138
  * @param remote Remote name
90
139
  */
@@ -103,28 +152,41 @@ export class PullCommand extends TransportCommand<PullResult> {
103
152
  }
104
153
 
105
154
  /**
106
- * Set the remote branch to pull.
155
+ * Set the remote branch to pull (one refspec, `git pull <remote> <branch>`).
107
156
  *
108
- * If not set, uses the tracking branch for the current local branch.
157
+ * If not set, the remote's configured refspecs are fetched and the current branch's
158
+ * `branch.<name>.merge` is merged.
109
159
  *
110
160
  * @param branch Remote branch name
111
161
  */
112
162
  setRemoteBranchName(branch: string): this {
113
163
  this.checkCallable();
114
- this.remoteBranchName = branch;
164
+ this.refSpecs = [branch];
115
165
  return this;
116
166
  }
117
167
 
118
168
  /**
119
- * Get the remote branch name.
169
+ * Get the remote branch name (the first refspec).
120
170
  */
121
171
  getRemoteBranchName(): string | undefined {
122
- return this.remoteBranchName;
172
+ return this.refSpecs[0];
173
+ }
174
+
175
+ /**
176
+ * The refspecs to fetch (`git pull <remote> <refspec>...`): what they fetch is merged, two
177
+ * or more heads as an octopus.
178
+ */
179
+ setRefSpecs(...refSpecs: string[]): this {
180
+ this.checkCallable();
181
+ this.refSpecs = [...refSpecs];
182
+ return this;
123
183
  }
124
184
 
125
185
  /**
126
186
  * Set whether to use rebase instead of merge (`--rebase` / `--no-rebase`). Without it the
127
- * configuration decides, as in git: `branch.<name>.rebase`, else `pull.rebase`, else merge.
187
+ * configuration decides, as in git: `branch.<name>.rebase`, else `pull.rebase`, else merge
188
+ * (a pull that cannot fast-forward then refuses unless `pull.ff` or a fast-forward mode
189
+ * is given: git's "Need to specify how to reconcile divergent branches.").
128
190
  * Only this option puts `--rebase` in the reflog lines (git's are the command line's).
129
191
  *
130
192
  * @param rebase Whether to use rebase
@@ -155,7 +217,7 @@ export class PullCommand extends TransportCommand<PullResult> {
155
217
  }
156
218
 
157
219
  /**
158
- * Set the merge strategy.
220
+ * Set the merge strategy (`-s <strategy>`, passed to the merge or the rebase).
159
221
  *
160
222
  * @param strategy Merge strategy
161
223
  */
@@ -166,7 +228,19 @@ export class PullCommand extends TransportCommand<PullResult> {
166
228
  }
167
229
 
168
230
  /**
169
- * Set the fast-forward mode.
231
+ * `-X <option>` for each option (passed to the merge or the rebase, see
232
+ * `MergeCommand.setStrategyOptions`).
233
+ */
234
+ setStrategyOptions(options: readonly string[]): this {
235
+ this.checkCallable();
236
+ this.strategyOptions = [...options];
237
+ return this;
238
+ }
239
+
240
+ /**
241
+ * Set the fast-forward mode (`--ff`, `--no-ff`, `--ff-only`; default `pull.ff`). With
242
+ * `--ff-only` a pull whose branches diverged dies before merging or rebasing (git's
243
+ * `die_ff_impossible`), and one that can fast-forward merges even when a rebase is asked.
170
244
  *
171
245
  * @param mode Fast-forward mode
172
246
  */
@@ -184,7 +258,7 @@ export class PullCommand extends TransportCommand<PullResult> {
184
258
  }
185
259
 
186
260
  /**
187
- * Set the specification of annotated tag behavior during fetch.
261
+ * Set the specification of annotated tag behavior during fetch (`--tags`, `--no-tags`).
188
262
  *
189
263
  * @param tagOption Tag option
190
264
  */
@@ -201,12 +275,169 @@ export class PullCommand extends TransportCommand<PullResult> {
201
275
  return this.tagOption;
202
276
  }
203
277
 
278
+ /** `--squash` / `--no-squash`, passed to the merge (see `MergeCommand.setSquash`). */
279
+ setSquash(squash: boolean): this {
280
+ this.checkCallable();
281
+ this.squash = squash;
282
+ return this;
283
+ }
284
+
285
+ /** `--commit` / `--no-commit`, passed to the merge (see `MergeCommand.setCommit`). */
286
+ setCommit(commit: boolean): this {
287
+ this.checkCallable();
288
+ this.commit = commit;
289
+ return this;
290
+ }
291
+
292
+ /**
293
+ * `--edit` / `--no-edit`, passed to the merge: with `--edit` the merge commit's message
294
+ * goes through the editor ({@link setEditor}; see `MergeCommand.setEdit`). Without either
295
+ * the merge does not edit (git's default without a terminal).
296
+ */
297
+ setEdit(edit: boolean): this {
298
+ this.checkCallable();
299
+ this.edit = edit;
300
+ return this;
301
+ }
302
+
303
+ /** The editor `--edit` runs over MERGE_MSG (git's `GIT_EDITOR`; see `CommitCommand.setEditor`). */
304
+ setEditor(editor: CommitEditor): this {
305
+ this.checkCallable();
306
+ this.editor = editor;
307
+ return this;
308
+ }
309
+
310
+ /**
311
+ * `--log[=<n>]` / `--no-log`, passed to the merge (see `MergeCommand.setLog`): true is
312
+ * `--log`, a number `--log=<n>`, false `--no-log`.
313
+ */
314
+ setLog(log: boolean | number): this {
315
+ this.checkCallable();
316
+ this.log = log;
317
+ return this;
318
+ }
319
+
320
+ /**
321
+ * `--signoff` / `--no-signoff`, passed to the merge, or to the rebase of a rebasing pull.
322
+ */
323
+ setSignoff(signoff: boolean): this {
324
+ this.checkCallable();
325
+ this.signoff = signoff;
326
+ return this;
327
+ }
328
+
329
+ /**
330
+ * `--cleanup=<mode>`, passed to the merge. A mode git does not know dies before the fetch
331
+ * (`Invalid cleanup mode <mode>`).
332
+ */
333
+ setCleanupMode(mode: CleanupMode | string): this {
334
+ this.checkCallable();
335
+ this.cleanupArg = mode;
336
+ return this;
337
+ }
338
+
339
+ /** `--no-verify` (true) / `--verify` (false), passed to the merge. */
340
+ setNoVerify(noVerify: boolean): this {
341
+ this.checkCallable();
342
+ this.noVerify = noVerify;
343
+ return this;
344
+ }
345
+
346
+ /** `--allow-unrelated-histories`, passed to the merge. */
347
+ setAllowUnrelatedHistories(allow: boolean): this {
348
+ this.checkCallable();
349
+ this.allowUnrelatedHistories = allow;
350
+ return this;
351
+ }
352
+
353
+ /**
354
+ * `--all`: fetch every remote (but those with `remote.<name>.skipDefaultUpdate`), each
355
+ * appending to FETCH_HEAD as git's `fetch --all` does, then merge what the current
356
+ * branch's upstream marked for merge. Takes no remote or refspec.
357
+ */
358
+ setAll(all: boolean): this {
359
+ this.checkCallable();
360
+ this.all = all;
361
+ return this;
362
+ }
363
+
364
+ /** `--prune` / `--no-prune`, passed to the fetch (`FetchCommand.setRemoveDeletedRefs`). */
365
+ setPrune(prune: boolean): this {
366
+ this.checkCallable();
367
+ this.prune = prune;
368
+ return this;
369
+ }
370
+
371
+ /** `--depth=<n>`, passed to the fetch. */
372
+ setDepth(depth: number): this {
373
+ this.checkCallable();
374
+ this.depth = depth;
375
+ return this;
376
+ }
377
+
378
+ /** `--deepen=<n>`, passed to the fetch (`FetchCommand.setDeepen`). */
379
+ setDeepen(deepen: number): this {
380
+ this.checkCallable();
381
+ this.deepen = deepen;
382
+ return this;
383
+ }
384
+
385
+ /** `--unshallow`, passed to the fetch. */
386
+ setUnshallow(unshallow: boolean): this {
387
+ this.checkCallable();
388
+ this.unshallow = unshallow;
389
+ return this;
390
+ }
391
+
392
+ /**
393
+ * The git version whose advice text the refusals follow (2.43: `hint: ` before an empty
394
+ * line, `git config advice.<name> false`); default the hooks' compatibility.
395
+ */
396
+ setCompatibility(version: "2.43" | "2.56"): this {
397
+ this.checkCallable();
398
+ this.compatibility = version;
399
+ return this;
400
+ }
401
+
402
+ /** `--force`, passed to the fetch (`FetchCommand.setForceUpdate`). */
403
+ setForce(force: boolean): this {
404
+ this.checkCallable();
405
+ this.force = force;
406
+ return this;
407
+ }
408
+
409
+ /**
410
+ * `--dry-run`: the fetch only shows what it would do (`FetchCommand.setDryRun`), and
411
+ * nothing is merged or rebased.
412
+ */
413
+ setDryRun(dryRun: boolean): this {
414
+ this.checkCallable();
415
+ this.dryRun = dryRun;
416
+ return this;
417
+ }
418
+
419
+ /**
420
+ * `--recurse-submodules[=yes|on-demand|no]` / `--no-recurse-submodules` (true is `yes`,
421
+ * false `no`): passed to the fetch (`FetchCommand.setRecurseSubmodules`), and, unless
422
+ * `no`, once the merge or rebase succeeded the submodules are updated as `git submodule
423
+ * update --recursive --checkout` (`--rebase` for a rebasing pull) does, its output in
424
+ * {@link PullResult.submodules}. Unset, `submodule.recurse` decides (the fetch reads its
425
+ * own configuration). A rebasing pull that would recurse refuses local commits that
426
+ * record submodule changes (`cannot rebase with locally recorded submodule modifications`).
427
+ */
428
+ setRecurseSubmodules(recurse: boolean | FetchRecurseSubmodules): this {
429
+ this.checkCallable();
430
+ this.recurseSubmodules = recurse === true ? "yes" : recurse === false ? "no" : recurse;
431
+ return this;
432
+ }
433
+
204
434
  /**
205
435
  * Execute the pull operation.
206
436
  *
207
437
  * @returns Pull result with fetch and merge results
208
- * @throws NoHeadError if HEAD is not set
209
- * @throws InvalidRemoteError if remote cannot be resolved
438
+ * @throws NoHeadError if HEAD is detached and no refspec is given
439
+ * @throws GitApiError with git's stderr where git's pull dies (exit 128, or 1 when nothing
440
+ * fetched is to be merged)
210
441
  */
211
442
  async call(): Promise<PullResult> {
212
443
  this.checkCallable();
@@ -218,53 +449,74 @@ export class PullCommand extends TransportCommand<PullResult> {
218
449
 
219
450
  // Get current branch
220
451
  const currentBranch = await this.getCurrentBranch();
221
- if (!currentBranch) {
452
+ if (!currentBranch && this.refSpecs.length === 0) {
222
453
  throw new NoHeadError("Cannot pull with detached HEAD");
223
454
  }
455
+ const localBranchName = currentBranch?.replace(/^refs\/heads\//, "");
224
456
 
225
- // Extract branch name from full ref
226
- const localBranchName = currentBranch.replace("refs/heads/", "");
227
-
228
- // Determine remote branch
229
- const remoteBranch = this.remoteBranchName || localBranchName;
230
-
231
- // a remote read from .git/remotes/ or .git/branches/ (git 2.x) is pulled as pull.c does:
232
- // `git fetch <remote> [<branch>]` with the remote's own refspecs, then the FETCH_HEAD
233
- // entries marked for merge
234
- await this.loadLegacyRemote(this.remote);
235
457
  const store = RemoteConfigStore.from(this._workingCopy);
236
- const legacy = store.legacyOrigin(this.remote) !== undefined;
237
- const trackingRef = `refs/remotes/${this.remote}/${remoteBranch}`;
238
-
239
- // Build refspec
240
- const refspecs = legacy
241
- ? this.remoteBranchName
242
- ? [this.remoteBranchName]
243
- : []
244
- : [`refs/heads/${remoteBranch}:${trackingRef}`];
458
+ if (!this.remoteGiven && localBranchName !== undefined) {
459
+ // git fetch without a repository: the branch's remote, else origin
460
+ this.remote = store.remoteForBranch(localBranchName);
461
+ }
462
+ if (this.all && (this.remoteGiven || this.refSpecs.length > 0)) {
463
+ throw new GitApiError("fatal: fetch --all does not take a repository argument", {
464
+ exitCode: 128,
465
+ });
466
+ }
467
+ // get_cleanup_mode: an unknown mode dies before anything is fetched
468
+ if (this.cleanupArg !== undefined) {
469
+ let mode: CleanupMode;
470
+ try {
471
+ mode = parseCleanupMode(this.cleanupArg);
472
+ } catch {
473
+ throw new GitApiError(`fatal: Invalid cleanup mode ${this.cleanupArg}`, { exitCode: 128 });
474
+ }
475
+ this.cleanupMode = mode;
476
+ }
245
477
 
246
478
  // git's GIT_REFLOG_ACTION for everything the pull writes: "pull" and its command-line
247
479
  // arguments (a rebase or autostash the configuration asks for is not among them)
248
- const action = this.reflogAction(
249
- [
250
- "pull",
251
- ...(this.rebase === true ? ["--rebase"] : this.rebase === false ? ["--no-rebase"] : []),
252
- ...(this.autoStash === true
253
- ? ["--autostash"]
254
- : this.autoStash === false
255
- ? ["--no-autostash"]
256
- : []),
257
- ...(this.fastForwardMode ? [`--${this.fastForwardMode}`] : []),
258
- ...(this.strategy ? [`--strategy=${this.strategy}`] : []),
259
- ...(this.tagOption === TagOption.FETCH_TAGS ? ["--tags"] : []),
260
- ...(this.tagOption === TagOption.NO_TAGS ? ["--no-tags"] : []),
261
- ...(this.remoteGiven || this.remoteBranchName ? [this.remote] : []),
262
- ...(this.remoteBranchName ? [this.remoteBranchName] : []),
263
- ].join(" "),
264
- );
480
+ const action = this.reflogAction(this.commandLine().join(" "));
265
481
 
482
+ // pull.ff, unless a fast-forward mode is given; an explicit --rebase / --no-rebase turns
483
+ // pull.ff=only into --ff
484
+ let ff = this.fastForwardMode;
485
+ if (ff === undefined) {
486
+ ff = this.configFastForward();
487
+ if (this.rebase !== undefined && ff === FastForwardMode.FF_ONLY) ff = FastForwardMode.FF;
488
+ }
266
489
  // git's pull.c: the option, else the configuration
267
- const rebase = this.rebase ?? this.configRebase(localBranchName);
490
+ const configured =
491
+ localBranchName !== undefined ? this.configRebase(localBranchName) : undefined;
492
+ let rebase = this.rebase ?? configured ?? false;
493
+ const rebaseUnspecified = this.rebase === undefined && configured === undefined;
494
+
495
+ // an index with unmerged entries, or a merge in progress, dies before the fetch
496
+ const { unmerged } = await readIndex(this.staging);
497
+ if (unmerged.length > 0) {
498
+ throw new GitApiError(
499
+ [
500
+ "error: Pulling is not possible because you have unmerged files.",
501
+ "hint: Fix them up in the work tree, and then use 'git add/rm <file>'",
502
+ "hint: as appropriate to mark resolution and make a commit.",
503
+ "fatal: Exiting because of an unresolved conflict.",
504
+ ].join("\n"),
505
+ { exitCode: 128 },
506
+ );
507
+ }
508
+ const checkout = (this._workingCopy as { checkout?: Checkout }).checkout;
509
+ if (await this.mergeInProgress()) {
510
+ throw new GitApiError(
511
+ [
512
+ "error: You have not concluded your merge (MERGE_HEAD exists).",
513
+ "hint: Please, commit your changes before merging.",
514
+ "fatal: Exiting because of unfinished merge.",
515
+ ].join("\n"),
516
+ { exitCode: 128 },
517
+ );
518
+ }
519
+
268
520
  const pullAutoStash = this.autoStash ?? parseGitBool(this.config("pull.autoStash"));
269
521
  const autoStash = rebase
270
522
  ? (pullAutoStash ?? parseGitBool(this.config("rebase.autoStash")) ?? false)
@@ -298,175 +550,361 @@ export class PullCommand extends TransportCommand<PullResult> {
298
550
  }
299
551
  }
300
552
 
301
- // Execute fetch
302
- const fetchCommand = new FetchCommand(this._workingCopy);
303
- fetchCommand.setTransports(this.getTransports());
304
- fetchCommand.setRemote(this.remote);
305
- fetchCommand.setRefSpecs(...refspecs);
306
- // git pull fetches with --update-head-ok
307
- fetchCommand.setUpdateHeadOk(true);
308
- fetchCommand.setReflogAction(action);
309
-
310
- if (this.credentials) {
311
- fetchCommand.setCredentials(this.credentials);
312
- }
313
- if (this.headers) {
314
- fetchCommand.setHeaders(this.headers);
315
- }
316
- if (this.timeout) {
317
- fetchCommand.setTimeout(this.timeout);
318
- }
319
- if (this.progressCallback) {
320
- fetchCommand.setProgressMonitor(this.progressCallback);
321
- }
322
- if (this.progressMessageCallback) {
323
- fetchCommand.setProgressMessageCallback(this.progressMessageCallback);
324
- }
325
- if (this.tagOption) {
326
- fetchCommand.setTagOpt(this.tagOption);
327
- }
328
- if (this.repositoryFiles) {
329
- fetchCommand.setRepositoryFiles(this.repositoryFiles);
330
- }
331
-
332
- const fetchResult = await fetchCommand.call();
333
-
334
- let warnings: string[] = [];
335
- let mergeTarget: { objectId: ObjectId; description?: string } | undefined;
336
- if (legacy) {
337
- if (fetchResult.isEmpty) {
338
- return { fetchResult, successful: true, rebaseUsed: false, fetchedFrom: this.remote };
553
+ // a remote read from .git/remotes/ or .git/branches/ (git 2.x) is fetched with its own
554
+ // refspecs, as any other: `git fetch <remote> [<refspec>...]`
555
+ const fetchResults: FetchResult[] = [];
556
+ // remote_get(NULL): the branch's remote (a name, or a URL or path git allows there too)
557
+ const defaultRemoteUrl = store.remoteUrlOf(store.remoteForBranch(localBranchName));
558
+ if (this.all) {
559
+ // fetch --all: builtin/fetch.c's fetch_multiple (every remote fetched, a failure
560
+ // reported once all ran, skipDefaultUpdate / skipFetchAll honoured)
561
+ const multiple = new FetchMultipleCommand(this._workingCopy)
562
+ .setAll(true)
563
+ .setUpdateHeadOk(true)
564
+ .setEnvReflogAction(action);
565
+ if (this.prune !== undefined) multiple.setPrune(this.prune);
566
+ if (this.tagOption !== undefined) multiple.setTagOpt(this.tagOption);
567
+ if (this.dryRun) multiple.setDryRun(true);
568
+ if (this.force) multiple.setForceUpdate(true);
569
+ if (this.recurseSubmodules !== undefined)
570
+ multiple.setRecurseSubmodules(this.recurseSubmodules);
571
+ // credentials and headers: decided from every URL the fetch reaches, handed down
572
+ this.resolveAuth(await multiple.plannedUrls(), defaultRemoteUrl);
573
+ this.configureChild(multiple);
574
+ const fetched = await multiple.call();
575
+ for (const entry of fetched.fetches) if (entry.result) fetchResults.push(entry.result);
576
+ if (fetched.exitCode !== 0) {
577
+ // run_fetch failed: pull returns its status before merging anything
578
+ throw new GitApiError(fetched.stderr.replace(/\n$/, ""), { exitCode: fetched.exitCode });
339
579
  }
340
- warnings = await this.fastForwardMovedHead(origHead);
341
- mergeTarget = await this.mergeHeadFromFetchHead(localBranchName);
580
+ if (fetched.remotes.length === 1) this.remote = fetched.remotes[0] as string;
342
581
  } else {
343
- // If repository is empty or nothing fetched, we're done
344
- if (fetchResult.isEmpty || fetchResult.trackingRefUpdates.length === 0) {
345
- return {
346
- fetchResult,
347
- successful: true,
348
- rebaseUsed: false,
349
- fetchedFrom: this.remote,
350
- };
351
- }
352
- // Get the remote tracking ref to merge
353
- const resolved = await this.refsStore.resolve(trackingRef);
354
- if (resolved?.objectId) mergeTarget = { objectId: resolved.objectId };
582
+ await this.loadLegacyRemote(this.remote);
583
+ // a URL the caller names (no configured remote) is the one this fetch is for: its
584
+ // origin is trusted, as FetchCommand trusts the URL it is given
585
+ const url = store.remoteUrlOf(this.remote);
586
+ const named = this.remoteGiven && !store.isConfigured(this.remote);
587
+ this.resolveAuth([url], named ? url : defaultRemoteUrl);
588
+ fetchResults.push(await this.fetchCommand(this.remote, this.refSpecs, action).call());
355
589
  }
590
+ const fetchResult = fetchResults[fetchResults.length - 1];
591
+ const fetched = {
592
+ fetchResult,
593
+ ...(fetchResults.length > 1 ? { fetchResults } : {}),
594
+ fetchedFrom: this.remote,
595
+ };
356
596
 
357
- if (!mergeTarget) {
358
- // Nothing to merge
359
- return {
360
- fetchResult,
361
- successful: true,
362
- rebaseUsed: false,
363
- fetchedFrom: this.remote,
364
- };
365
- }
366
- const trackingRefResolved = mergeTarget;
367
- // pull.c's warning() when the fetch moved the checked-out branch
368
- const shown = warnings.length > 0 ? { warnings } : {};
597
+ // --dry-run: nothing more once fetched
598
+ if (this.dryRun) return { ...fetched, successful: true, rebaseUsed: false };
599
+
600
+ let warnings = await this.fastForwardMovedHead(origHead);
601
+ const shown = () => (warnings.length > 0 ? { warnings } : {});
602
+
603
+ const { heads, text: fetchHead } = await this.mergeHeadsFromFetchHead(checkout);
604
+ if (heads.length === 0) this.dieNoMergeCandidates(localBranchName, rebase);
605
+ const mergeIds = heads.map((h) => h.objectId);
369
606
 
370
607
  // pull_into_void: an unborn branch (rebasing or not) branches off what was fetched, a
371
608
  // two-way switch from the empty tree keeping the staged changes it does not overwrite
372
- const headNow = (await this.refsStore.resolve("HEAD").catch(() => undefined))?.objectId;
373
- if (origHead === undefined && headNow === undefined) {
609
+ if (origHead === undefined) {
610
+ if (heads.length > 1) {
611
+ throw new GitApiError("fatal: Cannot merge multiple branches into empty head.", {
612
+ exitCode: 128,
613
+ });
614
+ }
374
615
  const mergeResult = await new MergeCommand(this._workingCopy)
375
616
  .shareHooksOf(this)
376
617
  .setVerifySignatures(this.verifySignatures)
377
- .callIntoVoid(trackingRefResolved.objectId);
618
+ .callIntoVoid(mergeIds[0] as ObjectId);
378
619
  return {
379
- fetchResult,
620
+ ...fetched,
380
621
  mergeResult,
381
622
  successful: isMergeSuccessful(mergeResult.status),
382
623
  rebaseUsed: false,
383
- fetchedFrom: this.remote,
384
- ...shown,
624
+ ...shown(),
385
625
  };
386
626
  }
627
+ if (heads.length > 1) {
628
+ if (rebase) {
629
+ throw new GitApiError("fatal: Cannot rebase onto multiple branches.", { exitCode: 128 });
630
+ }
631
+ if (ff === FastForwardMode.FF_ONLY) {
632
+ throw new GitApiError("fatal: Cannot fast-forward to multiple branches.", {
633
+ exitCode: 128,
634
+ });
635
+ }
636
+ }
387
637
 
388
- // `git pull --rebase`: the branch rebased onto what was fetched
389
- // (one that only fast-forwards is a `merge --ff-only --autostash`, as git's pull runs it)
390
- const headId = (await this.refsStore.resolve("HEAD"))?.objectId;
391
638
  const canFastForward =
639
+ heads.length === 1 && (await this.isAncestor(origHead, mergeIds[0] as ObjectId));
640
+ let upToDate = true;
641
+ if (!canFastForward) {
642
+ for (const id of mergeIds) {
643
+ if (!(await this.isAncestor(id, origHead))) {
644
+ upToDate = false;
645
+ break;
646
+ }
647
+ }
648
+ }
649
+ const divergent = !canFastForward && !upToDate;
650
+ // ff-only takes precedence over rebase
651
+ if (ff === FastForwardMode.FF_ONLY) {
652
+ if (divergent) {
653
+ throw new GitApiError(
654
+ this.advice(
655
+ [
656
+ "Diverging branches can't be fast-forwarded, you need to either:",
657
+ "",
658
+ "\tgit merge --no-ff",
659
+ "",
660
+ "or:",
661
+ "",
662
+ "\tgit rebase",
663
+ ],
664
+ "diverging",
665
+ "Not possible to fast-forward, aborting.",
666
+ ),
667
+ { exitCode: 128 },
668
+ );
669
+ }
670
+ rebase = false;
671
+ }
672
+ // no way to reconcile divergent branches given: git's advice, then it dies
673
+ if (ff === undefined && rebaseUnspecified && divergent) {
674
+ throw new GitApiError(
675
+ this.advice(
676
+ [
677
+ "You have divergent branches and need to specify how to reconcile them.",
678
+ "You can do so by running one of the following commands sometime before",
679
+ "your next pull:",
680
+ "",
681
+ " git config pull.rebase false # merge",
682
+ " git config pull.rebase true # rebase",
683
+ " git config pull.ff only # fast-forward only",
684
+ "",
685
+ 'You can replace "git config" with "git config --global" to set a default',
686
+ "preference for all repositories. You can also pass --rebase, --no-rebase,",
687
+ "or --ff-only on the command line to override the configured default per",
688
+ "invocation.",
689
+ ],
690
+ undefined,
691
+ "Need to specify how to reconcile divergent branches.",
692
+ ),
693
+ { exitCode: 128 },
694
+ );
695
+ }
696
+
697
+ // pull.c: recurse_submodules from the command line, else submodule.recurse
698
+ const recurse = this.recurseSubmodules ?? this.configRecurseSubmodules();
699
+ const updatesSubmodules = recurse === "yes" || recurse === "on-demand";
700
+ if (
392
701
  rebase &&
393
- headId !== undefined &&
394
- (await this.canFastForward(headId, trackingRefResolved.objectId));
702
+ updatesSubmodules &&
703
+ (await submoduleTouchesInRange(this._workingCopy, mergeIds[0] as ObjectId, origHead)) > 0
704
+ ) {
705
+ throw new GitApiError("fatal: cannot rebase with locally recorded submodule modifications", {
706
+ exitCode: 128,
707
+ });
708
+ }
709
+ // rebase_submodules / update_submodules once the merge or rebase succeeded
710
+ const withSubmodules = async (result: PullResult): Promise<PullResult> => {
711
+ if (!updatesSubmodules || !result.successful) return result;
712
+ const submodules = await this.updateSubmodules(rebase ? "rebase" : "checkout");
713
+ return { ...result, submodules, successful: submodules.exitCode === 0 };
714
+ };
715
+
716
+ // `git pull --rebase`: the branch rebased onto what was fetched
717
+ // (one that only fast-forwards is a `merge --ff-only`, as git's pull runs it)
395
718
  if (rebase && !canFastForward) {
396
719
  // run_rebase
397
720
  if (this.verifySignatures === true) {
398
721
  warnings = [...warnings, "warning: ignoring --verify-signatures for rebase"];
399
722
  }
400
- const rebaseResult = await new RebaseCommand(this._workingCopy)
723
+ const rebaseCommand = new RebaseCommand(this._workingCopy)
401
724
  .shareHooksOf(this)
402
- .setUpstream(trackingRefResolved.objectId)
725
+ .setUpstream(mergeIds[0] as ObjectId)
403
726
  .setReflogAction(action)
404
- .setAutoStash(autoStash === true)
405
- .call();
406
- return {
407
- fetchResult,
727
+ .setAutoStash(autoStash === true);
728
+ if (this.strategy) rebaseCommand.setStrategy(this.strategy);
729
+ if (this.strategyOptions.length > 0) rebaseCommand.setStrategyOptions(this.strategyOptions);
730
+ if (this.signoff !== undefined) rebaseCommand.setSignoff(this.signoff);
731
+ const rebaseResult = await rebaseCommand.call();
732
+ return withSubmodules({
733
+ ...fetched,
408
734
  rebaseResult,
409
735
  successful: isRebaseSuccessful(rebaseResult.status),
410
736
  rebaseUsed: true,
411
- fetchedFrom: this.remote,
412
- ...(warnings.length > 0 ? { warnings } : {}),
413
- };
737
+ ...shown(),
738
+ });
414
739
  }
415
740
 
416
- // Execute merge (git's message for a pull: `Merge branch 'x' of <url>`)
741
+ // run_merge: `git merge [<options>] FETCH_HEAD`
417
742
  const mergeCommand = new MergeCommand(this._workingCopy).shareHooksOf(this);
418
- mergeCommand.include(trackingRefResolved.objectId);
419
- // git's fmt-merge-msg shortens the URL: no trailing slash, no `.git`
420
- const url = (
421
- configValue(this._workingCopy, `remote.${this.remote}.url`) ??
422
- store.remoteUrls(this.remote)[0] ??
423
- this.remote
424
- )
425
- .replace(/\/+$/, "")
426
- .replace(/\.git$/, "");
427
- // git merges FETCH_HEAD: fmt-merge-msg describes the head from its line
428
- mergeCommand.setMergeNames(
429
- `${trackingRefResolved.objectId}\t\t${mergeTarget.description ?? `branch '${remoteBranch}' of ${url}`}\n`,
430
- );
743
+ for (const id of mergeIds) mergeCommand.include(id);
744
+ // git merges FETCH_HEAD: fmt-merge-msg describes the heads from its lines
745
+ mergeCommand.setMergeNames(fetchHead);
431
746
  mergeCommand.setReflogAction(action);
432
- if (canFastForward) mergeCommand.setFastForwardMode(FastForwardMode.FF_ONLY);
747
+ const mergeFf = rebase ? FastForwardMode.FF_ONLY : ff;
748
+ if (mergeFf !== undefined) mergeCommand.setFastForwardMode(mergeFf);
433
749
  if (this.verifySignatures !== undefined)
434
750
  mergeCommand.setVerifySignatures(this.verifySignatures);
435
751
  // run_merge passes --autostash / --no-autostash only when pull has one to give
436
752
  if (autoStash !== undefined) mergeCommand.setAutoStash(autoStash);
753
+ if (this.strategy) mergeCommand.setStrategy(this.strategy);
754
+ if (this.strategyOptions.length > 0) mergeCommand.setStrategyOptions(this.strategyOptions);
755
+ if (this.squash !== undefined) mergeCommand.setSquash(this.squash);
756
+ if (this.commit !== undefined) mergeCommand.setCommit(this.commit);
757
+ if (this.edit !== undefined) mergeCommand.setEdit(this.edit);
758
+ if (this.editor) mergeCommand.setEditor(this.editor);
759
+ if (this.log !== undefined) mergeCommand.setLog(this.log);
760
+ if (this.signoff !== undefined) mergeCommand.setSignoff(this.signoff);
761
+ if (this.cleanupMode !== undefined) mergeCommand.setCleanupMode(this.cleanupMode);
762
+ if (this.noVerify !== undefined) mergeCommand.setNoVerify(this.noVerify);
763
+ if (this.allowUnrelatedHistories) mergeCommand.setAllowUnrelatedHistories(true);
437
764
 
438
- if (this.strategy) {
439
- mergeCommand.setStrategy(this.strategy);
440
- }
441
- if (this.fastForwardMode && !canFastForward) {
442
- mergeCommand.setFastForwardMode(this.fastForwardMode);
443
- }
444
-
445
- const mergeResult = await mergeCommand.call();
765
+ const mergeResult: MergeResult = await mergeCommand.call();
446
766
  const successful = isMergeSuccessful(mergeResult.status);
447
767
 
448
- if (canFastForward) {
768
+ if (rebase) {
449
769
  // a rebasing pull still reports a rebase: the fast-forward it made instead
450
- return {
451
- fetchResult,
770
+ return withSubmodules({
771
+ ...fetched,
452
772
  mergeResult,
453
773
  rebaseResult: successful
454
774
  ? { status: RebaseStatus.FAST_FORWARD, newHead: mergeResult.newHead }
455
775
  : { status: RebaseStatus.FAILED, message: mergeResult.message },
456
776
  successful,
457
777
  rebaseUsed: true,
458
- fetchedFrom: this.remote,
459
- ...shown,
778
+ ...shown(),
779
+ });
780
+ }
781
+ return withSubmodules({ ...fetched, mergeResult, successful, rebaseUsed: false, ...shown() });
782
+ }
783
+
784
+ /** pull.c's `submodule.recurse`: a boolean (on or off), undefined when unset. */
785
+ private configRecurseSubmodules(): FetchRecurseSubmodules | undefined {
786
+ const values = RemoteConfigStore.from(this._workingCopy).valuesWithOrigin("submodule.recurse");
787
+ if (values.length === 0) return undefined;
788
+ const text = values[values.length - 1]?.text;
789
+ const bool = text === undefined ? true : parseGitBool(text);
790
+ if (bool === undefined) {
791
+ throw new GitApiError(`fatal: bad boolean config value '${text}' for 'submodule.recurse'`, {
792
+ exitCode: 128,
793
+ });
794
+ }
795
+ return bool ? "yes" : "no";
796
+ }
797
+
798
+ /** `git submodule update --recursive --checkout|--rebase`: its output and exit status. */
799
+ private async updateSubmodules(mode: "checkout" | "rebase"): Promise<SubmoduleCommandResult> {
800
+ const update = new SubmoduleUpdateCommand(this._workingCopy)
801
+ .setRecursive(true)
802
+ .setMode(mode)
803
+ .setCompatibility(this.compatibility ?? this.hooks.compatibility);
804
+ update.shareHooksOf(this);
805
+ // the guarded transports: credentials and headers only where this pull's rule allows
806
+ update.setTransports(this.getTransports());
807
+ if (this.timeout !== undefined) update.setTimeout(this.timeout);
808
+ try {
809
+ return await update.call();
810
+ } catch (error) {
811
+ if (!(error instanceof SubmoduleCommandError)) throw error;
812
+ return {
813
+ stdout: error.result.stdout,
814
+ stderr: `${error.result.stderr}${error.message}\n`,
815
+ exitCode: error.exitCode,
460
816
  };
461
817
  }
462
- return {
463
- fetchResult,
464
- mergeResult,
465
- successful,
466
- rebaseUsed: false,
467
- fetchedFrom: this.remote,
468
- ...shown,
469
- };
818
+ }
819
+
820
+ /**
821
+ * git's advise() lines (`hint:`, 2.43's `hint: ` before an empty line), the
822
+ * `advise_if_enabled` hint naming `advice.<name>` when given, then the `fatal:` line.
823
+ */
824
+ private advice(lines: string[], name: string | undefined, fatal: string): string {
825
+ const v243 = (this.compatibility ?? this.hooks.compatibility) === "2.43";
826
+ const out = lines.map((l) => (l === "" ? (v243 ? "hint: " : "hint:") : `hint: ${l}`));
827
+ if (name !== undefined) {
828
+ out.push(
829
+ v243 ? "hint: " : "hint:",
830
+ `hint: Disable this message with "git config${v243 ? "" : " set"} advice.${name} false"`,
831
+ );
832
+ }
833
+ out.push(`fatal: ${fatal}`);
834
+ return out.join("\n");
835
+ }
836
+
837
+ /**
838
+ * The pull's command line as git's reflog action spells it (`pull` and its arguments), in
839
+ * a fixed order since our options have none.
840
+ */
841
+ private commandLine(): string[] {
842
+ const flag = (value: boolean | undefined, name: string) =>
843
+ value === true ? [`--${name}`] : value === false ? [`--no-${name}`] : [];
844
+ return [
845
+ "pull",
846
+ ...flag(this.rebase, "rebase"),
847
+ ...flag(this.autoStash, "autostash"),
848
+ ...(this.log === undefined
849
+ ? []
850
+ : typeof this.log === "number"
851
+ ? [`--log=${this.log}`]
852
+ : flag(this.log, "log")),
853
+ ...flag(this.signoff, "signoff"),
854
+ ...flag(this.squash, "squash"),
855
+ ...flag(this.commit, "commit"),
856
+ ...flag(this.edit, "edit"),
857
+ ...(this.cleanupArg !== undefined ? [`--cleanup=${this.cleanupArg}`] : []),
858
+ ...(this.fastForwardMode ? [`--${this.fastForwardMode}`] : []),
859
+ ...(this.noVerify === true ? ["--no-verify"] : this.noVerify === false ? ["--verify"] : []),
860
+ ...flag(this.verifySignatures, "verify-signatures"),
861
+ ...(this.strategy ? [`--strategy=${this.strategy}`] : []),
862
+ ...this.strategyOptions.map((o) => `--strategy-option=${o}`),
863
+ ...(this.allowUnrelatedHistories ? ["--allow-unrelated-histories"] : []),
864
+ ...(this.all ? ["--all"] : []),
865
+ ...(this.force ? ["--force"] : []),
866
+ ...(this.dryRun ? ["--dry-run"] : []),
867
+ ...(this.tagOption === TagOption.FETCH_TAGS ? ["--tags"] : []),
868
+ ...(this.tagOption === TagOption.NO_TAGS ? ["--no-tags"] : []),
869
+ ...flag(this.prune, "prune"),
870
+ ...(this.depth !== undefined ? [`--depth=${this.depth}`] : []),
871
+ ...(this.deepen !== undefined ? [`--deepen=${this.deepen}`] : []),
872
+ ...(this.unshallow ? ["--unshallow"] : []),
873
+ ...(this.remoteGiven || this.refSpecs.length > 0 ? [this.remote] : []),
874
+ ...this.refSpecs,
875
+ ];
876
+ }
877
+
878
+ /**
879
+ * run_fetch: `git fetch [<options>] <remote> [<refspec>...]` with the pull's options, over
880
+ * the guarded transports (the credentials and headers go only where they are for).
881
+ */
882
+ private fetchCommand(remote: string, refSpecs: string[], action: string): FetchCommand {
883
+ const fetchCommand = this.configureChild(new FetchCommand(this._workingCopy));
884
+ fetchCommand.setRemote(remote);
885
+ fetchCommand.setRefSpecs(...refSpecs);
886
+ // git pull fetches with --update-head-ok
887
+ fetchCommand.setUpdateHeadOk(true);
888
+ fetchCommand.setReflogAction(action);
889
+ if (this.tagOption) fetchCommand.setTagOpt(this.tagOption);
890
+ if (this.prune !== undefined) fetchCommand.setRemoveDeletedRefs(this.prune);
891
+ if (this.depth !== undefined) fetchCommand.setDepth(this.depth);
892
+ if (this.deepen !== undefined) fetchCommand.setDeepen(this.deepen);
893
+ if (this.unshallow) fetchCommand.setUnshallow(true);
894
+ if (this.force) fetchCommand.setForceUpdate(true);
895
+ if (this.dryRun) fetchCommand.setDryRun(true);
896
+ if (this.repositoryFiles) fetchCommand.setRepositoryFiles(this.repositoryFiles);
897
+ if (this.recurseSubmodules !== undefined) {
898
+ fetchCommand.setRecurseSubmodules(this.recurseSubmodules);
899
+ }
900
+ return fetchCommand;
901
+ }
902
+
903
+ /** Whether MERGE_HEAD exists (pull.c's `file_exists(git_path_merge_head())`). */
904
+ private async mergeInProgress(): Promise<boolean> {
905
+ const state = new OperationState(this._workingCopy.checkout, this.refsStore);
906
+ if ((await state.read("MERGE_HEAD")) !== undefined) return true;
907
+ return (await state.ref("MERGE_HEAD")) !== undefined;
470
908
  }
471
909
 
472
910
  /**
@@ -505,66 +943,122 @@ export class PullCommand extends TransportCommand<PullResult> {
505
943
  }
506
944
 
507
945
  /**
508
- * pull.c's `get_merge_heads`: the first FETCH_HEAD entry not marked `not-for-merge`, with
509
- * its description (`branch 'x' of <url>`, as fmt-merge-msg titles the merge).
510
- *
511
- * @throws GitApiError with `die_no_merge_candidates`' lines (exit 1) when there is none
946
+ * pull.c's `get_merge_heads`: the FETCH_HEAD entries not marked `not-for-merge`, with the
947
+ * file's text (what `git merge FETCH_HEAD` gives fmt-merge-msg).
512
948
  */
513
- private async mergeHeadFromFetchHead(
514
- branch: string,
515
- ): Promise<{ objectId: ObjectId; description?: string }> {
516
- const checkout = (this._workingCopy as { checkout?: Checkout }).checkout;
949
+ private async mergeHeadsFromFetchHead(
950
+ checkout: Checkout | undefined,
951
+ ): Promise<{ heads: MergeHead[]; text: string }> {
517
952
  const text = (await checkout?.readFetchHead?.()) ?? "";
953
+ const heads: MergeHead[] = [];
518
954
  for (const line of text.split("\n")) {
519
955
  const m = /^([0-9a-f]{40,64})\t([^\t]*)\t(.*)$/.exec(line);
520
956
  if (!m || m[2] === "not-for-merge") continue;
521
- return { objectId: m[1] as ObjectId, description: m[3] };
957
+ heads.push({ objectId: m[1] as ObjectId, description: m[3] as string });
522
958
  }
959
+ return { heads, text };
960
+ }
961
+
962
+ /**
963
+ * pull.c's `die_no_merge_candidates`: why nothing fetched is to be merged.
964
+ *
965
+ * @throws GitApiError with git's lines (exit 1)
966
+ */
967
+ private dieNoMergeCandidates(branch: string | undefined, rebase: boolean): never {
523
968
  const store = RemoteConfigStore.from(this._workingCopy);
524
- let message: string;
525
- if (this.remoteBranchName) {
526
- message =
527
- "There are no candidates for merging among the refs that you just fetched.\n" +
528
- "Generally this means that you provided a wildcard refspec which had no\n" +
529
- "matches on the remote end.";
530
- } else if (store.value(`branch.${branch}.remote`) !== this.remote) {
531
- message =
532
- `You asked to pull from the remote '${this.remote}', but did not specify\n` +
533
- "a branch. Because this is not the default configured remote\n" +
534
- "for your current branch, you must specify a branch on the command line.";
969
+ const branchRemote = branch !== undefined ? store.value(`branch.${branch}.remote`) : undefined;
970
+ const which = rebase
971
+ ? "Please specify which branch you want to rebase against."
972
+ : "Please specify which branch you want to merge with.";
973
+ let lines: string[];
974
+ if (this.refSpecs.length > 0) {
975
+ lines = [
976
+ rebase
977
+ ? "There is no candidate for rebasing against among the refs that you just fetched."
978
+ : "There are no candidates for merging among the refs that you just fetched.",
979
+ "Generally this means that you provided a wildcard refspec which had no",
980
+ "matches on the remote end.",
981
+ ];
982
+ } else if (this.remoteGiven && branch !== undefined && branchRemote !== this.remote) {
983
+ lines = [
984
+ `You asked to pull from the remote '${this.remote}', but did not specify`,
985
+ "a branch. Because this is not the default configured remote",
986
+ "for your current branch, you must specify a branch on the command line.",
987
+ ];
988
+ } else if (branch === undefined) {
989
+ lines = [
990
+ "You are not currently on a branch.",
991
+ which,
992
+ "See git-pull(1) for details.",
993
+ "",
994
+ " git pull <remote> <branch>",
995
+ "",
996
+ ];
997
+ } else if (store.values(`branch.${branch}.merge`).length === 0) {
998
+ const remotes = store.configuredNames();
999
+ const remoteName = remotes.length === 1 ? remotes[0] : "<remote>";
1000
+ lines = [
1001
+ "There is no tracking information for the current branch.",
1002
+ which,
1003
+ "See git-pull(1) for details.",
1004
+ "",
1005
+ " git pull <remote> <branch>",
1006
+ "",
1007
+ "If you wish to set tracking information for this branch you can do so with:",
1008
+ "",
1009
+ ` git branch --set-upstream-to=${remoteName}/<branch> ${branch}`,
1010
+ "",
1011
+ ];
535
1012
  } else {
536
- message =
537
- `Your configuration specifies to merge with the ref '${store.value(`branch.${branch}.merge`) ?? ""}'\n` +
538
- "from the remote, but no such ref was fetched.";
1013
+ const merge = store.values(`branch.${branch}.merge`)[0] ?? "";
1014
+ lines = [
1015
+ `Your configuration specifies to merge with the ref '${merge}'`,
1016
+ "from the remote, but no such ref was fetched.",
1017
+ ];
539
1018
  }
540
- throw new GitApiError(message, { exitCode: 1 });
1019
+ throw new GitApiError(lines.join("\n"), { exitCode: 1 });
541
1020
  }
542
1021
 
543
1022
  private config(key: string): string | undefined {
544
1023
  return configValue(this._workingCopy, key);
545
1024
  }
546
1025
 
1026
+ /**
1027
+ * git's config_get_ff: `pull.ff` (false `--no-ff`, true `--ff`, `only` `--ff-only`).
1028
+ *
1029
+ * @throws GitApiError for any other value (`invalid value for 'pull.ff'`)
1030
+ */
1031
+ private configFastForward(): FastForwardMode | undefined {
1032
+ const value = this.config("pull.ff");
1033
+ if (value === undefined) return undefined;
1034
+ const bool = parseGitBool(value);
1035
+ if (bool === true) return FastForwardMode.FF;
1036
+ if (bool === false) return FastForwardMode.NO_FF;
1037
+ if (value === "only") return FastForwardMode.FF_ONLY;
1038
+ throw new GitApiError(`fatal: invalid value for 'pull.ff': '${value}'`, { exitCode: 128 });
1039
+ }
1040
+
547
1041
  /**
548
1042
  * git's config_get_rebase: `branch.<name>.rebase`, else `pull.rebase`; any value other
549
- * than false (`true`, `merges`, `interactive`) rebases.
1043
+ * than false (`true`, `merges`, `interactive`) rebases. Undefined when neither is set.
550
1044
  */
551
- private configRebase(branch: string): boolean {
1045
+ private configRebase(branch: string): boolean | undefined {
552
1046
  for (const key of [`branch.${branch}.rebase`, "pull.rebase"]) {
553
1047
  const value = this.config(key);
554
1048
  if (value === undefined) continue;
555
1049
  return parseGitBool(value) ?? true;
556
1050
  }
557
- return false;
1051
+ return undefined;
558
1052
  }
559
1053
 
560
1054
  /**
561
- * git's get_can_ff: whether `head` is a merge base of itself and `upstream` (an ancestor
562
- * of it), by git's date-ordered paint walk, which stops once the sides meet.
1055
+ * Whether `ancestor` is an ancestor of `commit` (git's repo_is_descendant_of), by git's
1056
+ * date-ordered paint walk, which stops once the sides meet.
563
1057
  */
564
- private async canFastForward(head: string, upstream: string): Promise<boolean> {
565
- if (head === upstream) return true;
1058
+ private async isAncestor(ancestor: string, commit: string): Promise<boolean> {
1059
+ if (ancestor === commit) return true;
566
1060
  const graph = new MergeBaseGraph(commitsBaseSource(this.commits, async () => new Map()));
567
- const bases = await graph.mergeBases(graph.commit(head), graph.commit(upstream));
568
- return bases.some((b) => b.id === head);
1061
+ const bases = await graph.mergeBases(graph.commit(ancestor), graph.commit(commit));
1062
+ return bases.some((b) => b.id === ancestor);
569
1063
  }
570
1064
  }