feat(picker.git_diff): add base option to show diff against a merge base. Useful to see changes on a branch/PR

This commit is contained in:
Folke Lemaitre 2025-10-23 09:25:54 +02:00
parent b4e2384da9
commit 7964f040bf
No known key found for this signature in database
GPG key ID: 9B52594D560070AB
2 changed files with 6 additions and 2 deletions

View file

@ -333,7 +333,8 @@ M.git_status = {
},
}
---@type snacks.picker.git.Config
---@class snacks.picker.git.diff.Config: snacks.picker.git.Config
---@field base? string base commit/branch/tag to diff against (default: HEAD)
M.git_diff = {
finder = "git_diff",
format = "file",

View file

@ -253,11 +253,14 @@ function M.status(opts, ctx)
}, ctx)
end
---@param opts snacks.picker.git.Config
---@param opts snacks.picker.git.diff.Config
---@type snacks.picker.finder
function M.diff(opts, ctx)
local args =
M.git("diff", "--no-color", "--no-ext-diff", { args = { "-c", "diff.noprefix=false", "--no-pager" } }, opts)
if opts.base then
vim.list_extend(args, { "--merge-base", opts.base })
end
local file, line ---@type string?, number?
local header, hunk = {}, {} ---@type string[], string[]
local header_len = 4