push: don't mark options of recurse-submodules for translation
[git/git.git] / builtin / push.c
CommitLineData
755225de
LT
1/*
2 * "git push"
3 */
4#include "cache.h"
5#include "refs.h"
6#include "run-command.h"
7#include "builtin.h"
5751f490 8#include "remote.h"
9b288516 9#include "transport.h"
378c4832 10#include "parse-options.h"
d2b17b32 11#include "submodule.h"
b33a15b0 12#include "submodule-config.h"
30261094 13#include "send-pack.h"
755225de 14
378c4832 15static const char * const push_usage[] = {
78dafaa5 16 N_("git push [<options>] [<repository> [<refspec>...]]"),
378c4832
DB
17 NULL,
18};
755225de 19
f7c815c3 20static int thin = 1;
f517f1f2 21static int deleterefs;
d23842fd 22static const char *receivepack;
8afd8dc0 23static int verbosity;
d34141cd
MC
24static int progress = -1;
25static int recurse_submodules = RECURSE_SUBMODULES_DEFAULT;
755225de 26
28f5d176
JH
27static struct push_cas_option cas;
28
96f1e58f
DR
29static const char **refspec;
30static int refspec_nr;
8a883b02 31static int refspec_alloc;
755225de
LT
32
33static void add_refspec(const char *ref)
34{
8a883b02
JH
35 refspec_nr++;
36 ALLOC_GROW(refspec, refspec_nr, refspec_alloc);
37 refspec[refspec_nr-1] = ref;
755225de
LT
38}
39
ca02465b
JH
40static const char *map_refspec(const char *ref,
41 struct remote *remote, struct ref *local_refs)
755225de 42{
ca02465b
JH
43 struct ref *matched = NULL;
44
45 /* Does "ref" uniquely name our ref? */
46 if (count_refspec_match(ref, local_refs, &matched) != 1)
47 return ref;
48
49 if (remote->push) {
50 struct refspec query;
51 memset(&query, 0, sizeof(struct refspec));
52 query.src = matched->name;
53 if (!query_refspecs(remote->push, remote->push_refspec_nr, &query) &&
54 query.dst) {
55 struct strbuf buf = STRBUF_INIT;
56 strbuf_addf(&buf, "%s%s:%s",
57 query.force ? "+" : "",
58 query.src, query.dst);
59 return strbuf_detach(&buf, NULL);
60 }
61 }
62
fc9261ca 63 if (push_default == PUSH_DEFAULT_UPSTREAM &&
e3f11859 64 starts_with(matched->name, "refs/heads/")) {
fc9261ca
JH
65 struct branch *branch = branch_get(matched->name + 11);
66 if (branch->merge_nr == 1 && branch->merge[0]->src) {
67 struct strbuf buf = STRBUF_INIT;
68 strbuf_addf(&buf, "%s:%s",
69 ref, branch->merge[0]->src);
70 return strbuf_detach(&buf, NULL);
71 }
72 }
73
ca02465b
JH
74 return ref;
75}
76
77static void set_refspecs(const char **refs, int nr, const char *repo)
78{
79 struct remote *remote = NULL;
80 struct ref *local_refs = NULL;
8558fd9e 81 int i;
ca02465b 82
8558fd9e
DB
83 for (i = 0; i < nr; i++) {
84 const char *ref = refs[i];
85 if (!strcmp("tag", ref)) {
50d829c1 86 struct strbuf tagref = STRBUF_INIT;
8558fd9e 87 if (nr <= ++i)
8352d29e 88 die(_("tag shorthand without <tag>"));
50d829c1
JH
89 ref = refs[i];
90 if (deleterefs)
91 strbuf_addf(&tagref, ":refs/tags/%s", ref);
92 else
93 strbuf_addf(&tagref, "refs/tags/%s", ref);
94 ref = strbuf_detach(&tagref, NULL);
95 } else if (deleterefs) {
96 struct strbuf delref = STRBUF_INIT;
97 if (strchr(ref, ':'))
98 die(_("--delete only accepts plain target ref names"));
99 strbuf_addf(&delref, ":%s", ref);
100 ref = strbuf_detach(&delref, NULL);
ca02465b
JH
101 } else if (!strchr(ref, ':')) {
102 if (!remote) {
103 /* lazily grab remote and local_refs */
104 remote = remote_get(repo);
105 local_refs = get_local_heads();
f517f1f2 106 }
ca02465b 107 ref = map_refspec(ref, remote, local_refs);
50d829c1 108 }
8558fd9e 109 add_refspec(ref);
755225de 110 }
755225de
LT
111}
112
135dadef
JH
113static int push_url_of_remote(struct remote *remote, const char ***url_p)
114{
115 if (remote->pushurl_nr) {
116 *url_p = remote->pushurl;
117 return remote->pushurl_nr;
118 }
119 *url_p = remote->url;
120 return remote->url_nr;
121}
122
b55e6775
MM
123static NORETURN int die_push_simple(struct branch *branch, struct remote *remote) {
124 /*
125 * There's no point in using shorten_unambiguous_ref here,
126 * as the ambiguity would be on the remote side, not what
127 * we have locally. Plus, this is supposed to be the simple
128 * mode. If the user is doing something crazy like setting
129 * upstream to a non-branch, we should probably be showing
130 * them the big ugly fully qualified ref.
131 */
132 const char *advice_maybe = "";
cf4fff57
JK
133 const char *short_upstream = branch->merge[0]->src;
134
135 skip_prefix(short_upstream, "refs/heads/", &short_upstream);
b55e6775 136
b55e6775 137 /*
98e023de 138 * Don't show advice for people who explicitly set
b55e6775
MM
139 * push.default.
140 */
141 if (push_default == PUSH_DEFAULT_UNSPECIFIED)
142 advice_maybe = _("\n"
143 "To choose either option permanently, "
144 "see push.default in 'git help config'.");
145 die(_("The upstream branch of your current branch does not match\n"
146 "the name of your current branch. To push to the upstream branch\n"
147 "on the remote, use\n"
148 "\n"
149 " git push %s HEAD:%s\n"
150 "\n"
151 "To push to the branch of the same name on the remote, use\n"
152 "\n"
153 " git push %s %s\n"
154 "%s"),
155 remote->name, short_upstream,
156 remote->name, branch->name, advice_maybe);
157}
158
35ee69c0
RR
159static const char message_detached_head_die[] =
160 N_("You are not currently on a branch.\n"
161 "To push the history leading to the current (detached HEAD)\n"
162 "state now, use\n"
163 "\n"
164 " git push %s HEAD:<name-of-remote-branch>\n");
165
ed2b1829 166static void setup_push_upstream(struct remote *remote, struct branch *branch,
00a6fa07 167 int triangular, int simple)
52153747
FAG
168{
169 struct strbuf refspec = STRBUF_INIT;
ed2b1829 170
52153747 171 if (!branch)
35ee69c0 172 die(_(message_detached_head_die), remote->name);
135dadef 173 if (!branch->merge_nr || !branch->merge || !branch->remote_name)
6c80cd29 174 die(_("The current branch %s has no upstream branch.\n"
ec8460bd
MM
175 "To push the current branch and set the remote as upstream, use\n"
176 "\n"
6c80cd29 177 " git push --set-upstream %s %s\n"),
ec8460bd
MM
178 branch->name,
179 remote->name,
52153747
FAG
180 branch->name);
181 if (branch->merge_nr != 1)
6c80cd29 182 die(_("The current branch %s has multiple upstream branches, "
8352d29e 183 "refusing to push."), branch->name);
ed2b1829 184 if (triangular)
135dadef
JH
185 die(_("You are pushing to remote '%s', which is not the upstream of\n"
186 "your current branch '%s', without telling me what to push\n"
187 "to update which remote branch."),
188 remote->name, branch->name);
ed2b1829 189
00a6fa07 190 if (simple) {
ed2b1829
RR
191 /* Additional safety */
192 if (strcmp(branch->refname, branch->merge[0]->src))
193 die_push_simple(branch, remote);
194 }
135dadef 195
52153747
FAG
196 strbuf_addf(&refspec, "%s:%s", branch->name, branch->merge[0]->src);
197 add_refspec(refspec.buf);
198}
199
ed2b1829
RR
200static void setup_push_current(struct remote *remote, struct branch *branch)
201{
202 if (!branch)
203 die(_(message_detached_head_die), remote->name);
204 add_refspec(branch->name);
205}
206
f2c2c901 207static char warn_unspecified_push_default_msg[] =
b2ed944a 208N_("push.default is unset; its implicit value has changed in\n"
f2c2c901 209 "Git 2.0 from 'matching' to 'simple'. To squelch this message\n"
b2ed944a 210 "and maintain the traditional behavior, use:\n"
f2c2c901
MM
211 "\n"
212 " git config --global push.default matching\n"
213 "\n"
214 "To squelch this message and adopt the new behavior now, use:\n"
215 "\n"
216 " git config --global push.default simple\n"
217 "\n"
c13a5fe4
GJ
218 "When push.default is set to 'matching', git will push local branches\n"
219 "to the remote branches that already exist with the same name.\n"
220 "\n"
11037ee7 221 "Since Git 2.0, Git defaults to the more conservative 'simple'\n"
c13a5fe4
GJ
222 "behavior, which only pushes the current branch to the corresponding\n"
223 "remote branch that 'git pull' uses to update the current branch.\n"
224 "\n"
f2c2c901
MM
225 "See 'git help config' and search for 'push.default' for further information.\n"
226 "(the 'simple' mode was introduced in Git 1.7.11. Use the similar mode\n"
227 "'current' instead of 'simple' if you sometimes use older versions of Git)");
228
229static void warn_unspecified_push_default_configuration(void)
230{
231 static int warn_once;
232
233 if (warn_once++)
234 return;
235 warning("%s\n", _(warn_unspecified_push_default_msg));
236}
237
ed2b1829
RR
238static int is_workflow_triangular(struct remote *remote)
239{
240 struct remote *fetch_remote = remote_get(NULL);
241 return (fetch_remote && fetch_remote != remote);
242}
243
ec8460bd 244static void setup_default_push_refspecs(struct remote *remote)
52153747 245{
ed2b1829
RR
246 struct branch *branch = branch_get(NULL);
247 int triangular = is_workflow_triangular(remote);
7b2ecd81 248
52153747 249 switch (push_default) {
bba0fd22 250 default:
52153747
FAG
251 case PUSH_DEFAULT_MATCHING:
252 add_refspec(":");
253 break;
254
b2ed944a
JH
255 case PUSH_DEFAULT_UNSPECIFIED:
256 warn_unspecified_push_default_configuration();
257 /* fallthru */
258
b55e6775 259 case PUSH_DEFAULT_SIMPLE:
ed2b1829
RR
260 if (triangular)
261 setup_push_current(remote, branch);
262 else
00a6fa07 263 setup_push_upstream(remote, branch, triangular, 1);
b55e6775
MM
264 break;
265
53c40311 266 case PUSH_DEFAULT_UPSTREAM:
00a6fa07 267 setup_push_upstream(remote, branch, triangular, 0);
52153747
FAG
268 break;
269
270 case PUSH_DEFAULT_CURRENT:
ed2b1829 271 setup_push_current(remote, branch);
52153747
FAG
272 break;
273
274 case PUSH_DEFAULT_NOTHING:
8352d29e
ÆAB
275 die(_("You didn't specify any refspecs to push, and "
276 "push.default is \"nothing\"."));
52153747
FAG
277 break;
278 }
279}
280
f25950f3
CT
281static const char message_advice_pull_before_push[] =
282 N_("Updates were rejected because the tip of your current branch is behind\n"
fc6c4e96
JK
283 "its remote counterpart. Integrate the remote changes (e.g.\n"
284 "'git pull ...') before pushing again.\n"
f25950f3
CT
285 "See the 'Note about fast-forwards' in 'git push --help' for details.");
286
f25950f3
CT
287static const char message_advice_checkout_pull_push[] =
288 N_("Updates were rejected because a pushed branch tip is behind its remote\n"
fc6c4e96
JK
289 "counterpart. Check out this branch and integrate the remote changes\n"
290 "(e.g. 'git pull ...') before pushing again.\n"
f25950f3
CT
291 "See the 'Note about fast-forwards' in 'git push --help' for details.");
292
75e5c0dc
JH
293static const char message_advice_ref_fetch_first[] =
294 N_("Updates were rejected because the remote contains work that you do\n"
295 "not have locally. This is usually caused by another repository pushing\n"
fc6c4e96
JK
296 "to the same ref. You may want to first integrate the remote changes\n"
297 "(e.g., 'git pull ...') before pushing again.\n"
75e5c0dc
JH
298 "See the 'Note about fast-forwards' in 'git push --help' for details.");
299
b24e6047 300static const char message_advice_ref_already_exists[] =
b4cf8db2 301 N_("Updates were rejected because the tag already exists in the remote.");
b24e6047 302
75e5c0dc
JH
303static const char message_advice_ref_needs_force[] =
304 N_("You cannot update a remote ref that points at a non-commit object,\n"
305 "or update a remote ref to make it point at a non-commit object,\n"
306 "without using the '--force' option.\n");
b24e6047 307
f25950f3
CT
308static void advise_pull_before_push(void)
309{
1184564e 310 if (!advice_push_non_ff_current || !advice_push_update_rejected)
f25950f3
CT
311 return;
312 advise(_(message_advice_pull_before_push));
313}
314
f25950f3
CT
315static void advise_checkout_pull_push(void)
316{
1184564e 317 if (!advice_push_non_ff_matching || !advice_push_update_rejected)
f25950f3
CT
318 return;
319 advise(_(message_advice_checkout_pull_push));
320}
321
b24e6047
CR
322static void advise_ref_already_exists(void)
323{
b4505682
CR
324 if (!advice_push_already_exists || !advice_push_update_rejected)
325 return;
b24e6047
CR
326 advise(_(message_advice_ref_already_exists));
327}
328
75e5c0dc
JH
329static void advise_ref_fetch_first(void)
330{
331 if (!advice_push_fetch_first || !advice_push_update_rejected)
332 return;
333 advise(_(message_advice_ref_fetch_first));
334}
335
336static void advise_ref_needs_force(void)
337{
338 if (!advice_push_needs_force || !advice_push_update_rejected)
339 return;
340 advise(_(message_advice_ref_needs_force));
341}
342
fb0cc87e
DB
343static int push_with_options(struct transport *transport, int flags)
344{
345 int err;
10643d4e 346 unsigned int reject_reasons;
8afd8dc0 347
78381069 348 transport_set_verbosity(transport, verbosity, progress);
8afd8dc0 349
fb0cc87e
DB
350 if (receivepack)
351 transport_set_option(transport,
352 TRANS_OPT_RECEIVEPACK, receivepack);
f7c815c3 353 transport_set_option(transport, TRANS_OPT_THIN, thin ? "yes" : NULL);
fb0cc87e 354
91048a95
JH
355 if (!is_empty_cas(&cas)) {
356 if (!transport->smart_options)
357 die("underlying transport does not support --%s option",
358 CAS_OPT_NAME);
359 transport->smart_options->cas = &cas;
360 }
361
8afd8dc0 362 if (verbosity > 0)
8352d29e 363 fprintf(stderr, _("Pushing to %s\n"), transport->url);
fb0cc87e 364 err = transport_push(transport, refspec_nr, refspec, flags,
10643d4e 365 &reject_reasons);
53970b92 366 if (err != 0)
8352d29e 367 error(_("failed to push some refs to '%s'"), transport->url);
53970b92 368
fb0cc87e 369 err |= transport_disconnect(transport);
fb0cc87e
DB
370 if (!err)
371 return 0;
372
10643d4e 373 if (reject_reasons & REJECT_NON_FF_HEAD) {
f25950f3 374 advise_pull_before_push();
10643d4e 375 } else if (reject_reasons & REJECT_NON_FF_OTHER) {
b2ed944a 376 advise_checkout_pull_push();
b24e6047
CR
377 } else if (reject_reasons & REJECT_ALREADY_EXISTS) {
378 advise_ref_already_exists();
75e5c0dc
JH
379 } else if (reject_reasons & REJECT_FETCH_FIRST) {
380 advise_ref_fetch_first();
381 } else if (reject_reasons & REJECT_NEEDS_FORCE) {
382 advise_ref_needs_force();
fb0cc87e
DB
383 }
384
385 return 1;
386}
387
9b288516 388static int do_push(const char *repo, int flags)
755225de 389{
5751f490 390 int i, errs;
f24f715e 391 struct remote *remote = pushremote_get(repo);
20346234
MG
392 const char **url;
393 int url_nr;
755225de 394
fa685bdf
DB
395 if (!remote) {
396 if (repo)
8352d29e 397 die(_("bad repository '%s'"), repo);
6c80cd29 398 die(_("No configured push destination.\n"
a3f5e7a3
MM
399 "Either specify the URL from the command-line or configure a remote repository using\n"
400 "\n"
401 " git remote add <name> <url>\n"
402 "\n"
403 "and then push using the remote name\n"
404 "\n"
6c80cd29 405 " git push <name>\n"));
fa685bdf 406 }
755225de 407
84bb2dfd
PB
408 if (remote->mirror)
409 flags |= (TRANSPORT_PUSH_MIRROR|TRANSPORT_PUSH_FORCE);
410
b259f09b
MZ
411 if ((flags & TRANSPORT_PUSH_ALL) && refspec) {
412 if (!strcmp(*refspec, "refs/tags/*"))
8352d29e
ÆAB
413 return error(_("--all and --tags are incompatible"));
414 return error(_("--all can't be combined with refspecs"));
b259f09b
MZ
415 }
416
417 if ((flags & TRANSPORT_PUSH_MIRROR) && refspec) {
418 if (!strcmp(*refspec, "refs/tags/*"))
8352d29e
ÆAB
419 return error(_("--mirror and --tags are incompatible"));
420 return error(_("--mirror can't be combined with refspecs"));
b259f09b 421 }
84bb2dfd
PB
422
423 if ((flags & (TRANSPORT_PUSH_ALL|TRANSPORT_PUSH_MIRROR)) ==
424 (TRANSPORT_PUSH_ALL|TRANSPORT_PUSH_MIRROR)) {
8352d29e 425 return error(_("--all and --mirror are incompatible"));
84bb2dfd
PB
426 }
427
52153747
FAG
428 if (!refspec && !(flags & TRANSPORT_PUSH_ALL)) {
429 if (remote->push_refspec_nr) {
430 refspec = remote->push_refspec;
431 refspec_nr = remote->push_refspec_nr;
432 } else if (!(flags & TRANSPORT_PUSH_MIRROR))
ec8460bd 433 setup_default_push_refspecs(remote);
5751f490 434 }
fd1d1b05 435 errs = 0;
135dadef 436 url_nr = push_url_of_remote(remote, &url);
fb0cc87e
DB
437 if (url_nr) {
438 for (i = 0; i < url_nr; i++) {
439 struct transport *transport =
440 transport_get(remote, url[i]);
441 if (push_with_options(transport, flags))
442 errs++;
07436e43 443 }
fb0cc87e
DB
444 } else {
445 struct transport *transport =
446 transport_get(remote, NULL);
447
448 if (push_with_options(transport, flags))
449 errs++;
755225de 450 }
fd1d1b05 451 return !!errs;
755225de
LT
452}
453
d2b17b32
FG
454static int option_parse_recurse_submodules(const struct option *opt,
455 const char *arg, int unset)
456{
b33a15b0 457 int *recurse_submodules = opt->value;
eb21c732 458
b33a15b0
MC
459 if (unset)
460 *recurse_submodules = RECURSE_SUBMODULES_OFF;
461 else if (arg)
462 *recurse_submodules = parse_push_recurse_submodules_arg(opt->long_name, arg);
463 else
464 die("%s missing parameter", opt->long_name);
d2b17b32
FG
465
466 return 0;
467}
468
68c757f2
DB
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
b9459019
MG
487static int git_push_config(const char *k, const char *v, void *cb)
488{
a8bc269f 489 int *flags = cb;
b9459019
MG
490 int status;
491
492 status = git_gpg_config(k, v, NULL);
493 if (status)
494 return status;
a8bc269f
DO
495
496 if (!strcmp(k, "push.followtags")) {
497 if (git_config_bool(k, v))
498 *flags |= TRANSPORT_PUSH_FOLLOW_TAGS;
499 else
500 *flags &= ~TRANSPORT_PUSH_FOLLOW_TAGS;
501 return 0;
68c757f2
DB
502 } else if (!strcmp(k, "push.gpgsign")) {
503 const char *value;
504 if (!git_config_get_value("push.gpgsign", &value)) {
505 switch (git_config_maybe_bool("push.gpgsign", value)) {
506 case 0:
507 set_push_cert_flags(flags, SEND_PACK_PUSH_CERT_NEVER);
508 break;
509 case 1:
510 set_push_cert_flags(flags, SEND_PACK_PUSH_CERT_ALWAYS);
511 break;
512 default:
513 if (value && !strcasecmp(value, "if-asked"))
514 set_push_cert_flags(flags, SEND_PACK_PUSH_CERT_IF_ASKED);
515 else
516 return error("Invalid value for '%s'", k);
517 }
518 }
b33a15b0
MC
519 } else if (!strcmp(k, "push.recursesubmodules")) {
520 const char *value;
521 if (!git_config_get_value("push.recursesubmodules", &value))
522 recurse_submodules = parse_push_recurse_submodules_arg(k, value);
a8bc269f
DO
523 }
524
06038cd7 525 return git_default_config(k, v, NULL);
b9459019
MG
526}
527
a633fca0 528int cmd_push(int argc, const char **argv, const char *prefix)
755225de 529{
9b288516 530 int flags = 0;
378c4832 531 int tags = 0;
30261094 532 int push_cert = -1;
84bb2dfd 533 int rc;
5751f490 534 const char *repo = NULL; /* default repository */
378c4832 535 struct option options[] = {
8afd8dc0 536 OPT__VERBOSITY(&verbosity),
78dafaa5
NTND
537 OPT_STRING( 0 , "repo", &repo, N_("repository"), N_("repository")),
538 OPT_BIT( 0 , "all", &flags, N_("push all refs"), TRANSPORT_PUSH_ALL),
539 OPT_BIT( 0 , "mirror", &flags, N_("mirror all refs"),
c29c1b40 540 (TRANSPORT_PUSH_MIRROR|TRANSPORT_PUSH_FORCE)),
d5d09d47
SB
541 OPT_BOOL( 0, "delete", &deleterefs, N_("delete refs")),
542 OPT_BOOL( 0 , "tags", &tags, N_("push tags (can't be used with --all or --mirror)")),
78dafaa5
NTND
543 OPT_BIT('n' , "dry-run", &flags, N_("dry run"), TRANSPORT_PUSH_DRY_RUN),
544 OPT_BIT( 0, "porcelain", &flags, N_("machine-readable output"), TRANSPORT_PUSH_PORCELAIN),
545 OPT_BIT('f', "force", &flags, N_("force updates"), TRANSPORT_PUSH_FORCE),
28f5d176
JH
546 { OPTION_CALLBACK,
547 0, CAS_OPT_NAME, &cas, N_("refname>:<expect"),
548 N_("require old value of ref to be at this value"),
549 PARSE_OPT_OPTARG, parseopt_push_cas_option },
6a4f2ece 550 { OPTION_CALLBACK, 0, "recurse-submodules", &recurse_submodules, "check|on-demand|no",
f63cf8c9 551 N_("control recursive pushing of submodules"),
d2b17b32 552 PARSE_OPT_OPTARG, option_parse_recurse_submodules },
d5d09d47 553 OPT_BOOL( 0 , "thin", &thin, N_("use thin pack")),
78dafaa5
NTND
554 OPT_STRING( 0 , "receive-pack", &receivepack, "receive-pack", N_("receive pack program")),
555 OPT_STRING( 0 , "exec", &receivepack, "receive-pack", N_("receive pack program")),
556 OPT_BIT('u', "set-upstream", &flags, N_("set upstream for git pull/status"),
e9fcd1e2 557 TRANSPORT_PUSH_SET_UPSTREAM),
78dafaa5
NTND
558 OPT_BOOL(0, "progress", &progress, N_("force progress reporting")),
559 OPT_BIT(0, "prune", &flags, N_("prune locally removed refs"),
6ddba5e2 560 TRANSPORT_PUSH_PRUNE),
ec55559f 561 OPT_BIT(0, "no-verify", &flags, N_("bypass pre-push hook"), TRANSPORT_PUSH_NO_HOOK),
c2aba155
JH
562 OPT_BIT(0, "follow-tags", &flags, N_("push missing but relevant tags"),
563 TRANSPORT_PUSH_FOLLOW_TAGS),
30261094
DB
564 { OPTION_CALLBACK,
565 0, "signed", &push_cert, "yes|no|if-asked", N_("GPG sign the push"),
566 PARSE_OPT_OPTARG, option_parse_push_signed },
d16c33b4 567 OPT_BIT(0, "atomic", &flags, N_("request atomic transaction on remote side"), TRANSPORT_PUSH_ATOMIC),
378c4832
DB
568 OPT_END()
569 };
755225de 570
bbc30f99 571 packet_trace_identity("push");
06c21e18 572 git_config(git_push_config, &flags);
37782920 573 argc = parse_options(argc, argv, prefix, options, push_usage, 0);
68c757f2 574 set_push_cert_flags(&flags, push_cert);
378c4832 575
f517f1f2 576 if (deleterefs && (tags || (flags & (TRANSPORT_PUSH_ALL | TRANSPORT_PUSH_MIRROR))))
8352d29e 577 die(_("--delete is incompatible with --all, --mirror and --tags"));
f517f1f2 578 if (deleterefs && argc < 2)
8352d29e 579 die(_("--delete doesn't make sense without any refs"));
f517f1f2 580
b33a15b0
MC
581 if (recurse_submodules == RECURSE_SUBMODULES_CHECK)
582 flags |= TRANSPORT_RECURSE_SUBMODULES_CHECK;
583 else if (recurse_submodules == RECURSE_SUBMODULES_ON_DEMAND)
584 flags |= TRANSPORT_RECURSE_SUBMODULES_ON_DEMAND;
585
378c4832
DB
586 if (tags)
587 add_refspec("refs/tags/*");
378c4832
DB
588
589 if (argc > 0) {
590 repo = argv[0];
ca02465b 591 set_refspecs(argv + 1, argc - 1, repo);
755225de 592 }
8558fd9e 593
84bb2dfd
PB
594 rc = do_push(repo, flags);
595 if (rc == -1)
94c89ba6 596 usage_with_options(push_usage, options);
84bb2dfd
PB
597 else
598 return rc;
755225de 599}