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