push.c 17.7 KB
Newer Older
Linus Torvalds's avatar
Linus Torvalds committed
1 2 3 4 5 6 7
/*
 * "git push"
 */
#include "cache.h"
#include "refs.h"
#include "run-command.h"
#include "builtin.h"
8
#include "remote.h"
9
#include "transport.h"
10
#include "parse-options.h"
11
#include "submodule.h"
12
#include "submodule-config.h"
13
#include "send-pack.h"
Linus Torvalds's avatar
Linus Torvalds committed
14

15
static const char * const push_usage[] = {
16
	N_("git push [<options>] [<repository> [<refspec>...]]"),
17 18
	NULL,
};
Linus Torvalds's avatar
Linus Torvalds committed
19

Duy Nguyen's avatar
Duy Nguyen committed
20
static int thin = 1;
21
static int deleterefs;
22
static const char *receivepack;
23
static int verbosity;
24 25
static int progress = -1;
static int recurse_submodules = RECURSE_SUBMODULES_DEFAULT;
26
static enum transport_family family;
Linus Torvalds's avatar
Linus Torvalds committed
27

28 29
static struct push_cas_option cas;

30 31
static const char **refspec;
static int refspec_nr;
32
static int refspec_alloc;
Linus Torvalds's avatar
Linus Torvalds committed
33 34 35

static void add_refspec(const char *ref)
{
36 37 38
	refspec_nr++;
	ALLOC_GROW(refspec, refspec_nr, refspec_alloc);
	refspec[refspec_nr-1] = ref;
Linus Torvalds's avatar
Linus Torvalds committed
39 40
}

41 42
static const char *map_refspec(const char *ref,
			       struct remote *remote, struct ref *local_refs)
Linus Torvalds's avatar
Linus Torvalds committed
43
{
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
	struct ref *matched = NULL;

	/* Does "ref" uniquely name our ref? */
	if (count_refspec_match(ref, local_refs, &matched) != 1)
		return ref;

	if (remote->push) {
		struct refspec query;
		memset(&query, 0, sizeof(struct refspec));
		query.src = matched->name;
		if (!query_refspecs(remote->push, remote->push_refspec_nr, &query) &&
		    query.dst) {
			struct strbuf buf = STRBUF_INIT;
			strbuf_addf(&buf, "%s%s:%s",
				    query.force ? "+" : "",
				    query.src, query.dst);
			return strbuf_detach(&buf, NULL);
		}
	}

64
	if (push_default == PUSH_DEFAULT_UPSTREAM &&
65
	    starts_with(matched->name, "refs/heads/")) {
66 67 68 69 70 71 72 73 74
		struct branch *branch = branch_get(matched->name + 11);
		if (branch->merge_nr == 1 && branch->merge[0]->src) {
			struct strbuf buf = STRBUF_INIT;
			strbuf_addf(&buf, "%s:%s",
				    ref, branch->merge[0]->src);
			return strbuf_detach(&buf, NULL);
		}
	}

75 76 77 78 79 80 81
	return ref;
}

static void set_refspecs(const char **refs, int nr, const char *repo)
{
	struct remote *remote = NULL;
	struct ref *local_refs = NULL;
82
	int i;
83

84 85 86
	for (i = 0; i < nr; i++) {
		const char *ref = refs[i];
		if (!strcmp("tag", ref)) {
87
			struct strbuf tagref = STRBUF_INIT;
88
			if (nr <= ++i)
89
				die(_("tag shorthand without <tag>"));
90 91 92 93 94 95 96 97 98 99 100 101
			ref = refs[i];
			if (deleterefs)
				strbuf_addf(&tagref, ":refs/tags/%s", ref);
			else
				strbuf_addf(&tagref, "refs/tags/%s", ref);
			ref = strbuf_detach(&tagref, NULL);
		} else if (deleterefs) {
			struct strbuf delref = STRBUF_INIT;
			if (strchr(ref, ':'))
				die(_("--delete only accepts plain target ref names"));
			strbuf_addf(&delref, ":%s", ref);
			ref = strbuf_detach(&delref, NULL);
102 103 104 105 106
		} else if (!strchr(ref, ':')) {
			if (!remote) {
				/* lazily grab remote and local_refs */
				remote = remote_get(repo);
				local_refs = get_local_heads();
107
			}
108
			ref = map_refspec(ref, remote, local_refs);
109
		}
110
		add_refspec(ref);
Linus Torvalds's avatar
Linus Torvalds committed
111 112 113
	}
}

