@@ -157,17 +157,36 @@ M.status_async = function(path, base)
157157 end
158158
159159 local context = {
160+ remaining_jobs = 0 ,
161+ success_count = 0 ,
160162 git_root = git_root ,
161163 git_status = {},
162164 exclude_directories = false ,
163165 }
166+
167+ local job_complete = function (return_val )
168+ context .remaining_jobs = context .remaining_jobs - 1
169+ if return_val == 0 then
170+ context .success_count = context .success_count + 1
171+ end
172+ if context .remaining_jobs < 1 and context .success_count > 0 then
173+ vim .schedule (function ()
174+ events .fire_event (events .GIT_STATUS_CHANGED , {
175+ git_root = context .git_root ,
176+ git_status = context .git_status ,
177+ })
178+ end )
179+ end
180+ end
181+
164182 local wrapped_process_line_staged = vim .schedule_wrap (function (err , line )
165183 if err and err > 0 then
166184 log .error (" status_async staged error: " , err , line )
167185 else
168186 parse_git_status_line (context , line )
169187 end
170188 end )
189+
171190 local wrapped_process_line_unstaged = vim .schedule_wrap (function (err , line )
172191 if err and err > 0 then
173192 log .error (" status_async unstaged error: " , err , line )
@@ -178,6 +197,7 @@ M.status_async = function(path, base)
178197 parse_git_status_line (context , line )
179198 end
180199 end )
200+
181201 local wrapped_process_line_untracked = vim .schedule_wrap (function (err , line )
182202 if err and err > 0 then
183203 log .error (" status_async untracked error: " , err , line )
@@ -202,20 +222,14 @@ M.status_async = function(path, base)
202222 log .error (" status_async staged error: " , err , line )
203223 end
204224 end ,
205- on_exit = function (job , return_val )
225+ on_exit = function (_ , return_val )
206226 utils .debounce (event_id_staged , nil , nil , nil , utils .debounce_action .COMPLETE_ASYNC_JOB )
207- if return_val == 0 then
208- log .trace (" status_async staged completed" )
209- vim .schedule (function ()
210- events .fire_event (events .GIT_STATUS_CHANGED , {
211- git_root = context .git_root ,
212- git_status = context .git_status ,
213- })
214- end )
215- end
227+ log .trace (" status_async staged completed with return_val: " , return_val )
228+ job_complete (return_val )
216229 end ,
217230 })
218231 :start ()
232+ context .remaining_jobs = context .remaining_jobs + 1
219233 end , 1000 , utils .debounce_strategy .CALL_FIRST_AND_LAST , utils .debounce_action .START_ASYNC_JOB )
220234
221235 local event_id_unstaged = " git_status_unstaged_" .. git_root
@@ -231,20 +245,14 @@ M.status_async = function(path, base)
231245 log .error (" status_async unstaged error: " , err , line )
232246 end
233247 end ,
234- on_exit = function (job , return_val )
248+ on_exit = function (_ , return_val )
235249 utils .debounce (event_id_unstaged , nil , nil , nil , utils .debounce_action .COMPLETE_ASYNC_JOB )
236- if return_val == 0 then
237- log .trace (" status_async unstaged completed" )
238- vim .schedule (function ()
239- events .fire_event (events .GIT_STATUS_CHANGED , {
240- git_root = context .git_root ,
241- git_status = context .git_status ,
242- })
243- end )
244- end
250+ log .trace (" status_async unstaged completed with return_val: " , return_val )
251+ job_complete (return_val )
245252 end ,
246253 })
247254 :start ()
255+ context .remaining_jobs = context .remaining_jobs + 1
248256 end , 1000 , utils .debounce_strategy .CALL_FIRST_AND_LAST , utils .debounce_action .START_ASYNC_JOB )
249257
250258 local event_id_untracked = " git_status_untracked_" .. git_root
@@ -260,26 +268,20 @@ M.status_async = function(path, base)
260268 log .error (" status_async untracked error: " , err , line )
261269 end
262270 end ,
263- on_exit = function (job , return_val )
271+ on_exit = function (_ , return_val )
264272 utils .debounce (
265273 event_id_untracked ,
266274 nil ,
267275 nil ,
268276 nil ,
269277 utils .debounce_action .COMPLETE_ASYNC_JOB
270278 )
271- if return_val == 0 then
272- log .trace (" status_async untracked completed" )
273- vim .schedule (function ()
274- events .fire_event (events .GIT_STATUS_CHANGED , {
275- git_root = context .git_root ,
276- git_status = context .git_status ,
277- })
278- end )
279- end
279+ log .trace (" status_async untracked completed with return_val: " , return_val )
280+ job_complete (return_val )
280281 end ,
281282 })
282283 :start ()
284+ context .remaining_jobs = context .remaining_jobs + 1
283285 end , 1000 , utils .debounce_strategy .CALL_FIRST_AND_LAST , utils .debounce_action .START_ASYNC_JOB )
284286
285287 return true
0 commit comments