@statewalker/vcs-commands 0.7.0 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (568) hide show
  1. package/dist/commands/add-command.d.ts +70 -0
  2. package/dist/commands/add-command.d.ts.map +1 -1
  3. package/dist/commands/add-patch/add-patch.d.ts +7 -0
  4. package/dist/commands/add-patch/add-patch.d.ts.map +1 -1
  5. package/dist/commands/add-patch/patch-backend.d.ts.map +1 -1
  6. package/dist/commands/am/am-command.d.ts +102 -1
  7. package/dist/commands/am/am-command.d.ts.map +1 -1
  8. package/dist/commands/am/index.d.ts +1 -0
  9. package/dist/commands/am/index.d.ts.map +1 -1
  10. package/dist/commands/am/mailsplit.d.ts +88 -0
  11. package/dist/commands/am/mailsplit.d.ts.map +1 -0
  12. package/dist/commands/apply/apply-command.d.ts +2 -0
  13. package/dist/commands/apply/apply-command.d.ts.map +1 -1
  14. package/dist/commands/apply/apply-engine.d.ts.map +1 -1
  15. package/dist/commands/apply/apply-parse.d.ts +7 -0
  16. package/dist/commands/apply/apply-parse.d.ts.map +1 -1
  17. package/dist/commands/apply/index.d.ts +1 -1
  18. package/dist/commands/apply/index.d.ts.map +1 -1
  19. package/dist/commands/bisect/bisect-command.d.ts +2 -0
  20. package/dist/commands/bisect/bisect-command.d.ts.map +1 -1
  21. package/dist/commands/blame-command.d.ts +303 -8
  22. package/dist/commands/blame-command.d.ts.map +1 -1
  23. package/dist/commands/blame-ignore.d.ts +48 -0
  24. package/dist/commands/blame-ignore.d.ts.map +1 -0
  25. package/dist/commands/branch-command.d.ts +148 -18
  26. package/dist/commands/branch-command.d.ts.map +1 -1
  27. package/dist/commands/branch-info-command.d.ts +55 -0
  28. package/dist/commands/branch-info-command.d.ts.map +1 -0
  29. package/dist/commands/branch-tracking.d.ts +106 -17
  30. package/dist/commands/branch-tracking.d.ts.map +1 -1
  31. package/dist/commands/branch-upstream-command.d.ts +83 -0
  32. package/dist/commands/branch-upstream-command.d.ts.map +1 -0
  33. package/dist/commands/check-mailmap-command.d.ts +49 -0
  34. package/dist/commands/check-mailmap-command.d.ts.map +1 -0
  35. package/dist/commands/checkout-command.d.ts +26 -3
  36. package/dist/commands/checkout-command.d.ts.map +1 -1
  37. package/dist/commands/checkout-paths.d.ts +4 -0
  38. package/dist/commands/checkout-paths.d.ts.map +1 -1
  39. package/dist/commands/cherry-command.d.ts +61 -0
  40. package/dist/commands/cherry-command.d.ts.map +1 -0
  41. package/dist/commands/cherry-pick-command.d.ts +82 -1
  42. package/dist/commands/cherry-pick-command.d.ts.map +1 -1
  43. package/dist/commands/clean-command.d.ts +44 -0
  44. package/dist/commands/clean-command.d.ts.map +1 -1
  45. package/dist/commands/clean-interactive.d.ts +56 -0
  46. package/dist/commands/clean-interactive.d.ts.map +1 -0
  47. package/dist/commands/clone-command.d.ts +116 -2
  48. package/dist/commands/clone-command.d.ts.map +1 -1
  49. package/dist/commands/commit-command.d.ts +239 -5
  50. package/dist/commands/commit-command.d.ts.map +1 -1
  51. package/dist/commands/commit-reuse.d.ts +33 -0
  52. package/dist/commands/commit-reuse.d.ts.map +1 -0
  53. package/dist/commands/config-command.d.ts +236 -0
  54. package/dist/commands/config-command.d.ts.map +1 -0
  55. package/dist/commands/config-value-types.d.ts +91 -0
  56. package/dist/commands/config-value-types.d.ts.map +1 -0
  57. package/dist/commands/core-config.d.ts +20 -0
  58. package/dist/commands/core-config.d.ts.map +1 -1
  59. package/dist/commands/describe-command.d.ts +71 -64
  60. package/dist/commands/describe-command.d.ts.map +1 -1
  61. package/dist/commands/diff-color-config.d.ts +73 -0
  62. package/dist/commands/diff-color-config.d.ts.map +1 -0
  63. package/dist/commands/diff-command.d.ts +369 -10
  64. package/dist/commands/diff-command.d.ts.map +1 -1
  65. package/dist/commands/fetch-command.d.ts +80 -0
  66. package/dist/commands/fetch-command.d.ts.map +1 -1
  67. package/dist/commands/fetch-multiple-command.d.ts +193 -0
  68. package/dist/commands/fetch-multiple-command.d.ts.map +1 -0
  69. package/dist/commands/fmt-merge-msg-command.d.ts +124 -0
  70. package/dist/commands/fmt-merge-msg-command.d.ts.map +1 -0
  71. package/dist/commands/fork-point.d.ts +38 -0
  72. package/dist/commands/fork-point.d.ts.map +1 -0
  73. package/dist/commands/format-patch-command.d.ts +69 -3
  74. package/dist/commands/format-patch-command.d.ts.map +1 -1
  75. package/dist/commands/fsck/fetch-fsck.d.ts +51 -0
  76. package/dist/commands/fsck/fetch-fsck.d.ts.map +1 -1
  77. package/dist/commands/gc-command.d.ts +8 -0
  78. package/dist/commands/gc-command.d.ts.map +1 -1
  79. package/dist/commands/git-describe.d.ts +81 -4
  80. package/dist/commands/git-describe.d.ts.map +1 -1
  81. package/dist/commands/git-hooks.d.ts +50 -1
  82. package/dist/commands/git-hooks.d.ts.map +1 -1
  83. package/dist/commands/grep/grep-command.d.ts +210 -0
  84. package/dist/commands/grep/grep-command.d.ts.map +1 -0
  85. package/dist/commands/grep/grep-engine.d.ts +218 -0
  86. package/dist/commands/grep/grep-engine.d.ts.map +1 -0
  87. package/dist/commands/grep/index.d.ts +3 -0
  88. package/dist/commands/grep/index.d.ts.map +1 -0
  89. package/dist/commands/index-adder.d.ts +13 -2
  90. package/dist/commands/index-adder.d.ts.map +1 -1
  91. package/dist/commands/index.d.ts +38 -0
  92. package/dist/commands/index.d.ts.map +1 -1
  93. package/dist/commands/index.js +5 -3
  94. package/dist/commands/init-command.d.ts +89 -0
  95. package/dist/commands/init-command.d.ts.map +1 -1
  96. package/dist/commands/interpret-trailers-command.d.ts +90 -0
  97. package/dist/commands/interpret-trailers-command.d.ts.map +1 -0
  98. package/dist/commands/line-log.d.ts +161 -0
  99. package/dist/commands/line-log.d.ts.map +1 -0
  100. package/dist/commands/local-transport.d.ts +36 -5
  101. package/dist/commands/local-transport.d.ts.map +1 -1
  102. package/dist/commands/log-command.d.ts +527 -13
  103. package/dist/commands/log-command.d.ts.map +1 -1
  104. package/dist/commands/log-graph.d.ts +30 -3
  105. package/dist/commands/log-graph.d.ts.map +1 -1
  106. package/dist/commands/log-output.d.ts +199 -6
  107. package/dist/commands/log-output.d.ts.map +1 -1
  108. package/dist/commands/ls-remote-command.d.ts +2 -0
  109. package/dist/commands/ls-remote-command.d.ts.map +1 -1
  110. package/dist/commands/mailmap.d.ts +53 -0
  111. package/dist/commands/mailmap.d.ts.map +1 -1
  112. package/dist/commands/merge-base-command.d.ts +60 -0
  113. package/dist/commands/merge-base-command.d.ts.map +1 -0
  114. package/dist/commands/merge-bases.d.ts +23 -0
  115. package/dist/commands/merge-bases.d.ts.map +1 -1
  116. package/dist/commands/merge-command.d.ts +147 -10
  117. package/dist/commands/merge-command.d.ts.map +1 -1
  118. package/dist/commands/merge-drivers.d.ts +2 -0
  119. package/dist/commands/merge-drivers.d.ts.map +1 -1
  120. package/dist/commands/merge-strategy-options.d.ts +69 -0
  121. package/dist/commands/merge-strategy-options.d.ts.map +1 -0
  122. package/dist/commands/merge-support.d.ts +10 -0
  123. package/dist/commands/merge-support.d.ts.map +1 -1
  124. package/dist/commands/message-cleanup.d.ts +2 -0
  125. package/dist/commands/message-cleanup.d.ts.map +1 -1
  126. package/dist/commands/mv-command.d.ts +4 -0
  127. package/dist/commands/mv-command.d.ts.map +1 -1
  128. package/dist/commands/name-rev-command.d.ts +65 -0
  129. package/dist/commands/name-rev-command.d.ts.map +1 -0
  130. package/dist/commands/name-rev.d.ts +136 -0
  131. package/dist/commands/name-rev.d.ts.map +1 -0
  132. package/dist/commands/notes-command.d.ts.map +1 -1
  133. package/dist/commands/octopus-merge.d.ts +26 -1
  134. package/dist/commands/octopus-merge.d.ts.map +1 -1
  135. package/dist/commands/ort-merge.d.ts +16 -0
  136. package/dist/commands/ort-merge.d.ts.map +1 -1
  137. package/dist/commands/ort-recursive.d.ts.map +1 -1
  138. package/dist/commands/patch-id.d.ts +58 -0
  139. package/dist/commands/patch-id.d.ts.map +1 -1
  140. package/dist/commands/pathspec-file.d.ts +39 -0
  141. package/dist/commands/pathspec-file.d.ts.map +1 -0
  142. package/dist/commands/pathspec.d.ts +3 -0
  143. package/dist/commands/pathspec.d.ts.map +1 -1
  144. package/dist/commands/pretty-format.d.ts +43 -3
  145. package/dist/commands/pretty-format.d.ts.map +1 -1
  146. package/dist/commands/promisor-remote.d.ts.map +1 -1
  147. package/dist/commands/pull-command.d.ts +186 -32
  148. package/dist/commands/pull-command.d.ts.map +1 -1
  149. package/dist/commands/push-command.d.ts +225 -9
  150. package/dist/commands/push-command.d.ts.map +1 -1
  151. package/dist/commands/range-diff/index.d.ts +4 -0
  152. package/dist/commands/range-diff/index.d.ts.map +1 -0
  153. package/dist/commands/range-diff/linear-assignment.d.ts +27 -0
  154. package/dist/commands/range-diff/linear-assignment.d.ts.map +1 -0
  155. package/dist/commands/range-diff/range-diff-command.d.ts +121 -0
  156. package/dist/commands/range-diff/range-diff-command.d.ts.map +1 -0
  157. package/dist/commands/range-diff/range-diff.d.ts +106 -0
  158. package/dist/commands/range-diff/range-diff.d.ts.map +1 -0
  159. package/dist/commands/read-tree-command.d.ts +20 -0
  160. package/dist/commands/read-tree-command.d.ts.map +1 -1
  161. package/dist/commands/rebase-command.d.ts +189 -8
  162. package/dist/commands/rebase-command.d.ts.map +1 -1
  163. package/dist/commands/ref-filter/for-each-ref-command.d.ts +121 -0
  164. package/dist/commands/ref-filter/for-each-ref-command.d.ts.map +1 -0
  165. package/dist/commands/ref-filter/index.d.ts +8 -0
  166. package/dist/commands/ref-filter/index.d.ts.map +1 -0
  167. package/dist/commands/ref-filter/ref-atoms.d.ts +88 -0
  168. package/dist/commands/ref-filter/ref-atoms.d.ts.map +1 -0
  169. package/dist/commands/ref-filter/ref-filter.d.ts +178 -0
  170. package/dist/commands/ref-filter/ref-filter.d.ts.map +1 -0
  171. package/dist/commands/ref-filter/ref-format.d.ts +222 -0
  172. package/dist/commands/ref-filter/ref-format.d.ts.map +1 -0
  173. package/dist/commands/ref-filter/ref-listing-command.d.ts +56 -0
  174. package/dist/commands/ref-filter/ref-listing-command.d.ts.map +1 -0
  175. package/dist/commands/ref-filter/ref-quote.d.ts +20 -0
  176. package/dist/commands/ref-filter/ref-quote.d.ts.map +1 -0
  177. package/dist/commands/ref-filter/version-compare.d.ts +20 -0
  178. package/dist/commands/ref-filter/version-compare.d.ts.map +1 -0
  179. package/dist/commands/reflog-command.d.ts +120 -0
  180. package/dist/commands/reflog-command.d.ts.map +1 -1
  181. package/dist/commands/reflog-walk.d.ts +72 -0
  182. package/dist/commands/reflog-walk.d.ts.map +1 -0
  183. package/dist/commands/remerge-diff.d.ts +59 -0
  184. package/dist/commands/remerge-diff.d.ts.map +1 -0
  185. package/dist/commands/remote-command.d.ts +179 -29
  186. package/dist/commands/remote-command.d.ts.map +1 -1
  187. package/dist/commands/remote-show-command.d.ts +204 -0
  188. package/dist/commands/remote-show-command.d.ts.map +1 -0
  189. package/dist/commands/remote-transport.d.ts +7 -1
  190. package/dist/commands/remote-transport.d.ts.map +1 -1
  191. package/dist/commands/reset-command.d.ts +21 -4
  192. package/dist/commands/reset-command.d.ts.map +1 -1
  193. package/dist/commands/restore-command.d.ts +9 -3
  194. package/dist/commands/restore-command.d.ts.map +1 -1
  195. package/dist/commands/rev-filter/commit-filter.d.ts +95 -0
  196. package/dist/commands/rev-filter/commit-filter.d.ts.map +1 -0
  197. package/dist/commands/rev-filter/commit-grep.d.ts +91 -0
  198. package/dist/commands/rev-filter/commit-grep.d.ts.map +1 -0
  199. package/dist/commands/rev-filter/index.d.ts +3 -0
  200. package/dist/commands/rev-filter/index.d.ts.map +1 -0
  201. package/dist/commands/rev-list-command.d.ts +226 -2
  202. package/dist/commands/rev-list-command.d.ts.map +1 -1
  203. package/dist/commands/revert-command.d.ts +54 -1
  204. package/dist/commands/revert-command.d.ts.map +1 -1
  205. package/dist/commands/revision-range.d.ts +34 -1
  206. package/dist/commands/revision-range.d.ts.map +1 -1
  207. package/dist/commands/revision-resolver.d.ts +15 -0
  208. package/dist/commands/revision-resolver.d.ts.map +1 -1
  209. package/dist/commands/rm-command.d.ts +70 -2
  210. package/dist/commands/rm-command.d.ts.map +1 -1
  211. package/dist/commands/sequencer-pick.d.ts +186 -5
  212. package/dist/commands/sequencer-pick.d.ts.map +1 -1
  213. package/dist/commands/sequencer-support.d.ts +12 -1
  214. package/dist/commands/sequencer-support.d.ts.map +1 -1
  215. package/dist/commands/serve-repository.d.ts +7 -0
  216. package/dist/commands/serve-repository.d.ts.map +1 -1
  217. package/dist/commands/shortlog-command.d.ts +109 -0
  218. package/dist/commands/shortlog-command.d.ts.map +1 -0
  219. package/dist/commands/shortlog.d.ts +151 -0
  220. package/dist/commands/shortlog.d.ts.map +1 -0
  221. package/dist/commands/show-command.d.ts +130 -0
  222. package/dist/commands/show-command.d.ts.map +1 -0
  223. package/dist/commands/show-commit.d.ts +11 -0
  224. package/dist/commands/show-commit.d.ts.map +1 -0
  225. package/dist/commands/signature-check.d.ts +164 -0
  226. package/dist/commands/signature-check.d.ts.map +1 -0
  227. package/dist/commands/signing.d.ts +160 -0
  228. package/dist/commands/signing.d.ts.map +1 -0
  229. package/dist/commands/sparse-checkout-command.d.ts.map +1 -1
  230. package/dist/commands/sparse-index-view.d.ts +45 -0
  231. package/dist/commands/sparse-index-view.d.ts.map +1 -0
  232. package/dist/commands/ssh-signer.d.ts +29 -0
  233. package/dist/commands/ssh-signer.d.ts.map +1 -0
  234. package/dist/commands/ssh-verifier.d.ts +42 -0
  235. package/dist/commands/ssh-verifier.d.ts.map +1 -0
  236. package/dist/commands/stash-apply-command.d.ts +5 -0
  237. package/dist/commands/stash-apply-command.d.ts.map +1 -1
  238. package/dist/commands/stash-branch-command.d.ts +34 -0
  239. package/dist/commands/stash-branch-command.d.ts.map +1 -0
  240. package/dist/commands/stash-create-command.d.ts +17 -0
  241. package/dist/commands/stash-create-command.d.ts.map +1 -1
  242. package/dist/commands/stash-info.d.ts +93 -0
  243. package/dist/commands/stash-info.d.ts.map +1 -0
  244. package/dist/commands/stash-list-command.d.ts +16 -0
  245. package/dist/commands/stash-list-command.d.ts.map +1 -1
  246. package/dist/commands/stash-pop-command.d.ts +39 -0
  247. package/dist/commands/stash-pop-command.d.ts.map +1 -0
  248. package/dist/commands/stash-show-command.d.ts +48 -0
  249. package/dist/commands/stash-show-command.d.ts.map +1 -0
  250. package/dist/commands/stash-store-command.d.ts +29 -0
  251. package/dist/commands/stash-store-command.d.ts.map +1 -0
  252. package/dist/commands/stash-working-tree.d.ts.map +1 -1
  253. package/dist/commands/status-command.d.ts +31 -2
  254. package/dist/commands/status-command.d.ts.map +1 -1
  255. package/dist/commands/status-header.d.ts +5 -0
  256. package/dist/commands/status-header.d.ts.map +1 -1
  257. package/dist/commands/submodule-add-command.d.ts +89 -0
  258. package/dist/commands/submodule-add-command.d.ts.map +1 -0
  259. package/dist/commands/submodule-auth.d.ts +90 -0
  260. package/dist/commands/submodule-auth.d.ts.map +1 -0
  261. package/dist/commands/submodule-commands.d.ts +463 -0
  262. package/dist/commands/submodule-commands.d.ts.map +1 -0
  263. package/dist/commands/submodule-fetch.d.ts +149 -0
  264. package/dist/commands/submodule-fetch.d.ts.map +1 -0
  265. package/dist/commands/submodule-model.d.ts +296 -0
  266. package/dist/commands/submodule-model.d.ts.map +1 -0
  267. package/dist/commands/submodule-unpack.d.ts +120 -0
  268. package/dist/commands/submodule-unpack.d.ts.map +1 -0
  269. package/dist/commands/submodule-update-command.d.ts +206 -0
  270. package/dist/commands/submodule-update-command.d.ts.map +1 -0
  271. package/dist/commands/subtree-shift.d.ts +27 -0
  272. package/dist/commands/subtree-shift.d.ts.map +1 -0
  273. package/dist/commands/switch-command.d.ts +3 -0
  274. package/dist/commands/switch-command.d.ts.map +1 -1
  275. package/dist/commands/tag-command.d.ts +259 -10
  276. package/dist/commands/tag-command.d.ts.map +1 -1
  277. package/dist/commands/trailers.d.ts +218 -17
  278. package/dist/commands/trailers.d.ts.map +1 -1
  279. package/dist/commands/tree-restore.d.ts +7 -0
  280. package/dist/commands/tree-restore.d.ts.map +1 -1
  281. package/dist/commands/verify-command.d.ts +92 -0
  282. package/dist/commands/verify-command.d.ts.map +1 -0
  283. package/dist/commands/worktree-add-command.d.ts +79 -7
  284. package/dist/commands/worktree-add-command.d.ts.map +1 -1
  285. package/dist/commands/worktree-overwrite-checks.d.ts +2 -0
  286. package/dist/commands/worktree-overwrite-checks.d.ts.map +1 -1
  287. package/dist/commands/worktree-path-rules.d.ts +66 -0
  288. package/dist/commands/worktree-path-rules.d.ts.map +1 -0
  289. package/dist/commands/worktree-remove-command.d.ts +10 -3
  290. package/dist/commands/worktree-remove-command.d.ts.map +1 -1
  291. package/dist/commands/worktree-repair-command.d.ts +15 -2
  292. package/dist/commands/worktree-repair-command.d.ts.map +1 -1
  293. package/dist/commands/worktree-support.d.ts +5 -0
  294. package/dist/commands/worktree-support.d.ts.map +1 -1
  295. package/dist/{commands-DIJ91NnD.js → commands-CNvli5bl.js} +49442 -54941
  296. package/dist/errors/checkout-errors.d.ts +19 -0
  297. package/dist/errors/checkout-errors.d.ts.map +1 -1
  298. package/dist/errors/command-errors.d.ts +25 -0
  299. package/dist/errors/command-errors.d.ts.map +1 -1
  300. package/dist/errors/index.js +85 -3
  301. package/dist/errors/ref-errors.d.ts +19 -0
  302. package/dist/errors/ref-errors.d.ts.map +1 -1
  303. package/dist/errors/worktree-errors.d.ts +6 -1
  304. package/dist/errors/worktree-errors.d.ts.map +1 -1
  305. package/dist/fsck-CPeDh9fh.js +5138 -0
  306. package/dist/git-command.d.ts +58 -2
  307. package/dist/git-command.d.ts.map +1 -1
  308. package/dist/git.d.ts +363 -1
  309. package/dist/git.d.ts.map +1 -1
  310. package/dist/guarded-transport-command.d.ts +82 -0
  311. package/dist/guarded-transport-command.d.ts.map +1 -0
  312. package/dist/index.d.ts +1 -0
  313. package/dist/index.d.ts.map +1 -1
  314. package/dist/index.js +6 -5
  315. package/dist/remote-config/index.d.ts +1 -1
  316. package/dist/remote-config/index.d.ts.map +1 -1
  317. package/dist/remote-config/remote-config-store.d.ts +55 -0
  318. package/dist/remote-config/remote-config-store.d.ts.map +1 -1
  319. package/dist/remote-transport-CCmBadm-.js +1606 -0
  320. package/dist/rename/detect-renames.d.ts +20 -0
  321. package/dist/rename/detect-renames.d.ts.map +1 -1
  322. package/dist/rename/diffcore-break.d.ts +51 -0
  323. package/dist/rename/diffcore-break.d.ts.map +1 -0
  324. package/dist/rename/index.d.ts +1 -0
  325. package/dist/rename/index.d.ts.map +1 -1
  326. package/dist/results/blame-format.d.ts +62 -1
  327. package/dist/results/blame-format.d.ts.map +1 -1
  328. package/dist/results/clone-result.d.ts +9 -0
  329. package/dist/results/clone-result.d.ts.map +1 -1
  330. package/dist/results/combined-diff.d.ts +3 -0
  331. package/dist/results/combined-diff.d.ts.map +1 -1
  332. package/dist/results/diff-check.d.ts +38 -0
  333. package/dist/results/diff-check.d.ts.map +1 -0
  334. package/dist/results/diff-color.d.ts +135 -0
  335. package/dist/results/diff-color.d.ts.map +1 -0
  336. package/dist/results/diff-dirstat.d.ts +36 -0
  337. package/dist/results/diff-dirstat.d.ts.map +1 -0
  338. package/dist/results/diff-entry.d.ts +10 -0
  339. package/dist/results/diff-entry.d.ts.map +1 -1
  340. package/dist/results/diff-formatter.d.ts.map +1 -1
  341. package/dist/results/diff-output.d.ts +103 -1
  342. package/dist/results/diff-output.d.ts.map +1 -1
  343. package/dist/results/diff-pickaxe.d.ts +67 -0
  344. package/dist/results/diff-pickaxe.d.ts.map +1 -0
  345. package/dist/results/diff-words.d.ts +55 -0
  346. package/dist/results/diff-words.d.ts.map +1 -0
  347. package/dist/results/fetch-result.d.ts +12 -1
  348. package/dist/results/fetch-result.d.ts.map +1 -1
  349. package/dist/results/index.d.ts +6 -0
  350. package/dist/results/index.d.ts.map +1 -1
  351. package/dist/results/index.js +2 -2
  352. package/dist/results/init-result.d.ts +8 -1
  353. package/dist/results/init-result.d.ts.map +1 -1
  354. package/dist/results/line-range-hunks.d.ts +27 -0
  355. package/dist/results/line-range-hunks.d.ts.map +1 -0
  356. package/dist/results/merge-result.d.ts +8 -1
  357. package/dist/results/merge-result.d.ts.map +1 -1
  358. package/dist/results/pull-result.d.ts +11 -0
  359. package/dist/results/pull-result.d.ts.map +1 -1
  360. package/dist/results/push-result.d.ts +12 -0
  361. package/dist/results/push-result.d.ts.map +1 -1
  362. package/dist/results/rebase-result.d.ts +2 -0
  363. package/dist/results/rebase-result.d.ts.map +1 -1
  364. package/dist/results/stash-result.d.ts +6 -0
  365. package/dist/results/stash-result.d.ts.map +1 -1
  366. package/dist/results/status-result.d.ts +1 -1
  367. package/dist/results/status-result.d.ts.map +1 -1
  368. package/dist/results-BDuEgdLU.js +46847 -0
  369. package/dist/transport-command.d.ts +14 -0
  370. package/dist/transport-command.d.ts.map +1 -1
  371. package/dist/whitespace/index.d.ts +2 -0
  372. package/dist/whitespace/index.d.ts.map +1 -0
  373. package/dist/whitespace/whitespace-rule.d.ts +94 -0
  374. package/dist/whitespace/whitespace-rule.d.ts.map +1 -0
  375. package/package.json +12 -12
  376. package/src/commands/add-command.ts +293 -17
  377. package/src/commands/add-patch/add-patch.ts +8 -0
  378. package/src/commands/add-patch/patch-backend.ts +20 -2
  379. package/src/commands/am/am-command.ts +400 -46
  380. package/src/commands/am/index.ts +1 -0
  381. package/src/commands/am/mailsplit.ts +326 -0
  382. package/src/commands/apply/apply-command.ts +58 -15
  383. package/src/commands/apply/apply-engine.ts +1 -1
  384. package/src/commands/apply/apply-parse.ts +17 -8
  385. package/src/commands/apply/index.ts +8 -1
  386. package/src/commands/bisect/bisect-command.ts +18 -5
  387. package/src/commands/blame-command.ts +1450 -51
  388. package/src/commands/blame-ignore.ts +307 -0
  389. package/src/commands/branch-command.ts +528 -53
  390. package/src/commands/branch-info-command.ts +150 -0
  391. package/src/commands/branch-tracking.ts +335 -60
  392. package/src/commands/branch-upstream-command.ts +218 -0
  393. package/src/commands/check-mailmap-command.ts +129 -0
  394. package/src/commands/checkout-command.ts +166 -55
  395. package/src/commands/checkout-paths.ts +28 -0
  396. package/src/commands/cherry-command.ts +187 -0
  397. package/src/commands/cherry-pick-command.ts +185 -1
  398. package/src/commands/clean-command.ts +126 -15
  399. package/src/commands/clean-interactive.ts +522 -0
  400. package/src/commands/clone-command.ts +598 -45
  401. package/src/commands/commit-command.ts +925 -74
  402. package/src/commands/commit-reuse.ts +94 -0
  403. package/src/commands/config-command.ts +1256 -0
  404. package/src/commands/config-value-types.ts +358 -0
  405. package/src/commands/core-config.ts +40 -0
  406. package/src/commands/describe-command.ts +341 -254
  407. package/src/commands/diff-color-config.ts +274 -0
  408. package/src/commands/diff-command.ts +1619 -99
  409. package/src/commands/fetch-command.ts +495 -14
  410. package/src/commands/fetch-multiple-command.ts +665 -0
  411. package/src/commands/fmt-merge-msg-command.ts +715 -0
  412. package/src/commands/fork-point.ts +63 -0
  413. package/src/commands/format-patch-command.ts +496 -116
  414. package/src/commands/fsck/fetch-fsck.ts +172 -18
  415. package/src/commands/gc-command.ts +31 -1
  416. package/src/commands/git-describe.ts +460 -201
  417. package/src/commands/git-hooks.ts +123 -3
  418. package/src/commands/grep/grep-command.ts +1077 -0
  419. package/src/commands/grep/grep-engine.ts +1024 -0
  420. package/src/commands/grep/index.ts +2 -0
  421. package/src/commands/index-adder.ts +46 -7
  422. package/src/commands/index.ts +43 -0
  423. package/src/commands/init-command.ts +603 -49
  424. package/src/commands/interpret-trailers-command.ts +256 -0
  425. package/src/commands/line-log.ts +931 -0
  426. package/src/commands/local-transport.ts +109 -10
  427. package/src/commands/log-command.ts +2599 -326
  428. package/src/commands/log-graph.ts +129 -29
  429. package/src/commands/log-output.ts +449 -27
  430. package/src/commands/ls-remote-command.ts +5 -0
  431. package/src/commands/mailmap.ts +155 -0
  432. package/src/commands/merge-base-command.ts +170 -0
  433. package/src/commands/merge-bases.ts +63 -8
  434. package/src/commands/merge-command.ts +601 -95
  435. package/src/commands/merge-drivers.ts +3 -0
  436. package/src/commands/merge-strategy-options.ts +224 -0
  437. package/src/commands/merge-support.ts +115 -22
  438. package/src/commands/message-cleanup.ts +1 -1
  439. package/src/commands/mv-command.ts +6 -3
  440. package/src/commands/name-rev-command.ts +184 -0
  441. package/src/commands/name-rev.ts +762 -0
  442. package/src/commands/notes-command.ts +11 -1
  443. package/src/commands/octopus-merge.ts +35 -11
  444. package/src/commands/ort-merge.ts +41 -7
  445. package/src/commands/ort-recursive.ts +40 -2
  446. package/src/commands/patch-id.ts +109 -0
  447. package/src/commands/pathspec-file.ts +72 -0
  448. package/src/commands/pathspec.ts +14 -2
  449. package/src/commands/pretty-format.ts +103 -19
  450. package/src/commands/promisor-remote.ts +10 -1
  451. package/src/commands/pull-command.ts +734 -221
  452. package/src/commands/push-command.ts +1035 -68
  453. package/src/commands/range-diff/index.ts +3 -0
  454. package/src/commands/range-diff/linear-assignment.ts +203 -0
  455. package/src/commands/range-diff/range-diff-command.ts +433 -0
  456. package/src/commands/range-diff/range-diff.ts +617 -0
  457. package/src/commands/read-tree-command.ts +102 -4
  458. package/src/commands/rebase-command.ts +1074 -194
  459. package/src/commands/ref-filter/for-each-ref-command.ts +298 -0
  460. package/src/commands/ref-filter/index.ts +7 -0
  461. package/src/commands/ref-filter/ref-atoms.ts +581 -0
  462. package/src/commands/ref-filter/ref-filter.ts +651 -0
  463. package/src/commands/ref-filter/ref-format.ts +1070 -0
  464. package/src/commands/ref-filter/ref-listing-command.ts +421 -0
  465. package/src/commands/ref-filter/ref-quote.ts +69 -0
  466. package/src/commands/ref-filter/version-compare.ts +177 -0
  467. package/src/commands/reflog-command.ts +492 -2
  468. package/src/commands/reflog-walk.ts +234 -0
  469. package/src/commands/remerge-diff.ts +241 -0
  470. package/src/commands/remote-command.ts +537 -69
  471. package/src/commands/remote-show-command.ts +836 -0
  472. package/src/commands/remote-transport.ts +9 -1
  473. package/src/commands/reset-command.ts +114 -34
  474. package/src/commands/restore-command.ts +27 -41
  475. package/src/commands/rev-filter/commit-filter.ts +159 -0
  476. package/src/commands/rev-filter/commit-grep.ts +444 -0
  477. package/src/commands/rev-filter/index.ts +2 -0
  478. package/src/commands/rev-list-command.ts +578 -15
  479. package/src/commands/revert-command.ts +123 -1
  480. package/src/commands/revision-range.ts +207 -5
  481. package/src/commands/revision-resolver.ts +23 -8
  482. package/src/commands/rm-command.ts +282 -21
  483. package/src/commands/sequencer-pick.ts +818 -111
  484. package/src/commands/sequencer-support.ts +184 -4
  485. package/src/commands/serve-repository.ts +18 -3
  486. package/src/commands/shortlog-command.ts +354 -0
  487. package/src/commands/shortlog.ts +361 -0
  488. package/src/commands/show-command.ts +491 -0
  489. package/src/commands/show-commit.ts +24 -0
  490. package/src/commands/signature-check.ts +657 -0
  491. package/src/commands/signing.ts +385 -0
  492. package/src/commands/sparse-checkout-command.ts +2 -9
  493. package/src/commands/sparse-checkout-support.ts +2 -2
  494. package/src/commands/sparse-index-view.ts +135 -0
  495. package/src/commands/ssh-signer.ts +199 -0
  496. package/src/commands/ssh-verifier.ts +523 -0
  497. package/src/commands/stash-apply-command.ts +16 -4
  498. package/src/commands/stash-branch-command.ts +88 -0
  499. package/src/commands/stash-create-command.ts +28 -0
  500. package/src/commands/stash-info.ts +243 -0
  501. package/src/commands/stash-list-command.ts +33 -0
  502. package/src/commands/stash-pop-command.ts +83 -0
  503. package/src/commands/stash-show-command.ts +141 -0
  504. package/src/commands/stash-store-command.ts +82 -0
  505. package/src/commands/stash-working-tree.ts +2 -2
  506. package/src/commands/status-command.ts +120 -27
  507. package/src/commands/status-format.ts +1 -1
  508. package/src/commands/status-header.ts +41 -7
  509. package/src/commands/submodule-add-command.ts +509 -0
  510. package/src/commands/submodule-auth.ts +276 -0
  511. package/src/commands/submodule-commands.ts +1835 -0
  512. package/src/commands/submodule-fetch.ts +789 -0
  513. package/src/commands/submodule-model.ts +938 -0
  514. package/src/commands/submodule-unpack.ts +265 -0
  515. package/src/commands/submodule-update-command.ts +1126 -0
  516. package/src/commands/subtree-shift.ts +215 -0
  517. package/src/commands/switch-command.ts +12 -1
  518. package/src/commands/tag-command.ts +876 -64
  519. package/src/commands/trailers.ts +837 -100
  520. package/src/commands/tree-restore.ts +44 -11
  521. package/src/commands/verify-command.ts +235 -0
  522. package/src/commands/worktree-add-command.ts +268 -24
  523. package/src/commands/worktree-overwrite-checks.ts +5 -0
  524. package/src/commands/worktree-path-rules.ts +183 -0
  525. package/src/commands/worktree-remove-command.ts +39 -5
  526. package/src/commands/worktree-repair-command.ts +52 -5
  527. package/src/commands/worktree-support.ts +22 -1
  528. package/src/errors/checkout-errors.ts +29 -0
  529. package/src/errors/command-errors.ts +37 -1
  530. package/src/errors/ref-errors.ts +23 -0
  531. package/src/errors/worktree-errors.ts +8 -1
  532. package/src/git-command.ts +153 -2
  533. package/src/git.ts +550 -1
  534. package/src/guarded-transport-command.ts +171 -0
  535. package/src/index.ts +1 -0
  536. package/src/remote-config/index.ts +2 -0
  537. package/src/remote-config/remote-config-store.ts +101 -0
  538. package/src/rename/detect-renames.ts +42 -8
  539. package/src/rename/diffcore-break.ts +166 -0
  540. package/src/rename/index.ts +1 -0
  541. package/src/results/blame-format.ts +268 -43
  542. package/src/results/clone-result.ts +6 -0
  543. package/src/results/combined-diff.ts +38 -18
  544. package/src/results/diff-check.ts +185 -0
  545. package/src/results/diff-color.ts +868 -0
  546. package/src/results/diff-dirstat.ts +117 -0
  547. package/src/results/diff-entry.ts +12 -0
  548. package/src/results/diff-formatter.ts +1 -0
  549. package/src/results/diff-output.ts +322 -32
  550. package/src/results/diff-pickaxe.ts +304 -0
  551. package/src/results/diff-words.ts +395 -0
  552. package/src/results/fetch-result.ts +12 -1
  553. package/src/results/index.ts +6 -0
  554. package/src/results/init-result.ts +10 -1
  555. package/src/results/line-range-hunks.ts +126 -0
  556. package/src/results/merge-result.ts +9 -0
  557. package/src/results/pull-result.ts +7 -0
  558. package/src/results/push-result.ts +12 -0
  559. package/src/results/rebase-result.ts +3 -0
  560. package/src/results/stash-result.ts +7 -0
  561. package/src/results/status-result.ts +2 -2
  562. package/src/transport-command.ts +34 -3
  563. package/src/whitespace/index.ts +1 -0
  564. package/src/{commands/apply/whitespace.ts → whitespace/whitespace-rule.ts} +173 -23
  565. package/dist/commands/apply/whitespace.d.ts +0 -58
  566. package/dist/commands/apply/whitespace.d.ts.map +0 -1
  567. package/dist/git-command-BGiOJ8Zk.js +0 -7246
  568. package/dist/results-WVlBhVb1.js +0 -2935
