@@ -45,20 +45,30 @@ local function get_local_diff_view(section_name, item_name, opts)
4545 local function update_files (current_file_path )
4646 local files = {}
4747
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+
4858 local sections = {
4959 conflicting = {
5060 items = vim .tbl_filter (function (item )
5161 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 {} ),
5363 },
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 = {} } ,
5666 }
5767
5868 for kind , section in pairs (sections ) do
5969 files [kind ] = {}
6070
61- for idx , item in ipairs (section .items ) do
71+ for idx , item in ipairs (section .items or {} ) do
6272 local file = {
6373 path = item .name ,
6474 status = item .mode and item .mode :sub (1 , 1 ),
@@ -110,17 +120,11 @@ local function get_local_diff_view(section_name, item_name, opts)
110120 end ,
111121 }
112122
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 )
124128 dv_lib .add_view (view )
125129
126130 return view
0 commit comments