blob: db9ba30b08c221ac2290b1ffc939713fe378e666 [file] [log] [blame]
Linus Torvalds755225d2006-04-29 21:22:49 -07001/*
2 * "git push"
3 */
4#include "cache.h"
5#include "refs.h"
6#include "run-command.h"
7#include "builtin.h"
Daniel Barkalow5751f492007-05-12 11:45:53 -04008#include "remote.h"
Daniel Barkalow9b288512007-09-10 23:03:04 -04009#include "transport.h"
Daniel Barkalow378c4832007-11-04 22:35:37 -050010#include "parse-options.h"
Fredrik Gustafssond2b17b32011-08-20 00:08:47 +020011#include "submodule.h"
Linus Torvalds755225d2006-04-29 21:22:49 -070012
Daniel Barkalow378c4832007-11-04 22:35:37 -050013static const char * const push_usage[] = {
Nguyễn Thái Ngọc Duy78dafaa2012-08-20 19:32:33 +070014 N_("git push [<options>] [<repository> [<refspec>...]]"),
Daniel Barkalow378c4832007-11-04 22:35:37 -050015 NULL,
16};
Linus Torvalds755225d2006-04-29 21:22:49 -070017
Michele Ballabioc29c1b42008-07-20 14:02:20 +020018static int thin;
Jan Krügerf517f1f2009-12-30 20:57:42 +010019static int deleterefs;
Uwe Kleine-Königd23842f2007-01-19 13:49:27 +010020static const char *receivepack;
Tay Ray Chuan8afd8dc2010-02-24 20:50:24 +080021static int verbosity;
Clemens Buchacher01fdc212012-02-13 21:17:15 +010022static int progress = -1;
Linus Torvalds755225d2006-04-29 21:22:49 -070023
David Rientjes96f1e582006-08-15 10:23:48 -070024static const char **refspec;
25static int refspec_nr;
Jared Hance8a883b02010-07-31 08:54:55 -040026static int refspec_alloc;
Christopher Tiwaldf25950f2012-03-20 00:31:33 -040027static int default_matching_used;
Linus Torvalds755225d2006-04-29 21:22:49 -070028
29static void add_refspec(const char *ref)
30{
Jared Hance8a883b02010-07-31 08:54:55 -040031 refspec_nr++;
32 ALLOC_GROW(refspec, refspec_nr, refspec_alloc);
33 refspec[refspec_nr-1] = ref;
Linus Torvalds755225d2006-04-29 21:22:49 -070034}
35
Linus Torvalds755225d2006-04-29 21:22:49 -070036static void set_refspecs(const char **refs, int nr)
37{
Daniel Barkalow8558fd92007-05-25 01:20:56 -040038 int i;
39 for (i = 0; i < nr; i++) {
40 const char *ref = refs[i];
41 if (!strcmp("tag", ref)) {
42 char *tag;
43 int len;
44 if (nr <= ++i)
Ævar Arnfjörð Bjarmason8352d292011-02-22 23:42:11 +000045 die(_("tag shorthand without <tag>"));
Daniel Barkalow8558fd92007-05-25 01:20:56 -040046 len = strlen(refs[i]) + 11;
Jan Krügerf517f1f2009-12-30 20:57:42 +010047 if (deleterefs) {
48 tag = xmalloc(len+1);
49 strcpy(tag, ":refs/tags/");
50 } else {
51 tag = xmalloc(len);
52 strcpy(tag, "refs/tags/");
53 }
Daniel Barkalow8558fd92007-05-25 01:20:56 -040054 strcat(tag, refs[i]);
55 ref = tag;
Jan Krügerf517f1f2009-12-30 20:57:42 +010056 } else if (deleterefs && !strchr(ref, ':')) {
57 char *delref;
58 int len = strlen(ref)+1;
Jeff King7b48c172010-01-29 05:31:30 -050059 delref = xmalloc(len+1);
Jan Krügerf517f1f2009-12-30 20:57:42 +010060 strcpy(delref, ":");
61 strcat(delref, ref);
62 ref = delref;
63 } else if (deleterefs)
Ævar Arnfjörð Bjarmason8352d292011-02-22 23:42:11 +000064 die(_("--delete only accepts plain target ref names"));
Daniel Barkalow8558fd92007-05-25 01:20:56 -040065 add_refspec(ref);
Linus Torvalds755225d2006-04-29 21:22:49 -070066 }
Linus Torvalds755225d2006-04-29 21:22:49 -070067}
68
Junio C Hamano135dade2012-03-30 16:07:12 -070069static int push_url_of_remote(struct remote *remote, const char ***url_p)
70{
71 if (remote->pushurl_nr) {
72 *url_p = remote->pushurl;
73 return remote->pushurl_nr;
74 }
75 *url_p = remote->url;
76 return remote->url_nr;
77}
78
Matthieu Moyb55e6772012-04-24 09:50:03 +020079static NORETURN int die_push_simple(struct branch *branch, struct remote *remote) {
80 /*
81 * There's no point in using shorten_unambiguous_ref here,
82 * as the ambiguity would be on the remote side, not what
83 * we have locally. Plus, this is supposed to be the simple
84 * mode. If the user is doing something crazy like setting
85 * upstream to a non-branch, we should probably be showing
86 * them the big ugly fully qualified ref.
87 */
88 const char *advice_maybe = "";
89 const char *short_upstream =
90 skip_prefix(branch->merge[0]->src, "refs/heads/");
91
92 if (!short_upstream)
93 short_upstream = branch->merge[0]->src;
94 /*
95 * Don't show advice for people who explicitely set
96 * push.default.
97 */
98 if (push_default == PUSH_DEFAULT_UNSPECIFIED)
99 advice_maybe = _("\n"
100 "To choose either option permanently, "
101 "see push.default in 'git help config'.");
102 die(_("The upstream branch of your current branch does not match\n"
103 "the name of your current branch. To push to the upstream branch\n"
104 "on the remote, use\n"
105 "\n"
106 " git push %s HEAD:%s\n"
107 "\n"
108 "To push to the branch of the same name on the remote, use\n"
109 "\n"
110 " git push %s %s\n"
111 "%s"),
112 remote->name, short_upstream,
113 remote->name, branch->name, advice_maybe);
114}
115
116static void setup_push_upstream(struct remote *remote, int simple)
Finn Arne Gangstad52153742009-03-16 16:42:51 +0100117{
118 struct strbuf refspec = STRBUF_INIT;
119 struct branch *branch = branch_get(NULL);
120 if (!branch)
Junio C Hamano6c80cd22011-04-01 17:55:55 -0700121 die(_("You are not currently on a branch.\n"
Matthieu Moyec8460b2011-03-02 21:12:10 +0100122 "To push the history leading to the current (detached HEAD)\n"
123 "state now, use\n"
124 "\n"
Junio C Hamano6c80cd22011-04-01 17:55:55 -0700125 " git push %s HEAD:<name-of-remote-branch>\n"),
Matthieu Moyec8460b2011-03-02 21:12:10 +0100126 remote->name);
Junio C Hamano135dade2012-03-30 16:07:12 -0700127 if (!branch->merge_nr || !branch->merge || !branch->remote_name)
Junio C Hamano6c80cd22011-04-01 17:55:55 -0700128 die(_("The current branch %s has no upstream branch.\n"
Matthieu Moyec8460b2011-03-02 21:12:10 +0100129 "To push the current branch and set the remote as upstream, use\n"
130 "\n"
Junio C Hamano6c80cd22011-04-01 17:55:55 -0700131 " git push --set-upstream %s %s\n"),
Matthieu Moyec8460b2011-03-02 21:12:10 +0100132 branch->name,
133 remote->name,
Finn Arne Gangstad52153742009-03-16 16:42:51 +0100134 branch->name);
135 if (branch->merge_nr != 1)
Junio C Hamano6c80cd22011-04-01 17:55:55 -0700136 die(_("The current branch %s has multiple upstream branches, "
Ævar Arnfjörð Bjarmason8352d292011-02-22 23:42:11 +0000137 "refusing to push."), branch->name);
Junio C Hamano135dade2012-03-30 16:07:12 -0700138 if (strcmp(branch->remote_name, remote->name))
139 die(_("You are pushing to remote '%s', which is not the upstream of\n"
140 "your current branch '%s', without telling me what to push\n"
141 "to update which remote branch."),
142 remote->name, branch->name);
Matthieu Moyb55e6772012-04-24 09:50:03 +0200143 if (simple && strcmp(branch->refname, branch->merge[0]->src))
144 die_push_simple(branch, remote);
Junio C Hamano135dade2012-03-30 16:07:12 -0700145
Finn Arne Gangstad52153742009-03-16 16:42:51 +0100146 strbuf_addf(&refspec, "%s:%s", branch->name, branch->merge[0]->src);
147 add_refspec(refspec.buf);
148}
149
Matthieu Moyf2c2c902012-06-24 13:01:37 +0200150static char warn_unspecified_push_default_msg[] =
151N_("push.default is unset; its implicit value is changing in\n"
152 "Git 2.0 from 'matching' to 'simple'. To squelch this message\n"
153 "and maintain the current behavior after the default changes, use:\n"
154 "\n"
155 " git config --global push.default matching\n"
156 "\n"
157 "To squelch this message and adopt the new behavior now, use:\n"
158 "\n"
159 " git config --global push.default simple\n"
160 "\n"
161 "See 'git help config' and search for 'push.default' for further information.\n"
162 "(the 'simple' mode was introduced in Git 1.7.11. Use the similar mode\n"
163 "'current' instead of 'simple' if you sometimes use older versions of Git)");
164
165static void warn_unspecified_push_default_configuration(void)
166{
167 static int warn_once;
168
169 if (warn_once++)
170 return;
171 warning("%s\n", _(warn_unspecified_push_default_msg));
172}
173
Matthieu Moyec8460b2011-03-02 21:12:10 +0100174static void setup_default_push_refspecs(struct remote *remote)
Finn Arne Gangstad52153742009-03-16 16:42:51 +0100175{
Finn Arne Gangstad52153742009-03-16 16:42:51 +0100176 switch (push_default) {
Junio C Hamanobba0fd22009-07-18 17:19:47 -0700177 default:
Christopher Tiwaldf25950f2012-03-20 00:31:33 -0400178 case PUSH_DEFAULT_UNSPECIFIED:
179 default_matching_used = 1;
Matthieu Moyf2c2c902012-06-24 13:01:37 +0200180 warn_unspecified_push_default_configuration();
Christopher Tiwaldf25950f2012-03-20 00:31:33 -0400181 /* fallthru */
Finn Arne Gangstad52153742009-03-16 16:42:51 +0100182 case PUSH_DEFAULT_MATCHING:
183 add_refspec(":");
184 break;
185
Matthieu Moyb55e6772012-04-24 09:50:03 +0200186 case PUSH_DEFAULT_SIMPLE:
187 setup_push_upstream(remote, 1);
188 break;
189
Johan Herland53c40312011-02-16 01:54:24 +0100190 case PUSH_DEFAULT_UPSTREAM:
Matthieu Moyb55e6772012-04-24 09:50:03 +0200191 setup_push_upstream(remote, 0);
Finn Arne Gangstad52153742009-03-16 16:42:51 +0100192 break;
193
194 case PUSH_DEFAULT_CURRENT:
195 add_refspec("HEAD");
196 break;
197
198 case PUSH_DEFAULT_NOTHING:
Ævar Arnfjörð Bjarmason8352d292011-02-22 23:42:11 +0000199 die(_("You didn't specify any refspecs to push, and "
200 "push.default is \"nothing\"."));
Finn Arne Gangstad52153742009-03-16 16:42:51 +0100201 break;
202 }
203}
204
Christopher Tiwaldf25950f2012-03-20 00:31:33 -0400205static const char message_advice_pull_before_push[] =
206 N_("Updates were rejected because the tip of your current branch is behind\n"
207 "its remote counterpart. Merge the remote changes (e.g. 'git pull')\n"
208 "before pushing again.\n"
209 "See the 'Note about fast-forwards' in 'git push --help' for details.");
210
211static const char message_advice_use_upstream[] =
212 N_("Updates were rejected because a pushed branch tip is behind its remote\n"
213 "counterpart. If you did not intend to push that branch, you may want to\n"
Matthieu Moyf2c2c902012-06-24 13:01:37 +0200214 "specify branches to push or set the 'push.default' configuration variable\n"
215 "to 'simple', 'current' or 'upstream' to push only the current branch.");
Christopher Tiwaldf25950f2012-03-20 00:31:33 -0400216
217static const char message_advice_checkout_pull_push[] =
218 N_("Updates were rejected because a pushed branch tip is behind its remote\n"
219 "counterpart. Check out this branch and merge the remote changes\n"
220 "(e.g. 'git pull') before pushing again.\n"
221 "See the 'Note about fast-forwards' in 'git push --help' for details.");
222
223static void advise_pull_before_push(void)
224{
225 if (!advice_push_non_ff_current || !advice_push_nonfastforward)
226 return;
227 advise(_(message_advice_pull_before_push));
228}
229
230static void advise_use_upstream(void)
231{
232 if (!advice_push_non_ff_default || !advice_push_nonfastforward)
233 return;
234 advise(_(message_advice_use_upstream));
235}
236
237static void advise_checkout_pull_push(void)
238{
239 if (!advice_push_non_ff_matching || !advice_push_nonfastforward)
240 return;
241 advise(_(message_advice_checkout_pull_push));
242}
243
Daniel Barkalowfb0cc872009-11-18 02:42:22 +0100244static int push_with_options(struct transport *transport, int flags)
245{
246 int err;
247 int nonfastforward;
Tay Ray Chuan8afd8dc2010-02-24 20:50:24 +0800248
Tay Ray Chuan78381062010-02-24 20:50:27 +0800249 transport_set_verbosity(transport, verbosity, progress);
Tay Ray Chuan8afd8dc2010-02-24 20:50:24 +0800250
Daniel Barkalowfb0cc872009-11-18 02:42:22 +0100251 if (receivepack)
252 transport_set_option(transport,
253 TRANS_OPT_RECEIVEPACK, receivepack);
254 if (thin)
255 transport_set_option(transport, TRANS_OPT_THIN, "yes");
256
Tay Ray Chuan8afd8dc2010-02-24 20:50:24 +0800257 if (verbosity > 0)
Ævar Arnfjörð Bjarmason8352d292011-02-22 23:42:11 +0000258 fprintf(stderr, _("Pushing to %s\n"), transport->url);
Daniel Barkalowfb0cc872009-11-18 02:42:22 +0100259 err = transport_push(transport, refspec_nr, refspec, flags,
260 &nonfastforward);
Tay Ray Chuan53970b92009-12-04 07:31:44 +0800261 if (err != 0)
Ævar Arnfjörð Bjarmason8352d292011-02-22 23:42:11 +0000262 error(_("failed to push some refs to '%s'"), transport->url);
Tay Ray Chuan53970b92009-12-04 07:31:44 +0800263
Daniel Barkalowfb0cc872009-11-18 02:42:22 +0100264 err |= transport_disconnect(transport);
Daniel Barkalowfb0cc872009-11-18 02:42:22 +0100265 if (!err)
266 return 0;
267
Christopher Tiwaldf25950f2012-03-20 00:31:33 -0400268 switch (nonfastforward) {
269 default:
270 break;
271 case NON_FF_HEAD:
272 advise_pull_before_push();
273 break;
274 case NON_FF_OTHER:
275 if (default_matching_used)
276 advise_use_upstream();
277 else
278 advise_checkout_pull_push();
279 break;
Daniel Barkalowfb0cc872009-11-18 02:42:22 +0100280 }
281
282 return 1;
283}
284
Daniel Barkalow9b288512007-09-10 23:03:04 -0400285static int do_push(const char *repo, int flags)
Linus Torvalds755225d2006-04-29 21:22:49 -0700286{
Daniel Barkalow5751f492007-05-12 11:45:53 -0400287 int i, errs;
Daniel Barkalow5751f492007-05-12 11:45:53 -0400288 struct remote *remote = remote_get(repo);
Michael J Gruber20346232009-06-09 18:01:34 +0200289 const char **url;
290 int url_nr;
Linus Torvalds755225d2006-04-29 21:22:49 -0700291
Daniel Barkalowfa685bd2009-03-11 01:47:20 -0400292 if (!remote) {
293 if (repo)
Ævar Arnfjörð Bjarmason8352d292011-02-22 23:42:11 +0000294 die(_("bad repository '%s'"), repo);
Junio C Hamano6c80cd22011-04-01 17:55:55 -0700295 die(_("No configured push destination.\n"
Matthieu Moya3f5e7a2011-03-02 21:12:11 +0100296 "Either specify the URL from the command-line or configure a remote repository using\n"
297 "\n"
298 " git remote add <name> <url>\n"
299 "\n"
300 "and then push using the remote name\n"
301 "\n"
Junio C Hamano6c80cd22011-04-01 17:55:55 -0700302 " git push <name>\n"));
Daniel Barkalowfa685bd2009-03-11 01:47:20 -0400303 }
Linus Torvalds755225d2006-04-29 21:22:49 -0700304
Paolo Bonzini84bb2df2008-04-17 13:17:20 +0200305 if (remote->mirror)
306 flags |= (TRANSPORT_PUSH_MIRROR|TRANSPORT_PUSH_FORCE);
307
Marek Zawirskib259f092008-08-16 19:58:32 +0200308 if ((flags & TRANSPORT_PUSH_ALL) && refspec) {
309 if (!strcmp(*refspec, "refs/tags/*"))
Ævar Arnfjörð Bjarmason8352d292011-02-22 23:42:11 +0000310 return error(_("--all and --tags are incompatible"));
311 return error(_("--all can't be combined with refspecs"));
Marek Zawirskib259f092008-08-16 19:58:32 +0200312 }
313
314 if ((flags & TRANSPORT_PUSH_MIRROR) && refspec) {
315 if (!strcmp(*refspec, "refs/tags/*"))
Ævar Arnfjörð Bjarmason8352d292011-02-22 23:42:11 +0000316 return error(_("--mirror and --tags are incompatible"));
317 return error(_("--mirror can't be combined with refspecs"));
Marek Zawirskib259f092008-08-16 19:58:32 +0200318 }
Paolo Bonzini84bb2df2008-04-17 13:17:20 +0200319
320 if ((flags & (TRANSPORT_PUSH_ALL|TRANSPORT_PUSH_MIRROR)) ==
321 (TRANSPORT_PUSH_ALL|TRANSPORT_PUSH_MIRROR)) {
Ævar Arnfjörð Bjarmason8352d292011-02-22 23:42:11 +0000322 return error(_("--all and --mirror are incompatible"));
Paolo Bonzini84bb2df2008-04-17 13:17:20 +0200323 }
324
Finn Arne Gangstad52153742009-03-16 16:42:51 +0100325 if (!refspec && !(flags & TRANSPORT_PUSH_ALL)) {
326 if (remote->push_refspec_nr) {
327 refspec = remote->push_refspec;
328 refspec_nr = remote->push_refspec_nr;
329 } else if (!(flags & TRANSPORT_PUSH_MIRROR))
Matthieu Moyec8460b2011-03-02 21:12:10 +0100330 setup_default_push_refspecs(remote);
Daniel Barkalow5751f492007-05-12 11:45:53 -0400331 }
Junio C Hamanofd1d1b02007-04-06 23:04:53 -0700332 errs = 0;
Junio C Hamano135dade2012-03-30 16:07:12 -0700333 url_nr = push_url_of_remote(remote, &url);
Daniel Barkalowfb0cc872009-11-18 02:42:22 +0100334 if (url_nr) {
335 for (i = 0; i < url_nr; i++) {
336 struct transport *transport =
337 transport_get(remote, url[i]);
338 if (push_with_options(transport, flags))
339 errs++;
Matthieu Moy07436e42009-08-08 09:51:08 +0200340 }
Daniel Barkalowfb0cc872009-11-18 02:42:22 +0100341 } else {
342 struct transport *transport =
343 transport_get(remote, NULL);
344
345 if (push_with_options(transport, flags))
346 errs++;
Linus Torvalds755225d2006-04-29 21:22:49 -0700347 }
Junio C Hamanofd1d1b02007-04-06 23:04:53 -0700348 return !!errs;
Linus Torvalds755225d2006-04-29 21:22:49 -0700349}
350
Fredrik Gustafssond2b17b32011-08-20 00:08:47 +0200351static int option_parse_recurse_submodules(const struct option *opt,
352 const char *arg, int unset)
353{
354 int *flags = opt->value;
Heiko Voigteb21c732012-03-29 09:21:24 +0200355
356 if (*flags & (TRANSPORT_RECURSE_SUBMODULES_CHECK |
357 TRANSPORT_RECURSE_SUBMODULES_ON_DEMAND))
358 die("%s can only be used once.", opt->long_name);
359
Fredrik Gustafssond2b17b32011-08-20 00:08:47 +0200360 if (arg) {
361 if (!strcmp(arg, "check"))
362 *flags |= TRANSPORT_RECURSE_SUBMODULES_CHECK;
Heiko Voigteb21c732012-03-29 09:21:24 +0200363 else if (!strcmp(arg, "on-demand"))
364 *flags |= TRANSPORT_RECURSE_SUBMODULES_ON_DEMAND;
Fredrik Gustafssond2b17b32011-08-20 00:08:47 +0200365 else
366 die("bad %s argument: %s", opt->long_name, arg);
367 } else
Heiko Voigteb21c732012-03-29 09:21:24 +0200368 die("option %s needs an argument (check|on-demand)",
369 opt->long_name);
Fredrik Gustafssond2b17b32011-08-20 00:08:47 +0200370
371 return 0;
372}
373
Linus Torvaldsa633fca2006-07-28 22:44:25 -0700374int cmd_push(int argc, const char **argv, const char *prefix)
Linus Torvalds755225d2006-04-29 21:22:49 -0700375{
Daniel Barkalow9b288512007-09-10 23:03:04 -0400376 int flags = 0;
Daniel Barkalow378c4832007-11-04 22:35:37 -0500377 int tags = 0;
Paolo Bonzini84bb2df2008-04-17 13:17:20 +0200378 int rc;
Daniel Barkalow5751f492007-05-12 11:45:53 -0400379 const char *repo = NULL; /* default repository */
Daniel Barkalow378c4832007-11-04 22:35:37 -0500380 struct option options[] = {
Tay Ray Chuan8afd8dc2010-02-24 20:50:24 +0800381 OPT__VERBOSITY(&verbosity),
Nguyễn Thái Ngọc Duy78dafaa2012-08-20 19:32:33 +0700382 OPT_STRING( 0 , "repo", &repo, N_("repository"), N_("repository")),
383 OPT_BIT( 0 , "all", &flags, N_("push all refs"), TRANSPORT_PUSH_ALL),
384 OPT_BIT( 0 , "mirror", &flags, N_("mirror all refs"),
Michele Ballabioc29c1b42008-07-20 14:02:20 +0200385 (TRANSPORT_PUSH_MIRROR|TRANSPORT_PUSH_FORCE)),
Nguyễn Thái Ngọc Duy78dafaa2012-08-20 19:32:33 +0700386 OPT_BOOLEAN( 0, "delete", &deleterefs, N_("delete refs")),
387 OPT_BOOLEAN( 0 , "tags", &tags, N_("push tags (can't be used with --all or --mirror)")),
388 OPT_BIT('n' , "dry-run", &flags, N_("dry run"), TRANSPORT_PUSH_DRY_RUN),
389 OPT_BIT( 0, "porcelain", &flags, N_("machine-readable output"), TRANSPORT_PUSH_PORCELAIN),
390 OPT_BIT('f', "force", &flags, N_("force updates"), TRANSPORT_PUSH_FORCE),
391 { OPTION_CALLBACK, 0, "recurse-submodules", &flags, N_("check"),
Nguyễn Thái Ngọc Duyf63cf8c2012-08-20 19:32:55 +0700392 N_("control recursive pushing of submodules"),
Fredrik Gustafssond2b17b32011-08-20 00:08:47 +0200393 PARSE_OPT_OPTARG, option_parse_recurse_submodules },
Nguyễn Thái Ngọc Duy78dafaa2012-08-20 19:32:33 +0700394 OPT_BOOLEAN( 0 , "thin", &thin, N_("use thin pack")),
395 OPT_STRING( 0 , "receive-pack", &receivepack, "receive-pack", N_("receive pack program")),
396 OPT_STRING( 0 , "exec", &receivepack, "receive-pack", N_("receive pack program")),
397 OPT_BIT('u', "set-upstream", &flags, N_("set upstream for git pull/status"),
Ilari Liusvaarae9fcd1e2010-01-16 23:45:31 +0200398 TRANSPORT_PUSH_SET_UPSTREAM),
Nguyễn Thái Ngọc Duy78dafaa2012-08-20 19:32:33 +0700399 OPT_BOOL(0, "progress", &progress, N_("force progress reporting")),
400 OPT_BIT(0, "prune", &flags, N_("prune locally removed refs"),
Felipe Contreras6ddba5e2012-02-23 00:43:41 +0200401 TRANSPORT_PUSH_PRUNE),
Daniel Barkalow378c4832007-11-04 22:35:37 -0500402 OPT_END()
403 };
Linus Torvalds755225d2006-04-29 21:22:49 -0700404
Jeff Kingbbc30f92011-02-24 09:30:19 -0500405 packet_trace_identity("push");
Jeff King2aae9052009-10-25 15:15:22 -0400406 git_config(git_default_config, NULL);
Stephen Boyd37782922009-05-23 11:53:12 -0700407 argc = parse_options(argc, argv, prefix, options, push_usage, 0);
Daniel Barkalow378c4832007-11-04 22:35:37 -0500408
Jan Krügerf517f1f2009-12-30 20:57:42 +0100409 if (deleterefs && (tags || (flags & (TRANSPORT_PUSH_ALL | TRANSPORT_PUSH_MIRROR))))
Ævar Arnfjörð Bjarmason8352d292011-02-22 23:42:11 +0000410 die(_("--delete is incompatible with --all, --mirror and --tags"));
Jan Krügerf517f1f2009-12-30 20:57:42 +0100411 if (deleterefs && argc < 2)
Ævar Arnfjörð Bjarmason8352d292011-02-22 23:42:11 +0000412 die(_("--delete doesn't make sense without any refs"));
Jan Krügerf517f1f2009-12-30 20:57:42 +0100413
Daniel Barkalow378c4832007-11-04 22:35:37 -0500414 if (tags)
415 add_refspec("refs/tags/*");
Daniel Barkalow378c4832007-11-04 22:35:37 -0500416
417 if (argc > 0) {
418 repo = argv[0];
419 set_refspecs(argv + 1, argc - 1);
Linus Torvalds755225d2006-04-29 21:22:49 -0700420 }
Daniel Barkalow8558fd92007-05-25 01:20:56 -0400421
Paolo Bonzini84bb2df2008-04-17 13:17:20 +0200422 rc = do_push(repo, flags);
423 if (rc == -1)
Andy Whitcroft94c89ba2007-11-09 23:32:25 +0000424 usage_with_options(push_usage, options);
Paolo Bonzini84bb2df2008-04-17 13:17:20 +0200425 else
426 return rc;
Linus Torvalds755225d2006-04-29 21:22:49 -0700427}