t0410: make test description clearer
[git/gitster.git] / builtin / push.c
blob51c609f2089e64a54d824fdb243e5b49524f854e
1 /*
2 * "git push"
3 */
4 #define USE_THE_REPOSITORY_VARIABLE
5 #include "builtin.h"
6 #include "advice.h"
7 #include "branch.h"
8 #include "config.h"
9 #include "environment.h"
10 #include "gettext.h"
11 #include "refspec.h"
12 #include "run-command.h"
13 #include "remote.h"
14 #include "transport.h"
15 #include "parse-options.h"
16 #include "pkt-line.h"
17 #include "submodule.h"
18 #include "submodule-config.h"
19 #include "send-pack.h"
20 #include "trace2.h"
21 #include "color.h"
23 static const char * const push_usage[] = {
24 N_("git push [<options>] [<repository> [<refspec>...]]"),
25 NULL,
28 static int push_use_color = -1;
29 static char push_colors[][COLOR_MAXLEN] = {
30 GIT_COLOR_RESET,
31 GIT_COLOR_RED, /* ERROR */
34 enum color_push {
35 PUSH_COLOR_RESET = 0,
36 PUSH_COLOR_ERROR = 1
39 static int parse_push_color_slot(const char *slot)
41 if (!strcasecmp(slot, "reset"))
42 return PUSH_COLOR_RESET;
43 if (!strcasecmp(slot, "error"))
44 return PUSH_COLOR_ERROR;
45 return -1;
48 static const char *push_get_color(enum color_push ix)
50 if (want_color_stderr(push_use_color))
51 return push_colors[ix];
52 return "";
55 static int thin = 1;
56 static int deleterefs;
57 static const char *receivepack;
58 static int verbosity;
59 static int progress = -1;
60 static int recurse_submodules = RECURSE_SUBMODULES_DEFAULT;
61 static enum transport_family family;
63 static struct push_cas_option cas;
65 static struct refspec rs = REFSPEC_INIT_PUSH;
67 static struct string_list push_options_config = STRING_LIST_INIT_DUP;
69 static void refspec_append_mapped(struct refspec *refspec, const char *ref,
70 struct remote *remote, struct ref *matched)
72 const char *branch_name;
74 if (remote->push.nr) {
75 struct refspec_item query = {
76 .src = matched->name,
79 if (!query_refspecs(&remote->push, &query) && query.dst) {
80 refspec_appendf(refspec, "%s%s:%s",
81 query.force ? "+" : "",
82 query.src, query.dst);
83 free(query.dst);
84 return;
88 if (push_default == PUSH_DEFAULT_UPSTREAM &&
89 skip_prefix(matched->name, "refs/heads/", &branch_name)) {
90 struct branch *branch = branch_get(branch_name);
91 if (branch->merge_nr == 1 && branch->merge[0]->src) {
92 refspec_appendf(refspec, "%s:%s",
93 ref, branch->merge[0]->src);
94 return;
98 refspec_append(refspec, ref);
101 static void set_refspecs(const char **refs, int nr, struct remote *remote)
103 struct ref *local_refs = NULL;
104 int i;
106 for (i = 0; i < nr; i++) {
107 const char *ref = refs[i];
108 if (!strcmp("tag", ref)) {
109 if (nr <= ++i)
110 die(_("tag shorthand without <tag>"));
111 ref = refs[i];
112 if (deleterefs)
113 refspec_appendf(&rs, ":refs/tags/%s", ref);
114 else
115 refspec_appendf(&rs, "refs/tags/%s", ref);
116 } else if (deleterefs) {
117 if (strchr(ref, ':') || !*ref)
118 die(_("--delete only accepts plain target ref names"));
119 refspec_appendf(&rs, ":%s", ref);
120 } else if (!strchr(ref, ':')) {
121 struct ref *matched = NULL;
123 /* lazily grab local_refs */
124 if (!local_refs)
125 local_refs = get_local_heads();
127 /* Does "ref" uniquely name our ref? */
128 if (count_refspec_match(ref, local_refs, &matched) != 1)
129 refspec_append(&rs, ref);
130 else
131 refspec_append_mapped(&rs, ref, remote, matched);
132 } else
133 refspec_append(&rs, ref);
135 free_refs(local_refs);
138 static NORETURN void die_push_simple(struct branch *branch,
139 struct remote *remote)
142 * There's no point in using shorten_unambiguous_ref here,
143 * as the ambiguity would be on the remote side, not what
144 * we have locally. Plus, this is supposed to be the simple
145 * mode. If the user is doing something crazy like setting
146 * upstream to a non-branch, we should probably be showing
147 * them the big ugly fully qualified ref.
149 const char *advice_pushdefault_maybe = "";
150 const char *advice_automergesimple_maybe = "";
151 const char *short_upstream = branch->merge[0]->src;
153 skip_prefix(short_upstream, "refs/heads/", &short_upstream);
156 * Don't show advice for people who explicitly set
157 * push.default.
159 if (push_default == PUSH_DEFAULT_UNSPECIFIED)
160 advice_pushdefault_maybe = _("\n"
161 "To choose either option permanently, "
162 "see push.default in 'git help config'.\n");
163 if (git_branch_track != BRANCH_TRACK_SIMPLE)
164 advice_automergesimple_maybe = _("\n"
165 "To avoid automatically configuring "
166 "an upstream branch when its name\n"
167 "won't match the local branch, see option "
168 "'simple' of branch.autoSetupMerge\n"
169 "in 'git help config'.\n");
170 die(_("The upstream branch of your current branch does not match\n"
171 "the name of your current branch. To push to the upstream branch\n"
172 "on the remote, use\n"
173 "\n"
174 " git push %s HEAD:%s\n"
175 "\n"
176 "To push to the branch of the same name on the remote, use\n"
177 "\n"
178 " git push %s HEAD\n"
179 "%s%s"),
180 remote->name, short_upstream,
181 remote->name, advice_pushdefault_maybe,
182 advice_automergesimple_maybe);
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");
192 static const char *get_upstream_ref(int flags, struct branch *branch, const char *remote_name)
194 if (branch->merge_nr == 0 && (flags & TRANSPORT_PUSH_AUTO_UPSTREAM)) {
195 /* if missing, assume same; set_upstream will be defined later */
196 return branch->refname;
199 if (!branch->merge_nr || !branch->merge || !branch->remote_name) {
200 const char *advice_autosetup_maybe = "";
201 if (!(flags & TRANSPORT_PUSH_AUTO_UPSTREAM)) {
202 advice_autosetup_maybe = _("\n"
203 "To have this happen automatically for "
204 "branches without a tracking\n"
205 "upstream, see 'push.autoSetupRemote' "
206 "in 'git help config'.\n");
208 die(_("The current branch %s has no upstream branch.\n"
209 "To push the current branch and set the remote as upstream, use\n"
210 "\n"
211 " git push --set-upstream %s %s\n"
212 "%s"),
213 branch->name,
214 remote_name,
215 branch->name,
216 advice_autosetup_maybe);
218 if (branch->merge_nr != 1)
219 die(_("The current branch %s has multiple upstream branches, "
220 "refusing to push."), branch->name);
222 return branch->merge[0]->src;
225 static void setup_default_push_refspecs(int *flags, struct remote *remote)
227 struct branch *branch;
228 const char *dst;
229 int same_remote;
231 switch (push_default) {
232 case PUSH_DEFAULT_MATCHING:
233 refspec_append(&rs, ":");
234 return;
236 case PUSH_DEFAULT_NOTHING:
237 die(_("You didn't specify any refspecs to push, and "
238 "push.default is \"nothing\"."));
239 return;
240 default:
241 break;
244 branch = branch_get(NULL);
245 if (!branch)
246 die(_(message_detached_head_die), remote->name);
248 dst = branch->refname;
249 same_remote = !strcmp(remote->name, remote_for_branch(branch, NULL));
251 switch (push_default) {
252 default:
253 case PUSH_DEFAULT_UNSPECIFIED:
254 case PUSH_DEFAULT_SIMPLE:
255 if (!same_remote)
256 break;
257 if (strcmp(branch->refname, get_upstream_ref(*flags, branch, remote->name)))
258 die_push_simple(branch, remote);
259 break;
261 case PUSH_DEFAULT_UPSTREAM:
262 if (!same_remote)
263 die(_("You are pushing to remote '%s', which is not the upstream of\n"
264 "your current branch '%s', without telling me what to push\n"
265 "to update which remote branch."),
266 remote->name, branch->name);
267 dst = get_upstream_ref(*flags, branch, remote->name);
268 break;
270 case PUSH_DEFAULT_CURRENT:
271 break;
275 * this is a default push - if auto-upstream is enabled and there is
276 * no upstream defined, then set it (with options 'simple', 'upstream',
277 * and 'current').
279 if ((*flags & TRANSPORT_PUSH_AUTO_UPSTREAM) && branch->merge_nr == 0)
280 *flags |= TRANSPORT_PUSH_SET_UPSTREAM;
282 refspec_appendf(&rs, "%s:%s", branch->refname, dst);
285 static const char message_advice_pull_before_push[] =
286 N_("Updates were rejected because the tip of your current branch is behind\n"
287 "its remote counterpart. If you want to integrate the remote changes,\n"
288 "use 'git pull' before pushing again.\n"
289 "See the 'Note about fast-forwards' in 'git push --help' for details.");
291 static const char message_advice_checkout_pull_push[] =
292 N_("Updates were rejected because a pushed branch tip is behind its remote\n"
293 "counterpart. If you want to integrate the remote changes, use 'git pull'\n"
294 "before pushing again.\n"
295 "See the 'Note about fast-forwards' in 'git push --help' for details.");
297 static const char message_advice_ref_fetch_first[] =
298 N_("Updates were rejected because the remote contains work that you do not\n"
299 "have locally. This is usually caused by another repository pushing to\n"
300 "the same ref. If you want to integrate the remote changes, use\n"
301 "'git pull' before pushing again.\n"
302 "See the 'Note about fast-forwards' in 'git push --help' for details.");
304 static const char message_advice_ref_already_exists[] =
305 N_("Updates were rejected because the tag already exists in the remote.");
307 static const char message_advice_ref_needs_force[] =
308 N_("You cannot update a remote ref that points at a non-commit object,\n"
309 "or update a remote ref to make it point at a non-commit object,\n"
310 "without using the '--force' option.\n");
312 static const char message_advice_ref_needs_update[] =
313 N_("Updates were rejected because the tip of the remote-tracking branch has\n"
314 "been updated since the last checkout. If you want to integrate the\n"
315 "remote changes, use 'git pull' before pushing again.\n"
316 "See the 'Note about fast-forwards' in 'git push --help' for details.");
318 static void advise_pull_before_push(void)
320 if (!advice_enabled(ADVICE_PUSH_NON_FF_CURRENT) || !advice_enabled(ADVICE_PUSH_UPDATE_REJECTED))
321 return;
322 advise(_(message_advice_pull_before_push));
325 static void advise_checkout_pull_push(void)
327 if (!advice_enabled(ADVICE_PUSH_NON_FF_MATCHING) || !advice_enabled(ADVICE_PUSH_UPDATE_REJECTED))
328 return;
329 advise(_(message_advice_checkout_pull_push));
332 static void advise_ref_already_exists(void)
334 if (!advice_enabled(ADVICE_PUSH_ALREADY_EXISTS) || !advice_enabled(ADVICE_PUSH_UPDATE_REJECTED))
335 return;
336 advise(_(message_advice_ref_already_exists));
339 static void advise_ref_fetch_first(void)
341 if (!advice_enabled(ADVICE_PUSH_FETCH_FIRST) || !advice_enabled(ADVICE_PUSH_UPDATE_REJECTED))
342 return;
343 advise(_(message_advice_ref_fetch_first));
346 static void advise_ref_needs_force(void)
348 if (!advice_enabled(ADVICE_PUSH_NEEDS_FORCE) || !advice_enabled(ADVICE_PUSH_UPDATE_REJECTED))
349 return;
350 advise(_(message_advice_ref_needs_force));
353 static void advise_ref_needs_update(void)
355 if (!advice_enabled(ADVICE_PUSH_REF_NEEDS_UPDATE) || !advice_enabled(ADVICE_PUSH_UPDATE_REJECTED))
356 return;
357 advise(_(message_advice_ref_needs_update));
360 static int push_with_options(struct transport *transport, struct refspec *rs,
361 int flags)
363 int err;
364 unsigned int reject_reasons;
365 char *anon_url = transport_anonymize_url(transport->url);
367 transport_set_verbosity(transport, verbosity, progress);
368 transport->family = family;
370 if (receivepack)
371 transport_set_option(transport,
372 TRANS_OPT_RECEIVEPACK, receivepack);
373 transport_set_option(transport, TRANS_OPT_THIN, thin ? "yes" : NULL);
375 if (!is_empty_cas(&cas)) {
376 if (!transport->smart_options)
377 die("underlying transport does not support --%s option",
378 "force-with-lease");
379 transport->smart_options->cas = &cas;
382 if (verbosity > 0)
383 fprintf(stderr, _("Pushing to %s\n"), anon_url);
384 trace2_region_enter("push", "transport_push", the_repository);
385 err = transport_push(the_repository, transport,
386 rs, flags, &reject_reasons);
387 trace2_region_leave("push", "transport_push", the_repository);
388 if (err != 0) {
389 fprintf(stderr, "%s", push_get_color(PUSH_COLOR_ERROR));
390 error(_("failed to push some refs to '%s'"), anon_url);
391 fprintf(stderr, "%s", push_get_color(PUSH_COLOR_RESET));
394 err |= transport_disconnect(transport);
395 free(anon_url);
396 if (!err)
397 return 0;
399 if (reject_reasons & REJECT_NON_FF_HEAD) {
400 advise_pull_before_push();
401 } else if (reject_reasons & REJECT_NON_FF_OTHER) {
402 advise_checkout_pull_push();
403 } else if (reject_reasons & REJECT_ALREADY_EXISTS) {
404 advise_ref_already_exists();
405 } else if (reject_reasons & REJECT_FETCH_FIRST) {
406 advise_ref_fetch_first();
407 } else if (reject_reasons & REJECT_NEEDS_FORCE) {
408 advise_ref_needs_force();
409 } else if (reject_reasons & REJECT_REF_NEEDS_UPDATE) {
410 advise_ref_needs_update();
413 return 1;
416 static int do_push(int flags,
417 const struct string_list *push_options,
418 struct remote *remote)
420 int i, errs;
421 struct strvec *url;
422 struct refspec *push_refspec = &rs;
424 if (push_options->nr)
425 flags |= TRANSPORT_PUSH_OPTIONS;
427 if (!push_refspec->nr && !(flags & TRANSPORT_PUSH_ALL)) {
428 if (remote->push.nr) {
429 push_refspec = &remote->push;
430 } else if (!(flags & TRANSPORT_PUSH_MIRROR))
431 setup_default_push_refspecs(&flags, remote);
433 errs = 0;
434 url = push_url_of_remote(remote);
435 for (i = 0; i < url->nr; i++) {
436 struct transport *transport =
437 transport_get(remote, url->v[i]);
438 if (flags & TRANSPORT_PUSH_OPTIONS)
439 transport->push_options = push_options;
440 if (push_with_options(transport, push_refspec, flags))
441 errs++;
443 return !!errs;
446 static int option_parse_recurse_submodules(const struct option *opt,
447 const char *arg, int unset)
449 int *recurse_submodules = opt->value;
451 if (unset)
452 *recurse_submodules = RECURSE_SUBMODULES_OFF;
453 else {
454 if (!strcmp(arg, "only-is-on-demand")) {
455 if (*recurse_submodules == RECURSE_SUBMODULES_ONLY) {
456 warning(_("recursing into submodule with push.recurseSubmodules=only; using on-demand instead"));
457 *recurse_submodules = RECURSE_SUBMODULES_ON_DEMAND;
459 } else {
460 *recurse_submodules = parse_push_recurse_submodules_arg(opt->long_name, arg);
464 return 0;
467 static void set_push_cert_flags(int *flags, int v)
469 switch (v) {
470 case SEND_PACK_PUSH_CERT_NEVER:
471 *flags &= ~(TRANSPORT_PUSH_CERT_ALWAYS | TRANSPORT_PUSH_CERT_IF_ASKED);
472 break;
473 case SEND_PACK_PUSH_CERT_ALWAYS:
474 *flags |= TRANSPORT_PUSH_CERT_ALWAYS;
475 *flags &= ~TRANSPORT_PUSH_CERT_IF_ASKED;
476 break;
477 case SEND_PACK_PUSH_CERT_IF_ASKED:
478 *flags |= TRANSPORT_PUSH_CERT_IF_ASKED;
479 *flags &= ~TRANSPORT_PUSH_CERT_ALWAYS;
480 break;
485 static int git_push_config(const char *k, const char *v,
486 const struct config_context *ctx, void *cb)
488 const char *slot_name;
489 int *flags = cb;
491 if (!strcmp(k, "push.followtags")) {
492 if (git_config_bool(k, v))
493 *flags |= TRANSPORT_PUSH_FOLLOW_TAGS;
494 else
495 *flags &= ~TRANSPORT_PUSH_FOLLOW_TAGS;
496 return 0;
497 } else if (!strcmp(k, "push.autosetupremote")) {
498 if (git_config_bool(k, v))
499 *flags |= TRANSPORT_PUSH_AUTO_UPSTREAM;
500 return 0;
501 } else if (!strcmp(k, "push.gpgsign")) {
502 switch (git_parse_maybe_bool(v)) {
503 case 0:
504 set_push_cert_flags(flags, SEND_PACK_PUSH_CERT_NEVER);
505 break;
506 case 1:
507 set_push_cert_flags(flags, SEND_PACK_PUSH_CERT_ALWAYS);
508 break;
509 default:
510 if (!strcasecmp(v, "if-asked"))
511 set_push_cert_flags(flags, SEND_PACK_PUSH_CERT_IF_ASKED);
512 else
513 return error(_("invalid value for '%s'"), k);
515 } else if (!strcmp(k, "push.recursesubmodules")) {
516 recurse_submodules = parse_push_recurse_submodules_arg(k, v);
517 } else if (!strcmp(k, "submodule.recurse")) {
518 int val = git_config_bool(k, v) ?
519 RECURSE_SUBMODULES_ON_DEMAND : RECURSE_SUBMODULES_OFF;
520 recurse_submodules = val;
521 } else if (!strcmp(k, "push.pushoption")) {
522 return parse_transport_option(k, v, &push_options_config);
523 } else if (!strcmp(k, "color.push")) {
524 push_use_color = git_config_colorbool(k, v);
525 return 0;
526 } else if (skip_prefix(k, "color.push.", &slot_name)) {
527 int slot = parse_push_color_slot(slot_name);
528 if (slot < 0)
529 return 0;
530 if (!v)
531 return config_error_nonbool(k);
532 return color_parse(v, push_colors[slot]);
533 } else if (!strcmp(k, "push.useforceifincludes")) {
534 if (git_config_bool(k, v))
535 *flags |= TRANSPORT_PUSH_FORCE_IF_INCLUDES;
536 else
537 *flags &= ~TRANSPORT_PUSH_FORCE_IF_INCLUDES;
538 return 0;
541 return git_default_config(k, v, ctx, NULL);
544 int cmd_push(int argc,
545 const char **argv,
546 const char *prefix,
547 struct repository *repository UNUSED)
549 int flags = 0;
550 int tags = 0;
551 int push_cert = -1;
552 int rc;
553 const char *repo = NULL; /* default repository */
554 struct string_list push_options_cmdline = STRING_LIST_INIT_DUP;
555 struct string_list *push_options;
556 const struct string_list_item *item;
557 struct remote *remote;
559 struct option options[] = {
560 OPT__VERBOSITY(&verbosity),
561 OPT_STRING( 0 , "repo", &repo, N_("repository"), N_("repository")),
562 OPT_BIT( 0 , "all", &flags, N_("push all branches"), TRANSPORT_PUSH_ALL),
563 OPT_ALIAS( 0 , "branches", "all"),
564 OPT_BIT( 0 , "mirror", &flags, N_("mirror all refs"),
565 (TRANSPORT_PUSH_MIRROR|TRANSPORT_PUSH_FORCE)),
566 OPT_BOOL('d', "delete", &deleterefs, N_("delete refs")),
567 OPT_BOOL( 0 , "tags", &tags, N_("push tags (can't be used with --all or --branches or --mirror)")),
568 OPT_BIT('n' , "dry-run", &flags, N_("dry run"), TRANSPORT_PUSH_DRY_RUN),
569 OPT_BIT( 0, "porcelain", &flags, N_("machine-readable output"), TRANSPORT_PUSH_PORCELAIN),
570 OPT_BIT('f', "force", &flags, N_("force updates"), TRANSPORT_PUSH_FORCE),
571 OPT_CALLBACK_F(0, "force-with-lease", &cas, N_("<refname>:<expect>"),
572 N_("require old value of ref to be at this value"),
573 PARSE_OPT_OPTARG | PARSE_OPT_LITERAL_ARGHELP, parseopt_push_cas_option),
574 OPT_BIT(0, TRANS_OPT_FORCE_IF_INCLUDES, &flags,
575 N_("require remote updates to be integrated locally"),
576 TRANSPORT_PUSH_FORCE_IF_INCLUDES),
577 OPT_CALLBACK(0, "recurse-submodules", &recurse_submodules, "(check|on-demand|no)",
578 N_("control recursive pushing of submodules"), option_parse_recurse_submodules),
579 OPT_BOOL_F( 0 , "thin", &thin, N_("use thin pack"), PARSE_OPT_NOCOMPLETE),
580 OPT_STRING( 0 , "receive-pack", &receivepack, "receive-pack", N_("receive pack program")),
581 OPT_STRING( 0 , "exec", &receivepack, "receive-pack", N_("receive pack program")),
582 OPT_BIT('u', "set-upstream", &flags, N_("set upstream for git pull/status"),
583 TRANSPORT_PUSH_SET_UPSTREAM),
584 OPT_BOOL(0, "progress", &progress, N_("force progress reporting")),
585 OPT_BIT(0, "prune", &flags, N_("prune locally removed refs"),
586 TRANSPORT_PUSH_PRUNE),
587 OPT_BIT(0, "no-verify", &flags, N_("bypass pre-push hook"), TRANSPORT_PUSH_NO_HOOK),
588 OPT_BIT(0, "follow-tags", &flags, N_("push missing but relevant tags"),
589 TRANSPORT_PUSH_FOLLOW_TAGS),
590 OPT_CALLBACK_F(0, "signed", &push_cert, "(yes|no|if-asked)", N_("GPG sign the push"),
591 PARSE_OPT_OPTARG, option_parse_push_signed),
592 OPT_BIT(0, "atomic", &flags, N_("request atomic transaction on remote side"), TRANSPORT_PUSH_ATOMIC),
593 OPT_STRING_LIST('o', "push-option", &push_options_cmdline, N_("server-specific"), N_("option to transmit")),
594 OPT_IPVERSION(&family),
595 OPT_END()
598 packet_trace_identity("push");
599 git_config(git_push_config, &flags);
600 argc = parse_options(argc, argv, prefix, options, push_usage, 0);
601 push_options = (push_options_cmdline.nr
602 ? &push_options_cmdline
603 : &push_options_config);
604 set_push_cert_flags(&flags, push_cert);
606 die_for_incompatible_opt4(deleterefs, "--delete",
607 tags, "--tags",
608 flags & TRANSPORT_PUSH_ALL, "--all/--branches",
609 flags & TRANSPORT_PUSH_MIRROR, "--mirror");
610 if (deleterefs && argc < 2)
611 die(_("--delete doesn't make sense without any refs"));
613 if (recurse_submodules == RECURSE_SUBMODULES_CHECK)
614 flags |= TRANSPORT_RECURSE_SUBMODULES_CHECK;
615 else if (recurse_submodules == RECURSE_SUBMODULES_ON_DEMAND)
616 flags |= TRANSPORT_RECURSE_SUBMODULES_ON_DEMAND;
617 else if (recurse_submodules == RECURSE_SUBMODULES_ONLY)
618 flags |= TRANSPORT_RECURSE_SUBMODULES_ONLY;
620 if (tags)
621 refspec_append(&rs, "refs/tags/*");
623 if (argc > 0)
624 repo = argv[0];
626 remote = pushremote_get(repo);
627 if (!remote) {
628 if (repo)
629 die(_("bad repository '%s'"), repo);
630 die(_("No configured push destination.\n"
631 "Either specify the URL from the command-line or configure a remote repository using\n"
632 "\n"
633 " git remote add <name> <url>\n"
634 "\n"
635 "and then push using the remote name\n"
636 "\n"
637 " git push <name>\n"));
640 if (argc > 0)
641 set_refspecs(argv + 1, argc - 1, remote);
643 if (remote->mirror)
644 flags |= (TRANSPORT_PUSH_MIRROR|TRANSPORT_PUSH_FORCE);
646 if (flags & TRANSPORT_PUSH_ALL) {
647 if (argc >= 2)
648 die(_("--all can't be combined with refspecs"));
650 if (flags & TRANSPORT_PUSH_MIRROR) {
651 if (argc >= 2)
652 die(_("--mirror can't be combined with refspecs"));
655 if (!is_empty_cas(&cas) && (flags & TRANSPORT_PUSH_FORCE_IF_INCLUDES))
656 cas.use_force_if_includes = 1;
658 for_each_string_list_item(item, push_options)
659 if (strchr(item->string, '\n'))
660 die(_("push options must not have new line characters"));
662 rc = do_push(flags, push_options, remote);
663 string_list_clear(&push_options_cmdline, 0);
664 string_list_clear(&push_options_config, 0);
665 clear_cas_option(&cas);
666 if (rc == -1)
667 usage_with_options(push_usage, options);
668 else
669 return rc;