@statewalker/vcs-commands 0.4.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (561) hide show
  1. package/README.md +123 -8
  2. package/dist/commands/add-command.d.ts +265 -34
  3. package/dist/commands/add-command.d.ts.map +1 -1
  4. package/dist/commands/add-patch/add-interactive.d.ts +46 -0
  5. package/dist/commands/add-patch/add-interactive.d.ts.map +1 -0
  6. package/dist/commands/add-patch/add-patch.d.ts +139 -0
  7. package/dist/commands/add-patch/add-patch.d.ts.map +1 -0
  8. package/dist/commands/add-patch/index.d.ts +6 -0
  9. package/dist/commands/add-patch/index.d.ts.map +1 -0
  10. package/dist/commands/add-patch/patch-backend.d.ts +80 -0
  11. package/dist/commands/add-patch/patch-backend.d.ts.map +1 -0
  12. package/dist/commands/add-patch/patch-modes.d.ts +71 -0
  13. package/dist/commands/add-patch/patch-modes.d.ts.map +1 -0
  14. package/dist/commands/add-patch/patch-session.d.ts +49 -0
  15. package/dist/commands/add-patch/patch-session.d.ts.map +1 -0
  16. package/dist/commands/am/am-command.d.ts +175 -0
  17. package/dist/commands/am/am-command.d.ts.map +1 -0
  18. package/dist/commands/am/index.d.ts +3 -0
  19. package/dist/commands/am/index.d.ts.map +1 -0
  20. package/dist/commands/am/mailinfo.d.ts +58 -0
  21. package/dist/commands/am/mailinfo.d.ts.map +1 -0
  22. package/dist/commands/am/patch-format.d.ts +24 -0
  23. package/dist/commands/am/patch-format.d.ts.map +1 -0
  24. package/dist/commands/apply/apply-command.d.ts +153 -0
  25. package/dist/commands/apply/apply-command.d.ts.map +1 -0
  26. package/dist/commands/apply/apply-engine.d.ts +195 -0
  27. package/dist/commands/apply/apply-engine.d.ts.map +1 -0
  28. package/dist/commands/apply/apply-parse.d.ts +86 -0
  29. package/dist/commands/apply/apply-parse.d.ts.map +1 -0
  30. package/dist/commands/apply/apply-types.d.ts +70 -0
  31. package/dist/commands/apply/apply-types.d.ts.map +1 -0
  32. package/dist/commands/apply/index.d.ts +6 -0
  33. package/dist/commands/apply/index.d.ts.map +1 -0
  34. package/dist/commands/apply/latin1.d.ts +32 -0
  35. package/dist/commands/apply/latin1.d.ts.map +1 -0
  36. package/dist/commands/apply/whitespace.d.ts +58 -0
  37. package/dist/commands/apply/whitespace.d.ts.map +1 -0
  38. package/dist/commands/attributes-source.d.ts +26 -0
  39. package/dist/commands/attributes-source.d.ts.map +1 -0
  40. package/dist/commands/backfill-command.d.ts +110 -0
  41. package/dist/commands/backfill-command.d.ts.map +1 -0
  42. package/dist/commands/bisect/bisect-checkout.d.ts +64 -0
  43. package/dist/commands/bisect/bisect-checkout.d.ts.map +1 -0
  44. package/dist/commands/bisect/bisect-command.d.ts +201 -0
  45. package/dist/commands/bisect/bisect-command.d.ts.map +1 -0
  46. package/dist/commands/bisect/bisect-engine.d.ts +219 -0
  47. package/dist/commands/bisect/bisect-engine.d.ts.map +1 -0
  48. package/dist/commands/bisect/bisect-graph.d.ts +127 -0
  49. package/dist/commands/bisect/bisect-graph.d.ts.map +1 -0
  50. package/dist/commands/bisect/bisect-quote.d.ts +27 -0
  51. package/dist/commands/bisect/bisect-quote.d.ts.map +1 -0
  52. package/dist/commands/bisect/index.d.ts +5 -0
  53. package/dist/commands/bisect/index.d.ts.map +1 -0
  54. package/dist/commands/blame-command.d.ts +122 -131
  55. package/dist/commands/blame-command.d.ts.map +1 -1
  56. package/dist/commands/branch-command.d.ts +52 -2
  57. package/dist/commands/branch-command.d.ts.map +1 -1
  58. package/dist/commands/branch-tracking.d.ts +98 -0
  59. package/dist/commands/branch-tracking.d.ts.map +1 -0
  60. package/dist/commands/checkout-command.d.ts +299 -34
  61. package/dist/commands/checkout-command.d.ts.map +1 -1
  62. package/dist/commands/checkout-paths.d.ts +124 -0
  63. package/dist/commands/checkout-paths.d.ts.map +1 -0
  64. package/dist/commands/cherry-pick-command.d.ts +50 -42
  65. package/dist/commands/cherry-pick-command.d.ts.map +1 -1
  66. package/dist/commands/clean-command.d.ts +67 -4
  67. package/dist/commands/clean-command.d.ts.map +1 -1
  68. package/dist/commands/clone-command.d.ts +179 -7
  69. package/dist/commands/clone-command.d.ts.map +1 -1
  70. package/dist/commands/commit-command.d.ts +311 -17
  71. package/dist/commands/commit-command.d.ts.map +1 -1
  72. package/dist/commands/core-config.d.ts +93 -0
  73. package/dist/commands/core-config.d.ts.map +1 -0
  74. package/dist/commands/date-format.d.ts +58 -0
  75. package/dist/commands/date-format.d.ts.map +1 -0
  76. package/dist/commands/describe-command.d.ts.map +1 -1
  77. package/dist/commands/diff-command.d.ts +377 -30
  78. package/dist/commands/diff-command.d.ts.map +1 -1
  79. package/dist/commands/diff-textconv.d.ts +40 -0
  80. package/dist/commands/diff-textconv.d.ts.map +1 -0
  81. package/dist/commands/fetch-command.d.ts +244 -23
  82. package/dist/commands/fetch-command.d.ts.map +1 -1
  83. package/dist/commands/format-patch-command.d.ts +164 -0
  84. package/dist/commands/format-patch-command.d.ts.map +1 -0
  85. package/dist/commands/fsck/fetch-fsck.d.ts +60 -0
  86. package/dist/commands/fsck/fetch-fsck.d.ts.map +1 -0
  87. package/dist/commands/fsck/fsck-command.d.ts +225 -0
  88. package/dist/commands/fsck/fsck-command.d.ts.map +1 -0
  89. package/dist/commands/fsck/fsck-loose.d.ts +68 -0
  90. package/dist/commands/fsck/fsck-loose.d.ts.map +1 -0
  91. package/dist/commands/fsck/fsck-msg-ids.d.ts +122 -0
  92. package/dist/commands/fsck/fsck-msg-ids.d.ts.map +1 -0
  93. package/dist/commands/fsck/fsck-object-checks.d.ts +148 -0
  94. package/dist/commands/fsck/fsck-object-checks.d.ts.map +1 -0
  95. package/dist/commands/fsck/fsck-object-table.d.ts +132 -0
  96. package/dist/commands/fsck/fsck-object-table.d.ts.map +1 -0
  97. package/dist/commands/fsck/fsck-pack.d.ts +115 -0
  98. package/dist/commands/fsck/fsck-pack.d.ts.map +1 -0
  99. package/dist/commands/fsck/index.d.ts +6 -0
  100. package/dist/commands/fsck/index.d.ts.map +1 -0
  101. package/dist/commands/fsck/verify-pack-command.d.ts +81 -0
  102. package/dist/commands/fsck/verify-pack-command.d.ts.map +1 -0
  103. package/dist/commands/gc-command.d.ts +43 -0
  104. package/dist/commands/gc-command.d.ts.map +1 -1
  105. package/dist/commands/git-date.d.ts +66 -0
  106. package/dist/commands/git-date.d.ts.map +1 -0
  107. package/dist/commands/git-describe.d.ts +67 -0
  108. package/dist/commands/git-describe.d.ts.map +1 -0
  109. package/dist/commands/git-hooks.d.ts +416 -0
  110. package/dist/commands/git-hooks.d.ts.map +1 -0
  111. package/dist/commands/git-ident.d.ts +128 -0
  112. package/dist/commands/git-ident.d.ts.map +1 -0
  113. package/dist/commands/hook-command.d.ts +96 -0
  114. package/dist/commands/hook-command.d.ts.map +1 -0
  115. package/dist/commands/index-adder.d.ts +231 -0
  116. package/dist/commands/index-adder.d.ts.map +1 -0
  117. package/dist/commands/index-host.d.ts +86 -0
  118. package/dist/commands/index-host.d.ts.map +1 -0
  119. package/dist/commands/index.d.ts +55 -0
  120. package/dist/commands/index.d.ts.map +1 -1
  121. package/dist/commands/index.js +3 -2
  122. package/dist/commands/init-command.d.ts +12 -1
  123. package/dist/commands/init-command.d.ts.map +1 -1
  124. package/dist/commands/local-clone.d.ts +60 -0
  125. package/dist/commands/local-clone.d.ts.map +1 -0
  126. package/dist/commands/local-transport.d.ts +117 -0
  127. package/dist/commands/local-transport.d.ts.map +1 -0
  128. package/dist/commands/log-command.d.ts +216 -24
  129. package/dist/commands/log-command.d.ts.map +1 -1
  130. package/dist/commands/log-graph.d.ts +120 -0
  131. package/dist/commands/log-graph.d.ts.map +1 -0
  132. package/dist/commands/log-output.d.ts +323 -0
  133. package/dist/commands/log-output.d.ts.map +1 -0
  134. package/dist/commands/ls-remote-command.d.ts +23 -7
  135. package/dist/commands/ls-remote-command.d.ts.map +1 -1
  136. package/dist/commands/mailmap.d.ts +31 -0
  137. package/dist/commands/mailmap.d.ts.map +1 -0
  138. package/dist/commands/merge-bases.d.ts +85 -0
  139. package/dist/commands/merge-bases.d.ts.map +1 -0
  140. package/dist/commands/merge-command.d.ts +209 -74
  141. package/dist/commands/merge-command.d.ts.map +1 -1
  142. package/dist/commands/merge-config.d.ts +13 -0
  143. package/dist/commands/merge-config.d.ts.map +1 -0
  144. package/dist/commands/merge-drivers.d.ts +130 -0
  145. package/dist/commands/merge-drivers.d.ts.map +1 -0
  146. package/dist/commands/merge-support.d.ts +252 -0
  147. package/dist/commands/merge-support.d.ts.map +1 -0
  148. package/dist/commands/message-cleanup.d.ts +86 -0
  149. package/dist/commands/message-cleanup.d.ts.map +1 -0
  150. package/dist/commands/mv-command.d.ts +94 -0
  151. package/dist/commands/mv-command.d.ts.map +1 -0
  152. package/dist/commands/notes-command.d.ts +256 -0
  153. package/dist/commands/notes-command.d.ts.map +1 -0
  154. package/dist/commands/notes-commands.d.ts +41 -0
  155. package/dist/commands/notes-commands.d.ts.map +1 -0
  156. package/dist/commands/notes-merge-command.d.ts +105 -0
  157. package/dist/commands/notes-merge-command.d.ts.map +1 -0
  158. package/dist/commands/notes-support.d.ts +125 -0
  159. package/dist/commands/notes-support.d.ts.map +1 -0
  160. package/dist/commands/notes-tree.d.ts +106 -0
  161. package/dist/commands/notes-tree.d.ts.map +1 -0
  162. package/dist/commands/object-id-input.d.ts +20 -0
  163. package/dist/commands/object-id-input.d.ts.map +1 -0
  164. package/dist/commands/octopus-merge.d.ts +59 -0
  165. package/dist/commands/octopus-merge.d.ts.map +1 -0
  166. package/dist/commands/ort-merge.d.ts +126 -0
  167. package/dist/commands/ort-merge.d.ts.map +1 -0
  168. package/dist/commands/ort-recursive.d.ts +53 -0
  169. package/dist/commands/ort-recursive.d.ts.map +1 -0
  170. package/dist/commands/pack-refs-command.d.ts +20 -0
  171. package/dist/commands/pack-refs-command.d.ts.map +1 -1
  172. package/dist/commands/patch-id.d.ts +41 -0
  173. package/dist/commands/patch-id.d.ts.map +1 -0
  174. package/dist/commands/pathspec-attributes.d.ts +64 -0
  175. package/dist/commands/pathspec-attributes.d.ts.map +1 -0
  176. package/dist/commands/pathspec.d.ts +324 -0
  177. package/dist/commands/pathspec.d.ts.map +1 -0
  178. package/dist/commands/post-index-change.d.ts +33 -0
  179. package/dist/commands/post-index-change.d.ts.map +1 -0
  180. package/dist/commands/pretty-format.d.ts +222 -0
  181. package/dist/commands/pretty-format.d.ts.map +1 -0
  182. package/dist/commands/promisor-remote.d.ts +80 -0
  183. package/dist/commands/promisor-remote.d.ts.map +1 -0
  184. package/dist/commands/pull-command.d.ts +41 -8
  185. package/dist/commands/pull-command.d.ts.map +1 -1
  186. package/dist/commands/push-command.d.ts +24 -8
  187. package/dist/commands/push-command.d.ts.map +1 -1
  188. package/dist/commands/read-tree-command.d.ts +112 -0
  189. package/dist/commands/read-tree-command.d.ts.map +1 -0
  190. package/dist/commands/rebase-command.d.ts +507 -75
  191. package/dist/commands/rebase-command.d.ts.map +1 -1
  192. package/dist/commands/rebase-todo.d.ts +130 -0
  193. package/dist/commands/rebase-todo.d.ts.map +1 -0
  194. package/dist/commands/ref-decoration-filter.d.ts +53 -0
  195. package/dist/commands/ref-decoration-filter.d.ts.map +1 -0
  196. package/dist/commands/reflog-messages.d.ts +98 -0
  197. package/dist/commands/reflog-messages.d.ts.map +1 -0
  198. package/dist/commands/remote-command.d.ts +146 -6
  199. package/dist/commands/remote-command.d.ts.map +1 -1
  200. package/dist/commands/remote-transport.d.ts +120 -0
  201. package/dist/commands/remote-transport.d.ts.map +1 -0
  202. package/dist/commands/reset-command.d.ts +161 -7
  203. package/dist/commands/reset-command.d.ts.map +1 -1
  204. package/dist/commands/restore-command.d.ts +103 -0
  205. package/dist/commands/restore-command.d.ts.map +1 -0
  206. package/dist/commands/rev-list-command.d.ts +78 -0
  207. package/dist/commands/rev-list-command.d.ts.map +1 -0
  208. package/dist/commands/rev-parse-command.d.ts +80 -0
  209. package/dist/commands/rev-parse-command.d.ts.map +1 -0
  210. package/dist/commands/revert-command.d.ts +46 -38
  211. package/dist/commands/revert-command.d.ts.map +1 -1
  212. package/dist/commands/revision-filenames.d.ts +95 -0
  213. package/dist/commands/revision-filenames.d.ts.map +1 -0
  214. package/dist/commands/revision-range.d.ts +67 -0
  215. package/dist/commands/revision-range.d.ts.map +1 -0
  216. package/dist/commands/revision-resolver.d.ts +321 -0
  217. package/dist/commands/revision-resolver.d.ts.map +1 -0
  218. package/dist/commands/rm-command.d.ts +69 -7
  219. package/dist/commands/rm-command.d.ts.map +1 -1
  220. package/dist/commands/sequencer-pick.d.ts +191 -0
  221. package/dist/commands/sequencer-pick.d.ts.map +1 -0
  222. package/dist/commands/sequencer-support.d.ts +125 -0
  223. package/dist/commands/sequencer-support.d.ts.map +1 -0
  224. package/dist/commands/serve-repository.d.ts +52 -0
  225. package/dist/commands/serve-repository.d.ts.map +1 -0
  226. package/dist/commands/sparse-checkout-command.d.ts +190 -0
  227. package/dist/commands/sparse-checkout-command.d.ts.map +1 -0
  228. package/dist/commands/sparse-checkout-support.d.ts +268 -0
  229. package/dist/commands/sparse-checkout-support.d.ts.map +1 -0
  230. package/dist/commands/stash-apply-command.d.ts +69 -13
  231. package/dist/commands/stash-apply-command.d.ts.map +1 -1
  232. package/dist/commands/stash-create-command.d.ts +214 -26
  233. package/dist/commands/stash-create-command.d.ts.map +1 -1
  234. package/dist/commands/stash-drop-command.d.ts +10 -2
  235. package/dist/commands/stash-drop-command.d.ts.map +1 -1
  236. package/dist/commands/stash-list-command.d.ts +2 -4
  237. package/dist/commands/stash-list-command.d.ts.map +1 -1
  238. package/dist/commands/stash-working-tree.d.ts +95 -0
  239. package/dist/commands/stash-working-tree.d.ts.map +1 -0
  240. package/dist/commands/status-command.d.ts +320 -28
  241. package/dist/commands/status-command.d.ts.map +1 -1
  242. package/dist/commands/status-format.d.ts +155 -0
  243. package/dist/commands/status-format.d.ts.map +1 -0
  244. package/dist/commands/status-header.d.ts +64 -0
  245. package/dist/commands/status-header.d.ts.map +1 -0
  246. package/dist/commands/strerror.d.ts +7 -0
  247. package/dist/commands/strerror.d.ts.map +1 -0
  248. package/dist/commands/submodule-config.d.ts +38 -0
  249. package/dist/commands/submodule-config.d.ts.map +1 -0
  250. package/dist/commands/submodule-summary-command.d.ts +80 -0
  251. package/dist/commands/submodule-summary-command.d.ts.map +1 -0
  252. package/dist/commands/submodule-summary.d.ts +150 -0
  253. package/dist/commands/submodule-summary.d.ts.map +1 -0
  254. package/dist/commands/switch-command.d.ts +132 -0
  255. package/dist/commands/switch-command.d.ts.map +1 -0
  256. package/dist/commands/tag-command.d.ts +23 -2
  257. package/dist/commands/tag-command.d.ts.map +1 -1
  258. package/dist/commands/tracking-info.d.ts +64 -0
  259. package/dist/commands/tracking-info.d.ts.map +1 -0
  260. package/dist/commands/trailers.d.ts +73 -0
  261. package/dist/commands/trailers.d.ts.map +1 -0
  262. package/dist/commands/tree-restore.d.ts +137 -6
  263. package/dist/commands/tree-restore.d.ts.map +1 -1
  264. package/dist/commands/untracked-cache-support.d.ts +53 -0
  265. package/dist/commands/untracked-cache-support.d.ts.map +1 -0
  266. package/dist/commands/worktree-add-command.d.ts +108 -0
  267. package/dist/commands/worktree-add-command.d.ts.map +1 -0
  268. package/dist/commands/worktree-list-command.d.ts +69 -0
  269. package/dist/commands/worktree-list-command.d.ts.map +1 -0
  270. package/dist/commands/worktree-lock-command.d.ts +44 -0
  271. package/dist/commands/worktree-lock-command.d.ts.map +1 -0
  272. package/dist/commands/worktree-overwrite-checks.d.ts +204 -0
  273. package/dist/commands/worktree-overwrite-checks.d.ts.map +1 -0
  274. package/dist/commands/worktree-prune-command.d.ts +48 -0
  275. package/dist/commands/worktree-prune-command.d.ts.map +1 -0
  276. package/dist/commands/worktree-remove-command.d.ts +59 -0
  277. package/dist/commands/worktree-remove-command.d.ts.map +1 -0
  278. package/dist/commands/worktree-repair-command.d.ts +35 -0
  279. package/dist/commands/worktree-repair-command.d.ts.map +1 -0
  280. package/dist/commands/worktree-support.d.ts +64 -0
  281. package/dist/commands/worktree-support.d.ts.map +1 -0
  282. package/dist/commands-DnmlfwGV.js +61620 -0
  283. package/dist/core-commands/add.command.impl.d.ts.map +1 -1
  284. package/dist/core-commands/index.d.ts +0 -3
  285. package/dist/core-commands/index.d.ts.map +1 -1
  286. package/dist/errors/add-errors.d.ts +55 -0
  287. package/dist/errors/add-errors.d.ts.map +1 -1
  288. package/dist/errors/checkout-errors.d.ts +29 -0
  289. package/dist/errors/checkout-errors.d.ts.map +1 -1
  290. package/dist/errors/command-errors.d.ts +77 -0
  291. package/dist/errors/command-errors.d.ts.map +1 -1
  292. package/dist/errors/commit-errors.d.ts +9 -0
  293. package/dist/errors/commit-errors.d.ts.map +1 -1
  294. package/dist/errors/git-api-error.d.ts +59 -2
  295. package/dist/errors/git-api-error.d.ts.map +1 -1
  296. package/dist/errors/index.d.ts +1 -0
  297. package/dist/errors/index.d.ts.map +1 -1
  298. package/dist/errors/index.js +371 -19
  299. package/dist/errors/rebase-errors.d.ts +9 -0
  300. package/dist/errors/rebase-errors.d.ts.map +1 -1
  301. package/dist/errors/ref-errors.d.ts +32 -0
  302. package/dist/errors/ref-errors.d.ts.map +1 -1
  303. package/dist/errors/transport-errors.d.ts +12 -2
  304. package/dist/errors/transport-errors.d.ts.map +1 -1
  305. package/dist/errors/worktree-errors.d.ts +35 -0
  306. package/dist/errors/worktree-errors.d.ts.map +1 -0
  307. package/dist/git-command-DxvwPrPB.js +7612 -0
  308. package/dist/git-command.d.ts +422 -32
  309. package/dist/git-command.d.ts.map +1 -1
  310. package/dist/git.d.ts +326 -5
  311. package/dist/git.d.ts.map +1 -1
  312. package/dist/index.d.ts +1 -1
  313. package/dist/index.d.ts.map +1 -1
  314. package/dist/index.js +5 -5
  315. package/dist/remote-config/index.d.ts +1 -0
  316. package/dist/remote-config/index.d.ts.map +1 -1
  317. package/dist/remote-config/remote-config-store.d.ts +123 -3
  318. package/dist/remote-config/remote-config-store.d.ts.map +1 -1
  319. package/dist/remote-config/remote-refs.d.ts +41 -0
  320. package/dist/remote-config/remote-refs.d.ts.map +1 -0
  321. package/dist/rename/detect-renames.d.ts +148 -0
  322. package/dist/rename/detect-renames.d.ts.map +1 -0
  323. package/dist/rename/git-similarity.d.ts +44 -0
  324. package/dist/rename/git-similarity.d.ts.map +1 -0
  325. package/dist/rename/index.d.ts +2 -0
  326. package/dist/rename/index.d.ts.map +1 -1
  327. package/dist/results/binary-patch.d.ts +11 -0
  328. package/dist/results/binary-patch.d.ts.map +1 -0
  329. package/dist/results/blame-format.d.ts +55 -0
  330. package/dist/results/blame-format.d.ts.map +1 -0
  331. package/dist/results/cherry-pick-result.d.ts +10 -0
  332. package/dist/results/cherry-pick-result.d.ts.map +1 -1
  333. package/dist/results/clone-result.d.ts +16 -0
  334. package/dist/results/clone-result.d.ts.map +1 -1
  335. package/dist/results/combined-diff.d.ts +77 -0
  336. package/dist/results/combined-diff.d.ts.map +1 -0
  337. package/dist/results/diff-entry.d.ts +32 -0
  338. package/dist/results/diff-entry.d.ts.map +1 -1
  339. package/dist/results/diff-formatter.d.ts +34 -60
  340. package/dist/results/diff-formatter.d.ts.map +1 -1
  341. package/dist/results/diff-order.d.ts +25 -0
  342. package/dist/results/diff-order.d.ts.map +1 -0
  343. package/dist/results/diff-output.d.ts +249 -0
  344. package/dist/results/diff-output.d.ts.map +1 -0
  345. package/dist/results/fetch-result.d.ts +24 -1
  346. package/dist/results/fetch-result.d.ts.map +1 -1
  347. package/dist/results/index.d.ts +5 -0
  348. package/dist/results/index.d.ts.map +1 -1
  349. package/dist/results/index.js +2 -252
  350. package/dist/results/merge-result.d.ts +15 -1
  351. package/dist/results/merge-result.d.ts.map +1 -1
  352. package/dist/results/pull-result.d.ts +12 -3
  353. package/dist/results/pull-result.d.ts.map +1 -1
  354. package/dist/results/push-result.d.ts +42 -0
  355. package/dist/results/push-result.d.ts.map +1 -1
  356. package/dist/results/quote-path.d.ts +27 -0
  357. package/dist/results/quote-path.d.ts.map +1 -0
  358. package/dist/results/rebase-result.d.ts +28 -1
  359. package/dist/results/rebase-result.d.ts.map +1 -1
  360. package/dist/results/revert-result.d.ts +10 -0
  361. package/dist/results/revert-result.d.ts.map +1 -1
  362. package/dist/results/stash-result.d.ts +5 -0
  363. package/dist/results/stash-result.d.ts.map +1 -1
  364. package/dist/results/status-result.d.ts +143 -18
  365. package/dist/results/status-result.d.ts.map +1 -1
  366. package/dist/results-BZGa2Z3I.js +2934 -0
  367. package/dist/transport-command.d.ts +56 -1
  368. package/dist/transport-command.d.ts.map +1 -1
  369. package/package.json +15 -10
  370. package/src/commands/add-command.ts +1291 -224
  371. package/src/commands/add-patch/add-interactive.ts +941 -0
  372. package/src/commands/add-patch/add-patch.ts +1169 -0
  373. package/src/commands/add-patch/index.ts +5 -0
  374. package/src/commands/add-patch/patch-backend.ts +239 -0
  375. package/src/commands/add-patch/patch-modes.ts +249 -0
  376. package/src/commands/add-patch/patch-session.ts +159 -0
  377. package/src/commands/am/am-command.ts +1111 -0
  378. package/src/commands/am/index.ts +2 -0
  379. package/src/commands/am/mailinfo.ts +1015 -0
  380. package/src/commands/am/patch-format.ts +121 -0
  381. package/src/commands/apply/apply-command.ts +832 -0
  382. package/src/commands/apply/apply-engine.ts +1603 -0
  383. package/src/commands/apply/apply-parse.ts +1209 -0
  384. package/src/commands/apply/apply-types.ts +112 -0
  385. package/src/commands/apply/index.ts +5 -0
  386. package/src/commands/apply/latin1.ts +171 -0
  387. package/src/commands/apply/whitespace.ts +260 -0
  388. package/src/commands/attributes-source.ts +96 -0
  389. package/src/commands/backfill-command.ts +694 -0
  390. package/src/commands/bisect/bisect-checkout.ts +217 -0
  391. package/src/commands/bisect/bisect-command.ts +788 -0
  392. package/src/commands/bisect/bisect-engine.ts +1079 -0
  393. package/src/commands/bisect/bisect-graph.ts +595 -0
  394. package/src/commands/bisect/bisect-quote.ts +92 -0
  395. package/src/commands/bisect/index.ts +4 -0
  396. package/src/commands/blame-command.ts +711 -986
  397. package/src/commands/branch-command.ts +354 -32
  398. package/src/commands/branch-tracking.ts +331 -0
  399. package/src/commands/checkout-command.ts +1426 -297
  400. package/src/commands/checkout-paths.ts +784 -0
  401. package/src/commands/cherry-pick-command.ts +156 -396
  402. package/src/commands/clean-command.ts +532 -85
  403. package/src/commands/clone-command.ts +826 -55
  404. package/src/commands/commit-command.ts +1781 -166
  405. package/src/commands/core-config.ts +196 -0
  406. package/src/commands/date-format.ts +668 -0
  407. package/src/commands/describe-command.ts +2 -0
  408. package/src/commands/diff-command.ts +1898 -110
  409. package/src/commands/diff-textconv.ts +50 -0
  410. package/src/commands/fetch-command.ts +1038 -79
  411. package/src/commands/format-patch-command.ts +969 -0
  412. package/src/commands/fsck/fetch-fsck.ts +229 -0
  413. package/src/commands/fsck/fsck-command.ts +3347 -0
  414. package/src/commands/fsck/fsck-loose.ts +287 -0
  415. package/src/commands/fsck/fsck-msg-ids.ts +176 -0
  416. package/src/commands/fsck/fsck-object-checks.ts +1044 -0
  417. package/src/commands/fsck/fsck-object-table.ts +363 -0
  418. package/src/commands/fsck/fsck-pack.ts +604 -0
  419. package/src/commands/fsck/index.ts +5 -0
  420. package/src/commands/fsck/verify-pack-command.ts +249 -0
  421. package/src/commands/gc-command.ts +147 -1
  422. package/src/commands/git-date.ts +895 -0
  423. package/src/commands/git-describe.ts +316 -0
  424. package/src/commands/git-hooks.ts +1472 -0
  425. package/src/commands/git-ident.ts +344 -0
  426. package/src/commands/hook-command.ts +247 -0
  427. package/src/commands/index-adder.ts +706 -0
  428. package/src/commands/index-host.ts +291 -0
  429. package/src/commands/index.ts +83 -0
  430. package/src/commands/init-command.ts +60 -11
  431. package/src/commands/local-clone.ts +183 -0
  432. package/src/commands/local-transport.ts +762 -0
  433. package/src/commands/log-command.ts +1915 -170
  434. package/src/commands/log-graph.ts +671 -0
  435. package/src/commands/log-output.ts +1359 -0
  436. package/src/commands/ls-remote-command.ts +101 -58
  437. package/src/commands/mailmap.ts +129 -0
  438. package/src/commands/merge-bases.ts +296 -0
  439. package/src/commands/merge-command.ts +1386 -491
  440. package/src/commands/merge-config.ts +25 -0
  441. package/src/commands/merge-drivers.ts +306 -0
  442. package/src/commands/merge-support.ts +1198 -0
  443. package/src/commands/message-cleanup.ts +275 -0
  444. package/src/commands/mv-command.ts +976 -0
  445. package/src/commands/notes-command.ts +890 -0
  446. package/src/commands/notes-commands.ts +87 -0
  447. package/src/commands/notes-merge-command.ts +768 -0
  448. package/src/commands/notes-support.ts +402 -0
  449. package/src/commands/notes-tree.ts +602 -0
  450. package/src/commands/object-id-input.ts +27 -0
  451. package/src/commands/octopus-merge.ts +377 -0
  452. package/src/commands/ort-merge.ts +1660 -0
  453. package/src/commands/ort-recursive.ts +160 -0
  454. package/src/commands/pack-refs-command.ts +39 -22
  455. package/src/commands/patch-id.ts +196 -0
  456. package/src/commands/pathspec-attributes.ts +162 -0
  457. package/src/commands/pathspec.ts +1199 -0
  458. package/src/commands/post-index-change.ts +62 -0
  459. package/src/commands/pretty-format.ts +1431 -0
  460. package/src/commands/promisor-remote.ts +298 -0
  461. package/src/commands/pull-command.ts +207 -22
  462. package/src/commands/push-command.ts +236 -23
  463. package/src/commands/read-tree-command.ts +857 -0
  464. package/src/commands/rebase-command.ts +3808 -371
  465. package/src/commands/rebase-todo.ts +584 -0
  466. package/src/commands/ref-decoration-filter.ts +118 -0
  467. package/src/commands/reflog-messages.ts +177 -0
  468. package/src/commands/remote-command.ts +500 -19
  469. package/src/commands/remote-transport.ts +383 -0
  470. package/src/commands/reset-command.ts +828 -91
  471. package/src/commands/restore-command.ts +350 -0
  472. package/src/commands/rev-list-command.ts +167 -0
  473. package/src/commands/rev-parse-command.ts +277 -0
  474. package/src/commands/revert-command.ts +152 -399
  475. package/src/commands/revision-filenames.ts +254 -0
  476. package/src/commands/revision-range.ts +222 -0
  477. package/src/commands/revision-resolver.ts +1379 -0
  478. package/src/commands/rm-command.ts +613 -67
  479. package/src/commands/sequencer-pick.ts +869 -0
  480. package/src/commands/sequencer-support.ts +869 -0
  481. package/src/commands/serve-repository.ts +125 -0
  482. package/src/commands/sparse-checkout-command.ts +1389 -0
  483. package/src/commands/sparse-checkout-support.ts +793 -0
  484. package/src/commands/stash-apply-command.ts +692 -124
  485. package/src/commands/stash-create-command.ts +752 -89
  486. package/src/commands/stash-drop-command.ts +67 -6
  487. package/src/commands/stash-list-command.ts +10 -4
  488. package/src/commands/stash-working-tree.ts +387 -0
  489. package/src/commands/status-command.ts +1426 -97
  490. package/src/commands/status-format.ts +775 -0
  491. package/src/commands/status-header.ts +330 -0
  492. package/src/commands/strerror.ts +29 -0
  493. package/src/commands/submodule-config.ts +94 -0
  494. package/src/commands/submodule-summary-command.ts +334 -0
  495. package/src/commands/submodule-summary.ts +446 -0
  496. package/src/commands/switch-command.ts +402 -0
  497. package/src/commands/tag-command.ts +129 -41
  498. package/src/commands/tracking-info.ts +201 -0
  499. package/src/commands/trailers.ts +417 -0
  500. package/src/commands/tree-restore.ts +344 -15
  501. package/src/commands/untracked-cache-support.ts +194 -0
  502. package/src/commands/worktree-add-command.ts +458 -0
  503. package/src/commands/worktree-list-command.ts +208 -0
  504. package/src/commands/worktree-lock-command.ts +96 -0
  505. package/src/commands/worktree-overwrite-checks.ts +641 -0
  506. package/src/commands/worktree-prune-command.ts +99 -0
  507. package/src/commands/worktree-remove-command.ts +186 -0
  508. package/src/commands/worktree-repair-command.ts +59 -0
  509. package/src/commands/worktree-support.ts +214 -0
  510. package/src/core-commands/add.command.impl.ts +9 -5
  511. package/src/core-commands/index.ts +0 -8
  512. package/src/errors/add-errors.ts +45 -0
  513. package/src/errors/checkout-errors.ts +46 -2
  514. package/src/errors/command-errors.ts +101 -1
  515. package/src/errors/commit-errors.ts +18 -2
  516. package/src/errors/git-api-error.ts +82 -2
  517. package/src/errors/index.ts +1 -0
  518. package/src/errors/merge-errors.ts +2 -2
  519. package/src/errors/rebase-errors.ts +12 -0
  520. package/src/errors/ref-errors.ts +56 -2
  521. package/src/errors/remote-errors.ts +2 -2
  522. package/src/errors/stash-errors.ts +1 -1
  523. package/src/errors/transport-errors.ts +20 -4
  524. package/src/errors/worktree-errors.ts +49 -0
  525. package/src/git-command.ts +1218 -118
  526. package/src/git.ts +552 -11
  527. package/src/index.ts +1 -1
  528. package/src/remote-config/index.ts +1 -0
  529. package/src/remote-config/remote-config-store.ts +326 -16
  530. package/src/remote-config/remote-refs.ts +119 -0
  531. package/src/rename/detect-renames.ts +711 -0
  532. package/src/rename/git-similarity.ts +116 -0
  533. package/src/rename/index.ts +2 -0
  534. package/src/results/binary-patch.ts +401 -0
  535. package/src/results/blame-format.ts +239 -0
  536. package/src/results/cherry-pick-result.ts +10 -0
  537. package/src/results/clone-result.ts +18 -0
  538. package/src/results/combined-diff.ts +585 -0
  539. package/src/results/diff-entry.ts +35 -0
  540. package/src/results/diff-formatter.ts +152 -288
  541. package/src/results/diff-order.ts +64 -0
  542. package/src/results/diff-output.ts +1051 -0
  543. package/src/results/fetch-result.ts +24 -1
  544. package/src/results/index.ts +5 -0
  545. package/src/results/merge-result.ts +15 -1
  546. package/src/results/pull-result.ts +12 -3
  547. package/src/results/push-result.ts +43 -0
  548. package/src/results/quote-path.ts +103 -0
  549. package/src/results/rebase-result.ts +37 -0
  550. package/src/results/revert-result.ts +10 -0
  551. package/src/results/stash-result.ts +6 -0
  552. package/src/results/status-result.ts +288 -27
  553. package/src/transport-command.ts +139 -2
  554. package/dist/commands-BpeXZTC3.js +0 -10278
  555. package/dist/core-commands/checkout.command.d.ts +0 -103
  556. package/dist/core-commands/checkout.command.d.ts.map +0 -1
  557. package/dist/core-commands/checkout.command.impl.d.ts +0 -110
  558. package/dist/core-commands/checkout.command.impl.d.ts.map +0 -1
  559. package/dist/status-result-BapZoQaR.js +0 -411
  560. package/src/core-commands/checkout.command.impl.ts +0 -564
  561. package/src/core-commands/checkout.command.ts +0 -125
