@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
@@ -6,7 +6,7 @@
6
6
  * (`fatal:`, exit 128; a usage error, 129) the command throws {@link SubmoduleCommandError},
7
7
  * whose `result` holds what was printed before.
8
8
  */
9
- import { FileMode, type ObjectId } from "@statewalker/vcs-core";
9
+ import { FileMode, type ObjectId, objectFormatOf } from "@statewalker/vcs-core";
10
10
  import { isGitDirectory } from "@statewalker/vcs-store-files";
11
11
  import type { GitTransportRegistry } from "@statewalker/vcs-transport";
12
12
  import { decodeGitPath } from "@statewalker/vcs-utils/encoding";
@@ -27,6 +27,7 @@ import {
27
27
  parsePathspec,
28
28
  pathspecErrors,
29
29
  } from "./pathspec.js";
30
+ import { ReadTreeCommand } from "./read-tree-command.js";
30
31
  import { RmCommand } from "./rm-command.js";
31
32
  import {
32
33
  defaultRemoteOf,
@@ -61,6 +62,10 @@ export interface SubmoduleCloneOptions {
61
62
  references?: string[];
62
63
  /** `--require-init`: a non-empty directory at the path is refused */
63
64
  requireInit?: boolean;
65
+ /** `--filter=<spec>` */
66
+ filter?: string;
67
+ /** `--single-branch` (true) / `--no-single-branch` (false) */
68
+ singleBranch?: boolean;
64
69
  /**
65
70
  * The transports and timeout the clone reaches its remote with. No credentials or headers
66
71
  * are taken: a submodule's URL comes from the repository's content, so they are attached
@@ -537,6 +542,8 @@ export abstract class SubmoduleCommandBase extends GitCommand<SubmoduleCommandRe
537
542
  .setDirectory(hostPath);
538
543
  if (options.depth !== undefined && options.depth > 0) clone.setDepth(options.depth);
539
544
  for (const reference of options.references ?? []) clone.addReference(reference);
545
+ if (options.filter !== undefined) clone.setFilter(options.filter);
546
+ if (options.singleBranch !== undefined) clone.setSingleBranch(options.singleBranch);
540
547
  if (options.transports) clone.setTransports(options.transports);
541
548
  if (options.timeout !== undefined) clone.setTimeout(options.timeout);
542
549
  clone.shareHooksOf(this);
@@ -626,7 +633,7 @@ export abstract class SubmoduleCommandBase extends GitCommand<SubmoduleCommandRe
626
633
  await this.absorbNested(path, innerGitDir ?? undefined);
627
634
  }
628
635
 
629
- private filesOrFail(): FilesApi {
636
+ protected filesOrFail(): FilesApi {
630
637
  const files = this.worktreeAccess?.getFiles?.();
631
638
  if (!files) throw new GitApiError("fatal: no worktree");
632
639
  return files;
@@ -793,7 +800,7 @@ export abstract class SubmoduleCommandBase extends GitCommand<SubmoduleCommandRe
793
800
  * repository, else what `read_gitfile_gently` makes of it (the repository a gitfile names,
794
801
  * `gitDir` null when it lies beyond this FilesApi, or git's error code).
795
802
  */
796
- private async resolveGitdirGently(
803
+ protected async resolveGitdirGently(
797
804
  path: string,
798
805
  ): Promise<ResolvedGitdir | { error: GitfileError }> {
799
806
  const files = this.worktreeAccess?.getFiles?.();
@@ -905,6 +912,317 @@ export abstract class SubmoduleCommandBase extends GitCommand<SubmoduleCommandRe
905
912
  }
906
913
  }
907
914
 
915
+ /** Flags of {@link SubmoduleHeadMover.moveHead} (submodule.c's `SUBMODULE_MOVE_HEAD_*`). */
916
+ export interface SubmoduleMoveHeadFlags {
917
+ /** `SUBMODULE_MOVE_HEAD_DRY_RUN`: only check (`read-tree -n`), change nothing */
918
+ dryRun?: boolean;
919
+ /** `SUBMODULE_MOVE_HEAD_FORCE`: local changes are thrown away (`read-tree --reset`) */
920
+ force?: boolean;
921
+ }
922
+
923
+ /**
924
+ * submodule.c's `submodule_move_head` for the unpack-trees runs of a superproject
925
+ * (`checkout`, `switch`, `reset`, `restore`, `read-tree` with `--recurse-submodules`): the
926
+ * submodule at a path moved from one commit to another (`null` for none: a submodule coming
927
+ * into existence or going away) by its own `read-tree --recurse-submodules` (in-process, the
928
+ * nested submodules moved the same way), its HEAD then detached at the new commit, or, for
929
+ * one going away, its gitfile removed, its directory if empty and its `core.worktree` unset.
930
+ * Its `error:` lines collect in the output ({@link takeStderr}); git's deaths throw
931
+ * `SubmoduleCommandError`. Not a command of its own.
932
+ *
933
+ * @internal
934
+ */
935
+ export class SubmoduleHeadMover extends SubmoduleCommandBase {
936
+ constructor(workingCopy: WorkingCopy, superPrefix: string) {
937
+ super(workingCopy);
938
+ this.superPrefix = superPrefix;
939
+ // `.gitmodules` warnings are printed by the commands that read it for themselves
940
+ this.modelWarningsShown = true;
941
+ }
942
+
943
+ async call(): Promise<SubmoduleCommandResult> {
944
+ throw new GitApiError("SubmoduleHeadMover is not a command");
945
+ }
946
+
947
+ /** What was printed since the last call (git's immediate `error:` lines). */
948
+ takeStderr(): string {
949
+ const text = this.out.stderr;
950
+ this.out.stderr = "";
951
+ return text;
952
+ }
953
+
954
+ /** `repo_read_gitmodules` again (after `.gitmodules` was checked out). */
955
+ reload(): void {
956
+ this.forgetModel();
957
+ }
958
+
959
+ /** `submodule_from_ce` of a gitlink at `path`: `.gitmodules` names a submodule there. */
960
+ async isSubmodule(path: string): Promise<boolean> {
961
+ return (await this.model()).fromPath(path) !== undefined;
962
+ }
963
+
964
+ /** git's `file_exists` (`lstat`) of a worktree path. */
965
+ async exists(path: string): Promise<boolean> {
966
+ return (await this.kindOf(path)) !== undefined;
967
+ }
968
+
969
+ /** The kind of what `lstat` finds at a worktree path (`symlink` for a link). */
970
+ async kind(path: string): Promise<string | undefined> {
971
+ const files = this.worktreeAccess?.getFiles?.();
972
+ if (!files) return undefined;
973
+ return lstatKind(files, this.filesPath(path));
974
+ }
975
+
976
+ /**
977
+ * A submodule path that is a symbolic link to a repository: git's stat follows it, finds the
978
+ * submodule populated and dies in `validate_submodule_path` before any change.
979
+ */
980
+ async validateLinked(path: string): Promise<void> {
981
+ if ((await this.kind(path)) !== "symlink") return;
982
+ if ((await this.kindThroughLinks(`${path}/.git`)) === undefined) return;
983
+ await this.validatePath(path);
984
+ }
985
+
986
+ /** `is_submodule_populated_gently` (with an error pointer: never dies). */
987
+ async populated(path: string): Promise<boolean> {
988
+ return !("error" in (await this.resolveGitdirGently(path)));
989
+ }
990
+
991
+ /** Whether `<path>/.git` is a repository directory (not absorbed into the superproject). */
992
+ async hasGitDirectory(path: string): Promise<boolean> {
993
+ const state = await this.resolveGitdirGently(path);
994
+ return !("error" in state) && state.kind === "directory";
995
+ }
996
+
997
+ /** `submodule_move_head`; false where git's returns an error (its lines in the output). */
998
+ async moveHead(
999
+ path: string,
1000
+ oldHead: string | null,
1001
+ newHead: string | null,
1002
+ flags: SubmoduleMoveHeadFlags = {},
1003
+ ): Promise<boolean> {
1004
+ const model = await this.model();
1005
+ if (!model.isActive(path)) return true;
1006
+ if (oldHead !== null) await this.validateLinked(path);
1007
+ if (oldHead !== null && !(await this.populatedGently(path, flags.force === true))) return true;
1008
+ const sub = model.fromPath(path);
1009
+ if (!sub) return true;
1010
+ await this.validatePath(path);
1011
+ if (oldHead !== null && !flags.force && (await this.hasDirtyIndex(path))) {
1012
+ this.out.stderr += `error: submodule '${path}' has dirty index\n`;
1013
+ return false;
1014
+ }
1015
+ const gitDir = await model.gitDirOf(sub.name);
1016
+ if (!flags.dryRun) {
1017
+ if (oldHead !== null) {
1018
+ if (!(await this.usesGitfile(path))) await this.absorbGitDirIntoSuperproject(path);
1019
+ } else if (gitDir !== undefined) {
1020
+ await this.connectWorkTreeAndGitDir(path, gitDir);
1021
+ // make sure the index is clean as well (submodule_reset_index)
1022
+ if (
1023
+ !(await this.readTreeIn(path, (c) => c.setReset(true).setUpdate(true), [null], false))
1024
+ ) {
1025
+ this.die("fatal: could not reset submodule index");
1026
+ }
1027
+ }
1028
+ if (oldHead !== null && flags.force && gitDir !== undefined) {
1029
+ await this.connectRecursively(path, gitDir, 0);
1030
+ }
1031
+ }
1032
+ const merged = await this.readTreeIn(
1033
+ path,
1034
+ (c) => {
1035
+ c.setRecurseSubmodules(true);
1036
+ if (flags.dryRun) c.setDryRun(true);
1037
+ else c.setUpdate(true);
1038
+ return flags.force ? c.setReset(true) : c.setMerge(true);
1039
+ },
1040
+ flags.force ? [newHead] : [oldHead, newHead],
1041
+ true,
1042
+ );
1043
+ if (!merged) {
1044
+ this.out.stderr += `error: Submodule '${path}' could not be updated.\n`;
1045
+ return false;
1046
+ }
1047
+ if (flags.dryRun) return true;
1048
+ if (newHead !== null) {
1049
+ const inner = await this.openSubmodule(path);
1050
+ if (!inner || !(await this.detachHead(inner, newHead))) return false;
1051
+ } else {
1052
+ const files = this.filesOrFail();
1053
+ await files.remove(this.filesPath(`${path}/.git`)).catch(() => false);
1054
+ const dir = this.filesPath(path);
1055
+ if ((await files.stats(dir).catch(() => undefined))?.kind === "directory") {
1056
+ let empty = true;
1057
+ for await (const _ of files.list(dir)) {
1058
+ empty = false;
1059
+ break;
1060
+ }
1061
+ if (empty) await files.remove(dir).catch(() => false);
1062
+ }
1063
+ // submodule_unset_core_worktree
1064
+ const unset =
1065
+ gitDir !== undefined &&
1066
+ (await setInConfigFile(this.workingCopy, `${gitDir}/config`, "core.worktree", undefined)
1067
+ .then(() => true)
1068
+ .catch(() => false));
1069
+ if (!unset) {
1070
+ this.out.stderr += `warning: Could not unset core.worktree setting in submodule '${path}'\n`;
1071
+ }
1072
+ }
1073
+ return true;
1074
+ }
1075
+
1076
+ /**
1077
+ * `is_submodule_populated_gently`: `<path>/.git` names a repository. Without `gentle`
1078
+ * (no error code pointer) the gitfile errors `read_gitfile_error_die` dies on are deaths.
1079
+ */
1080
+ private async populatedGently(path: string, gentle: boolean): Promise<boolean> {
1081
+ const state = await this.resolveGitdirGently(path);
1082
+ if (!("error" in state)) return true;
1083
+ if (!gentle) {
1084
+ if (state.error === "not-a-repo") {
1085
+ const files = this.filesOrFail();
1086
+ const text = decodeGitPath(
1087
+ await readFile(files, this.filesPath(`${path}/.git`)).catch(() => new Uint8Array()),
1088
+ );
1089
+ this.die(`fatal: not a git repository: ${text.replace(/^gitdir: /, "").trim()}`);
1090
+ }
1091
+ const fatal = GITFILE_ERRORS[state.error];
1092
+ if (fatal) this.die(`fatal: ${fatal}${path}/.git`);
1093
+ }
1094
+ return false;
1095
+ }
1096
+
1097
+ /** `submodule_has_dirty_index`: `git diff-index --quiet --cached HEAD` there fails. */
1098
+ private async hasDirtyIndex(path: string): Promise<boolean> {
1099
+ const inner = await this.openSubmodule(path);
1100
+ if (!inner) return true;
1101
+ return new SubmoduleIndexProbe(inner).call();
1102
+ }
1103
+
1104
+ /**
1105
+ * `submodule_uses_gitfile`: `<path>/.git` is a gitfile, and so is every populated nested
1106
+ * submodule's (`submodule foreach --recursive test -f .git`).
1107
+ */
1108
+ private async usesGitfile(path: string): Promise<boolean> {
1109
+ const state = await this.resolveGitdirGently(path);
1110
+ if ("error" in state || state.kind !== "gitfile") return false;
1111
+ const files = this.filesOrFail();
1112
+ const inner = await this.openSubmodule(path);
1113
+ if (!inner) return true;
1114
+ const nested = async (wc: WorkingCopy, prefix: string, depth: number): Promise<boolean> => {
1115
+ if (depth > MAX_ABSORB_DEPTH) return false;
1116
+ for await (const entry of wc.checkout.staging.entries()) {
1117
+ if (entry.mode !== FileMode.GITLINK || entry.stage !== 0) continue;
1118
+ const at = `${prefix}/${entry.path}`;
1119
+ const kind = (await files.stats(this.filesPath(`${at}/.git`)).catch(() => undefined))?.kind;
1120
+ if (kind === undefined) continue;
1121
+ if (kind !== "file") return false;
1122
+ const deeper = await wc.worktree.openGitlink?.(entry.path).catch(() => undefined);
1123
+ if (deeper && !(await nested(deeper, at, depth + 1))) return false;
1124
+ }
1125
+ return true;
1126
+ };
1127
+ return nested(inner, path, 0);
1128
+ }
1129
+
1130
+ /**
1131
+ * dir.c's `connect_work_tree_and_git_dir(path, gitDir, 1)`: the gitfile and `core.worktree`,
1132
+ * then the same for every nested submodule `.gitmodules` names and that is active
1133
+ * (`connect_wt_gitdir_in_nested`), populated or not.
1134
+ */
1135
+ private async connectRecursively(path: string, gitDir: string, depth: number): Promise<void> {
1136
+ await this.connectWorkTreeAndGitDir(path, gitDir);
1137
+ if (depth > MAX_ABSORB_DEPTH) return;
1138
+ const inner = await this.worktreeAccess?.openGitlink?.(path, { gitDir }).catch(() => undefined);
1139
+ if (!inner) return;
1140
+ const model = await SubmoduleModel.load(inner).catch(() => undefined);
1141
+ if (!model) return;
1142
+ for await (const entry of inner.checkout.staging.entries()) {
1143
+ if (entry.mode !== FileMode.GITLINK || entry.stage !== 0) continue;
1144
+ const sub = model.fromPath(entry.path);
1145
+ if (!sub || !model.isActive(entry.path)) continue;
1146
+ const nestedGitDir = await model.gitDirOf(sub.name).catch(() => undefined);
1147
+ if (nestedGitDir === undefined) continue;
1148
+ await this.connectRecursively(`${path}/${sub.path}`, nestedGitDir, depth + 1);
1149
+ }
1150
+ }
1151
+
1152
+ /**
1153
+ * git's child `read-tree --super-prefix=<prefix><path>/ ...` in the submodule
1154
+ * (`prepare_submodule_repo_env`: its own `.git`), `null` trees being the empty tree; its
1155
+ * error lines go to the output. False when it failed.
1156
+ */
1157
+ private async readTreeIn(
1158
+ path: string,
1159
+ configure: (command: ReadTreeCommand) => ReadTreeCommand,
1160
+ trees: (string | null)[],
1161
+ recursing: boolean,
1162
+ ): Promise<boolean> {
1163
+ const inner = await this.openSubmodule(path);
1164
+ if (!inner) {
1165
+ this.out.stderr += "fatal: not a git repository: '.git'\n";
1166
+ return false;
1167
+ }
1168
+ const command = configure(new ReadTreeCommand(inner)).setSuperPrefix(
1169
+ `${this.superPrefix}${path}/`,
1170
+ );
1171
+ if (!recursing) command.setRecurseSubmodules(false);
1172
+ const empty = objectFormatOf(inner.history).emptyTreeId;
1173
+ for (const tree of trees) command.addTree(tree ?? empty);
1174
+ try {
1175
+ const result = await command.call();
1176
+ for (const w of result.warnings) this.out.stderr += `${w}\n`;
1177
+ return true;
1178
+ } catch (error) {
1179
+ if (error instanceof SubmoduleCommandError) {
1180
+ this.out.stderr += error.result.stderr;
1181
+ this.out.stderr += `${error.message}\n`;
1182
+ return false;
1183
+ }
1184
+ if (!(error instanceof GitApiError)) throw error;
1185
+ this.out.stderr += `${error.message.replace(/\n$/, "")}\n`;
1186
+ return false;
1187
+ }
1188
+ }
1189
+
1190
+ /** `git update-ref HEAD --no-deref <id>` in the submodule. */
1191
+ private async detachHead(inner: WorkingCopy, id: string): Promise<boolean> {
1192
+ const refs = inner.history.refs;
1193
+ const result = await refs.batch([{ name: "HEAD", new: id, noDeref: true }]);
1194
+ if (!result.ok) await refs.set("HEAD", id);
1195
+ return true;
1196
+ }
1197
+ }
1198
+
1199
+ /** `git diff-index --quiet --cached HEAD` of a working copy (true: it differs or fails). */
1200
+ class SubmoduleIndexProbe extends GitCommand<boolean> {
1201
+ async call(): Promise<boolean> {
1202
+ const headId = (await this.refsStore.resolve("HEAD").catch(() => undefined))?.objectId;
1203
+ if (!headId) return true;
1204
+ const treeId = await this.commits.getTree(headId).catch(() => undefined);
1205
+ if (!treeId) return true;
1206
+ const head = new Map<string, { objectId: string; mode: number }>();
1207
+ const walk = async (id: string, prefix: string): Promise<void> => {
1208
+ for await (const entry of this.trees.loadTree(id)) {
1209
+ const path = prefix ? `${prefix}/${entry.name}` : entry.name;
1210
+ if (entry.mode === FileMode.TREE) await walk(entry.id, path);
1211
+ else head.set(path, { objectId: entry.id, mode: entry.mode });
1212
+ }
1213
+ };
1214
+ await walk(treeId, "");
1215
+ for await (const entry of this.staging.entries()) {
1216
+ const h = head.get(entry.path);
1217
+ if (entry.stage !== 0 || !h || h.objectId !== entry.objectId || h.mode !== entry.mode) {
1218
+ return true;
1219
+ }
1220
+ head.delete(entry.path);
1221
+ }
1222
+ return head.size > 0;
1223
+ }
1224
+ }
1225
+
908
1226
  /**
909
1227
  * `git submodule init [-q] [<path>...]`: each submodule of the index (matching the paths)
910
1228
  * registered in `.git/config` from `.gitmodules`: `submodule.<name>.active` unless already