@statewalker/vcs-commands 0.5.0 → 0.7.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 +300 -18
  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 +49 -16
  67. package/dist/commands/clean-command.d.ts.map +1 -1
  68. package/dist/commands/clone-command.d.ts +134 -0
  69. package/dist/commands/clone-command.d.ts.map +1 -1
  70. package/dist/commands/comment-char-config.d.ts +35 -0
  71. package/dist/commands/comment-char-config.d.ts.map +1 -0
  72. package/dist/commands/commit-command.d.ts +311 -17
  73. package/dist/commands/commit-command.d.ts.map +1 -1
  74. package/dist/commands/core-config.d.ts +78 -1
  75. package/dist/commands/core-config.d.ts.map +1 -1
  76. package/dist/commands/date-format.d.ts +58 -0
  77. package/dist/commands/date-format.d.ts.map +1 -0
  78. package/dist/commands/default-branch.d.ts +70 -0
  79. package/dist/commands/default-branch.d.ts.map +1 -0
  80. package/dist/commands/describe-command.d.ts.map +1 -1
  81. package/dist/commands/diff-command.d.ts +377 -30
  82. package/dist/commands/diff-command.d.ts.map +1 -1
  83. package/dist/commands/diff-textconv.d.ts +40 -0
  84. package/dist/commands/diff-textconv.d.ts.map +1 -0
  85. package/dist/commands/fetch-command.d.ts +149 -10
  86. package/dist/commands/fetch-command.d.ts.map +1 -1
  87. package/dist/commands/format-patch-command.d.ts +164 -0
  88. package/dist/commands/format-patch-command.d.ts.map +1 -0
  89. package/dist/commands/fsck/fetch-fsck.d.ts +60 -0
  90. package/dist/commands/fsck/fetch-fsck.d.ts.map +1 -0
  91. package/dist/commands/fsck/fsck-command.d.ts +227 -0
  92. package/dist/commands/fsck/fsck-command.d.ts.map +1 -0
  93. package/dist/commands/fsck/fsck-loose.d.ts +71 -0
  94. package/dist/commands/fsck/fsck-loose.d.ts.map +1 -0
  95. package/dist/commands/fsck/fsck-msg-ids.d.ts +122 -0
  96. package/dist/commands/fsck/fsck-msg-ids.d.ts.map +1 -0
  97. package/dist/commands/fsck/fsck-object-checks.d.ts +159 -0
  98. package/dist/commands/fsck/fsck-object-checks.d.ts.map +1 -0
  99. package/dist/commands/fsck/fsck-object-table.d.ts +140 -0
  100. package/dist/commands/fsck/fsck-object-table.d.ts.map +1 -0
  101. package/dist/commands/fsck/fsck-pack.d.ts +122 -0
  102. package/dist/commands/fsck/fsck-pack.d.ts.map +1 -0
  103. package/dist/commands/fsck/index.d.ts +6 -0
  104. package/dist/commands/fsck/index.d.ts.map +1 -0
  105. package/dist/commands/fsck/verify-pack-command.d.ts +81 -0
  106. package/dist/commands/fsck/verify-pack-command.d.ts.map +1 -0
  107. package/dist/commands/gc-command.d.ts +106 -39
  108. package/dist/commands/gc-command.d.ts.map +1 -1
  109. package/dist/commands/git-date.d.ts +2 -0
  110. package/dist/commands/git-date.d.ts.map +1 -0
  111. package/dist/commands/git-describe.d.ts +67 -0
  112. package/dist/commands/git-describe.d.ts.map +1 -0
  113. package/dist/commands/git-hooks.d.ts +424 -0
  114. package/dist/commands/git-hooks.d.ts.map +1 -0
  115. package/dist/commands/git-ident.d.ts +128 -0
  116. package/dist/commands/git-ident.d.ts.map +1 -0
  117. package/dist/commands/hook-command.d.ts +96 -0
  118. package/dist/commands/hook-command.d.ts.map +1 -0
  119. package/dist/commands/index-adder.d.ts +233 -0
  120. package/dist/commands/index-adder.d.ts.map +1 -0
  121. package/dist/commands/index-host.d.ts +86 -0
  122. package/dist/commands/index-host.d.ts.map +1 -0
  123. package/dist/commands/index.d.ts +56 -0
  124. package/dist/commands/index.d.ts.map +1 -1
  125. package/dist/commands/index.js +3 -2
  126. package/dist/commands/init-command.d.ts +62 -4
  127. package/dist/commands/init-command.d.ts.map +1 -1
  128. package/dist/commands/legacy-remotes.d.ts +55 -0
  129. package/dist/commands/legacy-remotes.d.ts.map +1 -0
  130. package/dist/commands/local-clone.d.ts +60 -0
  131. package/dist/commands/local-clone.d.ts.map +1 -0
  132. package/dist/commands/local-transport.d.ts +117 -0
  133. package/dist/commands/local-transport.d.ts.map +1 -0
  134. package/dist/commands/log-command.d.ts +216 -24
  135. package/dist/commands/log-command.d.ts.map +1 -1
  136. package/dist/commands/log-graph.d.ts +120 -0
  137. package/dist/commands/log-graph.d.ts.map +1 -0
  138. package/dist/commands/log-output.d.ts +323 -0
  139. package/dist/commands/log-output.d.ts.map +1 -0
  140. package/dist/commands/ls-remote-command.d.ts +23 -7
  141. package/dist/commands/ls-remote-command.d.ts.map +1 -1
  142. package/dist/commands/mailmap.d.ts +31 -0
  143. package/dist/commands/mailmap.d.ts.map +1 -0
  144. package/dist/commands/merge-bases.d.ts +85 -0
  145. package/dist/commands/merge-bases.d.ts.map +1 -0
  146. package/dist/commands/merge-command.d.ts +221 -74
  147. package/dist/commands/merge-command.d.ts.map +1 -1
  148. package/dist/commands/merge-config.d.ts +13 -0
  149. package/dist/commands/merge-config.d.ts.map +1 -0
  150. package/dist/commands/merge-drivers.d.ts +130 -0
  151. package/dist/commands/merge-drivers.d.ts.map +1 -0
  152. package/dist/commands/merge-support.d.ts +260 -0
  153. package/dist/commands/merge-support.d.ts.map +1 -0
  154. package/dist/commands/message-cleanup.d.ts +86 -0
  155. package/dist/commands/message-cleanup.d.ts.map +1 -0
  156. package/dist/commands/mv-command.d.ts +94 -0
  157. package/dist/commands/mv-command.d.ts.map +1 -0
  158. package/dist/commands/notes-command.d.ts +256 -0
  159. package/dist/commands/notes-command.d.ts.map +1 -0
  160. package/dist/commands/notes-commands.d.ts +41 -0
  161. package/dist/commands/notes-commands.d.ts.map +1 -0
  162. package/dist/commands/notes-merge-command.d.ts +105 -0
  163. package/dist/commands/notes-merge-command.d.ts.map +1 -0
  164. package/dist/commands/notes-support.d.ts +125 -0
  165. package/dist/commands/notes-support.d.ts.map +1 -0
  166. package/dist/commands/notes-tree.d.ts +116 -0
  167. package/dist/commands/notes-tree.d.ts.map +1 -0
  168. package/dist/commands/object-id-input.d.ts +20 -0
  169. package/dist/commands/object-id-input.d.ts.map +1 -0
  170. package/dist/commands/octopus-merge.d.ts +59 -0
  171. package/dist/commands/octopus-merge.d.ts.map +1 -0
  172. package/dist/commands/ort-merge.d.ts +126 -0
  173. package/dist/commands/ort-merge.d.ts.map +1 -0
  174. package/dist/commands/ort-recursive.d.ts +53 -0
  175. package/dist/commands/ort-recursive.d.ts.map +1 -0
  176. package/dist/commands/pack-refs-command.d.ts +20 -0
  177. package/dist/commands/pack-refs-command.d.ts.map +1 -1
  178. package/dist/commands/patch-id.d.ts +44 -0
  179. package/dist/commands/patch-id.d.ts.map +1 -0
  180. package/dist/commands/pathspec-attributes.d.ts +64 -0
  181. package/dist/commands/pathspec-attributes.d.ts.map +1 -0
  182. package/dist/commands/pathspec.d.ts +324 -0
  183. package/dist/commands/pathspec.d.ts.map +1 -0
  184. package/dist/commands/post-index-change.d.ts +33 -0
  185. package/dist/commands/post-index-change.d.ts.map +1 -0
  186. package/dist/commands/pretty-format.d.ts +222 -0
  187. package/dist/commands/pretty-format.d.ts.map +1 -0
  188. package/dist/commands/promisor-remote.d.ts +80 -0
  189. package/dist/commands/promisor-remote.d.ts.map +1 -0
  190. package/dist/commands/pull-command.d.ts +59 -8
  191. package/dist/commands/pull-command.d.ts.map +1 -1
  192. package/dist/commands/push-command.d.ts +24 -8
  193. package/dist/commands/push-command.d.ts.map +1 -1
  194. package/dist/commands/read-tree-command.d.ts +112 -0
  195. package/dist/commands/read-tree-command.d.ts.map +1 -0
  196. package/dist/commands/rebase-command.d.ts +507 -75
  197. package/dist/commands/rebase-command.d.ts.map +1 -1
  198. package/dist/commands/rebase-todo.d.ts +130 -0
  199. package/dist/commands/rebase-todo.d.ts.map +1 -0
  200. package/dist/commands/ref-decoration-filter.d.ts +53 -0
  201. package/dist/commands/ref-decoration-filter.d.ts.map +1 -0
  202. package/dist/commands/reflog-messages.d.ts +98 -0
  203. package/dist/commands/reflog-messages.d.ts.map +1 -0
  204. package/dist/commands/remote-command.d.ts +31 -0
  205. package/dist/commands/remote-command.d.ts.map +1 -1
  206. package/dist/commands/remote-transport.d.ts +120 -0
  207. package/dist/commands/remote-transport.d.ts.map +1 -0
  208. package/dist/commands/reset-command.d.ts +161 -7
  209. package/dist/commands/reset-command.d.ts.map +1 -1
  210. package/dist/commands/restore-command.d.ts +103 -0
  211. package/dist/commands/restore-command.d.ts.map +1 -0
  212. package/dist/commands/rev-list-command.d.ts +78 -0
  213. package/dist/commands/rev-list-command.d.ts.map +1 -0
  214. package/dist/commands/rev-parse-command.d.ts +89 -0
  215. package/dist/commands/rev-parse-command.d.ts.map +1 -0
  216. package/dist/commands/revert-command.d.ts +46 -38
  217. package/dist/commands/revert-command.d.ts.map +1 -1
  218. package/dist/commands/revision-filenames.d.ts +95 -0
  219. package/dist/commands/revision-filenames.d.ts.map +1 -0
  220. package/dist/commands/revision-range.d.ts +67 -0
  221. package/dist/commands/revision-range.d.ts.map +1 -0
  222. package/dist/commands/revision-resolver.d.ts +325 -0
  223. package/dist/commands/revision-resolver.d.ts.map +1 -0
  224. package/dist/commands/rm-command.d.ts +69 -7
  225. package/dist/commands/rm-command.d.ts.map +1 -1
  226. package/dist/commands/sequencer-pick.d.ts +191 -0
  227. package/dist/commands/sequencer-pick.d.ts.map +1 -0
  228. package/dist/commands/sequencer-support.d.ts +125 -0
  229. package/dist/commands/sequencer-support.d.ts.map +1 -0
  230. package/dist/commands/serve-repository.d.ts +52 -0
  231. package/dist/commands/serve-repository.d.ts.map +1 -0
  232. package/dist/commands/sparse-checkout-command.d.ts +190 -0
  233. package/dist/commands/sparse-checkout-command.d.ts.map +1 -0
  234. package/dist/commands/sparse-checkout-support.d.ts +268 -0
  235. package/dist/commands/sparse-checkout-support.d.ts.map +1 -0
  236. package/dist/commands/stash-apply-command.d.ts +42 -8
  237. package/dist/commands/stash-apply-command.d.ts.map +1 -1
  238. package/dist/commands/stash-create-command.d.ts +156 -2
  239. package/dist/commands/stash-create-command.d.ts.map +1 -1
  240. package/dist/commands/stash-drop-command.d.ts +2 -0
  241. package/dist/commands/stash-drop-command.d.ts.map +1 -1
  242. package/dist/commands/stash-working-tree.d.ts +23 -0
  243. package/dist/commands/stash-working-tree.d.ts.map +1 -1
  244. package/dist/commands/status-command.d.ts +300 -15
  245. package/dist/commands/status-command.d.ts.map +1 -1
  246. package/dist/commands/status-format.d.ts +155 -0
  247. package/dist/commands/status-format.d.ts.map +1 -0
  248. package/dist/commands/status-header.d.ts +64 -0
  249. package/dist/commands/status-header.d.ts.map +1 -0
  250. package/dist/commands/strerror.d.ts +7 -0
  251. package/dist/commands/strerror.d.ts.map +1 -0
  252. package/dist/commands/submodule-config.d.ts +38 -0
  253. package/dist/commands/submodule-config.d.ts.map +1 -0
  254. package/dist/commands/submodule-summary-command.d.ts +80 -0
  255. package/dist/commands/submodule-summary-command.d.ts.map +1 -0
  256. package/dist/commands/submodule-summary.d.ts +150 -0
  257. package/dist/commands/submodule-summary.d.ts.map +1 -0
  258. package/dist/commands/switch-command.d.ts +132 -0
  259. package/dist/commands/switch-command.d.ts.map +1 -0
  260. package/dist/commands/tag-command.d.ts +23 -2
  261. package/dist/commands/tag-command.d.ts.map +1 -1
  262. package/dist/commands/tracking-info.d.ts +64 -0
  263. package/dist/commands/tracking-info.d.ts.map +1 -0
  264. package/dist/commands/trailers.d.ts +73 -0
  265. package/dist/commands/trailers.d.ts.map +1 -0
  266. package/dist/commands/tree-restore.d.ts +85 -1
  267. package/dist/commands/tree-restore.d.ts.map +1 -1
  268. package/dist/commands/untracked-cache-support.d.ts +54 -0
  269. package/dist/commands/untracked-cache-support.d.ts.map +1 -0
  270. package/dist/commands/worktree-add-command.d.ts +108 -0
  271. package/dist/commands/worktree-add-command.d.ts.map +1 -0
  272. package/dist/commands/worktree-list-command.d.ts +69 -0
  273. package/dist/commands/worktree-list-command.d.ts.map +1 -0
  274. package/dist/commands/worktree-lock-command.d.ts +44 -0
  275. package/dist/commands/worktree-lock-command.d.ts.map +1 -0
  276. package/dist/commands/worktree-overwrite-checks.d.ts +146 -6
  277. package/dist/commands/worktree-overwrite-checks.d.ts.map +1 -1
  278. package/dist/commands/worktree-prune-command.d.ts +48 -0
  279. package/dist/commands/worktree-prune-command.d.ts.map +1 -0
  280. package/dist/commands/worktree-remove-command.d.ts +59 -0
  281. package/dist/commands/worktree-remove-command.d.ts.map +1 -0
  282. package/dist/commands/worktree-repair-command.d.ts +35 -0
  283. package/dist/commands/worktree-repair-command.d.ts.map +1 -0
  284. package/dist/commands/worktree-support.d.ts +64 -0
  285. package/dist/commands/worktree-support.d.ts.map +1 -0
  286. package/dist/commands-DIJ91NnD.js +62225 -0
  287. package/dist/core-commands/add.command.impl.d.ts.map +1 -1
  288. package/dist/errors/add-errors.d.ts +55 -0
  289. package/dist/errors/add-errors.d.ts.map +1 -1
  290. package/dist/errors/checkout-errors.d.ts +16 -0
  291. package/dist/errors/checkout-errors.d.ts.map +1 -1
  292. package/dist/errors/command-errors.d.ts +77 -0
  293. package/dist/errors/command-errors.d.ts.map +1 -1
  294. package/dist/errors/commit-errors.d.ts +9 -0
  295. package/dist/errors/commit-errors.d.ts.map +1 -1
  296. package/dist/errors/git-api-error.d.ts +59 -2
  297. package/dist/errors/git-api-error.d.ts.map +1 -1
  298. package/dist/errors/index.d.ts +1 -0
  299. package/dist/errors/index.d.ts.map +1 -1
  300. package/dist/errors/index.js +354 -19
  301. package/dist/errors/rebase-errors.d.ts +9 -0
  302. package/dist/errors/rebase-errors.d.ts.map +1 -1
  303. package/dist/errors/ref-errors.d.ts +32 -0
  304. package/dist/errors/ref-errors.d.ts.map +1 -1
  305. package/dist/errors/transport-errors.d.ts +12 -2
  306. package/dist/errors/transport-errors.d.ts.map +1 -1
  307. package/dist/errors/worktree-errors.d.ts +35 -0
  308. package/dist/errors/worktree-errors.d.ts.map +1 -0
  309. package/dist/git-command-BGiOJ8Zk.js +7246 -0
  310. package/dist/git-command.d.ts +428 -32
  311. package/dist/git-command.d.ts.map +1 -1
  312. package/dist/git.d.ts +315 -5
  313. package/dist/git.d.ts.map +1 -1
  314. package/dist/index.d.ts +1 -1
  315. package/dist/index.d.ts.map +1 -1
  316. package/dist/index.js +5 -5
  317. package/dist/remote-config/index.d.ts +1 -1
  318. package/dist/remote-config/index.d.ts.map +1 -1
  319. package/dist/remote-config/remote-config-store.d.ts +167 -6
  320. package/dist/remote-config/remote-config-store.d.ts.map +1 -1
  321. package/dist/remote-config/remote-refs.d.ts +7 -3
  322. package/dist/remote-config/remote-refs.d.ts.map +1 -1
  323. package/dist/rename/detect-renames.d.ts +148 -0
  324. package/dist/rename/detect-renames.d.ts.map +1 -0
  325. package/dist/rename/git-similarity.d.ts +44 -0
  326. package/dist/rename/git-similarity.d.ts.map +1 -0
  327. package/dist/rename/index.d.ts +2 -0
  328. package/dist/rename/index.d.ts.map +1 -1
  329. package/dist/results/binary-patch.d.ts +11 -0
  330. package/dist/results/binary-patch.d.ts.map +1 -0
  331. package/dist/results/blame-format.d.ts +55 -0
  332. package/dist/results/blame-format.d.ts.map +1 -0
  333. package/dist/results/cherry-pick-result.d.ts +10 -0
  334. package/dist/results/cherry-pick-result.d.ts.map +1 -1
  335. package/dist/results/clone-result.d.ts +18 -0
  336. package/dist/results/clone-result.d.ts.map +1 -1
  337. package/dist/results/combined-diff.d.ts +77 -0
  338. package/dist/results/combined-diff.d.ts.map +1 -0
  339. package/dist/results/diff-entry.d.ts +32 -0
  340. package/dist/results/diff-entry.d.ts.map +1 -1
  341. package/dist/results/diff-formatter.d.ts +34 -60
  342. package/dist/results/diff-formatter.d.ts.map +1 -1
  343. package/dist/results/diff-order.d.ts +25 -0
  344. package/dist/results/diff-order.d.ts.map +1 -0
  345. package/dist/results/diff-output.d.ts +249 -0
  346. package/dist/results/diff-output.d.ts.map +1 -0
  347. package/dist/results/fetch-result.d.ts +15 -0
  348. package/dist/results/fetch-result.d.ts.map +1 -1
  349. package/dist/results/index.d.ts +5 -0
  350. package/dist/results/index.d.ts.map +1 -1
  351. package/dist/results/index.js +2 -252
  352. package/dist/results/init-result.d.ts +7 -0
  353. package/dist/results/init-result.d.ts.map +1 -1
  354. package/dist/results/merge-result.d.ts +15 -1
  355. package/dist/results/merge-result.d.ts.map +1 -1
  356. package/dist/results/pull-result.d.ts +17 -3
  357. package/dist/results/pull-result.d.ts.map +1 -1
  358. package/dist/results/push-result.d.ts +47 -0
  359. package/dist/results/push-result.d.ts.map +1 -1
  360. package/dist/results/quote-path.d.ts +27 -0
  361. package/dist/results/quote-path.d.ts.map +1 -0
  362. package/dist/results/rebase-result.d.ts +28 -1
  363. package/dist/results/rebase-result.d.ts.map +1 -1
  364. package/dist/results/revert-result.d.ts +10 -0
  365. package/dist/results/revert-result.d.ts.map +1 -1
  366. package/dist/results/stash-result.d.ts +5 -0
  367. package/dist/results/stash-result.d.ts.map +1 -1
  368. package/dist/results/status-result.d.ts +60 -6
  369. package/dist/results/status-result.d.ts.map +1 -1
  370. package/dist/results-WVlBhVb1.js +2935 -0
  371. package/dist/transport-command.d.ts +44 -1
  372. package/dist/transport-command.d.ts.map +1 -1
  373. package/package.json +15 -11
  374. package/src/commands/add-command.ts +1291 -226
  375. package/src/commands/add-patch/add-interactive.ts +941 -0
  376. package/src/commands/add-patch/add-patch.ts +1169 -0
  377. package/src/commands/add-patch/index.ts +5 -0
  378. package/src/commands/add-patch/patch-backend.ts +239 -0
  379. package/src/commands/add-patch/patch-modes.ts +249 -0
  380. package/src/commands/add-patch/patch-session.ts +159 -0
  381. package/src/commands/am/am-command.ts +1111 -0
  382. package/src/commands/am/index.ts +2 -0
  383. package/src/commands/am/mailinfo.ts +1015 -0
  384. package/src/commands/am/patch-format.ts +121 -0
  385. package/src/commands/apply/apply-command.ts +842 -0
  386. package/src/commands/apply/apply-engine.ts +1602 -0
  387. package/src/commands/apply/apply-parse.ts +1210 -0
  388. package/src/commands/apply/apply-types.ts +112 -0
  389. package/src/commands/apply/index.ts +5 -0
  390. package/src/commands/apply/latin1.ts +171 -0
  391. package/src/commands/apply/whitespace.ts +260 -0
  392. package/src/commands/attributes-source.ts +96 -0
  393. package/src/commands/backfill-command.ts +694 -0
  394. package/src/commands/bisect/bisect-checkout.ts +217 -0
  395. package/src/commands/bisect/bisect-command.ts +788 -0
  396. package/src/commands/bisect/bisect-engine.ts +1080 -0
  397. package/src/commands/bisect/bisect-graph.ts +595 -0
  398. package/src/commands/bisect/bisect-quote.ts +92 -0
  399. package/src/commands/bisect/index.ts +4 -0
  400. package/src/commands/blame-command.ts +711 -986
  401. package/src/commands/branch-command.ts +354 -32
  402. package/src/commands/branch-tracking.ts +331 -0
  403. package/src/commands/checkout-command.ts +1290 -243
  404. package/src/commands/checkout-paths.ts +784 -0
  405. package/src/commands/cherry-pick-command.ts +156 -396
  406. package/src/commands/clean-command.ts +504 -156
  407. package/src/commands/clone-command.ts +748 -69
  408. package/src/commands/comment-char-config.ts +160 -0
  409. package/src/commands/commit-command.ts +1782 -166
  410. package/src/commands/core-config.ts +166 -6
  411. package/src/commands/date-format.ts +668 -0
  412. package/src/commands/default-branch.ts +196 -0
  413. package/src/commands/describe-command.ts +2 -0
  414. package/src/commands/diff-command.ts +1916 -110
  415. package/src/commands/diff-textconv.ts +50 -0
  416. package/src/commands/fetch-command.ts +622 -68
  417. package/src/commands/format-patch-command.ts +974 -0
  418. package/src/commands/fsck/fetch-fsck.ts +229 -0
  419. package/src/commands/fsck/fsck-command.ts +3464 -0
  420. package/src/commands/fsck/fsck-loose.ts +297 -0
  421. package/src/commands/fsck/fsck-msg-ids.ts +176 -0
  422. package/src/commands/fsck/fsck-object-checks.ts +1085 -0
  423. package/src/commands/fsck/fsck-object-table.ts +373 -0
  424. package/src/commands/fsck/fsck-pack.ts +634 -0
  425. package/src/commands/fsck/index.ts +5 -0
  426. package/src/commands/fsck/verify-pack-command.ts +252 -0
  427. package/src/commands/gc-command.ts +324 -77
  428. package/src/commands/git-date.ts +9 -0
  429. package/src/commands/git-describe.ts +316 -0
  430. package/src/commands/git-hooks.ts +1483 -0
  431. package/src/commands/git-ident.ts +344 -0
  432. package/src/commands/hook-command.ts +247 -0
  433. package/src/commands/index-adder.ts +711 -0
  434. package/src/commands/index-host.ts +291 -0
  435. package/src/commands/index.ts +84 -0
  436. package/src/commands/init-command.ts +194 -14
  437. package/src/commands/legacy-remotes.ts +224 -0
  438. package/src/commands/local-clone.ts +183 -0
  439. package/src/commands/local-transport.ts +762 -0
  440. package/src/commands/log-command.ts +1930 -170
  441. package/src/commands/log-graph.ts +671 -0
  442. package/src/commands/log-output.ts +1359 -0
  443. package/src/commands/ls-remote-command.ts +105 -58
  444. package/src/commands/mailmap.ts +129 -0
  445. package/src/commands/merge-bases.ts +296 -0
  446. package/src/commands/merge-command.ts +1416 -491
  447. package/src/commands/merge-config.ts +25 -0
  448. package/src/commands/merge-drivers.ts +306 -0
  449. package/src/commands/merge-support.ts +1219 -0
  450. package/src/commands/message-cleanup.ts +275 -0
  451. package/src/commands/mv-command.ts +976 -0
  452. package/src/commands/notes-command.ts +890 -0
  453. package/src/commands/notes-commands.ts +87 -0
  454. package/src/commands/notes-merge-command.ts +777 -0
  455. package/src/commands/notes-support.ts +402 -0
  456. package/src/commands/notes-tree.ts +617 -0
  457. package/src/commands/object-id-input.ts +27 -0
  458. package/src/commands/octopus-merge.ts +378 -0
  459. package/src/commands/ort-merge.ts +1660 -0
  460. package/src/commands/ort-recursive.ts +160 -0
  461. package/src/commands/pack-refs-command.ts +39 -22
  462. package/src/commands/patch-id.ts +204 -0
  463. package/src/commands/pathspec-attributes.ts +162 -0
  464. package/src/commands/pathspec.ts +1199 -0
  465. package/src/commands/post-index-change.ts +62 -0
  466. package/src/commands/pretty-format.ts +1432 -0
  467. package/src/commands/promisor-remote.ts +298 -0
  468. package/src/commands/pull-command.ts +326 -33
  469. package/src/commands/push-command.ts +257 -29
  470. package/src/commands/read-tree-command.ts +861 -0
  471. package/src/commands/rebase-command.ts +3820 -372
  472. package/src/commands/rebase-todo.ts +584 -0
  473. package/src/commands/ref-decoration-filter.ts +118 -0
  474. package/src/commands/reflog-messages.ts +177 -0
  475. package/src/commands/remote-command.ts +124 -23
  476. package/src/commands/remote-transport.ts +383 -0
  477. package/src/commands/reset-command.ts +821 -104
  478. package/src/commands/restore-command.ts +350 -0
  479. package/src/commands/rev-list-command.ts +167 -0
  480. package/src/commands/rev-parse-command.ts +299 -0
  481. package/src/commands/revert-command.ts +152 -399
  482. package/src/commands/revision-filenames.ts +254 -0
  483. package/src/commands/revision-range.ts +222 -0
  484. package/src/commands/revision-resolver.ts +1397 -0
  485. package/src/commands/rm-command.ts +613 -67
  486. package/src/commands/sequencer-pick.ts +874 -0
  487. package/src/commands/sequencer-support.ts +876 -0
  488. package/src/commands/serve-repository.ts +125 -0
  489. package/src/commands/sparse-checkout-command.ts +1389 -0
  490. package/src/commands/sparse-checkout-support.ts +793 -0
  491. package/src/commands/stash-apply-command.ts +376 -343
  492. package/src/commands/stash-create-command.ts +625 -42
  493. package/src/commands/stash-drop-command.ts +15 -2
  494. package/src/commands/stash-working-tree.ts +168 -24
  495. package/src/commands/status-command.ts +1326 -105
  496. package/src/commands/status-format.ts +775 -0
  497. package/src/commands/status-header.ts +332 -0
  498. package/src/commands/strerror.ts +29 -0
  499. package/src/commands/submodule-config.ts +94 -0
  500. package/src/commands/submodule-summary-command.ts +333 -0
  501. package/src/commands/submodule-summary.ts +446 -0
  502. package/src/commands/switch-command.ts +402 -0
  503. package/src/commands/tag-command.ts +129 -41
  504. package/src/commands/tracking-info.ts +201 -0
  505. package/src/commands/trailers.ts +417 -0
  506. package/src/commands/tree-restore.ts +204 -4
  507. package/src/commands/untracked-cache-support.ts +198 -0
  508. package/src/commands/worktree-add-command.ts +458 -0
  509. package/src/commands/worktree-list-command.ts +206 -0
  510. package/src/commands/worktree-lock-command.ts +96 -0
  511. package/src/commands/worktree-overwrite-checks.ts +452 -26
  512. package/src/commands/worktree-prune-command.ts +99 -0
  513. package/src/commands/worktree-remove-command.ts +186 -0
  514. package/src/commands/worktree-repair-command.ts +59 -0
  515. package/src/commands/worktree-support.ts +214 -0
  516. package/src/core-commands/add.command.impl.ts +8 -2
  517. package/src/errors/add-errors.ts +45 -0
  518. package/src/errors/checkout-errors.ts +26 -2
  519. package/src/errors/command-errors.ts +101 -1
  520. package/src/errors/commit-errors.ts +18 -2
  521. package/src/errors/git-api-error.ts +82 -2
  522. package/src/errors/index.ts +1 -0
  523. package/src/errors/merge-errors.ts +2 -2
  524. package/src/errors/rebase-errors.ts +12 -0
  525. package/src/errors/ref-errors.ts +56 -2
  526. package/src/errors/remote-errors.ts +2 -2
  527. package/src/errors/stash-errors.ts +1 -1
  528. package/src/errors/transport-errors.ts +20 -4
  529. package/src/errors/worktree-errors.ts +49 -0
  530. package/src/git-command.ts +1207 -118
  531. package/src/git.ts +538 -12
  532. package/src/index.ts +1 -1
  533. package/src/remote-config/index.ts +2 -0
  534. package/src/remote-config/remote-config-store.ts +378 -18
  535. package/src/remote-config/remote-refs.ts +22 -6
  536. package/src/rename/detect-renames.ts +715 -0
  537. package/src/rename/git-similarity.ts +116 -0
  538. package/src/rename/index.ts +2 -0
  539. package/src/results/binary-patch.ts +401 -0
  540. package/src/results/blame-format.ts +239 -0
  541. package/src/results/cherry-pick-result.ts +10 -0
  542. package/src/results/clone-result.ts +21 -0
  543. package/src/results/combined-diff.ts +585 -0
  544. package/src/results/diff-entry.ts +35 -0
  545. package/src/results/diff-formatter.ts +152 -288
  546. package/src/results/diff-order.ts +64 -0
  547. package/src/results/diff-output.ts +1053 -0
  548. package/src/results/fetch-result.ts +15 -0
  549. package/src/results/index.ts +5 -0
  550. package/src/results/init-result.ts +9 -0
  551. package/src/results/merge-result.ts +15 -1
  552. package/src/results/pull-result.ts +17 -3
  553. package/src/results/push-result.ts +48 -0
  554. package/src/results/quote-path.ts +103 -0
  555. package/src/results/rebase-result.ts +37 -0
  556. package/src/results/revert-result.ts +10 -0
  557. package/src/results/stash-result.ts +6 -0
  558. package/src/results/status-result.ts +127 -46
  559. package/src/transport-command.ts +121 -2
  560. package/dist/commands-CsLNyvZ1.js +0 -12587
  561. package/dist/status-result-BpyUK1Sg.js +0 -519
