diff options
author | Miklos Vajna <vmiklos@frugalware.org> | 2008-11-10 21:43:01 +0100 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2008-11-11 20:24:18 -0800 |
commit | 1dd1239aa33ddd7f159cd183338ef6f71298e29a (patch) | |
tree | 4c2013277d8c825c265c9c761adffaeee4700f37 /builtin-remote.c | |
parent | 89cf4c7004ec329c3171448a154d050c8f75874e (diff) | |
download | git-1dd1239aa33ddd7f159cd183338ef6f71298e29a.tar.gz |
git-remote rename: migrate from remotes/ and branches/
Remote definition that came from $GIT_DIR/remotes/nick and
$GIT_DIR/branches/nick are migrated to [remotes "nick"] section in the
configuration file.
Signed-off-by: Miklos Vajna <vmiklos@frugalware.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin-remote.c')
-rw-r--r-- | builtin-remote.c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/builtin-remote.c b/builtin-remote.c index 1ca6cdbe2a..3af18768e5 100644 --- a/builtin-remote.c +++ b/builtin-remote.c @@ -359,6 +359,38 @@ static int read_remote_branches(const char *refname, return 0; } +static int migrate_file(struct remote *remote) +{ + struct strbuf buf = STRBUF_INIT; + int i; + char *path = NULL; + + strbuf_addf(&buf, "remote.%s.url", remote->name); + for (i = 0; i < remote->url_nr; i++) + if (git_config_set_multivar(buf.buf, remote->url[i], "^$", 0)) + return error("Could not append '%s' to '%s'", + remote->url[i], buf.buf); + strbuf_reset(&buf); + strbuf_addf(&buf, "remote.%s.push", remote->name); + for (i = 0; i < remote->push_refspec_nr; i++) + if (git_config_set_multivar(buf.buf, remote->push_refspec[i], "^$", 0)) + return error("Could not append '%s' to '%s'", + remote->push_refspec[i], buf.buf); + strbuf_reset(&buf); + strbuf_addf(&buf, "remote.%s.fetch", remote->name); + for (i = 0; i < remote->fetch_refspec_nr; i++) + if (git_config_set_multivar(buf.buf, remote->fetch_refspec[i], "^$", 0)) + return error("Could not append '%s' to '%s'", + remote->fetch_refspec[i], buf.buf); + if (remote->origin == REMOTE_REMOTES) + path = git_path("remotes/%s", remote->name); + else if (remote->origin == REMOTE_BRANCHES) + path = git_path("branches/%s", remote->name); + if (path && unlink(path)) + warning("failed to remove '%s'", path); + return 0; +} + static int mv(int argc, const char **argv) { struct option options[] = { @@ -381,6 +413,9 @@ static int mv(int argc, const char **argv) if (!oldremote) die("No such remote: %s", rename.old); + if (!strcmp(rename.old, rename.new) && oldremote->origin != REMOTE_CONFIG) + return migrate_file(oldremote); + newremote = remote_get(rename.new); if (newremote && (newremote->url_nr > 1 || newremote->fetch_refspec_nr)) die("remote %s already exists.", rename.new); |