@@ -50,7 +50,7 @@ pub struct Status {
5050 git_diff : AsyncDiff ,
5151 git_status_workdir : AsyncStatus ,
5252 git_status_stage : AsyncStatus ,
53- git_branch_state : BranchCompare ,
53+ git_branch_state : Option < BranchCompare > ,
5454 git_branch_name : cached:: BranchName ,
5555 queue : Queue ,
5656 git_action_executed : bool ,
@@ -149,7 +149,7 @@ impl Status {
149149 git_status_workdir : AsyncStatus :: new ( sender. clone ( ) ) ,
150150 git_status_stage : AsyncStatus :: new ( sender. clone ( ) ) ,
151151 git_action_executed : false ,
152- git_branch_state : BranchCompare :: default ( ) ,
152+ git_branch_state : None ,
153153 git_branch_name : cached:: BranchName :: new ( CWD ) ,
154154 key_config,
155155 }
@@ -161,11 +161,18 @@ impl Status {
161161 chunks : & [ tui:: layout:: Rect ] ,
162162 ) {
163163 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+ } ;
164173 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
169176 ) )
170177 . alignment ( Alignment :: Right ) ;
171178
@@ -402,17 +409,17 @@ impl Status {
402409 }
403410
404411 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| {
408414 sync:: branch_compare_upstream ( CWD , branch. as_str ( ) )
409- . unwrap_or_default ( )
410- } ,
411- ) ;
415+ . ok ( )
416+ } ) ;
412417 }
413418
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 )
416423 }
417424}
418425
0 commit comments