@@ -6,11 +6,13 @@ import {
6
6
  } from "@statewalker/vcs-core";
7
7
  import {
8
8
  ByteSink,
9
+ compilePosixRegex,
9
10
  isNullObjectId,
11
+ type PosixRegex,
10
12
  parseGitBool,
11
13
  type XdiffAlgorithm,
12
14
  } from "@statewalker/vcs-utils";
13
- import { compareGitPaths, decodeGitPath } from "@statewalker/vcs-utils/encoding";
15
+ import { compareGitPaths, decodeGitPath, encodeGitPath } from "@statewalker/vcs-utils/encoding";
14
16
  import {
15
17
  type AttributesIndex,
16
18
  collectChunks,
@@ -25,16 +27,36 @@ import {
25
27
  withWorktreeEntries,
26
28
  } from "@statewalker/vcs-working-tree";
27
29
 
28
- import { NoHeadError, RefNotFoundError } from "../errors/index.js";
30
+ import {
31
+ GitApiError,
32
+ InvalidArgumentError,
33
+ NoHeadError,
34
+ RefNotFoundError,
35
+ } from "../errors/index.js";
29
36
  import { GitCommand } from "../git-command.js";
30
37
  import { RemoteConfigStore } from "../remote-config/index.js";
31
38
  import {
39
+ type BreakScores,
40
+ countChanges,
32
41
  DEFAULT_RENAME_LIMIT,
33
42
  detectRenames,
34
43
  findFollowSource,
44
+ parseBreakRewrites,
45
+ renameScoreOption,
35
46
  scorePercent,
47
+ shouldBreak,
48
+ spanCounts,
36
49
  } from "../rename/index.js";
37
50
  import { writeCombinedDiff } from "../results/combined-diff.js";
51
+ import { conflictMarkerSizeOf, writePairCheck } from "../results/diff-check.js";
52
+ import { MovedLineBuffer } from "../results/diff-color.js";
53
+ import {
54
+ DEFAULT_DIRSTAT,
55
+ type DirstatFile,
56
+ type DirstatParams,
57
+ formatDirstat,
58
+ parseDirstatParams,
59
+ } from "../results/diff-dirstat.js";
38
60
  import { ChangeType, type DiffEntry } from "../results/diff-entry.js";
39
61
  import { diffEntryToPair } from "../results/diff-formatter.js";
40
62
  import { orderByPatterns, parseOrderFile } from "../results/diff-order.js";
@@ -54,14 +76,29 @@ import {
54
76
  formatShortstat,
55
77
  formatStat,
56
78
  formatSummary,
79
+ writeHeaderOnlyPatch,
57
80
  writePairPatch,
58
81
  } from "../results/diff-output.js";
82
+ import { DiffPickaxe } from "../results/diff-pickaxe.js";
59
83
  import { quotePath } from "../results/quote-path.js";
84
+ import {
85
+ parseWhitespaceRule,
86
+ WS_DEFAULT_RULE,
87
+ WS_INCOMPLETE_LINE,
88
+ whitespaceRuleOf,
89
+ } from "../whitespace/index.js";
60
90
  import { bareAttributesResolver } from "./attributes-source.js";
61
91
  import { worktreeModeTrust } from "./core-config.js";
92
+ import {
93
+ type DiffColorOptions,
94
+ type DiffColorSettings,
95
+ readDiffColorSettings,
96
+ whitespaceRuleError,
97
+ } from "./diff-color-config.js";
62
98
  import { textconvRunnerOf } from "./diff-textconv.js";
63
99
  import { matchPathspec, type PathspecItem, parsePathspecItem } from "./pathspec.js";
64
100
  import { PathspecAttributes } from "./pathspec-attributes.js";
101
+ import { revisionMergeBases } from "./rev-parse-command.js";
65
102
  import { readSubmoduleDirt, type SubmoduleDirt } from "./status-command.js";
66
103
  import {
67
104
  isSubmoduleIgnoreMode,
@@ -87,7 +124,7 @@ const WITHOUT_INDEX_ATTRIBUTES: { direction: "checkin"; index: AttributesIndex }
87
124
  * The outputs whose diff git prefetches (diffcore_std's `output_formats_to_prefetch`: the
88
125
  * diffstat kinds, the patch, `--dirstat`)
89
126
  */
90
- const PREFETCH_FORMATS = new Set<string>(["patch", "stat", "numstat", "shortstat"]);
127
+ const PREFETCH_FORMATS = new Set<string>(["patch", "stat", "numstat", "shortstat", "dirstat"]);
91
128
 
92
129
  /**
93
130
  * The repository blobs of a diff's pairs (git's `diff_add_if_missing`: each side whose id is
@@ -96,7 +133,14 @@ const PREFETCH_FORMATS = new Set<string>(["patch", "stat", "numstat", "shortstat
96
133
  function prefetchIds(entries: readonly DiffEntry[]): ObjectId[] {
97
134
  const out: ObjectId[] = [];
98
135
  const add = (id: ObjectId | undefined, mode: number | undefined) => {
99
- if (id && !isNullObjectId(id) && mode !== GITLINK && mode !== undefined && mode !== 0)
136
+ if (
137
+ id &&
138
+ !isNullObjectId(id) &&
139
+ mode !== GITLINK &&
140
+ mode !== undefined &&
141
+ mode !== 0 &&
142
+ (mode & 0o170000) !== 0o040000
143
+ )
100
144
  out.push(id);
101
145
  };
102
146
  for (const e of entries) {
@@ -114,15 +158,48 @@ export type DiffOutputFormat =
114
158
  | "shortstat"
115
159
  | "summary"
116
160
  | "name-only"
117
- | "name-status";
161
+ | "name-status"
162
+ /**
163
+ * `--dirstat`: the share of the change each directory holds (see
164
+ * {@link DiffTextOptions.dirstat}, `diff.dirstat`)
165
+ */
166
+ | "dirstat"
167
+ /**
168
+ * `--check`: the whitespace errors and leftover conflict markers the change adds (see
169
+ * {@link writePairCheck}); it turns the other formats off, and {@link DiffCommand.exitCode}
170
+ * gets 2 when it found any
171
+ */
172
+ | "check";
118
173
 
119
174
  /** Options of the text output that `git diff` takes on its command line */
120
175
  export interface DiffTextOptions
121
- extends Omit<DiffOutputOptions, "driver" | "algorithm" | "indentHeuristic"> {
176
+ extends Omit<
177
+ DiffOutputOptions,
178
+ | "driver"
179
+ | "algorithm"
180
+ | "indentHeuristic"
181
+ | "ignoreRegex"
182
+ | "colors"
183
+ | "wsHighlight"
184
+ | "whitespaceRule"
185
+ | "defaultWordRegex"
186
+ | "anchors"
187
+ >,
188
+ DiffColorOptions {
189
+ /**
190
+ * The builtin diff drivers (funcname and word regexes) of that git version (default 2.56):
191
+ * 2.43 has no `ini`, `r` and `swift` drivers and older `bash`, `csharp` and `scheme` ones
192
+ */
193
+ driverCompatibility?: "2.43" | "2.56";
122
194
  /** `--diff-algorithm` (default `diff.algorithm`, else myers) */
123
195
  algorithm?: XdiffAlgorithm;
124
196
  /** `--indent-heuristic` / `--no-indent-heuristic` (default `diff.indentHeuristic`, true) */
125
197
  indentHeuristic?: boolean;
198
+ /**
199
+ * diff_options.stat_sep: text written after the blank line that separates a stat or
200
+ * summary from the patch (format-patch's MIME part header with `--attach`/`--inline`)
201
+ */
202
+ statSep?: string;
126
203
  /**
127
204
  * `--abbrev=<n>`: the `index` lines' ids at least n digits, clamped as git clamps it (below
128
205
  * 4, 0 too, is 4; above 40 is 40); the combined diffs of conflicted paths ignore it, as
@@ -188,6 +265,243 @@ export interface DiffTextOptions
188
265
  * prefixes with them (`diff --git b/f a/f`). Combined diffs of conflicted paths are not swapped.
189
266
  */
190
267
  reverse?: boolean;
268
+ /**
269
+ * `--diff-filter=<letters>`: only the pairs of these statuses (`A`dded, `C`opied,
270
+ * `D`eleted, `M`odified, `R`enamed, `T`ype changed, `U`nmerged, `X` unknown, `B`roken);
271
+ * a lowercase letter leaves its status out instead, and `*` keeps every pair as long as one
272
+ * of them matches (all or none). An unknown letter throws git's
273
+ * `error: unknown change class '<c>' in --diff-filter=<letters>` (exit 129). The combined
274
+ * diff (`diff --cc`) of a conflicted path is not filtered, as git's is not.
275
+ */
276
+ diffFilter?: string;
277
+ /**
278
+ * `--relative=<path>`: only the paths that start with `<path>` (a string prefix, as git's
279
+ * `strncmp`: `sub` takes `subdir/` too), shown without it (and the `/` after it);
280
+ * `--no-relative` is `false`. The commands run at the top of the worktree, so `true`
281
+ * (`--relative` without a path, or `diff.relative`) shows every path as it is.
282
+ */
283
+ relative?: string | boolean;
284
+ /**
285
+ * `--rotate-to=<path>`: the output starts at this path, the ones before it moved to the end;
286
+ * `git diff` throws `fatal: No such path '<path>' in the diff` when no pair has it, `git
287
+ * log` starts at the first path after it
288
+ */
289
+ rotateTo?: string;
290
+ /** `--skip-to=<path>`: as {@link rotateTo}, the paths before it left out */
291
+ skipTo?: string;
292
+ /**
293
+ * `-I<regex>` (`--ignore-matching-lines`): changes whose lines all match one of these POSIX
294
+ * extended regexes are not shown (xdiff's `xdl_mark_ignorable_regex`); an invalid one
295
+ * throws git's `error: invalid regex given to -I: '<regex>'` (exit 129)
296
+ */
297
+ ignoreMatchingLines?: readonly string[];
298
+ /**
299
+ * `--quiet` still detects renames and copies (git 2.43; default false: git 2.5x's
300
+ * diff_setup_done turns `detect_rename` off under `quick`, so `--quiet --diff-filter=R`
301
+ * finds nothing there)
302
+ */
303
+ quietDetectsRenames?: boolean;
304
+ /**
305
+ * `--exit-code` and `--quiet` count only the pairs an output shows (default true, git 2.5x,
306
+ * whose porcelain diff turns `diff_from_contents` on with an exit status: `--summary` alone
307
+ * then exits 0, a pair whose patch shows nothing does not count); false counts every queued
308
+ * pair unless a whitespace option or `-I` is given, as git 2.43
309
+ */
310
+ exitCodeFromContents?: boolean;
311
+ /**
312
+ * `-S<string>`: only the pairs whose two sides hold the string a different number of
313
+ * times (diffcore-pickaxe.c), read through textconv unless `textconv: false`. An empty
314
+ * string throws git's `error: -S requires a non-empty argument` (exit 129).
315
+ */
316
+ pickaxeString?: string;
317
+ /**
318
+ * `-G<regex>`: only the pairs whose added or removed lines match this POSIX extended
319
+ * regex; binary pairs are passed over unless `text` (or textconv makes them text). An
320
+ * empty one throws `error: -G requires a non-empty argument` (exit 129), an invalid one
321
+ * `fatal: invalid regex: <message>` (exit 128).
322
+ */
323
+ pickaxeGrep?: string;
324
+ /**
325
+ * `--find-object=<object>` (each a revision naming an object): only the pairs with one of
326
+ * them on either side; a diff of two trees also lists the subtrees that changed, so a tree
327
+ * can be found too (`tree_in_recursive`). One that names nothing throws `error: unable to
328
+ * resolve '<object>'` (exit 129).
329
+ */
330
+ findObjects?: readonly string[];
331
+ /** `--pickaxe-regex`: `-S` takes a POSIX extended regex */
332
+ pickaxeRegex?: boolean;
333
+ /** `--pickaxe-all`: when one pair matches, every pair is kept; when none, none */
334
+ pickaxeAll?: boolean;
335
+ /** `-i` / `--regexp-ignore-case` of `-S`/`-G` (ASCII case folded) */
336
+ pickaxeIgnoreCase?: boolean;
337
+ /**
338
+ * `-M[<n>]` / `--find-renames[=<n>]`: detect renames, at least this similar (git's
339
+ * syntax: `90%`, `9` and `.9` alike; `true` the default 50%); `false` is `--no-renames`.
340
+ * Wins over {@link DiffCommand.setRenames} and `diff.renames`. Trailing text throws git's
341
+ * `error: invalid argument to find-renames` (exit 129).
342
+ */
343
+ findRenames?: boolean | string;
344
+ /**
345
+ * `-C[<n>]` / `--find-copies[=<n>]`: renames and copies, from the modified paths too (the
346
+ * threshold as {@link findRenames}). With `diff.renames=copies` and nothing else asking,
347
+ * git's second `-C` is found: copies are then found harder.
348
+ */
349
+ findCopies?: boolean | string;
350
+ /** `--find-copies-harder` (or `-C -C`): unchanged paths are copy sources too */
351
+ findCopiesHarder?: boolean;
352
+ /**
353
+ * `-B[<n>][/<m>]` / `--break-rewrites`: modifications that changed at least `<n>` (default
354
+ * 50%) are broken into a deletion and a creation for rename detection, and merged back
355
+ * unless they removed at least `<m>` (default 60%) of the old content, shown then as a
356
+ * complete rewrite (`dissimilarity index`, `M<score>`)
357
+ */
358
+ breakRewrites?: boolean | string;
359
+ /**
360
+ * `--dirstat=<params>` for the `dirstat` format: comma-separated `changes`, `lines`,
361
+ * `files`, `cumulative`, `noncumulative` and a cut-off percentage (default `diff.dirstat`,
362
+ * else `changes,noncumulative,3`)
363
+ */
364
+ dirstat?: string;
365
+ /**
366
+ * `--anchored=<text>`: the patience diff, lines starting with one of these texts kept
367
+ * unchanged where they are unique on both sides
368
+ */
369
+ anchored?: readonly string[];
370
+ }
371
+
372
+ /** Whether options ask for a pickaxe (git's `DIFF_PICKAXE_KINDS_MASK`) */
373
+ export function hasPickaxe(o: DiffTextOptions): boolean {
374
+ return (
375
+ o.pickaxeString !== undefined ||
376
+ o.pickaxeGrep !== undefined ||
377
+ (o.findObjects !== undefined && o.findObjects.length > 0)
378
+ );
379
+ }
380
+
381
+ /**
382
+ * diff.c's checks of the pickaxe options (the option callbacks' empty-argument errors, then
383
+ * diff_setup_done's combinations), before anything is read
384
+ */
385
+ export function checkPickaxeOptions(o: DiffTextOptions): void {
386
+ if (o.pickaxeString === "") {
387
+ throw new InvalidArgumentError(
388
+ "pickaxeString",
389
+ "",
390
+ "error: -S requires a non-empty argument",
391
+ ).withExitCode(129);
392
+ }
393
+ if (o.pickaxeGrep === "") {
394
+ throw new InvalidArgumentError(
395
+ "pickaxeGrep",
396
+ "",
397
+ "error: -G requires a non-empty argument",
398
+ ).withExitCode(129);
399
+ }
400
+ const kinds =
401
+ (o.pickaxeString !== undefined ? 1 : 0) +
402
+ (o.pickaxeGrep !== undefined ? 1 : 0) +
403
+ ((o.findObjects?.length ?? 0) > 0 ? 1 : 0);
404
+ if (kinds > 1) {
405
+ throw new GitApiError(
406
+ "fatal: options '-G', '-S', and '--find-object' cannot be used together",
407
+ ).withExitCode(128);
408
+ }
409
+ if (o.pickaxeGrep !== undefined && o.pickaxeRegex) {
410
+ throw new GitApiError(
411
+ "fatal: options '-G' and '--pickaxe-regex' cannot be used together, use '--pickaxe-regex' with '-S'",
412
+ ).withExitCode(128);
413
+ }
414
+ if (o.pickaxeAll && (o.findObjects?.length ?? 0) > 0) {
415
+ throw new GitApiError(
416
+ "fatal: options '--pickaxe-all' and '--find-object' cannot be used together, use '--pickaxe-all' with '-G' and '-S'",
417
+ ).withExitCode(128);
418
+ }
419
+ }
420
+
421
+ /** git's status letters `--diff-filter` takes (`diff_status_letters`) */
422
+ const FILTER_LETTERS = "ACDMRTXU*B";
423
+
424
+ /** The bits of `--diff-filter=<letters>` (git's `filter`, `filter_not` folded in) */
425
+ function parseDiffFilter(spec: string): Set<string> {
426
+ const on = new Set<string>();
427
+ const off = new Set<string>();
428
+ for (const c of spec) {
429
+ const upper = c >= "a" && c <= "z" ? c.toUpperCase() : c;
430
+ if (!FILTER_LETTERS.includes(upper) || upper.length !== 1) {
431
+ throw new InvalidArgumentError(
432
+ "diffFilter",
433
+ spec,
434
+ `error: unknown change class '${c}' in --diff-filter=${spec}`,
435
+ ).withExitCode(129);
436
+ }
437
+ (upper === c ? on : off).add(upper);
438
+ }
439
+ // diff_setup_done: a negation alone starts from every bit but `*`
440
+ if (off.size > 0 && on.size === 0) {
441
+ for (const l of FILTER_LETTERS) if (l !== "*") on.add(l);
442
+ }
443
+ for (const l of off) on.delete(l);
444
+ return on;
445
+ }
446
+
447
+ /** git's status letter of a queued entry */
448
+ function statusOf(entry: DiffEntry): string {
449
+ if (entry.unmerged) return "U";
450
+ switch (entry.changeType) {
451
+ case ChangeType.ADD:
452
+ return "A";
453
+ case ChangeType.DELETE:
454
+ return "D";
455
+ case ChangeType.RENAME:
456
+ return "R";
457
+ case ChangeType.COPY:
458
+ return "C";
459
+ default:
460
+ return entry.oldMode !== undefined &&
461
+ entry.newMode !== undefined &&
462
+ (entry.oldMode & S_IFMT) !== (entry.newMode & S_IFMT)
463
+ ? "T"
464
+ : "M";
465
+ }
466
+ }
467
+
468
+ /** diffcore_apply_filter over the queue */
469
+ function applyDiffFilter(entries: DiffEntry[], filter: Set<string> | undefined): DiffEntry[] {
470
+ if (!filter) return entries;
471
+ // match_filter: a modification with a score is a broken pair (-B), filtered as `B`
472
+ const matches = (e: DiffEntry) => {
473
+ const status = statusOf(e);
474
+ return status === "M" && e.score ? filter.has("B") : filter.has(status);
475
+ };
476
+ if (filter.has("*")) return entries.some(matches) ? entries : [];
477
+ return entries.filter(matches);
478
+ }
479
+
480
+ /**
481
+ * diffcore_rotate: the queue from the pair whose (new side's) path is `to`, the ones before
482
+ * it after it (`skip`: dropped); `strict` (`git diff`) needs that exact path, else the first
483
+ * path after it starts, and a path past every pair changes nothing.
484
+ */
485
+ function rotateEntries(entries: DiffEntry[], to: string, skip: boolean, strict: boolean) {
486
+ if (entries.length === 0) return entries;
487
+ let at = 0;
488
+ for (; at < entries.length; at++) {
489
+ const e = entries[at] as DiffEntry;
490
+ const cmp = compareGitPaths(to, e.newPath ?? e.oldPath ?? "");
491
+ if (cmp === 0) break;
492
+ if (!strict && cmp < 0) break;
493
+ }
494
+ if (at >= entries.length) {
495
+ if (strict) throw new GitApiError(`fatal: No such path '${to}' in the diff`);
496
+ return entries;
497
+ }
498
+ return skip ? entries.slice(at) : [...entries.slice(at), ...entries.slice(0, at)];
499
+ }
500
+
501
+ /** strip_prefix: the path without `prefix` and the `/` after it */
502
+ function stripPrefix(path: string, prefix: string): string {
503
+ const rest = path.slice(prefix.length);
504
+ return rest.startsWith("/") ? rest.slice(1) : rest;
191
505
  }
192
506
 
193
507
  /** An entry with its two sides swapped (`diff -R`). */
@@ -209,6 +523,7 @@ function reverseEntry(entry: DiffEntry): DiffEntry {
209
523
  if (entry.readNew) out.readOld = entry.readNew;
210
524
  if (entry.readOld) out.readNew = entry.readOld;
211
525
  if (entry.score !== undefined) out.score = entry.score;
526
+ if (entry.lineRanges) out.lineRanges = entry.lineRanges;
212
527
  return out;
213
528
  }
214
529
 
@@ -244,6 +559,17 @@ interface Side {
244
559
  unknownId?: boolean;
245
560
  }
246
561
 
562
+ /** diffcore's settings of one run (see `DiffCommand.diffcoreSettings`) */
563
+ interface DiffcoreSettings {
564
+ detect: false | "renames" | "copies";
565
+ /** The rename/copy threshold (git's `rename_score`), default 50% */
566
+ score?: number;
567
+ /** `--find-copies-harder` */
568
+ harder: boolean;
569
+ /** `-B` */
570
+ breaks?: BreakScores;
571
+ }
572
+
247
573
  /** An index entry, of any stage */
248
574
  type StageEntry = Parameters<typeof compareWithWorktree>[1];
249
575
 
@@ -304,8 +630,12 @@ function abbrevOption(value: number | undefined): number | undefined {
304
630
  return Math.min(40, Math.max(4, Math.trunc(value)));
305
631
  }
306
632
 
307
- /** `diff.renames` as git_config_rename reads it: `copies`/`copy` detect copies too. */
308
- function renamesValue(value: string | undefined): boolean | "copies" | undefined {
633
+ /**
634
+ * `diff.renames` as git_config_rename reads it: `copies`/`copy` detect copies too.
635
+ *
636
+ * @internal
637
+ */
638
+ export function renamesValue(value: string | undefined): boolean | "copies" | undefined {
309
639
  if (value === undefined) return undefined;
310
640
  const v = value.trim().toLowerCase();
311
641
  if (v === "copies" || v === "copy") return "copies";
@@ -382,6 +712,20 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
382
712
  private dirtySubmodules?: boolean;
383
713
  /** `diff.submodule` (its last value git knows), read by the text outputs */
384
714
  private configuredSubmoduleFormat?: SubmoduleDiffFormat;
715
+ /** The colors of the output, read with the diff configuration (or given by `git log`) */
716
+ private colorSettings?: DiffColorSettings;
717
+
718
+ /**
719
+ * The colors already read (`readDiffColorSettings`): `git log` reads them once for all its
720
+ * commits' diffs
721
+ *
722
+ * @internal
723
+ */
724
+ setColorSettings(settings: DiffColorSettings): this {
725
+ this.checkCallable();
726
+ this.colorSettings = settings;
727
+ return this;
728
+ }
385
729
  private readonly configWarnings: string[] = [];
386
730
  /** {@link dirtySubmodules} for the comparison being collected */
387
731
  private dirtyThisCall = true;
@@ -398,10 +742,106 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
398
742
  private temporaryIndex?: Staging;
399
743
  /** Intent-to-add entries are in the index as empty files (plumbing's `diff-index --cached`) */
400
744
  private intentToAddVisible = false;
745
+ /** The index stands for a tree (see {@link setIndexAsTree}) */
746
+ private indexAsTree = false;
747
+ /** `--exit-code` */
748
+ private exitWithStatus = false;
749
+ /** `--quiet` */
750
+ private quiet = false;
751
+ /** `--merge-base` */
752
+ private mergeBase = false;
753
+ /** Whether `--rotate-to`/`--skip-to` need their exact path (`git diff`; not `git log`) */
754
+ private rotateStrict = true;
755
+ /** git's `has_changes` of the last call */
756
+ private changesFound = false;
757
+ /** git's `check_failed`: `--check` found an error in the last call */
758
+ private checkFailed = false;
759
+ /** The revisions given resolved (ranges, `--merge-base`) */
760
+ private sidesResolved = false;
761
+ /** The compiled pickaxe (`-S`, `-G`, `--find-object`), once the options are checked */
762
+ private pickaxe?: DiffPickaxe;
763
+ /**
764
+ * `--find-object`'s `tree_in_recursive`: the subtrees of a diff of two trees, by the side
765
+ * map their blobs go to
766
+ */
767
+ private treeSides?: Map<Map<string, Side>, Map<string, Side>>;
768
+
769
+ /**
770
+ * `--exit-code`: {@link exitCode} is 1 when the diff found differences, as git's status
771
+ * (`diff_result_code`). With whitespace options or `-I`, only pairs whose patch shows a
772
+ * change count (git's `diff_from_contents`).
773
+ */
774
+ setExitCode(exitCode: boolean): this {
775
+ this.checkCallable();
776
+ this.exitWithStatus = exitCode;
777
+ return this;
778
+ }
779
+
780
+ /**
781
+ * `--quiet`: {@link callText} and {@link callBytes} print nothing and {@link exitCode} is
782
+ * 1 when anything differs (`--exit-code`). As git's `quick` flag, the diff stops at its
783
+ * first difference: no rename detection (git 2.5x; see
784
+ * {@link DiffTextOptions.quietDetectsRenames}), no content read past the first pair that
785
+ * shows a change.
786
+ */
787
+ setQuiet(quiet: boolean): this {
788
+ this.checkCallable();
789
+ this.quiet = quiet;
790
+ return this;
791
+ }
792
+
793
+ /**
794
+ * `--merge-base`: diff from the merge base of the old tree and the new one (`git diff
795
+ * --merge-base A B`), or of the old tree and HEAD against the index (`--cached`) or the
796
+ * worktree (`git diff --merge-base A`). Both must be commits with exactly one merge base,
797
+ * else git's `fatal: no merge base found` / `fatal: multiple merge bases found`; a range
798
+ * throws `fatal: --merge-base does not work with ranges`.
799
+ */
800
+ setMergeBase(mergeBase: boolean): this {
801
+ this.checkCallable();
802
+ this.mergeBase = mergeBase;
803
+ return this;
804
+ }
805
+
806
+ /**
807
+ * `--rotate-to`/`--skip-to` take the first path after a missing one, as `git log` does,
808
+ * instead of failing as `git diff` does.
809
+ *
810
+ * @internal
811
+ */
812
+ setRotateStrict(strict: boolean): this {
813
+ this.checkCallable();
814
+ this.rotateStrict = strict;
815
+ return this;
816
+ }
817
+
818
+ /**
819
+ * The exit status `git diff` ends with (`diff_result_code`): bit 1 when `--exit-code` or
820
+ * `--quiet` is set and the last call found differences, bit 2 when its `--check` (the
821
+ * `check` format) found errors.
822
+ */
823
+ get exitCode(): number {
824
+ return (
825
+ ((this.exitWithStatus || this.quiet) && this.changesFound ? 1 : 0) |
826
+ (this.checkFailed ? 2 : 0)
827
+ );
828
+ }
829
+
830
+ /** Whether the last call's `--check` found errors (git's `check_failed`) */
831
+ get checkFoundErrors(): boolean {
832
+ return this.checkFailed;
833
+ }
834
+
835
+ /** Whether the last call found differences (git's `has_changes`) */
836
+ get hasChanges(): boolean {
837
+ return this.changesFound;
838
+ }
401
839
 
402
840
  /**
403
- * Show intent-to-add entries in a `--cached` comparison as the empty files they name, as
404
- * plumbing's `diff-index --cached` does (porcelain `git diff` sets `ita_invisible_in_index`).
841
+ * Show intent-to-add entries as the empty files they name, as plumbing's
842
+ * `diff-index --cached` and `diff-files` do (porcelain `git diff` sets
843
+ * `ita_invisible_in_index`): in a `--cached` comparison on the index side, against the
844
+ * worktree as the old side (`git add -e`'s diff).
405
845
  *
406
846
  * @internal
407
847
  */
@@ -415,9 +855,11 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
415
855
  * Set the old (base) tree/commit for comparison.
416
856
  *
417
857
  * Can be a commit ID, branch name, tag name, or tree ID.
418
- * If not set, defaults to HEAD (or the index, for the worktree diff).
858
+ * If not set, defaults to HEAD (or the index, for the worktree diff). Without a new tree, a
859
+ * range compares two commits as `git diff` does: `A..B` is `A B`, `A...B` diffs B from the
860
+ * merge base of A and B (an empty side is HEAD).
419
861
  *
420
- * @param refOrId Commit-ish or tree ID
862
+ * @param refOrId Commit-ish or tree ID, or a range
421
863
  */
422
864
  setOldTree(refOrId: string): this {
423
865
  this.checkCallable();
@@ -507,10 +949,95 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
507
949
  * `diff.submodule`, its warnings, and the failure of a variable without a value.
508
950
  */
509
951
  private readUiConfig(): void {
952
+ this.colorSettings ??= readDiffColorSettings(
953
+ this.workingCopy,
954
+ this.textOptions,
955
+ this.textOptions.uiConfig !== false,
956
+ );
510
957
  if (this.textOptions.uiConfig === false) return;
511
958
  const { format, warnings } = readDiffSubmoduleConfig(this.workingCopy);
512
959
  this.configuredSubmoduleFormat = format;
513
960
  this.configWarnings.splice(0, this.configWarnings.length, ...warnings);
961
+ // git_diff_ui_config: a diff.dirstat with errors is warned about, the rest applied
962
+ const dirstat = this.config.value("diff.dirstat");
963
+ this.configuredDirstat = { ...DEFAULT_DIRSTAT };
964
+ if (dirstat !== undefined) {
965
+ const errors = parseDirstatParams(dirstat, this.configuredDirstat);
966
+ if (errors.length > 0) {
967
+ this.configWarnings.push(
968
+ `warning: Found errors in 'diff.dirstat' config variable:\n${errors.join("\n")}\n`,
969
+ );
970
+ }
971
+ }
972
+ }
973
+
974
+ /** `diff.dirstat`'s parameters (git's defaults without it) */
975
+ private configuredDirstat?: DirstatParams;
976
+
977
+ /** The dirstat's parameters: `diff.dirstat`, then {@link DiffTextOptions.dirstat} */
978
+ private dirstatParams(): DirstatParams {
979
+ const params = { ...(this.configuredDirstat ?? DEFAULT_DIRSTAT) };
980
+ const text = this.textOptions.dirstat;
981
+ if (text !== undefined) {
982
+ const errors = parseDirstatParams(text, params);
983
+ if (errors.length > 0) {
984
+ throw new GitApiError(
985
+ `fatal: Failed to parse --dirstat/-X option parameter:\n${errors.join("\n")}\n`,
986
+ ).withExitCode(128);
987
+ }
988
+ }
989
+ return params;
990
+ }
991
+
992
+ /** show_dirstat (or show_dirstat_by_line): the dirstat of the pairs */
993
+ private async writeDirstat(
994
+ sink: ByteSink,
995
+ pairs: DiffFilePair[],
996
+ unmerged: Set<DiffFilePair>,
997
+ options: DiffOutputOptions,
998
+ params: DirstatParams,
999
+ ): Promise<void> {
1000
+ const files: DirstatFile[] = [];
1001
+ if (params.byLine) {
1002
+ for (const pair of pairs) {
1003
+ if (unmerged.has(pair)) {
1004
+ files.push({ name: pair.new?.path ?? pair.old?.path ?? "", changed: 0 });
1005
+ continue;
1006
+ }
1007
+ for (const f of await computeDiffstat([pair], options)) {
1008
+ const damage = f.added + f.deleted;
1009
+ // binary files count bytes: 64 of them a line
1010
+ files.push({ name: f.name, changed: f.isBinary ? Math.ceil(damage / 64) : damage });
1011
+ }
1012
+ }
1013
+ } else {
1014
+ const countLastSpan = this.textOptions.renameCountLastSpan;
1015
+ for (const pair of pairs) {
1016
+ if (unmerged.has(pair)) continue;
1017
+ const { old: one, new: two } = pair;
1018
+ const name = two?.path ?? one?.path ?? "";
1019
+ let damage: number;
1020
+ if (one && two && one.idValid !== false && two.idValid !== false && one.id === two.id) {
1021
+ damage = 0;
1022
+ } else if (params.byFile) damage = 1;
1023
+ else {
1024
+ if (one && two) {
1025
+ const a = await one.read();
1026
+ const b = await two.read();
1027
+ const { copied, added } = countChanges(
1028
+ spanCounts(a, { countLastSpan }),
1029
+ spanCounts(b, { countLastSpan }),
1030
+ );
1031
+ damage = a.length - copied + added;
1032
+ } else if (one) damage = (await one.read()).length;
1033
+ else if (two) damage = (await two.read()).length;
1034
+ else continue;
1035
+ if (!damage) damage = 1;
1036
+ }
1037
+ files.push({ name, changed: damage });
1038
+ }
1039
+ }
1040
+ sink.text(formatDirstat(files, params));
514
1041
  }
515
1042
 
516
1043
  /**
@@ -540,6 +1067,21 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
540
1067
  return this.temporaryIndex ?? super.staging;
541
1068
  }
542
1069
 
1070
+ /**
1071
+ * Compares the old tree with `index` taken as a tree, as git's `do_diff_cache` of an index
1072
+ * built in memory (`stash show -u`'s worktree and untracked trees): `--cached` against
1073
+ * it, with the prefixes of two trees (no mnemonic `c/` and `i/`).
1074
+ *
1075
+ * @internal
1076
+ */
1077
+ setIndexAsTree(index: Staging): this {
1078
+ this.checkCallable();
1079
+ this.temporaryIndex = index;
1080
+ this.cached = true;
1081
+ this.indexAsTree = true;
1082
+ return this;
1083
+ }
1084
+
543
1085
  /**
544
1086
  * Filter results to only paths starting with this prefix.
545
1087
  *
@@ -564,6 +1106,44 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
564
1106
  return this;
565
1107
  }
566
1108
 
1109
+ /**
1110
+ * The queue {@link callFormats} prints instead of comparing the trees: pairs a caller found
1111
+ * itself (`git log -L` queues each commit's pairs with their line ranges, line-log.c's
1112
+ * `line_log_queue_pairs`). diffcore's later stages (pickaxe, order, `--diff-filter`) still
1113
+ * apply.
1114
+ *
1115
+ * @internal
1116
+ */
1117
+ setQueue(entries: DiffEntry[]): this {
1118
+ this.checkCallable();
1119
+ this.presetQueue = entries;
1120
+ return this;
1121
+ }
1122
+
1123
+ private presetQueue?: DiffEntry[];
1124
+
1125
+ /**
1126
+ * diffcore's filtering stages over a queue a caller found (the pickaxe, `-O`,
1127
+ * `--diff-filter`): git 2.43's `git log -L` runs them on the pairs it follows renames with
1128
+ *
1129
+ * @internal
1130
+ */
1131
+ async filterQueue(entries: DiffEntry[]): Promise<DiffEntry[]> {
1132
+ await this.preparePickaxe();
1133
+ return this.selected(entries);
1134
+ }
1135
+
1136
+ /**
1137
+ * The diff driver of a path as a diff of two trees finds it (the worktree's attributes,
1138
+ * `diff.<driver>.*`, the builtin drivers): `git log -L :<funcname>:<file>` finds functions
1139
+ * by its funcname pattern (line-range.c's `userdiff_find_by_path`)
1140
+ *
1141
+ * @internal
1142
+ */
1143
+ async driverOf(path: string): Promise<DiffDriver | undefined> {
1144
+ return this.outputOptions().driver?.(path);
1145
+ }
1146
+
567
1147
  /**
568
1148
  * Detect renames (`-M`, `--no-renames`). Default: off for `call()` (each path as added and
569
1149
  * deleted), `diff.renames` (default on) for `callText()`.
@@ -586,6 +1166,52 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
586
1166
  return true;
587
1167
  }
588
1168
 
1169
+ /** diff.c's `additional_path_headers` (see {@link setAdditionalHeaders}) */
1170
+ private additionalHeaders?: Map<string, readonly string[]>;
1171
+
1172
+ /**
1173
+ * diff.c's `additional_path_headers` (`--remerge-diff`'s `remerge CONFLICT` lines), by path:
1174
+ * the paths within the pathspec keep theirs (log-tree.c's setup_additional_headers). A
1175
+ * pair's headers follow its rename lines; a path with headers and no change is shown as a
1176
+ * `diff --git` line with its headers alone, unless a pickaxe or a `--diff-filter` without
1177
+ * `U` is given (`include_conflict_headers`).
1178
+ */
1179
+ setAdditionalHeaders(headers: ReadonlyMap<string, readonly string[]>): this {
1180
+ this.checkCallable();
1181
+ this.additionalHeaders = new Map(headers);
1182
+ return this;
1183
+ }
1184
+
1185
+ /** The additional headers within the pathspec, undefined for none */
1186
+ private headersInPathspec(): Map<string, readonly string[]> | undefined {
1187
+ const all = this.additionalHeaders;
1188
+ if (!all || all.size === 0) return undefined;
1189
+ if (!this.pathspecItems) return all;
1190
+ const out = new Map<string, readonly string[]>();
1191
+ for (const [path, headers] of all) {
1192
+ if (matchPathspec(this.pathspecItems, path, 0) > 0) out.set(path, headers);
1193
+ }
1194
+ return out.size > 0 ? out : undefined;
1195
+ }
1196
+
1197
+ /**
1198
+ * diff.c's `include_conflict_headers`: headers present, no pickaxe, and no `--diff-filter`
1199
+ * or one that keeps `U`
1200
+ */
1201
+ private includesConflictHeaders(headers: Map<string, readonly string[]> | undefined): boolean {
1202
+ if (!headers || hasPickaxe(this.textOptions)) return false;
1203
+ const filter = this.textOptions.diffFilter;
1204
+ if (filter === undefined) return true;
1205
+ // diff_opt_diff_filter: a lowercase letter starts from every status, each letter then
1206
+ // adds (uppercase) or removes (lowercase) its own
1207
+ let keepsU = /[a-z]/.test(filter);
1208
+ for (const c of filter) {
1209
+ if (c === "U") keepsU = true;
1210
+ else if (c === "u") keepsU = false;
1211
+ }
1212
+ return keepsU;
1213
+ }
1214
+
589
1215
  /** Text output options: context, algorithm, whitespace, `--stat` widths, ... */
590
1216
  setOptions(options: DiffTextOptions): this {
591
1217
  this.checkCallable();
@@ -602,7 +1228,16 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
602
1228
  this.checkCallable();
603
1229
  this.setCallable(false);
604
1230
  this.dirtyThisCall = this.dirtySubmodules ?? true;
605
- return (await this.collect(this.renames ?? false)).entries;
1231
+ const run = async () => {
1232
+ const { entries } = await this.collect(this.renames ?? false, false, this.pickaxeReads);
1233
+ // diffcore_pickaxe, diffcore_apply_filter (the entries stay in path order, unswapped)
1234
+ const picked = await this.picked(entries);
1235
+ const filter = this.textOptions.diffFilter;
1236
+ return applyDiffFilter(picked, filter !== undefined ? parseDiffFilter(filter) : undefined);
1237
+ };
1238
+ const out = hasPickaxe(this.textOptions) ? await this.inOneOperation(run) : await run();
1239
+ this.changesFound = out.length > 0;
1240
+ return out;
606
1241
  }
607
1242
 
608
1243
  /**
@@ -624,13 +1259,17 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
624
1259
  this.setCallable(false);
625
1260
  const config = this.config;
626
1261
  const renames = this.renames ?? renamesValue(config.value("diff.renames")) ?? true;
627
- this.dirtyThisCall = this.dirtySubmodules ?? format === "patch";
1262
+ this.dirtyThisCall = this.dirtySubmodules ?? (format === "patch" && !this.quiet);
628
1263
  this.readUiConfig();
629
1264
  return this.inOneOperation(async () => {
1265
+ if (this.quiet) {
1266
+ await this.quietCheck(renames);
1267
+ return new Uint8Array(0);
1268
+ }
630
1269
  const collected = await this.collect(
631
1270
  renames,
632
1271
  format === "patch",
633
- PREFETCH_FORMATS.has(format),
1272
+ PREFETCH_FORMATS.has(format) || this.pickaxeReads,
634
1273
  );
635
1274
  const sink = new ByteSink();
636
1275
  await this.writeFormats(sink, [format], collected);
@@ -638,6 +1277,46 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
638
1277
  });
639
1278
  }
640
1279
 
1280
+ /**
1281
+ * `--quiet` (git's `quick` flag, `DIFF_FORMAT_NO_OUTPUT`): whether anything differs, stopping
1282
+ * early. Without `--diff-filter` and content options the first queued pair answers
1283
+ * (diff_can_quit_early): no renames are detected and no content is read; with content
1284
+ * options (`-w`, `-I`, ...) pairs are diffed until one shows a change (diff_flush's
1285
+ * `diff_flush_patch_quietly` loop).
1286
+ */
1287
+ private async quietCheck(renames: boolean | "copies"): Promise<void> {
1288
+ const fromContents = this.fromContents;
1289
+ const early = this.textOptions.diffFilter === undefined && !fromContents;
1290
+ const detect = !early && (this.textOptions.quietDetectsRenames ?? false);
1291
+ const collected = await this.collect(
1292
+ detect ? renames : false,
1293
+ false,
1294
+ this.pickaxeReads,
1295
+ !early,
1296
+ );
1297
+ // diff_can_quit_early: the walk stopped at the first change, which a pickaxe (git 2.43,
1298
+ // whose quiet diff does not look at contents) may then drop
1299
+ const queue = early && this.pickaxe ? collected.entries.slice(0, 1) : collected.entries;
1300
+ const entries = await this.selected(queue);
1301
+ this.changesFound = entries.length > 0;
1302
+ if (!fromContents || entries.length === 0) return;
1303
+ this.changesFound = false;
1304
+ const options = this.outputOptions();
1305
+ Object.assign(options, this.prefixes());
1306
+ for (const entry of entries) {
1307
+ if (entry.unmerged) {
1308
+ this.changesFound = true;
1309
+ break;
1310
+ }
1311
+ const scratch = new ByteSink();
1312
+ await writePairPatch(scratch, diffEntryToPair(entry, this.blobs), options);
1313
+ if (scratch.length > 0) {
1314
+ this.changesFound = true;
1315
+ break;
1316
+ }
1317
+ }
1318
+ }
1319
+
641
1320
  /**
642
1321
  * The diffstat of the comparison, one file per pair in git's order (`compute_diffstat` of
643
1322
  * the diff queue, as a `DIFF_FORMAT_CALLBACK` consumer sees it): an unmerged path as a
@@ -702,10 +1381,13 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
702
1381
  let followPath = follow;
703
1382
  let followChange: ChangeType.RENAME | ChangeType.COPY | undefined;
704
1383
  let collected: { entries: DiffEntry[]; combined: CombinedEntry[] };
705
- if (follow !== undefined) {
1384
+ if (this.presetQueue) {
1385
+ await this.preparePickaxe();
1386
+ collected = { entries: this.presetQueue, combined: [] };
1387
+ } else if (follow !== undefined) {
706
1388
  const spec = this.pathspecItems;
707
1389
  this.pathspecItems = [parsePathspecItem(`:(literal)${follow}`)];
708
- collected = await this.collect(false, false);
1390
+ collected = await this.collect(false, false, false, false);
709
1391
  const only = collected.entries[0];
710
1392
  if (collected.entries.length === 1 && only?.changeType === ChangeType.ADD) {
711
1393
  this.pathspecItems = spec;
@@ -720,16 +1402,22 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
720
1402
  collected = await this.collect(
721
1403
  renames,
722
1404
  formats.includes("patch"),
723
- formats.some((f) => PREFETCH_FORMATS.has(f)),
1405
+ formats.some((f) => PREFETCH_FORMATS.has(f)) || this.pickaxeReads,
724
1406
  );
725
1407
  }
726
1408
  const followed = {
727
1409
  ...(followPath !== undefined ? { followPath } : {}),
728
1410
  ...(followChange !== undefined ? { followChange } : {}),
729
1411
  };
730
- if (collected.entries.length === 0 && collected.combined.length === 0) return followed;
1412
+ // diff_queue_is_empty: headers to include count as a change
1413
+ const headers = this.headersInPathspec();
1414
+ const withHeaders = this.includesConflictHeaders(headers);
1415
+ if (collected.entries.length === 0 && collected.combined.length === 0 && !withHeaders)
1416
+ return followed;
731
1417
  const sink = new ByteSink();
732
- await this.writeFormats(sink, formats, collected);
1418
+ const queued = await this.writeFormats(sink, formats, collected, headers);
1419
+ // diffcore_std left nothing (`--diff-filter`, `--skip-to`): no diff, as an empty one
1420
+ if (queued === 0 && collected.combined.length === 0 && !withHeaders) return followed;
733
1421
  return { bytes: sink.bytes(), ...followed };
734
1422
  });
735
1423
  }
@@ -783,11 +1471,14 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
783
1471
  sink: ByteSink,
784
1472
  formats: DiffOutputFormat[],
785
1473
  collected: { entries: DiffEntry[]; combined: CombinedEntry[] },
786
- ): Promise<void> {
1474
+ headers?: Map<string, readonly string[]>,
1475
+ ): Promise<number> {
787
1476
  const config = this.config;
788
1477
  const { combined } = collected;
789
- const ordered = await this.ordered(collected.entries);
790
- const entries = this.textOptions.reverse ? ordered.map(reverseEntry) : ordered;
1478
+ const entries = await this.selected(collected.entries);
1479
+ // diffcore_std's has_changes; with diff_from_contents, what the outputs show (below)
1480
+ const fromContents = this.fromContents;
1481
+ this.changesFound = !fromContents && entries.length > 0;
791
1482
  const options = this.outputOptions();
792
1483
  Object.assign(options, this.prefixes());
793
1484
  if (this.textOptions.reverse) {
@@ -799,6 +1490,9 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
799
1490
  }
800
1491
  const pairs: DiffFilePair[] = [];
801
1492
  const unmerged = new Set<DiffFilePair>();
1493
+ /** The pairs with their full paths, for what git does not shorten (`--summary`) */
1494
+ const fullPairs = new Map<DiffFilePair, DiffFilePair>();
1495
+ const prefix = this.relativePrefix;
802
1496
  for (const entry of entries) {
803
1497
  // an unmerged path: only its name is printed
804
1498
  const pair: DiffFilePair = entry.unmerged
@@ -812,9 +1506,36 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
812
1506
  ),
813
1507
  }
814
1508
  : this.withTextconvInputs(diffEntryToPair(entry, this.blobs), entry);
815
- if (entry.unmerged) unmerged.add(pair);
816
- pairs.push(pair);
1509
+ // strip_prefix: names without the `--relative` prefix, attributes by the full path
1510
+ const shown: DiffFilePair =
1511
+ prefix === undefined
1512
+ ? pair
1513
+ : {
1514
+ ...pair,
1515
+ ...(pair.old
1516
+ ? {
1517
+ old: {
1518
+ ...pair.old,
1519
+ path: stripPrefix(pair.old.path, prefix),
1520
+ attrPath: pair.old.path,
1521
+ },
1522
+ }
1523
+ : {}),
1524
+ ...(pair.new
1525
+ ? {
1526
+ new: {
1527
+ ...pair.new,
1528
+ path: stripPrefix(pair.new.path, prefix),
1529
+ attrPath: pair.new.path,
1530
+ },
1531
+ }
1532
+ : {}),
1533
+ };
1534
+ fullPairs.set(shown, pair);
1535
+ if (entry.unmerged) unmerged.add(shown);
1536
+ pairs.push(shown);
817
1537
  }
1538
+ const full = (pair: DiffFilePair) => fullPairs.get(pair) ?? pair;
818
1539
  const quote = options.quotePath;
819
1540
  const order: DiffOutputFormat[] = [
820
1541
  "name-only",
@@ -822,6 +1543,7 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
822
1543
  "numstat",
823
1544
  "stat",
824
1545
  "shortstat",
1546
+ "dirstat",
825
1547
  "summary",
826
1548
  "patch",
827
1549
  ];
@@ -840,24 +1562,54 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
840
1562
  }
841
1563
  for (const c of combined) await this.writeCombined(sink, c, options, combinedLengths);
842
1564
  }
843
- // diff_flush of an empty queue prints nothing
844
- if (pairs.length === 0) return;
1565
+ // diff_flush of an empty queue prints nothing (unless headers are to be shown)
1566
+ if (pairs.length === 0 && !headers) return 0;
1567
+ if (headers) options.additionalHeaders = (name) => headers.get(name);
1568
+ // diff_setup_done: --check turns the other formats off
1569
+ if (formats.includes("check")) {
1570
+ const check = { conflictMarkerSize: this.conflictMarkerSizeOf() };
1571
+ for (const pair of pairs) {
1572
+ if (unmerged.has(pair)) continue;
1573
+ if (fromContents && this.namesFromContents) {
1574
+ // diff_flush_patch_quietly (git 2.50+): the changes are what the patch shows, and
1575
+ // a pair whose patch shows nothing is not checked
1576
+ const scratch = new ByteSink();
1577
+ await writePairPatch(scratch, pair, options);
1578
+ if (scratch.length === 0) continue;
1579
+ this.changesFound = true;
1580
+ } else if (fromContents) {
1581
+ // git 2.43 checks every pair, and each one checked counts as a change
1582
+ this.changesFound = true;
1583
+ }
1584
+ if (await writePairCheck(sink, pair, options, check)) this.checkFailed = true;
1585
+ }
1586
+ return pairs.length;
1587
+ }
845
1588
  let separator = false;
846
1589
  for (const format of order) {
847
1590
  if (!formats.includes(format)) continue;
848
- if (format === "patch" && separator) sink.text("\n");
1591
+ if (format === "patch" && separator) {
1592
+ sink.text("\n");
1593
+ // attach the patch instead of inlining it
1594
+ if (this.textOptions.statSep) sink.text(this.textOptions.statSep);
1595
+ }
849
1596
  // diff_flush: an empty summary (is_summary_empty) prints nothing and asks no separator
850
1597
  if (format === "summary") {
851
- const text = formatSummary(
852
- pairs.filter((p) => !unmerged.has(p)),
853
- quote,
854
- );
1598
+ // diff_summary names the paths in full, whatever `--relative` says
1599
+ const text = formatSummary(pairs.filter((p) => !unmerged.has(p)).map(full), quote);
855
1600
  if (text) {
856
1601
  sink.text(text);
857
1602
  separator = true;
858
1603
  }
859
1604
  continue;
860
1605
  }
1606
+ if (format === "dirstat") {
1607
+ const params = this.dirstatParams();
1608
+ await this.writeDirstat(sink, pairs, unmerged, options, params);
1609
+ // only the dirstat by lines comes with the diffstat's separator
1610
+ if (params.byLine) separator = true;
1611
+ continue;
1612
+ }
861
1613
  separator = true;
862
1614
  switch (format) {
863
1615
  case "patch": {
@@ -878,30 +1630,53 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
878
1630
  // `--abbrev=<n>`: at least n digits
879
1631
  options.abbrevLengths = await this.idAbbreviator().lengths(ids, options.abbrev);
880
1632
  }
881
- for (const pair of pairs) {
882
- if (unmerged.has(pair)) {
883
- sink.text(`* Unmerged path ${pair.new?.path ?? pair.old?.path}\n`);
884
- } else await writePairPatch(sink, pair, options);
1633
+ // diff_flush_patch_all_file_pairs: moved lines are looked for over every pair
1634
+ const moved = this.colorSettings;
1635
+ const out =
1636
+ moved?.colors && moved.colorMoved !== "no"
1637
+ ? new MovedLineBuffer(moved.colorMoved, moved.colorMovedWs)
1638
+ : sink;
1639
+ for (const pair of this.withHeaderOnlyPairs(pairs, full, headers)) {
1640
+ const before = out.length;
1641
+ if (typeof pair === "string") {
1642
+ if (this.includesConflictHeaders(headers)) {
1643
+ writeHeaderOnlyPatch(out, pair, headers?.get(pair) ?? [], options);
1644
+ }
1645
+ } else if (unmerged.has(pair)) {
1646
+ out.text(`* Unmerged path ${pair.new?.path ?? pair.old?.path}\n`);
1647
+ } else await writePairPatch(out, pair, options);
1648
+ // builtin_diff's found_changes: the pair showed something
1649
+ if (out.length > before) this.changesFound = true;
1650
+ }
1651
+ if (out instanceof MovedLineBuffer && moved?.colors) {
1652
+ out.flushTo(sink, { colors: moved.colors, wsErrorHighlight: moved.wsErrorHighlight });
885
1653
  }
886
1654
  break;
887
1655
  }
888
- case "name-only":
889
- sink.text(
890
- formatNameOnly(await this.shownNames(pairs, unmerged, options), { quotePath: quote }),
891
- );
1656
+ case "name-only": {
1657
+ const names = await this.shownNames(pairs, unmerged, options);
1658
+ // flush_one_pair: found_changes for each name listed
1659
+ if (names.length > 0) this.changesFound = true;
1660
+ sink.text(formatNameOnly(names, { quotePath: quote }));
892
1661
  break;
893
- case "name-status":
894
- for (const pair of await this.shownNames(pairs, unmerged, options)) {
1662
+ }
1663
+ case "name-status": {
1664
+ const names = await this.shownNames(pairs, unmerged, options);
1665
+ // flush_one_pair: found_changes for each name listed
1666
+ if (names.length > 0) this.changesFound = true;
1667
+ for (const pair of names) {
895
1668
  if (unmerged.has(pair)) {
896
1669
  sink.text(`U\t${quotePath(pair.new?.path ?? pair.old?.path ?? "", quote)}\n`);
897
1670
  } else sink.text(formatNameStatus([pair], { quotePath: quote }));
898
1671
  }
899
1672
  break;
1673
+ }
900
1674
  default: {
901
1675
  const files = [];
902
1676
  for (const pair of pairs) {
903
1677
  if (unmerged.has(pair)) {
904
- const name = pair.new?.path ?? pair.old?.path ?? "";
1678
+ // builtin_diffstat of an unmerged pair: its full path
1679
+ const name = full(pair).new?.path ?? full(pair).old?.path ?? "";
905
1680
  files.push({
906
1681
  name,
907
1682
  isRenamed: false,
@@ -912,11 +1687,14 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
912
1687
  });
913
1688
  } else files.push(...(await computeDiffstat([pair], options)));
914
1689
  }
1690
+ // compute_diffstat: found_changes when the diffstat lists a file
1691
+ if (files.length > 0) this.changesFound = true;
915
1692
  const statOptions: DiffstatOptions = {
916
1693
  nameWidth: intValue(config.value("diff.statNameWidth")),
917
1694
  graphWidth: intValue(config.value("diff.statGraphWidth")),
918
1695
  ...this.textOptions.stat,
919
1696
  quotePath: quote,
1697
+ ...(this.colorSettings?.colors ? { colors: this.colorSettings.colors } : {}),
920
1698
  };
921
1699
  if (format === "stat") sink.text(formatStat(files, statOptions));
922
1700
  else if (format === "numstat") sink.text(formatNumstat(files, { quotePath: quote }));
@@ -924,6 +1702,33 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
924
1702
  }
925
1703
  }
926
1704
  }
1705
+ return pairs.length;
1706
+ }
1707
+
1708
+ /**
1709
+ * create_filepairs_for_header_only_notifications: the pairs, and the paths with headers
1710
+ * none of them names first (as strings), sorted by first name (diffcore_fix_diff_index)
1711
+ */
1712
+ private withHeaderOnlyPairs(
1713
+ pairs: DiffFilePair[],
1714
+ full: (pair: DiffFilePair) => DiffFilePair,
1715
+ headers: Map<string, readonly string[]> | undefined,
1716
+ ): (DiffFilePair | string)[] {
1717
+ if (!headers) return pairs;
1718
+ const nameOf = (pair: DiffFilePair) => {
1719
+ const f = full(pair);
1720
+ return f.old?.path ?? f.new?.path ?? "";
1721
+ };
1722
+ const present = new Set(pairs.map(nameOf));
1723
+ const out: { name: string; item: DiffFilePair | string }[] = pairs.map((pair) => ({
1724
+ name: nameOf(pair),
1725
+ item: pair,
1726
+ }));
1727
+ for (const path of headers.keys()) {
1728
+ if (!present.has(path)) out.push({ name: path, item: path });
1729
+ }
1730
+ out.sort((a, b) => compareBytes(a.name, b.name));
1731
+ return out.map((e) => e.item);
927
1732
  }
928
1733
 
929
1734
  /**
@@ -937,7 +1742,8 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
937
1742
  options: DiffOutputOptions,
938
1743
  format: SubmoduleDiffFormat,
939
1744
  ): Promise<void> {
940
- const path = pair.old?.path ?? pair.new?.path ?? "";
1745
+ // `one->path`: the full path, whatever `--relative` shows
1746
+ const path = pair.old?.attrPath ?? pair.old?.path ?? pair.new?.attrPath ?? pair.new?.path ?? "";
941
1747
  const one = pair.old?.id ?? this.objectFormat.nullId;
942
1748
  const two = pair.new?.id ?? this.objectFormat.nullId;
943
1749
  const dirt = pair.new?.submoduleDirt;
@@ -945,7 +1751,27 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
945
1751
  const abbreviate = (id: ObjectId) => this.idAbbreviator().abbreviate(id);
946
1752
  const workingCopy = this.workingCopy;
947
1753
  if (format === "log") {
948
- sink.text(await showSubmoduleDiffSummary({ workingCopy, path, one, two, dirt, abbreviate }));
1754
+ const text = await showSubmoduleDiffSummary({
1755
+ workingCopy,
1756
+ path,
1757
+ one,
1758
+ two,
1759
+ dirt,
1760
+ abbreviate,
1761
+ });
1762
+ const c = options.colors;
1763
+ if (!c) {
1764
+ sink.text(text);
1765
+ return;
1766
+ }
1767
+ // print_submodule_diff_summary: each commit as diff_emit_submodule_del/_add
1768
+ const lines = text.split("\n");
1769
+ lines.pop();
1770
+ lines.forEach((line, i) => {
1771
+ const kind = i > 0 ? /^ {2}([<>]) /.exec(line)?.[1] : undefined;
1772
+ if (kind) sink.text(`${kind === "<" ? c.old : c.new}${line}${c.reset}\n`);
1773
+ else sink.text(`${line}\n`);
1774
+ });
949
1775
  return;
950
1776
  }
951
1777
  const sub = await openSubmoduleRepository(workingCopy, path);
@@ -969,6 +1795,8 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
969
1795
  .setOldTree(header.left ? one : this.objectFormat.emptyTreeId)
970
1796
  .setSubmoduleFormat("diff")
971
1797
  .setOptions({
1798
+ // the child `git diff --color=always|never` reads the submodule's own color slots
1799
+ color: options.colors !== undefined,
972
1800
  srcPrefix: `${options.srcPrefix ?? "a/"}${path}/`,
973
1801
  dstPrefix: `${options.dstPrefix ?? "b/"}${path}/`,
974
1802
  });
@@ -1063,6 +1891,44 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
1063
1891
  };
1064
1892
  }
1065
1893
 
1894
+ /**
1895
+ * diff.c's textconv_object, as `git show --textconv <rev>:<path>` runs it: the output of
1896
+ * the path's `diff.<driver>.textconv` over the blob as checkout writes it, or undefined
1897
+ * when no textconv applies (not a regular file, no driver, no command or no runner
1898
+ * installed, `textconv: false`). The attributes are the worktree's alone (git show reads
1899
+ * no index).
1900
+ */
1901
+ async textconvBlob(
1902
+ path: string,
1903
+ mode: number,
1904
+ read: () => Promise<Uint8Array>,
1905
+ ): Promise<Uint8Array | undefined> {
1906
+ if ((mode & S_IFMT) !== 0o100000) return undefined;
1907
+ const runner =
1908
+ (this.textOptions.textconv ?? true) ? textconvRunnerOf(this.workingCopy) : undefined;
1909
+ const filter = this.worktreeIfAny?.contentFilter as
1910
+ | {
1911
+ attributes?: (
1912
+ path: string,
1913
+ names?: readonly string[],
1914
+ context?: { direction: "checkin"; index?: AttributesIndex },
1915
+ ) => Promise<Map<string, true | false | string | undefined>>;
1916
+ }
1917
+ | undefined;
1918
+ if (!runner || !filter?.attributes) return undefined;
1919
+ const attrs = await filter.attributes(path, ["diff"], WITHOUT_INDEX_ATTRIBUTES);
1920
+ const driver = diffDriverOf(attrs?.get("diff"), (key) => this.config.value(key));
1921
+ const command = driver?.textconvCommand;
1922
+ if (!driver || command === undefined) return undefined;
1923
+ return runner({
1924
+ driver: driver.name ?? "",
1925
+ command,
1926
+ path,
1927
+ content: await this.smudged(path, mode, read),
1928
+ cache: driver.cacheTextconv ?? false,
1929
+ });
1930
+ }
1931
+
1066
1932
  /** A blob's content as checkout writes it to the worktree (the worktree's smudge filter) */
1067
1933
  private async smudged(
1068
1934
  path: string,
@@ -1075,18 +1941,18 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
1075
1941
  );
1076
1942
  }
1077
1943
 
1078
- /** The pairs `--name-only` lists: with whitespace options, those whose patch shows a change */
1944
+ /** git 2.5x's names from contents (see {@link DiffTextOptions.namesFromContents}) */
1945
+ private get namesFromContents(): boolean {
1946
+ return this.textOptions.namesFromContents ?? true;
1947
+ }
1948
+
1949
+ /** The pairs `--name-only` lists: with whitespace options or `-I`, those whose patch shows a change */
1079
1950
  private async shownNames(
1080
1951
  pairs: DiffFilePair[],
1081
1952
  unmerged: Set<DiffFilePair>,
1082
1953
  options: DiffOutputOptions,
1083
1954
  ): Promise<DiffFilePair[]> {
1084
- const fromContents =
1085
- (this.textOptions.namesFromContents ?? true) &&
1086
- (options.ignoreWhitespace ||
1087
- options.ignoreWhitespaceChange ||
1088
- options.ignoreWhitespaceAtEol ||
1089
- options.ignoreCrAtEol);
1955
+ const fromContents = this.namesFromContents && this.fromContents;
1090
1956
  if (!fromContents) return pairs;
1091
1957
  const shown: DiffFilePair[] = [];
1092
1958
  for (const pair of pairs) {
@@ -1107,7 +1973,7 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
1107
1973
 
1108
1974
  /** What this diff compares */
1109
1975
  private get sides(): DiffSides {
1110
- if (this.newTree) return "trees";
1976
+ if (this.newTree || this.indexAsTree) return "trees";
1111
1977
  if (this.cached) return "cached";
1112
1978
  if (!this.worktreeIfAny) return "trees";
1113
1979
  return this.oldTree ? "commit-worktree" : "index-worktree";
@@ -1245,7 +2111,9 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
1245
2111
  if (!found) {
1246
2112
  found = (async () => {
1247
2113
  const attrs = await filter.attributes?.(path, ["diff"], context);
1248
- return withTextconv(diffDriverOf(attrs?.get("diff"), get));
2114
+ return withTextconv(
2115
+ diffDriverOf(attrs?.get("diff"), get, this.textOptions.driverCompatibility),
2116
+ );
1249
2117
  })();
1250
2118
  drivers.set(path, found);
1251
2119
  }
@@ -1262,8 +2130,40 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
1262
2130
  orderFile: _orderFile,
1263
2131
  textconv: _textconv,
1264
2132
  abbrev: _abbrev,
2133
+ diffFilter: _diffFilter,
2134
+ relative: _relative,
2135
+ rotateTo: _rotateTo,
2136
+ skipTo: _skipTo,
2137
+ ignoreMatchingLines: _ignoreMatchingLines,
2138
+ quietDetectsRenames: _quietDetectsRenames,
2139
+ exitCodeFromContents: _exitCodeFromContents,
2140
+ pickaxeString: _pickaxeString,
2141
+ pickaxeGrep: _pickaxeGrep,
2142
+ findObjects: _findObjects,
2143
+ pickaxeRegex: _pickaxeRegex,
2144
+ pickaxeAll: _pickaxeAll,
2145
+ pickaxeIgnoreCase: _pickaxeIgnoreCase,
2146
+ color: _color,
2147
+ colorMoved: _colorMoved,
2148
+ colorMovedWs: _colorMovedWs,
2149
+ wsErrorHighlight: _wsErrorHighlight,
2150
+ colorCompatibility: _colorCompatibility,
2151
+ driverCompatibility: _driverCompatibility,
2152
+ findRenames: _findRenames,
2153
+ findCopies: _findCopies,
2154
+ findCopiesHarder: _findCopiesHarder,
2155
+ breakRewrites: _breakRewrites,
2156
+ dirstat: _dirstat,
2157
+ anchored,
1265
2158
  ...text
1266
2159
  } = this.textOptions;
2160
+ const colorSettings = this.colorSettings;
2161
+ // git_default_core_config: a core.whitespace git cannot parse dies in every diff
2162
+ const whitespaceRule = this.whitespaceRuleOf(filter, context);
2163
+ const colors = colorSettings?.colors
2164
+ ? { colors: colorSettings.colors, wsHighlight: colorSettings.wsErrorHighlight }
2165
+ : {};
2166
+ const ignoreRegex = this.ignoreRegex();
1267
2167
  const abbrev = abbrevOption(this.textOptions.abbrev);
1268
2168
  return {
1269
2169
  context: intValue(get("diff.context")) ?? 3,
@@ -1274,12 +2174,197 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
1274
2174
  : {}),
1275
2175
  ...text,
1276
2176
  ...(abbrev !== undefined ? { abbrev } : {}),
1277
- algorithm: text.algorithm ?? algorithmValue(get("diff.algorithm")) ?? "myers",
2177
+ algorithm:
2178
+ anchored && anchored.length > 0
2179
+ ? "patience"
2180
+ : (text.algorithm ?? algorithmValue(get("diff.algorithm")) ?? "myers"),
2181
+ ...(anchored && anchored.length > 0
2182
+ ? { anchors: anchored.map((a) => encodeGitPath(a)) }
2183
+ : {}),
1278
2184
  indentHeuristic: text.indentHeuristic ?? boolValue(get("diff.indentHeuristic")) ?? true,
1279
2185
  ...(driver ? { driver } : {}),
2186
+ ...(ignoreRegex.length > 0 ? { ignoreRegex } : {}),
2187
+ ...colors,
2188
+ ...(get("diff.wordRegex") !== undefined
2189
+ ? { defaultWordRegex: get("diff.wordRegex") as string }
2190
+ : {}),
2191
+ whitespaceRule,
2192
+ };
2193
+ }
2194
+
2195
+ /** `ll_merge_marker_size`: each path's `conflict-marker-size` attribute */
2196
+ private conflictMarkerSizeOf(): (path: string) => Promise<number> {
2197
+ const filter = this.worktreeIfAny?.contentFilter as
2198
+ | {
2199
+ attributes?: (
2200
+ path: string,
2201
+ names?: readonly string[],
2202
+ context?: { direction: "checkin"; index?: AttributesIndex },
2203
+ ) => Promise<Map<string, true | false | string | undefined>>;
2204
+ }
2205
+ | undefined;
2206
+ const context = this.newTree !== undefined ? WITHOUT_INDEX_ATTRIBUTES : undefined;
2207
+ return async (path: string) => {
2208
+ const attrs = await filter?.attributes?.(path, ["conflict-marker-size"], context);
2209
+ return conflictMarkerSizeOf(attrs?.get("conflict-marker-size") ?? undefined, (m) =>
2210
+ this.configWarnings.push(`warning: ${m}`),
2211
+ );
2212
+ };
2213
+ }
2214
+
2215
+ /**
2216
+ * ws.c's `whitespace_rule`: the `whitespace` attribute of a path over `core.whitespace`
2217
+ * (git 2.43 knows no `incomplete-line` rule)
2218
+ */
2219
+ private whitespaceRuleOf(
2220
+ filter:
2221
+ | {
2222
+ attributes?: (
2223
+ path: string,
2224
+ names?: readonly string[],
2225
+ context?: { direction: "checkin"; index?: AttributesIndex },
2226
+ ) => Promise<Map<string, true | false | string | undefined>>;
2227
+ }
2228
+ | undefined,
2229
+ context: { direction: "checkin"; index: AttributesIndex } | undefined,
2230
+ ): (path: string) => Promise<number> {
2231
+ const legacy = this.textOptions.colorCompatibility === "2.43";
2232
+ const mask = legacy ? ~WS_INCOMPLETE_LINE : ~0;
2233
+ const parse = (value: string) => {
2234
+ try {
2235
+ return parseWhitespaceRule(
2236
+ value,
2237
+ undefined,
2238
+ legacy ? { compatibility: "2.43" } : undefined,
2239
+ );
2240
+ } catch (e) {
2241
+ throw whitespaceRuleError((e as Error).message);
2242
+ }
2243
+ };
2244
+ const core = this.config.value("core.whitespace");
2245
+ const configRule = core === undefined ? WS_DEFAULT_RULE : parse(core);
2246
+ const rules = new Map<string, Promise<number>>();
2247
+ return (path: string) => {
2248
+ let found = rules.get(path);
2249
+ if (!found) {
2250
+ found = (async () => {
2251
+ const attrs = await filter?.attributes?.(path, ["whitespace"], context);
2252
+ const attr = attrs?.get("whitespace");
2253
+ if (typeof attr === "string") return parse(attr) & mask;
2254
+ return whitespaceRuleOf(attr ?? undefined, configRule) & mask;
2255
+ })();
2256
+ rules.set(path, found);
2257
+ }
2258
+ return found;
1280
2259
  };
1281
2260
  }
1282
2261
 
2262
+ /** `-I<regex>` compiled as git's `regcomp(REG_EXTENDED | REG_NEWLINE)` */
2263
+ private ignoreRegex(): PosixRegex[] {
2264
+ return (this.textOptions.ignoreMatchingLines ?? []).map((pattern) => {
2265
+ try {
2266
+ return compilePosixRegex(pattern, { extended: true, newline: true });
2267
+ } catch {
2268
+ throw new InvalidArgumentError(
2269
+ "ignoreMatchingLines",
2270
+ pattern,
2271
+ `error: invalid regex given to -I: '${pattern}'`,
2272
+ ).withExitCode(129);
2273
+ }
2274
+ });
2275
+ }
2276
+
2277
+ /**
2278
+ * git's `diff_from_contents`: whitespace options and `-I` (and, in git 2.5x, an exit status
2279
+ * asked for) make a pair count as a change only when its output shows one
2280
+ */
2281
+ private get fromContents(): boolean {
2282
+ const o = this.textOptions;
2283
+ // diff_setup_done (git 2.5x): porcelain diff allows external diffs, so an exit status
2284
+ // asked for (`--exit-code`, `--quiet`) always looks at the contents
2285
+ if ((this.exitWithStatus || this.quiet) && (o.exitCodeFromContents ?? true)) return true;
2286
+ return !!(
2287
+ o.ignoreWhitespace ||
2288
+ o.ignoreWhitespaceChange ||
2289
+ o.ignoreWhitespaceAtEol ||
2290
+ o.ignoreCrAtEol ||
2291
+ (o.ignoreMatchingLines?.length ?? 0) > 0
2292
+ );
2293
+ }
2294
+
2295
+ /**
2296
+ * The queue diffcore_std leaves of the collected entries: in `-O` order, swapped by `-R`,
2297
+ * rotated (`--rotate-to`, `--skip-to`), filtered (`--diff-filter`)
2298
+ */
2299
+ private async selected(entries: DiffEntry[]): Promise<DiffEntry[]> {
2300
+ const ordered = await this.ordered(await this.picked(entries));
2301
+ let out = this.textOptions.reverse ? ordered.map(reverseEntry) : ordered;
2302
+ const { rotateTo, skipTo } = this.textOptions;
2303
+ // diff_opt_rotate_to: the last of the two given wins
2304
+ if (skipTo !== undefined) out = rotateEntries(out, skipTo, true, this.rotateStrict);
2305
+ else if (rotateTo !== undefined) out = rotateEntries(out, rotateTo, false, this.rotateStrict);
2306
+ const filter = this.textOptions.diffFilter;
2307
+ return applyDiffFilter(out, filter !== undefined ? parseDiffFilter(filter) : undefined);
2308
+ }
2309
+
2310
+ /**
2311
+ * diffcore_std's prefetch condition: any pickaxe kind (`DIFF_PICKAXE_KINDS_MASK`,
2312
+ * `--find-object` included) fetches a partial clone's absent blobs of the queue in one
2313
+ * batch before rename detection
2314
+ */
2315
+ private get pickaxeReads(): boolean {
2316
+ return hasPickaxe(this.textOptions);
2317
+ }
2318
+
2319
+ /** diffcore_pickaxe over the queue (after rename detection, before `-O` and the filter) */
2320
+ private async picked(entries: DiffEntry[]): Promise<DiffEntry[]> {
2321
+ const pickaxe = this.pickaxe;
2322
+ if (!pickaxe) return entries;
2323
+ const options = this.outputOptions();
2324
+ return pickaxe.filter(
2325
+ entries,
2326
+ (e) => (e.unmerged ? undefined : this.withTextconvInputs(diffEntryToPair(e, this.blobs), e)),
2327
+ options,
2328
+ );
2329
+ }
2330
+
2331
+ /**
2332
+ * The pickaxe of the options (checked, compiled, `--find-object`'s revisions resolved),
2333
+ * before anything else is read
2334
+ */
2335
+ private async preparePickaxe(): Promise<void> {
2336
+ const o = this.textOptions;
2337
+ if (this.pickaxe || !hasPickaxe(o)) return;
2338
+ checkPickaxeOptions(o);
2339
+ let objects: Set<string> | undefined;
2340
+ if (o.findObjects && o.findObjects.length > 0) {
2341
+ objects = new Set();
2342
+ for (const name of o.findObjects) {
2343
+ const id = this.isFullObjectId(name)
2344
+ ? name.toLowerCase()
2345
+ : await this.revisionResolver()
2346
+ .resolve(name)
2347
+ .catch(() => undefined);
2348
+ if (id === undefined) {
2349
+ throw new InvalidArgumentError(
2350
+ "findObjects",
2351
+ name,
2352
+ `error: unable to resolve '${name}'`,
2353
+ ).withExitCode(129);
2354
+ }
2355
+ objects.add(id);
2356
+ }
2357
+ }
2358
+ this.pickaxe = DiffPickaxe.compile({
2359
+ ...(o.pickaxeString !== undefined ? { string: o.pickaxeString } : {}),
2360
+ ...(o.pickaxeGrep !== undefined ? { grep: o.pickaxeGrep } : {}),
2361
+ ...(objects ? { objects } : {}),
2362
+ regex: o.pickaxeRegex ?? false,
2363
+ all: o.pickaxeAll ?? false,
2364
+ ignoreCase: o.pickaxeIgnoreCase ?? false,
2365
+ });
2366
+ }
2367
+
1283
2368
  /**
1284
2369
  * The changed paths (and renames, when asked), in git's order, and the conflicted paths
1285
2370
  * `git diff` shows as combined diffs (`patch`: the patch format, where a path with both
@@ -1290,7 +2375,16 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
1290
2375
  renames: boolean | "copies",
1291
2376
  patch = false,
1292
2377
  prefetch = false,
2378
+ diffcore = true,
1293
2379
  ): Promise<{ entries: DiffEntry[]; combined: CombinedEntry[] }> {
2380
+ // option parsing fails before anything is read
2381
+ const core = diffcore
2382
+ ? this.diffcoreSettings(renames)
2383
+ : { detect: false as const, harder: false };
2384
+ if (this.textOptions.diffFilter !== undefined) parseDiffFilter(this.textOptions.diffFilter);
2385
+ this.ignoreRegex();
2386
+ await this.preparePickaxe();
2387
+ await this.resolveRevisions();
1294
2388
  // repo_read_index: in a sparse checkout, a skip-worktree entry whose file is present is
1295
2389
  // read as in the checkout (in memory: diff writes no index)
1296
2390
  await this.clearPresentSkipWorktree();
@@ -1325,6 +2419,7 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
1325
2419
  const unmerged = new Map<string, DiffEntry[]>();
1326
2420
  const combined: CombinedEntry[] = [];
1327
2421
  if (this.newTree) {
2422
+ if (this.pickaxe && !this.pickaxe.readsContent) this.treeSides = new Map();
1328
2423
  [oldSide, newSide] = await this.treePairSides(
1329
2424
  this.oldTree ?? "HEAD",
1330
2425
  this.oldTree === undefined,
@@ -1386,8 +2481,165 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
1386
2481
  // diffcore_std: an output that reads the blobs fetches a partial clone's absent ones in
1387
2482
  // one batch first (diff_queued_diff_prefetch), before rename detection
1388
2483
  if (prefetch) await this.blobs.prefetch?.(prefetchIds(entries));
1389
- if (renames) await this.detectRenames(entries, renames === "copies");
1390
- return { entries, combined };
2484
+ if (core.breaks || core.detect) {
2485
+ const oldFiles = async (): Promise<Map<string, Side>> => {
2486
+ if (this.newTree || this.cached || this.oldTree || !worktree) {
2487
+ return this.newTree
2488
+ ? this.treeSide(this.oldTree ?? "HEAD", this.oldTree === undefined)
2489
+ : oldSide;
2490
+ }
2491
+ // diff-files: the index's entries
2492
+ const out = new Map<string, Side>();
2493
+ for await (const entry of this.staging.entries()) {
2494
+ if (entry.stage === 0 && !entry.intentToAdd) {
2495
+ out.set(entry.path, { mode: entry.mode, id: entry.objectId });
2496
+ }
2497
+ }
2498
+ return out;
2499
+ };
2500
+ await this.diffcore(entries, core, oldFiles);
2501
+ }
2502
+ return { entries: this.withTreeEntries(entries, oldSide, newSide), combined };
2503
+ }
2504
+
2505
+ /**
2506
+ * `--find-object`'s tree_in_recursive: the changed subtrees of a diff of two trees among
2507
+ * the blob pairs, each before what lies below it (the tree walk's order: `a/` sorts after
2508
+ * `a.txt`); they take no part in rename detection
2509
+ */
2510
+ private withTreeEntries(
2511
+ entries: DiffEntry[],
2512
+ oldSide: Map<string, Side>,
2513
+ newSide: Map<string, Side>,
2514
+ ): DiffEntry[] {
2515
+ const sides = this.treeSides;
2516
+ if (!sides) return entries;
2517
+ this.treeSides = undefined;
2518
+ const trees = this.pairUp(
2519
+ sides.get(oldSide) ?? new Map(),
2520
+ sides.get(newSide) ?? new Map(),
2521
+ new Map(),
2522
+ );
2523
+ if (trees.length === 0) return entries;
2524
+ const keyOf = (e: DiffEntry) => e.newPath ?? e.oldPath ?? "";
2525
+ const treeKey = (e: DiffEntry) => `${e.newPath ?? e.oldPath ?? ""}/`;
2526
+ const out: DiffEntry[] = [];
2527
+ let t = 0;
2528
+ for (const e of entries) {
2529
+ const key = keyOf(e);
2530
+ while (t < trees.length && compareBytes(treeKey(trees[t] as DiffEntry), key) < 0) {
2531
+ out.push(trees[t++] as DiffEntry);
2532
+ }
2533
+ out.push(e);
2534
+ }
2535
+ while (t < trees.length) out.push(trees[t++] as DiffEntry);
2536
+ return out;
2537
+ }
2538
+
2539
+ /**
2540
+ * builtin/diff.c's revision handling: `A..B` is `A B`, `A...B` the merge base of A and B
2541
+ * against B (symdiff_prepare: the first base, with git's warning when there are several),
2542
+ * `--merge-base` the merge base of the two sides (diff_get_merge_base); an empty side of a
2543
+ * range is HEAD.
2544
+ */
2545
+ private async resolveRevisions(): Promise<void> {
2546
+ if (this.sidesResolved) return;
2547
+ this.sidesResolved = true;
2548
+ const old = this.oldTree;
2549
+ const range =
2550
+ old !== undefined && this.newTree === undefined && !old.includes(":")
2551
+ ? /^(.*?)(\.\.\.?)(.*)$/s.exec(old)
2552
+ : null;
2553
+ if (range) {
2554
+ if (this.mergeBase) throw new GitApiError("fatal: --merge-base does not work with ranges");
2555
+ const left = range[1] || "HEAD";
2556
+ const right = range[3] || "HEAD";
2557
+ if (range[2] === "..") {
2558
+ this.oldTree = left;
2559
+ this.newTree = right;
2560
+ return;
2561
+ }
2562
+ const errors: string[] = [];
2563
+ const a = await this.commitOf(left, errors, old);
2564
+ const b = await this.commitOf(right, errors, old);
2565
+ if (a === undefined || b === undefined) {
2566
+ throw new GitApiError(
2567
+ [...errors, `fatal: Invalid symmetric difference expression ${old}`].join("\n"),
2568
+ );
2569
+ }
2570
+ const bases = await revisionMergeBases(this.commits, a, b);
2571
+ const base = bases[0];
2572
+ if (base === undefined) throw new GitApiError(`fatal: ${left}...${right}: no merge base`);
2573
+ if (bases.length > 1) {
2574
+ this.configWarnings.push(
2575
+ `warning: ${left}...${right}: multiple merge bases, using ${base}`,
2576
+ );
2577
+ }
2578
+ this.oldTree = base;
2579
+ this.newTree = b;
2580
+ return;
2581
+ }
2582
+ if (!this.mergeBase) return;
2583
+ // `git diff --cached --merge-base`: HEAD, the default of --cached
2584
+ if (old === undefined && this.cached) this.oldTree = "HEAD";
2585
+ if (this.oldTree === undefined) {
2586
+ throw new InvalidArgumentError(
2587
+ "mergeBase",
2588
+ true,
2589
+ "error: invalid option: --merge-base",
2590
+ ).withExitCode(129);
2591
+ }
2592
+ const errors: string[] = [];
2593
+ const a = await this.commitOf(this.oldTree, errors);
2594
+ let b: ObjectId | undefined;
2595
+ if (this.newTree !== undefined) b = await this.commitOf(this.newTree, errors);
2596
+ else {
2597
+ let head: ObjectId;
2598
+ try {
2599
+ head = await this.resolveRevision("HEAD");
2600
+ } catch {
2601
+ throw new GitApiError("fatal: unable to get HEAD");
2602
+ }
2603
+ b = await this.commitOf(head, errors);
2604
+ }
2605
+ const bases =
2606
+ a !== undefined && b !== undefined ? await revisionMergeBases(this.commits, a, b) : [];
2607
+ if (bases.length === 0) {
2608
+ throw new GitApiError([...errors, "fatal: no merge base found"].join("\n"));
2609
+ }
2610
+ if (bases.length > 1) throw new GitApiError("fatal: multiple merge bases found");
2611
+ this.oldTree = bases[0];
2612
+ }
2613
+
2614
+ /**
2615
+ * lookup_commit_reference of a revision: the commit it names (tags peeled); for another
2616
+ * object git's `error: object <id> is a <type>, not a commit` goes to `errors`. A name that
2617
+ * resolves to nothing throws git's `ambiguous argument` (of the whole `argument`).
2618
+ */
2619
+ private async commitOf(
2620
+ name: string,
2621
+ errors: string[],
2622
+ argument = name,
2623
+ ): Promise<ObjectId | undefined> {
2624
+ let id: ObjectId;
2625
+ try {
2626
+ id = await this.resolveRevision(name);
2627
+ } catch (e) {
2628
+ if (e instanceof RefNotFoundError || e instanceof NoHeadError) {
2629
+ // setup_revisions: an argument that names no revision (nor a path)
2630
+ throw new RefNotFoundError(
2631
+ argument,
2632
+ `fatal: ambiguous argument '${argument}': unknown revision or path not in the working tree.`,
2633
+ );
2634
+ }
2635
+ throw e;
2636
+ }
2637
+ const peeled = await this.revisionResolver().peelTags(id);
2638
+ if (peeled.type === "commit") return peeled.id;
2639
+ if (peeled.type !== undefined) {
2640
+ errors.push(`error: object ${peeled.id} is a ${peeled.type}, not a commit`);
2641
+ }
2642
+ return undefined;
1391
2643
  }
1392
2644
 
1393
2645
  /**
@@ -1472,8 +2724,17 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
1472
2724
  ];
1473
2725
  }
1474
2726
 
2727
+ /** The `--relative=<path>` prefix paths are limited to and shown without */
2728
+ private get relativePrefix(): string | undefined {
2729
+ const relative = this.textOptions.relative;
2730
+ return typeof relative === "string" && relative !== "" ? relative : undefined;
2731
+ }
2732
+
1475
2733
  private matches(path: string): boolean {
1476
2734
  if (this.pathFilter && !path.startsWith(this.pathFilter)) return false;
2735
+ // diff_queue_addremove / diff_change / diff_unmerge: outside the prefix, nothing is queued
2736
+ const prefix = this.relativePrefix;
2737
+ if (prefix !== undefined && !path.startsWith(prefix)) return false;
1477
2738
  return !this.pathspecItems || matchPathspec(this.pathspecItems, path, 0) > 0;
1478
2739
  }
1479
2740
 
@@ -1543,51 +2804,264 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
1543
2804
  }
