blob: 2fbb31c3ad8eb9b7a15ffac4e5d9aa65367d298f [file] [log] [blame]
Linus Torvalds755225d2006-04-29 21:22:49 -07001/*
2 * "git push"
3 */
Elijah Newrenbc5c5ec2023-05-16 06:33:57 +00004#include "builtin.h"
Elijah Newren6c6ddf92023-04-11 03:00:39 +00005#include "advice.h"
Tao Klerksbdaf1df2022-04-29 09:56:44 +00006#include "branch.h"
Brandon Williamsb2141fc2017-06-14 11:07:36 -07007#include "config.h"
Elijah Newren32a8f512023-03-21 06:26:03 +00008#include "environment.h"
Elijah Newrenf394e092023-03-21 06:25:54 +00009#include "gettext.h"
Brandon Williamsec0cb492018-05-16 15:57:48 -070010#include "refspec.h"
Linus Torvalds755225d2006-04-29 21:22:49 -070011#include "run-command.h"
Daniel Barkalow5751f492007-05-12 11:45:53 -040012#include "remote.h"
Daniel Barkalow9b288512007-09-10 23:03:04 -040013#include "transport.h"
Daniel Barkalow378c4832007-11-04 22:35:37 -050014#include "parse-options.h"
Elijah Newrenb3886332023-04-22 20:17:14 +000015#include "pkt-line.h"
Elijah Newrend1cbe1e2023-04-22 20:17:20 +000016#include "repository.h"
Fredrik Gustafssond2b17b32011-08-20 00:08:47 +020017#include "submodule.h"
Mike Croweb33a15b2015-11-17 11:05:56 +000018#include "submodule-config.h"
Dave Borowitz30261092015-08-19 11:26:46 -040019#include "send-pack.h"
Elijah Newren74ea5c92023-04-11 03:00:38 +000020#include "trace2.h"
Ryan Dammrose960786e2018-04-21 12:10:00 +020021#include "color.h"
Linus Torvalds755225d2006-04-29 21:22:49 -070022
Daniel Barkalow378c4832007-11-04 22:35:37 -050023static const char * const push_usage[] = {
Nguyễn Thái Ngọc Duy78dafaa2012-08-20 19:32:33 +070024 N_("git push [<options>] [<repository> [<refspec>...]]"),
Daniel Barkalow378c4832007-11-04 22:35:37 -050025 NULL,
26};
Linus Torvalds755225d2006-04-29 21:22:49 -070027
Ryan Dammrose960786e2018-04-21 12:10:00 +020028static int push_use_color = -1;
29static char push_colors[][COLOR_MAXLEN] = {
30 GIT_COLOR_RESET,
31 GIT_COLOR_RED, /* ERROR */
32};
33
34enum color_push {
35 PUSH_COLOR_RESET = 0,
36 PUSH_COLOR_ERROR = 1
37};
38
39static int parse_push_color_slot(const char *slot)
40{
41 if (!strcasecmp(slot, "reset"))
42 return PUSH_COLOR_RESET;
43 if (!strcasecmp(slot, "error"))
44 return PUSH_COLOR_ERROR;
45 return -1;
46}
47
48static const char *push_get_color(enum color_push ix)
49{
50 if (want_color_stderr(push_use_color))
51 return push_colors[ix];
52 return "";
53}
54
Nguyễn Thái Ngọc Duyf7c815c2013-08-12 20:55:55 +070055static int thin = 1;
Jan Krügerf517f1f2009-12-30 20:57:42 +010056static int deleterefs;
Uwe Kleine-Königd23842f2007-01-19 13:49:27 +010057static const char *receivepack;
Tay Ray Chuan8afd8dc2010-02-24 20:50:24 +080058static int verbosity;
Mike Crowed34141c2015-12-03 13:10:35 +000059static int progress = -1;
60static int recurse_submodules = RECURSE_SUBMODULES_DEFAULT;
Eric Wongc915f112016-02-03 04:09:14 +000061static enum transport_family family;
Linus Torvalds755225d2006-04-29 21:22:49 -070062
Junio C Hamano28f5d172013-07-08 15:34:36 -070063static struct push_cas_option cas;
64
Brandon Williamsaa402892018-05-16 15:58:16 -070065static struct refspec rs = REFSPEC_INIT_PUSH;
Linus Torvalds755225d2006-04-29 21:22:49 -070066
Marius Paligad8052752017-10-23 13:44:49 +020067static struct string_list push_options_config = STRING_LIST_INIT_DUP;
68
René Scharfe30035d92020-09-05 16:47:47 +020069static void refspec_append_mapped(struct refspec *refspec, const char *ref,
Ævar Arnfjörð Bjarmasonaa561202023-02-07 00:07:53 +010070 struct remote *remote, struct ref *matched)
Linus Torvalds755225d2006-04-29 21:22:49 -070071{
René Scharfe1768aaf2019-11-26 16:18:28 +010072 const char *branch_name;
Junio C Hamanoca024652013-12-03 15:41:15 -080073
Brandon Williams6bdb3042018-05-16 15:58:00 -070074 if (remote->push.nr) {
Brandon Williams0ad4a5f2018-05-16 15:57:49 -070075 struct refspec_item query;
76 memset(&query, 0, sizeof(struct refspec_item));
Junio C Hamanoca024652013-12-03 15:41:15 -080077 query.src = matched->name;
Brandon Williams86baf822018-05-16 15:58:12 -070078 if (!query_refspecs(&remote->push, &query) && query.dst) {
René Scharfe1af8b8c2020-09-05 16:49:30 +020079 refspec_appendf(refspec, "%s%s:%s",
80 query.force ? "+" : "",
81 query.src, query.dst);
René Scharfe30035d92020-09-05 16:47:47 +020082 return;
Junio C Hamanoca024652013-12-03 15:41:15 -080083 }
84 }
85
Junio C Hamanofc9261c2013-12-03 16:23:35 -080086 if (push_default == PUSH_DEFAULT_UPSTREAM &&
René Scharfe1768aaf2019-11-26 16:18:28 +010087 skip_prefix(matched->name, "refs/heads/", &branch_name)) {
88 struct branch *branch = branch_get(branch_name);
Junio C Hamanofc9261c2013-12-03 16:23:35 -080089 if (branch->merge_nr == 1 && branch->merge[0]->src) {
René Scharfe1af8b8c2020-09-05 16:49:30 +020090 refspec_appendf(refspec, "%s:%s",
91 ref, branch->merge[0]->src);
René Scharfe30035d92020-09-05 16:47:47 +020092 return;
Junio C Hamanofc9261c2013-12-03 16:23:35 -080093 }
94 }
95
René Scharfe30035d92020-09-05 16:47:47 +020096 refspec_append(refspec, ref);
Junio C Hamanoca024652013-12-03 15:41:15 -080097}
98
99static void set_refspecs(const char **refs, int nr, const char *repo)
100{
101 struct remote *remote = NULL;
102 struct ref *local_refs = NULL;
Daniel Barkalow8558fd92007-05-25 01:20:56 -0400103 int i;
Junio C Hamanoca024652013-12-03 15:41:15 -0800104
Daniel Barkalow8558fd92007-05-25 01:20:56 -0400105 for (i = 0; i < nr; i++) {
106 const char *ref = refs[i];
107 if (!strcmp("tag", ref)) {
Daniel Barkalow8558fd92007-05-25 01:20:56 -0400108 if (nr <= ++i)
Ævar Arnfjörð Bjarmason8352d292011-02-22 23:42:11 +0000109 die(_("tag shorthand without <tag>"));
Junio C Hamano50d829c2013-12-03 14:33:10 -0800110 ref = refs[i];
111 if (deleterefs)
René Scharfe1af8b8c2020-09-05 16:49:30 +0200112 refspec_appendf(&rs, ":refs/tags/%s", ref);
Junio C Hamano50d829c2013-12-03 14:33:10 -0800113 else
René Scharfe1af8b8c2020-09-05 16:49:30 +0200114 refspec_appendf(&rs, "refs/tags/%s", ref);
Junio C Hamano50d829c2013-12-03 14:33:10 -0800115 } else if (deleterefs) {
Junio C Hamano20e41642021-02-23 15:13:32 -0800116 if (strchr(ref, ':') || !*ref)
Junio C Hamano50d829c2013-12-03 14:33:10 -0800117 die(_("--delete only accepts plain target ref names"));
René Scharfe1af8b8c2020-09-05 16:49:30 +0200118 refspec_appendf(&rs, ":%s", ref);
Junio C Hamanoca024652013-12-03 15:41:15 -0800119 } else if (!strchr(ref, ':')) {
Ævar Arnfjörð Bjarmasonaa561202023-02-07 00:07:53 +0100120 struct ref *matched = NULL;
121
122 /* lazily grab local_refs */
123 if (!local_refs)
Junio C Hamanoca024652013-12-03 15:41:15 -0800124 local_refs = get_local_heads();
Ævar Arnfjörð Bjarmasonaa561202023-02-07 00:07:53 +0100125
126 /* Does "ref" uniquely name our ref? */
127 if (count_refspec_match(ref, local_refs, &matched) != 1) {
128 refspec_append(&rs, ref);
129 } else {
130 /* lazily grab remote */
131 if (!remote)
132 remote = remote_get(repo);
133 if (!remote)
134 BUG("must get a remote for repo '%s'", repo);
135
136 refspec_append_mapped(&rs, ref, remote, matched);
Jan Krügerf517f1f2009-12-30 20:57:42 +0100137 }
René Scharfe30035d92020-09-05 16:47:47 +0200138 } else
139 refspec_append(&rs, ref);
Linus Torvalds755225d2006-04-29 21:22:49 -0700140 }
Ævar Arnfjörð Bjarmasonc65d18c2023-02-07 00:07:54 +0100141 free_refs(local_refs);
Linus Torvalds755225d2006-04-29 21:22:49 -0700142}
143
Junio C Hamano135dade2012-03-30 16:07:12 -0700144static int push_url_of_remote(struct remote *remote, const char ***url_p)
145{
146 if (remote->pushurl_nr) {
147 *url_p = remote->pushurl;
148 return remote->pushurl_nr;
149 }
150 *url_p = remote->url;
151 return remote->url_nr;
152}
153
Johannes Schindelindbcd9702019-09-30 02:55:31 -0700154static NORETURN void die_push_simple(struct branch *branch,
155 struct remote *remote)
Nguyễn Thái Ngọc Duy3b335762018-12-09 11:25:21 +0100156{
Matthieu Moyb55e6772012-04-24 09:50:03 +0200157 /*
158 * There's no point in using shorten_unambiguous_ref here,
159 * as the ambiguity would be on the remote side, not what
160 * we have locally. Plus, this is supposed to be the simple
161 * mode. If the user is doing something crazy like setting
162 * upstream to a non-branch, we should probably be showing
163 * them the big ugly fully qualified ref.
164 */
Tao Klerksbdaf1df2022-04-29 09:56:44 +0000165 const char *advice_pushdefault_maybe = "";
166 const char *advice_automergesimple_maybe = "";
Jeff Kingcf4fff52014-06-18 15:44:19 -0400167 const char *short_upstream = branch->merge[0]->src;
Matthieu Moyb55e6772012-04-24 09:50:03 +0200168
Jeff Kingcf4fff52014-06-18 15:44:19 -0400169 skip_prefix(short_upstream, "refs/heads/", &short_upstream);
170
Matthieu Moyb55e6772012-04-24 09:50:03 +0200171 /*
Ondřej Bílka98e023d2013-07-29 10:18:21 +0200172 * Don't show advice for people who explicitly set
Matthieu Moyb55e6772012-04-24 09:50:03 +0200173 * push.default.
174 */
175 if (push_default == PUSH_DEFAULT_UNSPECIFIED)
Tao Klerksbdaf1df2022-04-29 09:56:44 +0000176 advice_pushdefault_maybe = _("\n"
Matthieu Moyb55e6772012-04-24 09:50:03 +0200177 "To choose either option permanently, "
Tao Klerksbdaf1df2022-04-29 09:56:44 +0000178 "see push.default in 'git help config'.\n");
179 if (git_branch_track != BRANCH_TRACK_SIMPLE)
180 advice_automergesimple_maybe = _("\n"
181 "To avoid automatically configuring "
Alex Henrie2a905f82022-09-27 23:58:11 -0600182 "an upstream branch when its name\n"
183 "won't match the local branch, see option "
Fangyi Zhou1f8496c2022-06-15 15:35:44 +0000184 "'simple' of branch.autoSetupMerge\n"
Tao Klerksbdaf1df2022-04-29 09:56:44 +0000185 "in 'git help config'.\n");
Matthieu Moyb55e6772012-04-24 09:50:03 +0200186 die(_("The upstream branch of your current branch does not match\n"
187 "the name of your current branch. To push to the upstream branch\n"
188 "on the remote, use\n"
189 "\n"
190 " git push %s HEAD:%s\n"
191 "\n"
192 "To push to the branch of the same name on the remote, use\n"
193 "\n"
Ævar Arnfjörð Bjarmason82471662018-11-13 20:39:09 +0000194 " git push %s HEAD\n"
Tao Klerksbdaf1df2022-04-29 09:56:44 +0000195 "%s%s"),
Matthieu Moyb55e6772012-04-24 09:50:03 +0200196 remote->name, short_upstream,
Tao Klerksbdaf1df2022-04-29 09:56:44 +0000197 remote->name, advice_pushdefault_maybe,
198 advice_automergesimple_maybe);
Matthieu Moyb55e6772012-04-24 09:50:03 +0200199}
200
Ramkumar Ramachandra35ee69c2013-05-30 00:51:49 +0530201static const char message_detached_head_die[] =
202 N_("You are not currently on a branch.\n"
203 "To push the history leading to the current (detached HEAD)\n"
204 "state now, use\n"
205 "\n"
206 " git push %s HEAD:<name-of-remote-branch>\n");
207
Tao Klerks05d57752022-04-29 09:56:46 +0000208static const char *get_upstream_ref(int flags, struct branch *branch, const char *remote_name)
Finn Arne Gangstad52153742009-03-16 16:42:51 +0100209{
Tao Klerks05d57752022-04-29 09:56:46 +0000210 if (branch->merge_nr == 0 && (flags & TRANSPORT_PUSH_AUTO_UPSTREAM)) {
211 /* if missing, assume same; set_upstream will be defined later */
212 return branch->refname;
213 }
214
215 if (!branch->merge_nr || !branch->merge || !branch->remote_name) {
216 const char *advice_autosetup_maybe = "";
217 if (!(flags & TRANSPORT_PUSH_AUTO_UPSTREAM)) {
218 advice_autosetup_maybe = _("\n"
219 "To have this happen automatically for "
220 "branches without a tracking\n"
221 "upstream, see 'push.autoSetupRemote' "
222 "in 'git help config'.\n");
223 }
Junio C Hamano6c80cd22011-04-01 17:55:55 -0700224 die(_("The current branch %s has no upstream branch.\n"
Matthieu Moyec8460b2011-03-02 21:12:10 +0100225 "To push the current branch and set the remote as upstream, use\n"
226 "\n"
Tao Klerks05d57752022-04-29 09:56:46 +0000227 " git push --set-upstream %s %s\n"
228 "%s"),
Matthieu Moyec8460b2011-03-02 21:12:10 +0100229 branch->name,
Felipe Contreras533e0322021-05-31 14:51:12 -0500230 remote_name,
Tao Klerks05d57752022-04-29 09:56:46 +0000231 branch->name,
232 advice_autosetup_maybe);
233 }
Finn Arne Gangstad52153742009-03-16 16:42:51 +0100234 if (branch->merge_nr != 1)
Junio C Hamano6c80cd22011-04-01 17:55:55 -0700235 die(_("The current branch %s has multiple upstream branches, "
Ævar Arnfjörð Bjarmason8352d292011-02-22 23:42:11 +0000236 "refusing to push."), branch->name);
Felipe Contreras533e0322021-05-31 14:51:12 -0500237
238 return branch->merge[0]->src;
239}
240
Tao Klerks05d57752022-04-29 09:56:46 +0000241static void setup_default_push_refspecs(int *flags, struct remote *remote)
Finn Arne Gangstad52153742009-03-16 16:42:51 +0100242{
Felipe Contreras65c63a02021-05-31 14:51:16 -0500243 struct branch *branch;
Felipe Contreras00458dc2021-05-31 14:51:17 -0500244 const char *dst;
Felipe Contrerase0c91cf2021-05-31 14:51:23 -0500245 int same_remote;
Ramkumar Ramachandra7b2ecd82013-05-30 00:51:50 +0530246
Finn Arne Gangstad52153742009-03-16 16:42:51 +0100247 switch (push_default) {
Finn Arne Gangstad52153742009-03-16 16:42:51 +0100248 case PUSH_DEFAULT_MATCHING:
Brandon Williamsaa402892018-05-16 15:58:16 -0700249 refspec_append(&rs, ":");
Felipe Contreras72739682021-05-31 14:51:13 -0500250 return;
Finn Arne Gangstad52153742009-03-16 16:42:51 +0100251
Felipe Contreras04159fb2021-05-31 14:51:14 -0500252 case PUSH_DEFAULT_NOTHING:
253 die(_("You didn't specify any refspecs to push, and "
254 "push.default is \"nothing\"."));
255 return;
256 default:
257 break;
258 }
259
Felipe Contreras65c63a02021-05-31 14:51:16 -0500260 branch = branch_get(NULL);
Felipe Contrerascc16f952021-05-31 14:51:15 -0500261 if (!branch)
262 die(_(message_detached_head_die), remote->name);
263
Felipe Contreras1f934722021-05-31 14:51:20 -0500264 dst = branch->refname;
Felipe Contreras7088ce72021-05-31 14:51:24 -0500265 same_remote = !strcmp(remote->name, remote_for_branch(branch, NULL));
Felipe Contreras1f934722021-05-31 14:51:20 -0500266
Felipe Contreras04159fb2021-05-31 14:51:14 -0500267 switch (push_default) {
268 default:
Junio C Hamanob2ed9442013-01-04 16:02:29 -0800269 case PUSH_DEFAULT_UNSPECIFIED:
Matthieu Moyb55e6772012-04-24 09:50:03 +0200270 case PUSH_DEFAULT_SIMPLE:
Felipe Contreras1f934722021-05-31 14:51:20 -0500271 if (!same_remote)
272 break;
Tao Klerks05d57752022-04-29 09:56:46 +0000273 if (strcmp(branch->refname, get_upstream_ref(*flags, branch, remote->name)))
Felipe Contreras1f934722021-05-31 14:51:20 -0500274 die_push_simple(branch, remote);
Felipe Contreras00458dc2021-05-31 14:51:17 -0500275 break;
Matthieu Moyb55e6772012-04-24 09:50:03 +0200276
Johan Herland53c40312011-02-16 01:54:24 +0100277 case PUSH_DEFAULT_UPSTREAM:
Felipe Contreras0add8992021-05-31 14:51:19 -0500278 if (!same_remote)
279 die(_("You are pushing to remote '%s', which is not the upstream of\n"
280 "your current branch '%s', without telling me what to push\n"
281 "to update which remote branch."),
282 remote->name, branch->name);
Tao Klerks05d57752022-04-29 09:56:46 +0000283 dst = get_upstream_ref(*flags, branch, remote->name);
Felipe Contreras00458dc2021-05-31 14:51:17 -0500284 break;
Finn Arne Gangstad52153742009-03-16 16:42:51 +0100285
286 case PUSH_DEFAULT_CURRENT:
Felipe Contreras00458dc2021-05-31 14:51:17 -0500287 break;
Finn Arne Gangstad52153742009-03-16 16:42:51 +0100288 }
Felipe Contreras00458dc2021-05-31 14:51:17 -0500289
Tao Klerks05d57752022-04-29 09:56:46 +0000290 /*
291 * this is a default push - if auto-upstream is enabled and there is
292 * no upstream defined, then set it (with options 'simple', 'upstream',
293 * and 'current').
294 */
295 if ((*flags & TRANSPORT_PUSH_AUTO_UPSTREAM) && branch->merge_nr == 0)
296 *flags |= TRANSPORT_PUSH_SET_UPSTREAM;
297
Felipe Contreras00458dc2021-05-31 14:51:17 -0500298 refspec_appendf(&rs, "%s:%s", branch->refname, dst);
Finn Arne Gangstad52153742009-03-16 16:42:51 +0100299}
300
Christopher Tiwaldf25950f2012-03-20 00:31:33 -0400301static const char message_advice_pull_before_push[] =
302 N_("Updates were rejected because the tip of your current branch is behind\n"
Alex Henriec577d652023-07-12 22:41:15 -0600303 "its remote counterpart. If you want to integrate the remote changes,\n"
304 "use 'git pull' before pushing again.\n"
Christopher Tiwaldf25950f2012-03-20 00:31:33 -0400305 "See the 'Note about fast-forwards' in 'git push --help' for details.");
306
Christopher Tiwaldf25950f2012-03-20 00:31:33 -0400307static const char message_advice_checkout_pull_push[] =
308 N_("Updates were rejected because a pushed branch tip is behind its remote\n"
Alex Henriec577d652023-07-12 22:41:15 -0600309 "counterpart. If you want to integrate the remote changes, use 'git pull'\n"
310 "before pushing again.\n"
Christopher Tiwaldf25950f2012-03-20 00:31:33 -0400311 "See the 'Note about fast-forwards' in 'git push --help' for details.");
312
Junio C Hamano75e5c0d2013-01-23 13:55:30 -0800313static const char message_advice_ref_fetch_first[] =
Alex Henriec577d652023-07-12 22:41:15 -0600314 N_("Updates were rejected because the remote contains work that you do not\n"
315 "have locally. This is usually caused by another repository pushing to\n"
316 "the same ref. If you want to integrate the remote changes, use\n"
317 "'git pull' before pushing again.\n"
Junio C Hamano75e5c0d2013-01-23 13:55:30 -0800318 "See the 'Note about fast-forwards' in 'git push --help' for details.");
319
Chris Rorvickb24e6042012-11-29 19:41:34 -0600320static const char message_advice_ref_already_exists[] =
Junio C Hamanob4cf8db2013-01-24 21:09:00 -0800321 N_("Updates were rejected because the tag already exists in the remote.");
Chris Rorvickb24e6042012-11-29 19:41:34 -0600322
Junio C Hamano75e5c0d2013-01-23 13:55:30 -0800323static const char message_advice_ref_needs_force[] =
324 N_("You cannot update a remote ref that points at a non-commit object,\n"
325 "or update a remote ref to make it point at a non-commit object,\n"
326 "without using the '--force' option.\n");
Christopher Tiwaldf25950f2012-03-20 00:31:33 -0400327
Srinidhi Kaushik3b990aa2020-10-03 17:40:45 +0530328static const char message_advice_ref_needs_update[] =
Alex Henriec577d652023-07-12 22:41:15 -0600329 N_("Updates were rejected because the tip of the remote-tracking branch has\n"
330 "been updated since the last checkout. If you want to integrate the\n"
331 "remote changes, use 'git pull' before pushing again.\n"
332 "See the 'Note about fast-forwards' in 'git push --help' for details.");
Srinidhi Kaushik3b990aa2020-10-03 17:40:45 +0530333
Christopher Tiwaldf25950f2012-03-20 00:31:33 -0400334static void advise_pull_before_push(void)
335{
Ben Boeckeled9bff02021-08-23 12:44:00 +0200336 if (!advice_enabled(ADVICE_PUSH_NON_FF_CURRENT) || !advice_enabled(ADVICE_PUSH_UPDATE_REJECTED))
Christopher Tiwaldf25950f2012-03-20 00:31:33 -0400337 return;
338 advise(_(message_advice_pull_before_push));
339}
340
Christopher Tiwaldf25950f2012-03-20 00:31:33 -0400341static void advise_checkout_pull_push(void)
342{
Ben Boeckeled9bff02021-08-23 12:44:00 +0200343 if (!advice_enabled(ADVICE_PUSH_NON_FF_MATCHING) || !advice_enabled(ADVICE_PUSH_UPDATE_REJECTED))
Christopher Tiwaldf25950f2012-03-20 00:31:33 -0400344 return;
345 advise(_(message_advice_checkout_pull_push));
346}
347
Chris Rorvickb24e6042012-11-29 19:41:34 -0600348static void advise_ref_already_exists(void)
349{
Ben Boeckeled9bff02021-08-23 12:44:00 +0200350 if (!advice_enabled(ADVICE_PUSH_ALREADY_EXISTS) || !advice_enabled(ADVICE_PUSH_UPDATE_REJECTED))
Chris Rorvickb4505682012-12-02 21:27:51 -0600351 return;
Chris Rorvickb24e6042012-11-29 19:41:34 -0600352 advise(_(message_advice_ref_already_exists));
353}
354
Junio C Hamano75e5c0d2013-01-23 13:55:30 -0800355static void advise_ref_fetch_first(void)
356{
Ben Boeckeled9bff02021-08-23 12:44:00 +0200357 if (!advice_enabled(ADVICE_PUSH_FETCH_FIRST) || !advice_enabled(ADVICE_PUSH_UPDATE_REJECTED))
Junio C Hamano75e5c0d2013-01-23 13:55:30 -0800358 return;
359 advise(_(message_advice_ref_fetch_first));
360}
361
362static void advise_ref_needs_force(void)
363{
Ben Boeckeled9bff02021-08-23 12:44:00 +0200364 if (!advice_enabled(ADVICE_PUSH_NEEDS_FORCE) || !advice_enabled(ADVICE_PUSH_UPDATE_REJECTED))
Junio C Hamano75e5c0d2013-01-23 13:55:30 -0800365 return;
366 advise(_(message_advice_ref_needs_force));
367}
368
Srinidhi Kaushik3b990aa2020-10-03 17:40:45 +0530369static void advise_ref_needs_update(void)
370{
Ben Boeckeled9bff02021-08-23 12:44:00 +0200371 if (!advice_enabled(ADVICE_PUSH_REF_NEEDS_UPDATE) || !advice_enabled(ADVICE_PUSH_UPDATE_REJECTED))
Srinidhi Kaushik3b990aa2020-10-03 17:40:45 +0530372 return;
373 advise(_(message_advice_ref_needs_update));
374}
375
Brandon Williamsaa402892018-05-16 15:58:16 -0700376static int push_with_options(struct transport *transport, struct refspec *rs,
377 int flags)
Daniel Barkalowfb0cc872009-11-18 02:42:22 +0100378{
379 int err;
Chris Rorvick10643d42012-11-29 19:41:33 -0600380 unsigned int reject_reasons;
Johannes Schindelind192fa52020-04-24 14:20:08 +0000381 char *anon_url = transport_anonymize_url(transport->url);
Tay Ray Chuan8afd8dc2010-02-24 20:50:24 +0800382
Tay Ray Chuan78381062010-02-24 20:50:27 +0800383 transport_set_verbosity(transport, verbosity, progress);
Eric Wongc915f112016-02-03 04:09:14 +0000384 transport->family = family;
Tay Ray Chuan8afd8dc2010-02-24 20:50:24 +0800385
Daniel Barkalowfb0cc872009-11-18 02:42:22 +0100386 if (receivepack)
387 transport_set_option(transport,
388 TRANS_OPT_RECEIVEPACK, receivepack);
Nguyễn Thái Ngọc Duyf7c815c2013-08-12 20:55:55 +0700389 transport_set_option(transport, TRANS_OPT_THIN, thin ? "yes" : NULL);
Daniel Barkalowfb0cc872009-11-18 02:42:22 +0100390
Junio C Hamano91048a92013-07-09 11:01:06 -0700391 if (!is_empty_cas(&cas)) {
392 if (!transport->smart_options)
393 die("underlying transport does not support --%s option",
Junio C Hamanoa762af32023-12-19 11:26:25 -0800394 "force-with-lease");
Junio C Hamano91048a92013-07-09 11:01:06 -0700395 transport->smart_options->cas = &cas;
396 }
397
Tay Ray Chuan8afd8dc2010-02-24 20:50:24 +0800398 if (verbosity > 0)
Johannes Schindelind192fa52020-04-24 14:20:08 +0000399 fprintf(stderr, _("Pushing to %s\n"), anon_url);
Josh Steadmon25e4b802019-10-02 16:49:29 -0700400 trace2_region_enter("push", "transport_push", the_repository);
Nguyễn Thái Ngọc Duy6c6d5d02018-11-10 06:48:55 +0100401 err = transport_push(the_repository, transport,
402 rs, flags, &reject_reasons);
Josh Steadmon25e4b802019-10-02 16:49:29 -0700403 trace2_region_leave("push", "transport_push", the_repository);
Ryan Dammrose960786e2018-04-21 12:10:00 +0200404 if (err != 0) {
405 fprintf(stderr, "%s", push_get_color(PUSH_COLOR_ERROR));
Johannes Schindelind192fa52020-04-24 14:20:08 +0000406 error(_("failed to push some refs to '%s'"), anon_url);
Ryan Dammrose960786e2018-04-21 12:10:00 +0200407 fprintf(stderr, "%s", push_get_color(PUSH_COLOR_RESET));
408 }
Tay Ray Chuan53970b92009-12-04 07:31:44 +0800409
Daniel Barkalowfb0cc872009-11-18 02:42:22 +0100410 err |= transport_disconnect(transport);
Johannes Schindelind192fa52020-04-24 14:20:08 +0000411 free(anon_url);
Daniel Barkalowfb0cc872009-11-18 02:42:22 +0100412 if (!err)
413 return 0;
414
Chris Rorvick10643d42012-11-29 19:41:33 -0600415 if (reject_reasons & REJECT_NON_FF_HEAD) {
Christopher Tiwaldf25950f2012-03-20 00:31:33 -0400416 advise_pull_before_push();
Chris Rorvick10643d42012-11-29 19:41:33 -0600417 } else if (reject_reasons & REJECT_NON_FF_OTHER) {
Junio C Hamanob2ed9442013-01-04 16:02:29 -0800418 advise_checkout_pull_push();
Chris Rorvickb24e6042012-11-29 19:41:34 -0600419 } else if (reject_reasons & REJECT_ALREADY_EXISTS) {
420 advise_ref_already_exists();
Junio C Hamano75e5c0d2013-01-23 13:55:30 -0800421 } else if (reject_reasons & REJECT_FETCH_FIRST) {
422 advise_ref_fetch_first();
423 } else if (reject_reasons & REJECT_NEEDS_FORCE) {
424 advise_ref_needs_force();
Srinidhi Kaushik3b990aa2020-10-03 17:40:45 +0530425 } else if (reject_reasons & REJECT_REF_NEEDS_UPDATE) {
426 advise_ref_needs_update();
Daniel Barkalowfb0cc872009-11-18 02:42:22 +0100427 }
428
429 return 1;
430}
431
Jeff King5b9427e2020-09-30 08:29:09 -0400432static int do_push(int flags,
Thomas Gummerer8e4c8af2019-09-02 19:08:28 +0100433 const struct string_list *push_options,
434 struct remote *remote)
Linus Torvalds755225d2006-04-29 21:22:49 -0700435{
Daniel Barkalow5751f492007-05-12 11:45:53 -0400436 int i, errs;
Michael J Gruber20346232009-06-09 18:01:34 +0200437 const char **url;
438 int url_nr;
Brandon Williamsaa402892018-05-16 15:58:16 -0700439 struct refspec *push_refspec = &rs;
Linus Torvalds755225d2006-04-29 21:22:49 -0700440
Stefan Bellerf6a4e612016-07-14 14:49:47 -0700441 if (push_options->nr)
442 flags |= TRANSPORT_PUSH_OPTIONS;
443
Brandon Williamsaa402892018-05-16 15:58:16 -0700444 if (!push_refspec->nr && !(flags & TRANSPORT_PUSH_ALL)) {
445 if (remote->push.nr) {
446 push_refspec = &remote->push;
Finn Arne Gangstad52153742009-03-16 16:42:51 +0100447 } else if (!(flags & TRANSPORT_PUSH_MIRROR))
Tao Klerks05d57752022-04-29 09:56:46 +0000448 setup_default_push_refspecs(&flags, remote);
Daniel Barkalow5751f492007-05-12 11:45:53 -0400449 }
Junio C Hamanofd1d1b02007-04-06 23:04:53 -0700450 errs = 0;
Junio C Hamano135dade2012-03-30 16:07:12 -0700451 url_nr = push_url_of_remote(remote, &url);
Daniel Barkalowfb0cc872009-11-18 02:42:22 +0100452 if (url_nr) {
453 for (i = 0; i < url_nr; i++) {
454 struct transport *transport =
455 transport_get(remote, url[i]);
Stefan Bellerf6a4e612016-07-14 14:49:47 -0700456 if (flags & TRANSPORT_PUSH_OPTIONS)
457 transport->push_options = push_options;
Brandon Williamsaa402892018-05-16 15:58:16 -0700458 if (push_with_options(transport, push_refspec, flags))
Daniel Barkalowfb0cc872009-11-18 02:42:22 +0100459 errs++;
Matthieu Moy07436e42009-08-08 09:51:08 +0200460 }
Daniel Barkalowfb0cc872009-11-18 02:42:22 +0100461 } else {
462 struct transport *transport =
463 transport_get(remote, NULL);
Stefan Bellerf6a4e612016-07-14 14:49:47 -0700464 if (flags & TRANSPORT_PUSH_OPTIONS)
465 transport->push_options = push_options;
Brandon Williamsaa402892018-05-16 15:58:16 -0700466 if (push_with_options(transport, push_refspec, flags))
Daniel Barkalowfb0cc872009-11-18 02:42:22 +0100467 errs++;
Linus Torvalds755225d2006-04-29 21:22:49 -0700468 }
Junio C Hamanofd1d1b02007-04-06 23:04:53 -0700469 return !!errs;
Linus Torvalds755225d2006-04-29 21:22:49 -0700470}
471
Fredrik Gustafssond2b17b32011-08-20 00:08:47 +0200472static int option_parse_recurse_submodules(const struct option *opt,
473 const char *arg, int unset)
474{
Mike Croweb33a15b2015-11-17 11:05:56 +0000475 int *recurse_submodules = opt->value;
Heiko Voigteb21c732012-03-29 09:21:24 +0200476
Mike Croweb33a15b2015-11-17 11:05:56 +0000477 if (unset)
478 *recurse_submodules = RECURSE_SUBMODULES_OFF;
Jonathan Tane62f7792022-11-14 13:37:12 -0800479 else {
480 if (!strcmp(arg, "only-is-on-demand")) {
481 if (*recurse_submodules == RECURSE_SUBMODULES_ONLY) {
482 warning(_("recursing into submodule with push.recurseSubmodules=only; using on-demand instead"));
483 *recurse_submodules = RECURSE_SUBMODULES_ON_DEMAND;
484 }
485 } else {
486 *recurse_submodules = parse_push_recurse_submodules_arg(opt->long_name, arg);
487 }
488 }
Fredrik Gustafssond2b17b32011-08-20 00:08:47 +0200489
490 return 0;
491}
492
Dave Borowitz68c757f2015-08-19 11:26:47 -0400493static void set_push_cert_flags(int *flags, int v)
494{
495 switch (v) {
496 case SEND_PACK_PUSH_CERT_NEVER:
497 *flags &= ~(TRANSPORT_PUSH_CERT_ALWAYS | TRANSPORT_PUSH_CERT_IF_ASKED);
498 break;
499 case SEND_PACK_PUSH_CERT_ALWAYS:
500 *flags |= TRANSPORT_PUSH_CERT_ALWAYS;
501 *flags &= ~TRANSPORT_PUSH_CERT_IF_ASKED;
502 break;
503 case SEND_PACK_PUSH_CERT_IF_ASKED:
504 *flags |= TRANSPORT_PUSH_CERT_IF_ASKED;
505 *flags &= ~TRANSPORT_PUSH_CERT_ALWAYS;
506 break;
507 }
508}
509
510
Glen Chooa4e7e312023-06-28 19:26:22 +0000511static int git_push_config(const char *k, const char *v,
512 const struct config_context *ctx, void *cb)
Michael J Gruberb9459012014-10-22 16:57:49 +0200513{
Ryan Dammrose960786e2018-04-21 12:10:00 +0200514 const char *slot_name;
Dave Olszewskia8bc2692015-02-16 01:16:19 -0500515 int *flags = cb;
Dave Olszewskia8bc2692015-02-16 01:16:19 -0500516
517 if (!strcmp(k, "push.followtags")) {
518 if (git_config_bool(k, v))
519 *flags |= TRANSPORT_PUSH_FOLLOW_TAGS;
520 else
521 *flags &= ~TRANSPORT_PUSH_FOLLOW_TAGS;
522 return 0;
Tao Klerks05d57752022-04-29 09:56:46 +0000523 } else if (!strcmp(k, "push.autosetupremote")) {
524 if (git_config_bool(k, v))
525 *flags |= TRANSPORT_PUSH_AUTO_UPSTREAM;
526 return 0;
Dave Borowitz68c757f2015-08-19 11:26:47 -0400527 } else if (!strcmp(k, "push.gpgsign")) {
Jeff King37e8a342023-12-07 02:26:22 -0500528 switch (git_parse_maybe_bool(v)) {
529 case 0:
530 set_push_cert_flags(flags, SEND_PACK_PUSH_CERT_NEVER);
531 break;
532 case 1:
533 set_push_cert_flags(flags, SEND_PACK_PUSH_CERT_ALWAYS);
534 break;
535 default:
536 if (!strcasecmp(v, "if-asked"))
537 set_push_cert_flags(flags, SEND_PACK_PUSH_CERT_IF_ASKED);
538 else
539 return error(_("invalid value for '%s'"), k);
Dave Borowitz68c757f2015-08-19 11:26:47 -0400540 }
Mike Croweb33a15b2015-11-17 11:05:56 +0000541 } else if (!strcmp(k, "push.recursesubmodules")) {
Jeff King37e8a342023-12-07 02:26:22 -0500542 recurse_submodules = parse_push_recurse_submodules_arg(k, v);
Stefan Beller4e53d6a2017-05-31 17:30:49 -0700543 } else if (!strcmp(k, "submodule.recurse")) {
544 int val = git_config_bool(k, v) ?
545 RECURSE_SUBMODULES_ON_DEMAND : RECURSE_SUBMODULES_OFF;
546 recurse_submodules = val;
Marius Paligad8052752017-10-23 13:44:49 +0200547 } else if (!strcmp(k, "push.pushoption")) {
548 if (!v)
549 return config_error_nonbool(k);
550 else
551 if (!*v)
552 string_list_clear(&push_options_config, 0);
553 else
554 string_list_append(&push_options_config, v);
555 return 0;
Ryan Dammrose960786e2018-04-21 12:10:00 +0200556 } else if (!strcmp(k, "color.push")) {
557 push_use_color = git_config_colorbool(k, v);
558 return 0;
559 } else if (skip_prefix(k, "color.push.", &slot_name)) {
560 int slot = parse_push_color_slot(slot_name);
561 if (slot < 0)
562 return 0;
563 if (!v)
564 return config_error_nonbool(k);
565 return color_parse(v, push_colors[slot]);
Srinidhi Kaushik3b990aa2020-10-03 17:40:45 +0530566 } else if (!strcmp(k, "push.useforceifincludes")) {
567 if (git_config_bool(k, v))
568 *flags |= TRANSPORT_PUSH_FORCE_IF_INCLUDES;
569 else
570 *flags &= ~TRANSPORT_PUSH_FORCE_IF_INCLUDES;
571 return 0;
Dave Olszewskia8bc2692015-02-16 01:16:19 -0500572 }
573
Glen Chooa4e7e312023-06-28 19:26:22 +0000574 return git_default_config(k, v, ctx, NULL);
Michael J Gruberb9459012014-10-22 16:57:49 +0200575}
576
Linus Torvaldsa633fca2006-07-28 22:44:25 -0700577int cmd_push(int argc, const char **argv, const char *prefix)
Linus Torvalds755225d2006-04-29 21:22:49 -0700578{
Daniel Barkalow9b288512007-09-10 23:03:04 -0400579 int flags = 0;
Daniel Barkalow378c4832007-11-04 22:35:37 -0500580 int tags = 0;
Dave Borowitz30261092015-08-19 11:26:46 -0400581 int push_cert = -1;
Paolo Bonzini84bb2df2008-04-17 13:17:20 +0200582 int rc;
Daniel Barkalow5751f492007-05-12 11:45:53 -0400583 const char *repo = NULL; /* default repository */
Marius Paligad8052752017-10-23 13:44:49 +0200584 struct string_list push_options_cmdline = STRING_LIST_INIT_DUP;
585 struct string_list *push_options;
Brandon Williams54cc8ac2017-03-31 16:56:22 -0700586 const struct string_list_item *item;
Thomas Gummerer8e4c8af2019-09-02 19:08:28 +0100587 struct remote *remote;
Stefan Bellerf6a4e612016-07-14 14:49:47 -0700588
Daniel Barkalow378c4832007-11-04 22:35:37 -0500589 struct option options[] = {
Tay Ray Chuan8afd8dc2010-02-24 20:50:24 +0800590 OPT__VERBOSITY(&verbosity),
Nguyễn Thái Ngọc Duy78dafaa2012-08-20 19:32:33 +0700591 OPT_STRING( 0 , "repo", &repo, N_("repository"), N_("repository")),
Teng Long425b4d72023-05-06 19:34:08 +0800592 OPT_BIT( 0 , "all", &flags, N_("push all branches"), TRANSPORT_PUSH_ALL),
593 OPT_ALIAS( 0 , "branches", "all"),
Nguyễn Thái Ngọc Duy78dafaa2012-08-20 19:32:33 +0700594 OPT_BIT( 0 , "mirror", &flags, N_("mirror all refs"),
Michele Ballabioc29c1b42008-07-20 14:02:20 +0200595 (TRANSPORT_PUSH_MIRROR|TRANSPORT_PUSH_FORCE)),
Patrick Steinhardt38a25592015-12-14 16:23:04 +0100596 OPT_BOOL('d', "delete", &deleterefs, N_("delete refs")),
Teng Long425b4d72023-05-06 19:34:08 +0800597 OPT_BOOL( 0 , "tags", &tags, N_("push tags (can't be used with --all or --branches or --mirror)")),
Nguyễn Thái Ngọc Duy78dafaa2012-08-20 19:32:33 +0700598 OPT_BIT('n' , "dry-run", &flags, N_("dry run"), TRANSPORT_PUSH_DRY_RUN),
599 OPT_BIT( 0, "porcelain", &flags, N_("machine-readable output"), TRANSPORT_PUSH_PORCELAIN),
600 OPT_BIT('f', "force", &flags, N_("force updates"), TRANSPORT_PUSH_FORCE),
Junio C Hamanoa762af32023-12-19 11:26:25 -0800601 OPT_CALLBACK_F(0, "force-with-lease", &cas, N_("<refname>:<expect>"),
Denton Liu203c8532020-04-28 04:36:28 -0400602 N_("require old value of ref to be at this value"),
603 PARSE_OPT_OPTARG | PARSE_OPT_LITERAL_ARGHELP, parseopt_push_cas_option),
Srinidhi Kaushik3b990aa2020-10-03 17:40:45 +0530604 OPT_BIT(0, TRANS_OPT_FORCE_IF_INCLUDES, &flags,
605 N_("require remote updates to be integrated locally"),
606 TRANSPORT_PUSH_FORCE_IF_INCLUDES),
Denton Liuce9baf22020-04-27 02:44:08 -0400607 OPT_CALLBACK(0, "recurse-submodules", &recurse_submodules, "(check|on-demand|no)",
608 N_("control recursive pushing of submodules"), option_parse_recurse_submodules),
Nguyễn Thái Ngọc Duyf1e1bdd2018-02-09 18:02:10 +0700609 OPT_BOOL_F( 0 , "thin", &thin, N_("use thin pack"), PARSE_OPT_NOCOMPLETE),
Nguyễn Thái Ngọc Duy78dafaa2012-08-20 19:32:33 +0700610 OPT_STRING( 0 , "receive-pack", &receivepack, "receive-pack", N_("receive pack program")),
611 OPT_STRING( 0 , "exec", &receivepack, "receive-pack", N_("receive pack program")),
612 OPT_BIT('u', "set-upstream", &flags, N_("set upstream for git pull/status"),
Ilari Liusvaarae9fcd1e2010-01-16 23:45:31 +0200613 TRANSPORT_PUSH_SET_UPSTREAM),
Nguyễn Thái Ngọc Duy78dafaa2012-08-20 19:32:33 +0700614 OPT_BOOL(0, "progress", &progress, N_("force progress reporting")),
615 OPT_BIT(0, "prune", &flags, N_("prune locally removed refs"),
Felipe Contreras6ddba5e2012-02-23 00:43:41 +0200616 TRANSPORT_PUSH_PRUNE),
Aaron Schrabec555592013-01-13 00:17:03 -0500617 OPT_BIT(0, "no-verify", &flags, N_("bypass pre-push hook"), TRANSPORT_PUSH_NO_HOOK),
Junio C Hamanoc2aba152013-03-04 12:09:50 -0800618 OPT_BIT(0, "follow-tags", &flags, N_("push missing but relevant tags"),
619 TRANSPORT_PUSH_FOLLOW_TAGS),
Denton Liu203c8532020-04-28 04:36:28 -0400620 OPT_CALLBACK_F(0, "signed", &push_cert, "(yes|no|if-asked)", N_("GPG sign the push"),
621 PARSE_OPT_OPTARG, option_parse_push_signed),
Jeff Kingd16c33b2015-02-16 01:12:04 -0500622 OPT_BIT(0, "atomic", &flags, N_("request atomic transaction on remote side"), TRANSPORT_PUSH_ATOMIC),
Marius Paligad8052752017-10-23 13:44:49 +0200623 OPT_STRING_LIST('o', "push-option", &push_options_cmdline, N_("server-specific"), N_("option to transmit")),
Junio C Hamanoae2c9122023-07-18 14:34:33 -0700624 OPT_IPVERSION(&family),
Daniel Barkalow378c4832007-11-04 22:35:37 -0500625 OPT_END()
626 };
Linus Torvalds755225d2006-04-29 21:22:49 -0700627
Jeff Kingbbc30f92011-02-24 09:30:19 -0500628 packet_trace_identity("push");
Jeff King06c21e182015-02-16 01:13:25 -0500629 git_config(git_push_config, &flags);
Stephen Boyd37782922009-05-23 11:53:12 -0700630 argc = parse_options(argc, argv, prefix, options, push_usage, 0);
Marius Paligad8052752017-10-23 13:44:49 +0200631 push_options = (push_options_cmdline.nr
632 ? &push_options_cmdline
633 : &push_options_config);
Dave Borowitz68c757f2015-08-19 11:26:47 -0400634 set_push_cert_flags(&flags, push_cert);
Daniel Barkalow378c4832007-11-04 22:35:37 -0500635
René Scharfeb3bf4702023-12-06 12:51:55 +0100636 die_for_incompatible_opt4(deleterefs, "--delete",
637 tags, "--tags",
638 flags & TRANSPORT_PUSH_ALL, "--all/--branches",
639 flags & TRANSPORT_PUSH_MIRROR, "--mirror");
Jan Krügerf517f1f2009-12-30 20:57:42 +0100640 if (deleterefs && argc < 2)
Ævar Arnfjörð Bjarmason8352d292011-02-22 23:42:11 +0000641 die(_("--delete doesn't make sense without any refs"));
Jan Krügerf517f1f2009-12-30 20:57:42 +0100642
Mike Croweb33a15b2015-11-17 11:05:56 +0000643 if (recurse_submodules == RECURSE_SUBMODULES_CHECK)
644 flags |= TRANSPORT_RECURSE_SUBMODULES_CHECK;
645 else if (recurse_submodules == RECURSE_SUBMODULES_ON_DEMAND)
646 flags |= TRANSPORT_RECURSE_SUBMODULES_ON_DEMAND;
Brandon Williams225e8bf2016-12-19 10:25:33 -0800647 else if (recurse_submodules == RECURSE_SUBMODULES_ONLY)
648 flags |= TRANSPORT_RECURSE_SUBMODULES_ONLY;
Mike Croweb33a15b2015-11-17 11:05:56 +0000649
Daniel Barkalow378c4832007-11-04 22:35:37 -0500650 if (tags)
Brandon Williamsaa402892018-05-16 15:58:16 -0700651 refspec_append(&rs, "refs/tags/*");
Daniel Barkalow378c4832007-11-04 22:35:37 -0500652
653 if (argc > 0) {
654 repo = argv[0];
Junio C Hamanoca024652013-12-03 15:41:15 -0800655 set_refspecs(argv + 1, argc - 1, repo);
Linus Torvalds755225d2006-04-29 21:22:49 -0700656 }
Daniel Barkalow8558fd92007-05-25 01:20:56 -0400657
Thomas Gummerer8e4c8af2019-09-02 19:08:28 +0100658 remote = pushremote_get(repo);
659 if (!remote) {
660 if (repo)
661 die(_("bad repository '%s'"), repo);
662 die(_("No configured push destination.\n"
663 "Either specify the URL from the command-line or configure a remote repository using\n"
664 "\n"
665 " git remote add <name> <url>\n"
666 "\n"
667 "and then push using the remote name\n"
668 "\n"
669 " git push <name>\n"));
670 }
671
672 if (remote->mirror)
673 flags |= (TRANSPORT_PUSH_MIRROR|TRANSPORT_PUSH_FORCE);
674
675 if (flags & TRANSPORT_PUSH_ALL) {
Thomas Gummerer8e4c8af2019-09-02 19:08:28 +0100676 if (argc >= 2)
677 die(_("--all can't be combined with refspecs"));
678 }
679 if (flags & TRANSPORT_PUSH_MIRROR) {
Thomas Gummerer8e4c8af2019-09-02 19:08:28 +0100680 if (argc >= 2)
681 die(_("--mirror can't be combined with refspecs"));
682 }
Thomas Gummerer8e4c8af2019-09-02 19:08:28 +0100683
Srinidhi Kaushik3b990aa2020-10-03 17:40:45 +0530684 if (!is_empty_cas(&cas) && (flags & TRANSPORT_PUSH_FORCE_IF_INCLUDES))
685 cas.use_force_if_includes = 1;
686
Marius Paligad8052752017-10-23 13:44:49 +0200687 for_each_string_list_item(item, push_options)
Stefan Bellerf6a4e612016-07-14 14:49:47 -0700688 if (strchr(item->string, '\n'))
689 die(_("push options must not have new line characters"));
690
Jeff King5b9427e2020-09-30 08:29:09 -0400691 rc = do_push(flags, push_options, remote);
Marius Paligad8052752017-10-23 13:44:49 +0200692 string_list_clear(&push_options_cmdline, 0);
693 string_list_clear(&push_options_config, 0);
Paolo Bonzini84bb2df2008-04-17 13:17:20 +0200694 if (rc == -1)
Andy Whitcroft94c89ba2007-11-09 23:32:25 +0000695 usage_with_options(push_usage, options);
Paolo Bonzini84bb2df2008-04-17 13:17:20 +0200696 else
697 return rc;
Linus Torvalds755225d2006-04-29 21:22:49 -0700698}