@@ -1,26 +1,90 @@
1
- import { FileMode, type ObjectId } from "@statewalker/vcs-core";
1
+ import { type Commits, countAheadBehind, FileMode, type ObjectId } from "@statewalker/vcs-core";
2
+ import { parseGitBool } from "@statewalker/vcs-utils";
2
3
  import {
4
+ type CacheTree,
3
5
  compareWithWorktree,
4
- findUntrackedFiles,
6
+ compareWithWorktreeStat,
7
+ DIR_HIDE_EMPTY_DIRECTORIES,
8
+ DIR_SHOW_IGNORED_TOO,
9
+ DIR_SHOW_IGNORED_TOO_MODE_MATCHING,
10
+ DIR_SHOW_OTHER_DIRECTORIES,
5
11
  getStageState,
12
+ getWorktreeEntries,
13
+ IndexPathLookup,
6
14
  type IndexStatUpdate,
15
+ isCleanByStat,
7
16
  modeFromWorktree,
17
+ readConvertedContent,
8
18
  refreshIndexStats,
9
19
  type StageStateValue,
20
+ type StagingEntry,
21
+ scanUntracked,
10
22
  statUpdateOf,
11
- trackedUnder,
23
+ unreadableDirectoryWarning,
24
+ type WorkingCopy,
12
25
  type Worktree,
26
+ type WorktreeModeTrust,
27
+ walkUntrackedScanHost,
13
28
  } from "@statewalker/vcs-working-tree";
