push: anonymize URLs in error messages and warnings
[git] / builtin / push.c
1 /*
2  * "git push"
3  */
4 #include "cache.h"
5 #include "config.h"
6 #include "refs.h"
7 #include "refspec.h"
8 #include "run-command.h"
9 #include "builtin.h"
10 #include "remote.h"
11 #include "transport.h"
12 #include "parse-options.h"
13 #include "submodule.h"
14 #include "submodule-config.h"
15 #include "send-pack.h"
16 #include "color.h"
17
18 static const char * const push_usage[] = {
19         N_("git push [<options>] [<repository> [<refspec>...]]"),
20         NULL,
21 };
22
23 static int push_use_color = -1;
24 static char push_colors[][COLOR_MAXLEN] = {
25         GIT_COLOR_RESET,
26         GIT_COLOR_RED,  /* ERROR */
27 };
28
29 enum color_push {
30         PUSH_COLOR_RESET = 0,
31         PUSH_COLOR_ERROR = 1
32 };
33
34 static int parse_push_color_slot(const char *slot)
35 {
36         if (!strcasecmp(slot, "reset"))
37                 return PUSH_COLOR_RESET;
38         if (!strcasecmp(slot, "error"))
39                 return PUSH_COLOR_ERROR;
40         return -1;
41 }
42
43 static const char *push_get_color(enum color_push ix)
44 {
45         if (want_color_stderr(push_use_color))
46                 return push_colors[ix];
47         return "";
48 }
49
50 static int thin = 1;
51 static int deleterefs;
52 static const char *receivepack;
53 static int verbosity;
54 static int progress = -1;
55 static int recurse_submodules = RECURSE_SUBMODULES_DEFAULT;
56 static enum transport_family family;
57
58 static struct push_cas_option cas;
59
60 static struct refspec rs = REFSPEC_INIT_PUSH;
61
62 static struct string_list push_options_config = STRING_LIST_INIT_DUP;
63
64 static const char *map_refspec(const char *ref,
65                                struct remote *remote, struct ref *local_refs)
66 {
67         const char *branch_name;
68         struct ref *matched = NULL;
69
70         /* Does "ref" uniquely name our ref? */
71         if (count_refspec_match(ref, local_refs, &matched) != 1)
72                 return ref;
73
74         if (remote->push.nr) {
75                 struct refspec_item query;
76                 memset(&query, 0, sizeof(struct refspec_item));
77                 query.src = matched->name;
78                 if (!query_refspecs(&remote->push, &query) && query.dst) {
79                         struct strbuf buf = STRBUF_INIT;
80                         strbuf_addf(&buf, "%s%s:%s",
81                                     query.force ? "+" : "",
82                                     query.src, query.dst);
83                         return strbuf_detach(&buf, NULL);
84                 }
85         }
86
87         if (push_default == PUSH_DEFAULT_UPSTREAM &&
88             skip_prefix(matched->name, "refs/heads/", &branch_name)) {
89                 struct branch *branch = branch_get(branch_name);
90                 if (branch->merge_nr == 1 && branch->merge[0]->src) {
91                         struct strbuf buf = STRBUF_INIT;
92                         strbuf_addf(&buf, "%s:%s",
93                                     ref, branch->merge[0]->src);
94                         return strbuf_detach(&buf, NULL);
95                 }
96         }
97
98         return ref;
99 }
100
101 static void set_refspecs(const char **refs, int nr, const char *repo)
102 {
103         struct remote *remote = NULL;
104         struct ref *local_refs = NULL;
105         int i;
106
107         for (i = 0; i < nr; i++) {
108                 const char *ref = refs[i];
109                 if (!strcmp("tag", ref)) {
110                         struct strbuf tagref = STRBUF_INIT;
111                         if (nr <= ++i)
112                                 die(_("tag shorthand without <tag>"));
113                         ref = refs[i];
114                         if (deleterefs)
115                                 strbuf_addf(&tagref, ":refs/tags/%s", ref);
116                         else
117                                 strbuf_addf(&tagref, "refs/tags/%s", ref);
118                         ref = strbuf_detach(&tagref, NULL);
119                 } else if (deleterefs) {
120                         struct strbuf delref = STRBUF_INIT;
121                         if (strchr(ref, ':'))
122                                 die(_("--delete only accepts plain target ref names"));
123                         strbuf_addf(&delref, ":%s", ref);
124                         ref = strbuf_detach(&delref, NULL);
125                 } else if (!strchr(ref, ':')) {
126                         if (!remote) {
127                                 /* lazily grab remote and local_refs */
128                                 remote = remote_get(repo);
129                                 local_refs = get_local_heads();
130                         }
131                         ref = map_refspec(ref, remote, local_refs);
132                 }
133                 refspec_append(&rs, ref);
134         }
135 }
136
137 static int push_url_of_remote(struct remote *remote, const char ***url_p)
138 {
139         if (remote->pushurl_nr) {
140                 *url_p = remote->pushurl;
141                 return remote->pushurl_nr;
142         }
143         *url_p = remote->url;
144         return remote->url_nr;
145 }
146
147 static NORETURN void die_push_simple(struct branch *branch,
148                                      struct remote *remote)
149 {
150         /*
151          * There's no point in using shorten_unambiguous_ref here,
152          * as the ambiguity would be on the remote side, not what
153          * we have locally. Plus, this is supposed to be the simple
154          * mode. If the user is doing something crazy like setting
155          * upstream to a non-branch, we should probably be showing
156          * them the big ugly fully qualified ref.
157          */
158         const char *advice_maybe = "";
159         const char *short_upstream = branch->merge[0]->src;
160
161         skip_prefix(short_upstream, "refs/heads/", &short_upstream);
162
163         /*
164          * Don't show advice for people who explicitly set
165          * push.default.
166          */
167         if (push_default == PUSH_DEFAULT_UNSPECIFIED)
168                 advice_maybe = _("\n"
169                                  "To choose either option permanently, "
170                                  "see push.default in 'git help config'.");
171         die(_("The upstream branch of your current branch does not match\n"
172               "the name of your current branch.  To push to the upstream branch\n"
173               "on the remote, use\n"
174               "\n"
175               "    git push %s HEAD:%s\n"
176               "\n"
177               "To push to the branch of the same name on the remote, use\n"
178               "\n"
179               "    git push %s HEAD\n"
180               "%s"),
181             remote->name, short_upstream,
182             remote->name, advice_maybe);
183 }
184
185 static const char message_detached_head_die[] =
186         N_("You are not currently on a branch.\n"
187            "To push the history leading to the current (detached HEAD)\n"
188            "state now, use\n"
189            "\n"
190            "    git push %s HEAD:<name-of-remote-branch>\n");
191
192 static void setup_push_upstream(struct remote *remote, struct branch *branch,
193                                 int triangular, int simple)
194 {
195         struct strbuf refspec = STRBUF_INIT;
196
197         if (!branch)
198                 die(_(message_detached_head_die), remote->name);
199         if (!branch->merge_nr || !branch->merge || !branch->remote_name)
200                 die(_("The current branch %s has no upstream branch.\n"
201                     "To push the current branch and set the remote as upstream, use\n"
202                     "\n"
203                     "    git push --set-upstream %s %s\n"),
204                     branch->name,
205                     remote->name,
206                     branch->name);
207         if (branch->merge_nr != 1)
208                 die(_("The current branch %s has multiple upstream branches, "
209                     "refusing to push."), branch->name);
210         if (triangular)
211                 die(_("You are pushing to remote '%s', which is not the upstream of\n"
212                       "your current branch '%s', without telling me what to push\n"
213                       "to update which remote branch."),
214                     remote->name, branch->name);
215
216         if (simple) {
217                 /* Additional safety */
218                 if (strcmp(branch->refname, branch->merge[0]->src))
219                         die_push_simple(branch, remote);
220         }
221
222         strbuf_addf(&refspec, "%s:%s", branch->refname, branch->merge[0]->src);
223         refspec_append(&rs, refspec.buf);
224 }
225
226 static void setup_push_current(struct remote *remote, struct branch *branch)
227 {
228         struct strbuf refspec = STRBUF_INIT;
229
230         if (!branch)
231                 die(_(message_detached_head_die), remote->name);
232         strbuf_addf(&refspec, "%s:%s", branch->refname, branch->refname);
233         refspec_append(&rs, refspec.buf);
234 }
235
236 static int is_workflow_triangular(struct remote *remote)
237 {
238         struct remote *fetch_remote = remote_get(NULL);
239         return (fetch_remote && fetch_remote != remote);
240 }
241
242 static void setup_default_push_refspecs(struct remote *remote)
243 {
244         struct branch *branch = branch_get(NULL);
245         int triangular = is_workflow_triangular(remote);
246
247         switch (push_default) {
248         default:
249         case PUSH_DEFAULT_MATCHING:
250                 refspec_append(&rs, ":");
251                 break;
252
253         case PUSH_DEFAULT_UNSPECIFIED:
254         case PUSH_DEFAULT_SIMPLE:
255                 if (triangular)
256                         setup_push_current(remote, branch);
257                 else
258                         setup_push_upstream(remote, branch, triangular, 1);
259                 break;
260
261         case PUSH_DEFAULT_UPSTREAM:
262                 setup_push_upstream(remote, branch, triangular, 0);
263                 break;
264
265         case PUSH_DEFAULT_CURRENT:
266                 setup_push_current(remote, branch);
267                 break;
268
269         case PUSH_DEFAULT_NOTHING:
270                 die(_("You didn't specify any refspecs to push, and "
271                     "push.default is \"nothing\"."));
272                 break;
273         }
274 }
275
276 static const char message_advice_pull_before_push[] =
277         N_("Updates were rejected because the tip of your current branch is behind\n"
278            "its remote counterpart. Integrate the remote changes (e.g.\n"
279            "'git pull ...') before pushing again.\n"
280            "See the 'Note about fast-forwards' in 'git push --help' for details.");
281
282 static const char message_advice_checkout_pull_push[] =
283         N_("Updates were rejected because a pushed branch tip is behind its remote\n"
284            "counterpart. Check out this branch and integrate the remote changes\n"
285            "(e.g. 'git pull ...') before pushing again.\n"
286            "See the 'Note about fast-forwards' in 'git push --help' for details.");
287
288 static const char message_advice_ref_fetch_first[] =
289         N_("Updates were rejected because the remote contains work that you do\n"
290            "not have locally. This is usually caused by another repository pushing\n"
291            "to the same ref. You may want to first integrate the remote changes\n"
292            "(e.g., 'git pull ...') before pushing again.\n"
293            "See the 'Note about fast-forwards' in 'git push --help' for details.");
294
295 static const char message_advice_ref_already_exists[] =
296         N_("Updates were rejected because the tag already exists in the remote.");
297
298 static const char message_advice_ref_needs_force[] =
299         N_("You cannot update a remote ref that points at a non-commit object,\n"
300            "or update a remote ref to make it point at a non-commit object,\n"
301            "without using the '--force' option.\n");
302
303 static void advise_pull_before_push(void)
304 {
305         if (!advice_push_non_ff_current || !advice_push_update_rejected)
306                 return;
307         advise(_(message_advice_pull_before_push));
308 }
309
310 static void advise_checkout_pull_push(void)
311 {
312         if (!advice_push_non_ff_matching || !advice_push_update_rejected)
313                 return;
314         advise(_(message_advice_checkout_pull_push));
315 }
316
317 static void advise_ref_already_exists(void)
318 {
319         if (!advice_push_already_exists || !advice_push_update_rejected)
320                 return;
321         advise(_(message_advice_ref_already_exists));
322 }
323
324 static void advise_ref_fetch_first(void)
325 {
326         if (!advice_push_fetch_first || !advice_push_update_rejected)
327                 return;
328         advise(_(message_advice_ref_fetch_first));
329 }
330
331 static void advise_ref_needs_force(void)
332 {
333         if (!advice_push_needs_force || !advice_push_update_rejected)
334                 return;
335         advise(_(message_advice_ref_needs_force));
336 }
337
338 static int push_with_options(struct transport *transport, struct refspec *rs,
339                              int flags)
340 {
341         int err;
342         unsigned int reject_reasons;
343         char *anon_url = transport_anonymize_url(transport->url);
344
345         transport_set_verbosity(transport, verbosity, progress);
346         transport->family = family;
347
348         if (receivepack)
349                 transport_set_option(transport,
350                                      TRANS_OPT_RECEIVEPACK, receivepack);
351         transport_set_option(transport, TRANS_OPT_THIN, thin ? "yes" : NULL);
352
353         if (!is_empty_cas(&cas)) {
354                 if (!transport->smart_options)
355                         die("underlying transport does not support --%s option",
356                             CAS_OPT_NAME);
357                 transport->smart_options->cas = &cas;
358         }
359
360         if (verbosity > 0)
361                 fprintf(stderr, _("Pushing to %s\n"), anon_url);
362         trace2_region_enter("push", "transport_push", the_repository);
363         err = transport_push(the_repository, transport,
364                              rs, flags, &reject_reasons);
365         trace2_region_leave("push", "transport_push", the_repository);
366         if (err != 0) {
367                 fprintf(stderr, "%s", push_get_color(PUSH_COLOR_ERROR));
368                 error(_("failed to push some refs to '%s'"), anon_url);
369                 fprintf(stderr, "%s", push_get_color(PUSH_COLOR_RESET));
370         }
371
372         err |= transport_disconnect(transport);
373         free(anon_url);
374         if (!err)
375                 return 0;
376
377         if (reject_reasons & REJECT_NON_FF_HEAD) {
378                 advise_pull_before_push();
379         } else if (reject_reasons & REJECT_NON_FF_OTHER) {
380                 advise_checkout_pull_push();
381         } else if (reject_reasons & REJECT_ALREADY_EXISTS) {
382                 advise_ref_already_exists();
383         } else if (reject_reasons & REJECT_FETCH_FIRST) {
384                 advise_ref_fetch_first();
385         } else if (reject_reasons & REJECT_NEEDS_FORCE) {
386                 advise_ref_needs_force();
387         }
388
389         return 1;
390 }
391
392 static int do_push(const char *repo, int flags,
393                    const struct string_list *push_options,
394                    struct remote *remote)
395 {
396         int i, errs;
397         const char **url;
398         int url_nr;
399         struct refspec *push_refspec = &rs;
400
401         if (push_options->nr)
402                 flags |= TRANSPORT_PUSH_OPTIONS;
403
404         if (!push_refspec->nr && !(flags & TRANSPORT_PUSH_ALL)) {
405                 if (remote->push.nr) {
406                         push_refspec = &remote->push;
407                 } else if (!(flags & TRANSPORT_PUSH_MIRROR))
408                         setup_default_push_refspecs(remote);
409         }
410         errs = 0;
411         url_nr = push_url_of_remote(remote, &url);
412         if (url_nr) {
413                 for (i = 0; i < url_nr; i++) {
414                         struct transport *transport =
415                                 transport_get(remote, url[i]);
416                         if (flags & TRANSPORT_PUSH_OPTIONS)
417                                 transport->push_options = push_options;
418                         if (push_with_options(transport, push_refspec, flags))
419                                 errs++;
420                 }
421         } else {
422                 struct transport *transport =
423                         transport_get(remote, NULL);
424                 if (flags & TRANSPORT_PUSH_OPTIONS)
425                         transport->push_options = push_options;
426                 if (push_with_options(transport, push_refspec, flags))
427                         errs++;
428         }
429         return !!errs;
430 }
431
432 static int option_parse_recurse_submodules(const struct option *opt,
433                                    const char *arg, int unset)
434 {
435         int *recurse_submodules = opt->value;
436
437         if (unset)
438                 *recurse_submodules = RECURSE_SUBMODULES_OFF;
439         else if (arg)
440                 *recurse_submodules = parse_push_recurse_submodules_arg(opt->long_name, arg);
441         else
442                 die("%s missing parameter", opt->long_name);
443
444         return 0;
445 }
446
447 static void set_push_cert_flags(int *flags, int v)
448 {
449         switch (v) {
450         case SEND_PACK_PUSH_CERT_NEVER:
451                 *flags &= ~(TRANSPORT_PUSH_CERT_ALWAYS | TRANSPORT_PUSH_CERT_IF_ASKED);
452                 break;
453         case SEND_PACK_PUSH_CERT_ALWAYS:
454                 *flags |= TRANSPORT_PUSH_CERT_ALWAYS;
455                 *flags &= ~TRANSPORT_PUSH_CERT_IF_ASKED;
456                 break;
457         case SEND_PACK_PUSH_CERT_IF_ASKED:
458                 *flags |= TRANSPORT_PUSH_CERT_IF_ASKED;
459                 *flags &= ~TRANSPORT_PUSH_CERT_ALWAYS;
460                 break;
461         }
462 }
463
464
465 static int git_push_config(const char *k, const char *v, void *cb)
466 {
467         const char *slot_name;
468         int *flags = cb;
469         int status;
470
471         status = git_gpg_config(k, v, NULL);
472         if (status)
473                 return status;
474
475         if (!strcmp(k, "push.followtags")) {
476                 if (git_config_bool(k, v))
477                         *flags |= TRANSPORT_PUSH_FOLLOW_TAGS;
478                 else
479                         *flags &= ~TRANSPORT_PUSH_FOLLOW_TAGS;
480                 return 0;
481         } else if (!strcmp(k, "push.gpgsign")) {
482                 const char *value;
483                 if (!git_config_get_value("push.gpgsign", &value)) {
484                         switch (git_parse_maybe_bool(value)) {
485                         case 0:
486                                 set_push_cert_flags(flags, SEND_PACK_PUSH_CERT_NEVER);
487                                 break;
488                         case 1:
489                                 set_push_cert_flags(flags, SEND_PACK_PUSH_CERT_ALWAYS);
490                                 break;
491                         default:
492                                 if (value && !strcasecmp(value, "if-asked"))
493                                         set_push_cert_flags(flags, SEND_PACK_PUSH_CERT_IF_ASKED);
494                                 else
495                                         return error("Invalid value for '%s'", k);
496                         }
497                 }
498         } else if (!strcmp(k, "push.recursesubmodules")) {
499                 const char *value;
500                 if (!git_config_get_value("push.recursesubmodules", &value))
501                         recurse_submodules = parse_push_recurse_submodules_arg(k, value);
502         } else if (!strcmp(k, "submodule.recurse")) {
503                 int val = git_config_bool(k, v) ?
504                         RECURSE_SUBMODULES_ON_DEMAND : RECURSE_SUBMODULES_OFF;
505                 recurse_submodules = val;
506         } else if (!strcmp(k, "push.pushoption")) {
507                 if (!v)
508                         return config_error_nonbool(k);
509                 else
510                         if (!*v)
511                                 string_list_clear(&push_options_config, 0);
512                         else
513                                 string_list_append(&push_options_config, v);
514                 return 0;
515         } else if (!strcmp(k, "color.push")) {
516                 push_use_color = git_config_colorbool(k, v);
517                 return 0;
518         } else if (skip_prefix(k, "color.push.", &slot_name)) {
519                 int slot = parse_push_color_slot(slot_name);
520                 if (slot < 0)
521                         return 0;
522                 if (!v)
523                         return config_error_nonbool(k);
524                 return color_parse(v, push_colors[slot]);
525         }
526
527         return git_default_config(k, v, NULL);
528 }
529
530 int cmd_push(int argc, const char **argv, const char *prefix)
531 {
532         int flags = 0;
533         int tags = 0;
534         int push_cert = -1;
535         int rc;
536         const char *repo = NULL;        /* default repository */
537         struct string_list push_options_cmdline = STRING_LIST_INIT_DUP;
538         struct string_list *push_options;
539         const struct string_list_item *item;
540         struct remote *remote;
541
542         struct option options[] = {
543                 OPT__VERBOSITY(&verbosity),
544                 OPT_STRING( 0 , "repo", &repo, N_("repository"), N_("repository")),
545                 OPT_BIT( 0 , "all", &flags, N_("push all refs"), TRANSPORT_PUSH_ALL),
546                 OPT_BIT( 0 , "mirror", &flags, N_("mirror all refs"),
547                             (TRANSPORT_PUSH_MIRROR|TRANSPORT_PUSH_FORCE)),
548                 OPT_BOOL('d', "delete", &deleterefs, N_("delete refs")),
549                 OPT_BOOL( 0 , "tags", &tags, N_("push tags (can't be used with --all or --mirror)")),
550                 OPT_BIT('n' , "dry-run", &flags, N_("dry run"), TRANSPORT_PUSH_DRY_RUN),
551                 OPT_BIT( 0,  "porcelain", &flags, N_("machine-readable output"), TRANSPORT_PUSH_PORCELAIN),
552                 OPT_BIT('f', "force", &flags, N_("force updates"), TRANSPORT_PUSH_FORCE),
553                 { OPTION_CALLBACK,
554                   0, CAS_OPT_NAME, &cas, N_("<refname>:<expect>"),
555                   N_("require old value of ref to be at this value"),
556                   PARSE_OPT_OPTARG | PARSE_OPT_LITERAL_ARGHELP, parseopt_push_cas_option },
557                 { OPTION_CALLBACK, 0, "recurse-submodules", &recurse_submodules, "(check|on-demand|no)",
558                         N_("control recursive pushing of submodules"),
559                         PARSE_OPT_OPTARG, option_parse_recurse_submodules },
560                 OPT_BOOL_F( 0 , "thin", &thin, N_("use thin pack"), PARSE_OPT_NOCOMPLETE),
561                 OPT_STRING( 0 , "receive-pack", &receivepack, "receive-pack", N_("receive pack program")),
562                 OPT_STRING( 0 , "exec", &receivepack, "receive-pack", N_("receive pack program")),
563                 OPT_BIT('u', "set-upstream", &flags, N_("set upstream for git pull/status"),
564                         TRANSPORT_PUSH_SET_UPSTREAM),
565                 OPT_BOOL(0, "progress", &progress, N_("force progress reporting")),
566                 OPT_BIT(0, "prune", &flags, N_("prune locally removed refs"),
567                         TRANSPORT_PUSH_PRUNE),
568                 OPT_BIT(0, "no-verify", &flags, N_("bypass pre-push hook"), TRANSPORT_PUSH_NO_HOOK),
569                 OPT_BIT(0, "follow-tags", &flags, N_("push missing but relevant tags"),
570                         TRANSPORT_PUSH_FOLLOW_TAGS),
571                 { OPTION_CALLBACK,
572                   0, "signed", &push_cert, "(yes|no|if-asked)", N_("GPG sign the push"),
573                   PARSE_OPT_OPTARG, option_parse_push_signed },
574                 OPT_BIT(0, "atomic", &flags, N_("request atomic transaction on remote side"), TRANSPORT_PUSH_ATOMIC),
575                 OPT_STRING_LIST('o', "push-option", &push_options_cmdline, N_("server-specific"), N_("option to transmit")),
576                 OPT_SET_INT('4', "ipv4", &family, N_("use IPv4 addresses only"),
577                                 TRANSPORT_FAMILY_IPV4),
578                 OPT_SET_INT('6', "ipv6", &family, N_("use IPv6 addresses only"),
579                                 TRANSPORT_FAMILY_IPV6),
580                 OPT_END()
581         };
582
583         packet_trace_identity("push");
584         git_config(git_push_config, &flags);
585         argc = parse_options(argc, argv, prefix, options, push_usage, 0);
586         push_options = (push_options_cmdline.nr
587                 ? &push_options_cmdline
588                 : &push_options_config);
589         set_push_cert_flags(&flags, push_cert);
590
591         if (deleterefs && (tags || (flags & (TRANSPORT_PUSH_ALL | TRANSPORT_PUSH_MIRROR))))
592                 die(_("--delete is incompatible with --all, --mirror and --tags"));
593         if (deleterefs && argc < 2)
594                 die(_("--delete doesn't make sense without any refs"));
595
596         if (recurse_submodules == RECURSE_SUBMODULES_CHECK)
597                 flags |= TRANSPORT_RECURSE_SUBMODULES_CHECK;
598         else if (recurse_submodules == RECURSE_SUBMODULES_ON_DEMAND)
599                 flags |= TRANSPORT_RECURSE_SUBMODULES_ON_DEMAND;
600         else if (recurse_submodules == RECURSE_SUBMODULES_ONLY)
601                 flags |= TRANSPORT_RECURSE_SUBMODULES_ONLY;
602
603         if (tags)
604                 refspec_append(&rs, "refs/tags/*");
605
606         if (argc > 0) {
607                 repo = argv[0];
608                 set_refspecs(argv + 1, argc - 1, repo);
609         }
610
611         remote = pushremote_get(repo);
612         if (!remote) {
613                 if (repo)
614                         die(_("bad repository '%s'"), repo);
615                 die(_("No configured push destination.\n"
616                     "Either specify the URL from the command-line or configure a remote repository using\n"
617                     "\n"
618                     "    git remote add <name> <url>\n"
619                     "\n"
620                     "and then push using the remote name\n"
621                     "\n"
622                     "    git push <name>\n"));
623         }
624
625         if (remote->mirror)
626                 flags |= (TRANSPORT_PUSH_MIRROR|TRANSPORT_PUSH_FORCE);
627
628         if (flags & TRANSPORT_PUSH_ALL) {
629                 if (tags)
630                         die(_("--all and --tags are incompatible"));
631                 if (argc >= 2)
632                         die(_("--all can't be combined with refspecs"));
633         }
634         if (flags & TRANSPORT_PUSH_MIRROR) {
635                 if (tags)
636                         die(_("--mirror and --tags are incompatible"));
637                 if (argc >= 2)
638                         die(_("--mirror can't be combined with refspecs"));
639         }
640         if ((flags & TRANSPORT_PUSH_ALL) && (flags & TRANSPORT_PUSH_MIRROR))
641                 die(_("--all and --mirror are incompatible"));
642
643         for_each_string_list_item(item, push_options)
644                 if (strchr(item->string, '\n'))
645                         die(_("push options must not have new line characters"));
646
647         rc = do_push(repo, flags, push_options, remote);
648         string_list_clear(&push_options_cmdline, 0);
649         string_list_clear(&push_options_config, 0);
650         if (rc == -1)
651                 usage_with_options(push_usage, options);
652         else
653                 return rc;
654 }