feat(picker.git): use default previewer args in git_show (#1736)

## Description

<!-- Describe the big picture of your changes to communicate to the
maintainers
  why we should accept this pull request. -->

Currently, I'm able to perform a search on a YADM repo by passing the
args `{ "--git-dir", "/Users/pedro/.local/share/yadm/repo.git",
"--work-tree", "/Users/pedro" }` to `picker.previewers.git.args`.
Unfortunately, the `git_show` previewer is currently not using this
configuration, so constantly fails to show the preview with an error
message. This MR fixes the problem by leveraging the existing `git`
local function.

## Related Issue(s)

<!--
  If this PR fixes any issues, please link to the issue here.
  - Fixes #<issue_number>
-->

## Screenshots

<!-- Add screenshots of the changes if applicable. -->

<img width="1582" alt="image"
src="https://github.com/user-attachments/assets/6f7c3960-cfc0-4c0c-a264-105a721cd9a8"
/>

Previewer working inside a YADM repo.
This commit is contained in:
Pedro Pombeiro 2025-10-21 16:43:37 +02:00 committed by GitHub
parent 5f52f9d9e2
commit f324f96bea
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -285,16 +285,18 @@ function M.cmd(cmd, ctx, opts)
return jid
end
---@param ctx snacks.picker.preview.ctx
local function git(ctx, ...)
local ret = { "git", "-c", "delta." .. vim.o.background .. "=true" }
vim.list_extend(ret, ctx.picker.opts.previewers.git.args or {})
vim.list_extend(ret, { ... })
return ret
end
---@param ctx snacks.picker.preview.ctx
function M.git_show(ctx)
local builtin = ctx.picker.opts.previewers.git.builtin
local cmd = {
"git",
"-c",
"delta." .. vim.o.background .. "=true",
"show",
ctx.item.commit,
}
local cmd = git(ctx, "show", ctx.item.commit)
local pathspec = ctx.item.files or ctx.item.file
pathspec = type(pathspec) == "table" and pathspec or { pathspec }
if #pathspec > 0 then
@ -307,14 +309,6 @@ function M.git_show(ctx)
M.cmd(cmd, ctx, { ft = builtin and "git" or nil })
end
---@param ctx snacks.picker.preview.ctx
local function git(ctx, ...)
local ret = { "git", "-c", "delta." .. vim.o.background .. "=true" }
vim.list_extend(ret, ctx.picker.opts.previewers.git.args or {})
vim.list_extend(ret, { ... })
return ret
end
---@param ctx snacks.picker.preview.ctx
function M.git_log(ctx)
local cmd = git(