@@ -2237,31 +2237,22 @@ int stat_tracking_info(struct branch *branch, int *num_ours, int *num_theirs,
22372237 return stat_branch_pair (branch -> refname , base , num_ours , num_theirs , abf );
22382238}
22392239
2240- static char * get_goal_branch_ref ( char * * full_ref_out )
2240+ static char * get_remote_push_branch ( struct branch * branch , char * * full_ref_out )
22412241{
2242- const char * config_value ;
2242+ const char * push_remote ;
22432243 const char * resolved ;
22442244 int flag ;
22452245 struct strbuf ref_buf = STRBUF_INIT ;
2246- char * slash_pos ;
22472246 char * ret = NULL ;
22482247
2249- if (repo_config_get_value (the_repository , "status.goalBranch" , & config_value ))
2250- return NULL ;
2251-
2252- if (!config_value || !* config_value )
2248+ if (!branch )
22532249 return NULL ;
22542250
2255- slash_pos = strchr (config_value , '/' );
2256- if (!slash_pos || slash_pos == config_value || !slash_pos [1 ]) {
2257- warning (_ ("invalid value for status.goalBranch: '%s' (expected format: remote/branch)" ),
2258- config_value );
2251+ push_remote = pushremote_for_branch (branch , NULL );
2252+ if (!push_remote )
22592253 return NULL ;
2260- }
22612254
2262- strbuf_addf (& ref_buf , "refs/remotes/%.*s/%s" ,
2263- (int )(slash_pos - config_value ), config_value ,
2264- slash_pos + 1 );
2255+ strbuf_addf (& ref_buf , "refs/remotes/%s/%s" , push_remote , branch -> name );
22652256
22662257 resolved = refs_resolve_ref_unsafe (
22672258 get_main_ref_store (the_repository ),
@@ -2280,38 +2271,44 @@ static char *get_goal_branch_ref(char **full_ref_out)
22802271 return ret ;
22812272}
22822273
2283- static void format_goal_branch_comparison (struct strbuf * sb ,
2274+ static void format_push_branch_comparison (struct strbuf * sb ,
22842275 const char * branch_refname ,
2285- const char * goal_full ,
2286- const char * goal_short ,
2276+ const char * push_full ,
2277+ const char * push_short ,
22872278 enum ahead_behind_flags abf )
22882279{
2289- int goal_ahead = 0 , goal_behind = 0 ;
2280+ int push_ahead = 0 , push_behind = 0 ;
2281+ int stat_result ;
22902282
2291- if (stat_branch_pair (branch_refname , goal_full ,
2292- & goal_ahead , & goal_behind , abf ) <= 0 )
2283+ stat_result = stat_branch_pair (branch_refname , push_full ,
2284+ & push_ahead , & push_behind , abf );
2285+ if (stat_result < 0 )
22932286 return ;
22942287
22952288 strbuf_addstr (sb , "\n" );
22962289
2297- if (goal_ahead > 0 && goal_behind == 0 ) {
2290+ if (stat_result == 0 || (push_ahead == 0 && push_behind == 0 )) {
2291+ strbuf_addf (sb ,
2292+ _ ("Your branch is up to date with '%s'.\n" ),
2293+ push_short );
2294+ } else if (push_ahead > 0 && push_behind == 0 ) {
22982295 strbuf_addf (sb ,
22992296 Q_ ("Ahead of '%s' by %d commit.\n" ,
23002297 "Ahead of '%s' by %d commits.\n" ,
2301- goal_ahead ),
2302- goal_short , goal_ahead );
2303- } else if (goal_behind > 0 && goal_ahead == 0 ) {
2298+ push_ahead ),
2299+ push_short , push_ahead );
2300+ } else if (push_behind > 0 && push_ahead == 0 ) {
23042301 strbuf_addf (sb ,
23052302 Q_ ("Behind '%s' by %d commit.\n" ,
23062303 "Behind '%s' by %d commits.\n" ,
2307- goal_behind ),
2308- goal_short , goal_behind );
2309- } else if (goal_ahead > 0 && goal_behind > 0 ) {
2304+ push_behind ),
2305+ push_short , push_behind );
2306+ } else if (push_ahead > 0 && push_behind > 0 ) {
23102307 strbuf_addf (sb ,
23112308 Q_ ("Diverged from '%s' by %d commit.\n" ,
23122309 "Diverged from '%s' by %d commits.\n" ,
2313- goal_ahead + goal_behind ),
2314- goal_short , goal_ahead + goal_behind );
2310+ push_ahead + push_behind ),
2311+ push_short , push_ahead + push_behind );
23152312 }
23162313}
23172314
@@ -2392,15 +2389,15 @@ int format_tracking_info(struct branch *branch, struct strbuf *sb,
23922389 }
23932390
23942391 if (!upstream_is_gone && sti >= 0 && abf != AHEAD_BEHIND_QUICK ) {
2395- char * goal_full = NULL ;
2396- char * goal_short = get_goal_branch_ref ( & goal_full );
2392+ char * push_full = NULL ;
2393+ char * push_short = get_remote_push_branch ( branch , & push_full );
23972394
2398- if (goal_short && strcmp (base , goal_short ))
2399- format_goal_branch_comparison (sb , branch -> refname , goal_full ,
2400- goal_short , abf );
2395+ if (push_short && strcmp (base , push_short ))
2396+ format_push_branch_comparison (sb , branch -> refname , push_full ,
2397+ push_short , abf );
24012398
2402- free (goal_short );
2403- free (goal_full );
2399+ free (push_short );
2400+ free (push_full );
24042401 }
24052402
24062403 free (base );
0 commit comments