#include "cache.h"
#include "parse-options.h"
#include "transport.h"
#include "remote.h"
#include "string-list.h"
#include "strbuf.h"
#include "run-command.h"
#include "refs.h"
static const char * const builtin_remote_usage[] = {
"git remote [-v | --verbose]",
"git remote add [-t <branch>] [-m <master>] [-f] [--mirror] <name> <url>",
"git remote rename <old> <new>",
"git remote rm <name>",
"git remote set-head <name> [-a | -d | <branch>]",
"git remote show [-n] <name>",
"git remote prune [-n | --dry-run] <name>",
"git remote [-v | --verbose] update [-p | --prune] [group]",
NULL
};
#define GET_REF_STATES (1<<0)
#define GET_HEAD_NAMES (1<<1)
#define GET_PUSH_REF_STATES (1<<2)
static int verbose;
static int show_all(void);
static int prune_remote(const char *remote, int dry_run);
static inline int postfixcmp(const char *string, const char *postfix)
{
int len1 = strlen(string), len2 = strlen(postfix);
if (len1 < len2)
return 1;
return strcmp(string + len1 - len2, postfix);
}
static int opt_parse_track(const struct option *opt, const char *arg, int not)
{
struct string_list *list = opt->value;
if (not)
string_list_clear(list, 0);
else
string_list_append(arg, list);
return 0;
}
static int fetch_remote(const char *name)
{
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);
return 0;
}
static int add(int argc, const char **argv)
{
int fetch = 0, mirror = 0;
struct string_list track = { NULL, 0, 0 };
const char *master = NULL;
struct remote *remote;
struct strbuf buf = STRBUF_INIT, buf2 = STRBUF_INIT;
const char *name, *url;
int i;
struct option options[] = {
OPT_GROUP("add specific options"),
OPT_BOOLEAN('f', "fetch", &fetch, "fetch the remote branches"),
OPT_CALLBACK('t', "track", &track, "branch",
"branch(es) to track", opt_parse_track),
OPT_STRING('m', "master", &master, "branch", "master branch"),
OPT_BOOLEAN(0, "mirror", &mirror, "no separate remotes"),
OPT_END()
};
argc = parse_options(argc, argv, NULL, options, builtin_remote_usage,
0);
if (argc < 2)
usage_with_options(builtin_remote_usage, options);
name = argv[0];
url = argv[1];
remote = remote_get(name);
if (remote && (remote->url_nr > 1 || strcmp(name, remote->url[0]) ||
remote->fetch_refspec_nr))
die("remote %s already exists.", name);
strbuf_addf(&buf2, "refs/heads/test:refs/remotes/%s/test", name);
if (!
|