114 115 116 117 118 119 120 121 122 123
static int push_url_of_remote(struct remote *remote, const char ***url_p)
{
	if (remote->pushurl_nr) {
		*url_p = remote->pushurl;
		return remote->pushurl_nr;
	}
	*url_p = remote->url;
	return remote->url_nr;
}

124 125 126 127 128 129 130 131 132 133
static NORETURN int die_push_simple(struct branch *branch, struct remote *remote) {
	/*
	 * There's no point in using shorten_unambiguous_ref here,
	 * as the ambiguity would be on the remote side, not what
	 * we have locally. Plus, this is supposed to be the simple
	 * mode. If the user is doing something crazy like setting
	 * upstream to a non-branch, we should probably be showing
	 * them the big ugly fully qualified ref.
	 */
	const char *advice_maybe = "";
134 135 136
	const char *short_upstream = branch->merge[0]->src;

	skip_prefix(short_upstream, "refs/heads/", &short_upstream);
137 138

	/*
Ondřej Bílka's avatar
Ondřej Bílka committed
139
	 * Don't show advice for people who explicitly set
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
	 * push.default.
	 */
	if (push_default == PUSH_DEFAULT_UNSPECIFIED)
		advice_maybe = _("\n"
				 "To choose either option permanently, "
				 "see push.default in 'git help config'.");
	die(_("The upstream branch of your current branch does not match\n"
	      "the name of your current branch.  To push to the upstream branch\n"
	      "on the remote, use\n"
	      "\n"
	      "    git push %s HEAD:%s\n"
	      "\n"
	      "To push to the branch of the same name on the remote, use\n"
	      "\n"
	      "    git push %s %s\n"
	      "%s"),
	    remote->name, short_upstream,
	    remote->name, branch->name, advice_maybe);
}

160 161 162 163 164 165 166
static const char message_detached_head_die[] =
	N_("You are not currently on a branch.\n"
	   "To push the history leading to the current (detached HEAD)\n"
	   "state now, use\n"
	   "\n"
	   "    git push %s HEAD:<name-of-remote-branch>\n");

167
static void setup_push_upstream(struct remote *remote, struct branch *branch,
168
				int triangular, int simple)
169 170
{
	struct strbuf refspec = STRBUF_INIT;
171

172
	if (!branch)
173
		die(_(message_detached_head_die), remote->name);
174
	if (!branch->merge_nr || !branch->merge || !branch->remote_name)
Junio C Hamano's avatar
Junio C Hamano committed
175
		die(_("The current branch %s has no upstream branch.\n"
176 177
		    "To push the current branch and set the remote as upstream, use\n"
		    "\n"
Junio C Hamano's avatar
Junio C Hamano committed
178
		    "    git push --set-upstream %s %s\n"),
179 180
		    branch->name,
		    remote->name,
181 182
		    branch->name);
	if (branch->merge_nr != 1)
Junio C Hamano's avatar
Junio C Hamano committed
183
		die(_("The current branch %s has multiple upstream branches, "
184
		    "refusing to push."), branch->name);
185
	if (triangular)
186 187 188 189
		die(_("You are pushing to remote '%s', which is not the upstream of\n"
		      "your current branch '%s', without telling me what to push\n"
		      "to update which remote branch."),
		    remote->name, branch->name);
190

191
	if (simple) {
192 193 194 195
		/* Additional safety */
		if (strcmp(branch->refname, branch->merge[0]->src))
			die_push_simple(branch, remote);
	}
196

197
	strbuf_addf(&refspec, "%s:%s", branch->refname, branch->merge[0]->src);
198 199 200
	add_refspec(refspec.buf);
}

201 202
static void setup_push_current(struct remote *remote, struct branch *branch)
{
203 204
	struct strbuf refspec = STRBUF_INIT;

205 206
	if (!branch)
		die(_(message_detached_head_die), remote->name);
207 208
	strbuf_addf(&refspec, "%s:%s", branch->refname, branch->refname);
	add_refspec(refspec.buf);
209 210 211 212 213 214 215 216
}

static int is_workflow_triangular(struct remote *remote)
{
	struct remote *fetch_remote = remote_get(NULL);
	return (fetch_remote && fetch_remote != remote);
}

