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