When renaming a remote we may have to also rename remote refs in case the refspec changes. Pull out this computation into a separate loop. While that seems nonsensical right now, it'll help us in a subsequent commit where we will prepare the reference transaction before we rewrite the configuration. Signed-off-by: Patrick Steinhardt <ps@xxxxxx> --- builtin/remote.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/builtin/remote.c b/builtin/remote.c index f63c5eb888..34ddcaf5f6 100644 --- a/builtin/remote.c +++ b/builtin/remote.c @@ -741,7 +741,7 @@ static int mv(int argc, const char **argv, const char *prefix, old_remote_context = STRBUF_INIT; struct string_list remote_branches = STRING_LIST_INIT_DUP; struct rename_info rename; - int refs_renamed_nr = 0, refspec_updated = 0; + int refs_renamed_nr = 0, refspecs_need_update = 0; struct progress *progress = NULL; int result = 0; @@ -782,11 +782,16 @@ static int mv(int argc, const char **argv, const char *prefix, goto out; } + strbuf_addf(&old_remote_context, ":refs/remotes/%s/", rename.old_name); + + for (int i = 0; i < oldremote->fetch.nr && !refspecs_need_update; i++) + refspecs_need_update = !!strstr(oldremote->fetch.items[i].raw, + old_remote_context.buf); + if (oldremote->fetch.nr) { strbuf_reset(&buf); strbuf_addf(&buf, "remote.%s.fetch", rename.new_name); git_config_set_multivar(buf.buf, NULL, NULL, CONFIG_FLAGS_MULTI_REPLACE); - strbuf_addf(&old_remote_context, ":refs/remotes/%s/", rename.old_name); for (int i = 0; i < oldremote->fetch.nr; i++) { char *ptr; @@ -794,7 +799,6 @@ static int mv(int argc, const char **argv, const char *prefix, strbuf_addstr(&buf2, oldremote->fetch.items[i].raw); ptr = strstr(buf2.buf, old_remote_context.buf); if (ptr) { - refspec_updated = 1; strbuf_splice(&buf2, ptr-buf2.buf + strlen(":refs/remotes/"), strlen(rename.old_name), rename.new_name, @@ -825,7 +829,7 @@ static int mv(int argc, const char **argv, const char *prefix, } } - if (!refspec_updated) + if (!refspecs_need_update) goto out; /* -- 2.50.1.619.g074bbf1d35.dirty