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