@@ -1,60 +1,348 @@
1
- import type { ObjectId } from "@statewalker/vcs-core";
2
- import { FileMode } from "@statewalker/vcs-core";
3
- import { MergeStage } from "@statewalker/vcs-working-tree";
1
+ import { type Commits, countAheadBehind, FileMode, type ObjectId } from "@statewalker/vcs-core";
2
+ import { parseGitBool } from "@statewalker/vcs-utils";
3
+ import {
4
+ type CacheTree,
5
+ compareWithWorktree,
6
+ compareWithWorktreeStat,
7
+ DIR_HIDE_EMPTY_DIRECTORIES,
8
+ DIR_SHOW_IGNORED_TOO,
9
+ DIR_SHOW_IGNORED_TOO_MODE_MATCHING,
10
+ DIR_SHOW_OTHER_DIRECTORIES,
11
+ getStageState,
12
+ getWorktreeEntries,
13
+ IndexPathLookup,
14
+ type IndexStatUpdate,
15
+ isCleanByStat,
16
+ modeFromWorktree,
17
+ readConvertedContent,
18
+ refreshIndexStats,
19
+ type StageStateValue,
20
+ type StagingEntry,
21
+ scanUntracked,
22
+ statUpdateOf,
23
+ unreadableDirectoryWarning,
24
+ type WorkingCopy,
25
+ type Worktree,
26
+ type WorktreeModeTrust,
27
+ walkUntrackedScanHost,
28
+ } from "@statewalker/vcs-working-tree";
4
29
 
