Re: [PATCH] Implement git remote rename
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Oct 24, 2008, 23:33 UTC
- Message-ID
- <7v63nh1sc7.fsf@gitster.siamese.dyndns.org>
- In-Reply-To
- <1224766597-16034-1-git-send-email-vmiklos@frugalware.org>
Miklos Vajna <vmiklos@frugalware.org> writes:
Show 36 quoted lines
> +static int mv(int argc, const char **argv)
> +{
> + struct option options[] = {
> + OPT_END()
> + };
> + struct remote *oldremote, *newremote;
> + struct strbuf buf = STRBUF_INIT, buf2 = STRBUF_INIT;
> + struct string_list remote_branches = { NULL, 0, 0, 0 };
> + struct rename_info rename;
> + int i;
> +
> + if (argc != 3)
> + usage_with_options(builtin_remote_usage, options);
> +
> + rename.old = argv[1];
> + rename.new = argv[2];
> + rename.remote_branches = &remote_branches;
> +
> + oldremote = remote_get(rename.old);
> + if (!oldremote)
> + die("No such remote: %s", rename.old);
> +
> + newremote = remote_get(rename.new);
> + if (newremote && (newremote->url_nr > 1 || newremote->fetch_refspec_nr))
> + die("remote %s already exists.", rename.new);
> +
> + strbuf_addf(&buf, "refs/heads/test:refs/remotes/%s/test", rename.new);
> + if (!valid_fetch_refspec(buf.buf))
> + die("'%s' is not a valid remote name", rename.new);
> +
> + strbuf_reset(&buf);
> + strbuf_addf(&buf, "remote.%s", rename.old);
> + strbuf_addf(&buf2, "remote.%s", rename.new);
> + if (git_config_rename_section(buf.buf, buf2.buf) < 1)
> + return error("Could not rename config section '%s' to '%s'",
> + buf.buf, buf2.buf);Hmm, remote_get() can read from all three supported places that you can define remotes. Could you explain what happens if the old remote is read from say $GIT_DIR/remotes/origin and you are renaming it to "upstream" with "git remote rename origin upstream"?
I suspect that if you record where you read the configuration from in "struct remote" and add necessary code to remove the original when rename.old is *not* coming from in-config definition, you would make it possible for repositories initialized with older git that has either $GIT_DIR/branches/origin or $GIT_DIR/remotes/origin to be migrated to the in-config format using "git remote rename origin origin".