Skip to content

Commit af12567

Browse files
committed
fix(git): only show untracked files when comparing index vs working tree
PR sindrets#587 changed the condition to show untracked files whenever the right side is LOCAL (working tree). This caused untracked files to appear when running `DiffviewOpen <commit>`, which compares a commit to the working tree. Restore the original behaviour: only show untracked files when comparing STAGE (index) vs LOCAL (working tree), i.e. standard `DiffviewOpen`.
1 parent 07be128 commit af12567

2 files changed

Lines changed: 7 additions & 5 deletions

File tree

lua/diffview/ui/panels/commit_log_panel.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ end
4949
---@field args string[]
5050
---@field name string
5151

52+
---@param parent StandardView
5253
---@param adapter VCSAdapter
5354
---@param opt CommitLogPanelSpec
5455
function CommitLogPanel:init(parent, adapter, opt)

lua/diffview/vcs/adapters/git/init.lua

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -311,14 +311,14 @@ function GitAdapter:get_merge_context()
311311
end
312312

313313
local ret = {}
314-
local out, code = self:exec_sync({ "show", "-s", "--pretty=format:%H%n%D", "HEAD", "--no-show-signature", "--" }, self.ctx.toplevel)
314+
local out, code = self:exec_sync({ "show", "-s", "--no-show-signature", "--pretty=format:%H%n%D", "HEAD", "--" }, self.ctx.toplevel)
315315

316316
ret.ours = code ~= 0 and {} or {
317317
hash = out[1],
318318
ref_names = out[2],
319319
}
320320

321-
out, code = self:exec_sync({ "show", "-s", "--pretty=format:%H%n%D", their_head, "--no-show-signature", "--" }, self.ctx.toplevel)
321+
out, code = self:exec_sync({ "show", "-s", "--no-show-signature", "--pretty=format:%H%n%D", their_head, "--" }, self.ctx.toplevel)
322322

323323
ret.theirs = code ~= 0 and {} or {
324324
hash = out[1],
@@ -1040,10 +1040,10 @@ GitAdapter.fh_retry_commit = async.wrap(function(self, rev_arg, state, opt, call
10401040
"-c",
10411041
"core.quotePath=false",
10421042
"show",
1043+
"--no-show-signature",
10431044
"--pretty=format:" .. GitAdapter.COMMIT_PRETTY_FMT,
10441045
"--numstat",
10451046
"--raw",
1046-
"--no-show-signature",
10471047
"--diff-merges=" .. state.log_options.diff_merges,
10481048
(state.single_file and state.log_options.follow) and "--follow" or nil,
10491049
rev_arg,
@@ -1801,8 +1801,9 @@ function GitAdapter:show_untracked(opt)
18011801
opt = opt or {}
18021802

18031803
if opt.revs then
1804-
-- Show untracked files when comparing against the working tree (LOCAL)
1805-
if opt.revs.right.type ~= RevType.LOCAL then
1804+
-- Show untracked files only when comparing index (STAGE) vs working tree (LOCAL).
1805+
-- Don't show untracked when comparing a commit to working tree.
1806+
if not (opt.revs.left.type == RevType.STAGE and opt.revs.right.type == RevType.LOCAL) then
18061807
return false
18071808
end
18081809
end

0 commit comments

Comments
 (0)