30
+ import {
31
+ IncompatibleOptionsError,
32
+ InvalidArgumentError,
33
+ InvalidConfigError,
34
+ } from "../errors/index.js";
5
35
  import { GitCommand } from "../git-command.js";
6
- import { type Status, StatusImpl } from "../results/status-result.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";
43
+ import {
44
+ type Status,
45
+ type StatusCode,
46
+ type StatusFileEntry,
47
+ StatusImpl,
48
+ type StatusSide,
49
+ submoduleToken,
50
+ } from "../results/status-result.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";
88
+
89
+ /** The porcelain `XY` of an unmerged path, by which of stages 1-3 it has. */
90
+ const UNMERGED_CODES: Record<number, [StatusCode, StatusCode]> = {
91
+ 1: ["D", "D"],
92
+ 2: ["A", "U"],
93
+ 3: ["U", "D"],
94
+ 4: ["U", "A"],
95
+ 5: ["D", "U"],
96
+ 6: ["A", "A"],
97
+ 7: ["U", "U"],
98
+ };
99
+
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");
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
+ }
7
120
 
8
121
  /**
9
- * Entry with full path for internal use.
122
+ * Which untracked files status lists (`--untracked-files`, `status.showUntrackedFiles`):
123
+ * none, untracked directories as `dir/` (git's default), or every file.
10
124
  */
