Sync with 2.38.5
[git.git] / builtin / push.c
blob60ac8017e521f0c7c9192df89c797e1898ec60fd
1 /*
2 * "git push"
3 */
4 #include "cache.h"
5 #include "branch.h"
6 #include "config.h"
7 #include "refs.h"
8 #include "refspec.h"
9 #include "run-command.h"
10 #include "builtin.h"
11 #include "remote.h"
12 #include "transport.h"
13 #include "parse-options.h"
14 #include "submodule.h"
15 #include "submodule-config.h"
16 #include "send-pack.h"
17 #include "color.h"
19 static const char * const push_usage[] = {
20 N_("git push [<options>] [<repository> [<refspec>...]]"),
21 NULL,
24 static int push_use_color = -1;
25 static char push_colors[][COLOR_MAXLEN] = {
26 GIT_COLOR_RESET,
27 GIT_COLOR_RED, /* ERROR */
30 enum color_push {
31 PUSH_COLOR_RESET = 0,
32 PUSH_COLOR_ERROR = 1
35 static int parse_push_color_slot(const char *slot)
37 if (!strcasecmp(slot, "reset"))
38 return PUSH_COLOR_RESET;
39 if (!strcasecmp(slot, "error"))
40 return PUSH_COLOR_ERROR;
41 return -1;
44 static const char *push_get_color(enum color_push ix)
46 if (want_color_stderr(push_use_color))
47 return push_colors[ix];
48 return "";
51 static int thin = 1;
52 static int deleterefs;
53 static const char *receivepack;
54 static int verbosity;
55 static int progress = -1;
56 static int recurse_submodules = RECURSE_SUBMODULES_DEFAULT;
57 static enum transport_family family;
59 static struct push_cas_option cas;
61 static struct refspec rs = REFSPEC_INIT_PUSH;
63 static struct string_list push_options_config = STRING_LIST_INIT_DUP;
65 static void refspec_append_mapped(struct refspec *refspec, const char *ref,
66 struct remote *remote, struct ref *local_refs)
68 const char *branch_name;
69 struct ref *matched = NULL;
71 /* Does "ref" uniquely name our ref? */
72 if (count_refspec_match(ref, local_refs, &matched) != 1) {
73 refspec_append(refspec, ref);
74 return;
77 if (remote->push.nr) {
78 struct refspec_item query;
79 memset(&query, 0, sizeof(struct refspec_item));
80 query.src = matched->name;
81 if (!query_refspecs(&remote->push, &query) && query.dst) {
82 refspec_appendf(refspec, "%s%s:%s",
83 query.force ? "+" : "",
84 query.src, query.dst);
85 return;
89 if (push_default == PUSH_DEFAULT_UPSTREAM &&
90 skip_prefix(matched->name, "refs/heads/", &branch_name)) {
91 struct branch *branch = branch_get(branch_name);
92 if (branch->merge_nr == 1 && branch->merge[0]->src) {
93 refspec_appendf(refspec, "%s:%s",
94 ref, branch->merge[0]->src);
95 return;
99 refspec_append(refspec, ref);
102 static void set_refspecs(const char **refs, int nr, const char *repo)
104 struct remote *remote = NULL;
105 struct ref *local_refs = NULL;
106 int i;
108 for (i = 0; i < nr; i++) {
109 const char *ref = refs[i];
110 if (!strcmp("tag", ref)) {
111 if (nr <= ++i)
112 die(_("tag shorthand without <tag>"));
113 ref = refs[i];
114 if (deleterefs)
115 refspec_appendf(&rs, ":refs/tags/%s", ref);
116 else
117 refspec_appendf(&rs, "refs/tags/%s", ref);
118 } else if (deleterefs) {
119 if (strchr(ref, ':') || !*ref)
120 die(_("--delete only accepts plain target ref names"));
121 refspec_appendf(&rs, ":%s", ref);
122 } else if (!strchr(ref, ':')) {
123 if (!remote) {
124 /* lazily grab remote and local_refs */
125 remote = remote_get(repo);
126 local_refs = get_local_heads();
128 refspec_append_mapped(&rs, ref, remote, local_refs);
129 } else
130 refspec_append(&rs, ref);
134 static int push_url_of_remote(struct remote *remote, const char ***url_p)
136 if (remote->pushurl_nr) {
137 *url_p = remote->pushurl;
138 return remote->pushurl_nr;
140 *url_p = remote->url;
141 return remote->url_nr;
144 static NORETURN void die_push_simple(struct branch *branch,
145 struct remote *remote)
148 * There's no point in using shorten_unambiguous_ref here,
149 * as the ambiguity would be on the remote side, not what
150 * we have locally. Plus, this is supposed to be the simple
151 * mode. If the user is doing something crazy like setting
152 * upstream to a non-branch, we should probably be showing
153 * them the big ugly fully qualified ref.
155 const char *advice_pushdefault_maybe = "";
156 const char *advice_automergesimple_maybe = "";
157 const char *short_upstream = branch->merge[0]->src;
159 skip_prefix(short_upstream, "refs/heads/", &short_upstream);
162 * Don't show advice for people who explicitly set
163 * push.default.
165 if (push_default == PUSH_DEFAULT_UNSPECIFIED)
166 advice_pushdefault_maybe = _("\n"
167 "To choose either option permanently, "
168 "see push.default in 'git help config'.\n");
169 if (git_branch_track != BRANCH_TRACK_SIMPLE)
170 advice_automergesimple_maybe = _("\n"
171 "To avoid automatically configuring "
172 "an upstream branch when its name\n"
173 "won't match the local branch, see option "
174 "'simple' of branch.autoSetupMerge\n"
175 "in 'git help config'.\n");
176 die(_("The upstream branch of your current branch does not match\n"
177 "the name of your current branch. To push to the upstream branch\n"
178 "on the remote, use\n"
179 "\n"
180 " git push %s HEAD:%s\n"
181 "\n"
182 "To push to the branch of the same name on the remote, use\n"
183 "\n"
184 " git push %s HEAD\n"
185 "%s%s"),
186 remote->name, short_upstream,
187 remote->name, advice_pushdefault_maybe,
188 advice_automergesimple_maybe);
191 static const char message_detached_head_die[] =
192 N_("You are not currently on a branch.\n"
193 "To push the history leading to the current (detached HEAD)\n"
194 "state now, use\n"
195 "\n"
196 " git push %s HEAD:<name-of-remote-branch>\n");
198 static const char *get_upstream_ref(int flags, struct branch *branch, const char *remote_name)
200 if (branch->merge_nr == 0 && (flags & TRANSPORT_PUSH_AUTO_UPSTREAM)) {
201 /* if missing, assume same; set_upstream will be defined later */
202 return branch->refname;
205 if (!branch->merge_nr || !branch->merge || !branch->remote_name) {
206 const char *advice_autosetup_maybe = "";
207 if (!(flags & TRANSPORT_PUSH_AUTO_UPSTREAM)) {
208 advice_autosetup_maybe = _("\n"
209 "To have this happen automatically for "
210 "branches without a tracking\n"
211 "upstream, see 'push.autoSetupRemote' "
212 "in 'git help config'.\n");
214 die(_("The current branch %s has no upstream branch.\n"
215 "To push the current branch and set the remote as upstream, use\n"
216 "\n"
217 " git push --set-upstream %s %s\n"
218 "%s"),
219 branch->name,
220 remote_name,
221 branch->name,
222 advice_autosetup_maybe);
224 if (branch->merge_nr != 1)
225 die(_("The current branch %s has multiple upstream branches, "
226 "refusing to push."), branch->name);
228 return branch->merge[0]->src;
231 static void setup_default_push_refspecs(int *flags, struct remote *remote)
233 struct branch *branch;
234 const char *dst;
235 int same_remote;
237 switch (push_default) {
238 case PUSH_DEFAULT_MATCHING:
239 refspec_append(&rs, ":");
240 return;
242 case PUSH_DEFAULT_NOTHING:
243 die(_("You didn't specify any refspecs to push, and "
244 "push.default is \"nothing\"."));
245 return;
246 default:
247 break;
250 branch = branch_get(NULL);
251 if (!branch)
252 die(_(message_detached_head_die), remote->name);
254 dst = branch->refname;
255 same_remote = !strcmp(remote->name, remote_for_branch(branch, NULL));
257 switch (push_default) {
258 default:
259 case PUSH_DEFAULT_UNSPECIFIED:
260 case PUSH_DEFAULT_SIMPLE:
261 if (!same_remote)
262 break;
263 if (strcmp(branch->refname, get_upstream_ref(*flags, branch, remote->name)))
264 die_push_simple(branch, remote);
265 break;
267 case PUSH_DEFAULT_UPSTREAM:
268 if (!same_remote)
269 die(_("You are pushing to remote '%s', which is not the upstream of\n"
270 "your current branch '%s', without telling me what to push\n"
271 "to update which remote branch."),
272 remote->name, branch->name);
273 dst = get_upstream_ref(*flags, branch, remote->name);
274 break;
276 case PUSH_DEFAULT_CURRENT:
277 break;
281 * this is a default push - if auto-upstream is enabled and there is
282 * no upstream defined, then set it (with options 'simple', 'upstream',
283 * and 'current').
285 if ((*flags & TRANSPORT_PUSH_AUTO_UPSTREAM) && branch->merge_nr == 0)
286 *flags |= TRANSPORT_PUSH_SET_UPSTREAM;
288 refspec_appendf(&rs, "%s:%s", branch->refname, dst);
291 static const char message_advice_pull_before_push[] =
292 N_("Updates were rejected because the tip of your current branch is behind\n"
293 "its remote counterpart. Integrate the remote changes (e.g.\n"
294 "'git pull ...') before pushing again.\n"
295 "See the 'Note about fast-forwards' in 'git push --help' for details.");
297 static const char message_advice_checkout_pull_push[] =
298 N_("Updates were rejected because a pushed branch tip is behind its remote\n"
299 "counterpart. Check out this branch and integrate the remote changes\n"
300 "(e.g. 'git pull ...') before pushing again.\n"
301 "See the 'Note about fast-forwards' in 'git push --help' for details.");
303 static const char message_advice_ref_fetch_first[] =
304 N_("Updates were rejected because the remote contains work that you do\n"
305 "not have locally. This is usually caused by another repository pushing\n"
306 "to the same ref. You may want to first integrate the remote changes\n"
307 "(e.g., 'git pull ...') before pushing again.\n"
308 "See the 'Note about fast-forwards' in 'git push --help' for details.");
310 static const char message_advice_ref_already_exists[] =
311 N_("Updates were rejected because the tag already exists in the remote.");
313 static const char message_advice_ref_needs_force[] =
314 N_("You cannot update a remote ref that points at a non-commit object,\n"
315 "or update a remote ref to make it point at a non-commit object,\n"
316 "without using the '--force' option.\n");
318 static const char message_advice_ref_needs_update[] =
319 N_("Updates were rejected because the tip of the remote-tracking\n"
320 "branch has been updated since the last checkout. You may want\n"
321 "to integrate those changes locally (e.g., 'git pull ...')\n"
322 "before forcing an update.\n");
324 static void advise_pull_before_push(void)
326 if (!advice_enabled(ADVICE_PUSH_NON_FF_CURRENT) || !advice_enabled(ADVICE_PUSH_UPDATE_REJECTED))
327 return;
328 advise(_(message_advice_pull_before_push));
331 static void advise_checkout_pull_push(void)
333 if (!advice_enabled(ADVICE_PUSH_NON_FF_MATCHING) || !advice_enabled(ADVICE_PUSH_UPDATE_REJECTED))
334 return;
335 advise(_(message_advice_checkout_pull_push));
338 static void advise_ref_already_exists(void)
340 if (!advice_enabled(ADVICE_PUSH_ALREADY_EXISTS) || !advice_enabled(ADVICE_PUSH_UPDATE_REJECTED))
341 return;
342 advise(_(message_advice_ref_already_exists));
345 static void advise_ref_fetch_first(void)
347 if (!advice_enabled(ADVICE_PUSH_FETCH_FIRST) || !advice_enabled(ADVICE_PUSH_UPDATE_REJECTED))
348 return;
349 advise(_(message_advice_ref_fetch_first));
352 static void advise_ref_needs_force(void)
354 if (!advice_enabled(ADVICE_PUSH_NEEDS_FORCE) || !advice_enabled(ADVICE_PUSH_UPDATE_REJECTED))
355 return;
356 advise(_(message_advice_ref_needs_force));
359 static void advise_ref_needs_update(void)
361 if (!advice_enabled(ADVICE_PUSH_REF_NEEDS_UPDATE) || !advice_enabled(ADVICE_PUSH_UPDATE_REJECTED))
362 return;
363 advise(_(message_advice_ref_needs_update));
366 static int push_with_options(struct transport *transport, struct refspec *rs,
367 int flags)
369 int err;
370 unsigned int reject_reasons;
371 char *anon_url = transport_anonymize_url(transport->url);
373 transport_set_verbosity(transport, verbosity, progress);
374 transport->family = family;
376 if (receivepack)
377 transport_set_option(transport,
378 TRANS_OPT_RECEIVEPACK, receivepack);
379 transport_set_option(transport, TRANS_OPT_THIN, thin ? "yes" : NULL);
381 if (!is_empty_cas(&cas)) {
382 if (!transport->smart_options)
383 die("underlying transport does not support --%s option",
384 CAS_OPT_NAME);
385 transport->smart_options->cas = &cas;
388 if (verbosity > 0)
389 fprintf(stderr, _("Pushing to %s\n"), anon_url);
390 trace2_region_enter("push", "transport_push", the_repository);
391 err = transport_push(the_repository, transport,
392 rs, flags, &reject_reasons);
393 trace2_region_leave("push", "transport_push", the_repository);
394 if (err != 0) {
395 fprintf(stderr, "%s", push_get_color(PUSH_COLOR_ERROR));
396 error(_("failed to push some refs to '%s'"), anon_url);
397 fprintf(stderr, "%s", push_get_color(PUSH_COLOR_RESET));
400 err |= transport_disconnect(transport);
401 free(anon_url);
402 if (!err)
403 return 0;
405 if (reject_reasons & REJECT_NON_FF_HEAD) {
406 advise_pull_before_push();
407 } else if (reject_reasons & REJECT_NON_FF_OTHER) {
408 advise_checkout_pull_push();
409 } else if (reject_reasons & REJECT_ALREADY_EXISTS) {
410 advise_ref_already_exists();
411 } else if (reject_reasons & REJECT_FETCH_FIRST) {
412 advise_ref_fetch_first();
413 } else if (reject_reasons & REJECT_NEEDS_FORCE) {
414 advise_ref_needs_force();
415 } else if (reject_reasons & REJECT_REF_NEEDS_UPDATE) {
416 advise_ref_needs_update();
419 return 1;
422 static int do_push(int flags,
423 const struct string_list *push_options,
424 struct remote *remote)
426 int i, errs;
427 const char **url;
428 int url_nr;
429 struct refspec *push_refspec = &rs;
431 if (push_options->nr)
432 flags |= TRANSPORT_PUSH_OPTIONS;
434 if (!push_refspec->nr && !(flags & TRANSPORT_PUSH_ALL)) {
435 if (remote->push.nr) {
436 push_refspec = &remote->push;
437 } else if (!(flags & TRANSPORT_PUSH_MIRROR))
438 setup_default_push_refspecs(&flags, remote);
440 errs = 0;
441 url_nr = push_url_of_remote(remote, &url);
442 if (url_nr) {
443 for (i = 0; i < url_nr; i++) {
444 struct transport *transport =
445 transport_get(remote, url[i]);
446 if (flags & TRANSPORT_PUSH_OPTIONS)
447 transport->push_options = push_options;
448 if (push_with_options(transport, push_refspec, flags))
449 errs++;
451 } else {
452 struct transport *transport =
453 transport_get(remote, NULL);
454 if (flags & TRANSPORT_PUSH_OPTIONS)
455 transport->push_options = push_options;
456 if (push_with_options(transport, push_refspec, flags))
457 errs++;
459 return !!errs;
462 static int option_parse_recurse_submodules(const struct option *opt,
463 const char *arg, int unset)
465 int *recurse_submodules = opt->value;
467 if (unset)
468 *recurse_submodules = RECURSE_SUBMODULES_OFF;
469 else {
470 if (!strcmp(arg, "only-is-on-demand")) {
471 if (*recurse_submodules == RECURSE_SUBMODULES_ONLY) {
472 warning(_("recursing into submodule with push.recurseSubmodules=only; using on-demand instead"));
473 *recurse_submodules = RECURSE_SUBMODULES_ON_DEMAND;
475 } else {
476 *recurse_submodules = parse_push_recurse_submodules_arg(opt->long_name, arg);
480 return 0;
483 static void set_push_cert_flags(int *flags, int v)
485 switch (v) {
486 case SEND_PACK_PUSH_CERT_NEVER:
487 *flags &= ~(TRANSPORT_PUSH_CERT_ALWAYS | TRANSPORT_PUSH_CERT_IF_ASKED);
488 break;
489 case SEND_PACK_PUSH_CERT_ALWAYS:
490 *flags |= TRANSPORT_PUSH_CERT_ALWAYS;
491 *flags &= ~TRANSPORT_PUSH_CERT_IF_ASKED;
492 break;
493 case SEND_PACK_PUSH_CERT_IF_ASKED:
494 *flags |= TRANSPORT_PUSH_CERT_IF_ASKED;
495 *flags &= ~TRANSPORT_PUSH_CERT_ALWAYS;
496 break;
501 static int git_push_config(const char *k, const char *v, void *cb)
503 const char *slot_name;
504 int *flags = cb;
505 int status;
507 status = git_gpg_config(k, v, NULL);
508 if (status)
509 return status;
511 if (!strcmp(k, "push.followtags")) {
512 if (git_config_bool(k, v))
513 *flags |= TRANSPORT_PUSH_FOLLOW_TAGS;
514 else
515 *flags &= ~TRANSPORT_PUSH_FOLLOW_TAGS;
516 return 0;
517 } else if (!strcmp(k, "push.autosetupremote")) {
518 if (git_config_bool(k, v))
519 *flags |= TRANSPORT_PUSH_AUTO_UPSTREAM;
520 return 0;
521 } else if (!strcmp(k, "push.gpgsign")) {
522 const char *value;
523 if (!git_config_get_value("push.gpgsign", &value)) {
524 switch (git_parse_maybe_bool(value)) {
525 case 0:
526 set_push_cert_flags(flags, SEND_PACK_PUSH_CERT_NEVER);
527 break;
528 case 1:
529 set_push_cert_flags(flags, SEND_PACK_PUSH_CERT_ALWAYS);
530 break;
531 default:
532 if (value && !strcasecmp(value, "if-asked"))
533 set_push_cert_flags(flags, SEND_PACK_PUSH_CERT_IF_ASKED);
534 else
535 return error(_("invalid value for '%s'"), k);
538 } else if (!strcmp(k, "push.recursesubmodules")) {
539 const char *value;
540 if (!git_config_get_value("push.recursesubmodules", &value))
541 recurse_submodules = parse_push_recurse_submodules_arg(k, value);
542 } else if (!strcmp(k, "submodule.recurse")) {
543 int val = git_config_bool(k, v) ?
544 RECURSE_SUBMODULES_ON_DEMAND : RECURSE_SUBMODULES_OFF;
545 recurse_submodules = val;
546 } else if (!strcmp(k, "push.pushoption")) {
547 if (!v)
548 return config_error_nonbool(k);
549 else
550 if (!*v)
551 string_list_clear(&push_options_config, 0);
552 else
553 string_list_append(&push_options_config, v);
554 return 0;
555 } else if (!strcmp(k, "color.push")) {
556 push_use_color = git_config_colorbool(k, v);
557 return 0;
558 } else if (skip_prefix(k, "color.push.", &slot_name)) {
559 int slot = parse_push_color_slot(slot_name);
560 if (slot < 0)
561 return 0;
562 if (!v)
563 return config_error_nonbool(k);
564 return color_parse(v, push_colors[slot]);
565 } else if (!strcmp(k, "push.useforceifincludes")) {
566 if (git_config_bool(k, v))
567 *flags |= TRANSPORT_PUSH_FORCE_IF_INCLUDES;
568 else
569 *flags &= ~TRANSPORT_PUSH_FORCE_IF_INCLUDES;
570 return 0;
573 return git_default_config(k, v, NULL);
576 int cmd_push(int argc, const char **argv, const char *prefix)
578 int flags = 0;
579 int tags = 0;
580 int push_cert = -1;
581 int rc;
582 const char *repo = NULL; /* default repository */
583 struct string_list push_options_cmdline = STRING_LIST_INIT_DUP;
584 struct string_list *push_options;
585 const struct string_list_item *item;
586 struct remote *remote;
588 struct option options[] = {
589 OPT__VERBOSITY(&verbosity),
590 OPT_STRING( 0 , "repo", &repo, N_("repository"), N_("repository")),
591 OPT_BIT( 0 , "all", &flags, N_("push all refs"), TRANSPORT_PUSH_ALL),
592 OPT_BIT( 0 , "mirror", &flags, N_("mirror all refs"),
593 (TRANSPORT_PUSH_MIRROR|TRANSPORT_PUSH_FORCE)),
594 OPT_BOOL('d', "delete", &deleterefs, N_("delete refs")),
595 OPT_BOOL( 0 , "tags", &tags, N_("push tags (can't be used with --all or --mirror)")),
596 OPT_BIT('n' , "dry-run", &flags, N_("dry run"), TRANSPORT_PUSH_DRY_RUN),
597 OPT_BIT( 0, "porcelain", &flags, N_("machine-readable output"), TRANSPORT_PUSH_PORCELAIN),
598 OPT_BIT('f', "force", &flags, N_("force updates"), TRANSPORT_PUSH_FORCE),
599 OPT_CALLBACK_F(0, CAS_OPT_NAME, &cas, N_("<refname>:<expect>"),
600 N_("require old value of ref to be at this value"),
601 PARSE_OPT_OPTARG | PARSE_OPT_LITERAL_ARGHELP, parseopt_push_cas_option),
602 OPT_BIT(0, TRANS_OPT_FORCE_IF_INCLUDES, &flags,
603 N_("require remote updates to be integrated locally"),
604 TRANSPORT_PUSH_FORCE_IF_INCLUDES),
605 OPT_CALLBACK(0, "recurse-submodules", &recurse_submodules, "(check|on-demand|no)",
606 N_("control recursive pushing of submodules"), option_parse_recurse_submodules),
607 OPT_BOOL_F( 0 , "thin", &thin, N_("use thin pack"), PARSE_OPT_NOCOMPLETE),
608 OPT_STRING( 0 , "receive-pack", &receivepack, "receive-pack", N_("receive pack program")),
609 OPT_STRING( 0 , "exec", &receivepack, "receive-pack", N_("receive pack program")),
610 OPT_BIT('u', "set-upstream", &flags, N_("set upstream for git pull/status"),
611 TRANSPORT_PUSH_SET_UPSTREAM),
612 OPT_BOOL(0, "progress", &progress, N_("force progress reporting")),
613 OPT_BIT(0, "prune", &flags, N_("prune locally removed refs"),
614 TRANSPORT_PUSH_PRUNE),
615 OPT_BIT(0, "no-verify", &flags, N_("bypass pre-push hook"), TRANSPORT_PUSH_NO_HOOK),
616 OPT_BIT(0, "follow-tags", &flags, N_("push missing but relevant tags"),
617 TRANSPORT_PUSH_FOLLOW_TAGS),
618 OPT_CALLBACK_F(0, "signed", &push_cert, "(yes|no|if-asked)", N_("GPG sign the push"),
619 PARSE_OPT_OPTARG, option_parse_push_signed),
620 OPT_BIT(0, "atomic", &flags, N_("request atomic transaction on remote side"), TRANSPORT_PUSH_ATOMIC),
621 OPT_STRING_LIST('o', "push-option", &push_options_cmdline, N_("server-specific"), N_("option to transmit")),
622 OPT_SET_INT('4', "ipv4", &family, N_("use IPv4 addresses only"),
623 TRANSPORT_FAMILY_IPV4),
624 OPT_SET_INT('6', "ipv6", &family, N_("use IPv6 addresses only"),
625 TRANSPORT_FAMILY_IPV6),
626 OPT_END()
629 packet_trace_identity("push");
630 git_config(git_push_config, &flags);
631 argc = parse_options(argc, argv, prefix, options, push_usage, 0);
632 push_options = (push_options_cmdline.nr
633 ? &push_options_cmdline
634 : &push_options_config);
635 set_push_cert_flags(&flags, push_cert);
637 if (deleterefs && (tags || (flags & (TRANSPORT_PUSH_ALL | TRANSPORT_PUSH_MIRROR))))
638 die(_("options '%s' and '%s' cannot be used together"), "--delete", "--all/--mirror/--tags");
639 if (deleterefs && argc < 2)
640 die(_("--delete doesn't make sense without any refs"));
642 if (recurse_submodules == RECURSE_SUBMODULES_CHECK)
643 flags |= TRANSPORT_RECURSE_SUBMODULES_CHECK;
644 else if (recurse_submodules == RECURSE_SUBMODULES_ON_DEMAND)
645 flags |= TRANSPORT_RECURSE_SUBMODULES_ON_DEMAND;
646 else if (recurse_submodules == RECURSE_SUBMODULES_ONLY)
647 flags |= TRANSPORT_RECURSE_SUBMODULES_ONLY;
649 if (tags)
650 refspec_append(&rs, "refs/tags/*");
652 if (argc > 0) {
653 repo = argv[0];
654 set_refspecs(argv + 1, argc - 1, repo);
657 remote = pushremote_get(repo);
658 if (!remote) {
659 if (repo)
660 die(_("bad repository '%s'"), repo);
661 die(_("No configured push destination.\n"
662 "Either specify the URL from the command-line or configure a remote repository using\n"
663 "\n"
664 " git remote add <name> <url>\n"
665 "\n"
666 "and then push using the remote name\n"
667 "\n"
668 " git push <name>\n"));
671 if (remote->mirror)
672 flags |= (TRANSPORT_PUSH_MIRROR|TRANSPORT_PUSH_FORCE);
674 if (flags & TRANSPORT_PUSH_ALL) {
675 if (tags)
676 die(_("options '%s' and '%s' cannot be used together"), "--all", "--tags");
677 if (argc >= 2)
678 die(_("--all can't be combined with refspecs"));
680 if (flags & TRANSPORT_PUSH_MIRROR) {
681 if (tags)
682 die(_("options '%s' and '%s' cannot be used together"), "--mirror", "--tags");
683 if (argc >= 2)
684 die(_("--mirror can't be combined with refspecs"));
686 if ((flags & TRANSPORT_PUSH_ALL) && (flags & TRANSPORT_PUSH_MIRROR))
687 die(_("options '%s' and '%s' cannot be used together"), "--all", "--mirror");
689 if (!is_empty_cas(&cas) && (flags & TRANSPORT_PUSH_FORCE_IF_INCLUDES))
690 cas.use_force_if_includes = 1;
692 for_each_string_list_item(item, push_options)
693 if (strchr(item->string, '\n'))
694 die(_("push options must not have new line characters"));
696 rc = do_push(flags, push_options, remote);
697 string_list_clear(&push_options_cmdline, 0);
698 string_list_clear(&push_options_config, 0);
699 if (rc == -1)
700 usage_with_options(push_usage, options);
701 else
702 return rc;