@statewalker/vcs-commands 0.6.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 (481) 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/bisect/bisect-engine.d.ts.map +1 -1
  15. package/dist/commands/branch-command.d.ts +148 -18
  16. package/dist/commands/branch-command.d.ts.map +1 -1
  17. package/dist/commands/branch-info-command.d.ts +55 -0
  18. package/dist/commands/branch-info-command.d.ts.map +1 -0
  19. package/dist/commands/branch-tracking.d.ts +106 -17
  20. package/dist/commands/branch-tracking.d.ts.map +1 -1
  21. package/dist/commands/branch-upstream-command.d.ts +83 -0
  22. package/dist/commands/branch-upstream-command.d.ts.map +1 -0
  23. package/dist/commands/checkout-command.d.ts +19 -3
  24. package/dist/commands/checkout-command.d.ts.map +1 -1
  25. package/dist/commands/cherry-pick-command.d.ts +59 -0
  26. package/dist/commands/cherry-pick-command.d.ts.map +1 -1
  27. package/dist/commands/clean-command.d.ts +12 -0
  28. package/dist/commands/clean-command.d.ts.map +1 -1
  29. package/dist/commands/clone-command.d.ts +17 -0
  30. package/dist/commands/clone-command.d.ts.map +1 -1
  31. package/dist/commands/comment-char-config.d.ts +35 -0
  32. package/dist/commands/comment-char-config.d.ts.map +1 -0
  33. package/dist/commands/commit-command.d.ts +191 -5
  34. package/dist/commands/commit-command.d.ts.map +1 -1
  35. package/dist/commands/commit-reuse.d.ts +33 -0
  36. package/dist/commands/commit-reuse.d.ts.map +1 -0
  37. package/dist/commands/config-command.d.ts +236 -0
  38. package/dist/commands/config-command.d.ts.map +1 -0
  39. package/dist/commands/config-value-types.d.ts +91 -0
  40. package/dist/commands/config-value-types.d.ts.map +1 -0
  41. package/dist/commands/core-config.d.ts +20 -0
  42. package/dist/commands/core-config.d.ts.map +1 -1
  43. package/dist/commands/default-branch.d.ts +70 -0
  44. package/dist/commands/default-branch.d.ts.map +1 -0
  45. package/dist/commands/diff-color-config.d.ts +73 -0
  46. package/dist/commands/diff-color-config.d.ts.map +1 -0
  47. package/dist/commands/diff-command.d.ts +252 -5
  48. package/dist/commands/diff-command.d.ts.map +1 -1
  49. package/dist/commands/fetch-command.d.ts +20 -0
  50. package/dist/commands/fetch-command.d.ts.map +1 -1
  51. package/dist/commands/fmt-merge-msg-command.d.ts +124 -0
  52. package/dist/commands/fmt-merge-msg-command.d.ts.map +1 -0
  53. package/dist/commands/fork-point.d.ts +38 -0
  54. package/dist/commands/fork-point.d.ts.map +1 -0
  55. package/dist/commands/format-patch-command.d.ts +41 -1
  56. package/dist/commands/format-patch-command.d.ts.map +1 -1
  57. package/dist/commands/fsck/fetch-fsck.d.ts +51 -0
  58. package/dist/commands/fsck/fetch-fsck.d.ts.map +1 -1
  59. package/dist/commands/fsck/fsck-command.d.ts +2 -0
  60. package/dist/commands/fsck/fsck-command.d.ts.map +1 -1
  61. package/dist/commands/fsck/fsck-loose.d.ts +3 -0
  62. package/dist/commands/fsck/fsck-loose.d.ts.map +1 -1
  63. package/dist/commands/fsck/fsck-object-checks.d.ts +25 -14
  64. package/dist/commands/fsck/fsck-object-checks.d.ts.map +1 -1
  65. package/dist/commands/fsck/fsck-object-table.d.ts +15 -7
  66. package/dist/commands/fsck/fsck-object-table.d.ts.map +1 -1
  67. package/dist/commands/fsck/fsck-pack.d.ts +11 -4
  68. package/dist/commands/fsck/fsck-pack.d.ts.map +1 -1
  69. package/dist/commands/fsck/verify-pack-command.d.ts.map +1 -1
  70. package/dist/commands/gc-command.d.ts +80 -48
  71. package/dist/commands/gc-command.d.ts.map +1 -1
  72. package/dist/commands/git-date.d.ts +1 -65
  73. package/dist/commands/git-date.d.ts.map +1 -1
  74. package/dist/commands/git-describe.d.ts +4 -0
  75. package/dist/commands/git-describe.d.ts.map +1 -1
  76. package/dist/commands/git-hooks.d.ts +43 -0
  77. package/dist/commands/git-hooks.d.ts.map +1 -1
  78. package/dist/commands/grep/grep-command.d.ts +210 -0
  79. package/dist/commands/grep/grep-command.d.ts.map +1 -0
  80. package/dist/commands/grep/grep-engine.d.ts +218 -0
  81. package/dist/commands/grep/grep-engine.d.ts.map +1 -0
  82. package/dist/commands/grep/index.d.ts +3 -0
  83. package/dist/commands/grep/index.d.ts.map +1 -0
  84. package/dist/commands/index-adder.d.ts +15 -2
  85. package/dist/commands/index-adder.d.ts.map +1 -1
  86. package/dist/commands/index.d.ts +28 -0
  87. package/dist/commands/index.d.ts.map +1 -1
  88. package/dist/commands/index.js +3 -3
  89. package/dist/commands/init-command.d.ts +50 -3
  90. package/dist/commands/init-command.d.ts.map +1 -1
  91. package/dist/commands/interpret-trailers-command.d.ts +90 -0
  92. package/dist/commands/interpret-trailers-command.d.ts.map +1 -0
  93. package/dist/commands/legacy-remotes.d.ts +55 -0
  94. package/dist/commands/legacy-remotes.d.ts.map +1 -0
  95. package/dist/commands/local-transport.d.ts +36 -5
  96. package/dist/commands/local-transport.d.ts.map +1 -1
  97. package/dist/commands/log-command.d.ts +296 -11
  98. package/dist/commands/log-command.d.ts.map +1 -1
  99. package/dist/commands/log-graph.d.ts +26 -1
  100. package/dist/commands/log-graph.d.ts.map +1 -1
  101. package/dist/commands/log-output.d.ts +133 -5
  102. package/dist/commands/log-output.d.ts.map +1 -1
  103. package/dist/commands/ls-remote-command.d.ts +2 -0
  104. package/dist/commands/ls-remote-command.d.ts.map +1 -1
  105. package/dist/commands/mailmap.d.ts +30 -0
  106. package/dist/commands/mailmap.d.ts.map +1 -1
  107. package/dist/commands/merge-base-command.d.ts +60 -0
  108. package/dist/commands/merge-base-command.d.ts.map +1 -0
  109. package/dist/commands/merge-bases.d.ts +23 -0
  110. package/dist/commands/merge-bases.d.ts.map +1 -1
  111. package/dist/commands/merge-command.d.ts +108 -9
  112. package/dist/commands/merge-command.d.ts.map +1 -1
  113. package/dist/commands/merge-support.d.ts +11 -3
  114. package/dist/commands/merge-support.d.ts.map +1 -1
  115. package/dist/commands/mv-command.d.ts +4 -0
  116. package/dist/commands/mv-command.d.ts.map +1 -1
  117. package/dist/commands/name-rev.d.ts +48 -0
  118. package/dist/commands/name-rev.d.ts.map +1 -0
  119. package/dist/commands/notes-command.d.ts.map +1 -1
  120. package/dist/commands/notes-merge-command.d.ts.map +1 -1
  121. package/dist/commands/notes-tree.d.ts +11 -1
  122. package/dist/commands/notes-tree.d.ts.map +1 -1
  123. package/dist/commands/patch-id.d.ts +3 -0
  124. package/dist/commands/patch-id.d.ts.map +1 -1
  125. package/dist/commands/pathspec-file.d.ts +39 -0
  126. package/dist/commands/pathspec-file.d.ts.map +1 -0
  127. package/dist/commands/pathspec.d.ts +3 -0
  128. package/dist/commands/pathspec.d.ts.map +1 -1
  129. package/dist/commands/pretty-format.d.ts +43 -3
  130. package/dist/commands/pretty-format.d.ts.map +1 -1
  131. package/dist/commands/promisor-remote.d.ts.map +1 -1
  132. package/dist/commands/pull-command.d.ts +28 -0
  133. package/dist/commands/pull-command.d.ts.map +1 -1
  134. package/dist/commands/push-command.d.ts +160 -9
  135. package/dist/commands/push-command.d.ts.map +1 -1
  136. package/dist/commands/read-tree-command.d.ts +6 -0
  137. package/dist/commands/read-tree-command.d.ts.map +1 -1
  138. package/dist/commands/rebase-command.d.ts +168 -6
  139. package/dist/commands/rebase-command.d.ts.map +1 -1
  140. package/dist/commands/ref-filter/for-each-ref-command.d.ts +121 -0
  141. package/dist/commands/ref-filter/for-each-ref-command.d.ts.map +1 -0
  142. package/dist/commands/ref-filter/index.d.ts +8 -0
  143. package/dist/commands/ref-filter/index.d.ts.map +1 -0
  144. package/dist/commands/ref-filter/ref-atoms.d.ts +88 -0
  145. package/dist/commands/ref-filter/ref-atoms.d.ts.map +1 -0
  146. package/dist/commands/ref-filter/ref-filter.d.ts +178 -0
  147. package/dist/commands/ref-filter/ref-filter.d.ts.map +1 -0
  148. package/dist/commands/ref-filter/ref-format.d.ts +222 -0
  149. package/dist/commands/ref-filter/ref-format.d.ts.map +1 -0
  150. package/dist/commands/ref-filter/ref-listing-command.d.ts +56 -0
  151. package/dist/commands/ref-filter/ref-listing-command.d.ts.map +1 -0
  152. package/dist/commands/ref-filter/ref-quote.d.ts +20 -0
  153. package/dist/commands/ref-filter/ref-quote.d.ts.map +1 -0
  154. package/dist/commands/ref-filter/version-compare.d.ts +20 -0
  155. package/dist/commands/ref-filter/version-compare.d.ts.map +1 -0
  156. package/dist/commands/reflog-command.d.ts +120 -0
  157. package/dist/commands/reflog-command.d.ts.map +1 -1
  158. package/dist/commands/reflog-walk.d.ts +72 -0
  159. package/dist/commands/reflog-walk.d.ts.map +1 -0
  160. package/dist/commands/remote-command.d.ts +138 -29
  161. package/dist/commands/remote-command.d.ts.map +1 -1
  162. package/dist/commands/remote-transport.d.ts +7 -1
  163. package/dist/commands/remote-transport.d.ts.map +1 -1
  164. package/dist/commands/reset-command.d.ts +2 -3
  165. package/dist/commands/reset-command.d.ts.map +1 -1
  166. package/dist/commands/restore-command.d.ts +2 -3
  167. package/dist/commands/restore-command.d.ts.map +1 -1
  168. package/dist/commands/rev-filter/commit-filter.d.ts +95 -0
  169. package/dist/commands/rev-filter/commit-filter.d.ts.map +1 -0
  170. package/dist/commands/rev-filter/commit-grep.d.ts +91 -0
  171. package/dist/commands/rev-filter/commit-grep.d.ts.map +1 -0
  172. package/dist/commands/rev-filter/index.d.ts +3 -0
  173. package/dist/commands/rev-filter/index.d.ts.map +1 -0
  174. package/dist/commands/rev-list-command.d.ts +154 -2
  175. package/dist/commands/rev-list-command.d.ts.map +1 -1
  176. package/dist/commands/rev-parse-command.d.ts +9 -0
  177. package/dist/commands/rev-parse-command.d.ts.map +1 -1
  178. package/dist/commands/revert-command.d.ts +32 -0
  179. package/dist/commands/revert-command.d.ts.map +1 -1
  180. package/dist/commands/revision-range.d.ts +32 -1
  181. package/dist/commands/revision-range.d.ts.map +1 -1
  182. package/dist/commands/revision-resolver.d.ts +21 -2
  183. package/dist/commands/revision-resolver.d.ts.map +1 -1
  184. package/dist/commands/rm-command.d.ts +70 -2
  185. package/dist/commands/rm-command.d.ts.map +1 -1
  186. package/dist/commands/sequencer-pick.d.ts +85 -5
  187. package/dist/commands/sequencer-pick.d.ts.map +1 -1
  188. package/dist/commands/sequencer-support.d.ts +2 -0
  189. package/dist/commands/sequencer-support.d.ts.map +1 -1
  190. package/dist/commands/serve-repository.d.ts +7 -0
  191. package/dist/commands/serve-repository.d.ts.map +1 -1
  192. package/dist/commands/show-command.d.ts +130 -0
  193. package/dist/commands/show-command.d.ts.map +1 -0
  194. package/dist/commands/show-commit.d.ts +11 -0
  195. package/dist/commands/show-commit.d.ts.map +1 -0
  196. package/dist/commands/signature-check.d.ts +164 -0
  197. package/dist/commands/signature-check.d.ts.map +1 -0
  198. package/dist/commands/signing.d.ts +160 -0
  199. package/dist/commands/signing.d.ts.map +1 -0
  200. package/dist/commands/sparse-checkout-command.d.ts.map +1 -1
  201. package/dist/commands/sparse-index-view.d.ts +45 -0
  202. package/dist/commands/sparse-index-view.d.ts.map +1 -0
  203. package/dist/commands/ssh-signer.d.ts +29 -0
  204. package/dist/commands/ssh-signer.d.ts.map +1 -0
  205. package/dist/commands/ssh-verifier.d.ts +42 -0
  206. package/dist/commands/ssh-verifier.d.ts.map +1 -0
  207. package/dist/commands/stash-apply-command.d.ts +5 -0
  208. package/dist/commands/stash-apply-command.d.ts.map +1 -1
  209. package/dist/commands/stash-branch-command.d.ts +34 -0
  210. package/dist/commands/stash-branch-command.d.ts.map +1 -0
  211. package/dist/commands/stash-create-command.d.ts +18 -1
  212. package/dist/commands/stash-create-command.d.ts.map +1 -1
  213. package/dist/commands/stash-info.d.ts +93 -0
  214. package/dist/commands/stash-info.d.ts.map +1 -0
  215. package/dist/commands/stash-list-command.d.ts +16 -0
  216. package/dist/commands/stash-list-command.d.ts.map +1 -1
  217. package/dist/commands/stash-pop-command.d.ts +39 -0
  218. package/dist/commands/stash-pop-command.d.ts.map +1 -0
  219. package/dist/commands/stash-show-command.d.ts +48 -0
  220. package/dist/commands/stash-show-command.d.ts.map +1 -0
  221. package/dist/commands/stash-store-command.d.ts +29 -0
  222. package/dist/commands/stash-store-command.d.ts.map +1 -0
  223. package/dist/commands/stash-working-tree.d.ts.map +1 -1
  224. package/dist/commands/status-command.d.ts.map +1 -1
  225. package/dist/commands/status-header.d.ts +5 -0
  226. package/dist/commands/status-header.d.ts.map +1 -1
  227. package/dist/commands/submodule-add-command.d.ts +89 -0
  228. package/dist/commands/submodule-add-command.d.ts.map +1 -0
  229. package/dist/commands/submodule-auth.d.ts +90 -0
  230. package/dist/commands/submodule-auth.d.ts.map +1 -0
  231. package/dist/commands/submodule-commands.d.ts +375 -0
  232. package/dist/commands/submodule-commands.d.ts.map +1 -0
  233. package/dist/commands/submodule-model.d.ts +288 -0
  234. package/dist/commands/submodule-model.d.ts.map +1 -0
  235. package/dist/commands/submodule-summary-command.d.ts.map +1 -1
  236. package/dist/commands/submodule-update-command.d.ts +198 -0
  237. package/dist/commands/submodule-update-command.d.ts.map +1 -0
  238. package/dist/commands/switch-command.d.ts.map +1 -1
  239. package/dist/commands/tag-command.d.ts +259 -10
  240. package/dist/commands/tag-command.d.ts.map +1 -1
  241. package/dist/commands/trailers.d.ts +218 -17
  242. package/dist/commands/trailers.d.ts.map +1 -1
  243. package/dist/commands/tree-restore.d.ts +7 -0
  244. package/dist/commands/tree-restore.d.ts.map +1 -1
  245. package/dist/commands/untracked-cache-support.d.ts +2 -1
  246. package/dist/commands/untracked-cache-support.d.ts.map +1 -1
  247. package/dist/commands/verify-command.d.ts +92 -0
  248. package/dist/commands/verify-command.d.ts.map +1 -0
  249. package/dist/commands/worktree-add-command.d.ts +79 -7
  250. package/dist/commands/worktree-add-command.d.ts.map +1 -1
  251. package/dist/commands/worktree-list-command.d.ts.map +1 -1
  252. package/dist/commands/worktree-path-rules.d.ts +66 -0
  253. package/dist/commands/worktree-path-rules.d.ts.map +1 -0
  254. package/dist/commands/worktree-remove-command.d.ts +10 -3
  255. package/dist/commands/worktree-remove-command.d.ts.map +1 -1
  256. package/dist/commands/worktree-repair-command.d.ts +15 -2
  257. package/dist/commands/worktree-repair-command.d.ts.map +1 -1
  258. package/dist/commands/worktree-support.d.ts +5 -0
  259. package/dist/commands/worktree-support.d.ts.map +1 -1
  260. package/dist/{commands-DnmlfwGV.js → commands-ISM52N0n.js} +66120 -49271
  261. package/dist/errors/checkout-errors.d.ts +19 -0
  262. package/dist/errors/checkout-errors.d.ts.map +1 -1
  263. package/dist/errors/command-errors.d.ts.map +1 -1
  264. package/dist/errors/index.js +57 -3
  265. package/dist/errors/ref-errors.d.ts +19 -0
  266. package/dist/errors/ref-errors.d.ts.map +1 -1
  267. package/dist/errors/worktree-errors.d.ts +6 -1
  268. package/dist/errors/worktree-errors.d.ts.map +1 -1
  269. package/dist/{git-command-DxvwPrPB.js → fsck-DLRpbwTj.js} +6863 -1070
  270. package/dist/git-command.d.ts +43 -2
  271. package/dist/git-command.d.ts.map +1 -1
  272. package/dist/git.d.ts +276 -3
  273. package/dist/git.d.ts.map +1 -1
  274. package/dist/index.js +5 -5
  275. package/dist/remote-config/index.d.ts +1 -1
  276. package/dist/remote-config/index.d.ts.map +1 -1
  277. package/dist/remote-config/remote-config-store.d.ts +117 -3
  278. package/dist/remote-config/remote-config-store.d.ts.map +1 -1
  279. package/dist/rename/detect-renames.d.ts.map +1 -1
  280. package/dist/results/clone-result.d.ts +8 -0
  281. package/dist/results/clone-result.d.ts.map +1 -1
  282. package/dist/results/combined-diff.d.ts +3 -0
  283. package/dist/results/combined-diff.d.ts.map +1 -1
  284. package/dist/results/diff-check.d.ts +38 -0
  285. package/dist/results/diff-check.d.ts.map +1 -0
  286. package/dist/results/diff-color.d.ts +135 -0
  287. package/dist/results/diff-color.d.ts.map +1 -0
  288. package/dist/results/diff-output.d.ts +85 -1
  289. package/dist/results/diff-output.d.ts.map +1 -1
  290. package/dist/results/diff-pickaxe.d.ts +67 -0
  291. package/dist/results/diff-pickaxe.d.ts.map +1 -0
  292. package/dist/results/diff-words.d.ts +55 -0
  293. package/dist/results/diff-words.d.ts.map +1 -0
  294. package/dist/results/index.d.ts +4 -0
  295. package/dist/results/index.d.ts.map +1 -1
  296. package/dist/results/index.js +2 -2
  297. package/dist/results/init-result.d.ts +7 -0
  298. package/dist/results/init-result.d.ts.map +1 -1
  299. package/dist/results/pull-result.d.ts +5 -0
  300. package/dist/results/pull-result.d.ts.map +1 -1
  301. package/dist/results/push-result.d.ts +12 -0
  302. package/dist/results/push-result.d.ts.map +1 -1
  303. package/dist/results/rebase-result.d.ts +2 -0
  304. package/dist/results/rebase-result.d.ts.map +1 -1
  305. package/dist/results/stash-result.d.ts +6 -0
  306. package/dist/results/stash-result.d.ts.map +1 -1
  307. package/dist/results/status-result.d.ts.map +1 -1
  308. package/dist/{results-BZGa2Z3I.js → results-TB2IJ64h.js} +2178 -412
  309. package/dist/whitespace/index.d.ts +2 -0
  310. package/dist/whitespace/index.d.ts.map +1 -0
  311. package/dist/whitespace/whitespace-rule.d.ts +94 -0
  312. package/dist/whitespace/whitespace-rule.d.ts.map +1 -0
  313. package/package.json +12 -12
  314. package/src/commands/add-command.ts +178 -17
  315. package/src/commands/add-patch/add-interactive.ts +3 -3
  316. package/src/commands/am/am-command.ts +263 -43
  317. package/src/commands/am/index.ts +1 -0
  318. package/src/commands/am/mailsplit.ts +326 -0
  319. package/src/commands/apply/apply-command.ts +18 -8
  320. package/src/commands/apply/apply-engine.ts +6 -7
  321. package/src/commands/apply/apply-parse.ts +10 -10
  322. package/src/commands/attributes-source.ts +1 -1
  323. package/src/commands/bisect/bisect-command.ts +18 -5
  324. package/src/commands/bisect/bisect-engine.ts +2 -1
  325. package/src/commands/branch-command.ts +528 -53
  326. package/src/commands/branch-info-command.ts +150 -0
  327. package/src/commands/branch-tracking.ts +335 -60
  328. package/src/commands/branch-upstream-command.ts +218 -0
  329. package/src/commands/checkout-command.ts +70 -44
  330. package/src/commands/cherry-pick-command.ts +143 -0
  331. package/src/commands/clean-command.ts +34 -3
  332. package/src/commands/clone-command.ts +118 -5
  333. package/src/commands/comment-char-config.ts +160 -0
  334. package/src/commands/commit-command.ts +790 -71
  335. package/src/commands/commit-reuse.ts +94 -0
  336. package/src/commands/config-command.ts +1256 -0
  337. package/src/commands/config-value-types.ts +358 -0
  338. package/src/commands/core-config.ts +47 -2
  339. package/src/commands/default-branch.ts +196 -0
  340. package/src/commands/diff-color-config.ts +274 -0
  341. package/src/commands/diff-command.ts +1053 -75
  342. package/src/commands/fetch-command.ts +161 -13
  343. package/src/commands/fmt-merge-msg-command.ts +715 -0
  344. package/src/commands/fork-point.ts +63 -0
  345. package/src/commands/format-patch-command.ts +316 -43
  346. package/src/commands/fsck/fetch-fsck.ts +172 -18
  347. package/src/commands/fsck/fsck-command.ts +183 -66
  348. package/src/commands/fsck/fsck-loose.ts +14 -4
  349. package/src/commands/fsck/fsck-object-checks.ts +87 -46
  350. package/src/commands/fsck/fsck-object-table.ts +52 -42
  351. package/src/commands/fsck/fsck-pack.ts +64 -34
  352. package/src/commands/fsck/verify-pack-command.ts +5 -2
  353. package/src/commands/gc-command.ts +238 -107
  354. package/src/commands/git-date.ts +9 -895
  355. package/src/commands/git-describe.ts +31 -11
  356. package/src/commands/git-hooks.ts +92 -0
  357. package/src/commands/grep/grep-command.ts +1077 -0
  358. package/src/commands/grep/grep-engine.ts +1024 -0
  359. package/src/commands/grep/index.ts +2 -0
  360. package/src/commands/index-adder.ts +54 -10
  361. package/src/commands/index.ts +28 -0
  362. package/src/commands/init-command.ts +167 -11
  363. package/src/commands/interpret-trailers-command.ts +256 -0
  364. package/src/commands/legacy-remotes.ts +224 -0
  365. package/src/commands/local-transport.ts +109 -10
  366. package/src/commands/log-command.ts +1283 -232
  367. package/src/commands/log-graph.ts +123 -26
  368. package/src/commands/log-output.ts +280 -21
  369. package/src/commands/ls-remote-command.ts +9 -0
  370. package/src/commands/mailmap.ts +119 -0
  371. package/src/commands/merge-base-command.ts +170 -0
  372. package/src/commands/merge-bases.ts +63 -8
  373. package/src/commands/merge-command.ts +360 -82
  374. package/src/commands/merge-support.ts +43 -9
  375. package/src/commands/mv-command.ts +6 -3
  376. package/src/commands/name-rev.ts +171 -0
  377. package/src/commands/notes-command.ts +11 -1
  378. package/src/commands/notes-merge-command.ts +23 -14
  379. package/src/commands/notes-tree.ts +28 -13
  380. package/src/commands/octopus-merge.ts +3 -2
  381. package/src/commands/patch-id.ts +16 -8
  382. package/src/commands/pathspec-file.ts +72 -0
  383. package/src/commands/pathspec.ts +14 -2
  384. package/src/commands/pretty-format.ts +105 -20
  385. package/src/commands/promisor-remote.ts +10 -1
  386. package/src/commands/pull-command.ts +149 -22
  387. package/src/commands/push-command.ts +704 -72
  388. package/src/commands/read-tree-command.ts +34 -3
  389. package/src/commands/rebase-command.ts +957 -142
  390. package/src/commands/ref-filter/for-each-ref-command.ts +298 -0
  391. package/src/commands/ref-filter/index.ts +7 -0
  392. package/src/commands/ref-filter/ref-atoms.ts +581 -0
  393. package/src/commands/ref-filter/ref-filter.ts +651 -0
  394. package/src/commands/ref-filter/ref-format.ts +1070 -0
  395. package/src/commands/ref-filter/ref-listing-command.ts +421 -0
  396. package/src/commands/ref-filter/ref-quote.ts +69 -0
  397. package/src/commands/ref-filter/version-compare.ts +177 -0
  398. package/src/commands/reflog-command.ts +492 -2
  399. package/src/commands/reflog-walk.ts +234 -0
  400. package/src/commands/remote-command.ts +484 -74
  401. package/src/commands/remote-transport.ts +9 -1
  402. package/src/commands/reset-command.ts +40 -42
  403. package/src/commands/restore-command.ts +12 -41
  404. package/src/commands/rev-filter/commit-filter.ts +159 -0
  405. package/src/commands/rev-filter/commit-grep.ts +444 -0
  406. package/src/commands/rev-filter/index.ts +2 -0
  407. package/src/commands/rev-list-command.ts +402 -15
  408. package/src/commands/rev-parse-command.ts +22 -0
  409. package/src/commands/revert-command.ts +82 -0
  410. package/src/commands/revision-range.ts +204 -4
  411. package/src/commands/revision-resolver.ts +55 -22
  412. package/src/commands/rm-command.ts +282 -21
  413. package/src/commands/sequencer-pick.ts +504 -86
  414. package/src/commands/sequencer-support.ts +30 -5
  415. package/src/commands/serve-repository.ts +18 -3
  416. package/src/commands/show-command.ts +490 -0
  417. package/src/commands/show-commit.ts +24 -0
  418. package/src/commands/signature-check.ts +657 -0
  419. package/src/commands/signing.ts +385 -0
  420. package/src/commands/sparse-checkout-command.ts +2 -9
  421. package/src/commands/sparse-checkout-support.ts +2 -2
  422. package/src/commands/sparse-index-view.ts +135 -0
  423. package/src/commands/ssh-signer.ts +199 -0
  424. package/src/commands/ssh-verifier.ts +523 -0
  425. package/src/commands/stash-apply-command.ts +17 -5
  426. package/src/commands/stash-branch-command.ts +88 -0
  427. package/src/commands/stash-create-command.ts +30 -2
  428. package/src/commands/stash-info.ts +243 -0
  429. package/src/commands/stash-list-command.ts +33 -0
  430. package/src/commands/stash-pop-command.ts +83 -0
  431. package/src/commands/stash-show-command.ts +141 -0
  432. package/src/commands/stash-store-command.ts +82 -0
  433. package/src/commands/stash-working-tree.ts +2 -2
  434. package/src/commands/status-command.ts +7 -6
  435. package/src/commands/status-header.ts +44 -8
  436. package/src/commands/submodule-add-command.ts +509 -0
  437. package/src/commands/submodule-auth.ts +276 -0
  438. package/src/commands/submodule-commands.ts +1517 -0
  439. package/src/commands/submodule-model.ts +930 -0
  440. package/src/commands/submodule-summary-command.ts +6 -7
  441. package/src/commands/submodule-update-command.ts +1092 -0
  442. package/src/commands/switch-command.ts +3 -1
  443. package/src/commands/tag-command.ts +876 -64
  444. package/src/commands/trailers.ts +837 -100
  445. package/src/commands/tree-restore.ts +38 -10
  446. package/src/commands/untracked-cache-support.ts +16 -12
  447. package/src/commands/verify-command.ts +235 -0
  448. package/src/commands/worktree-add-command.ts +268 -24
  449. package/src/commands/worktree-list-command.ts +3 -5
  450. package/src/commands/worktree-path-rules.ts +183 -0
  451. package/src/commands/worktree-remove-command.ts +39 -5
  452. package/src/commands/worktree-repair-command.ts +52 -5
  453. package/src/commands/worktree-support.ts +22 -1
  454. package/src/core-commands/add.command.impl.ts +1 -1
  455. package/src/errors/checkout-errors.ts +29 -0
  456. package/src/errors/command-errors.ts +2 -1
  457. package/src/errors/ref-errors.ts +23 -0
  458. package/src/errors/worktree-errors.ts +8 -1
  459. package/src/git-command.ts +98 -3
  460. package/src/git.ts +420 -4
  461. package/src/remote-config/index.ts +4 -0
  462. package/src/remote-config/remote-config-store.ts +238 -11
  463. package/src/rename/detect-renames.ts +5 -1
  464. package/src/results/clone-result.ts +9 -0
  465. package/src/results/combined-diff.ts +38 -18
  466. package/src/results/diff-check.ts +185 -0
  467. package/src/results/diff-color.ts +868 -0
  468. package/src/results/diff-output.ts +204 -37
  469. package/src/results/diff-pickaxe.ts +304 -0
  470. package/src/results/diff-words.ts +395 -0
  471. package/src/results/index.ts +4 -0
  472. package/src/results/init-result.ts +9 -0
  473. package/src/results/pull-result.ts +5 -0
  474. package/src/results/push-result.ts +12 -0
  475. package/src/results/rebase-result.ts +3 -0
  476. package/src/results/stash-result.ts +7 -0
  477. package/src/results/status-result.ts +5 -2
  478. package/src/whitespace/index.ts +1 -0
  479. package/src/{commands/apply/whitespace.ts → whitespace/whitespace-rule.ts} +173 -23
  480. package/dist/commands/apply/whitespace.d.ts +0 -58
  481. package/dist/commands/apply/whitespace.d.ts.map +0 -1