11
- interface PathEntry {
12
- path: string;
13
- mode: number;
14
- id: ObjectId;
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;
15
152
  }
16
153
 
17
154
  /**
18
- * Shows the staging area status compared to HEAD.
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).
19
159
  *
20
- * This is a simplified version for repositories without working trees,
21
- * focusing on staged changes and conflicts.
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
+ }
266
+
267
+ /**
268
+ * Shows the working tree status, as `git status`: the index against HEAD (staged changes),
269
+ * the worktree against the index (unstaged changes: modified, deleted, type changed),
270
+ * unmerged entries, untracked files and, on request, ignored ones.
22
271
  *
23
- * Equivalent to `git status` but only for staged changes.
272
+ * Worktree files are compared with the index through the stat it recorded: a file whose
273
+ * size and modification time still match is not read, unless its entry is racily clean
274
+ * (modified at or after the index was written), which is re-hashed as git does. Links are
275
+ * compared as links (mode 120000), the executable bit only where `core.filemode` trusts it,
276
+ * and the ignore rules are read afresh for each status.
24
277
  *
25
- * Based on JGit's StatusCommand (staged-only subset).
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.
26
287
  *
27
- * @example
28
- * ```typescript
29
- * // Get repository status
30
- * const status = await git.status().call();
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.
31
293
  *
32
- * // Check if clean
33
- * if (status.isClean()) {
34
- * console.log("Nothing to commit");
35
- * }
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.
36
298
  *
37
- * // Check for changes
38
- * console.log("Added:", status.added);
39
- * console.log("Changed:", status.changed);
40
- * console.log("Removed:", status.removed);
41
- * console.log("Conflicting:", status.conflicting);
299
+ * Without a worktree only the index is compared with HEAD.
42
300
  *
43
- * // Filter by path
44
- * const subStatus = await git.status()
45
- * .addPath("src/")
46
- * .call();
301
+ * Based on JGit's StatusCommand.
302
+ *
303
+ * @example
304
+ * ```typescript
305
+ * const status = await git.status().call();
306
+ * if (status.isClean()) console.log("nothing to commit, working tree clean");
307
+ * console.log("Staged:", status.added, status.changed, status.removed, status.renamed);
308
+ * console.log("Unstaged:", status.modified, status.missing);
309
+ * console.log("Untracked:", status.untracked);
310
+ * // the lines of `git status --porcelain`
311
+ * console.log(formatStatusPorcelain(status));
47
312
  * ```
48
313
  */
