@@ -16,7 +16,7 @@ use asyncgit::{
16
16
self , branch:: checkout_remote_branch, checkout_branch,
17
17
get_branches_info, BranchInfo ,
18
18
} ,
19
- CWD ,
19
+ AsyncGitNotification , CWD ,
20
20
} ;
21
21
use crossterm:: event:: Event ;
22
22
use std:: { cell:: Cell , convert:: TryInto } ;
@@ -286,23 +286,39 @@ impl BranchListComponent {
286
286
287
287
///
288
288
pub fn open ( & mut self ) -> Result < ( ) > {
289
- self . update_branches ( ) ?;
290
289
self . show ( ) ?;
290
+ self . update_branches ( ) ?;
291
291
292
292
Ok ( ( ) )
293
293
}
294
294
295
295
/// fetch list of branches
296
296
pub fn update_branches ( & mut self ) -> Result < ( ) > {
297
- self . branches = get_branches_info ( CWD , self . local ) ?;
298
- //remove remote branch called `HEAD`
299
- if !self . local {
300
- self . branches
301
- . iter ( )
302
- . position ( |b| b. name . ends_with ( "/HEAD" ) )
303
- . map ( |idx| self . branches . remove ( idx) ) ;
297
+ if self . is_visible ( ) {
298
+ self . branches = get_branches_info ( CWD , self . local ) ?;
299
+ //remove remote branch called `HEAD`
300
+ if !self . local {
301
+ self . branches
302
+ . iter ( )
303
+ . position ( |b| b. name . ends_with ( "/HEAD" ) )
304
+ . map ( |idx| self . branches . remove ( idx) ) ;
305
+ }
306
+ self . set_selection ( self . selection ) ?;
304
307
}
305
- self . set_selection ( self . selection ) ?;
308
+ Ok ( ( ) )
309
+ }
310
+
311
+ ///
312
+ pub fn update_git (
313
+ & mut self ,
314
+ ev : AsyncGitNotification ,
315
+ ) -> Result < ( ) > {
316
+ if self . is_visible ( ) {
317
+ if let AsyncGitNotification :: Push = ev {
318
+ self . update_branches ( ) ?;
319
+ }
320
+ }
321
+
306
322
Ok ( ( ) )
307
323
}
308
324
0 commit comments