@@ -21,20 +21,30 @@ local function get_local_diff_view(section_name, item_name, opts)
21
21
local function update_files (current_file_path )
22
22
local files = {}
23
23
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
+
24
34
local sections = {
25
35
conflicting = {
26
36
items = vim .tbl_filter (function (item )
27
37
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 {} ),
29
39
},
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 = {} } ,
32
42
}
33
43
34
44
for kind , section in pairs (sections ) do
35
45
files [kind ] = {}
36
46
37
- for idx , item in ipairs (section .items ) do
47
+ for idx , item in ipairs (section .items or {} ) do
38
48
local file = {
39
49
path = item .name ,
40
50
status = item .mode and item .mode :sub (1 , 1 ),
@@ -86,17 +96,11 @@ local function get_local_diff_view(section_name, item_name, opts)
86
96
end ,
87
97
}
88
98
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 )
100
104
dv_lib .add_view (view )
101
105
102
106
return view
0 commit comments