Skip to content

Commit 2a6ffa0

Browse files
feat(setqflist): include untracked files when attach_to_untracked is enabled
When using setqflist('all'), untracked files are now included in the quickfix list if the attach_to_untracked config option is enabled. Closes #829
1 parent abf82a6 commit 2a6ffa0

File tree

4 files changed

+15
-5
lines changed

4 files changed

+15
-5
lines changed

doc/gitsigns.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,9 @@ setqflist({target}, {opts}, {callback}) *gitsigns.setqflist()*
160160
`"attached"`: All attached buffers.
161161
`"all"`: All modified files for each git
162162
directory of all attached buffers in addition
163-
to the current working directory.
163+
to the current working directory. When
164+
`attach_to_untracked` is enabled, untracked
165+
files are also included.
164166
{opts} (`Gitsigns.SetqflistOpts?`): Additional options.
165167
• {use_location_list}: (`boolean?`)
166168
Populate the location list instead of the quickfix list.

lua/gitsigns/actions.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -896,7 +896,9 @@ CP.show_commit = complete_heads
896896
--- - `"attached"`: All attached buffers.
897897
--- - `"all"`: All modified files for each git
898898
--- directory of all attached buffers in addition
899-
--- to the current working directory.
899+
--- to the current working directory. When
900+
--- `attach_to_untracked` is enabled, untracked
901+
--- files are also included.
900902
--- @param opts Gitsigns.SetqflistOpts? Additional options.
901903
--- @param callback? fun(err?: string)
902904
function M.setqflist(target, opts, callback)

lua/gitsigns/actions/qflist.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ local function buildqflist(target)
7474
end
7575

7676
for _, r in pairs(repos) do
77-
for _, f in ipairs(r:files_changed(config.base)) do
77+
for _, f in ipairs(r:files_changed(config.base, config.attach_to_untracked)) do
7878
local f_abs = r.toplevel .. '/' .. f
7979
local stat = uv.fs_stat(f_abs)
8080
if stat and stat.type == 'file' then

lua/gitsigns/git/repo.lua

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,21 +105,27 @@ end
105105

106106
--- @async
107107
--- @param base string?
108+
--- @param include_untracked? boolean
108109
--- @return string[]
109-
function M:files_changed(base)
110+
function M:files_changed(base, include_untracked)
110111
if base and base ~= ':0' then
111112
local results = self:command({ 'diff', '--name-status', base })
112113
for i, result in ipairs(results) do
113114
results[i] = vim.split(result:gsub('\t', ' '), ' ', { plain = true })[2]
114115
end
116+
if include_untracked then
117+
local untracked = self:command({ 'ls-files', '--others', '--exclude-standard' })
118+
vim.list_extend(results, untracked)
119+
end
115120
return results
116121
end
117122

118123
local results = self:command({ 'status', '--porcelain', '--ignore-submodules' })
119124

120125
local ret = {} --- @type string[]
121126
for _, line in ipairs(results) do
122-
if line:sub(1, 2):match('^.M') then
127+
local status = line:sub(1, 2)
128+
if status:match('^.M') or (include_untracked and status == '??') then
123129
ret[#ret + 1] = line:sub(4, -1)
124130
end
125131
end

0 commit comments

Comments
 (0)