]> git.ipfire.org Git - thirdparty/git.git/commitdiff
builtin/remote: determine whether refs need renaming early on
authorPatrick Steinhardt <ps@pks.im>
Thu, 31 Jul 2025 14:56:52 +0000 (16:56 +0200)
committerJunio C Hamano <gitster@pobox.com>
Wed, 6 Aug 2025 21:19:30 +0000 (14:19 -0700)
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@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/remote.c

index f63c5eb8881a6c6217b95afd77f4e840ed10ac8f..34ddcaf5f6fb8f6a6e0d21d5a65e39ddaf7f940f 100644 (file)
@@ -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;
 
        /*