49
314
  export class StatusCommand extends GitCommand<Status> {
50
315
  private paths: string[] = [];
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;
51
332
 
52
333
  /**
53
- * 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.
54
344
  *
55
- * Only status for paths starting with this prefix will be returned.
56
- *
57
- * @param path Path prefix to filter by
345
+ * @param path A pathspec element
58
346
  */
59
347
  addPath(path: string): this {
60
348
  this.checkCallable();
@@ -62,112 +350,1153 @@ export class StatusCommand extends GitCommand<Status> {
62
350
  return this;
63
351
  }
64
352
 
65
- async call(): Promise<Status> {
353
+ /**
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 {
66
361
  this.checkCallable();
67
- this.setCallable(false);
362
+ this.ignoredMode = ignored === true ? "traditional" : ignored === false ? "no" : ignored;
363
+ return this;
364
+ }
68
365
 
69
- // Get conflicting paths first
70
- const conflicting = new Set<string>();
71
- for (const path of await this.staging.getConflictedPaths()) {
72
- if (this.matchesPath(path)) {
73
- conflicting.add(path);
74
- }
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).
371
+ */
372
+ setUntrackedFiles(mode: UntrackedFilesMode): this {
373
+ this.checkCallable();
374
+ this.untrackedMode = mode;
375
+ return this;
376
+ }
377
+
378
+ /**
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}.
383
+ */
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 {
452
+ this.checkCallable();
453
+ this.submoduleSummary = summary === true ? -1 : summary === false ? 0 : summary;
454
+ return this;
455
+ }
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
+ );
75
470
  }
471
+ return bool ? -1 : 0;
472
+ }
76
473
 
77
- // Get HEAD tree entries
78
- const headEntries = new Map<string, PathEntry>();
79
- const headRef = await this.refsStore.resolve("HEAD");
80
- if (headRef?.objectId) {
81
- try {
82
- const headCommit = await this.commits.load(headRef.objectId);
83
- if (headCommit) {
84
- await this.collectTreeEntries(headCommit.tree, "", headEntries);
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;
85
640
  }
86
- } catch {
87
- // No HEAD commit yet - headEntries stays empty
88
- }
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/" };
89
711
  }
712
+ const cached = new DiffCommand(this.workingCopy)
713
+ .setCached(true)
714
+ .setOldTree(o.referenceId ?? EMPTY_TREE)
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
+ }
90
732
 
91
- // Get staging entries (only stage 0 = merged)
92
- const stagingEntries = new Map<string, PathEntry>();
93
- for await (const entry of this.staging.entries()) {
94
- if (entry.stage === MergeStage.MERGED) {
95
- stagingEntries.set(entry.path, {
96
- path: entry.path,
97
- mode: entry.mode,
98
- id: entry.objectId,
99
- });
733
+ async call(): Promise<Status> {
734
+ this.checkCallable();
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
+ }
747
+ const worktree = this.worktreeAccess;
748
+ // one operation: fresh ignore rules and one lstat cache for the whole status
749
+ return worktree?.batch ? worktree.batch(() => this.compute(worktree)) : this.compute(worktree);
750
+ }
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
+
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();
780
+ const head = new Map<string, StatusSide>();
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);
100
789
  }
101
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
+ };
102
810
 
103
- // Compare HEAD vs staging
104
811
  const added = new Set<string>();
105
812
  const changed = new Set<string>();
106
813
  const removed = new Set<string>();
814
+ const conflicting = new Set<string>();
815
+ const conflictingStageState = new Map<string, StageStateValue>();
816
+ const modified = new Set<string>();
817
+ const missing = new Set<string>();
818
+ const untracked = new Set<string>();
819
+ const ignored = new Set<string>();
820
+ const files: StatusFileEntry[] = [];
107
821
 
108
- // Files in staging but not in HEAD = added
109
- // Files in staging and HEAD with different IDs = changed
110
- for (const [path, stagingEntry] of stagingEntries) {
111
- if (!this.matchesPath(path)) continue;
822
+ const trust = worktree ? worktreeModeTrust(this.workingCopy, worktree) : undefined;
823
+ const indexTime = this.staging.getUpdateTime();
824
+ const gitlinks = new Set<string>();
825
+ const refresh: IndexStatUpdate[] = [];
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>();
112
830
 
113
- const headEntry = headEntries.get(path);
114
- if (!headEntry) {
115
- added.add(path);
116
- } else if (headEntry.id !== stagingEntry.id || headEntry.mode !== stagingEntry.mode) {
117
- changed.add(path);
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++;
118
859
  }
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;
872
+ }
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
+ });
964
+ }
965
+ }
966
+ start = end;
119
967
  }