14
29
 
30
+ import {
31
+ IncompatibleOptionsError,
32
+ InvalidArgumentError,
33
+ InvalidConfigError,
34
+ } from "../errors/index.js";
15
35
  import { GitCommand } from "../git-command.js";
36
+ import { RemoteConfigStore } from "../remote-config/index.js";
37
+ import {
38
+ DEFAULT_RENAME_LIMIT,
39
+ detectRenames,
40
+ type RenameCandidate,
41
+ scorePercent,
42
+ } from "../rename/index.js";
16
43
  import {
17
44
  type Status,
18
45
  type StatusCode,
19
46
  type StatusFileEntry,
20
47
  StatusImpl,
21
48
  type StatusSide,
49
+ submoduleToken,
22
50
  } from "../results/status-result.js";
23
- import { worktreeModeTrust } from "./core-config.js";
51
+ import { coreBool, worktreeModeTrust } from "./core-config.js";
52
+ import { DiffCommand } from "./diff-command.js";
53
+ import { hostEnvironmentOf } from "./git-ident.js";
54
+ import { OperationState } from "./merge-support.js";
55
+ import { commentPrefixOf } from "./message-cleanup.js";
56
+ import { canonicalObjectId } from "./object-id-input.js";
57
+ import {
58
+ DO_MATCH_DIRECTORY,
59
+ globalPathspecMagic,
60
+ matchPathspec,
61
+ type PathspecItem,
62
+ parsePathspec,
63
+ untrackedScanPathspec,
64
+ } from "./pathspec.js";
65
+ import { PathspecAttributes } from "./pathspec-attributes.js";
66
+ import {
67
+ type CommitWhence,
68
+ formatStatusText,
69
+ type StatusText,
70
+ statusCommitInfo,
71
+ } from "./status-format.js";
72
+ import { readStatusHeader } from "./status-header.js";
73
+ import {
74
+ type GitmodulesEntry,
75
+ isSubmoduleIgnoreMode,
76
+ parseGitmodules,
77
+ type SubmoduleIgnoreFlags,
78
+ type SubmoduleIgnoreMode,
79
+ submoduleIgnoreFlags,
80
+ } from "./submodule-config.js";
81
+ import { readDiffSubmoduleConfig } from "./submodule-summary.js";
82
+ import { SubmoduleSummaryCommand } from "./submodule-summary-command.js";
83
+ import type { TrackingSource } from "./tracking-info.js";
84
+ import { openUntrackedCache } from "./untracked-cache-support.js";
85
+ import { shortenUnambiguousRef } from "./worktree-list-command.js";
86
+
87
+ export type { SubmoduleIgnoreMode } from "./submodule-config.js";
24
88
 
25
89
  /** The porcelain `XY` of an unmerged path, by which of stages 1-3 it has. */
