From 97097b779f1b10ef098edf7e913c282e4c274dca Mon Sep 17 00:00:00 2001 From: xzb <2598514867@qq.com> Date: Sun, 21 Jul 2024 05:47:50 +0800 Subject: [PATCH] fix: setqflist("all") should respect change_base pass config.base as parameter to files_changed check if base = ":0" --- lua/gitsigns/actions.lua | 11 +++++++++-- lua/gitsigns/git/repo.lua | 25 ++++++++++++++++++------- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/lua/gitsigns/actions.lua b/lua/gitsigns/actions.lua index e70a940f5..a019af844 100644 --- a/lua/gitsigns/actions.lua +++ b/lua/gitsigns/actions.lua @@ -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) diff --git a/lua/gitsigns/git/repo.lua b/lua/gitsigns/git/repo.lua index 4c86ee556..2bd611609 100644 --- a/lua/gitsigns/git/repo.lua +++ b/lua/gitsigns/git/repo.lua @@ -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