Skip to content

Commit 4ccbb92

Browse files
committed
fix(diffview): Refresh git state before updating files
1 parent 094a432 commit 4ccbb92

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

lua/neogit/integrations/diffview.lua

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,30 @@ local function get_local_diff_view(section_name, item_name, opts)
2121
local function update_files(current_file_path)
2222
local files = {}
2323

24+
git.repo:dispatch_refresh({
25+
source = "diffview_update",
26+
callback = function() end,
27+
})
28+
29+
local repo_state = git.repo.state
30+
if not repo_state then
31+
return files
32+
end
33+
2434
local sections = {
2535
conflicting = {
2636
items = vim.tbl_filter(function(item)
2737
return item.mode and item.mode:sub(2, 2) == "U"
28-
end, git.repo.state.untracked.items),
38+
end, repo_state.untracked and repo_state.untracked.items or {}),
2939
},
30-
working = git.repo.state.unstaged,
31-
staged = git.repo.state.staged,
40+
working = repo_state.unstaged or { items = {} },
41+
staged = repo_state.staged or { items = {} },
3242
}
3343

3444
for kind, section in pairs(sections) do
3545
files[kind] = {}
3646

37-
for idx, item in ipairs(section.items) do
47+
for idx, item in ipairs(section.items or {}) do
3848
local file = {
3949
path = item.name,
4050
status = item.mode and item.mode:sub(1, 1),
@@ -86,17 +96,11 @@ local function get_local_diff_view(section_name, item_name, opts)
8696
end,
8797
}
8898

89-
view:on_files_staged(a.void(function()
90-
local current_file_path
91-
local current_buf_name = vim.api.nvim_buf_get_name(0)
92-
if current_buf_name and current_buf_name ~= "" then
93-
current_file_path = current_buf_name:gsub(git.repo.worktree_root .. "/", "")
94-
end
95-
96-
Watcher.instance():dispatch_refresh()
97-
view:update_files(current_file_path)
98-
end))
99-
99+
view:on_files_staged(function()
100+
vim.schedule(function()
101+
Watcher.instance():dispatch_refresh()
102+
end)
103+
end)
100104
dv_lib.add_view(view)
101105

102106
return view

0 commit comments

Comments
 (0)