@@ -45,20 +45,30 @@ local function get_local_diff_view(section_name, item_name, opts)
45
45
local function update_files (current_file_path )
46
46
local files = {}
47
47
48
+ git .repo :dispatch_refresh ({
49
+ source = " diffview_update" ,
50
+ callback = function () end ,
51
+ })
52
+
53
+ local repo_state = git .repo .state
54
+ if not repo_state then
55
+ return files
56
+ end
57
+
48
58
local sections = {
49
59
conflicting = {
50
60
items = vim .tbl_filter (function (item )
51
61
return item .mode and item .mode :sub (2 , 2 ) == " U"
52
- end , git . repo . state . untracked .items ),
62
+ end , repo_state . untracked and repo_state . untracked .items or {} ),
53
63
},
54
- working = git . repo . state . unstaged ,
55
- staged = git . repo . state . staged ,
64
+ working = repo_state . unstaged or { items = {} } ,
65
+ staged = repo_state . staged or { items = {} } ,
56
66
}
57
67
58
68
for kind , section in pairs (sections ) do
59
69
files [kind ] = {}
60
70
61
- for idx , item in ipairs (section .items ) do
71
+ for idx , item in ipairs (section .items or {} ) do
62
72
local file = {
63
73
path = item .name ,
64
74
status = item .mode and item .mode :sub (1 , 1 ),
@@ -110,17 +120,11 @@ local function get_local_diff_view(section_name, item_name, opts)
110
120
end ,
111
121
}
112
122
113
- view :on_files_staged (a .void (function ()
114
- local current_file_path
115
- local current_buf_name = vim .api .nvim_buf_get_name (0 )
116
- if current_buf_name and current_buf_name ~= " " then
117
- current_file_path = current_buf_name :gsub (git .repo .worktree_root .. " /" , " " )
118
- end
119
-
120
- Watcher .instance ():dispatch_refresh ()
121
- view :update_files (current_file_path )
122
- end ))
123
-
123
+ view :on_files_staged (function ()
124
+ vim .schedule (function ()
125
+ Watcher .instance ():dispatch_refresh ()
126
+ end )
127
+ end )
124
128
dv_lib .add_view (view )
125
129
126
130
return view
0 commit comments