@@ -157,17 +157,36 @@ M.status_async = function(path, base)
157
157
end
158
158
159
159
local context = {
160
+ remaining_jobs = 0 ,
161
+ success_count = 0 ,
160
162
git_root = git_root ,
161
163
git_status = {},
162
164
exclude_directories = false ,
163
165
}
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
+
164
182
local wrapped_process_line_staged = vim .schedule_wrap (function (err , line )
165
183
if err and err > 0 then
166
184
log .error (" status_async staged error: " , err , line )
167
185
else
168
186
parse_git_status_line (context , line )
169
187
end
170
188
end )
189
+
171
190
local wrapped_process_line_unstaged = vim .schedule_wrap (function (err , line )
172
191
if err and err > 0 then
173
192
log .error (" status_async unstaged error: " , err , line )
@@ -178,6 +197,7 @@ M.status_async = function(path, base)
178
197
parse_git_status_line (context , line )
179
198
end
180
199
end )
200
+
181
201
local wrapped_process_line_untracked = vim .schedule_wrap (function (err , line )
182
202
if err and err > 0 then
183
203
log .error (" status_async untracked error: " , err , line )
@@ -202,20 +222,14 @@ M.status_async = function(path, base)
202
222
log .error (" status_async staged error: " , err , line )
203
223
end
204
224
end ,
205
- on_exit = function (job , return_val )
225
+ on_exit = function (_ , return_val )
206
226
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 )
216
229
end ,
217
230
})
218
231
:start ()
232
+ context .remaining_jobs = context .remaining_jobs + 1
219
233
end , 1000 , utils .debounce_strategy .CALL_FIRST_AND_LAST , utils .debounce_action .START_ASYNC_JOB )
220
234
221
235
local event_id_unstaged = " git_status_unstaged_" .. git_root
@@ -231,20 +245,14 @@ M.status_async = function(path, base)
231
245
log .error (" status_async unstaged error: " , err , line )
232
246
end
233
247
end ,
234
- on_exit = function (job , return_val )
248
+ on_exit = function (_ , return_val )
235
249
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 )
245
252
end ,
246
253
})
247
254
:start ()
255
+ context .remaining_jobs = context .remaining_jobs + 1
248
256
end , 1000 , utils .debounce_strategy .CALL_FIRST_AND_LAST , utils .debounce_action .START_ASYNC_JOB )
249
257
250
258
local event_id_untracked = " git_status_untracked_" .. git_root
@@ -260,26 +268,20 @@ M.status_async = function(path, base)
260
268
log .error (" status_async untracked error: " , err , line )
261
269
end
262
270
end ,
263
- on_exit = function (job , return_val )
271
+ on_exit = function (_ , return_val )
264
272
utils .debounce (
265
273
event_id_untracked ,
266
274
nil ,
267
275
nil ,
268
276
nil ,
269
277
utils .debounce_action .COMPLETE_ASYNC_JOB
270
278
)
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 )
280
281
end ,
281
282
})
282
283
:start ()
284
+ context .remaining_jobs = context .remaining_jobs + 1
283
285
end , 1000 , utils .debounce_strategy .CALL_FIRST_AND_LAST , utils .debounce_action .START_ASYNC_JOB )
284
286
285
287
return true
0 commit comments