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