1544
2805
 
1545
2806
  /**
1546
- * git's `diffcore_rename` over the added and deleted paths; `copies` (DIFF_DETECT_COPY,
1547
- * `diff.renames=copies`): the modified paths are sources too, which stay (copied only)
2807
+ * diffcore's settings of a run: rename or copy detection (`renames` as configured or set,
2808
+ * then `-M`/`-C`), its threshold, `--find-copies-harder`, `-B`; option errors are thrown here
2809
+ */
2810
+ private diffcoreSettings(renames: boolean | "copies"): DiffcoreSettings {
2811
+ const o = this.textOptions;
2812
+ let detect: DiffcoreSettings["detect"] =
2813
+ renames === "copies" ? "copies" : renames ? "renames" : false;
2814
+ let score: number | undefined;
2815
+ let harder = o.findCopiesHarder === true;
2816
+ if (o.findRenames !== undefined) {
2817
+ if (o.findRenames === false) detect = false;
2818
+ else {
2819
+ detect = "renames";
2820
+ score = renameScoreOption(o.findRenames, "find-renames");
2821
+ }
2822
+ }
2823
+ if (o.findCopies !== undefined && o.findCopies !== false) {
2824
+ // diff_opt_find_copies: a second -C (copies already on, from diff.renames) finds harder
2825
+ if (detect === "copies" && o.findRenames === undefined) harder = true;
2826
+ detect = "copies";
2827
+ score = renameScoreOption(o.findCopies, "find-copies") ?? score;
2828
+ }
2829
+ const breaks =
2830
+ o.breakRewrites !== undefined && o.breakRewrites !== false
2831
+ ? parseBreakRewrites(o.breakRewrites)
2832
+ : undefined;
2833
+ return {
2834
+ detect,
2835
+ harder: detect === "copies" && harder,
2836
+ ...(score !== undefined ? { score } : {}),
2837
+ ...(breaks ? { breaks } : {}),
2838
+ };
2839
+ }
2840
+
2841
+ /**
2842
+ * diffcore_std's pair stages: `diffcore_break` (`-B`), `diffcore_rename` (renames, copies,
2843
+ * `--find-copies-harder`), `diffcore_merge_broken`, then `diff_resolve_rename_copy`. The
2844
+ * entries are changed in place, in git's queue order.
2845
+ */
2846
+ private async diffcore(
2847
+ entries: DiffEntry[],
2848
+ core: DiffcoreSettings,
2849
+ oldFiles: () => Promise<Map<string, Side>>,
2850
+ ): Promise<void> {
2851
+ const readBlob = async (id: ObjectId) => collectChunks((await this.blobs.load(id)) ?? []);
2852
+ const countLastSpan = this.textOptions.renameCountLastSpan;
2853
+ /** git's diff_filepair extras: a broken half's score, a renamed creation's source */
2854
+ const broken = new Map<DiffEntry, number>();
2855
+ const source = new Map<DiffEntry, { path: string; breakScore?: number }>();
2856
+ const uses = new Map<string, number>();
2857
+
2858
+ if (core.breaks) {
2859
+ const { breakScore, mergeScore } = core.breaks;
2860
+ const out: DiffEntry[] = [];
2861
+ for (const e of entries) {
2862
+ const blobMode = (m: number | undefined) =>
2863
+ m !== undefined && m !== 0 && m !== GITLINK && (m & 0o170000) !== 0o040000;
2864
+ if (
2865
+ e.changeType !== ChangeType.MODIFY ||
2866
+ e.unmerged ||
2867
+ !blobMode(e.oldMode) ||
2868
+ !blobMode(e.newMode) ||
2869
+ e.oldId === undefined
2870
+ ) {
2871
+ out.push(e);
2872
+ continue;
2873
+ }
2874
+ const oldContent = () => (e.readOld ? e.readOld() : readBlob(e.oldId as ObjectId));
2875
+ const newContent = () => (e.readNew ? e.readNew() : readBlob(e.newId as ObjectId));
2876
+ const sideOf = async (mode: number, read: () => Promise<Uint8Array>) => {
2877
+ const content = await read();
2878
+ return {
2879
+ mode,
2880
+ size: content.length,
2881
+ spans: async () => spanCounts(content, { countLastSpan }),
2882
+ };
2883
+ };
2884
+ const same = !e.readOld && !e.readNew && !e.newIdUnknown && e.oldId === e.newId;
2885
+ const verdict = await shouldBreak(
2886
+ await sideOf(e.oldMode as number, oldContent),
2887
+ await sideOf(e.newMode as number, newContent),
2888
+ breakScore,
2889
+ same,
2890
+ );
2891
+ if (!verdict.broken) {
2892
+ out.push(e);
2893
+ continue;
2894
+ }
2895
+ const score = verdict.mergeScore < mergeScore ? 0 : verdict.mergeScore;
2896
+ const del: DiffEntry = {
2897
+ changeType: ChangeType.DELETE,
2898
+ oldPath: e.oldPath,
2899
+ oldId: e.oldId,
2900
+ oldMode: e.oldMode,
2901
+ ...(e.readOld ? { readOld: e.readOld } : {}),
2902
+ };
2903
+ const add: DiffEntry = {
2904
+ changeType: ChangeType.ADD,
2905
+ newPath: e.newPath,
2906
+ newId: e.newId,
2907
+ newMode: e.newMode,
2908
+ ...(e.readNew ? { readNew: e.readNew } : {}),
2909
+ };
2910
+ broken.set(del, score);
2911
+ broken.set(add, score);
2912
+ out.push(del, add);
2913
+ }
2914
+ entries.splice(0, entries.length, ...out);
2915
+ }
2916
+
2917
+ if (core.detect) await this.detectRenames(entries, core, oldFiles, broken, source, uses);
2918
+
2919
+ if (core.breaks) {
2920
+ // diffcore_merge_broken: halves that both survived are one modification again
2921
+ const onePath = (e: DiffEntry) =>
2922
+ source.get(e)?.path ?? (e.changeType === ChangeType.ADD ? e.newPath : e.oldPath);
2923
+ const twoPath = (e: DiffEntry) =>
2924
+ e.changeType === ChangeType.DELETE ? e.oldPath : e.newPath;
2925
+ const samePath = (e: DiffEntry) => broken.has(e) && onePath(e) === twoPath(e);
2926
+ const out: DiffEntry[] = [];
2927
+ const merged = new Set<DiffEntry>();
2928
+ for (let i = 0; i < entries.length; i++) {
2929
+ const p = entries[i] as DiffEntry;
2930
+ if (merged.has(p)) continue;
2931
+ if (samePath(p)) {
2932
+ let peer: DiffEntry | undefined;
2933
+ for (let j = i + 1; j < entries.length; j++) {
2934
+ const pp = entries[j] as DiffEntry;
2935
+ if (!merged.has(pp) && samePath(pp) && onePath(p) === twoPath(pp)) {
2936
+ peer = pp;
2937
+ break;
2938
+ }
2939
+ }
2940
+ if (peer) {
2941
+ merged.add(peer);
2942
+ const d = p.changeType === ChangeType.DELETE ? p : peer;
2943
+ const c = d === p ? peer : p;
2944
+ const score = broken.get(p) ?? 0;
2945
+ out.push({
2946
+ changeType: ChangeType.MODIFY,
2947
+ oldPath: d.oldPath,
2948
+ newPath: c.newPath,
2949
+ oldId: d.oldId,
2950
+ newId: c.newId,
2951
+ oldMode: d.oldMode,
2952
+ newMode: c.newMode,
2953
+ ...(d.readOld ? { readOld: d.readOld } : {}),
2954
+ ...(c.readNew ? { readNew: c.readNew } : {}),
2955
+ ...(score ? { score: scorePercent(score) } : {}),
2956
+ });
2957
+ const from = d.oldPath ?? "";
2958
+ uses.set(from, (uses.get(from) ?? 0) + 1);
2959
+ continue;
2960
+ }
2961
+ }
2962
+ out.push(p);
2963
+ }
2964
+ entries.splice(0, entries.length, ...out);
2965
+ }
2966
+
2967
+ // diff_resolve_rename_copy: in queue order, each renamed pair takes one use of its source
2968
+ for (const e of entries) {
2969
+ const from = source.get(e);
2970
+ if (!from) continue;
2971
+ if (from.path === e.newPath) {
2972
+ // a rename joined a broken pair again: a modification (a rewrite with its score)
2973
+ e.changeType = ChangeType.MODIFY;
2974
+ if (from.breakScore) e.score = scorePercent(from.breakScore);
2975
+ else delete e.score;
2976
+ continue;
2977
+ }
2978
+ const left = (uses.get(from.path) ?? 0) - 1;
2979
+ uses.set(from.path, left);
2980
+ e.changeType = left > 0 ? ChangeType.COPY : ChangeType.RENAME;
2981
+ }
2982
+ }
2983
+
2984
+ /**
2985
+ * git's `diffcore_rename` over the queue: deleted paths (broken deletions too) as sources,
2986
+ * with copies the modified paths (and, harder, the unmodified ones) as sources that stay,
2987
+ * created paths as destinations. A destination paired becomes a rename (resolved into a
2988
+ * copy or a rename by {@link diffcore}); a deletion its rename takes is dropped.
1548
2989
  */
