feat(git_log): add author filter (#1091)

## Description

I was using LazyGit feature to filter git logs by the author,
unfortunately it was missing in snacks picker. Here is my solution to
it. Let me know if you have better suggestion :)

---------

Co-authored-by: Folke Lemaitre <folke.lemaitre@gmail.com>
This commit is contained in:
Imron Gamidli 2025-02-18 21:12:31 +01:00 committed by GitHub
parent f32002607a
commit 8c1166165b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 6 additions and 0 deletions

View file

@ -269,6 +269,7 @@ M.git_grep = {
---@field follow? boolean track file history across renames
---@field current_file? boolean show current file log
---@field current_line? boolean show current line log
---@field author? string filter commits by author
M.git_log = {
finder = "git_log",
format = "git_log",

View file

@ -100,6 +100,10 @@ function M.log(opts, ctx)
"--no-patch"
)
if opts.author then
table.insert(args, "--author=" .. opts.author)
end
local file ---@type string?
if opts.current_line then
local cursor = vim.api.nvim_win_get_cursor(ctx.filter.current_win)
@ -118,6 +122,7 @@ function M.log(opts, ctx)
local Proc = require("snacks.picker.source.proc")
file = file and vim.fs.normalize(file) or nil
local cwd = vim.fs.normalize(file and vim.fn.fnamemodify(file, ":h") or opts and opts.cwd or uv.cwd() or ".") or nil
cwd = Snacks.git.get_root(cwd) or cwd