217
static void setup_default_push_refspecs(struct remote *remote)
218
{
219 220
	struct branch *branch = branch_get(NULL);
	int triangular = is_workflow_triangular(remote);
221

222
	switch (push_default) {
223
	default:
224 225 226 227
	case PUSH_DEFAULT_MATCHING:
		add_refspec(":");
		break;

228
	case PUSH_DEFAULT_UNSPECIFIED:
229
	case PUSH_DEFAULT_SIMPLE:
230 231 232
		if (triangular)
			setup_push_current(remote, branch);
		else
233
			setup_push_upstream(remote, branch, triangular, 1);
234 235
		break;

236
	case PUSH_DEFAULT_UPSTREAM:
237
		setup_push_upstream(remote, branch, triangular, 0);
238 239 240
		break;

	case PUSH_DEFAULT_CURRENT:
241
		setup_push_current(remote, branch);
242 243 244
		break;

	case PUSH_DEFAULT_NOTHING:
245 246
		die(_("You didn't specify any refspecs to push, and "
		    "push.default is \"nothing\"."));
247 248 249 250
		break;
	}
}

251 252
static const char message_advice_pull_before_push[] =
	N_("Updates were rejected because the tip of your current branch is behind\n"
253 254
	   "its remote counterpart. Integrate the remote changes (e.g.\n"
	   "'git pull ...') before pushing again.\n"
255 256 257 258
	   "See the 'Note about fast-forwards' in 'git push --help' for details.");

static const char message_advice_checkout_pull_push[] =
	N_("Updates were rejected because a pushed branch tip is behind its remote\n"
259 260
	   "counterpart. Check out this branch and integrate the remote changes\n"
	   "(e.g. 'git pull ...') before pushing again.\n"
261 262
	   "See the 'Note about fast-forwards' in 'git push --help' for details.");

263 264 265
static const char message_advice_ref_fetch_first[] =
	N_("Updates were rejected because the remote contains work that you do\n"
	   "not have locally. This is usually caused by another repository pushing\n"
266 267
	   "to the same ref. You may want to first integrate the remote changes\n"
	   "(e.g., 'git pull ...') before pushing again.\n"
268 269
	   "See the 'Note about fast-forwards' in 'git push --help' for details.");

270
static const char message_advice_ref_already_exists[] =
271
	N_("Updates were rejected because the tag already exists in the remote.");
272

273 274 275 276
static const char message_advice_ref_needs_force[] =
	N_("You cannot update a remote ref that points at a non-commit object,\n"
	   "or update a remote ref to make it point at a non-commit object,\n"
	   "without using the '--force' option.\n");
277

278 279
static void advise_pull_before_push(void)
{
280
	if (!advice_push_non_ff_current || !advice_push_update_rejected)
281 282 283 284 285 286
		return;
	advise(_(message_advice_pull_before_push));
}

static void advise_checkout_pull_push(void)
{
287
	if (!advice_push_non_ff_matching || !advice_push_update_rejected)
288 289 290 291
		return;
	advise(_(message_advice_checkout_pull_push));
}

292 293
static void advise_ref_already_exists(void)
{
294 295
	if (!advice_push_already_exists || !advice_push_update_rejected)
		return;
296 297 298
	advise(_(message_advice_ref_already_exists));
}

299 300 301 302 303 304 305 306 307 308 309 310 311 312
static void advise_ref_fetch_first(void)
{
	if (!advice_push_fetch_first || !advice_push_update_rejected)
		return;
	advise(_(message_advice_ref_fetch_first));
}

static void advise_ref_needs_force(void)
{
	if (!advice_push_needs_force || !advice_push_update_rejected)
		return;
	advise(_(message_advice_ref_needs_force));
}

