fix(picker.git): --follow only works for git_log_file. Closes #666

This commit is contained in:
Folke Lemaitre 2025-01-20 16:04:39 +01:00
parent f65a2c82f3
commit 23a8668ef0
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040
2 changed files with 11 additions and 7 deletions

View file

@ -8,6 +8,7 @@
---@field paths {path:string, want:boolean}[] ---@field paths {path:string, want:boolean}[]
---@field opts snacks.picker.filter.Config ---@field opts snacks.picker.filter.Config
---@field current_buf number ---@field current_buf number
---@field current_win number
local M = {} local M = {}
M.__index = M M.__index = M
@ -18,6 +19,7 @@ function M.new(picker)
local opts = picker.opts ---@type snacks.picker.Config|{filter?:snacks.picker.filter.Config} local opts = picker.opts ---@type snacks.picker.Config|{filter?:snacks.picker.filter.Config}
local self = setmetatable({}, M) local self = setmetatable({}, M)
self.current_buf = vim.api.nvim_get_current_buf() self.current_buf = vim.api.nvim_get_current_buf()
self.current_win = vim.api.nvim_get_current_win()
self.opts = opts.filter or {} self.opts = opts.filter or {}
local function gets(v) local function gets(v)
return type(v) == "function" and v(picker) or v or "" --[[@as string]] return type(v) == "function" and v(picker) or v or "" --[[@as string]]

View file

@ -33,7 +33,7 @@ end
---@param opts snacks.picker.git.log.Config ---@param opts snacks.picker.git.log.Config
---@type snacks.picker.finder ---@type snacks.picker.finder
function M.log(opts) function M.log(opts, filter)
local args = { local args = {
"log", "log",
"--pretty=format:%h %s (%ch)", "--pretty=format:%h %s (%ch)",
@ -44,20 +44,22 @@ function M.log(opts)
"--no-show-signature", "--no-show-signature",
"--no-patch", "--no-patch",
} }
if opts.follow and not opts.current_file then
if opts.follow and not opts.current_line then opts.follow = nil
args[#args + 1] = "--follow"
end end
local file ---@type string? local file ---@type string?
if opts.current_line then if opts.current_line then
local cursor = vim.api.nvim_win_get_cursor(0) local cursor = vim.api.nvim_win_get_cursor(filter.current_win)
file = vim.api.nvim_buf_get_name(0) file = vim.api.nvim_buf_get_name(filter.current_buf)
local line = cursor[1] local line = cursor[1]
args[#args + 1] = "-L" args[#args + 1] = "-L"
args[#args + 1] = line .. ",+1:" .. file args[#args + 1] = line .. ",+1:" .. file
elseif opts.current_file then elseif opts.current_file then
file = vim.api.nvim_buf_get_name(0) file = vim.api.nvim_buf_get_name(filter.current_buf)
if opts.follow then
args[#args + 1] = "--follow"
end
args[#args + 1] = "--" args[#args + 1] = "--"
args[#args + 1] = file args[#args + 1] = file
end end