@@ -580,7 +580,7 @@ static int read_remote_branches(const char *refname,
580580 unsigned char orig_sha1 [20 ];
581581 const char * symref ;
582582
583- strbuf_addf (& buf , "refs/remotes/%s" , rename -> old );
583+ strbuf_addf (& buf , "refs/remotes/%s/ " , rename -> old );
584584 if (!prefixcmp (refname , buf .buf )) {
585585 item = string_list_append (rename -> remote_branches , xstrdup (refname ));
586586 symref = resolve_ref (refname , orig_sha1 , 1 , & flag );
@@ -631,10 +631,11 @@ static int mv(int argc, const char **argv)
631631 OPT_END ()
632632 };
633633 struct remote * oldremote , * newremote ;
634- struct strbuf buf = STRBUF_INIT , buf2 = STRBUF_INIT , buf3 = STRBUF_INIT ;
634+ struct strbuf buf = STRBUF_INIT , buf2 = STRBUF_INIT , buf3 = STRBUF_INIT ,
635+ old_remote_context = STRBUF_INIT ;
635636 struct string_list remote_branches = STRING_LIST_INIT_NODUP ;
636637 struct rename_info rename ;
637- int i ;
638+ int i , refspec_updated = 0 ;
638639
639640 if (argc != 3 )
640641 usage_with_options (builtin_remote_rename_usage , options );
@@ -669,15 +670,25 @@ static int mv(int argc, const char **argv)
669670 strbuf_addf (& buf , "remote.%s.fetch" , rename .new );
670671 if (git_config_set_multivar (buf .buf , NULL , NULL , 1 ))
671672 return error ("Could not remove config section '%s'" , buf .buf );
673+ strbuf_addf (& old_remote_context , ":refs/remotes/%s/" , rename .old );
672674 for (i = 0 ; i < oldremote -> fetch_refspec_nr ; i ++ ) {
673675 char * ptr ;
674676
675677 strbuf_reset (& buf2 );
676678 strbuf_addstr (& buf2 , oldremote -> fetch_refspec [i ]);
677- ptr = strstr (buf2 .buf , rename .old );
678- if (ptr )
679- strbuf_splice (& buf2 , ptr - buf2 .buf , strlen (rename .old ),
680- rename .new , strlen (rename .new ));
679+ ptr = strstr (buf2 .buf , old_remote_context .buf );
680+ if (ptr ) {
681+ refspec_updated = 1 ;
682+ strbuf_splice (& buf2 ,
683+ ptr - buf2 .buf + strlen (":refs/remotes/" ),
684+ strlen (rename .old ), rename .new ,
685+ strlen (rename .new ));
686+ } else
687+ warning ("Not updating non-default fetch respec\n"
688+ "\t%s\n"
689+ "\tPlease update the configuration manually if necessary." ,
690+ buf2 .buf );
691+
681692 if (git_config_set_multivar (buf .buf , buf2 .buf , "^$" , 0 ))
682693 return error ("Could not append '%s'" , buf .buf );
683694 }
@@ -695,6 +706,9 @@ static int mv(int argc, const char **argv)
695706 }
696707 }
697708
709+ if (!refspec_updated )
710+ return 0 ;
711+
698712 /*
699713 * First remove symrefs, then rename the rest, finally create
700714 * the new symrefs.
0 commit comments