120
968
 
121
- // Files in HEAD but not in staging = removed
122
- for (const [path] of headEntries) {
123
- if (!this.matchesPath(path)) continue;
969
+ for (const [path, stages] of unmerged) {
970
+ conflicting.add(path);
971
+ const [base, ours, theirs] = stages;
972
+ conflictingStageState.set(path, getStageState(!!base, !!ours, !!theirs));
973
+ const mask = (base ? 1 : 0) | (ours ? 2 : 0) | (theirs ? 4 : 0);
974
+ const [x, y] = UNMERGED_CODES[mask];
975
+ let worktreeMode: number | undefined;
976
+ const current = worktree ? await worktree.getEntry(path) : undefined;
977
+ if (current && !current.isDirectory && trust) {
978
+ worktreeMode = modeFromWorktree(current.mode, (ours ?? theirs ?? base)?.mode, trust);
979
+ }
980
+ files.push({ path, index: x, worktree: y, worktreeMode, stages: [base, ours, theirs] });
981
+ }
982
+
983
+ for (const [path, h] of head) {
984
+ if (tracked.has(path) || !this.matchesTracked(path, h.mode)) continue;
985
+ if (isGitlink(h.mode) && (await this.indexIgnoresAll(path))) continue;
986
+ removed.add(path);
987
+ files.push({ path, index: "D", worktree: " ", head: h });
988
+ }
124
989
 
125
- if (!stagingEntries.has(path)) {
126
- removed.add(path);
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
+ );
1002
+ if (worktree && this.resolvedUntracked !== "no") {
1003
+ // git's wt_status_collect_untracked: the dir flags of the modes
1004
+ let flags =
1005
+ this.resolvedUntracked === "all"
1006
+ ? 0
1007
+ : DIR_SHOW_OTHER_DIRECTORIES | DIR_HIDE_EMPTY_DIRECTORIES;
1008
+ if (this.ignoredMode !== "no") {
1009
+ flags |= DIR_SHOW_IGNORED_TOO;
1010
+ if (this.ignoredMode === "matching") flags |= DIR_SHOW_IGNORED_TOO_MODE_MATCHING;
1011
+ }
1012
+ // read_directory, through the untracked cache for a whole-tree scan without ignored
1013
+ // files (validate_untracked_cache)
1014
+ const cache =
1015
+ host && matchAll && this.ignoredMode === "no"
1016
+ ? await untrackedCache.forScan(flags)
1017
+ : undefined;
1018
+ const ignoreFiles = this.indexIgnoreOids(all, upToDate);
1019
+ // dir.c asks the index through its name hashes, which fold case under core.ignorecase
1020
+ // (index_file_exists, directory_exists_in_index_icase): a file or directory differing
1021
+ // from an index path only by case is tracked, never untracked
1022
+ const ignoreCase = coreBool(this.workingCopy, "ignorecase", false);
1023
+ const scanIndex = new IndexPathLookup(index.all, { ignoreCase, gitlinks, sorted: true });
1024
+ const result = await scanUntracked(host ?? (await walkUntrackedScanHost(worktree)), {
1025
+ isTracked: (p) => scanIndex.has(p),
1026
+ isTrackedExactly: (p) => index.hasExactly(p),
1027
+ trackedIn: (dir) => scanIndex.trackedIn(dir),
1028
+ indexDirectory: (dir) => scanIndex.indexDirectory(dir),
1029
+ indexIgnoreOid: (p) => ignoreFiles.upToDate.get(p),
1030
+ skipWorktreeIgnoreOid: (p) => ignoreFiles.skipWorktree.get(p),
1031
+ flags,
1032
+ ...(matchAll ? {} : { matcher: untrackedScanPathspec(this.pathspec, attributes) }),
1033
+ ...(cache ? { cache } : {}),
1034
+ indexSeconds: Math.floor(indexTime / 1000),
1035
+ ...(trust ? { stat: { ctime: trust.ctime, fullStat: trust.fullStat } } : {}),
1036
+ // git's "could not open directory" for each directory its scan cannot list
1037
+ onUnreadable: (path, error) => warnings.push(unreadableDirectoryWarning(path, error)),
1038
+ });
1039
+ for (const path of result.paths) {
1040
+ untracked.add(path);
1041
+ files.push({ path, index: "?", worktree: "?" });
127
1042
  }
1043
+ for (const path of result.ignored) {
1044
+ ignored.add(path);
1045
+ files.push({ path, index: "!", worktree: "!" });
1046
+ }
1047
+ }
1048
+
1049
+ // as git status: the refreshed stats written back when the index is free and unchanged,
1050
+ // with the untracked cache when it changed
1051
+ if (this.writeIndex) {
1052
+ await refreshIndexStats(
1053
+ this.staging,
1054
+ refresh,
1055
+ untrackedCache.changed() ? { untrackedCache: untrackedCache.cache ?? null } : undefined,
1056
+ );
1057
+ }
1058
+
1059
+ return new StatusImpl(added, changed, removed, conflicting, {
1060
+ modified,
1061
+ missing,
1062
+ untracked,
1063
+ ignored,
1064
+ conflictingStageState,
1065
+ files,
1066
+ renamed,
1067
+ warnings,
1068
+ });
1069
+ }
1070
+
1071
+ /**
1072
+ * The ids the untracked cache takes from the index for `.gitignore` files (git's
1073
+ * `add_patterns`): `upToDate`, the stage-0 entry's where the file is up to date with it
1074
+ * (assume-unchanged and skip-worktree count as up to date); `skipWorktree`, the stage-0
1075
+ * entry's where it is skip-worktree, for a file missing from the worktree (read from the
1076
+ * index then; an assume-unchanged one missing records the null id).
1077
+ */
1078
+ private indexIgnoreOids(
1079
+ entries: readonly StagingEntry[],
1080
+ upToDate: ReadonlySet<string>,
1081
+ ): { upToDate: Map<string, string>; skipWorktree: Map<string, string> } {
1082
+ const out = { upToDate: new Map<string, string>(), skipWorktree: new Map<string, string>() };
1083
+ if (upToDate.size === 0) return out;
1084
+ for (const entry of entries) {
1085
+ if (entry.stage !== 0 || !upToDate.has(entry.path)) continue;
1086
+ out.upToDate.set(entry.path, entry.objectId);
1087
+ if (entry.skipWorktree) out.skipWorktree.set(entry.path, entry.objectId);
128
1088
  }
1089
+ return out;
1090
+ }
129
1091
 
130
- return new StatusImpl(added, changed, removed, conflicting);
1092
+ /** Whether renames are detected: the setter, else `status.renames`, else `diff.renames`. */
1093
+ private detectsRenames(): boolean {
1094
+ if (this.renames !== undefined) return this.renames;
1095
+ return (
1096
+ renamesValue(this.config.value("status.renames")) ??
1097
+ renamesValue(this.config.value("diff.renames")) ??
1098
+ true
1099
+ );
131
1100
  }
132
1101
 
133
1102
  /**
134
- * Check if a path matches the configured path filters.
1103
+ * Pairs renames as git status does: on the index side (`diff-index --cached`) a path
1104
+ * removed from the index with one added to it; on the worktree side (`diff-files`) a
1105
+ * path deleted from the worktree with an intent-to-add file. The source's line goes (or
1106
+ * keeps only its other side); the destination's line becomes the rename. Unmerged paths
1107
+ * take part on the worktree side only, as diff-files queues them: a file there is a
1108
+ * destination, stage #2 of one gone a source; their own lines stay as they are.
135
1109
  */