26
90
  const UNMERGED_CODES: Record<number, [StatusCode, StatusCode]> = {
@@ -34,7 +98,171 @@ const UNMERGED_CODES: Record<number, [StatusCode, StatusCode]> = {
34
98
  };
35
99
 
36
100
  const S_IFMT = 0o170000;
101
+
102
+ /** HEAD's side of an entry in a directory the cache-tree shows unchanged: the entry's own. */
103
+ const SAME = Symbol("same-as-head");
104
+
105
+ /** How many files the stat pass asks the worktree for at once. */
106
+ const STAT_CHUNK = 4096;
107
+
108
+ /** A `.gitignore` path (the untracked cache records the ids of those files). */
109
+ const isIgnoreFilePath = (path: string) => path === ".gitignore" || path.endsWith("/.gitignore");
37
110
  const typeOf = (mode: number) => mode & S_IFMT;
111
+ const isGitlink = (mode: number | undefined) => mode === FileMode.GITLINK;
112
+
113
+ /** A git boolean, `copies`/`copy` (rename detection on) or undefined when not one. */
114
+ function renamesValue(value: string | undefined): boolean | undefined {
115
+ if (value === undefined) return undefined;
116
+ const v = value.toLowerCase();
117
+ if (v === "copies" || v === "copy") return true;
118
+ return parseGitBool(value);
119
+ }
120
+
121
+ /**
122
+ * Which untracked files status lists (`--untracked-files`, `status.showUntrackedFiles`):
123
+ * none, untracked directories as `dir/` (git's default), or every file.
124
+ */
125
+ export type UntrackedFilesMode = "no" | "normal" | "all";
126
+
127
+ /**
128
+ * Which ignored files status lists (`--ignored`): none (the default), every ignored path
129
+ * with an ignored directory as `dir/` (`traditional`, what `--ignored` alone means), or the
130
+ * paths an exclude pattern matches (`matching`).
131
+ */
132
+ export type IgnoredMode = "no" | "traditional" | "matching";
133
+
134
+ /**
135
+ * A value of `--untracked-files` or `status.showUntrackedFiles` as git 2.5x reads it
136
+ * (builtin/commit.c `parse_untracked_setting_name`): a boolean (`true`, `yes`, `on`, `1`, a
137
+ * variable without `=`; `false`, `off`, `0`, an empty value) is `normal` or `no`, else
138
+ * exactly `no`, `normal` or `all`. Undefined for anything else. git 2.43 took the three
139
+ * names alone.
140
+ *
141
+ * @example
142
+ * ```typescript
143
+ * parseUntrackedFilesMode("false"); // "no"
144
+ * parseUntrackedFilesMode("All"); // undefined (git: "Invalid untracked files mode 'All'")
145
+ * ```
146
+ */
147
+ export function parseUntrackedFilesMode(value: string | undefined): UntrackedFilesMode | undefined {
148
+ const asBool = value === undefined ? true : parseGitBool(value);
149
+ if (asBool === false) return "no";
150
+ if (asBool === true) return "normal";
151
+ return value === "no" || value === "normal" || value === "all" ? value : undefined;
152
+ }
153
+
154
+ /**
155
+ * `status.showUntrackedFiles` as git's `git_status_config` reads it (`git status` and
156
+ * `git commit` alike): its last value, undefined when it is not set. Every value is checked
157
+ * in the configuration's order, and the first one git cannot read fails with git's message
158
+ * (`error: Invalid untracked files mode '<value>'`, then where it was read).
159
+ *
160
+ * @example
161
+ * ```typescript
162
+ * const mode = readShowUntrackedFiles(workingCopy) ?? "normal";
163
+ * ```
164
+ */
165
+ export function readShowUntrackedFiles(workingCopy: WorkingCopy): UntrackedFilesMode | undefined {
166
+ const key = "status.showuntrackedfiles";
167
+ let configured: UntrackedFilesMode | undefined;
168
+ const values = RemoteConfigStore.from(workingCopy).valuesWithOrigin("status.showUntrackedFiles");
169
+ for (const { text, file, line } of values) {
170
+ const mode = parseUntrackedFilesMode(text);
171
+ if (mode === undefined) {
172
+ const where =
173
+ file !== undefined && line !== undefined
174
+ ? `fatal: bad config variable '${key}' in file '${file}' at line ${line}`
175
+ : `fatal: unable to parse '${key}' from command-line config`;
176
+ throw new InvalidConfigError(
177
+ "status.showUntrackedFiles",
178
+ `error: Invalid untracked files mode '${text}'\n${where}`,
179
+ );
180
+ }
181
+ configured = mode;
182
+ }
183
+ return configured;
184
+ }
185
+
186
+ /** A value of `--ignored` (builtin/commit.c `handle_ignored_arg`), else undefined. */
187
+ export function parseIgnoredMode(value: string): IgnoredMode | undefined {
188
+ return value === "no" || value === "traditional" || value === "matching" ? value : undefined;
189
+ }
190
+
191
+ /** A git integer (`1000`, `2k`), or undefined when not one. */
192
+ function intValue(value: string | undefined): number | undefined {
193
+ const m = value?.trim().match(/^(-?\d+)([kmg]?)$/i);
194
+ if (!m) return undefined;
195
+ const unit = { "": 1, k: 1024, m: 1024 ** 2, g: 1024 ** 3 }[m[2].toLowerCase()] ?? 1;
196
+ return Number(m[1]) * unit;
197
+ }
198
+
199
+ async function concat(chunks: AsyncIterable<Uint8Array> | Iterable<Uint8Array>) {
200
+ const parts: Uint8Array[] = [];
201
+ let size = 0;
202
+ for await (const chunk of chunks) {
203
+ parts.push(chunk);
204
+ size += chunk.length;
205
+ }
206
+ const out = new Uint8Array(size);
207
+ let offset = 0;
208
+ for (const part of parts) {
209
+ out.set(part, offset);
210
+ offset += part.length;
211
+ }
212
+ return out;
213
+ }
214
+
215
+ /** What a submodule's own worktree holds (git's `DIRTY_SUBMODULE_*`). */
216
+ export interface SubmoduleDirt {
217
+ modified?: boolean;
218
+ untracked?: boolean;
219
+ }
220
+
221
+ /**
222
+ * The state of the submodule at `path` in its own index and worktree, as git's
223
+ * `is_submodule_modified` reads it from `git status --porcelain=2` run inside it: an
224
+ * untracked file there (or a nested submodule holding only untracked files, `S..U`) is
225
+ * untracked content; any other change, a nested submodule's included, is modified content.
226
+ * Nothing for a submodule that is not populated (or that the worktree cannot open). A
227
+ * configuration the inner status cannot read fails with its messages and git's
228
+ * `'git status --porcelain=2' failed in submodule <path>`.
229
+ */
230
+ export async function readSubmoduleDirt(
231
+ worktree: Worktree,
232
+ path: string,
233
+ ignoreUntracked: boolean,
234
+ ): Promise<SubmoduleDirt> {
235
+ const inner: WorkingCopy | undefined = await worktree.openGitlink?.(path);
236
+ if (!inner) return {};
237
+ // `git status --porcelain=2` there, with `-uno` when untracked content is ignored
238
+ const command = new StatusCommand(inner).setRenames(false);
239
+ if (ignoreUntracked) command.setUntrackedFiles("no");
240
+ let status: Status;
241
+ try {
242
+ status = await command.call();
243
+ } catch (error) {
244
+ // the child dies on its configuration (its own messages), then the parent does
245
+ if (error instanceof InvalidConfigError) {
246
+ throw new InvalidConfigError(
247
+ error.key,
248
+ `${error.message}\nfatal: 'git status --porcelain=2' failed in submodule ${path}`,
249
+ );
250
+ }
251
+ throw error;
252
+ }
253
+ const dirt: SubmoduleDirt = {};
254
+ for (const f of status.files) {
255
+ if (f.index === "!") continue;
256
+ if (f.index === "?") {
257
+ dirt.untracked = true;
258
+ continue;
259
+ }
260
+ const token = submoduleToken(f);
261
+ if (token[0] === "S" && token[3] === "U") dirt.untracked = true;
262
+ if (f.stages || f.renamedFrom || token !== "S..U") dirt.modified = true;
263
+ }
264
+ return dirt;
265
+ }
38
266
 
39
267
  /**
40
268
  * Shows the working tree status, as `git status`: the index against HEAD (staged changes),
@@ -45,8 +273,28 @@ const typeOf = (mode: number) => mode & S_IFMT;
45
273
  * size and modification time still match is not read, unless its entry is racily clean
46
274
  * (modified at or after the index was written), which is re-hashed as git does. Links are
47
275
  * compared as links (mode 120000), the executable bit only where `core.filemode` trusts it,
48
- * and the ignore rules are read afresh for each status. Untracked files are listed one by
49
- * one (`--untracked-files=all`). Renames are not detected.
276
+ * and the ignore rules are read afresh for each status.
277
+ *
278
+ * Untracked files are found by git's directory walk (dir.c `read_directory`) in the mode
279
+ * {@link setUntrackedFiles} or `status.showUntrackedFiles` asks: `normal` (the default) shows
280
+ * an untracked directory as `dir/` and hides one holding nothing untracked, `all` lists every
281
+ * file, `no` none. {@link setIgnored} adds the ignored paths (`traditional`: an ignored
282
+ * directory as `dir/`; `matching`: the paths an exclude pattern matches). A whole-tree scan
283
+ * without ignored files goes through the index's untracked cache (`UNTR`) as git uses it:
284
+ * directories whose stat and ignore rules are unchanged are not read again, and the cache is
285
+ * written back as git writes it (`core.untrackedCache`: true writes it, false removes it,
286
+ * unset keeps it), made for the mode `status.showUntrackedFiles` names.
287
+ *
288
+ * Renames are detected as git's default `status.renames=true` does: a path deleted from the
289
+ * index paired with one added to it (`R old -> new`), and a path deleted from the worktree
290
+ * paired with an intent-to-add file (` R old -> new`); untracked files are never paired.
291
+ * `status.renames` (else `diff.renames`), `status.renameLimit` (else `diff.renameLimit`) and
292
+ * {@link setRenames} control it.
293
+ *
294
+ * A populated submodule's own state is read as git does: a commit other than the index's
295
+ * (`SC..`), tracked changes inside it (`S.M.`) and untracked files inside it (`S..U`) all
296
+ * show as ` M sub`; `diff.ignoreSubmodules`, `submodule.<name>.ignore` (config, then
297
+ * `.gitmodules`) and {@link setIgnoreSubmodules} limit what is looked at.
50
298
  *
51
299
  * Without a worktree only the index is compared with HEAD.
52
300
  *
@@ -56,7 +304,7 @@ const typeOf = (mode: number) => mode & S_IFMT;
56
304
  * ```typescript
57
305
  * const status = await git.status().call();
58
306
  * if (status.isClean()) console.log("nothing to commit, working tree clean");
59
- * console.log("Staged:", status.added, status.changed, status.removed);
307
+ * console.log("Staged:", status.added, status.changed, status.removed, status.renamed);
60
308
  * console.log("Unstaged:", status.modified, status.missing);
61
309
  * console.log("Untracked:", status.untracked);
62
310
  * // the lines of `git status --porcelain`
@@ -65,15 +313,36 @@ const typeOf = (mode: number) => mode & S_IFMT;
65
313
  */
66
314
  export class StatusCommand extends GitCommand<Status> {
67
315
  private paths: string[] = [];
68
- private showIgnored = false;
69
- private showUntracked = true;
316
+ /** The pathspec of the running status (git's `s->pathspec`), parsed from `paths` */
317
+ private pathspec: PathspecItem[] = [];
318
+ private ignoredMode: IgnoredMode = "no";
319
+ private untrackedMode?: UntrackedFilesMode;
320
+ /** The mode of the running status (the setter, else `status.showUntrackedFiles`) */
321
+ private resolvedUntracked: UntrackedFilesMode = "normal";
322
+ private renames?: boolean;
323
+ private renameLimit?: number;
324
+ private ignoreSubmodules?: SubmoduleIgnoreMode;
325
+ private gitmodules?: Promise<GitmodulesEntry[]>;
326
+ /** The commit the index is compared with: undefined is HEAD, null none (initial) */
327
+ private reference?: ObjectId | null;
328
+ /** Whether the refreshed stats (and the untracked cache) are written back */
329
+ private writeIndex = true;
330
+ /** `status.submoduleSummary` as set here (a limit; -1 none, 0 off) */
331
+ private submoduleSummary?: number;
70
332
 
71
333
  /**
72
- * Add a path filter.
334
+ * Add a pathspec element (from the top of the worktree), as `git status -- <pathspec>`
335
+ * takes it (pathspec.c): a path or directory, a wildcard (`*.txt`, matched by `fnmatch`
336
+ * without `WM_PATHNAME`, so `*` crosses `/`), or an element with magic: `:(glob)`,
337
+ * `:(literal)`, `:(icase)`, `:(exclude)` (`:!`, `:^`; an element of excludes alone gets
338
+ * an implicit `.`), `:/` and `:(prefix:N)`. `GIT_LITERAL_PATHSPECS`, `GIT_GLOB_PATHSPECS`,
339
+ * `GIT_NOGLOB_PATHSPECS` and `GIT_ICASE_PATHSPECS` of the host environment apply.
340
+ * `:(attr:<spec>)` matches paths by their attributes (`name`, `-name`, `!name`,
341
+ * `name=value`, several per element), read through the worktree's attribute stack, an
342
+ * untracked directory by its own name (`d/`). Tracked paths are matched as diff-files and
343
+ * diff-index match them (`ce_path_match`), untracked ones by dir.c's walk.
73
344
  *
74
- * Only status for paths starting with this prefix will be returned.
75
- *
76
- * @param path Path prefix to filter by
345
+ * @param path A pathspec element
77
346
  */
78
347
  addPath(path: string): this {
79
348
  this.checkCallable();
@@ -82,39 +351,462 @@ export class StatusCommand extends GitCommand<Status> {
82
351
  }
83
352
 
84
353
  /**
85
- * Whether to report the ignored files the index does not track (`--ignored`). Off by
86
- * default.
354
+ * Which ignored files the index does not track to report (`--ignored[=<mode>]`): `no`
355
+ * (the default), `traditional` (`true`: what `--ignored` alone means) or `matching`. They
356
+ * are looked for with the untracked files, so `--untracked-files=no` shows none, and
357
+ * `matching` with it fails as git does ("Unsupported combination of ignored and
358
+ * untracked-files arguments").
359
+ */
360
+ setIgnored(ignored: boolean | IgnoredMode): this {
361
+ this.checkCallable();
362
+ this.ignoredMode = ignored === true ? "traditional" : ignored === false ? "no" : ignored;
363
+ return this;
364
+ }
365
+
366
+ /**
367
+ * Which untracked files to report (`--untracked-files=<mode>`): `normal` shows an
368
+ * untracked directory as `dir/` (hiding one with nothing untracked in it), `all` every
369
+ * file in it, `no` none (untracked files inside submodules are not looked for either).
370
+ * Unset, `status.showUntrackedFiles` decides, else `normal` (git's default).
87
371
  */
88
- setIgnored(ignored: boolean): this {
372
+ setUntrackedFiles(mode: UntrackedFilesMode): this {
89
373
  this.checkCallable();
90
- this.showIgnored = ignored;
374
+ this.untrackedMode = mode;
91
375
  return this;
92
376
  }
93
377
 
94
378
  /**
95
- * Whether to report untracked files (`--untracked-files=all`, the default, or `=no`).
379
+ * Whether to report untracked files: true is `--untracked-files=all` (every file listed),
380
+ * false `--untracked-files=no`.
381
+ *
382
+ * @deprecated Use {@link setUntrackedFiles}.
96
383
  */
97
384
  setUntracked(untracked: boolean): this {
385
+ return this.setUntrackedFiles(untracked ? "all" : "no");
386
+ }
387
+
388
+ /**
389
+ * Whether to detect renames (`--renames` / `--no-renames`). Unset, `status.renames`
390
+ * decides, else `diff.renames`, else on (git's default).
391
+ */
392
+ setRenames(renames: boolean): this {
393
+ this.checkCallable();
394
+ this.renames = renames;
395
+ return this;
396
+ }
397
+
398
+ /**
399
+ * The rename limit: inexact renames are looked for only while the unpaired deleted
400
+ * times added paths stay within its square. Unset, `status.renameLimit` decides, else
401
+ * `diff.renameLimit`, else 1000; 0 is no limit.
402
+ */
403
+ setRenameLimit(limit: number): this {
404
+ this.checkCallable();
405
+ this.renameLimit = limit;
406
+ return this;
407
+ }
408
+
409
+ /**
410
+ * `--ignore-submodules=<when>`: overrides `diff.ignoreSubmodules` and every
411
+ * `submodule.<name>.ignore`. `all` hides submodule changes (staged ones too), `dirty`
412
+ * only reports a submodule at another commit, `untracked` ignores untracked files inside
413
+ * submodules, `none` reports everything.
414
+ */
415
+ setIgnoreSubmodules(mode: SubmoduleIgnoreMode): this {
416
+ this.checkCallable();
417
+ this.ignoreSubmodules = mode;
418
+ return this;
419
+ }
420
+
421
+ /**
422
+ * The commit the index is compared with instead of HEAD (`s->reference`: `git commit
423
+ * --amend` compares with `HEAD^1`), null for none (every entry new, as before the first
424
+ * commit).
425
+ */
426
+ setReferenceCommit(id: ObjectId | null): this {
427
+ id = id === null ? null : canonicalObjectId(id);
428
+ this.checkCallable();
429
+ this.reference = id;
430
+ return this;
431
+ }
432
+
433
+ /**
434
+ * Whether the stats refreshed while comparing (and a changed untracked cache) are written
435
+ * back to the index (default true, as `git status`). A caller holding the index with
436
+ * edits of its own (a commit's prepared index) passes false.
437
+ */
438
+ setWriteIndex(write: boolean): this {
439
+ this.checkCallable();
440
+ this.writeIndex = write;
441
+ return this;
442
+ }
443
+
444
+ /**
445
+ * The submodule summaries of the long format (`status.submoduleSummary`, which this
446
+ * overrides): true lists every commit of each changed submodule, a number at most that
447
+ * many (a negative one: all), false or 0 none. The summaries are `git submodule summary
448
+ * --cached` and `--files` (see {@link SubmoduleSummaryCommand}), under "Submodule changes
449
+ * to be committed:" and "Submodules changed but not updated:".
450
+ */
451
+ setSubmoduleSummary(summary: boolean | number): this {
98
452
  this.checkCallable();
99
- this.showUntracked = untracked;
453
+ this.submoduleSummary = summary === true ? -1 : summary === false ? 0 : summary;
100
454
  return this;
101
455
  }
102
456
 
457
+ /** git_status_config's `status.submodulesummary` (git_config_bool_or_int; true is -1). */
458
+ private submoduleSummaryLimit(): number {
459
+ if (this.submoduleSummary !== undefined) return this.submoduleSummary;
460
+ const value = this.config.value("status.submoduleSummary");
461
+ if (value === undefined) return 0;
462
+ const int = parseConfigInt(value);
463
+ if (int !== undefined) return int;
464
+ const bool = parseGitBool(value);
465
+ if (bool === undefined) {
466
+ throw new InvalidConfigError(
467
+ "status.submoduleSummary",
468
+ `fatal: bad boolean config value '${value}' for 'status.submodulesummary'`,
469
+ );
470
+ }
471
+ return bool ? -1 : 0;
472
+ }
473
+
474
+ /** wt_longstatus_print_submodule_summary's two runs of `git submodule summary`. */
475
+ private async submoduleSummaries(
476
+ limit: number,
477
+ amend: boolean,
478
+ ): Promise<{ staged: string; unstaged: string }> {
479
+ const run = (configure: (c: SubmoduleSummaryCommand) => void) => {
480
+ const command = new SubmoduleSummaryCommand(this.workingCopy)
481
+ .setForStatus(true)
482
+ .setSummaryLimit(limit);
483
+ configure(command);
484
+ return command.call();
485
+ };
486
+ const staged = await run((c) => c.setCached(true).setCommit(amend ? "HEAD^" : "HEAD"));
487
+ const unstaged = await run((c) => c.setFiles(true));
488
+ return { staged, unstaged };
489
+ }
490
+
491
+ /** The commit compared with: the one set, else HEAD's (undefined: none). */
492
+ private async referenceCommit(): Promise<ObjectId | undefined> {
493
+ if (this.reference !== undefined) return this.reference ?? undefined;
494
+ const headRef = await this.refsStore.resolve("HEAD").catch(() => undefined);
495
+ if (!headRef?.objectId) return undefined;
496
+ // repo_get_oid("HEAD") names a commit only when it loads as one
497
+ return (await this.commits.load(headRef.objectId).catch(() => undefined))
498
+ ? headRef.objectId
499
+ : undefined;
500
+ }
501
+
502
+ /**
503
+ * The status as `git status` prints it (wt_status_print), in the format asked: the long
504
+ * format (the default, or `status.short`), `short`, `porcelain` (v1) or `porcelain-v2`,
505
+ * with `--branch`, `-z`, `--show-stash` and `-v`; the deferred configuration
506
+ * (`status.short`, `status.branch`, `status.aheadBehind`, `status.showStash`) applies to
507
+ * the human formats as in git. `committable` is wt_status's: something staged (or a
508
+ * merge with every conflict resolved).
509
+ *
510
+ * @example
511
+ * ```typescript
512
+ * const { text } = await git.status().callText({ format: "short", branch: true });
513
+ * // "## main...origin/main [ahead 1]\n M a.txt\n?? new.txt\n"
514
+ * ```
515
+ */
516
+ async callText(options: StatusCallTextOptions = {}): Promise<StatusTextResult> {
517
+ const z = options.z === true;
518
+ let format = options.format;
519
+ if (z && format === "long") {
520
+ throw new IncompatibleOptionsError(
521
+ ["--long", "-z"],
522
+ "options '--long' and '-z' cannot be used together",
523
+ );
524
+ }
525
+ if (z && format === undefined) format = "porcelain";
526
+ const deferred = format !== "porcelain" && format !== "porcelain-v2" && !z;
527
+ const config = this.config;
528
+ if (deferred && format === undefined) {
529
+ format = cfgBool(config, "status.short", false) ? "short" : "long";
530
+ }
531
+ const resolvedFormat = format ?? "long";
532
+ const branch = options.branch ?? (deferred ? cfgBool(config, "status.branch", false) : false);
533
+ const quick =
534
+ options.aheadBehind !== undefined
535
+ ? !options.aheadBehind
536
+ : deferred
537
+ ? !cfgBool(config, "status.aheadBehind", true)
538
+ : false;
539
+ const showStash = options.showStash ?? cfgBool(config, "status.showStash", false);
540
+ const status = await this.call();
541
+ const hints = options.hints ?? cfgBool(config, "advice.statusHints", true);
542
+ const commentPrefix =
543
+ options.commentPrefix ??
544
+ (resolvedFormat === "long" && cfgBool(config, "status.displayCommentPrefix", false)
545
+ ? commentLineString(this.workingCopy)
546
+ : undefined);
547
+ const referenceId = await this.referenceCommit();
548
+ const header = await this.readHeader(status, referenceId, {
549
+ long: resolvedFormat === "long",
550
+ short: branch && resolvedFormat !== "long",
551
+ quick,
552
+ divergenceAdvice: options.commitTemplate !== true,
553
+ hints,
554
+ stash: showStash,
555
+ amend: options.amend === true,
556
+ nowarn: options.nowarn === true,
557
+ });
558
+ const info = statusCommitInfo(status, header);
559
+ let verbose: string | undefined;
560
+ if ((options.verbose ?? 0) > 0 && resolvedFormat === "long") {
561
+ verbose = await this.verboseText(options.verbose ?? 0, {
562
+ toFile: options.toFile === true,
563
+ cutLineAdded: options.cutLineAdded === true,
564
+ committable: info.committable,
565
+ worktreeChanges: info.worktreeChanges,
566
+ referenceId,
567
+ commentPrefix,
568
+ });
569
+ }
570
+ const summaryLimit = resolvedFormat === "long" ? this.submoduleSummaryLimit() : 0;
571
+ const submoduleSummary =
572
+ summaryLimit !== 0 && this.ignoreSubmodules !== "all"
573
+ ? await this.submoduleSummaries(summaryLimit, options.amend === true)
574
+ : undefined;
575
+ const out = formatStatusText(status, header, {
576
+ format: resolvedFormat,
577
+ branch,
578
+ z,
579
+ showStash,
580
+ quotePath: cfgBool(config, "core.quotePath", true),
581
+ hints,
582
+ ...(commentPrefix !== undefined ? { commentPrefix } : {}),
583
+ untracked: this.resolvedUntracked,
584
+ ignored: this.ignoredMode,
585
+ commitTemplate: options.commitTemplate === true,
586
+ amend: options.amend === true,
587
+ nowarn: options.nowarn === true,
588
+ whence: options.whence ?? (await this.determineWhence()),
589
+ reference: options.amend ? "HEAD^1" : "HEAD",
590
+ aheadBehindQuick: quick,
591
+ ...(verbose !== undefined ? { verbose } : {}),
592
+ ...(submoduleSummary ? { submoduleSummary } : {}),
593
+ });
594
+ return {
595
+ ...out,
596
+ status,
597
+ warnings: [...status.warnings, ...header.warnings],
598
+ };
599
+ }
600
+
601
+ /**
602
+ * builtin/commit.c's determine_whence: a merge while MERGE_HEAD exists, a cherry-pick
603
+ * while CHERRY_PICK_HEAD does (sequencer_determine_whence), else a plain commit.
604
+ */
605
+ private async determineWhence(): Promise<CommitWhence> {
606
+ const state = new OperationState(this.workingCopy.checkout, this.refsStore);
607
+ if ((await state.read("MERGE_HEAD")) !== undefined) return "merge";
608
+ if (await state.ref("CHERRY_PICK_HEAD")) return "cherry-pick";
609
+ return "commit";
610
+ }
611
+
612
+ /** The header of the text forms: branch, operations in progress, tracking, stash. */
613
+ private async readHeader(
614
+ status: Status,
615
+ referenceId: ObjectId | undefined,
616
+ want: {
617
+ long: boolean;
618
+ short: boolean;
619
+ quick: boolean;
620
+ divergenceAdvice: boolean;
621
+ hints: boolean;
622
+ stash: boolean;
623
+ amend: boolean;
624
+ nowarn: boolean;
625
+ },
626
+ ) {
627
+ const refs = this.refsStore;
628
+ const resolver = this.revisionResolver();
629
+ const commits = this.walkCommits;
630
+ const peel = async (id: ObjectId) => resolver.commitReference(id).catch(() => undefined);
631
+ const tracking: TrackingSource = {
632
+ config: (key) => this.config.value(key),
633
+ upstreamOf: (branch) => resolver.upstreamOf(branch).catch(() => undefined),
634
+ pushOf: (branch) => resolver.pushOf(branch).catch(() => undefined),
635
+ pushRemoteOf: async (branch) => {
636
+ try {
637
+ return resolver.pushRemoteOf(branch);
638
+ } catch {
639
+ return undefined;
640
+ }
641
+ },
642
+ refCommit: async (ref) => {
643
+ const id = (await refs.resolve(ref).catch(() => undefined))?.objectId;
644
+ return id ? peel(id) : undefined;
645
+ },
646
+ shortenRef: (ref) => shortenUnambiguousRef(refs, ref),
647
+ aheadBehind: (ours, theirs) => aheadBehind(commits, ours, theirs),
648
+ };
649
+ const entries = this.staging.entryList?.() ?? (await collectEntries(this.staging.entries()));
650
+ return readStatusHeader(
651
+ {
652
+ refs,
653
+ state: new OperationState(this.workingCopy.checkout, refs),
654
+ tracking,
655
+ abbreviate: (id) => this.abbreviateObjectId(id),
656
+ dwimRef: (name) => resolver.dwimRef(name).catch(() => []),
657
+ commitOf: peel,
658
+ objectExists: async (id) =>
659
+ (await resolver.objectType(id).catch(() => undefined)) !== undefined,
660
+ config: (key) => this.config.value(key),
661
+ entries,
662
+ },
663
+ {
664
+ ...(referenceId ? { referenceId } : {}),
665
+ tracking: {
666
+ ...(want.long
667
+ ? {
668
+ long: {
669
+ quick: want.quick,
670
+ divergenceAdvice: want.divergenceAdvice,
671
+ hints: want.hints,
672
+ },
673
+ }
674
+ : {}),
675
+ ...(want.short ? { short: { quick: want.quick } } : {}),
676
+ },
677
+ amend: want.amend,
678
+ nowarn: want.nowarn,
679
+ workdirDirty: statusCommitInfo(status, { isInitial: !referenceId, state: {} }).workdirDirty,
680
+ stash: want.stash,
681
+ },
682
+ );
683
+ }
684
+
685
+ /**
686
+ * wt_longstatus_print_verbose: the staged changes as a patch (and with `-vv` the unstaged
687
+ * ones, under their own headers); in a file (the commit template) after the cut line.
688
+ */
689
+ private async verboseText(
690
+ level: number,
691
+ o: {
692
+ toFile: boolean;
693
+ cutLineAdded: boolean;
694
+ committable: boolean;
695
+ /** wt_status_check_worktree_changes: unmerged paths left out */
696
+ worktreeChanges: boolean;
697
+ referenceId: ObjectId | undefined;
698
+ commentPrefix: string | undefined;
699
+ },
700
+ ): Promise<string> {
701
+ const p = (text: string) =>
702
+ o.commentPrefix !== undefined ? `${o.commentPrefix}${text ? ` ${text}` : ""}\n` : `${text}\n`;
703
+ let out = "";
704
+ if (o.toFile && !o.cutLineAdded) out += cutLine(o.commentPrefix ?? "#");
705
+ const twoLevels = level > 1;
706
+ let cachedPrefixes: { srcPrefix: string; dstPrefix: string } | undefined;
707
+ if (twoLevels && o.committable) {
708
+ if (o.toFile) out += p("");
709
+ out += p("Changes to be committed:");
710
+ cachedPrefixes = { srcPrefix: "c/", dstPrefix: "i/" };
711
+ }
712
+ const cached = new DiffCommand(this.workingCopy)
713
+ .setCached(true)
714
+ .setOldTree(o.referenceId ?? this.objectFormat.emptyTreeId)
715
+ .setOptions({ ...(cachedPrefixes ?? {}) });
716
+ if (this.renames !== undefined) cached.setRenames(this.renames);
717
+ out += await cached.callText("patch");
718
+ if (twoLevels && o.worktreeChanges) {
719
+ out += p("--------------------------------------------------");
720
+ out += p("Changes not staged for commit:");
721
+ // run_diff_files without combine_merges (a conflicted path listed as unmerged and
722
+ // diffed as its stage 2) nor dirty_submodules (git sets it after diff_setup_done)
723
+ const files = new DiffCommand(this.workingCopy)
724
+ .setCombineMerges(false)
725
+ .setDirtySubmodules(false)
726
+ .setOptions({ srcPrefix: "i/", dstPrefix: "w/" });
727
+ if (this.renames !== undefined) files.setRenames(this.renames);
728
+ out += await files.callText("patch");
729
+ }
730
+ return out;
731
+ }
732
+
103
733
  async call(): Promise<Status> {
104
734
  this.checkCallable();
105
735
  this.setCallable(false);
736
+ // git reads its configuration, then the options, before anything else
737
+ this.resolvedUntracked = this.untrackedFilesMode();
738
+ // git_status_config ends in git_diff_ui_config: a diff.submodule without a value dies
739
+ readDiffSubmoduleConfig(this.workingCopy);
740
+ this.pathspec = this.parsePaths();
741
+ if (this.ignoredMode === "matching" && this.resolvedUntracked === "no") {
742
+ throw new IncompatibleOptionsError(
743
+ ["--ignored=matching", "--untracked-files=no"],
744
+ "Unsupported combination of ignored and untracked-files arguments",
745
+ );
746
+ }
106
747
  const worktree = this.worktreeAccess;
107
748
  // one operation: fresh ignore rules and one lstat cache for the whole status
108
749
  return worktree?.batch ? worktree.batch(() => this.compute(worktree)) : this.compute(worktree);
109
750
  }
110
751
 
752
+ /** cmd_status's parse_pathspec (PATHSPEC_PREFER_FULL): none for no elements. */
753
+ private parsePaths(): PathspecItem[] {
754
+ if (this.paths.length === 0) return [];
755
+ try {
756
+ const global = globalPathspecMagic(hostEnvironmentOf(this.workingCopy)?.pathspecs);
757
+ return parsePathspec(this.paths, { global, attr: true });
758
+ } catch (error) {
759
+ throw new InvalidArgumentError("path", this.paths, `fatal: ${(error as Error).message}`);
760
+ }
761
+ }
762
+
763
+ private get config(): RemoteConfigStore {
764
+ return RemoteConfigStore.from(this.workingCopy);
765
+ }
766
+
767
+ /**
768
+ * The untracked mode: the setter, else `status.showUntrackedFiles`, else `normal`. A bad
769
+ * value of the variable fails whatever the setter says, as git reads its configuration
770
+ * first.
771
+ */
772
+ private untrackedFilesMode(): UntrackedFilesMode {
773
+ const configured = readShowUntrackedFiles(this.workingCopy);
774
+ return this.untrackedMode ?? configured ?? "normal";
775
+ }
776
+
111
777
  private async compute(worktree: Worktree | undefined): Promise<Status> {
778
+ // git's repo_read_index: skip-worktree entries present in the worktree are checked out
779
+ await this.clearPresentSkipWorktree();
112
780
  const head = new Map<string, StatusSide>();
113
- const headRef = await this.refsStore.resolve("HEAD");
114
- if (headRef?.objectId) {
115
- const headCommit = await this.commits.load(headRef.objectId).catch(() => undefined);
116
- if (headCommit) await this.collectTreeEntries(headCommit.tree, "", head);
781
+ // directories where HEAD and the index agree (by the cache-tree): their entries are HEAD's
782
+ const sameAsHead = new Set<string>();
783
+ const referenceId = await this.referenceCommit();
784
+ if (referenceId) {
785
+ const headCommit = await this.commits.load(referenceId).catch(() => undefined);
786
+ if (headCommit) {
787
+ const cacheTree = this.staging.getCacheTree?.();
788
+ await this.collectTreeEntries(headCommit.tree, "", head, cacheTree, sameAsHead);
789
+ }
117
790
  }
791
+ // (the entries come in path order: the last directory's answer serves its neighbours)
792
+ let lastDir: string | undefined;
793
+ let lastInSame = false;
794
+ const headOf = (entry: StagingEntry): StatusSide | typeof SAME | undefined => {
795
+ const path = entry.path;
796
+ const found = head.get(path);
797
+ if (found || sameAsHead.size === 0 || entry.intentToAdd) return found;
798
+ const slash = path.lastIndexOf("/");
799
+ const dir = slash < 0 ? "" : path.slice(0, slash);
800
+ if (dir !== lastDir) {
801
+ lastDir = dir;
802
+ let inSame = sameAsHead.has("");
803
+ for (let k = path.indexOf("/"); !inSame && k > 0; k = path.indexOf("/", k + 1)) {
804
+ inSame = sameAsHead.has(path.slice(0, k));
805
+ }
806
+ lastInSame = inSame;
807
+ }
808
+ return lastInSame ? SAME : undefined;
809
+ };
118
810
 
119
811
  const added = new Set<string>();
120
812
  const changed = new Set<string>();
@@ -129,67 +821,149 @@ export class StatusCommand extends GitCommand<Status> {
129
821
 
130
822
  const trust = worktree ? worktreeModeTrust(this.workingCopy, worktree) : undefined;
131
823
  const indexTime = this.staging.getUpdateTime();
132
- const tracked = new Set<string>();
824
+ const gitlinks = new Set<string>();
133
825
  const refresh: IndexStatUpdate[] = [];
134
826
  const unmerged = new Map<string, [StatusSide?, StatusSide?, StatusSide?]>();
827
+ // the `.gitignore` files whose entry is up to date (git's ce_uptodate after its refresh):
828
+ // the untracked cache takes their ids from the index
829
+ const upToDate = new Set<string>();
135
830
 
136
- for await (const entry of this.staging.entries()) {
137
- tracked.add(entry.path);
138
- if (!this.matchesPath(entry.path)) continue;
139
- if (entry.stage !== 0) {
140
- const stages = unmerged.get(entry.path) ?? [undefined, undefined, undefined];
141
- stages[entry.stage - 1] = { mode: entry.mode, id: entry.objectId };
142
- unmerged.set(entry.path, stages);
143
- continue;
831
+ // the stat pass: the files of the entries compared below, stat'ed a chunk at a time
832
+ // (git's preload_index), each entry then compared synchronously where its stat settles
833
+ // it, so only the few undecided ones (racy, changed, submodules) cost a promise
834
+ const matchAll = this.paths.length === 0;
835
+ const stated = (entry: StagingEntry) =>
836
+ !!worktree &&
837
+ entry.stage === 0 &&
838
+ !entry.skipWorktree &&
839
+ !entry.assumeValid &&
840
+ !isGitlink(entry.mode) &&
841
+ (matchAll || this.matchesTracked(entry.path, entry.mode));
842
+ const all = this.staging.entryList?.() ?? (await collectEntries(this.staging.entries()));
843
+ // `:(attr:...)`: the attributes of the tracked paths the pathspec may match
844
+ const attributes = PathspecAttributes.forWorktree(this.pathspec, worktree);
845
+ await attributes?.load([...all.map((e) => e.path), ...head.keys()]);
846
+ // the index's paths by binary search (git's index_name_pos), no set of every path built
847
+ const index = new IndexPathLookup(all.map((e) => e.path));
848
+ const tracked = { has: (path: string) => index.has(path) };
849
+ const wanted: boolean[] = new Array(all.length);
850
+ for (let start = 0; start < all.length; ) {
851
+ let end = start;
852
+ const paths: string[] = [];
853
+ while (end < all.length && paths.length < STAT_CHUNK) {
854
+ const entry = all[end] as StagingEntry;
855
+ const want = stated(entry);
856
+ wanted[end] = want;
857
+ if (want) paths.push(entry.path);
858
+ end++;
144
859
  }
145
- const h = head.get(entry.path);
146
- const staged = { mode: entry.mode, id: entry.objectId };
147
- let x: StatusCode = " ";
148
- if (!h) {
149
- if (!entry.intentToAdd) {
150
- x = "A";
151
- added.add(entry.path);
860
+ const found = worktree && paths.length > 0 ? await getWorktreeEntries(worktree, paths) : [];
861
+ let k = 0;
862
+ for (let i = start; i < end; i++) {
863
+ const entry = all[i] as StagingEntry;
864
+ const current = wanted[i] ? (found[k++] ?? null) : undefined;
865
+ if (entry.mode === FileMode.GITLINK) gitlinks.add(entry.path);
866
+ if (!matchAll && !this.matchesTracked(entry.path, entry.mode)) continue;
867
+ if (entry.stage !== 0) {
868
+ const stages = unmerged.get(entry.path) ?? [undefined, undefined, undefined];
869
+ stages[entry.stage - 1] = { mode: entry.mode, id: entry.objectId };
870
+ unmerged.set(entry.path, stages);
871
+ continue;
152
872
  }
153
- } else if (h.id !== entry.objectId || h.mode !== entry.mode) {
154
- x = typeOf(h.mode) === typeOf(entry.mode) ? "M" : "T";
155
- changed.add(entry.path);
156
- }
157
- let y: StatusCode = " ";
158
- let worktreeMode: number | undefined = entry.mode;
159
- let commitChanged = false;
160
- if (worktree && !entry.skipWorktree && !entry.assumeValid) {
161
- const result = await compareWithWorktree(worktree, entry, { trust, indexTime });
162
- worktreeMode = result.worktreeMode;
163
- // proved clean only by hashing: its fresh stat goes into the index (git's refresh);
164
- // changed behind a matching stat: smudged
165
- const update = statUpdateOf(entry, result);
166
- if (update) refresh.push(update);
167
- if (entry.mode === FileMode.GITLINK && result.kind === "modified") commitChanged = true;
168
- if (result.kind === "deleted") {
169
- y = "D";
170
- missing.add(entry.path);
171
- } else if (result.kind) {
172
- y = result.kind === "typechange" ? "T" : "M";
173
- modified.add(entry.path);
174
- } else if (entry.intentToAdd) {
175
- y = "A";
176
- added.add(entry.path);
873
+ // HEAD's side: SAME (a directory the cache-tree shows unchanged) is the entry itself
874
+ const head = headOf(entry);
875
+ let x: StatusCode = " ";
876
+ if (head === SAME) {
877
+ // HEAD and the index agree
878
+ } else if (head && entry.intentToAdd) {
879
+ // an intent-to-add entry is in no tree: against HEAD's path it is a deletion (git's
880
+ // diff-index --cached), the file itself new on the worktree side
881
+ x = "D";
882
+ removed.add(entry.path);
883
+ } else if (!head) {
884
+ // an added submodule a `submodule.<name>.ignore=all` hides (git's diff_addremove)
885
+ const hidden = isGitlink(entry.mode) && (await this.indexIgnoresAll(entry.path));
886
+ if (!entry.intentToAdd && !hidden) {
887
+ x = "A";
888
+ added.add(entry.path);
889
+ }
890
+ } else if (head.id !== entry.objectId || head.mode !== entry.mode) {
891
+ const hidden =
892
+ isGitlink(head.mode) &&
893
+ isGitlink(entry.mode) &&
894
+ (await this.indexIgnoresAll(entry.path));
895
+ if (!hidden) {
896
+ x = typeOf(head.mode) === typeOf(entry.mode) ? "M" : "T";
897
+ changed.add(entry.path);
898
+ }
899
+ }
900
+ let y: StatusCode = " ";
901
+ let worktreeMode: number | undefined = entry.mode;
902
+ let commitChanged = false;
903
+ let dirt: SubmoduleDirt = {};
904
+ if (worktree && (entry.skipWorktree || entry.assumeValid)) {
905
+ // git's refresh takes these as up to date (CE_SKIP_WORKTREE, CE_VALID)
906
+ if (isIgnoreFilePath(entry.path)) upToDate.add(entry.path);
907
+ } else if (
908
+ current !== undefined &&
909
+ isCleanByStat(entry, current, trust as WorktreeModeTrust, indexTime)
910
+ ) {
911
+ // clean by its stat: nothing to report, nothing to refresh
912
+ if (isIgnoreFilePath(entry.path)) upToDate.add(entry.path);
913
+ } else if (worktree) {
914
+ const flags = isGitlink(entry.mode) ? await this.worktreeFlags(entry.path) : undefined;
915
+ if (!flags?.all) {
916
+ const result =
917
+ (current !== undefined &&
918
+ compareWithWorktreeStat(entry, current, trust as WorktreeModeTrust, indexTime)) ||
919
+ (await compareWithWorktree(worktree, entry, { trust, indexTime }, current));
920
+ worktreeMode = result.worktreeMode;
921
+ // proved clean only by hashing: its fresh stat goes into the index (git's refresh);
922
+ // changed behind a matching stat: smudged
923
+ if (result.hashedId !== undefined || result.smudge) {
924
+ const update = statUpdateOf(entry, result);
925
+ if (update) refresh.push(update);
926
+ }
927
+ if (!result.kind && isIgnoreFilePath(entry.path)) upToDate.add(entry.path);
928
+ if (flags && result.kind === "modified") commitChanged = true;
929
+ // a populated submodule's own index and worktree (git's is_submodule_modified)
930
+ if (flags && !flags.dirty && result.worktreeEntry?.isDirectory) {
931
+ dirt = await readSubmoduleDirt(worktree, entry.path, flags.untracked);
932
+ }
933
+ if (result.kind === "deleted") {
934
+ y = "D";
935
+ missing.add(entry.path);
936
+ } else if (result.kind || dirt.modified || dirt.untracked) {
937
+ y = result.kind === "typechange" ? "T" : "M";
938
+ modified.add(entry.path);
939
+ } else if (entry.intentToAdd) {
940
+ y = "A";
941
+ added.add(entry.path);
942
+ }
943
+ }
944
+ }
945
+ if (x !== " " || y !== " ") {
946
+ const staged = { mode: entry.mode, id: entry.objectId };
947
+ const h = head === SAME ? staged : head;
948
+ // git's v2 line of an intent-to-add entry: no index side while the file is there
949
+ // (".A", "DA" over a path of HEAD), and the placeholder as the index side once it is
950
+ // gone (".D" with the placeholder as the HEAD side too, "DD" with HEAD's)
951
+ const ita = entry.intentToAdd;
952
+ files.push({
953
+ path: entry.path,
954
+ index: x,
955
+ worktree: y,
956
+ head: ita && y === "D" ? (h ?? staged) : h,
957
+ staged: ita && y === "A" ? undefined : staged,
958
+ worktreeMode,
959
+ ...(commitChanged ? { submoduleCommitChanged: true } : {}),
960
+ ...(dirt.modified ? { submoduleModified: true } : {}),
961
+ ...(dirt.untracked ? { submoduleUntracked: true } : {}),
962
+ ...(ita ? { intentToAdd: true } : {}),
963
+ });
177
964
  }
178
965
  }
179
- if (x !== " " || y !== " ") {
180
- // git's v2 line of an intent-to-add entry: no index side while the file is there
181
- // (".A"), and the placeholder as the HEAD side once it is gone (".D")
182
- const ita = entry.intentToAdd;
183
- files.push({
184
- path: entry.path,
185
- index: x,
186
- worktree: y,
187
- head: ita && y === "D" ? staged : h,
188
- staged: ita && y === "A" ? undefined : staged,
189
- worktreeMode,
190
- ...(commitChanged ? { submoduleCommitChanged: true } : {}),
191
- });
192
- }
966
+ start = end;
193
967
  }
194
968
 
195
969
  for (const [path, stages] of unmerged) {
@@ -207,29 +981,81 @@ export class StatusCommand extends GitCommand<Status> {
207
981
  }
208
982
 
209
983
  for (const [path, h] of head) {
210
- if (tracked.has(path) || !this.matchesPath(path)) continue;
984
+ if (tracked.has(path) || !this.matchesTracked(path, h.mode)) continue;
985
+ if (isGitlink(h.mode) && (await this.indexIgnoresAll(path))) continue;
211
986
  removed.add(path);
212
987
  files.push({ path, index: "D", worktree: " ", head: h });
213
988
  }
214
989
 
215
- if (worktree && this.showUntracked) {
216
- for await (const file of findUntrackedFiles(worktree, (p) => tracked.has(p), {
217
- hasTrackedUnder: trackedUnder(tracked),
218
- includeIgnored: this.showIgnored,
219
- filter: (p) => this.matchesPath(p),
220
- })) {
221
- if (file.ignored) {
222
- ignored.add(file.path);
223
- files.push({ path: file.path, index: "!", worktree: "!" });
224
- } else {
225
- untracked.add(file.path);
226
- files.push({ path: file.path, index: "?", worktree: "?" });
227
- }
990
+ const renamed = new Map<string, string>();
991
+ const warnings: string[] = [];
992
+ if (this.detectsRenames()) await this.pairRenames(files, renamed, worktree, warnings);
993
+
994
+ // the index's untracked cache, as core.untrackedCache has it (git's tweak_untracked_cache)
995
+ const host = worktree ? await worktree.untrackedScanHost?.() : undefined;
996
+ const untrackedCache = openUntrackedCache(
997
+ this.staging,
998
+ this.config,
999
+ hostEnvironmentOf(this.workingCopy),
1000
+ host,
1001
+ this.objectFormat,
1002
+ );
1003
+ if (worktree && this.resolvedUntracked !== "no") {
1004
+ // git's wt_status_collect_untracked: the dir flags of the modes
1005
+ let flags =
1006
+ this.resolvedUntracked === "all"
1007
+ ? 0
1008
+ : DIR_SHOW_OTHER_DIRECTORIES | DIR_HIDE_EMPTY_DIRECTORIES;
1009
+ if (this.ignoredMode !== "no") {
1010
+ flags |= DIR_SHOW_IGNORED_TOO;
1011
+ if (this.ignoredMode === "matching") flags |= DIR_SHOW_IGNORED_TOO_MODE_MATCHING;
1012
+ }
1013
+ // read_directory, through the untracked cache for a whole-tree scan without ignored
1014
+ // files (validate_untracked_cache)
1015
+ const cache =
1016
+ host && matchAll && this.ignoredMode === "no"
1017
+ ? await untrackedCache.forScan(flags)
1018
+ : undefined;
1019
+ const ignoreFiles = this.indexIgnoreOids(all, upToDate);
1020
+ // dir.c asks the index through its name hashes, which fold case under core.ignorecase
1021
+ // (index_file_exists, directory_exists_in_index_icase): a file or directory differing
1022
+ // from an index path only by case is tracked, never untracked
1023
+ const ignoreCase = coreBool(this.workingCopy, "ignorecase", false);
1024
+ const scanIndex = new IndexPathLookup(index.all, { ignoreCase, gitlinks, sorted: true });
1025
+ const result = await scanUntracked(host ?? (await walkUntrackedScanHost(worktree)), {
1026
+ isTracked: (p) => scanIndex.has(p),
1027
+ isTrackedExactly: (p) => index.hasExactly(p),
1028
+ trackedIn: (dir) => scanIndex.trackedIn(dir),
1029
+ indexDirectory: (dir) => scanIndex.indexDirectory(dir),
1030
+ indexIgnoreOid: (p) => ignoreFiles.upToDate.get(p),
1031
+ skipWorktreeIgnoreOid: (p) => ignoreFiles.skipWorktree.get(p),
1032
+ flags,
1033
+ ...(matchAll ? {} : { matcher: untrackedScanPathspec(this.pathspec, attributes) }),
1034
+ ...(cache ? { cache } : {}),
1035
+ indexSeconds: Math.floor(indexTime / 1000),
1036
+ ...(trust ? { stat: { ctime: trust.ctime, fullStat: trust.fullStat } } : {}),
1037
+ // git's "could not open directory" for each directory its scan cannot list
1038
+ onUnreadable: (path, error) => warnings.push(unreadableDirectoryWarning(path, error)),
1039
+ });
1040
+ for (const path of result.paths) {
1041
+ untracked.add(path);
1042
+ files.push({ path, index: "?", worktree: "?" });
1043
+ }
1044
+ for (const path of result.ignored) {
1045
+ ignored.add(path);
1046
+ files.push({ path, index: "!", worktree: "!" });
228
1047
  }
229
1048
  }
230
1049
 
231
- // as git status: the refreshed stats written back when the index is free and unchanged
232
- await refreshIndexStats(this.staging, refresh);
1050
+ // as git status: the refreshed stats written back when the index is free and unchanged,
1051
+ // with the untracked cache when it changed
1052
+ if (this.writeIndex) {
1053
+ await refreshIndexStats(
1054
+ this.staging,
1055
+ refresh,
1056
+ untrackedCache.changed() ? { untrackedCache: untrackedCache.cache ?? null } : undefined,
1057
+ );
1058
+ }
233
1059
 
234
1060
  return new StatusImpl(added, changed, removed, conflicting, {
235
1061
  modified,
@@ -238,42 +1064,437 @@ export class StatusCommand extends GitCommand<Status> {
238
1064
  ignored,
239
1065
  conflictingStageState,
240
1066
  files,
1067
+ renamed,
1068
+ warnings,
241
1069
  });
242
1070
  }
243
1071
 
244
1072
  /**
245
- * Check if a path matches the configured path filters.
1073
+ * The ids the untracked cache takes from the index for `.gitignore` files (git's
1074
+ * `add_patterns`): `upToDate`, the stage-0 entry's where the file is up to date with it
1075
+ * (assume-unchanged and skip-worktree count as up to date); `skipWorktree`, the stage-0
1076
+ * entry's where it is skip-worktree, for a file missing from the worktree (read from the
1077
+ * index then; an assume-unchanged one missing records the null id).
1078
+ */
1079
+ private indexIgnoreOids(
1080
+ entries: readonly StagingEntry[],
1081
+ upToDate: ReadonlySet<string>,
1082
+ ): { upToDate: Map<string, string>; skipWorktree: Map<string, string> } {
1083
+ const out = { upToDate: new Map<string, string>(), skipWorktree: new Map<string, string>() };
1084
+ if (upToDate.size === 0) return out;
1085
+ for (const entry of entries) {
1086
+ if (entry.stage !== 0 || !upToDate.has(entry.path)) continue;
1087
+ out.upToDate.set(entry.path, entry.objectId);
1088
+ if (entry.skipWorktree) out.skipWorktree.set(entry.path, entry.objectId);
1089
+ }
1090
+ return out;
1091
+ }
1092
+
1093
+ /** Whether renames are detected: the setter, else `status.renames`, else `diff.renames`. */
1094
+ private detectsRenames(): boolean {
1095
+ if (this.renames !== undefined) return this.renames;
1096
+ return (
1097
+ renamesValue(this.config.value("status.renames")) ??
1098
+ renamesValue(this.config.value("diff.renames")) ??
1099
+ true
1100
+ );
1101
+ }
1102
+
1103
+ /**
1104
+ * Pairs renames as git status does: on the index side (`diff-index --cached`) a path
1105
+ * removed from the index with one added to it; on the worktree side (`diff-files`) a
1106
+ * path deleted from the worktree with an intent-to-add file. The source's line goes (or
1107
+ * keeps only its other side); the destination's line becomes the rename. Unmerged paths
1108
+ * take part on the worktree side only, as diff-files queues them: a file there is a
1109
+ * destination, stage #2 of one gone a source; their own lines stay as they are.
246
1110
  */
247
- private matchesPath(path: string): boolean {
248
- if (this.paths.length === 0) {
249
- return true;
1111
+ private async pairRenames(
1112
+ files: StatusFileEntry[],
1113
+ renamed: Map<string, string>,
1114
+ worktree: Worktree | undefined,
1115
+ warnings: string[],
1116
+ ): Promise<void> {
1117
+ const limit =
1118
+ this.renameLimit ??
1119
+ intValue(this.config.value("status.renameLimit")) ??
1120
+ intValue(this.config.value("diff.renameLimit")) ??
1121
+ DEFAULT_RENAME_LIMIT;
1122
+ const byPath = new Map(files.map((f) => [f.path, f]));
1123
+ const blob = async (id: ObjectId) => concat((await this.blobs.load(id)) ?? []);
1124
+ const blobSize = async (id: ObjectId) => {
1125
+ try {
1126
+ return await this.blobs.size(id);
1127
+ } catch {
1128
+ return undefined;
1129
+ }
1130
+ };
1131
+ // diffcore-rename's prefetches: a partial clone's absent blobs in one batch (the
1132
+ // worktree side's files are no blobs)
1133
+ const prefetch = async (
1134
+ wanted: Array<{ candidate: RenameCandidate; side: "source" | "destination" }>,
1135
+ sourcesOnly = false,
1136
+ ) => {
1137
+ const ids = wanted
1138
+ .filter((w) => !sourcesOnly || w.side === "source")
1139
+ .filter((w) => w.candidate.mode !== 0o160000)
1140
+ .map((w) => w.candidate.id);
1141
+ await this.blobs.prefetch?.(ids);
1142
+ };
1143
+ // git's diff warning when inexact renames were skipped (git status itself prints none)
1144
+ let needed = 0;
1145
+ const onRenameLimit = (n: number) => {
1146
+ needed = Math.max(needed, n);
1147
+ };
1148
+ const drop = new Set<StatusFileEntry>();
1149
+
1150
+ // index side: HEAD's deletions against the index's additions
1151
+ const indexSources: RenameCandidate[] = [];
1152
+ const indexDestinations: RenameCandidate[] = [];
1153
+ for (const f of files) {
1154
+ if (f.stages) continue;
1155
+ if (f.index === "D" && f.head) indexSources.push({ path: f.path, ...side(f.head) });
1156
+ else if (f.index === "A" && f.staged) {
1157
+ indexDestinations.push({ path: f.path, ...side(f.staged) });
1158
+ }
250
1159
  }
251
- const p = path.endsWith("/") ? path.slice(0, -1) : path;
252
- for (const raw of this.paths) {
253
- const filterPath = raw.replace(/\/+$/, "");
254
- if (filterPath === "" || filterPath === ".") return true;
255
- if (p === filterPath || p.startsWith(`${filterPath}/`) || filterPath.startsWith(`${p}/`)) {
256
- return true;
1160
+ if (indexSources.length > 0 && indexDestinations.length > 0) {
1161
+ const pairs = await detectRenames(indexSources, indexDestinations, {
1162
+ renameLimit: limit,
1163
+ onRenameLimit,
1164
+ prefetch: (wanted) => prefetch(wanted),
1165
+ size: (c) => blobSize(c.id),
1166
+ load: (c) => blob(c.id),
1167
+ });
1168
+ for (const pair of pairs) {
1169
+ const from = byPath.get(pair.from);
1170
+ const to = byPath.get(pair.to);
1171
+ if (!from || !to) continue;
1172
+ to.index = "R";
1173
+ to.head = from.head;
1174
+ // an intent-to-add source keeps its worktree side, without a HEAD side ("DA" to " A")
1175
+ if (from.intentToAdd && from.worktree !== " ") {
1176
+ from.index = " ";
1177
+ from.head = from.worktree === "D" ? from.staged : undefined;
1178
+ } else drop.add(from);
1179
+ to.renamedFrom = pair.from;
1180
+ to.renameScore = scorePercent(pair.score);
1181
+ renamed.set(pair.to, pair.from);
257
1182
  }
258
1183
  }
259
- return false;
1184
+
1185
+ // worktree side: deletions from the worktree against intent-to-add files; an unmerged
1186
+ // path takes part as git's diff-files queues it: its file, when there, is a destination
1187
+ // (diff_unmerge with the worktree mode), and its stage #2 a deletion (a source) when the
1188
+ // file is gone
1189
+ if (worktree) {
1190
+ const sources: RenameCandidate[] = [];
1191
+ const sourceSides = new Map<string, { mode: number; id: ObjectId }>();
1192
+ const destinations: Array<[RenameCandidate, StatusFileEntry]> = [];
1193
+ for (const f of files) {
1194
+ if (drop.has(f)) continue;
1195
+ if (f.stages) {
1196
+ const ours = f.stages[1];
1197
+ if (f.worktreeMode !== undefined) {
1198
+ destinations.push([{ path: f.path, mode: f.worktreeMode, id: "" }, f]);
1199
+ } else if (ours && !isGitlink(ours.mode)) {
1200
+ // no file (or a directory, which git's check_removed takes as gone)
1201
+ sources.push({ path: f.path, ...side(ours) });
1202
+ sourceSides.set(f.path, side(ours));
1203
+ }
1204
+ continue;
1205
+ }
1206
+ if (f.worktree === "D" && f.staged) {
1207
+ sources.push({ path: f.path, ...side(f.staged) });
1208
+ sourceSides.set(f.path, side(f.staged));
1209
+ } else if (f.worktree === "A" && f.worktreeMode !== undefined) {
1210
+ destinations.push([{ path: f.path, mode: f.worktreeMode, id: "" }, f]);
1211
+ }
1212
+ }
1213
+ if (sources.length > 0 && destinations.length > 0) {
1214
+ for (const [candidate] of destinations) {
1215
+ candidate.id = await worktree.computeHash(candidate.path);
1216
+ }
1217
+ // the worktree side as git's diff reads it: cleaned (convert_to_git) where a
1218
+ // conversion applies, read once for both its size and its content
1219
+ const cleaned = new Map<string, Promise<Uint8Array | undefined>>();
1220
+ const cleanedOf = (c: RenameCandidate) => {
1221
+ if (c.mode === 0o120000) return Promise.resolve(undefined);
1222
+ let found = cleaned.get(c.path);
1223
+ if (!found) {
1224
+ found = readConvertedContent(worktree, c.path);
1225
+ cleaned.set(c.path, found);
1226
+ }
1227
+ return found;
1228
+ };
1229
+ const pairs = await detectRenames(
1230
+ sources,
1231
+ destinations.map(([c]) => c),
1232
+ {
1233
+ renameLimit: limit,
1234
+ onRenameLimit,
1235
+ prefetch: (wanted) => prefetch(wanted, true),
1236
+ size: async (c, role) =>
1237
+ role === "source"
1238
+ ? blobSize(c.id)
1239
+ : ((await cleanedOf(c))?.length ?? (await worktree.getEntry(c.path))?.size),
1240
+ load: async (c, role) => {
1241
+ if (role === "source") return blob(c.id);
1242
+ const converted = await cleanedOf(c);
1243
+ cleaned.delete(c.path);
1244
+ return converted ?? concat(worktree.readContent(c.path));
1245
+ },
1246
+ },
1247
+ );
1248
+ for (const pair of pairs) {
1249
+ const from = byPath.get(pair.from);
1250
+ const to = byPath.get(pair.to);
1251
+ const source = sourceSides.get(pair.from);
1252
+ if (!from || !source || !to) continue;
1253
+ // the source keeps only its index side, if it has one; an unmerged source keeps
1254
+ // its line (its stage #2 deletion goes)
1255
+ if (from.stages) {
1256
+ // nothing shown changes
1257
+ } else if (from.index === " ") drop.add(from);
1258
+ else {
1259
+ from.worktree = " ";
1260
+ from.worktreeMode = source.mode;
1261
+ }
1262
+ // an unmerged destination stays as it is (wt_status shows its stages, no rename)
1263
+ if (to.stages) continue;
1264
+ to.worktree = "R";
1265
+ to.head = source;
1266
+ to.staged = source;
1267
+ to.renamedFrom = pair.from;
1268
+ to.renameScore = scorePercent(pair.score);
1269
+ renamed.set(pair.to, pair.from);
1270
+ }
1271
+ }
1272
+ }
1273
+
1274
+ if (drop.size > 0) {
1275
+ const kept = files.filter((f) => !drop.has(f));
1276
+ files.splice(0, files.length, ...kept);
1277
+ }
1278
+ if (needed > 0) {
1279
+ warnings.push(
1280
+ "warning: exhaustive rename detection was skipped due to too many files.",
1281
+ `warning: you may want to set your status.renameLimit variable to at least ${needed} and retry the command.`,
1282
+ );
1283
+ }
1284
+ }
1285
+
1286
+ /** The submodules `.gitmodules` names: the worktree's file, else the index's. */
1287
+ private submodules(): Promise<GitmodulesEntry[]> {
1288
+ this.gitmodules ??= (async () => {
1289
+ const worktree = this.worktreeAccess;
1290
+ let bytes: Uint8Array | undefined;
1291
+ try {
1292
+ const entry = worktree ? await worktree.getEntry(".gitmodules") : undefined;
1293
+ if (worktree && entry && !entry.isDirectory && entry.mode !== FileMode.SYMLINK) {
1294
+ bytes = await concat(worktree.readContent(".gitmodules"));
1295
+ }
1296
+ } catch {
1297
+ bytes = undefined;
1298
+ }
1299
+ if (!bytes) {
1300
+ const staged = await this.staging.getEntry(".gitmodules");
1301
+ if (staged && staged.mode !== FileMode.SYMLINK) {
1302
+ bytes = await concat((await this.blobs.load(staged.objectId)) ?? []);
1303
+ }
1304
+ }
1305
+ return bytes ? parseGitmodules(new TextDecoder().decode(bytes)) : [];
1306
+ })();
1307
+ return this.gitmodules;
1308
+ }
1309
+
1310
+ /**
1311
+ * `submodule.<name>.ignore` for the submodule at `path`: the repository's config, else
1312
+ * `.gitmodules`; undefined when neither names a valid value (or no submodule is there).
1313
+ */
1314
+ private async submoduleIgnore(path: string): Promise<SubmoduleIgnoreMode | undefined> {
1315
+ const submodule = (await this.submodules()).find((s) => s.path === path);
1316
+ if (!submodule) return undefined;
1317
+ const configured = this.config.value(`submodule.${submodule.name}.ignore`)?.trim();
1318
+ if (configured !== undefined) return isSubmoduleIgnoreMode(configured) ? configured : undefined;
1319
+ const declared = submodule.ignore?.trim();
1320
+ return isSubmoduleIgnoreMode(declared) ? declared : undefined;
1321
+ }
1322
+
1323
+ /**
1324
+ * What the worktree side ignores of the submodule at `path`, as git's status sets its
1325
+ * diff flags: `--ignore-submodules` overrides everything; else `submodule.<name>.ignore`
1326
+ * replaces `diff.ignoreSubmodules` (and `--untracked-files=no`) when set.
1327
+ */
1328
+ private async worktreeFlags(path: string): Promise<SubmoduleIgnoreFlags> {
1329
+ if (this.ignoreSubmodules) return submoduleIgnoreFlags(this.ignoreSubmodules);
1330
+ const own = await this.submoduleIgnore(path);
1331
+ if (own) return submoduleIgnoreFlags(own);
1332
+ const configured = this.config.value("diff.ignoreSubmodules")?.trim();
1333
+ const flags = submoduleIgnoreFlags(isSubmoduleIgnoreMode(configured) ? configured : "none");
1334
+ if (this.resolvedUntracked === "no") flags.untracked = true;
1335
+ return flags;
1336
+ }
1337
+
1338
+ /**
1339
+ * Whether the index side hides submodules: only `--ignore-submodules=all` does (git
1340
+ * compares HEAD and index with `dirty` otherwise, whatever `diff.ignoreSubmodules` or
1341
+ * `submodule.<name>.ignore` say, so a staged submodule is always shown).
1342
+ */
1343
+ private async indexIgnoresAll(_path: string): Promise<boolean> {
1344
+ return this.ignoreSubmodules === "all";
1345
+ }
1346
+
1347
+ /**
1348
+ * Whether the tracked path (an index or HEAD entry of `mode`) matches the path filters,
1349
+ * as git's `ce_path_match` / `tree_entry_interesting` match a literal pathspec: the path
1350
+ * itself or a directory above it. An element ending in `/` names a directory only, so
1351
+ * `f.txt/` does not match the file `f.txt` (a gitlink counts as a directory), and an
1352
+ * element below a file (`a/b`) does not match the file `a`.
1353
+ */
1354
+ private matchesTracked(path: string, mode: number): boolean {
1355
+ if (this.pathspec.length === 0) return true;
1356
+ // ce_path_match: a gitlink matches as a directory (`sub/` names it)
1357
+ return matchPathspec(this.pathspec, path, isGitlink(mode) ? DO_MATCH_DIRECTORY : 0) > 0;
260
1358
  }
261
1359
 
262
1360
  /**
263
1361
  * Collect all blob entries from a tree recursively.
264
1362
  */
1363
+ /**
1364
+ * HEAD's blobs below `prefix`. A directory whose cache-tree node is valid and names the
1365
+ * same tree holds exactly the index's entries: it is not read, only noted in `same` (git's
1366
+ * unpack-trees skips such a directory too, `cache_tree_matches_traversal`).
1367
+ */
265
1368
  private async collectTreeEntries(
266
1369
  treeId: ObjectId,
267
1370
  prefix: string,
268
1371
  entries: Map<string, StatusSide>,
1372
+ node?: CacheTree,
1373
+ same?: Set<string>,
269
1374
  ): Promise<void> {
1375
+ if (node && same && node.entryCount >= 0 && node.id === treeId) {
1376
+ same.add(prefix);
1377
+ return;
1378
+ }
1379
+ const subtrees =
1380
+ node && node.subtrees.length > 0
1381
+ ? new Map(node.subtrees.map((s) => [s.name, s.tree] as const))
1382
+ : undefined;
270
1383
  for await (const entry of this.trees.loadTree(treeId)) {
271
1384
  const path = prefix ? `${prefix}/${entry.name}` : entry.name;
272
1385
  if (entry.mode === FileMode.TREE) {
273
- await this.collectTreeEntries(entry.id, path, entries);
1386
+ await this.collectTreeEntries(entry.id, path, entries, subtrees?.get(entry.name), same);
274
1387
  } else {
275
1388
  entries.set(path, { mode: entry.mode, id: entry.id });
276
1389
  }
277
1390
  }
278
1391
  }
279
1392
  }
1393
+
1394
+ /** A side's mode and id, as a rename candidate takes them. */
1395
+ function side(s: StatusSide): { mode: number; id: ObjectId } {
1396
+ return { mode: s.mode, id: s.id };
1397
+ }
1398
+
1399
+ /** The index entries of a staging without `entryList`, in order. */
1400
+ async function collectEntries(entries: AsyncIterable<StagingEntry>): Promise<StagingEntry[]> {
1401
+ const out: StagingEntry[] = [];
1402
+ for await (const entry of entries) out.push(entry);
1403
+ return out;
1404
+ }
1405
+
1406
+ /** The options of `StatusCommand.callText`. */
1407
+ export interface StatusCallTextOptions {
1408
+ /** `--long`, `--short`, `--porcelain[=v1]`, `--porcelain=v2`; unset: `status.short`, else long */
1409
+ format?: "long" | "short" | "porcelain" | "porcelain-v2";
1410
+ /** `-b` / `--branch` (unset: `status.branch` for the human formats) */
1411
+ branch?: boolean;
1412
+ /** `-z` (porcelain unless another format is given; `--long` refuses it) */
1413
+ z?: boolean;
1414
+ /** `--show-stash` (unset: `status.showStash`) */
1415
+ showStash?: boolean;
1416
+ /** `--[no-]ahead-behind` (unset: `status.aheadBehind` for the human formats, else full) */
1417
+ aheadBehind?: boolean;
1418
+ /** `-v` (1) / `-vv` (2): the staged (and unstaged) changes as a patch, long format only */
1419
+ verbose?: number;
1420
+ /** `advice.statusHints` override (the commit template has none) */
1421
+ hints?: boolean;
1422
+ /** Comment every line with this string (the commit template); unset: `status.displayCommentPrefix` */
1423
+ commentPrefix?: string;
1424
+ /** The commit template: "Initial commit", no divergence advice */
1425
+ commitTemplate?: boolean;
1426
+ /** `git commit --amend` */
1427
+ amend?: boolean;
1428
+ /** `s->nowarn`: no closing line when nothing is committable (the commit template) */
1429
+ nowarn?: boolean;
1430
+ /** Where the commit comes from (the "to unstage" hints only show for a plain commit) */
1431
+ whence?: CommitWhence;
1432
+ /** The text goes to a file (the commit template): `-v` puts the cut line before its patch */
1433
+ toFile?: boolean;
1434
+ /** The cut line was written already (`s->added_cut_line`) */
1435
+ cutLineAdded?: boolean;
1436
+ }
1437
+
1438
+ /** What `StatusCommand.callText` gives: the text, the status, and git's warnings. */
1439
+ export interface StatusTextResult extends StatusText {
1440
+ status: Status;
1441
+ warnings: string[];
1442
+ }
1443
+
1444
+ /** A git boolean of the configuration, `fallback` when unset or not a boolean. */
1445
+ /** git_parse_int: a decimal integer with an optional k, m or g unit; undefined otherwise. */
1446
+ function parseConfigInt(value: string): number | undefined {
1447
+ const m = /^\s*([-+]?\d+)([kmg]?)\s*$/i.exec(value);
1448
+ if (!m) return undefined;
1449
+ const scale = { "": 1, k: 1024, m: 1024 ** 2, g: 1024 ** 3 }[m[2].toLowerCase()] ?? 1;
1450
+ return Number.parseInt(m[1], 10) * scale;
1451
+ }
1452
+
1453
+ function cfgBool(config: RemoteConfigStore, key: string, fallback: boolean): boolean {
1454
+ const value = config.value(key);
1455
+ return value === undefined ? fallback : (parseGitBool(value) ?? fallback);
1456
+ }
1457
+
1458
+ /** The comment-line string of status's commented lines. */
1459
+ function commentLineString(workingCopy: WorkingCopy): string {
1460
+ return commentPrefixOf(workingCopy);
1461
+ }
1462
+
1463
+ /**
1464
+ * wt_status_append_cut_line: the scissors line and its explanation, commented.
1465
+ *
1466
+ * @example
1467
+ * ```typescript
1468
+ * cutLine("#"); // "# ------------------------ >8 ------------------------\n# Do not modify ..."
1469
+ * ```
1470
+ */
1471
+ export function cutLine(comment: string): string {
1472
+ return (
1473
+ `${comment} ------------------------ >8 ------------------------\n` +
1474
+ `${comment} Do not modify or remove the line above.\n` +
1475
+ `${comment} Everything below it will be ignored.\n`
1476
+ );
1477
+ }
1478
+
1479
+ /**
1480
+ * `rev-list --left-right --count ours...theirs` (git's `stat_branch_pair`): the commits only
1481
+ * each side reaches, walked no further than the merge bases (the store's commit-graph
1482
+ * ordering the walk where it has one).
1483
+ */
1484
+ async function aheadBehind(
1485
+ commits: Pick<Commits, "load" | "countAheadBehind">,
1486
+ ours: ObjectId,
1487
+ theirs: ObjectId,
1488
+ ): Promise<{ ahead: number; behind: number }> {
1489
+ if (commits.countAheadBehind) return commits.countAheadBehind(ours, theirs);
1490
+ return countAheadBehind(
1491
+ async (id) => {
1492
+ const c = await commits.load(id).catch(() => undefined);
1493
+ return c
1494
+ ? { parents: c.parents, date: c.committer.timestamp, generation: Number.POSITIVE_INFINITY }
1495
+ : undefined;
1496
+ },
1497
+ ours,
1498
+ theirs,
1499
+ );
1500
+ }