313 314 315
static int push_with_options(struct transport *transport, int flags)
{
	int err;
316
	unsigned int reject_reasons;
317

Ray's avatar
Ray committed
318
	transport_set_verbosity(transport, verbosity, progress);
319
	transport->family = family;
320

321 322 323
	if (receivepack)
		transport_set_option(transport,
				     TRANS_OPT_RECEIVEPACK, receivepack);
Duy Nguyen's avatar
Duy Nguyen committed
324
	transport_set_option(transport, TRANS_OPT_THIN, thin ? "yes" : NULL);
325

326 327 328 329 330 331 332
	if (!is_empty_cas(&cas)) {
		if (!transport->smart_options)
			die("underlying transport does not support --%s option",
			    CAS_OPT_NAME);
		transport->smart_options->cas = &cas;
	}

333
	if (verbosity > 0)
334
		fprintf(stderr, _("Pushing to %s\n"), transport->url);
335
	err = transport_push(transport, refspec_nr, refspec, flags,
336
			     &reject_reasons);
337
	if (err != 0)
338
		error(_("failed to push some refs to '%s'"), transport->url);
339

340 341 342 343
	err |= transport_disconnect(transport);
	if (!err)
		return 0;

344
	if (reject_reasons & REJECT_NON_FF_HEAD) {
345
		advise_pull_before_push();
346
	} else if (reject_reasons & REJECT_NON_FF_OTHER) {
347
		advise_checkout_pull_push();
348 349
	} else if (reject_reasons & REJECT_ALREADY_EXISTS) {
		advise_ref_already_exists();
350 351 352 353
	} else if (reject_reasons & REJECT_FETCH_FIRST) {
		advise_ref_fetch_first();
	} else if (reject_reasons & REJECT_NEEDS_FORCE) {
		advise_ref_needs_force();
354 355 356 357 358
	}

	return 1;
}

Stefan Beller's avatar
Stefan Beller committed
359 360
static int do_push(const char *repo, int flags,
		   const struct string_list *push_options)
Linus Torvalds's avatar
Linus Torvalds committed
361
{
362
	int i, errs;
363
	struct remote *remote = pushremote_get(repo);
364 365
	const char **url;
	int url_nr;
Linus Torvalds's avatar
Linus Torvalds committed
366

367 368
	if (!remote) {
		if (repo)
369
			die(_("bad repository '%s'"), repo);
Junio C Hamano's avatar
Junio C Hamano committed
370
		die(_("No configured push destination.\n"
371 372 373 374 375 376
		    "Either specify the URL from the command-line or configure a remote repository using\n"
		    "\n"
		    "    git remote add <name> <url>\n"
		    "\n"
		    "and then push using the remote name\n"
		    "\n"
Junio C Hamano's avatar
Junio C Hamano committed
377
		    "    git push <name>\n"));
378
	}
Linus Torvalds's avatar
Linus Torvalds committed
379

380 381 382
	if (remote->mirror)
		flags |= (TRANSPORT_PUSH_MIRROR|TRANSPORT_PUSH_FORCE);

Stefan Beller's avatar
Stefan Beller committed
383 384 385
	if (push_options->nr)
		flags |= TRANSPORT_PUSH_OPTIONS;

386 387
	if ((flags & TRANSPORT_PUSH_ALL) && refspec) {
		if (!strcmp(*refspec, "refs/tags/*"))
388 389
			return error(_("--all and --tags are incompatible"));
		return error(_("--all can't be combined with refspecs"));
390 391 392 393
	}

	if ((flags & TRANSPORT_PUSH_MIRROR) && refspec) {
		if (!strcmp(*refspec, "refs/tags/*"))
394 395
			return error(_("--mirror and --tags are incompatible"));
		return error(_("--mirror can't be combined with refspecs"));
396
	}
397 398 399

	if ((flags & (TRANSPORT_PUSH_ALL|TRANSPORT_PUSH_MIRROR)) ==
				(TRANSPORT_PUSH_ALL|TRANSPORT_PUSH_MIRROR)) {
400
		return error(_("--all and --mirror are incompatible"));
401 402
	}

403 404 405 406 407
	if (!refspec && !(flags & TRANSPORT_PUSH_ALL)) {
		if (remote->push_refspec_nr) {
			refspec = remote->push_refspec;
			refspec_nr = remote->push_refspec_nr;
		} else if (!(flags & TRANSPORT_PUSH_MIRROR))
408
			setup_default_push_refspecs(remote);
409
	}
410
	errs = 0;
411
	url_nr = push_url_of_remote(remote, &url);
412 413 414 415
	if (url_nr) {
		for (i = 0; i < url_nr; i++) {
			struct transport *transport =
				transport_get(remote, url[i]);
Stefan Beller's avatar
Stefan Beller committed
416 417
			if (flags & TRANSPORT_PUSH_OPTIONS)
				transport->push_options = push_options;
418 419
			if (push_with_options(transport, flags))
				errs++;
420
		}
421 422 423
	} else {
		struct transport *transport =
			transport_get(remote, NULL);
Stefan Beller's avatar
Stefan Beller committed
424 425
		if (flags & TRANSPORT_PUSH_OPTIONS)
			transport->push_options = push_options;
426 427
		if (push_with_options(transport, flags))
			errs++;
Linus Torvalds's avatar
Linus Torvalds committed
428
	}
429
	return !!errs;
Linus Torvalds's avatar
Linus Torvalds committed
430 431
}

