Stephen Boyd | c2e86ad | 2011-03-22 00:51:05 -0700 | [diff] [blame] | 1 | #include "builtin.h" |
Brandon Williams | b2141fc | 2017-06-14 11:07:36 -0700 | [diff] [blame] | 2 | #include "config.h" |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 3 | #include "parse-options.h" |
| 4 | #include "transport.h" |
| 5 | #include "remote.h" |
Johannes Schindelin | c455c87 | 2008-07-21 19:03:49 +0100 | [diff] [blame] | 6 | #include "string-list.h" |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 7 | #include "strbuf.h" |
| 8 | #include "run-command.h" |
| 9 | #include "refs.h" |
Stefan Beller | cbd53a2 | 2018-05-15 16:42:15 -0700 | [diff] [blame^] | 10 | #include "object-store.h" |
Michael Haggerty | 8607590 | 2013-10-30 06:33:03 +0100 | [diff] [blame] | 11 | #include "argv-array.h" |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 12 | |
| 13 | static const char * const builtin_remote_usage[] = { |
Nguyễn Thái Ngọc Duy | fbbae14 | 2012-08-20 19:32:35 +0700 | [diff] [blame] | 14 | N_("git remote [-v | --verbose]"), |
Alex Henrie | 9c9b4f2 | 2015-01-13 00:44:47 -0700 | [diff] [blame] | 15 | N_("git remote add [-t <branch>] [-m <master>] [-f] [--tags | --no-tags] [--mirror=<fetch|push>] <name> <url>"), |
Nguyễn Thái Ngọc Duy | fbbae14 | 2012-08-20 19:32:35 +0700 | [diff] [blame] | 16 | N_("git remote rename <old> <new>"), |
Junio C Hamano | 9058560 | 2012-09-12 14:21:58 -0700 | [diff] [blame] | 17 | N_("git remote remove <name>"), |
Alex Henrie | 9c9b4f2 | 2015-01-13 00:44:47 -0700 | [diff] [blame] | 18 | N_("git remote set-head <name> (-a | --auto | -d | --delete | <branch>)"), |
Nguyễn Thái Ngọc Duy | fbbae14 | 2012-08-20 19:32:35 +0700 | [diff] [blame] | 19 | N_("git remote [-v | --verbose] show [-n] <name>"), |
| 20 | N_("git remote prune [-n | --dry-run] <name>"), |
| 21 | N_("git remote [-v | --verbose] update [-p | --prune] [(<group> | <remote>)...]"), |
| 22 | N_("git remote set-branches [--add] <name> <branch>..."), |
Ben Boeckel | 96f78d3 | 2015-09-15 21:53:47 -0400 | [diff] [blame] | 23 | N_("git remote get-url [--push] [--all] <name>"), |
Nguyễn Thái Ngọc Duy | fbbae14 | 2012-08-20 19:32:35 +0700 | [diff] [blame] | 24 | N_("git remote set-url [--push] <name> <newurl> [<oldurl>]"), |
| 25 | N_("git remote set-url --add <name> <newurl>"), |
| 26 | N_("git remote set-url --delete <name> <url>"), |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 27 | NULL |
| 28 | }; |
| 29 | |
Tim Henigan | 4504107 | 2009-11-20 18:43:13 -0500 | [diff] [blame] | 30 | static const char * const builtin_remote_add_usage[] = { |
Nguyễn Thái Ngọc Duy | fbbae14 | 2012-08-20 19:32:35 +0700 | [diff] [blame] | 31 | N_("git remote add [<options>] <name> <url>"), |
Tim Henigan | 4504107 | 2009-11-20 18:43:13 -0500 | [diff] [blame] | 32 | NULL |
| 33 | }; |
| 34 | |
| 35 | static const char * const builtin_remote_rename_usage[] = { |
Nguyễn Thái Ngọc Duy | fbbae14 | 2012-08-20 19:32:35 +0700 | [diff] [blame] | 36 | N_("git remote rename <old> <new>"), |
Tim Henigan | 4504107 | 2009-11-20 18:43:13 -0500 | [diff] [blame] | 37 | NULL |
| 38 | }; |
| 39 | |
| 40 | static const char * const builtin_remote_rm_usage[] = { |
Junio C Hamano | 9058560 | 2012-09-12 14:21:58 -0700 | [diff] [blame] | 41 | N_("git remote remove <name>"), |
Tim Henigan | 4504107 | 2009-11-20 18:43:13 -0500 | [diff] [blame] | 42 | NULL |
| 43 | }; |
| 44 | |
| 45 | static const char * const builtin_remote_sethead_usage[] = { |
Philip Oakley | e49c8f3 | 2013-09-21 16:51:46 +0100 | [diff] [blame] | 46 | N_("git remote set-head <name> (-a | --auto | -d | --delete | <branch>)"), |
Tim Henigan | 4504107 | 2009-11-20 18:43:13 -0500 | [diff] [blame] | 47 | NULL |
| 48 | }; |
| 49 | |
Jonathan Nieder | 3d8b694 | 2010-05-19 13:38:50 -0500 | [diff] [blame] | 50 | static const char * const builtin_remote_setbranches_usage[] = { |
Nguyễn Thái Ngọc Duy | fbbae14 | 2012-08-20 19:32:35 +0700 | [diff] [blame] | 51 | N_("git remote set-branches <name> <branch>..."), |
| 52 | N_("git remote set-branches --add <name> <branch>..."), |
Jonathan Nieder | 3d8b694 | 2010-05-19 13:38:50 -0500 | [diff] [blame] | 53 | NULL |
| 54 | }; |
| 55 | |
Tim Henigan | 4504107 | 2009-11-20 18:43:13 -0500 | [diff] [blame] | 56 | static const char * const builtin_remote_show_usage[] = { |
Nguyễn Thái Ngọc Duy | fbbae14 | 2012-08-20 19:32:35 +0700 | [diff] [blame] | 57 | N_("git remote show [<options>] <name>"), |
Tim Henigan | 4504107 | 2009-11-20 18:43:13 -0500 | [diff] [blame] | 58 | NULL |
| 59 | }; |
| 60 | |
| 61 | static const char * const builtin_remote_prune_usage[] = { |
Nguyễn Thái Ngọc Duy | fbbae14 | 2012-08-20 19:32:35 +0700 | [diff] [blame] | 62 | N_("git remote prune [<options>] <name>"), |
Tim Henigan | 4504107 | 2009-11-20 18:43:13 -0500 | [diff] [blame] | 63 | NULL |
| 64 | }; |
| 65 | |
| 66 | static const char * const builtin_remote_update_usage[] = { |
Nguyễn Thái Ngọc Duy | fbbae14 | 2012-08-20 19:32:35 +0700 | [diff] [blame] | 67 | N_("git remote update [<options>] [<group> | <remote>]..."), |
Tim Henigan | 4504107 | 2009-11-20 18:43:13 -0500 | [diff] [blame] | 68 | NULL |
| 69 | }; |
| 70 | |
Ben Boeckel | 96f78d3 | 2015-09-15 21:53:47 -0400 | [diff] [blame] | 71 | static const char * const builtin_remote_geturl_usage[] = { |
| 72 | N_("git remote get-url [--push] [--all] <name>"), |
| 73 | NULL |
| 74 | }; |
| 75 | |
Ilari Liusvaara | 433f2be | 2010-01-18 19:18:02 +0200 | [diff] [blame] | 76 | static const char * const builtin_remote_seturl_usage[] = { |
Nguyễn Thái Ngọc Duy | fbbae14 | 2012-08-20 19:32:35 +0700 | [diff] [blame] | 77 | N_("git remote set-url [--push] <name> <newurl> [<oldurl>]"), |
| 78 | N_("git remote set-url --add <name> <newurl>"), |
| 79 | N_("git remote set-url --delete <name> <url>"), |
Ilari Liusvaara | 433f2be | 2010-01-18 19:18:02 +0200 | [diff] [blame] | 80 | NULL |
| 81 | }; |
| 82 | |
Jay Soffian | e61e0cc | 2009-02-25 03:32:24 -0500 | [diff] [blame] | 83 | #define GET_REF_STATES (1<<0) |
| 84 | #define GET_HEAD_NAMES (1<<1) |
Jay Soffian | e5dcbfd | 2009-02-25 03:32:28 -0500 | [diff] [blame] | 85 | #define GET_PUSH_REF_STATES (1<<2) |
Jay Soffian | e61e0cc | 2009-02-25 03:32:24 -0500 | [diff] [blame] | 86 | |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 87 | static int verbose; |
| 88 | |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 89 | static int fetch_remote(const char *name) |
| 90 | { |
Cheng Renquan | dbbd56f | 2008-11-18 19:04:02 +0800 | [diff] [blame] | 91 | const char *argv[] = { "fetch", name, NULL, NULL }; |
| 92 | if (verbose) { |
| 93 | argv[1] = "-v"; |
| 94 | argv[2] = name; |
| 95 | } |
Nguyễn Thái Ngọc Duy | bb16d5d | 2012-04-23 19:30:26 +0700 | [diff] [blame] | 96 | printf_ln(_("Updating %s"), name); |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 97 | if (run_command_v_opt(argv, RUN_GIT_CMD)) |
Nguyễn Thái Ngọc Duy | bb16d5d | 2012-04-23 19:30:26 +0700 | [diff] [blame] | 98 | return error(_("Could not fetch %s"), name); |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 99 | return 0; |
| 100 | } |
| 101 | |
Samuel Tardieu | 111fb85 | 2010-04-20 01:31:31 +0200 | [diff] [blame] | 102 | enum { |
| 103 | TAGS_UNSET = 0, |
| 104 | TAGS_DEFAULT = 1, |
| 105 | TAGS_SET = 2 |
| 106 | }; |
| 107 | |
Jeff King | a9f5a35 | 2011-03-30 15:53:19 -0400 | [diff] [blame] | 108 | #define MIRROR_NONE 0 |
| 109 | #define MIRROR_FETCH 1 |
| 110 | #define MIRROR_PUSH 2 |
| 111 | #define MIRROR_BOTH (MIRROR_FETCH|MIRROR_PUSH) |
| 112 | |
Patrick Steinhardt | ab5e4b6 | 2016-02-22 12:23:29 +0100 | [diff] [blame] | 113 | static void add_branch(const char *key, const char *branchname, |
| 114 | const char *remotename, int mirror, struct strbuf *tmp) |
Jonathan Nieder | 3d8b694 | 2010-05-19 13:38:50 -0500 | [diff] [blame] | 115 | { |
| 116 | strbuf_reset(tmp); |
| 117 | strbuf_addch(tmp, '+'); |
| 118 | if (mirror) |
| 119 | strbuf_addf(tmp, "refs/%s:refs/%s", |
| 120 | branchname, branchname); |
| 121 | else |
| 122 | strbuf_addf(tmp, "refs/heads/%s:refs/remotes/%s/%s", |
| 123 | branchname, remotename, branchname); |
Patrick Steinhardt | 3d18064 | 2016-02-22 12:23:36 +0100 | [diff] [blame] | 124 | git_config_set_multivar(key, tmp->buf, "^$", 0); |
Jonathan Nieder | 3d8b694 | 2010-05-19 13:38:50 -0500 | [diff] [blame] | 125 | } |
| 126 | |
Jeff King | 0990248 | 2011-03-30 15:53:39 -0400 | [diff] [blame] | 127 | static const char mirror_advice[] = |
Nguyễn Thái Ngọc Duy | bb16d5d | 2012-04-23 19:30:26 +0700 | [diff] [blame] | 128 | N_("--mirror is dangerous and deprecated; please\n" |
| 129 | "\t use --mirror=fetch or --mirror=push instead"); |
Jeff King | 0990248 | 2011-03-30 15:53:39 -0400 | [diff] [blame] | 130 | |
Jeff King | a9f5a35 | 2011-03-30 15:53:19 -0400 | [diff] [blame] | 131 | static int parse_mirror_opt(const struct option *opt, const char *arg, int not) |
| 132 | { |
| 133 | unsigned *mirror = opt->value; |
| 134 | if (not) |
| 135 | *mirror = MIRROR_NONE; |
Jeff King | 0990248 | 2011-03-30 15:53:39 -0400 | [diff] [blame] | 136 | else if (!arg) { |
Nguyễn Thái Ngọc Duy | bb16d5d | 2012-04-23 19:30:26 +0700 | [diff] [blame] | 137 | warning("%s", _(mirror_advice)); |
Jeff King | a9f5a35 | 2011-03-30 15:53:19 -0400 | [diff] [blame] | 138 | *mirror = MIRROR_BOTH; |
Jeff King | 0990248 | 2011-03-30 15:53:39 -0400 | [diff] [blame] | 139 | } |
Jeff King | a9f5a35 | 2011-03-30 15:53:19 -0400 | [diff] [blame] | 140 | else if (!strcmp(arg, "fetch")) |
| 141 | *mirror = MIRROR_FETCH; |
| 142 | else if (!strcmp(arg, "push")) |
| 143 | *mirror = MIRROR_PUSH; |
| 144 | else |
Nguyễn Thái Ngọc Duy | bb16d5d | 2012-04-23 19:30:26 +0700 | [diff] [blame] | 145 | return error(_("unknown mirror argument: %s"), arg); |
Jeff King | a9f5a35 | 2011-03-30 15:53:19 -0400 | [diff] [blame] | 146 | return 0; |
| 147 | } |
| 148 | |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 149 | static int add(int argc, const char **argv) |
| 150 | { |
Jeff King | a9f5a35 | 2011-03-30 15:53:19 -0400 | [diff] [blame] | 151 | int fetch = 0, fetch_tags = TAGS_DEFAULT; |
| 152 | unsigned mirror = MIRROR_NONE; |
Thiago Farina | 183113a | 2010-07-04 16:46:19 -0300 | [diff] [blame] | 153 | struct string_list track = STRING_LIST_INIT_NODUP; |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 154 | const char *master = NULL; |
| 155 | struct remote *remote; |
Brandon Casey | f285a2d | 2008-10-09 14:12:12 -0500 | [diff] [blame] | 156 | struct strbuf buf = STRBUF_INIT, buf2 = STRBUF_INIT; |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 157 | const char *name, *url; |
| 158 | int i; |
| 159 | |
| 160 | struct option options[] = { |
Stefan Beller | d5d09d4 | 2013-08-03 13:51:19 +0200 | [diff] [blame] | 161 | OPT_BOOL('f', "fetch", &fetch, N_("fetch the remote branches")), |
Samuel Tardieu | 111fb85 | 2010-04-20 01:31:31 +0200 | [diff] [blame] | 162 | OPT_SET_INT(0, "tags", &fetch_tags, |
Nguyễn Thái Ngọc Duy | fbbae14 | 2012-08-20 19:32:35 +0700 | [diff] [blame] | 163 | N_("import all tags and associated objects when fetching"), |
Samuel Tardieu | 111fb85 | 2010-04-20 01:31:31 +0200 | [diff] [blame] | 164 | TAGS_SET), |
| 165 | OPT_SET_INT(0, NULL, &fetch_tags, |
Nguyễn Thái Ngọc Duy | fbbae14 | 2012-08-20 19:32:35 +0700 | [diff] [blame] | 166 | N_("or do not fetch any tag at all (--no-tags)"), TAGS_UNSET), |
| 167 | OPT_STRING_LIST('t', "track", &track, N_("branch"), |
| 168 | N_("branch(es) to track")), |
| 169 | OPT_STRING('m', "master", &master, N_("branch"), N_("master branch")), |
| 170 | { OPTION_CALLBACK, 0, "mirror", &mirror, N_("push|fetch"), |
| 171 | N_("set up remote as a mirror to push to or fetch from"), |
Nguyễn Thái Ngọc Duy | ebc4a04 | 2018-02-09 18:02:12 +0700 | [diff] [blame] | 172 | PARSE_OPT_OPTARG | PARSE_OPT_COMP_ARG, parse_mirror_opt }, |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 173 | OPT_END() |
| 174 | }; |
| 175 | |
Tim Henigan | 4504107 | 2009-11-20 18:43:13 -0500 | [diff] [blame] | 176 | argc = parse_options(argc, argv, NULL, options, builtin_remote_add_usage, |
Stephen Boyd | 3778292 | 2009-05-23 11:53:12 -0700 | [diff] [blame] | 177 | 0); |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 178 | |
Thomas Rast | 2d2e3d2 | 2013-04-24 15:54:36 +0200 | [diff] [blame] | 179 | if (argc != 2) |
Tim Henigan | 4504107 | 2009-11-20 18:43:13 -0500 | [diff] [blame] | 180 | usage_with_options(builtin_remote_add_usage, options); |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 181 | |
Jeff King | 13fc2c1 | 2011-03-30 15:52:52 -0400 | [diff] [blame] | 182 | if (mirror && master) |
Nguyễn Thái Ngọc Duy | bb16d5d | 2012-04-23 19:30:26 +0700 | [diff] [blame] | 183 | die(_("specifying a master branch makes no sense with --mirror")); |
Jeff King | 3eafdc9 | 2011-05-26 11:11:00 -0400 | [diff] [blame] | 184 | if (mirror && !(mirror & MIRROR_FETCH) && track.nr) |
Nguyễn Thái Ngọc Duy | bb16d5d | 2012-04-23 19:30:26 +0700 | [diff] [blame] | 185 | die(_("specifying branches to track makes sense only with fetch mirrors")); |
Jeff King | 13fc2c1 | 2011-03-30 15:52:52 -0400 | [diff] [blame] | 186 | |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 187 | name = argv[0]; |
| 188 | url = argv[1]; |
| 189 | |
| 190 | remote = remote_get(name); |
Johannes Schindelin | e459b07 | 2017-01-19 22:20:02 +0100 | [diff] [blame] | 191 | if (remote_is_configured(remote, 1)) |
Nguyễn Thái Ngọc Duy | bb16d5d | 2012-04-23 19:30:26 +0700 | [diff] [blame] | 192 | die(_("remote %s already exists."), name); |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 193 | |
Jonas Fonseca | 24b6177 | 2008-04-13 11:56:54 +0200 | [diff] [blame] | 194 | strbuf_addf(&buf2, "refs/heads/test:refs/remotes/%s/test", name); |
| 195 | if (!valid_fetch_refspec(buf2.buf)) |
Nguyễn Thái Ngọc Duy | bb16d5d | 2012-04-23 19:30:26 +0700 | [diff] [blame] | 196 | die(_("'%s' is not a valid remote name"), name); |
Jonas Fonseca | 24b6177 | 2008-04-13 11:56:54 +0200 | [diff] [blame] | 197 | |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 198 | strbuf_addf(&buf, "remote.%s.url", name); |
Patrick Steinhardt | 3d18064 | 2016-02-22 12:23:36 +0100 | [diff] [blame] | 199 | git_config_set(buf.buf, url); |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 200 | |
Jeff King | a9f5a35 | 2011-03-30 15:53:19 -0400 | [diff] [blame] | 201 | if (!mirror || mirror & MIRROR_FETCH) { |
| 202 | strbuf_reset(&buf); |
| 203 | strbuf_addf(&buf, "remote.%s.fetch", name); |
| 204 | if (track.nr == 0) |
| 205 | string_list_append(&track, "*"); |
| 206 | for (i = 0; i < track.nr; i++) { |
Patrick Steinhardt | ab5e4b6 | 2016-02-22 12:23:29 +0100 | [diff] [blame] | 207 | add_branch(buf.buf, track.items[i].string, |
| 208 | name, mirror, &buf2); |
Jeff King | a9f5a35 | 2011-03-30 15:53:19 -0400 | [diff] [blame] | 209 | } |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 210 | } |
| 211 | |
Jeff King | a9f5a35 | 2011-03-30 15:53:19 -0400 | [diff] [blame] | 212 | if (mirror & MIRROR_PUSH) { |
Paolo Bonzini | 84bb2df | 2008-04-17 13:17:20 +0200 | [diff] [blame] | 213 | strbuf_reset(&buf); |
| 214 | strbuf_addf(&buf, "remote.%s.mirror", name); |
Patrick Steinhardt | 3d18064 | 2016-02-22 12:23:36 +0100 | [diff] [blame] | 215 | git_config_set(buf.buf, "true"); |
Paolo Bonzini | 84bb2df | 2008-04-17 13:17:20 +0200 | [diff] [blame] | 216 | } |
| 217 | |
Samuel Tardieu | 111fb85 | 2010-04-20 01:31:31 +0200 | [diff] [blame] | 218 | if (fetch_tags != TAGS_DEFAULT) { |
| 219 | strbuf_reset(&buf); |
| 220 | strbuf_addf(&buf, "remote.%s.tagopt", name); |
Patrick Steinhardt | 3d18064 | 2016-02-22 12:23:36 +0100 | [diff] [blame] | 221 | git_config_set(buf.buf, |
| 222 | fetch_tags == TAGS_SET ? "--tags" : "--no-tags"); |
Samuel Tardieu | 111fb85 | 2010-04-20 01:31:31 +0200 | [diff] [blame] | 223 | } |
| 224 | |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 225 | if (fetch && fetch_remote(name)) |
| 226 | return 1; |
| 227 | |
| 228 | if (master) { |
| 229 | strbuf_reset(&buf); |
| 230 | strbuf_addf(&buf, "refs/remotes/%s/HEAD", name); |
| 231 | |
| 232 | strbuf_reset(&buf2); |
| 233 | strbuf_addf(&buf2, "refs/remotes/%s/%s", name, master); |
| 234 | |
| 235 | if (create_symref(buf.buf, buf2.buf, "remote add")) |
Nguyễn Thái Ngọc Duy | bb16d5d | 2012-04-23 19:30:26 +0700 | [diff] [blame] | 236 | return error(_("Could not setup master '%s'"), master); |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 237 | } |
| 238 | |
| 239 | strbuf_release(&buf); |
| 240 | strbuf_release(&buf2); |
Johannes Schindelin | c455c87 | 2008-07-21 19:03:49 +0100 | [diff] [blame] | 241 | string_list_clear(&track, 0); |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 242 | |
| 243 | return 0; |
| 244 | } |
| 245 | |
| 246 | struct branch_info { |
Jay Soffian | e0cc81e | 2009-02-25 03:32:21 -0500 | [diff] [blame] | 247 | char *remote_name; |
Johannes Schindelin | c455c87 | 2008-07-21 19:03:49 +0100 | [diff] [blame] | 248 | struct string_list merge; |
Johannes Schindelin | b5496d4 | 2016-01-13 13:17:19 +0100 | [diff] [blame] | 249 | enum { NO_REBASE, NORMAL_REBASE, INTERACTIVE_REBASE } rebase; |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 250 | }; |
| 251 | |
Jeff King | 2721ce2 | 2016-06-13 06:04:20 -0400 | [diff] [blame] | 252 | static struct string_list branch_list = STRING_LIST_INIT_NODUP; |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 253 | |
Junio C Hamano | 72972eb | 2008-07-17 21:30:33 -0700 | [diff] [blame] | 254 | static const char *abbrev_ref(const char *name, const char *prefix) |
| 255 | { |
Jeff King | cf4fff5 | 2014-06-18 15:44:19 -0400 | [diff] [blame] | 256 | skip_prefix(name, prefix, &name); |
Junio C Hamano | 72972eb | 2008-07-17 21:30:33 -0700 | [diff] [blame] | 257 | return name; |
| 258 | } |
| 259 | #define abbrev_branch(name) abbrev_ref((name), "refs/heads/") |
| 260 | |
Johannes Schindelin | ef90d6d | 2008-05-14 18:46:53 +0100 | [diff] [blame] | 261 | static int config_read_branches(const char *key, const char *value, void *cb) |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 262 | { |
Christian Couder | 5955654 | 2013-11-30 21:55:40 +0100 | [diff] [blame] | 263 | if (starts_with(key, "branch.")) { |
Jay Soffian | 7ecbbf8 | 2009-02-25 03:32:27 -0500 | [diff] [blame] | 264 | const char *orig_key = key; |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 265 | char *name; |
Johannes Schindelin | c455c87 | 2008-07-21 19:03:49 +0100 | [diff] [blame] | 266 | struct string_list_item *item; |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 267 | struct branch_info *info; |
Jay Soffian | 7ecbbf8 | 2009-02-25 03:32:27 -0500 | [diff] [blame] | 268 | enum { REMOTE, MERGE, REBASE } type; |
Jeff King | 26936bf | 2014-06-30 12:58:51 -0400 | [diff] [blame] | 269 | size_t key_len; |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 270 | |
| 271 | key += 7; |
Jeff King | 26936bf | 2014-06-30 12:58:51 -0400 | [diff] [blame] | 272 | if (strip_suffix(key, ".remote", &key_len)) { |
| 273 | name = xmemdupz(key, key_len); |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 274 | type = REMOTE; |
Jeff King | 26936bf | 2014-06-30 12:58:51 -0400 | [diff] [blame] | 275 | } else if (strip_suffix(key, ".merge", &key_len)) { |
| 276 | name = xmemdupz(key, key_len); |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 277 | type = MERGE; |
Jeff King | 26936bf | 2014-06-30 12:58:51 -0400 | [diff] [blame] | 278 | } else if (strip_suffix(key, ".rebase", &key_len)) { |
| 279 | name = xmemdupz(key, key_len); |
Jay Soffian | 7ecbbf8 | 2009-02-25 03:32:27 -0500 | [diff] [blame] | 280 | type = REBASE; |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 281 | } else |
| 282 | return 0; |
| 283 | |
Julian Phillips | 78a395d | 2010-06-26 00:41:35 +0100 | [diff] [blame] | 284 | item = string_list_insert(&branch_list, name); |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 285 | |
| 286 | if (!item->util) |
Brian Gesiak | 3806945 | 2014-05-27 00:33:44 +0900 | [diff] [blame] | 287 | item->util = xcalloc(1, sizeof(struct branch_info)); |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 288 | info = item->util; |
| 289 | if (type == REMOTE) { |
Jay Soffian | e0cc81e | 2009-02-25 03:32:21 -0500 | [diff] [blame] | 290 | if (info->remote_name) |
Nguyễn Thái Ngọc Duy | bb16d5d | 2012-04-23 19:30:26 +0700 | [diff] [blame] | 291 | warning(_("more than one %s"), orig_key); |
Jay Soffian | e0cc81e | 2009-02-25 03:32:21 -0500 | [diff] [blame] | 292 | info->remote_name = xstrdup(value); |
Jay Soffian | 7ecbbf8 | 2009-02-25 03:32:27 -0500 | [diff] [blame] | 293 | } else if (type == MERGE) { |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 294 | char *space = strchr(value, ' '); |
Junio C Hamano | 72972eb | 2008-07-17 21:30:33 -0700 | [diff] [blame] | 295 | value = abbrev_branch(value); |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 296 | while (space) { |
| 297 | char *merge; |
| 298 | merge = xstrndup(value, space - value); |
Julian Phillips | 1d2f80f | 2010-06-26 00:41:38 +0100 | [diff] [blame] | 299 | string_list_append(&info->merge, merge); |
Junio C Hamano | 72972eb | 2008-07-17 21:30:33 -0700 | [diff] [blame] | 300 | value = abbrev_branch(space + 1); |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 301 | space = strchr(value, ' '); |
| 302 | } |
Julian Phillips | 1d2f80f | 2010-06-26 00:41:38 +0100 | [diff] [blame] | 303 | string_list_append(&info->merge, xstrdup(value)); |
Felipe Contreras | 0a54f70 | 2013-12-07 07:08:37 -0600 | [diff] [blame] | 304 | } else { |
Martin Ågren | 8957661 | 2017-08-07 20:20:49 +0200 | [diff] [blame] | 305 | int v = git_parse_maybe_bool(value); |
Felipe Contreras | 0a54f70 | 2013-12-07 07:08:37 -0600 | [diff] [blame] | 306 | if (v >= 0) |
| 307 | info->rebase = v; |
| 308 | else if (!strcmp(value, "preserve")) |
Johannes Schindelin | b5496d4 | 2016-01-13 13:17:19 +0100 | [diff] [blame] | 309 | info->rebase = NORMAL_REBASE; |
| 310 | else if (!strcmp(value, "interactive")) |
| 311 | info->rebase = INTERACTIVE_REBASE; |
Felipe Contreras | 0a54f70 | 2013-12-07 07:08:37 -0600 | [diff] [blame] | 312 | } |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 313 | } |
| 314 | return 0; |
| 315 | } |
| 316 | |
| 317 | static void read_branches(void) |
| 318 | { |
| 319 | if (branch_list.nr) |
| 320 | return; |
Johannes Schindelin | ef90d6d | 2008-05-14 18:46:53 +0100 | [diff] [blame] | 321 | git_config(config_read_branches, NULL); |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 322 | } |
| 323 | |
| 324 | struct ref_states { |
| 325 | struct remote *remote; |
Brandon Williams | b537e0b | 2018-02-14 10:59:35 -0800 | [diff] [blame] | 326 | struct string_list new_refs, stale, tracked, heads, push; |
Jay Soffian | 7ecbbf8 | 2009-02-25 03:32:27 -0500 | [diff] [blame] | 327 | int queried; |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 328 | }; |
| 329 | |
Jay Soffian | e0cc81e | 2009-02-25 03:32:21 -0500 | [diff] [blame] | 330 | static int get_ref_states(const struct ref *remote_refs, struct ref_states *states) |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 331 | { |
| 332 | struct ref *fetch_map = NULL, **tail = &fetch_map; |
Jay Soffian | f2ef607 | 2009-11-10 00:03:31 -0500 | [diff] [blame] | 333 | struct ref *ref, *stale_refs; |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 334 | int i; |
| 335 | |
| 336 | for (i = 0; i < states->remote->fetch_refspec_nr; i++) |
Jay Soffian | e0cc81e | 2009-02-25 03:32:21 -0500 | [diff] [blame] | 337 | if (get_fetch_map(remote_refs, states->remote->fetch + i, &tail, 1)) |
Nguyễn Thái Ngọc Duy | bb16d5d | 2012-04-23 19:30:26 +0700 | [diff] [blame] | 338 | die(_("Could not get fetch map for refspec %s"), |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 339 | states->remote->fetch_refspec[i]); |
| 340 | |
Brandon Williams | b537e0b | 2018-02-14 10:59:35 -0800 | [diff] [blame] | 341 | states->new_refs.strdup_strings = 1; |
Bert Wesarg | 92f676f | 2009-12-01 00:57:27 +0100 | [diff] [blame] | 342 | states->tracked.strdup_strings = 1; |
| 343 | states->stale.strdup_strings = 1; |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 344 | for (ref = fetch_map; ref; ref = ref->next) { |
Nguyễn Thái Ngọc Duy | c689332 | 2011-11-13 17:22:14 +0700 | [diff] [blame] | 345 | if (!ref->peer_ref || !ref_exists(ref->peer_ref->name)) |
Brandon Williams | b537e0b | 2018-02-14 10:59:35 -0800 | [diff] [blame] | 346 | string_list_append(&states->new_refs, abbrev_branch(ref->name)); |
Jay Soffian | 7b9a5e2 | 2009-02-25 03:32:20 -0500 | [diff] [blame] | 347 | else |
Julian Phillips | 1d2f80f | 2010-06-26 00:41:38 +0100 | [diff] [blame] | 348 | string_list_append(&states->tracked, abbrev_branch(ref->name)); |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 349 | } |
Carlos Martín Nieto | ed43de6 | 2011-10-15 07:04:25 +0200 | [diff] [blame] | 350 | stale_refs = get_stale_heads(states->remote->fetch, |
| 351 | states->remote->fetch_refspec_nr, fetch_map); |
Jay Soffian | f2ef607 | 2009-11-10 00:03:31 -0500 | [diff] [blame] | 352 | for (ref = stale_refs; ref; ref = ref->next) { |
| 353 | struct string_list_item *item = |
Julian Phillips | 1d2f80f | 2010-06-26 00:41:38 +0100 | [diff] [blame] | 354 | string_list_append(&states->stale, abbrev_branch(ref->name)); |
Jay Soffian | f2ef607 | 2009-11-10 00:03:31 -0500 | [diff] [blame] | 355 | item->util = xstrdup(ref->name); |
| 356 | } |
| 357 | free_refs(stale_refs); |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 358 | free_refs(fetch_map); |
| 359 | |
Brandon Williams | b537e0b | 2018-02-14 10:59:35 -0800 | [diff] [blame] | 360 | string_list_sort(&states->new_refs); |
Michael Haggerty | 3383e19 | 2014-11-25 09:02:35 +0100 | [diff] [blame] | 361 | string_list_sort(&states->tracked); |
| 362 | string_list_sort(&states->stale); |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 363 | |
| 364 | return 0; |
| 365 | } |
| 366 | |
Jay Soffian | e5dcbfd | 2009-02-25 03:32:28 -0500 | [diff] [blame] | 367 | struct push_info { |
| 368 | char *dest; |
| 369 | int forced; |
| 370 | enum { |
| 371 | PUSH_STATUS_CREATE = 0, |
| 372 | PUSH_STATUS_DELETE, |
| 373 | PUSH_STATUS_UPTODATE, |
| 374 | PUSH_STATUS_FASTFORWARD, |
| 375 | PUSH_STATUS_OUTOFDATE, |
Gary V. Vaughan | 4b05548 | 2010-05-14 09:31:35 +0000 | [diff] [blame] | 376 | PUSH_STATUS_NOTQUERIED |
Jay Soffian | e5dcbfd | 2009-02-25 03:32:28 -0500 | [diff] [blame] | 377 | } status; |
| 378 | }; |
| 379 | |
| 380 | static int get_push_ref_states(const struct ref *remote_refs, |
| 381 | struct ref_states *states) |
| 382 | { |
| 383 | struct remote *remote = states->remote; |
Clemens Buchacher | 6d2bf96 | 2009-05-31 16:26:48 +0200 | [diff] [blame] | 384 | struct ref *ref, *local_refs, *push_map; |
Jay Soffian | e5dcbfd | 2009-02-25 03:32:28 -0500 | [diff] [blame] | 385 | if (remote->mirror) |
| 386 | return 0; |
| 387 | |
| 388 | local_refs = get_local_heads(); |
Clemens Buchacher | 6a01554 | 2009-05-27 22:13:43 +0200 | [diff] [blame] | 389 | push_map = copy_ref_list(remote_refs); |
Jay Soffian | e5dcbfd | 2009-02-25 03:32:28 -0500 | [diff] [blame] | 390 | |
Junio C Hamano | 29753cd | 2011-09-09 11:54:58 -0700 | [diff] [blame] | 391 | match_push_refs(local_refs, &push_map, remote->push_refspec_nr, |
| 392 | remote->push_refspec, MATCH_REFS_NONE); |
Jay Soffian | e5dcbfd | 2009-02-25 03:32:28 -0500 | [diff] [blame] | 393 | |
| 394 | states->push.strdup_strings = 1; |
| 395 | for (ref = push_map; ref; ref = ref->next) { |
| 396 | struct string_list_item *item; |
| 397 | struct push_info *info; |
| 398 | |
| 399 | if (!ref->peer_ref) |
| 400 | continue; |
brian m. carlson | f4e54d0 | 2015-11-10 02:22:20 +0000 | [diff] [blame] | 401 | oidcpy(&ref->new_oid, &ref->peer_ref->new_oid); |
Jay Soffian | e5dcbfd | 2009-02-25 03:32:28 -0500 | [diff] [blame] | 402 | |
Julian Phillips | 1d2f80f | 2010-06-26 00:41:38 +0100 | [diff] [blame] | 403 | item = string_list_append(&states->push, |
| 404 | abbrev_branch(ref->peer_ref->name)); |
Brian Gesiak | 3806945 | 2014-05-27 00:33:44 +0900 | [diff] [blame] | 405 | item->util = xcalloc(1, sizeof(struct push_info)); |
Jay Soffian | e5dcbfd | 2009-02-25 03:32:28 -0500 | [diff] [blame] | 406 | info = item->util; |
| 407 | info->forced = ref->force; |
| 408 | info->dest = xstrdup(abbrev_branch(ref->name)); |
| 409 | |
brian m. carlson | f4e54d0 | 2015-11-10 02:22:20 +0000 | [diff] [blame] | 410 | if (is_null_oid(&ref->new_oid)) { |
Jay Soffian | e5dcbfd | 2009-02-25 03:32:28 -0500 | [diff] [blame] | 411 | info->status = PUSH_STATUS_DELETE; |
brian m. carlson | f4e54d0 | 2015-11-10 02:22:20 +0000 | [diff] [blame] | 412 | } else if (!oidcmp(&ref->old_oid, &ref->new_oid)) |
Jay Soffian | e5dcbfd | 2009-02-25 03:32:28 -0500 | [diff] [blame] | 413 | info->status = PUSH_STATUS_UPTODATE; |
brian m. carlson | f4e54d0 | 2015-11-10 02:22:20 +0000 | [diff] [blame] | 414 | else if (is_null_oid(&ref->old_oid)) |
Jay Soffian | e5dcbfd | 2009-02-25 03:32:28 -0500 | [diff] [blame] | 415 | info->status = PUSH_STATUS_CREATE; |
brian m. carlson | f4e54d0 | 2015-11-10 02:22:20 +0000 | [diff] [blame] | 416 | else if (has_object_file(&ref->old_oid) && |
brian m. carlson | 6f3d57b | 2015-11-10 02:22:25 +0000 | [diff] [blame] | 417 | ref_newer(&ref->new_oid, &ref->old_oid)) |
Jay Soffian | e5dcbfd | 2009-02-25 03:32:28 -0500 | [diff] [blame] | 418 | info->status = PUSH_STATUS_FASTFORWARD; |
| 419 | else |
| 420 | info->status = PUSH_STATUS_OUTOFDATE; |
Jay Soffian | e5dcbfd | 2009-02-25 03:32:28 -0500 | [diff] [blame] | 421 | } |
| 422 | free_refs(local_refs); |
| 423 | free_refs(push_map); |
| 424 | return 0; |
| 425 | } |
| 426 | |
| 427 | static int get_push_ref_states_noquery(struct ref_states *states) |
| 428 | { |
| 429 | int i; |
| 430 | struct remote *remote = states->remote; |
| 431 | struct string_list_item *item; |
| 432 | struct push_info *info; |
| 433 | |
| 434 | if (remote->mirror) |
| 435 | return 0; |
| 436 | |
| 437 | states->push.strdup_strings = 1; |
| 438 | if (!remote->push_refspec_nr) { |
Nguyễn Thái Ngọc Duy | bb16d5d | 2012-04-23 19:30:26 +0700 | [diff] [blame] | 439 | item = string_list_append(&states->push, _("(matching)")); |
Brian Gesiak | 3806945 | 2014-05-27 00:33:44 +0900 | [diff] [blame] | 440 | info = item->util = xcalloc(1, sizeof(struct push_info)); |
Jay Soffian | e5dcbfd | 2009-02-25 03:32:28 -0500 | [diff] [blame] | 441 | info->status = PUSH_STATUS_NOTQUERIED; |
| 442 | info->dest = xstrdup(item->string); |
| 443 | } |
| 444 | for (i = 0; i < remote->push_refspec_nr; i++) { |
| 445 | struct refspec *spec = remote->push + i; |
Jay Soffian | e5dcbfd | 2009-02-25 03:32:28 -0500 | [diff] [blame] | 446 | if (spec->matching) |
Nguyễn Thái Ngọc Duy | bb16d5d | 2012-04-23 19:30:26 +0700 | [diff] [blame] | 447 | item = string_list_append(&states->push, _("(matching)")); |
Junio C Hamano | 5ad6b02 | 2009-03-08 00:12:33 -0800 | [diff] [blame] | 448 | else if (strlen(spec->src)) |
Julian Phillips | 1d2f80f | 2010-06-26 00:41:38 +0100 | [diff] [blame] | 449 | item = string_list_append(&states->push, spec->src); |
Jay Soffian | e5dcbfd | 2009-02-25 03:32:28 -0500 | [diff] [blame] | 450 | else |
Nguyễn Thái Ngọc Duy | bb16d5d | 2012-04-23 19:30:26 +0700 | [diff] [blame] | 451 | item = string_list_append(&states->push, _("(delete)")); |
Jay Soffian | e5dcbfd | 2009-02-25 03:32:28 -0500 | [diff] [blame] | 452 | |
Brian Gesiak | 3806945 | 2014-05-27 00:33:44 +0900 | [diff] [blame] | 453 | info = item->util = xcalloc(1, sizeof(struct push_info)); |
Jay Soffian | e5dcbfd | 2009-02-25 03:32:28 -0500 | [diff] [blame] | 454 | info->forced = spec->force; |
| 455 | info->status = PUSH_STATUS_NOTQUERIED; |
Junio C Hamano | 5ad6b02 | 2009-03-08 00:12:33 -0800 | [diff] [blame] | 456 | info->dest = xstrdup(spec->dst ? spec->dst : item->string); |
Jay Soffian | e5dcbfd | 2009-02-25 03:32:28 -0500 | [diff] [blame] | 457 | } |
| 458 | return 0; |
| 459 | } |
| 460 | |
Jay Soffian | e61e0cc | 2009-02-25 03:32:24 -0500 | [diff] [blame] | 461 | static int get_head_names(const struct ref *remote_refs, struct ref_states *states) |
| 462 | { |
| 463 | struct ref *ref, *matches; |
| 464 | struct ref *fetch_map = NULL, **fetch_map_tail = &fetch_map; |
| 465 | struct refspec refspec; |
| 466 | |
| 467 | refspec.force = 0; |
| 468 | refspec.pattern = 1; |
Junio C Hamano | 5ad6b02 | 2009-03-08 00:12:33 -0800 | [diff] [blame] | 469 | refspec.src = refspec.dst = "refs/heads/*"; |
Jay Soffian | e61e0cc | 2009-02-25 03:32:24 -0500 | [diff] [blame] | 470 | states->heads.strdup_strings = 1; |
| 471 | get_fetch_map(remote_refs, &refspec, &fetch_map_tail, 0); |
| 472 | matches = guess_remote_head(find_ref_by_name(remote_refs, "HEAD"), |
| 473 | fetch_map, 1); |
Brian Gianforcaro | eeefa7c | 2009-09-01 01:35:10 -0400 | [diff] [blame] | 474 | for (ref = matches; ref; ref = ref->next) |
Julian Phillips | 1d2f80f | 2010-06-26 00:41:38 +0100 | [diff] [blame] | 475 | string_list_append(&states->heads, abbrev_branch(ref->name)); |
Jay Soffian | e61e0cc | 2009-02-25 03:32:24 -0500 | [diff] [blame] | 476 | |
| 477 | free_refs(fetch_map); |
| 478 | free_refs(matches); |
| 479 | |
| 480 | return 0; |
| 481 | } |
| 482 | |
Shawn O. Pearce | 7ad2458 | 2008-06-01 00:28:04 -0400 | [diff] [blame] | 483 | struct known_remote { |
| 484 | struct known_remote *next; |
| 485 | struct remote *remote; |
| 486 | }; |
| 487 | |
| 488 | struct known_remotes { |
| 489 | struct remote *to_delete; |
| 490 | struct known_remote *list; |
| 491 | }; |
| 492 | |
| 493 | static int add_known_remote(struct remote *remote, void *cb_data) |
| 494 | { |
| 495 | struct known_remotes *all = cb_data; |
| 496 | struct known_remote *r; |
| 497 | |
| 498 | if (!strcmp(all->to_delete->name, remote->name)) |
| 499 | return 0; |
| 500 | |
| 501 | r = xmalloc(sizeof(*r)); |
| 502 | r->remote = remote; |
| 503 | r->next = all->list; |
| 504 | all->list = r; |
| 505 | return 0; |
| 506 | } |
| 507 | |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 508 | struct branches_for_remote { |
Shawn O. Pearce | 7ad2458 | 2008-06-01 00:28:04 -0400 | [diff] [blame] | 509 | struct remote *remote; |
Jay Soffian | 441adf0 | 2009-02-04 11:06:07 -0500 | [diff] [blame] | 510 | struct string_list *branches, *skipped; |
Shawn O. Pearce | 7ad2458 | 2008-06-01 00:28:04 -0400 | [diff] [blame] | 511 | struct known_remotes *keep; |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 512 | }; |
| 513 | |
| 514 | static int add_branch_for_removal(const char *refname, |
Michael Haggerty | 45690a5 | 2015-05-25 18:38:41 +0000 | [diff] [blame] | 515 | const struct object_id *oid, int flags, void *cb_data) |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 516 | { |
| 517 | struct branches_for_remote *branches = cb_data; |
Shawn O. Pearce | 7ad2458 | 2008-06-01 00:28:04 -0400 | [diff] [blame] | 518 | struct refspec refspec; |
Shawn O. Pearce | 7ad2458 | 2008-06-01 00:28:04 -0400 | [diff] [blame] | 519 | struct known_remote *kr; |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 520 | |
Shawn O. Pearce | 7ad2458 | 2008-06-01 00:28:04 -0400 | [diff] [blame] | 521 | memset(&refspec, 0, sizeof(refspec)); |
| 522 | refspec.dst = (char *)refname; |
| 523 | if (remote_find_tracking(branches->remote, &refspec)) |
| 524 | return 0; |
Johannes Schindelin | 3b9dcff | 2008-03-08 23:40:42 +0100 | [diff] [blame] | 525 | |
Shawn O. Pearce | 7ad2458 | 2008-06-01 00:28:04 -0400 | [diff] [blame] | 526 | /* don't delete a branch if another remote also uses it */ |
| 527 | for (kr = branches->keep->list; kr; kr = kr->next) { |
| 528 | memset(&refspec, 0, sizeof(refspec)); |
| 529 | refspec.dst = (char *)refname; |
| 530 | if (!remote_find_tracking(kr->remote, &refspec)) |
| 531 | return 0; |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 532 | } |
| 533 | |
Matthieu Moy | 1393123 | 2010-11-02 16:31:25 +0100 | [diff] [blame] | 534 | /* don't delete non-remote-tracking refs */ |
Christian Couder | 5955654 | 2013-11-30 21:55:40 +0100 | [diff] [blame] | 535 | if (!starts_with(refname, "refs/remotes/")) { |
Jay Soffian | 441adf0 | 2009-02-04 11:06:07 -0500 | [diff] [blame] | 536 | /* advise user how to delete local branches */ |
Christian Couder | 5955654 | 2013-11-30 21:55:40 +0100 | [diff] [blame] | 537 | if (starts_with(refname, "refs/heads/")) |
Julian Phillips | 1d2f80f | 2010-06-26 00:41:38 +0100 | [diff] [blame] | 538 | string_list_append(branches->skipped, |
| 539 | abbrev_branch(refname)); |
Jay Soffian | 441adf0 | 2009-02-04 11:06:07 -0500 | [diff] [blame] | 540 | /* silently skip over other non-remote refs */ |
| 541 | return 0; |
| 542 | } |
| 543 | |
Michael Haggerty | e26cdf9 | 2015-05-25 18:38:42 +0000 | [diff] [blame] | 544 | string_list_append(branches->branches, refname); |
Shawn O. Pearce | 7ad2458 | 2008-06-01 00:28:04 -0400 | [diff] [blame] | 545 | |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 546 | return 0; |
| 547 | } |
| 548 | |
Miklos Vajna | bf98421 | 2008-11-03 19:26:18 +0100 | [diff] [blame] | 549 | struct rename_info { |
Brandon Williams | b537e0b | 2018-02-14 10:59:35 -0800 | [diff] [blame] | 550 | const char *old_name; |
| 551 | const char *new_name; |
Miklos Vajna | bf98421 | 2008-11-03 19:26:18 +0100 | [diff] [blame] | 552 | struct string_list *remote_branches; |
| 553 | }; |
| 554 | |
| 555 | static int read_remote_branches(const char *refname, |
Michael Haggerty | 53dc95b | 2015-05-25 18:38:43 +0000 | [diff] [blame] | 556 | const struct object_id *oid, int flags, void *cb_data) |
Miklos Vajna | bf98421 | 2008-11-03 19:26:18 +0100 | [diff] [blame] | 557 | { |
| 558 | struct rename_info *rename = cb_data; |
| 559 | struct strbuf buf = STRBUF_INIT; |
| 560 | struct string_list_item *item; |
| 561 | int flag; |
Miklos Vajna | bf98421 | 2008-11-03 19:26:18 +0100 | [diff] [blame] | 562 | const char *symref; |
| 563 | |
Brandon Williams | b537e0b | 2018-02-14 10:59:35 -0800 | [diff] [blame] | 564 | strbuf_addf(&buf, "refs/remotes/%s/", rename->old_name); |
Christian Couder | 5955654 | 2013-11-30 21:55:40 +0100 | [diff] [blame] | 565 | if (starts_with(refname, buf.buf)) { |
Julian Phillips | 1d2f80f | 2010-06-26 00:41:38 +0100 | [diff] [blame] | 566 | item = string_list_append(rename->remote_branches, xstrdup(refname)); |
Ronnie Sahlberg | 7695d11 | 2014-07-15 12:59:36 -0700 | [diff] [blame] | 567 | symref = resolve_ref_unsafe(refname, RESOLVE_REF_READING, |
René Scharfe | 744c040 | 2017-09-23 11:45:04 +0200 | [diff] [blame] | 568 | NULL, &flag); |
Jeff King | 752848d | 2017-10-19 13:47:30 -0400 | [diff] [blame] | 569 | if (symref && (flag & REF_ISSYMREF)) |
Miklos Vajna | bf98421 | 2008-11-03 19:26:18 +0100 | [diff] [blame] | 570 | item->util = xstrdup(symref); |
| 571 | else |
| 572 | item->util = NULL; |
| 573 | } |
Rene Scharfe | e2581b7 | 2017-08-30 20:00:25 +0200 | [diff] [blame] | 574 | strbuf_release(&buf); |
Miklos Vajna | bf98421 | 2008-11-03 19:26:18 +0100 | [diff] [blame] | 575 | |
| 576 | return 0; |
| 577 | } |
| 578 | |
Miklos Vajna | 1dd1239 | 2008-11-10 21:43:01 +0100 | [diff] [blame] | 579 | static int migrate_file(struct remote *remote) |
| 580 | { |
| 581 | struct strbuf buf = STRBUF_INIT; |
| 582 | int i; |
Miklos Vajna | 1dd1239 | 2008-11-10 21:43:01 +0100 | [diff] [blame] | 583 | |
| 584 | strbuf_addf(&buf, "remote.%s.url", remote->name); |
| 585 | for (i = 0; i < remote->url_nr; i++) |
Patrick Steinhardt | 3d18064 | 2016-02-22 12:23:36 +0100 | [diff] [blame] | 586 | git_config_set_multivar(buf.buf, remote->url[i], "^$", 0); |
Miklos Vajna | 1dd1239 | 2008-11-10 21:43:01 +0100 | [diff] [blame] | 587 | strbuf_reset(&buf); |
| 588 | strbuf_addf(&buf, "remote.%s.push", remote->name); |
| 589 | for (i = 0; i < remote->push_refspec_nr; i++) |
Patrick Steinhardt | 3d18064 | 2016-02-22 12:23:36 +0100 | [diff] [blame] | 590 | git_config_set_multivar(buf.buf, remote->push_refspec[i], "^$", 0); |
Miklos Vajna | 1dd1239 | 2008-11-10 21:43:01 +0100 | [diff] [blame] | 591 | strbuf_reset(&buf); |
| 592 | strbuf_addf(&buf, "remote.%s.fetch", remote->name); |
| 593 | for (i = 0; i < remote->fetch_refspec_nr; i++) |
Patrick Steinhardt | 3d18064 | 2016-02-22 12:23:36 +0100 | [diff] [blame] | 594 | git_config_set_multivar(buf.buf, remote->fetch_refspec[i], "^$", 0); |
Miklos Vajna | 1dd1239 | 2008-11-10 21:43:01 +0100 | [diff] [blame] | 595 | if (remote->origin == REMOTE_REMOTES) |
Jeff King | b21a5d6 | 2015-08-10 05:35:49 -0400 | [diff] [blame] | 596 | unlink_or_warn(git_path("remotes/%s", remote->name)); |
Miklos Vajna | 1dd1239 | 2008-11-10 21:43:01 +0100 | [diff] [blame] | 597 | else if (remote->origin == REMOTE_BRANCHES) |
Jeff King | b21a5d6 | 2015-08-10 05:35:49 -0400 | [diff] [blame] | 598 | unlink_or_warn(git_path("branches/%s", remote->name)); |
Rene Scharfe | b95c8ce | 2017-08-30 20:00:26 +0200 | [diff] [blame] | 599 | strbuf_release(&buf); |
Patrick Steinhardt | c397deb | 2016-02-22 12:23:30 +0100 | [diff] [blame] | 600 | |
Miklos Vajna | 1dd1239 | 2008-11-10 21:43:01 +0100 | [diff] [blame] | 601 | return 0; |
| 602 | } |
| 603 | |
Miklos Vajna | bf98421 | 2008-11-03 19:26:18 +0100 | [diff] [blame] | 604 | static int mv(int argc, const char **argv) |
| 605 | { |
| 606 | struct option options[] = { |
| 607 | OPT_END() |
| 608 | }; |
| 609 | struct remote *oldremote, *newremote; |
Martin von Zweigbergk | 28f555f | 2011-09-01 20:50:33 -0400 | [diff] [blame] | 610 | struct strbuf buf = STRBUF_INIT, buf2 = STRBUF_INIT, buf3 = STRBUF_INIT, |
| 611 | old_remote_context = STRBUF_INIT; |
Thiago Farina | 183113a | 2010-07-04 16:46:19 -0300 | [diff] [blame] | 612 | struct string_list remote_branches = STRING_LIST_INIT_NODUP; |
Miklos Vajna | bf98421 | 2008-11-03 19:26:18 +0100 | [diff] [blame] | 613 | struct rename_info rename; |
Martin von Zweigbergk | b52d00a | 2011-09-10 15:39:23 -0400 | [diff] [blame] | 614 | int i, refspec_updated = 0; |
Miklos Vajna | bf98421 | 2008-11-03 19:26:18 +0100 | [diff] [blame] | 615 | |
| 616 | if (argc != 3) |
Tim Henigan | 4504107 | 2009-11-20 18:43:13 -0500 | [diff] [blame] | 617 | usage_with_options(builtin_remote_rename_usage, options); |
Miklos Vajna | bf98421 | 2008-11-03 19:26:18 +0100 | [diff] [blame] | 618 | |
Brandon Williams | b537e0b | 2018-02-14 10:59:35 -0800 | [diff] [blame] | 619 | rename.old_name = argv[1]; |
| 620 | rename.new_name = argv[2]; |
Miklos Vajna | bf98421 | 2008-11-03 19:26:18 +0100 | [diff] [blame] | 621 | rename.remote_branches = &remote_branches; |
| 622 | |
Brandon Williams | b537e0b | 2018-02-14 10:59:35 -0800 | [diff] [blame] | 623 | oldremote = remote_get(rename.old_name); |
Johannes Schindelin | e459b07 | 2017-01-19 22:20:02 +0100 | [diff] [blame] | 624 | if (!remote_is_configured(oldremote, 1)) |
Brandon Williams | b537e0b | 2018-02-14 10:59:35 -0800 | [diff] [blame] | 625 | die(_("No such remote: %s"), rename.old_name); |
Miklos Vajna | bf98421 | 2008-11-03 19:26:18 +0100 | [diff] [blame] | 626 | |
Brandon Williams | b537e0b | 2018-02-14 10:59:35 -0800 | [diff] [blame] | 627 | if (!strcmp(rename.old_name, rename.new_name) && oldremote->origin != REMOTE_CONFIG) |
Miklos Vajna | 1dd1239 | 2008-11-10 21:43:01 +0100 | [diff] [blame] | 628 | return migrate_file(oldremote); |
| 629 | |
Brandon Williams | b537e0b | 2018-02-14 10:59:35 -0800 | [diff] [blame] | 630 | newremote = remote_get(rename.new_name); |
Johannes Schindelin | e459b07 | 2017-01-19 22:20:02 +0100 | [diff] [blame] | 631 | if (remote_is_configured(newremote, 1)) |
Brandon Williams | b537e0b | 2018-02-14 10:59:35 -0800 | [diff] [blame] | 632 | die(_("remote %s already exists."), rename.new_name); |
Miklos Vajna | bf98421 | 2008-11-03 19:26:18 +0100 | [diff] [blame] | 633 | |
Brandon Williams | b537e0b | 2018-02-14 10:59:35 -0800 | [diff] [blame] | 634 | strbuf_addf(&buf, "refs/heads/test:refs/remotes/%s/test", rename.new_name); |
Miklos Vajna | bf98421 | 2008-11-03 19:26:18 +0100 | [diff] [blame] | 635 | if (!valid_fetch_refspec(buf.buf)) |
Brandon Williams | b537e0b | 2018-02-14 10:59:35 -0800 | [diff] [blame] | 636 | die(_("'%s' is not a valid remote name"), rename.new_name); |
Miklos Vajna | bf98421 | 2008-11-03 19:26:18 +0100 | [diff] [blame] | 637 | |
| 638 | strbuf_reset(&buf); |
Brandon Williams | b537e0b | 2018-02-14 10:59:35 -0800 | [diff] [blame] | 639 | strbuf_addf(&buf, "remote.%s", rename.old_name); |
| 640 | strbuf_addf(&buf2, "remote.%s", rename.new_name); |
Miklos Vajna | bf98421 | 2008-11-03 19:26:18 +0100 | [diff] [blame] | 641 | if (git_config_rename_section(buf.buf, buf2.buf) < 1) |
Nguyễn Thái Ngọc Duy | bb16d5d | 2012-04-23 19:30:26 +0700 | [diff] [blame] | 642 | return error(_("Could not rename config section '%s' to '%s'"), |
Miklos Vajna | bf98421 | 2008-11-03 19:26:18 +0100 | [diff] [blame] | 643 | buf.buf, buf2.buf); |
| 644 | |
| 645 | strbuf_reset(&buf); |
Brandon Williams | b537e0b | 2018-02-14 10:59:35 -0800 | [diff] [blame] | 646 | strbuf_addf(&buf, "remote.%s.fetch", rename.new_name); |
Patrick Steinhardt | 3d18064 | 2016-02-22 12:23:36 +0100 | [diff] [blame] | 647 | git_config_set_multivar(buf.buf, NULL, NULL, 1); |
Brandon Williams | b537e0b | 2018-02-14 10:59:35 -0800 | [diff] [blame] | 648 | strbuf_addf(&old_remote_context, ":refs/remotes/%s/", rename.old_name); |
Miklos Vajna | bf98421 | 2008-11-03 19:26:18 +0100 | [diff] [blame] | 649 | for (i = 0; i < oldremote->fetch_refspec_nr; i++) { |
| 650 | char *ptr; |
| 651 | |
| 652 | strbuf_reset(&buf2); |
| 653 | strbuf_addstr(&buf2, oldremote->fetch_refspec[i]); |
Martin von Zweigbergk | 28f555f | 2011-09-01 20:50:33 -0400 | [diff] [blame] | 654 | ptr = strstr(buf2.buf, old_remote_context.buf); |
Martin von Zweigbergk | b52d00a | 2011-09-10 15:39:23 -0400 | [diff] [blame] | 655 | if (ptr) { |
| 656 | refspec_updated = 1; |
Martin von Zweigbergk | 28f555f | 2011-09-01 20:50:33 -0400 | [diff] [blame] | 657 | strbuf_splice(&buf2, |
| 658 | ptr-buf2.buf + strlen(":refs/remotes/"), |
Brandon Williams | b537e0b | 2018-02-14 10:59:35 -0800 | [diff] [blame] | 659 | strlen(rename.old_name), rename.new_name, |
| 660 | strlen(rename.new_name)); |
Martin von Zweigbergk | b52d00a | 2011-09-10 15:39:23 -0400 | [diff] [blame] | 661 | } else |
Ralf Thielow | aa3bb87 | 2012-05-18 18:46:01 +0200 | [diff] [blame] | 662 | warning(_("Not updating non-default fetch refspec\n" |
Nguyễn Thái Ngọc Duy | bb16d5d | 2012-04-23 19:30:26 +0700 | [diff] [blame] | 663 | "\t%s\n" |
| 664 | "\tPlease update the configuration manually if necessary."), |
Martin von Zweigbergk | 1822b86 | 2011-09-03 11:26:59 -0400 | [diff] [blame] | 665 | buf2.buf); |
| 666 | |
Patrick Steinhardt | 3d18064 | 2016-02-22 12:23:36 +0100 | [diff] [blame] | 667 | git_config_set_multivar(buf.buf, buf2.buf, "^$", 0); |
Miklos Vajna | bf98421 | 2008-11-03 19:26:18 +0100 | [diff] [blame] | 668 | } |
| 669 | |
| 670 | read_branches(); |
| 671 | for (i = 0; i < branch_list.nr; i++) { |
| 672 | struct string_list_item *item = branch_list.items + i; |
| 673 | struct branch_info *info = item->util; |
Brandon Williams | b537e0b | 2018-02-14 10:59:35 -0800 | [diff] [blame] | 674 | if (info->remote_name && !strcmp(info->remote_name, rename.old_name)) { |
Miklos Vajna | bf98421 | 2008-11-03 19:26:18 +0100 | [diff] [blame] | 675 | strbuf_reset(&buf); |
| 676 | strbuf_addf(&buf, "branch.%s.remote", item->string); |
Brandon Williams | b537e0b | 2018-02-14 10:59:35 -0800 | [diff] [blame] | 677 | git_config_set(buf.buf, rename.new_name); |
Miklos Vajna | bf98421 | 2008-11-03 19:26:18 +0100 | [diff] [blame] | 678 | } |
| 679 | } |
| 680 | |
Martin von Zweigbergk | b52d00a | 2011-09-10 15:39:23 -0400 | [diff] [blame] | 681 | if (!refspec_updated) |
| 682 | return 0; |
| 683 | |
Miklos Vajna | bf98421 | 2008-11-03 19:26:18 +0100 | [diff] [blame] | 684 | /* |
| 685 | * First remove symrefs, then rename the rest, finally create |
| 686 | * the new symrefs. |
| 687 | */ |
Michael Haggerty | 53dc95b | 2015-05-25 18:38:43 +0000 | [diff] [blame] | 688 | for_each_ref(read_remote_branches, &rename); |
Miklos Vajna | bf98421 | 2008-11-03 19:26:18 +0100 | [diff] [blame] | 689 | for (i = 0; i < remote_branches.nr; i++) { |
| 690 | struct string_list_item *item = remote_branches.items + i; |
| 691 | int flag = 0; |
Michael Haggerty | 53dc95b | 2015-05-25 18:38:43 +0000 | [diff] [blame] | 692 | struct object_id oid; |
Miklos Vajna | bf98421 | 2008-11-03 19:26:18 +0100 | [diff] [blame] | 693 | |
brian m. carlson | 34c290a | 2017-10-15 22:06:56 +0000 | [diff] [blame] | 694 | read_ref_full(item->string, RESOLVE_REF_READING, &oid, &flag); |
Miklos Vajna | bf98421 | 2008-11-03 19:26:18 +0100 | [diff] [blame] | 695 | if (!(flag & REF_ISSYMREF)) |
| 696 | continue; |
Michael Haggerty | 91774af | 2017-11-05 09:42:06 +0100 | [diff] [blame] | 697 | if (delete_ref(NULL, item->string, NULL, REF_NO_DEREF)) |
Nguyễn Thái Ngọc Duy | bb16d5d | 2012-04-23 19:30:26 +0700 | [diff] [blame] | 698 | die(_("deleting '%s' failed"), item->string); |
Miklos Vajna | bf98421 | 2008-11-03 19:26:18 +0100 | [diff] [blame] | 699 | } |
| 700 | for (i = 0; i < remote_branches.nr; i++) { |
| 701 | struct string_list_item *item = remote_branches.items + i; |
| 702 | |
| 703 | if (item->util) |
| 704 | continue; |
| 705 | strbuf_reset(&buf); |
| 706 | strbuf_addstr(&buf, item->string); |
Brandon Williams | b537e0b | 2018-02-14 10:59:35 -0800 | [diff] [blame] | 707 | strbuf_splice(&buf, strlen("refs/remotes/"), strlen(rename.old_name), |
| 708 | rename.new_name, strlen(rename.new_name)); |
Miklos Vajna | bf98421 | 2008-11-03 19:26:18 +0100 | [diff] [blame] | 709 | strbuf_reset(&buf2); |
| 710 | strbuf_addf(&buf2, "remote: renamed %s to %s", |
| 711 | item->string, buf.buf); |
| 712 | if (rename_ref(item->string, buf.buf, buf2.buf)) |
Nguyễn Thái Ngọc Duy | bb16d5d | 2012-04-23 19:30:26 +0700 | [diff] [blame] | 713 | die(_("renaming '%s' failed"), item->string); |
Miklos Vajna | bf98421 | 2008-11-03 19:26:18 +0100 | [diff] [blame] | 714 | } |
| 715 | for (i = 0; i < remote_branches.nr; i++) { |
| 716 | struct string_list_item *item = remote_branches.items + i; |
| 717 | |
| 718 | if (!item->util) |
| 719 | continue; |
| 720 | strbuf_reset(&buf); |
| 721 | strbuf_addstr(&buf, item->string); |
Brandon Williams | b537e0b | 2018-02-14 10:59:35 -0800 | [diff] [blame] | 722 | strbuf_splice(&buf, strlen("refs/remotes/"), strlen(rename.old_name), |
| 723 | rename.new_name, strlen(rename.new_name)); |
Miklos Vajna | bf98421 | 2008-11-03 19:26:18 +0100 | [diff] [blame] | 724 | strbuf_reset(&buf2); |
| 725 | strbuf_addstr(&buf2, item->util); |
Brandon Williams | b537e0b | 2018-02-14 10:59:35 -0800 | [diff] [blame] | 726 | strbuf_splice(&buf2, strlen("refs/remotes/"), strlen(rename.old_name), |
| 727 | rename.new_name, strlen(rename.new_name)); |
Miklos Vajna | bf98421 | 2008-11-03 19:26:18 +0100 | [diff] [blame] | 728 | strbuf_reset(&buf3); |
| 729 | strbuf_addf(&buf3, "remote: renamed %s to %s", |
| 730 | item->string, buf.buf); |
| 731 | if (create_symref(buf.buf, buf2.buf, buf3.buf)) |
Nguyễn Thái Ngọc Duy | bb16d5d | 2012-04-23 19:30:26 +0700 | [diff] [blame] | 732 | die(_("creating '%s' failed"), buf.buf); |
Miklos Vajna | bf98421 | 2008-11-03 19:26:18 +0100 | [diff] [blame] | 733 | } |
| 734 | return 0; |
| 735 | } |
| 736 | |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 737 | static int rm(int argc, const char **argv) |
| 738 | { |
| 739 | struct option options[] = { |
| 740 | OPT_END() |
| 741 | }; |
| 742 | struct remote *remote; |
Brandon Casey | f285a2d | 2008-10-09 14:12:12 -0500 | [diff] [blame] | 743 | struct strbuf buf = STRBUF_INIT; |
Shawn O. Pearce | 7ad2458 | 2008-06-01 00:28:04 -0400 | [diff] [blame] | 744 | struct known_remotes known_remotes = { NULL, NULL }; |
Thiago Farina | 183113a | 2010-07-04 16:46:19 -0300 | [diff] [blame] | 745 | struct string_list branches = STRING_LIST_INIT_DUP; |
| 746 | struct string_list skipped = STRING_LIST_INIT_DUP; |
Gary V. Vaughan | 66dbfd5 | 2010-05-14 09:31:33 +0000 | [diff] [blame] | 747 | struct branches_for_remote cb_data; |
Jay Soffian | e02f176 | 2009-02-03 12:51:12 -0500 | [diff] [blame] | 748 | int i, result; |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 749 | |
Gary V. Vaughan | 66dbfd5 | 2010-05-14 09:31:33 +0000 | [diff] [blame] | 750 | memset(&cb_data, 0, sizeof(cb_data)); |
| 751 | cb_data.branches = &branches; |
| 752 | cb_data.skipped = &skipped; |
| 753 | cb_data.keep = &known_remotes; |
| 754 | |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 755 | if (argc != 2) |
Tim Henigan | 4504107 | 2009-11-20 18:43:13 -0500 | [diff] [blame] | 756 | usage_with_options(builtin_remote_rm_usage, options); |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 757 | |
| 758 | remote = remote_get(argv[1]); |
Johannes Schindelin | e459b07 | 2017-01-19 22:20:02 +0100 | [diff] [blame] | 759 | if (!remote_is_configured(remote, 1)) |
Nguyễn Thái Ngọc Duy | bb16d5d | 2012-04-23 19:30:26 +0700 | [diff] [blame] | 760 | die(_("No such remote: %s"), argv[1]); |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 761 | |
Shawn O. Pearce | 7ad2458 | 2008-06-01 00:28:04 -0400 | [diff] [blame] | 762 | known_remotes.to_delete = remote; |
| 763 | for_each_remote(add_known_remote, &known_remotes); |
| 764 | |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 765 | read_branches(); |
| 766 | for (i = 0; i < branch_list.nr; i++) { |
Johannes Schindelin | c455c87 | 2008-07-21 19:03:49 +0100 | [diff] [blame] | 767 | struct string_list_item *item = branch_list.items + i; |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 768 | struct branch_info *info = item->util; |
Jay Soffian | e0cc81e | 2009-02-25 03:32:21 -0500 | [diff] [blame] | 769 | if (info->remote_name && !strcmp(info->remote_name, remote->name)) { |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 770 | const char *keys[] = { "remote", "merge", NULL }, **k; |
| 771 | for (k = keys; *k; k++) { |
| 772 | strbuf_reset(&buf); |
| 773 | strbuf_addf(&buf, "branch.%s.%s", |
Johannes Schindelin | c455c87 | 2008-07-21 19:03:49 +0100 | [diff] [blame] | 774 | item->string, *k); |
Ross Lagerwall | 20690b2 | 2017-02-18 00:23:41 +0000 | [diff] [blame] | 775 | result = git_config_set_gently(buf.buf, NULL); |
| 776 | if (result && result != CONFIG_NOTHING_SET) |
| 777 | die(_("could not unset '%s'"), buf.buf); |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 778 | } |
| 779 | } |
| 780 | } |
| 781 | |
| 782 | /* |
| 783 | * We cannot just pass a function to for_each_ref() which deletes |
| 784 | * the branches one by one, since for_each_ref() relies on cached |
| 785 | * refs, which are invalidated when deleting a branch. |
| 786 | */ |
Shawn O. Pearce | 7ad2458 | 2008-06-01 00:28:04 -0400 | [diff] [blame] | 787 | cb_data.remote = remote; |
Michael Haggerty | 45690a5 | 2015-05-25 18:38:41 +0000 | [diff] [blame] | 788 | result = for_each_ref(add_branch_for_removal, &cb_data); |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 789 | strbuf_release(&buf); |
| 790 | |
Jay Soffian | e02f176 | 2009-02-03 12:51:12 -0500 | [diff] [blame] | 791 | if (!result) |
Michael Haggerty | 91774af | 2017-11-05 09:42:06 +0100 | [diff] [blame] | 792 | result = delete_refs("remote: remove", &branches, REF_NO_DEREF); |
Michael Haggerty | e26cdf9 | 2015-05-25 18:38:42 +0000 | [diff] [blame] | 793 | string_list_clear(&branches, 0); |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 794 | |
Jay Soffian | 441adf0 | 2009-02-04 11:06:07 -0500 | [diff] [blame] | 795 | if (skipped.nr) { |
Nguyễn Thái Ngọc Duy | bb16d5d | 2012-04-23 19:30:26 +0700 | [diff] [blame] | 796 | fprintf_ln(stderr, |
| 797 | Q_("Note: A branch outside the refs/remotes/ hierarchy was not removed;\n" |
| 798 | "to delete it, use:", |
| 799 | "Note: Some branches outside the refs/remotes/ hierarchy were not removed;\n" |
| 800 | "to delete them, use:", |
| 801 | skipped.nr)); |
Jay Soffian | 441adf0 | 2009-02-04 11:06:07 -0500 | [diff] [blame] | 802 | for (i = 0; i < skipped.nr; i++) |
| 803 | fprintf(stderr, " git branch -d %s\n", |
| 804 | skipped.items[i].string); |
| 805 | } |
| 806 | string_list_clear(&skipped, 0); |
| 807 | |
Jens Lindström | b07bdd3 | 2014-05-23 12:28:43 +0200 | [diff] [blame] | 808 | if (!result) { |
| 809 | strbuf_addf(&buf, "remote.%s", remote->name); |
| 810 | if (git_config_rename_section(buf.buf, NULL) < 1) |
| 811 | return error(_("Could not remove config section '%s'"), buf.buf); |
| 812 | } |
| 813 | |
Jay Soffian | e02f176 | 2009-02-03 12:51:12 -0500 | [diff] [blame] | 814 | return result; |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 815 | } |
| 816 | |
Linus Torvalds | 2af202b | 2009-06-18 10:28:43 -0700 | [diff] [blame] | 817 | static void clear_push_info(void *util, const char *string) |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 818 | { |
Jay Soffian | e5dcbfd | 2009-02-25 03:32:28 -0500 | [diff] [blame] | 819 | struct push_info *info = util; |
| 820 | free(info->dest); |
| 821 | free(info); |
| 822 | } |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 823 | |
Jay Soffian | 8873323 | 2009-02-25 03:32:19 -0500 | [diff] [blame] | 824 | static void free_remote_ref_states(struct ref_states *states) |
| 825 | { |
Brandon Williams | b537e0b | 2018-02-14 10:59:35 -0800 | [diff] [blame] | 826 | string_list_clear(&states->new_refs, 0); |
Bert Wesarg | 92f676f | 2009-12-01 00:57:27 +0100 | [diff] [blame] | 827 | string_list_clear(&states->stale, 1); |
Jay Soffian | 8873323 | 2009-02-25 03:32:19 -0500 | [diff] [blame] | 828 | string_list_clear(&states->tracked, 0); |
Jay Soffian | e61e0cc | 2009-02-25 03:32:24 -0500 | [diff] [blame] | 829 | string_list_clear(&states->heads, 0); |
Jay Soffian | e5dcbfd | 2009-02-25 03:32:28 -0500 | [diff] [blame] | 830 | string_list_clear_func(&states->push, clear_push_info); |
Jay Soffian | 8873323 | 2009-02-25 03:32:19 -0500 | [diff] [blame] | 831 | } |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 832 | |
Jay Soffian | cca7c97 | 2009-02-25 03:32:22 -0500 | [diff] [blame] | 833 | static int append_ref_to_tracked_list(const char *refname, |
Michael Haggerty | 53dc95b | 2015-05-25 18:38:43 +0000 | [diff] [blame] | 834 | const struct object_id *oid, int flags, void *cb_data) |
Jay Soffian | cca7c97 | 2009-02-25 03:32:22 -0500 | [diff] [blame] | 835 | { |
| 836 | struct ref_states *states = cb_data; |
| 837 | struct refspec refspec; |
| 838 | |
Jay Soffian | 3bd9256 | 2009-02-25 03:32:23 -0500 | [diff] [blame] | 839 | if (flags & REF_ISSYMREF) |
| 840 | return 0; |
| 841 | |
Jay Soffian | cca7c97 | 2009-02-25 03:32:22 -0500 | [diff] [blame] | 842 | memset(&refspec, 0, sizeof(refspec)); |
| 843 | refspec.dst = (char *)refname; |
| 844 | if (!remote_find_tracking(states->remote, &refspec)) |
Julian Phillips | 1d2f80f | 2010-06-26 00:41:38 +0100 | [diff] [blame] | 845 | string_list_append(&states->tracked, abbrev_branch(refspec.src)); |
Jay Soffian | cca7c97 | 2009-02-25 03:32:22 -0500 | [diff] [blame] | 846 | |
| 847 | return 0; |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 848 | } |
| 849 | |
Olivier Marin | 67a7e2d | 2008-06-10 16:51:21 +0200 | [diff] [blame] | 850 | static int get_remote_ref_states(const char *name, |
| 851 | struct ref_states *states, |
| 852 | int query) |
| 853 | { |
| 854 | struct transport *transport; |
Jay Soffian | e0cc81e | 2009-02-25 03:32:21 -0500 | [diff] [blame] | 855 | const struct ref *remote_refs; |
Olivier Marin | 67a7e2d | 2008-06-10 16:51:21 +0200 | [diff] [blame] | 856 | |
| 857 | states->remote = remote_get(name); |
| 858 | if (!states->remote) |
Nguyễn Thái Ngọc Duy | bb16d5d | 2012-04-23 19:30:26 +0700 | [diff] [blame] | 859 | return error(_("No such remote: %s"), name); |
Olivier Marin | 67a7e2d | 2008-06-10 16:51:21 +0200 | [diff] [blame] | 860 | |
| 861 | read_branches(); |
| 862 | |
| 863 | if (query) { |
Chris Frey | 345a380 | 2009-06-25 17:21:35 -0400 | [diff] [blame] | 864 | transport = transport_get(states->remote, states->remote->url_nr > 0 ? |
Olivier Marin | 67a7e2d | 2008-06-10 16:51:21 +0200 | [diff] [blame] | 865 | states->remote->url[0] : NULL); |
Jay Soffian | e0cc81e | 2009-02-25 03:32:21 -0500 | [diff] [blame] | 866 | remote_refs = transport_get_remote_refs(transport); |
Olivier Marin | 67a7e2d | 2008-06-10 16:51:21 +0200 | [diff] [blame] | 867 | transport_disconnect(transport); |
| 868 | |
Jay Soffian | 7ecbbf8 | 2009-02-25 03:32:27 -0500 | [diff] [blame] | 869 | states->queried = 1; |
Jay Soffian | e61e0cc | 2009-02-25 03:32:24 -0500 | [diff] [blame] | 870 | if (query & GET_REF_STATES) |
| 871 | get_ref_states(remote_refs, states); |
| 872 | if (query & GET_HEAD_NAMES) |
| 873 | get_head_names(remote_refs, states); |
Jay Soffian | e5dcbfd | 2009-02-25 03:32:28 -0500 | [diff] [blame] | 874 | if (query & GET_PUSH_REF_STATES) |
| 875 | get_push_ref_states(remote_refs, states); |
Jay Soffian | 3bd9256 | 2009-02-25 03:32:23 -0500 | [diff] [blame] | 876 | } else { |
Michael Haggerty | 53dc95b | 2015-05-25 18:38:43 +0000 | [diff] [blame] | 877 | for_each_ref(append_ref_to_tracked_list, states); |
Michael Haggerty | 3383e19 | 2014-11-25 09:02:35 +0100 | [diff] [blame] | 878 | string_list_sort(&states->tracked); |
Jay Soffian | e5dcbfd | 2009-02-25 03:32:28 -0500 | [diff] [blame] | 879 | get_push_ref_states_noquery(states); |
Olivier Marin | 67a7e2d | 2008-06-10 16:51:21 +0200 | [diff] [blame] | 880 | } |
| 881 | |
| 882 | return 0; |
| 883 | } |
| 884 | |
Jay Soffian | 7ecbbf8 | 2009-02-25 03:32:27 -0500 | [diff] [blame] | 885 | struct show_info { |
| 886 | struct string_list *list; |
| 887 | struct ref_states *states; |
Jay Soffian | e5dcbfd | 2009-02-25 03:32:28 -0500 | [diff] [blame] | 888 | int width, width2; |
Jay Soffian | 7ecbbf8 | 2009-02-25 03:32:27 -0500 | [diff] [blame] | 889 | int any_rebase; |
| 890 | }; |
| 891 | |
Linus Torvalds | 2af202b | 2009-06-18 10:28:43 -0700 | [diff] [blame] | 892 | static int add_remote_to_show_info(struct string_list_item *item, void *cb_data) |
Olivier Marin | e7d5a97 | 2008-06-11 00:54:49 +0200 | [diff] [blame] | 893 | { |
Jay Soffian | 7ecbbf8 | 2009-02-25 03:32:27 -0500 | [diff] [blame] | 894 | struct show_info *info = cb_data; |
| 895 | int n = strlen(item->string); |
| 896 | if (n > info->width) |
| 897 | info->width = n; |
Julian Phillips | 78a395d | 2010-06-26 00:41:35 +0100 | [diff] [blame] | 898 | string_list_insert(info->list, item->string); |
Jay Soffian | 7ecbbf8 | 2009-02-25 03:32:27 -0500 | [diff] [blame] | 899 | return 0; |
| 900 | } |
Olivier Marin | e7d5a97 | 2008-06-11 00:54:49 +0200 | [diff] [blame] | 901 | |
Linus Torvalds | 2af202b | 2009-06-18 10:28:43 -0700 | [diff] [blame] | 902 | static int show_remote_info_item(struct string_list_item *item, void *cb_data) |
Jay Soffian | 7ecbbf8 | 2009-02-25 03:32:27 -0500 | [diff] [blame] | 903 | { |
| 904 | struct show_info *info = cb_data; |
| 905 | struct ref_states *states = info->states; |
| 906 | const char *name = item->string; |
Olivier Marin | e7d5a97 | 2008-06-11 00:54:49 +0200 | [diff] [blame] | 907 | |
Jay Soffian | 7ecbbf8 | 2009-02-25 03:32:27 -0500 | [diff] [blame] | 908 | if (states->queried) { |
| 909 | const char *fmt = "%s"; |
| 910 | const char *arg = ""; |
Brandon Williams | b537e0b | 2018-02-14 10:59:35 -0800 | [diff] [blame] | 911 | if (string_list_has_string(&states->new_refs, name)) { |
Nguyễn Thái Ngọc Duy | bb16d5d | 2012-04-23 19:30:26 +0700 | [diff] [blame] | 912 | fmt = _(" new (next fetch will store in remotes/%s)"); |
Jay Soffian | 7ecbbf8 | 2009-02-25 03:32:27 -0500 | [diff] [blame] | 913 | arg = states->remote->name; |
| 914 | } else if (string_list_has_string(&states->tracked, name)) |
Nguyễn Thái Ngọc Duy | bb16d5d | 2012-04-23 19:30:26 +0700 | [diff] [blame] | 915 | arg = _(" tracked"); |
Jay Soffian | 7ecbbf8 | 2009-02-25 03:32:27 -0500 | [diff] [blame] | 916 | else if (string_list_has_string(&states->stale, name)) |
Nguyễn Thái Ngọc Duy | bb16d5d | 2012-04-23 19:30:26 +0700 | [diff] [blame] | 917 | arg = _(" stale (use 'git remote prune' to remove)"); |
Jay Soffian | 7ecbbf8 | 2009-02-25 03:32:27 -0500 | [diff] [blame] | 918 | else |
Nguyễn Thái Ngọc Duy | bb16d5d | 2012-04-23 19:30:26 +0700 | [diff] [blame] | 919 | arg = _(" ???"); |
Jay Soffian | 7ecbbf8 | 2009-02-25 03:32:27 -0500 | [diff] [blame] | 920 | printf(" %-*s", info->width, name); |
| 921 | printf(fmt, arg); |
| 922 | printf("\n"); |
| 923 | } else |
| 924 | printf(" %s\n", name); |
| 925 | |
| 926 | return 0; |
| 927 | } |
| 928 | |
Linus Torvalds | 2af202b | 2009-06-18 10:28:43 -0700 | [diff] [blame] | 929 | static int add_local_to_show_info(struct string_list_item *branch_item, void *cb_data) |
Jay Soffian | 7ecbbf8 | 2009-02-25 03:32:27 -0500 | [diff] [blame] | 930 | { |
| 931 | struct show_info *show_info = cb_data; |
| 932 | struct ref_states *states = show_info->states; |
| 933 | struct branch_info *branch_info = branch_item->util; |
| 934 | struct string_list_item *item; |
| 935 | int n; |
| 936 | |
| 937 | if (!branch_info->merge.nr || !branch_info->remote_name || |
| 938 | strcmp(states->remote->name, branch_info->remote_name)) |
| 939 | return 0; |
| 940 | if ((n = strlen(branch_item->string)) > show_info->width) |
| 941 | show_info->width = n; |
| 942 | if (branch_info->rebase) |
| 943 | show_info->any_rebase = 1; |
| 944 | |
Julian Phillips | 78a395d | 2010-06-26 00:41:35 +0100 | [diff] [blame] | 945 | item = string_list_insert(show_info->list, branch_item->string); |
Jay Soffian | 7ecbbf8 | 2009-02-25 03:32:27 -0500 | [diff] [blame] | 946 | item->util = branch_info; |
| 947 | |
| 948 | return 0; |
| 949 | } |
| 950 | |
Linus Torvalds | 2af202b | 2009-06-18 10:28:43 -0700 | [diff] [blame] | 951 | static int show_local_info_item(struct string_list_item *item, void *cb_data) |
Jay Soffian | 7ecbbf8 | 2009-02-25 03:32:27 -0500 | [diff] [blame] | 952 | { |
| 953 | struct show_info *show_info = cb_data; |
| 954 | struct branch_info *branch_info = item->util; |
| 955 | struct string_list *merge = &branch_info->merge; |
Vasco Almeida | a1b467a | 2016-06-17 20:21:22 +0000 | [diff] [blame] | 956 | int width = show_info->width + 4; |
Jay Soffian | 7ecbbf8 | 2009-02-25 03:32:27 -0500 | [diff] [blame] | 957 | int i; |
| 958 | |
| 959 | if (branch_info->rebase && branch_info->merge.nr > 1) { |
Nguyễn Thái Ngọc Duy | bb16d5d | 2012-04-23 19:30:26 +0700 | [diff] [blame] | 960 | error(_("invalid branch.%s.merge; cannot rebase onto > 1 branch"), |
Jay Soffian | 7ecbbf8 | 2009-02-25 03:32:27 -0500 | [diff] [blame] | 961 | item->string); |
| 962 | return 0; |
| 963 | } |
| 964 | |
| 965 | printf(" %-*s ", show_info->width, item->string); |
| 966 | if (branch_info->rebase) { |
Vasco Almeida | 070b7e4 | 2016-06-17 20:20:50 +0000 | [diff] [blame] | 967 | printf_ln(branch_info->rebase == INTERACTIVE_REBASE |
| 968 | ? _("rebases interactively onto remote %s") |
| 969 | : _("rebases onto remote %s"), merge->items[0].string); |
Jay Soffian | 7ecbbf8 | 2009-02-25 03:32:27 -0500 | [diff] [blame] | 970 | return 0; |
| 971 | } else if (show_info->any_rebase) { |
Nguyễn Thái Ngọc Duy | bb16d5d | 2012-04-23 19:30:26 +0700 | [diff] [blame] | 972 | printf_ln(_(" merges with remote %s"), merge->items[0].string); |
Vasco Almeida | a1b467a | 2016-06-17 20:21:22 +0000 | [diff] [blame] | 973 | width++; |
Jay Soffian | 7ecbbf8 | 2009-02-25 03:32:27 -0500 | [diff] [blame] | 974 | } else { |
Nguyễn Thái Ngọc Duy | bb16d5d | 2012-04-23 19:30:26 +0700 | [diff] [blame] | 975 | printf_ln(_("merges with remote %s"), merge->items[0].string); |
Jay Soffian | 7ecbbf8 | 2009-02-25 03:32:27 -0500 | [diff] [blame] | 976 | } |
| 977 | for (i = 1; i < merge->nr; i++) |
Vasco Almeida | a1b467a | 2016-06-17 20:21:22 +0000 | [diff] [blame] | 978 | printf(_("%-*s and with remote %s\n"), width, "", |
Jay Soffian | 7ecbbf8 | 2009-02-25 03:32:27 -0500 | [diff] [blame] | 979 | merge->items[i].string); |
| 980 | |
| 981 | return 0; |
| 982 | } |
| 983 | |
Linus Torvalds | 2af202b | 2009-06-18 10:28:43 -0700 | [diff] [blame] | 984 | static int add_push_to_show_info(struct string_list_item *push_item, void *cb_data) |
Jay Soffian | e5dcbfd | 2009-02-25 03:32:28 -0500 | [diff] [blame] | 985 | { |
| 986 | struct show_info *show_info = cb_data; |
| 987 | struct push_info *push_info = push_item->util; |
| 988 | struct string_list_item *item; |
| 989 | int n; |
| 990 | if ((n = strlen(push_item->string)) > show_info->width) |
| 991 | show_info->width = n; |
| 992 | if ((n = strlen(push_info->dest)) > show_info->width2) |
| 993 | show_info->width2 = n; |
Julian Phillips | 1d2f80f | 2010-06-26 00:41:38 +0100 | [diff] [blame] | 994 | item = string_list_append(show_info->list, push_item->string); |
Jay Soffian | e5dcbfd | 2009-02-25 03:32:28 -0500 | [diff] [blame] | 995 | item->util = push_item->util; |
| 996 | return 0; |
| 997 | } |
| 998 | |
Jeff King | 48ef563 | 2009-03-22 04:59:20 -0400 | [diff] [blame] | 999 | /* |
| 1000 | * Sorting comparison for a string list that has push_info |
| 1001 | * structs in its util field |
| 1002 | */ |
| 1003 | static int cmp_string_with_push(const void *va, const void *vb) |
| 1004 | { |
| 1005 | const struct string_list_item *a = va; |
| 1006 | const struct string_list_item *b = vb; |
| 1007 | const struct push_info *a_push = a->util; |
| 1008 | const struct push_info *b_push = b->util; |
| 1009 | int cmp = strcmp(a->string, b->string); |
| 1010 | return cmp ? cmp : strcmp(a_push->dest, b_push->dest); |
| 1011 | } |
| 1012 | |
Linus Torvalds | 2af202b | 2009-06-18 10:28:43 -0700 | [diff] [blame] | 1013 | static int show_push_info_item(struct string_list_item *item, void *cb_data) |
Jay Soffian | e5dcbfd | 2009-02-25 03:32:28 -0500 | [diff] [blame] | 1014 | { |
| 1015 | struct show_info *show_info = cb_data; |
| 1016 | struct push_info *push_info = item->util; |
Nguyễn Thái Ngọc Duy | bb16d5d | 2012-04-23 19:30:26 +0700 | [diff] [blame] | 1017 | const char *src = item->string, *status = NULL; |
Jay Soffian | e5dcbfd | 2009-02-25 03:32:28 -0500 | [diff] [blame] | 1018 | |
| 1019 | switch (push_info->status) { |
| 1020 | case PUSH_STATUS_CREATE: |
Nguyễn Thái Ngọc Duy | bb16d5d | 2012-04-23 19:30:26 +0700 | [diff] [blame] | 1021 | status = _("create"); |
Jay Soffian | e5dcbfd | 2009-02-25 03:32:28 -0500 | [diff] [blame] | 1022 | break; |
| 1023 | case PUSH_STATUS_DELETE: |
Nguyễn Thái Ngọc Duy | bb16d5d | 2012-04-23 19:30:26 +0700 | [diff] [blame] | 1024 | status = _("delete"); |
| 1025 | src = _("(none)"); |
Jay Soffian | e5dcbfd | 2009-02-25 03:32:28 -0500 | [diff] [blame] | 1026 | break; |
| 1027 | case PUSH_STATUS_UPTODATE: |
Nguyễn Thái Ngọc Duy | bb16d5d | 2012-04-23 19:30:26 +0700 | [diff] [blame] | 1028 | status = _("up to date"); |
Jay Soffian | e5dcbfd | 2009-02-25 03:32:28 -0500 | [diff] [blame] | 1029 | break; |
| 1030 | case PUSH_STATUS_FASTFORWARD: |
Nguyễn Thái Ngọc Duy | bb16d5d | 2012-04-23 19:30:26 +0700 | [diff] [blame] | 1031 | status = _("fast-forwardable"); |
Jay Soffian | e5dcbfd | 2009-02-25 03:32:28 -0500 | [diff] [blame] | 1032 | break; |
| 1033 | case PUSH_STATUS_OUTOFDATE: |
Nguyễn Thái Ngọc Duy | bb16d5d | 2012-04-23 19:30:26 +0700 | [diff] [blame] | 1034 | status = _("local out of date"); |
Jay Soffian | e5dcbfd | 2009-02-25 03:32:28 -0500 | [diff] [blame] | 1035 | break; |
| 1036 | case PUSH_STATUS_NOTQUERIED: |
| 1037 | break; |
| 1038 | } |
Nguyễn Thái Ngọc Duy | bb16d5d | 2012-04-23 19:30:26 +0700 | [diff] [blame] | 1039 | if (status) { |
| 1040 | if (push_info->forced) |
| 1041 | printf_ln(_(" %-*s forces to %-*s (%s)"), show_info->width, src, |
| 1042 | show_info->width2, push_info->dest, status); |
| 1043 | else |
| 1044 | printf_ln(_(" %-*s pushes to %-*s (%s)"), show_info->width, src, |
| 1045 | show_info->width2, push_info->dest, status); |
| 1046 | } else { |
| 1047 | if (push_info->forced) |
| 1048 | printf_ln(_(" %-*s forces to %s"), show_info->width, src, |
| 1049 | push_info->dest); |
| 1050 | else |
| 1051 | printf_ln(_(" %-*s pushes to %s"), show_info->width, src, |
| 1052 | push_info->dest); |
| 1053 | } |
Olivier Marin | e7d5a97 | 2008-06-11 00:54:49 +0200 | [diff] [blame] | 1054 | return 0; |
| 1055 | } |
| 1056 | |
Michael Haggerty | ce2223f | 2013-10-30 06:33:02 +0100 | [diff] [blame] | 1057 | static int get_one_entry(struct remote *remote, void *priv) |
| 1058 | { |
| 1059 | struct string_list *list = priv; |
| 1060 | struct strbuf url_buf = STRBUF_INIT; |
| 1061 | const char **url; |
| 1062 | int i, url_nr; |
| 1063 | |
| 1064 | if (remote->url_nr > 0) { |
| 1065 | strbuf_addf(&url_buf, "%s (fetch)", remote->url[0]); |
| 1066 | string_list_append(list, remote->name)->util = |
| 1067 | strbuf_detach(&url_buf, NULL); |
| 1068 | } else |
| 1069 | string_list_append(list, remote->name)->util = NULL; |
| 1070 | if (remote->pushurl_nr) { |
| 1071 | url = remote->pushurl; |
| 1072 | url_nr = remote->pushurl_nr; |
| 1073 | } else { |
| 1074 | url = remote->url; |
| 1075 | url_nr = remote->url_nr; |
| 1076 | } |
| 1077 | for (i = 0; i < url_nr; i++) |
| 1078 | { |
| 1079 | strbuf_addf(&url_buf, "%s (push)", url[i]); |
| 1080 | string_list_append(list, remote->name)->util = |
| 1081 | strbuf_detach(&url_buf, NULL); |
| 1082 | } |
| 1083 | |
| 1084 | return 0; |
| 1085 | } |
| 1086 | |
| 1087 | static int show_all(void) |
| 1088 | { |
| 1089 | struct string_list list = STRING_LIST_INIT_NODUP; |
| 1090 | int result; |
| 1091 | |
| 1092 | list.strdup_strings = 1; |
| 1093 | result = for_each_remote(get_one_entry, &list); |
| 1094 | |
| 1095 | if (!result) { |
| 1096 | int i; |
| 1097 | |
Michael Haggerty | 3383e19 | 2014-11-25 09:02:35 +0100 | [diff] [blame] | 1098 | string_list_sort(&list); |
Michael Haggerty | ce2223f | 2013-10-30 06:33:02 +0100 | [diff] [blame] | 1099 | for (i = 0; i < list.nr; i++) { |
| 1100 | struct string_list_item *item = list.items + i; |
| 1101 | if (verbose) |
| 1102 | printf("%s\t%s\n", item->string, |
| 1103 | item->util ? (const char *)item->util : ""); |
| 1104 | else { |
| 1105 | if (i && !strcmp((item - 1)->string, item->string)) |
| 1106 | continue; |
| 1107 | printf("%s\n", item->string); |
| 1108 | } |
| 1109 | } |
| 1110 | } |
| 1111 | string_list_clear(&list, 1); |
| 1112 | return result; |
| 1113 | } |
| 1114 | |
Olivier Marin | 67a7e2d | 2008-06-10 16:51:21 +0200 | [diff] [blame] | 1115 | static int show(int argc, const char **argv) |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 1116 | { |
Jay Soffian | e61e0cc | 2009-02-25 03:32:24 -0500 | [diff] [blame] | 1117 | int no_query = 0, result = 0, query_flag = 0; |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 1118 | struct option options[] = { |
Stefan Beller | d5d09d4 | 2013-08-03 13:51:19 +0200 | [diff] [blame] | 1119 | OPT_BOOL('n', NULL, &no_query, N_("do not query remotes")), |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 1120 | OPT_END() |
| 1121 | }; |
| 1122 | struct ref_states states; |
Thiago Farina | 183113a | 2010-07-04 16:46:19 -0300 | [diff] [blame] | 1123 | struct string_list info_list = STRING_LIST_INIT_NODUP; |
Jay Soffian | 7ecbbf8 | 2009-02-25 03:32:27 -0500 | [diff] [blame] | 1124 | struct show_info info; |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 1125 | |
Tim Henigan | 4504107 | 2009-11-20 18:43:13 -0500 | [diff] [blame] | 1126 | argc = parse_options(argc, argv, NULL, options, builtin_remote_show_usage, |
Stephen Boyd | 3778292 | 2009-05-23 11:53:12 -0700 | [diff] [blame] | 1127 | 0); |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 1128 | |
Olivier Marin | 67a7e2d | 2008-06-10 16:51:21 +0200 | [diff] [blame] | 1129 | if (argc < 1) |
| 1130 | return show_all(); |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 1131 | |
Jay Soffian | e61e0cc | 2009-02-25 03:32:24 -0500 | [diff] [blame] | 1132 | if (!no_query) |
Jay Soffian | e5dcbfd | 2009-02-25 03:32:28 -0500 | [diff] [blame] | 1133 | query_flag = (GET_REF_STATES | GET_HEAD_NAMES | GET_PUSH_REF_STATES); |
Jay Soffian | e61e0cc | 2009-02-25 03:32:24 -0500 | [diff] [blame] | 1134 | |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 1135 | memset(&states, 0, sizeof(states)); |
Jay Soffian | 7ecbbf8 | 2009-02-25 03:32:27 -0500 | [diff] [blame] | 1136 | memset(&info, 0, sizeof(info)); |
| 1137 | info.states = &states; |
| 1138 | info.list = &info_list; |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 1139 | for (; argc; argc--, argv++) { |
Olivier Marin | 0ecfcb3 | 2008-06-10 16:51:08 +0200 | [diff] [blame] | 1140 | int i; |
Michael J Gruber | 857f8c3 | 2009-06-13 18:29:10 +0200 | [diff] [blame] | 1141 | const char **url; |
| 1142 | int url_nr; |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 1143 | |
Jay Soffian | e61e0cc | 2009-02-25 03:32:24 -0500 | [diff] [blame] | 1144 | get_remote_ref_states(*argv, &states, query_flag); |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 1145 | |
Nguyễn Thái Ngọc Duy | bb16d5d | 2012-04-23 19:30:26 +0700 | [diff] [blame] | 1146 | printf_ln(_("* remote %s"), *argv); |
| 1147 | printf_ln(_(" Fetch URL: %s"), states.remote->url_nr > 0 ? |
| 1148 | states.remote->url[0] : _("(no URL)")); |
Michael J Gruber | 857f8c3 | 2009-06-13 18:29:10 +0200 | [diff] [blame] | 1149 | if (states.remote->pushurl_nr) { |
| 1150 | url = states.remote->pushurl; |
| 1151 | url_nr = states.remote->pushurl_nr; |
| 1152 | } else { |
| 1153 | url = states.remote->url; |
| 1154 | url_nr = states.remote->url_nr; |
| 1155 | } |
Junio C Hamano | cd2b8ae | 2011-08-25 14:46:52 -0700 | [diff] [blame] | 1156 | for (i = 0; i < url_nr; i++) |
Ævar Arnfjörð Bjarmason | 66f5f6d | 2017-05-11 21:20:12 +0000 | [diff] [blame] | 1157 | /* |
| 1158 | * TRANSLATORS: the colon ':' should align |
| 1159 | * with the one in " Fetch URL: %s" |
| 1160 | * translation. |
| 1161 | */ |
Nguyễn Thái Ngọc Duy | bb16d5d | 2012-04-23 19:30:26 +0700 | [diff] [blame] | 1162 | printf_ln(_(" Push URL: %s"), url[i]); |
Michael J Gruber | 857f8c3 | 2009-06-13 18:29:10 +0200 | [diff] [blame] | 1163 | if (!i) |
Vasco Almeida | 7ba7b9a | 2016-06-17 20:21:21 +0000 | [diff] [blame] | 1164 | printf_ln(_(" Push URL: %s"), _("(no URL)")); |
Olivier Marin | e7d5a97 | 2008-06-11 00:54:49 +0200 | [diff] [blame] | 1165 | if (no_query) |
Vasco Almeida | 7ba7b9a | 2016-06-17 20:21:21 +0000 | [diff] [blame] | 1166 | printf_ln(_(" HEAD branch: %s"), _("(not queried)")); |
Jay Soffian | e61e0cc | 2009-02-25 03:32:24 -0500 | [diff] [blame] | 1167 | else if (!states.heads.nr) |
Vasco Almeida | 7ba7b9a | 2016-06-17 20:21:21 +0000 | [diff] [blame] | 1168 | printf_ln(_(" HEAD branch: %s"), _("(unknown)")); |
Jay Soffian | e61e0cc | 2009-02-25 03:32:24 -0500 | [diff] [blame] | 1169 | else if (states.heads.nr == 1) |
Nguyễn Thái Ngọc Duy | bb16d5d | 2012-04-23 19:30:26 +0700 | [diff] [blame] | 1170 | printf_ln(_(" HEAD branch: %s"), states.heads.items[0].string); |
Jay Soffian | e61e0cc | 2009-02-25 03:32:24 -0500 | [diff] [blame] | 1171 | else { |
Nguyễn Thái Ngọc Duy | bb16d5d | 2012-04-23 19:30:26 +0700 | [diff] [blame] | 1172 | printf(_(" HEAD branch (remote HEAD is ambiguous," |
| 1173 | " may be one of the following):\n")); |
Jay Soffian | e61e0cc | 2009-02-25 03:32:24 -0500 | [diff] [blame] | 1174 | for (i = 0; i < states.heads.nr; i++) |
| 1175 | printf(" %s\n", states.heads.items[i].string); |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 1176 | } |
Olivier Marin | 67a7e2d | 2008-06-10 16:51:21 +0200 | [diff] [blame] | 1177 | |
Jay Soffian | 7ecbbf8 | 2009-02-25 03:32:27 -0500 | [diff] [blame] | 1178 | /* remote branch info */ |
| 1179 | info.width = 0; |
Brandon Williams | b537e0b | 2018-02-14 10:59:35 -0800 | [diff] [blame] | 1180 | for_each_string_list(&states.new_refs, add_remote_to_show_info, &info); |
Julian Phillips | b684e97 | 2010-06-26 00:41:34 +0100 | [diff] [blame] | 1181 | for_each_string_list(&states.tracked, add_remote_to_show_info, &info); |
| 1182 | for_each_string_list(&states.stale, add_remote_to_show_info, &info); |
Jay Soffian | 7ecbbf8 | 2009-02-25 03:32:27 -0500 | [diff] [blame] | 1183 | if (info.list->nr) |
Nguyễn Thái Ngọc Duy | bb16d5d | 2012-04-23 19:30:26 +0700 | [diff] [blame] | 1184 | printf_ln(Q_(" Remote branch:%s", |
| 1185 | " Remote branches:%s", |
| 1186 | info.list->nr), |
| 1187 | no_query ? _(" (status not queried)") : ""); |
Julian Phillips | b684e97 | 2010-06-26 00:41:34 +0100 | [diff] [blame] | 1188 | for_each_string_list(info.list, show_remote_info_item, &info); |
Jay Soffian | 7ecbbf8 | 2009-02-25 03:32:27 -0500 | [diff] [blame] | 1189 | string_list_clear(info.list, 0); |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 1190 | |
Jay Soffian | 7ecbbf8 | 2009-02-25 03:32:27 -0500 | [diff] [blame] | 1191 | /* git pull info */ |
| 1192 | info.width = 0; |
| 1193 | info.any_rebase = 0; |
Julian Phillips | b684e97 | 2010-06-26 00:41:34 +0100 | [diff] [blame] | 1194 | for_each_string_list(&branch_list, add_local_to_show_info, &info); |
Jay Soffian | 7ecbbf8 | 2009-02-25 03:32:27 -0500 | [diff] [blame] | 1195 | if (info.list->nr) |
Nguyễn Thái Ngọc Duy | bb16d5d | 2012-04-23 19:30:26 +0700 | [diff] [blame] | 1196 | printf_ln(Q_(" Local branch configured for 'git pull':", |
| 1197 | " Local branches configured for 'git pull':", |
| 1198 | info.list->nr)); |
Julian Phillips | b684e97 | 2010-06-26 00:41:34 +0100 | [diff] [blame] | 1199 | for_each_string_list(info.list, show_local_info_item, &info); |
Jay Soffian | 7ecbbf8 | 2009-02-25 03:32:27 -0500 | [diff] [blame] | 1200 | string_list_clear(info.list, 0); |
Olivier Marin | 67a7e2d | 2008-06-10 16:51:21 +0200 | [diff] [blame] | 1201 | |
Jay Soffian | 7ecbbf8 | 2009-02-25 03:32:27 -0500 | [diff] [blame] | 1202 | /* git push info */ |
Jay Soffian | e5dcbfd | 2009-02-25 03:32:28 -0500 | [diff] [blame] | 1203 | if (states.remote->mirror) |
Nguyễn Thái Ngọc Duy | bb16d5d | 2012-04-23 19:30:26 +0700 | [diff] [blame] | 1204 | printf_ln(_(" Local refs will be mirrored by 'git push'")); |
Jay Soffian | e5dcbfd | 2009-02-25 03:32:28 -0500 | [diff] [blame] | 1205 | |
| 1206 | info.width = info.width2 = 0; |
Julian Phillips | b684e97 | 2010-06-26 00:41:34 +0100 | [diff] [blame] | 1207 | for_each_string_list(&states.push, add_push_to_show_info, &info); |
René Scharfe | 9ed0d8d | 2016-09-29 17:27:31 +0200 | [diff] [blame] | 1208 | QSORT(info.list->items, info.list->nr, cmp_string_with_push); |
Jay Soffian | e5dcbfd | 2009-02-25 03:32:28 -0500 | [diff] [blame] | 1209 | if (info.list->nr) |
Nguyễn Thái Ngọc Duy | bb16d5d | 2012-04-23 19:30:26 +0700 | [diff] [blame] | 1210 | printf_ln(Q_(" Local ref configured for 'git push'%s:", |
| 1211 | " Local refs configured for 'git push'%s:", |
| 1212 | info.list->nr), |
| 1213 | no_query ? _(" (status not queried)") : ""); |
Julian Phillips | b684e97 | 2010-06-26 00:41:34 +0100 | [diff] [blame] | 1214 | for_each_string_list(info.list, show_push_info_item, &info); |
Jay Soffian | e5dcbfd | 2009-02-25 03:32:28 -0500 | [diff] [blame] | 1215 | string_list_clear(info.list, 0); |
Olivier Marin | 67a7e2d | 2008-06-10 16:51:21 +0200 | [diff] [blame] | 1216 | |
Jay Soffian | 8873323 | 2009-02-25 03:32:19 -0500 | [diff] [blame] | 1217 | free_remote_ref_states(&states); |
Olivier Marin | 67a7e2d | 2008-06-10 16:51:21 +0200 | [diff] [blame] | 1218 | } |
| 1219 | |
| 1220 | return result; |
| 1221 | } |
| 1222 | |
Jay Soffian | bc14fac | 2009-02-25 03:32:25 -0500 | [diff] [blame] | 1223 | static int set_head(int argc, const char **argv) |
| 1224 | { |
| 1225 | int i, opt_a = 0, opt_d = 0, result = 0; |
| 1226 | struct strbuf buf = STRBUF_INIT, buf2 = STRBUF_INIT; |
| 1227 | char *head_name = NULL; |
| 1228 | |
| 1229 | struct option options[] = { |
Stefan Beller | d5d09d4 | 2013-08-03 13:51:19 +0200 | [diff] [blame] | 1230 | OPT_BOOL('a', "auto", &opt_a, |
| 1231 | N_("set refs/remotes/<name>/HEAD according to remote")), |
| 1232 | OPT_BOOL('d', "delete", &opt_d, |
| 1233 | N_("delete refs/remotes/<name>/HEAD")), |
Jay Soffian | bc14fac | 2009-02-25 03:32:25 -0500 | [diff] [blame] | 1234 | OPT_END() |
| 1235 | }; |
Tim Henigan | 4504107 | 2009-11-20 18:43:13 -0500 | [diff] [blame] | 1236 | argc = parse_options(argc, argv, NULL, options, builtin_remote_sethead_usage, |
Stephen Boyd | 3778292 | 2009-05-23 11:53:12 -0700 | [diff] [blame] | 1237 | 0); |
Jay Soffian | bc14fac | 2009-02-25 03:32:25 -0500 | [diff] [blame] | 1238 | if (argc) |
| 1239 | strbuf_addf(&buf, "refs/remotes/%s/HEAD", argv[0]); |
| 1240 | |
| 1241 | if (!opt_a && !opt_d && argc == 2) { |
| 1242 | head_name = xstrdup(argv[1]); |
| 1243 | } else if (opt_a && !opt_d && argc == 1) { |
| 1244 | struct ref_states states; |
| 1245 | memset(&states, 0, sizeof(states)); |
| 1246 | get_remote_ref_states(argv[0], &states, GET_HEAD_NAMES); |
| 1247 | if (!states.heads.nr) |
Nguyễn Thái Ngọc Duy | bb16d5d | 2012-04-23 19:30:26 +0700 | [diff] [blame] | 1248 | result |= error(_("Cannot determine remote HEAD")); |
Jay Soffian | bc14fac | 2009-02-25 03:32:25 -0500 | [diff] [blame] | 1249 | else if (states.heads.nr > 1) { |
Nguyễn Thái Ngọc Duy | bb16d5d | 2012-04-23 19:30:26 +0700 | [diff] [blame] | 1250 | result |= error(_("Multiple remote HEAD branches. " |
| 1251 | "Please choose one explicitly with:")); |
Jay Soffian | bc14fac | 2009-02-25 03:32:25 -0500 | [diff] [blame] | 1252 | for (i = 0; i < states.heads.nr; i++) |
| 1253 | fprintf(stderr, " git remote set-head %s %s\n", |
| 1254 | argv[0], states.heads.items[i].string); |
| 1255 | } else |
| 1256 | head_name = xstrdup(states.heads.items[0].string); |
| 1257 | free_remote_ref_states(&states); |
| 1258 | } else if (opt_d && !opt_a && argc == 1) { |
Michael Haggerty | 91774af | 2017-11-05 09:42:06 +0100 | [diff] [blame] | 1259 | if (delete_ref(NULL, buf.buf, NULL, REF_NO_DEREF)) |
Nguyễn Thái Ngọc Duy | bb16d5d | 2012-04-23 19:30:26 +0700 | [diff] [blame] | 1260 | result |= error(_("Could not delete %s"), buf.buf); |
Jay Soffian | bc14fac | 2009-02-25 03:32:25 -0500 | [diff] [blame] | 1261 | } else |
Tim Henigan | 4504107 | 2009-11-20 18:43:13 -0500 | [diff] [blame] | 1262 | usage_with_options(builtin_remote_sethead_usage, options); |
Jay Soffian | bc14fac | 2009-02-25 03:32:25 -0500 | [diff] [blame] | 1263 | |
| 1264 | if (head_name) { |
Jay Soffian | bc14fac | 2009-02-25 03:32:25 -0500 | [diff] [blame] | 1265 | strbuf_addf(&buf2, "refs/remotes/%s/%s", argv[0], head_name); |
| 1266 | /* make sure it's valid */ |
Nguyễn Thái Ngọc Duy | c689332 | 2011-11-13 17:22:14 +0700 | [diff] [blame] | 1267 | if (!ref_exists(buf2.buf)) |
Nguyễn Thái Ngọc Duy | bb16d5d | 2012-04-23 19:30:26 +0700 | [diff] [blame] | 1268 | result |= error(_("Not a valid ref: %s"), buf2.buf); |
Jay Soffian | bc14fac | 2009-02-25 03:32:25 -0500 | [diff] [blame] | 1269 | else if (create_symref(buf.buf, buf2.buf, "remote set-head")) |
Nguyễn Thái Ngọc Duy | bb16d5d | 2012-04-23 19:30:26 +0700 | [diff] [blame] | 1270 | result |= error(_("Could not setup %s"), buf.buf); |
Jay Soffian | bc14fac | 2009-02-25 03:32:25 -0500 | [diff] [blame] | 1271 | if (opt_a) |
| 1272 | printf("%s/HEAD set to %s\n", argv[0], head_name); |
| 1273 | free(head_name); |
| 1274 | } |
| 1275 | |
| 1276 | strbuf_release(&buf); |
| 1277 | strbuf_release(&buf2); |
| 1278 | return result; |
| 1279 | } |
| 1280 | |
Finn Arne Gangstad | b92c5f2 | 2009-04-03 11:02:37 +0200 | [diff] [blame] | 1281 | static int prune_remote(const char *remote, int dry_run) |
| 1282 | { |
Michael Haggerty | 8552943 | 2014-11-25 09:02:34 +0100 | [diff] [blame] | 1283 | int result = 0; |
Finn Arne Gangstad | b92c5f2 | 2009-04-03 11:02:37 +0200 | [diff] [blame] | 1284 | struct ref_states states; |
Michael Haggerty | fcce0da | 2014-11-25 09:02:33 +0100 | [diff] [blame] | 1285 | struct string_list refs_to_prune = STRING_LIST_INIT_NODUP; |
Michael Haggerty | 8552943 | 2014-11-25 09:02:34 +0100 | [diff] [blame] | 1286 | struct string_list_item *item; |
Finn Arne Gangstad | b92c5f2 | 2009-04-03 11:02:37 +0200 | [diff] [blame] | 1287 | const char *dangling_msg = dry_run |
Nguyễn Thái Ngọc Duy | bb16d5d | 2012-04-23 19:30:26 +0700 | [diff] [blame] | 1288 | ? _(" %s will become dangling!") |
| 1289 | : _(" %s has become dangling!"); |
Junio C Hamano | f8948e2 | 2009-02-08 23:27:10 -0800 | [diff] [blame] | 1290 | |
Olivier Marin | 67a7e2d | 2008-06-10 16:51:21 +0200 | [diff] [blame] | 1291 | memset(&states, 0, sizeof(states)); |
Finn Arne Gangstad | b92c5f2 | 2009-04-03 11:02:37 +0200 | [diff] [blame] | 1292 | get_remote_ref_states(remote, &states, GET_REF_STATES); |
Olivier Marin | 67a7e2d | 2008-06-10 16:51:21 +0200 | [diff] [blame] | 1293 | |
Michael Haggerty | 16d4fa3 | 2014-11-25 09:02:29 +0100 | [diff] [blame] | 1294 | if (!states.stale.nr) { |
| 1295 | free_remote_ref_states(&states); |
| 1296 | return 0; |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 1297 | } |
| 1298 | |
Michael Haggerty | 16d4fa3 | 2014-11-25 09:02:29 +0100 | [diff] [blame] | 1299 | printf_ln(_("Pruning %s"), remote); |
| 1300 | printf_ln(_("URL: %s"), |
| 1301 | states.remote->url_nr |
| 1302 | ? states.remote->url[0] |
| 1303 | : _("(no URL)")); |
| 1304 | |
Michael Haggerty | 8552943 | 2014-11-25 09:02:34 +0100 | [diff] [blame] | 1305 | for_each_string_list_item(item, &states.stale) |
| 1306 | string_list_append(&refs_to_prune, item->util); |
Michael Haggerty | 3383e19 | 2014-11-25 09:02:35 +0100 | [diff] [blame] | 1307 | string_list_sort(&refs_to_prune); |
Michael Haggerty | 28d3f21 | 2014-11-25 09:02:30 +0100 | [diff] [blame] | 1308 | |
Michael Haggerty | a122366 | 2015-06-22 16:02:58 +0200 | [diff] [blame] | 1309 | if (!dry_run) |
Michael Haggerty | 64da419 | 2017-05-22 16:17:38 +0200 | [diff] [blame] | 1310 | result |= delete_refs("remote: prune", &refs_to_prune, 0); |
Michael Haggerty | 16d4fa3 | 2014-11-25 09:02:29 +0100 | [diff] [blame] | 1311 | |
Michael Haggerty | 8552943 | 2014-11-25 09:02:34 +0100 | [diff] [blame] | 1312 | for_each_string_list_item(item, &states.stale) { |
| 1313 | const char *refname = item->util; |
Finn Arne Gangstad | b92c5f2 | 2009-04-03 11:02:37 +0200 | [diff] [blame] | 1314 | |
Nguyễn Thái Ngọc Duy | bb16d5d | 2012-04-23 19:30:26 +0700 | [diff] [blame] | 1315 | if (dry_run) |
| 1316 | printf_ln(_(" * [would prune] %s"), |
| 1317 | abbrev_ref(refname, "refs/remotes/")); |
| 1318 | else |
| 1319 | printf_ln(_(" * [pruned] %s"), |
| 1320 | abbrev_ref(refname, "refs/remotes/")); |
Finn Arne Gangstad | b92c5f2 | 2009-04-03 11:02:37 +0200 | [diff] [blame] | 1321 | } |
| 1322 | |
Michael Haggerty | fcce0da | 2014-11-25 09:02:33 +0100 | [diff] [blame] | 1323 | warn_dangling_symrefs(stdout, dangling_msg, &refs_to_prune); |
Jens Lindström | e6bea66 | 2014-05-23 12:30:25 +0200 | [diff] [blame] | 1324 | |
Michael Haggerty | fcce0da | 2014-11-25 09:02:33 +0100 | [diff] [blame] | 1325 | string_list_clear(&refs_to_prune, 0); |
Finn Arne Gangstad | b92c5f2 | 2009-04-03 11:02:37 +0200 | [diff] [blame] | 1326 | free_remote_ref_states(&states); |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 1327 | return result; |
| 1328 | } |
| 1329 | |
Michael Haggerty | ce2223f | 2013-10-30 06:33:02 +0100 | [diff] [blame] | 1330 | static int prune(int argc, const char **argv) |
| 1331 | { |
| 1332 | int dry_run = 0, result = 0; |
| 1333 | struct option options[] = { |
| 1334 | OPT__DRY_RUN(&dry_run, N_("dry run")), |
| 1335 | OPT_END() |
| 1336 | }; |
| 1337 | |
| 1338 | argc = parse_options(argc, argv, NULL, options, builtin_remote_prune_usage, |
| 1339 | 0); |
| 1340 | |
| 1341 | if (argc < 1) |
| 1342 | usage_with_options(builtin_remote_prune_usage, options); |
| 1343 | |
| 1344 | for (; argc; argc--, argv++) |
| 1345 | result |= prune_remote(*argv, dry_run); |
| 1346 | |
| 1347 | return result; |
| 1348 | } |
| 1349 | |
Björn Gustavsson | 8db3559 | 2009-11-10 09:21:32 +0100 | [diff] [blame] | 1350 | static int get_remote_default(const char *key, const char *value, void *priv) |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 1351 | { |
Björn Gustavsson | 8db3559 | 2009-11-10 09:21:32 +0100 | [diff] [blame] | 1352 | if (strcmp(key, "remotes.default") == 0) { |
| 1353 | int *found = priv; |
| 1354 | *found = 1; |
Johannes Schindelin | 84521ed | 2008-03-04 11:23:53 +0000 | [diff] [blame] | 1355 | } |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 1356 | return 0; |
| 1357 | } |
| 1358 | |
| 1359 | static int update(int argc, const char **argv) |
| 1360 | { |
Michael Haggerty | 90765fa | 2013-10-30 06:33:04 +0100 | [diff] [blame] | 1361 | int i, prune = -1; |
Finn Arne Gangstad | efa5480 | 2009-04-03 11:03:44 +0200 | [diff] [blame] | 1362 | struct option options[] = { |
Stefan Beller | d5d09d4 | 2013-08-03 13:51:19 +0200 | [diff] [blame] | 1363 | OPT_BOOL('p', "prune", &prune, |
| 1364 | N_("prune remotes after fetching")), |
Finn Arne Gangstad | efa5480 | 2009-04-03 11:03:44 +0200 | [diff] [blame] | 1365 | OPT_END() |
| 1366 | }; |
Michael Haggerty | 8607590 | 2013-10-30 06:33:03 +0100 | [diff] [blame] | 1367 | struct argv_array fetch_argv = ARGV_ARRAY_INIT; |
Björn Gustavsson | 8db3559 | 2009-11-10 09:21:32 +0100 | [diff] [blame] | 1368 | int default_defined = 0; |
Michael Haggerty | 8607590 | 2013-10-30 06:33:03 +0100 | [diff] [blame] | 1369 | int retval; |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 1370 | |
Tim Henigan | 4504107 | 2009-11-20 18:43:13 -0500 | [diff] [blame] | 1371 | argc = parse_options(argc, argv, NULL, options, builtin_remote_update_usage, |
Finn Arne Gangstad | efa5480 | 2009-04-03 11:03:44 +0200 | [diff] [blame] | 1372 | PARSE_OPT_KEEP_ARGV0); |
Björn Gustavsson | 8db3559 | 2009-11-10 09:21:32 +0100 | [diff] [blame] | 1373 | |
Michael Haggerty | 8607590 | 2013-10-30 06:33:03 +0100 | [diff] [blame] | 1374 | argv_array_push(&fetch_argv, "fetch"); |
Björn Gustavsson | 8db3559 | 2009-11-10 09:21:32 +0100 | [diff] [blame] | 1375 | |
Michael Haggerty | 90765fa | 2013-10-30 06:33:04 +0100 | [diff] [blame] | 1376 | if (prune != -1) |
| 1377 | argv_array_push(&fetch_argv, prune ? "--prune" : "--no-prune"); |
Björn Gustavsson | 8db3559 | 2009-11-10 09:21:32 +0100 | [diff] [blame] | 1378 | if (verbose) |
Michael Haggerty | 8607590 | 2013-10-30 06:33:03 +0100 | [diff] [blame] | 1379 | argv_array_push(&fetch_argv, "-v"); |
| 1380 | argv_array_push(&fetch_argv, "--multiple"); |
Björn Gustavsson | 4f2e842 | 2009-12-31 10:43:17 +0100 | [diff] [blame] | 1381 | if (argc < 2) |
Michael Haggerty | 8607590 | 2013-10-30 06:33:03 +0100 | [diff] [blame] | 1382 | argv_array_push(&fetch_argv, "default"); |
Björn Gustavsson | 4f2e842 | 2009-12-31 10:43:17 +0100 | [diff] [blame] | 1383 | for (i = 1; i < argc; i++) |
Michael Haggerty | 8607590 | 2013-10-30 06:33:03 +0100 | [diff] [blame] | 1384 | argv_array_push(&fetch_argv, argv[i]); |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 1385 | |
Michael Haggerty | 8607590 | 2013-10-30 06:33:03 +0100 | [diff] [blame] | 1386 | if (strcmp(fetch_argv.argv[fetch_argv.argc-1], "default") == 0) { |
Björn Gustavsson | 8db3559 | 2009-11-10 09:21:32 +0100 | [diff] [blame] | 1387 | git_config(get_remote_default, &default_defined); |
Michael Haggerty | 8607590 | 2013-10-30 06:33:03 +0100 | [diff] [blame] | 1388 | if (!default_defined) { |
| 1389 | argv_array_pop(&fetch_argv); |
| 1390 | argv_array_push(&fetch_argv, "--all"); |
| 1391 | } |
Johannes Schindelin | 84521ed | 2008-03-04 11:23:53 +0000 | [diff] [blame] | 1392 | } |
| 1393 | |
Michael Haggerty | 8607590 | 2013-10-30 06:33:03 +0100 | [diff] [blame] | 1394 | retval = run_command_v_opt(fetch_argv.argv, RUN_GIT_CMD); |
| 1395 | argv_array_clear(&fetch_argv); |
| 1396 | return retval; |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 1397 | } |
| 1398 | |
Jonathan Nieder | 3d8b694 | 2010-05-19 13:38:50 -0500 | [diff] [blame] | 1399 | static int remove_all_fetch_refspecs(const char *remote, const char *key) |
| 1400 | { |
Patrick Steinhardt | 30598ad | 2016-02-22 12:23:35 +0100 | [diff] [blame] | 1401 | return git_config_set_multivar_gently(key, NULL, NULL, 1); |
Jonathan Nieder | 3d8b694 | 2010-05-19 13:38:50 -0500 | [diff] [blame] | 1402 | } |
| 1403 | |
Patrick Steinhardt | ab5e4b6 | 2016-02-22 12:23:29 +0100 | [diff] [blame] | 1404 | static void add_branches(struct remote *remote, const char **branches, |
| 1405 | const char *key) |
Jonathan Nieder | 3d8b694 | 2010-05-19 13:38:50 -0500 | [diff] [blame] | 1406 | { |
| 1407 | const char *remotename = remote->name; |
| 1408 | int mirror = remote->mirror; |
| 1409 | struct strbuf refspec = STRBUF_INIT; |
| 1410 | |
| 1411 | for (; *branches; branches++) |
Patrick Steinhardt | ab5e4b6 | 2016-02-22 12:23:29 +0100 | [diff] [blame] | 1412 | add_branch(key, *branches, remotename, mirror, &refspec); |
Jonathan Nieder | 3d8b694 | 2010-05-19 13:38:50 -0500 | [diff] [blame] | 1413 | |
| 1414 | strbuf_release(&refspec); |
Jonathan Nieder | 3d8b694 | 2010-05-19 13:38:50 -0500 | [diff] [blame] | 1415 | } |
| 1416 | |
| 1417 | static int set_remote_branches(const char *remotename, const char **branches, |
| 1418 | int add_mode) |
| 1419 | { |
| 1420 | struct strbuf key = STRBUF_INIT; |
| 1421 | struct remote *remote; |
| 1422 | |
| 1423 | strbuf_addf(&key, "remote.%s.fetch", remotename); |
| 1424 | |
Jonathan Nieder | 3d8b694 | 2010-05-19 13:38:50 -0500 | [diff] [blame] | 1425 | remote = remote_get(remotename); |
Johannes Schindelin | e459b07 | 2017-01-19 22:20:02 +0100 | [diff] [blame] | 1426 | if (!remote_is_configured(remote, 1)) |
Thomas Gummerer | 674468b | 2016-02-16 10:47:50 +0100 | [diff] [blame] | 1427 | die(_("No such remote '%s'"), remotename); |
Jonathan Nieder | 3d8b694 | 2010-05-19 13:38:50 -0500 | [diff] [blame] | 1428 | |
| 1429 | if (!add_mode && remove_all_fetch_refspecs(remotename, key.buf)) { |
| 1430 | strbuf_release(&key); |
| 1431 | return 1; |
| 1432 | } |
Patrick Steinhardt | ab5e4b6 | 2016-02-22 12:23:29 +0100 | [diff] [blame] | 1433 | add_branches(remote, branches, key.buf); |
Jonathan Nieder | 3d8b694 | 2010-05-19 13:38:50 -0500 | [diff] [blame] | 1434 | |
| 1435 | strbuf_release(&key); |
| 1436 | return 0; |
| 1437 | } |
| 1438 | |
| 1439 | static int set_branches(int argc, const char **argv) |
| 1440 | { |
| 1441 | int add_mode = 0; |
| 1442 | struct option options[] = { |
Stefan Beller | d5d09d4 | 2013-08-03 13:51:19 +0200 | [diff] [blame] | 1443 | OPT_BOOL('\0', "add", &add_mode, N_("add branch")), |
Jonathan Nieder | 3d8b694 | 2010-05-19 13:38:50 -0500 | [diff] [blame] | 1444 | OPT_END() |
| 1445 | }; |
| 1446 | |
| 1447 | argc = parse_options(argc, argv, NULL, options, |
| 1448 | builtin_remote_setbranches_usage, 0); |
| 1449 | if (argc == 0) { |
Nguyễn Thái Ngọc Duy | bb16d5d | 2012-04-23 19:30:26 +0700 | [diff] [blame] | 1450 | error(_("no remote specified")); |
Junio C Hamano | 656cdf0 | 2011-11-06 21:12:59 -0800 | [diff] [blame] | 1451 | usage_with_options(builtin_remote_setbranches_usage, options); |
Jonathan Nieder | 3d8b694 | 2010-05-19 13:38:50 -0500 | [diff] [blame] | 1452 | } |
| 1453 | argv[argc] = NULL; |
| 1454 | |
| 1455 | return set_remote_branches(argv[0], argv + 1, add_mode); |
| 1456 | } |
| 1457 | |
Ben Boeckel | 96f78d3 | 2015-09-15 21:53:47 -0400 | [diff] [blame] | 1458 | static int get_url(int argc, const char **argv) |
| 1459 | { |
| 1460 | int i, push_mode = 0, all_mode = 0; |
| 1461 | const char *remotename = NULL; |
| 1462 | struct remote *remote; |
| 1463 | const char **url; |
| 1464 | int url_nr; |
| 1465 | struct option options[] = { |
| 1466 | OPT_BOOL('\0', "push", &push_mode, |
| 1467 | N_("query push URLs rather than fetch URLs")), |
| 1468 | OPT_BOOL('\0', "all", &all_mode, |
| 1469 | N_("return all URLs")), |
| 1470 | OPT_END() |
| 1471 | }; |
| 1472 | argc = parse_options(argc, argv, NULL, options, builtin_remote_geturl_usage, 0); |
| 1473 | |
| 1474 | if (argc != 1) |
| 1475 | usage_with_options(builtin_remote_geturl_usage, options); |
| 1476 | |
| 1477 | remotename = argv[0]; |
| 1478 | |
Ben Boeckel | 96f78d3 | 2015-09-15 21:53:47 -0400 | [diff] [blame] | 1479 | remote = remote_get(remotename); |
Johannes Schindelin | e459b07 | 2017-01-19 22:20:02 +0100 | [diff] [blame] | 1480 | if (!remote_is_configured(remote, 1)) |
Thomas Gummerer | 674468b | 2016-02-16 10:47:50 +0100 | [diff] [blame] | 1481 | die(_("No such remote '%s'"), remotename); |
Ben Boeckel | 96f78d3 | 2015-09-15 21:53:47 -0400 | [diff] [blame] | 1482 | |
| 1483 | url_nr = 0; |
| 1484 | if (push_mode) { |
| 1485 | url = remote->pushurl; |
| 1486 | url_nr = remote->pushurl_nr; |
| 1487 | } |
| 1488 | /* else fetch mode */ |
| 1489 | |
| 1490 | /* Use the fetch URL when no push URLs were found or requested. */ |
| 1491 | if (!url_nr) { |
| 1492 | url = remote->url; |
| 1493 | url_nr = remote->url_nr; |
| 1494 | } |
| 1495 | |
| 1496 | if (!url_nr) |
| 1497 | die(_("no URLs configured for remote '%s'"), remotename); |
| 1498 | |
| 1499 | if (all_mode) { |
| 1500 | for (i = 0; i < url_nr; i++) |
| 1501 | printf_ln("%s", url[i]); |
| 1502 | } else { |
| 1503 | printf_ln("%s", *url); |
| 1504 | } |
| 1505 | |
| 1506 | return 0; |
| 1507 | } |
| 1508 | |
Ilari Liusvaara | 433f2be | 2010-01-18 19:18:02 +0200 | [diff] [blame] | 1509 | static int set_url(int argc, const char **argv) |
| 1510 | { |
| 1511 | int i, push_mode = 0, add_mode = 0, delete_mode = 0; |
| 1512 | int matches = 0, negative_matches = 0; |
| 1513 | const char *remotename = NULL; |
| 1514 | const char *newurl = NULL; |
| 1515 | const char *oldurl = NULL; |
| 1516 | struct remote *remote; |
| 1517 | regex_t old_regex; |
| 1518 | const char **urlset; |
| 1519 | int urlset_nr; |
| 1520 | struct strbuf name_buf = STRBUF_INIT; |
| 1521 | struct option options[] = { |
Stefan Beller | d5d09d4 | 2013-08-03 13:51:19 +0200 | [diff] [blame] | 1522 | OPT_BOOL('\0', "push", &push_mode, |
| 1523 | N_("manipulate push URLs")), |
| 1524 | OPT_BOOL('\0', "add", &add_mode, |
| 1525 | N_("add URL")), |
| 1526 | OPT_BOOL('\0', "delete", &delete_mode, |
Nguyễn Thái Ngọc Duy | fbbae14 | 2012-08-20 19:32:35 +0700 | [diff] [blame] | 1527 | N_("delete URLs")), |
Ilari Liusvaara | 433f2be | 2010-01-18 19:18:02 +0200 | [diff] [blame] | 1528 | OPT_END() |
| 1529 | }; |
Felipe Contreras | c49904e | 2011-11-07 05:36:57 +0200 | [diff] [blame] | 1530 | argc = parse_options(argc, argv, NULL, options, builtin_remote_seturl_usage, |
Ilari Liusvaara | 433f2be | 2010-01-18 19:18:02 +0200 | [diff] [blame] | 1531 | PARSE_OPT_KEEP_ARGV0); |
| 1532 | |
| 1533 | if (add_mode && delete_mode) |
Nguyễn Thái Ngọc Duy | bb16d5d | 2012-04-23 19:30:26 +0700 | [diff] [blame] | 1534 | die(_("--add --delete doesn't make sense")); |
Ilari Liusvaara | 433f2be | 2010-01-18 19:18:02 +0200 | [diff] [blame] | 1535 | |
| 1536 | if (argc < 3 || argc > 4 || ((add_mode || delete_mode) && argc != 3)) |
| 1537 | usage_with_options(builtin_remote_seturl_usage, options); |
| 1538 | |
| 1539 | remotename = argv[1]; |
| 1540 | newurl = argv[2]; |
| 1541 | if (argc > 3) |
| 1542 | oldurl = argv[3]; |
| 1543 | |
| 1544 | if (delete_mode) |
| 1545 | oldurl = newurl; |
| 1546 | |
Ilari Liusvaara | 433f2be | 2010-01-18 19:18:02 +0200 | [diff] [blame] | 1547 | remote = remote_get(remotename); |
Johannes Schindelin | e459b07 | 2017-01-19 22:20:02 +0100 | [diff] [blame] | 1548 | if (!remote_is_configured(remote, 1)) |
Thomas Gummerer | 674468b | 2016-02-16 10:47:50 +0100 | [diff] [blame] | 1549 | die(_("No such remote '%s'"), remotename); |
Ilari Liusvaara | 433f2be | 2010-01-18 19:18:02 +0200 | [diff] [blame] | 1550 | |
| 1551 | if (push_mode) { |
| 1552 | strbuf_addf(&name_buf, "remote.%s.pushurl", remotename); |
| 1553 | urlset = remote->pushurl; |
| 1554 | urlset_nr = remote->pushurl_nr; |
| 1555 | } else { |
| 1556 | strbuf_addf(&name_buf, "remote.%s.url", remotename); |
| 1557 | urlset = remote->url; |
| 1558 | urlset_nr = remote->url_nr; |
| 1559 | } |
| 1560 | |
| 1561 | /* Special cases that add new entry. */ |
| 1562 | if ((!oldurl && !delete_mode) || add_mode) { |
| 1563 | if (add_mode) |
| 1564 | git_config_set_multivar(name_buf.buf, newurl, |
Patrick Steinhardt | 45ebdcc | 2016-02-22 12:23:28 +0100 | [diff] [blame] | 1565 | "^$", 0); |
Ilari Liusvaara | 433f2be | 2010-01-18 19:18:02 +0200 | [diff] [blame] | 1566 | else |
| 1567 | git_config_set(name_buf.buf, newurl); |
Rene Scharfe | 85af9f7 | 2017-08-30 20:00:27 +0200 | [diff] [blame] | 1568 | goto out; |
Ilari Liusvaara | 433f2be | 2010-01-18 19:18:02 +0200 | [diff] [blame] | 1569 | } |
| 1570 | |
| 1571 | /* Old URL specified. Demand that one matches. */ |
| 1572 | if (regcomp(&old_regex, oldurl, REG_EXTENDED)) |
Nguyễn Thái Ngọc Duy | bb16d5d | 2012-04-23 19:30:26 +0700 | [diff] [blame] | 1573 | die(_("Invalid old URL pattern: %s"), oldurl); |
Ilari Liusvaara | 433f2be | 2010-01-18 19:18:02 +0200 | [diff] [blame] | 1574 | |
| 1575 | for (i = 0; i < urlset_nr; i++) |
| 1576 | if (!regexec(&old_regex, urlset[i], 0, NULL, 0)) |
| 1577 | matches++; |
| 1578 | else |
| 1579 | negative_matches++; |
| 1580 | if (!delete_mode && !matches) |
Nguyễn Thái Ngọc Duy | bb16d5d | 2012-04-23 19:30:26 +0700 | [diff] [blame] | 1581 | die(_("No such URL found: %s"), oldurl); |
Ilari Liusvaara | 433f2be | 2010-01-18 19:18:02 +0200 | [diff] [blame] | 1582 | if (delete_mode && !negative_matches && !push_mode) |
Nguyễn Thái Ngọc Duy | bb16d5d | 2012-04-23 19:30:26 +0700 | [diff] [blame] | 1583 | die(_("Will not delete all non-push URLs")); |
Ilari Liusvaara | 433f2be | 2010-01-18 19:18:02 +0200 | [diff] [blame] | 1584 | |
| 1585 | regfree(&old_regex); |
| 1586 | |
| 1587 | if (!delete_mode) |
| 1588 | git_config_set_multivar(name_buf.buf, newurl, oldurl, 0); |
| 1589 | else |
| 1590 | git_config_set_multivar(name_buf.buf, NULL, oldurl, 1); |
Rene Scharfe | 85af9f7 | 2017-08-30 20:00:27 +0200 | [diff] [blame] | 1591 | out: |
| 1592 | strbuf_release(&name_buf); |
Ilari Liusvaara | 433f2be | 2010-01-18 19:18:02 +0200 | [diff] [blame] | 1593 | return 0; |
| 1594 | } |
| 1595 | |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 1596 | int cmd_remote(int argc, const char **argv, const char *prefix) |
| 1597 | { |
| 1598 | struct option options[] = { |
Nguyễn Thái Ngọc Duy | fbbae14 | 2012-08-20 19:32:35 +0700 | [diff] [blame] | 1599 | OPT__VERBOSE(&verbose, N_("be verbose; must be placed before a subcommand")), |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 1600 | OPT_END() |
| 1601 | }; |
| 1602 | int result; |
| 1603 | |
Stephen Boyd | 3778292 | 2009-05-23 11:53:12 -0700 | [diff] [blame] | 1604 | argc = parse_options(argc, argv, prefix, options, builtin_remote_usage, |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 1605 | PARSE_OPT_STOP_AT_NON_OPTION); |
| 1606 | |
| 1607 | if (argc < 1) |
| 1608 | result = show_all(); |
| 1609 | else if (!strcmp(argv[0], "add")) |
| 1610 | result = add(argc, argv); |
Miklos Vajna | bf98421 | 2008-11-03 19:26:18 +0100 | [diff] [blame] | 1611 | else if (!strcmp(argv[0], "rename")) |
| 1612 | result = mv(argc, argv); |
Nguyễn Thái Ngọc Duy | e17dba8 | 2012-09-06 19:25:23 +0700 | [diff] [blame] | 1613 | else if (!strcmp(argv[0], "rm") || !strcmp(argv[0], "remove")) |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 1614 | result = rm(argc, argv); |
Jay Soffian | bc14fac | 2009-02-25 03:32:25 -0500 | [diff] [blame] | 1615 | else if (!strcmp(argv[0], "set-head")) |
| 1616 | result = set_head(argc, argv); |
Jonathan Nieder | 3d8b694 | 2010-05-19 13:38:50 -0500 | [diff] [blame] | 1617 | else if (!strcmp(argv[0], "set-branches")) |
| 1618 | result = set_branches(argc, argv); |
Ben Boeckel | 96f78d3 | 2015-09-15 21:53:47 -0400 | [diff] [blame] | 1619 | else if (!strcmp(argv[0], "get-url")) |
| 1620 | result = get_url(argc, argv); |
Ilari Liusvaara | 433f2be | 2010-01-18 19:18:02 +0200 | [diff] [blame] | 1621 | else if (!strcmp(argv[0], "set-url")) |
| 1622 | result = set_url(argc, argv); |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 1623 | else if (!strcmp(argv[0], "show")) |
Olivier Marin | 67a7e2d | 2008-06-10 16:51:21 +0200 | [diff] [blame] | 1624 | result = show(argc, argv); |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 1625 | else if (!strcmp(argv[0], "prune")) |
Olivier Marin | 67a7e2d | 2008-06-10 16:51:21 +0200 | [diff] [blame] | 1626 | result = prune(argc, argv); |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 1627 | else if (!strcmp(argv[0], "update")) |
| 1628 | result = update(argc, argv); |
| 1629 | else { |
Nguyễn Thái Ngọc Duy | bb16d5d | 2012-04-23 19:30:26 +0700 | [diff] [blame] | 1630 | error(_("Unknown subcommand: %s"), argv[0]); |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 1631 | usage_with_options(builtin_remote_usage, options); |
| 1632 | } |
| 1633 | |
| 1634 | return result ? 1 : 0; |
| 1635 | } |