Git fork
at reftables-rust 672 lines 21 kB view raw
1/* 2 * "git push" 3 */ 4 5#define USE_THE_REPOSITORY_VARIABLE 6 7#include "builtin.h" 8#include "advice.h" 9#include "branch.h" 10#include "config.h" 11#include "environment.h" 12#include "gettext.h" 13#include "refspec.h" 14#include "run-command.h" 15#include "remote.h" 16#include "transport.h" 17#include "parse-options.h" 18#include "pkt-line.h" 19#include "submodule.h" 20#include "submodule-config.h" 21#include "send-pack.h" 22#include "trace2.h" 23#include "color.h" 24 25static const char * const push_usage[] = { 26 N_("git push [<options>] [<repository> [<refspec>...]]"), 27 NULL, 28}; 29 30static enum git_colorbool push_use_color = GIT_COLOR_UNKNOWN; 31static char push_colors[][COLOR_MAXLEN] = { 32 GIT_COLOR_RESET, 33 GIT_COLOR_RED, /* ERROR */ 34}; 35 36enum color_push { 37 PUSH_COLOR_RESET = 0, 38 PUSH_COLOR_ERROR = 1 39}; 40 41static int parse_push_color_slot(const char *slot) 42{ 43 if (!strcasecmp(slot, "reset")) 44 return PUSH_COLOR_RESET; 45 if (!strcasecmp(slot, "error")) 46 return PUSH_COLOR_ERROR; 47 return -1; 48} 49 50static const char *push_get_color(enum color_push ix) 51{ 52 if (want_color_stderr(push_use_color)) 53 return push_colors[ix]; 54 return ""; 55} 56 57static int thin = 1; 58static int deleterefs; 59static const char *receivepack; 60static int verbosity; 61static int progress = -1; 62static int recurse_submodules = RECURSE_SUBMODULES_DEFAULT; 63static enum transport_family family; 64 65static struct push_cas_option cas; 66 67static struct refspec rs = REFSPEC_INIT_PUSH; 68 69static struct string_list push_options_config = STRING_LIST_INIT_DUP; 70 71static void refspec_append_mapped(struct refspec *refspec, const char *ref, 72 struct remote *remote, struct ref *matched) 73{ 74 const char *branch_name; 75 76 if (remote->push.nr) { 77 struct refspec_item query = { 78 .src = matched->name, 79 }; 80 81 if (!refspec_find_match(&remote->push, &query) && query.dst) { 82 refspec_appendf(refspec, "%s%s:%s", 83 query.force ? "+" : "", 84 query.src, query.dst); 85 free(query.dst); 86 return; 87 } 88 } 89 90 if (push_default == PUSH_DEFAULT_UPSTREAM && 91 skip_prefix(matched->name, "refs/heads/", &branch_name)) { 92 struct branch *branch = branch_get(branch_name); 93 if (branch->merge_nr == 1 && branch->merge[0]->src) { 94 refspec_appendf(refspec, "%s:%s", 95 ref, branch->merge[0]->src); 96 return; 97 } 98 } 99 100 refspec_append(refspec, ref); 101} 102 103static void set_refspecs(const char **refs, int nr, struct remote *remote) 104{ 105 struct ref *local_refs = NULL; 106 int i; 107 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 struct ref *matched = NULL; 124 125 /* lazily grab local_refs */ 126 if (!local_refs) 127 local_refs = get_local_heads(); 128 129 /* Does "ref" uniquely name our ref? */ 130 if (count_refspec_match(ref, local_refs, &matched) != 1) 131 refspec_append(&rs, ref); 132 else 133 refspec_append_mapped(&rs, ref, remote, matched); 134 } else 135 refspec_append(&rs, ref); 136 } 137 free_refs(local_refs); 138} 139 140static NORETURN void die_push_simple(struct branch *branch, 141 struct remote *remote) 142{ 143 /* 144 * There's no point in using shorten_unambiguous_ref here, 145 * as the ambiguity would be on the remote side, not what 146 * we have locally. Plus, this is supposed to be the simple 147 * mode. If the user is doing something crazy like setting 148 * upstream to a non-branch, we should probably be showing 149 * them the big ugly fully qualified ref. 150 */ 151 const char *advice_pushdefault_maybe = ""; 152 const char *advice_automergesimple_maybe = ""; 153 const char *short_upstream = branch->merge[0]->src; 154 155 skip_prefix(short_upstream, "refs/heads/", &short_upstream); 156 157 /* 158 * Don't show advice for people who explicitly set 159 * push.default. 160 */ 161 if (push_default == PUSH_DEFAULT_UNSPECIFIED) 162 advice_pushdefault_maybe = _("\n" 163 "To choose either option permanently, " 164 "see push.default in 'git help config'.\n"); 165 if (git_branch_track != BRANCH_TRACK_SIMPLE) 166 advice_automergesimple_maybe = _("\n" 167 "To avoid automatically configuring " 168 "an upstream branch when its name\n" 169 "won't match the local branch, see option " 170 "'simple' of branch.autoSetupMerge\n" 171 "in 'git help config'.\n"); 172 die(_("The upstream branch of your current branch does not match\n" 173 "the name of your current branch. To push to the upstream branch\n" 174 "on the remote, use\n" 175 "\n" 176 " git push %s HEAD:%s\n" 177 "\n" 178 "To push to the branch of the same name on the remote, use\n" 179 "\n" 180 " git push %s HEAD\n" 181 "%s%s"), 182 remote->name, short_upstream, 183 remote->name, advice_pushdefault_maybe, 184 advice_automergesimple_maybe); 185} 186 187static const char message_detached_head_die[] = 188 N_("You are not currently on a branch.\n" 189 "To push the history leading to the current (detached HEAD)\n" 190 "state now, use\n" 191 "\n" 192 " git push %s HEAD:<name-of-remote-branch>\n"); 193 194static const char *get_upstream_ref(int flags, struct branch *branch, const char *remote_name) 195{ 196 if (branch->merge_nr == 0 && (flags & TRANSPORT_PUSH_AUTO_UPSTREAM)) { 197 /* if missing, assume same; set_upstream will be defined later */ 198 return branch->refname; 199 } 200 201 if (!branch->merge_nr || !branch->merge || !branch->remote_name) { 202 const char *advice_autosetup_maybe = ""; 203 if (!(flags & TRANSPORT_PUSH_AUTO_UPSTREAM)) { 204 advice_autosetup_maybe = _("\n" 205 "To have this happen automatically for " 206 "branches without a tracking\n" 207 "upstream, see 'push.autoSetupRemote' " 208 "in 'git help config'.\n"); 209 } 210 die(_("The current branch %s has no upstream branch.\n" 211 "To push the current branch and set the remote as upstream, use\n" 212 "\n" 213 " git push --set-upstream %s %s\n" 214 "%s"), 215 branch->name, 216 remote_name, 217 branch->name, 218 advice_autosetup_maybe); 219 } 220 if (branch->merge_nr != 1) 221 die(_("The current branch %s has multiple upstream branches, " 222 "refusing to push."), branch->name); 223 224 return branch->merge[0]->src; 225} 226 227static void setup_default_push_refspecs(int *flags, struct remote *remote) 228{ 229 struct branch *branch; 230 const char *dst; 231 int same_remote; 232 233 switch (push_default) { 234 case PUSH_DEFAULT_MATCHING: 235 refspec_append(&rs, ":"); 236 return; 237 238 case PUSH_DEFAULT_NOTHING: 239 die(_("You didn't specify any refspecs to push, and " 240 "push.default is \"nothing\".")); 241 return; 242 default: 243 break; 244 } 245 246 branch = branch_get(NULL); 247 if (!branch) 248 die(_(message_detached_head_die), remote->name); 249 250 dst = branch->refname; 251 same_remote = !strcmp(remote->name, remote_for_branch(branch, NULL)); 252 253 switch (push_default) { 254 default: 255 case PUSH_DEFAULT_UNSPECIFIED: 256 case PUSH_DEFAULT_SIMPLE: 257 if (!same_remote) 258 break; 259 if (strcmp(branch->refname, get_upstream_ref(*flags, branch, remote->name))) 260 die_push_simple(branch, remote); 261 break; 262 263 case PUSH_DEFAULT_UPSTREAM: 264 if (!same_remote) 265 die(_("You are pushing to remote '%s', which is not the upstream of\n" 266 "your current branch '%s', without telling me what to push\n" 267 "to update which remote branch."), 268 remote->name, branch->name); 269 dst = get_upstream_ref(*flags, branch, remote->name); 270 break; 271 272 case PUSH_DEFAULT_CURRENT: 273 break; 274 } 275 276 /* 277 * this is a default push - if auto-upstream is enabled and there is 278 * no upstream defined, then set it (with options 'simple', 'upstream', 279 * and 'current'). 280 */ 281 if ((*flags & TRANSPORT_PUSH_AUTO_UPSTREAM) && branch->merge_nr == 0) 282 *flags |= TRANSPORT_PUSH_SET_UPSTREAM; 283 284 refspec_appendf(&rs, "%s:%s", branch->refname, dst); 285} 286 287static const char message_advice_pull_before_push[] = 288 N_("Updates were rejected because the tip of your current branch is behind\n" 289 "its remote counterpart. If you want to integrate the remote changes,\n" 290 "use 'git pull' before pushing again.\n" 291 "See the 'Note about fast-forwards' in 'git push --help' for details."); 292 293static const char message_advice_checkout_pull_push[] = 294 N_("Updates were rejected because a pushed branch tip is behind its remote\n" 295 "counterpart. If you want to integrate the remote changes, use 'git pull'\n" 296 "before pushing again.\n" 297 "See the 'Note about fast-forwards' in 'git push --help' for details."); 298 299static const char message_advice_ref_fetch_first[] = 300 N_("Updates were rejected because the remote contains work that you do not\n" 301 "have locally. This is usually caused by another repository pushing to\n" 302 "the same ref. If you want to integrate the remote changes, use\n" 303 "'git pull' before pushing again.\n" 304 "See the 'Note about fast-forwards' in 'git push --help' for details."); 305 306static const char message_advice_ref_already_exists[] = 307 N_("Updates were rejected because the tag already exists in the remote."); 308 309static const char message_advice_ref_needs_force[] = 310 N_("You cannot update a remote ref that points at a non-commit object,\n" 311 "or update a remote ref to make it point at a non-commit object,\n" 312 "without using the '--force' option.\n"); 313 314static const char message_advice_ref_needs_update[] = 315 N_("Updates were rejected because the tip of the remote-tracking branch has\n" 316 "been updated since the last checkout. If you want to integrate the\n" 317 "remote changes, use 'git pull' before pushing again.\n" 318 "See the 'Note about fast-forwards' in 'git push --help' for details."); 319 320static void advise_pull_before_push(void) 321{ 322 if (!advice_enabled(ADVICE_PUSH_NON_FF_CURRENT) || !advice_enabled(ADVICE_PUSH_UPDATE_REJECTED)) 323 return; 324 advise(_(message_advice_pull_before_push)); 325} 326 327static void advise_checkout_pull_push(void) 328{ 329 if (!advice_enabled(ADVICE_PUSH_NON_FF_MATCHING) || !advice_enabled(ADVICE_PUSH_UPDATE_REJECTED)) 330 return; 331 advise(_(message_advice_checkout_pull_push)); 332} 333 334static void advise_ref_already_exists(void) 335{ 336 if (!advice_enabled(ADVICE_PUSH_ALREADY_EXISTS) || !advice_enabled(ADVICE_PUSH_UPDATE_REJECTED)) 337 return; 338 advise(_(message_advice_ref_already_exists)); 339} 340 341static void advise_ref_fetch_first(void) 342{ 343 if (!advice_enabled(ADVICE_PUSH_FETCH_FIRST) || !advice_enabled(ADVICE_PUSH_UPDATE_REJECTED)) 344 return; 345 advise(_(message_advice_ref_fetch_first)); 346} 347 348static void advise_ref_needs_force(void) 349{ 350 if (!advice_enabled(ADVICE_PUSH_NEEDS_FORCE) || !advice_enabled(ADVICE_PUSH_UPDATE_REJECTED)) 351 return; 352 advise(_(message_advice_ref_needs_force)); 353} 354 355static void advise_ref_needs_update(void) 356{ 357 if (!advice_enabled(ADVICE_PUSH_REF_NEEDS_UPDATE) || !advice_enabled(ADVICE_PUSH_UPDATE_REJECTED)) 358 return; 359 advise(_(message_advice_ref_needs_update)); 360} 361 362static int push_with_options(struct transport *transport, struct refspec *rs, 363 int flags) 364{ 365 int err; 366 unsigned int reject_reasons; 367 char *anon_url = transport_anonymize_url(transport->url); 368 369 transport_set_verbosity(transport, verbosity, progress); 370 transport->family = family; 371 372 if (receivepack) 373 transport_set_option(transport, 374 TRANS_OPT_RECEIVEPACK, receivepack); 375 transport_set_option(transport, TRANS_OPT_THIN, thin ? "yes" : NULL); 376 377 if (!is_empty_cas(&cas)) { 378 if (!transport->smart_options) 379 die("underlying transport does not support --%s option", 380 "force-with-lease"); 381 transport->smart_options->cas = &cas; 382 } 383 384 if (verbosity > 0) 385 fprintf(stderr, _("Pushing to %s\n"), anon_url); 386 trace2_region_enter("push", "transport_push", the_repository); 387 err = transport_push(the_repository, transport, 388 rs, flags, &reject_reasons); 389 trace2_region_leave("push", "transport_push", the_repository); 390 if (err != 0) { 391 fprintf(stderr, "%s", push_get_color(PUSH_COLOR_ERROR)); 392 error(_("failed to push some refs to '%s'"), anon_url); 393 fprintf(stderr, "%s", push_get_color(PUSH_COLOR_RESET)); 394 } 395 396 err |= transport_disconnect(transport); 397 free(anon_url); 398 if (!err) 399 return 0; 400 401 if (reject_reasons & REJECT_NON_FF_HEAD) { 402 advise_pull_before_push(); 403 } else if (reject_reasons & REJECT_NON_FF_OTHER) { 404 advise_checkout_pull_push(); 405 } else if (reject_reasons & REJECT_ALREADY_EXISTS) { 406 advise_ref_already_exists(); 407 } else if (reject_reasons & REJECT_FETCH_FIRST) { 408 advise_ref_fetch_first(); 409 } else if (reject_reasons & REJECT_NEEDS_FORCE) { 410 advise_ref_needs_force(); 411 } else if (reject_reasons & REJECT_REF_NEEDS_UPDATE) { 412 advise_ref_needs_update(); 413 } 414 415 return 1; 416} 417 418static int do_push(int flags, 419 const struct string_list *push_options, 420 struct remote *remote) 421{ 422 int errs; 423 struct strvec *url; 424 struct refspec *push_refspec = &rs; 425 426 if (push_options->nr) 427 flags |= TRANSPORT_PUSH_OPTIONS; 428 429 if (!push_refspec->nr && !(flags & TRANSPORT_PUSH_ALL)) { 430 if (remote->push.nr) { 431 push_refspec = &remote->push; 432 } else if (!(flags & TRANSPORT_PUSH_MIRROR)) 433 setup_default_push_refspecs(&flags, remote); 434 } 435 errs = 0; 436 url = push_url_of_remote(remote); 437 for (size_t i = 0; i < url->nr; i++) { 438 struct transport *transport = 439 transport_get(remote, url->v[i]); 440 if (flags & TRANSPORT_PUSH_OPTIONS) 441 transport->push_options = push_options; 442 if (push_with_options(transport, push_refspec, flags)) 443 errs++; 444 } 445 return !!errs; 446} 447 448static int option_parse_recurse_submodules(const struct option *opt, 449 const char *arg, int unset) 450{ 451 int *recurse_submodules = opt->value; 452 453 if (unset) 454 *recurse_submodules = RECURSE_SUBMODULES_OFF; 455 else { 456 if (!strcmp(arg, "only-is-on-demand")) { 457 if (*recurse_submodules == RECURSE_SUBMODULES_ONLY) { 458 warning(_("recursing into submodule with push.recurseSubmodules=only; using on-demand instead")); 459 *recurse_submodules = RECURSE_SUBMODULES_ON_DEMAND; 460 } 461 } else { 462 *recurse_submodules = parse_push_recurse_submodules_arg(opt->long_name, arg); 463 } 464 } 465 466 return 0; 467} 468 469static void set_push_cert_flags(int *flags, int v) 470{ 471 switch (v) { 472 case SEND_PACK_PUSH_CERT_NEVER: 473 *flags &= ~(TRANSPORT_PUSH_CERT_ALWAYS | TRANSPORT_PUSH_CERT_IF_ASKED); 474 break; 475 case SEND_PACK_PUSH_CERT_ALWAYS: 476 *flags |= TRANSPORT_PUSH_CERT_ALWAYS; 477 *flags &= ~TRANSPORT_PUSH_CERT_IF_ASKED; 478 break; 479 case SEND_PACK_PUSH_CERT_IF_ASKED: 480 *flags |= TRANSPORT_PUSH_CERT_IF_ASKED; 481 *flags &= ~TRANSPORT_PUSH_CERT_ALWAYS; 482 break; 483 } 484} 485 486 487static int git_push_config(const char *k, const char *v, 488 const struct config_context *ctx, void *cb) 489{ 490 const char *slot_name; 491 int *flags = cb; 492 493 if (!strcmp(k, "push.followtags")) { 494 if (git_config_bool(k, v)) 495 *flags |= TRANSPORT_PUSH_FOLLOW_TAGS; 496 else 497 *flags &= ~TRANSPORT_PUSH_FOLLOW_TAGS; 498 return 0; 499 } else if (!strcmp(k, "push.autosetupremote")) { 500 if (git_config_bool(k, v)) 501 *flags |= TRANSPORT_PUSH_AUTO_UPSTREAM; 502 return 0; 503 } else if (!strcmp(k, "push.gpgsign")) { 504 switch (git_parse_maybe_bool(v)) { 505 case 0: 506 set_push_cert_flags(flags, SEND_PACK_PUSH_CERT_NEVER); 507 break; 508 case 1: 509 set_push_cert_flags(flags, SEND_PACK_PUSH_CERT_ALWAYS); 510 break; 511 default: 512 if (!strcasecmp(v, "if-asked")) 513 set_push_cert_flags(flags, SEND_PACK_PUSH_CERT_IF_ASKED); 514 else 515 return error(_("invalid value for '%s'"), k); 516 } 517 } else if (!strcmp(k, "push.recursesubmodules")) { 518 recurse_submodules = parse_push_recurse_submodules_arg(k, v); 519 } else if (!strcmp(k, "submodule.recurse")) { 520 int val = git_config_bool(k, v) ? 521 RECURSE_SUBMODULES_ON_DEMAND : RECURSE_SUBMODULES_OFF; 522 recurse_submodules = val; 523 } else if (!strcmp(k, "push.pushoption")) { 524 return parse_transport_option(k, v, &push_options_config); 525 } else if (!strcmp(k, "color.push")) { 526 push_use_color = git_config_colorbool(k, v); 527 return 0; 528 } else if (skip_prefix(k, "color.push.", &slot_name)) { 529 int slot = parse_push_color_slot(slot_name); 530 if (slot < 0) 531 return 0; 532 if (!v) 533 return config_error_nonbool(k); 534 return color_parse(v, push_colors[slot]); 535 } else if (!strcmp(k, "push.useforceifincludes")) { 536 if (git_config_bool(k, v)) 537 *flags |= TRANSPORT_PUSH_FORCE_IF_INCLUDES; 538 else 539 *flags &= ~TRANSPORT_PUSH_FORCE_IF_INCLUDES; 540 return 0; 541 } 542 543 return git_default_config(k, v, ctx, NULL); 544} 545 546int cmd_push(int argc, 547 const char **argv, 548 const char *prefix, 549 struct repository *repository UNUSED) 550{ 551 int flags = 0; 552 int tags = 0; 553 int push_cert = -1; 554 int rc; 555 const char *repo = NULL; /* default repository */ 556 struct string_list push_options_cmdline = STRING_LIST_INIT_DUP; 557 struct string_list *push_options; 558 const struct string_list_item *item; 559 struct remote *remote; 560 561 struct option options[] = { 562 OPT__VERBOSITY(&verbosity), 563 OPT_STRING( 0 , "repo", &repo, N_("repository"), N_("repository")), 564 OPT_BIT( 0 , "all", &flags, N_("push all branches"), TRANSPORT_PUSH_ALL), 565 OPT_ALIAS( 0 , "branches", "all"), 566 OPT_BIT( 0 , "mirror", &flags, N_("mirror all refs"), 567 (TRANSPORT_PUSH_MIRROR|TRANSPORT_PUSH_FORCE)), 568 OPT_BOOL('d', "delete", &deleterefs, N_("delete refs")), 569 OPT_BOOL( 0 , "tags", &tags, N_("push tags (can't be used with --all or --branches or --mirror)")), 570 OPT_BIT('n' , "dry-run", &flags, N_("dry run"), TRANSPORT_PUSH_DRY_RUN), 571 OPT_BIT( 0, "porcelain", &flags, N_("machine-readable output"), TRANSPORT_PUSH_PORCELAIN), 572 OPT_BIT('f', "force", &flags, N_("force updates"), TRANSPORT_PUSH_FORCE), 573 OPT_CALLBACK_F(0, "force-with-lease", &cas, N_("<refname>:<expect>"), 574 N_("require old value of ref to be at this value"), 575 PARSE_OPT_OPTARG | PARSE_OPT_LITERAL_ARGHELP, parseopt_push_cas_option), 576 OPT_BIT(0, TRANS_OPT_FORCE_IF_INCLUDES, &flags, 577 N_("require remote updates to be integrated locally"), 578 TRANSPORT_PUSH_FORCE_IF_INCLUDES), 579 OPT_CALLBACK(0, "recurse-submodules", &recurse_submodules, "(check|on-demand|no)", 580 N_("control recursive pushing of submodules"), option_parse_recurse_submodules), 581 OPT_BOOL_F( 0 , "thin", &thin, N_("use thin pack"), PARSE_OPT_NOCOMPLETE), 582 OPT_STRING( 0 , "receive-pack", &receivepack, "receive-pack", N_("receive pack program")), 583 OPT_STRING( 0 , "exec", &receivepack, "receive-pack", N_("receive pack program")), 584 OPT_BIT('u', "set-upstream", &flags, N_("set upstream for git pull/status"), 585 TRANSPORT_PUSH_SET_UPSTREAM), 586 OPT_BOOL(0, "progress", &progress, N_("force progress reporting")), 587 OPT_BIT(0, "prune", &flags, N_("prune locally removed refs"), 588 TRANSPORT_PUSH_PRUNE), 589 OPT_BIT(0, "no-verify", &flags, N_("bypass pre-push hook"), TRANSPORT_PUSH_NO_HOOK), 590 OPT_BIT(0, "follow-tags", &flags, N_("push missing but relevant tags"), 591 TRANSPORT_PUSH_FOLLOW_TAGS), 592 OPT_CALLBACK_F(0, "signed", &push_cert, "(yes|no|if-asked)", N_("GPG sign the push"), 593 PARSE_OPT_OPTARG, option_parse_push_signed), 594 OPT_BIT(0, "atomic", &flags, N_("request atomic transaction on remote side"), TRANSPORT_PUSH_ATOMIC), 595 OPT_STRING_LIST('o', "push-option", &push_options_cmdline, N_("server-specific"), N_("option to transmit")), 596 OPT_IPVERSION(&family), 597 OPT_END() 598 }; 599 600 packet_trace_identity("push"); 601 repo_config(the_repository, git_push_config, &flags); 602 argc = parse_options(argc, argv, prefix, options, push_usage, 0); 603 push_options = (push_options_cmdline.nr 604 ? &push_options_cmdline 605 : &push_options_config); 606 set_push_cert_flags(&flags, push_cert); 607 608 die_for_incompatible_opt4(deleterefs, "--delete", 609 tags, "--tags", 610 flags & TRANSPORT_PUSH_ALL, "--all/--branches", 611 flags & TRANSPORT_PUSH_MIRROR, "--mirror"); 612 if (deleterefs && argc < 2) 613 die(_("--delete doesn't make sense without any refs")); 614 615 if (recurse_submodules == RECURSE_SUBMODULES_CHECK) 616 flags |= TRANSPORT_RECURSE_SUBMODULES_CHECK; 617 else if (recurse_submodules == RECURSE_SUBMODULES_ON_DEMAND) 618 flags |= TRANSPORT_RECURSE_SUBMODULES_ON_DEMAND; 619 else if (recurse_submodules == RECURSE_SUBMODULES_ONLY) 620 flags |= TRANSPORT_RECURSE_SUBMODULES_ONLY; 621 622 if (tags) 623 refspec_append(&rs, "refs/tags/*"); 624 625 if (argc > 0) 626 repo = argv[0]; 627 628 remote = pushremote_get(repo); 629 if (!remote) { 630 if (repo) 631 die(_("bad repository '%s'"), repo); 632 die(_("No configured push destination.\n" 633 "Either specify the URL from the command-line or configure a remote repository using\n" 634 "\n" 635 " git remote add <name> <url>\n" 636 "\n" 637 "and then push using the remote name\n" 638 "\n" 639 " git push <name>\n")); 640 } 641 642 if (argc > 0) 643 set_refspecs(argv + 1, argc - 1, remote); 644 645 if (remote->mirror) 646 flags |= (TRANSPORT_PUSH_MIRROR|TRANSPORT_PUSH_FORCE); 647 648 if (flags & TRANSPORT_PUSH_ALL) { 649 if (argc >= 2) 650 die(_("--all can't be combined with refspecs")); 651 } 652 if (flags & TRANSPORT_PUSH_MIRROR) { 653 if (argc >= 2) 654 die(_("--mirror can't be combined with refspecs")); 655 } 656 657 if (!is_empty_cas(&cas) && (flags & TRANSPORT_PUSH_FORCE_IF_INCLUDES)) 658 cas.use_force_if_includes = 1; 659 660 for_each_string_list_item(item, push_options) 661 if (strchr(item->string, '\n')) 662 die(_("push options must not have new line characters")); 663 664 rc = do_push(flags, push_options, remote); 665 string_list_clear(&push_options_cmdline, 0); 666 string_list_clear(&push_options_config, 0); 667 clear_cas_option(&cas); 668 if (rc == -1) 669 usage_with_options(push_usage, options); 670 else 671 return rc; 672}