432 433 434
static int option_parse_recurse_submodules(const struct option *opt,
				   const char *arg, int unset)
{
435
	int *recurse_submodules = opt->value;
436

437 438 439 440 441 442
	if (unset)
		*recurse_submodules = RECURSE_SUBMODULES_OFF;
	else if (arg)
		*recurse_submodules = parse_push_recurse_submodules_arg(opt->long_name, arg);
	else
		die("%s missing parameter", opt->long_name);
443 444 445 446

	return 0;
}

447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464
static void set_push_cert_flags(int *flags, int v)
{
	switch (v) {
	case SEND_PACK_PUSH_CERT_NEVER:
		*flags &= ~(TRANSPORT_PUSH_CERT_ALWAYS | TRANSPORT_PUSH_CERT_IF_ASKED);
		break;
	case SEND_PACK_PUSH_CERT_ALWAYS:
		*flags |= TRANSPORT_PUSH_CERT_ALWAYS;
		*flags &= ~TRANSPORT_PUSH_CERT_IF_ASKED;
		break;
	case SEND_PACK_PUSH_CERT_IF_ASKED:
		*flags |= TRANSPORT_PUSH_CERT_IF_ASKED;
		*flags &= ~TRANSPORT_PUSH_CERT_ALWAYS;
		break;
	}
}


465 466
static int git_push_config(const char *k, const char *v, void *cb)
{
467
	int *flags = cb;
468 469 470 471 472
	int status;

	status = git_gpg_config(k, v, NULL);
	if (status)
		return status;
473 474 475 476 477 478 479

	if (!strcmp(k, "push.followtags")) {
		if (git_config_bool(k, v))
			*flags |= TRANSPORT_PUSH_FOLLOW_TAGS;
		else
			*flags &= ~TRANSPORT_PUSH_FOLLOW_TAGS;
		return 0;
480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496
	} else if (!strcmp(k, "push.gpgsign")) {
		const char *value;
		if (!git_config_get_value("push.gpgsign", &value)) {
			switch (git_config_maybe_bool("push.gpgsign", value)) {
			case 0:
				set_push_cert_flags(flags, SEND_PACK_PUSH_CERT_NEVER);
				break;
			case 1:
				set_push_cert_flags(flags, SEND_PACK_PUSH_CERT_ALWAYS);
				break;
			default:
				if (value && !strcasecmp(value, "if-asked"))
					set_push_cert_flags(flags, SEND_PACK_PUSH_CERT_IF_ASKED);
				else
					return error("Invalid value for '%s'", k);
			}
		}
497 498 499 500
	} else if (!strcmp(k, "push.recursesubmodules")) {
		const char *value;
		if (!git_config_get_value("push.recursesubmodules", &value))
			recurse_submodules = parse_push_recurse_submodules_arg(k, value);
501 502
	}

503
	return git_default_config(k, v, NULL);
504 505
}

