@@ -50,7 +50,7 @@ pub struct Status {
50
50
git_diff : AsyncDiff ,
51
51
git_status_workdir : AsyncStatus ,
52
52
git_status_stage : AsyncStatus ,
53
- git_branch_state : BranchCompare ,
53
+ git_branch_state : Option < BranchCompare > ,
54
54
git_branch_name : cached:: BranchName ,
55
55
queue : Queue ,
56
56
git_action_executed : bool ,
@@ -149,7 +149,7 @@ impl Status {
149
149
git_status_workdir : AsyncStatus :: new ( sender. clone ( ) ) ,
150
150
git_status_stage : AsyncStatus :: new ( sender. clone ( ) ) ,
151
151
git_action_executed : false ,
152
- git_branch_state : BranchCompare :: default ( ) ,
152
+ git_branch_state : None ,
153
153
git_branch_name : cached:: BranchName :: new ( CWD ) ,
154
154
key_config,
155
155
}
@@ -161,11 +161,18 @@ impl Status {
161
161
chunks : & [ tui:: layout:: Rect ] ,
162
162
) {
163
163
if let Some ( branch_name) = self . git_branch_name . last ( ) {
164
+ let ahead_behind =
165
+ if let Some ( state) = & self . git_branch_state {
166
+ format ! (
167
+ "\u{2191} {} \u{2193} {} " ,
168
+ state. ahead, state. behind,
169
+ )
170
+ } else {
171
+ String :: new ( )
172
+ } ;
164
173
let w = Paragraph :: new ( format ! (
165
- "\u{2191} {} \u{2193} {} {{{}}}" ,
166
- self . git_branch_state. ahead,
167
- self . git_branch_state. behind,
168
- branch_name
174
+ "{}{{{}}}" ,
175
+ ahead_behind, branch_name
169
176
) )
170
177
. alignment ( Alignment :: Right ) ;
171
178
@@ -402,17 +409,17 @@ impl Status {
402
409
}
403
410
404
411
fn check_branch_state ( & mut self ) {
405
- self . git_branch_state = self . git_branch_name . last ( ) . map_or (
406
- BranchCompare :: default ( ) ,
407
- |branch| {
412
+ self . git_branch_state =
413
+ self . git_branch_name . last ( ) . and_then ( |branch| {
408
414
sync:: branch_compare_upstream ( CWD , branch. as_str ( ) )
409
- . unwrap_or_default ( )
410
- } ,
411
- ) ;
415
+ . ok ( )
416
+ } ) ;
412
417
}
413
418
414
- const fn can_push ( & self ) -> bool {
415
- self . git_branch_state . ahead > 0
419
+ fn can_push ( & self ) -> bool {
420
+ self . git_branch_state
421
+ . as_ref ( )
422
+ . map_or ( true , |state| state. ahead > 0 )
416
423
}
417
424
}
418
425
0 commit comments