feat(picker.git): allow passing extra args to other git pickers (#1205)

## Description

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

This PR builds on
7122a03fdf
to provide a way to pass custom `args` to git command invocations.

An alternative (probably cleaner) way of doing this could be to add an
`args` field to `picker.sources.git`:

```yaml
      picker = {
        ---@class snacks.picker.previewers.Config
        previewers = {
          git = {
            args = git_opts(),
          },
        },
        ---@class snacks.picker.sources.Config
        sources = {
          git = {
            args = git_opts(),
          },
        },
```

## Related Issue(s)

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

Fixes #1184

## Screenshots

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

---------

Co-authored-by: Folke Lemaitre <folke.lemaitre@gmail.com>
This commit is contained in:
Pedro Pombeiro 2025-02-18 21:07:50 +01:00 committed by GitHub
parent 7c382193ee
commit 4d46574b24
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 33 additions and 25 deletions

View file

@ -207,6 +207,10 @@ M.files = {
supports_live = true,
}
---@class snacks.picker.git.Config: snacks.picker.Config
---@field args? string[] additional arguments to pass to `git ls-files`
---@type snacks.picker.git.Config
M.git_branches = {
finder = "git_branches",
format = "git_branch",
@ -220,6 +224,7 @@ M.git_branches = {
},
},
},
---@param picker snacks.Picker
on_show = function(picker)
for i, item in ipairs(picker:items()) do
if item.current then
@ -232,7 +237,7 @@ M.git_branches = {
}
-- Find git files
---@class snacks.picker.git.files.Config: snacks.picker.Config
---@class snacks.picker.git.files.Config: snacks.picker.git.Config
---@field untracked? boolean show untracked files
---@field submodules? boolean show submodule files
M.git_files = {
@ -244,8 +249,7 @@ M.git_files = {
}
-- Grep in git files
---@class snacks.picker.git.grep.Config: snacks.picker.Config
---@field args? string[] additional arguments to pass to `git grep`
---@class snacks.picker.git.grep.Config: snacks.picker.git.Config
---@field untracked? boolean search in untracked files
---@field submodules? boolean search in submodule files
---@field need_search? boolean require a search pattern
@ -261,7 +265,7 @@ M.git_grep = {
}
-- Git log
---@class snacks.picker.git.log.Config: snacks.picker.Config
---@class snacks.picker.git.log.Config: snacks.picker.git.Config
---@field follow? boolean track file history across renames
---@field current_file? boolean show current file log
---@field current_line? boolean show current line log
@ -302,7 +306,7 @@ M.git_stash = {
confirm = "git_stash_apply",
}
---@class snacks.picker.git.status.Config: snacks.picker.Config
---@class snacks.picker.git.status.Config: snacks.picker.git.Config
---@field ignored? boolean show ignored files
M.git_status = {
finder = "git_status",
@ -317,6 +321,7 @@ M.git_status = {
},
}
---@type snacks.picker.git.Config
M.git_diff = {
finder = "git_diff",
format = "file",