@@ -570,7 +570,7 @@ static int read_remote_branches(const char *refname,
570570 unsigned char orig_sha1 [20 ];
571571 const char * symref ;
572572
573- strbuf_addf (& buf , "refs/remotes/%s" , rename -> old );
573+ strbuf_addf (& buf , "refs/remotes/%s/ " , rename -> old );
574574 if (!prefixcmp (refname , buf .buf )) {
575575 item = string_list_append (rename -> remote_branches , xstrdup (refname ));
576576 symref = resolve_ref (refname , orig_sha1 , 1 , & flag );
@@ -621,10 +621,11 @@ static int mv(int argc, const char **argv)
621621 OPT_END ()
622622 };
623623 struct remote * oldremote , * newremote ;
624- struct strbuf buf = STRBUF_INIT , buf2 = STRBUF_INIT , buf3 = STRBUF_INIT ;
624+ struct strbuf buf = STRBUF_INIT , buf2 = STRBUF_INIT , buf3 = STRBUF_INIT ,
625+ old_remote_context = STRBUF_INIT ;
625626 struct string_list remote_branches = STRING_LIST_INIT_NODUP ;
626627 struct rename_info rename ;
627- int i ;
628+ int i , refspec_updated = 0 ;
628629
629630 if (argc != 3 )
630631 usage_with_options (builtin_remote_rename_usage , options );
@@ -659,15 +660,25 @@ static int mv(int argc, const char **argv)
659660 strbuf_addf (& buf , "remote.%s.fetch" , rename .new );
660661 if (git_config_set_multivar (buf .buf , NULL , NULL , 1 ))
661662 return error ("Could not remove config section '%s'" , buf .buf );
663+ strbuf_addf (& old_remote_context , ":refs/remotes/%s/" , rename .old );
662664 for (i = 0 ; i < oldremote -> fetch_refspec_nr ; i ++ ) {
663665 char * ptr ;
664666
665667 strbuf_reset (& buf2 );
666668 strbuf_addstr (& buf2 , oldremote -> fetch_refspec [i ]);
667- ptr = strstr (buf2 .buf , rename .old );
668- if (ptr )
669- strbuf_splice (& buf2 , ptr - buf2 .buf , strlen (rename .old ),
670- rename .new , strlen (rename .new ));
669+ ptr = strstr (buf2 .buf , old_remote_context .buf );
670+ if (ptr ) {
671+ refspec_updated = 1 ;
672+ strbuf_splice (& buf2 ,
673+ ptr - buf2 .buf + strlen (":refs/remotes/" ),
674+ strlen (rename .old ), rename .new ,
675+ strlen (rename .new ));
676+ } else
677+ warning ("Not updating non-default fetch respec\n"
678+ "\t%s\n"
679+ "\tPlease update the configuration manually if necessary." ,
680+ buf2 .buf );
681+
671682 if (git_config_set_multivar (buf .buf , buf2 .buf , "^$" , 0 ))
672683 return error ("Could not append '%s'" , buf .buf );
673684 }
@@ -685,6 +696,9 @@ static int mv(int argc, const char **argv)
685696 }
686697 }
687698
699+ if (!refspec_updated )
700+ return 0 ;
701+
688702 /*
689703 * First remove symrefs, then rename the rest, finally create
690704 * the new symrefs.
0 commit comments