@statewalker/vcs-commands 0.7.0 → 0.8.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 (410) hide show
  1. package/dist/commands/add-command.d.ts +38 -0
  2. package/dist/commands/add-command.d.ts.map +1 -1
  3. package/dist/commands/am/am-command.d.ts +55 -1
  4. package/dist/commands/am/am-command.d.ts.map +1 -1
  5. package/dist/commands/am/index.d.ts +1 -0
  6. package/dist/commands/am/index.d.ts.map +1 -1
  7. package/dist/commands/am/mailsplit.d.ts +88 -0
  8. package/dist/commands/am/mailsplit.d.ts.map +1 -0
  9. package/dist/commands/apply/apply-command.d.ts.map +1 -1
  10. package/dist/commands/apply/apply-engine.d.ts.map +1 -1
  11. package/dist/commands/apply/apply-parse.d.ts.map +1 -1
  12. package/dist/commands/bisect/bisect-command.d.ts +2 -0
  13. package/dist/commands/bisect/bisect-command.d.ts.map +1 -1
  14. package/dist/commands/branch-command.d.ts +148 -18
  15. package/dist/commands/branch-command.d.ts.map +1 -1
  16. package/dist/commands/branch-info-command.d.ts +55 -0
  17. package/dist/commands/branch-info-command.d.ts.map +1 -0
  18. package/dist/commands/branch-tracking.d.ts +106 -17
  19. package/dist/commands/branch-tracking.d.ts.map +1 -1
  20. package/dist/commands/branch-upstream-command.d.ts +83 -0
  21. package/dist/commands/branch-upstream-command.d.ts.map +1 -0
  22. package/dist/commands/checkout-command.d.ts +19 -3
  23. package/dist/commands/checkout-command.d.ts.map +1 -1
  24. package/dist/commands/cherry-pick-command.d.ts +59 -0
  25. package/dist/commands/cherry-pick-command.d.ts.map +1 -1
  26. package/dist/commands/clean-command.d.ts +12 -0
  27. package/dist/commands/clean-command.d.ts.map +1 -1
  28. package/dist/commands/clone-command.d.ts.map +1 -1
  29. package/dist/commands/commit-command.d.ts +191 -5
  30. package/dist/commands/commit-command.d.ts.map +1 -1
  31. package/dist/commands/commit-reuse.d.ts +33 -0
  32. package/dist/commands/commit-reuse.d.ts.map +1 -0
  33. package/dist/commands/config-command.d.ts +236 -0
  34. package/dist/commands/config-command.d.ts.map +1 -0
  35. package/dist/commands/config-value-types.d.ts +91 -0
  36. package/dist/commands/config-value-types.d.ts.map +1 -0
  37. package/dist/commands/core-config.d.ts +20 -0
  38. package/dist/commands/core-config.d.ts.map +1 -1
  39. package/dist/commands/diff-color-config.d.ts +73 -0
  40. package/dist/commands/diff-color-config.d.ts.map +1 -0
  41. package/dist/commands/diff-command.d.ts +252 -5
  42. package/dist/commands/diff-command.d.ts.map +1 -1
  43. package/dist/commands/fetch-command.d.ts +20 -0
  44. package/dist/commands/fetch-command.d.ts.map +1 -1
  45. package/dist/commands/fmt-merge-msg-command.d.ts +124 -0
  46. package/dist/commands/fmt-merge-msg-command.d.ts.map +1 -0
  47. package/dist/commands/fork-point.d.ts +38 -0
  48. package/dist/commands/fork-point.d.ts.map +1 -0
  49. package/dist/commands/format-patch-command.d.ts +41 -1
  50. package/dist/commands/format-patch-command.d.ts.map +1 -1
  51. package/dist/commands/fsck/fetch-fsck.d.ts +51 -0
  52. package/dist/commands/fsck/fetch-fsck.d.ts.map +1 -1
  53. package/dist/commands/gc-command.d.ts +8 -0
  54. package/dist/commands/gc-command.d.ts.map +1 -1
  55. package/dist/commands/git-describe.d.ts +4 -0
  56. package/dist/commands/git-describe.d.ts.map +1 -1
  57. package/dist/commands/git-hooks.d.ts +35 -0
  58. package/dist/commands/git-hooks.d.ts.map +1 -1
  59. package/dist/commands/grep/grep-command.d.ts +210 -0
  60. package/dist/commands/grep/grep-command.d.ts.map +1 -0
  61. package/dist/commands/grep/grep-engine.d.ts +218 -0
  62. package/dist/commands/grep/grep-engine.d.ts.map +1 -0
  63. package/dist/commands/grep/index.d.ts +3 -0
  64. package/dist/commands/grep/index.d.ts.map +1 -0
  65. package/dist/commands/index-adder.d.ts +13 -2
  66. package/dist/commands/index-adder.d.ts.map +1 -1
  67. package/dist/commands/index.d.ts +26 -0
  68. package/dist/commands/index.d.ts.map +1 -1
  69. package/dist/commands/index.js +3 -3
  70. package/dist/commands/interpret-trailers-command.d.ts +90 -0
  71. package/dist/commands/interpret-trailers-command.d.ts.map +1 -0
  72. package/dist/commands/local-transport.d.ts +36 -5
  73. package/dist/commands/local-transport.d.ts.map +1 -1
  74. package/dist/commands/log-command.d.ts +296 -11
  75. package/dist/commands/log-command.d.ts.map +1 -1
  76. package/dist/commands/log-graph.d.ts +26 -1
  77. package/dist/commands/log-graph.d.ts.map +1 -1
  78. package/dist/commands/log-output.d.ts +133 -5
  79. package/dist/commands/log-output.d.ts.map +1 -1
  80. package/dist/commands/ls-remote-command.d.ts +2 -0
  81. package/dist/commands/ls-remote-command.d.ts.map +1 -1
  82. package/dist/commands/mailmap.d.ts +30 -0
  83. package/dist/commands/mailmap.d.ts.map +1 -1
  84. package/dist/commands/merge-base-command.d.ts +60 -0
  85. package/dist/commands/merge-base-command.d.ts.map +1 -0
  86. package/dist/commands/merge-bases.d.ts +23 -0
  87. package/dist/commands/merge-bases.d.ts.map +1 -1
  88. package/dist/commands/merge-command.d.ts +96 -9
  89. package/dist/commands/merge-command.d.ts.map +1 -1
  90. package/dist/commands/merge-support.d.ts.map +1 -1
  91. package/dist/commands/mv-command.d.ts +4 -0
  92. package/dist/commands/mv-command.d.ts.map +1 -1
  93. package/dist/commands/name-rev.d.ts +48 -0
  94. package/dist/commands/name-rev.d.ts.map +1 -0
  95. package/dist/commands/notes-command.d.ts.map +1 -1
  96. package/dist/commands/pathspec-file.d.ts +39 -0
  97. package/dist/commands/pathspec-file.d.ts.map +1 -0
  98. package/dist/commands/pathspec.d.ts +3 -0
  99. package/dist/commands/pathspec.d.ts.map +1 -1
  100. package/dist/commands/pretty-format.d.ts +43 -3
  101. package/dist/commands/pretty-format.d.ts.map +1 -1
  102. package/dist/commands/promisor-remote.d.ts.map +1 -1
  103. package/dist/commands/pull-command.d.ts +10 -0
  104. package/dist/commands/pull-command.d.ts.map +1 -1
  105. package/dist/commands/push-command.d.ts +160 -9
  106. package/dist/commands/push-command.d.ts.map +1 -1
  107. package/dist/commands/read-tree-command.d.ts +6 -0
  108. package/dist/commands/read-tree-command.d.ts.map +1 -1
  109. package/dist/commands/rebase-command.d.ts +168 -6
  110. package/dist/commands/rebase-command.d.ts.map +1 -1
  111. package/dist/commands/ref-filter/for-each-ref-command.d.ts +121 -0
  112. package/dist/commands/ref-filter/for-each-ref-command.d.ts.map +1 -0
  113. package/dist/commands/ref-filter/index.d.ts +8 -0
  114. package/dist/commands/ref-filter/index.d.ts.map +1 -0
  115. package/dist/commands/ref-filter/ref-atoms.d.ts +88 -0
  116. package/dist/commands/ref-filter/ref-atoms.d.ts.map +1 -0
  117. package/dist/commands/ref-filter/ref-filter.d.ts +178 -0
  118. package/dist/commands/ref-filter/ref-filter.d.ts.map +1 -0
  119. package/dist/commands/ref-filter/ref-format.d.ts +222 -0
  120. package/dist/commands/ref-filter/ref-format.d.ts.map +1 -0
  121. package/dist/commands/ref-filter/ref-listing-command.d.ts +56 -0
  122. package/dist/commands/ref-filter/ref-listing-command.d.ts.map +1 -0
  123. package/dist/commands/ref-filter/ref-quote.d.ts +20 -0
  124. package/dist/commands/ref-filter/ref-quote.d.ts.map +1 -0
  125. package/dist/commands/ref-filter/version-compare.d.ts +20 -0
  126. package/dist/commands/ref-filter/version-compare.d.ts.map +1 -0
  127. package/dist/commands/reflog-command.d.ts +120 -0
  128. package/dist/commands/reflog-command.d.ts.map +1 -1
  129. package/dist/commands/reflog-walk.d.ts +72 -0
  130. package/dist/commands/reflog-walk.d.ts.map +1 -0
  131. package/dist/commands/remote-command.d.ts +138 -29
  132. package/dist/commands/remote-command.d.ts.map +1 -1
  133. package/dist/commands/remote-transport.d.ts +7 -1
  134. package/dist/commands/remote-transport.d.ts.map +1 -1
  135. package/dist/commands/reset-command.d.ts +2 -3
  136. package/dist/commands/reset-command.d.ts.map +1 -1
  137. package/dist/commands/restore-command.d.ts +2 -3
  138. package/dist/commands/restore-command.d.ts.map +1 -1
  139. package/dist/commands/rev-filter/commit-filter.d.ts +95 -0
  140. package/dist/commands/rev-filter/commit-filter.d.ts.map +1 -0
  141. package/dist/commands/rev-filter/commit-grep.d.ts +91 -0
  142. package/dist/commands/rev-filter/commit-grep.d.ts.map +1 -0
  143. package/dist/commands/rev-filter/index.d.ts +3 -0
  144. package/dist/commands/rev-filter/index.d.ts.map +1 -0
  145. package/dist/commands/rev-list-command.d.ts +154 -2
  146. package/dist/commands/rev-list-command.d.ts.map +1 -1
  147. package/dist/commands/revert-command.d.ts +32 -0
  148. package/dist/commands/revert-command.d.ts.map +1 -1
  149. package/dist/commands/revision-range.d.ts +32 -1
  150. package/dist/commands/revision-range.d.ts.map +1 -1
  151. package/dist/commands/revision-resolver.d.ts +15 -0
  152. package/dist/commands/revision-resolver.d.ts.map +1 -1
  153. package/dist/commands/rm-command.d.ts +70 -2
  154. package/dist/commands/rm-command.d.ts.map +1 -1
  155. package/dist/commands/sequencer-pick.d.ts +84 -4
  156. package/dist/commands/sequencer-pick.d.ts.map +1 -1
  157. package/dist/commands/sequencer-support.d.ts +2 -0
  158. package/dist/commands/sequencer-support.d.ts.map +1 -1
  159. package/dist/commands/serve-repository.d.ts +7 -0
  160. package/dist/commands/serve-repository.d.ts.map +1 -1
  161. package/dist/commands/show-command.d.ts +130 -0
  162. package/dist/commands/show-command.d.ts.map +1 -0
  163. package/dist/commands/show-commit.d.ts +11 -0
  164. package/dist/commands/show-commit.d.ts.map +1 -0
  165. package/dist/commands/signature-check.d.ts +164 -0
  166. package/dist/commands/signature-check.d.ts.map +1 -0
  167. package/dist/commands/signing.d.ts +160 -0
  168. package/dist/commands/signing.d.ts.map +1 -0
  169. package/dist/commands/sparse-checkout-command.d.ts.map +1 -1
  170. package/dist/commands/sparse-index-view.d.ts +45 -0
  171. package/dist/commands/sparse-index-view.d.ts.map +1 -0
  172. package/dist/commands/ssh-signer.d.ts +29 -0
  173. package/dist/commands/ssh-signer.d.ts.map +1 -0
  174. package/dist/commands/ssh-verifier.d.ts +42 -0
  175. package/dist/commands/ssh-verifier.d.ts.map +1 -0
  176. package/dist/commands/stash-apply-command.d.ts +5 -0
  177. package/dist/commands/stash-apply-command.d.ts.map +1 -1
  178. package/dist/commands/stash-branch-command.d.ts +34 -0
  179. package/dist/commands/stash-branch-command.d.ts.map +1 -0
  180. package/dist/commands/stash-create-command.d.ts +17 -0
  181. package/dist/commands/stash-create-command.d.ts.map +1 -1
  182. package/dist/commands/stash-info.d.ts +93 -0
  183. package/dist/commands/stash-info.d.ts.map +1 -0
  184. package/dist/commands/stash-list-command.d.ts +16 -0
  185. package/dist/commands/stash-list-command.d.ts.map +1 -1
  186. package/dist/commands/stash-pop-command.d.ts +39 -0
  187. package/dist/commands/stash-pop-command.d.ts.map +1 -0
  188. package/dist/commands/stash-show-command.d.ts +48 -0
  189. package/dist/commands/stash-show-command.d.ts.map +1 -0
  190. package/dist/commands/stash-store-command.d.ts +29 -0
  191. package/dist/commands/stash-store-command.d.ts.map +1 -0
  192. package/dist/commands/stash-working-tree.d.ts.map +1 -1
  193. package/dist/commands/status-command.d.ts.map +1 -1
  194. package/dist/commands/status-header.d.ts +5 -0
  195. package/dist/commands/status-header.d.ts.map +1 -1
  196. package/dist/commands/submodule-add-command.d.ts +89 -0
  197. package/dist/commands/submodule-add-command.d.ts.map +1 -0
  198. package/dist/commands/submodule-auth.d.ts +90 -0
  199. package/dist/commands/submodule-auth.d.ts.map +1 -0
  200. package/dist/commands/submodule-commands.d.ts +375 -0
  201. package/dist/commands/submodule-commands.d.ts.map +1 -0
  202. package/dist/commands/submodule-model.d.ts +288 -0
  203. package/dist/commands/submodule-model.d.ts.map +1 -0
  204. package/dist/commands/submodule-update-command.d.ts +198 -0
  205. package/dist/commands/submodule-update-command.d.ts.map +1 -0
  206. package/dist/commands/switch-command.d.ts.map +1 -1
  207. package/dist/commands/tag-command.d.ts +259 -10
  208. package/dist/commands/tag-command.d.ts.map +1 -1
  209. package/dist/commands/trailers.d.ts +218 -17
  210. package/dist/commands/trailers.d.ts.map +1 -1
  211. package/dist/commands/tree-restore.d.ts +7 -0
  212. package/dist/commands/tree-restore.d.ts.map +1 -1
  213. package/dist/commands/verify-command.d.ts +92 -0
  214. package/dist/commands/verify-command.d.ts.map +1 -0
  215. package/dist/commands/worktree-add-command.d.ts +79 -7
  216. package/dist/commands/worktree-add-command.d.ts.map +1 -1
  217. package/dist/commands/worktree-path-rules.d.ts +66 -0
  218. package/dist/commands/worktree-path-rules.d.ts.map +1 -0
  219. package/dist/commands/worktree-remove-command.d.ts +10 -3
  220. package/dist/commands/worktree-remove-command.d.ts.map +1 -1
  221. package/dist/commands/worktree-repair-command.d.ts +15 -2
  222. package/dist/commands/worktree-repair-command.d.ts.map +1 -1
  223. package/dist/commands/worktree-support.d.ts +5 -0
  224. package/dist/commands/worktree-support.d.ts.map +1 -1
  225. package/dist/{commands-DIJ91NnD.js → commands-ISM52N0n.js} +70736 -54492
  226. package/dist/errors/checkout-errors.d.ts +19 -0
  227. package/dist/errors/checkout-errors.d.ts.map +1 -1
  228. package/dist/errors/command-errors.d.ts.map +1 -1
  229. package/dist/errors/index.js +57 -3
  230. package/dist/errors/ref-errors.d.ts +19 -0
  231. package/dist/errors/ref-errors.d.ts.map +1 -1
  232. package/dist/errors/worktree-errors.d.ts +6 -1
  233. package/dist/errors/worktree-errors.d.ts.map +1 -1
  234. package/dist/{git-command-BGiOJ8Zk.js → fsck-DLRpbwTj.js} +6230 -71
  235. package/dist/git-command.d.ts +27 -1
  236. package/dist/git-command.d.ts.map +1 -1
  237. package/dist/git.d.ts +267 -1
  238. package/dist/git.d.ts.map +1 -1
  239. package/dist/index.js +5 -5
  240. package/dist/remote-config/index.d.ts +1 -1
  241. package/dist/remote-config/index.d.ts.map +1 -1
  242. package/dist/remote-config/remote-config-store.d.ts +55 -0
  243. package/dist/remote-config/remote-config-store.d.ts.map +1 -1
  244. package/dist/results/combined-diff.d.ts +3 -0
  245. package/dist/results/combined-diff.d.ts.map +1 -1
  246. package/dist/results/diff-check.d.ts +38 -0
  247. package/dist/results/diff-check.d.ts.map +1 -0
  248. package/dist/results/diff-color.d.ts +135 -0
  249. package/dist/results/diff-color.d.ts.map +1 -0
  250. package/dist/results/diff-output.d.ts +85 -1
  251. package/dist/results/diff-output.d.ts.map +1 -1
  252. package/dist/results/diff-pickaxe.d.ts +67 -0
  253. package/dist/results/diff-pickaxe.d.ts.map +1 -0
  254. package/dist/results/diff-words.d.ts +55 -0
  255. package/dist/results/diff-words.d.ts.map +1 -0
  256. package/dist/results/index.d.ts +4 -0
  257. package/dist/results/index.d.ts.map +1 -1
  258. package/dist/results/index.js +2 -2
  259. package/dist/results/push-result.d.ts +7 -0
  260. package/dist/results/push-result.d.ts.map +1 -1
  261. package/dist/results/rebase-result.d.ts +2 -0
  262. package/dist/results/rebase-result.d.ts.map +1 -1
  263. package/dist/results/stash-result.d.ts +6 -0
  264. package/dist/results/stash-result.d.ts.map +1 -1
  265. package/dist/{results-WVlBhVb1.js → results-TB2IJ64h.js} +2168 -403
  266. package/dist/whitespace/index.d.ts +2 -0
  267. package/dist/whitespace/index.d.ts.map +1 -0
  268. package/dist/whitespace/whitespace-rule.d.ts +94 -0
  269. package/dist/whitespace/whitespace-rule.d.ts.map +1 -0
  270. package/package.json +12 -12
  271. package/src/commands/add-command.ts +178 -17
  272. package/src/commands/am/am-command.ts +262 -42
  273. package/src/commands/am/index.ts +1 -0
  274. package/src/commands/am/mailsplit.ts +326 -0
  275. package/src/commands/apply/apply-command.ts +6 -6
  276. package/src/commands/apply/apply-engine.ts +1 -1
  277. package/src/commands/apply/apply-parse.ts +7 -8
  278. package/src/commands/bisect/bisect-command.ts +18 -5
  279. package/src/commands/branch-command.ts +528 -53
  280. package/src/commands/branch-info-command.ts +150 -0
  281. package/src/commands/branch-tracking.ts +335 -60
  282. package/src/commands/branch-upstream-command.ts +218 -0
  283. package/src/commands/checkout-command.ts +69 -43
  284. package/src/commands/cherry-pick-command.ts +143 -0
  285. package/src/commands/clean-command.ts +34 -3
  286. package/src/commands/clone-command.ts +2 -1
  287. package/src/commands/commit-command.ts +782 -64
  288. package/src/commands/commit-reuse.ts +94 -0
  289. package/src/commands/config-command.ts +1256 -0
  290. package/src/commands/config-value-types.ts +358 -0
  291. package/src/commands/core-config.ts +40 -0
  292. package/src/commands/diff-color-config.ts +274 -0
  293. package/src/commands/diff-command.ts +1009 -49
  294. package/src/commands/fetch-command.ts +142 -8
  295. package/src/commands/fmt-merge-msg-command.ts +715 -0
  296. package/src/commands/fork-point.ts +63 -0
  297. package/src/commands/format-patch-command.ts +314 -46
  298. package/src/commands/fsck/fetch-fsck.ts +172 -18
  299. package/src/commands/gc-command.ts +31 -1
  300. package/src/commands/git-describe.ts +31 -11
  301. package/src/commands/git-hooks.ts +81 -0
  302. package/src/commands/grep/grep-command.ts +1077 -0
  303. package/src/commands/grep/grep-engine.ts +1024 -0
  304. package/src/commands/grep/index.ts +2 -0
  305. package/src/commands/index-adder.ts +46 -7
  306. package/src/commands/index.ts +26 -0
  307. package/src/commands/interpret-trailers-command.ts +256 -0
  308. package/src/commands/local-transport.ts +109 -10
  309. package/src/commands/log-command.ts +1246 -210
  310. package/src/commands/log-graph.ts +123 -26
  311. package/src/commands/log-output.ts +280 -21
  312. package/src/commands/ls-remote-command.ts +5 -0
  313. package/src/commands/mailmap.ts +119 -0
  314. package/src/commands/merge-base-command.ts +170 -0
  315. package/src/commands/merge-bases.ts +63 -8
  316. package/src/commands/merge-command.ts +330 -82
  317. package/src/commands/merge-support.ts +14 -1
  318. package/src/commands/mv-command.ts +6 -3
  319. package/src/commands/name-rev.ts +171 -0
  320. package/src/commands/notes-command.ts +11 -1
  321. package/src/commands/pathspec-file.ts +72 -0
  322. package/src/commands/pathspec.ts +14 -2
  323. package/src/commands/pretty-format.ts +103 -19
  324. package/src/commands/promisor-remote.ts +10 -1
  325. package/src/commands/pull-command.ts +26 -7
  326. package/src/commands/push-command.ts +682 -65
  327. package/src/commands/read-tree-command.ts +28 -1
  328. package/src/commands/rebase-command.ts +933 -129
  329. package/src/commands/ref-filter/for-each-ref-command.ts +298 -0
  330. package/src/commands/ref-filter/index.ts +7 -0
  331. package/src/commands/ref-filter/ref-atoms.ts +581 -0
  332. package/src/commands/ref-filter/ref-filter.ts +651 -0
  333. package/src/commands/ref-filter/ref-format.ts +1070 -0
  334. package/src/commands/ref-filter/ref-listing-command.ts +421 -0
  335. package/src/commands/ref-filter/ref-quote.ts +69 -0
  336. package/src/commands/ref-filter/version-compare.ts +177 -0
  337. package/src/commands/reflog-command.ts +492 -2
  338. package/src/commands/reflog-walk.ts +234 -0
  339. package/src/commands/remote-command.ts +449 -69
  340. package/src/commands/remote-transport.ts +9 -1
  341. package/src/commands/reset-command.ts +36 -31
  342. package/src/commands/restore-command.ts +12 -41
  343. package/src/commands/rev-filter/commit-filter.ts +159 -0
  344. package/src/commands/rev-filter/commit-grep.ts +444 -0
  345. package/src/commands/rev-filter/index.ts +2 -0
  346. package/src/commands/rev-list-command.ts +402 -15
  347. package/src/commands/revert-command.ts +82 -0
  348. package/src/commands/revision-range.ts +204 -4
  349. package/src/commands/revision-resolver.ts +23 -8
  350. package/src/commands/rm-command.ts +282 -21
  351. package/src/commands/sequencer-pick.ts +498 -85
  352. package/src/commands/sequencer-support.ts +20 -2
  353. package/src/commands/serve-repository.ts +18 -3
  354. package/src/commands/show-command.ts +490 -0
  355. package/src/commands/show-commit.ts +24 -0
  356. package/src/commands/signature-check.ts +657 -0
  357. package/src/commands/signing.ts +385 -0
  358. package/src/commands/sparse-checkout-command.ts +2 -9
  359. package/src/commands/sparse-checkout-support.ts +2 -2
  360. package/src/commands/sparse-index-view.ts +135 -0
  361. package/src/commands/ssh-signer.ts +199 -0
  362. package/src/commands/ssh-verifier.ts +523 -0
  363. package/src/commands/stash-apply-command.ts +16 -4
  364. package/src/commands/stash-branch-command.ts +88 -0
  365. package/src/commands/stash-create-command.ts +28 -0
  366. package/src/commands/stash-info.ts +243 -0
  367. package/src/commands/stash-list-command.ts +33 -0
  368. package/src/commands/stash-pop-command.ts +83 -0
  369. package/src/commands/stash-show-command.ts +141 -0
  370. package/src/commands/stash-store-command.ts +82 -0
  371. package/src/commands/stash-working-tree.ts +2 -2
  372. package/src/commands/status-command.ts +5 -2
  373. package/src/commands/status-header.ts +41 -7
  374. package/src/commands/submodule-add-command.ts +509 -0
  375. package/src/commands/submodule-auth.ts +276 -0
  376. package/src/commands/submodule-commands.ts +1517 -0
  377. package/src/commands/submodule-model.ts +930 -0
  378. package/src/commands/submodule-update-command.ts +1092 -0
  379. package/src/commands/switch-command.ts +3 -1
  380. package/src/commands/tag-command.ts +876 -64
  381. package/src/commands/trailers.ts +837 -100
  382. package/src/commands/tree-restore.ts +38 -10
  383. package/src/commands/verify-command.ts +235 -0
  384. package/src/commands/worktree-add-command.ts +268 -24
  385. package/src/commands/worktree-path-rules.ts +183 -0
  386. package/src/commands/worktree-remove-command.ts +39 -5
  387. package/src/commands/worktree-repair-command.ts +52 -5
  388. package/src/commands/worktree-support.ts +22 -1
  389. package/src/errors/checkout-errors.ts +29 -0
  390. package/src/errors/command-errors.ts +2 -1
  391. package/src/errors/ref-errors.ts +23 -0
  392. package/src/errors/worktree-errors.ts +8 -1
  393. package/src/git-command.ts +66 -1
  394. package/src/git.ts +404 -1
  395. package/src/remote-config/index.ts +2 -0
  396. package/src/remote-config/remote-config-store.ts +101 -0
  397. package/src/results/combined-diff.ts +38 -18
  398. package/src/results/diff-check.ts +185 -0
  399. package/src/results/diff-color.ts +868 -0
  400. package/src/results/diff-output.ts +195 -30
  401. package/src/results/diff-pickaxe.ts +304 -0
  402. package/src/results/diff-words.ts +395 -0
  403. package/src/results/index.ts +4 -0
  404. package/src/results/push-result.ts +7 -0
  405. package/src/results/rebase-result.ts +3 -0
  406. package/src/results/stash-result.ts +7 -0
  407. package/src/whitespace/index.ts +1 -0
  408. package/src/{commands/apply/whitespace.ts → whitespace/whitespace-rule.ts} +173 -23
  409. package/dist/commands/apply/whitespace.d.ts +0 -58
  410. package/dist/commands/apply/whitespace.d.ts.map +0 -1
