Merge branch 'sg/index-format-doc-update' into maint
[git/debian.git] / builtin / push.c
blobdf0d68e599857c74a4edf0a85ecdfb037516c47d
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 "upstream branches when their name\n"
173 "doesn'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 *recurse_submodules = parse_push_recurse_submodules_arg(opt->long_name, arg);
472 return 0;
475 static void set_push_cert_flags(int *flags, int v)
477 switch (v) {
478 case SEND_PACK_PUSH_CERT_NEVER:
479 *flags &= ~(TRANSPORT_PUSH_CERT_ALWAYS | TRANSPORT_PUSH_CERT_IF_ASKED);
480 break;
481 case SEND_PACK_PUSH_CERT_ALWAYS:
482 *flags |= TRANSPORT_PUSH_CERT_ALWAYS;
483 *flags &= ~TRANSPORT_PUSH_CERT_IF_ASKED;
484 break;
485 case SEND_PACK_PUSH_CERT_IF_ASKED:
486 *flags |= TRANSPORT_PUSH_CERT_IF_ASKED;
487 *flags &= ~TRANSPORT_PUSH_CERT_ALWAYS;
488 break;
493 static int git_push_config(const char *k, const char *v, void *cb)
495 const char *slot_name;
496 int *flags = cb;
497 int status;
499 status = git_gpg_config(k, v, NULL);
500 if (status)
501 return status;
503 if (!strcmp(k, "push.followtags")) {
504 if (git_config_bool(k, v))
505 *flags |= TRANSPORT_PUSH_FOLLOW_TAGS;
506 else
507 *flags &= ~TRANSPORT_PUSH_FOLLOW_TAGS;
508 return 0;
509 } else if (!strcmp(k, "push.autosetupremote")) {
510 if (git_config_bool(k, v))
511 *flags |= TRANSPORT_PUSH_AUTO_UPSTREAM;
512 return 0;
513 } else if (!strcmp(k, "push.gpgsign")) {
514 const char *value;
515 if (!git_config_get_value("push.gpgsign", &value)) {
516 switch (git_parse_maybe_bool(value)) {
517 case 0:
518 set_push_cert_flags(flags, SEND_PACK_PUSH_CERT_NEVER);
519 break;
520 case 1:
521 set_push_cert_flags(flags, SEND_PACK_PUSH_CERT_ALWAYS);
522 break;
523 default:
524 if (value && !strcasecmp(value, "if-asked"))
525 set_push_cert_flags(flags, SEND_PACK_PUSH_CERT_IF_ASKED);
526 else
527 return error(_("invalid value for '%s'"), k);
530 } else if (!strcmp(k, "push.recursesubmodules")) {
531 const char *value;
532 if (!git_config_get_value("push.recursesubmodules", &value))
533 recurse_submodules = parse_push_recurse_submodules_arg(k, value);
534 } else if (!strcmp(k, "submodule.recurse")) {
535 int val = git_config_bool(k, v) ?
536 RECURSE_SUBMODULES_ON_DEMAND : RECURSE_SUBMODULES_OFF;
537 recurse_submodules = val;
538 } else if (!strcmp(k, "push.pushoption")) {
539 if (!v)
540 return config_error_nonbool(k);
541 else
542 if (!*v)
543 string_list_clear(&push_options_config, 0);
544 else
545 string_list_append(&push_options_config, v);
546 return 0;
547 } else if (!strcmp(k, "color.push")) {
548 push_use_color = git_config_colorbool(k, v);
549 return 0;
550 } else if (skip_prefix(k, "color.push.", &slot_name)) {
551 int slot = parse_push_color_slot(slot_name);
552 if (slot < 0)
553 return 0;
554 if (!v)
555 return config_error_nonbool(k);
556 return color_parse(v, push_colors[slot]);
557 } else if (!strcmp(k, "push.useforceifincludes")) {
558 if (git_config_bool(k, v))
559 *flags |= TRANSPORT_PUSH_FORCE_IF_INCLUDES;
560 else
561 *flags &= ~TRANSPORT_PUSH_FORCE_IF_INCLUDES;
562 return 0;
565 return git_default_config(k, v, NULL);
568 int cmd_push(int argc, const char **argv, const char *prefix)
570 int flags = 0;
571 int tags = 0;
572 int push_cert = -1;
573 int rc;
574 const char *repo = NULL; /* default repository */
575 struct string_list push_options_cmdline = STRING_LIST_INIT_DUP;
576 struct string_list *push_options;
577 const struct string_list_item *item;
578 struct remote *remote;
580 struct option options[] = {
581 OPT__VERBOSITY(&verbosity),
582 OPT_STRING( 0 , "repo", &repo, N_("repository"), N_("repository")),
583 OPT_BIT( 0 , "all", &flags, N_("push all refs"), TRANSPORT_PUSH_ALL),
584 OPT_BIT( 0 , "mirror", &flags, N_("mirror all refs"),
585 (TRANSPORT_PUSH_MIRROR|TRANSPORT_PUSH_FORCE)),
586 OPT_BOOL('d', "delete", &deleterefs, N_("delete refs")),
587 OPT_BOOL( 0 , "tags", &tags, N_("push tags (can't be used with --all or --mirror)")),
588 OPT_BIT('n' , "dry-run", &flags, N_("dry run"), TRANSPORT_PUSH_DRY_RUN),
589 OPT_BIT( 0, "porcelain", &flags, N_("machine-readable output"), TRANSPORT_PUSH_PORCELAIN),
590 OPT_BIT('f', "force", &flags, N_("force updates"), TRANSPORT_PUSH_FORCE),
591 OPT_CALLBACK_F(0, CAS_OPT_NAME, &cas, N_("<refname>:<expect>"),
592 N_("require old value of ref to be at this value"),
593 PARSE_OPT_OPTARG | PARSE_OPT_LITERAL_ARGHELP, parseopt_push_cas_option),
594 OPT_BIT(0, TRANS_OPT_FORCE_IF_INCLUDES, &flags,
595 N_("require remote updates to be integrated locally"),
596 TRANSPORT_PUSH_FORCE_IF_INCLUDES),
597 OPT_CALLBACK(0, "recurse-submodules", &recurse_submodules, "(check|on-demand|no)",
598 N_("control recursive pushing of submodules"), option_parse_recurse_submodules),
599 OPT_BOOL_F( 0 , "thin", &thin, N_("use thin pack"), PARSE_OPT_NOCOMPLETE),
600 OPT_STRING( 0 , "receive-pack", &receivepack, "receive-pack", N_("receive pack program")),
601 OPT_STRING( 0 , "exec", &receivepack, "receive-pack", N_("receive pack program")),
602 OPT_BIT('u', "set-upstream", &flags, N_("set upstream for git pull/status"),
603 TRANSPORT_PUSH_SET_UPSTREAM),
604 OPT_BOOL(0, "progress", &progress, N_("force progress reporting")),
605 OPT_BIT(0, "prune", &flags, N_("prune locally removed refs"),
606 TRANSPORT_PUSH_PRUNE),
607 OPT_BIT(0, "no-verify", &flags, N_("bypass pre-push hook"), TRANSPORT_PUSH_NO_HOOK),
608 OPT_BIT(0, "follow-tags", &flags, N_("push missing but relevant tags"),
609 TRANSPORT_PUSH_FOLLOW_TAGS),
610 OPT_CALLBACK_F(0, "signed", &push_cert, "(yes|no|if-asked)", N_("GPG sign the push"),
611 PARSE_OPT_OPTARG, option_parse_push_signed),
612 OPT_BIT(0, "atomic", &flags, N_("request atomic transaction on remote side"), TRANSPORT_PUSH_ATOMIC),
613 OPT_STRING_LIST('o', "push-option", &push_options_cmdline, N_("server-specific"), N_("option to transmit")),
614 OPT_SET_INT('4', "ipv4", &family, N_("use IPv4 addresses only"),
615 TRANSPORT_FAMILY_IPV4),
616 OPT_SET_INT('6', "ipv6", &family, N_("use IPv6 addresses only"),
617 TRANSPORT_FAMILY_IPV6),
618 OPT_END()
621 packet_trace_identity("push");
622 git_config(git_push_config, &flags);
623 argc = parse_options(argc, argv, prefix, options, push_usage, 0);
624 push_options = (push_options_cmdline.nr
625 ? &push_options_cmdline
626 : &push_options_config);
627 set_push_cert_flags(&flags, push_cert);
629 if (deleterefs && (tags || (flags & (TRANSPORT_PUSH_ALL | TRANSPORT_PUSH_MIRROR))))
630 die(_("options '%s' and '%s' cannot be used together"), "--delete", "--all/--mirror/--tags");
631 if (deleterefs && argc < 2)
632 die(_("--delete doesn't make sense without any refs"));
634 if (recurse_submodules == RECURSE_SUBMODULES_CHECK)
635 flags |= TRANSPORT_RECURSE_SUBMODULES_CHECK;
636 else if (recurse_submodules == RECURSE_SUBMODULES_ON_DEMAND)
637 flags |= TRANSPORT_RECURSE_SUBMODULES_ON_DEMAND;
638 else if (recurse_submodules == RECURSE_SUBMODULES_ONLY)
639 flags |= TRANSPORT_RECURSE_SUBMODULES_ONLY;
641 if (tags)
642 refspec_append(&rs, "refs/tags/*");
644 if (argc > 0) {
645 repo = argv[0];
646 set_refspecs(argv + 1, argc - 1, repo);
649 remote = pushremote_get(repo);
650 if (!remote) {
651 if (repo)
652 die(_("bad repository '%s'"), repo);
653 die(_("No configured push destination.\n"
654 "Either specify the URL from the command-line or configure a remote repository using\n"
655 "\n"
656 " git remote add <name> <url>\n"
657 "\n"
658 "and then push using the remote name\n"
659 "\n"
660 " git push <name>\n"));
663 if (remote->mirror)
664 flags |= (TRANSPORT_PUSH_MIRROR|TRANSPORT_PUSH_FORCE);
666 if (flags & TRANSPORT_PUSH_ALL) {
667 if (tags)
668 die(_("options '%s' and '%s' cannot be used together"), "--all", "--tags");
669 if (argc >= 2)
670 die(_("--all can't be combined with refspecs"));
672 if (flags & TRANSPORT_PUSH_MIRROR) {
673 if (tags)
674 die(_("options '%s' and '%s' cannot be used together"), "--mirror", "--tags");
675 if (argc >= 2)
676 die(_("--mirror can't be combined with refspecs"));
678 if ((flags & TRANSPORT_PUSH_ALL) && (flags & TRANSPORT_PUSH_MIRROR))
679 die(_("options '%s' and '%s' cannot be used together"), "--all", "--mirror");
681 if (!is_empty_cas(&cas) && (flags & TRANSPORT_PUSH_FORCE_IF_INCLUDES))
682 cas.use_force_if_includes = 1;
684 for_each_string_list_item(item, push_options)
685 if (strchr(item->string, '\n'))
686 die(_("push options must not have new line characters"));
688 rc = do_push(flags, push_options, remote);
689 string_list_clear(&push_options_cmdline, 0);
690 string_list_clear(&push_options_config, 0);
691 if (rc == -1)
692 usage_with_options(push_usage, options);
693 else
694 return rc;