| 175 | } |
| 176 | |
| 177 | static int add(int argc, const char **argv, const char *prefix, |
| 178 | struct repository *repo UNUSED) |
| 179 | { |
| 180 | int fetch = 0, fetch_tags = TAGS_DEFAULT; |
| 181 | unsigned mirror = MIRROR_NONE; |
| 182 | struct string_list track = STRING_LIST_INIT_NODUP; |
| 183 | const char *master = NULL; |
| 184 | struct remote *remote; |
| 185 | struct strbuf buf = STRBUF_INIT, buf2 = STRBUF_INIT; |
| 186 | const char *name, *url; |
| 187 | int result = 0; |
| 188 | |
| 189 | struct option options[] = { |
| 190 | OPT_BOOL('f', "fetch", &fetch, N_("fetch the remote branches")), |
| 191 | OPT_SET_INT(0, "tags", &fetch_tags, |
| 192 | N_("import all tags and associated objects when fetching\n" |
| 193 | "or do not fetch any tag at all (--no-tags)"), |
| 194 | TAGS_SET), |
| 195 | OPT_STRING_LIST('t', "track", &track, N_("branch"), |
| 196 | N_("branch(es) to track")), |
| 197 | OPT_STRING('m', "master", &master, N_("branch"), N_("master branch")), |
| 198 | OPT_CALLBACK_F(0, "mirror", &mirror, "(push|fetch)", |
| 199 | N_("set up remote as a mirror to push to or fetch from"), |
| 200 | PARSE_OPT_OPTARG | PARSE_OPT_COMP_ARG, parse_mirror_opt), |
| 201 | OPT_END() |
| 202 | }; |
| 203 | |
| 204 | argc = parse_options(argc, argv, prefix, options, |
| 205 | builtin_remote_add_usage, 0); |
| 206 | |
| 207 | if (argc != 2) |
| 208 | usage_with_options(builtin_remote_add_usage, options); |
| 209 | |
| 210 | if (mirror && master) |
| 211 | die(_("specifying a master branch makes no sense with --mirror")); |
| 212 | if (mirror && !(mirror & MIRROR_FETCH) && track.nr) |
| 213 | die(_("specifying branches to track makes sense only with fetch mirrors")); |
| 214 | |
| 215 | name = argv[0]; |
| 216 | url = argv[1]; |
| 217 | |
| 218 | remote = remote_get(name); |
| 219 | if (remote_is_configured(remote, 1)) { |
| 220 | error(_("remote %s already exists."), name); |
| 221 | exit(3); |
| 222 | } |
| 223 | |
| 224 | if (!valid_remote_name(name)) |
| 225 | die(_("'%s' is not a valid remote name"), name); |
| 226 | |
| 227 | for_each_remote(check_remote_collision, (void *)name); |
| 228 | |
| 229 | strbuf_addf(&buf, "remote.%s.url", name); |
| 230 | repo_config_set(the_repository, buf.buf, url); |
| 231 | |
| 232 | if (!mirror || mirror & MIRROR_FETCH) { |
| 233 | strbuf_reset(&buf); |
| 234 | strbuf_addf(&buf, "remote.%s.fetch", name); |
nothing calls this directly
no test coverage detected