@@ -6,7 +6,9 @@ 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";
@@ -25,7 +27,12 @@ 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 {
@@ -35,6 +42,8 @@ import {
35
42
  scorePercent,
36
43
  } from "../rename/index.js";
37
44
  import { writeCombinedDiff } from "../results/combined-diff.js";
45
+ import { conflictMarkerSizeOf, writePairCheck } from "../results/diff-check.js";
46
+ import { MovedLineBuffer } from "../results/diff-color.js";
38
47
  import { ChangeType, type DiffEntry } from "../results/diff-entry.js";
39
48
  import { diffEntryToPair } from "../results/diff-formatter.js";
40
49
  import { orderByPatterns, parseOrderFile } from "../results/diff-order.js";
@@ -56,12 +65,26 @@ import {
56
65
  formatSummary,
57
66
  writePairPatch,
58
67
  } from "../results/diff-output.js";
68
+ import { DiffPickaxe } from "../results/diff-pickaxe.js";
59
69
  import { quotePath } from "../results/quote-path.js";
70
+ import {
71
+ parseWhitespaceRule,
72
+ WS_DEFAULT_RULE,
73
+ WS_INCOMPLETE_LINE,
74
+ whitespaceRuleOf,
75
+ } from "../whitespace/index.js";
60
76
  import { bareAttributesResolver } from "./attributes-source.js";
61
77
  import { worktreeModeTrust } from "./core-config.js";
78
+ import {
79
+ type DiffColorOptions,
80
+ type DiffColorSettings,
81
+ readDiffColorSettings,
82
+ whitespaceRuleError,
83
+ } from "./diff-color-config.js";
62
84
  import { textconvRunnerOf } from "./diff-textconv.js";
63
85
  import { matchPathspec, type PathspecItem, parsePathspecItem } from "./pathspec.js";
64
86
  import { PathspecAttributes } from "./pathspec-attributes.js";
87
+ import { revisionMergeBases } from "./rev-parse-command.js";
65
88
  import { readSubmoduleDirt, type SubmoduleDirt } from "./status-command.js";
66
89
  import {
67
90
  isSubmoduleIgnoreMode,
@@ -96,7 +119,14 @@ const PREFETCH_FORMATS = new Set<string>(["patch", "stat", "numstat", "shortstat
96
119
  function prefetchIds(entries: readonly DiffEntry[]): ObjectId[] {
97
120
  const out: ObjectId[] = [];
98
121
  const add = (id: ObjectId | undefined, mode: number | undefined) => {
99
- if (id && !isNullObjectId(id) && mode !== GITLINK && mode !== undefined && mode !== 0)
122
+ if (
123
+ id &&
124
+ !isNullObjectId(id) &&
125
+ mode !== GITLINK &&
126
+ mode !== undefined &&
127
+ mode !== 0 &&
128
+ (mode & 0o170000) !== 0o040000
129
+ )
100
130
  out.push(id);
101
131
  };
102
132
  for (const e of entries) {
@@ -114,15 +144,42 @@ export type DiffOutputFormat =
114
144
  | "shortstat"
115
145
  | "summary"
116
146
  | "name-only"
117
- | "name-status";
147
+ | "name-status"
148
+ /**
149
+ * `--check`: the whitespace errors and leftover conflict markers the change adds (see
150
+ * {@link writePairCheck}); it turns the other formats off, and {@link DiffCommand.exitCode}
151
+ * gets 2 when it found any
152
+ */
153
+ | "check";
118
154
 
119
155
  /** Options of the text output that `git diff` takes on its command line */
120
156
  export interface DiffTextOptions
121
- extends Omit<DiffOutputOptions, "driver" | "algorithm" | "indentHeuristic"> {
157
+ extends Omit<
158
+ DiffOutputOptions,
159
+ | "driver"
160
+ | "algorithm"
161
+ | "indentHeuristic"
162
+ | "ignoreRegex"
163
+ | "colors"
164
+ | "wsHighlight"
165
+ | "whitespaceRule"
166
+ | "defaultWordRegex"
167
+ >,
168
+ DiffColorOptions {
169
+ /**
170
+ * The builtin diff drivers (funcname and word regexes) of that git version (default 2.56):
171
+ * 2.43 has no `ini`, `r` and `swift` drivers and older `bash`, `csharp` and `scheme` ones
172
+ */
173
+ driverCompatibility?: "2.43" | "2.56";
122
174
  /** `--diff-algorithm` (default `diff.algorithm`, else myers) */
123
175
  algorithm?: XdiffAlgorithm;
124
176
  /** `--indent-heuristic` / `--no-indent-heuristic` (default `diff.indentHeuristic`, true) */
125
177
  indentHeuristic?: boolean;
178
+ /**
179
+ * diff_options.stat_sep: text written after the blank line that separates a stat or
180
+ * summary from the patch (format-patch's MIME part header with `--attach`/`--inline`)
181
+ */
182
+ statSep?: string;
126
183
  /**
127
184
  * `--abbrev=<n>`: the `index` lines' ids at least n digits, clamped as git clamps it (below
128
185
  * 4, 0 too, is 4; above 40 is 40); the combined diffs of conflicted paths ignore it, as
@@ -188,6 +245,207 @@ export interface DiffTextOptions
188
245
  * prefixes with them (`diff --git b/f a/f`). Combined diffs of conflicted paths are not swapped.
189
246
  */
190
247
  reverse?: boolean;
248
+ /**
249
+ * `--diff-filter=<letters>`: only the pairs of these statuses (`A`dded, `C`opied,
250
+ * `D`eleted, `M`odified, `R`enamed, `T`ype changed, `U`nmerged, `X` unknown, `B`roken);
251
+ * a lowercase letter leaves its status out instead, and `*` keeps every pair as long as one
252
+ * of them matches (all or none). An unknown letter throws git's
253
+ * `error: unknown change class '<c>' in --diff-filter=<letters>` (exit 129). The combined
254
+ * diff (`diff --cc`) of a conflicted path is not filtered, as git's is not.
255
+ */
256
+ diffFilter?: string;
257
+ /**
258
+ * `--relative=<path>`: only the paths that start with `<path>` (a string prefix, as git's
259
+ * `strncmp`: `sub` takes `subdir/` too), shown without it (and the `/` after it);
260
+ * `--no-relative` is `false`. The commands run at the top of the worktree, so `true`
261
+ * (`--relative` without a path, or `diff.relative`) shows every path as it is.
262
+ */
263
+ relative?: string | boolean;
264
+ /**
265
+ * `--rotate-to=<path>`: the output starts at this path, the ones before it moved to the end;
266
+ * `git diff` throws `fatal: No such path '<path>' in the diff` when no pair has it, `git
267
+ * log` starts at the first path after it
268
+ */
269
+ rotateTo?: string;
270
+ /** `--skip-to=<path>`: as {@link rotateTo}, the paths before it left out */
271
+ skipTo?: string;
272
+ /**
273
+ * `-I<regex>` (`--ignore-matching-lines`): changes whose lines all match one of these POSIX
274
+ * extended regexes are not shown (xdiff's `xdl_mark_ignorable_regex`); an invalid one
275
+ * throws git's `error: invalid regex given to -I: '<regex>'` (exit 129)
276
+ */
277
+ ignoreMatchingLines?: readonly string[];
278
+ /**
279
+ * `--quiet` still detects renames and copies (git 2.43; default false: git 2.5x's
280
+ * diff_setup_done turns `detect_rename` off under `quick`, so `--quiet --diff-filter=R`
281
+ * finds nothing there)
282
+ */
283
+ quietDetectsRenames?: boolean;
284
+ /**
285
+ * `--exit-code` and `--quiet` count only the pairs an output shows (default true, git 2.5x,
286
+ * whose porcelain diff turns `diff_from_contents` on with an exit status: `--summary` alone
287
+ * then exits 0, a pair whose patch shows nothing does not count); false counts every queued
288
+ * pair unless a whitespace option or `-I` is given, as git 2.43
289
+ */
290
+ exitCodeFromContents?: boolean;
291
+ /**
292
+ * `-S<string>`: only the pairs whose two sides hold the string a different number of
293
+ * times (diffcore-pickaxe.c), read through textconv unless `textconv: false`. An empty
294
+ * string throws git's `error: -S requires a non-empty argument` (exit 129).
295
+ */
296
+ pickaxeString?: string;
297
+ /**
298
+ * `-G<regex>`: only the pairs whose added or removed lines match this POSIX extended
299
+ * regex; binary pairs are passed over unless `text` (or textconv makes them text). An
300
+ * empty one throws `error: -G requires a non-empty argument` (exit 129), an invalid one
301
+ * `fatal: invalid regex: <message>` (exit 128).
302
+ */
303
+ pickaxeGrep?: string;
304
+ /**
305
+ * `--find-object=<object>` (each a revision naming an object): only the pairs with one of
306
+ * them on either side; a diff of two trees also lists the subtrees that changed, so a tree
307
+ * can be found too (`tree_in_recursive`). One that names nothing throws `error: unable to
308
+ * resolve '<object>'` (exit 129).
309
+ */
310
+ findObjects?: readonly string[];
311
+ /** `--pickaxe-regex`: `-S` takes a POSIX extended regex */
312
+ pickaxeRegex?: boolean;
313
+ /** `--pickaxe-all`: when one pair matches, every pair is kept; when none, none */
314
+ pickaxeAll?: boolean;
315
+ /** `-i` / `--regexp-ignore-case` of `-S`/`-G` (ASCII case folded) */
316
+ pickaxeIgnoreCase?: boolean;
317
+ }
318
+
319
+ /** Whether options ask for a pickaxe (git's `DIFF_PICKAXE_KINDS_MASK`) */
320
+ export function hasPickaxe(o: DiffTextOptions): boolean {
321
+ return (
322
+ o.pickaxeString !== undefined ||
323
+ o.pickaxeGrep !== undefined ||
324
+ (o.findObjects !== undefined && o.findObjects.length > 0)
325
+ );
326
+ }
327
+
328
+ /**
329
+ * diff.c's checks of the pickaxe options (the option callbacks' empty-argument errors, then
330
+ * diff_setup_done's combinations), before anything is read
331
+ */
332
+ export function checkPickaxeOptions(o: DiffTextOptions): void {
333
+ if (o.pickaxeString === "") {
334
+ throw new InvalidArgumentError(
335
+ "pickaxeString",
336
+ "",
337
+ "error: -S requires a non-empty argument",
338
+ ).withExitCode(129);
339
+ }
340
+ if (o.pickaxeGrep === "") {
341
+ throw new InvalidArgumentError(
342
+ "pickaxeGrep",
343
+ "",
344
+ "error: -G requires a non-empty argument",
345
+ ).withExitCode(129);
346
+ }
347
+ const kinds =
348
+ (o.pickaxeString !== undefined ? 1 : 0) +
349
+ (o.pickaxeGrep !== undefined ? 1 : 0) +
350
+ ((o.findObjects?.length ?? 0) > 0 ? 1 : 0);
351
+ if (kinds > 1) {
352
+ throw new GitApiError(
353
+ "fatal: options '-G', '-S', and '--find-object' cannot be used together",
354
+ ).withExitCode(128);
355
+ }
356
+ if (o.pickaxeGrep !== undefined && o.pickaxeRegex) {
357
+ throw new GitApiError(
358
+ "fatal: options '-G' and '--pickaxe-regex' cannot be used together, use '--pickaxe-regex' with '-S'",
359
+ ).withExitCode(128);
360
+ }
361
+ if (o.pickaxeAll && (o.findObjects?.length ?? 0) > 0) {
362
+ throw new GitApiError(
363
+ "fatal: options '--pickaxe-all' and '--find-object' cannot be used together, use '--pickaxe-all' with '-G' and '-S'",
364
+ ).withExitCode(128);
365
+ }
366
+ }
367
+
368
+ /** git's status letters `--diff-filter` takes (`diff_status_letters`) */
369
+ const FILTER_LETTERS = "ACDMRTXU*B";
370
+
371
+ /** The bits of `--diff-filter=<letters>` (git's `filter`, `filter_not` folded in) */
372
+ function parseDiffFilter(spec: string): Set<string> {
373
+ const on = new Set<string>();
374
+ const off = new Set<string>();
375
+ for (const c of spec) {
376
+ const upper = c >= "a" && c <= "z" ? c.toUpperCase() : c;
377
+ if (!FILTER_LETTERS.includes(upper) || upper.length !== 1) {
378
+ throw new InvalidArgumentError(
379
+ "diffFilter",
380
+ spec,
381
+ `error: unknown change class '${c}' in --diff-filter=${spec}`,
382
+ ).withExitCode(129);
383
+ }
384
+ (upper === c ? on : off).add(upper);
385
+ }
386
+ // diff_setup_done: a negation alone starts from every bit but `*`
387
+ if (off.size > 0 && on.size === 0) {
388
+ for (const l of FILTER_LETTERS) if (l !== "*") on.add(l);
389
+ }
390
+ for (const l of off) on.delete(l);
391
+ return on;
392
+ }
393
+
394
+ /** git's status letter of a queued entry */
395
+ function statusOf(entry: DiffEntry): string {
396
+ if (entry.unmerged) return "U";
397
+ switch (entry.changeType) {
398
+ case ChangeType.ADD:
399
+ return "A";
400
+ case ChangeType.DELETE:
401
+ return "D";
402
+ case ChangeType.RENAME:
403
+ return "R";
404
+ case ChangeType.COPY:
405
+ return "C";
406
+ default:
407
+ return entry.oldMode !== undefined &&
408
+ entry.newMode !== undefined &&
409
+ (entry.oldMode & S_IFMT) !== (entry.newMode & S_IFMT)
410
+ ? "T"
411
+ : "M";
412
+ }
413
+ }
414
+
415
+ /** diffcore_apply_filter over the queue */
416
+ function applyDiffFilter(entries: DiffEntry[], filter: Set<string> | undefined): DiffEntry[] {
417
+ if (!filter) return entries;
418
+ // match_filter: a modification with a score is a broken pair (-B), which we never make
419
+ const matches = (e: DiffEntry) => filter.has(statusOf(e));
420
+ if (filter.has("*")) return entries.some(matches) ? entries : [];
421
+ return entries.filter(matches);
422
+ }
423
+
424
+ /**
425
+ * diffcore_rotate: the queue from the pair whose (new side's) path is `to`, the ones before
426
+ * it after it (`skip`: dropped); `strict` (`git diff`) needs that exact path, else the first
427
+ * path after it starts, and a path past every pair changes nothing.
428
+ */
429
+ function rotateEntries(entries: DiffEntry[], to: string, skip: boolean, strict: boolean) {
430
+ if (entries.length === 0) return entries;
431
+ let at = 0;
432
+ for (; at < entries.length; at++) {
433
+ const e = entries[at] as DiffEntry;
434
+ const cmp = compareGitPaths(to, e.newPath ?? e.oldPath ?? "");
435
+ if (cmp === 0) break;
436
+ if (!strict && cmp < 0) break;
437
+ }
438
+ if (at >= entries.length) {
439
+ if (strict) throw new GitApiError(`fatal: No such path '${to}' in the diff`);
440
+ return entries;
441
+ }
442
+ return skip ? entries.slice(at) : [...entries.slice(at), ...entries.slice(0, at)];
443
+ }
444
+
445
+ /** strip_prefix: the path without `prefix` and the `/` after it */
446
+ function stripPrefix(path: string, prefix: string): string {
447
+ const rest = path.slice(prefix.length);
448
+ return rest.startsWith("/") ? rest.slice(1) : rest;
191
449
  }
192
450
 
193
451
  /** An entry with its two sides swapped (`diff -R`). */
@@ -382,6 +640,20 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
382
640
  private dirtySubmodules?: boolean;
383
641
  /** `diff.submodule` (its last value git knows), read by the text outputs */
384
642
  private configuredSubmoduleFormat?: SubmoduleDiffFormat;
643
+ /** The colors of the output, read with the diff configuration (or given by `git log`) */
644
+ private colorSettings?: DiffColorSettings;
645
+
646
+ /**
647
+ * The colors already read (`readDiffColorSettings`): `git log` reads them once for all its
648
+ * commits' diffs
649
+ *
650
+ * @internal
651
+ */
652
+ setColorSettings(settings: DiffColorSettings): this {
653
+ this.checkCallable();
654
+ this.colorSettings = settings;
655
+ return this;
656
+ }
385
657
  private readonly configWarnings: string[] = [];
386
658
  /** {@link dirtySubmodules} for the comparison being collected */
387
659
  private dirtyThisCall = true;
@@ -398,6 +670,100 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
398
670
  private temporaryIndex?: Staging;
399
671
  /** Intent-to-add entries are in the index as empty files (plumbing's `diff-index --cached`) */
400
672
  private intentToAddVisible = false;
673
+ /** The index stands for a tree (see {@link setIndexAsTree}) */
674
+ private indexAsTree = false;
675
+ /** `--exit-code` */
676
+ private exitWithStatus = false;
677
+ /** `--quiet` */
678
+ private quiet = false;
679
+ /** `--merge-base` */
680
+ private mergeBase = false;
681
+ /** Whether `--rotate-to`/`--skip-to` need their exact path (`git diff`; not `git log`) */
682
+ private rotateStrict = true;
683
+ /** git's `has_changes` of the last call */
684
+ private changesFound = false;
685
+ /** git's `check_failed`: `--check` found an error in the last call */
686
+ private checkFailed = false;
687
+ /** The revisions given resolved (ranges, `--merge-base`) */
688
+ private sidesResolved = false;
689
+ /** The compiled pickaxe (`-S`, `-G`, `--find-object`), once the options are checked */
690
+ private pickaxe?: DiffPickaxe;
691
+ /**
692
+ * `--find-object`'s `tree_in_recursive`: the subtrees of a diff of two trees, by the side
693
+ * map their blobs go to
694
+ */
695
+ private treeSides?: Map<Map<string, Side>, Map<string, Side>>;
696
+
697
+ /**
698
+ * `--exit-code`: {@link exitCode} is 1 when the diff found differences, as git's status
699
+ * (`diff_result_code`). With whitespace options or `-I`, only pairs whose patch shows a
700
+ * change count (git's `diff_from_contents`).
701
+ */
702
+ setExitCode(exitCode: boolean): this {
703
+ this.checkCallable();
704
+ this.exitWithStatus = exitCode;
705
+ return this;
706
+ }
707
+
708
+ /**
709
+ * `--quiet`: {@link callText} and {@link callBytes} print nothing and {@link exitCode} is
710
+ * 1 when anything differs (`--exit-code`). As git's `quick` flag, the diff stops at its
711
+ * first difference: no rename detection (git 2.5x; see
712
+ * {@link DiffTextOptions.quietDetectsRenames}), no content read past the first pair that
713
+ * shows a change.
714
+ */
715
+ setQuiet(quiet: boolean): this {
716
+ this.checkCallable();
717
+ this.quiet = quiet;
718
+ return this;
719
+ }
720
+
721
+ /**
722
+ * `--merge-base`: diff from the merge base of the old tree and the new one (`git diff
723
+ * --merge-base A B`), or of the old tree and HEAD against the index (`--cached`) or the
724
+ * worktree (`git diff --merge-base A`). Both must be commits with exactly one merge base,
725
+ * else git's `fatal: no merge base found` / `fatal: multiple merge bases found`; a range
726
+ * throws `fatal: --merge-base does not work with ranges`.
727
+ */
728
+ setMergeBase(mergeBase: boolean): this {
729
+ this.checkCallable();
730
+ this.mergeBase = mergeBase;
731
+ return this;
732
+ }
733
+
734
+ /**
735
+ * `--rotate-to`/`--skip-to` take the first path after a missing one, as `git log` does,
736
+ * instead of failing as `git diff` does.
737
+ *
738
+ * @internal
739
+ */
740
+ setRotateStrict(strict: boolean): this {
741
+ this.checkCallable();
742
+ this.rotateStrict = strict;
743
+ return this;
744
+ }
745
+
746
+ /**
747
+ * The exit status `git diff` ends with (`diff_result_code`): bit 1 when `--exit-code` or
748
+ * `--quiet` is set and the last call found differences, bit 2 when its `--check` (the
749
+ * `check` format) found errors.
750
+ */
751
+ get exitCode(): number {
752
+ return (
753
+ ((this.exitWithStatus || this.quiet) && this.changesFound ? 1 : 0) |
754
+ (this.checkFailed ? 2 : 0)
755
+ );
756
+ }
757
+
758
+ /** Whether the last call's `--check` found errors (git's `check_failed`) */
759
+ get checkFoundErrors(): boolean {
760
+ return this.checkFailed;
761
+ }
762
+
763
+ /** Whether the last call found differences (git's `has_changes`) */
764
+ get hasChanges(): boolean {
765
+ return this.changesFound;
766
+ }
401
767
 
402
768
  /**
403
769
  * Show intent-to-add entries in a `--cached` comparison as the empty files they name, as
@@ -415,9 +781,11 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
415
781
  * Set the old (base) tree/commit for comparison.
416
782
  *
417
783
  * 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).
784
+ * If not set, defaults to HEAD (or the index, for the worktree diff). Without a new tree, a
785
+ * range compares two commits as `git diff` does: `A..B` is `A B`, `A...B` diffs B from the
786
+ * merge base of A and B (an empty side is HEAD).
419
787
  *
420
- * @param refOrId Commit-ish or tree ID
788
+ * @param refOrId Commit-ish or tree ID, or a range
421
789
  */
422
790
  setOldTree(refOrId: string): this {
423
791
  this.checkCallable();
@@ -507,6 +875,11 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
507
875
  * `diff.submodule`, its warnings, and the failure of a variable without a value.
508
876
  */
509
877
  private readUiConfig(): void {
878
+ this.colorSettings ??= readDiffColorSettings(
879
+ this.workingCopy,
880
+ this.textOptions,
881
+ this.textOptions.uiConfig !== false,
882
+ );
510
883
  if (this.textOptions.uiConfig === false) return;
511
884
  const { format, warnings } = readDiffSubmoduleConfig(this.workingCopy);
512
885
  this.configuredSubmoduleFormat = format;
@@ -540,6 +913,21 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
540
913
  return this.temporaryIndex ?? super.staging;
541
914
  }
542
915
 
916
+ /**
917
+ * Compares the old tree with `index` taken as a tree, as git's `do_diff_cache` of an index
918
+ * built in memory (`stash show -u`'s worktree and untracked trees): `--cached` against
919
+ * it, with the prefixes of two trees (no mnemonic `c/` and `i/`).
920
+ *
921
+ * @internal
922
+ */
923
+ setIndexAsTree(index: Staging): this {
924
+ this.checkCallable();
925
+ this.temporaryIndex = index;
926
+ this.cached = true;
927
+ this.indexAsTree = true;
928
+ return this;
929
+ }
930
+
543
931
  /**
544
932
  * Filter results to only paths starting with this prefix.
545
933
  *
@@ -602,7 +990,16 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
602
990
  this.checkCallable();
603
991
  this.setCallable(false);
604
992
  this.dirtyThisCall = this.dirtySubmodules ?? true;
605
- return (await this.collect(this.renames ?? false)).entries;
993
+ const run = async () => {
994
+ const { entries } = await this.collect(this.renames ?? false, false, this.pickaxeReads);
995
+ // diffcore_pickaxe, diffcore_apply_filter (the entries stay in path order, unswapped)
996
+ const picked = await this.picked(entries);
997
+ const filter = this.textOptions.diffFilter;
998
+ return applyDiffFilter(picked, filter !== undefined ? parseDiffFilter(filter) : undefined);
999
+ };
1000
+ const out = hasPickaxe(this.textOptions) ? await this.inOneOperation(run) : await run();
1001
+ this.changesFound = out.length > 0;
1002
+ return out;
606
1003
  }
607
1004
 
608
1005
  /**
@@ -624,13 +1021,17 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
624
1021
  this.setCallable(false);
625
1022
  const config = this.config;
626
1023
  const renames = this.renames ?? renamesValue(config.value("diff.renames")) ?? true;
627
- this.dirtyThisCall = this.dirtySubmodules ?? format === "patch";
1024
+ this.dirtyThisCall = this.dirtySubmodules ?? (format === "patch" && !this.quiet);
628
1025
  this.readUiConfig();
629
1026
  return this.inOneOperation(async () => {
1027
+ if (this.quiet) {
1028
+ await this.quietCheck(renames);
1029
+ return new Uint8Array(0);
1030
+ }
630
1031
  const collected = await this.collect(
631
1032
  renames,
632
1033
  format === "patch",
633
- PREFETCH_FORMATS.has(format),
1034
+ PREFETCH_FORMATS.has(format) || this.pickaxeReads,
634
1035
  );
635
1036
  const sink = new ByteSink();
636
1037
  await this.writeFormats(sink, [format], collected);
@@ -638,6 +1039,41 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
638
1039
  });
639
1040
  }
640
1041
 
1042
+ /**
1043
+ * `--quiet` (git's `quick` flag, `DIFF_FORMAT_NO_OUTPUT`): whether anything differs, stopping
1044
+ * early. Without `--diff-filter` and content options the first queued pair answers
1045
+ * (diff_can_quit_early): no renames are detected and no content is read; with content
1046
+ * options (`-w`, `-I`, ...) pairs are diffed until one shows a change (diff_flush's
1047
+ * `diff_flush_patch_quietly` loop).
1048
+ */
1049
+ private async quietCheck(renames: boolean | "copies"): Promise<void> {
1050
+ const fromContents = this.fromContents;
1051
+ const early = this.textOptions.diffFilter === undefined && !fromContents;
1052
+ const detect = !early && (this.textOptions.quietDetectsRenames ?? false);
1053
+ const collected = await this.collect(detect ? renames : false, false, this.pickaxeReads);
1054
+ // diff_can_quit_early: the walk stopped at the first change, which a pickaxe (git 2.43,
1055
+ // whose quiet diff does not look at contents) may then drop
1056
+ const queue = early && this.pickaxe ? collected.entries.slice(0, 1) : collected.entries;
1057
+ const entries = await this.selected(queue);
1058
+ this.changesFound = entries.length > 0;
1059
+ if (!fromContents || entries.length === 0) return;
1060
+ this.changesFound = false;
1061
+ const options = this.outputOptions();
1062
+ Object.assign(options, this.prefixes());
1063
+ for (const entry of entries) {
1064
+ if (entry.unmerged) {
1065
+ this.changesFound = true;
1066
+ break;
1067
+ }
1068
+ const scratch = new ByteSink();
1069
+ await writePairPatch(scratch, diffEntryToPair(entry, this.blobs), options);
1070
+ if (scratch.length > 0) {
1071
+ this.changesFound = true;
1072
+ break;
1073
+ }
1074
+ }
1075
+ }
1076
+
641
1077
  /**
642
1078
  * The diffstat of the comparison, one file per pair in git's order (`compute_diffstat` of
643
1079
  * the diff queue, as a `DIFF_FORMAT_CALLBACK` consumer sees it): an unmerged path as a
@@ -720,7 +1156,7 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
720
1156
  collected = await this.collect(
721
1157
  renames,
722
1158
  formats.includes("patch"),
723
- formats.some((f) => PREFETCH_FORMATS.has(f)),
1159
+ formats.some((f) => PREFETCH_FORMATS.has(f)) || this.pickaxeReads,
724
1160
  );
725
1161
  }
726
1162
  const followed = {
@@ -729,7 +1165,9 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
729
1165
  };
730
1166
  if (collected.entries.length === 0 && collected.combined.length === 0) return followed;
731
1167
  const sink = new ByteSink();
732
- await this.writeFormats(sink, formats, collected);
1168
+ const queued = await this.writeFormats(sink, formats, collected);
1169
+ // diffcore_std left nothing (`--diff-filter`, `--skip-to`): no diff, as an empty one
1170
+ if (queued === 0 && collected.combined.length === 0) return followed;
733
1171
  return { bytes: sink.bytes(), ...followed };
734
1172
  });
735
1173
  }
@@ -783,11 +1221,13 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
783
1221
  sink: ByteSink,
784
1222
  formats: DiffOutputFormat[],
785
1223
  collected: { entries: DiffEntry[]; combined: CombinedEntry[] },
786
- ): Promise<void> {
1224
+ ): Promise<number> {
787
1225
  const config = this.config;
788
1226
  const { combined } = collected;
789
- const ordered = await this.ordered(collected.entries);
790
- const entries = this.textOptions.reverse ? ordered.map(reverseEntry) : ordered;
1227
+ const entries = await this.selected(collected.entries);
1228
+ // diffcore_std's has_changes; with diff_from_contents, what the outputs show (below)
1229
+ const fromContents = this.fromContents;
1230
+ this.changesFound = !fromContents && entries.length > 0;
791
1231
  const options = this.outputOptions();
792
1232
  Object.assign(options, this.prefixes());
793
1233
  if (this.textOptions.reverse) {
@@ -799,6 +1239,9 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
799
1239
  }
800
1240
  const pairs: DiffFilePair[] = [];
801
1241
  const unmerged = new Set<DiffFilePair>();
1242
+ /** The pairs with their full paths, for what git does not shorten (`--summary`) */
1243
+ const fullPairs = new Map<DiffFilePair, DiffFilePair>();
1244
+ const prefix = this.relativePrefix;
802
1245
  for (const entry of entries) {
803
1246
  // an unmerged path: only its name is printed
804
1247
  const pair: DiffFilePair = entry.unmerged
@@ -812,9 +1255,36 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
812
1255
  ),
813
1256
  }
814
1257
  : this.withTextconvInputs(diffEntryToPair(entry, this.blobs), entry);
815
- if (entry.unmerged) unmerged.add(pair);
816
- pairs.push(pair);
1258
+ // strip_prefix: names without the `--relative` prefix, attributes by the full path
1259
+ const shown: DiffFilePair =
1260
+ prefix === undefined
1261
+ ? pair
1262
+ : {
1263
+ ...pair,
1264
+ ...(pair.old
1265
+ ? {
1266
+ old: {
1267
+ ...pair.old,
1268
+ path: stripPrefix(pair.old.path, prefix),
1269
+ attrPath: pair.old.path,
1270
+ },
1271
+ }
1272
+ : {}),
1273
+ ...(pair.new
1274
+ ? {
1275
+ new: {
1276
+ ...pair.new,
1277
+ path: stripPrefix(pair.new.path, prefix),
1278
+ attrPath: pair.new.path,
1279
+ },
1280
+ }
1281
+ : {}),
1282
+ };
1283
+ fullPairs.set(shown, pair);
1284
+ if (entry.unmerged) unmerged.add(shown);
1285
+ pairs.push(shown);
817
1286
  }
1287
+ const full = (pair: DiffFilePair) => fullPairs.get(pair) ?? pair;
818
1288
  const quote = options.quotePath;
819
1289
  const order: DiffOutputFormat[] = [
820
1290
  "name-only",
@@ -841,17 +1311,39 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
841
1311
  for (const c of combined) await this.writeCombined(sink, c, options, combinedLengths);
842
1312
  }
843
1313
  // diff_flush of an empty queue prints nothing
844
- if (pairs.length === 0) return;
1314
+ if (pairs.length === 0) return 0;
1315
+ // diff_setup_done: --check turns the other formats off
1316
+ if (formats.includes("check")) {
1317
+ const check = { conflictMarkerSize: this.conflictMarkerSizeOf() };
1318
+ for (const pair of pairs) {
1319
+ if (unmerged.has(pair)) continue;
1320
+ if (fromContents && this.namesFromContents) {
1321
+ // diff_flush_patch_quietly (git 2.50+): the changes are what the patch shows, and
1322
+ // a pair whose patch shows nothing is not checked
1323
+ const scratch = new ByteSink();
1324
+ await writePairPatch(scratch, pair, options);
1325
+ if (scratch.length === 0) continue;
1326
+ this.changesFound = true;
1327
+ } else if (fromContents) {
1328
+ // git 2.43 checks every pair, and each one checked counts as a change
1329
+ this.changesFound = true;
1330
+ }
1331
+ if (await writePairCheck(sink, pair, options, check)) this.checkFailed = true;
1332
+ }
1333
+ return pairs.length;
1334
+ }
845
1335
  let separator = false;
846
1336
  for (const format of order) {
847
1337
  if (!formats.includes(format)) continue;
848
- if (format === "patch" && separator) sink.text("\n");
1338
+ if (format === "patch" && separator) {
1339
+ sink.text("\n");
1340
+ // attach the patch instead of inlining it
1341
+ if (this.textOptions.statSep) sink.text(this.textOptions.statSep);
1342
+ }
849
1343
  // diff_flush: an empty summary (is_summary_empty) prints nothing and asks no separator
850
1344
  if (format === "summary") {
851
- const text = formatSummary(
852
- pairs.filter((p) => !unmerged.has(p)),
853
- quote,
854
- );
1345
+ // diff_summary names the paths in full, whatever `--relative` says
1346
+ const text = formatSummary(pairs.filter((p) => !unmerged.has(p)).map(full), quote);
855
1347
  if (text) {
856
1348
  sink.text(text);
857
1349
  separator = true;
@@ -878,30 +1370,49 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
878
1370
  // `--abbrev=<n>`: at least n digits
879
1371
  options.abbrevLengths = await this.idAbbreviator().lengths(ids, options.abbrev);
880
1372
  }
1373
+ // diff_flush_patch_all_file_pairs: moved lines are looked for over every pair
1374
+ const moved = this.colorSettings;
1375
+ const out =
1376
+ moved?.colors && moved.colorMoved !== "no"
1377
+ ? new MovedLineBuffer(moved.colorMoved, moved.colorMovedWs)
1378
+ : sink;
881
1379
  for (const pair of pairs) {
1380
+ const before = out.length;
882
1381
  if (unmerged.has(pair)) {
883
- sink.text(`* Unmerged path ${pair.new?.path ?? pair.old?.path}\n`);
884
- } else await writePairPatch(sink, pair, options);
1382
+ out.text(`* Unmerged path ${pair.new?.path ?? pair.old?.path}\n`);
1383
+ } else await writePairPatch(out, pair, options);
1384
+ // builtin_diff's found_changes: the pair showed something
1385
+ if (out.length > before) this.changesFound = true;
1386
+ }
1387
+ if (out instanceof MovedLineBuffer && moved?.colors) {
1388
+ out.flushTo(sink, { colors: moved.colors, wsErrorHighlight: moved.wsErrorHighlight });
885
1389
  }
886
1390
  break;
887
1391
  }
888
- case "name-only":
889
- sink.text(
890
- formatNameOnly(await this.shownNames(pairs, unmerged, options), { quotePath: quote }),
891
- );
1392
+ case "name-only": {
1393
+ const names = await this.shownNames(pairs, unmerged, options);
1394
+ // flush_one_pair: found_changes for each name listed
1395
+ if (names.length > 0) this.changesFound = true;
1396
+ sink.text(formatNameOnly(names, { quotePath: quote }));
892
1397
  break;
893
- case "name-status":
894
- for (const pair of await this.shownNames(pairs, unmerged, options)) {
1398
+ }
1399
+ case "name-status": {
1400
+ const names = await this.shownNames(pairs, unmerged, options);
1401
+ // flush_one_pair: found_changes for each name listed
1402
+ if (names.length > 0) this.changesFound = true;
1403
+ for (const pair of names) {
895
1404
  if (unmerged.has(pair)) {
896
1405
  sink.text(`U\t${quotePath(pair.new?.path ?? pair.old?.path ?? "", quote)}\n`);
897
1406
  } else sink.text(formatNameStatus([pair], { quotePath: quote }));
898
1407
  }
899
1408
  break;
1409
+ }
900
1410
  default: {
901
1411
  const files = [];
902
1412
  for (const pair of pairs) {
903
1413
  if (unmerged.has(pair)) {
904
- const name = pair.new?.path ?? pair.old?.path ?? "";
1414
+ // builtin_diffstat of an unmerged pair: its full path
1415
+ const name = full(pair).new?.path ?? full(pair).old?.path ?? "";
905
1416
  files.push({
906
1417
  name,
907
1418
  isRenamed: false,
@@ -912,11 +1423,14 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
912
1423
  });
913
1424
  } else files.push(...(await computeDiffstat([pair], options)));
914
1425
  }
1426
+ // compute_diffstat: found_changes when the diffstat lists a file
1427
+ if (files.length > 0) this.changesFound = true;
915
1428
  const statOptions: DiffstatOptions = {
916
1429
  nameWidth: intValue(config.value("diff.statNameWidth")),
917
1430
  graphWidth: intValue(config.value("diff.statGraphWidth")),
918
1431
  ...this.textOptions.stat,
919
1432
  quotePath: quote,
1433
+ ...(this.colorSettings?.colors ? { colors: this.colorSettings.colors } : {}),
920
1434
  };
921
1435
  if (format === "stat") sink.text(formatStat(files, statOptions));
922
1436
  else if (format === "numstat") sink.text(formatNumstat(files, { quotePath: quote }));
@@ -924,6 +1438,7 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
924
1438
  }
925
1439
  }
926
1440
  }
1441
+ return pairs.length;
927
1442
  }
928
1443
 
929
1444
  /**
@@ -937,7 +1452,8 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
937
1452
  options: DiffOutputOptions,
938
1453
  format: SubmoduleDiffFormat,
939
1454
  ): Promise<void> {
940
- const path = pair.old?.path ?? pair.new?.path ?? "";
1455
+ // `one->path`: the full path, whatever `--relative` shows
1456
+ const path = pair.old?.attrPath ?? pair.old?.path ?? pair.new?.attrPath ?? pair.new?.path ?? "";
941
1457
  const one = pair.old?.id ?? this.objectFormat.nullId;
942
1458
  const two = pair.new?.id ?? this.objectFormat.nullId;
943
1459
  const dirt = pair.new?.submoduleDirt;
@@ -945,7 +1461,27 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
945
1461
  const abbreviate = (id: ObjectId) => this.idAbbreviator().abbreviate(id);
946
1462
  const workingCopy = this.workingCopy;
947
1463
  if (format === "log") {
948
- sink.text(await showSubmoduleDiffSummary({ workingCopy, path, one, two, dirt, abbreviate }));
1464
+ const text = await showSubmoduleDiffSummary({
1465
+ workingCopy,
1466
+ path,
1467
+ one,
1468
+ two,
1469
+ dirt,
1470
+ abbreviate,
1471
+ });
1472
+ const c = options.colors;
1473
+ if (!c) {
1474
+ sink.text(text);
1475
+ return;
1476
+ }
1477
+ // print_submodule_diff_summary: each commit as diff_emit_submodule_del/_add
1478
+ const lines = text.split("\n");
1479
+ lines.pop();
1480
+ lines.forEach((line, i) => {
1481
+ const kind = i > 0 ? /^ {2}([<>]) /.exec(line)?.[1] : undefined;
1482
+ if (kind) sink.text(`${kind === "<" ? c.old : c.new}${line}${c.reset}\n`);
1483
+ else sink.text(`${line}\n`);
1484
+ });
949
1485
  return;
950
1486
  }
951
1487
  const sub = await openSubmoduleRepository(workingCopy, path);
@@ -969,6 +1505,8 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
969
1505
  .setOldTree(header.left ? one : this.objectFormat.emptyTreeId)
970
1506
  .setSubmoduleFormat("diff")
971
1507
  .setOptions({
1508
+ // the child `git diff --color=always|never` reads the submodule's own color slots
1509
+ color: options.colors !== undefined,
972
1510
  srcPrefix: `${options.srcPrefix ?? "a/"}${path}/`,
973
1511
  dstPrefix: `${options.dstPrefix ?? "b/"}${path}/`,
974
1512
  });
@@ -1063,6 +1601,44 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
1063
1601
  };
1064
1602
  }
1065
1603
 
1604
+ /**
1605
+ * diff.c's textconv_object, as `git show --textconv <rev>:<path>` runs it: the output of
1606
+ * the path's `diff.<driver>.textconv` over the blob as checkout writes it, or undefined
1607
+ * when no textconv applies (not a regular file, no driver, no command or no runner
1608
+ * installed, `textconv: false`). The attributes are the worktree's alone (git show reads
1609
+ * no index).
1610
+ */
1611
+ async textconvBlob(
1612
+ path: string,
1613
+ mode: number,
1614
+ read: () => Promise<Uint8Array>,
1615
+ ): Promise<Uint8Array | undefined> {
1616
+ if ((mode & S_IFMT) !== 0o100000) return undefined;
1617
+ const runner =
1618
+ (this.textOptions.textconv ?? true) ? textconvRunnerOf(this.workingCopy) : undefined;
1619
+ const filter = this.worktreeIfAny?.contentFilter as
1620
+ | {
1621
+ attributes?: (
1622
+ path: string,
1623
+ names?: readonly string[],
1624
+ context?: { direction: "checkin"; index?: AttributesIndex },
1625
+ ) => Promise<Map<string, true | false | string | undefined>>;
1626
+ }
1627
+ | undefined;
1628
+ if (!runner || !filter?.attributes) return undefined;
1629
+ const attrs = await filter.attributes(path, ["diff"], WITHOUT_INDEX_ATTRIBUTES);
1630
+ const driver = diffDriverOf(attrs?.get("diff"), (key) => this.config.value(key));
1631
+ const command = driver?.textconvCommand;
1632
+ if (!driver || command === undefined) return undefined;
1633
+ return runner({
1634
+ driver: driver.name ?? "",
1635
+ command,
1636
+ path,
1637
+ content: await this.smudged(path, mode, read),
1638
+ cache: driver.cacheTextconv ?? false,
1639
+ });
1640
+ }
1641
+
1066
1642
  /** A blob's content as checkout writes it to the worktree (the worktree's smudge filter) */
1067
1643
  private async smudged(
1068
1644
  path: string,
@@ -1075,18 +1651,18 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
1075
1651
  );
1076
1652
  }
1077
1653
 
1078
- /** The pairs `--name-only` lists: with whitespace options, those whose patch shows a change */
1654
+ /** git 2.5x's names from contents (see {@link DiffTextOptions.namesFromContents}) */
1655
+ private get namesFromContents(): boolean {
1656
+ return this.textOptions.namesFromContents ?? true;
1657
+ }
1658
+
1659
+ /** The pairs `--name-only` lists: with whitespace options or `-I`, those whose patch shows a change */
1079
1660
  private async shownNames(
1080
1661
  pairs: DiffFilePair[],
1081
1662
  unmerged: Set<DiffFilePair>,
1082
1663
  options: DiffOutputOptions,
1083
1664
  ): Promise<DiffFilePair[]> {
1084
- const fromContents =
1085
- (this.textOptions.namesFromContents ?? true) &&
1086
- (options.ignoreWhitespace ||
1087
- options.ignoreWhitespaceChange ||
1088
- options.ignoreWhitespaceAtEol ||
1089
- options.ignoreCrAtEol);
1665
+ const fromContents = this.namesFromContents && this.fromContents;
1090
1666
  if (!fromContents) return pairs;
1091
1667
  const shown: DiffFilePair[] = [];
1092
1668
  for (const pair of pairs) {
@@ -1107,7 +1683,7 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
1107
1683
 
1108
1684
  /** What this diff compares */
1109
1685
  private get sides(): DiffSides {
1110
- if (this.newTree) return "trees";
1686
+ if (this.newTree || this.indexAsTree) return "trees";
1111
1687
  if (this.cached) return "cached";
1112
1688
  if (!this.worktreeIfAny) return "trees";
1113
1689
  return this.oldTree ? "commit-worktree" : "index-worktree";
@@ -1245,7 +1821,9 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
1245
1821
  if (!found) {
1246
1822
  found = (async () => {
1247
1823
  const attrs = await filter.attributes?.(path, ["diff"], context);
1248
- return withTextconv(diffDriverOf(attrs?.get("diff"), get));
1824
+ return withTextconv(
1825
+ diffDriverOf(attrs?.get("diff"), get, this.textOptions.driverCompatibility),
1826
+ );
1249
1827
  })();
1250
1828
  drivers.set(path, found);
1251
1829
  }
@@ -1262,8 +1840,34 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
1262
1840
  orderFile: _orderFile,
1263
1841
  textconv: _textconv,
1264
1842
  abbrev: _abbrev,
1843
+ diffFilter: _diffFilter,
1844
+ relative: _relative,
1845
+ rotateTo: _rotateTo,
1846
+ skipTo: _skipTo,
1847
+ ignoreMatchingLines: _ignoreMatchingLines,
1848
+ quietDetectsRenames: _quietDetectsRenames,
1849
+ exitCodeFromContents: _exitCodeFromContents,
1850
+ pickaxeString: _pickaxeString,
1851
+ pickaxeGrep: _pickaxeGrep,
1852
+ findObjects: _findObjects,
1853
+ pickaxeRegex: _pickaxeRegex,
1854
+ pickaxeAll: _pickaxeAll,
1855
+ pickaxeIgnoreCase: _pickaxeIgnoreCase,
1856
+ color: _color,
1857
+ colorMoved: _colorMoved,
1858
+ colorMovedWs: _colorMovedWs,
1859
+ wsErrorHighlight: _wsErrorHighlight,
1860
+ colorCompatibility: _colorCompatibility,
1861
+ driverCompatibility: _driverCompatibility,
1265
1862
  ...text
1266
1863
  } = this.textOptions;
1864
+ const colorSettings = this.colorSettings;
1865
+ // git_default_core_config: a core.whitespace git cannot parse dies in every diff
1866
+ const whitespaceRule = this.whitespaceRuleOf(filter, context);
1867
+ const colors = colorSettings?.colors
1868
+ ? { colors: colorSettings.colors, wsHighlight: colorSettings.wsErrorHighlight }
1869
+ : {};
1870
+ const ignoreRegex = this.ignoreRegex();
1267
1871
  const abbrev = abbrevOption(this.textOptions.abbrev);
1268
1872
  return {
1269
1873
  context: intValue(get("diff.context")) ?? 3,
@@ -1277,9 +1881,188 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
1277
1881
  algorithm: text.algorithm ?? algorithmValue(get("diff.algorithm")) ?? "myers",
1278
1882
  indentHeuristic: text.indentHeuristic ?? boolValue(get("diff.indentHeuristic")) ?? true,
1279
1883
  ...(driver ? { driver } : {}),
1884
+ ...(ignoreRegex.length > 0 ? { ignoreRegex } : {}),
1885
+ ...colors,
1886
+ ...(get("diff.wordRegex") !== undefined
1887
+ ? { defaultWordRegex: get("diff.wordRegex") as string }
1888
+ : {}),
1889
+ whitespaceRule,
1890
+ };
1891
+ }
1892
+
1893
+ /** `ll_merge_marker_size`: each path's `conflict-marker-size` attribute */
1894
+ private conflictMarkerSizeOf(): (path: string) => Promise<number> {
1895
+ const filter = this.worktreeIfAny?.contentFilter as
1896
+ | {
1897
+ attributes?: (
1898
+ path: string,
1899
+ names?: readonly string[],
1900
+ context?: { direction: "checkin"; index?: AttributesIndex },
1901
+ ) => Promise<Map<string, true | false | string | undefined>>;
1902
+ }
1903
+ | undefined;
1904
+ const context = this.newTree !== undefined ? WITHOUT_INDEX_ATTRIBUTES : undefined;
1905
+ return async (path: string) => {
1906
+ const attrs = await filter?.attributes?.(path, ["conflict-marker-size"], context);
1907
+ return conflictMarkerSizeOf(attrs?.get("conflict-marker-size") ?? undefined, (m) =>
1908
+ this.configWarnings.push(`warning: ${m}`),
1909
+ );
1280
1910
  };
1281
1911
  }
1282
1912
 
1913
+ /**
1914
+ * ws.c's `whitespace_rule`: the `whitespace` attribute of a path over `core.whitespace`
1915
+ * (git 2.43 knows no `incomplete-line` rule)
1916
+ */
1917
+ private whitespaceRuleOf(
1918
+ filter:
1919
+ | {
1920
+ attributes?: (
1921
+ path: string,
1922
+ names?: readonly string[],
1923
+ context?: { direction: "checkin"; index?: AttributesIndex },
1924
+ ) => Promise<Map<string, true | false | string | undefined>>;
1925
+ }
1926
+ | undefined,
1927
+ context: { direction: "checkin"; index: AttributesIndex } | undefined,
1928
+ ): (path: string) => Promise<number> {
1929
+ const legacy = this.textOptions.colorCompatibility === "2.43";
1930
+ const mask = legacy ? ~WS_INCOMPLETE_LINE : ~0;
1931
+ const parse = (value: string) => {
1932
+ try {
1933
+ return parseWhitespaceRule(
1934
+ value,
1935
+ undefined,
1936
+ legacy ? { compatibility: "2.43" } : undefined,
1937
+ );
1938
+ } catch (e) {
1939
+ throw whitespaceRuleError((e as Error).message);
1940
+ }
1941
+ };
1942
+ const core = this.config.value("core.whitespace");
1943
+ const configRule = core === undefined ? WS_DEFAULT_RULE : parse(core);
1944
+ const rules = new Map<string, Promise<number>>();
1945
+ return (path: string) => {
1946
+ let found = rules.get(path);
1947
+ if (!found) {
1948
+ found = (async () => {
1949
+ const attrs = await filter?.attributes?.(path, ["whitespace"], context);
1950
+ const attr = attrs?.get("whitespace");
1951
+ if (typeof attr === "string") return parse(attr) & mask;
1952
+ return whitespaceRuleOf(attr ?? undefined, configRule) & mask;
1953
+ })();
1954
+ rules.set(path, found);
1955
+ }
1956
+ return found;
1957
+ };
1958
+ }
1959
+
1960
+ /** `-I<regex>` compiled as git's `regcomp(REG_EXTENDED | REG_NEWLINE)` */
1961
+ private ignoreRegex(): PosixRegex[] {
1962
+ return (this.textOptions.ignoreMatchingLines ?? []).map((pattern) => {
1963
+ try {
1964
+ return compilePosixRegex(pattern, { extended: true, newline: true });
1965
+ } catch {
1966
+ throw new InvalidArgumentError(
1967
+ "ignoreMatchingLines",
1968
+ pattern,
1969
+ `error: invalid regex given to -I: '${pattern}'`,
1970
+ ).withExitCode(129);
1971
+ }
1972
+ });
1973
+ }
1974
+
1975
+ /**
1976
+ * git's `diff_from_contents`: whitespace options and `-I` (and, in git 2.5x, an exit status
1977
+ * asked for) make a pair count as a change only when its output shows one
1978
+ */
1979
+ private get fromContents(): boolean {
1980
+ const o = this.textOptions;
1981
+ // diff_setup_done (git 2.5x): porcelain diff allows external diffs, so an exit status
1982
+ // asked for (`--exit-code`, `--quiet`) always looks at the contents
1983
+ if ((this.exitWithStatus || this.quiet) && (o.exitCodeFromContents ?? true)) return true;
1984
+ return !!(
1985
+ o.ignoreWhitespace ||
1986
+ o.ignoreWhitespaceChange ||
1987
+ o.ignoreWhitespaceAtEol ||
1988
+ o.ignoreCrAtEol ||
1989
+ (o.ignoreMatchingLines?.length ?? 0) > 0
1990
+ );
1991
+ }
1992
+
1993
+ /**
1994
+ * The queue diffcore_std leaves of the collected entries: in `-O` order, swapped by `-R`,
1995
+ * rotated (`--rotate-to`, `--skip-to`), filtered (`--diff-filter`)
1996
+ */
1997
+ private async selected(entries: DiffEntry[]): Promise<DiffEntry[]> {
1998
+ const ordered = await this.ordered(await this.picked(entries));
1999
+ let out = this.textOptions.reverse ? ordered.map(reverseEntry) : ordered;
2000
+ const { rotateTo, skipTo } = this.textOptions;
2001
+ // diff_opt_rotate_to: the last of the two given wins
2002
+ if (skipTo !== undefined) out = rotateEntries(out, skipTo, true, this.rotateStrict);
2003
+ else if (rotateTo !== undefined) out = rotateEntries(out, rotateTo, false, this.rotateStrict);
2004
+ const filter = this.textOptions.diffFilter;
2005
+ return applyDiffFilter(out, filter !== undefined ? parseDiffFilter(filter) : undefined);
2006
+ }
2007
+
2008
+ /**
2009
+ * diffcore_std's prefetch condition: any pickaxe kind (`DIFF_PICKAXE_KINDS_MASK`,
2010
+ * `--find-object` included) fetches a partial clone's absent blobs of the queue in one
2011
+ * batch before rename detection
2012
+ */
2013
+ private get pickaxeReads(): boolean {
2014
+ return hasPickaxe(this.textOptions);
2015
+ }
2016
+
2017
+ /** diffcore_pickaxe over the queue (after rename detection, before `-O` and the filter) */
2018
+ private async picked(entries: DiffEntry[]): Promise<DiffEntry[]> {
2019
+ const pickaxe = this.pickaxe;
2020
+ if (!pickaxe) return entries;
2021
+ const options = this.outputOptions();
2022
+ return pickaxe.filter(
2023
+ entries,
2024
+ (e) => (e.unmerged ? undefined : this.withTextconvInputs(diffEntryToPair(e, this.blobs), e)),
2025
+ options,
2026
+ );
2027
+ }
2028
+
2029
+ /**
2030
+ * The pickaxe of the options (checked, compiled, `--find-object`'s revisions resolved),
2031
+ * before anything else is read
2032
+ */
2033
+ private async preparePickaxe(): Promise<void> {
2034
+ const o = this.textOptions;
2035
+ if (this.pickaxe || !hasPickaxe(o)) return;
2036
+ checkPickaxeOptions(o);
2037
+ let objects: Set<string> | undefined;
2038
+ if (o.findObjects && o.findObjects.length > 0) {
2039
+ objects = new Set();
2040
+ for (const name of o.findObjects) {
2041
+ const id = this.isFullObjectId(name)
2042
+ ? name.toLowerCase()
2043
+ : await this.revisionResolver()
2044
+ .resolve(name)
2045
+ .catch(() => undefined);
2046
+ if (id === undefined) {
2047
+ throw new InvalidArgumentError(
2048
+ "findObjects",
2049
+ name,
2050
+ `error: unable to resolve '${name}'`,
2051
+ ).withExitCode(129);
2052
+ }
2053
+ objects.add(id);
2054
+ }
2055
+ }
2056
+ this.pickaxe = DiffPickaxe.compile({
2057
+ ...(o.pickaxeString !== undefined ? { string: o.pickaxeString } : {}),
2058
+ ...(o.pickaxeGrep !== undefined ? { grep: o.pickaxeGrep } : {}),
2059
+ ...(objects ? { objects } : {}),
2060
+ regex: o.pickaxeRegex ?? false,
2061
+ all: o.pickaxeAll ?? false,
2062
+ ignoreCase: o.pickaxeIgnoreCase ?? false,
2063
+ });
2064
+ }
2065
+
1283
2066
  /**
1284
2067
  * The changed paths (and renames, when asked), in git's order, and the conflicted paths
1285
2068
  * `git diff` shows as combined diffs (`patch`: the patch format, where a path with both
@@ -1291,6 +2074,11 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
1291
2074
  patch = false,
1292
2075
  prefetch = false,
1293
2076
  ): Promise<{ entries: DiffEntry[]; combined: CombinedEntry[] }> {
2077
+ // option parsing fails before anything is read
2078
+ if (this.textOptions.diffFilter !== undefined) parseDiffFilter(this.textOptions.diffFilter);
2079
+ this.ignoreRegex();
2080
+ await this.preparePickaxe();
2081
+ await this.resolveRevisions();
1294
2082
  // repo_read_index: in a sparse checkout, a skip-worktree entry whose file is present is
1295
2083
  // read as in the checkout (in memory: diff writes no index)
1296
2084
  await this.clearPresentSkipWorktree();
@@ -1325,6 +2113,7 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
1325
2113
  const unmerged = new Map<string, DiffEntry[]>();
1326
2114
  const combined: CombinedEntry[] = [];
1327
2115
  if (this.newTree) {
2116
+ if (this.pickaxe && !this.pickaxe.readsContent) this.treeSides = new Map();
1328
2117
  [oldSide, newSide] = await this.treePairSides(
1329
2118
  this.oldTree ?? "HEAD",
1330
2119
  this.oldTree === undefined,
@@ -1387,7 +2176,147 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
1387
2176
  // one batch first (diff_queued_diff_prefetch), before rename detection
1388
2177
  if (prefetch) await this.blobs.prefetch?.(prefetchIds(entries));
1389
2178
  if (renames) await this.detectRenames(entries, renames === "copies");
1390
- return { entries, combined };
2179
+ return { entries: this.withTreeEntries(entries, oldSide, newSide), combined };
2180
+ }
2181
+
2182
+ /**
2183
+ * `--find-object`'s tree_in_recursive: the changed subtrees of a diff of two trees among
2184
+ * the blob pairs, each before what lies below it (the tree walk's order: `a/` sorts after
2185
+ * `a.txt`); they take no part in rename detection
2186
+ */
2187
+ private withTreeEntries(
2188
+ entries: DiffEntry[],
2189
+ oldSide: Map<string, Side>,
2190
+ newSide: Map<string, Side>,
2191
+ ): DiffEntry[] {
2192
+ const sides = this.treeSides;
2193
+ if (!sides) return entries;
2194
+ this.treeSides = undefined;
2195
+ const trees = this.pairUp(
2196
+ sides.get(oldSide) ?? new Map(),
2197
+ sides.get(newSide) ?? new Map(),
2198
+ new Map(),
2199
+ );
2200
+ if (trees.length === 0) return entries;
2201
+ const keyOf = (e: DiffEntry) => e.newPath ?? e.oldPath ?? "";
2202
+ const treeKey = (e: DiffEntry) => `${e.newPath ?? e.oldPath ?? ""}/`;
2203
+ const out: DiffEntry[] = [];
2204
+ let t = 0;
2205
+ for (const e of entries) {
2206
+ const key = keyOf(e);
2207
+ while (t < trees.length && compareBytes(treeKey(trees[t] as DiffEntry), key) < 0) {
2208
+ out.push(trees[t++] as DiffEntry);
2209
+ }
2210
+ out.push(e);
2211
+ }
2212
+ while (t < trees.length) out.push(trees[t++] as DiffEntry);
2213
+ return out;
2214
+ }
2215
+
2216
+ /**
2217
+ * builtin/diff.c's revision handling: `A..B` is `A B`, `A...B` the merge base of A and B
2218
+ * against B (symdiff_prepare: the first base, with git's warning when there are several),
2219
+ * `--merge-base` the merge base of the two sides (diff_get_merge_base); an empty side of a
2220
+ * range is HEAD.
2221
+ */
2222
+ private async resolveRevisions(): Promise<void> {
2223
+ if (this.sidesResolved) return;
2224
+ this.sidesResolved = true;
2225
+ const old = this.oldTree;
2226
+ const range =
2227
+ old !== undefined && this.newTree === undefined && !old.includes(":")
2228
+ ? /^(.*?)(\.\.\.?)(.*)$/s.exec(old)
2229
+ : null;
2230
+ if (range) {
2231
+ if (this.mergeBase) throw new GitApiError("fatal: --merge-base does not work with ranges");
2232
+ const left = range[1] || "HEAD";
2233
+ const right = range[3] || "HEAD";
2234
+ if (range[2] === "..") {
2235
+ this.oldTree = left;
2236
+ this.newTree = right;
2237
+ return;
2238
+ }
2239
+ const errors: string[] = [];
2240
+ const a = await this.commitOf(left, errors, old);
2241
+ const b = await this.commitOf(right, errors, old);
2242
+ if (a === undefined || b === undefined) {
2243
+ throw new GitApiError(
2244
+ [...errors, `fatal: Invalid symmetric difference expression ${old}`].join("\n"),
2245
+ );
2246
+ }
2247
+ const bases = await revisionMergeBases(this.commits, a, b);
2248
+ const base = bases[0];
2249
+ if (base === undefined) throw new GitApiError(`fatal: ${left}...${right}: no merge base`);
2250
+ if (bases.length > 1) {
2251
+ this.configWarnings.push(
2252
+ `warning: ${left}...${right}: multiple merge bases, using ${base}`,
2253
+ );
2254
+ }
2255
+ this.oldTree = base;
2256
+ this.newTree = b;
2257
+ return;
2258
+ }
2259
+ if (!this.mergeBase) return;
2260
+ // `git diff --cached --merge-base`: HEAD, the default of --cached
2261
+ if (old === undefined && this.cached) this.oldTree = "HEAD";
2262
+ if (this.oldTree === undefined) {
2263
+ throw new InvalidArgumentError(
2264
+ "mergeBase",
2265
+ true,
2266
+ "error: invalid option: --merge-base",
2267
+ ).withExitCode(129);
2268
+ }
2269
+ const errors: string[] = [];
2270
+ const a = await this.commitOf(this.oldTree, errors);
2271
+ let b: ObjectId | undefined;
2272
+ if (this.newTree !== undefined) b = await this.commitOf(this.newTree, errors);
2273
+ else {
2274
+ let head: ObjectId;
2275
+ try {
2276
+ head = await this.resolveRevision("HEAD");
2277
+ } catch {
2278
+ throw new GitApiError("fatal: unable to get HEAD");
2279
+ }
2280
+ b = await this.commitOf(head, errors);
2281
+ }
2282
+ const bases =
2283
+ a !== undefined && b !== undefined ? await revisionMergeBases(this.commits, a, b) : [];
2284
+ if (bases.length === 0) {
2285
+ throw new GitApiError([...errors, "fatal: no merge base found"].join("\n"));
2286
+ }
2287
+ if (bases.length > 1) throw new GitApiError("fatal: multiple merge bases found");
2288
+ this.oldTree = bases[0];
2289
+ }
2290
+
2291
+ /**
2292
+ * lookup_commit_reference of a revision: the commit it names (tags peeled); for another
2293
+ * object git's `error: object <id> is a <type>, not a commit` goes to `errors`. A name that
2294
+ * resolves to nothing throws git's `ambiguous argument` (of the whole `argument`).
2295
+ */
2296
+ private async commitOf(
2297
+ name: string,
2298
+ errors: string[],
2299
+ argument = name,
2300
+ ): Promise<ObjectId | undefined> {
2301
+ let id: ObjectId;
2302
+ try {
2303
+ id = await this.resolveRevision(name);
2304
+ } catch (e) {
2305
+ if (e instanceof RefNotFoundError || e instanceof NoHeadError) {
2306
+ // setup_revisions: an argument that names no revision (nor a path)
2307
+ throw new RefNotFoundError(
2308
+ argument,
2309
+ `fatal: ambiguous argument '${argument}': unknown revision or path not in the working tree.`,
2310
+ );
2311
+ }
2312
+ throw e;
2313
+ }
2314
+ const peeled = await this.revisionResolver().peelTags(id);
2315
+ if (peeled.type === "commit") return peeled.id;
2316
+ if (peeled.type !== undefined) {
2317
+ errors.push(`error: object ${peeled.id} is a ${peeled.type}, not a commit`);
2318
+ }
2319
+ return undefined;
1391
2320
  }
1392
2321
 
1393
2322
  /**
@@ -1472,8 +2401,17 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
1472
2401
  ];
1473
2402
  }
1474
2403
 
2404
+ /** The `--relative=<path>` prefix paths are limited to and shown without */
2405
+ private get relativePrefix(): string | undefined {
2406
+ const relative = this.textOptions.relative;
2407
+ return typeof relative === "string" && relative !== "" ? relative : undefined;
2408
+ }
2409
+
1475
2410
  private matches(path: string): boolean {
1476
2411
  if (this.pathFilter && !path.startsWith(this.pathFilter)) return false;
2412
+ // diff_queue_addremove / diff_change / diff_unmerge: outside the prefix, nothing is queued
2413
+ const prefix = this.relativePrefix;
2414
+ if (prefix !== undefined && !path.startsWith(prefix)) return false;
1477
2415
  return !this.pathspecItems || matchPathspec(this.pathspecItems, path, 0) > 0;
1478
2416
  }
1479
2417
 
@@ -1734,6 +2672,8 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
1734
2672
  if (xe.id === ye.id && xe.mode === ye.mode) continue;
1735
2673
  const path = prefix ? `${prefix}/${xe.name}` : xe.name;
1736
2674
  if (isTreeMode(xe.mode) && isTreeMode(ye.mode)) {
2675
+ this.addTreeSide(path, xe.mode, xe.id, oldSide);
2676
+ this.addTreeSide(path, ye.mode, ye.id, newSide);
1737
2677
  await this.diffTreeSides(xe.id, ye.id, path, oldSide, newSide);
1738
2678
  continue;
1739
2679
  }
@@ -1774,8 +2714,11 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
1774
2714
  } else {
1775
2715
  if (!x.sameAs(y)) {
1776
2716
  const path = pathOf(x.name());
1777
- if (x.isTree && y.isTree) await this.diffRawTrees(x.id(), y.id(), path, oldSide, newSide);
1778
- else {
2717
+ if (x.isTree && y.isTree) {
2718
+ this.addTreeSide(path, x.mode, x.id(), oldSide);
2719
+ this.addTreeSide(path, y.mode, y.id(), newSide);
2720
+ await this.diffRawTrees(x.id(), y.id(), path, oldSide, newSide);
2721
+ } else {
1779
2722
  await this.addRawSide(x, path, oldSide);
1780
2723
  await this.addRawSide(y, path, newSide);
1781
2724
  }
@@ -1792,14 +2735,30 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
1792
2735
  path: string,
1793
2736
  side: Map<string, Side>,
1794
2737
  ): Promise<void> {
1795
- if (c.isTree) await this.collectTreeEntries(c.id(), path, side);
1796
- else side.set(path, { mode: c.mode, id: c.id() });
2738
+ if (c.isTree) {
2739
+ this.addTreeSide(path, c.mode, c.id(), side);
2740
+ await this.collectTreeEntries(c.id(), path, side);
2741
+ } else side.set(path, { mode: c.mode, id: c.id() });
1797
2742
  }
1798
2743
 
1799
2744
  /** A tree entry on one side: a blob as itself, a subtree as its blobs */
1800
2745
  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 });
2746
+ if (isTreeMode(e.mode)) {
2747
+ this.addTreeSide(path, e.mode, e.id, side);
2748
+ await this.collectTreeEntries(e.id, path, side);
2749
+ } else side.set(path, { mode: e.mode, id: e.id });
2750
+ }
2751
+
2752
+ /** A subtree on one side, kept for `--find-object` (see {@link withTreeEntries}) */
2753
+ private addTreeSide(path: string, mode: number, id: ObjectId, side: Map<string, Side>): void {
2754
+ const sides = this.treeSides;
2755
+ if (!sides) return;
2756
+ let trees = sides.get(side);
2757
+ if (!trees) {
2758
+ trees = new Map();
2759
+ sides.set(side, trees);
2760
+ }
2761
+ trees.set(path, { mode, id });
1803
2762
  }
1804
2763
 
1805
2764
  /**
@@ -2001,6 +2960,7 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
2001
2960
  for (const entry of await this.treeEntries(treeId)) {
2002
2961
  const path = prefix ? `${prefix}/${entry.name}` : entry.name;
2003
2962
  if ((entry.mode & S_IFMT) === TREE_MODE) {
2963
+ this.addTreeSide(path, entry.mode, entry.id, entries);
2004
2964
  await this.collectTreeEntries(entry.id, path, entries);
2005
2965
  } else {
2006
2966
  // the mode as git's tree walk reads it (canon_mode), as the tree store reads it