@@ -1643,9 +1643,6 @@ static int set_head(const struct ref *remote_refs, struct remote *remote)
16431643 string_list_append (& heads , strip_refshead (ref -> name ));
16441644 }
16451645
1646- if (follow_remote_head == FOLLOW_REMOTE_NEVER )
1647- goto cleanup ;
1648-
16491646 if (!heads .nr )
16501647 result = 1 ;
16511648 else if (heads .nr > 1 )
@@ -1691,21 +1688,6 @@ static int set_head(const struct ref *remote_refs, struct remote *remote)
16911688 return result ;
16921689}
16931690
1694- static int uses_remote_tracking (struct transport * transport , struct refspec * rs )
1695- {
1696- if (!remote_is_configured (transport -> remote , 0 ))
1697- return 0 ;
1698-
1699- if (!rs -> nr )
1700- rs = & transport -> remote -> fetch ;
1701-
1702- for (int i = 0 ; i < rs -> nr ; i ++ )
1703- if (rs -> items [i ].dst )
1704- return 1 ;
1705-
1706- return 0 ;
1707- }
1708-
17091691static int do_fetch (struct transport * transport ,
17101692 struct refspec * rs ,
17111693 const struct fetch_config * config )
@@ -1720,6 +1702,7 @@ static int do_fetch(struct transport *transport,
17201702 TRANSPORT_LS_REFS_OPTIONS_INIT ;
17211703 struct fetch_head fetch_head = { 0 };
17221704 struct strbuf err = STRBUF_INIT ;
1705+ int do_set_head = 0 ;
17231706
17241707 if (tags == TAGS_DEFAULT ) {
17251708 if (transport -> remote -> fetch_tags == 2 )
@@ -1740,9 +1723,12 @@ static int do_fetch(struct transport *transport,
17401723 } else {
17411724 struct branch * branch = branch_get (NULL );
17421725
1743- if (transport -> remote -> fetch .nr )
1726+ if (transport -> remote -> fetch .nr ) {
17441727 refspec_ref_prefixes (& transport -> remote -> fetch ,
17451728 & transport_ls_refs_options .ref_prefixes );
1729+ if (transport -> remote -> follow_remote_head != FOLLOW_REMOTE_NEVER )
1730+ do_set_head = 1 ;
1731+ }
17461732 if (branch_has_merge_config (branch ) &&
17471733 !strcmp (branch -> remote_name , transport -> remote -> name )) {
17481734 int i ;
@@ -1765,8 +1751,7 @@ static int do_fetch(struct transport *transport,
17651751 strvec_push (& transport_ls_refs_options .ref_prefixes ,
17661752 "refs/tags/" );
17671753
1768- if (transport_ls_refs_options .ref_prefixes .nr &&
1769- uses_remote_tracking (transport , rs ))
1754+ if (do_set_head )
17701755 strvec_push (& transport_ls_refs_options .ref_prefixes ,
17711756 "HEAD" );
17721757
@@ -1925,12 +1910,13 @@ static int do_fetch(struct transport *transport,
19251910 "you need to specify exactly one branch with the --set-upstream option" ));
19261911 }
19271912 }
1928- if (set_head (remote_refs , transport -> remote ))
1929- ;
1913+ if (do_set_head ) {
19301914 /*
1931- * Way too many cases where this can go wrong
1932- * so let's just fail silently for now.
1915+ * Way too many cases where this can go wrong so let's just
1916+ * ignore errors and fail silently for now.
19331917 */
1918+ set_head (remote_refs , transport -> remote );
1919+ }
19341920
19351921cleanup :
19361922 if (retcode ) {
0 commit comments