Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 1 | #include "cache.h" |
| 2 | #include "parse-options.h" |
| 3 | #include "transport.h" |
| 4 | #include "remote.h" |
Johannes Schindelin | c455c87 | 2008-07-21 19:03:49 +0100 | [diff] [blame] | 5 | #include "string-list.h" |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 6 | #include "strbuf.h" |
| 7 | #include "run-command.h" |
| 8 | #include "refs.h" |
| 9 | |
| 10 | static const char * const builtin_remote_usage[] = { |
Cheng Renquan | 357af14 | 2008-11-17 19:15:49 +0800 | [diff] [blame] | 11 | "git remote [-v | --verbose]", |
| 12 | "git remote add [-t <branch>] [-m <master>] [-f] [--mirror] <name> <url>", |
Miklos Vajna | bf98421 | 2008-11-03 19:26:18 +0100 | [diff] [blame] | 13 | "git remote rename <old> <new>", |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 14 | "git remote rm <name>", |
Tim Henigan | 4504107 | 2009-11-20 18:43:13 -0500 | [diff] [blame] | 15 | "git remote set-head <name> (-a | -d | <branch>)", |
| 16 | "git remote [-v | --verbose] show [-n] <name>", |
Cheng Renquan | 357af14 | 2008-11-17 19:15:49 +0800 | [diff] [blame] | 17 | "git remote prune [-n | --dry-run] <name>", |
Tim Henigan | 997c2a4 | 2009-11-15 14:46:25 -0500 | [diff] [blame] | 18 | "git remote [-v | --verbose] update [-p | --prune] [group | remote]", |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 19 | NULL |
| 20 | }; |
| 21 | |
Tim Henigan | 4504107 | 2009-11-20 18:43:13 -0500 | [diff] [blame] | 22 | static const char * const builtin_remote_add_usage[] = { |
| 23 | "git remote add [<options>] <name> <url>", |
| 24 | NULL |
| 25 | }; |
| 26 | |
| 27 | static const char * const builtin_remote_rename_usage[] = { |
| 28 | "git remote rename <old> <new>", |
| 29 | NULL |
| 30 | }; |
| 31 | |
| 32 | static const char * const builtin_remote_rm_usage[] = { |
| 33 | "git remote rm <name>", |
| 34 | NULL |
| 35 | }; |
| 36 | |
| 37 | static const char * const builtin_remote_sethead_usage[] = { |
| 38 | "git remote set-head <name> (-a | -d | <branch>])", |
| 39 | NULL |
| 40 | }; |
| 41 | |
| 42 | static const char * const builtin_remote_show_usage[] = { |
| 43 | "git remote show [<options>] <name>", |
| 44 | NULL |
| 45 | }; |
| 46 | |
| 47 | static const char * const builtin_remote_prune_usage[] = { |
| 48 | "git remote prune [<options>] <name>", |
| 49 | NULL |
| 50 | }; |
| 51 | |
| 52 | static const char * const builtin_remote_update_usage[] = { |
| 53 | "git remote update [<options>] [<group> | <remote>]...", |
| 54 | NULL |
| 55 | }; |
| 56 | |
Jay Soffian | e61e0cc | 2009-02-25 03:32:24 -0500 | [diff] [blame] | 57 | #define GET_REF_STATES (1<<0) |
| 58 | #define GET_HEAD_NAMES (1<<1) |
Jay Soffian | e5dcbfd | 2009-02-25 03:32:28 -0500 | [diff] [blame] | 59 | #define GET_PUSH_REF_STATES (1<<2) |
Jay Soffian | e61e0cc | 2009-02-25 03:32:24 -0500 | [diff] [blame] | 60 | |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 61 | static int verbose; |
| 62 | |
Jeff King | c4112bb | 2008-04-09 11:15:51 -0400 | [diff] [blame] | 63 | static int show_all(void); |
Finn Arne Gangstad | b92c5f2 | 2009-04-03 11:02:37 +0200 | [diff] [blame] | 64 | static int prune_remote(const char *remote, int dry_run); |
Jeff King | c4112bb | 2008-04-09 11:15:51 -0400 | [diff] [blame] | 65 | |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 66 | static inline int postfixcmp(const char *string, const char *postfix) |
| 67 | { |
| 68 | int len1 = strlen(string), len2 = strlen(postfix); |
| 69 | if (len1 < len2) |
| 70 | return 1; |
| 71 | return strcmp(string + len1 - len2, postfix); |
| 72 | } |
| 73 | |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 74 | static int opt_parse_track(const struct option *opt, const char *arg, int not) |
| 75 | { |
Johannes Schindelin | c455c87 | 2008-07-21 19:03:49 +0100 | [diff] [blame] | 76 | struct string_list *list = opt->value; |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 77 | if (not) |
Johannes Schindelin | c455c87 | 2008-07-21 19:03:49 +0100 | [diff] [blame] | 78 | string_list_clear(list, 0); |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 79 | else |
Johannes Schindelin | c455c87 | 2008-07-21 19:03:49 +0100 | [diff] [blame] | 80 | string_list_append(arg, list); |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 81 | return 0; |
| 82 | } |
| 83 | |
| 84 | static int fetch_remote(const char *name) |
| 85 | { |
Cheng Renquan | dbbd56f | 2008-11-18 19:04:02 +0800 | [diff] [blame] | 86 | const char *argv[] = { "fetch", name, NULL, NULL }; |
| 87 | if (verbose) { |
| 88 | argv[1] = "-v"; |
| 89 | argv[2] = name; |
| 90 | } |
Samuel Tardieu | 3000658 | 2008-03-09 13:37:55 +0100 | [diff] [blame] | 91 | printf("Updating %s\n", name); |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 92 | if (run_command_v_opt(argv, RUN_GIT_CMD)) |
| 93 | return error("Could not fetch %s", name); |
| 94 | return 0; |
| 95 | } |
| 96 | |
| 97 | static int add(int argc, const char **argv) |
| 98 | { |
| 99 | int fetch = 0, mirror = 0; |
Johannes Schindelin | c455c87 | 2008-07-21 19:03:49 +0100 | [diff] [blame] | 100 | struct string_list track = { NULL, 0, 0 }; |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 101 | const char *master = NULL; |
| 102 | struct remote *remote; |
Brandon Casey | f285a2d | 2008-10-09 14:12:12 -0500 | [diff] [blame] | 103 | struct strbuf buf = STRBUF_INIT, buf2 = STRBUF_INIT; |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 104 | const char *name, *url; |
| 105 | int i; |
| 106 | |
| 107 | struct option options[] = { |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 108 | OPT_BOOLEAN('f', "fetch", &fetch, "fetch the remote branches"), |
| 109 | OPT_CALLBACK('t', "track", &track, "branch", |
| 110 | "branch(es) to track", opt_parse_track), |
| 111 | OPT_STRING('m', "master", &master, "branch", "master branch"), |
| 112 | OPT_BOOLEAN(0, "mirror", &mirror, "no separate remotes"), |
| 113 | OPT_END() |
| 114 | }; |
| 115 | |
Tim Henigan | 4504107 | 2009-11-20 18:43:13 -0500 | [diff] [blame] | 116 | argc = parse_options(argc, argv, NULL, options, builtin_remote_add_usage, |
Stephen Boyd | 3778292 | 2009-05-23 11:53:12 -0700 | [diff] [blame] | 117 | 0); |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 118 | |
| 119 | if (argc < 2) |
Tim Henigan | 4504107 | 2009-11-20 18:43:13 -0500 | [diff] [blame] | 120 | usage_with_options(builtin_remote_add_usage, options); |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 121 | |
| 122 | name = argv[0]; |
| 123 | url = argv[1]; |
| 124 | |
| 125 | remote = remote_get(name); |
| 126 | if (remote && (remote->url_nr > 1 || strcmp(name, remote->url[0]) || |
| 127 | remote->fetch_refspec_nr)) |
| 128 | die("remote %s already exists.", name); |
| 129 | |
Jonas Fonseca | 24b6177 | 2008-04-13 11:56:54 +0200 | [diff] [blame] | 130 | strbuf_addf(&buf2, "refs/heads/test:refs/remotes/%s/test", name); |
| 131 | if (!valid_fetch_refspec(buf2.buf)) |
| 132 | die("'%s' is not a valid remote name", name); |
| 133 | |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 134 | strbuf_addf(&buf, "remote.%s.url", name); |
| 135 | if (git_config_set(buf.buf, url)) |
| 136 | return 1; |
| 137 | |
Jonas Fonseca | 24b6177 | 2008-04-13 11:56:54 +0200 | [diff] [blame] | 138 | strbuf_reset(&buf); |
| 139 | strbuf_addf(&buf, "remote.%s.fetch", name); |
| 140 | |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 141 | if (track.nr == 0) |
Johannes Schindelin | c455c87 | 2008-07-21 19:03:49 +0100 | [diff] [blame] | 142 | string_list_append("*", &track); |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 143 | for (i = 0; i < track.nr; i++) { |
Johannes Schindelin | c455c87 | 2008-07-21 19:03:49 +0100 | [diff] [blame] | 144 | struct string_list_item *item = track.items + i; |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 145 | |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 146 | strbuf_reset(&buf2); |
Jeff King | 1ce89cc | 2008-04-22 07:11:13 -0400 | [diff] [blame] | 147 | strbuf_addch(&buf2, '+'); |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 148 | if (mirror) |
| 149 | strbuf_addf(&buf2, "refs/%s:refs/%s", |
Johannes Schindelin | c455c87 | 2008-07-21 19:03:49 +0100 | [diff] [blame] | 150 | item->string, item->string); |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 151 | else |
| 152 | strbuf_addf(&buf2, "refs/heads/%s:refs/remotes/%s/%s", |
Johannes Schindelin | c455c87 | 2008-07-21 19:03:49 +0100 | [diff] [blame] | 153 | item->string, name, item->string); |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 154 | if (git_config_set_multivar(buf.buf, buf2.buf, "^$", 0)) |
| 155 | return 1; |
| 156 | } |
| 157 | |
Paolo Bonzini | 84bb2df | 2008-04-17 13:17:20 +0200 | [diff] [blame] | 158 | if (mirror) { |
| 159 | strbuf_reset(&buf); |
| 160 | strbuf_addf(&buf, "remote.%s.mirror", name); |
Johannes Schindelin | bc699af | 2008-08-02 21:38:56 +0200 | [diff] [blame] | 161 | if (git_config_set(buf.buf, "true")) |
Paolo Bonzini | 84bb2df | 2008-04-17 13:17:20 +0200 | [diff] [blame] | 162 | return 1; |
| 163 | } |
| 164 | |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 165 | if (fetch && fetch_remote(name)) |
| 166 | return 1; |
| 167 | |
| 168 | if (master) { |
| 169 | strbuf_reset(&buf); |
| 170 | strbuf_addf(&buf, "refs/remotes/%s/HEAD", name); |
| 171 | |
| 172 | strbuf_reset(&buf2); |
| 173 | strbuf_addf(&buf2, "refs/remotes/%s/%s", name, master); |
| 174 | |
| 175 | if (create_symref(buf.buf, buf2.buf, "remote add")) |
| 176 | return error("Could not setup master '%s'", master); |
| 177 | } |
| 178 | |
| 179 | strbuf_release(&buf); |
| 180 | strbuf_release(&buf2); |
Johannes Schindelin | c455c87 | 2008-07-21 19:03:49 +0100 | [diff] [blame] | 181 | string_list_clear(&track, 0); |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 182 | |
| 183 | return 0; |
| 184 | } |
| 185 | |
| 186 | struct branch_info { |
Jay Soffian | e0cc81e | 2009-02-25 03:32:21 -0500 | [diff] [blame] | 187 | char *remote_name; |
Johannes Schindelin | c455c87 | 2008-07-21 19:03:49 +0100 | [diff] [blame] | 188 | struct string_list merge; |
Jay Soffian | 7ecbbf8 | 2009-02-25 03:32:27 -0500 | [diff] [blame] | 189 | int rebase; |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 190 | }; |
| 191 | |
Johannes Schindelin | c455c87 | 2008-07-21 19:03:49 +0100 | [diff] [blame] | 192 | static struct string_list branch_list; |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 193 | |
Junio C Hamano | 72972eb | 2008-07-17 21:30:33 -0700 | [diff] [blame] | 194 | static const char *abbrev_ref(const char *name, const char *prefix) |
| 195 | { |
| 196 | const char *abbrev = skip_prefix(name, prefix); |
| 197 | if (abbrev) |
| 198 | return abbrev; |
| 199 | return name; |
| 200 | } |
| 201 | #define abbrev_branch(name) abbrev_ref((name), "refs/heads/") |
| 202 | |
Johannes Schindelin | ef90d6d | 2008-05-14 18:46:53 +0100 | [diff] [blame] | 203 | 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] | 204 | { |
| 205 | if (!prefixcmp(key, "branch.")) { |
Jay Soffian | 7ecbbf8 | 2009-02-25 03:32:27 -0500 | [diff] [blame] | 206 | const char *orig_key = key; |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 207 | char *name; |
Johannes Schindelin | c455c87 | 2008-07-21 19:03:49 +0100 | [diff] [blame] | 208 | struct string_list_item *item; |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 209 | struct branch_info *info; |
Jay Soffian | 7ecbbf8 | 2009-02-25 03:32:27 -0500 | [diff] [blame] | 210 | enum { REMOTE, MERGE, REBASE } type; |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 211 | |
| 212 | key += 7; |
| 213 | if (!postfixcmp(key, ".remote")) { |
| 214 | name = xstrndup(key, strlen(key) - 7); |
| 215 | type = REMOTE; |
| 216 | } else if (!postfixcmp(key, ".merge")) { |
| 217 | name = xstrndup(key, strlen(key) - 6); |
| 218 | type = MERGE; |
Jay Soffian | 7ecbbf8 | 2009-02-25 03:32:27 -0500 | [diff] [blame] | 219 | } else if (!postfixcmp(key, ".rebase")) { |
| 220 | name = xstrndup(key, strlen(key) - 7); |
| 221 | type = REBASE; |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 222 | } else |
| 223 | return 0; |
| 224 | |
Johannes Schindelin | c455c87 | 2008-07-21 19:03:49 +0100 | [diff] [blame] | 225 | item = string_list_insert(name, &branch_list); |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 226 | |
| 227 | if (!item->util) |
| 228 | item->util = xcalloc(sizeof(struct branch_info), 1); |
| 229 | info = item->util; |
| 230 | if (type == REMOTE) { |
Jay Soffian | e0cc81e | 2009-02-25 03:32:21 -0500 | [diff] [blame] | 231 | if (info->remote_name) |
Jay Soffian | 7ecbbf8 | 2009-02-25 03:32:27 -0500 | [diff] [blame] | 232 | warning("more than one %s", orig_key); |
Jay Soffian | e0cc81e | 2009-02-25 03:32:21 -0500 | [diff] [blame] | 233 | info->remote_name = xstrdup(value); |
Jay Soffian | 7ecbbf8 | 2009-02-25 03:32:27 -0500 | [diff] [blame] | 234 | } else if (type == MERGE) { |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 235 | char *space = strchr(value, ' '); |
Junio C Hamano | 72972eb | 2008-07-17 21:30:33 -0700 | [diff] [blame] | 236 | value = abbrev_branch(value); |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 237 | while (space) { |
| 238 | char *merge; |
| 239 | merge = xstrndup(value, space - value); |
Johannes Schindelin | c455c87 | 2008-07-21 19:03:49 +0100 | [diff] [blame] | 240 | string_list_append(merge, &info->merge); |
Junio C Hamano | 72972eb | 2008-07-17 21:30:33 -0700 | [diff] [blame] | 241 | value = abbrev_branch(space + 1); |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 242 | space = strchr(value, ' '); |
| 243 | } |
Johannes Schindelin | c455c87 | 2008-07-21 19:03:49 +0100 | [diff] [blame] | 244 | string_list_append(xstrdup(value), &info->merge); |
Jay Soffian | 7ecbbf8 | 2009-02-25 03:32:27 -0500 | [diff] [blame] | 245 | } else |
| 246 | info->rebase = git_config_bool(orig_key, value); |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 247 | } |
| 248 | return 0; |
| 249 | } |
| 250 | |
| 251 | static void read_branches(void) |
| 252 | { |
| 253 | if (branch_list.nr) |
| 254 | return; |
Johannes Schindelin | ef90d6d | 2008-05-14 18:46:53 +0100 | [diff] [blame] | 255 | git_config(config_read_branches, NULL); |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 256 | } |
| 257 | |
| 258 | struct ref_states { |
| 259 | struct remote *remote; |
Jay Soffian | e5dcbfd | 2009-02-25 03:32:28 -0500 | [diff] [blame] | 260 | struct string_list new, stale, tracked, heads, push; |
Jay Soffian | 7ecbbf8 | 2009-02-25 03:32:27 -0500 | [diff] [blame] | 261 | int queried; |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 262 | }; |
| 263 | |
Jay Soffian | e0cc81e | 2009-02-25 03:32:21 -0500 | [diff] [blame] | 264 | 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] | 265 | { |
| 266 | struct ref *fetch_map = NULL, **tail = &fetch_map; |
Jay Soffian | f2ef607 | 2009-11-10 00:03:31 -0500 | [diff] [blame] | 267 | struct ref *ref, *stale_refs; |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 268 | int i; |
| 269 | |
| 270 | for (i = 0; i < states->remote->fetch_refspec_nr; i++) |
Jay Soffian | e0cc81e | 2009-02-25 03:32:21 -0500 | [diff] [blame] | 271 | if (get_fetch_map(remote_refs, states->remote->fetch + i, &tail, 1)) |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 272 | die("Could not get fetch map for refspec %s", |
| 273 | states->remote->fetch_refspec[i]); |
| 274 | |
Bert Wesarg | 92f676f | 2009-12-01 00:57:27 +0100 | [diff] [blame] | 275 | states->new.strdup_strings = 1; |
| 276 | states->tracked.strdup_strings = 1; |
| 277 | states->stale.strdup_strings = 1; |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 278 | for (ref = fetch_map; ref; ref = ref->next) { |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 279 | unsigned char sha1[20]; |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 280 | if (!ref->peer_ref || read_ref(ref->peer_ref->name, sha1)) |
Jay Soffian | 7b9a5e2 | 2009-02-25 03:32:20 -0500 | [diff] [blame] | 281 | string_list_append(abbrev_branch(ref->name), &states->new); |
| 282 | else |
| 283 | string_list_append(abbrev_branch(ref->name), &states->tracked); |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 284 | } |
Jay Soffian | f2ef607 | 2009-11-10 00:03:31 -0500 | [diff] [blame] | 285 | stale_refs = get_stale_heads(states->remote, fetch_map); |
| 286 | for (ref = stale_refs; ref; ref = ref->next) { |
| 287 | struct string_list_item *item = |
| 288 | string_list_append(abbrev_branch(ref->name), &states->stale); |
| 289 | item->util = xstrdup(ref->name); |
| 290 | } |
| 291 | free_refs(stale_refs); |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 292 | free_refs(fetch_map); |
| 293 | |
Jay Soffian | 3bd9256 | 2009-02-25 03:32:23 -0500 | [diff] [blame] | 294 | sort_string_list(&states->new); |
| 295 | sort_string_list(&states->tracked); |
Johannes Schindelin | c455c87 | 2008-07-21 19:03:49 +0100 | [diff] [blame] | 296 | sort_string_list(&states->stale); |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 297 | |
| 298 | return 0; |
| 299 | } |
| 300 | |
Jay Soffian | e5dcbfd | 2009-02-25 03:32:28 -0500 | [diff] [blame] | 301 | struct push_info { |
| 302 | char *dest; |
| 303 | int forced; |
| 304 | enum { |
| 305 | PUSH_STATUS_CREATE = 0, |
| 306 | PUSH_STATUS_DELETE, |
| 307 | PUSH_STATUS_UPTODATE, |
| 308 | PUSH_STATUS_FASTFORWARD, |
| 309 | PUSH_STATUS_OUTOFDATE, |
| 310 | PUSH_STATUS_NOTQUERIED, |
| 311 | } status; |
| 312 | }; |
| 313 | |
| 314 | static int get_push_ref_states(const struct ref *remote_refs, |
| 315 | struct ref_states *states) |
| 316 | { |
| 317 | struct remote *remote = states->remote; |
Clemens Buchacher | 6d2bf96 | 2009-05-31 16:26:48 +0200 | [diff] [blame] | 318 | struct ref *ref, *local_refs, *push_map; |
Jay Soffian | e5dcbfd | 2009-02-25 03:32:28 -0500 | [diff] [blame] | 319 | if (remote->mirror) |
| 320 | return 0; |
| 321 | |
| 322 | local_refs = get_local_heads(); |
Clemens Buchacher | 6a01554 | 2009-05-27 22:13:43 +0200 | [diff] [blame] | 323 | push_map = copy_ref_list(remote_refs); |
Jay Soffian | e5dcbfd | 2009-02-25 03:32:28 -0500 | [diff] [blame] | 324 | |
Clemens Buchacher | 6d2bf96 | 2009-05-31 16:26:48 +0200 | [diff] [blame] | 325 | match_refs(local_refs, &push_map, remote->push_refspec_nr, |
Jay Soffian | e5dcbfd | 2009-02-25 03:32:28 -0500 | [diff] [blame] | 326 | remote->push_refspec, MATCH_REFS_NONE); |
| 327 | |
| 328 | states->push.strdup_strings = 1; |
| 329 | for (ref = push_map; ref; ref = ref->next) { |
| 330 | struct string_list_item *item; |
| 331 | struct push_info *info; |
| 332 | |
| 333 | if (!ref->peer_ref) |
| 334 | continue; |
| 335 | hashcpy(ref->new_sha1, ref->peer_ref->new_sha1); |
| 336 | |
| 337 | item = string_list_append(abbrev_branch(ref->peer_ref->name), |
| 338 | &states->push); |
| 339 | item->util = xcalloc(sizeof(struct push_info), 1); |
| 340 | info = item->util; |
| 341 | info->forced = ref->force; |
| 342 | info->dest = xstrdup(abbrev_branch(ref->name)); |
| 343 | |
| 344 | if (is_null_sha1(ref->new_sha1)) { |
| 345 | info->status = PUSH_STATUS_DELETE; |
| 346 | } else if (!hashcmp(ref->old_sha1, ref->new_sha1)) |
| 347 | info->status = PUSH_STATUS_UPTODATE; |
| 348 | else if (is_null_sha1(ref->old_sha1)) |
| 349 | info->status = PUSH_STATUS_CREATE; |
| 350 | else if (has_sha1_file(ref->old_sha1) && |
| 351 | ref_newer(ref->new_sha1, ref->old_sha1)) |
| 352 | info->status = PUSH_STATUS_FASTFORWARD; |
| 353 | else |
| 354 | info->status = PUSH_STATUS_OUTOFDATE; |
Jay Soffian | e5dcbfd | 2009-02-25 03:32:28 -0500 | [diff] [blame] | 355 | } |
| 356 | free_refs(local_refs); |
| 357 | free_refs(push_map); |
| 358 | return 0; |
| 359 | } |
| 360 | |
| 361 | static int get_push_ref_states_noquery(struct ref_states *states) |
| 362 | { |
| 363 | int i; |
| 364 | struct remote *remote = states->remote; |
| 365 | struct string_list_item *item; |
| 366 | struct push_info *info; |
| 367 | |
| 368 | if (remote->mirror) |
| 369 | return 0; |
| 370 | |
| 371 | states->push.strdup_strings = 1; |
| 372 | if (!remote->push_refspec_nr) { |
| 373 | item = string_list_append("(matching)", &states->push); |
| 374 | info = item->util = xcalloc(sizeof(struct push_info), 1); |
| 375 | info->status = PUSH_STATUS_NOTQUERIED; |
| 376 | info->dest = xstrdup(item->string); |
| 377 | } |
| 378 | for (i = 0; i < remote->push_refspec_nr; i++) { |
| 379 | struct refspec *spec = remote->push + i; |
Jay Soffian | e5dcbfd | 2009-02-25 03:32:28 -0500 | [diff] [blame] | 380 | if (spec->matching) |
| 381 | item = string_list_append("(matching)", &states->push); |
Junio C Hamano | 5ad6b02 | 2009-03-08 00:12:33 -0800 | [diff] [blame] | 382 | else if (strlen(spec->src)) |
Jay Soffian | e5dcbfd | 2009-02-25 03:32:28 -0500 | [diff] [blame] | 383 | item = string_list_append(spec->src, &states->push); |
| 384 | else |
| 385 | item = string_list_append("(delete)", &states->push); |
| 386 | |
| 387 | info = item->util = xcalloc(sizeof(struct push_info), 1); |
| 388 | info->forced = spec->force; |
| 389 | info->status = PUSH_STATUS_NOTQUERIED; |
Junio C Hamano | 5ad6b02 | 2009-03-08 00:12:33 -0800 | [diff] [blame] | 390 | info->dest = xstrdup(spec->dst ? spec->dst : item->string); |
Jay Soffian | e5dcbfd | 2009-02-25 03:32:28 -0500 | [diff] [blame] | 391 | } |
| 392 | return 0; |
| 393 | } |
| 394 | |
Jay Soffian | e61e0cc | 2009-02-25 03:32:24 -0500 | [diff] [blame] | 395 | static int get_head_names(const struct ref *remote_refs, struct ref_states *states) |
| 396 | { |
| 397 | struct ref *ref, *matches; |
| 398 | struct ref *fetch_map = NULL, **fetch_map_tail = &fetch_map; |
| 399 | struct refspec refspec; |
| 400 | |
| 401 | refspec.force = 0; |
| 402 | refspec.pattern = 1; |
Junio C Hamano | 5ad6b02 | 2009-03-08 00:12:33 -0800 | [diff] [blame] | 403 | refspec.src = refspec.dst = "refs/heads/*"; |
Jay Soffian | e61e0cc | 2009-02-25 03:32:24 -0500 | [diff] [blame] | 404 | states->heads.strdup_strings = 1; |
| 405 | get_fetch_map(remote_refs, &refspec, &fetch_map_tail, 0); |
| 406 | matches = guess_remote_head(find_ref_by_name(remote_refs, "HEAD"), |
| 407 | fetch_map, 1); |
Brian Gianforcaro | eeefa7c | 2009-09-01 01:35:10 -0400 | [diff] [blame] | 408 | for (ref = matches; ref; ref = ref->next) |
Jay Soffian | e61e0cc | 2009-02-25 03:32:24 -0500 | [diff] [blame] | 409 | string_list_append(abbrev_branch(ref->name), &states->heads); |
| 410 | |
| 411 | free_refs(fetch_map); |
| 412 | free_refs(matches); |
| 413 | |
| 414 | return 0; |
| 415 | } |
| 416 | |
Shawn O. Pearce | 7ad2458 | 2008-06-01 00:28:04 -0400 | [diff] [blame] | 417 | struct known_remote { |
| 418 | struct known_remote *next; |
| 419 | struct remote *remote; |
| 420 | }; |
| 421 | |
| 422 | struct known_remotes { |
| 423 | struct remote *to_delete; |
| 424 | struct known_remote *list; |
| 425 | }; |
| 426 | |
| 427 | static int add_known_remote(struct remote *remote, void *cb_data) |
| 428 | { |
| 429 | struct known_remotes *all = cb_data; |
| 430 | struct known_remote *r; |
| 431 | |
| 432 | if (!strcmp(all->to_delete->name, remote->name)) |
| 433 | return 0; |
| 434 | |
| 435 | r = xmalloc(sizeof(*r)); |
| 436 | r->remote = remote; |
| 437 | r->next = all->list; |
| 438 | all->list = r; |
| 439 | return 0; |
| 440 | } |
| 441 | |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 442 | struct branches_for_remote { |
Shawn O. Pearce | 7ad2458 | 2008-06-01 00:28:04 -0400 | [diff] [blame] | 443 | struct remote *remote; |
Jay Soffian | 441adf0 | 2009-02-04 11:06:07 -0500 | [diff] [blame] | 444 | struct string_list *branches, *skipped; |
Shawn O. Pearce | 7ad2458 | 2008-06-01 00:28:04 -0400 | [diff] [blame] | 445 | struct known_remotes *keep; |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 446 | }; |
| 447 | |
| 448 | static int add_branch_for_removal(const char *refname, |
| 449 | const unsigned char *sha1, int flags, void *cb_data) |
| 450 | { |
| 451 | struct branches_for_remote *branches = cb_data; |
Shawn O. Pearce | 7ad2458 | 2008-06-01 00:28:04 -0400 | [diff] [blame] | 452 | struct refspec refspec; |
Johannes Schindelin | c455c87 | 2008-07-21 19:03:49 +0100 | [diff] [blame] | 453 | struct string_list_item *item; |
Shawn O. Pearce | 7ad2458 | 2008-06-01 00:28:04 -0400 | [diff] [blame] | 454 | struct known_remote *kr; |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 455 | |
Shawn O. Pearce | 7ad2458 | 2008-06-01 00:28:04 -0400 | [diff] [blame] | 456 | memset(&refspec, 0, sizeof(refspec)); |
| 457 | refspec.dst = (char *)refname; |
| 458 | if (remote_find_tracking(branches->remote, &refspec)) |
| 459 | return 0; |
Johannes Schindelin | 3b9dcff | 2008-03-08 23:40:42 +0100 | [diff] [blame] | 460 | |
Shawn O. Pearce | 7ad2458 | 2008-06-01 00:28:04 -0400 | [diff] [blame] | 461 | /* don't delete a branch if another remote also uses it */ |
| 462 | for (kr = branches->keep->list; kr; kr = kr->next) { |
| 463 | memset(&refspec, 0, sizeof(refspec)); |
| 464 | refspec.dst = (char *)refname; |
| 465 | if (!remote_find_tracking(kr->remote, &refspec)) |
| 466 | return 0; |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 467 | } |
| 468 | |
Jay Soffian | 441adf0 | 2009-02-04 11:06:07 -0500 | [diff] [blame] | 469 | /* don't delete non-remote refs */ |
| 470 | if (prefixcmp(refname, "refs/remotes")) { |
| 471 | /* advise user how to delete local branches */ |
| 472 | if (!prefixcmp(refname, "refs/heads/")) |
| 473 | string_list_append(abbrev_branch(refname), |
| 474 | branches->skipped); |
| 475 | /* silently skip over other non-remote refs */ |
| 476 | return 0; |
| 477 | } |
| 478 | |
Shawn O. Pearce | 7ad2458 | 2008-06-01 00:28:04 -0400 | [diff] [blame] | 479 | /* make sure that symrefs are deleted */ |
| 480 | if (flags & REF_ISSYMREF) |
Daniel Lowe | 9db56f7 | 2008-11-10 16:07:52 -0500 | [diff] [blame] | 481 | return unlink(git_path("%s", refname)); |
Shawn O. Pearce | 7ad2458 | 2008-06-01 00:28:04 -0400 | [diff] [blame] | 482 | |
Johannes Schindelin | c455c87 | 2008-07-21 19:03:49 +0100 | [diff] [blame] | 483 | item = string_list_append(refname, branches->branches); |
Shawn O. Pearce | 7ad2458 | 2008-06-01 00:28:04 -0400 | [diff] [blame] | 484 | item->util = xmalloc(20); |
| 485 | hashcpy(item->util, sha1); |
| 486 | |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 487 | return 0; |
| 488 | } |
| 489 | |
Miklos Vajna | bf98421 | 2008-11-03 19:26:18 +0100 | [diff] [blame] | 490 | struct rename_info { |
| 491 | const char *old; |
| 492 | const char *new; |
| 493 | struct string_list *remote_branches; |
| 494 | }; |
| 495 | |
| 496 | static int read_remote_branches(const char *refname, |
| 497 | const unsigned char *sha1, int flags, void *cb_data) |
| 498 | { |
| 499 | struct rename_info *rename = cb_data; |
| 500 | struct strbuf buf = STRBUF_INIT; |
| 501 | struct string_list_item *item; |
| 502 | int flag; |
| 503 | unsigned char orig_sha1[20]; |
| 504 | const char *symref; |
| 505 | |
| 506 | strbuf_addf(&buf, "refs/remotes/%s", rename->old); |
Brian Gianforcaro | eeefa7c | 2009-09-01 01:35:10 -0400 | [diff] [blame] | 507 | if (!prefixcmp(refname, buf.buf)) { |
Miklos Vajna | bf98421 | 2008-11-03 19:26:18 +0100 | [diff] [blame] | 508 | item = string_list_append(xstrdup(refname), rename->remote_branches); |
| 509 | symref = resolve_ref(refname, orig_sha1, 1, &flag); |
| 510 | if (flag & REF_ISSYMREF) |
| 511 | item->util = xstrdup(symref); |
| 512 | else |
| 513 | item->util = NULL; |
| 514 | } |
| 515 | |
| 516 | return 0; |
| 517 | } |
| 518 | |
Miklos Vajna | 1dd1239 | 2008-11-10 21:43:01 +0100 | [diff] [blame] | 519 | static int migrate_file(struct remote *remote) |
| 520 | { |
| 521 | struct strbuf buf = STRBUF_INIT; |
| 522 | int i; |
| 523 | char *path = NULL; |
| 524 | |
| 525 | strbuf_addf(&buf, "remote.%s.url", remote->name); |
| 526 | for (i = 0; i < remote->url_nr; i++) |
| 527 | if (git_config_set_multivar(buf.buf, remote->url[i], "^$", 0)) |
| 528 | return error("Could not append '%s' to '%s'", |
| 529 | remote->url[i], buf.buf); |
| 530 | strbuf_reset(&buf); |
| 531 | strbuf_addf(&buf, "remote.%s.push", remote->name); |
| 532 | for (i = 0; i < remote->push_refspec_nr; i++) |
| 533 | if (git_config_set_multivar(buf.buf, remote->push_refspec[i], "^$", 0)) |
| 534 | return error("Could not append '%s' to '%s'", |
| 535 | remote->push_refspec[i], buf.buf); |
| 536 | strbuf_reset(&buf); |
| 537 | strbuf_addf(&buf, "remote.%s.fetch", remote->name); |
| 538 | for (i = 0; i < remote->fetch_refspec_nr; i++) |
| 539 | if (git_config_set_multivar(buf.buf, remote->fetch_refspec[i], "^$", 0)) |
| 540 | return error("Could not append '%s' to '%s'", |
| 541 | remote->fetch_refspec[i], buf.buf); |
| 542 | if (remote->origin == REMOTE_REMOTES) |
| 543 | path = git_path("remotes/%s", remote->name); |
| 544 | else if (remote->origin == REMOTE_BRANCHES) |
| 545 | path = git_path("branches/%s", remote->name); |
Alex Riesen | 691f1a2 | 2009-04-29 23:22:56 +0200 | [diff] [blame] | 546 | if (path) |
| 547 | unlink_or_warn(path); |
Miklos Vajna | 1dd1239 | 2008-11-10 21:43:01 +0100 | [diff] [blame] | 548 | return 0; |
| 549 | } |
| 550 | |
Miklos Vajna | bf98421 | 2008-11-03 19:26:18 +0100 | [diff] [blame] | 551 | static int mv(int argc, const char **argv) |
| 552 | { |
| 553 | struct option options[] = { |
| 554 | OPT_END() |
| 555 | }; |
| 556 | struct remote *oldremote, *newremote; |
| 557 | struct strbuf buf = STRBUF_INIT, buf2 = STRBUF_INIT, buf3 = STRBUF_INIT; |
| 558 | struct string_list remote_branches = { NULL, 0, 0, 0 }; |
| 559 | struct rename_info rename; |
| 560 | int i; |
| 561 | |
| 562 | if (argc != 3) |
Tim Henigan | 4504107 | 2009-11-20 18:43:13 -0500 | [diff] [blame] | 563 | usage_with_options(builtin_remote_rename_usage, options); |
Miklos Vajna | bf98421 | 2008-11-03 19:26:18 +0100 | [diff] [blame] | 564 | |
| 565 | rename.old = argv[1]; |
| 566 | rename.new = argv[2]; |
| 567 | rename.remote_branches = &remote_branches; |
| 568 | |
| 569 | oldremote = remote_get(rename.old); |
| 570 | if (!oldremote) |
| 571 | die("No such remote: %s", rename.old); |
| 572 | |
Miklos Vajna | 1dd1239 | 2008-11-10 21:43:01 +0100 | [diff] [blame] | 573 | if (!strcmp(rename.old, rename.new) && oldremote->origin != REMOTE_CONFIG) |
| 574 | return migrate_file(oldremote); |
| 575 | |
Miklos Vajna | bf98421 | 2008-11-03 19:26:18 +0100 | [diff] [blame] | 576 | newremote = remote_get(rename.new); |
| 577 | if (newremote && (newremote->url_nr > 1 || newremote->fetch_refspec_nr)) |
| 578 | die("remote %s already exists.", rename.new); |
| 579 | |
| 580 | strbuf_addf(&buf, "refs/heads/test:refs/remotes/%s/test", rename.new); |
| 581 | if (!valid_fetch_refspec(buf.buf)) |
| 582 | die("'%s' is not a valid remote name", rename.new); |
| 583 | |
| 584 | strbuf_reset(&buf); |
| 585 | strbuf_addf(&buf, "remote.%s", rename.old); |
| 586 | strbuf_addf(&buf2, "remote.%s", rename.new); |
| 587 | if (git_config_rename_section(buf.buf, buf2.buf) < 1) |
| 588 | return error("Could not rename config section '%s' to '%s'", |
| 589 | buf.buf, buf2.buf); |
| 590 | |
| 591 | strbuf_reset(&buf); |
| 592 | strbuf_addf(&buf, "remote.%s.fetch", rename.new); |
| 593 | if (git_config_set_multivar(buf.buf, NULL, NULL, 1)) |
| 594 | return error("Could not remove config section '%s'", buf.buf); |
| 595 | for (i = 0; i < oldremote->fetch_refspec_nr; i++) { |
| 596 | char *ptr; |
| 597 | |
| 598 | strbuf_reset(&buf2); |
| 599 | strbuf_addstr(&buf2, oldremote->fetch_refspec[i]); |
| 600 | ptr = strstr(buf2.buf, rename.old); |
| 601 | if (ptr) |
| 602 | strbuf_splice(&buf2, ptr-buf2.buf, strlen(rename.old), |
| 603 | rename.new, strlen(rename.new)); |
| 604 | if (git_config_set_multivar(buf.buf, buf2.buf, "^$", 0)) |
| 605 | return error("Could not append '%s'", buf.buf); |
| 606 | } |
| 607 | |
| 608 | read_branches(); |
| 609 | for (i = 0; i < branch_list.nr; i++) { |
| 610 | struct string_list_item *item = branch_list.items + i; |
| 611 | struct branch_info *info = item->util; |
Jay Soffian | e0cc81e | 2009-02-25 03:32:21 -0500 | [diff] [blame] | 612 | if (info->remote_name && !strcmp(info->remote_name, rename.old)) { |
Miklos Vajna | bf98421 | 2008-11-03 19:26:18 +0100 | [diff] [blame] | 613 | strbuf_reset(&buf); |
| 614 | strbuf_addf(&buf, "branch.%s.remote", item->string); |
| 615 | if (git_config_set(buf.buf, rename.new)) { |
| 616 | return error("Could not set '%s'", buf.buf); |
| 617 | } |
| 618 | } |
| 619 | } |
| 620 | |
| 621 | /* |
| 622 | * First remove symrefs, then rename the rest, finally create |
| 623 | * the new symrefs. |
| 624 | */ |
| 625 | for_each_ref(read_remote_branches, &rename); |
| 626 | for (i = 0; i < remote_branches.nr; i++) { |
| 627 | struct string_list_item *item = remote_branches.items + i; |
| 628 | int flag = 0; |
| 629 | unsigned char sha1[20]; |
Miklos Vajna | bf98421 | 2008-11-03 19:26:18 +0100 | [diff] [blame] | 630 | |
Benjamin Kramer | eb3a9dd | 2009-03-07 21:02:10 +0100 | [diff] [blame] | 631 | resolve_ref(item->string, sha1, 1, &flag); |
Miklos Vajna | bf98421 | 2008-11-03 19:26:18 +0100 | [diff] [blame] | 632 | if (!(flag & REF_ISSYMREF)) |
| 633 | continue; |
| 634 | if (delete_ref(item->string, NULL, REF_NODEREF)) |
| 635 | die("deleting '%s' failed", item->string); |
| 636 | } |
| 637 | for (i = 0; i < remote_branches.nr; i++) { |
| 638 | struct string_list_item *item = remote_branches.items + i; |
| 639 | |
| 640 | if (item->util) |
| 641 | continue; |
| 642 | strbuf_reset(&buf); |
| 643 | strbuf_addstr(&buf, item->string); |
| 644 | strbuf_splice(&buf, strlen("refs/remotes/"), strlen(rename.old), |
| 645 | rename.new, strlen(rename.new)); |
| 646 | strbuf_reset(&buf2); |
| 647 | strbuf_addf(&buf2, "remote: renamed %s to %s", |
| 648 | item->string, buf.buf); |
| 649 | if (rename_ref(item->string, buf.buf, buf2.buf)) |
| 650 | die("renaming '%s' failed", item->string); |
| 651 | } |
| 652 | for (i = 0; i < remote_branches.nr; i++) { |
| 653 | struct string_list_item *item = remote_branches.items + i; |
| 654 | |
| 655 | if (!item->util) |
| 656 | continue; |
| 657 | strbuf_reset(&buf); |
| 658 | strbuf_addstr(&buf, item->string); |
| 659 | strbuf_splice(&buf, strlen("refs/remotes/"), strlen(rename.old), |
| 660 | rename.new, strlen(rename.new)); |
| 661 | strbuf_reset(&buf2); |
| 662 | strbuf_addstr(&buf2, item->util); |
| 663 | strbuf_splice(&buf2, strlen("refs/remotes/"), strlen(rename.old), |
| 664 | rename.new, strlen(rename.new)); |
| 665 | strbuf_reset(&buf3); |
| 666 | strbuf_addf(&buf3, "remote: renamed %s to %s", |
| 667 | item->string, buf.buf); |
| 668 | if (create_symref(buf.buf, buf2.buf, buf3.buf)) |
| 669 | die("creating '%s' failed", buf.buf); |
| 670 | } |
| 671 | return 0; |
| 672 | } |
| 673 | |
Johannes Schindelin | c455c87 | 2008-07-21 19:03:49 +0100 | [diff] [blame] | 674 | static int remove_branches(struct string_list *branches) |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 675 | { |
| 676 | int i, result = 0; |
| 677 | for (i = 0; i < branches->nr; i++) { |
Johannes Schindelin | c455c87 | 2008-07-21 19:03:49 +0100 | [diff] [blame] | 678 | struct string_list_item *item = branches->items + i; |
| 679 | const char *refname = item->string; |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 680 | unsigned char *sha1 = item->util; |
| 681 | |
Miklos Vajna | eca35a2 | 2008-10-26 03:33:56 +0100 | [diff] [blame] | 682 | if (delete_ref(refname, sha1, 0)) |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 683 | result |= error("Could not remove branch %s", refname); |
| 684 | } |
| 685 | return result; |
| 686 | } |
| 687 | |
| 688 | static int rm(int argc, const char **argv) |
| 689 | { |
| 690 | struct option options[] = { |
| 691 | OPT_END() |
| 692 | }; |
| 693 | struct remote *remote; |
Brandon Casey | f285a2d | 2008-10-09 14:12:12 -0500 | [diff] [blame] | 694 | struct strbuf buf = STRBUF_INIT; |
Shawn O. Pearce | 7ad2458 | 2008-06-01 00:28:04 -0400 | [diff] [blame] | 695 | struct known_remotes known_remotes = { NULL, NULL }; |
Johannes Schindelin | c455c87 | 2008-07-21 19:03:49 +0100 | [diff] [blame] | 696 | struct string_list branches = { NULL, 0, 0, 1 }; |
Jay Soffian | 441adf0 | 2009-02-04 11:06:07 -0500 | [diff] [blame] | 697 | struct string_list skipped = { NULL, 0, 0, 1 }; |
| 698 | struct branches_for_remote cb_data = { |
| 699 | NULL, &branches, &skipped, &known_remotes |
| 700 | }; |
Jay Soffian | e02f176 | 2009-02-03 12:51:12 -0500 | [diff] [blame] | 701 | int i, result; |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 702 | |
| 703 | if (argc != 2) |
Tim Henigan | 4504107 | 2009-11-20 18:43:13 -0500 | [diff] [blame] | 704 | usage_with_options(builtin_remote_rm_usage, options); |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 705 | |
| 706 | remote = remote_get(argv[1]); |
| 707 | if (!remote) |
| 708 | die("No such remote: %s", argv[1]); |
| 709 | |
Shawn O. Pearce | 7ad2458 | 2008-06-01 00:28:04 -0400 | [diff] [blame] | 710 | known_remotes.to_delete = remote; |
| 711 | for_each_remote(add_known_remote, &known_remotes); |
| 712 | |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 713 | strbuf_addf(&buf, "remote.%s", remote->name); |
| 714 | if (git_config_rename_section(buf.buf, NULL) < 1) |
| 715 | return error("Could not remove config section '%s'", buf.buf); |
| 716 | |
| 717 | read_branches(); |
| 718 | for (i = 0; i < branch_list.nr; i++) { |
Johannes Schindelin | c455c87 | 2008-07-21 19:03:49 +0100 | [diff] [blame] | 719 | struct string_list_item *item = branch_list.items + i; |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 720 | struct branch_info *info = item->util; |
Jay Soffian | e0cc81e | 2009-02-25 03:32:21 -0500 | [diff] [blame] | 721 | if (info->remote_name && !strcmp(info->remote_name, remote->name)) { |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 722 | const char *keys[] = { "remote", "merge", NULL }, **k; |
| 723 | for (k = keys; *k; k++) { |
| 724 | strbuf_reset(&buf); |
| 725 | strbuf_addf(&buf, "branch.%s.%s", |
Johannes Schindelin | c455c87 | 2008-07-21 19:03:49 +0100 | [diff] [blame] | 726 | item->string, *k); |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 727 | if (git_config_set(buf.buf, NULL)) { |
| 728 | strbuf_release(&buf); |
| 729 | return -1; |
| 730 | } |
| 731 | } |
| 732 | } |
| 733 | } |
| 734 | |
| 735 | /* |
| 736 | * We cannot just pass a function to for_each_ref() which deletes |
| 737 | * the branches one by one, since for_each_ref() relies on cached |
| 738 | * refs, which are invalidated when deleting a branch. |
| 739 | */ |
Shawn O. Pearce | 7ad2458 | 2008-06-01 00:28:04 -0400 | [diff] [blame] | 740 | cb_data.remote = remote; |
Jay Soffian | e02f176 | 2009-02-03 12:51:12 -0500 | [diff] [blame] | 741 | result = for_each_ref(add_branch_for_removal, &cb_data); |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 742 | strbuf_release(&buf); |
| 743 | |
Jay Soffian | e02f176 | 2009-02-03 12:51:12 -0500 | [diff] [blame] | 744 | if (!result) |
| 745 | result = remove_branches(&branches); |
Johannes Schindelin | c455c87 | 2008-07-21 19:03:49 +0100 | [diff] [blame] | 746 | string_list_clear(&branches, 1); |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 747 | |
Jay Soffian | 441adf0 | 2009-02-04 11:06:07 -0500 | [diff] [blame] | 748 | if (skipped.nr) { |
| 749 | fprintf(stderr, skipped.nr == 1 ? |
| 750 | "Note: A non-remote branch was not removed; " |
| 751 | "to delete it, use:\n" : |
| 752 | "Note: Non-remote branches were not removed; " |
| 753 | "to delete them, use:\n"); |
| 754 | for (i = 0; i < skipped.nr; i++) |
| 755 | fprintf(stderr, " git branch -d %s\n", |
| 756 | skipped.items[i].string); |
| 757 | } |
| 758 | string_list_clear(&skipped, 0); |
| 759 | |
Jay Soffian | e02f176 | 2009-02-03 12:51:12 -0500 | [diff] [blame] | 760 | return result; |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 761 | } |
| 762 | |
Linus Torvalds | 2af202b | 2009-06-18 10:28:43 -0700 | [diff] [blame] | 763 | static void clear_push_info(void *util, const char *string) |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 764 | { |
Jay Soffian | e5dcbfd | 2009-02-25 03:32:28 -0500 | [diff] [blame] | 765 | struct push_info *info = util; |
| 766 | free(info->dest); |
| 767 | free(info); |
| 768 | } |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 769 | |
Jay Soffian | 8873323 | 2009-02-25 03:32:19 -0500 | [diff] [blame] | 770 | static void free_remote_ref_states(struct ref_states *states) |
| 771 | { |
| 772 | string_list_clear(&states->new, 0); |
Bert Wesarg | 92f676f | 2009-12-01 00:57:27 +0100 | [diff] [blame] | 773 | string_list_clear(&states->stale, 1); |
Jay Soffian | 8873323 | 2009-02-25 03:32:19 -0500 | [diff] [blame] | 774 | string_list_clear(&states->tracked, 0); |
Jay Soffian | e61e0cc | 2009-02-25 03:32:24 -0500 | [diff] [blame] | 775 | string_list_clear(&states->heads, 0); |
Jay Soffian | e5dcbfd | 2009-02-25 03:32:28 -0500 | [diff] [blame] | 776 | string_list_clear_func(&states->push, clear_push_info); |
Jay Soffian | 8873323 | 2009-02-25 03:32:19 -0500 | [diff] [blame] | 777 | } |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 778 | |
Jay Soffian | cca7c97 | 2009-02-25 03:32:22 -0500 | [diff] [blame] | 779 | static int append_ref_to_tracked_list(const char *refname, |
| 780 | const unsigned char *sha1, int flags, void *cb_data) |
| 781 | { |
| 782 | struct ref_states *states = cb_data; |
| 783 | struct refspec refspec; |
| 784 | |
Jay Soffian | 3bd9256 | 2009-02-25 03:32:23 -0500 | [diff] [blame] | 785 | if (flags & REF_ISSYMREF) |
| 786 | return 0; |
| 787 | |
Jay Soffian | cca7c97 | 2009-02-25 03:32:22 -0500 | [diff] [blame] | 788 | memset(&refspec, 0, sizeof(refspec)); |
| 789 | refspec.dst = (char *)refname; |
| 790 | if (!remote_find_tracking(states->remote, &refspec)) |
| 791 | string_list_append(abbrev_branch(refspec.src), &states->tracked); |
| 792 | |
| 793 | return 0; |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 794 | } |
| 795 | |
Olivier Marin | 67a7e2d | 2008-06-10 16:51:21 +0200 | [diff] [blame] | 796 | static int get_remote_ref_states(const char *name, |
| 797 | struct ref_states *states, |
| 798 | int query) |
| 799 | { |
| 800 | struct transport *transport; |
Jay Soffian | e0cc81e | 2009-02-25 03:32:21 -0500 | [diff] [blame] | 801 | const struct ref *remote_refs; |
Olivier Marin | 67a7e2d | 2008-06-10 16:51:21 +0200 | [diff] [blame] | 802 | |
| 803 | states->remote = remote_get(name); |
| 804 | if (!states->remote) |
| 805 | return error("No such remote: %s", name); |
| 806 | |
| 807 | read_branches(); |
| 808 | |
| 809 | if (query) { |
Chris Frey | 345a380 | 2009-06-25 17:21:35 -0400 | [diff] [blame] | 810 | transport = transport_get(states->remote, states->remote->url_nr > 0 ? |
Olivier Marin | 67a7e2d | 2008-06-10 16:51:21 +0200 | [diff] [blame] | 811 | states->remote->url[0] : NULL); |
Jay Soffian | e0cc81e | 2009-02-25 03:32:21 -0500 | [diff] [blame] | 812 | remote_refs = transport_get_remote_refs(transport); |
Olivier Marin | 67a7e2d | 2008-06-10 16:51:21 +0200 | [diff] [blame] | 813 | transport_disconnect(transport); |
| 814 | |
Jay Soffian | 7ecbbf8 | 2009-02-25 03:32:27 -0500 | [diff] [blame] | 815 | states->queried = 1; |
Jay Soffian | e61e0cc | 2009-02-25 03:32:24 -0500 | [diff] [blame] | 816 | if (query & GET_REF_STATES) |
| 817 | get_ref_states(remote_refs, states); |
| 818 | if (query & GET_HEAD_NAMES) |
| 819 | get_head_names(remote_refs, states); |
Jay Soffian | e5dcbfd | 2009-02-25 03:32:28 -0500 | [diff] [blame] | 820 | if (query & GET_PUSH_REF_STATES) |
| 821 | get_push_ref_states(remote_refs, states); |
Jay Soffian | 3bd9256 | 2009-02-25 03:32:23 -0500 | [diff] [blame] | 822 | } else { |
Jay Soffian | cca7c97 | 2009-02-25 03:32:22 -0500 | [diff] [blame] | 823 | for_each_ref(append_ref_to_tracked_list, states); |
Jay Soffian | 3bd9256 | 2009-02-25 03:32:23 -0500 | [diff] [blame] | 824 | sort_string_list(&states->tracked); |
Jay Soffian | e5dcbfd | 2009-02-25 03:32:28 -0500 | [diff] [blame] | 825 | get_push_ref_states_noquery(states); |
Olivier Marin | 67a7e2d | 2008-06-10 16:51:21 +0200 | [diff] [blame] | 826 | } |
| 827 | |
| 828 | return 0; |
| 829 | } |
| 830 | |
Jay Soffian | 7ecbbf8 | 2009-02-25 03:32:27 -0500 | [diff] [blame] | 831 | struct show_info { |
| 832 | struct string_list *list; |
| 833 | struct ref_states *states; |
Jay Soffian | e5dcbfd | 2009-02-25 03:32:28 -0500 | [diff] [blame] | 834 | int width, width2; |
Jay Soffian | 7ecbbf8 | 2009-02-25 03:32:27 -0500 | [diff] [blame] | 835 | int any_rebase; |
| 836 | }; |
| 837 | |
Linus Torvalds | 2af202b | 2009-06-18 10:28:43 -0700 | [diff] [blame] | 838 | 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] | 839 | { |
Jay Soffian | 7ecbbf8 | 2009-02-25 03:32:27 -0500 | [diff] [blame] | 840 | struct show_info *info = cb_data; |
| 841 | int n = strlen(item->string); |
| 842 | if (n > info->width) |
| 843 | info->width = n; |
| 844 | string_list_insert(item->string, info->list); |
| 845 | return 0; |
| 846 | } |
Olivier Marin | e7d5a97 | 2008-06-11 00:54:49 +0200 | [diff] [blame] | 847 | |
Linus Torvalds | 2af202b | 2009-06-18 10:28:43 -0700 | [diff] [blame] | 848 | 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] | 849 | { |
| 850 | struct show_info *info = cb_data; |
| 851 | struct ref_states *states = info->states; |
| 852 | const char *name = item->string; |
Olivier Marin | e7d5a97 | 2008-06-11 00:54:49 +0200 | [diff] [blame] | 853 | |
Jay Soffian | 7ecbbf8 | 2009-02-25 03:32:27 -0500 | [diff] [blame] | 854 | if (states->queried) { |
| 855 | const char *fmt = "%s"; |
| 856 | const char *arg = ""; |
| 857 | if (string_list_has_string(&states->new, name)) { |
| 858 | fmt = " new (next fetch will store in remotes/%s)"; |
| 859 | arg = states->remote->name; |
| 860 | } else if (string_list_has_string(&states->tracked, name)) |
| 861 | arg = " tracked"; |
| 862 | else if (string_list_has_string(&states->stale, name)) |
| 863 | arg = " stale (use 'git remote prune' to remove)"; |
| 864 | else |
| 865 | arg = " ???"; |
| 866 | printf(" %-*s", info->width, name); |
| 867 | printf(fmt, arg); |
| 868 | printf("\n"); |
| 869 | } else |
| 870 | printf(" %s\n", name); |
| 871 | |
| 872 | return 0; |
| 873 | } |
| 874 | |
Linus Torvalds | 2af202b | 2009-06-18 10:28:43 -0700 | [diff] [blame] | 875 | 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] | 876 | { |
| 877 | struct show_info *show_info = cb_data; |
| 878 | struct ref_states *states = show_info->states; |
| 879 | struct branch_info *branch_info = branch_item->util; |
| 880 | struct string_list_item *item; |
| 881 | int n; |
| 882 | |
| 883 | if (!branch_info->merge.nr || !branch_info->remote_name || |
| 884 | strcmp(states->remote->name, branch_info->remote_name)) |
| 885 | return 0; |
| 886 | if ((n = strlen(branch_item->string)) > show_info->width) |
| 887 | show_info->width = n; |
| 888 | if (branch_info->rebase) |
| 889 | show_info->any_rebase = 1; |
| 890 | |
| 891 | item = string_list_insert(branch_item->string, show_info->list); |
| 892 | item->util = branch_info; |
| 893 | |
| 894 | return 0; |
| 895 | } |
| 896 | |
Linus Torvalds | 2af202b | 2009-06-18 10:28:43 -0700 | [diff] [blame] | 897 | 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] | 898 | { |
| 899 | struct show_info *show_info = cb_data; |
| 900 | struct branch_info *branch_info = item->util; |
| 901 | struct string_list *merge = &branch_info->merge; |
| 902 | const char *also; |
| 903 | int i; |
| 904 | |
| 905 | if (branch_info->rebase && branch_info->merge.nr > 1) { |
| 906 | error("invalid branch.%s.merge; cannot rebase onto > 1 branch", |
| 907 | item->string); |
| 908 | return 0; |
| 909 | } |
| 910 | |
| 911 | printf(" %-*s ", show_info->width, item->string); |
| 912 | if (branch_info->rebase) { |
| 913 | printf("rebases onto remote %s\n", merge->items[0].string); |
| 914 | return 0; |
| 915 | } else if (show_info->any_rebase) { |
| 916 | printf(" merges with remote %s\n", merge->items[0].string); |
| 917 | also = " and with remote"; |
| 918 | } else { |
| 919 | printf("merges with remote %s\n", merge->items[0].string); |
| 920 | also = " and with remote"; |
| 921 | } |
| 922 | for (i = 1; i < merge->nr; i++) |
| 923 | printf(" %-*s %s %s\n", show_info->width, "", also, |
| 924 | merge->items[i].string); |
| 925 | |
| 926 | return 0; |
| 927 | } |
| 928 | |
Linus Torvalds | 2af202b | 2009-06-18 10:28:43 -0700 | [diff] [blame] | 929 | 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] | 930 | { |
| 931 | struct show_info *show_info = cb_data; |
| 932 | struct push_info *push_info = push_item->util; |
| 933 | struct string_list_item *item; |
| 934 | int n; |
| 935 | if ((n = strlen(push_item->string)) > show_info->width) |
| 936 | show_info->width = n; |
| 937 | if ((n = strlen(push_info->dest)) > show_info->width2) |
| 938 | show_info->width2 = n; |
| 939 | item = string_list_append(push_item->string, show_info->list); |
| 940 | item->util = push_item->util; |
| 941 | return 0; |
| 942 | } |
| 943 | |
Jeff King | 48ef563 | 2009-03-22 04:59:20 -0400 | [diff] [blame] | 944 | /* |
| 945 | * Sorting comparison for a string list that has push_info |
| 946 | * structs in its util field |
| 947 | */ |
| 948 | static int cmp_string_with_push(const void *va, const void *vb) |
| 949 | { |
| 950 | const struct string_list_item *a = va; |
| 951 | const struct string_list_item *b = vb; |
| 952 | const struct push_info *a_push = a->util; |
| 953 | const struct push_info *b_push = b->util; |
| 954 | int cmp = strcmp(a->string, b->string); |
| 955 | return cmp ? cmp : strcmp(a_push->dest, b_push->dest); |
| 956 | } |
| 957 | |
Linus Torvalds | 2af202b | 2009-06-18 10:28:43 -0700 | [diff] [blame] | 958 | 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] | 959 | { |
| 960 | struct show_info *show_info = cb_data; |
| 961 | struct push_info *push_info = item->util; |
| 962 | char *src = item->string, *status = NULL; |
| 963 | |
| 964 | switch (push_info->status) { |
| 965 | case PUSH_STATUS_CREATE: |
| 966 | status = "create"; |
| 967 | break; |
| 968 | case PUSH_STATUS_DELETE: |
| 969 | status = "delete"; |
| 970 | src = "(none)"; |
| 971 | break; |
| 972 | case PUSH_STATUS_UPTODATE: |
| 973 | status = "up to date"; |
| 974 | break; |
| 975 | case PUSH_STATUS_FASTFORWARD: |
Felipe Contreras | a75d7b5 | 2009-10-24 11:31:32 +0300 | [diff] [blame] | 976 | status = "fast-forwardable"; |
Jay Soffian | e5dcbfd | 2009-02-25 03:32:28 -0500 | [diff] [blame] | 977 | break; |
| 978 | case PUSH_STATUS_OUTOFDATE: |
| 979 | status = "local out of date"; |
| 980 | break; |
| 981 | case PUSH_STATUS_NOTQUERIED: |
| 982 | break; |
| 983 | } |
| 984 | if (status) |
| 985 | printf(" %-*s %s to %-*s (%s)\n", show_info->width, src, |
| 986 | push_info->forced ? "forces" : "pushes", |
| 987 | show_info->width2, push_info->dest, status); |
| 988 | else |
| 989 | printf(" %-*s %s to %s\n", show_info->width, src, |
| 990 | push_info->forced ? "forces" : "pushes", |
| 991 | push_info->dest); |
Olivier Marin | e7d5a97 | 2008-06-11 00:54:49 +0200 | [diff] [blame] | 992 | return 0; |
| 993 | } |
| 994 | |
Olivier Marin | 67a7e2d | 2008-06-10 16:51:21 +0200 | [diff] [blame] | 995 | static int show(int argc, const char **argv) |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 996 | { |
Jay Soffian | e61e0cc | 2009-02-25 03:32:24 -0500 | [diff] [blame] | 997 | int no_query = 0, result = 0, query_flag = 0; |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 998 | struct option options[] = { |
Olivier Marin | 0ecfcb3 | 2008-06-10 16:51:08 +0200 | [diff] [blame] | 999 | OPT_BOOLEAN('n', NULL, &no_query, "do not query remotes"), |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 1000 | OPT_END() |
| 1001 | }; |
| 1002 | struct ref_states states; |
Jay Soffian | 7ecbbf8 | 2009-02-25 03:32:27 -0500 | [diff] [blame] | 1003 | struct string_list info_list = { NULL, 0, 0, 0 }; |
| 1004 | struct show_info info; |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 1005 | |
Tim Henigan | 4504107 | 2009-11-20 18:43:13 -0500 | [diff] [blame] | 1006 | argc = parse_options(argc, argv, NULL, options, builtin_remote_show_usage, |
Stephen Boyd | 3778292 | 2009-05-23 11:53:12 -0700 | [diff] [blame] | 1007 | 0); |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 1008 | |
Olivier Marin | 67a7e2d | 2008-06-10 16:51:21 +0200 | [diff] [blame] | 1009 | if (argc < 1) |
| 1010 | return show_all(); |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 1011 | |
Jay Soffian | e61e0cc | 2009-02-25 03:32:24 -0500 | [diff] [blame] | 1012 | if (!no_query) |
Jay Soffian | e5dcbfd | 2009-02-25 03:32:28 -0500 | [diff] [blame] | 1013 | query_flag = (GET_REF_STATES | GET_HEAD_NAMES | GET_PUSH_REF_STATES); |
Jay Soffian | e61e0cc | 2009-02-25 03:32:24 -0500 | [diff] [blame] | 1014 | |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 1015 | memset(&states, 0, sizeof(states)); |
Jay Soffian | 7ecbbf8 | 2009-02-25 03:32:27 -0500 | [diff] [blame] | 1016 | memset(&info, 0, sizeof(info)); |
| 1017 | info.states = &states; |
| 1018 | info.list = &info_list; |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 1019 | for (; argc; argc--, argv++) { |
Olivier Marin | 0ecfcb3 | 2008-06-10 16:51:08 +0200 | [diff] [blame] | 1020 | int i; |
Michael J Gruber | 857f8c3 | 2009-06-13 18:29:10 +0200 | [diff] [blame] | 1021 | const char **url; |
| 1022 | int url_nr; |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 1023 | |
Jay Soffian | e61e0cc | 2009-02-25 03:32:24 -0500 | [diff] [blame] | 1024 | get_remote_ref_states(*argv, &states, query_flag); |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 1025 | |
Michael J Gruber | 956d27a | 2009-06-06 17:16:30 +0200 | [diff] [blame] | 1026 | printf("* remote %s\n", *argv); |
Michael J Gruber | 857f8c3 | 2009-06-13 18:29:10 +0200 | [diff] [blame] | 1027 | printf(" Fetch URL: %s\n", states.remote->url_nr > 0 ? |
| 1028 | states.remote->url[0] : "(no URL)"); |
| 1029 | if (states.remote->pushurl_nr) { |
| 1030 | url = states.remote->pushurl; |
| 1031 | url_nr = states.remote->pushurl_nr; |
| 1032 | } else { |
| 1033 | url = states.remote->url; |
| 1034 | url_nr = states.remote->url_nr; |
| 1035 | } |
| 1036 | for (i=0; i < url_nr; i++) |
| 1037 | printf(" Push URL: %s\n", url[i]); |
| 1038 | if (!i) |
| 1039 | printf(" Push URL: %s\n", "(no URL)"); |
Olivier Marin | e7d5a97 | 2008-06-11 00:54:49 +0200 | [diff] [blame] | 1040 | if (no_query) |
Jay Soffian | e61e0cc | 2009-02-25 03:32:24 -0500 | [diff] [blame] | 1041 | printf(" HEAD branch: (not queried)\n"); |
| 1042 | else if (!states.heads.nr) |
| 1043 | printf(" HEAD branch: (unknown)\n"); |
| 1044 | else if (states.heads.nr == 1) |
| 1045 | printf(" HEAD branch: %s\n", states.heads.items[0].string); |
| 1046 | else { |
| 1047 | printf(" HEAD branch (remote HEAD is ambiguous," |
| 1048 | " may be one of the following):\n"); |
| 1049 | for (i = 0; i < states.heads.nr; i++) |
| 1050 | printf(" %s\n", states.heads.items[i].string); |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 1051 | } |
Olivier Marin | 67a7e2d | 2008-06-10 16:51:21 +0200 | [diff] [blame] | 1052 | |
Jay Soffian | 7ecbbf8 | 2009-02-25 03:32:27 -0500 | [diff] [blame] | 1053 | /* remote branch info */ |
| 1054 | info.width = 0; |
| 1055 | for_each_string_list(add_remote_to_show_info, &states.new, &info); |
| 1056 | for_each_string_list(add_remote_to_show_info, &states.tracked, &info); |
| 1057 | for_each_string_list(add_remote_to_show_info, &states.stale, &info); |
| 1058 | if (info.list->nr) |
| 1059 | printf(" Remote branch%s:%s\n", |
| 1060 | info.list->nr > 1 ? "es" : "", |
| 1061 | no_query ? " (status not queried)" : ""); |
| 1062 | for_each_string_list(show_remote_info_item, info.list, &info); |
| 1063 | string_list_clear(info.list, 0); |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 1064 | |
Jay Soffian | 7ecbbf8 | 2009-02-25 03:32:27 -0500 | [diff] [blame] | 1065 | /* git pull info */ |
| 1066 | info.width = 0; |
| 1067 | info.any_rebase = 0; |
| 1068 | for_each_string_list(add_local_to_show_info, &branch_list, &info); |
| 1069 | if (info.list->nr) |
| 1070 | printf(" Local branch%s configured for 'git pull':\n", |
| 1071 | info.list->nr > 1 ? "es" : ""); |
| 1072 | for_each_string_list(show_local_info_item, info.list, &info); |
| 1073 | string_list_clear(info.list, 0); |
Olivier Marin | 67a7e2d | 2008-06-10 16:51:21 +0200 | [diff] [blame] | 1074 | |
Jay Soffian | 7ecbbf8 | 2009-02-25 03:32:27 -0500 | [diff] [blame] | 1075 | /* git push info */ |
Jay Soffian | e5dcbfd | 2009-02-25 03:32:28 -0500 | [diff] [blame] | 1076 | if (states.remote->mirror) |
| 1077 | printf(" Local refs will be mirrored by 'git push'\n"); |
| 1078 | |
| 1079 | info.width = info.width2 = 0; |
| 1080 | for_each_string_list(add_push_to_show_info, &states.push, &info); |
Jeff King | 48ef563 | 2009-03-22 04:59:20 -0400 | [diff] [blame] | 1081 | qsort(info.list->items, info.list->nr, |
| 1082 | sizeof(*info.list->items), cmp_string_with_push); |
Jay Soffian | e5dcbfd | 2009-02-25 03:32:28 -0500 | [diff] [blame] | 1083 | if (info.list->nr) |
| 1084 | printf(" Local ref%s configured for 'git push'%s:\n", |
| 1085 | info.list->nr > 1 ? "s" : "", |
| 1086 | no_query ? " (status not queried)" : ""); |
| 1087 | for_each_string_list(show_push_info_item, info.list, &info); |
| 1088 | string_list_clear(info.list, 0); |
Olivier Marin | 67a7e2d | 2008-06-10 16:51:21 +0200 | [diff] [blame] | 1089 | |
Jay Soffian | 8873323 | 2009-02-25 03:32:19 -0500 | [diff] [blame] | 1090 | free_remote_ref_states(&states); |
Olivier Marin | 67a7e2d | 2008-06-10 16:51:21 +0200 | [diff] [blame] | 1091 | } |
| 1092 | |
| 1093 | return result; |
| 1094 | } |
| 1095 | |
Jay Soffian | bc14fac | 2009-02-25 03:32:25 -0500 | [diff] [blame] | 1096 | static int set_head(int argc, const char **argv) |
| 1097 | { |
| 1098 | int i, opt_a = 0, opt_d = 0, result = 0; |
| 1099 | struct strbuf buf = STRBUF_INIT, buf2 = STRBUF_INIT; |
| 1100 | char *head_name = NULL; |
| 1101 | |
| 1102 | struct option options[] = { |
Jay Soffian | bc14fac | 2009-02-25 03:32:25 -0500 | [diff] [blame] | 1103 | OPT_BOOLEAN('a', "auto", &opt_a, |
| 1104 | "set refs/remotes/<name>/HEAD according to remote"), |
| 1105 | OPT_BOOLEAN('d', "delete", &opt_d, |
| 1106 | "delete refs/remotes/<name>/HEAD"), |
| 1107 | OPT_END() |
| 1108 | }; |
Tim Henigan | 4504107 | 2009-11-20 18:43:13 -0500 | [diff] [blame] | 1109 | argc = parse_options(argc, argv, NULL, options, builtin_remote_sethead_usage, |
Stephen Boyd | 3778292 | 2009-05-23 11:53:12 -0700 | [diff] [blame] | 1110 | 0); |
Jay Soffian | bc14fac | 2009-02-25 03:32:25 -0500 | [diff] [blame] | 1111 | if (argc) |
| 1112 | strbuf_addf(&buf, "refs/remotes/%s/HEAD", argv[0]); |
| 1113 | |
| 1114 | if (!opt_a && !opt_d && argc == 2) { |
| 1115 | head_name = xstrdup(argv[1]); |
| 1116 | } else if (opt_a && !opt_d && argc == 1) { |
| 1117 | struct ref_states states; |
| 1118 | memset(&states, 0, sizeof(states)); |
| 1119 | get_remote_ref_states(argv[0], &states, GET_HEAD_NAMES); |
| 1120 | if (!states.heads.nr) |
| 1121 | result |= error("Cannot determine remote HEAD"); |
| 1122 | else if (states.heads.nr > 1) { |
| 1123 | result |= error("Multiple remote HEAD branches. " |
| 1124 | "Please choose one explicitly with:"); |
| 1125 | for (i = 0; i < states.heads.nr; i++) |
| 1126 | fprintf(stderr, " git remote set-head %s %s\n", |
| 1127 | argv[0], states.heads.items[i].string); |
| 1128 | } else |
| 1129 | head_name = xstrdup(states.heads.items[0].string); |
| 1130 | free_remote_ref_states(&states); |
| 1131 | } else if (opt_d && !opt_a && argc == 1) { |
| 1132 | if (delete_ref(buf.buf, NULL, REF_NODEREF)) |
| 1133 | result |= error("Could not delete %s", buf.buf); |
| 1134 | } else |
Tim Henigan | 4504107 | 2009-11-20 18:43:13 -0500 | [diff] [blame] | 1135 | usage_with_options(builtin_remote_sethead_usage, options); |
Jay Soffian | bc14fac | 2009-02-25 03:32:25 -0500 | [diff] [blame] | 1136 | |
| 1137 | if (head_name) { |
| 1138 | unsigned char sha1[20]; |
| 1139 | strbuf_addf(&buf2, "refs/remotes/%s/%s", argv[0], head_name); |
| 1140 | /* make sure it's valid */ |
| 1141 | if (!resolve_ref(buf2.buf, sha1, 1, NULL)) |
| 1142 | result |= error("Not a valid ref: %s", buf2.buf); |
| 1143 | else if (create_symref(buf.buf, buf2.buf, "remote set-head")) |
| 1144 | result |= error("Could not setup %s", buf.buf); |
| 1145 | if (opt_a) |
| 1146 | printf("%s/HEAD set to %s\n", argv[0], head_name); |
| 1147 | free(head_name); |
| 1148 | } |
| 1149 | |
| 1150 | strbuf_release(&buf); |
| 1151 | strbuf_release(&buf2); |
| 1152 | return result; |
| 1153 | } |
| 1154 | |
Olivier Marin | 67a7e2d | 2008-06-10 16:51:21 +0200 | [diff] [blame] | 1155 | static int prune(int argc, const char **argv) |
| 1156 | { |
Olivier Marin | 8d76792 | 2008-06-10 16:51:35 +0200 | [diff] [blame] | 1157 | int dry_run = 0, result = 0; |
Olivier Marin | 67a7e2d | 2008-06-10 16:51:21 +0200 | [diff] [blame] | 1158 | struct option options[] = { |
Olivier Marin | 8d76792 | 2008-06-10 16:51:35 +0200 | [diff] [blame] | 1159 | OPT__DRY_RUN(&dry_run), |
Olivier Marin | 67a7e2d | 2008-06-10 16:51:21 +0200 | [diff] [blame] | 1160 | OPT_END() |
| 1161 | }; |
Olivier Marin | 67a7e2d | 2008-06-10 16:51:21 +0200 | [diff] [blame] | 1162 | |
Tim Henigan | 4504107 | 2009-11-20 18:43:13 -0500 | [diff] [blame] | 1163 | argc = parse_options(argc, argv, NULL, options, builtin_remote_prune_usage, |
Stephen Boyd | 3778292 | 2009-05-23 11:53:12 -0700 | [diff] [blame] | 1164 | 0); |
Olivier Marin | 67a7e2d | 2008-06-10 16:51:21 +0200 | [diff] [blame] | 1165 | |
| 1166 | if (argc < 1) |
Tim Henigan | 4504107 | 2009-11-20 18:43:13 -0500 | [diff] [blame] | 1167 | usage_with_options(builtin_remote_prune_usage, options); |
Olivier Marin | 67a7e2d | 2008-06-10 16:51:21 +0200 | [diff] [blame] | 1168 | |
Finn Arne Gangstad | b92c5f2 | 2009-04-03 11:02:37 +0200 | [diff] [blame] | 1169 | for (; argc; argc--, argv++) |
| 1170 | result |= prune_remote(*argv, dry_run); |
| 1171 | |
| 1172 | return result; |
| 1173 | } |
| 1174 | |
| 1175 | static int prune_remote(const char *remote, int dry_run) |
| 1176 | { |
| 1177 | int result = 0, i; |
| 1178 | struct ref_states states; |
| 1179 | const char *dangling_msg = dry_run |
| 1180 | ? " %s will become dangling!\n" |
| 1181 | : " %s has become dangling!\n"; |
Junio C Hamano | f8948e2 | 2009-02-08 23:27:10 -0800 | [diff] [blame] | 1182 | |
Olivier Marin | 67a7e2d | 2008-06-10 16:51:21 +0200 | [diff] [blame] | 1183 | memset(&states, 0, sizeof(states)); |
Finn Arne Gangstad | b92c5f2 | 2009-04-03 11:02:37 +0200 | [diff] [blame] | 1184 | get_remote_ref_states(remote, &states, GET_REF_STATES); |
Olivier Marin | 67a7e2d | 2008-06-10 16:51:21 +0200 | [diff] [blame] | 1185 | |
Finn Arne Gangstad | b92c5f2 | 2009-04-03 11:02:37 +0200 | [diff] [blame] | 1186 | if (states.stale.nr) { |
| 1187 | printf("Pruning %s\n", remote); |
| 1188 | printf("URL: %s\n", |
| 1189 | states.remote->url_nr |
| 1190 | ? states.remote->url[0] |
| 1191 | : "(no URL)"); |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 1192 | } |
| 1193 | |
Finn Arne Gangstad | b92c5f2 | 2009-04-03 11:02:37 +0200 | [diff] [blame] | 1194 | for (i = 0; i < states.stale.nr; i++) { |
| 1195 | const char *refname = states.stale.items[i].util; |
| 1196 | |
| 1197 | if (!dry_run) |
| 1198 | result |= delete_ref(refname, NULL, 0); |
| 1199 | |
| 1200 | printf(" * [%s] %s\n", dry_run ? "would prune" : "pruned", |
| 1201 | abbrev_ref(refname, "refs/remotes/")); |
Jay Soffian | 3cf6134 | 2009-11-10 00:03:32 -0500 | [diff] [blame] | 1202 | warn_dangling_symref(stdout, dangling_msg, refname); |
Finn Arne Gangstad | b92c5f2 | 2009-04-03 11:02:37 +0200 | [diff] [blame] | 1203 | } |
| 1204 | |
| 1205 | free_remote_ref_states(&states); |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 1206 | return result; |
| 1207 | } |
| 1208 | |
Björn Gustavsson | 8db3559 | 2009-11-10 09:21:32 +0100 | [diff] [blame] | 1209 | 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] | 1210 | { |
Björn Gustavsson | 8db3559 | 2009-11-10 09:21:32 +0100 | [diff] [blame] | 1211 | if (strcmp(key, "remotes.default") == 0) { |
| 1212 | int *found = priv; |
| 1213 | *found = 1; |
Johannes Schindelin | 84521ed | 2008-03-04 11:23:53 +0000 | [diff] [blame] | 1214 | } |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 1215 | return 0; |
| 1216 | } |
| 1217 | |
| 1218 | static int update(int argc, const char **argv) |
| 1219 | { |
Björn Gustavsson | 8db3559 | 2009-11-10 09:21:32 +0100 | [diff] [blame] | 1220 | int i, prune = 0; |
Finn Arne Gangstad | efa5480 | 2009-04-03 11:03:44 +0200 | [diff] [blame] | 1221 | struct option options[] = { |
Finn Arne Gangstad | efa5480 | 2009-04-03 11:03:44 +0200 | [diff] [blame] | 1222 | OPT_BOOLEAN('p', "prune", &prune, |
Mike Ralphson | 7c0282b | 2009-04-17 19:13:29 +0100 | [diff] [blame] | 1223 | "prune remotes after fetching"), |
Finn Arne Gangstad | efa5480 | 2009-04-03 11:03:44 +0200 | [diff] [blame] | 1224 | OPT_END() |
| 1225 | }; |
Björn Gustavsson | 8db3559 | 2009-11-10 09:21:32 +0100 | [diff] [blame] | 1226 | const char **fetch_argv; |
| 1227 | int fetch_argc = 0; |
| 1228 | int default_defined = 0; |
| 1229 | |
| 1230 | fetch_argv = xmalloc(sizeof(char *) * (argc+5)); |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 1231 | |
Tim Henigan | 4504107 | 2009-11-20 18:43:13 -0500 | [diff] [blame] | 1232 | argc = parse_options(argc, argv, NULL, options, builtin_remote_update_usage, |
Finn Arne Gangstad | efa5480 | 2009-04-03 11:03:44 +0200 | [diff] [blame] | 1233 | PARSE_OPT_KEEP_ARGV0); |
Björn Gustavsson | 8db3559 | 2009-11-10 09:21:32 +0100 | [diff] [blame] | 1234 | |
| 1235 | fetch_argv[fetch_argc++] = "fetch"; |
| 1236 | |
| 1237 | if (prune) |
| 1238 | fetch_argv[fetch_argc++] = "--prune"; |
| 1239 | if (verbose) |
| 1240 | fetch_argv[fetch_argc++] = "-v"; |
Björn Gustavsson | 4f2e842 | 2009-12-31 10:43:17 +0100 | [diff] [blame] | 1241 | fetch_argv[fetch_argc++] = "--multiple"; |
| 1242 | if (argc < 2) |
Björn Gustavsson | 8db3559 | 2009-11-10 09:21:32 +0100 | [diff] [blame] | 1243 | fetch_argv[fetch_argc++] = "default"; |
Björn Gustavsson | 4f2e842 | 2009-12-31 10:43:17 +0100 | [diff] [blame] | 1244 | for (i = 1; i < argc; i++) |
| 1245 | fetch_argv[fetch_argc++] = argv[i]; |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 1246 | |
Björn Gustavsson | 8db3559 | 2009-11-10 09:21:32 +0100 | [diff] [blame] | 1247 | if (strcmp(fetch_argv[fetch_argc-1], "default") == 0) { |
| 1248 | git_config(get_remote_default, &default_defined); |
| 1249 | if (!default_defined) |
| 1250 | fetch_argv[fetch_argc-1] = "--all"; |
Johannes Schindelin | 84521ed | 2008-03-04 11:23:53 +0000 | [diff] [blame] | 1251 | } |
| 1252 | |
Björn Gustavsson | 8db3559 | 2009-11-10 09:21:32 +0100 | [diff] [blame] | 1253 | fetch_argv[fetch_argc] = NULL; |
Johannes Schindelin | 84521ed | 2008-03-04 11:23:53 +0000 | [diff] [blame] | 1254 | |
Björn Gustavsson | 8db3559 | 2009-11-10 09:21:32 +0100 | [diff] [blame] | 1255 | return run_command_v_opt(fetch_argv, RUN_GIT_CMD); |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 1256 | } |
| 1257 | |
| 1258 | static int get_one_entry(struct remote *remote, void *priv) |
| 1259 | { |
Johannes Schindelin | c455c87 | 2008-07-21 19:03:49 +0100 | [diff] [blame] | 1260 | struct string_list *list = priv; |
Bert Wesarg | 3f721d1 | 2009-06-23 00:27:44 +0200 | [diff] [blame] | 1261 | struct strbuf url_buf = STRBUF_INIT; |
Michael J Gruber | 4a4b4cd | 2009-06-13 18:29:11 +0200 | [diff] [blame] | 1262 | const char **url; |
| 1263 | int i, url_nr; |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 1264 | |
Michael J Gruber | 7d20e21 | 2008-09-22 10:57:51 +0200 | [diff] [blame] | 1265 | if (remote->url_nr > 0) { |
Bert Wesarg | 3f721d1 | 2009-06-23 00:27:44 +0200 | [diff] [blame] | 1266 | strbuf_addf(&url_buf, "%s (fetch)", remote->url[0]); |
| 1267 | string_list_append(remote->name, list)->util = |
| 1268 | strbuf_detach(&url_buf, NULL); |
Michael J Gruber | 7d20e21 | 2008-09-22 10:57:51 +0200 | [diff] [blame] | 1269 | } else |
| 1270 | string_list_append(remote->name, list)->util = NULL; |
Michael J Gruber | 4a4b4cd | 2009-06-13 18:29:11 +0200 | [diff] [blame] | 1271 | if (remote->pushurl_nr) { |
| 1272 | url = remote->pushurl; |
| 1273 | url_nr = remote->pushurl_nr; |
| 1274 | } else { |
| 1275 | url = remote->url; |
| 1276 | url_nr = remote->url_nr; |
| 1277 | } |
| 1278 | for (i = 0; i < url_nr; i++) |
| 1279 | { |
Bert Wesarg | 3f721d1 | 2009-06-23 00:27:44 +0200 | [diff] [blame] | 1280 | strbuf_addf(&url_buf, "%s (push)", url[i]); |
| 1281 | string_list_append(remote->name, list)->util = |
| 1282 | strbuf_detach(&url_buf, NULL); |
Michael J Gruber | 4a4b4cd | 2009-06-13 18:29:11 +0200 | [diff] [blame] | 1283 | } |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 1284 | |
| 1285 | return 0; |
| 1286 | } |
| 1287 | |
| 1288 | static int show_all(void) |
| 1289 | { |
Johannes Schindelin | c455c87 | 2008-07-21 19:03:49 +0100 | [diff] [blame] | 1290 | struct string_list list = { NULL, 0, 0 }; |
Michael J Gruber | 4a4b4cd | 2009-06-13 18:29:11 +0200 | [diff] [blame] | 1291 | int result; |
| 1292 | |
| 1293 | list.strdup_strings = 1; |
| 1294 | result = for_each_remote(get_one_entry, &list); |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 1295 | |
| 1296 | if (!result) { |
| 1297 | int i; |
| 1298 | |
Johannes Schindelin | c455c87 | 2008-07-21 19:03:49 +0100 | [diff] [blame] | 1299 | sort_string_list(&list); |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 1300 | for (i = 0; i < list.nr; i++) { |
Johannes Schindelin | c455c87 | 2008-07-21 19:03:49 +0100 | [diff] [blame] | 1301 | struct string_list_item *item = list.items + i; |
Michael J Gruber | 7d20e21 | 2008-09-22 10:57:51 +0200 | [diff] [blame] | 1302 | if (verbose) |
| 1303 | printf("%s\t%s\n", item->string, |
| 1304 | item->util ? (const char *)item->util : ""); |
| 1305 | else { |
| 1306 | if (i && !strcmp((item - 1)->string, item->string)) |
| 1307 | continue; |
| 1308 | printf("%s\n", item->string); |
| 1309 | } |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 1310 | } |
| 1311 | } |
Michael J Gruber | 4a4b4cd | 2009-06-13 18:29:11 +0200 | [diff] [blame] | 1312 | string_list_clear(&list, 1); |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 1313 | return result; |
| 1314 | } |
| 1315 | |
| 1316 | int cmd_remote(int argc, const char **argv, const char *prefix) |
| 1317 | { |
| 1318 | struct option options[] = { |
Tim Henigan | 4504107 | 2009-11-20 18:43:13 -0500 | [diff] [blame] | 1319 | OPT_BOOLEAN('v', "verbose", &verbose, "be verbose; must be placed before a subcommand"), |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 1320 | OPT_END() |
| 1321 | }; |
| 1322 | int result; |
| 1323 | |
Stephen Boyd | 3778292 | 2009-05-23 11:53:12 -0700 | [diff] [blame] | 1324 | argc = parse_options(argc, argv, prefix, options, builtin_remote_usage, |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 1325 | PARSE_OPT_STOP_AT_NON_OPTION); |
| 1326 | |
| 1327 | if (argc < 1) |
| 1328 | result = show_all(); |
| 1329 | else if (!strcmp(argv[0], "add")) |
| 1330 | result = add(argc, argv); |
Miklos Vajna | bf98421 | 2008-11-03 19:26:18 +0100 | [diff] [blame] | 1331 | else if (!strcmp(argv[0], "rename")) |
| 1332 | result = mv(argc, argv); |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 1333 | else if (!strcmp(argv[0], "rm")) |
| 1334 | result = rm(argc, argv); |
Jay Soffian | bc14fac | 2009-02-25 03:32:25 -0500 | [diff] [blame] | 1335 | else if (!strcmp(argv[0], "set-head")) |
| 1336 | result = set_head(argc, argv); |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 1337 | else if (!strcmp(argv[0], "show")) |
Olivier Marin | 67a7e2d | 2008-06-10 16:51:21 +0200 | [diff] [blame] | 1338 | result = show(argc, argv); |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 1339 | else if (!strcmp(argv[0], "prune")) |
Olivier Marin | 67a7e2d | 2008-06-10 16:51:21 +0200 | [diff] [blame] | 1340 | result = prune(argc, argv); |
Johannes Schindelin | 211c896 | 2008-02-29 01:45:45 +0000 | [diff] [blame] | 1341 | else if (!strcmp(argv[0], "update")) |
| 1342 | result = update(argc, argv); |
| 1343 | else { |
| 1344 | error("Unknown subcommand: %s", argv[0]); |
| 1345 | usage_with_options(builtin_remote_usage, options); |
| 1346 | } |
| 1347 | |
| 1348 | return result ? 1 : 0; |
| 1349 | } |