@statewalker/vcs-commands 0.4.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (561) hide show
  1. package/README.md +123 -8
  2. package/dist/commands/add-command.d.ts +265 -34
  3. package/dist/commands/add-command.d.ts.map +1 -1
  4. package/dist/commands/add-patch/add-interactive.d.ts +46 -0
  5. package/dist/commands/add-patch/add-interactive.d.ts.map +1 -0
  6. package/dist/commands/add-patch/add-patch.d.ts +139 -0
  7. package/dist/commands/add-patch/add-patch.d.ts.map +1 -0
  8. package/dist/commands/add-patch/index.d.ts +6 -0
  9. package/dist/commands/add-patch/index.d.ts.map +1 -0
  10. package/dist/commands/add-patch/patch-backend.d.ts +80 -0
  11. package/dist/commands/add-patch/patch-backend.d.ts.map +1 -0
  12. package/dist/commands/add-patch/patch-modes.d.ts +71 -0
  13. package/dist/commands/add-patch/patch-modes.d.ts.map +1 -0
  14. package/dist/commands/add-patch/patch-session.d.ts +49 -0
  15. package/dist/commands/add-patch/patch-session.d.ts.map +1 -0
  16. package/dist/commands/am/am-command.d.ts +175 -0
  17. package/dist/commands/am/am-command.d.ts.map +1 -0
  18. package/dist/commands/am/index.d.ts +3 -0
  19. package/dist/commands/am/index.d.ts.map +1 -0
  20. package/dist/commands/am/mailinfo.d.ts +58 -0
  21. package/dist/commands/am/mailinfo.d.ts.map +1 -0
  22. package/dist/commands/am/patch-format.d.ts +24 -0
  23. package/dist/commands/am/patch-format.d.ts.map +1 -0
  24. package/dist/commands/apply/apply-command.d.ts +153 -0
  25. package/dist/commands/apply/apply-command.d.ts.map +1 -0
  26. package/dist/commands/apply/apply-engine.d.ts +195 -0
  27. package/dist/commands/apply/apply-engine.d.ts.map +1 -0
  28. package/dist/commands/apply/apply-parse.d.ts +86 -0
  29. package/dist/commands/apply/apply-parse.d.ts.map +1 -0
  30. package/dist/commands/apply/apply-types.d.ts +70 -0
  31. package/dist/commands/apply/apply-types.d.ts.map +1 -0
  32. package/dist/commands/apply/index.d.ts +6 -0
  33. package/dist/commands/apply/index.d.ts.map +1 -0
  34. package/dist/commands/apply/latin1.d.ts +32 -0
  35. package/dist/commands/apply/latin1.d.ts.map +1 -0
  36. package/dist/commands/apply/whitespace.d.ts +58 -0
  37. package/dist/commands/apply/whitespace.d.ts.map +1 -0
  38. package/dist/commands/attributes-source.d.ts +26 -0
  39. package/dist/commands/attributes-source.d.ts.map +1 -0
  40. package/dist/commands/backfill-command.d.ts +110 -0
  41. package/dist/commands/backfill-command.d.ts.map +1 -0
  42. package/dist/commands/bisect/bisect-checkout.d.ts +64 -0
  43. package/dist/commands/bisect/bisect-checkout.d.ts.map +1 -0
  44. package/dist/commands/bisect/bisect-command.d.ts +201 -0
  45. package/dist/commands/bisect/bisect-command.d.ts.map +1 -0
  46. package/dist/commands/bisect/bisect-engine.d.ts +219 -0
  47. package/dist/commands/bisect/bisect-engine.d.ts.map +1 -0
  48. package/dist/commands/bisect/bisect-graph.d.ts +127 -0
  49. package/dist/commands/bisect/bisect-graph.d.ts.map +1 -0
  50. package/dist/commands/bisect/bisect-quote.d.ts +27 -0
  51. package/dist/commands/bisect/bisect-quote.d.ts.map +1 -0
  52. package/dist/commands/bisect/index.d.ts +5 -0
  53. package/dist/commands/bisect/index.d.ts.map +1 -0
  54. package/dist/commands/blame-command.d.ts +122 -131
  55. package/dist/commands/blame-command.d.ts.map +1 -1
  56. package/dist/commands/branch-command.d.ts +52 -2
  57. package/dist/commands/branch-command.d.ts.map +1 -1
  58. package/dist/commands/branch-tracking.d.ts +98 -0
  59. package/dist/commands/branch-tracking.d.ts.map +1 -0
  60. package/dist/commands/checkout-command.d.ts +299 -34
  61. package/dist/commands/checkout-command.d.ts.map +1 -1
  62. package/dist/commands/checkout-paths.d.ts +124 -0
  63. package/dist/commands/checkout-paths.d.ts.map +1 -0
  64. package/dist/commands/cherry-pick-command.d.ts +50 -42
  65. package/dist/commands/cherry-pick-command.d.ts.map +1 -1
  66. package/dist/commands/clean-command.d.ts +67 -4
  67. package/dist/commands/clean-command.d.ts.map +1 -1
  68. package/dist/commands/clone-command.d.ts +179 -7
  69. package/dist/commands/clone-command.d.ts.map +1 -1
  70. package/dist/commands/commit-command.d.ts +311 -17
  71. package/dist/commands/commit-command.d.ts.map +1 -1
  72. package/dist/commands/core-config.d.ts +93 -0
  73. package/dist/commands/core-config.d.ts.map +1 -0
  74. package/dist/commands/date-format.d.ts +58 -0
  75. package/dist/commands/date-format.d.ts.map +1 -0
  76. package/dist/commands/describe-command.d.ts.map +1 -1
  77. package/dist/commands/diff-command.d.ts +377 -30
  78. package/dist/commands/diff-command.d.ts.map +1 -1
  79. package/dist/commands/diff-textconv.d.ts +40 -0
  80. package/dist/commands/diff-textconv.d.ts.map +1 -0
  81. package/dist/commands/fetch-command.d.ts +244 -23
  82. package/dist/commands/fetch-command.d.ts.map +1 -1
  83. package/dist/commands/format-patch-command.d.ts +164 -0
  84. package/dist/commands/format-patch-command.d.ts.map +1 -0
  85. package/dist/commands/fsck/fetch-fsck.d.ts +60 -0
  86. package/dist/commands/fsck/fetch-fsck.d.ts.map +1 -0
  87. package/dist/commands/fsck/fsck-command.d.ts +225 -0
  88. package/dist/commands/fsck/fsck-command.d.ts.map +1 -0
  89. package/dist/commands/fsck/fsck-loose.d.ts +68 -0
  90. package/dist/commands/fsck/fsck-loose.d.ts.map +1 -0
  91. package/dist/commands/fsck/fsck-msg-ids.d.ts +122 -0
  92. package/dist/commands/fsck/fsck-msg-ids.d.ts.map +1 -0
  93. package/dist/commands/fsck/fsck-object-checks.d.ts +148 -0
  94. package/dist/commands/fsck/fsck-object-checks.d.ts.map +1 -0
  95. package/dist/commands/fsck/fsck-object-table.d.ts +132 -0
  96. package/dist/commands/fsck/fsck-object-table.d.ts.map +1 -0
  97. package/dist/commands/fsck/fsck-pack.d.ts +115 -0
  98. package/dist/commands/fsck/fsck-pack.d.ts.map +1 -0
  99. package/dist/commands/fsck/index.d.ts +6 -0
  100. package/dist/commands/fsck/index.d.ts.map +1 -0
  101. package/dist/commands/fsck/verify-pack-command.d.ts +81 -0
  102. package/dist/commands/fsck/verify-pack-command.d.ts.map +1 -0
  103. package/dist/commands/gc-command.d.ts +43 -0
  104. package/dist/commands/gc-command.d.ts.map +1 -1
  105. package/dist/commands/git-date.d.ts +66 -0
  106. package/dist/commands/git-date.d.ts.map +1 -0
  107. package/dist/commands/git-describe.d.ts +67 -0
  108. package/dist/commands/git-describe.d.ts.map +1 -0
  109. package/dist/commands/git-hooks.d.ts +416 -0
  110. package/dist/commands/git-hooks.d.ts.map +1 -0
  111. package/dist/commands/git-ident.d.ts +128 -0
  112. package/dist/commands/git-ident.d.ts.map +1 -0
  113. package/dist/commands/hook-command.d.ts +96 -0
  114. package/dist/commands/hook-command.d.ts.map +1 -0
  115. package/dist/commands/index-adder.d.ts +231 -0
  116. package/dist/commands/index-adder.d.ts.map +1 -0
  117. package/dist/commands/index-host.d.ts +86 -0
  118. package/dist/commands/index-host.d.ts.map +1 -0
  119. package/dist/commands/index.d.ts +55 -0
  120. package/dist/commands/index.d.ts.map +1 -1
  121. package/dist/commands/index.js +3 -2
  122. package/dist/commands/init-command.d.ts +12 -1
  123. package/dist/commands/init-command.d.ts.map +1 -1
  124. package/dist/commands/local-clone.d.ts +60 -0
  125. package/dist/commands/local-clone.d.ts.map +1 -0
  126. package/dist/commands/local-transport.d.ts +117 -0
  127. package/dist/commands/local-transport.d.ts.map +1 -0
  128. package/dist/commands/log-command.d.ts +216 -24
  129. package/dist/commands/log-command.d.ts.map +1 -1
  130. package/dist/commands/log-graph.d.ts +120 -0
  131. package/dist/commands/log-graph.d.ts.map +1 -0
  132. package/dist/commands/log-output.d.ts +323 -0
  133. package/dist/commands/log-output.d.ts.map +1 -0
  134. package/dist/commands/ls-remote-command.d.ts +23 -7
  135. package/dist/commands/ls-remote-command.d.ts.map +1 -1
  136. package/dist/commands/mailmap.d.ts +31 -0
  137. package/dist/commands/mailmap.d.ts.map +1 -0
  138. package/dist/commands/merge-bases.d.ts +85 -0
  139. package/dist/commands/merge-bases.d.ts.map +1 -0
  140. package/dist/commands/merge-command.d.ts +209 -74
  141. package/dist/commands/merge-command.d.ts.map +1 -1
  142. package/dist/commands/merge-config.d.ts +13 -0
  143. package/dist/commands/merge-config.d.ts.map +1 -0
  144. package/dist/commands/merge-drivers.d.ts +130 -0
  145. package/dist/commands/merge-drivers.d.ts.map +1 -0
  146. package/dist/commands/merge-support.d.ts +252 -0
  147. package/dist/commands/merge-support.d.ts.map +1 -0
  148. package/dist/commands/message-cleanup.d.ts +86 -0
  149. package/dist/commands/message-cleanup.d.ts.map +1 -0
  150. package/dist/commands/mv-command.d.ts +94 -0
  151. package/dist/commands/mv-command.d.ts.map +1 -0
  152. package/dist/commands/notes-command.d.ts +256 -0
  153. package/dist/commands/notes-command.d.ts.map +1 -0
  154. package/dist/commands/notes-commands.d.ts +41 -0
  155. package/dist/commands/notes-commands.d.ts.map +1 -0
  156. package/dist/commands/notes-merge-command.d.ts +105 -0
  157. package/dist/commands/notes-merge-command.d.ts.map +1 -0
  158. package/dist/commands/notes-support.d.ts +125 -0
  159. package/dist/commands/notes-support.d.ts.map +1 -0
  160. package/dist/commands/notes-tree.d.ts +106 -0
  161. package/dist/commands/notes-tree.d.ts.map +1 -0
  162. package/dist/commands/object-id-input.d.ts +20 -0
  163. package/dist/commands/object-id-input.d.ts.map +1 -0
  164. package/dist/commands/octopus-merge.d.ts +59 -0
  165. package/dist/commands/octopus-merge.d.ts.map +1 -0
  166. package/dist/commands/ort-merge.d.ts +126 -0
  167. package/dist/commands/ort-merge.d.ts.map +1 -0
  168. package/dist/commands/ort-recursive.d.ts +53 -0
  169. package/dist/commands/ort-recursive.d.ts.map +1 -0
  170. package/dist/commands/pack-refs-command.d.ts +20 -0
  171. package/dist/commands/pack-refs-command.d.ts.map +1 -1
  172. package/dist/commands/patch-id.d.ts +41 -0
  173. package/dist/commands/patch-id.d.ts.map +1 -0
  174. package/dist/commands/pathspec-attributes.d.ts +64 -0
  175. package/dist/commands/pathspec-attributes.d.ts.map +1 -0
  176. package/dist/commands/pathspec.d.ts +324 -0
  177. package/dist/commands/pathspec.d.ts.map +1 -0
  178. package/dist/commands/post-index-change.d.ts +33 -0
  179. package/dist/commands/post-index-change.d.ts.map +1 -0
  180. package/dist/commands/pretty-format.d.ts +222 -0
  181. package/dist/commands/pretty-format.d.ts.map +1 -0
  182. package/dist/commands/promisor-remote.d.ts +80 -0
  183. package/dist/commands/promisor-remote.d.ts.map +1 -0
  184. package/dist/commands/pull-command.d.ts +41 -8
  185. package/dist/commands/pull-command.d.ts.map +1 -1
  186. package/dist/commands/push-command.d.ts +24 -8
  187. package/dist/commands/push-command.d.ts.map +1 -1
  188. package/dist/commands/read-tree-command.d.ts +112 -0
  189. package/dist/commands/read-tree-command.d.ts.map +1 -0
  190. package/dist/commands/rebase-command.d.ts +507 -75
  191. package/dist/commands/rebase-command.d.ts.map +1 -1
  192. package/dist/commands/rebase-todo.d.ts +130 -0
  193. package/dist/commands/rebase-todo.d.ts.map +1 -0
  194. package/dist/commands/ref-decoration-filter.d.ts +53 -0
  195. package/dist/commands/ref-decoration-filter.d.ts.map +1 -0
  196. package/dist/commands/reflog-messages.d.ts +98 -0
  197. package/dist/commands/reflog-messages.d.ts.map +1 -0
  198. package/dist/commands/remote-command.d.ts +146 -6
  199. package/dist/commands/remote-command.d.ts.map +1 -1
  200. package/dist/commands/remote-transport.d.ts +120 -0
  201. package/dist/commands/remote-transport.d.ts.map +1 -0
  202. package/dist/commands/reset-command.d.ts +161 -7
  203. package/dist/commands/reset-command.d.ts.map +1 -1
  204. package/dist/commands/restore-command.d.ts +103 -0
  205. package/dist/commands/restore-command.d.ts.map +1 -0
  206. package/dist/commands/rev-list-command.d.ts +78 -0
  207. package/dist/commands/rev-list-command.d.ts.map +1 -0
  208. package/dist/commands/rev-parse-command.d.ts +80 -0
  209. package/dist/commands/rev-parse-command.d.ts.map +1 -0
  210. package/dist/commands/revert-command.d.ts +46 -38
  211. package/dist/commands/revert-command.d.ts.map +1 -1
  212. package/dist/commands/revision-filenames.d.ts +95 -0
  213. package/dist/commands/revision-filenames.d.ts.map +1 -0
  214. package/dist/commands/revision-range.d.ts +67 -0
  215. package/dist/commands/revision-range.d.ts.map +1 -0
  216. package/dist/commands/revision-resolver.d.ts +321 -0
  217. package/dist/commands/revision-resolver.d.ts.map +1 -0
  218. package/dist/commands/rm-command.d.ts +69 -7
  219. package/dist/commands/rm-command.d.ts.map +1 -1
  220. package/dist/commands/sequencer-pick.d.ts +191 -0
  221. package/dist/commands/sequencer-pick.d.ts.map +1 -0
  222. package/dist/commands/sequencer-support.d.ts +125 -0
  223. package/dist/commands/sequencer-support.d.ts.map +1 -0
  224. package/dist/commands/serve-repository.d.ts +52 -0
  225. package/dist/commands/serve-repository.d.ts.map +1 -0
  226. package/dist/commands/sparse-checkout-command.d.ts +190 -0
  227. package/dist/commands/sparse-checkout-command.d.ts.map +1 -0
  228. package/dist/commands/sparse-checkout-support.d.ts +268 -0
  229. package/dist/commands/sparse-checkout-support.d.ts.map +1 -0
  230. package/dist/commands/stash-apply-command.d.ts +69 -13
  231. package/dist/commands/stash-apply-command.d.ts.map +1 -1
  232. package/dist/commands/stash-create-command.d.ts +214 -26
  233. package/dist/commands/stash-create-command.d.ts.map +1 -1
  234. package/dist/commands/stash-drop-command.d.ts +10 -2
  235. package/dist/commands/stash-drop-command.d.ts.map +1 -1
  236. package/dist/commands/stash-list-command.d.ts +2 -4
  237. package/dist/commands/stash-list-command.d.ts.map +1 -1
  238. package/dist/commands/stash-working-tree.d.ts +95 -0
  239. package/dist/commands/stash-working-tree.d.ts.map +1 -0
  240. package/dist/commands/status-command.d.ts +320 -28
  241. package/dist/commands/status-command.d.ts.map +1 -1
  242. package/dist/commands/status-format.d.ts +155 -0
  243. package/dist/commands/status-format.d.ts.map +1 -0
  244. package/dist/commands/status-header.d.ts +64 -0
  245. package/dist/commands/status-header.d.ts.map +1 -0
  246. package/dist/commands/strerror.d.ts +7 -0
  247. package/dist/commands/strerror.d.ts.map +1 -0
  248. package/dist/commands/submodule-config.d.ts +38 -0
  249. package/dist/commands/submodule-config.d.ts.map +1 -0
  250. package/dist/commands/submodule-summary-command.d.ts +80 -0
  251. package/dist/commands/submodule-summary-command.d.ts.map +1 -0
  252. package/dist/commands/submodule-summary.d.ts +150 -0
  253. package/dist/commands/submodule-summary.d.ts.map +1 -0
  254. package/dist/commands/switch-command.d.ts +132 -0
  255. package/dist/commands/switch-command.d.ts.map +1 -0
  256. package/dist/commands/tag-command.d.ts +23 -2
  257. package/dist/commands/tag-command.d.ts.map +1 -1
  258. package/dist/commands/tracking-info.d.ts +64 -0
  259. package/dist/commands/tracking-info.d.ts.map +1 -0
  260. package/dist/commands/trailers.d.ts +73 -0
  261. package/dist/commands/trailers.d.ts.map +1 -0
  262. package/dist/commands/tree-restore.d.ts +137 -6
  263. package/dist/commands/tree-restore.d.ts.map +1 -1
  264. package/dist/commands/untracked-cache-support.d.ts +53 -0
  265. package/dist/commands/untracked-cache-support.d.ts.map +1 -0
  266. package/dist/commands/worktree-add-command.d.ts +108 -0
  267. package/dist/commands/worktree-add-command.d.ts.map +1 -0
  268. package/dist/commands/worktree-list-command.d.ts +69 -0
  269. package/dist/commands/worktree-list-command.d.ts.map +1 -0
  270. package/dist/commands/worktree-lock-command.d.ts +44 -0
  271. package/dist/commands/worktree-lock-command.d.ts.map +1 -0
  272. package/dist/commands/worktree-overwrite-checks.d.ts +204 -0
  273. package/dist/commands/worktree-overwrite-checks.d.ts.map +1 -0
  274. package/dist/commands/worktree-prune-command.d.ts +48 -0
  275. package/dist/commands/worktree-prune-command.d.ts.map +1 -0
  276. package/dist/commands/worktree-remove-command.d.ts +59 -0
  277. package/dist/commands/worktree-remove-command.d.ts.map +1 -0
  278. package/dist/commands/worktree-repair-command.d.ts +35 -0
  279. package/dist/commands/worktree-repair-command.d.ts.map +1 -0
  280. package/dist/commands/worktree-support.d.ts +64 -0
  281. package/dist/commands/worktree-support.d.ts.map +1 -0
  282. package/dist/commands-DnmlfwGV.js +61620 -0
  283. package/dist/core-commands/add.command.impl.d.ts.map +1 -1
  284. package/dist/core-commands/index.d.ts +0 -3
  285. package/dist/core-commands/index.d.ts.map +1 -1
  286. package/dist/errors/add-errors.d.ts +55 -0
  287. package/dist/errors/add-errors.d.ts.map +1 -1
  288. package/dist/errors/checkout-errors.d.ts +29 -0
  289. package/dist/errors/checkout-errors.d.ts.map +1 -1
  290. package/dist/errors/command-errors.d.ts +77 -0
  291. package/dist/errors/command-errors.d.ts.map +1 -1
  292. package/dist/errors/commit-errors.d.ts +9 -0
  293. package/dist/errors/commit-errors.d.ts.map +1 -1
  294. package/dist/errors/git-api-error.d.ts +59 -2
  295. package/dist/errors/git-api-error.d.ts.map +1 -1
  296. package/dist/errors/index.d.ts +1 -0
  297. package/dist/errors/index.d.ts.map +1 -1
  298. package/dist/errors/index.js +371 -19
  299. package/dist/errors/rebase-errors.d.ts +9 -0
  300. package/dist/errors/rebase-errors.d.ts.map +1 -1
  301. package/dist/errors/ref-errors.d.ts +32 -0
  302. package/dist/errors/ref-errors.d.ts.map +1 -1
  303. package/dist/errors/transport-errors.d.ts +12 -2
  304. package/dist/errors/transport-errors.d.ts.map +1 -1
  305. package/dist/errors/worktree-errors.d.ts +35 -0
  306. package/dist/errors/worktree-errors.d.ts.map +1 -0
  307. package/dist/git-command-DxvwPrPB.js +7612 -0
  308. package/dist/git-command.d.ts +422 -32
  309. package/dist/git-command.d.ts.map +1 -1
  310. package/dist/git.d.ts +326 -5
  311. package/dist/git.d.ts.map +1 -1
  312. package/dist/index.d.ts +1 -1
  313. package/dist/index.d.ts.map +1 -1
  314. package/dist/index.js +5 -5
  315. package/dist/remote-config/index.d.ts +1 -0
  316. package/dist/remote-config/index.d.ts.map +1 -1
  317. package/dist/remote-config/remote-config-store.d.ts +123 -3
  318. package/dist/remote-config/remote-config-store.d.ts.map +1 -1
  319. package/dist/remote-config/remote-refs.d.ts +41 -0
  320. package/dist/remote-config/remote-refs.d.ts.map +1 -0
  321. package/dist/rename/detect-renames.d.ts +148 -0
  322. package/dist/rename/detect-renames.d.ts.map +1 -0
  323. package/dist/rename/git-similarity.d.ts +44 -0
  324. package/dist/rename/git-similarity.d.ts.map +1 -0
  325. package/dist/rename/index.d.ts +2 -0
  326. package/dist/rename/index.d.ts.map +1 -1
  327. package/dist/results/binary-patch.d.ts +11 -0
  328. package/dist/results/binary-patch.d.ts.map +1 -0
  329. package/dist/results/blame-format.d.ts +55 -0
  330. package/dist/results/blame-format.d.ts.map +1 -0
  331. package/dist/results/cherry-pick-result.d.ts +10 -0
  332. package/dist/results/cherry-pick-result.d.ts.map +1 -1
  333. package/dist/results/clone-result.d.ts +16 -0
  334. package/dist/results/clone-result.d.ts.map +1 -1
  335. package/dist/results/combined-diff.d.ts +77 -0
  336. package/dist/results/combined-diff.d.ts.map +1 -0
  337. package/dist/results/diff-entry.d.ts +32 -0
  338. package/dist/results/diff-entry.d.ts.map +1 -1
  339. package/dist/results/diff-formatter.d.ts +34 -60
  340. package/dist/results/diff-formatter.d.ts.map +1 -1
  341. package/dist/results/diff-order.d.ts +25 -0
  342. package/dist/results/diff-order.d.ts.map +1 -0
  343. package/dist/results/diff-output.d.ts +249 -0
  344. package/dist/results/diff-output.d.ts.map +1 -0
  345. package/dist/results/fetch-result.d.ts +24 -1
  346. package/dist/results/fetch-result.d.ts.map +1 -1
  347. package/dist/results/index.d.ts +5 -0
  348. package/dist/results/index.d.ts.map +1 -1
  349. package/dist/results/index.js +2 -252
  350. package/dist/results/merge-result.d.ts +15 -1
  351. package/dist/results/merge-result.d.ts.map +1 -1
  352. package/dist/results/pull-result.d.ts +12 -3
  353. package/dist/results/pull-result.d.ts.map +1 -1
  354. package/dist/results/push-result.d.ts +42 -0
  355. package/dist/results/push-result.d.ts.map +1 -1
  356. package/dist/results/quote-path.d.ts +27 -0
  357. package/dist/results/quote-path.d.ts.map +1 -0
  358. package/dist/results/rebase-result.d.ts +28 -1
  359. package/dist/results/rebase-result.d.ts.map +1 -1
  360. package/dist/results/revert-result.d.ts +10 -0
  361. package/dist/results/revert-result.d.ts.map +1 -1
  362. package/dist/results/stash-result.d.ts +5 -0
  363. package/dist/results/stash-result.d.ts.map +1 -1
  364. package/dist/results/status-result.d.ts +143 -18
  365. package/dist/results/status-result.d.ts.map +1 -1
  366. package/dist/results-BZGa2Z3I.js +2934 -0
  367. package/dist/transport-command.d.ts +56 -1
  368. package/dist/transport-command.d.ts.map +1 -1
  369. package/package.json +15 -10
  370. package/src/commands/add-command.ts +1291 -224
  371. package/src/commands/add-patch/add-interactive.ts +941 -0
  372. package/src/commands/add-patch/add-patch.ts +1169 -0
  373. package/src/commands/add-patch/index.ts +5 -0
  374. package/src/commands/add-patch/patch-backend.ts +239 -0
  375. package/src/commands/add-patch/patch-modes.ts +249 -0
  376. package/src/commands/add-patch/patch-session.ts +159 -0
  377. package/src/commands/am/am-command.ts +1111 -0
  378. package/src/commands/am/index.ts +2 -0
  379. package/src/commands/am/mailinfo.ts +1015 -0
  380. package/src/commands/am/patch-format.ts +121 -0
  381. package/src/commands/apply/apply-command.ts +832 -0
  382. package/src/commands/apply/apply-engine.ts +1603 -0
  383. package/src/commands/apply/apply-parse.ts +1209 -0
  384. package/src/commands/apply/apply-types.ts +112 -0
  385. package/src/commands/apply/index.ts +5 -0
  386. package/src/commands/apply/latin1.ts +171 -0
  387. package/src/commands/apply/whitespace.ts +260 -0
  388. package/src/commands/attributes-source.ts +96 -0
  389. package/src/commands/backfill-command.ts +694 -0
  390. package/src/commands/bisect/bisect-checkout.ts +217 -0
  391. package/src/commands/bisect/bisect-command.ts +788 -0
  392. package/src/commands/bisect/bisect-engine.ts +1079 -0
  393. package/src/commands/bisect/bisect-graph.ts +595 -0
  394. package/src/commands/bisect/bisect-quote.ts +92 -0
  395. package/src/commands/bisect/index.ts +4 -0
  396. package/src/commands/blame-command.ts +711 -986
  397. package/src/commands/branch-command.ts +354 -32
  398. package/src/commands/branch-tracking.ts +331 -0
  399. package/src/commands/checkout-command.ts +1426 -297
  400. package/src/commands/checkout-paths.ts +784 -0
  401. package/src/commands/cherry-pick-command.ts +156 -396
  402. package/src/commands/clean-command.ts +532 -85
  403. package/src/commands/clone-command.ts +826 -55
  404. package/src/commands/commit-command.ts +1781 -166
  405. package/src/commands/core-config.ts +196 -0
  406. package/src/commands/date-format.ts +668 -0
  407. package/src/commands/describe-command.ts +2 -0
  408. package/src/commands/diff-command.ts +1898 -110
  409. package/src/commands/diff-textconv.ts +50 -0
  410. package/src/commands/fetch-command.ts +1038 -79
  411. package/src/commands/format-patch-command.ts +969 -0
  412. package/src/commands/fsck/fetch-fsck.ts +229 -0
  413. package/src/commands/fsck/fsck-command.ts +3347 -0
  414. package/src/commands/fsck/fsck-loose.ts +287 -0
  415. package/src/commands/fsck/fsck-msg-ids.ts +176 -0
  416. package/src/commands/fsck/fsck-object-checks.ts +1044 -0
  417. package/src/commands/fsck/fsck-object-table.ts +363 -0
  418. package/src/commands/fsck/fsck-pack.ts +604 -0
  419. package/src/commands/fsck/index.ts +5 -0
  420. package/src/commands/fsck/verify-pack-command.ts +249 -0
  421. package/src/commands/gc-command.ts +147 -1
  422. package/src/commands/git-date.ts +895 -0
  423. package/src/commands/git-describe.ts +316 -0
  424. package/src/commands/git-hooks.ts +1472 -0
  425. package/src/commands/git-ident.ts +344 -0
  426. package/src/commands/hook-command.ts +247 -0
  427. package/src/commands/index-adder.ts +706 -0
  428. package/src/commands/index-host.ts +291 -0
  429. package/src/commands/index.ts +83 -0
  430. package/src/commands/init-command.ts +60 -11
  431. package/src/commands/local-clone.ts +183 -0
  432. package/src/commands/local-transport.ts +762 -0
  433. package/src/commands/log-command.ts +1915 -170
  434. package/src/commands/log-graph.ts +671 -0
  435. package/src/commands/log-output.ts +1359 -0
  436. package/src/commands/ls-remote-command.ts +101 -58
  437. package/src/commands/mailmap.ts +129 -0
  438. package/src/commands/merge-bases.ts +296 -0
  439. package/src/commands/merge-command.ts +1386 -491
  440. package/src/commands/merge-config.ts +25 -0
  441. package/src/commands/merge-drivers.ts +306 -0
  442. package/src/commands/merge-support.ts +1198 -0
  443. package/src/commands/message-cleanup.ts +275 -0
  444. package/src/commands/mv-command.ts +976 -0
  445. package/src/commands/notes-command.ts +890 -0
  446. package/src/commands/notes-commands.ts +87 -0
  447. package/src/commands/notes-merge-command.ts +768 -0
  448. package/src/commands/notes-support.ts +402 -0
  449. package/src/commands/notes-tree.ts +602 -0
  450. package/src/commands/object-id-input.ts +27 -0
  451. package/src/commands/octopus-merge.ts +377 -0
  452. package/src/commands/ort-merge.ts +1660 -0
  453. package/src/commands/ort-recursive.ts +160 -0
  454. package/src/commands/pack-refs-command.ts +39 -22
  455. package/src/commands/patch-id.ts +196 -0
  456. package/src/commands/pathspec-attributes.ts +162 -0
  457. package/src/commands/pathspec.ts +1199 -0
  458. package/src/commands/post-index-change.ts +62 -0
  459. package/src/commands/pretty-format.ts +1431 -0
  460. package/src/commands/promisor-remote.ts +298 -0
  461. package/src/commands/pull-command.ts +207 -22
  462. package/src/commands/push-command.ts +236 -23
  463. package/src/commands/read-tree-command.ts +857 -0
  464. package/src/commands/rebase-command.ts +3808 -371
  465. package/src/commands/rebase-todo.ts +584 -0
  466. package/src/commands/ref-decoration-filter.ts +118 -0
  467. package/src/commands/reflog-messages.ts +177 -0
  468. package/src/commands/remote-command.ts +500 -19
  469. package/src/commands/remote-transport.ts +383 -0
  470. package/src/commands/reset-command.ts +828 -91
  471. package/src/commands/restore-command.ts +350 -0
  472. package/src/commands/rev-list-command.ts +167 -0
  473. package/src/commands/rev-parse-command.ts +277 -0
  474. package/src/commands/revert-command.ts +152 -399
  475. package/src/commands/revision-filenames.ts +254 -0
  476. package/src/commands/revision-range.ts +222 -0
  477. package/src/commands/revision-resolver.ts +1379 -0
  478. package/src/commands/rm-command.ts +613 -67
  479. package/src/commands/sequencer-pick.ts +869 -0
  480. package/src/commands/sequencer-support.ts +869 -0
  481. package/src/commands/serve-repository.ts +125 -0
  482. package/src/commands/sparse-checkout-command.ts +1389 -0
  483. package/src/commands/sparse-checkout-support.ts +793 -0
  484. package/src/commands/stash-apply-command.ts +692 -124
  485. package/src/commands/stash-create-command.ts +752 -89
  486. package/src/commands/stash-drop-command.ts +67 -6
  487. package/src/commands/stash-list-command.ts +10 -4
  488. package/src/commands/stash-working-tree.ts +387 -0
  489. package/src/commands/status-command.ts +1426 -97
  490. package/src/commands/status-format.ts +775 -0
  491. package/src/commands/status-header.ts +330 -0
  492. package/src/commands/strerror.ts +29 -0
  493. package/src/commands/submodule-config.ts +94 -0
  494. package/src/commands/submodule-summary-command.ts +334 -0
  495. package/src/commands/submodule-summary.ts +446 -0
  496. package/src/commands/switch-command.ts +402 -0
  497. package/src/commands/tag-command.ts +129 -41
  498. package/src/commands/tracking-info.ts +201 -0
  499. package/src/commands/trailers.ts +417 -0
  500. package/src/commands/tree-restore.ts +344 -15
  501. package/src/commands/untracked-cache-support.ts +194 -0
  502. package/src/commands/worktree-add-command.ts +458 -0
  503. package/src/commands/worktree-list-command.ts +208 -0
  504. package/src/commands/worktree-lock-command.ts +96 -0
  505. package/src/commands/worktree-overwrite-checks.ts +641 -0
  506. package/src/commands/worktree-prune-command.ts +99 -0
  507. package/src/commands/worktree-remove-command.ts +186 -0
  508. package/src/commands/worktree-repair-command.ts +59 -0
  509. package/src/commands/worktree-support.ts +214 -0
  510. package/src/core-commands/add.command.impl.ts +9 -5
  511. package/src/core-commands/index.ts +0 -8
  512. package/src/errors/add-errors.ts +45 -0
  513. package/src/errors/checkout-errors.ts +46 -2
  514. package/src/errors/command-errors.ts +101 -1
  515. package/src/errors/commit-errors.ts +18 -2
  516. package/src/errors/git-api-error.ts +82 -2
  517. package/src/errors/index.ts +1 -0
  518. package/src/errors/merge-errors.ts +2 -2
  519. package/src/errors/rebase-errors.ts +12 -0
  520. package/src/errors/ref-errors.ts +56 -2
  521. package/src/errors/remote-errors.ts +2 -2
  522. package/src/errors/stash-errors.ts +1 -1
  523. package/src/errors/transport-errors.ts +20 -4
  524. package/src/errors/worktree-errors.ts +49 -0
  525. package/src/git-command.ts +1218 -118
  526. package/src/git.ts +552 -11
  527. package/src/index.ts +1 -1
  528. package/src/remote-config/index.ts +1 -0
  529. package/src/remote-config/remote-config-store.ts +326 -16
  530. package/src/remote-config/remote-refs.ts +119 -0
  531. package/src/rename/detect-renames.ts +711 -0
  532. package/src/rename/git-similarity.ts +116 -0
  533. package/src/rename/index.ts +2 -0
  534. package/src/results/binary-patch.ts +401 -0
  535. package/src/results/blame-format.ts +239 -0
  536. package/src/results/cherry-pick-result.ts +10 -0
  537. package/src/results/clone-result.ts +18 -0
  538. package/src/results/combined-diff.ts +585 -0
  539. package/src/results/diff-entry.ts +35 -0
  540. package/src/results/diff-formatter.ts +152 -288
  541. package/src/results/diff-order.ts +64 -0
  542. package/src/results/diff-output.ts +1051 -0
  543. package/src/results/fetch-result.ts +24 -1
  544. package/src/results/index.ts +5 -0
  545. package/src/results/merge-result.ts +15 -1
  546. package/src/results/pull-result.ts +12 -3
  547. package/src/results/push-result.ts +43 -0
  548. package/src/results/quote-path.ts +103 -0
  549. package/src/results/rebase-result.ts +37 -0
  550. package/src/results/revert-result.ts +10 -0
  551. package/src/results/stash-result.ts +6 -0
  552. package/src/results/status-result.ts +288 -27
  553. package/src/transport-command.ts +139 -2
  554. package/dist/commands-BpeXZTC3.js +0 -10278
  555. package/dist/core-commands/checkout.command.d.ts +0 -103
  556. package/dist/core-commands/checkout.command.d.ts.map +0 -1
  557. package/dist/core-commands/checkout.command.impl.d.ts +0 -110
  558. package/dist/core-commands/checkout.command.impl.d.ts.map +0 -1
  559. package/dist/status-result-BapZoQaR.js +0 -411
  560. package/src/core-commands/checkout.command.impl.ts +0 -564
  561. package/src/core-commands/checkout.command.ts +0 -125
