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