X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=builtin-remote.c;h=abc8dd8389be4a51b467b4f6d4f74e2037d65423;hb=58f37f3c07ef4869f88c79b61f11829bebf7bf40;hp=1ca6cdbe2a64a5c4b8d97b30183d48c929b4be53;hpb=bf98421a3363696f3b4c8aedc242bfaadc1ce6f6;p=git.git diff --git a/builtin-remote.c b/builtin-remote.c index 1ca6cdbe2..abc8dd838 100644 --- a/builtin-remote.c +++ b/builtin-remote.c @@ -8,13 +8,13 @@ #include "refs.h" static const char * const builtin_remote_usage[] = { - "git remote", - "git remote add ", + "git remote [-v | --verbose]", + "git remote add [-t ] [-m ] [-f] [--mirror] ", "git remote rename ", "git remote rm ", - "git remote show ", - "git remote prune ", - "git remote update [group]", + "git remote show [-n] ", + "git remote prune [-n | --dry-run] ", + "git remote [-v | --verbose] update [group]", NULL }; @@ -42,7 +42,11 @@ static int opt_parse_track(const struct option *opt, const char *arg, int not) static int fetch_remote(const char *name) { - const char *argv[] = { "fetch", name, NULL }; + const char *argv[] = { "fetch", name, NULL, NULL }; + if (verbose) { + argv[1] = "-v"; + argv[2] = name; + } printf("Updating %s\n", name); if (run_command_v_opt(argv, RUN_GIT_CMD)) return error("Could not fetch %s", name); @@ -321,7 +325,7 @@ static int add_branch_for_removal(const char *refname, /* make sure that symrefs are deleted */ if (flags & REF_ISSYMREF) - return unlink(git_path(refname)); + return unlink(git_path("%s", refname)); item = string_list_append(refname, branches->branches); item->util = xmalloc(20); @@ -359,6 +363,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 +417,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); @@ -735,7 +774,7 @@ static int get_one_remote_for_update(struct remote *remote, void *priv) { struct string_list *list = priv; if (!remote->skip_default_update) - string_list_append(xstrdup(remote->name), list); + string_list_append(remote->name, list); return 0; }