136
- private matchesPath(path: string): boolean {
137
- if (this.paths.length === 0) {
138
- return true;
1110
+ private async pairRenames(
1111
+ files: StatusFileEntry[],
1112
+ renamed: Map<string, string>,
1113
+ worktree: Worktree | undefined,
1114
+ warnings: string[],
1115
+ ): Promise<void> {
1116
+ const limit =
1117
+ this.renameLimit ??
1118
+ intValue(this.config.value("status.renameLimit")) ??
1119
+ intValue(this.config.value("diff.renameLimit")) ??
1120
+ DEFAULT_RENAME_LIMIT;
1121
+ const byPath = new Map(files.map((f) => [f.path, f]));
1122
+ const blob = async (id: ObjectId) => concat((await this.blobs.load(id)) ?? []);
1123
+ const blobSize = async (id: ObjectId) => {
1124
+ try {
1125
+ return await this.blobs.size(id);
1126
+ } catch {
1127
+ return undefined;
1128
+ }
1129
+ };
1130
+ // diffcore-rename's prefetches: a partial clone's absent blobs in one batch (the
1131
+ // worktree side's files are no blobs)
1132
+ const prefetch = async (
1133
+ wanted: Array<{ candidate: RenameCandidate; side: "source" | "destination" }>,
1134
+ sourcesOnly = false,
1135
+ ) => {
1136
+ const ids = wanted
1137
+ .filter((w) => !sourcesOnly || w.side === "source")
1138
+ .filter((w) => w.candidate.mode !== 0o160000)
1139
+ .map((w) => w.candidate.id);
1140
+ await this.blobs.prefetch?.(ids);
1141
+ };
1142
+ // git's diff warning when inexact renames were skipped (git status itself prints none)
1143
+ let needed = 0;
1144
+ const onRenameLimit = (n: number) => {
1145
+ needed = Math.max(needed, n);
1146
+ };
1147
+ const drop = new Set<StatusFileEntry>();
1148
+
1149
+ // index side: HEAD's deletions against the index's additions
1150
+ const indexSources: RenameCandidate[] = [];
1151
+ const indexDestinations: RenameCandidate[] = [];
1152
+ for (const f of files) {
1153
+ if (f.stages) continue;
1154
+ if (f.index === "D" && f.head) indexSources.push({ path: f.path, ...side(f.head) });
1155
+ else if (f.index === "A" && f.staged) {
1156
+ indexDestinations.push({ path: f.path, ...side(f.staged) });
1157
+ }
1158
+ }
1159
+ if (indexSources.length > 0 && indexDestinations.length > 0) {
1160
+ const pairs = await detectRenames(indexSources, indexDestinations, {
1161
+ renameLimit: limit,
1162
+ onRenameLimit,
1163
+ prefetch: (wanted) => prefetch(wanted),
1164
+ size: (c) => blobSize(c.id),
1165
+ load: (c) => blob(c.id),
1166
+ });
1167
+ for (const pair of pairs) {
1168
+ const from = byPath.get(pair.from);
1169
+ const to = byPath.get(pair.to);
1170
+ if (!from || !to) continue;
1171
+ to.index = "R";
1172
+ to.head = from.head;
1173
+ // an intent-to-add source keeps its worktree side, without a HEAD side ("DA" to " A")
1174
+ if (from.intentToAdd && from.worktree !== " ") {
1175
+ from.index = " ";
1176
+ from.head = from.worktree === "D" ? from.staged : undefined;
1177
+ } else drop.add(from);
1178
+ to.renamedFrom = pair.from;
1179
+ to.renameScore = scorePercent(pair.score);
1180
+ renamed.set(pair.to, pair.from);
1181
+ }
139
1182
  }
140
1183
 
141
- for (const filterPath of this.paths) {
142
- if (
143
- path === filterPath ||
144
- path.startsWith(`${filterPath}/`) ||
145
- filterPath.startsWith(`${path}/`)
146
- ) {
147
- return true;
1184
+ // worktree side: deletions from the worktree against intent-to-add files; an unmerged
1185
+ // path takes part as git's diff-files queues it: its file, when there, is a destination
1186
+ // (diff_unmerge with the worktree mode), and its stage #2 a deletion (a source) when the
1187
+ // file is gone
1188
+ if (worktree) {
1189
+ const sources: RenameCandidate[] = [];
1190
+ const sourceSides = new Map<string, { mode: number; id: ObjectId }>();
1191
+ const destinations: Array<[RenameCandidate, StatusFileEntry]> = [];
1192
+ for (const f of files) {
1193
+ if (drop.has(f)) continue;
1194
+ if (f.stages) {
1195
+ const ours = f.stages[1];
1196
+ if (f.worktreeMode !== undefined) {
1197
+ destinations.push([{ path: f.path, mode: f.worktreeMode, id: "" }, f]);
1198
+ } else if (ours && !isGitlink(ours.mode)) {
1199
+ // no file (or a directory, which git's check_removed takes as gone)
1200
+ sources.push({ path: f.path, ...side(ours) });
1201
+ sourceSides.set(f.path, side(ours));
1202
+ }
1203
+ continue;
1204
+ }
1205
+ if (f.worktree === "D" && f.staged) {
1206
+ sources.push({ path: f.path, ...side(f.staged) });
1207
+ sourceSides.set(f.path, side(f.staged));
1208
+ } else if (f.worktree === "A" && f.worktreeMode !== undefined) {
1209
+ destinations.push([{ path: f.path, mode: f.worktreeMode, id: "" }, f]);
1210
+ }
148
1211
  }
1212
+ if (sources.length > 0 && destinations.length > 0) {
1213
+ for (const [candidate] of destinations) {
1214
+ candidate.id = await worktree.computeHash(candidate.path);
1215
+ }
1216
+ // the worktree side as git's diff reads it: cleaned (convert_to_git) where a
1217
+ // conversion applies, read once for both its size and its content
1218
+ const cleaned = new Map<string, Promise<Uint8Array | undefined>>();
1219
+ const cleanedOf = (c: RenameCandidate) => {
1220
+ if (c.mode === 0o120000) return Promise.resolve(undefined);
1221
+ let found = cleaned.get(c.path);
1222
+ if (!found) {
1223
+ found = readConvertedContent(worktree, c.path);
1224
+ cleaned.set(c.path, found);
1225
+ }
1226
+ return found;
1227
+ };
1228
+ const pairs = await detectRenames(
1229
+ sources,
1230
+ destinations.map(([c]) => c),
1231
+ {
1232
+ renameLimit: limit,
1233
+ onRenameLimit,
1234
+ prefetch: (wanted) => prefetch(wanted, true),
1235
+ size: async (c, role) =>
1236
+ role === "source"
1237
+ ? blobSize(c.id)
1238
+ : ((await cleanedOf(c))?.length ?? (await worktree.getEntry(c.path))?.size),
1239
+ load: async (c, role) => {
1240
+ if (role === "source") return blob(c.id);
1241
+ const converted = await cleanedOf(c);
1242
+ cleaned.delete(c.path);
1243
+ return converted ?? concat(worktree.readContent(c.path));
1244
+ },
1245
+ },
1246
+ );
1247
+ for (const pair of pairs) {
1248
+ const from = byPath.get(pair.from);
1249
+ const to = byPath.get(pair.to);
1250
+ const source = sourceSides.get(pair.from);
1251
+ if (!from || !source || !to) continue;
1252
+ // the source keeps only its index side, if it has one; an unmerged source keeps
1253
+ // its line (its stage #2 deletion goes)
1254
+ if (from.stages) {
1255
+ // nothing shown changes
1256
+ } else if (from.index === " ") drop.add(from);
1257
+ else {
1258
+ from.worktree = " ";
1259
+ from.worktreeMode = source.mode;
1260
+ }
1261
+ // an unmerged destination stays as it is (wt_status shows its stages, no rename)
1262
+ if (to.stages) continue;
1263
+ to.worktree = "R";
1264
+ to.head = source;
1265
+ to.staged = source;
1266
+ to.renamedFrom = pair.from;
1267
+ to.renameScore = scorePercent(pair.score);
1268
+ renamed.set(pair.to, pair.from);
1269
+ }
1270
+ }
1271
+ }
1272
+
1273
+ if (drop.size > 0) {
1274
+ const kept = files.filter((f) => !drop.has(f));
1275
+ files.splice(0, files.length, ...kept);
1276
+ }
1277
+ if (needed > 0) {
1278
+ warnings.push(
1279
+ "warning: exhaustive rename detection was skipped due to too many files.",
1280
+ `warning: you may want to set your status.renameLimit variable to at least ${needed} and retry the command.`,
1281
+ );
149
1282
  }
150
- return false;
1283
+ }
1284
+
1285
+ /** The submodules `.gitmodules` names: the worktree's file, else the index's. */
1286
+ private submodules(): Promise<GitmodulesEntry[]> {
1287
+ this.gitmodules ??= (async () => {
1288
+ const worktree = this.worktreeAccess;
1289
+ let bytes: Uint8Array | undefined;
1290
+ try {
1291
+ const entry = worktree ? await worktree.getEntry(".gitmodules") : undefined;
1292
+ if (worktree && entry && !entry.isDirectory && entry.mode !== FileMode.SYMLINK) {
1293
+ bytes = await concat(worktree.readContent(".gitmodules"));
1294
+ }
1295
+ } catch {
1296
+ bytes = undefined;
1297
+ }
1298
+ if (!bytes) {
1299
+ const staged = await this.staging.getEntry(".gitmodules");
1300
+ if (staged && staged.mode !== FileMode.SYMLINK) {
1301
+ bytes = await concat((await this.blobs.load(staged.objectId)) ?? []);
1302
+ }
1303
+ }
1304
+ return bytes ? parseGitmodules(new TextDecoder().decode(bytes)) : [];
1305
+ })();
1306
+ return this.gitmodules;
1307
+ }
1308
+
1309
+ /**
1310
+ * `submodule.<name>.ignore` for the submodule at `path`: the repository's config, else
1311
+ * `.gitmodules`; undefined when neither names a valid value (or no submodule is there).
1312
+ */
1313
+ private async submoduleIgnore(path: string): Promise<SubmoduleIgnoreMode | undefined> {
1314
+ const submodule = (await this.submodules()).find((s) => s.path === path);
1315
+ if (!submodule) return undefined;
1316
+ const configured = this.config.value(`submodule.${submodule.name}.ignore`)?.trim();
1317
+ if (configured !== undefined) return isSubmoduleIgnoreMode(configured) ? configured : undefined;
1318
+ const declared = submodule.ignore?.trim();
1319
+ return isSubmoduleIgnoreMode(declared) ? declared : undefined;
1320
+ }
1321
+
1322
+ /**
1323
+ * What the worktree side ignores of the submodule at `path`, as git's status sets its
1324
+ * diff flags: `--ignore-submodules` overrides everything; else `submodule.<name>.ignore`
1325
+ * replaces `diff.ignoreSubmodules` (and `--untracked-files=no`) when set.
1326
+ */
1327
+ private async worktreeFlags(path: string): Promise<SubmoduleIgnoreFlags> {
1328
+ if (this.ignoreSubmodules) return submoduleIgnoreFlags(this.ignoreSubmodules);
1329
+ const own = await this.submoduleIgnore(path);
1330
+ if (own) return submoduleIgnoreFlags(own);
1331
+ const configured = this.config.value("diff.ignoreSubmodules")?.trim();
1332
+ const flags = submoduleIgnoreFlags(isSubmoduleIgnoreMode(configured) ? configured : "none");
1333
+ if (this.resolvedUntracked === "no") flags.untracked = true;
1334
+ return flags;
1335
+ }
1336
+
1337
+ /**
1338
+ * Whether the index side hides submodules: only `--ignore-submodules=all` does (git
1339
+ * compares HEAD and index with `dirty` otherwise, whatever `diff.ignoreSubmodules` or
1340
+ * `submodule.<name>.ignore` say, so a staged submodule is always shown).
1341
+ */
1342
+ private async indexIgnoresAll(_path: string): Promise<boolean> {
1343
+ return this.ignoreSubmodules === "all";
1344
+ }
1345
+
1346
+ /**
1347
+ * Whether the tracked path (an index or HEAD entry of `mode`) matches the path filters,
1348
+ * as git's `ce_path_match` / `tree_entry_interesting` match a literal pathspec: the path
1349
+ * itself or a directory above it. An element ending in `/` names a directory only, so
1350
+ * `f.txt/` does not match the file `f.txt` (a gitlink counts as a directory), and an
1351
+ * element below a file (`a/b`) does not match the file `a`.
1352
+ */
1353
+ private matchesTracked(path: string, mode: number): boolean {
1354
+ if (this.pathspec.length === 0) return true;
1355
+ // ce_path_match: a gitlink matches as a directory (`sub/` names it)
1356
+ return matchPathspec(this.pathspec, path, isGitlink(mode) ? DO_MATCH_DIRECTORY : 0) > 0;
151
1357
  }
152
1358
 
153
1359
  /**
154
1360
  * Collect all blob entries from a tree recursively.
155
1361
  */
1362
+ /**
1363
+ * HEAD's blobs below `prefix`. A directory whose cache-tree node is valid and names the
1364
+ * same tree holds exactly the index's entries: it is not read, only noted in `same` (git's
1365
+ * unpack-trees skips such a directory too, `cache_tree_matches_traversal`).
1366
+ */
156
1367
  private async collectTreeEntries(
157
1368
  treeId: ObjectId,
158
1369
  prefix: string,
159
- entries: Map<string, PathEntry>,
1370
+ entries: Map<string, StatusSide>,
1371
+ node?: CacheTree,
1372
+ same?: Set<string>,
160
1373
  ): Promise<void> {
1374
+ if (node && same && node.entryCount >= 0 && node.id === treeId) {
1375
+ same.add(prefix);
1376
+ return;
1377
+ }
1378
+ const subtrees =
1379
+ node && node.subtrees.length > 0
1380
+ ? new Map(node.subtrees.map((s) => [s.name, s.tree] as const))
1381
+ : undefined;
161
1382
  for await (const entry of this.trees.loadTree(treeId)) {
162
1383
  const path = prefix ? `${prefix}/${entry.name}` : entry.name;
163
-
164
1384
  if (entry.mode === FileMode.TREE) {
165
- // Recurse into subtree
166
- await this.collectTreeEntries(entry.id, path, entries);
1385
+ await this.collectTreeEntries(entry.id, path, entries, subtrees?.get(entry.name), same);
167
1386
  } else {
168
- // Blob entry
169
- entries.set(path, { path, mode: entry.mode, id: entry.id });
1387
+ entries.set(path, { mode: entry.mode, id: entry.id });
170
1388
  }
171
1389
  }
172
1390
  }
173
1391
  }
1392
+
1393
+ /** A side's mode and id, as a rename candidate takes them. */
1394
+ function side(s: StatusSide): { mode: number; id: ObjectId } {
1395
+ return { mode: s.mode, id: s.id };
1396
+ }
1397
+
1398
+ /** The index entries of a staging without `entryList`, in order. */
1399
+ async function collectEntries(entries: AsyncIterable<StagingEntry>): Promise<StagingEntry[]> {
1400
+ const out: StagingEntry[] = [];
1401
+ for await (const entry of entries) out.push(entry);
1402
+ return out;
1403
+ }
1404
+
1405
+ /** The options of `StatusCommand.callText`. */
1406
+ export interface StatusCallTextOptions {
1407
+ /** `--long`, `--short`, `--porcelain[=v1]`, `--porcelain=v2`; unset: `status.short`, else long */
1408
+ format?: "long" | "short" | "porcelain" | "porcelain-v2";
1409
+ /** `-b` / `--branch` (unset: `status.branch` for the human formats) */
1410
+ branch?: boolean;
1411
+ /** `-z` (porcelain unless another format is given; `--long` refuses it) */
1412
+ z?: boolean;
1413
+ /** `--show-stash` (unset: `status.showStash`) */
1414
+ showStash?: boolean;
1415
+ /** `--[no-]ahead-behind` (unset: `status.aheadBehind` for the human formats, else full) */
1416
+ aheadBehind?: boolean;
1417
+ /** `-v` (1) / `-vv` (2): the staged (and unstaged) changes as a patch, long format only */
1418
+ verbose?: number;
1419
+ /** `advice.statusHints` override (the commit template has none) */
1420
+ hints?: boolean;
1421
+ /** Comment every line with this string (the commit template); unset: `status.displayCommentPrefix` */
1422
+ commentPrefix?: string;
1423
+ /** The commit template: "Initial commit", no divergence advice */
1424
+ commitTemplate?: boolean;
1425
+ /** `git commit --amend` */
1426
+ amend?: boolean;
1427
+ /** `s->nowarn`: no closing line when nothing is committable (the commit template) */
1428
+ nowarn?: boolean;
1429
+ /** Where the commit comes from (the "to unstage" hints only show for a plain commit) */
1430
+ whence?: CommitWhence;
1431
+ /** The text goes to a file (the commit template): `-v` puts the cut line before its patch */
1432
+ toFile?: boolean;
1433
+ /** The cut line was written already (`s->added_cut_line`) */
1434
+ cutLineAdded?: boolean;
1435
+ }
1436
+
1437
+ /** What `StatusCommand.callText` gives: the text, the status, and git's warnings. */
1438
+ export interface StatusTextResult extends StatusText {
1439
+ status: Status;
1440
+ warnings: string[];
1441
+ }
1442
+
1443
+ /** A git boolean of the configuration, `fallback` when unset or not a boolean. */
1444
+ /** git_parse_int: a decimal integer with an optional k, m or g unit; undefined otherwise. */
1445
+ function parseConfigInt(value: string): number | undefined {
1446
+ const m = /^\s*([-+]?\d+)([kmg]?)\s*$/i.exec(value);
1447
+ if (!m) return undefined;
1448
+ const scale = { "": 1, k: 1024, m: 1024 ** 2, g: 1024 ** 3 }[m[2].toLowerCase()] ?? 1;
1449
+ return Number.parseInt(m[1], 10) * scale;
1450
+ }
1451
+
1452
+ function cfgBool(config: RemoteConfigStore, key: string, fallback: boolean): boolean {
1453
+ const value = config.value(key);
1454
+ return value === undefined ? fallback : (parseGitBool(value) ?? fallback);
1455
+ }
1456
+
1457
+ /** git's empty tree, the side compared with before the first commit. */
1458
+ const EMPTY_TREE = "4b825dc642cb6eb9a060e54bf8d69288fbee4904";
1459
+
1460
+ /** The comment-line string of status's commented lines. */
1461
+ function commentLineString(workingCopy: WorkingCopy): string {
1462
+ return commentPrefixOf(workingCopy);
1463
+ }
1464
+
1465
+ /**
1466
+ * wt_status_append_cut_line: the scissors line and its explanation, commented.
1467
+ *
1468
+ * @example
1469
+ * ```typescript
1470
+ * cutLine("#"); // "# ------------------------ >8 ------------------------\n# Do not modify ..."
1471
+ * ```
1472
+ */
1473
+ export function cutLine(comment: string): string {
1474
+ return (
1475
+ `${comment} ------------------------ >8 ------------------------\n` +
1476
+ `${comment} Do not modify or remove the line above.\n` +
1477
+ `${comment} Everything below it will be ignored.\n`
1478
+ );
1479
+ }
1480
+
1481
+ /**
1482
+ * `rev-list --left-right --count ours...theirs` (git's `stat_branch_pair`): the commits only
1483
+ * each side reaches, walked no further than the merge bases (the store's commit-graph
1484
+ * ordering the walk where it has one).
1485
+ */
1486
+ async function aheadBehind(
1487
+ commits: Pick<Commits, "load" | "countAheadBehind">,
1488
+ ours: ObjectId,
1489
+ theirs: ObjectId,
1490
+ ): Promise<{ ahead: number; behind: number }> {
1491
+ if (commits.countAheadBehind) return commits.countAheadBehind(ours, theirs);
1492
+ return countAheadBehind(
1493
+ async (id) => {
1494
+ const c = await commits.load(id).catch(() => undefined);
1495
+ return c
1496
+ ? { parents: c.parents, date: c.committer.timestamp, generation: Number.POSITIVE_INFINITY }
1497
+ : undefined;
1498
+ },
1499
+ ours,
1500
+ theirs,
1501
+ );
1502
+ }