Start the 2.46 cycle
[git.git] / builtin / push.c
blob2fbb31c3ad8eb9b7a15ffac4e5d9aa65367d298f
1 /*
2 * "git push"
3 */
4 #include "builtin.h"
5 #include "advice.h"
6 #include "branch.h"
7 #include "config.h"
8 #include "environment.h"
9 #include "gettext.h"
10 #include "refspec.h"
11 #include "run-command.h"
12 #include "remote.h"
13 #include "transport.h"
14 #include "parse-options.h"
15 #include "pkt-line.h"
16 #include "repository.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 memset(&query, 0, sizeof(struct refspec_item));
77 query.src = matched->name;
78 if (!query_refspecs(&remote->push, &query) && query.dst) {
79 refspec_appendf(refspec, "%s%s:%s",
80 query.force ? "+" : "",
81 query.src, query.dst);
82 return;
86 if (push_default == PUSH_DEFAULT_UPSTREAM &&
87 skip_prefix(matched->name, "refs/heads/", &branch_name)) {
88 struct branch *branch = branch_get(branch_name);
89 if (branch->merge_nr == 1 && branch->merge[0]->src) {
90 refspec_appendf(refspec, "%s:%s",
91 ref, branch->merge[0]->src);
92 return;
96 refspec_append(refspec, ref);
99 static void set_refspecs(const char **refs, int nr, const char *repo)
101 struct remote *remote = NULL;
102 struct ref *local_refs = NULL;
103 int i;
105 for (i = 0; i < nr; i++) {
106 const char *ref = refs[i];
107 if (!strcmp("tag", ref)) {
108 if (nr <= ++i)
109 die(_("tag shorthand without <tag>"));
110 ref = refs[i];
111 if (deleterefs)
112 refspec_appendf(&rs, ":refs/tags/%s", ref);
113 else
114 refspec_appendf(&rs, "refs/tags/%s", ref);
115 } else if (deleterefs) {
116 if (strchr(ref, ':') || !*ref)
117 die(_("--delete only accepts plain target ref names"));
118 refspec_appendf(&rs, ":%s", ref);
119 } else if (!strchr(ref, ':')) {
120 struct ref *matched = NULL;
122 /* lazily grab local_refs */
123 if (!local_refs)
124 local_refs = get_local_heads();
126 /* Does "ref" uniquely name our ref? */
127 if (count_refspec_match(ref, local_refs, &matched) != 1) {
128 refspec_append(&rs, ref);
129 } else {
130 /* lazily grab remote */
131 if (!remote)
132 remote = remote_get(repo);
133 if (!remote)
134 BUG("must get a remote for repo '%s'", repo);
136 refspec_append_mapped(&rs, ref, remote, matched);
138 } else
139 refspec_append(&rs, ref);
141 free_refs(local_refs);
144 static int push_url_of_remote(struct remote *remote, const char ***url_p)
146 if (remote->pushurl_nr) {
147 *url_p = remote->pushurl;
148 return remote->pushurl_nr;
150 *url_p = remote->url;
151 return remote->url_nr;
154 static NORETURN void die_push_simple(struct branch *branch,
155 struct remote *remote)
158 * There's no point in using shorten_unambiguous_ref here,
159 * as the ambiguity would be on the remote side, not what
160 * we have locally. Plus, this is supposed to be the simple
161 * mode. If the user is doing something crazy like setting
162 * upstream to a non-branch, we should probably be showing
163 * them the big ugly fully qualified ref.
165 const char *advice_pushdefault_maybe = "";
166 const char *advice_automergesimple_maybe = "";
167 const char *short_upstream = branch->merge[0]->src;
169 skip_prefix(short_upstream, "refs/heads/", &short_upstream);
172 * Don't show advice for people who explicitly set
173 * push.default.
175 if (push_default == PUSH_DEFAULT_UNSPECIFIED)
176 advice_pushdefault_maybe = _("\n"
177 "To choose either option permanently, "
178 "see push.default in 'git help config'.\n");
179 if (git_branch_track != BRANCH_TRACK_SIMPLE)
180 advice_automergesimple_maybe = _("\n"
181 "To avoid automatically configuring "
182 "an upstream branch when its name\n"
183 "won't match the local branch, see option "
184 "'simple' of branch.autoSetupMerge\n"
185 "in 'git help config'.\n");
186 die(_("The upstream branch of your current branch does not match\n"
187 "the name of your current branch. To push to the upstream branch\n"
188 "on the remote, use\n"
189 "\n"
190 " git push %s HEAD:%s\n"
191 "\n"
192 "To push to the branch of the same name on the remote, use\n"
193 "\n"
194 " git push %s HEAD\n"
195 "%s%s"),
196 remote->name, short_upstream,
197 remote->name, advice_pushdefault_maybe,
198 advice_automergesimple_maybe);
201 static const char message_detached_head_die[] =
202 N_("You are not currently on a branch.\n"
203 "To push the history leading to the current (detached HEAD)\n"
204 "state now, use\n"
205 "\n"
206 " git push %s HEAD:<name-of-remote-branch>\n");
208 static const char *get_upstream_ref(int flags, struct branch *branch, const char *remote_name)
210 if (branch->merge_nr == 0 && (flags & TRANSPORT_PUSH_AUTO_UPSTREAM)) {
211 /* if missing, assume same; set_upstream will be defined later */
212 return branch->refname;
215 if (!branch->merge_nr || !branch->merge || !branch->remote_name) {
216 const char *advice_autosetup_maybe = "";
217 if (!(flags & TRANSPORT_PUSH_AUTO_UPSTREAM)) {
218 advice_autosetup_maybe = _("\n"
219 "To have this happen automatically for "
220 "branches without a tracking\n"
221 "upstream, see 'push.autoSetupRemote' "
222 "in 'git help config'.\n");
224 die(_("The current branch %s has no upstream branch.\n"
225 "To push the current branch and set the remote as upstream, use\n"
226 "\n"
227 " git push --set-upstream %s %s\n"
228 "%s"),
229 branch->name,
230 remote_name,
231 branch->name,
232 advice_autosetup_maybe);
234 if (branch->merge_nr != 1)
235 die(_("The current branch %s has multiple upstream branches, "
236 "refusing to push."), branch->name);
238 return branch->merge[0]->src;
241 static void setup_default_push_refspecs(int *flags, struct remote *remote)
243 struct branch *branch;
244 const char *dst;
245 int same_remote;
247 switch (push_default) {
248 case PUSH_DEFAULT_MATCHING:
249 refspec_append(&rs, ":");
250 return;
252 case PUSH_DEFAULT_NOTHING:
253 die(_("You didn't specify any refspecs to push, and "
254 "push.default is \"nothing\"."));
255 return;
256 default:
257 break;
260 branch = branch_get(NULL);
261 if (!branch)
262 die(_(message_detached_head_die), remote->name);
264 dst = branch->refname;
265 same_remote = !strcmp(remote->name, remote_for_branch(branch, NULL));
267 switch (push_default) {
268 default:
269 case PUSH_DEFAULT_UNSPECIFIED:
270 case PUSH_DEFAULT_SIMPLE:
271 if (!same_remote)
272 break;
273 if (strcmp(branch->refname, get_upstream_ref(*flags, branch, remote->name)))
274 die_push_simple(branch, remote);
275 break;
277 case PUSH_DEFAULT_UPSTREAM:
278 if (!same_remote)
279 die(_("You are pushing to remote '%s', which is not the upstream of\n"
280 "your current branch '%s', without telling me what to push\n"
281 "to update which remote branch."),
282 remote->name, branch->name);
283 dst = get_upstream_ref(*flags, branch, remote->name);
284 break;
286 case PUSH_DEFAULT_CURRENT:
287 break;
291 * this is a default push - if auto-upstream is enabled and there is
292 * no upstream defined, then set it (with options 'simple', 'upstream',
293 * and 'current').
295 if ((*flags & TRANSPORT_PUSH_AUTO_UPSTREAM) && branch->merge_nr == 0)
296 *flags |= TRANSPORT_PUSH_SET_UPSTREAM;
298 refspec_appendf(&rs, "%s:%s", branch->refname, dst);
301 static const char message_advice_pull_before_push[] =
302 N_("Updates were rejected because the tip of your current branch is behind\n"
303 "its remote counterpart. If you want to integrate the remote changes,\n"
304 "use 'git pull' before pushing again.\n"
305 "See the 'Note about fast-forwards' in 'git push --help' for details.");
307 static const char message_advice_checkout_pull_push[] =
308 N_("Updates were rejected because a pushed branch tip is behind its remote\n"
309 "counterpart. If you want to integrate the remote changes, use 'git pull'\n"
310 "before pushing again.\n"
311 "See the 'Note about fast-forwards' in 'git push --help' for details.");
313 static const char message_advice_ref_fetch_first[] =
314 N_("Updates were rejected because the remote contains work that you do not\n"
315 "have locally. This is usually caused by another repository pushing to\n"
316 "the same ref. If you want to integrate the remote changes, use\n"
317 "'git pull' before pushing again.\n"
318 "See the 'Note about fast-forwards' in 'git push --help' for details.");
320 static const char message_advice_ref_already_exists[] =
321 N_("Updates were rejected because the tag already exists in the remote.");
323 static const char message_advice_ref_needs_force[] =
324 N_("You cannot update a remote ref that points at a non-commit object,\n"
325 "or update a remote ref to make it point at a non-commit object,\n"
326 "without using the '--force' option.\n");
328 static const char message_advice_ref_needs_update[] =
329 N_("Updates were rejected because the tip of the remote-tracking branch has\n"
330 "been updated since the last checkout. If you want to integrate the\n"
331 "remote changes, use 'git pull' before pushing again.\n"
332 "See the 'Note about fast-forwards' in 'git push --help' for details.");
334 static void advise_pull_before_push(void)
336 if (!advice_enabled(ADVICE_PUSH_NON_FF_CURRENT) || !advice_enabled(ADVICE_PUSH_UPDATE_REJECTED))
337 return;
338 advise(_(message_advice_pull_before_push));
341 static void advise_checkout_pull_push(void)
343 if (!advice_enabled(ADVICE_PUSH_NON_FF_MATCHING) || !advice_enabled(ADVICE_PUSH_UPDATE_REJECTED))
344 return;
345 advise(_(message_advice_checkout_pull_push));
348 static void advise_ref_already_exists(void)
350 if (!advice_enabled(ADVICE_PUSH_ALREADY_EXISTS) || !advice_enabled(ADVICE_PUSH_UPDATE_REJECTED))
351 return;
352 advise(_(message_advice_ref_already_exists));
355 static void advise_ref_fetch_first(void)
357 if (!advice_enabled(ADVICE_PUSH_FETCH_FIRST) || !advice_enabled(ADVICE_PUSH_UPDATE_REJECTED))
358 return;
359 advise(_(message_advice_ref_fetch_first));
362 static void advise_ref_needs_force(void)
364 if (!advice_enabled(ADVICE_PUSH_NEEDS_FORCE) || !advice_enabled(ADVICE_PUSH_UPDATE_REJECTED))
365 return;
366 advise(_(message_advice_ref_needs_force));
369 static void advise_ref_needs_update(void)
371 if (!advice_enabled(ADVICE_PUSH_REF_NEEDS_UPDATE) || !advice_enabled(ADVICE_PUSH_UPDATE_REJECTED))
372 return;
373 advise(_(message_advice_ref_needs_update));
376 static int push_with_options(struct transport *transport, struct refspec *rs,
377 int flags)
379 int err;
380 unsigned int reject_reasons;
381 char *anon_url = transport_anonymize_url(transport->url);
383 transport_set_verbosity(transport, verbosity, progress);
384 transport->family = family;
386 if (receivepack)
387 transport_set_option(transport,
388 TRANS_OPT_RECEIVEPACK, receivepack);
389 transport_set_option(transport, TRANS_OPT_THIN, thin ? "yes" : NULL);
391 if (!is_empty_cas(&cas)) {
392 if (!transport->smart_options)
393 die("underlying transport does not support --%s option",
394 "force-with-lease");
395 transport->smart_options->cas = &cas;
398 if (verbosity > 0)
399 fprintf(stderr, _("Pushing to %s\n"), anon_url);
400 trace2_region_enter("push", "transport_push", the_repository);
401 err = transport_push(the_repository, transport,
402 rs, flags, &reject_reasons);
403 trace2_region_leave("push", "transport_push", the_repository);
404 if (err != 0) {
405 fprintf(stderr, "%s", push_get_color(PUSH_COLOR_ERROR));
406 error(_("failed to push some refs to '%s'"), anon_url);
407 fprintf(stderr, "%s", push_get_color(PUSH_COLOR_RESET));
410 err |= transport_disconnect(transport);
411 free(anon_url);
412 if (!err)
413 return 0;
415 if (reject_reasons & REJECT_NON_FF_HEAD) {
416 advise_pull_before_push();
417 } else if (reject_reasons & REJECT_NON_FF_OTHER) {
418 advise_checkout_pull_push();
419 } else if (reject_reasons & REJECT_ALREADY_EXISTS) {
420 advise_ref_already_exists();
421 } else if (reject_reasons & REJECT_FETCH_FIRST) {
422 advise_ref_fetch_first();
423 } else if (reject_reasons & REJECT_NEEDS_FORCE) {
424 advise_ref_needs_force();
425 } else if (reject_reasons & REJECT_REF_NEEDS_UPDATE) {
426 advise_ref_needs_update();
429 return 1;
432 static int do_push(int flags,
433 const struct string_list *push_options,
434 struct remote *remote)
436 int i, errs;
437 const char **url;
438 int url_nr;
439 struct refspec *push_refspec = &rs;
441 if (push_options->nr)
442 flags |= TRANSPORT_PUSH_OPTIONS;
444 if (!push_refspec->nr && !(flags & TRANSPORT_PUSH_ALL)) {
445 if (remote->push.nr) {
446 push_refspec = &remote->push;
447 } else if (!(flags & TRANSPORT_PUSH_MIRROR))
448 setup_default_push_refspecs(&flags, remote);
450 errs = 0;
451 url_nr = push_url_of_remote(remote, &url);
452 if (url_nr) {
453 for (i = 0; i < url_nr; i++) {
454 struct transport *transport =
455 transport_get(remote, url[i]);
456 if (flags & TRANSPORT_PUSH_OPTIONS)
457 transport->push_options = push_options;
458 if (push_with_options(transport, push_refspec, flags))
459 errs++;
461 } else {
462 struct transport *transport =
463 transport_get(remote, NULL);
464 if (flags & TRANSPORT_PUSH_OPTIONS)
465 transport->push_options = push_options;
466 if (push_with_options(transport, push_refspec, flags))
467 errs++;
469 return !!errs;
472 static int option_parse_recurse_submodules(const struct option *opt,
473 const char *arg, int unset)
475 int *recurse_submodules = opt->value;
477 if (unset)
478 *recurse_submodules = RECURSE_SUBMODULES_OFF;
479 else {
480 if (!strcmp(arg, "only-is-on-demand")) {
481 if (*recurse_submodules == RECURSE_SUBMODULES_ONLY) {
482 warning(_("recursing into submodule with push.recurseSubmodules=only; using on-demand instead"));
483 *recurse_submodules = RECURSE_SUBMODULES_ON_DEMAND;
485 } else {
486 *recurse_submodules = parse_push_recurse_submodules_arg(opt->long_name, arg);
490 return 0;
493 static void set_push_cert_flags(int *flags, int v)
495 switch (v) {
496 case SEND_PACK_PUSH_CERT_NEVER:
497 *flags &= ~(TRANSPORT_PUSH_CERT_ALWAYS | TRANSPORT_PUSH_CERT_IF_ASKED);
498 break;
499 case SEND_PACK_PUSH_CERT_ALWAYS:
500 *flags |= TRANSPORT_PUSH_CERT_ALWAYS;
501 *flags &= ~TRANSPORT_PUSH_CERT_IF_ASKED;
502 break;
503 case SEND_PACK_PUSH_CERT_IF_ASKED:
504 *flags |= TRANSPORT_PUSH_CERT_IF_ASKED;
505 *flags &= ~TRANSPORT_PUSH_CERT_ALWAYS;
506 break;
511 static int git_push_config(const char *k, const char *v,
512 const struct config_context *ctx, void *cb)
514 const char *slot_name;
515 int *flags = cb;
517 if (!strcmp(k, "push.followtags")) {
518 if (git_config_bool(k, v))
519 *flags |= TRANSPORT_PUSH_FOLLOW_TAGS;
520 else
521 *flags &= ~TRANSPORT_PUSH_FOLLOW_TAGS;
522 return 0;
523 } else if (!strcmp(k, "push.autosetupremote")) {
524 if (git_config_bool(k, v))
525 *flags |= TRANSPORT_PUSH_AUTO_UPSTREAM;
526 return 0;
527 } else if (!strcmp(k, "push.gpgsign")) {
528 switch (git_parse_maybe_bool(v)) {
529 case 0:
530 set_push_cert_flags(flags, SEND_PACK_PUSH_CERT_NEVER);
531 break;
532 case 1:
533 set_push_cert_flags(flags, SEND_PACK_PUSH_CERT_ALWAYS);
534 break;
535 default:
536 if (!strcasecmp(v, "if-asked"))
537 set_push_cert_flags(flags, SEND_PACK_PUSH_CERT_IF_ASKED);
538 else
539 return error(_("invalid value for '%s'"), k);
541 } else if (!strcmp(k, "push.recursesubmodules")) {
542 recurse_submodules = parse_push_recurse_submodules_arg(k, v);
543 } else if (!strcmp(k, "submodule.recurse")) {
544 int val = git_config_bool(k, v) ?
545 RECURSE_SUBMODULES_ON_DEMAND : RECURSE_SUBMODULES_OFF;
546 recurse_submodules = val;
547 } else if (!strcmp(k, "push.pushoption")) {
548 if (!v)
549 return config_error_nonbool(k);
550 else
551 if (!*v)
552 string_list_clear(&push_options_config, 0);
553 else
554 string_list_append(&push_options_config, v);
555 return 0;
556 } else if (!strcmp(k, "color.push")) {
557 push_use_color = git_config_colorbool(k, v);
558 return 0;
559 } else if (skip_prefix(k, "color.push.", &slot_name)) {
560 int slot = parse_push_color_slot(slot_name);
561 if (slot < 0)
562 return 0;
563 if (!v)
564 return config_error_nonbool(k);
565 return color_parse(v, push_colors[slot]);
566 } else if (!strcmp(k, "push.useforceifincludes")) {
567 if (git_config_bool(k, v))
568 *flags |= TRANSPORT_PUSH_FORCE_IF_INCLUDES;
569 else
570 *flags &= ~TRANSPORT_PUSH_FORCE_IF_INCLUDES;
571 return 0;
574 return git_default_config(k, v, ctx, NULL);
577 int cmd_push(int argc, const char **argv, const char *prefix)
579 int flags = 0;
580 int tags = 0;
581 int push_cert = -1;
582 int rc;
583 const char *repo = NULL; /* default repository */
584 struct string_list push_options_cmdline = STRING_LIST_INIT_DUP;
585 struct string_list *push_options;
586 const struct string_list_item *item;
587 struct remote *remote;
589 struct option options[] = {
590 OPT__VERBOSITY(&verbosity),
591 OPT_STRING( 0 , "repo", &repo, N_("repository"), N_("repository")),
592 OPT_BIT( 0 , "all", &flags, N_("push all branches"), TRANSPORT_PUSH_ALL),
593 OPT_ALIAS( 0 , "branches", "all"),
594 OPT_BIT( 0 , "mirror", &flags, N_("mirror all refs"),
595 (TRANSPORT_PUSH_MIRROR|TRANSPORT_PUSH_FORCE)),
596 OPT_BOOL('d', "delete", &deleterefs, N_("delete refs")),
597 OPT_BOOL( 0 , "tags", &tags, N_("push tags (can't be used with --all or --branches or --mirror)")),
598 OPT_BIT('n' , "dry-run", &flags, N_("dry run"), TRANSPORT_PUSH_DRY_RUN),
599 OPT_BIT( 0, "porcelain", &flags, N_("machine-readable output"), TRANSPORT_PUSH_PORCELAIN),
600 OPT_BIT('f', "force", &flags, N_("force updates"), TRANSPORT_PUSH_FORCE),
601 OPT_CALLBACK_F(0, "force-with-lease", &cas, N_("<refname>:<expect>"),
602 N_("require old value of ref to be at this value"),
603 PARSE_OPT_OPTARG | PARSE_OPT_LITERAL_ARGHELP, parseopt_push_cas_option),
604 OPT_BIT(0, TRANS_OPT_FORCE_IF_INCLUDES, &flags,
605 N_("require remote updates to be integrated locally"),
606 TRANSPORT_PUSH_FORCE_IF_INCLUDES),
607 OPT_CALLBACK(0, "recurse-submodules", &recurse_submodules, "(check|on-demand|no)",
608 N_("control recursive pushing of submodules"), option_parse_recurse_submodules),
609 OPT_BOOL_F( 0 , "thin", &thin, N_("use thin pack"), PARSE_OPT_NOCOMPLETE),
610 OPT_STRING( 0 , "receive-pack", &receivepack, "receive-pack", N_("receive pack program")),
611 OPT_STRING( 0 , "exec", &receivepack, "receive-pack", N_("receive pack program")),
612 OPT_BIT('u', "set-upstream", &flags, N_("set upstream for git pull/status"),
613 TRANSPORT_PUSH_SET_UPSTREAM),
614 OPT_BOOL(0, "progress", &progress, N_("force progress reporting")),
615 OPT_BIT(0, "prune", &flags, N_("prune locally removed refs"),
616 TRANSPORT_PUSH_PRUNE),
617 OPT_BIT(0, "no-verify", &flags, N_("bypass pre-push hook"), TRANSPORT_PUSH_NO_HOOK),
618 OPT_BIT(0, "follow-tags", &flags, N_("push missing but relevant tags"),
619 TRANSPORT_PUSH_FOLLOW_TAGS),
620 OPT_CALLBACK_F(0, "signed", &push_cert, "(yes|no|if-asked)", N_("GPG sign the push"),
621 PARSE_OPT_OPTARG, option_parse_push_signed),
622 OPT_BIT(0, "atomic", &flags, N_("request atomic transaction on remote side"), TRANSPORT_PUSH_ATOMIC),
623 OPT_STRING_LIST('o', "push-option", &push_options_cmdline, N_("server-specific"), N_("option to transmit")),
624 OPT_IPVERSION(&family),
625 OPT_END()
628 packet_trace_identity("push");
629 git_config(git_push_config, &flags);
630 argc = parse_options(argc, argv, prefix, options, push_usage, 0);
631 push_options = (push_options_cmdline.nr
632 ? &push_options_cmdline
633 : &push_options_config);
634 set_push_cert_flags(&flags, push_cert);
636 die_for_incompatible_opt4(deleterefs, "--delete",
637 tags, "--tags",
638 flags & TRANSPORT_PUSH_ALL, "--all/--branches",
639 flags & TRANSPORT_PUSH_MIRROR, "--mirror");
640 if (deleterefs && argc < 2)
641 die(_("--delete doesn't make sense without any refs"));
643 if (recurse_submodules == RECURSE_SUBMODULES_CHECK)
644 flags |= TRANSPORT_RECURSE_SUBMODULES_CHECK;
645 else if (recurse_submodules == RECURSE_SUBMODULES_ON_DEMAND)
646 flags |= TRANSPORT_RECURSE_SUBMODULES_ON_DEMAND;
647 else if (recurse_submodules == RECURSE_SUBMODULES_ONLY)
648 flags |= TRANSPORT_RECURSE_SUBMODULES_ONLY;
650 if (tags)
651 refspec_append(&rs, "refs/tags/*");
653 if (argc > 0) {
654 repo = argv[0];
655 set_refspecs(argv + 1, argc - 1, repo);
658 remote = pushremote_get(repo);
659 if (!remote) {
660 if (repo)
661 die(_("bad repository '%s'"), repo);
662 die(_("No configured push destination.\n"
663 "Either specify the URL from the command-line or configure a remote repository using\n"
664 "\n"
665 " git remote add <name> <url>\n"
666 "\n"
667 "and then push using the remote name\n"
668 "\n"
669 " git push <name>\n"));
672 if (remote->mirror)
673 flags |= (TRANSPORT_PUSH_MIRROR|TRANSPORT_PUSH_FORCE);
675 if (flags & TRANSPORT_PUSH_ALL) {
676 if (argc >= 2)
677 die(_("--all can't be combined with refspecs"));
679 if (flags & TRANSPORT_PUSH_MIRROR) {
680 if (argc >= 2)
681 die(_("--mirror can't be combined with refspecs"));
684 if (!is_empty_cas(&cas) && (flags & TRANSPORT_PUSH_FORCE_IF_INCLUDES))
685 cas.use_force_if_includes = 1;
687 for_each_string_list_item(item, push_options)
688 if (strchr(item->string, '\n'))
689 die(_("push options must not have new line characters"));
691 rc = do_push(flags, push_options, remote);
692 string_list_clear(&push_options_cmdline, 0);
693 string_list_clear(&push_options_config, 0);
694 if (rc == -1)
695 usage_with_options(push_usage, options);
696 else
697 return rc;