@@ -14,13 +14,14 @@ use crate::{
14
14
} ;
15
15
use anyhow:: Result ;
16
16
use asyncgit:: {
17
+ asyncjob:: AsyncSingleJob ,
17
18
cached,
18
19
sync:: {
19
20
self , status:: StatusType , RepoPath , RepoPathRef , RepoState ,
20
21
} ,
21
22
sync:: { BranchCompare , CommitId } ,
22
- AsyncDiff , AsyncGitNotification , AsyncStatus , DiffParams ,
23
- DiffType , PushType , StatusParams ,
23
+ AsyncBranchesJob , AsyncDiff , AsyncGitNotification , AsyncStatus ,
24
+ DiffParams , DiffType , PushType , StatusParams ,
24
25
} ;
25
26
use crossbeam_channel:: Sender ;
26
27
use crossterm:: event:: Event ;
@@ -73,6 +74,7 @@ pub struct Status {
73
74
git_status_stage : AsyncStatus ,
74
75
git_branch_state : Option < BranchCompare > ,
75
76
git_branch_name : cached:: BranchName ,
77
+ git_branches : AsyncSingleJob < AsyncBranchesJob > ,
76
78
queue : Queue ,
77
79
git_action_executed : bool ,
78
80
options : SharedOptions ,
@@ -203,6 +205,7 @@ impl Status {
203
205
repo_clone,
204
206
sender. clone ( ) ,
205
207
) ,
208
+ git_branches : AsyncSingleJob :: new ( sender. clone ( ) ) ,
206
209
git_action_executed : false ,
207
210
git_branch_state : None ,
208
211
git_branch_name : cached:: BranchName :: new ( repo. clone ( ) ) ,
@@ -424,14 +427,22 @@ impl Status {
424
427
self . git_diff . is_pending ( )
425
428
|| self . git_status_stage . is_pending ( )
426
429
|| self . git_status_workdir . is_pending ( )
430
+ || self . git_branches . is_pending ( )
427
431
}
428
432
429
433
fn check_remotes ( & mut self ) {
430
- //TODO: make get_branches_info async
431
- self . has_remotes =
432
- sync:: get_branches_info ( & self . repo . borrow ( ) , false )
433
- . map ( |branches| !branches. is_empty ( ) )
434
- . unwrap_or ( false ) ;
434
+ self . has_remotes = false ;
435
+
436
+ if let Some ( result) = self . git_branches . take_last ( ) {
437
+ if let Some ( Ok ( branches) ) = result. result ( ) {
438
+ self . has_remotes = !branches. is_empty ( ) ;
439
+ }
440
+ } else {
441
+ self . git_branches . spawn ( AsyncBranchesJob :: new (
442
+ self . repo . borrow ( ) . clone ( ) ,
443
+ false ,
444
+ ) ) ;
445
+ }
435
446
}
436
447
437
448
///
@@ -442,6 +453,7 @@ impl Status {
442
453
match ev {
443
454
AsyncGitNotification :: Diff => self . update_diff ( ) ?,
444
455
AsyncGitNotification :: Status => self . update_status ( ) ?,
456
+ AsyncGitNotification :: Branches => self . check_remotes ( ) ,
445
457
AsyncGitNotification :: Push
446
458
| AsyncGitNotification :: Pull
447
459
| AsyncGitNotification :: CommitFiles => {
@@ -461,7 +473,6 @@ impl Status {
461
473
self . index_wd . set_items ( & workdir_status. items ) ?;
462
474
463
475
self . update_diff ( ) ?;
464
- self . check_remotes ( ) ;
465
476
466
477
if self . git_action_executed {
467
478
self . git_action_executed = false ;
0 commit comments