Merge branch 'sl/worktree-sparse'
[alt-git.git] / builtin / push.c
blobdbdf609daf33172cb95ff082f3e23edb88c3d806
1 /*
2 * "git push"
3 */
4 #include "cache.h"
5 #include "advice.h"
6 #include "branch.h"
7 #include "config.h"
8 #include "environment.h"
9 #include "gettext.h"
10 #include "refs.h"
11 #include "refspec.h"
12 #include "run-command.h"
13 #include "builtin.h"
14 #include "remote.h"
15 #include "transport.h"
16 #include "parse-options.h"
17 #include "pkt-line.h"
18 #include "repository.h"
19 #include "submodule.h"
20 #include "submodule-config.h"
21 #include "send-pack.h"
22 #include "trace2.h"
23 #include "color.h"
25 static const char * const push_usage[] = {
26 N_("git push [<options>] [<repository> [<refspec>...]]"),
27 NULL,
30 static int push_use_color = -1;
31 static char push_colors[][COLOR_MAXLEN] = {
32 GIT_COLOR_RESET,
33 GIT_COLOR_RED, /* ERROR */
36 enum color_push {
37 PUSH_COLOR_RESET = 0,
38 PUSH_COLOR_ERROR = 1
41 static int parse_push_color_slot(const char *slot)
43 if (!strcasecmp(slot, "reset"))
44 return PUSH_COLOR_RESET;
45 if (!strcasecmp(slot, "error"))
46 return PUSH_COLOR_ERROR;
47 return -1;
50 static const char *push_get_color(enum color_push ix)
52 if (want_color_stderr(push_use_color))
53 return push_colors[ix];
54 return "";
57 static int thin = 1;
58 static int deleterefs;
59 static const char *receivepack;
60 static int verbosity;
61 static int progress = -1;
62 static int recurse_submodules = RECURSE_SUBMODULES_DEFAULT;
63 static enum transport_family family;
65 static struct push_cas_option cas;
67 static struct refspec rs = REFSPEC_INIT_PUSH;
69 static struct string_list push_options_config = STRING_LIST_INIT_DUP;
71 static void refspec_append_mapped(struct refspec *refspec, const char *ref,
72 struct remote *remote, struct ref *matched)
74 const char *branch_name;
76 if (remote->push.nr) {
77 struct refspec_item query;
78 memset(&query, 0, sizeof(struct refspec_item));
79 query.src = matched->name;
80 if (!query_refspecs(&remote->push, &query) && query.dst) {
81 refspec_appendf(refspec, "%s%s:%s",
82 query.force ? "+" : "",
83 query.src, 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, const char *repo)
103 struct remote *remote = NULL;
104 struct ref *local_refs = NULL;
105 int i;
107 for (i = 0; i < nr; i++) {
108 const char *ref = refs[i];
109 if (!strcmp("tag", ref)) {
110 if (nr <= ++i)
111 die(_("tag shorthand without <tag>"));
112 ref = refs[i];
113 if (deleterefs)
114 refspec_appendf(&rs, ":refs/tags/%s", ref);
115 else
116 refspec_appendf(&rs, "refs/tags/%s", ref);
117 } else if (deleterefs) {
118 if (strchr(ref, ':') || !*ref)
119 die(_("--delete only accepts plain target ref names"));
120 refspec_appendf(&rs, ":%s", ref);
121 } else if (!strchr(ref, ':')) {
122 struct ref *matched = NULL;
124 /* lazily grab local_refs */
125 if (!local_refs)
126 local_refs = get_local_heads();
128 /* Does "ref" uniquely name our ref? */
129 if (count_refspec_match(ref, local_refs, &matched) != 1) {
130 refspec_append(&rs, ref);
131 } else {
132 /* lazily grab remote */
133 if (!remote)
134 remote = remote_get(repo);
135 if (!remote)
136 BUG("must get a remote for repo '%s'", repo);
138 refspec_append_mapped(&rs, ref, remote, matched);
140 } else
141 refspec_append(&rs, ref);
143 free_refs(local_refs);
146 static int push_url_of_remote(struct remote *remote, const char ***url_p)
148 if (remote->pushurl_nr) {
149 *url_p = remote->pushurl;
150 return remote->pushurl_nr;
152 *url_p = remote->url;
153 return remote->url_nr;
156 static NORETURN void die_push_simple(struct branch *branch,
157 struct remote *remote)
160 * There's no point in using shorten_unambiguous_ref here,
161 * as the ambiguity would be on the remote side, not what
162 * we have locally. Plus, this is supposed to be the simple
163 * mode. If the user is doing something crazy like setting
164 * upstream to a non-branch, we should probably be showing
165 * them the big ugly fully qualified ref.
167 const char *advice_pushdefault_maybe = "";
168 const char *advice_automergesimple_maybe = "";
169 const char *short_upstream = branch->merge[0]->src;
171 skip_prefix(short_upstream, "refs/heads/", &short_upstream);
174 * Don't show advice for people who explicitly set
175 * push.default.
177 if (push_default == PUSH_DEFAULT_UNSPECIFIED)
178 advice_pushdefault_maybe = _("\n"
179 "To choose either option permanently, "
180 "see push.default in 'git help config'.\n");
181 if (git_branch_track != BRANCH_TRACK_SIMPLE)
182 advice_automergesimple_maybe = _("\n"
183 "To avoid automatically configuring "
184 "an upstream branch when its name\n"
185 "won't match the local branch, see option "
186 "'simple' of branch.autoSetupMerge\n"
187 "in 'git help config'.\n");
188 die(_("The upstream branch of your current branch does not match\n"
189 "the name of your current branch. To push to the upstream branch\n"
190 "on the remote, use\n"
191 "\n"
192 " git push %s HEAD:%s\n"
193 "\n"
194 "To push to the branch of the same name on the remote, use\n"
195 "\n"
196 " git push %s HEAD\n"
197 "%s%s"),
198 remote->name, short_upstream,
199 remote->name, advice_pushdefault_maybe,
200 advice_automergesimple_maybe);
203 static const char message_detached_head_die[] =
204 N_("You are not currently on a branch.\n"
205 "To push the history leading to the current (detached HEAD)\n"
206 "state now, use\n"
207 "\n"
208 " git push %s HEAD:<name-of-remote-branch>\n");
210 static const char *get_upstream_ref(int flags, struct branch *branch, const char *remote_name)
212 if (branch->merge_nr == 0 && (flags & TRANSPORT_PUSH_AUTO_UPSTREAM)) {
213 /* if missing, assume same; set_upstream will be defined later */
214 return branch->refname;
217 if (!branch->merge_nr || !branch->merge || !branch->remote_name) {
218 const char *advice_autosetup_maybe = "";
219 if (!(flags & TRANSPORT_PUSH_AUTO_UPSTREAM)) {
220 advice_autosetup_maybe = _("\n"
221 "To have this happen automatically for "
222 "branches without a tracking\n"
223 "upstream, see 'push.autoSetupRemote' "
224 "in 'git help config'.\n");
226 die(_("The current branch %s has no upstream branch.\n"
227 "To push the current branch and set the remote as upstream, use\n"
228 "\n"
229 " git push --set-upstream %s %s\n"
230 "%s"),
231 branch->name,
232 remote_name,
233 branch->name,
234 advice_autosetup_maybe);
236 if (branch->merge_nr != 1)
237 die(_("The current branch %s has multiple upstream branches, "
238 "refusing to push."), branch->name);
240 return branch->merge[0]->src;
243 static void setup_default_push_refspecs(int *flags, struct remote *remote)
245 struct branch *branch;
246 const char *dst;
247 int same_remote;
249 switch (push_default) {
250 case PUSH_DEFAULT_MATCHING:
251 refspec_append(&rs, ":");
252 return;
254 case PUSH_DEFAULT_NOTHING:
255 die(_("You didn't specify any refspecs to push, and "
256 "push.default is \"nothing\"."));
257 return;
258 default:
259 break;
262 branch = branch_get(NULL);
263 if (!branch)
264 die(_(message_detached_head_die), remote->name);
266 dst = branch->refname;
267 same_remote = !strcmp(remote->name, remote_for_branch(branch, NULL));
269 switch (push_default) {
270 default:
271 case PUSH_DEFAULT_UNSPECIFIED:
272 case PUSH_DEFAULT_SIMPLE:
273 if (!same_remote)
274 break;
275 if (strcmp(branch->refname, get_upstream_ref(*flags, branch, remote->name)))
276 die_push_simple(branch, remote);
277 break;
279 case PUSH_DEFAULT_UPSTREAM:
280 if (!same_remote)
281 die(_("You are pushing to remote '%s', which is not the upstream of\n"
282 "your current branch '%s', without telling me what to push\n"
283 "to update which remote branch."),
284 remote->name, branch->name);
285 dst = get_upstream_ref(*flags, branch, remote->name);
286 break;
288 case PUSH_DEFAULT_CURRENT:
289 break;
293 * this is a default push - if auto-upstream is enabled and there is
294 * no upstream defined, then set it (with options 'simple', 'upstream',
295 * and 'current').
297 if ((*flags & TRANSPORT_PUSH_AUTO_UPSTREAM) && branch->merge_nr == 0)
298 *flags |= TRANSPORT_PUSH_SET_UPSTREAM;
300 refspec_appendf(&rs, "%s:%s", branch->refname, dst);
303 static const char message_advice_pull_before_push[] =
304 N_("Updates were rejected because the tip of your current branch is behind\n"
305 "its remote counterpart. Integrate the remote changes (e.g.\n"
306 "'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_checkout_pull_push[] =
310 N_("Updates were rejected because a pushed branch tip is behind its remote\n"
311 "counterpart. Check out this branch and integrate the remote changes\n"
312 "(e.g. 'git pull ...') before pushing again.\n"
313 "See the 'Note about fast-forwards' in 'git push --help' for details.");
315 static const char message_advice_ref_fetch_first[] =
316 N_("Updates were rejected because the remote contains work that you do\n"
317 "not have locally. This is usually caused by another repository pushing\n"
318 "to the same ref. You may want to first integrate the remote changes\n"
319 "(e.g., 'git pull ...') before pushing again.\n"
320 "See the 'Note about fast-forwards' in 'git push --help' for details.");
322 static const char message_advice_ref_already_exists[] =
323 N_("Updates were rejected because the tag already exists in the remote.");
325 static const char message_advice_ref_needs_force[] =
326 N_("You cannot update a remote ref that points at a non-commit object,\n"
327 "or update a remote ref to make it point at a non-commit object,\n"
328 "without using the '--force' option.\n");
330 static const char message_advice_ref_needs_update[] =
331 N_("Updates were rejected because the tip of the remote-tracking\n"
332 "branch has been updated since the last checkout. You may want\n"
333 "to integrate those changes locally (e.g., 'git pull ...')\n"
334 "before forcing an update.\n");
336 static void advise_pull_before_push(void)
338 if (!advice_enabled(ADVICE_PUSH_NON_FF_CURRENT) || !advice_enabled(ADVICE_PUSH_UPDATE_REJECTED))
339 return;
340 advise(_(message_advice_pull_before_push));
343 static void advise_checkout_pull_push(void)
345 if (!advice_enabled(ADVICE_PUSH_NON_FF_MATCHING) || !advice_enabled(ADVICE_PUSH_UPDATE_REJECTED))
346 return;
347 advise(_(message_advice_checkout_pull_push));
350 static void advise_ref_already_exists(void)
352 if (!advice_enabled(ADVICE_PUSH_ALREADY_EXISTS) || !advice_enabled(ADVICE_PUSH_UPDATE_REJECTED))
353 return;
354 advise(_(message_advice_ref_already_exists));
357 static void advise_ref_fetch_first(void)
359 if (!advice_enabled(ADVICE_PUSH_FETCH_FIRST) || !advice_enabled(ADVICE_PUSH_UPDATE_REJECTED))
360 return;
361 advise(_(message_advice_ref_fetch_first));
364 static void advise_ref_needs_force(void)
366 if (!advice_enabled(ADVICE_PUSH_NEEDS_FORCE) || !advice_enabled(ADVICE_PUSH_UPDATE_REJECTED))
367 return;
368 advise(_(message_advice_ref_needs_force));
371 static void advise_ref_needs_update(void)
373 if (!advice_enabled(ADVICE_PUSH_REF_NEEDS_UPDATE) || !advice_enabled(ADVICE_PUSH_UPDATE_REJECTED))
374 return;
375 advise(_(message_advice_ref_needs_update));
378 static int push_with_options(struct transport *transport, struct refspec *rs,
379 int flags)
381 int err;
382 unsigned int reject_reasons;
383 char *anon_url = transport_anonymize_url(transport->url);
385 transport_set_verbosity(transport, verbosity, progress);
386 transport->family = family;
388 if (receivepack)
389 transport_set_option(transport,
390 TRANS_OPT_RECEIVEPACK, receivepack);
391 transport_set_option(transport, TRANS_OPT_THIN, thin ? "yes" : NULL);
393 if (!is_empty_cas(&cas)) {
394 if (!transport->smart_options)
395 die("underlying transport does not support --%s option",
396 CAS_OPT_NAME);
397 transport->smart_options->cas = &cas;
400 if (verbosity > 0)
401 fprintf(stderr, _("Pushing to %s\n"), anon_url);
402 trace2_region_enter("push", "transport_push", the_repository);
403 err = transport_push(the_repository, transport,
404 rs, flags, &reject_reasons);
405 trace2_region_leave("push", "transport_push", the_repository);
406 if (err != 0) {
407 fprintf(stderr, "%s", push_get_color(PUSH_COLOR_ERROR));
408 error(_("failed to push some refs to '%s'"), anon_url);
409 fprintf(stderr, "%s", push_get_color(PUSH_COLOR_RESET));
412 err |= transport_disconnect(transport);
413 free(anon_url);
414 if (!err)
415 return 0;
417 if (reject_reasons & REJECT_NON_FF_HEAD) {
418 advise_pull_before_push();
419 } else if (reject_reasons & REJECT_NON_FF_OTHER) {
420 advise_checkout_pull_push();
421 } else if (reject_reasons & REJECT_ALREADY_EXISTS) {
422 advise_ref_already_exists();
423 } else if (reject_reasons & REJECT_FETCH_FIRST) {
424 advise_ref_fetch_first();
425 } else if (reject_reasons & REJECT_NEEDS_FORCE) {
426 advise_ref_needs_force();
427 } else if (reject_reasons & REJECT_REF_NEEDS_UPDATE) {
428 advise_ref_needs_update();
431 return 1;
434 static int do_push(int flags,
435 const struct string_list *push_options,
436 struct remote *remote)
438 int i, errs;
439 const char **url;
440 int url_nr;
441 struct refspec *push_refspec = &rs;
443 if (push_options->nr)
444 flags |= TRANSPORT_PUSH_OPTIONS;
446 if (!push_refspec->nr && !(flags & TRANSPORT_PUSH_ALL)) {
447 if (remote->push.nr) {
448 push_refspec = &remote->push;
449 } else if (!(flags & TRANSPORT_PUSH_MIRROR))
450 setup_default_push_refspecs(&flags, remote);
452 errs = 0;
453 url_nr = push_url_of_remote(remote, &url);
454 if (url_nr) {
455 for (i = 0; i < url_nr; i++) {
456 struct transport *transport =
457 transport_get(remote, url[i]);
458 if (flags & TRANSPORT_PUSH_OPTIONS)
459 transport->push_options = push_options;
460 if (push_with_options(transport, push_refspec, flags))
461 errs++;
463 } else {
464 struct transport *transport =
465 transport_get(remote, NULL);
466 if (flags & TRANSPORT_PUSH_OPTIONS)
467 transport->push_options = push_options;
468 if (push_with_options(transport, push_refspec, flags))
469 errs++;
471 return !!errs;
474 static int option_parse_recurse_submodules(const struct option *opt,
475 const char *arg, int unset)
477 int *recurse_submodules = opt->value;
479 if (unset)
480 *recurse_submodules = RECURSE_SUBMODULES_OFF;
481 else {
482 if (!strcmp(arg, "only-is-on-demand")) {
483 if (*recurse_submodules == RECURSE_SUBMODULES_ONLY) {
484 warning(_("recursing into submodule with push.recurseSubmodules=only; using on-demand instead"));
485 *recurse_submodules = RECURSE_SUBMODULES_ON_DEMAND;
487 } else {
488 *recurse_submodules = parse_push_recurse_submodules_arg(opt->long_name, arg);
492 return 0;
495 static void set_push_cert_flags(int *flags, int v)
497 switch (v) {
498 case SEND_PACK_PUSH_CERT_NEVER:
499 *flags &= ~(TRANSPORT_PUSH_CERT_ALWAYS | TRANSPORT_PUSH_CERT_IF_ASKED);
500 break;
501 case SEND_PACK_PUSH_CERT_ALWAYS:
502 *flags |= TRANSPORT_PUSH_CERT_ALWAYS;
503 *flags &= ~TRANSPORT_PUSH_CERT_IF_ASKED;
504 break;
505 case SEND_PACK_PUSH_CERT_IF_ASKED:
506 *flags |= TRANSPORT_PUSH_CERT_IF_ASKED;
507 *flags &= ~TRANSPORT_PUSH_CERT_ALWAYS;
508 break;
513 static int git_push_config(const char *k, const char *v, void *cb)
515 const char *slot_name;
516 int *flags = cb;
518 if (!strcmp(k, "push.followtags")) {
519 if (git_config_bool(k, v))
520 *flags |= TRANSPORT_PUSH_FOLLOW_TAGS;
521 else
522 *flags &= ~TRANSPORT_PUSH_FOLLOW_TAGS;
523 return 0;
524 } else if (!strcmp(k, "push.autosetupremote")) {
525 if (git_config_bool(k, v))
526 *flags |= TRANSPORT_PUSH_AUTO_UPSTREAM;
527 return 0;
528 } else if (!strcmp(k, "push.gpgsign")) {
529 const char *value;
530 if (!git_config_get_value("push.gpgsign", &value)) {
531 switch (git_parse_maybe_bool(value)) {
532 case 0:
533 set_push_cert_flags(flags, SEND_PACK_PUSH_CERT_NEVER);
534 break;
535 case 1:
536 set_push_cert_flags(flags, SEND_PACK_PUSH_CERT_ALWAYS);
537 break;
538 default:
539 if (value && !strcasecmp(value, "if-asked"))
540 set_push_cert_flags(flags, SEND_PACK_PUSH_CERT_IF_ASKED);
541 else
542 return error(_("invalid value for '%s'"), k);
545 } else if (!strcmp(k, "push.recursesubmodules")) {
546 const char *value;
547 if (!git_config_get_value("push.recursesubmodules", &value))
548 recurse_submodules = parse_push_recurse_submodules_arg(k, value);
549 } else if (!strcmp(k, "submodule.recurse")) {
550 int val = git_config_bool(k, v) ?
551 RECURSE_SUBMODULES_ON_DEMAND : RECURSE_SUBMODULES_OFF;
552 recurse_submodules = val;
553 } else if (!strcmp(k, "push.pushoption")) {
554 if (!v)
555 return config_error_nonbool(k);
556 else
557 if (!*v)
558 string_list_clear(&push_options_config, 0);
559 else
560 string_list_append(&push_options_config, v);
561 return 0;
562 } else if (!strcmp(k, "color.push")) {
563 push_use_color = git_config_colorbool(k, v);
564 return 0;
565 } else if (skip_prefix(k, "color.push.", &slot_name)) {
566 int slot = parse_push_color_slot(slot_name);
567 if (slot < 0)
568 return 0;
569 if (!v)
570 return config_error_nonbool(k);
571 return color_parse(v, push_colors[slot]);
572 } else if (!strcmp(k, "push.useforceifincludes")) {
573 if (git_config_bool(k, v))
574 *flags |= TRANSPORT_PUSH_FORCE_IF_INCLUDES;
575 else
576 *flags &= ~TRANSPORT_PUSH_FORCE_IF_INCLUDES;
577 return 0;
580 return git_default_config(k, v, NULL);
583 int cmd_push(int argc, const char **argv, const char *prefix)
585 int flags = 0;
586 int tags = 0;
587 int push_cert = -1;
588 int rc;
589 const char *repo = NULL; /* default repository */
590 struct string_list push_options_cmdline = STRING_LIST_INIT_DUP;
591 struct string_list *push_options;
592 const struct string_list_item *item;
593 struct remote *remote;
595 struct option options[] = {
596 OPT__VERBOSITY(&verbosity),
597 OPT_STRING( 0 , "repo", &repo, N_("repository"), N_("repository")),
598 OPT_BIT( 0 , "all", &flags, N_("push all branches"), TRANSPORT_PUSH_ALL),
599 OPT_ALIAS( 0 , "branches", "all"),
600 OPT_BIT( 0 , "mirror", &flags, N_("mirror all refs"),
601 (TRANSPORT_PUSH_MIRROR|TRANSPORT_PUSH_FORCE)),
602 OPT_BOOL('d', "delete", &deleterefs, N_("delete refs")),
603 OPT_BOOL( 0 , "tags", &tags, N_("push tags (can't be used with --all or --branches or --mirror)")),
604 OPT_BIT('n' , "dry-run", &flags, N_("dry run"), TRANSPORT_PUSH_DRY_RUN),
605 OPT_BIT( 0, "porcelain", &flags, N_("machine-readable output"), TRANSPORT_PUSH_PORCELAIN),
606 OPT_BIT('f', "force", &flags, N_("force updates"), TRANSPORT_PUSH_FORCE),
607 OPT_CALLBACK_F(0, CAS_OPT_NAME, &cas, N_("<refname>:<expect>"),
608 N_("require old value of ref to be at this value"),
609 PARSE_OPT_OPTARG | PARSE_OPT_LITERAL_ARGHELP, parseopt_push_cas_option),
610 OPT_BIT(0, TRANS_OPT_FORCE_IF_INCLUDES, &flags,
611 N_("require remote updates to be integrated locally"),
612 TRANSPORT_PUSH_FORCE_IF_INCLUDES),
613 OPT_CALLBACK(0, "recurse-submodules", &recurse_submodules, "(check|on-demand|no)",
614 N_("control recursive pushing of submodules"), option_parse_recurse_submodules),
615 OPT_BOOL_F( 0 , "thin", &thin, N_("use thin pack"), PARSE_OPT_NOCOMPLETE),
616 OPT_STRING( 0 , "receive-pack", &receivepack, "receive-pack", N_("receive pack program")),
617 OPT_STRING( 0 , "exec", &receivepack, "receive-pack", N_("receive pack program")),
618 OPT_BIT('u', "set-upstream", &flags, N_("set upstream for git pull/status"),
619 TRANSPORT_PUSH_SET_UPSTREAM),
620 OPT_BOOL(0, "progress", &progress, N_("force progress reporting")),
621 OPT_BIT(0, "prune", &flags, N_("prune locally removed refs"),
622 TRANSPORT_PUSH_PRUNE),
623 OPT_BIT(0, "no-verify", &flags, N_("bypass pre-push hook"), TRANSPORT_PUSH_NO_HOOK),
624 OPT_BIT(0, "follow-tags", &flags, N_("push missing but relevant tags"),
625 TRANSPORT_PUSH_FOLLOW_TAGS),
626 OPT_CALLBACK_F(0, "signed", &push_cert, "(yes|no|if-asked)", N_("GPG sign the push"),
627 PARSE_OPT_OPTARG, option_parse_push_signed),
628 OPT_BIT(0, "atomic", &flags, N_("request atomic transaction on remote side"), TRANSPORT_PUSH_ATOMIC),
629 OPT_STRING_LIST('o', "push-option", &push_options_cmdline, N_("server-specific"), N_("option to transmit")),
630 OPT_SET_INT('4', "ipv4", &family, N_("use IPv4 addresses only"),
631 TRANSPORT_FAMILY_IPV4),
632 OPT_SET_INT('6', "ipv6", &family, N_("use IPv6 addresses only"),
633 TRANSPORT_FAMILY_IPV6),
634 OPT_END()
637 packet_trace_identity("push");
638 git_config(git_push_config, &flags);
639 argc = parse_options(argc, argv, prefix, options, push_usage, 0);
640 push_options = (push_options_cmdline.nr
641 ? &push_options_cmdline
642 : &push_options_config);
643 set_push_cert_flags(&flags, push_cert);
645 if (deleterefs && (tags || (flags & (TRANSPORT_PUSH_ALL | TRANSPORT_PUSH_MIRROR))))
646 die(_("options '%s' and '%s' cannot be used together"), "--delete", "--all/--branches/--mirror/--tags");
647 if (deleterefs && argc < 2)
648 die(_("--delete doesn't make sense without any refs"));
650 if (recurse_submodules == RECURSE_SUBMODULES_CHECK)
651 flags |= TRANSPORT_RECURSE_SUBMODULES_CHECK;
652 else if (recurse_submodules == RECURSE_SUBMODULES_ON_DEMAND)
653 flags |= TRANSPORT_RECURSE_SUBMODULES_ON_DEMAND;
654 else if (recurse_submodules == RECURSE_SUBMODULES_ONLY)
655 flags |= TRANSPORT_RECURSE_SUBMODULES_ONLY;
657 if (tags)
658 refspec_append(&rs, "refs/tags/*");
660 if (argc > 0) {
661 repo = argv[0];
662 set_refspecs(argv + 1, argc - 1, repo);
665 remote = pushremote_get(repo);
666 if (!remote) {
667 if (repo)
668 die(_("bad repository '%s'"), repo);
669 die(_("No configured push destination.\n"
670 "Either specify the URL from the command-line or configure a remote repository using\n"
671 "\n"
672 " git remote add <name> <url>\n"
673 "\n"
674 "and then push using the remote name\n"
675 "\n"
676 " git push <name>\n"));
679 if (remote->mirror)
680 flags |= (TRANSPORT_PUSH_MIRROR|TRANSPORT_PUSH_FORCE);
682 if (flags & TRANSPORT_PUSH_ALL) {
683 if (tags)
684 die(_("options '%s' and '%s' cannot be used together"), "--all", "--tags");
685 if (argc >= 2)
686 die(_("--all can't be combined with refspecs"));
688 if (flags & TRANSPORT_PUSH_MIRROR) {
689 if (tags)
690 die(_("options '%s' and '%s' cannot be used together"), "--mirror", "--tags");
691 if (argc >= 2)
692 die(_("--mirror can't be combined with refspecs"));
694 if ((flags & TRANSPORT_PUSH_ALL) && (flags & TRANSPORT_PUSH_MIRROR))
695 die(_("options '%s' and '%s' cannot be used together"), "--all", "--mirror");
697 if (!is_empty_cas(&cas) && (flags & TRANSPORT_PUSH_FORCE_IF_INCLUDES))
698 cas.use_force_if_includes = 1;
700 for_each_string_list_item(item, push_options)
701 if (strchr(item->string, '\n'))
702 die(_("push options must not have new line characters"));
704 rc = do_push(flags, push_options, remote);
705 string_list_clear(&push_options_cmdline, 0);
706 string_list_clear(&push_options_config, 0);
707 if (rc == -1)
708 usage_with_options(push_usage, options);
709 else
710 return rc;