Documentation/gitprotocol-v2.txt: fix a slight inconsistency in format
[git/gitster.git] / builtin / push.c
blob8f7d326ab3f4b06d3d3d1262d5276fd8c6b2b968
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 *matched)
68 const char *branch_name;
70 if (remote->push.nr) {
71 struct refspec_item query;
72 memset(&query, 0, sizeof(struct refspec_item));
73 query.src = matched->name;
74 if (!query_refspecs(&remote->push, &query) && query.dst) {
75 refspec_appendf(refspec, "%s%s:%s",
76 query.force ? "+" : "",
77 query.src, query.dst);
78 return;
82 if (push_default == PUSH_DEFAULT_UPSTREAM &&
83 skip_prefix(matched->name, "refs/heads/", &branch_name)) {
84 struct branch *branch = branch_get(branch_name);
85 if (branch->merge_nr == 1 && branch->merge[0]->src) {
86 refspec_appendf(refspec, "%s:%s",
87 ref, branch->merge[0]->src);
88 return;
92 refspec_append(refspec, ref);
95 static void set_refspecs(const char **refs, int nr, const char *repo)
97 struct remote *remote = NULL;
98 struct ref *local_refs = NULL;
99 int i;
101 for (i = 0; i < nr; i++) {
102 const char *ref = refs[i];
103 if (!strcmp("tag", ref)) {
104 if (nr <= ++i)
105 die(_("tag shorthand without <tag>"));
106 ref = refs[i];
107 if (deleterefs)
108 refspec_appendf(&rs, ":refs/tags/%s", ref);
109 else
110 refspec_appendf(&rs, "refs/tags/%s", ref);
111 } else if (deleterefs) {
112 if (strchr(ref, ':') || !*ref)
113 die(_("--delete only accepts plain target ref names"));
114 refspec_appendf(&rs, ":%s", ref);
115 } else if (!strchr(ref, ':')) {
116 struct ref *matched = NULL;
118 /* lazily grab local_refs */
119 if (!local_refs)
120 local_refs = get_local_heads();
122 /* Does "ref" uniquely name our ref? */
123 if (count_refspec_match(ref, local_refs, &matched) != 1) {
124 refspec_append(&rs, ref);
125 } else {
126 /* lazily grab remote */
127 if (!remote)
128 remote = remote_get(repo);
129 if (!remote)
130 BUG("must get a remote for repo '%s'", repo);
132 refspec_append_mapped(&rs, ref, remote, matched);
134 } else
135 refspec_append(&rs, ref);
137 free_refs(local_refs);
140 static int push_url_of_remote(struct remote *remote, const char ***url_p)
142 if (remote->pushurl_nr) {
143 *url_p = remote->pushurl;
144 return remote->pushurl_nr;
146 *url_p = remote->url;
147 return remote->url_nr;
150 static NORETURN void die_push_simple(struct branch *branch,
151 struct remote *remote)
154 * There's no point in using shorten_unambiguous_ref here,
155 * as the ambiguity would be on the remote side, not what
156 * we have locally. Plus, this is supposed to be the simple
157 * mode. If the user is doing something crazy like setting
158 * upstream to a non-branch, we should probably be showing
159 * them the big ugly fully qualified ref.
161 const char *advice_pushdefault_maybe = "";
162 const char *advice_automergesimple_maybe = "";
163 const char *short_upstream = branch->merge[0]->src;
165 skip_prefix(short_upstream, "refs/heads/", &short_upstream);
168 * Don't show advice for people who explicitly set
169 * push.default.
171 if (push_default == PUSH_DEFAULT_UNSPECIFIED)
172 advice_pushdefault_maybe = _("\n"
173 "To choose either option permanently, "
174 "see push.default in 'git help config'.\n");
175 if (git_branch_track != BRANCH_TRACK_SIMPLE)
176 advice_automergesimple_maybe = _("\n"
177 "To avoid automatically configuring "
178 "an upstream branch when its name\n"
179 "won't match the local branch, see option "
180 "'simple' of branch.autoSetupMerge\n"
181 "in 'git help config'.\n");
182 die(_("The upstream branch of your current branch does not match\n"
183 "the name of your current branch. To push to the upstream branch\n"
184 "on the remote, use\n"
185 "\n"
186 " git push %s HEAD:%s\n"
187 "\n"
188 "To push to the branch of the same name on the remote, use\n"
189 "\n"
190 " git push %s HEAD\n"
191 "%s%s"),
192 remote->name, short_upstream,
193 remote->name, advice_pushdefault_maybe,
194 advice_automergesimple_maybe);
197 static const char message_detached_head_die[] =
198 N_("You are not currently on a branch.\n"
199 "To push the history leading to the current (detached HEAD)\n"
200 "state now, use\n"
201 "\n"
202 " git push %s HEAD:<name-of-remote-branch>\n");
204 static const char *get_upstream_ref(int flags, struct branch *branch, const char *remote_name)
206 if (branch->merge_nr == 0 && (flags & TRANSPORT_PUSH_AUTO_UPSTREAM)) {
207 /* if missing, assume same; set_upstream will be defined later */
208 return branch->refname;
211 if (!branch->merge_nr || !branch->merge || !branch->remote_name) {
212 const char *advice_autosetup_maybe = "";
213 if (!(flags & TRANSPORT_PUSH_AUTO_UPSTREAM)) {
214 advice_autosetup_maybe = _("\n"
215 "To have this happen automatically for "
216 "branches without a tracking\n"
217 "upstream, see 'push.autoSetupRemote' "
218 "in 'git help config'.\n");
220 die(_("The current branch %s has no upstream branch.\n"
221 "To push the current branch and set the remote as upstream, use\n"
222 "\n"
223 " git push --set-upstream %s %s\n"
224 "%s"),
225 branch->name,
226 remote_name,
227 branch->name,
228 advice_autosetup_maybe);
230 if (branch->merge_nr != 1)
231 die(_("The current branch %s has multiple upstream branches, "
232 "refusing to push."), branch->name);
234 return branch->merge[0]->src;
237 static void setup_default_push_refspecs(int *flags, struct remote *remote)
239 struct branch *branch;
240 const char *dst;
241 int same_remote;
243 switch (push_default) {
244 case PUSH_DEFAULT_MATCHING:
245 refspec_append(&rs, ":");
246 return;
248 case PUSH_DEFAULT_NOTHING:
249 die(_("You didn't specify any refspecs to push, and "
250 "push.default is \"nothing\"."));
251 return;
252 default:
253 break;
256 branch = branch_get(NULL);
257 if (!branch)
258 die(_(message_detached_head_die), remote->name);
260 dst = branch->refname;
261 same_remote = !strcmp(remote->name, remote_for_branch(branch, NULL));
263 switch (push_default) {
264 default:
265 case PUSH_DEFAULT_UNSPECIFIED:
266 case PUSH_DEFAULT_SIMPLE:
267 if (!same_remote)
268 break;
269 if (strcmp(branch->refname, get_upstream_ref(*flags, branch, remote->name)))
270 die_push_simple(branch, remote);
271 break;
273 case PUSH_DEFAULT_UPSTREAM:
274 if (!same_remote)
275 die(_("You are pushing to remote '%s', which is not the upstream of\n"
276 "your current branch '%s', without telling me what to push\n"
277 "to update which remote branch."),
278 remote->name, branch->name);
279 dst = get_upstream_ref(*flags, branch, remote->name);
280 break;
282 case PUSH_DEFAULT_CURRENT:
283 break;
287 * this is a default push - if auto-upstream is enabled and there is
288 * no upstream defined, then set it (with options 'simple', 'upstream',
289 * and 'current').
291 if ((*flags & TRANSPORT_PUSH_AUTO_UPSTREAM) && branch->merge_nr == 0)
292 *flags |= TRANSPORT_PUSH_SET_UPSTREAM;
294 refspec_appendf(&rs, "%s:%s", branch->refname, dst);
297 static const char message_advice_pull_before_push[] =
298 N_("Updates were rejected because the tip of your current branch is behind\n"
299 "its remote counterpart. Integrate the remote changes (e.g.\n"
300 "'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_checkout_pull_push[] =
304 N_("Updates were rejected because a pushed branch tip is behind its remote\n"
305 "counterpart. Check out this branch and integrate the remote changes\n"
306 "(e.g. 'git pull ...') before pushing again.\n"
307 "See the 'Note about fast-forwards' in 'git push --help' for details.");
309 static const char message_advice_ref_fetch_first[] =
310 N_("Updates were rejected because the remote contains work that you do\n"
311 "not have locally. This is usually caused by another repository pushing\n"
312 "to the same ref. You may want to first integrate the remote changes\n"
313 "(e.g., 'git pull ...') before pushing again.\n"
314 "See the 'Note about fast-forwards' in 'git push --help' for details.");
316 static const char message_advice_ref_already_exists[] =
317 N_("Updates were rejected because the tag already exists in the remote.");
319 static const char message_advice_ref_needs_force[] =
320 N_("You cannot update a remote ref that points at a non-commit object,\n"
321 "or update a remote ref to make it point at a non-commit object,\n"
322 "without using the '--force' option.\n");
324 static const char message_advice_ref_needs_update[] =
325 N_("Updates were rejected because the tip of the remote-tracking\n"
326 "branch has been updated since the last checkout. You may want\n"
327 "to integrate those changes locally (e.g., 'git pull ...')\n"
328 "before forcing an update.\n");
330 static void advise_pull_before_push(void)
332 if (!advice_enabled(ADVICE_PUSH_NON_FF_CURRENT) || !advice_enabled(ADVICE_PUSH_UPDATE_REJECTED))
333 return;
334 advise(_(message_advice_pull_before_push));
337 static void advise_checkout_pull_push(void)
339 if (!advice_enabled(ADVICE_PUSH_NON_FF_MATCHING) || !advice_enabled(ADVICE_PUSH_UPDATE_REJECTED))
340 return;
341 advise(_(message_advice_checkout_pull_push));
344 static void advise_ref_already_exists(void)
346 if (!advice_enabled(ADVICE_PUSH_ALREADY_EXISTS) || !advice_enabled(ADVICE_PUSH_UPDATE_REJECTED))
347 return;
348 advise(_(message_advice_ref_already_exists));
351 static void advise_ref_fetch_first(void)
353 if (!advice_enabled(ADVICE_PUSH_FETCH_FIRST) || !advice_enabled(ADVICE_PUSH_UPDATE_REJECTED))
354 return;
355 advise(_(message_advice_ref_fetch_first));
358 static void advise_ref_needs_force(void)
360 if (!advice_enabled(ADVICE_PUSH_NEEDS_FORCE) || !advice_enabled(ADVICE_PUSH_UPDATE_REJECTED))
361 return;
362 advise(_(message_advice_ref_needs_force));
365 static void advise_ref_needs_update(void)
367 if (!advice_enabled(ADVICE_PUSH_REF_NEEDS_UPDATE) || !advice_enabled(ADVICE_PUSH_UPDATE_REJECTED))
368 return;
369 advise(_(message_advice_ref_needs_update));
372 static int push_with_options(struct transport *transport, struct refspec *rs,
373 int flags)
375 int err;
376 unsigned int reject_reasons;
377 char *anon_url = transport_anonymize_url(transport->url);
379 transport_set_verbosity(transport, verbosity, progress);
380 transport->family = family;
382 if (receivepack)
383 transport_set_option(transport,
384 TRANS_OPT_RECEIVEPACK, receivepack);
385 transport_set_option(transport, TRANS_OPT_THIN, thin ? "yes" : NULL);
387 if (!is_empty_cas(&cas)) {
388 if (!transport->smart_options)
389 die("underlying transport does not support --%s option",
390 CAS_OPT_NAME);
391 transport->smart_options->cas = &cas;
394 if (verbosity > 0)
395 fprintf(stderr, _("Pushing to %s\n"), anon_url);
396 trace2_region_enter("push", "transport_push", the_repository);
397 err = transport_push(the_repository, transport,
398 rs, flags, &reject_reasons);
399 trace2_region_leave("push", "transport_push", the_repository);
400 if (err != 0) {
401 fprintf(stderr, "%s", push_get_color(PUSH_COLOR_ERROR));
402 error(_("failed to push some refs to '%s'"), anon_url);
403 fprintf(stderr, "%s", push_get_color(PUSH_COLOR_RESET));
406 err |= transport_disconnect(transport);
407 free(anon_url);
408 if (!err)
409 return 0;
411 if (reject_reasons & REJECT_NON_FF_HEAD) {
412 advise_pull_before_push();
413 } else if (reject_reasons & REJECT_NON_FF_OTHER) {
414 advise_checkout_pull_push();
415 } else if (reject_reasons & REJECT_ALREADY_EXISTS) {
416 advise_ref_already_exists();
417 } else if (reject_reasons & REJECT_FETCH_FIRST) {
418 advise_ref_fetch_first();
419 } else if (reject_reasons & REJECT_NEEDS_FORCE) {
420 advise_ref_needs_force();
421 } else if (reject_reasons & REJECT_REF_NEEDS_UPDATE) {
422 advise_ref_needs_update();
425 return 1;
428 static int do_push(int flags,
429 const struct string_list *push_options,
430 struct remote *remote)
432 int i, errs;
433 const char **url;
434 int url_nr;
435 struct refspec *push_refspec = &rs;
437 if (push_options->nr)
438 flags |= TRANSPORT_PUSH_OPTIONS;
440 if (!push_refspec->nr && !(flags & TRANSPORT_PUSH_ALL)) {
441 if (remote->push.nr) {
442 push_refspec = &remote->push;
443 } else if (!(flags & TRANSPORT_PUSH_MIRROR))
444 setup_default_push_refspecs(&flags, remote);
446 errs = 0;
447 url_nr = push_url_of_remote(remote, &url);
448 if (url_nr) {
449 for (i = 0; i < url_nr; i++) {
450 struct transport *transport =
451 transport_get(remote, url[i]);
452 if (flags & TRANSPORT_PUSH_OPTIONS)
453 transport->push_options = push_options;
454 if (push_with_options(transport, push_refspec, flags))
455 errs++;
457 } else {
458 struct transport *transport =
459 transport_get(remote, NULL);
460 if (flags & TRANSPORT_PUSH_OPTIONS)
461 transport->push_options = push_options;
462 if (push_with_options(transport, push_refspec, flags))
463 errs++;
465 return !!errs;
468 static int option_parse_recurse_submodules(const struct option *opt,
469 const char *arg, int unset)
471 int *recurse_submodules = opt->value;
473 if (unset)
474 *recurse_submodules = RECURSE_SUBMODULES_OFF;
475 else {
476 if (!strcmp(arg, "only-is-on-demand")) {
477 if (*recurse_submodules == RECURSE_SUBMODULES_ONLY) {
478 warning(_("recursing into submodule with push.recurseSubmodules=only; using on-demand instead"));
479 *recurse_submodules = RECURSE_SUBMODULES_ON_DEMAND;
481 } else {
482 *recurse_submodules = parse_push_recurse_submodules_arg(opt->long_name, arg);
486 return 0;
489 static void set_push_cert_flags(int *flags, int v)
491 switch (v) {
492 case SEND_PACK_PUSH_CERT_NEVER:
493 *flags &= ~(TRANSPORT_PUSH_CERT_ALWAYS | TRANSPORT_PUSH_CERT_IF_ASKED);
494 break;
495 case SEND_PACK_PUSH_CERT_ALWAYS:
496 *flags |= TRANSPORT_PUSH_CERT_ALWAYS;
497 *flags &= ~TRANSPORT_PUSH_CERT_IF_ASKED;
498 break;
499 case SEND_PACK_PUSH_CERT_IF_ASKED:
500 *flags |= TRANSPORT_PUSH_CERT_IF_ASKED;
501 *flags &= ~TRANSPORT_PUSH_CERT_ALWAYS;
502 break;
507 static int git_push_config(const char *k, const char *v, void *cb)
509 const char *slot_name;
510 int *flags = cb;
511 int status;
513 status = git_gpg_config(k, v, NULL);
514 if (status)
515 return status;
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 const char *value;
529 if (!git_config_get_value("push.gpgsign", &value)) {
530 switch (git_parse_maybe_bool(value)) {
531 case 0:
532 set_push_cert_flags(flags, SEND_PACK_PUSH_CERT_NEVER);
533 break;
534 case 1:
535 set_push_cert_flags(flags, SEND_PACK_PUSH_CERT_ALWAYS);
536 break;
537 default:
538 if (value && !strcasecmp(value, "if-asked"))
539 set_push_cert_flags(flags, SEND_PACK_PUSH_CERT_IF_ASKED);
540 else
541 return error(_("invalid value for '%s'"), k);
544 } else if (!strcmp(k, "push.recursesubmodules")) {
545 const char *value;
546 if (!git_config_get_value("push.recursesubmodules", &value))
547 recurse_submodules = parse_push_recurse_submodules_arg(k, value);
548 } else if (!strcmp(k, "submodule.recurse")) {
549 int val = git_config_bool(k, v) ?
550 RECURSE_SUBMODULES_ON_DEMAND : RECURSE_SUBMODULES_OFF;
551 recurse_submodules = val;
552 } else if (!strcmp(k, "push.pushoption")) {
553 if (!v)
554 return config_error_nonbool(k);
555 else
556 if (!*v)
557 string_list_clear(&push_options_config, 0);
558 else
559 string_list_append(&push_options_config, v);
560 return 0;
561 } else if (!strcmp(k, "color.push")) {
562 push_use_color = git_config_colorbool(k, v);
563 return 0;
564 } else if (skip_prefix(k, "color.push.", &slot_name)) {
565 int slot = parse_push_color_slot(slot_name);
566 if (slot < 0)
567 return 0;
568 if (!v)
569 return config_error_nonbool(k);
570 return color_parse(v, push_colors[slot]);
571 } else if (!strcmp(k, "push.useforceifincludes")) {
572 if (git_config_bool(k, v))
573 *flags |= TRANSPORT_PUSH_FORCE_IF_INCLUDES;
574 else
575 *flags &= ~TRANSPORT_PUSH_FORCE_IF_INCLUDES;
576 return 0;
579 return git_default_config(k, v, NULL);
582 int cmd_push(int argc, const char **argv, const char *prefix)
584 int flags = 0;
585 int tags = 0;
586 int push_cert = -1;
587 int rc;
588 const char *repo = NULL; /* default repository */
589 struct string_list push_options_cmdline = STRING_LIST_INIT_DUP;
590 struct string_list *push_options;
591 const struct string_list_item *item;
592 struct remote *remote;
594 struct option options[] = {
595 OPT__VERBOSITY(&verbosity),
596 OPT_STRING( 0 , "repo", &repo, N_("repository"), N_("repository")),
597 OPT_BIT( 0 , "all", &flags, N_("push all refs"), TRANSPORT_PUSH_ALL),
598 OPT_BIT( 0 , "mirror", &flags, N_("mirror all refs"),
599 (TRANSPORT_PUSH_MIRROR|TRANSPORT_PUSH_FORCE)),
600 OPT_BOOL('d', "delete", &deleterefs, N_("delete refs")),
601 OPT_BOOL( 0 , "tags", &tags, N_("push tags (can't be used with --all or --mirror)")),
602 OPT_BIT('n' , "dry-run", &flags, N_("dry run"), TRANSPORT_PUSH_DRY_RUN),
603 OPT_BIT( 0, "porcelain", &flags, N_("machine-readable output"), TRANSPORT_PUSH_PORCELAIN),
604 OPT_BIT('f', "force", &flags, N_("force updates"), TRANSPORT_PUSH_FORCE),
605 OPT_CALLBACK_F(0, CAS_OPT_NAME, &cas, N_("<refname>:<expect>"),
606 N_("require old value of ref to be at this value"),
607 PARSE_OPT_OPTARG | PARSE_OPT_LITERAL_ARGHELP, parseopt_push_cas_option),
608 OPT_BIT(0, TRANS_OPT_FORCE_IF_INCLUDES, &flags,
609 N_("require remote updates to be integrated locally"),
610 TRANSPORT_PUSH_FORCE_IF_INCLUDES),
611 OPT_CALLBACK(0, "recurse-submodules", &recurse_submodules, "(check|on-demand|no)",
612 N_("control recursive pushing of submodules"), option_parse_recurse_submodules),
613 OPT_BOOL_F( 0 , "thin", &thin, N_("use thin pack"), PARSE_OPT_NOCOMPLETE),
614 OPT_STRING( 0 , "receive-pack", &receivepack, "receive-pack", N_("receive pack program")),
615 OPT_STRING( 0 , "exec", &receivepack, "receive-pack", N_("receive pack program")),
616 OPT_BIT('u', "set-upstream", &flags, N_("set upstream for git pull/status"),
617 TRANSPORT_PUSH_SET_UPSTREAM),
618 OPT_BOOL(0, "progress", &progress, N_("force progress reporting")),
619 OPT_BIT(0, "prune", &flags, N_("prune locally removed refs"),
620 TRANSPORT_PUSH_PRUNE),
621 OPT_BIT(0, "no-verify", &flags, N_("bypass pre-push hook"), TRANSPORT_PUSH_NO_HOOK),
622 OPT_BIT(0, "follow-tags", &flags, N_("push missing but relevant tags"),
623 TRANSPORT_PUSH_FOLLOW_TAGS),
624 OPT_CALLBACK_F(0, "signed", &push_cert, "(yes|no|if-asked)", N_("GPG sign the push"),
625 PARSE_OPT_OPTARG, option_parse_push_signed),
626 OPT_BIT(0, "atomic", &flags, N_("request atomic transaction on remote side"), TRANSPORT_PUSH_ATOMIC),
627 OPT_STRING_LIST('o', "push-option", &push_options_cmdline, N_("server-specific"), N_("option to transmit")),
628 OPT_SET_INT('4', "ipv4", &family, N_("use IPv4 addresses only"),
629 TRANSPORT_FAMILY_IPV4),
630 OPT_SET_INT('6', "ipv6", &family, N_("use IPv6 addresses only"),
631 TRANSPORT_FAMILY_IPV6),
632 OPT_END()
635 packet_trace_identity("push");
636 git_config(git_push_config, &flags);
637 argc = parse_options(argc, argv, prefix, options, push_usage, 0);
638 push_options = (push_options_cmdline.nr
639 ? &push_options_cmdline
640 : &push_options_config);
641 set_push_cert_flags(&flags, push_cert);
643 if (deleterefs && (tags || (flags & (TRANSPORT_PUSH_ALL | TRANSPORT_PUSH_MIRROR))))
644 die(_("options '%s' and '%s' cannot be used together"), "--delete", "--all/--mirror/--tags");
645 if (deleterefs && argc < 2)
646 die(_("--delete doesn't make sense without any refs"));
648 if (recurse_submodules == RECURSE_SUBMODULES_CHECK)
649 flags |= TRANSPORT_RECURSE_SUBMODULES_CHECK;
650 else if (recurse_submodules == RECURSE_SUBMODULES_ON_DEMAND)
651 flags |= TRANSPORT_RECURSE_SUBMODULES_ON_DEMAND;
652 else if (recurse_submodules == RECURSE_SUBMODULES_ONLY)
653 flags |= TRANSPORT_RECURSE_SUBMODULES_ONLY;
655 if (tags)
656 refspec_append(&rs, "refs/tags/*");
658 if (argc > 0) {
659 repo = argv[0];
660 set_refspecs(argv + 1, argc - 1, repo);
663 remote = pushremote_get(repo);
664 if (!remote) {
665 if (repo)
666 die(_("bad repository '%s'"), repo);
667 die(_("No configured push destination.\n"
668 "Either specify the URL from the command-line or configure a remote repository using\n"
669 "\n"
670 " git remote add <name> <url>\n"
671 "\n"
672 "and then push using the remote name\n"
673 "\n"
674 " git push <name>\n"));
677 if (remote->mirror)
678 flags |= (TRANSPORT_PUSH_MIRROR|TRANSPORT_PUSH_FORCE);
680 if (flags & TRANSPORT_PUSH_ALL) {
681 if (tags)
682 die(_("options '%s' and '%s' cannot be used together"), "--all", "--tags");
683 if (argc >= 2)
684 die(_("--all can't be combined with refspecs"));
686 if (flags & TRANSPORT_PUSH_MIRROR) {
687 if (tags)
688 die(_("options '%s' and '%s' cannot be used together"), "--mirror", "--tags");
689 if (argc >= 2)
690 die(_("--mirror can't be combined with refspecs"));
692 if ((flags & TRANSPORT_PUSH_ALL) && (flags & TRANSPORT_PUSH_MIRROR))
693 die(_("options '%s' and '%s' cannot be used together"), "--all", "--mirror");
695 if (!is_empty_cas(&cas) && (flags & TRANSPORT_PUSH_FORCE_IF_INCLUDES))
696 cas.use_force_if_includes = 1;
698 for_each_string_list_item(item, push_options)
699 if (strchr(item->string, '\n'))
700 die(_("push options must not have new line characters"));
702 rc = do_push(flags, push_options, remote);
703 string_list_clear(&push_options_cmdline, 0);
704 string_list_clear(&push_options_config, 0);
705 if (rc == -1)
706 usage_with_options(push_usage, options);
707 else
708 return rc;