Skip to content

Commit

Permalink
fix: setqflist("all") should respect change_base
Browse files Browse the repository at this point in the history
pass config.base as parameter to files_changed

check if base = ":0"
  • Loading branch information
xzbdmw authored and lewis6991 committed Aug 4, 2024
1 parent 564849a commit 58bd9e9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
11 changes: 9 additions & 2 deletions lua/gitsigns/actions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1294,11 +1294,18 @@ local function buildqflist(target)
end

for _, r in pairs(repos) do
for _, f in ipairs(r:files_changed()) do
for _, f in ipairs(r:files_changed(config.base)) do
local f_abs = r.toplevel .. '/' .. f
local stat = vim.loop.fs_stat(f_abs)
if stat and stat.type == 'file' then
local a = r:get_show_text(':0:' .. f)
---@type string
local obj
if config.base and config.base ~= ':0' then
obj = config.base .. ':' .. f
else
obj = ':0:' .. f
end
local a = r:get_show_text(obj)
async.scheduler()
local hunks = run_diff(a, util.file_lines(f_abs))
hunks_to_qflist(f_abs, hunks, qflist)
Expand Down
25 changes: 18 additions & 7 deletions lua/gitsigns/git/repo.lua
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,29 @@ function M:command(args, spec)
return git_command(args1, spec)
end

--- @param base string?
--- @return string[]
function M:files_changed()
function M:files_changed(base)
--- @type string[]
local results = self:command({ 'status', '--porcelain', '--ignore-submodules' })
local results
if base and base ~= ':0' then
results = self:command({ 'diff', '--name-status', base })

local ret = {} --- @type string[]
for _, line in ipairs(results) do
if line:sub(1, 2):match('^.M') then
ret[#ret + 1] = line:sub(4, -1)
for i, result in ipairs(results) do
results[i] = vim.split(string.gsub(result, '\t', ' '), ' ', { plain = true })[2]
end
return results
else
results = self:command({ 'status', '--porcelain', '--ignore-submodules' })

local ret = {} --- @type string[]
for _, line in ipairs(results) do
if line:sub(1, 2):match('^.M') then
ret[#ret + 1] = line:sub(4, -1)
end
end
return ret
end
return ret
end

--- @param encoding string
Expand Down

0 comments on commit 58bd9e9

Please sign in to comment.