@@ -1579,6 +1579,19 @@ static const char *strip_refshead(const char *name){
15791579 return name ;
15801580}
15811581
1582+ static void set_head_advice_msg (const char * remote , const char * head_name )
1583+ {
1584+ const char message_advice_set_head [] =
1585+ N_ ("Run 'git remote set-head %s %s' to follow the change, or set\n"
1586+ "'remote.%s.followRemoteHEAD' configuration option to a different value\n"
1587+ "if you do not want to see this message. Specifically running\n"
1588+ "'git config set remote.%s.followRemoteHEAD %s' will disable the warning\n"
1589+ "until the remote changes HEAD to something else." );
1590+
1591+ advise_if_enabled (ADVICE_FETCH_SET_HEAD_WARN , _ (message_advice_set_head ),
1592+ remote , head_name , remote , remote , head_name );
1593+ }
1594+
15821595static void report_set_head (const char * remote , const char * head_name ,
15831596 struct strbuf * buf_prev , int updateres ) {
15841597 struct strbuf buf_prefix = STRBUF_INIT ;
@@ -1590,20 +1603,19 @@ static void report_set_head(const char *remote, const char *head_name,
15901603 if (prev_head && strcmp (prev_head , head_name )) {
15911604 printf ("'HEAD' at '%s' is '%s', but we have '%s' locally.\n" ,
15921605 remote , head_name , prev_head );
1593- printf ("Run 'git remote set-head %s %s' to follow the change.\n" ,
1594- remote , head_name );
1606+ set_head_advice_msg (remote , head_name );
15951607 }
15961608 else if (updateres && buf_prev -> len ) {
15971609 printf ("'HEAD' at '%s' is '%s', "
15981610 "but we have a detached HEAD pointing to '%s' locally.\n" ,
15991611 remote , head_name , buf_prev -> buf );
1600- printf ("Run 'git remote set-head %s %s' to follow the change.\n" ,
1601- remote , head_name );
1612+ set_head_advice_msg (remote , head_name );
16021613 }
16031614 strbuf_release (& buf_prefix );
16041615}
16051616
1606- static int set_head (const struct ref * remote_refs , int follow_remote_head )
1617+ static int set_head (const struct ref * remote_refs , int follow_remote_head ,
1618+ const char * no_warn_branch )
16071619{
16081620 int result = 0 , create_only , is_bare , was_detached ;
16091621 struct strbuf b_head = STRBUF_INIT , b_remote_head = STRBUF_INIT ,
@@ -1660,7 +1672,9 @@ static int set_head(const struct ref *remote_refs, int follow_remote_head)
16601672 result = 1 ;
16611673 goto cleanup ;
16621674 }
1663- if (follow_remote_head == FOLLOW_REMOTE_WARN && verbosity >= 0 )
1675+ if (verbosity >= 0 &&
1676+ follow_remote_head == FOLLOW_REMOTE_WARN &&
1677+ (!no_warn_branch || strcmp (no_warn_branch , head_name )))
16641678 report_set_head (remote , head_name , & b_local_head , was_detached );
16651679
16661680cleanup :
@@ -1889,7 +1903,8 @@ static int do_fetch(struct transport *transport,
18891903 "you need to specify exactly one branch with the --set-upstream option" ));
18901904 }
18911905 }
1892- if (set_head (remote_refs , transport -> remote -> follow_remote_head ))
1906+ if (set_head (remote_refs , transport -> remote -> follow_remote_head ,
1907+ transport -> remote -> no_warn_branch ))
18931908 ;
18941909 /*
18951910 * Way too many cases where this can go wrong
0 commit comments