506
int cmd_push(int argc, const char **argv, const char *prefix)
Linus Torvalds's avatar
Linus Torvalds committed
507
{
508
	int flags = 0;
509
	int tags = 0;
510
	int push_cert = -1;
511
	int rc;
512
	const char *repo = NULL;	/* default repository */
Stefan Beller's avatar
Stefan Beller committed
513 514 515
	static struct string_list push_options = STRING_LIST_INIT_DUP;
	static struct string_list_item *item;

516
	struct option options[] = {
517
		OPT__VERBOSITY(&verbosity),
518 519 520
		OPT_STRING( 0 , "repo", &repo, N_("repository"), N_("repository")),
		OPT_BIT( 0 , "all", &flags, N_("push all refs"), TRANSPORT_PUSH_ALL),
		OPT_BIT( 0 , "mirror", &flags, N_("mirror all refs"),
521
			    (TRANSPORT_PUSH_MIRROR|TRANSPORT_PUSH_FORCE)),
522
		OPT_BOOL('d', "delete", &deleterefs, N_("delete refs")),
523
		OPT_BOOL( 0 , "tags", &tags, N_("push tags (can't be used with --all or --mirror)")),
524 525 526
		OPT_BIT('n' , "dry-run", &flags, N_("dry run"), TRANSPORT_PUSH_DRY_RUN),
		OPT_BIT( 0,  "porcelain", &flags, N_("machine-readable output"), TRANSPORT_PUSH_PORCELAIN),
		OPT_BIT('f', "force", &flags, N_("force updates"), TRANSPORT_PUSH_FORCE),
527 528 529 530
		{ OPTION_CALLBACK,
		  0, CAS_OPT_NAME, &cas, N_("refname>:<expect"),
		  N_("require old value of ref to be at this value"),
		  PARSE_OPT_OPTARG, parseopt_push_cas_option },
531
		{ OPTION_CALLBACK, 0, "recurse-submodules", &recurse_submodules, "check|on-demand|no",
532
			N_("control recursive pushing of submodules"),
533
			PARSE_OPT_OPTARG, option_parse_recurse_submodules },
534
		OPT_BOOL( 0 , "thin", &thin, N_("use thin pack")),
535 536 537
		OPT_STRING( 0 , "receive-pack", &receivepack, "receive-pack", N_("receive pack program")),
		OPT_STRING( 0 , "exec", &receivepack, "receive-pack", N_("receive pack program")),
		OPT_BIT('u', "set-upstream", &flags, N_("set upstream for git pull/status"),
Ilari Liusvaara's avatar
Ilari Liusvaara committed
538
			TRANSPORT_PUSH_SET_UPSTREAM),
539 540
		OPT_BOOL(0, "progress", &progress, N_("force progress reporting")),
		OPT_BIT(0, "prune", &flags, N_("prune locally removed refs"),
541
			TRANSPORT_PUSH_PRUNE),
542
		OPT_BIT(0, "no-verify", &flags, N_("bypass pre-push hook"), TRANSPORT_PUSH_NO_HOOK),
Junio C Hamano's avatar
Junio C Hamano committed
543 544
		OPT_BIT(0, "follow-tags", &flags, N_("push missing but relevant tags"),
			TRANSPORT_PUSH_FOLLOW_TAGS),
545 546 547
		{ OPTION_CALLBACK,
		  0, "signed", &push_cert, "yes|no|if-asked", N_("GPG sign the push"),
		  PARSE_OPT_OPTARG, option_parse_push_signed },
548
		OPT_BIT(0, "atomic", &flags, N_("request atomic transaction on remote side"), TRANSPORT_PUSH_ATOMIC),
Stefan Beller's avatar
Stefan Beller committed
549
		OPT_STRING_LIST('o', "push-option", &push_options, N_("server-specific"), N_("option to transmit")),
550 551 552 553
		OPT_SET_INT('4', "ipv4", &family, N_("use IPv4 addresses only"),
				TRANSPORT_FAMILY_IPV4),
		OPT_SET_INT('6', "ipv6", &family, N_("use IPv6 addresses only"),
				TRANSPORT_FAMILY_IPV6),
554 555
		OPT_END()
	};
Linus Torvalds's avatar
Linus Torvalds committed
556

Jeff King's avatar
Jeff King committed
557
	packet_trace_identity("push");
558
	git_config(git_push_config, &flags);
559
	argc = parse_options(argc, argv, prefix, options, push_usage, 0);
560
	set_push_cert_flags(&flags, push_cert);
561

562
	if (deleterefs && (tags || (flags & (TRANSPORT_PUSH_ALL | TRANSPORT_PUSH_MIRROR))))
563
		die(_("--delete is incompatible with --all, --mirror and --tags"));
564
	if (deleterefs && argc < 2)
565
		die(_("--delete doesn't make sense without any refs"));
566

567 568 569 570 571
	if (recurse_submodules == RECURSE_SUBMODULES_CHECK)
		flags |= TRANSPORT_RECURSE_SUBMODULES_CHECK;
	else if (recurse_submodules == RECURSE_SUBMODULES_ON_DEMAND)
		flags |= TRANSPORT_RECURSE_SUBMODULES_ON_DEMAND;

572 573 574 575 576
	if (tags)
		add_refspec("refs/tags/*");

	if (argc > 0) {
		repo = argv[0];
577
		set_refspecs(argv + 1, argc - 1, repo);
Linus Torvalds's avatar
Linus Torvalds committed
578
	}
579

Stefan Beller's avatar
Stefan Beller committed
580 581 582 583 584
	for_each_string_list_item(item, &push_options)
		if (strchr(item->string, '\n'))
			die(_("push options must not have new line characters"));

	rc = do_push(repo, flags, &push_options);
585
	if (rc == -1)
586
		usage_with_options(push_usage, options);
587 588
	else
		return rc;
Linus Torvalds's avatar
Linus Torvalds committed
589
}