@@ -1,11 +1,17 @@
1
1
  import {
2
- EMPTY_TREE_ID,
3
2
  type FileModeValue,
4
3
  type ObjectId,
5
4
  type TreeEntry,
6
5
  TreeEntryCursor,
7
6
  } from "@statewalker/vcs-core";
8
- import { ByteSink, parseGitBool, type XdiffAlgorithm } from "@statewalker/vcs-utils";
7
+ import {
8
+ ByteSink,
9
+ compilePosixRegex,
10
+ isNullObjectId,
11
+ type PosixRegex,
12
+ parseGitBool,
13
+ type XdiffAlgorithm,
14
+ } from "@statewalker/vcs-utils";
9
15
  import { compareGitPaths, decodeGitPath } from "@statewalker/vcs-utils/encoding";
10
16
  import {
11
17
  type AttributesIndex,
@@ -21,7 +27,12 @@ import {
21
27
  withWorktreeEntries,
22
28
  } from "@statewalker/vcs-working-tree";
23
29
 
24
- import { NoHeadError, RefNotFoundError } from "../errors/index.js";
30
+ import {
31
+ GitApiError,
32
+ InvalidArgumentError,
33
+ NoHeadError,
34
+ RefNotFoundError,
35
+ } from "../errors/index.js";
25
36
  import { GitCommand } from "../git-command.js";
26
37
  import { RemoteConfigStore } from "../remote-config/index.js";
27
38
  import {
@@ -31,6 +42,8 @@ import {
31
42
  scorePercent,
32
43
  } from "../rename/index.js";
33
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";
34
47
  import { ChangeType, type DiffEntry } from "../results/diff-entry.js";
35
48
  import { diffEntryToPair } from "../results/diff-formatter.js";
36
49
  import { orderByPatterns, parseOrderFile } from "../results/diff-order.js";
@@ -52,12 +65,26 @@ import {
52
65
  formatSummary,
53
66
  writePairPatch,
54
67
  } from "../results/diff-output.js";
68
+ import { DiffPickaxe } from "../results/diff-pickaxe.js";
55
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";
56
76
  import { bareAttributesResolver } from "./attributes-source.js";
57
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";
58
84
  import { textconvRunnerOf } from "./diff-textconv.js";
59
85
  import { matchPathspec, type PathspecItem, parsePathspecItem } from "./pathspec.js";
60
86
  import { PathspecAttributes } from "./pathspec-attributes.js";
87
+ import { revisionMergeBases } from "./rev-parse-command.js";
61
88
  import { readSubmoduleDirt, type SubmoduleDirt } from "./status-command.js";
62
89
  import {
63
90
  isSubmoduleIgnoreMode,
@@ -92,7 +119,15 @@ const PREFETCH_FORMATS = new Set<string>(["patch", "stat", "numstat", "shortstat
92
119
  function prefetchIds(entries: readonly DiffEntry[]): ObjectId[] {
93
120
  const out: ObjectId[] = [];
94
121
  const add = (id: ObjectId | undefined, mode: number | undefined) => {
95
- if (id && id !== NULL_ID && mode !== GITLINK && mode !== undefined && mode !== 0) out.push(id);
122
+ if (
123
+ id &&
124
+ !isNullObjectId(id) &&
125
+ mode !== GITLINK &&
126
+ mode !== undefined &&
127
+ mode !== 0 &&
128
+ (mode & 0o170000) !== 0o040000
129
+ )
130
+ out.push(id);
96
131
  };
97
132
  for (const e of entries) {
98
133
  if (e.unmerged) continue;
@@ -109,15 +144,42 @@ export type DiffOutputFormat =
109
144
  | "shortstat"
110
145
  | "summary"
111
146
  | "name-only"
112
- | "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";
113
154
 
114
155
  /** Options of the text output that `git diff` takes on its command line */
115
156
  export interface DiffTextOptions
116
- 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";
117
174
  /** `--diff-algorithm` (default `diff.algorithm`, else myers) */
118
175
  algorithm?: XdiffAlgorithm;
119
176
  /** `--indent-heuristic` / `--no-indent-heuristic` (default `diff.indentHeuristic`, true) */
120
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;
121
183
  /**
122
184
  * `--abbrev=<n>`: the `index` lines' ids at least n digits, clamped as git clamps it (below
123
185
  * 4, 0 too, is 4; above 40 is 40); the combined diffs of conflicted paths ignore it, as
@@ -183,6 +245,207 @@ export interface DiffTextOptions
183
245
  * prefixes with them (`diff --git b/f a/f`). Combined diffs of conflicted paths are not swapped.
184
246
  */
185
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;
186
449
  }
187
450
 
188
451
  /** An entry with its two sides swapped (`diff -R`). */
@@ -262,7 +525,6 @@ function submoduleIgnoreValue(
262
525
 
263
526
  const S_IFMT = 0o170000;
264
527
  const GITLINK = 0o160000;
265
- const NULL_ID = "0".repeat(40);
266
528
  const encoder = new TextEncoder();
267
529
 
268
530
  /** The chunks as one array. */
@@ -378,6 +640,20 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
378
640
  private dirtySubmodules?: boolean;
379
641
  /** `diff.submodule` (its last value git knows), read by the text outputs */
380
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
+ }
381
657
  private readonly configWarnings: string[] = [];
382
658
  /** {@link dirtySubmodules} for the comparison being collected */
383
659
  private dirtyThisCall = true;
@@ -394,6 +670,100 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
394
670
  private temporaryIndex?: Staging;
395
671
  /** Intent-to-add entries are in the index as empty files (plumbing's `diff-index --cached`) */
396
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
+ }
397
767
 
398
768
  /**
399
769
  * Show intent-to-add entries in a `--cached` comparison as the empty files they name, as
@@ -411,9 +781,11 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
411
781
  * Set the old (base) tree/commit for comparison.
412
782
  *
413
783
  * Can be a commit ID, branch name, tag name, or tree ID.
414
- * 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).
415
787
  *
416
- * @param refOrId Commit-ish or tree ID
788
+ * @param refOrId Commit-ish or tree ID, or a range
417
789
  */
418
790
  setOldTree(refOrId: string): this {
419
791
  this.checkCallable();
@@ -503,6 +875,11 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
503
875
  * `diff.submodule`, its warnings, and the failure of a variable without a value.
504
876
  */
505
877
  private readUiConfig(): void {
878
+ this.colorSettings ??= readDiffColorSettings(
879
+ this.workingCopy,
880
+ this.textOptions,
881
+ this.textOptions.uiConfig !== false,
882
+ );
506
883
  if (this.textOptions.uiConfig === false) return;
507
884
  const { format, warnings } = readDiffSubmoduleConfig(this.workingCopy);
508
885
  this.configuredSubmoduleFormat = format;
@@ -536,6 +913,21 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
536
913
  return this.temporaryIndex ?? super.staging;
537
914
  }
538
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
+
539
931
  /**
540
932
  * Filter results to only paths starting with this prefix.
541
933
  *
@@ -598,7 +990,16 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
598
990
  this.checkCallable();
599
991
  this.setCallable(false);
600
992
  this.dirtyThisCall = this.dirtySubmodules ?? true;
601
- 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;
602
1003
  }
603
1004
 
604
1005
  /**
@@ -620,13 +1021,17 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
620
1021
  this.setCallable(false);
621
1022
  const config = this.config;
622
1023
  const renames = this.renames ?? renamesValue(config.value("diff.renames")) ?? true;
623
- this.dirtyThisCall = this.dirtySubmodules ?? format === "patch";
1024
+ this.dirtyThisCall = this.dirtySubmodules ?? (format === "patch" && !this.quiet);
624
1025
  this.readUiConfig();
625
1026
  return this.inOneOperation(async () => {
1027
+ if (this.quiet) {
1028
+ await this.quietCheck(renames);
1029
+ return new Uint8Array(0);
1030
+ }
626
1031
  const collected = await this.collect(
627
1032
  renames,
628
1033
  format === "patch",
629
- PREFETCH_FORMATS.has(format),
1034
+ PREFETCH_FORMATS.has(format) || this.pickaxeReads,
630
1035
  );
631
1036
  const sink = new ByteSink();
632
1037
  await this.writeFormats(sink, [format], collected);
@@ -634,6 +1039,41 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
634
1039
  });
635
1040
  }
636
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
+
637
1077
  /**
638
1078
  * The diffstat of the comparison, one file per pair in git's order (`compute_diffstat` of
639
1079
  * the diff queue, as a `DIFF_FORMAT_CALLBACK` consumer sees it): an unmerged path as a
@@ -716,7 +1156,7 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
716
1156
  collected = await this.collect(
717
1157
  renames,
718
1158
  formats.includes("patch"),
719
- formats.some((f) => PREFETCH_FORMATS.has(f)),
1159
+ formats.some((f) => PREFETCH_FORMATS.has(f)) || this.pickaxeReads,
720
1160
  );
721
1161
  }
722
1162
  const followed = {
@@ -725,7 +1165,9 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
725
1165
  };
726
1166
  if (collected.entries.length === 0 && collected.combined.length === 0) return followed;
727
1167
  const sink = new ByteSink();
728
- 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;
729
1171
  return { bytes: sink.bytes(), ...followed };
730
1172
  });
731
1173
  }
@@ -779,11 +1221,13 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
779
1221
  sink: ByteSink,
780
1222
  formats: DiffOutputFormat[],
781
1223
  collected: { entries: DiffEntry[]; combined: CombinedEntry[] },
782
- ): Promise<void> {
1224
+ ): Promise<number> {
783
1225
  const config = this.config;
784
1226
  const { combined } = collected;
785
- const ordered = await this.ordered(collected.entries);
786
- 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;
787
1231
  const options = this.outputOptions();
788
1232
  Object.assign(options, this.prefixes());
789
1233
  if (this.textOptions.reverse) {
@@ -795,17 +1239,52 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
795
1239
  }
796
1240
  const pairs: DiffFilePair[] = [];
797
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;
798
1245
  for (const entry of entries) {
799
1246
  // an unmerged path: only its name is printed
800
1247
  const pair: DiffFilePair = entry.unmerged
801
1248
  ? {
802
1249
  status: "M",
803
- old: contentSide(entry.oldPath ?? "", 0, NULL_ID, async () => new Uint8Array(0)),
1250
+ old: contentSide(
1251
+ entry.oldPath ?? "",
1252
+ 0,
1253
+ this.objectFormat.nullId,
1254
+ async () => new Uint8Array(0),
1255
+ ),
804
1256
  }
805
1257
  : this.withTextconvInputs(diffEntryToPair(entry, this.blobs), entry);
806
- if (entry.unmerged) unmerged.add(pair);
807
- 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);
808
1286
  }
1287
+ const full = (pair: DiffFilePair) => fullPairs.get(pair) ?? pair;
809
1288
  const quote = options.quotePath;
810
1289
  const order: DiffOutputFormat[] = [
811
1290
  "name-only",
@@ -822,7 +1301,7 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
822
1301
  // combine-diff.c's index lines take DEFAULT_ABBREV, whatever --abbrev says
823
1302
  let combinedLengths: ReadonlyMap<string, number> | undefined;
824
1303
  if (!options.fullIndex) {
825
- const ids = new Set<string>([NULL_ID]);
1304
+ const ids = new Set<string>([this.objectFormat.nullId]);
826
1305
  for (const c of combined) {
827
1306
  ids.add(c.ours.objectId);
828
1307
  ids.add(c.theirs.objectId);
@@ -832,17 +1311,39 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
832
1311
  for (const c of combined) await this.writeCombined(sink, c, options, combinedLengths);
833
1312
  }
834
1313
  // diff_flush of an empty queue prints nothing
835
- 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
+ }
836
1335
  let separator = false;
837
1336
  for (const format of order) {
838
1337
  if (!formats.includes(format)) continue;
839
- 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
+ }
840
1343
  // diff_flush: an empty summary (is_summary_empty) prints nothing and asks no separator
841
1344
  if (format === "summary") {
842
- const text = formatSummary(
843
- pairs.filter((p) => !unmerged.has(p)),
844
- quote,
845
- );
1345
+ // diff_summary names the paths in full, whatever `--relative` says
1346
+ const text = formatSummary(pairs.filter((p) => !unmerged.has(p)).map(full), quote);
846
1347
  if (text) {
847
1348
  sink.text(text);
848
1349
  separator = true;
@@ -863,36 +1364,55 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
863
1364
  const ids = new Set<string>();
864
1365
  for (const pair of pairs) {
865
1366
  if (unmerged.has(pair)) continue;
866
- ids.add(pair.old?.id ?? NULL_ID);
867
- ids.add(pair.new?.id ?? NULL_ID);
1367
+ ids.add(pair.old?.id ?? this.objectFormat.nullId);
1368
+ ids.add(pair.new?.id ?? this.objectFormat.nullId);
868
1369
  }
869
1370
  // `--abbrev=<n>`: at least n digits
870
1371
  options.abbrevLengths = await this.idAbbreviator().lengths(ids, options.abbrev);
871
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;
872
1379
  for (const pair of pairs) {
1380
+ const before = out.length;
873
1381
  if (unmerged.has(pair)) {
874
- sink.text(`* Unmerged path ${pair.new?.path ?? pair.old?.path}\n`);
875
- } 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 });
876
1389
  }
877
1390
  break;
878
1391
  }
879
- case "name-only":
880
- sink.text(
881
- formatNameOnly(await this.shownNames(pairs, unmerged, options), { quotePath: quote }),
882
- );
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 }));
883
1397
  break;
884
- case "name-status":
885
- 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) {
886
1404
  if (unmerged.has(pair)) {
887
1405
  sink.text(`U\t${quotePath(pair.new?.path ?? pair.old?.path ?? "", quote)}\n`);
888
1406
  } else sink.text(formatNameStatus([pair], { quotePath: quote }));
889
1407
  }
890
1408
  break;
1409
+ }
891
1410
  default: {
892
1411
  const files = [];
893
1412
  for (const pair of pairs) {
894
1413
  if (unmerged.has(pair)) {
895
- 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 ?? "";
896
1416
  files.push({
897
1417
  name,
898
1418
  isRenamed: false,
@@ -903,11 +1423,14 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
903
1423
  });
904
1424
  } else files.push(...(await computeDiffstat([pair], options)));
905
1425
  }
1426
+ // compute_diffstat: found_changes when the diffstat lists a file
1427
+ if (files.length > 0) this.changesFound = true;
906
1428
  const statOptions: DiffstatOptions = {
907
1429
  nameWidth: intValue(config.value("diff.statNameWidth")),
908
1430
  graphWidth: intValue(config.value("diff.statGraphWidth")),
909
1431
  ...this.textOptions.stat,
910
1432
  quotePath: quote,
1433
+ ...(this.colorSettings?.colors ? { colors: this.colorSettings.colors } : {}),
911
1434
  };
912
1435
  if (format === "stat") sink.text(formatStat(files, statOptions));
913
1436
  else if (format === "numstat") sink.text(formatNumstat(files, { quotePath: quote }));
@@ -915,6 +1438,7 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
915
1438
  }
916
1439
  }
917
1440
  }
1441
+ return pairs.length;
918
1442
  }
919
1443
 
920
1444
  /**
@@ -928,22 +1452,47 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
928
1452
  options: DiffOutputOptions,
929
1453
  format: SubmoduleDiffFormat,
930
1454
  ): Promise<void> {
931
- const path = pair.old?.path ?? pair.new?.path ?? "";
932
- const one = pair.old?.id ?? NULL_ID;
933
- const two = pair.new?.id ?? NULL_ID;
1455
+ // `one->path`: the full path, whatever `--relative` shows
1456
+ const path = pair.old?.attrPath ?? pair.old?.path ?? pair.new?.attrPath ?? pair.new?.path ?? "";
1457
+ const one = pair.old?.id ?? this.objectFormat.nullId;
1458
+ const two = pair.new?.id ?? this.objectFormat.nullId;
934
1459
  const dirt = pair.new?.submoduleDirt;
935
1460
  // strbuf_add_unique_abbrev(..., DEFAULT_ABBREV): the superproject's abbreviation
936
1461
  const abbreviate = (id: ObjectId) => this.idAbbreviator().abbreviate(id);
937
1462
  const workingCopy = this.workingCopy;
938
1463
  if (format === "log") {
939
- 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
+ });
940
1485
  return;
941
1486
  }
942
1487
  const sub = await openSubmoduleRepository(workingCopy, path);
943
1488
  const header = await submoduleHeader({ path, one, two, dirt, sub, abbreviate });
944
1489
  sink.text(header.text);
945
1490
  // a valid left and right commit (or none on that side) to diff
946
- if (!(header.left || one === NULL_ID) || !(header.right || two === NULL_ID)) return;
1491
+ if (
1492
+ !(header.left || one === this.objectFormat.nullId) ||
1493
+ !(header.right || two === this.objectFormat.nullId)
1494
+ )
1495
+ return;
947
1496
  if (!sub) return;
948
1497
  const failed = "(diff failed)\n";
949
1498
  // `git diff` runs in the submodule's directory: one that holds no repository of its own
@@ -953,14 +1502,16 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
953
1502
  return;
954
1503
  }
955
1504
  const inner = new DiffCommand(sub.repository)
956
- .setOldTree(header.left ? one : EMPTY_TREE_ID)
1505
+ .setOldTree(header.left ? one : this.objectFormat.emptyTreeId)
957
1506
  .setSubmoduleFormat("diff")
958
1507
  .setOptions({
1508
+ // the child `git diff --color=always|never` reads the submodule's own color slots
1509
+ color: options.colors !== undefined,
959
1510
  srcPrefix: `${options.srcPrefix ?? "a/"}${path}/`,
960
1511
  dstPrefix: `${options.dstPrefix ?? "b/"}${path}/`,
961
1512
  });
962
1513
  // modified content: the submodule's worktree is diffed, not its commit
963
- if (!dirt?.modified) inner.setNewTree(header.right ? two : EMPTY_TREE_ID);
1514
+ if (!dirt?.modified) inner.setNewTree(header.right ? two : this.objectFormat.emptyTreeId);
964
1515
  try {
965
1516
  sink.push(await inner.callBytes("patch"));
966
1517
  } catch {
@@ -981,7 +1532,8 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
981
1532
  const textconv = driver?.textconv;
982
1533
  const stage = async (e: StageEntry) => {
983
1534
  const side = blobSide(this.blobs, c.path, e.mode, e.objectId);
984
- const convert = textconv && (e.mode & S_IFMT) !== GITLINK && e.objectId !== NULL_ID;
1535
+ const convert =
1536
+ textconv && (e.mode & S_IFMT) !== GITLINK && e.objectId !== this.objectFormat.nullId;
985
1537
  return {
986
1538
  id: e.objectId,
987
1539
  mode: e.mode,
@@ -997,7 +1549,7 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
997
1549
  if (worktree && file) {
998
1550
  if (file.isDirectory) {
999
1551
  mode = GITLINK;
1000
- content = encoder.encode(`Subproject commit ${NULL_ID}\n`);
1552
+ content = encoder.encode(`Subproject commit ${this.objectFormat.nullId}\n`);
1001
1553
  } else {
1002
1554
  const kind = file.mode & S_IFMT;
1003
1555
  mode = kind === 0o120000 ? 0o120000 : file.mode & 0o111 ? 0o100755 : 0o100644;
@@ -1013,7 +1565,7 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
1013
1565
  {
1014
1566
  path: c.path,
1015
1567
  parents: [await stage(c.ours), await stage(c.theirs)],
1016
- result: { id: NULL_ID, mode, content },
1568
+ result: { id: this.objectFormat.nullId, mode, content },
1017
1569
  },
1018
1570
  {
1019
1571
  ...options,
@@ -1022,7 +1574,7 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
1022
1574
  : driver?.binary !== undefined
1023
1575
  ? { binary: driver.binary }
1024
1576
  : {}),
1025
- abbreviate: (id) => id.slice(0, options.fullIndex ? 40 : (lengths?.get(id) ?? 7)),
1577
+ abbreviate: (id) => id.slice(0, options.fullIndex ? id.length : (lengths?.get(id) ?? 7)),
1026
1578
  },
1027
1579
  );
1028
1580
  }
@@ -1049,6 +1601,44 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
1049
1601
  };
1050
1602
  }
1051
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
+
1052
1642
  /** A blob's content as checkout writes it to the worktree (the worktree's smudge filter) */
1053
1643
  private async smudged(
1054
1644
  path: string,
@@ -1061,18 +1651,18 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
1061
1651
  );
1062
1652
  }
1063
1653
 
1064
- /** 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 */
1065
1660
  private async shownNames(
1066
1661
  pairs: DiffFilePair[],
1067
1662
  unmerged: Set<DiffFilePair>,
1068
1663
  options: DiffOutputOptions,
1069
1664
  ): Promise<DiffFilePair[]> {
1070
- const fromContents =
1071
- (this.textOptions.namesFromContents ?? true) &&
1072
- (options.ignoreWhitespace ||
1073
- options.ignoreWhitespaceChange ||
1074
- options.ignoreWhitespaceAtEol ||
1075
- options.ignoreCrAtEol);
1665
+ const fromContents = this.namesFromContents && this.fromContents;
1076
1666
  if (!fromContents) return pairs;
1077
1667
  const shown: DiffFilePair[] = [];
1078
1668
  for (const pair of pairs) {
@@ -1093,7 +1683,7 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
1093
1683
 
1094
1684
  /** What this diff compares */
1095
1685
  private get sides(): DiffSides {
1096
- if (this.newTree) return "trees";
1686
+ if (this.newTree || this.indexAsTree) return "trees";
1097
1687
  if (this.cached) return "cached";
1098
1688
  if (!this.worktreeIfAny) return "trees";
1099
1689
  return this.oldTree ? "commit-worktree" : "index-worktree";
@@ -1231,7 +1821,9 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
1231
1821
  if (!found) {
1232
1822
  found = (async () => {
1233
1823
  const attrs = await filter.attributes?.(path, ["diff"], context);
1234
- return withTextconv(diffDriverOf(attrs?.get("diff"), get));
1824
+ return withTextconv(
1825
+ diffDriverOf(attrs?.get("diff"), get, this.textOptions.driverCompatibility),
1826
+ );
1235
1827
  })();
1236
1828
  drivers.set(path, found);
1237
1829
  }
@@ -1248,8 +1840,34 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
1248
1840
  orderFile: _orderFile,
1249
1841
  textconv: _textconv,
1250
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,
1251
1862
  ...text
1252
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();
1253
1871
  const abbrev = abbrevOption(this.textOptions.abbrev);
1254
1872
  return {
1255
1873
  context: intValue(get("diff.context")) ?? 3,
@@ -1263,9 +1881,188 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
1263
1881
  algorithm: text.algorithm ?? algorithmValue(get("diff.algorithm")) ?? "myers",
1264
1882
  indentHeuristic: text.indentHeuristic ?? boolValue(get("diff.indentHeuristic")) ?? true,
1265
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
+ );
1266
1910
  };
1267
1911
  }
1268
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
+
1269
2066
  /**
1270
2067
  * The changed paths (and renames, when asked), in git's order, and the conflicted paths
1271
2068
  * `git diff` shows as combined diffs (`patch`: the patch format, where a path with both
@@ -1277,6 +2074,11 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
1277
2074
  patch = false,
1278
2075
  prefetch = false,
1279
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();
1280
2082
  // repo_read_index: in a sparse checkout, a skip-worktree entry whose file is present is
1281
2083
  // read as in the checkout (in memory: diff writes no index)
1282
2084
  await this.clearPresentSkipWorktree();
@@ -1311,6 +2113,7 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
1311
2113
  const unmerged = new Map<string, DiffEntry[]>();
1312
2114
  const combined: CombinedEntry[] = [];
1313
2115
  if (this.newTree) {
2116
+ if (this.pickaxe && !this.pickaxe.readsContent) this.treeSides = new Map();
1314
2117
  [oldSide, newSide] = await this.treePairSides(
1315
2118
  this.oldTree ?? "HEAD",
1316
2119
  this.oldTree === undefined,
@@ -1373,7 +2176,147 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
1373
2176
  // one batch first (diff_queued_diff_prefetch), before rename detection
1374
2177
  if (prefetch) await this.blobs.prefetch?.(prefetchIds(entries));
1375
2178
  if (renames) await this.detectRenames(entries, renames === "copies");
1376
- 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;
1377
2320
  }
1378
2321
 
1379
2322
  /**
@@ -1458,8 +2401,17 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
1458
2401
  ];
1459
2402
  }
1460
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
+
1461
2410
  private matches(path: string): boolean {
1462
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;
1463
2415
  return !this.pathspecItems || matchPathspec(this.pathspecItems, path, 0) > 0;
1464
2416
  }
1465
2417
 
@@ -1627,7 +2579,7 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
1627
2579
  private async treeSide(refOrId: string, implicitHead = false): Promise<Map<string, Side>> {
1628
2580
  const out = new Map<string, Side>();
1629
2581
  // the empty tree (a root commit's parent side), which a store need not hold
1630
- if (refOrId === EMPTY_TREE_ID) return out;
2582
+ if (refOrId === this.objectFormat.emptyTreeId) return out;
1631
2583
  let treeId: ObjectId;
1632
2584
  try {
1633
2585
  treeId = await this.resolveTreeId(refOrId);
@@ -1652,11 +2604,11 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
1652
2604
  const oldSide = new Map<string, Side>();
1653
2605
  const newSide = new Map<string, Side>();
1654
2606
  const treeOf = async (ref: string, implicit: boolean): Promise<ObjectId | undefined> => {
1655
- if (ref === EMPTY_TREE_ID) return undefined;
2607
+ if (ref === this.objectFormat.emptyTreeId) return undefined;
1656
2608
  // a tree's full id (as `git log -p` passes its commits' trees): read at once, its
1657
2609
  // entries kept for the comparison
1658
2610
  const trees = this.trees;
1659
- if (/^[0-9a-f]{40}$/.test(ref)) {
2611
+ if (this.isFullObjectId(ref)) {
1660
2612
  const known = trees.raw ? trees.raw(ref) : trees.entries?.(ref);
1661
2613
  if (known && (await known)) return ref;
1662
2614
  }
@@ -1687,8 +2639,10 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
1687
2639
  ): Promise<void> {
1688
2640
  if (a === b) return;
1689
2641
  if (this.trees.raw) return this.diffRawTrees(a, b, prefix, oldSide, newSide);
1690
- const ea = a === undefined || a === EMPTY_TREE_ID ? [] : await this.treeEntries(a);
1691
- const eb = b === undefined || b === EMPTY_TREE_ID ? [] : await this.treeEntries(b);
2642
+ const ea =
2643
+ a === undefined || a === this.objectFormat.emptyTreeId ? [] : await this.treeEntries(a);
2644
+ const eb =
2645
+ b === undefined || b === this.objectFormat.emptyTreeId ? [] : await this.treeEntries(b);
1692
2646
  let i = 0;
1693
2647
  let j = 0;
1694
2648
  while (i < ea.length || j < eb.length) {
@@ -1718,6 +2672,8 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
1718
2672
  if (xe.id === ye.id && xe.mode === ye.mode) continue;
1719
2673
  const path = prefix ? `${prefix}/${xe.name}` : xe.name;
1720
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);
1721
2677
  await this.diffTreeSides(xe.id, ye.id, path, oldSide, newSide);
1722
2678
  continue;
1723
2679
  }
@@ -1741,9 +2697,11 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
1741
2697
  if (a === b) return;
1742
2698
  const trees = this.trees;
1743
2699
  const read = async (id: ObjectId | undefined) =>
1744
- id === undefined || id === EMPTY_TREE_ID ? NO_BYTES : ((await trees.raw?.(id)) ?? NO_BYTES);
1745
- const x = new TreeEntryCursor(await read(a));
1746
- const y = new TreeEntryCursor(await read(b));
2700
+ id === undefined || id === this.objectFormat.emptyTreeId
2701
+ ? NO_BYTES
2702
+ : ((await trees.raw?.(id)) ?? NO_BYTES);
2703
+ const x = new TreeEntryCursor(await read(a), this.objectFormat.rawLength);
2704
+ const y = new TreeEntryCursor(await read(b), this.objectFormat.rawLength);
1747
2705
  const pathOf = (name: string) => (prefix ? `${prefix}/${name}` : name);
1748
2706
  while (!x.done || !y.done) {
1749
2707
  const order = x.done ? 1 : y.done ? -1 : x.compare(y);
@@ -1756,8 +2714,11 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
1756
2714
  } else {
1757
2715
  if (!x.sameAs(y)) {
1758
2716
  const path = pathOf(x.name());
1759
- if (x.isTree && y.isTree) await this.diffRawTrees(x.id(), y.id(), path, oldSide, newSide);
1760
- 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 {
1761
2722
  await this.addRawSide(x, path, oldSide);
1762
2723
  await this.addRawSide(y, path, newSide);
1763
2724
  }
@@ -1774,14 +2735,30 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
1774
2735
  path: string,
1775
2736
  side: Map<string, Side>,
1776
2737
  ): Promise<void> {
1777
- if (c.isTree) await this.collectTreeEntries(c.id(), path, side);
1778
- 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() });
1779
2742
  }
1780
2743
 
1781
2744
  /** A tree entry on one side: a blob as itself, a subtree as its blobs */
1782
2745
  private async addSide(e: TreeEntry, path: string, side: Map<string, Side>): Promise<void> {
1783
- if (isTreeMode(e.mode)) await this.collectTreeEntries(e.id, path, side);
1784
- 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 });
1785
2762
  }
1786
2763
 
1787
2764
  /**
@@ -1940,7 +2917,7 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
1940
2917
  */
1941
2918
  private async resolveTreeId(refOrId: string): Promise<ObjectId> {
1942
2919
  // a full object id names that object, as get_oid takes it: no ref is looked up
1943
- if (/^[0-9a-f]{40}$/.test(refOrId)) {
2920
+ if (this.isFullObjectId(refOrId)) {
1944
2921
  const tree = await this.revisionResolver()
1945
2922
  .peelToType(refOrId, "tree")
1946
2923
  .catch(() => undefined);
@@ -1950,7 +2927,7 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
1950
2927
  try {
1951
2928
  id = await this.resolveRevision(refOrId);
1952
2929
  } catch (e) {
1953
- if (/^[0-9a-f]{40}$/.test(refOrId) && (await this.isTree(refOrId))) return refOrId;
2930
+ if (this.isFullObjectId(refOrId) && (await this.isTree(refOrId))) return refOrId;
1954
2931
  if (refOrId === "HEAD") throw new NoHeadError("HEAD cannot be resolved");
1955
2932
  if (e instanceof RefNotFoundError) {
1956
2933
  throw new RefNotFoundError(refOrId, `bad revision '${refOrId}'`);
@@ -1983,6 +2960,7 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
1983
2960
  for (const entry of await this.treeEntries(treeId)) {
1984
2961
  const path = prefix ? `${prefix}/${entry.name}` : entry.name;
1985
2962
  if ((entry.mode & S_IFMT) === TREE_MODE) {
2963
+ this.addTreeSide(path, entry.mode, entry.id, entries);
1986
2964
  await this.collectTreeEntries(entry.id, path, entries);
1987
2965
  } else {
1988
2966
  // the mode as git's tree walk reads it (canon_mode), as the tree store reads it