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