Fix sparse warnings
Fix warnings from 'make check'.
- These files don't include 'builtin.h' causing sparse to complain that
cmd_* isn't declared:
builtin/clone.c:364, builtin/fetch-pack.c:797,
builtin/fmt-merge-msg.c:34, builtin/hash-object.c:78,
builtin/merge-index.c:69, builtin/merge-recursive.c:22
builtin/merge-tree.c:341, builtin/mktag.c:156, builtin/notes.c:426
builtin/notes.c:822, builtin/pack-redundant.c:596,
builtin/pack-refs.c:10, builtin/patch-id.c:60, builtin/patch-id.c:149,
builtin/remote.c:1512, builtin/remote-ext.c:240,
builtin/remote-fd.c:53, builtin/reset.c:236, builtin/send-pack.c:384,
builtin/unpack-file.c:25, builtin/var.c:75
- These files have symbols which should be marked static since they're
only file scope:
submodule.c:12, diff.c:631, replace_object.c:92, submodule.c:13,
submodule.c:14, trace.c:78, transport.c:195, transport-helper.c:79,
unpack-trees.c:19, url.c:3, url.c:18, url.c:104, url.c:117, url.c:123,
url.c:129, url.c:136, thread-utils.c:21, thread-utils.c:48
- These files redeclare symbols to be different types:
builtin/index-pack.c:210, parse-options.c:564, parse-options.c:571,
usage.c:49, usage.c:58, usage.c:63, usage.c:72
- These files use a literal integer 0 when they really should use a NULL
pointer:
daemon.c:663, fast-import.c:2942, imap-send.c:1072, notes-merge.c:362
While we're in the area, clean up some unused #includes in builtin files
(mostly exec_cmd.h).
Signed-off-by: Stephen Boyd <bebarino@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-03-22 10:51:05 +03:00
|
|
|
#include "builtin.h"
|
2017-06-14 21:07:36 +03:00
|
|
|
#include "config.h"
|
2008-02-29 04:45:45 +03:00
|
|
|
#include "parse-options.h"
|
|
|
|
#include "transport.h"
|
|
|
|
#include "remote.h"
|
2008-07-21 22:03:49 +04:00
|
|
|
#include "string-list.h"
|
2008-02-29 04:45:45 +03:00
|
|
|
#include "strbuf.h"
|
|
|
|
#include "run-command.h"
|
2020-01-27 10:04:27 +03:00
|
|
|
#include "rebase.h"
|
2008-02-29 04:45:45 +03:00
|
|
|
#include "refs.h"
|
2018-05-17 01:57:48 +03:00
|
|
|
#include "refspec.h"
|
2018-05-16 02:42:15 +03:00
|
|
|
#include "object-store.h"
|
2013-10-30 09:33:03 +04:00
|
|
|
#include "argv-array.h"
|
2018-07-20 19:33:06 +03:00
|
|
|
#include "commit-reach.h"
|
2008-02-29 04:45:45 +03:00
|
|
|
|
|
|
|
static const char * const builtin_remote_usage[] = {
|
2012-08-20 16:32:35 +04:00
|
|
|
N_("git remote [-v | --verbose]"),
|
2015-01-13 10:44:47 +03:00
|
|
|
N_("git remote add [-t <branch>] [-m <master>] [-f] [--tags | --no-tags] [--mirror=<fetch|push>] <name> <url>"),
|
2012-08-20 16:32:35 +04:00
|
|
|
N_("git remote rename <old> <new>"),
|
2012-09-13 01:21:58 +04:00
|
|
|
N_("git remote remove <name>"),
|
2015-01-13 10:44:47 +03:00
|
|
|
N_("git remote set-head <name> (-a | --auto | -d | --delete | <branch>)"),
|
2012-08-20 16:32:35 +04:00
|
|
|
N_("git remote [-v | --verbose] show [-n] <name>"),
|
|
|
|
N_("git remote prune [-n | --dry-run] <name>"),
|
|
|
|
N_("git remote [-v | --verbose] update [-p | --prune] [(<group> | <remote>)...]"),
|
|
|
|
N_("git remote set-branches [--add] <name> <branch>..."),
|
2015-09-16 04:53:47 +03:00
|
|
|
N_("git remote get-url [--push] [--all] <name>"),
|
2012-08-20 16:32:35 +04:00
|
|
|
N_("git remote set-url [--push] <name> <newurl> [<oldurl>]"),
|
|
|
|
N_("git remote set-url --add <name> <newurl>"),
|
|
|
|
N_("git remote set-url --delete <name> <url>"),
|
2008-02-29 04:45:45 +03:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2009-11-21 02:43:13 +03:00
|
|
|
static const char * const builtin_remote_add_usage[] = {
|
2012-08-20 16:32:35 +04:00
|
|
|
N_("git remote add [<options>] <name> <url>"),
|
2009-11-21 02:43:13 +03:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char * const builtin_remote_rename_usage[] = {
|
2012-08-20 16:32:35 +04:00
|
|
|
N_("git remote rename <old> <new>"),
|
2009-11-21 02:43:13 +03:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char * const builtin_remote_rm_usage[] = {
|
2012-09-13 01:21:58 +04:00
|
|
|
N_("git remote remove <name>"),
|
2009-11-21 02:43:13 +03:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char * const builtin_remote_sethead_usage[] = {
|
2013-09-21 19:51:46 +04:00
|
|
|
N_("git remote set-head <name> (-a | --auto | -d | --delete | <branch>)"),
|
2009-11-21 02:43:13 +03:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2010-05-19 22:38:50 +04:00
|
|
|
static const char * const builtin_remote_setbranches_usage[] = {
|
2012-08-20 16:32:35 +04:00
|
|
|
N_("git remote set-branches <name> <branch>..."),
|
|
|
|
N_("git remote set-branches --add <name> <branch>..."),
|
2010-05-19 22:38:50 +04:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2009-11-21 02:43:13 +03:00
|
|
|
static const char * const builtin_remote_show_usage[] = {
|
2012-08-20 16:32:35 +04:00
|
|
|
N_("git remote show [<options>] <name>"),
|
2009-11-21 02:43:13 +03:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char * const builtin_remote_prune_usage[] = {
|
2012-08-20 16:32:35 +04:00
|
|
|
N_("git remote prune [<options>] <name>"),
|
2009-11-21 02:43:13 +03:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char * const builtin_remote_update_usage[] = {
|
2012-08-20 16:32:35 +04:00
|
|
|
N_("git remote update [<options>] [<group> | <remote>]..."),
|
2009-11-21 02:43:13 +03:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2015-09-16 04:53:47 +03:00
|
|
|
static const char * const builtin_remote_geturl_usage[] = {
|
|
|
|
N_("git remote get-url [--push] [--all] <name>"),
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2010-01-18 20:18:02 +03:00
|
|
|
static const char * const builtin_remote_seturl_usage[] = {
|
2012-08-20 16:32:35 +04:00
|
|
|
N_("git remote set-url [--push] <name> <newurl> [<oldurl>]"),
|
|
|
|
N_("git remote set-url --add <name> <newurl>"),
|
|
|
|
N_("git remote set-url --delete <name> <url>"),
|
2010-01-18 20:18:02 +03:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2009-02-25 11:32:24 +03:00
|
|
|
#define GET_REF_STATES (1<<0)
|
|
|
|
#define GET_HEAD_NAMES (1<<1)
|
2009-02-25 11:32:28 +03:00
|
|
|
#define GET_PUSH_REF_STATES (1<<2)
|
2009-02-25 11:32:24 +03:00
|
|
|
|
2008-02-29 04:45:45 +03:00
|
|
|
static int verbose;
|
|
|
|
|
|
|
|
static int fetch_remote(const char *name)
|
|
|
|
{
|
2008-11-18 14:04:02 +03:00
|
|
|
const char *argv[] = { "fetch", name, NULL, NULL };
|
|
|
|
if (verbose) {
|
|
|
|
argv[1] = "-v";
|
|
|
|
argv[2] = name;
|
|
|
|
}
|
2012-04-23 16:30:26 +04:00
|
|
|
printf_ln(_("Updating %s"), name);
|
2008-02-29 04:45:45 +03:00
|
|
|
if (run_command_v_opt(argv, RUN_GIT_CMD))
|
2012-04-23 16:30:26 +04:00
|
|
|
return error(_("Could not fetch %s"), name);
|
2008-02-29 04:45:45 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-04-20 03:31:31 +04:00
|
|
|
enum {
|
|
|
|
TAGS_UNSET = 0,
|
|
|
|
TAGS_DEFAULT = 1,
|
|
|
|
TAGS_SET = 2
|
|
|
|
};
|
|
|
|
|
remote: separate the concept of push and fetch mirrors
git-remote currently has one option, "--mirror", which sets
up mirror configuration which can be used for either
fetching or pushing. It looks like this:
[remote "mirror"]
url = wherever
fetch = +refs/*:refs/*
mirror = true
However, a remote like this can be dangerous and confusing.
Specifically:
1. If you issue the wrong command, it can be devastating.
You are not likely to "push" when you meant to "fetch",
but "git remote update" will try to fetch it, even if
you intended the remote only for pushing. In either
case, the results can be quite destructive. An
unintended push will overwrite or delete remote refs,
and an unintended fetch can overwrite local branches.
2. The tracking setup code can produce confusing results.
The fetch refspec above means that "git checkout -b new
master" will consider refs/heads/master to come from
the remote "mirror", even if you only ever intend to
push to the mirror. It will set up the "new" branch to
track mirror's refs/heads/master.
3. The push code tries to opportunistically update
tracking branches. If you "git push mirror foo:bar",
it will see that we are updating mirror's
refs/heads/bar, which corresponds to our local
refs/heads/bar, and will update our local branch.
To solve this, we split the concept into "push mirrors" and
"fetch mirrors". Push mirrors set only remote.*.mirror,
solving (2) and (3), and making an accidental fetch write
only into FETCH_HEAD. Fetch mirrors set only the fetch
refspec, meaning an accidental push will not force-overwrite
or delete refs on the remote end.
The new syntax is "--mirror=<fetch|push>". For
compatibility, we keep "--mirror" as-is, setting up both
types simultaneously.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-03-30 23:53:19 +04:00
|
|
|
#define MIRROR_NONE 0
|
|
|
|
#define MIRROR_FETCH 1
|
|
|
|
#define MIRROR_PUSH 2
|
|
|
|
#define MIRROR_BOTH (MIRROR_FETCH|MIRROR_PUSH)
|
|
|
|
|
2016-02-22 14:23:29 +03:00
|
|
|
static void add_branch(const char *key, const char *branchname,
|
|
|
|
const char *remotename, int mirror, struct strbuf *tmp)
|
2010-05-19 22:38:50 +04:00
|
|
|
{
|
|
|
|
strbuf_reset(tmp);
|
|
|
|
strbuf_addch(tmp, '+');
|
|
|
|
if (mirror)
|
|
|
|
strbuf_addf(tmp, "refs/%s:refs/%s",
|
|
|
|
branchname, branchname);
|
|
|
|
else
|
|
|
|
strbuf_addf(tmp, "refs/heads/%s:refs/remotes/%s/%s",
|
|
|
|
branchname, remotename, branchname);
|
2016-02-22 14:23:36 +03:00
|
|
|
git_config_set_multivar(key, tmp->buf, "^$", 0);
|
2010-05-19 22:38:50 +04:00
|
|
|
}
|
|
|
|
|
2011-03-30 23:53:39 +04:00
|
|
|
static const char mirror_advice[] =
|
2012-04-23 16:30:26 +04:00
|
|
|
N_("--mirror is dangerous and deprecated; please\n"
|
|
|
|
"\t use --mirror=fetch or --mirror=push instead");
|
2011-03-30 23:53:39 +04:00
|
|
|
|
remote: separate the concept of push and fetch mirrors
git-remote currently has one option, "--mirror", which sets
up mirror configuration which can be used for either
fetching or pushing. It looks like this:
[remote "mirror"]
url = wherever
fetch = +refs/*:refs/*
mirror = true
However, a remote like this can be dangerous and confusing.
Specifically:
1. If you issue the wrong command, it can be devastating.
You are not likely to "push" when you meant to "fetch",
but "git remote update" will try to fetch it, even if
you intended the remote only for pushing. In either
case, the results can be quite destructive. An
unintended push will overwrite or delete remote refs,
and an unintended fetch can overwrite local branches.
2. The tracking setup code can produce confusing results.
The fetch refspec above means that "git checkout -b new
master" will consider refs/heads/master to come from
the remote "mirror", even if you only ever intend to
push to the mirror. It will set up the "new" branch to
track mirror's refs/heads/master.
3. The push code tries to opportunistically update
tracking branches. If you "git push mirror foo:bar",
it will see that we are updating mirror's
refs/heads/bar, which corresponds to our local
refs/heads/bar, and will update our local branch.
To solve this, we split the concept into "push mirrors" and
"fetch mirrors". Push mirrors set only remote.*.mirror,
solving (2) and (3), and making an accidental fetch write
only into FETCH_HEAD. Fetch mirrors set only the fetch
refspec, meaning an accidental push will not force-overwrite
or delete refs on the remote end.
The new syntax is "--mirror=<fetch|push>". For
compatibility, we keep "--mirror" as-is, setting up both
types simultaneously.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-03-30 23:53:19 +04:00
|
|
|
static int parse_mirror_opt(const struct option *opt, const char *arg, int not)
|
|
|
|
{
|
|
|
|
unsigned *mirror = opt->value;
|
|
|
|
if (not)
|
|
|
|
*mirror = MIRROR_NONE;
|
2011-03-30 23:53:39 +04:00
|
|
|
else if (!arg) {
|
2012-04-23 16:30:26 +04:00
|
|
|
warning("%s", _(mirror_advice));
|
remote: separate the concept of push and fetch mirrors
git-remote currently has one option, "--mirror", which sets
up mirror configuration which can be used for either
fetching or pushing. It looks like this:
[remote "mirror"]
url = wherever
fetch = +refs/*:refs/*
mirror = true
However, a remote like this can be dangerous and confusing.
Specifically:
1. If you issue the wrong command, it can be devastating.
You are not likely to "push" when you meant to "fetch",
but "git remote update" will try to fetch it, even if
you intended the remote only for pushing. In either
case, the results can be quite destructive. An
unintended push will overwrite or delete remote refs,
and an unintended fetch can overwrite local branches.
2. The tracking setup code can produce confusing results.
The fetch refspec above means that "git checkout -b new
master" will consider refs/heads/master to come from
the remote "mirror", even if you only ever intend to
push to the mirror. It will set up the "new" branch to
track mirror's refs/heads/master.
3. The push code tries to opportunistically update
tracking branches. If you "git push mirror foo:bar",
it will see that we are updating mirror's
refs/heads/bar, which corresponds to our local
refs/heads/bar, and will update our local branch.
To solve this, we split the concept into "push mirrors" and
"fetch mirrors". Push mirrors set only remote.*.mirror,
solving (2) and (3), and making an accidental fetch write
only into FETCH_HEAD. Fetch mirrors set only the fetch
refspec, meaning an accidental push will not force-overwrite
or delete refs on the remote end.
The new syntax is "--mirror=<fetch|push>". For
compatibility, we keep "--mirror" as-is, setting up both
types simultaneously.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-03-30 23:53:19 +04:00
|
|
|
*mirror = MIRROR_BOTH;
|
2011-03-30 23:53:39 +04:00
|
|
|
}
|
remote: separate the concept of push and fetch mirrors
git-remote currently has one option, "--mirror", which sets
up mirror configuration which can be used for either
fetching or pushing. It looks like this:
[remote "mirror"]
url = wherever
fetch = +refs/*:refs/*
mirror = true
However, a remote like this can be dangerous and confusing.
Specifically:
1. If you issue the wrong command, it can be devastating.
You are not likely to "push" when you meant to "fetch",
but "git remote update" will try to fetch it, even if
you intended the remote only for pushing. In either
case, the results can be quite destructive. An
unintended push will overwrite or delete remote refs,
and an unintended fetch can overwrite local branches.
2. The tracking setup code can produce confusing results.
The fetch refspec above means that "git checkout -b new
master" will consider refs/heads/master to come from
the remote "mirror", even if you only ever intend to
push to the mirror. It will set up the "new" branch to
track mirror's refs/heads/master.
3. The push code tries to opportunistically update
tracking branches. If you "git push mirror foo:bar",
it will see that we are updating mirror's
refs/heads/bar, which corresponds to our local
refs/heads/bar, and will update our local branch.
To solve this, we split the concept into "push mirrors" and
"fetch mirrors". Push mirrors set only remote.*.mirror,
solving (2) and (3), and making an accidental fetch write
only into FETCH_HEAD. Fetch mirrors set only the fetch
refspec, meaning an accidental push will not force-overwrite
or delete refs on the remote end.
The new syntax is "--mirror=<fetch|push>". For
compatibility, we keep "--mirror" as-is, setting up both
types simultaneously.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-03-30 23:53:19 +04:00
|
|
|
else if (!strcmp(arg, "fetch"))
|
|
|
|
*mirror = MIRROR_FETCH;
|
|
|
|
else if (!strcmp(arg, "push"))
|
|
|
|
*mirror = MIRROR_PUSH;
|
|
|
|
else
|
2012-04-23 16:30:26 +04:00
|
|
|
return error(_("unknown mirror argument: %s"), arg);
|
remote: separate the concept of push and fetch mirrors
git-remote currently has one option, "--mirror", which sets
up mirror configuration which can be used for either
fetching or pushing. It looks like this:
[remote "mirror"]
url = wherever
fetch = +refs/*:refs/*
mirror = true
However, a remote like this can be dangerous and confusing.
Specifically:
1. If you issue the wrong command, it can be devastating.
You are not likely to "push" when you meant to "fetch",
but "git remote update" will try to fetch it, even if
you intended the remote only for pushing. In either
case, the results can be quite destructive. An
unintended push will overwrite or delete remote refs,
and an unintended fetch can overwrite local branches.
2. The tracking setup code can produce confusing results.
The fetch refspec above means that "git checkout -b new
master" will consider refs/heads/master to come from
the remote "mirror", even if you only ever intend to
push to the mirror. It will set up the "new" branch to
track mirror's refs/heads/master.
3. The push code tries to opportunistically update
tracking branches. If you "git push mirror foo:bar",
it will see that we are updating mirror's
refs/heads/bar, which corresponds to our local
refs/heads/bar, and will update our local branch.
To solve this, we split the concept into "push mirrors" and
"fetch mirrors". Push mirrors set only remote.*.mirror,
solving (2) and (3), and making an accidental fetch write
only into FETCH_HEAD. Fetch mirrors set only the fetch
refspec, meaning an accidental push will not force-overwrite
or delete refs on the remote end.
The new syntax is "--mirror=<fetch|push>". For
compatibility, we keep "--mirror" as-is, setting up both
types simultaneously.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-03-30 23:53:19 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-02-29 04:45:45 +03:00
|
|
|
static int add(int argc, const char **argv)
|
|
|
|
{
|
remote: separate the concept of push and fetch mirrors
git-remote currently has one option, "--mirror", which sets
up mirror configuration which can be used for either
fetching or pushing. It looks like this:
[remote "mirror"]
url = wherever
fetch = +refs/*:refs/*
mirror = true
However, a remote like this can be dangerous and confusing.
Specifically:
1. If you issue the wrong command, it can be devastating.
You are not likely to "push" when you meant to "fetch",
but "git remote update" will try to fetch it, even if
you intended the remote only for pushing. In either
case, the results can be quite destructive. An
unintended push will overwrite or delete remote refs,
and an unintended fetch can overwrite local branches.
2. The tracking setup code can produce confusing results.
The fetch refspec above means that "git checkout -b new
master" will consider refs/heads/master to come from
the remote "mirror", even if you only ever intend to
push to the mirror. It will set up the "new" branch to
track mirror's refs/heads/master.
3. The push code tries to opportunistically update
tracking branches. If you "git push mirror foo:bar",
it will see that we are updating mirror's
refs/heads/bar, which corresponds to our local
refs/heads/bar, and will update our local branch.
To solve this, we split the concept into "push mirrors" and
"fetch mirrors". Push mirrors set only remote.*.mirror,
solving (2) and (3), and making an accidental fetch write
only into FETCH_HEAD. Fetch mirrors set only the fetch
refspec, meaning an accidental push will not force-overwrite
or delete refs on the remote end.
The new syntax is "--mirror=<fetch|push>". For
compatibility, we keep "--mirror" as-is, setting up both
types simultaneously.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-03-30 23:53:19 +04:00
|
|
|
int fetch = 0, fetch_tags = TAGS_DEFAULT;
|
|
|
|
unsigned mirror = MIRROR_NONE;
|
2010-07-04 23:46:19 +04:00
|
|
|
struct string_list track = STRING_LIST_INIT_NODUP;
|
2008-02-29 04:45:45 +03:00
|
|
|
const char *master = NULL;
|
|
|
|
struct remote *remote;
|
2008-10-09 23:12:12 +04:00
|
|
|
struct strbuf buf = STRBUF_INIT, buf2 = STRBUF_INIT;
|
2008-02-29 04:45:45 +03:00
|
|
|
const char *name, *url;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
struct option options[] = {
|
2013-08-03 15:51:19 +04:00
|
|
|
OPT_BOOL('f', "fetch", &fetch, N_("fetch the remote branches")),
|
2010-04-20 03:31:31 +04:00
|
|
|
OPT_SET_INT(0, "tags", &fetch_tags,
|
2012-08-20 16:32:35 +04:00
|
|
|
N_("import all tags and associated objects when fetching"),
|
2010-04-20 03:31:31 +04:00
|
|
|
TAGS_SET),
|
|
|
|
OPT_SET_INT(0, NULL, &fetch_tags,
|
2012-08-20 16:32:35 +04:00
|
|
|
N_("or do not fetch any tag at all (--no-tags)"), TAGS_UNSET),
|
|
|
|
OPT_STRING_LIST('t', "track", &track, N_("branch"),
|
|
|
|
N_("branch(es) to track")),
|
|
|
|
OPT_STRING('m', "master", &master, N_("branch"), N_("master branch")),
|
Use OPT_CALLBACK and OPT_CALLBACK_F
In the codebase, there are many options which use OPTION_CALLBACK in a
plain ol' struct definition. However, we have the OPT_CALLBACK and
OPT_CALLBACK_F macros which are meant to abstract these plain struct
definitions away. These macros are useful as they semantically signal to
developers that these are just normal callback option with nothing fancy
happening.
Replace plain struct definitions of OPTION_CALLBACK with OPT_CALLBACK or
OPT_CALLBACK_F where applicable. The heavy lifting was done using the
following (disgusting) shell script:
#!/bin/sh
do_replacement () {
tr '\n' '\r' |
sed -e 's/{\s*OPTION_CALLBACK,\s*\([^,]*\),\([^,]*\),\([^,]*\),\([^,]*\),\([^,]*\),\s*0,\(\s*[^[:space:]}]*\)\s*}/OPT_CALLBACK(\1,\2,\3,\4,\5,\6)/g' |
sed -e 's/{\s*OPTION_CALLBACK,\s*\([^,]*\),\([^,]*\),\([^,]*\),\([^,]*\),\([^,]*\),\([^,]*\),\(\s*[^[:space:]}]*\)\s*}/OPT_CALLBACK_F(\1,\2,\3,\4,\5,\6,\7)/g' |
tr '\r' '\n'
}
for f in $(git ls-files \*.c)
do
do_replacement <"$f" >"$f.tmp"
mv "$f.tmp" "$f"
done
The result was manually inspected and then reformatted to match the
style of the surrounding code. Finally, using
`git grep OPTION_CALLBACK \*.c`, leftover results which were not handled
by the script were manually transformed.
Signed-off-by: Denton Liu <liu.denton@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-04-28 11:36:28 +03:00
|
|
|
OPT_CALLBACK_F(0, "mirror", &mirror, "(push|fetch)",
|
2012-08-20 16:32:35 +04:00
|
|
|
N_("set up remote as a mirror to push to or fetch from"),
|
Use OPT_CALLBACK and OPT_CALLBACK_F
In the codebase, there are many options which use OPTION_CALLBACK in a
plain ol' struct definition. However, we have the OPT_CALLBACK and
OPT_CALLBACK_F macros which are meant to abstract these plain struct
definitions away. These macros are useful as they semantically signal to
developers that these are just normal callback option with nothing fancy
happening.
Replace plain struct definitions of OPTION_CALLBACK with OPT_CALLBACK or
OPT_CALLBACK_F where applicable. The heavy lifting was done using the
following (disgusting) shell script:
#!/bin/sh
do_replacement () {
tr '\n' '\r' |
sed -e 's/{\s*OPTION_CALLBACK,\s*\([^,]*\),\([^,]*\),\([^,]*\),\([^,]*\),\([^,]*\),\s*0,\(\s*[^[:space:]}]*\)\s*}/OPT_CALLBACK(\1,\2,\3,\4,\5,\6)/g' |
sed -e 's/{\s*OPTION_CALLBACK,\s*\([^,]*\),\([^,]*\),\([^,]*\),\([^,]*\),\([^,]*\),\([^,]*\),\(\s*[^[:space:]}]*\)\s*}/OPT_CALLBACK_F(\1,\2,\3,\4,\5,\6,\7)/g' |
tr '\r' '\n'
}
for f in $(git ls-files \*.c)
do
do_replacement <"$f" >"$f.tmp"
mv "$f.tmp" "$f"
done
The result was manually inspected and then reformatted to match the
style of the surrounding code. Finally, using
`git grep OPTION_CALLBACK \*.c`, leftover results which were not handled
by the script were manually transformed.
Signed-off-by: Denton Liu <liu.denton@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-04-28 11:36:28 +03:00
|
|
|
PARSE_OPT_OPTARG | PARSE_OPT_COMP_ARG, parse_mirror_opt),
|
2008-02-29 04:45:45 +03:00
|
|
|
OPT_END()
|
|
|
|
};
|
|
|
|
|
2009-11-21 02:43:13 +03:00
|
|
|
argc = parse_options(argc, argv, NULL, options, builtin_remote_add_usage,
|
2009-05-23 22:53:12 +04:00
|
|
|
0);
|
2008-02-29 04:45:45 +03:00
|
|
|
|
2013-04-24 17:54:36 +04:00
|
|
|
if (argc != 2)
|
2009-11-21 02:43:13 +03:00
|
|
|
usage_with_options(builtin_remote_add_usage, options);
|
2008-02-29 04:45:45 +03:00
|
|
|
|
remote: disallow some nonsensical option combinations
It doesn't make sense to use "-m" on a mirror, since "-m"
sets up the HEAD symref in the remotes namespace, but with
mirror, we are by definition not using a remotes namespace.
Similarly, it does not make much sense to specify refspecs
with --mirror. For a mirror you plan to push to, those
refspecs will be ignored. For a mirror you are fetching
from, there is no point in mirroring, since the refspec
specifies everything you want to grab.
There is one case where "--mirror -t <X>" would be useful.
Because <X> is used as-is in the refspec, and because we
append it to to refs/, you could mirror a subset of the
hierarchy by doing:
git remote add --mirror -t 'tags/*'
But using anything besides a single branch as an argument to
"-t" is not documented and only happens to work, so closing
it off is not a serious regression.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-03-30 23:52:52 +04:00
|
|
|
if (mirror && master)
|
2012-04-23 16:30:26 +04:00
|
|
|
die(_("specifying a master branch makes no sense with --mirror"));
|
2011-05-26 19:11:00 +04:00
|
|
|
if (mirror && !(mirror & MIRROR_FETCH) && track.nr)
|
2012-04-23 16:30:26 +04:00
|
|
|
die(_("specifying branches to track makes sense only with fetch mirrors"));
|
remote: disallow some nonsensical option combinations
It doesn't make sense to use "-m" on a mirror, since "-m"
sets up the HEAD symref in the remotes namespace, but with
mirror, we are by definition not using a remotes namespace.
Similarly, it does not make much sense to specify refspecs
with --mirror. For a mirror you plan to push to, those
refspecs will be ignored. For a mirror you are fetching
from, there is no point in mirroring, since the refspec
specifies everything you want to grab.
There is one case where "--mirror -t <X>" would be useful.
Because <X> is used as-is in the refspec, and because we
append it to to refs/, you could mirror a subset of the
hierarchy by doing:
git remote add --mirror -t 'tags/*'
But using anything besides a single branch as an argument to
"-t" is not documented and only happens to work, so closing
it off is not a serious regression.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-03-30 23:52:52 +04:00
|
|
|
|
2008-02-29 04:45:45 +03:00
|
|
|
name = argv[0];
|
|
|
|
url = argv[1];
|
|
|
|
|
|
|
|
remote = remote_get(name);
|
2017-01-20 00:20:02 +03:00
|
|
|
if (remote_is_configured(remote, 1))
|
2012-04-23 16:30:26 +04:00
|
|
|
die(_("remote %s already exists."), name);
|
2008-02-29 04:45:45 +03:00
|
|
|
|
2008-04-13 13:56:54 +04:00
|
|
|
strbuf_addf(&buf2, "refs/heads/test:refs/remotes/%s/test", name);
|
|
|
|
if (!valid_fetch_refspec(buf2.buf))
|
2012-04-23 16:30:26 +04:00
|
|
|
die(_("'%s' is not a valid remote name"), name);
|
2008-04-13 13:56:54 +04:00
|
|
|
|
2008-02-29 04:45:45 +03:00
|
|
|
strbuf_addf(&buf, "remote.%s.url", name);
|
2016-02-22 14:23:36 +03:00
|
|
|
git_config_set(buf.buf, url);
|
2008-02-29 04:45:45 +03:00
|
|
|
|
remote: separate the concept of push and fetch mirrors
git-remote currently has one option, "--mirror", which sets
up mirror configuration which can be used for either
fetching or pushing. It looks like this:
[remote "mirror"]
url = wherever
fetch = +refs/*:refs/*
mirror = true
However, a remote like this can be dangerous and confusing.
Specifically:
1. If you issue the wrong command, it can be devastating.
You are not likely to "push" when you meant to "fetch",
but "git remote update" will try to fetch it, even if
you intended the remote only for pushing. In either
case, the results can be quite destructive. An
unintended push will overwrite or delete remote refs,
and an unintended fetch can overwrite local branches.
2. The tracking setup code can produce confusing results.
The fetch refspec above means that "git checkout -b new
master" will consider refs/heads/master to come from
the remote "mirror", even if you only ever intend to
push to the mirror. It will set up the "new" branch to
track mirror's refs/heads/master.
3. The push code tries to opportunistically update
tracking branches. If you "git push mirror foo:bar",
it will see that we are updating mirror's
refs/heads/bar, which corresponds to our local
refs/heads/bar, and will update our local branch.
To solve this, we split the concept into "push mirrors" and
"fetch mirrors". Push mirrors set only remote.*.mirror,
solving (2) and (3), and making an accidental fetch write
only into FETCH_HEAD. Fetch mirrors set only the fetch
refspec, meaning an accidental push will not force-overwrite
or delete refs on the remote end.
The new syntax is "--mirror=<fetch|push>". For
compatibility, we keep "--mirror" as-is, setting up both
types simultaneously.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-03-30 23:53:19 +04:00
|
|
|
if (!mirror || mirror & MIRROR_FETCH) {
|
|
|
|
strbuf_reset(&buf);
|
|
|
|
strbuf_addf(&buf, "remote.%s.fetch", name);
|
|
|
|
if (track.nr == 0)
|
|
|
|
string_list_append(&track, "*");
|
|
|
|
for (i = 0; i < track.nr; i++) {
|
2016-02-22 14:23:29 +03:00
|
|
|
add_branch(buf.buf, track.items[i].string,
|
|
|
|
name, mirror, &buf2);
|
remote: separate the concept of push and fetch mirrors
git-remote currently has one option, "--mirror", which sets
up mirror configuration which can be used for either
fetching or pushing. It looks like this:
[remote "mirror"]
url = wherever
fetch = +refs/*:refs/*
mirror = true
However, a remote like this can be dangerous and confusing.
Specifically:
1. If you issue the wrong command, it can be devastating.
You are not likely to "push" when you meant to "fetch",
but "git remote update" will try to fetch it, even if
you intended the remote only for pushing. In either
case, the results can be quite destructive. An
unintended push will overwrite or delete remote refs,
and an unintended fetch can overwrite local branches.
2. The tracking setup code can produce confusing results.
The fetch refspec above means that "git checkout -b new
master" will consider refs/heads/master to come from
the remote "mirror", even if you only ever intend to
push to the mirror. It will set up the "new" branch to
track mirror's refs/heads/master.
3. The push code tries to opportunistically update
tracking branches. If you "git push mirror foo:bar",
it will see that we are updating mirror's
refs/heads/bar, which corresponds to our local
refs/heads/bar, and will update our local branch.
To solve this, we split the concept into "push mirrors" and
"fetch mirrors". Push mirrors set only remote.*.mirror,
solving (2) and (3), and making an accidental fetch write
only into FETCH_HEAD. Fetch mirrors set only the fetch
refspec, meaning an accidental push will not force-overwrite
or delete refs on the remote end.
The new syntax is "--mirror=<fetch|push>". For
compatibility, we keep "--mirror" as-is, setting up both
types simultaneously.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-03-30 23:53:19 +04:00
|
|
|
}
|
2008-02-29 04:45:45 +03:00
|
|
|
}
|
|
|
|
|
remote: separate the concept of push and fetch mirrors
git-remote currently has one option, "--mirror", which sets
up mirror configuration which can be used for either
fetching or pushing. It looks like this:
[remote "mirror"]
url = wherever
fetch = +refs/*:refs/*
mirror = true
However, a remote like this can be dangerous and confusing.
Specifically:
1. If you issue the wrong command, it can be devastating.
You are not likely to "push" when you meant to "fetch",
but "git remote update" will try to fetch it, even if
you intended the remote only for pushing. In either
case, the results can be quite destructive. An
unintended push will overwrite or delete remote refs,
and an unintended fetch can overwrite local branches.
2. The tracking setup code can produce confusing results.
The fetch refspec above means that "git checkout -b new
master" will consider refs/heads/master to come from
the remote "mirror", even if you only ever intend to
push to the mirror. It will set up the "new" branch to
track mirror's refs/heads/master.
3. The push code tries to opportunistically update
tracking branches. If you "git push mirror foo:bar",
it will see that we are updating mirror's
refs/heads/bar, which corresponds to our local
refs/heads/bar, and will update our local branch.
To solve this, we split the concept into "push mirrors" and
"fetch mirrors". Push mirrors set only remote.*.mirror,
solving (2) and (3), and making an accidental fetch write
only into FETCH_HEAD. Fetch mirrors set only the fetch
refspec, meaning an accidental push will not force-overwrite
or delete refs on the remote end.
The new syntax is "--mirror=<fetch|push>". For
compatibility, we keep "--mirror" as-is, setting up both
types simultaneously.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-03-30 23:53:19 +04:00
|
|
|
if (mirror & MIRROR_PUSH) {
|
2008-04-17 15:17:20 +04:00
|
|
|
strbuf_reset(&buf);
|
|
|
|
strbuf_addf(&buf, "remote.%s.mirror", name);
|
2016-02-22 14:23:36 +03:00
|
|
|
git_config_set(buf.buf, "true");
|
2008-04-17 15:17:20 +04:00
|
|
|
}
|
|
|
|
|
2010-04-20 03:31:31 +04:00
|
|
|
if (fetch_tags != TAGS_DEFAULT) {
|
|
|
|
strbuf_reset(&buf);
|
|
|
|
strbuf_addf(&buf, "remote.%s.tagopt", name);
|
2016-02-22 14:23:36 +03:00
|
|
|
git_config_set(buf.buf,
|
|
|
|
fetch_tags == TAGS_SET ? "--tags" : "--no-tags");
|
2010-04-20 03:31:31 +04:00
|
|
|
}
|
|
|
|
|
2008-02-29 04:45:45 +03:00
|
|
|
if (fetch && fetch_remote(name))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
if (master) {
|
|
|
|
strbuf_reset(&buf);
|
|
|
|
strbuf_addf(&buf, "refs/remotes/%s/HEAD", name);
|
|
|
|
|
|
|
|
strbuf_reset(&buf2);
|
|
|
|
strbuf_addf(&buf2, "refs/remotes/%s/%s", name, master);
|
|
|
|
|
|
|
|
if (create_symref(buf.buf, buf2.buf, "remote add"))
|
2012-04-23 16:30:26 +04:00
|
|
|
return error(_("Could not setup master '%s'"), master);
|
2008-02-29 04:45:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
strbuf_release(&buf);
|
|
|
|
strbuf_release(&buf2);
|
2008-07-21 22:03:49 +04:00
|
|
|
string_list_clear(&track, 0);
|
2008-02-29 04:45:45 +03:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct branch_info {
|
2009-02-25 11:32:21 +03:00
|
|
|
char *remote_name;
|
2008-07-21 22:03:49 +04:00
|
|
|
struct string_list merge;
|
2020-01-27 10:04:27 +03:00
|
|
|
enum rebase_type rebase;
|
2020-01-27 10:04:30 +03:00
|
|
|
char *push_remote_name;
|
2008-02-29 04:45:45 +03:00
|
|
|
};
|
|
|
|
|
2016-06-13 13:04:20 +03:00
|
|
|
static struct string_list branch_list = STRING_LIST_INIT_NODUP;
|
2008-02-29 04:45:45 +03:00
|
|
|
|
2008-07-18 08:30:33 +04:00
|
|
|
static const char *abbrev_ref(const char *name, const char *prefix)
|
|
|
|
{
|
refactor skip_prefix to return a boolean
The skip_prefix() function returns a pointer to the content
past the prefix, or NULL if the prefix was not found. While
this is nice and simple, in practice it makes it hard to use
for two reasons:
1. When you want to conditionally skip or keep the string
as-is, you have to introduce a temporary variable.
For example:
tmp = skip_prefix(buf, "foo");
if (tmp)
buf = tmp;
2. It is verbose to check the outcome in a conditional, as
you need extra parentheses to silence compiler
warnings. For example:
if ((cp = skip_prefix(buf, "foo"))
/* do something with cp */
Both of these make it harder to use for long if-chains, and
we tend to use starts_with() instead. However, the first line
of "do something" is often to then skip forward in buf past
the prefix, either using a magic constant or with an extra
strlen(3) (which is generally computed at compile time, but
means we are repeating ourselves).
This patch refactors skip_prefix() to return a simple boolean,
and to provide the pointer value as an out-parameter. If the
prefix is not found, the out-parameter is untouched. This
lets you write:
if (skip_prefix(arg, "foo ", &arg))
do_foo(arg);
else if (skip_prefix(arg, "bar ", &arg))
do_bar(arg);
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2014-06-18 23:44:19 +04:00
|
|
|
skip_prefix(name, prefix, &name);
|
2008-07-18 08:30:33 +04:00
|
|
|
return name;
|
|
|
|
}
|
|
|
|
#define abbrev_branch(name) abbrev_ref((name), "refs/heads/")
|
|
|
|
|
2008-05-14 21:46:53 +04:00
|
|
|
static int config_read_branches(const char *key, const char *value, void *cb)
|
2008-02-29 04:45:45 +03:00
|
|
|
{
|
2020-01-27 10:04:28 +03:00
|
|
|
const char *orig_key = key;
|
|
|
|
char *name;
|
|
|
|
struct string_list_item *item;
|
|
|
|
struct branch_info *info;
|
2020-01-27 10:04:30 +03:00
|
|
|
enum { REMOTE, MERGE, REBASE, PUSH_REMOTE } type;
|
2020-01-27 10:04:28 +03:00
|
|
|
size_t key_len;
|
|
|
|
|
|
|
|
if (!starts_with(key, "branch."))
|
|
|
|
return 0;
|
|
|
|
|
2020-01-27 10:04:29 +03:00
|
|
|
key += strlen("branch.");
|
|
|
|
if (strip_suffix(key, ".remote", &key_len))
|
2020-01-27 10:04:28 +03:00
|
|
|
type = REMOTE;
|
2020-01-27 10:04:29 +03:00
|
|
|
else if (strip_suffix(key, ".merge", &key_len))
|
2020-01-27 10:04:28 +03:00
|
|
|
type = MERGE;
|
2020-01-27 10:04:29 +03:00
|
|
|
else if (strip_suffix(key, ".rebase", &key_len))
|
2020-01-27 10:04:28 +03:00
|
|
|
type = REBASE;
|
2020-01-27 10:04:30 +03:00
|
|
|
else if (strip_suffix(key, ".pushremote", &key_len))
|
|
|
|
type = PUSH_REMOTE;
|
2020-01-27 10:04:29 +03:00
|
|
|
else
|
2020-01-27 10:04:28 +03:00
|
|
|
return 0;
|
2020-01-27 10:04:29 +03:00
|
|
|
name = xmemdupz(key, key_len);
|
2020-01-27 10:04:28 +03:00
|
|
|
|
|
|
|
item = string_list_insert(&branch_list, name);
|
|
|
|
|
|
|
|
if (!item->util)
|
|
|
|
item->util = xcalloc(1, sizeof(struct branch_info));
|
|
|
|
info = item->util;
|
2020-01-27 10:04:29 +03:00
|
|
|
switch (type) {
|
|
|
|
case REMOTE:
|
2020-01-27 10:04:28 +03:00
|
|
|
if (info->remote_name)
|
|
|
|
warning(_("more than one %s"), orig_key);
|
|
|
|
info->remote_name = xstrdup(value);
|
2020-01-27 10:04:29 +03:00
|
|
|
break;
|
|
|
|
case MERGE: {
|
2020-01-27 10:04:28 +03:00
|
|
|
char *space = strchr(value, ' ');
|
|
|
|
value = abbrev_branch(value);
|
|
|
|
while (space) {
|
|
|
|
char *merge;
|
|
|
|
merge = xstrndup(value, space - value);
|
|
|
|
string_list_append(&info->merge, merge);
|
|
|
|
value = abbrev_branch(space + 1);
|
|
|
|
space = strchr(value, ' ');
|
|
|
|
}
|
|
|
|
string_list_append(&info->merge, xstrdup(value));
|
2020-01-27 10:04:29 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case REBASE:
|
2020-01-27 10:04:28 +03:00
|
|
|
/*
|
|
|
|
* Consider invalid values as false and check the
|
|
|
|
* truth value with >= REBASE_TRUE.
|
|
|
|
*/
|
|
|
|
info->rebase = rebase_parse_value(value);
|
2020-01-27 10:04:29 +03:00
|
|
|
break;
|
2020-01-27 10:04:30 +03:00
|
|
|
case PUSH_REMOTE:
|
|
|
|
if (info->push_remote_name)
|
|
|
|
warning(_("more than one %s"), orig_key);
|
|
|
|
info->push_remote_name = xstrdup(value);
|
|
|
|
break;
|
2020-01-27 10:04:29 +03:00
|
|
|
default:
|
|
|
|
BUG("unexpected type=%d", type);
|
|
|
|
}
|
2020-01-27 10:04:28 +03:00
|
|
|
|
2008-02-29 04:45:45 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void read_branches(void)
|
|
|
|
{
|
|
|
|
if (branch_list.nr)
|
|
|
|
return;
|
2008-05-14 21:46:53 +04:00
|
|
|
git_config(config_read_branches, NULL);
|
2008-02-29 04:45:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
struct ref_states {
|
|
|
|
struct remote *remote;
|
2018-02-14 21:59:35 +03:00
|
|
|
struct string_list new_refs, stale, tracked, heads, push;
|
2009-02-25 11:32:27 +03:00
|
|
|
int queried;
|
2008-02-29 04:45:45 +03:00
|
|
|
};
|
|
|
|
|
2009-02-25 11:32:21 +03:00
|
|
|
static int get_ref_states(const struct ref *remote_refs, struct ref_states *states)
|
2008-02-29 04:45:45 +03:00
|
|
|
{
|
|
|
|
struct ref *fetch_map = NULL, **tail = &fetch_map;
|
2009-11-10 08:03:31 +03:00
|
|
|
struct ref *ref, *stale_refs;
|
2008-02-29 04:45:45 +03:00
|
|
|
int i;
|
|
|
|
|
2018-05-17 01:58:01 +03:00
|
|
|
for (i = 0; i < states->remote->fetch.nr; i++)
|
|
|
|
if (get_fetch_map(remote_refs, &states->remote->fetch.items[i], &tail, 1))
|
2012-04-23 16:30:26 +04:00
|
|
|
die(_("Could not get fetch map for refspec %s"),
|
2018-05-17 01:58:01 +03:00
|
|
|
states->remote->fetch.raw[i]);
|
2008-02-29 04:45:45 +03:00
|
|
|
|
2018-02-14 21:59:35 +03:00
|
|
|
states->new_refs.strdup_strings = 1;
|
2009-12-01 02:57:27 +03:00
|
|
|
states->tracked.strdup_strings = 1;
|
|
|
|
states->stale.strdup_strings = 1;
|
2008-02-29 04:45:45 +03:00
|
|
|
for (ref = fetch_map; ref; ref = ref->next) {
|
2011-11-13 14:22:14 +04:00
|
|
|
if (!ref->peer_ref || !ref_exists(ref->peer_ref->name))
|
2018-02-14 21:59:35 +03:00
|
|
|
string_list_append(&states->new_refs, abbrev_branch(ref->name));
|
2009-02-25 11:32:20 +03:00
|
|
|
else
|
2010-06-26 03:41:38 +04:00
|
|
|
string_list_append(&states->tracked, abbrev_branch(ref->name));
|
2008-02-29 04:45:45 +03:00
|
|
|
}
|
2018-05-17 01:58:10 +03:00
|
|
|
stale_refs = get_stale_heads(&states->remote->fetch, fetch_map);
|
2009-11-10 08:03:31 +03:00
|
|
|
for (ref = stale_refs; ref; ref = ref->next) {
|
|
|
|
struct string_list_item *item =
|
2010-06-26 03:41:38 +04:00
|
|
|
string_list_append(&states->stale, abbrev_branch(ref->name));
|
2009-11-10 08:03:31 +03:00
|
|
|
item->util = xstrdup(ref->name);
|
|
|
|
}
|
|
|
|
free_refs(stale_refs);
|
2008-02-29 04:45:45 +03:00
|
|
|
free_refs(fetch_map);
|
|
|
|
|
2018-02-14 21:59:35 +03:00
|
|
|
string_list_sort(&states->new_refs);
|
2014-11-25 11:02:35 +03:00
|
|
|
string_list_sort(&states->tracked);
|
|
|
|
string_list_sort(&states->stale);
|
2008-02-29 04:45:45 +03:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-02-25 11:32:28 +03:00
|
|
|
struct push_info {
|
|
|
|
char *dest;
|
|
|
|
int forced;
|
|
|
|
enum {
|
|
|
|
PUSH_STATUS_CREATE = 0,
|
|
|
|
PUSH_STATUS_DELETE,
|
|
|
|
PUSH_STATUS_UPTODATE,
|
|
|
|
PUSH_STATUS_FASTFORWARD,
|
|
|
|
PUSH_STATUS_OUTOFDATE,
|
2010-05-14 13:31:35 +04:00
|
|
|
PUSH_STATUS_NOTQUERIED
|
2009-02-25 11:32:28 +03:00
|
|
|
} status;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int get_push_ref_states(const struct ref *remote_refs,
|
|
|
|
struct ref_states *states)
|
|
|
|
{
|
|
|
|
struct remote *remote = states->remote;
|
2009-05-31 18:26:48 +04:00
|
|
|
struct ref *ref, *local_refs, *push_map;
|
2009-02-25 11:32:28 +03:00
|
|
|
if (remote->mirror)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
local_refs = get_local_heads();
|
2009-05-28 00:13:43 +04:00
|
|
|
push_map = copy_ref_list(remote_refs);
|
2009-02-25 11:32:28 +03:00
|
|
|
|
2018-05-17 01:58:21 +03:00
|
|
|
match_push_refs(local_refs, &push_map, &remote->push, MATCH_REFS_NONE);
|
2009-02-25 11:32:28 +03:00
|
|
|
|
|
|
|
states->push.strdup_strings = 1;
|
|
|
|
for (ref = push_map; ref; ref = ref->next) {
|
|
|
|
struct string_list_item *item;
|
|
|
|
struct push_info *info;
|
|
|
|
|
|
|
|
if (!ref->peer_ref)
|
|
|
|
continue;
|
2015-11-10 05:22:20 +03:00
|
|
|
oidcpy(&ref->new_oid, &ref->peer_ref->new_oid);
|
2009-02-25 11:32:28 +03:00
|
|
|
|
2010-06-26 03:41:38 +04:00
|
|
|
item = string_list_append(&states->push,
|
|
|
|
abbrev_branch(ref->peer_ref->name));
|
2014-05-26 19:33:44 +04:00
|
|
|
item->util = xcalloc(1, sizeof(struct push_info));
|
2009-02-25 11:32:28 +03:00
|
|
|
info = item->util;
|
|
|
|
info->forced = ref->force;
|
|
|
|
info->dest = xstrdup(abbrev_branch(ref->name));
|
|
|
|
|
2015-11-10 05:22:20 +03:00
|
|
|
if (is_null_oid(&ref->new_oid)) {
|
2009-02-25 11:32:28 +03:00
|
|
|
info->status = PUSH_STATUS_DELETE;
|
convert "oidcmp() == 0" to oideq()
Using the more restrictive oideq() should, in the long run,
give the compiler more opportunities to optimize these
callsites. For now, this conversion should be a complete
noop with respect to the generated code.
The result is also perhaps a little more readable, as it
avoids the "zero is equal" idiom. Since it's so prevalent in
C, I think seasoned programmers tend not to even notice it
anymore, but it can sometimes make for awkward double
negations (e.g., we can drop a few !!oidcmp() instances
here).
This patch was generated almost entirely by the included
coccinelle patch. This mechanical conversion should be
completely safe, because we check explicitly for cases where
oidcmp() is compared to 0, which is what oideq() is doing
under the hood. Note that we don't have to catch "!oidcmp()"
separately; coccinelle's standard isomorphisms make sure the
two are treated equivalently.
I say "almost" because I did hand-edit the coccinelle output
to fix up a few style violations (it mostly keeps the
original formatting, but sometimes unwraps long lines).
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2018-08-29 00:22:40 +03:00
|
|
|
} else if (oideq(&ref->old_oid, &ref->new_oid))
|
2009-02-25 11:32:28 +03:00
|
|
|
info->status = PUSH_STATUS_UPTODATE;
|
2015-11-10 05:22:20 +03:00
|
|
|
else if (is_null_oid(&ref->old_oid))
|
2009-02-25 11:32:28 +03:00
|
|
|
info->status = PUSH_STATUS_CREATE;
|
2015-11-10 05:22:20 +03:00
|
|
|
else if (has_object_file(&ref->old_oid) &&
|
2015-11-10 05:22:25 +03:00
|
|
|
ref_newer(&ref->new_oid, &ref->old_oid))
|
2009-02-25 11:32:28 +03:00
|
|
|
info->status = PUSH_STATUS_FASTFORWARD;
|
|
|
|
else
|
|
|
|
info->status = PUSH_STATUS_OUTOFDATE;
|
|
|
|
}
|
|
|
|
free_refs(local_refs);
|
|
|
|
free_refs(push_map);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int get_push_ref_states_noquery(struct ref_states *states)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
struct remote *remote = states->remote;
|
|
|
|
struct string_list_item *item;
|
|
|
|
struct push_info *info;
|
|
|
|
|
|
|
|
if (remote->mirror)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
states->push.strdup_strings = 1;
|
2018-05-17 01:58:00 +03:00
|
|
|
if (!remote->push.nr) {
|
2012-04-23 16:30:26 +04:00
|
|
|
item = string_list_append(&states->push, _("(matching)"));
|
2014-05-26 19:33:44 +04:00
|
|
|
info = item->util = xcalloc(1, sizeof(struct push_info));
|
2009-02-25 11:32:28 +03:00
|
|
|
info->status = PUSH_STATUS_NOTQUERIED;
|
|
|
|
info->dest = xstrdup(item->string);
|
|
|
|
}
|
2018-05-17 01:58:00 +03:00
|
|
|
for (i = 0; i < remote->push.nr; i++) {
|
|
|
|
const struct refspec_item *spec = &remote->push.items[i];
|
2009-02-25 11:32:28 +03:00
|
|
|
if (spec->matching)
|
2012-04-23 16:30:26 +04:00
|
|
|
item = string_list_append(&states->push, _("(matching)"));
|
2009-03-08 11:12:33 +03:00
|
|
|
else if (strlen(spec->src))
|
2010-06-26 03:41:38 +04:00
|
|
|
item = string_list_append(&states->push, spec->src);
|
2009-02-25 11:32:28 +03:00
|
|
|
else
|
2012-04-23 16:30:26 +04:00
|
|
|
item = string_list_append(&states->push, _("(delete)"));
|
2009-02-25 11:32:28 +03:00
|
|
|
|
2014-05-26 19:33:44 +04:00
|
|
|
info = item->util = xcalloc(1, sizeof(struct push_info));
|
2009-02-25 11:32:28 +03:00
|
|
|
info->forced = spec->force;
|
|
|
|
info->status = PUSH_STATUS_NOTQUERIED;
|
2009-03-08 11:12:33 +03:00
|
|
|
info->dest = xstrdup(spec->dst ? spec->dst : item->string);
|
2009-02-25 11:32:28 +03:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-02-25 11:32:24 +03:00
|
|
|
static int get_head_names(const struct ref *remote_refs, struct ref_states *states)
|
|
|
|
{
|
|
|
|
struct ref *ref, *matches;
|
|
|
|
struct ref *fetch_map = NULL, **fetch_map_tail = &fetch_map;
|
2018-05-17 01:57:49 +03:00
|
|
|
struct refspec_item refspec;
|
2009-02-25 11:32:24 +03:00
|
|
|
|
|
|
|
refspec.force = 0;
|
|
|
|
refspec.pattern = 1;
|
2009-03-08 11:12:33 +03:00
|
|
|
refspec.src = refspec.dst = "refs/heads/*";
|
2009-02-25 11:32:24 +03:00
|
|
|
states->heads.strdup_strings = 1;
|
|
|
|
get_fetch_map(remote_refs, &refspec, &fetch_map_tail, 0);
|
|
|
|
matches = guess_remote_head(find_ref_by_name(remote_refs, "HEAD"),
|
|
|
|
fetch_map, 1);
|
2009-09-01 09:35:10 +04:00
|
|
|
for (ref = matches; ref; ref = ref->next)
|
2010-06-26 03:41:38 +04:00
|
|
|
string_list_append(&states->heads, abbrev_branch(ref->name));
|
2009-02-25 11:32:24 +03:00
|
|
|
|
|
|
|
free_refs(fetch_map);
|
|
|
|
free_refs(matches);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-06-01 08:28:04 +04:00
|
|
|
struct known_remote {
|
|
|
|
struct known_remote *next;
|
|
|
|
struct remote *remote;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct known_remotes {
|
|
|
|
struct remote *to_delete;
|
|
|
|
struct known_remote *list;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int add_known_remote(struct remote *remote, void *cb_data)
|
|
|
|
{
|
|
|
|
struct known_remotes *all = cb_data;
|
|
|
|
struct known_remote *r;
|
|
|
|
|
|
|
|
if (!strcmp(all->to_delete->name, remote->name))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
r = xmalloc(sizeof(*r));
|
|
|
|
r->remote = remote;
|
|
|
|
r->next = all->list;
|
|
|
|
all->list = r;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-02-29 04:45:45 +03:00
|
|
|
struct branches_for_remote {
|
2008-06-01 08:28:04 +04:00
|
|
|
struct remote *remote;
|
2009-02-04 19:06:07 +03:00
|
|
|
struct string_list *branches, *skipped;
|
2008-06-01 08:28:04 +04:00
|
|
|
struct known_remotes *keep;
|
2008-02-29 04:45:45 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
static int add_branch_for_removal(const char *refname,
|
2015-05-25 21:38:41 +03:00
|
|
|
const struct object_id *oid, int flags, void *cb_data)
|
2008-02-29 04:45:45 +03:00
|
|
|
{
|
|
|
|
struct branches_for_remote *branches = cb_data;
|
2018-05-17 01:57:49 +03:00
|
|
|
struct refspec_item refspec;
|
2008-06-01 08:28:04 +04:00
|
|
|
struct known_remote *kr;
|
2008-02-29 04:45:45 +03:00
|
|
|
|
2008-06-01 08:28:04 +04:00
|
|
|
memset(&refspec, 0, sizeof(refspec));
|
|
|
|
refspec.dst = (char *)refname;
|
|
|
|
if (remote_find_tracking(branches->remote, &refspec))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* don't delete a branch if another remote also uses it */
|
|
|
|
for (kr = branches->keep->list; kr; kr = kr->next) {
|
|
|
|
memset(&refspec, 0, sizeof(refspec));
|
|
|
|
refspec.dst = (char *)refname;
|
|
|
|
if (!remote_find_tracking(kr->remote, &refspec))
|
|
|
|
return 0;
|
|
|
|
}
|
2008-03-09 01:40:42 +03:00
|
|
|
|
2010-11-02 18:31:25 +03:00
|
|
|
/* don't delete non-remote-tracking refs */
|
2013-12-01 00:55:40 +04:00
|
|
|
if (!starts_with(refname, "refs/remotes/")) {
|
2009-02-04 19:06:07 +03:00
|
|
|
/* advise user how to delete local branches */
|
2013-12-01 00:55:40 +04:00
|
|
|
if (starts_with(refname, "refs/heads/"))
|
2010-06-26 03:41:38 +04:00
|
|
|
string_list_append(branches->skipped,
|
|
|
|
abbrev_branch(refname));
|
2009-02-04 19:06:07 +03:00
|
|
|
/* silently skip over other non-remote refs */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-05-25 21:38:42 +03:00
|
|
|
string_list_append(branches->branches, refname);
|
2008-02-29 04:45:45 +03:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-11-03 21:26:18 +03:00
|
|
|
struct rename_info {
|
2018-02-14 21:59:35 +03:00
|
|
|
const char *old_name;
|
|
|
|
const char *new_name;
|
2008-11-03 21:26:18 +03:00
|
|
|
struct string_list *remote_branches;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int read_remote_branches(const char *refname,
|
2015-05-25 21:38:43 +03:00
|
|
|
const struct object_id *oid, int flags, void *cb_data)
|
2008-11-03 21:26:18 +03:00
|
|
|
{
|
|
|
|
struct rename_info *rename = cb_data;
|
|
|
|
struct strbuf buf = STRBUF_INIT;
|
|
|
|
struct string_list_item *item;
|
|
|
|
int flag;
|
|
|
|
const char *symref;
|
|
|
|
|
2018-02-14 21:59:35 +03:00
|
|
|
strbuf_addf(&buf, "refs/remotes/%s/", rename->old_name);
|
2013-12-01 00:55:40 +04:00
|
|
|
if (starts_with(refname, buf.buf)) {
|
2018-08-01 13:19:07 +03:00
|
|
|
item = string_list_append(rename->remote_branches, refname);
|
2014-07-15 23:59:36 +04:00
|
|
|
symref = resolve_ref_unsafe(refname, RESOLVE_REF_READING,
|
2017-09-23 12:45:04 +03:00
|
|
|
NULL, &flag);
|
2017-10-19 20:47:30 +03:00
|
|
|
if (symref && (flag & REF_ISSYMREF))
|
2008-11-03 21:26:18 +03:00
|
|
|
item->util = xstrdup(symref);
|
|
|
|
else
|
|
|
|
item->util = NULL;
|
|
|
|
}
|
2017-08-30 21:00:25 +03:00
|
|
|
strbuf_release(&buf);
|
2008-11-03 21:26:18 +03:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-11-10 23:43:01 +03:00
|
|
|
static int migrate_file(struct remote *remote)
|
|
|
|
{
|
|
|
|
struct strbuf buf = STRBUF_INIT;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
strbuf_addf(&buf, "remote.%s.url", remote->name);
|
|
|
|
for (i = 0; i < remote->url_nr; i++)
|
2016-02-22 14:23:36 +03:00
|
|
|
git_config_set_multivar(buf.buf, remote->url[i], "^$", 0);
|
2008-11-10 23:43:01 +03:00
|
|
|
strbuf_reset(&buf);
|
|
|
|
strbuf_addf(&buf, "remote.%s.push", remote->name);
|
2018-05-17 01:58:00 +03:00
|
|
|
for (i = 0; i < remote->push.raw_nr; i++)
|
|
|
|
git_config_set_multivar(buf.buf, remote->push.raw[i], "^$", 0);
|
2008-11-10 23:43:01 +03:00
|
|
|
strbuf_reset(&buf);
|
|
|
|
strbuf_addf(&buf, "remote.%s.fetch", remote->name);
|
2018-05-17 01:58:01 +03:00
|
|
|
for (i = 0; i < remote->fetch.raw_nr; i++)
|
|
|
|
git_config_set_multivar(buf.buf, remote->fetch.raw[i], "^$", 0);
|
2008-11-10 23:43:01 +03:00
|
|
|
if (remote->origin == REMOTE_REMOTES)
|
2015-08-10 12:35:49 +03:00
|
|
|
unlink_or_warn(git_path("remotes/%s", remote->name));
|
2008-11-10 23:43:01 +03:00
|
|
|
else if (remote->origin == REMOTE_BRANCHES)
|
2015-08-10 12:35:49 +03:00
|
|
|
unlink_or_warn(git_path("branches/%s", remote->name));
|
2017-08-30 21:00:26 +03:00
|
|
|
strbuf_release(&buf);
|
2016-02-22 14:23:30 +03:00
|
|
|
|
2008-11-10 23:43:01 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-02-01 12:34:09 +03:00
|
|
|
struct push_default_info
|
|
|
|
{
|
|
|
|
const char *old_name;
|
|
|
|
enum config_scope scope;
|
|
|
|
struct strbuf origin;
|
|
|
|
int linenr;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int config_read_push_default(const char *key, const char *value,
|
|
|
|
void *cb)
|
|
|
|
{
|
|
|
|
struct push_default_info* info = cb;
|
|
|
|
if (strcmp(key, "remote.pushdefault") ||
|
|
|
|
!value || strcmp(value, info->old_name))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
info->scope = current_config_scope();
|
|
|
|
strbuf_reset(&info->origin);
|
|
|
|
strbuf_addstr(&info->origin, current_config_name());
|
|
|
|
info->linenr = current_config_line();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void handle_push_default(const char* old_name, const char* new_name)
|
|
|
|
{
|
|
|
|
struct push_default_info push_default = {
|
|
|
|
old_name, CONFIG_SCOPE_UNKNOWN, STRBUF_INIT, -1 };
|
|
|
|
git_config(config_read_push_default, &push_default);
|
|
|
|
if (push_default.scope >= CONFIG_SCOPE_COMMAND)
|
|
|
|
; /* pass */
|
|
|
|
else if (push_default.scope >= CONFIG_SCOPE_LOCAL) {
|
|
|
|
int result = git_config_set_gently("remote.pushDefault",
|
|
|
|
new_name);
|
|
|
|
if (new_name && result && result != CONFIG_NOTHING_SET)
|
|
|
|
die(_("could not set '%s'"), "remote.pushDefault");
|
|
|
|
else if (!new_name && result && result != CONFIG_NOTHING_SET)
|
|
|
|
die(_("could not unset '%s'"), "remote.pushDefault");
|
|
|
|
} else if (push_default.scope >= CONFIG_SCOPE_SYSTEM) {
|
|
|
|
/* warn */
|
|
|
|
warning(_("The %s configuration remote.pushDefault in:\n"
|
|
|
|
"\t%s:%d\n"
|
|
|
|
"now names the non-existent remote '%s'"),
|
|
|
|
config_scope_name(push_default.scope),
|
|
|
|
push_default.origin.buf, push_default.linenr,
|
|
|
|
old_name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-03 21:26:18 +03:00
|
|
|
static int mv(int argc, const char **argv)
|
|
|
|
{
|
|
|
|
struct option options[] = {
|
|
|
|
OPT_END()
|
|
|
|
};
|
|
|
|
struct remote *oldremote, *newremote;
|
2011-09-02 04:50:33 +04:00
|
|
|
struct strbuf buf = STRBUF_INIT, buf2 = STRBUF_INIT, buf3 = STRBUF_INIT,
|
|
|
|
old_remote_context = STRBUF_INIT;
|
2018-08-01 13:19:07 +03:00
|
|
|
struct string_list remote_branches = STRING_LIST_INIT_DUP;
|
2008-11-03 21:26:18 +03:00
|
|
|
struct rename_info rename;
|
2011-09-10 23:39:23 +04:00
|
|
|
int i, refspec_updated = 0;
|
2008-11-03 21:26:18 +03:00
|
|
|
|
|
|
|
if (argc != 3)
|
2009-11-21 02:43:13 +03:00
|
|
|
usage_with_options(builtin_remote_rename_usage, options);
|
2008-11-03 21:26:18 +03:00
|
|
|
|
2018-02-14 21:59:35 +03:00
|
|
|
rename.old_name = argv[1];
|
|
|
|
rename.new_name = argv[2];
|
2008-11-03 21:26:18 +03:00
|
|
|
rename.remote_branches = &remote_branches;
|
|
|
|
|
2018-02-14 21:59:35 +03:00
|
|
|
oldremote = remote_get(rename.old_name);
|
2017-01-20 00:20:02 +03:00
|
|
|
if (!remote_is_configured(oldremote, 1))
|
2018-09-13 16:18:33 +03:00
|
|
|
die(_("No such remote: '%s'"), rename.old_name);
|
2008-11-03 21:26:18 +03:00
|
|
|
|
2018-02-14 21:59:35 +03:00
|
|
|
if (!strcmp(rename.old_name, rename.new_name) && oldremote->origin != REMOTE_CONFIG)
|
2008-11-10 23:43:01 +03:00
|
|
|
return migrate_file(oldremote);
|
|
|
|
|
2018-02-14 21:59:35 +03:00
|
|
|
newremote = remote_get(rename.new_name);
|
2017-01-20 00:20:02 +03:00
|
|
|
if (remote_is_configured(newremote, 1))
|
2018-02-14 21:59:35 +03:00
|
|
|
die(_("remote %s already exists."), rename.new_name);
|
2008-11-03 21:26:18 +03:00
|
|
|
|
2018-02-14 21:59:35 +03:00
|
|
|
strbuf_addf(&buf, "refs/heads/test:refs/remotes/%s/test", rename.new_name);
|
2008-11-03 21:26:18 +03:00
|
|
|
if (!valid_fetch_refspec(buf.buf))
|
2018-02-14 21:59:35 +03:00
|
|
|
die(_("'%s' is not a valid remote name"), rename.new_name);
|
2008-11-03 21:26:18 +03:00
|
|
|
|
|
|
|
strbuf_reset(&buf);
|
2018-02-14 21:59:35 +03:00
|
|
|
strbuf_addf(&buf, "remote.%s", rename.old_name);
|
|
|
|
strbuf_addf(&buf2, "remote.%s", rename.new_name);
|
2008-11-03 21:26:18 +03:00
|
|
|
if (git_config_rename_section(buf.buf, buf2.buf) < 1)
|
2012-04-23 16:30:26 +04:00
|
|
|
return error(_("Could not rename config section '%s' to '%s'"),
|
2008-11-03 21:26:18 +03:00
|
|
|
buf.buf, buf2.buf);
|
|
|
|
|
|
|
|
strbuf_reset(&buf);
|
2018-02-14 21:59:35 +03:00
|
|
|
strbuf_addf(&buf, "remote.%s.fetch", rename.new_name);
|
2016-02-22 14:23:36 +03:00
|
|
|
git_config_set_multivar(buf.buf, NULL, NULL, 1);
|
2018-02-14 21:59:35 +03:00
|
|
|
strbuf_addf(&old_remote_context, ":refs/remotes/%s/", rename.old_name);
|
2018-05-17 01:58:01 +03:00
|
|
|
for (i = 0; i < oldremote->fetch.raw_nr; i++) {
|
2008-11-03 21:26:18 +03:00
|
|
|
char *ptr;
|
|
|
|
|
|
|
|
strbuf_reset(&buf2);
|
2018-05-17 01:58:01 +03:00
|
|
|
strbuf_addstr(&buf2, oldremote->fetch.raw[i]);
|
2011-09-02 04:50:33 +04:00
|
|
|
ptr = strstr(buf2.buf, old_remote_context.buf);
|
2011-09-10 23:39:23 +04:00
|
|
|
if (ptr) {
|
|
|
|
refspec_updated = 1;
|
2011-09-02 04:50:33 +04:00
|
|
|
strbuf_splice(&buf2,
|
|
|
|
ptr-buf2.buf + strlen(":refs/remotes/"),
|
2018-02-14 21:59:35 +03:00
|
|
|
strlen(rename.old_name), rename.new_name,
|
|
|
|
strlen(rename.new_name));
|
2011-09-10 23:39:23 +04:00
|
|
|
} else
|
2012-05-18 20:46:01 +04:00
|
|
|
warning(_("Not updating non-default fetch refspec\n"
|
2012-04-23 16:30:26 +04:00
|
|
|
"\t%s\n"
|
|
|
|
"\tPlease update the configuration manually if necessary."),
|
2011-09-03 19:26:59 +04:00
|
|
|
buf2.buf);
|
|
|
|
|
2016-02-22 14:23:36 +03:00
|
|
|
git_config_set_multivar(buf.buf, buf2.buf, "^$", 0);
|
2008-11-03 21:26:18 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
read_branches();
|
|
|
|
for (i = 0; i < branch_list.nr; i++) {
|
|
|
|
struct string_list_item *item = branch_list.items + i;
|
|
|
|
struct branch_info *info = item->util;
|
2018-02-14 21:59:35 +03:00
|
|
|
if (info->remote_name && !strcmp(info->remote_name, rename.old_name)) {
|
2008-11-03 21:26:18 +03:00
|
|
|
strbuf_reset(&buf);
|
|
|
|
strbuf_addf(&buf, "branch.%s.remote", item->string);
|
2018-02-14 21:59:35 +03:00
|
|
|
git_config_set(buf.buf, rename.new_name);
|
2008-11-03 21:26:18 +03:00
|
|
|
}
|
2020-01-27 10:04:30 +03:00
|
|
|
if (info->push_remote_name && !strcmp(info->push_remote_name, rename.old_name)) {
|
|
|
|
strbuf_reset(&buf);
|
|
|
|
strbuf_addf(&buf, "branch.%s.pushremote", item->string);
|
|
|
|
git_config_set(buf.buf, rename.new_name);
|
|
|
|
}
|
2008-11-03 21:26:18 +03:00
|
|
|
}
|
|
|
|
|
2011-09-10 23:39:23 +04:00
|
|
|
if (!refspec_updated)
|
|
|
|
return 0;
|
|
|
|
|
2008-11-03 21:26:18 +03:00
|
|
|
/*
|
|
|
|
* First remove symrefs, then rename the rest, finally create
|
|
|
|
* the new symrefs.
|
|
|
|
*/
|
2015-05-25 21:38:43 +03:00
|
|
|
for_each_ref(read_remote_branches, &rename);
|
2008-11-03 21:26:18 +03:00
|
|
|
for (i = 0; i < remote_branches.nr; i++) {
|
|
|
|
struct string_list_item *item = remote_branches.items + i;
|
|
|
|
int flag = 0;
|
|
|
|
|
2019-12-11 21:46:37 +03:00
|
|
|
read_ref_full(item->string, RESOLVE_REF_READING, NULL, &flag);
|
2008-11-03 21:26:18 +03:00
|
|
|
if (!(flag & REF_ISSYMREF))
|
|
|
|
continue;
|
2017-11-05 11:42:06 +03:00
|
|
|
if (delete_ref(NULL, item->string, NULL, REF_NO_DEREF))
|
2012-04-23 16:30:26 +04:00
|
|
|
die(_("deleting '%s' failed"), item->string);
|
2008-11-03 21:26:18 +03:00
|
|
|
}
|
|
|
|
for (i = 0; i < remote_branches.nr; i++) {
|
|
|
|
struct string_list_item *item = remote_branches.items + i;
|
|
|
|
|
|
|
|
if (item->util)
|
|
|
|
continue;
|
|
|
|
strbuf_reset(&buf);
|
|
|
|
strbuf_addstr(&buf, item->string);
|
2018-02-14 21:59:35 +03:00
|
|
|
strbuf_splice(&buf, strlen("refs/remotes/"), strlen(rename.old_name),
|
|
|
|
rename.new_name, strlen(rename.new_name));
|
2008-11-03 21:26:18 +03:00
|
|
|
strbuf_reset(&buf2);
|
|
|
|
strbuf_addf(&buf2, "remote: renamed %s to %s",
|
|
|
|
item->string, buf.buf);
|
|
|
|
if (rename_ref(item->string, buf.buf, buf2.buf))
|
2012-04-23 16:30:26 +04:00
|
|
|
die(_("renaming '%s' failed"), item->string);
|
2008-11-03 21:26:18 +03:00
|
|
|
}
|
|
|
|
for (i = 0; i < remote_branches.nr; i++) {
|
|
|
|
struct string_list_item *item = remote_branches.items + i;
|
|
|
|
|
|
|
|
if (!item->util)
|
|
|
|
continue;
|
|
|
|
strbuf_reset(&buf);
|
|
|
|
strbuf_addstr(&buf, item->string);
|
2018-02-14 21:59:35 +03:00
|
|
|
strbuf_splice(&buf, strlen("refs/remotes/"), strlen(rename.old_name),
|
|
|
|
rename.new_name, strlen(rename.new_name));
|
2008-11-03 21:26:18 +03:00
|
|
|
strbuf_reset(&buf2);
|
|
|
|
strbuf_addstr(&buf2, item->util);
|
2018-02-14 21:59:35 +03:00
|
|
|
strbuf_splice(&buf2, strlen("refs/remotes/"), strlen(rename.old_name),
|
|
|
|
rename.new_name, strlen(rename.new_name));
|
2008-11-03 21:26:18 +03:00
|
|
|
strbuf_reset(&buf3);
|
|
|
|
strbuf_addf(&buf3, "remote: renamed %s to %s",
|
|
|
|
item->string, buf.buf);
|
|
|
|
if (create_symref(buf.buf, buf2.buf, buf3.buf))
|
2012-04-23 16:30:26 +04:00
|
|
|
die(_("creating '%s' failed"), buf.buf);
|
2008-11-03 21:26:18 +03:00
|
|
|
}
|
2018-08-01 13:19:07 +03:00
|
|
|
string_list_clear(&remote_branches, 1);
|
2020-02-01 12:34:09 +03:00
|
|
|
|
|
|
|
handle_push_default(rename.old_name, rename.new_name);
|
|
|
|
|
2008-11-03 21:26:18 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-02-29 04:45:45 +03:00
|
|
|
static int rm(int argc, const char **argv)
|
|
|
|
{
|
|
|
|
struct option options[] = {
|
|
|
|
OPT_END()
|
|
|
|
};
|
|
|
|
struct remote *remote;
|
2008-10-09 23:12:12 +04:00
|
|
|
struct strbuf buf = STRBUF_INIT;
|
2008-06-01 08:28:04 +04:00
|
|
|
struct known_remotes known_remotes = { NULL, NULL };
|
2010-07-04 23:46:19 +04:00
|
|
|
struct string_list branches = STRING_LIST_INIT_DUP;
|
|
|
|
struct string_list skipped = STRING_LIST_INIT_DUP;
|
2010-05-14 13:31:33 +04:00
|
|
|
struct branches_for_remote cb_data;
|
2009-02-03 20:51:12 +03:00
|
|
|
int i, result;
|
2008-02-29 04:45:45 +03:00
|
|
|
|
2010-05-14 13:31:33 +04:00
|
|
|
memset(&cb_data, 0, sizeof(cb_data));
|
|
|
|
cb_data.branches = &branches;
|
|
|
|
cb_data.skipped = &skipped;
|
|
|
|
cb_data.keep = &known_remotes;
|
|
|
|
|
2008-02-29 04:45:45 +03:00
|
|
|
if (argc != 2)
|
2009-11-21 02:43:13 +03:00
|
|
|
usage_with_options(builtin_remote_rm_usage, options);
|
2008-02-29 04:45:45 +03:00
|
|
|
|
|
|
|
remote = remote_get(argv[1]);
|
2017-01-20 00:20:02 +03:00
|
|
|
if (!remote_is_configured(remote, 1))
|
2018-09-13 16:18:33 +03:00
|
|
|
die(_("No such remote: '%s'"), argv[1]);
|
2008-02-29 04:45:45 +03:00
|
|
|
|
2008-06-01 08:28:04 +04:00
|
|
|
known_remotes.to_delete = remote;
|
|
|
|
for_each_remote(add_known_remote, &known_remotes);
|
|
|
|
|
2008-02-29 04:45:45 +03:00
|
|
|
read_branches();
|
|
|
|
for (i = 0; i < branch_list.nr; i++) {
|
2008-07-21 22:03:49 +04:00
|
|
|
struct string_list_item *item = branch_list.items + i;
|
2008-02-29 04:45:45 +03:00
|
|
|
struct branch_info *info = item->util;
|
2009-02-25 11:32:21 +03:00
|
|
|
if (info->remote_name && !strcmp(info->remote_name, remote->name)) {
|
2008-02-29 04:45:45 +03:00
|
|
|
const char *keys[] = { "remote", "merge", NULL }, **k;
|
|
|
|
for (k = keys; *k; k++) {
|
|
|
|
strbuf_reset(&buf);
|
|
|
|
strbuf_addf(&buf, "branch.%s.%s",
|
2008-07-21 22:03:49 +04:00
|
|
|
item->string, *k);
|
2017-02-18 03:23:41 +03:00
|
|
|
result = git_config_set_gently(buf.buf, NULL);
|
|
|
|
if (result && result != CONFIG_NOTHING_SET)
|
|
|
|
die(_("could not unset '%s'"), buf.buf);
|
2008-02-29 04:45:45 +03:00
|
|
|
}
|
|
|
|
}
|
2020-01-27 10:04:30 +03:00
|
|
|
if (info->push_remote_name && !strcmp(info->push_remote_name, remote->name)) {
|
|
|
|
strbuf_reset(&buf);
|
|
|
|
strbuf_addf(&buf, "branch.%s.pushremote", item->string);
|
|
|
|
result = git_config_set_gently(buf.buf, NULL);
|
|
|
|
if (result && result != CONFIG_NOTHING_SET)
|
|
|
|
die(_("could not unset '%s'"), buf.buf);
|
|
|
|
}
|
2008-02-29 04:45:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We cannot just pass a function to for_each_ref() which deletes
|
|
|
|
* the branches one by one, since for_each_ref() relies on cached
|
|
|
|
* refs, which are invalidated when deleting a branch.
|
|
|
|
*/
|
2008-06-01 08:28:04 +04:00
|
|
|
cb_data.remote = remote;
|
2015-05-25 21:38:41 +03:00
|
|
|
result = for_each_ref(add_branch_for_removal, &cb_data);
|
2008-02-29 04:45:45 +03:00
|
|
|
strbuf_release(&buf);
|
|
|
|
|
2009-02-03 20:51:12 +03:00
|
|
|
if (!result)
|
2017-11-05 11:42:06 +03:00
|
|
|
result = delete_refs("remote: remove", &branches, REF_NO_DEREF);
|
2015-05-25 21:38:42 +03:00
|
|
|
string_list_clear(&branches, 0);
|
2008-02-29 04:45:45 +03:00
|
|
|
|
2009-02-04 19:06:07 +03:00
|
|
|
if (skipped.nr) {
|
2012-04-23 16:30:26 +04:00
|
|
|
fprintf_ln(stderr,
|
|
|
|
Q_("Note: A branch outside the refs/remotes/ hierarchy was not removed;\n"
|
|
|
|
"to delete it, use:",
|
|
|
|
"Note: Some branches outside the refs/remotes/ hierarchy were not removed;\n"
|
|
|
|
"to delete them, use:",
|
|
|
|
skipped.nr));
|
2009-02-04 19:06:07 +03:00
|
|
|
for (i = 0; i < skipped.nr; i++)
|
|
|
|
fprintf(stderr, " git branch -d %s\n",
|
|
|
|
skipped.items[i].string);
|
|
|
|
}
|
|
|
|
string_list_clear(&skipped, 0);
|
|
|
|
|
2014-05-23 14:28:43 +04:00
|
|
|
if (!result) {
|
|
|
|
strbuf_addf(&buf, "remote.%s", remote->name);
|
|
|
|
if (git_config_rename_section(buf.buf, NULL) < 1)
|
|
|
|
return error(_("Could not remove config section '%s'"), buf.buf);
|
2020-02-01 12:34:09 +03:00
|
|
|
|
|
|
|
handle_push_default(remote->name, NULL);
|
2014-05-23 14:28:43 +04:00
|
|
|
}
|
|
|
|
|
2009-02-03 20:51:12 +03:00
|
|
|
return result;
|
2008-02-29 04:45:45 +03:00
|
|
|
}
|
|
|
|
|
2009-06-18 21:28:43 +04:00
|
|
|
static void clear_push_info(void *util, const char *string)
|
2008-02-29 04:45:45 +03:00
|
|
|
{
|
2009-02-25 11:32:28 +03:00
|
|
|
struct push_info *info = util;
|
|
|
|
free(info->dest);
|
|
|
|
free(info);
|
|
|
|
}
|
2008-02-29 04:45:45 +03:00
|
|
|
|
2009-02-25 11:32:19 +03:00
|
|
|
static void free_remote_ref_states(struct ref_states *states)
|
|
|
|
{
|
2018-02-14 21:59:35 +03:00
|
|
|
string_list_clear(&states->new_refs, 0);
|
2009-12-01 02:57:27 +03:00
|
|
|
string_list_clear(&states->stale, 1);
|
2009-02-25 11:32:19 +03:00
|
|
|
string_list_clear(&states->tracked, 0);
|
2009-02-25 11:32:24 +03:00
|
|
|
string_list_clear(&states->heads, 0);
|
2009-02-25 11:32:28 +03:00
|
|
|
string_list_clear_func(&states->push, clear_push_info);
|
2009-02-25 11:32:19 +03:00
|
|
|
}
|
2008-02-29 04:45:45 +03:00
|
|
|
|
2009-02-25 11:32:22 +03:00
|
|
|
static int append_ref_to_tracked_list(const char *refname,
|
2015-05-25 21:38:43 +03:00
|
|
|
const struct object_id *oid, int flags, void *cb_data)
|
2009-02-25 11:32:22 +03:00
|
|
|
{
|
|
|
|
struct ref_states *states = cb_data;
|
2018-05-17 01:57:49 +03:00
|
|
|
struct refspec_item refspec;
|
2009-02-25 11:32:22 +03:00
|
|
|
|
2009-02-25 11:32:23 +03:00
|
|
|
if (flags & REF_ISSYMREF)
|
|
|
|
return 0;
|
|
|
|
|
2009-02-25 11:32:22 +03:00
|
|
|
memset(&refspec, 0, sizeof(refspec));
|
|
|
|
refspec.dst = (char *)refname;
|
|
|
|
if (!remote_find_tracking(states->remote, &refspec))
|
2010-06-26 03:41:38 +04:00
|
|
|
string_list_append(&states->tracked, abbrev_branch(refspec.src));
|
2009-02-25 11:32:22 +03:00
|
|
|
|
|
|
|
return 0;
|
2008-02-29 04:45:45 +03:00
|
|
|
}
|
|
|
|
|
2008-06-10 18:51:21 +04:00
|
|
|
static int get_remote_ref_states(const char *name,
|
|
|
|
struct ref_states *states,
|
|
|
|
int query)
|
|
|
|
{
|
|
|
|
struct transport *transport;
|
2009-02-25 11:32:21 +03:00
|
|
|
const struct ref *remote_refs;
|
2008-06-10 18:51:21 +04:00
|
|
|
|
|
|
|
states->remote = remote_get(name);
|
|
|
|
if (!states->remote)
|
2018-09-13 16:18:33 +03:00
|
|
|
return error(_("No such remote: '%s'"), name);
|
2008-06-10 18:51:21 +04:00
|
|
|
|
|
|
|
read_branches();
|
|
|
|
|
|
|
|
if (query) {
|
2009-06-26 01:21:35 +04:00
|
|
|
transport = transport_get(states->remote, states->remote->url_nr > 0 ?
|
2008-06-10 18:51:21 +04:00
|
|
|
states->remote->url[0] : NULL);
|
2018-03-15 20:31:23 +03:00
|
|
|
remote_refs = transport_get_remote_refs(transport, NULL);
|
2008-06-10 18:51:21 +04:00
|
|
|
transport_disconnect(transport);
|
|
|
|
|
2009-02-25 11:32:27 +03:00
|
|
|
states->queried = 1;
|
2009-02-25 11:32:24 +03:00
|
|
|
if (query & GET_REF_STATES)
|
|
|
|
get_ref_states(remote_refs, states);
|
|
|
|
if (query & GET_HEAD_NAMES)
|
|
|
|
get_head_names(remote_refs, states);
|
2009-02-25 11:32:28 +03:00
|
|
|
if (query & GET_PUSH_REF_STATES)
|
|
|
|
get_push_ref_states(remote_refs, states);
|
2009-02-25 11:32:23 +03:00
|
|
|
} else {
|
2015-05-25 21:38:43 +03:00
|
|
|
for_each_ref(append_ref_to_tracked_list, states);
|
2014-11-25 11:02:35 +03:00
|
|
|
string_list_sort(&states->tracked);
|
2009-02-25 11:32:28 +03:00
|
|
|
get_push_ref_states_noquery(states);
|
2008-06-10 18:51:21 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-02-25 11:32:27 +03:00
|
|
|
struct show_info {
|
|
|
|
struct string_list *list;
|
|
|
|
struct ref_states *states;
|
2009-02-25 11:32:28 +03:00
|
|
|
int width, width2;
|
2009-02-25 11:32:27 +03:00
|
|
|
int any_rebase;
|
|
|
|
};
|
|
|
|
|
2009-06-18 21:28:43 +04:00
|
|
|
static int add_remote_to_show_info(struct string_list_item *item, void *cb_data)
|
2008-06-11 02:54:49 +04:00
|
|
|
{
|
2009-02-25 11:32:27 +03:00
|
|
|
struct show_info *info = cb_data;
|
|
|
|
int n = strlen(item->string);
|
|
|
|
if (n > info->width)
|
|
|
|
info->width = n;
|
2010-06-26 03:41:35 +04:00
|
|
|
string_list_insert(info->list, item->string);
|
2009-02-25 11:32:27 +03:00
|
|
|
return 0;
|
|
|
|
}
|
2008-06-11 02:54:49 +04:00
|
|
|
|
2009-06-18 21:28:43 +04:00
|
|
|
static int show_remote_info_item(struct string_list_item *item, void *cb_data)
|
2009-02-25 11:32:27 +03:00
|
|
|
{
|
|
|
|
struct show_info *info = cb_data;
|
|
|
|
struct ref_states *states = info->states;
|
|
|
|
const char *name = item->string;
|
|
|
|
|
|
|
|
if (states->queried) {
|
|
|
|
const char *fmt = "%s";
|
|
|
|
const char *arg = "";
|
2018-02-14 21:59:35 +03:00
|
|
|
if (string_list_has_string(&states->new_refs, name)) {
|
2012-04-23 16:30:26 +04:00
|
|
|
fmt = _(" new (next fetch will store in remotes/%s)");
|
2009-02-25 11:32:27 +03:00
|
|
|
arg = states->remote->name;
|
|
|
|
} else if (string_list_has_string(&states->tracked, name))
|
2012-04-23 16:30:26 +04:00
|
|
|
arg = _(" tracked");
|
2009-02-25 11:32:27 +03:00
|
|
|
else if (string_list_has_string(&states->stale, name))
|
2012-04-23 16:30:26 +04:00
|
|
|
arg = _(" stale (use 'git remote prune' to remove)");
|
2009-02-25 11:32:27 +03:00
|
|
|
else
|
2012-04-23 16:30:26 +04:00
|
|
|
arg = _(" ???");
|
2009-02-25 11:32:27 +03:00
|
|
|
printf(" %-*s", info->width, name);
|
|
|
|
printf(fmt, arg);
|
|
|
|
printf("\n");
|
|
|
|
} else
|
|
|
|
printf(" %s\n", name);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-06-18 21:28:43 +04:00
|
|
|
static int add_local_to_show_info(struct string_list_item *branch_item, void *cb_data)
|
2009-02-25 11:32:27 +03:00
|
|
|
{
|
|
|
|
struct show_info *show_info = cb_data;
|
|
|
|
struct ref_states *states = show_info->states;
|
|
|
|
struct branch_info *branch_info = branch_item->util;
|
|
|
|
struct string_list_item *item;
|
|
|
|
int n;
|
|
|
|
|
|
|
|
if (!branch_info->merge.nr || !branch_info->remote_name ||
|
|
|
|
strcmp(states->remote->name, branch_info->remote_name))
|
|
|
|
return 0;
|
|
|
|
if ((n = strlen(branch_item->string)) > show_info->width)
|
|
|
|
show_info->width = n;
|
2020-01-27 10:04:27 +03:00
|
|
|
if (branch_info->rebase >= REBASE_TRUE)
|
2009-02-25 11:32:27 +03:00
|
|
|
show_info->any_rebase = 1;
|
|
|
|
|
2010-06-26 03:41:35 +04:00
|
|
|
item = string_list_insert(show_info->list, branch_item->string);
|
2009-02-25 11:32:27 +03:00
|
|
|
item->util = branch_info;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-06-18 21:28:43 +04:00
|
|
|
static int show_local_info_item(struct string_list_item *item, void *cb_data)
|
2009-02-25 11:32:27 +03:00
|
|
|
{
|
|
|
|
struct show_info *show_info = cb_data;
|
|
|
|
struct branch_info *branch_info = item->util;
|
|
|
|
struct string_list *merge = &branch_info->merge;
|
2016-06-17 23:21:22 +03:00
|
|
|
int width = show_info->width + 4;
|
2009-02-25 11:32:27 +03:00
|
|
|
int i;
|
|
|
|
|
2020-01-27 10:04:27 +03:00
|
|
|
if (branch_info->rebase >= REBASE_TRUE && branch_info->merge.nr > 1) {
|
2012-04-23 16:30:26 +04:00
|
|
|
error(_("invalid branch.%s.merge; cannot rebase onto > 1 branch"),
|
2009-02-25 11:32:27 +03:00
|
|
|
item->string);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
printf(" %-*s ", show_info->width, item->string);
|
2020-01-27 10:04:27 +03:00
|
|
|
if (branch_info->rebase >= REBASE_TRUE) {
|
2018-04-25 15:29:38 +03:00
|
|
|
const char *msg;
|
2020-01-27 10:04:27 +03:00
|
|
|
if (branch_info->rebase == REBASE_INTERACTIVE)
|
2018-04-25 15:29:38 +03:00
|
|
|
msg = _("rebases interactively onto remote %s");
|
|
|
|
else if (branch_info->rebase == REBASE_MERGES)
|
|
|
|
msg = _("rebases interactively (with merges) onto "
|
|
|
|
"remote %s");
|
|
|
|
else
|
|
|
|
msg = _("rebases onto remote %s");
|
|
|
|
printf_ln(msg, merge->items[0].string);
|
2009-02-25 11:32:27 +03:00
|
|
|
return 0;
|
|
|
|
} else if (show_info->any_rebase) {
|
2012-04-23 16:30:26 +04:00
|
|
|
printf_ln(_(" merges with remote %s"), merge->items[0].string);
|
2016-06-17 23:21:22 +03:00
|
|
|
width++;
|
2009-02-25 11:32:27 +03:00
|
|
|
} else {
|
2012-04-23 16:30:26 +04:00
|
|
|
printf_ln(_("merges with remote %s"), merge->items[0].string);
|
2009-02-25 11:32:27 +03:00
|
|
|
}
|
|
|
|
for (i = 1; i < merge->nr; i++)
|
2016-06-17 23:21:22 +03:00
|
|
|
printf(_("%-*s and with remote %s\n"), width, "",
|
2009-02-25 11:32:27 +03:00
|
|
|
merge->items[i].string);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2008-06-11 02:54:49 +04:00
|
|
|
|
2009-06-18 21:28:43 +04:00
|
|
|
static int add_push_to_show_info(struct string_list_item *push_item, void *cb_data)
|
2009-02-25 11:32:28 +03:00
|
|
|
{
|
|
|
|
struct show_info *show_info = cb_data;
|
|
|
|
struct push_info *push_info = push_item->util;
|
|
|
|
struct string_list_item *item;
|
|
|
|
int n;
|
|
|
|
if ((n = strlen(push_item->string)) > show_info->width)
|
|
|
|
show_info->width = n;
|
|
|
|
if ((n = strlen(push_info->dest)) > show_info->width2)
|
|
|
|
show_info->width2 = n;
|
2010-06-26 03:41:38 +04:00
|
|
|
item = string_list_append(show_info->list, push_item->string);
|
2009-02-25 11:32:28 +03:00
|
|
|
item->util = push_item->util;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-03-22 11:59:20 +03:00
|
|
|
/*
|
|
|
|
* Sorting comparison for a string list that has push_info
|
|
|
|
* structs in its util field
|
|
|
|
*/
|
|
|
|
static int cmp_string_with_push(const void *va, const void *vb)
|
|
|
|
{
|
|
|
|
const struct string_list_item *a = va;
|
|
|
|
const struct string_list_item *b = vb;
|
|
|
|
const struct push_info *a_push = a->util;
|
|
|
|
const struct push_info *b_push = b->util;
|
|
|
|
int cmp = strcmp(a->string, b->string);
|
|
|
|
return cmp ? cmp : strcmp(a_push->dest, b_push->dest);
|
|
|
|
}
|
|
|
|
|
2009-06-18 21:28:43 +04:00
|
|
|
static int show_push_info_item(struct string_list_item *item, void *cb_data)
|
2009-02-25 11:32:28 +03:00
|
|
|
{
|
|
|
|
struct show_info *show_info = cb_data;
|
|
|
|
struct push_info *push_info = item->util;
|
2012-04-23 16:30:26 +04:00
|
|
|
const char *src = item->string, *status = NULL;
|
2009-02-25 11:32:28 +03:00
|
|
|
|
|
|
|
switch (push_info->status) {
|
|
|
|
case PUSH_STATUS_CREATE:
|
2012-04-23 16:30:26 +04:00
|
|
|
status = _("create");
|
2009-02-25 11:32:28 +03:00
|
|
|
break;
|
|
|
|
case PUSH_STATUS_DELETE:
|
2012-04-23 16:30:26 +04:00
|
|
|
status = _("delete");
|
|
|
|
src = _("(none)");
|
2009-02-25 11:32:28 +03:00
|
|
|
break;
|
|
|
|
case PUSH_STATUS_UPTODATE:
|
2012-04-23 16:30:26 +04:00
|
|
|
status = _("up to date");
|
2009-02-25 11:32:28 +03:00
|
|
|
break;
|
|
|
|
case PUSH_STATUS_FASTFORWARD:
|
2012-04-23 16:30:26 +04:00
|
|
|
status = _("fast-forwardable");
|
2009-02-25 11:32:28 +03:00
|
|
|
break;
|
|
|
|
case PUSH_STATUS_OUTOFDATE:
|
2012-04-23 16:30:26 +04:00
|
|
|
status = _("local out of date");
|
2009-02-25 11:32:28 +03:00
|
|
|
break;
|
|
|
|
case PUSH_STATUS_NOTQUERIED:
|
|
|
|
break;
|
|
|
|
}
|
2012-04-23 16:30:26 +04:00
|
|
|
if (status) {
|
|
|
|
if (push_info->forced)
|
|
|
|
printf_ln(_(" %-*s forces to %-*s (%s)"), show_info->width, src,
|
|
|
|
show_info->width2, push_info->dest, status);
|
|
|
|
else
|
|
|
|
printf_ln(_(" %-*s pushes to %-*s (%s)"), show_info->width, src,
|
|
|
|
show_info->width2, push_info->dest, status);
|
|
|
|
} else {
|
|
|
|
if (push_info->forced)
|
|
|
|
printf_ln(_(" %-*s forces to %s"), show_info->width, src,
|
|
|
|
push_info->dest);
|
|
|
|
else
|
|
|
|
printf_ln(_(" %-*s pushes to %s"), show_info->width, src,
|
|
|
|
push_info->dest);
|
|
|
|
}
|
2008-06-11 02:54:49 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-10-30 09:33:02 +04:00
|
|
|
static int get_one_entry(struct remote *remote, void *priv)
|
|
|
|
{
|
|
|
|
struct string_list *list = priv;
|
|
|
|
struct strbuf url_buf = STRBUF_INIT;
|
|
|
|
const char **url;
|
|
|
|
int i, url_nr;
|
|
|
|
|
|
|
|
if (remote->url_nr > 0) {
|
|
|
|
strbuf_addf(&url_buf, "%s (fetch)", remote->url[0]);
|
|
|
|
string_list_append(list, remote->name)->util =
|
|
|
|
strbuf_detach(&url_buf, NULL);
|
|
|
|
} else
|
|
|
|
string_list_append(list, remote->name)->util = NULL;
|
|
|
|
if (remote->pushurl_nr) {
|
|
|
|
url = remote->pushurl;
|
|
|
|
url_nr = remote->pushurl_nr;
|
|
|
|
} else {
|
|
|
|
url = remote->url;
|
|
|
|
url_nr = remote->url_nr;
|
|
|
|
}
|
|
|
|
for (i = 0; i < url_nr; i++)
|
|
|
|
{
|
|
|
|
strbuf_addf(&url_buf, "%s (push)", url[i]);
|
|
|
|
string_list_append(list, remote->name)->util =
|
|
|
|
strbuf_detach(&url_buf, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int show_all(void)
|
|
|
|
{
|
|
|
|
struct string_list list = STRING_LIST_INIT_NODUP;
|
|
|
|
int result;
|
|
|
|
|
|
|
|
list.strdup_strings = 1;
|
|
|
|
result = for_each_remote(get_one_entry, &list);
|
|
|
|
|
|
|
|
if (!result) {
|
|
|
|
int i;
|
|
|
|
|
2014-11-25 11:02:35 +03:00
|
|
|
string_list_sort(&list);
|
2013-10-30 09:33:02 +04:00
|
|
|
for (i = 0; i < list.nr; i++) {
|
|
|
|
struct string_list_item *item = list.items + i;
|
|
|
|
if (verbose)
|
|
|
|
printf("%s\t%s\n", item->string,
|
|
|
|
item->util ? (const char *)item->util : "");
|
|
|
|
else {
|
|
|
|
if (i && !strcmp((item - 1)->string, item->string))
|
|
|
|
continue;
|
|
|
|
printf("%s\n", item->string);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
string_list_clear(&list, 1);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2008-06-10 18:51:21 +04:00
|
|
|
static int show(int argc, const char **argv)
|
2008-02-29 04:45:45 +03:00
|
|
|
{
|
2009-02-25 11:32:24 +03:00
|
|
|
int no_query = 0, result = 0, query_flag = 0;
|
2008-02-29 04:45:45 +03:00
|
|
|
struct option options[] = {
|
2013-08-03 15:51:19 +04:00
|
|
|
OPT_BOOL('n', NULL, &no_query, N_("do not query remotes")),
|
2008-02-29 04:45:45 +03:00
|
|
|
OPT_END()
|
|
|
|
};
|
|
|
|
struct ref_states states;
|
2010-07-04 23:46:19 +04:00
|
|
|
struct string_list info_list = STRING_LIST_INIT_NODUP;
|
2009-02-25 11:32:27 +03:00
|
|
|
struct show_info info;
|
2008-02-29 04:45:45 +03:00
|
|
|
|
2009-11-21 02:43:13 +03:00
|
|
|
argc = parse_options(argc, argv, NULL, options, builtin_remote_show_usage,
|
2009-05-23 22:53:12 +04:00
|
|
|
0);
|
2008-02-29 04:45:45 +03:00
|
|
|
|
2008-06-10 18:51:21 +04:00
|
|
|
if (argc < 1)
|
|
|
|
return show_all();
|
2008-02-29 04:45:45 +03:00
|
|
|
|
2009-02-25 11:32:24 +03:00
|
|
|
if (!no_query)
|
2009-02-25 11:32:28 +03:00
|
|
|
query_flag = (GET_REF_STATES | GET_HEAD_NAMES | GET_PUSH_REF_STATES);
|
2009-02-25 11:32:24 +03:00
|
|
|
|
2008-02-29 04:45:45 +03:00
|
|
|
memset(&states, 0, sizeof(states));
|
2009-02-25 11:32:27 +03:00
|
|
|
memset(&info, 0, sizeof(info));
|
|
|
|
info.states = &states;
|
|
|
|
info.list = &info_list;
|
2008-02-29 04:45:45 +03:00
|
|
|
for (; argc; argc--, argv++) {
|
2008-06-10 18:51:08 +04:00
|
|
|
int i;
|
2009-06-13 20:29:10 +04:00
|
|
|
const char **url;
|
|
|
|
int url_nr;
|
2008-02-29 04:45:45 +03:00
|
|
|
|
2009-02-25 11:32:24 +03:00
|
|
|
get_remote_ref_states(*argv, &states, query_flag);
|
2008-02-29 04:45:45 +03:00
|
|
|
|
2012-04-23 16:30:26 +04:00
|
|
|
printf_ln(_("* remote %s"), *argv);
|
|
|
|
printf_ln(_(" Fetch URL: %s"), states.remote->url_nr > 0 ?
|
|
|
|
states.remote->url[0] : _("(no URL)"));
|
2009-06-13 20:29:10 +04:00
|
|
|
if (states.remote->pushurl_nr) {
|
|
|
|
url = states.remote->pushurl;
|
|
|
|
url_nr = states.remote->pushurl_nr;
|
|
|
|
} else {
|
|
|
|
url = states.remote->url;
|
|
|
|
url_nr = states.remote->url_nr;
|
|
|
|
}
|
2011-08-26 01:46:52 +04:00
|
|
|
for (i = 0; i < url_nr; i++)
|
C style: use standard style for "TRANSLATORS" comments
Change all the "TRANSLATORS: [...]" comments in the C code to use the
regular Git coding style, and amend the style guide so that the
example there uses that style.
This custom style was necessary back in 2010 when the gettext support
was initially added, and was subsequently documented in commit
cbcfd4e3ea ("i18n: mention "TRANSLATORS:" marker in
Documentation/CodingGuidelines", 2014-04-18).
GNU xgettext hasn't had the parsing limitation that necessitated this
exception for almost 3 years. Since its 0.19 release on 2014-06-02
it's been able to recognize TRANSLATOR comments in the standard Git
comment syntax[1].
Usually we'd like to keep compatibility with software that's that
young, but in this case literally the only person who needs to be
using a gettext newer than 3 years old is Jiang Xin (the only person
who runs & commits "make pot" results), so I think in this case we can
make an exception.
This xgettext parsing feature was added after a thread on the Git
mailing list[2] which continued on the bug-gettext[3] list, but we
never subsequently changed our style & styleguide, do so.
There are already longstanding changes in git that use the standard
comment style & have their TRANSLATORS comments extracted properly
without getting the literal "*"'s mixed up in the text, as would
happen before xgettext 0.19.
Commit 7ff2683253 ("builtin-am: implement -i/--interactive",
2015-08-04) added one such comment, which in commit df0617bfa7 ("l10n:
git.pot: v2.6.0 round 1 (123 new, 41 removed)", 2015-09-05) got picked
up in the po/git.pot file with the right format, showing that Jiang
already runs a modern xgettext.
The xgettext parser does not handle the sort of non-standard comment
style that I'm amending here in sequencer.c, but that isn't standard
Git comment syntax anyway. With this change to sequencer.c & "make
pot" the comment in the pot file is now correct:
#. TRANSLATORS: %s will be "revert", "cherry-pick" or
-#. * "rebase -i".
+#. "rebase -i".
1. http://git.savannah.gnu.org/cgit/gettext.git/commit/?id=10af7fe6bd
2. <2ce9ec406501d112e032c8208417f8100bed04c6.1397712142.git.worldhello.net@gmail.com>
(https://public-inbox.org/git/2ce9ec406501d112e032c8208417f8100bed04c6.1397712142.git.worldhello.net@gmail.com/)
3. https://lists.gnu.org/archive/html/bug-gettext/2014-04/msg00016.html
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Acked-by: Jiang Xin <worldhello.net@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2017-05-12 00:20:12 +03:00
|
|
|
/*
|
|
|
|
* TRANSLATORS: the colon ':' should align
|
|
|
|
* with the one in " Fetch URL: %s"
|
|
|
|
* translation.
|
|
|
|
*/
|
2012-04-23 16:30:26 +04:00
|
|
|
printf_ln(_(" Push URL: %s"), url[i]);
|
2009-06-13 20:29:10 +04:00
|
|
|
if (!i)
|
2016-06-17 23:21:21 +03:00
|
|
|
printf_ln(_(" Push URL: %s"), _("(no URL)"));
|
2009-02-25 11:32:24 +03:00
|
|
|
if (no_query)
|
2016-06-17 23:21:21 +03:00
|
|
|
printf_ln(_(" HEAD branch: %s"), _("(not queried)"));
|
2009-02-25 11:32:24 +03:00
|
|
|
else if (!states.heads.nr)
|
2016-06-17 23:21:21 +03:00
|
|
|
printf_ln(_(" HEAD branch: %s"), _("(unknown)"));
|
2009-02-25 11:32:24 +03:00
|
|
|
else if (states.heads.nr == 1)
|
2012-04-23 16:30:26 +04:00
|
|
|
printf_ln(_(" HEAD branch: %s"), states.heads.items[0].string);
|
2009-02-25 11:32:24 +03:00
|
|
|
else {
|
2012-04-23 16:30:26 +04:00
|
|
|
printf(_(" HEAD branch (remote HEAD is ambiguous,"
|
|
|
|
" may be one of the following):\n"));
|
2009-02-25 11:32:24 +03:00
|
|
|
for (i = 0; i < states.heads.nr; i++)
|
|
|
|
printf(" %s\n", states.heads.items[i].string);
|
2008-02-29 04:45:45 +03:00
|
|
|
}
|
|
|
|
|
2009-02-25 11:32:27 +03:00
|
|
|
/* remote branch info */
|
|
|
|
info.width = 0;
|
2018-02-14 21:59:35 +03:00
|
|
|
for_each_string_list(&states.new_refs, add_remote_to_show_info, &info);
|
2010-06-26 03:41:34 +04:00
|
|
|
for_each_string_list(&states.tracked, add_remote_to_show_info, &info);
|
|
|
|
for_each_string_list(&states.stale, add_remote_to_show_info, &info);
|
2009-02-25 11:32:27 +03:00
|
|
|
if (info.list->nr)
|
2012-04-23 16:30:26 +04:00
|
|
|
printf_ln(Q_(" Remote branch:%s",
|
|
|
|
" Remote branches:%s",
|
|
|
|
info.list->nr),
|
|
|
|
no_query ? _(" (status not queried)") : "");
|
2010-06-26 03:41:34 +04:00
|
|
|
for_each_string_list(info.list, show_remote_info_item, &info);
|
2009-02-25 11:32:27 +03:00
|
|
|
string_list_clear(info.list, 0);
|
|
|
|
|
|
|
|
/* git pull info */
|
|
|
|
info.width = 0;
|
|
|
|
info.any_rebase = 0;
|
2010-06-26 03:41:34 +04:00
|
|
|
for_each_string_list(&branch_list, add_local_to_show_info, &info);
|
2009-02-25 11:32:27 +03:00
|
|
|
if (info.list->nr)
|
2012-04-23 16:30:26 +04:00
|
|
|
printf_ln(Q_(" Local branch configured for 'git pull':",
|
|
|
|
" Local branches configured for 'git pull':",
|
|
|
|
info.list->nr));
|
2010-06-26 03:41:34 +04:00
|
|
|
for_each_string_list(info.list, show_local_info_item, &info);
|
2009-02-25 11:32:27 +03:00
|
|
|
string_list_clear(info.list, 0);
|
|
|
|
|
|
|
|
/* git push info */
|
2009-02-25 11:32:28 +03:00
|
|
|
if (states.remote->mirror)
|
2012-04-23 16:30:26 +04:00
|
|
|
printf_ln(_(" Local refs will be mirrored by 'git push'"));
|
2009-02-25 11:32:28 +03:00
|
|
|
|
|
|
|
info.width = info.width2 = 0;
|
2010-06-26 03:41:34 +04:00
|
|
|
for_each_string_list(&states.push, add_push_to_show_info, &info);
|
2016-09-29 18:27:31 +03:00
|
|
|
QSORT(info.list->items, info.list->nr, cmp_string_with_push);
|
2009-02-25 11:32:28 +03:00
|
|
|
if (info.list->nr)
|
2012-04-23 16:30:26 +04:00
|
|
|
printf_ln(Q_(" Local ref configured for 'git push'%s:",
|
|
|
|
" Local refs configured for 'git push'%s:",
|
|
|
|
info.list->nr),
|
|
|
|
no_query ? _(" (status not queried)") : "");
|
2010-06-26 03:41:34 +04:00
|
|
|
for_each_string_list(info.list, show_push_info_item, &info);
|
2009-02-25 11:32:28 +03:00
|
|
|
string_list_clear(info.list, 0);
|
2008-06-10 18:51:21 +04:00
|
|
|
|
2009-02-25 11:32:19 +03:00
|
|
|
free_remote_ref_states(&states);
|
2008-06-10 18:51:21 +04:00
|
|
|
}
|
2008-02-29 04:45:45 +03:00
|
|
|
|
2008-06-10 18:51:21 +04:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2009-02-25 11:32:25 +03:00
|
|
|
static int set_head(int argc, const char **argv)
|
|
|
|
{
|
|
|
|
int i, opt_a = 0, opt_d = 0, result = 0;
|
|
|
|
struct strbuf buf = STRBUF_INIT, buf2 = STRBUF_INIT;
|
|
|
|
char *head_name = NULL;
|
|
|
|
|
|
|
|
struct option options[] = {
|
2013-08-03 15:51:19 +04:00
|
|
|
OPT_BOOL('a', "auto", &opt_a,
|
|
|
|
N_("set refs/remotes/<name>/HEAD according to remote")),
|
|
|
|
OPT_BOOL('d', "delete", &opt_d,
|
|
|
|
N_("delete refs/remotes/<name>/HEAD")),
|
2009-02-25 11:32:25 +03:00
|
|
|
OPT_END()
|
|
|
|
};
|
2009-11-21 02:43:13 +03:00
|
|
|
argc = parse_options(argc, argv, NULL, options, builtin_remote_sethead_usage,
|
2009-05-23 22:53:12 +04:00
|
|
|
0);
|
2009-02-25 11:32:25 +03:00
|
|
|
if (argc)
|
|
|
|
strbuf_addf(&buf, "refs/remotes/%s/HEAD", argv[0]);
|
|
|
|
|
|
|
|
if (!opt_a && !opt_d && argc == 2) {
|
|
|
|
head_name = xstrdup(argv[1]);
|
|
|
|
} else if (opt_a && !opt_d && argc == 1) {
|
|
|
|
struct ref_states states;
|
|
|
|
memset(&states, 0, sizeof(states));
|
|
|
|
get_remote_ref_states(argv[0], &states, GET_HEAD_NAMES);
|
|
|
|
if (!states.heads.nr)
|
2012-04-23 16:30:26 +04:00
|
|
|
result |= error(_("Cannot determine remote HEAD"));
|
2009-02-25 11:32:25 +03:00
|
|
|
else if (states.heads.nr > 1) {
|
2012-04-23 16:30:26 +04:00
|
|
|
result |= error(_("Multiple remote HEAD branches. "
|
|
|
|
"Please choose one explicitly with:"));
|
2009-02-25 11:32:25 +03:00
|
|
|
for (i = 0; i < states.heads.nr; i++)
|
|
|
|
fprintf(stderr, " git remote set-head %s %s\n",
|
|
|
|
argv[0], states.heads.items[i].string);
|
|
|
|
} else
|
|
|
|
head_name = xstrdup(states.heads.items[0].string);
|
|
|
|
free_remote_ref_states(&states);
|
|
|
|
} else if (opt_d && !opt_a && argc == 1) {
|
2017-11-05 11:42:06 +03:00
|
|
|
if (delete_ref(NULL, buf.buf, NULL, REF_NO_DEREF))
|
2012-04-23 16:30:26 +04:00
|
|
|
result |= error(_("Could not delete %s"), buf.buf);
|
2009-02-25 11:32:25 +03:00
|
|
|
} else
|
2009-11-21 02:43:13 +03:00
|
|
|
usage_with_options(builtin_remote_sethead_usage, options);
|
2009-02-25 11:32:25 +03:00
|
|
|
|
|
|
|
if (head_name) {
|
|
|
|
strbuf_addf(&buf2, "refs/remotes/%s/%s", argv[0], head_name);
|
|
|
|
/* make sure it's valid */
|
2011-11-13 14:22:14 +04:00
|
|
|
if (!ref_exists(buf2.buf))
|
2012-04-23 16:30:26 +04:00
|
|
|
result |= error(_("Not a valid ref: %s"), buf2.buf);
|
2009-02-25 11:32:25 +03:00
|
|
|
else if (create_symref(buf.buf, buf2.buf, "remote set-head"))
|
2012-04-23 16:30:26 +04:00
|
|
|
result |= error(_("Could not setup %s"), buf.buf);
|
2009-02-25 11:32:25 +03:00
|
|
|
if (opt_a)
|
|
|
|
printf("%s/HEAD set to %s\n", argv[0], head_name);
|
|
|
|
free(head_name);
|
2008-06-10 18:51:21 +04:00
|
|
|
}
|
|
|
|
|
2009-02-25 11:32:25 +03:00
|
|
|
strbuf_release(&buf);
|
|
|
|
strbuf_release(&buf2);
|
2008-06-10 18:51:21 +04:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2009-04-03 13:02:37 +04:00
|
|
|
static int prune_remote(const char *remote, int dry_run)
|
|
|
|
{
|
2014-11-25 11:02:34 +03:00
|
|
|
int result = 0;
|
2009-04-03 13:02:37 +04:00
|
|
|
struct ref_states states;
|
2014-11-25 11:02:33 +03:00
|
|
|
struct string_list refs_to_prune = STRING_LIST_INIT_NODUP;
|
2014-11-25 11:02:34 +03:00
|
|
|
struct string_list_item *item;
|
2009-04-03 13:02:37 +04:00
|
|
|
const char *dangling_msg = dry_run
|
2012-04-23 16:30:26 +04:00
|
|
|
? _(" %s will become dangling!")
|
|
|
|
: _(" %s has become dangling!");
|
2008-06-10 18:51:21 +04:00
|
|
|
|
2009-04-03 13:02:37 +04:00
|
|
|
memset(&states, 0, sizeof(states));
|
|
|
|
get_remote_ref_states(remote, &states, GET_REF_STATES);
|
|
|
|
|
2014-11-25 11:02:29 +03:00
|
|
|
if (!states.stale.nr) {
|
|
|
|
free_remote_ref_states(&states);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
printf_ln(_("Pruning %s"), remote);
|
|
|
|
printf_ln(_("URL: %s"),
|
|
|
|
states.remote->url_nr
|
|
|
|
? states.remote->url[0]
|
|
|
|
: _("(no URL)"));
|
|
|
|
|
2014-11-25 11:02:34 +03:00
|
|
|
for_each_string_list_item(item, &states.stale)
|
|
|
|
string_list_append(&refs_to_prune, item->util);
|
2014-11-25 11:02:35 +03:00
|
|
|
string_list_sort(&refs_to_prune);
|
2014-11-25 11:02:30 +03:00
|
|
|
|
2015-06-22 17:02:58 +03:00
|
|
|
if (!dry_run)
|
2017-05-22 17:17:38 +03:00
|
|
|
result |= delete_refs("remote: prune", &refs_to_prune, 0);
|
2008-06-10 18:51:35 +04:00
|
|
|
|
2014-11-25 11:02:34 +03:00
|
|
|
for_each_string_list_item(item, &states.stale) {
|
|
|
|
const char *refname = item->util;
|
2008-06-10 18:51:35 +04:00
|
|
|
|
2012-04-23 16:30:26 +04:00
|
|
|
if (dry_run)
|
|
|
|
printf_ln(_(" * [would prune] %s"),
|
|
|
|
abbrev_ref(refname, "refs/remotes/"));
|
|
|
|
else
|
|
|
|
printf_ln(_(" * [pruned] %s"),
|
|
|
|
abbrev_ref(refname, "refs/remotes/"));
|
2008-02-29 04:45:45 +03:00
|
|
|
}
|
|
|
|
|
2014-11-25 11:02:33 +03:00
|
|
|
warn_dangling_symrefs(stdout, dangling_msg, &refs_to_prune);
|
2014-05-23 14:30:25 +04:00
|
|
|
|
2014-11-25 11:02:33 +03:00
|
|
|
string_list_clear(&refs_to_prune, 0);
|
2009-04-03 13:02:37 +04:00
|
|
|
free_remote_ref_states(&states);
|
2008-02-29 04:45:45 +03:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2013-10-30 09:33:02 +04:00
|
|
|
static int prune(int argc, const char **argv)
|
|
|
|
{
|
|
|
|
int dry_run = 0, result = 0;
|
|
|
|
struct option options[] = {
|
|
|
|
OPT__DRY_RUN(&dry_run, N_("dry run")),
|
|
|
|
OPT_END()
|
|
|
|
};
|
|
|
|
|
|
|
|
argc = parse_options(argc, argv, NULL, options, builtin_remote_prune_usage,
|
|
|
|
0);
|
|
|
|
|
|
|
|
if (argc < 1)
|
|
|
|
usage_with_options(builtin_remote_prune_usage, options);
|
|
|
|
|
|
|
|
for (; argc; argc--, argv++)
|
|
|
|
result |= prune_remote(*argv, dry_run);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2009-11-10 11:21:32 +03:00
|
|
|
static int get_remote_default(const char *key, const char *value, void *priv)
|
2008-02-29 04:45:45 +03:00
|
|
|
{
|
2009-11-10 11:21:32 +03:00
|
|
|
if (strcmp(key, "remotes.default") == 0) {
|
|
|
|
int *found = priv;
|
|
|
|
*found = 1;
|
2008-03-04 14:23:53 +03:00
|
|
|
}
|
2008-02-29 04:45:45 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int update(int argc, const char **argv)
|
|
|
|
{
|
2013-10-30 09:33:04 +04:00
|
|
|
int i, prune = -1;
|
2009-04-03 13:03:44 +04:00
|
|
|
struct option options[] = {
|
2013-08-03 15:51:19 +04:00
|
|
|
OPT_BOOL('p', "prune", &prune,
|
|
|
|
N_("prune remotes after fetching")),
|
2009-04-03 13:03:44 +04:00
|
|
|
OPT_END()
|
|
|
|
};
|
2013-10-30 09:33:03 +04:00
|
|
|
struct argv_array fetch_argv = ARGV_ARRAY_INIT;
|
2009-11-10 11:21:32 +03:00
|
|
|
int default_defined = 0;
|
2013-10-30 09:33:03 +04:00
|
|
|
int retval;
|
2008-02-29 04:45:45 +03:00
|
|
|
|
2009-11-21 02:43:13 +03:00
|
|
|
argc = parse_options(argc, argv, NULL, options, builtin_remote_update_usage,
|
2009-04-03 13:03:44 +04:00
|
|
|
PARSE_OPT_KEEP_ARGV0);
|
2008-02-29 04:45:45 +03:00
|
|
|
|
2013-10-30 09:33:03 +04:00
|
|
|
argv_array_push(&fetch_argv, "fetch");
|
2008-03-04 14:23:53 +03:00
|
|
|
|
2013-10-30 09:33:04 +04:00
|
|
|
if (prune != -1)
|
|
|
|
argv_array_push(&fetch_argv, prune ? "--prune" : "--no-prune");
|
2009-11-10 11:21:32 +03:00
|
|
|
if (verbose)
|
2013-10-30 09:33:03 +04:00
|
|
|
argv_array_push(&fetch_argv, "-v");
|
|
|
|
argv_array_push(&fetch_argv, "--multiple");
|
2009-12-31 12:43:17 +03:00
|
|
|
if (argc < 2)
|
2013-10-30 09:33:03 +04:00
|
|
|
argv_array_push(&fetch_argv, "default");
|
2009-12-31 12:43:17 +03:00
|
|
|
for (i = 1; i < argc; i++)
|
2013-10-30 09:33:03 +04:00
|
|
|
argv_array_push(&fetch_argv, argv[i]);
|
2008-03-04 14:23:53 +03:00
|
|
|
|
2013-10-30 09:33:03 +04:00
|
|
|
if (strcmp(fetch_argv.argv[fetch_argv.argc-1], "default") == 0) {
|
2009-11-10 11:21:32 +03:00
|
|
|
git_config(get_remote_default, &default_defined);
|
2013-10-30 09:33:03 +04:00
|
|
|
if (!default_defined) {
|
|
|
|
argv_array_pop(&fetch_argv);
|
|
|
|
argv_array_push(&fetch_argv, "--all");
|
|
|
|
}
|
2009-04-03 13:03:44 +04:00
|
|
|
}
|
2008-03-04 14:23:53 +03:00
|
|
|
|
2013-10-30 09:33:03 +04:00
|
|
|
retval = run_command_v_opt(fetch_argv.argv, RUN_GIT_CMD);
|
|
|
|
argv_array_clear(&fetch_argv);
|
|
|
|
return retval;
|
2008-02-29 04:45:45 +03:00
|
|
|
}
|
|
|
|
|
2019-05-10 00:31:46 +03:00
|
|
|
static int remove_all_fetch_refspecs(const char *key)
|
2010-05-19 22:38:50 +04:00
|
|
|
{
|
2016-02-22 14:23:35 +03:00
|
|
|
return git_config_set_multivar_gently(key, NULL, NULL, 1);
|
2010-05-19 22:38:50 +04:00
|
|
|
}
|
|
|
|
|
2016-02-22 14:23:29 +03:00
|
|
|
static void add_branches(struct remote *remote, const char **branches,
|
|
|
|
const char *key)
|
2010-05-19 22:38:50 +04:00
|
|
|
{
|
|
|
|
const char *remotename = remote->name;
|
|
|
|
int mirror = remote->mirror;
|
|
|
|
struct strbuf refspec = STRBUF_INIT;
|
|
|
|
|
|
|
|
for (; *branches; branches++)
|
2016-02-22 14:23:29 +03:00
|
|
|
add_branch(key, *branches, remotename, mirror, &refspec);
|
2010-05-19 22:38:50 +04:00
|
|
|
|
|
|
|
strbuf_release(&refspec);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int set_remote_branches(const char *remotename, const char **branches,
|
|
|
|
int add_mode)
|
|
|
|
{
|
|
|
|
struct strbuf key = STRBUF_INIT;
|
|
|
|
struct remote *remote;
|
|
|
|
|
|
|
|
strbuf_addf(&key, "remote.%s.fetch", remotename);
|
|
|
|
|
|
|
|
remote = remote_get(remotename);
|
2017-01-20 00:20:02 +03:00
|
|
|
if (!remote_is_configured(remote, 1))
|
2016-02-16 12:47:50 +03:00
|
|
|
die(_("No such remote '%s'"), remotename);
|
2010-05-19 22:38:50 +04:00
|
|
|
|
2019-05-10 00:31:46 +03:00
|
|
|
if (!add_mode && remove_all_fetch_refspecs(key.buf)) {
|
2010-05-19 22:38:50 +04:00
|
|
|
strbuf_release(&key);
|
|
|
|
return 1;
|
|
|
|
}
|
2016-02-22 14:23:29 +03:00
|
|
|
add_branches(remote, branches, key.buf);
|
2010-05-19 22:38:50 +04:00
|
|
|
|
|
|
|
strbuf_release(&key);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int set_branches(int argc, const char **argv)
|
|
|
|
{
|
|
|
|
int add_mode = 0;
|
|
|
|
struct option options[] = {
|
2013-08-03 15:51:19 +04:00
|
|
|
OPT_BOOL('\0', "add", &add_mode, N_("add branch")),
|
2010-05-19 22:38:50 +04:00
|
|
|
OPT_END()
|
|
|
|
};
|
|
|
|
|
|
|
|
argc = parse_options(argc, argv, NULL, options,
|
|
|
|
builtin_remote_setbranches_usage, 0);
|
|
|
|
if (argc == 0) {
|
2012-04-23 16:30:26 +04:00
|
|
|
error(_("no remote specified"));
|
2011-11-07 09:12:59 +04:00
|
|
|
usage_with_options(builtin_remote_setbranches_usage, options);
|
2010-05-19 22:38:50 +04:00
|
|
|
}
|
|
|
|
argv[argc] = NULL;
|
|
|
|
|
|
|
|
return set_remote_branches(argv[0], argv + 1, add_mode);
|
|
|
|
}
|
|
|
|
|
2015-09-16 04:53:47 +03:00
|
|
|
static int get_url(int argc, const char **argv)
|
|
|
|
{
|
|
|
|
int i, push_mode = 0, all_mode = 0;
|
|
|
|
const char *remotename = NULL;
|
|
|
|
struct remote *remote;
|
|
|
|
const char **url;
|
|
|
|
int url_nr;
|
|
|
|
struct option options[] = {
|
|
|
|
OPT_BOOL('\0', "push", &push_mode,
|
|
|
|
N_("query push URLs rather than fetch URLs")),
|
|
|
|
OPT_BOOL('\0', "all", &all_mode,
|
|
|
|
N_("return all URLs")),
|
|
|
|
OPT_END()
|
|
|
|
};
|
|
|
|
argc = parse_options(argc, argv, NULL, options, builtin_remote_geturl_usage, 0);
|
|
|
|
|
|
|
|
if (argc != 1)
|
|
|
|
usage_with_options(builtin_remote_geturl_usage, options);
|
|
|
|
|
|
|
|
remotename = argv[0];
|
|
|
|
|
|
|
|
remote = remote_get(remotename);
|
2017-01-20 00:20:02 +03:00
|
|
|
if (!remote_is_configured(remote, 1))
|
2016-02-16 12:47:50 +03:00
|
|
|
die(_("No such remote '%s'"), remotename);
|
2015-09-16 04:53:47 +03:00
|
|
|
|
|
|
|
url_nr = 0;
|
|
|
|
if (push_mode) {
|
|
|
|
url = remote->pushurl;
|
|
|
|
url_nr = remote->pushurl_nr;
|
|
|
|
}
|
|
|
|
/* else fetch mode */
|
|
|
|
|
|
|
|
/* Use the fetch URL when no push URLs were found or requested. */
|
|
|
|
if (!url_nr) {
|
|
|
|
url = remote->url;
|
|
|
|
url_nr = remote->url_nr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!url_nr)
|
|
|
|
die(_("no URLs configured for remote '%s'"), remotename);
|
|
|
|
|
|
|
|
if (all_mode) {
|
|
|
|
for (i = 0; i < url_nr; i++)
|
|
|
|
printf_ln("%s", url[i]);
|
|
|
|
} else {
|
|
|
|
printf_ln("%s", *url);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-01-18 20:18:02 +03:00
|
|
|
static int set_url(int argc, const char **argv)
|
|
|
|
{
|
|
|
|
int i, push_mode = 0, add_mode = 0, delete_mode = 0;
|
|
|
|
int matches = 0, negative_matches = 0;
|
|
|
|
const char *remotename = NULL;
|
|
|
|
const char *newurl = NULL;
|
|
|
|
const char *oldurl = NULL;
|
|
|
|
struct remote *remote;
|
|
|
|
regex_t old_regex;
|
|
|
|
const char **urlset;
|
|
|
|
int urlset_nr;
|
|
|
|
struct strbuf name_buf = STRBUF_INIT;
|
|
|
|
struct option options[] = {
|
2013-08-03 15:51:19 +04:00
|
|
|
OPT_BOOL('\0', "push", &push_mode,
|
|
|
|
N_("manipulate push URLs")),
|
|
|
|
OPT_BOOL('\0', "add", &add_mode,
|
|
|
|
N_("add URL")),
|
|
|
|
OPT_BOOL('\0', "delete", &delete_mode,
|
2012-08-20 16:32:35 +04:00
|
|
|
N_("delete URLs")),
|
2010-01-18 20:18:02 +03:00
|
|
|
OPT_END()
|
|
|
|
};
|
2011-11-07 07:36:57 +04:00
|
|
|
argc = parse_options(argc, argv, NULL, options, builtin_remote_seturl_usage,
|
2010-01-18 20:18:02 +03:00
|
|
|
PARSE_OPT_KEEP_ARGV0);
|
|
|
|
|
|
|
|
if (add_mode && delete_mode)
|
2012-04-23 16:30:26 +04:00
|
|
|
die(_("--add --delete doesn't make sense"));
|
2010-01-18 20:18:02 +03:00
|
|
|
|
|
|
|
if (argc < 3 || argc > 4 || ((add_mode || delete_mode) && argc != 3))
|
|
|
|
usage_with_options(builtin_remote_seturl_usage, options);
|
|
|
|
|
|
|
|
remotename = argv[1];
|
|
|
|
newurl = argv[2];
|
|
|
|
if (argc > 3)
|
|
|
|
oldurl = argv[3];
|
|
|
|
|
|
|
|
if (delete_mode)
|
|
|
|
oldurl = newurl;
|
|
|
|
|
|
|
|
remote = remote_get(remotename);
|
2017-01-20 00:20:02 +03:00
|
|
|
if (!remote_is_configured(remote, 1))
|
2016-02-16 12:47:50 +03:00
|
|
|
die(_("No such remote '%s'"), remotename);
|
2010-01-18 20:18:02 +03:00
|
|
|
|
|
|
|
if (push_mode) {
|
|
|
|
strbuf_addf(&name_buf, "remote.%s.pushurl", remotename);
|
|
|
|
urlset = remote->pushurl;
|
|
|
|
urlset_nr = remote->pushurl_nr;
|
|
|
|
} else {
|
|
|
|
strbuf_addf(&name_buf, "remote.%s.url", remotename);
|
|
|
|
urlset = remote->url;
|
|
|
|
urlset_nr = remote->url_nr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Special cases that add new entry. */
|
|
|
|
if ((!oldurl && !delete_mode) || add_mode) {
|
|
|
|
if (add_mode)
|
|
|
|
git_config_set_multivar(name_buf.buf, newurl,
|
2016-02-22 14:23:28 +03:00
|
|
|
"^$", 0);
|
2010-01-18 20:18:02 +03:00
|
|
|
else
|
|
|
|
git_config_set(name_buf.buf, newurl);
|
2017-08-30 21:00:27 +03:00
|
|
|
goto out;
|
2010-01-18 20:18:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Old URL specified. Demand that one matches. */
|
|
|
|
if (regcomp(&old_regex, oldurl, REG_EXTENDED))
|
2012-04-23 16:30:26 +04:00
|
|
|
die(_("Invalid old URL pattern: %s"), oldurl);
|
2010-01-18 20:18:02 +03:00
|
|
|
|
|
|
|
for (i = 0; i < urlset_nr; i++)
|
|
|
|
if (!regexec(&old_regex, urlset[i], 0, NULL, 0))
|
|
|
|
matches++;
|
|
|
|
else
|
|
|
|
negative_matches++;
|
|
|
|
if (!delete_mode && !matches)
|
2012-04-23 16:30:26 +04:00
|
|
|
die(_("No such URL found: %s"), oldurl);
|
2010-01-18 20:18:02 +03:00
|
|
|
if (delete_mode && !negative_matches && !push_mode)
|
2012-04-23 16:30:26 +04:00
|
|
|
die(_("Will not delete all non-push URLs"));
|
2010-01-18 20:18:02 +03:00
|
|
|
|
|
|
|
regfree(&old_regex);
|
|
|
|
|
|
|
|
if (!delete_mode)
|
|
|
|
git_config_set_multivar(name_buf.buf, newurl, oldurl, 0);
|
|
|
|
else
|
|
|
|
git_config_set_multivar(name_buf.buf, NULL, oldurl, 1);
|
2017-08-30 21:00:27 +03:00
|
|
|
out:
|
|
|
|
strbuf_release(&name_buf);
|
2010-01-18 20:18:02 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-02-29 04:45:45 +03:00
|
|
|
int cmd_remote(int argc, const char **argv, const char *prefix)
|
|
|
|
{
|
|
|
|
struct option options[] = {
|
2012-08-20 16:32:35 +04:00
|
|
|
OPT__VERBOSE(&verbose, N_("be verbose; must be placed before a subcommand")),
|
2008-02-29 04:45:45 +03:00
|
|
|
OPT_END()
|
|
|
|
};
|
|
|
|
int result;
|
|
|
|
|
2009-05-23 22:53:12 +04:00
|
|
|
argc = parse_options(argc, argv, prefix, options, builtin_remote_usage,
|
2008-02-29 04:45:45 +03:00
|
|
|
PARSE_OPT_STOP_AT_NON_OPTION);
|
|
|
|
|
|
|
|
if (argc < 1)
|
|
|
|
result = show_all();
|
|
|
|
else if (!strcmp(argv[0], "add"))
|
|
|
|
result = add(argc, argv);
|
2008-11-03 21:26:18 +03:00
|
|
|
else if (!strcmp(argv[0], "rename"))
|
|
|
|
result = mv(argc, argv);
|
2012-09-06 16:25:23 +04:00
|
|
|
else if (!strcmp(argv[0], "rm") || !strcmp(argv[0], "remove"))
|
2008-02-29 04:45:45 +03:00
|
|
|
result = rm(argc, argv);
|
2009-02-25 11:32:25 +03:00
|
|
|
else if (!strcmp(argv[0], "set-head"))
|
|
|
|
result = set_head(argc, argv);
|
2010-05-19 22:38:50 +04:00
|
|
|
else if (!strcmp(argv[0], "set-branches"))
|
|
|
|
result = set_branches(argc, argv);
|
2015-09-16 04:53:47 +03:00
|
|
|
else if (!strcmp(argv[0], "get-url"))
|
|
|
|
result = get_url(argc, argv);
|
2010-01-18 20:18:02 +03:00
|
|
|
else if (!strcmp(argv[0], "set-url"))
|
|
|
|
result = set_url(argc, argv);
|
2008-02-29 04:45:45 +03:00
|
|
|
else if (!strcmp(argv[0], "show"))
|
2008-06-10 18:51:21 +04:00
|
|
|
result = show(argc, argv);
|
2008-02-29 04:45:45 +03:00
|
|
|
else if (!strcmp(argv[0], "prune"))
|
2008-06-10 18:51:21 +04:00
|
|
|
result = prune(argc, argv);
|
2008-02-29 04:45:45 +03:00
|
|
|
else if (!strcmp(argv[0], "update"))
|
|
|
|
result = update(argc, argv);
|
|
|
|
else {
|
2012-04-23 16:30:26 +04:00
|
|
|
error(_("Unknown subcommand: %s"), argv[0]);
|
2008-02-29 04:45:45 +03:00
|
|
|
usage_with_options(builtin_remote_usage, options);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result ? 1 : 0;
|
|
|
|
}
|