@@ -0,0 +1,976 @@
1
+ /**
2
+ * `git mv` (builtin/mv.c): move or rename files, directories and submodules in the worktree
3
+ * and the index together.
4
+ */
5
+ import { FileMode, type ObjectId } from "@statewalker/vcs-core";
6
+ import { compareGitPaths } from "@statewalker/vcs-utils/encoding";
7
+ import {
8
+ attributesIndexOf,
9
+ compareWithWorktree,
10
+ entryStatOf,
11
+ type IndexEntry,
12
+ type Worktree,
13
+ type WorktreeModeTrust,
14
+ } from "@statewalker/vcs-working-tree";
15
+
16
+ import { MvFailedError } from "../errors/index.js";
17
+ import { GitCommand } from "../git-command.js";
18
+ import { worktreeModeTrust } from "./core-config.js";
19
+ import { IndexAdder } from "./index-adder.js";
20
+ import { configBool } from "./merge-config.js";
21
+ import { sparseCheckoutConfig, sparsePathAdvice } from "./sparse-checkout-support.js";
22
+ import { strerror } from "./strerror.js";
23
+ import { parseGitmodules } from "./submodule-config.js";
24
+ import { planFlatRestore, writeTreeRestorePlan } from "./tree-restore.js";
25
+ import {
26
+ removeDirectoryIfEmpty,
27
+ statFollowingLinks,
28
+ statThroughLeadingLinks,
29
+ } from "./worktree-overwrite-checks.js";
30
+
31
+ /** One move `git mv` made (or, with `-n`, would make). */
32
+ export interface MvRename {
33
+ source: string;
34
+ destination: string;
35
+ }
36
+
37
+ /** Result of {@link MvCommand}. */
38
+ export interface MvResult {
39
+ /** The moves made, in git's order (a directory's entries after the directory) */
40
+ renamed: MvRename[];
41
+ /** What git prints on stdout: `Checking rename of ...` (`-n`), `Renaming ...` (`-n`, `-v`) */
42
+ output: string[];
43
+ /**
44
+ * What git prints on stderr without failing: `warning: overwriting '<dst>'` (`-f -v`), the
45
+ * sparse advice with `-k`, the advice on paths moved out of the cone while dirty, the
46
+ * `.gitmodules` warnings
47
+ */
48
+ warnings: string[];
49
+ }
50
+
51
+ // builtin/mv.c's `enum update_mode`
52
+ const WORKING_DIRECTORY = 1 << 1;
53
+ const INDEX = 1 << 2;
54
+ const SPARSE = 1 << 3;
55
+ const SKIP_WORKTREE_DIR = 1 << 4;
56
+ const MOVE_VIA_PARENT_DIR = 1 << 5;
57
+
58
+ /** `submodule_gitfile_path`'s marker for a submodule holding its own `.git` directory. */
59
+ const SUBMODULE_WITH_GITDIR = Symbol("SUBMODULE_WITH_GITDIR");
60
+ type SubmoduleGitfile = string | typeof SUBMODULE_WITH_GITDIR | undefined;
61
+
62
+ /** `needs_worktree_rename`: whether the move renames anything in the worktree. */
63
+ function needsWorktreeRename(mode: number, dstMode: number): boolean {
64
+ return (
65
+ (mode & (INDEX | SPARSE | SKIP_WORKTREE_DIR)) === 0 &&
66
+ (dstMode & (SKIP_WORKTREE_DIR | SPARSE)) === 0
67
+ );
68
+ }
69
+
70
+ /** `add_slash`: `path` with a trailing `/` (the empty path stays empty). */
71
+ function addSlash(path: string): string {
72
+ return path.length > 0 && !path.endsWith("/") ? `${path}/` : path;
73
+ }
74
+
75
+ /** POSIX `basename` of a path without trailing slashes. */
76
+ function basename(path: string): string {
77
+ if (path === "") return ".";
78
+ const at = path.lastIndexOf("/");
79
+ return at < 0 ? path : path.slice(at + 1);
80
+ }
81
+
82
+ /**
83
+ * git's `prefix_path` with the worktree root as prefix (`normalize_path_copy`): `.` and
84
+ * empty components dropped, `..` climbing one, a trailing `/` kept; undefined when the
85
+ * path leaves the worktree.
86
+ */
87
+ function normalizePath(path: string): string | undefined {
88
+ const trailing = path.endsWith("/") && path.replace(/\/+$/, "") !== "";
89
+ const out: string[] = [];
90
+ for (const part of path.split("/")) {
91
+ if (part === "" || part === ".") continue;
92
+ if (part === "..") {
93
+ if (out.length === 0) return undefined;
94
+ out.pop();
95
+ continue;
96
+ }
97
+ out.push(part);
98
+ }
99
+ const joined = out.join("/");
100
+ return trailing && joined ? `${joined}/` : joined;
101
+ }
102
+
103
+ /**
104
+ * Move or rename files, directories and submodules (`git mv`).
105
+ *
106
+ * ```typescript
107
+ * // rename one file
108
+ * await git.mv().addSource("old.txt").setDestination("new.txt").call();
109
+ *
110
+ * // move several paths into a directory, skipping the ones that cannot move
111
+ * await git.mv().addSource("a").addSource("b").setDestination("dir").setSkipErrors(true).call();
112
+ * ```
113
+ *
114
+ * Every check runs first (builtin/mv.c's "Checking" loop): one failing dies with git's
115
+ * `fatal: <reason>, source=<src>, destination=<dst>` before anything moves, unless `-k`
116
+ * passes over it. Then each worktree path is renamed through the worktree (a symbolic link
117
+ * as the link, a directory with everything in it) and its index entries renamed with
118
+ * `rename_index_entry_at`: flags kept, the stat data refreshed only where the file still
119
+ * matches, the cache-tree invalidated at both paths. A submodule's gitfile, `core.worktree`
120
+ * and `.gitmodules` path follow it, `.gitmodules` staged again.
121
+ */
122
+ export class MvCommand extends GitCommand<MvResult> {
123
+ private sources: string[] = [];
124
+ private destination: string | undefined;
125
+ private force = false;
126
+ private skipErrors = false;
127
+ private dryRun = false;
128
+ private verbose = false;
129
+ private sparse = false;
130
+ private compatibility: "2.43" | "2.56" = "2.56";
131
+
132
+ /** A `<source>` (relative to the worktree root, `/` separated). */
133
+ addSource(source: string): this {
134
+ this.checkCallable();
135
+ this.sources.push(source);
136
+ return this;
137
+ }
138
+
139
+ /** The `<destination>`: a new name for one source, or a directory for several. */
140
+ setDestination(destination: string): this {
141
+ this.checkCallable();
142
+ this.destination = destination;
143
+ return this;
144
+ }
145
+
146
+ /** `-f`: a file or link at the destination is overwritten (`warning: overwriting` with `-v`). */
147
+ setForce(force: boolean): this {
148
+ this.checkCallable();
149
+ this.force = force;
150
+ return this;
151
+ }
152
+
153
+ /** `-k`: a source whose move would fail is passed over instead of dying. */
154
+ setSkipErrors(skip: boolean): this {
155
+ this.checkCallable();
156
+ this.skipErrors = skip;
157
+ return this;
158
+ }
159
+
160
+ /** `-n`: tell what would be moved (`Checking rename of`, `Renaming`), change nothing. */
161
+ setDryRun(dryRun: boolean): this {
162
+ this.checkCallable();
163
+ this.dryRun = dryRun;
164
+ return this;
165
+ }
166
+
167
+ /** `-v`: tell each move (`Renaming <src> to <dst>`), and each file overwritten with `-f`. */
168
+ setVerbose(verbose: boolean): this {
169
+ this.checkCallable();
170
+ this.verbose = verbose;
171
+ return this;
172
+ }
173
+
174
+ /**
175
+ * `--sparse`: entries outside the sparse checkout (skip-worktree, or paths out of the
176
+ * patterns) may be moved; in cone mode an entry moved into the cone is checked out and
177
+ * one moved out of it leaves the worktree (kept there, with git's advice, when dirty).
178
+ */
179
+ setSparse(sparse: boolean): this {
180
+ this.checkCallable();
181
+ this.sparse = sparse;
182
+ return this;
183
+ }
184
+
185
+ /**
186
+ * The git version whose behaviour is reproduced where versions differ (default 2.56):
187
+ * 2.43 has no check of the destination's leading directory (the rename fails instead,
188
+ * `renaming '<src>' failed: <reason>`) and gives the advice's older last hint.
189
+ */
190
+ setCompatibility(version: "2.43" | "2.56"): this {
191
+ this.checkCallable();
192
+ this.compatibility = version;
193
+ return this;
194
+ }
195
+
196
+ async call(): Promise<MvResult> {
197
+ this.checkCallable();
198
+ this.setCallable(false);
199
+ if (this.sources.length === 0 || this.destination === undefined) {
200
+ throw new MvFailedError(
201
+ "usage: git mv [-v] [-f] [-n] [-k] <source> <destination>\n" +
202
+ " or: git mv [-v] [-f] [-n] [-k] <source>... <destination-directory>",
203
+ );
204
+ }
205
+ await this.readCurrentIndex();
206
+ const worktree = this.worktreeAccess;
207
+ if (!worktree) throw new MvFailedError("fatal: this operation must be run in a work tree");
208
+
209
+ const result: MvResult = { renamed: [], output: [], warnings: [] };
210
+ const die = (message: string): never => {
211
+ throw new MvFailedError([...result.warnings, `fatal: ${message}`].join("\n"), result);
212
+ };
213
+ // git names the worktree's top as the host does (an absolute path)
214
+ const top =
215
+ (worktree as { hostPath?: string }).hostPath?.replace(/(.)\/+$/, "$1") ?? worktree.getRoot();
216
+ const normalized = (path: string) =>
217
+ normalizePath(path) ?? die(`'${path}' is outside repository at '${top}'`);
218
+ const lstat = (path: string) => worktree.getEntry(path).catch(() => undefined);
219
+ // lstat(2) of a path with a trailing slash, or of one beneath a symbolic link, follows
220
+ // the links (`ld/` names the directory `ld` points to)
221
+ const lstatFollowing = async (path: string) => {
222
+ const bare = path.replace(/\/+$/, "");
223
+ if (bare !== path) return statFollowingLinks(worktree, bare);
224
+ const found = await lstat(path);
225
+ if (found) return found;
226
+ const through = await statThroughLeadingLinks(worktree, path);
227
+ return through?.entry;
228
+ };
229
+ // is_directory: stat(2), following links
230
+ const isDirectory = async (path: string) =>
231
+ (await statFollowingLinks(worktree, path.replace(/\/+$/, "")))?.isDirectory === true;
232
+
233
+ const cache = await this.indexEntries();
234
+ const namePos = (name: string) => indexNamePos(cache, name);
235
+ const patterns = await this.sparseCheckoutPatterns();
236
+ const inSparse = (path: string) => !path || !patterns || patterns.includes(path);
237
+ const inCone = (path: string) => !path || !patterns?.cone || inSparse(path);
238
+ const ignoreCase = configBool(this.workingCopy, "core.ignoreCase", false);
239
+ const fold = (p: string) => (ignoreCase ? p.toLowerCase() : p);
240
+ const emptyDirHasSparseContents = (name: string) => {
241
+ const withSlash = addSlash(name);
242
+ let pos = namePos(withSlash);
243
+ if (pos >= 0) return false;
244
+ pos = -pos - 1;
245
+ const ce = cache[pos];
246
+ return ce?.path.startsWith(withSlash) === true && ce.skipWorktree === true;
247
+ };
248
+ const indexRangeOfSameDir = (src: string): [number, number] => {
249
+ const withSlash = addSlash(src);
250
+ let first = namePos(withSlash);
251
+ if (first >= 0) die(`${withSlash} is in index`);
252
+ first = -1 - first;
253
+ let last = first;
254
+ while (last < cache.length && (cache[last] as IndexEntry).path.startsWith(withSlash)) last++;
255
+ return [first, last];
256
+ };
257
+
258
+ // internal_prefix_pathspec: sources without trailing slashes; the destination keeps its
259
+ // own unless one directory moves to a name that is no directory
260
+ const argv = this.sources;
261
+ let argc = argv.length;
262
+ const sources = argv.map((a) => normalized(a.replace(/\/+$/, "")));
263
+ const keepSlash = !(
264
+ argc === 1 &&
265
+ (await isDirectory(sources[0] as string)) &&
266
+ !(await isDirectory(normalized(this.destination)))
267
+ );
268
+ const destPath = normalized(
269
+ keepSlash ? this.destination : this.destination.replace(/\/+$/, ""),
270
+ );
271
+ const dstWithSlash = addSlash(destPath);
272
+ const intoDir = (prefix: string) =>
273
+ argv.map((a) => normalized(`${prefix}${basename(a.replace(/\/+$/, ""))}`));
274
+ let destinations: string[];
275
+ let dstMode = 0;
276
+ // git's `struct stat st`, shared by several lstat calls: a failing one leaves it as the
277
+ // last successful one left it (a skip-worktree directory as source relies on it)
278
+ let lastStat: { isDirectory: boolean } | undefined;
279
+ const lstatSt = async (path: string) => {
280
+ const found = await lstatFollowing(path);
281
+ if (found) lastStat = found;
282
+ return found;
283
+ };
284
+ if (destPath === "") destinations = intoDir("");
285
+ else if ((await lstatSt(destPath))?.isDirectory) destinations = intoDir(dstWithSlash);
286
+ else if (!inSparse(dstWithSlash) && emptyDirHasSparseContents(dstWithSlash)) {
287
+ destinations = intoDir(dstWithSlash);
288
+ dstMode = SKIP_WORKTREE_DIR;
289
+ } else if (argc !== 1) {
290
+ return die(`destination '${destPath}' is not a directory`);
291
+ } else {
292
+ destinations = [destPath];
293
+ if (!inCone(destPath)) dstMode = SPARSE;
294
+ }
295
+
296
+ const modes: number[] = argv.map(() => 0);
297
+ const gitfiles: SubmoduleGitfile[] = argv.map(() => undefined);
298
+ const srcForDst = new Set<string>();
299
+ const onlyMatchSkipWorktree: string[] = [];
300
+ const movedDirs = new Set<string>();
301
+ const srcDirs: string[] = [];
302
+ /** The repository of each submodule with a gitfile, found before anything moves */
303
+ const gitDirs = new Map<string, string>();
304
+ const trust = worktreeModeTrust(this.workingCopy, worktree);
305
+ const indexTime = this.staging.getUpdateTime();
306
+
307
+ for (let i = 0; i < argc; i++) {
308
+ const src = sources[i] as string;
309
+ const dst = destinations[i] as string;
310
+ let bad: string | undefined;
311
+ let skipSparse = false;
312
+ let removeEntry = false;
313
+ if (this.dryRun) result.output.push(`Checking rename of '${src}' to '${dst}'`);
314
+ const st = await lstatSt(src);
315
+ const check = async (): Promise<void> => {
316
+ let srcIsDir = st?.isDirectory === true;
317
+ if (!st) {
318
+ const pos = namePos(src);
319
+ if (pos < 0) {
320
+ if (!inSparse(addSlash(src)) && emptyDirHasSparseContents(src)) {
321
+ modes[i] = (modes[i] as number) | SKIP_WORKTREE_DIR;
322
+ // S_ISDIR(st.st_mode) of whatever lstat filled in last; where none did, git
323
+ // reads a stat nothing filled in, almost always no directory ("not under
324
+ // version control" on 2.43 and 2.5x alike; rarely a directory, moving it)
325
+ srcIsDir = lastStat ? lastStat.isDirectory : false;
326
+ return dirCheck(srcIsDir);
327
+ }
328
+ if (!((modes[i] as number) & SPARSE)) bad = "bad source";
329
+ return;
330
+ }
331
+ const ce = cache[pos] as IndexEntry;
332
+ if (!ce.skipWorktree) {
333
+ bad = "bad source";
334
+ return;
335
+ }
336
+ if (!this.sparse) {
337
+ onlyMatchSkipWorktree.push(src);
338
+ return;
339
+ }
340
+ if (namePos(dst) < 0) {
341
+ modes[i] = (modes[i] as number) | SPARSE;
342
+ return;
343
+ }
344
+ if (!this.force) {
345
+ bad = "destination exists";
346
+ return;
347
+ }
348
+ modes[i] = (modes[i] as number) | SPARSE;
349
+ return;
350
+ }
351
+ if (dst.startsWith(src) && (dst.length === src.length || dst[src.length] === "/")) {
352
+ bad = "can not move directory into itself";
353
+ return;
354
+ }
355
+ if (st.isDirectory && (await lstatFollowing(dst))) {
356
+ bad = "destination already exists";
357
+ return;
358
+ }
359
+ return dirCheck(srcIsDir);
360
+ };
361
+ const dirCheck = async (srcIsDir: boolean): Promise<void> => {
362
+ if (srcIsDir) {
363
+ const first = namePos(src);
364
+ if (first >= 0) {
365
+ const gitfile = await this.submoduleGitfilePath(
366
+ worktree,
367
+ src,
368
+ cache[first] as IndexEntry,
369
+ );
370
+ gitfiles[i] = gitfile;
371
+ if (gitfile && gitfile !== SUBMODULE_WITH_GITDIR && worktree.gitlinkRepository) {
372
+ // connect_work_tree_and_git_dir rewrites the gitfile and the repository's
373
+ // core.worktree after the move: refused now when that repository cannot be
374
+ // reached, rather than leave the submodule broken
375
+ const gitDir = await worktree.gitlinkRepository(src);
376
+ if (gitDir === null) {
377
+ die(
378
+ `cannot update the repository of submodule '${src}' ('${gitfile}'): it lies outside the files this worktree reaches`,
379
+ );
380
+ }
381
+ if (gitDir) gitDirs.set(src, gitDir);
382
+ }
383
+ return;
384
+ }
385
+ const [from, to] = indexRangeOfSameDir(src);
386
+ if (to - from < 1) {
387
+ bad = "source directory is empty";
388
+ return;
389
+ }
390
+ movedDirs.add(fold(src));
391
+ modes[i] = (modes[i] as number) | WORKING_DIRECTORY;
392
+ srcDirs.push(src);
393
+ const dstSlash = addSlash(dst);
394
+ for (let j = from; j < to; j++) {
395
+ const ce = cache[j] as IndexEntry;
396
+ sources.push(ce.path);
397
+ destinations.push(normalized(`${dstSlash}${ce.path.slice(src.length + 1)}`));
398
+ modes.push(MOVE_VIA_PARENT_DIR | (ce.skipWorktree ? SPARSE : INDEX));
399
+ gitfiles.push(undefined);
400
+ }
401
+ argc += to - from;
402
+ return;
403
+ }
404
+ const anyStage = cache.find((e) => e.path === src);
405
+ if (!anyStage) {
406
+ bad = "not under version control";
407
+ return;
408
+ }
409
+ if (anyStage.stage !== 0 && !cache.some((e) => e.path === src && e.stage === 0)) {
410
+ bad = "conflicted";
411
+ return;
412
+ }
413
+ const dstStat = await lstatSt(dst);
414
+ if (dstStat && (!ignoreCase || src.toLowerCase() !== dst.toLowerCase())) {
415
+ bad = "destination exists";
416
+ if (this.force) {
417
+ // only files can overwrite each other
418
+ if (!dstStat.isDirectory) {
419
+ if (this.verbose) result.warnings.push(`warning: overwriting '${dst}'`);
420
+ bad = undefined;
421
+ } else bad = "Cannot overwrite";
422
+ }
423
+ return;
424
+ }
425
+ if (srcForDst.has(dst)) {
426
+ bad = "multiple sources for the same target";
427
+ return;
428
+ }
429
+ if (dst.endsWith("/")) {
430
+ bad = "destination directory does not exist";
431
+ return;
432
+ }
433
+ if (this.compatibility !== "2.43" && (await hasSymlinkLeadingPath(worktree, dst))) {
434
+ bad = "destination is beyond a symbolic link";
435
+ return;
436
+ }
437
+ if (this.compatibility !== "2.43" && needsWorktreeRename(modes[i] as number, dstMode)) {
438
+ const slash = dst.lastIndexOf("/");
439
+ if (slash >= 0) {
440
+ const dir = dst.slice(0, slash);
441
+ const dirStat = await lstat(dir);
442
+ if (!dirStat) {
443
+ // ENOENT or ENOTDIR (a file among the leading components)
444
+ bad = "destination directory does not exist";
445
+ } else if (!dirStat.isDirectory) bad = "destination is not a directory";
446
+ if (bad) return;
447
+ }
448
+ }
449
+ if (
450
+ this.sparse &&
451
+ dstMode & (SKIP_WORKTREE_DIR | SPARSE) &&
452
+ cache.some((e) => e.path === dst)
453
+ ) {
454
+ bad = "destination exists in the index";
455
+ if (!this.force) return;
456
+ if (this.verbose) result.warnings.push(`warning: overwriting '${dst}'`);
457
+ bad = undefined;
458
+ }
459
+ // the sparse checks last, so the advice can point at --sparse
460
+ if (!this.sparse && !inSparse(src)) {
461
+ onlyMatchSkipWorktree.push(src);
462
+ skipSparse = true;
463
+ }
464
+ if (!this.sparse && !inSparse(dst)) {
465
+ onlyMatchSkipWorktree.push(dst);
466
+ skipSparse = true;
467
+ }
468
+ if (skipSparse) {
469
+ removeEntry = true;
470
+ return;
471
+ }
472
+ srcForDst.add(dst);
473
+ };
474
+ await check();
475
+ if (!removeEntry) {
476
+ if (!bad) continue;
477
+ if (!this.skipErrors) die(`${bad}, source=${src}, destination=${dst}`);
478
+ }
479
+ // remove_entry
480
+ if (--argc > 0) {
481
+ sources.splice(i, 1);
482
+ destinations.splice(i, 1);
483
+ modes.splice(i, 1);
484
+ gitfiles.splice(i, 1);
485
+ i--;
486
+ }
487
+ }
488
+
489
+ // a path moved together with one of its parent directories (2.5x; 2.43 moves the
490
+ // directory, then fails renaming the path, or aborts on an assertion)
491
+ for (let i = 0; i < argc && this.compatibility !== "2.43"; i++) {
492
+ if ((modes[i] as number) & MOVE_VIA_PARENT_DIR) continue;
493
+ const src = sources[i] as string;
494
+ for (let at = src.lastIndexOf("/"); at > 0; at = src.lastIndexOf("/", at - 1)) {
495
+ const parent = src.slice(0, at);
496
+ if (movedDirs.has(fold(parent))) {
497
+ die(`cannot move both '${src}' and its parent directory '${parent}'`);
498
+ }
499
+ }
500
+ }
501
+
502
+ if (onlyMatchSkipWorktree.length > 0) {
503
+ const advice = sparsePathAdvice(
504
+ onlyMatchSkipWorktree,
505
+ configBool(this.workingCopy, "advice.updateSparsePath", true),
506
+ this.compatibility,
507
+ );
508
+ result.warnings.push(...advice);
509
+ if (!this.skipErrors) throw new MvFailedError(result.warnings.join("\n"), result);
510
+ }
511
+
512
+ // the moves
513
+ const sparseConfig = sparseCheckoutConfig(this.workingCopy);
514
+ const adder = await IndexAdder.open(this.staging, this.blobs, trust);
515
+ const current = new Map<string, IndexEntry>();
516
+ for (const e of cache) if (e.stage === 0) current.set(e.path, e);
517
+ const dirtyPaths: string[] = [];
518
+ let gitmodulesModified = false;
519
+ let changed = false;
520
+ for (let i = 0; i < argc; i++) {
521
+ const src = sources[i] as string;
522
+ const dst = destinations[i] as string;
523
+ const mode = modes[i] as number;
524
+ if (this.dryRun || this.verbose) result.output.push(`Renaming ${src} to ${dst}`);
525
+ if (this.dryRun) continue;
526
+ const gitfile = gitfiles[i];
527
+ const gitDir = gitfile && gitfile !== SUBMODULE_WITH_GITDIR ? gitDirs.get(src) : undefined;
528
+ if (needsWorktreeRename(mode, dstMode)) {
529
+ try {
530
+ await renamePath(worktree, src, dst);
531
+ } catch (error) {
532
+ if (this.skipErrors) continue;
533
+ // die_errno: the index lock is rolled back, the moves made so far stay unrecorded
534
+ die(
535
+ this.compatibility === "2.43"
536
+ ? `renaming '${src}' failed: ${strerror(error)}`
537
+ : `renaming '${src}' to '${dst}' failed: ${strerror(error)}`,
538
+ );
539
+ }
540
+ }
541
+ result.renamed.push({ source: src, destination: dst });
542
+ if (gitfile) {
543
+ if (await this.updatePathInGitmodules(worktree, src, dst, result.warnings)) {
544
+ gitmodulesModified = true;
545
+ }
546
+ if (gitDir !== undefined) await worktree.connectGitlink?.(dst, gitDir);
547
+ }
548
+ if (mode & (WORKING_DIRECTORY | SKIP_WORKTREE_DIR)) continue;
549
+
550
+ const old = current.get(src);
551
+ if (!old) die(`BUG: could not find source in index: '${src}'`);
552
+ const entry = old as IndexEntry;
553
+ let sparseAndDirty = false;
554
+ if (!(mode & SPARSE)) {
555
+ const at = await lstat(src);
556
+ if (at) sparseAndDirty = await entryModified(worktree, entry, trust, indexTime);
557
+ }
558
+ // rename_index_entry_at: flags kept; refresh_cache_entry takes the new file's stat
559
+ // only while the content still matches (a gitlink's never: ie_match_stat compares its
560
+ // type and HEAD alone, so its stat data stays as it was)
561
+ let moved: IndexEntry = { ...entry, path: dst };
562
+ if (
563
+ !entry.skipWorktree &&
564
+ !entry.assumeValid &&
565
+ !entry.intentToAdd &&
566
+ entry.mode !== FileMode.GITLINK
567
+ ) {
568
+ const file = await lstat(dst);
569
+ if (file && !(await entryModified(worktree, moved, trust, indexTime, true))) {
570
+ moved = { ...moved, ...entryStatOf(file) };
571
+ }
572
+ }
573
+ let checkout = false;
574
+ if (this.sparse && sparseConfig.enabled && sparseConfig.cone) {
575
+ if (mode & SPARSE && inSparse(dst)) {
576
+ // from out-of-cone to in-cone: checked out (checkout_entry, forced only with -f:
577
+ // without it a file already there stops the move before the index is written)
578
+ moved = { ...moved, skipWorktree: false };
579
+ if (!this.force && (await lstat(dst))) {
580
+ result.warnings.push(`${dst} already exists, no checkout`);
581
+ die(`cannot checkout ${dst}`);
582
+ }
583
+ checkout = true;
584
+ } else if (dstMode & (SKIP_WORKTREE_DIR | SPARSE) && !(mode & SPARSE) && !inSparse(dst)) {
585
+ // from in-cone to out-of-cone
586
+ if (!sparseAndDirty) {
587
+ moved = { ...moved, skipWorktree: true };
588
+ await worktree.remove(src).catch((error) => {
589
+ result.warnings.push(`warning: unable to unlink '${src}': ${strerror(error)}`);
590
+ });
591
+ } else {
592
+ dirtyPaths.push(dst);
593
+ const slash = dst.lastIndexOf("/");
594
+ if (slash > 0) await worktree.mkdir(dst.slice(0, slash), { recursive: true });
595
+ await renamePath(worktree, src, dst).catch(() => undefined);
596
+ }
597
+ }
598
+ }
599
+ if (moved.skipWorktree === false) {
600
+ const { skipWorktree: _drop, ...rest } = moved;
601
+ moved = rest;
602
+ }
603
+ current.delete(src);
604
+ current.set(dst, moved);
605
+ adder.remove(src);
606
+ adder.put(moved);
607
+ changed = true;
608
+ if (checkout) await this.checkoutEntries(worktree, [moved], current, trust);
609
+ }
610
+
611
+ // remove_empty_src_dirs
612
+ if (!this.dryRun) {
613
+ for (const dir of srcDirs) {
614
+ const prefix = `${dir}/`;
615
+ let has = false;
616
+ for (const p of current.keys()) {
617
+ if (p.startsWith(prefix)) {
618
+ has = true;
619
+ break;
620
+ }
621
+ }
622
+ if (!has && (await lstat(dir))) await worktree.remove(dir, { recursive: true });
623
+ }
624
+ }
625
+
626
+ if (dirtyPaths.length > 0) {
627
+ result.warnings.push(
628
+ "The following paths have been moved outside the",
629
+ "sparse-checkout definition but are not sparse due to local",
630
+ "modifications.",
631
+ ...dirtyPaths,
632
+ );
633
+ if (configBool(this.workingCopy, "advice.updateSparsePath", true)) {
634
+ result.warnings.push(
635
+ "hint: To correct the sparsity of these paths, do the following:",
636
+ 'hint: * Use "git add --sparse <paths>" to update the index',
637
+ 'hint: * Use "git sparse-checkout reapply" to apply the sparsity rules',
638
+ `hint: Disable this message with "${this.compatibility === "2.43" ? "git config" : "git config set"} advice.updateSparsePath false"`,
639
+ );
640
+ }
641
+ }
642
+ if (changed || gitmodulesModified) {
643
+ await this.writeMoves(adder, worktree, gitmodulesModified);
644
+ }
645
+ return result;
646
+ }
647
+
648
+ /** The index's entries in its order. */
649
+ private async indexEntries(): Promise<IndexEntry[]> {
650
+ const list = this.staging.entryList?.();
651
+ if (list) return [...list];
652
+ const out: IndexEntry[] = [];
653
+ for await (const e of this.staging.entries()) out.push(e);
654
+ return out;
655
+ }
656
+
657
+ /** `stage_updated_gitmodules` when needed, then the index written. */
658
+ private async writeMoves(
659
+ adder: IndexAdder,
660
+ worktree: Worktree,
661
+ gitmodulesModified: boolean,
662
+ ): Promise<void> {
663
+ if (gitmodulesModified) {
664
+ const entry = await worktree.getEntry(".gitmodules");
665
+ if (entry && !entry.isDirectory) await adder.add(worktree, ".gitmodules", entry);
666
+ }
667
+ await adder.finish();
668
+ await this.staging.write();
669
+ }
670
+
671
+ /** `checkout_entry` (forced) of the entries moved into the sparse cone. */
672
+ private async checkoutEntries(
673
+ worktree: Worktree,
674
+ entries: IndexEntry[],
675
+ index: Map<string, IndexEntry>,
676
+ trust: WorktreeModeTrust,
677
+ ): Promise<void> {
678
+ const target = new Map<string, { objectId: ObjectId; mode: number }>();
679
+ for (const e of entries) target.set(e.path, e);
680
+ const plan = await planFlatRestore(this.blobs, target, new Set(target.keys()), "mv", {
681
+ symlinks: true,
682
+ windows: worktree.capabilities?.windowsPaths === true,
683
+ reservedNames: worktree.capabilities?.reservedNames,
684
+ });
685
+ const attributes = new Map<string, ObjectId>();
686
+ for (const [path, e] of index)
687
+ if (path.endsWith(".gitattributes")) attributes.set(path, e.objectId);
688
+ await writeTreeRestorePlan(worktree, this.blobs, plan, "mv", {
689
+ symlinks: trust.symlinks,
690
+ gitlinks: true,
691
+ replaceInTheWay: true,
692
+ discardUntracked: true,
693
+ attributes: { direction: "checkout", index: attributesIndexOf(attributes) },
694
+ });
695
+ }
696
+
697
+ /**
698
+ * `submodule_gitfile_path`: the repository of the submodule at `src` (its gitfile's
699
+ * target, relative to the worktree root), or {@link SUBMODULE_WITH_GITDIR}; dies on a
700
+ * directory the index holds as no submodule, and on unstaged `.gitmodules` changes.
701
+ */
702
+ private async submoduleGitfilePath(
703
+ worktree: Worktree,
704
+ src: string,
705
+ entry: IndexEntry,
706
+ ): Promise<SubmoduleGitfile> {
707
+ if (entry.mode !== FileMode.GITLINK) {
708
+ throw new MvFailedError(`fatal: Directory ${src} is in index and no submodule?`);
709
+ }
710
+ if (!(await this.stagingGitmodulesOk(worktree))) {
711
+ throw new MvFailedError(
712
+ "fatal: Please stage your changes to .gitmodules or stash them to proceed",
713
+ );
714
+ }
715
+ const dotGit = await worktree.getEntry(`${src}/.git`).catch(() => undefined);
716
+ if (!dotGit || dotGit.isDirectory) return SUBMODULE_WITH_GITDIR;
717
+ const text = await readText(worktree, `${src}/.git`);
718
+ const m = /^gitdir: (.*?)\s*$/m.exec(text);
719
+ if (!m?.[1]) return SUBMODULE_WITH_GITDIR;
720
+ const target = m[1];
721
+ if (target.startsWith("/")) return target;
722
+ // relative to the submodule: as a path from the worktree's top (it may climb out)
723
+ const out: string[] = [];
724
+ for (const part of `${src}/${target}`.split("/")) {
725
+ if (part === "" || part === ".") continue;
726
+ if (part === ".." && out.length > 0 && out[out.length - 1] !== "..") out.pop();
727
+ else out.push(part);
728
+ }
729
+ return out.join("/") || ".";
730
+ }
731
+
732
+ /** `is_staging_gitmodules_ok`: `.gitmodules` holds no change the index does not. */
733
+ private async stagingGitmodulesOk(worktree: Worktree): Promise<boolean> {
734
+ const entry = await this.staging.getEntry(".gitmodules");
735
+ if (!entry) return true;
736
+ const file = await worktree.getEntry(".gitmodules").catch(() => undefined);
737
+ if (!file || file.isDirectory) return true;
738
+ const compared = await compareWithWorktree(worktree, entry, {
739
+ trust: worktreeModeTrust(this.workingCopy, worktree),
740
+ indexTime: this.staging.getUpdateTime(),
741
+ }).catch(() => undefined);
742
+ if (compared?.kind !== "modified") return true;
743
+ const id = compared.hashedId ?? (await worktree.computeHash(".gitmodules"));
744
+ return id === entry.objectId;
745
+ }
746
+
747
+ /**
748
+ * `update_path_in_gitmodules`: the `path` of the `.gitmodules` section naming `oldPath`
749
+ * set to `newPath` (the line rewritten as `git config` writes it). Returns whether the
750
+ * file changed; nothing without a `.gitmodules`, git's warning without a section.
751
+ */
752
+ private async updatePathInGitmodules(
753
+ worktree: Worktree,
754
+ oldPath: string,
755
+ newPath: string,
756
+ warnings: string[],
757
+ ): Promise<boolean> {
758
+ const file = await worktree.getEntry(".gitmodules").catch(() => undefined);
759
+ if (!file || file.isDirectory) return false;
760
+ for await (const e of this.staging.entries()) {
761
+ if (e.path === ".gitmodules" && e.stage !== 0) {
762
+ throw new MvFailedError(
763
+ "fatal: Cannot change unmerged .gitmodules, resolve merge conflicts first",
764
+ );
765
+ }
766
+ }
767
+ const text = await readText(worktree, ".gitmodules");
768
+ const declared = parseGitmodules(text).filter((s) => s.path === oldPath);
769
+ const submodule = declared[declared.length - 1];
770
+ if (!submodule) {
771
+ warnings.push(`warning: Could not find section in .gitmodules where path=${oldPath}`);
772
+ return false;
773
+ }
774
+ const updated = setGitmodulesPath(text, submodule.name, newPath);
775
+ if (updated === undefined) return false;
776
+ await worktree.writeContent(".gitmodules", new TextEncoder().encode(updated), { raw: true });
777
+ return true;
778
+ }
779
+ }
780
+
781
+ /** `index_name_pos`: the position of `name` at stage 0, or `-(insertion point) - 1`. */
782
+ function indexNamePos(cache: readonly IndexEntry[], name: string): number {
783
+ let lo = 0;
784
+ let hi = cache.length;
785
+ while (lo < hi) {
786
+ const mid = (lo + hi) >>> 1;
787
+ const e = cache[mid] as IndexEntry;
788
+ const c = compareGitPaths(e.path, name) || e.stage;
789
+ if (c === 0) return mid;
790
+ if (c < 0) lo = mid + 1;
791
+ else hi = mid;
792
+ }
793
+ return -lo - 1;
794
+ }
795
+
796
+ /**
797
+ * `ie_modified` of an index entry against its file: the content (or mode) differs. An
798
+ * intent-to-add entry always differs (`ie_match_stat`), unless `refresh` asks as
799
+ * `refresh_cache_entry` does for an entry it may take a new stat for.
800
+ */
801
+ async function entryModified(
802
+ worktree: Worktree,
803
+ entry: IndexEntry,
804
+ trust: WorktreeModeTrust,
805
+ indexTime: number,
806
+ refresh = false,
807
+ ): Promise<boolean> {
808
+ if (entry.intentToAdd && !refresh) return true;
809
+ const compared = await compareWithWorktree(worktree, entry, { trust, indexTime }).catch(
810
+ () => undefined,
811
+ );
812
+ return compared === undefined || compared.kind !== undefined;
813
+ }
814
+
815
+ /** `has_symlink_leading_path`: a leading directory of `path` is a symbolic link. */
816
+ async function hasSymlinkLeadingPath(worktree: Worktree, path: string): Promise<boolean> {
817
+ const parts = path.split("/");
818
+ for (let k = 1; k < parts.length; k++) {
819
+ const entry = await worktree.getEntry(parts.slice(0, k).join("/")).catch(() => undefined);
820
+ if (!entry) return (await statThroughLeadingLinks(worktree, path)) !== undefined;
821
+ if (entry.mode === FileMode.SYMLINK) return true;
822
+ if (!entry.isDirectory) return false;
823
+ }
824
+ return false;
825
+ }
826
+
827
+ /**
828
+ * `rename(2)` through the worktree: a link moves as the link, a directory with everything
829
+ * in it. A worktree without rename copies the file and removes the original. A destination
830
+ * that is the source itself (a case-only rename where the filesystem folds case, or the
831
+ * same file under another name) is never removed first: the entry is renamed directly, as
832
+ * git's `rename` does; a directory moved beneath itself fails (`EINVAL`): one of the
833
+ * destination's leading directories is the source (the same path, the same inode where the
834
+ * worktree reports one, or a case variant the filesystem folds onto it: `core.ignoreCase`
835
+ * alone folds nothing, as on a case-sensitive filesystem `D` and `d` are two). A file at the
836
+ * destination is replaced by the rename itself, atomically as `rename(2)` does, so a move
837
+ * that fails leaves it in place; only a worktree without rename removes it first. An empty
838
+ * directory at the destination is removed first (never one holding anything: `ENOTEMPTY`).
839
+ */
840
+ async function renamePath(worktree: Worktree, src: string, dst: string): Promise<void> {
841
+ const fail = (code: string): never => {
842
+ throw Object.assign(new Error(code), { code });
843
+ };
844
+ const source = await worktree.getEntry(src).catch(() => undefined);
845
+ if (!source) fail("ENOENT");
846
+ const sameInode = (other: { ino?: number; dev?: number } | undefined) =>
847
+ other !== undefined &&
848
+ source?.ino !== undefined &&
849
+ source.ino !== 0 &&
850
+ source.ino === other.ino &&
851
+ source.dev === other.dev;
852
+ if (source?.isDirectory) {
853
+ for (let at = dst.lastIndexOf("/"); at > 0; at = dst.lastIndexOf("/", at - 1)) {
854
+ const ancestor = dst.slice(0, at);
855
+ if (ancestor === src || (await sameEntryByCase(worktree, ancestor, src))) fail("EINVAL");
856
+ if (sameInode(await worktree.getEntry(ancestor).catch(() => undefined))) fail("EINVAL");
857
+ }
858
+ }
859
+ // rename(2) creates no leading directory: ENOENT for a missing one, ENOTDIR for a file
860
+ // (a link included) among them
861
+ const slash = dst.lastIndexOf("/");
862
+ if (slash > 0) {
863
+ const parent = await worktree.getEntry(dst.slice(0, slash)).catch(() => undefined);
864
+ if (!parent) {
865
+ const through = await statThroughLeadingLinks(worktree, `${dst.slice(0, slash)}/x`);
866
+ fail(through === undefined ? "ENOENT" : "ENOTDIR");
867
+ } else if (!parent.isDirectory) fail("ENOTDIR");
868
+ }
869
+ const target = await worktree.getEntry(dst).catch(() => undefined);
870
+ const sameEntry =
871
+ target !== undefined &&
872
+ (src === dst || sameInode(target) || (await sameEntryByCase(worktree, src, dst)));
873
+ const canRename = typeof worktree.rename === "function";
874
+ if (target && !sameEntry) {
875
+ if (target.isDirectory) {
876
+ // rename(2) of a directory over an empty one replaces it; anything else fails
877
+ if (!source?.isDirectory) fail("EISDIR");
878
+ if (!(await removeDirectoryIfEmpty(worktree, dst).catch(() => false))) fail("ENOTEMPTY");
879
+ } else if (source?.isDirectory) {
880
+ fail("ENOTDIR");
881
+ } else if (!canRename) {
882
+ await worktree.remove(dst);
883
+ }
884
+ }
885
+ if (canRename) {
886
+ await worktree.rename(src, dst);
887
+ return;
888
+ }
889
+ if (sameEntry) fail("EINVAL");
890
+ const chunks: Uint8Array[] = [];
891
+ for await (const chunk of worktree.readContent(src)) chunks.push(chunk);
892
+ await worktree.writeContent(dst, concat(chunks), { raw: true });
893
+ await worktree.remove(src);
894
+ }
895
+
896
+ /**
897
+ * Whether `a` and `b`, two spellings of one path that differ in case only, name one entry
898
+ * (the filesystem folds case): each differing component's directory lists only one of the
899
+ * two names. A directory never lists one entry twice, so where both are listed (a
900
+ * case-sensitive filesystem holding `D` and `d`) they are two.
901
+ */
902
+ async function sameEntryByCase(worktree: Worktree, a: string, b: string): Promise<boolean> {
903
+ const pa = a.split("/");
904
+ const pb = b.split("/");
905
+ if (a === b || pa.length !== pb.length || a.toLowerCase() !== b.toLowerCase()) return false;
906
+ for (let k = 0; k < pa.length; k++) {
907
+ const na = pa[k] as string;
908
+ const nb = pb[k] as string;
909
+ if (na === nb) continue;
910
+ const parent = pa.slice(0, k).join("/");
911
+ const listed = new Set<string>();
912
+ const inside = worktree.walk({
913
+ ...(parent ? { pathPrefix: parent } : {}),
914
+ includeIgnored: true,
915
+ includeDirectories: true,
916
+ maxDepth: 0,
917
+ });
918
+ try {
919
+ for await (const entry of inside) {
920
+ const name = parent ? entry.path.slice(parent.length + 1) : entry.path;
921
+ if (!name.includes("/")) listed.add(name);
922
+ }
923
+ } catch {
924
+ return false;
925
+ }
926
+ if (listed.has(na) && listed.has(nb)) return false;
927
+ }
928
+ return true;
929
+ }
930
+
931
+ /**
932
+ * `git config -f .gitmodules submodule.<name>.path <value>`: the `path` line of the last
933
+ * section of that name replaced by `\tpath = <value>` (quoted and escaped as git writes it).
934
+ */
935
+ function setGitmodulesPath(text: string, name: string, value: string): string | undefined {
936
+ const lines = text.split(/(?<=\n)/);
937
+ let inSection = false;
938
+ let at = -1;
939
+ for (let i = 0; i < lines.length; i++) {
940
+ const line = lines[i] as string;
941
+ const trimmed = line.trimStart();
942
+ if (trimmed.startsWith("[")) {
943
+ const m = /^\[\s*submodule\s+"((?:[^"\\]|\\.)*)"\s*\]/i.exec(trimmed);
944
+ inSection = m !== null && m[1]?.replace(/\\(.)/g, "$1") === name;
945
+ continue;
946
+ }
947
+ if (inSection && /^\s*path\s*(=|$)/i.test(line)) at = i;
948
+ }
949
+ if (at < 0) return undefined;
950
+ const quote = /^\s|\s$|[;#]/.test(value) ? '"' : "";
951
+ const escaped = value
952
+ .replace(/\\/g, "\\\\")
953
+ .replace(/"/g, '\\"')
954
+ .replace(/\n/g, "\\n")
955
+ .replace(/\t/g, "\\t");
956
+ lines[at] = `\tpath = ${quote}${escaped}${quote}\n`;
957
+ return lines.join("");
958
+ }
959
+
960
+ async function readText(worktree: Worktree, path: string): Promise<string> {
961
+ const chunks: Uint8Array[] = [];
962
+ for await (const chunk of worktree.readContent(path)) chunks.push(chunk);
963
+ return new TextDecoder().decode(concat(chunks));
964
+ }
965
+
966
+ function concat(chunks: Uint8Array[]): Uint8Array {
967
+ let size = 0;
968
+ for (const c of chunks) size += c.length;
969
+ const out = new Uint8Array(size);
970
+ let at = 0;
971
+ for (const c of chunks) {
972
+ out.set(c, at);
973
+ at += c.length;
974
+ }
975
+ return out;
976
+ }