Linus Torvalds | 755225d | 2006-04-29 21:22:49 -0700 | [diff] [blame] | 1 | /* |
| 2 | * "git push" |
| 3 | */ |
| 4 | #include "cache.h" |
| 5 | #include "refs.h" |
| 6 | #include "run-command.h" |
| 7 | #include "builtin.h" |
| 8 | |
| 9 | #define MAX_URI (16) |
| 10 | |
Uwe Kleine-König | d23842f | 2007-01-19 13:49:27 +0100 | [diff] [blame] | 11 | static const char push_usage[] = "git-push [--all] [--tags] [--receive-pack=<git-receive-pack>] [--repo=all] [-f | --force] [-v] [<repository> <refspec>...]"; |
Linus Torvalds | 755225d | 2006-04-29 21:22:49 -0700 | [diff] [blame] | 12 | |
Linus Torvalds | bcc785f | 2006-10-30 08:28:59 -0800 | [diff] [blame] | 13 | static int all, tags, force, thin = 1, verbose; |
Uwe Kleine-König | d23842f | 2007-01-19 13:49:27 +0100 | [diff] [blame] | 14 | static const char *receivepack; |
Linus Torvalds | 755225d | 2006-04-29 21:22:49 -0700 | [diff] [blame] | 15 | |
| 16 | #define BUF_SIZE (2084) |
| 17 | static char buffer[BUF_SIZE]; |
| 18 | |
David Rientjes | 96f1e58 | 2006-08-15 10:23:48 -0700 | [diff] [blame] | 19 | static const char **refspec; |
| 20 | static int refspec_nr; |
Linus Torvalds | 755225d | 2006-04-29 21:22:49 -0700 | [diff] [blame] | 21 | |
| 22 | static void add_refspec(const char *ref) |
| 23 | { |
| 24 | int nr = refspec_nr + 1; |
| 25 | refspec = xrealloc(refspec, nr * sizeof(char *)); |
| 26 | refspec[nr-1] = ref; |
| 27 | refspec_nr = nr; |
| 28 | } |
| 29 | |
Junio C Hamano | 8da1977 | 2006-09-20 22:02:01 -0700 | [diff] [blame] | 30 | static int expand_one_ref(const char *ref, const unsigned char *sha1, int flag, void *cb_data) |
Linus Torvalds | 755225d | 2006-04-29 21:22:49 -0700 | [diff] [blame] | 31 | { |
| 32 | /* Ignore the "refs/" at the beginning of the refname */ |
| 33 | ref += 5; |
| 34 | |
Junio C Hamano | cc44c76 | 2007-02-20 01:53:29 -0800 | [diff] [blame] | 35 | if (!prefixcmp(ref, "tags/")) |
Shawn Pearce | 9befac4 | 2006-09-02 00:16:31 -0400 | [diff] [blame] | 36 | add_refspec(xstrdup(ref)); |
Linus Torvalds | 755225d | 2006-04-29 21:22:49 -0700 | [diff] [blame] | 37 | return 0; |
| 38 | } |
| 39 | |
| 40 | static void expand_refspecs(void) |
| 41 | { |
| 42 | if (all) { |
| 43 | if (refspec_nr) |
| 44 | die("cannot mix '--all' and a refspec"); |
| 45 | |
| 46 | /* |
| 47 | * No need to expand "--all" - we'll just use |
| 48 | * the "--all" flag to send-pack |
| 49 | */ |
| 50 | return; |
| 51 | } |
| 52 | if (!tags) |
| 53 | return; |
Junio C Hamano | cb5d709 | 2006-09-20 21:47:42 -0700 | [diff] [blame] | 54 | for_each_ref(expand_one_ref, NULL); |
Linus Torvalds | 755225d | 2006-04-29 21:22:49 -0700 | [diff] [blame] | 55 | } |
| 56 | |
Junio C Hamano | d46ae3f | 2007-02-05 23:01:14 -0800 | [diff] [blame] | 57 | struct wildcard_cb { |
| 58 | const char *from_prefix; |
| 59 | int from_prefix_len; |
| 60 | const char *to_prefix; |
| 61 | int to_prefix_len; |
| 62 | int force; |
| 63 | }; |
| 64 | |
| 65 | static int expand_wildcard_ref(const char *ref, const unsigned char *sha1, int flag, void *cb_data) |
| 66 | { |
| 67 | struct wildcard_cb *cb = cb_data; |
| 68 | int len = strlen(ref); |
| 69 | char *expanded, *newref; |
| 70 | |
| 71 | if (len < cb->from_prefix_len || |
| 72 | memcmp(cb->from_prefix, ref, cb->from_prefix_len)) |
| 73 | return 0; |
| 74 | expanded = xmalloc(len * 2 + cb->force + |
| 75 | (cb->to_prefix_len - cb->from_prefix_len) + 2); |
| 76 | newref = expanded + cb->force; |
| 77 | if (cb->force) |
| 78 | expanded[0] = '+'; |
| 79 | memcpy(newref, ref, len); |
| 80 | newref[len] = ':'; |
| 81 | memcpy(newref + len + 1, cb->to_prefix, cb->to_prefix_len); |
| 82 | strcpy(newref + len + 1 + cb->to_prefix_len, |
| 83 | ref + cb->from_prefix_len); |
| 84 | add_refspec(expanded); |
| 85 | return 0; |
| 86 | } |
| 87 | |
| 88 | static int wildcard_ref(const char *ref) |
| 89 | { |
| 90 | int len; |
| 91 | const char *colon; |
| 92 | struct wildcard_cb cb; |
| 93 | |
| 94 | memset(&cb, 0, sizeof(cb)); |
| 95 | if (ref[0] == '+') { |
| 96 | cb.force = 1; |
| 97 | ref++; |
| 98 | } |
| 99 | len = strlen(ref); |
| 100 | colon = strchr(ref, ':'); |
| 101 | if (! (colon && ref < colon && |
| 102 | colon[-2] == '/' && colon[-1] == '*' && |
| 103 | /* "<mine>/<asterisk>:<yours>/<asterisk>" is at least 7 bytes */ |
| 104 | 7 <= len && |
| 105 | ref[len-2] == '/' && ref[len-1] == '*') ) |
| 106 | return 0 ; |
| 107 | cb.from_prefix = ref; |
| 108 | cb.from_prefix_len = colon - ref - 1; |
| 109 | cb.to_prefix = colon + 1; |
| 110 | cb.to_prefix_len = len - (colon - ref) - 2; |
| 111 | for_each_ref(expand_wildcard_ref, &cb); |
| 112 | return 1; |
| 113 | } |
| 114 | |
Linus Torvalds | 755225d | 2006-04-29 21:22:49 -0700 | [diff] [blame] | 115 | static void set_refspecs(const char **refs, int nr) |
| 116 | { |
| 117 | if (nr) { |
Junio C Hamano | d46ae3f | 2007-02-05 23:01:14 -0800 | [diff] [blame] | 118 | int i; |
| 119 | for (i = 0; i < nr; i++) { |
| 120 | const char *ref = refs[i]; |
| 121 | if (!strcmp("tag", ref)) { |
| 122 | char *tag; |
| 123 | int len; |
| 124 | if (nr <= ++i) |
| 125 | die("tag shorthand without <tag>"); |
| 126 | len = strlen(refs[i]) + 11; |
| 127 | tag = xmalloc(len); |
| 128 | strcpy(tag, "refs/tags/"); |
| 129 | strcat(tag, refs[i]); |
| 130 | ref = tag; |
Junio C Hamano | 411fb8b | 2006-12-13 10:03:39 -0800 | [diff] [blame] | 131 | } |
Junio C Hamano | d46ae3f | 2007-02-05 23:01:14 -0800 | [diff] [blame] | 132 | else if (wildcard_ref(ref)) |
| 133 | continue; |
| 134 | add_refspec(ref); |
Junio C Hamano | 411fb8b | 2006-12-13 10:03:39 -0800 | [diff] [blame] | 135 | } |
Linus Torvalds | 755225d | 2006-04-29 21:22:49 -0700 | [diff] [blame] | 136 | } |
| 137 | expand_refspecs(); |
| 138 | } |
| 139 | |
| 140 | static int get_remotes_uri(const char *repo, const char *uri[MAX_URI]) |
| 141 | { |
| 142 | int n = 0; |
| 143 | FILE *f = fopen(git_path("remotes/%s", repo), "r"); |
Johannes Schindelin | 5edbcd8 | 2006-05-04 23:18:14 +0200 | [diff] [blame] | 144 | int has_explicit_refspec = refspec_nr || all || tags; |
Linus Torvalds | 755225d | 2006-04-29 21:22:49 -0700 | [diff] [blame] | 145 | |
| 146 | if (!f) |
| 147 | return -1; |
| 148 | while (fgets(buffer, BUF_SIZE, f)) { |
Johannes Schindelin | 5c477b9 | 2006-04-30 14:05:55 +0200 | [diff] [blame] | 149 | int is_refspec; |
Linus Torvalds | 755225d | 2006-04-29 21:22:49 -0700 | [diff] [blame] | 150 | char *s, *p; |
| 151 | |
Junio C Hamano | 599065a | 2007-02-20 01:54:00 -0800 | [diff] [blame] | 152 | if (!prefixcmp(buffer, "URL:")) { |
Johannes Schindelin | 5c477b9 | 2006-04-30 14:05:55 +0200 | [diff] [blame] | 153 | is_refspec = 0; |
Junio C Hamano | 6fe5b7f | 2006-10-02 00:43:52 -0700 | [diff] [blame] | 154 | s = buffer + 4; |
Junio C Hamano | 599065a | 2007-02-20 01:54:00 -0800 | [diff] [blame] | 155 | } else if (!prefixcmp(buffer, "Push:")) { |
Johannes Schindelin | 5c477b9 | 2006-04-30 14:05:55 +0200 | [diff] [blame] | 156 | is_refspec = 1; |
Junio C Hamano | 6fe5b7f | 2006-10-02 00:43:52 -0700 | [diff] [blame] | 157 | s = buffer + 5; |
Johannes Schindelin | 5c477b9 | 2006-04-30 14:05:55 +0200 | [diff] [blame] | 158 | } else |
Linus Torvalds | 755225d | 2006-04-29 21:22:49 -0700 | [diff] [blame] | 159 | continue; |
Linus Torvalds | 755225d | 2006-04-29 21:22:49 -0700 | [diff] [blame] | 160 | |
| 161 | /* Remove whitespace at the head.. */ |
| 162 | while (isspace(*s)) |
| 163 | s++; |
| 164 | if (!*s) |
| 165 | continue; |
| 166 | |
| 167 | /* ..and at the end */ |
| 168 | p = s + strlen(s); |
| 169 | while (isspace(p[-1])) |
| 170 | *--p = 0; |
| 171 | |
Junio C Hamano | 7aaf83d | 2006-04-30 16:03:27 -0700 | [diff] [blame] | 172 | if (!is_refspec) { |
| 173 | if (n < MAX_URI) |
Shawn Pearce | 9befac4 | 2006-09-02 00:16:31 -0400 | [diff] [blame] | 174 | uri[n++] = xstrdup(s); |
Junio C Hamano | 7aaf83d | 2006-04-30 16:03:27 -0700 | [diff] [blame] | 175 | else |
Pavel Roskin | 82e5a82 | 2006-07-10 01:50:18 -0400 | [diff] [blame] | 176 | error("more than %d URL's specified, ignoring the rest", MAX_URI); |
Junio C Hamano | 7aaf83d | 2006-04-30 16:03:27 -0700 | [diff] [blame] | 177 | } |
Junio C Hamano | d46ae3f | 2007-02-05 23:01:14 -0800 | [diff] [blame] | 178 | else if (is_refspec && !has_explicit_refspec) { |
| 179 | if (!wildcard_ref(s)) |
| 180 | add_refspec(xstrdup(s)); |
| 181 | } |
Linus Torvalds | 755225d | 2006-04-29 21:22:49 -0700 | [diff] [blame] | 182 | } |
| 183 | fclose(f); |
| 184 | if (!n) |
| 185 | die("remote '%s' has no URL", repo); |
| 186 | return n; |
| 187 | } |
| 188 | |
Johannes Schindelin | 97d4df0 | 2006-04-30 15:23:48 +0200 | [diff] [blame] | 189 | static const char **config_uri; |
| 190 | static const char *config_repo; |
| 191 | static int config_repo_len; |
| 192 | static int config_current_uri; |
| 193 | static int config_get_refspecs; |
Uwe Kleine-König | 060aafc | 2007-01-19 13:46:16 +0100 | [diff] [blame] | 194 | static int config_get_receivepack; |
Johannes Schindelin | 97d4df0 | 2006-04-30 15:23:48 +0200 | [diff] [blame] | 195 | |
| 196 | static int get_remote_config(const char* key, const char* value) |
| 197 | { |
Junio C Hamano | cc44c76 | 2007-02-20 01:53:29 -0800 | [diff] [blame] | 198 | if (!prefixcmp(key, "remote.") && |
Johannes Schindelin | 97d4df0 | 2006-04-30 15:23:48 +0200 | [diff] [blame] | 199 | !strncmp(key + 7, config_repo, config_repo_len)) { |
| 200 | if (!strcmp(key + 7 + config_repo_len, ".url")) { |
| 201 | if (config_current_uri < MAX_URI) |
Shawn Pearce | 9befac4 | 2006-09-02 00:16:31 -0400 | [diff] [blame] | 202 | config_uri[config_current_uri++] = xstrdup(value); |
Johannes Schindelin | 97d4df0 | 2006-04-30 15:23:48 +0200 | [diff] [blame] | 203 | else |
| 204 | error("more than %d URL's specified, ignoring the rest", MAX_URI); |
| 205 | } |
| 206 | else if (config_get_refspecs && |
Junio C Hamano | d46ae3f | 2007-02-05 23:01:14 -0800 | [diff] [blame] | 207 | !strcmp(key + 7 + config_repo_len, ".push")) { |
| 208 | if (!wildcard_ref(value)) |
| 209 | add_refspec(xstrdup(value)); |
| 210 | } |
Uwe Kleine-König | 060aafc | 2007-01-19 13:46:16 +0100 | [diff] [blame] | 211 | else if (config_get_receivepack && |
| 212 | !strcmp(key + 7 + config_repo_len, ".receivepack")) { |
Uwe Kleine-König | d23842f | 2007-01-19 13:49:27 +0100 | [diff] [blame] | 213 | if (!receivepack) { |
| 214 | char *rp = xmalloc(strlen(value) + 16); |
| 215 | sprintf(rp, "--receive-pack=%s", value); |
| 216 | receivepack = rp; |
Uwe Kleine-König | 060aafc | 2007-01-19 13:46:16 +0100 | [diff] [blame] | 217 | } else |
| 218 | error("more than one receivepack given, using the first"); |
| 219 | } |
Johannes Schindelin | 97d4df0 | 2006-04-30 15:23:48 +0200 | [diff] [blame] | 220 | } |
| 221 | return 0; |
| 222 | } |
| 223 | |
| 224 | static int get_config_remotes_uri(const char *repo, const char *uri[MAX_URI]) |
| 225 | { |
| 226 | config_repo_len = strlen(repo); |
| 227 | config_repo = repo; |
| 228 | config_current_uri = 0; |
| 229 | config_uri = uri; |
Johannes Schindelin | 5edbcd8 | 2006-05-04 23:18:14 +0200 | [diff] [blame] | 230 | config_get_refspecs = !(refspec_nr || all || tags); |
Uwe Kleine-König | d23842f | 2007-01-19 13:49:27 +0100 | [diff] [blame] | 231 | config_get_receivepack = (receivepack == NULL); |
Johannes Schindelin | 97d4df0 | 2006-04-30 15:23:48 +0200 | [diff] [blame] | 232 | |
| 233 | git_config(get_remote_config); |
| 234 | return config_current_uri; |
| 235 | } |
| 236 | |
Linus Torvalds | 755225d | 2006-04-29 21:22:49 -0700 | [diff] [blame] | 237 | static int get_branches_uri(const char *repo, const char *uri[MAX_URI]) |
| 238 | { |
| 239 | const char *slash = strchr(repo, '/'); |
| 240 | int n = slash ? slash - repo : 1000; |
| 241 | FILE *f = fopen(git_path("branches/%.*s", n, repo), "r"); |
| 242 | char *s, *p; |
| 243 | int len; |
| 244 | |
| 245 | if (!f) |
| 246 | return 0; |
| 247 | s = fgets(buffer, BUF_SIZE, f); |
| 248 | fclose(f); |
| 249 | if (!s) |
| 250 | return 0; |
| 251 | while (isspace(*s)) |
| 252 | s++; |
| 253 | if (!*s) |
| 254 | return 0; |
| 255 | p = s + strlen(s); |
| 256 | while (isspace(p[-1])) |
| 257 | *--p = 0; |
| 258 | len = p - s; |
| 259 | if (slash) |
| 260 | len += strlen(slash); |
| 261 | p = xmalloc(len + 1); |
| 262 | strcpy(p, s); |
| 263 | if (slash) |
| 264 | strcat(p, slash); |
| 265 | uri[0] = p; |
| 266 | return 1; |
| 267 | } |
| 268 | |
Junio C Hamano | 7aaf83d | 2006-04-30 16:03:27 -0700 | [diff] [blame] | 269 | /* |
| 270 | * Read remotes and branches file, fill the push target URI |
| 271 | * list. If there is no command line refspecs, read Push: lines |
| 272 | * to set up the *refspec list as well. |
| 273 | * return the number of push target URIs |
| 274 | */ |
| 275 | static int read_config(const char *repo, const char *uri[MAX_URI]) |
Linus Torvalds | 755225d | 2006-04-29 21:22:49 -0700 | [diff] [blame] | 276 | { |
| 277 | int n; |
| 278 | |
| 279 | if (*repo != '/') { |
| 280 | n = get_remotes_uri(repo, uri); |
| 281 | if (n > 0) |
| 282 | return n; |
| 283 | |
Johannes Schindelin | 97d4df0 | 2006-04-30 15:23:48 +0200 | [diff] [blame] | 284 | n = get_config_remotes_uri(repo, uri); |
| 285 | if (n > 0) |
| 286 | return n; |
| 287 | |
Linus Torvalds | 755225d | 2006-04-29 21:22:49 -0700 | [diff] [blame] | 288 | n = get_branches_uri(repo, uri); |
| 289 | if (n > 0) |
| 290 | return n; |
| 291 | } |
| 292 | |
| 293 | uri[0] = repo; |
| 294 | return 1; |
| 295 | } |
| 296 | |
| 297 | static int do_push(const char *repo) |
| 298 | { |
| 299 | const char *uri[MAX_URI]; |
Junio C Hamano | fd1d1b0 | 2007-04-06 23:04:53 -0700 | [diff] [blame] | 300 | int i, n, errs; |
Nick Hengeveld | 441c823 | 2006-06-05 13:02:29 -0700 | [diff] [blame] | 301 | int common_argc; |
Linus Torvalds | 755225d | 2006-04-29 21:22:49 -0700 | [diff] [blame] | 302 | const char **argv; |
| 303 | int argc; |
| 304 | |
Junio C Hamano | 7aaf83d | 2006-04-30 16:03:27 -0700 | [diff] [blame] | 305 | n = read_config(repo, uri); |
Linus Torvalds | 755225d | 2006-04-29 21:22:49 -0700 | [diff] [blame] | 306 | if (n <= 0) |
| 307 | die("bad repository '%s'", repo); |
| 308 | |
Linus Torvalds | 755225d | 2006-04-29 21:22:49 -0700 | [diff] [blame] | 309 | argv = xmalloc((refspec_nr + 10) * sizeof(char *)); |
| 310 | argv[0] = "dummy-send-pack"; |
| 311 | argc = 1; |
| 312 | if (all) |
| 313 | argv[argc++] = "--all"; |
| 314 | if (force) |
| 315 | argv[argc++] = "--force"; |
Uwe Kleine-König | d23842f | 2007-01-19 13:49:27 +0100 | [diff] [blame] | 316 | if (receivepack) |
| 317 | argv[argc++] = receivepack; |
Nick Hengeveld | 441c823 | 2006-06-05 13:02:29 -0700 | [diff] [blame] | 318 | common_argc = argc; |
Linus Torvalds | 755225d | 2006-04-29 21:22:49 -0700 | [diff] [blame] | 319 | |
Junio C Hamano | fd1d1b0 | 2007-04-06 23:04:53 -0700 | [diff] [blame] | 320 | errs = 0; |
Linus Torvalds | 755225d | 2006-04-29 21:22:49 -0700 | [diff] [blame] | 321 | for (i = 0; i < n; i++) { |
Pierre Habouzit | 60b7f38 | 2006-08-23 12:39:10 +0200 | [diff] [blame] | 322 | int err; |
Nick Hengeveld | 441c823 | 2006-06-05 13:02:29 -0700 | [diff] [blame] | 323 | int dest_argc = common_argc; |
| 324 | int dest_refspec_nr = refspec_nr; |
| 325 | const char **dest_refspec = refspec; |
Linus Torvalds | 755225d | 2006-04-29 21:22:49 -0700 | [diff] [blame] | 326 | const char *dest = uri[i]; |
Shawn O. Pearce | df91ba3 | 2007-03-12 19:00:15 -0400 | [diff] [blame] | 327 | const char *sender = "send-pack"; |
Junio C Hamano | cc44c76 | 2007-02-20 01:53:29 -0800 | [diff] [blame] | 328 | if (!prefixcmp(dest, "http://") || |
| 329 | !prefixcmp(dest, "https://")) |
Shawn O. Pearce | df91ba3 | 2007-03-12 19:00:15 -0400 | [diff] [blame] | 330 | sender = "http-push"; |
Nick Hengeveld | 441c823 | 2006-06-05 13:02:29 -0700 | [diff] [blame] | 331 | else if (thin) |
| 332 | argv[dest_argc++] = "--thin"; |
Linus Torvalds | 755225d | 2006-04-29 21:22:49 -0700 | [diff] [blame] | 333 | argv[0] = sender; |
Nick Hengeveld | 441c823 | 2006-06-05 13:02:29 -0700 | [diff] [blame] | 334 | argv[dest_argc++] = dest; |
| 335 | while (dest_refspec_nr--) |
| 336 | argv[dest_argc++] = *dest_refspec++; |
| 337 | argv[dest_argc] = NULL; |
Linus Torvalds | bcc785f | 2006-10-30 08:28:59 -0800 | [diff] [blame] | 338 | if (verbose) |
| 339 | fprintf(stderr, "Pushing to %s\n", dest); |
Shawn O. Pearce | df91ba3 | 2007-03-12 19:00:15 -0400 | [diff] [blame] | 340 | err = run_command_v_opt(argv, RUN_GIT_CMD); |
Pierre Habouzit | 60b7f38 | 2006-08-23 12:39:10 +0200 | [diff] [blame] | 341 | if (!err) |
Linus Torvalds | 755225d | 2006-04-29 21:22:49 -0700 | [diff] [blame] | 342 | continue; |
Junio C Hamano | 39878b0 | 2007-04-06 23:04:55 -0700 | [diff] [blame] | 343 | |
| 344 | error("failed to push to '%s'", uri[i]); |
Pierre Habouzit | 60b7f38 | 2006-08-23 12:39:10 +0200 | [diff] [blame] | 345 | switch (err) { |
Linus Torvalds | 755225d | 2006-04-29 21:22:49 -0700 | [diff] [blame] | 346 | case -ERR_RUN_COMMAND_FORK: |
Junio C Hamano | fd1d1b0 | 2007-04-06 23:04:53 -0700 | [diff] [blame] | 347 | error("unable to fork for %s", sender); |
Linus Torvalds | 755225d | 2006-04-29 21:22:49 -0700 | [diff] [blame] | 348 | case -ERR_RUN_COMMAND_EXEC: |
Junio C Hamano | fd1d1b0 | 2007-04-06 23:04:53 -0700 | [diff] [blame] | 349 | error("unable to exec %s", sender); |
| 350 | break; |
Linus Torvalds | 755225d | 2006-04-29 21:22:49 -0700 | [diff] [blame] | 351 | case -ERR_RUN_COMMAND_WAITPID: |
| 352 | case -ERR_RUN_COMMAND_WAITPID_WRONG_PID: |
| 353 | case -ERR_RUN_COMMAND_WAITPID_SIGNAL: |
| 354 | case -ERR_RUN_COMMAND_WAITPID_NOEXIT: |
Junio C Hamano | fd1d1b0 | 2007-04-06 23:04:53 -0700 | [diff] [blame] | 355 | error("%s died with strange error", sender); |
Linus Torvalds | 755225d | 2006-04-29 21:22:49 -0700 | [diff] [blame] | 356 | } |
Junio C Hamano | fd1d1b0 | 2007-04-06 23:04:53 -0700 | [diff] [blame] | 357 | errs++; |
Linus Torvalds | 755225d | 2006-04-29 21:22:49 -0700 | [diff] [blame] | 358 | } |
Junio C Hamano | fd1d1b0 | 2007-04-06 23:04:53 -0700 | [diff] [blame] | 359 | return !!errs; |
Linus Torvalds | 755225d | 2006-04-29 21:22:49 -0700 | [diff] [blame] | 360 | } |
| 361 | |
Linus Torvalds | a633fca | 2006-07-28 22:44:25 -0700 | [diff] [blame] | 362 | int cmd_push(int argc, const char **argv, const char *prefix) |
Linus Torvalds | 755225d | 2006-04-29 21:22:49 -0700 | [diff] [blame] | 363 | { |
| 364 | int i; |
Pavel Roskin | a9486b0 | 2006-07-10 02:57:51 -0400 | [diff] [blame] | 365 | const char *repo = "origin"; /* default repository */ |
Linus Torvalds | 755225d | 2006-04-29 21:22:49 -0700 | [diff] [blame] | 366 | |
| 367 | for (i = 1; i < argc; i++) { |
| 368 | const char *arg = argv[i]; |
| 369 | |
| 370 | if (arg[0] != '-') { |
| 371 | repo = arg; |
| 372 | i++; |
| 373 | break; |
| 374 | } |
Linus Torvalds | bcc785f | 2006-10-30 08:28:59 -0800 | [diff] [blame] | 375 | if (!strcmp(arg, "-v")) { |
| 376 | verbose=1; |
| 377 | continue; |
| 378 | } |
Junio C Hamano | cc44c76 | 2007-02-20 01:53:29 -0800 | [diff] [blame] | 379 | if (!prefixcmp(arg, "--repo=")) { |
Linus Torvalds | bcc785f | 2006-10-30 08:28:59 -0800 | [diff] [blame] | 380 | repo = arg+7; |
| 381 | continue; |
| 382 | } |
Linus Torvalds | 755225d | 2006-04-29 21:22:49 -0700 | [diff] [blame] | 383 | if (!strcmp(arg, "--all")) { |
| 384 | all = 1; |
| 385 | continue; |
| 386 | } |
| 387 | if (!strcmp(arg, "--tags")) { |
| 388 | tags = 1; |
| 389 | continue; |
| 390 | } |
Jeff King | 8f61549 | 2006-08-02 11:28:16 -0400 | [diff] [blame] | 391 | if (!strcmp(arg, "--force") || !strcmp(arg, "-f")) { |
Linus Torvalds | 755225d | 2006-04-29 21:22:49 -0700 | [diff] [blame] | 392 | force = 1; |
| 393 | continue; |
| 394 | } |
| 395 | if (!strcmp(arg, "--thin")) { |
| 396 | thin = 1; |
| 397 | continue; |
| 398 | } |
| 399 | if (!strcmp(arg, "--no-thin")) { |
| 400 | thin = 0; |
| 401 | continue; |
| 402 | } |
Junio C Hamano | cc44c76 | 2007-02-20 01:53:29 -0800 | [diff] [blame] | 403 | if (!prefixcmp(arg, "--receive-pack=")) { |
Uwe Kleine-König | d23842f | 2007-01-19 13:49:27 +0100 | [diff] [blame] | 404 | receivepack = arg; |
| 405 | continue; |
| 406 | } |
Junio C Hamano | cc44c76 | 2007-02-20 01:53:29 -0800 | [diff] [blame] | 407 | if (!prefixcmp(arg, "--exec=")) { |
Uwe Kleine-König | d23842f | 2007-01-19 13:49:27 +0100 | [diff] [blame] | 408 | receivepack = arg; |
Linus Torvalds | 755225d | 2006-04-29 21:22:49 -0700 | [diff] [blame] | 409 | continue; |
| 410 | } |
| 411 | usage(push_usage); |
| 412 | } |
| 413 | set_refspecs(argv + i, argc - i); |
| 414 | return do_push(repo); |
| 415 | } |