1549
- private async detectRenames(entries: DiffEntry[], copies = false): Promise<void> {
2990
+ private async detectRenames(
2991
+ entries: DiffEntry[],
2992
+ core: DiffcoreSettings,
2993
+ oldFiles: () => Promise<Map<string, Side>>,
2994
+ broken: Map<DiffEntry, number>,
2995
+ source: Map<DiffEntry, { path: string; breakScore?: number }>,
2996
+ uses: Map<string, number>,
2997
+ ): Promise<void> {
2998
+ const copies = core.detect === "copies";
1550
2999
  const sources = entries.filter(
1551
3000
  (e) =>
1552
- e.changeType === ChangeType.DELETE ||
3001
+ (e.changeType === ChangeType.DELETE && !e.unmerged) ||
1553
3002
  (copies && e.changeType === ChangeType.MODIFY && !e.unmerged),
1554
3003
  );
1555
3004
  // a submodule of git's null id (diff-index of a moved one) matches no source exactly,
1556
3005
  // and gitlinks pair only exactly
1557
3006
  const destinations = entries.filter((e) => e.changeType === ChangeType.ADD && !e.newIdUnknown);
3007
+ // --find-copies-harder: every unchanged path of the old side is a source too
3008
+ const unmodified: DiffEntry[] = [];
3009
+ if (copies && core.harder && destinations.length > 0) {
3010
+ const listed = new Set(entries.map((e) => e.oldPath ?? e.newPath));
3011
+ for (const [path, side] of await oldFiles()) {
3012
+ if (listed.has(path) || !this.matches(path)) continue;
3013
+ unmodified.push({
3014
+ changeType: ChangeType.MODIFY,
3015
+ oldPath: path,
3016
+ newPath: path,
3017
+ oldId: side.id,
3018
+ newId: side.id,
3019
+ oldMode: side.mode as FileModeValue,
3020
+ newMode: side.mode as FileModeValue,
3021
+ });
3022
+ }
3023
+ sources.push(...unmodified);
3024
+ }
3025
+ for (const e of sources) {
3026
+ const kept = e.changeType === ChangeType.MODIFY || (broken.has(e) && !broken.get(e));
3027
+ uses.set(e.oldPath ?? "", kept ? 1 : 0);
3028
+ }
1558
3029
  if (sources.length === 0 || destinations.length === 0) return;
1559
3030
  const byPath = new Map<string, DiffEntry>();
1560
3031
  for (const e of sources) byPath.set(`s:${e.oldPath}`, e);
1561
3032
  for (const e of destinations) byPath.set(`d:${e.newPath}`, e);
1562
- const readBlob = async (id: ObjectId) => {
1563
- const chunks: Uint8Array[] = [];
1564
- let size = 0;
1565
- for await (const c of (await this.blobs.load(id)) ?? []) {
1566
- chunks.push(c);
1567
- size += c.length;
1568
- }
1569
- const out = new Uint8Array(size);
1570
- let at = 0;
1571
- for (const c of chunks) {
1572
- out.set(c, at);
1573
- at += c.length;
1574
- }
1575
- return out;
1576
- };
3033
+ const unmodifiedSet = new Set(unmodified);
1577
3034
  const limit =
1578
3035
  this.renameLimit ?? intValue(this.config.value("diff.renameLimit")) ?? DEFAULT_RENAME_LIMIT;
3036
+ let needed = 0;
3037
+ let degraded = false;
1579
3038
  const pairs = await detectRenames(
1580
- sources.map((e) => ({
1581
- path: e.oldPath ?? "",
1582
- mode: e.oldMode ?? 0,
1583
- id: e.oldId ?? "",
1584
- ...(e.changeType === ChangeType.MODIFY ? { kept: true } : {}),
1585
- })),
3039
+ sources.map((e) => {
3040
+ const kept = e.changeType === ChangeType.MODIFY || (broken.has(e) && !broken.get(e));
3041
+ return {
3042
+ path: e.oldPath ?? "",
3043
+ mode: e.oldMode ?? 0,
3044
+ id: e.oldId ?? "",
3045
+ ...(kept ? { kept: true } : {}),
3046
+ ...(unmodifiedSet.has(e) ? { unmodified: true } : {}),
3047
+ };
3048
+ }),
1586
3049
  destinations.map((e) => ({ path: e.newPath ?? "", mode: e.newMode ?? 0, id: e.newId ?? "" })),
1587
3050
  {
1588
3051
  renameLimit: limit,
1589
3052
  countLastSpan: this.textOptions.renameCountLastSpan,
1590
3053
  copies,
3054
+ breakMode: sources.some((e) => broken.has(e)),
3055
+ ...(core.score !== undefined ? { minimumScore: core.score } : {}),
3056
+ onRenameLimit: (n) => {
3057
+ needed = n;
3058
+ },
3059
+ onDegraded: () => {
3060
+ degraded = true;
3061
+ },
3062
+ onUses: (counted) => {
3063
+ for (const [path, n] of counted) uses.set(path, n);
3064
+ },
1591
3065
  // a partial clone's absent blobs, fetched in one batch (a worktree file is no blob)
1592
3066
  prefetch: async (wanted) => {
1593
3067
  const ids: ObjectId[] = [];
@@ -1610,27 +3084,51 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
1610
3084
  load: async (c, role) => {
1611
3085
  const e = byPath.get(`${role === "source" ? "s" : "d"}:${c.path}`);
1612
3086
  if (role === "destination" && e?.readNew) return e.readNew();
1613
- return readBlob(c.id);
3087
+ return collectChunks((await this.blobs.load(c.id)) ?? []);
1614
3088
  },
1615
3089
  },
1616
3090
  );
1617
- const drop = new Set<DiffEntry>();
3091
+ // diff_warn_rename_limit
3092
+ if (degraded) {
3093
+ this.configWarnings.push(
3094
+ "warning: only found copies from modified paths due to too many files.",
3095
+ );
3096
+ } else if (needed) {
3097
+ this.configWarnings.push(
3098
+ "warning: exhaustive rename detection was skipped due to too many files.",
3099
+ );
3100
+ }
3101
+ if (needed) {
3102
+ this.configWarnings.push(
3103
+ `warning: you may want to set your diff.renameLimit variable to at least ${needed} and retry the command.`,
3104
+ );
3105
+ }
3106
+ const renamedHalves = new Set<string>();
1618
3107
  for (const pair of pairs) {
1619
3108
  const src = byPath.get(`s:${pair.from}`);
1620
3109
  const dst = byPath.get(`d:${pair.to}`);
1621
3110
  if (!src || !dst) continue;
1622
- // a deleted source taken by a rename or copy is no deletion any more
1623
- if (src.changeType === ChangeType.DELETE) drop.add(src);
1624
- dst.changeType = pair.copy ? ChangeType.COPY : ChangeType.RENAME;
3111
+ const breakScore = broken.get(src);
3112
+ source.set(dst, {
3113
+ path: pair.from,
3114
+ ...(breakScore !== undefined ? { breakScore } : {}),
3115
+ });
3116
+ if (broken.has(dst)) renamedHalves.add(dst.newPath ?? "");
3117
+ dst.changeType = ChangeType.RENAME;
1625
3118
  dst.oldPath = src.oldPath;
1626
3119
  dst.oldId = src.oldId;
1627
3120
  dst.oldMode = src.oldMode;
1628
- dst.score = scorePercent(pair.score);
1629
- }
1630
- if (drop.size > 0) {
1631
- const kept = entries.filter((e) => !drop.has(e));
1632
- entries.splice(0, entries.length, ...kept);
3121
+ if (src.readOld) dst.readOld = src.readOld;
3122
+ dst.score = scorePercent(pair.from === pair.to ? (breakScore ?? 0) : pair.score);
1633
3123
  }
3124
+ // the deletions a rename or copy takes away: a broken one when its own creation was
3125
+ // paired, any other once used
3126
+ const kept = entries.filter((e) => {
3127
+ if (e.changeType !== ChangeType.DELETE || e.unmerged) return true;
3128
+ if (broken.has(e)) return !renamedHalves.has(e.oldPath ?? "");
3129
+ return !(uses.get(e.oldPath ?? "") ?? 0);
3130
+ });
3131
+ entries.splice(0, entries.length, ...kept);
1634
3132
  }
1635
3133
 
1636
3134
  /**
@@ -1734,6 +3232,8 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
1734
3232
  if (xe.id === ye.id && xe.mode === ye.mode) continue;
1735
3233
  const path = prefix ? `${prefix}/${xe.name}` : xe.name;
1736
3234
  if (isTreeMode(xe.mode) && isTreeMode(ye.mode)) {
3235
+ this.addTreeSide(path, xe.mode, xe.id, oldSide);
3236
+ this.addTreeSide(path, ye.mode, ye.id, newSide);
1737
3237
  await this.diffTreeSides(xe.id, ye.id, path, oldSide, newSide);
1738
3238
  continue;
1739
3239
  }
@@ -1774,8 +3274,11 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
1774
3274
  } else {
1775
3275
  if (!x.sameAs(y)) {
1776
3276
  const path = pathOf(x.name());
1777
- if (x.isTree && y.isTree) await this.diffRawTrees(x.id(), y.id(), path, oldSide, newSide);
1778
- else {
3277
+ if (x.isTree && y.isTree) {
3278
+ this.addTreeSide(path, x.mode, x.id(), oldSide);
3279
+ this.addTreeSide(path, y.mode, y.id(), newSide);
3280
+ await this.diffRawTrees(x.id(), y.id(), path, oldSide, newSide);
3281
+ } else {
1779
3282
  await this.addRawSide(x, path, oldSide);
1780
3283
  await this.addRawSide(y, path, newSide);
1781
3284
  }
@@ -1792,14 +3295,30 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
1792
3295
  path: string,
1793
3296
  side: Map<string, Side>,
1794
3297
  ): Promise<void> {
1795
- if (c.isTree) await this.collectTreeEntries(c.id(), path, side);
1796
- else side.set(path, { mode: c.mode, id: c.id() });
3298
+ if (c.isTree) {
3299
+ this.addTreeSide(path, c.mode, c.id(), side);
3300
+ await this.collectTreeEntries(c.id(), path, side);
3301
+ } else side.set(path, { mode: c.mode, id: c.id() });
1797
3302
  }
1798
3303
 
1799
3304
  /** A tree entry on one side: a blob as itself, a subtree as its blobs */
1800
3305
  private async addSide(e: TreeEntry, path: string, side: Map<string, Side>): Promise<void> {
1801
- if (isTreeMode(e.mode)) await this.collectTreeEntries(e.id, path, side);
1802
- else side.set(path, { mode: e.mode, id: e.id });
3306
+ if (isTreeMode(e.mode)) {
3307
+ this.addTreeSide(path, e.mode, e.id, side);
3308
+ await this.collectTreeEntries(e.id, path, side);
3309
+ } else side.set(path, { mode: e.mode, id: e.id });
3310
+ }
3311
+
3312
+ /** A subtree on one side, kept for `--find-object` (see {@link withTreeEntries}) */
3313
+ private addTreeSide(path: string, mode: number, id: ObjectId, side: Map<string, Side>): void {
3314
+ const sides = this.treeSides;
3315
+ if (!sides) return;
3316
+ let trees = sides.get(side);
3317
+ if (!trees) {
3318
+ trees = new Map();
3319
+ sides.set(side, trees);
3320
+ }
3321
+ trees.set(path, { mode, id });
1803
3322
  }
1804
3323
 
1805
3324
  /**
@@ -1927,7 +3446,7 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
1927
3446
  }
1928
3447
  if (!this.matches(entry.path)) continue;
1929
3448
  const side = await compareWith(entry, current);
1930
- if (changedOnly && !entry.intentToAdd) {
3449
+ if (changedOnly && (!entry.intentToAdd || this.intentToAddVisible)) {
1931
3450
  // diff-files: an entry its file still holds is no change on either side, left out
1932
3451
  // of both (the index side is the entry, as `indexSide` gives it)
1933
3452
  if (side && side.id === entry.objectId && side.mode === entry.mode && !side.dirty) {
@@ -2001,6 +3520,7 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
2001
3520
  for (const entry of await this.treeEntries(treeId)) {
2002
3521
  const path = prefix ? `${prefix}/${entry.name}` : entry.name;
2003
3522
  if ((entry.mode & S_IFMT) === TREE_MODE) {
3523
+ this.addTreeSide(path, entry.mode, entry.id, entries);
2004
3524
  await this.collectTreeEntries(entry.id, path, entries);
2005
3525
  } else {
2006
3526
  // the mode as git's tree walk reads it (canon_mode), as the tree store reads it