Linus Torvalds | 755225d | 2006-04-29 21:22:49 -0700 | [diff] [blame] | 1 | /* |
| 2 | * "git push" |
| 3 | */ |
| 4 | #include "cache.h" |
Brandon Williams | b2141fc | 2017-06-14 11:07:36 -0700 | [diff] [blame] | 5 | #include "config.h" |
Linus Torvalds | 755225d | 2006-04-29 21:22:49 -0700 | [diff] [blame] | 6 | #include "refs.h" |
Brandon Williams | ec0cb49 | 2018-05-16 15:57:48 -0700 | [diff] [blame] | 7 | #include "refspec.h" |
Linus Torvalds | 755225d | 2006-04-29 21:22:49 -0700 | [diff] [blame] | 8 | #include "run-command.h" |
| 9 | #include "builtin.h" |
Daniel Barkalow | 5751f49 | 2007-05-12 11:45:53 -0400 | [diff] [blame] | 10 | #include "remote.h" |
Daniel Barkalow | 9b28851 | 2007-09-10 23:03:04 -0400 | [diff] [blame] | 11 | #include "transport.h" |
Daniel Barkalow | 378c483 | 2007-11-04 22:35:37 -0500 | [diff] [blame] | 12 | #include "parse-options.h" |
Fredrik Gustafsson | d2b17b3 | 2011-08-20 00:08:47 +0200 | [diff] [blame] | 13 | #include "submodule.h" |
Mike Crowe | b33a15b | 2015-11-17 11:05:56 +0000 | [diff] [blame] | 14 | #include "submodule-config.h" |
Dave Borowitz | 3026109 | 2015-08-19 11:26:46 -0400 | [diff] [blame] | 15 | #include "send-pack.h" |
Ryan Dammrose | 960786e | 2018-04-21 12:10:00 +0200 | [diff] [blame] | 16 | #include "color.h" |
Linus Torvalds | 755225d | 2006-04-29 21:22:49 -0700 | [diff] [blame] | 17 | |
Daniel Barkalow | 378c483 | 2007-11-04 22:35:37 -0500 | [diff] [blame] | 18 | static const char * const push_usage[] = { |
Nguyễn Thái Ngọc Duy | 78dafaa | 2012-08-20 19:32:33 +0700 | [diff] [blame] | 19 | N_("git push [<options>] [<repository> [<refspec>...]]"), |
Daniel Barkalow | 378c483 | 2007-11-04 22:35:37 -0500 | [diff] [blame] | 20 | NULL, |
| 21 | }; |
Linus Torvalds | 755225d | 2006-04-29 21:22:49 -0700 | [diff] [blame] | 22 | |
Ryan Dammrose | 960786e | 2018-04-21 12:10:00 +0200 | [diff] [blame] | 23 | static int push_use_color = -1; |
| 24 | static char push_colors[][COLOR_MAXLEN] = { |
| 25 | GIT_COLOR_RESET, |
| 26 | GIT_COLOR_RED, /* ERROR */ |
| 27 | }; |
| 28 | |
| 29 | enum color_push { |
| 30 | PUSH_COLOR_RESET = 0, |
| 31 | PUSH_COLOR_ERROR = 1 |
| 32 | }; |
| 33 | |
| 34 | static 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 | |
| 43 | static 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 | |
Nguyễn Thái Ngọc Duy | f7c815c | 2013-08-12 20:55:55 +0700 | [diff] [blame] | 50 | static int thin = 1; |
Jan Krüger | f517f1f | 2009-12-30 20:57:42 +0100 | [diff] [blame] | 51 | static int deleterefs; |
Uwe Kleine-König | d23842f | 2007-01-19 13:49:27 +0100 | [diff] [blame] | 52 | static const char *receivepack; |
Tay Ray Chuan | 8afd8dc | 2010-02-24 20:50:24 +0800 | [diff] [blame] | 53 | static int verbosity; |
Mike Crowe | d34141c | 2015-12-03 13:10:35 +0000 | [diff] [blame] | 54 | static int progress = -1; |
| 55 | static int recurse_submodules = RECURSE_SUBMODULES_DEFAULT; |
Eric Wong | c915f11 | 2016-02-03 04:09:14 +0000 | [diff] [blame] | 56 | static enum transport_family family; |
Linus Torvalds | 755225d | 2006-04-29 21:22:49 -0700 | [diff] [blame] | 57 | |
Junio C Hamano | 28f5d17 | 2013-07-08 15:34:36 -0700 | [diff] [blame] | 58 | static struct push_cas_option cas; |
| 59 | |
Brandon Williams | aa40289 | 2018-05-16 15:58:16 -0700 | [diff] [blame] | 60 | static struct refspec rs = REFSPEC_INIT_PUSH; |
Linus Torvalds | 755225d | 2006-04-29 21:22:49 -0700 | [diff] [blame] | 61 | |
Marius Paliga | d805275 | 2017-10-23 13:44:49 +0200 | [diff] [blame] | 62 | static struct string_list push_options_config = STRING_LIST_INIT_DUP; |
| 63 | |
Junio C Hamano | ca02465 | 2013-12-03 15:41:15 -0800 | [diff] [blame] | 64 | static const char *map_refspec(const char *ref, |
| 65 | struct remote *remote, struct ref *local_refs) |
Linus Torvalds | 755225d | 2006-04-29 21:22:49 -0700 | [diff] [blame] | 66 | { |
René Scharfe | 1768aaf | 2019-11-26 16:18:28 +0100 | [diff] [blame] | 67 | const char *branch_name; |
Junio C Hamano | ca02465 | 2013-12-03 15:41:15 -0800 | [diff] [blame] | 68 | struct ref *matched = NULL; |
| 69 | |
| 70 | /* Does "ref" uniquely name our ref? */ |
| 71 | if (count_refspec_match(ref, local_refs, &matched) != 1) |
| 72 | return ref; |
| 73 | |
Brandon Williams | 6bdb304 | 2018-05-16 15:58:00 -0700 | [diff] [blame] | 74 | if (remote->push.nr) { |
Brandon Williams | 0ad4a5f | 2018-05-16 15:57:49 -0700 | [diff] [blame] | 75 | struct refspec_item query; |
| 76 | memset(&query, 0, sizeof(struct refspec_item)); |
Junio C Hamano | ca02465 | 2013-12-03 15:41:15 -0800 | [diff] [blame] | 77 | query.src = matched->name; |
Brandon Williams | 86baf82 | 2018-05-16 15:58:12 -0700 | [diff] [blame] | 78 | if (!query_refspecs(&remote->push, &query) && query.dst) { |
Junio C Hamano | ca02465 | 2013-12-03 15:41:15 -0800 | [diff] [blame] | 79 | struct strbuf buf = STRBUF_INIT; |
| 80 | strbuf_addf(&buf, "%s%s:%s", |
| 81 | query.force ? "+" : "", |
| 82 | query.src, query.dst); |
| 83 | return strbuf_detach(&buf, NULL); |
| 84 | } |
| 85 | } |
| 86 | |
Junio C Hamano | fc9261c | 2013-12-03 16:23:35 -0800 | [diff] [blame] | 87 | if (push_default == PUSH_DEFAULT_UPSTREAM && |
René Scharfe | 1768aaf | 2019-11-26 16:18:28 +0100 | [diff] [blame] | 88 | skip_prefix(matched->name, "refs/heads/", &branch_name)) { |
| 89 | struct branch *branch = branch_get(branch_name); |
Junio C Hamano | fc9261c | 2013-12-03 16:23:35 -0800 | [diff] [blame] | 90 | if (branch->merge_nr == 1 && branch->merge[0]->src) { |
| 91 | struct strbuf buf = STRBUF_INIT; |
| 92 | strbuf_addf(&buf, "%s:%s", |
| 93 | ref, branch->merge[0]->src); |
| 94 | return strbuf_detach(&buf, NULL); |
| 95 | } |
| 96 | } |
| 97 | |
Junio C Hamano | ca02465 | 2013-12-03 15:41:15 -0800 | [diff] [blame] | 98 | return ref; |
| 99 | } |
| 100 | |
| 101 | static void set_refspecs(const char **refs, int nr, const char *repo) |
| 102 | { |
| 103 | struct remote *remote = NULL; |
| 104 | struct ref *local_refs = NULL; |
Daniel Barkalow | 8558fd9 | 2007-05-25 01:20:56 -0400 | [diff] [blame] | 105 | int i; |
Junio C Hamano | ca02465 | 2013-12-03 15:41:15 -0800 | [diff] [blame] | 106 | |
Daniel Barkalow | 8558fd9 | 2007-05-25 01:20:56 -0400 | [diff] [blame] | 107 | for (i = 0; i < nr; i++) { |
| 108 | const char *ref = refs[i]; |
| 109 | if (!strcmp("tag", ref)) { |
Junio C Hamano | 50d829c | 2013-12-03 14:33:10 -0800 | [diff] [blame] | 110 | struct strbuf tagref = STRBUF_INIT; |
Daniel Barkalow | 8558fd9 | 2007-05-25 01:20:56 -0400 | [diff] [blame] | 111 | if (nr <= ++i) |
Ævar Arnfjörð Bjarmason | 8352d29 | 2011-02-22 23:42:11 +0000 | [diff] [blame] | 112 | die(_("tag shorthand without <tag>")); |
Junio C Hamano | 50d829c | 2013-12-03 14:33:10 -0800 | [diff] [blame] | 113 | ref = refs[i]; |
| 114 | if (deleterefs) |
| 115 | strbuf_addf(&tagref, ":refs/tags/%s", ref); |
| 116 | else |
| 117 | strbuf_addf(&tagref, "refs/tags/%s", ref); |
| 118 | ref = strbuf_detach(&tagref, NULL); |
| 119 | } else if (deleterefs) { |
| 120 | struct strbuf delref = STRBUF_INIT; |
| 121 | if (strchr(ref, ':')) |
| 122 | die(_("--delete only accepts plain target ref names")); |
| 123 | strbuf_addf(&delref, ":%s", ref); |
| 124 | ref = strbuf_detach(&delref, NULL); |
Junio C Hamano | ca02465 | 2013-12-03 15:41:15 -0800 | [diff] [blame] | 125 | } else if (!strchr(ref, ':')) { |
| 126 | if (!remote) { |
| 127 | /* lazily grab remote and local_refs */ |
| 128 | remote = remote_get(repo); |
| 129 | local_refs = get_local_heads(); |
Jan Krüger | f517f1f | 2009-12-30 20:57:42 +0100 | [diff] [blame] | 130 | } |
Junio C Hamano | ca02465 | 2013-12-03 15:41:15 -0800 | [diff] [blame] | 131 | ref = map_refspec(ref, remote, local_refs); |
Junio C Hamano | 50d829c | 2013-12-03 14:33:10 -0800 | [diff] [blame] | 132 | } |
Brandon Williams | aa40289 | 2018-05-16 15:58:16 -0700 | [diff] [blame] | 133 | refspec_append(&rs, ref); |
Linus Torvalds | 755225d | 2006-04-29 21:22:49 -0700 | [diff] [blame] | 134 | } |
Linus Torvalds | 755225d | 2006-04-29 21:22:49 -0700 | [diff] [blame] | 135 | } |
| 136 | |
Junio C Hamano | 135dade | 2012-03-30 16:07:12 -0700 | [diff] [blame] | 137 | static int push_url_of_remote(struct remote *remote, const char ***url_p) |
| 138 | { |
| 139 | if (remote->pushurl_nr) { |
| 140 | *url_p = remote->pushurl; |
| 141 | return remote->pushurl_nr; |
| 142 | } |
| 143 | *url_p = remote->url; |
| 144 | return remote->url_nr; |
| 145 | } |
| 146 | |
Johannes Schindelin | dbcd970 | 2019-09-30 02:55:31 -0700 | [diff] [blame] | 147 | static NORETURN void die_push_simple(struct branch *branch, |
| 148 | struct remote *remote) |
Nguyễn Thái Ngọc Duy | 3b33576 | 2018-12-09 11:25:21 +0100 | [diff] [blame] | 149 | { |
Matthieu Moy | b55e677 | 2012-04-24 09:50:03 +0200 | [diff] [blame] | 150 | /* |
| 151 | * There's no point in using shorten_unambiguous_ref here, |
| 152 | * as the ambiguity would be on the remote side, not what |
| 153 | * we have locally. Plus, this is supposed to be the simple |
| 154 | * mode. If the user is doing something crazy like setting |
| 155 | * upstream to a non-branch, we should probably be showing |
| 156 | * them the big ugly fully qualified ref. |
| 157 | */ |
| 158 | const char *advice_maybe = ""; |
Jeff King | cf4fff5 | 2014-06-18 15:44:19 -0400 | [diff] [blame] | 159 | const char *short_upstream = branch->merge[0]->src; |
Matthieu Moy | b55e677 | 2012-04-24 09:50:03 +0200 | [diff] [blame] | 160 | |
Jeff King | cf4fff5 | 2014-06-18 15:44:19 -0400 | [diff] [blame] | 161 | skip_prefix(short_upstream, "refs/heads/", &short_upstream); |
| 162 | |
Matthieu Moy | b55e677 | 2012-04-24 09:50:03 +0200 | [diff] [blame] | 163 | /* |
Ondřej Bílka | 98e023d | 2013-07-29 10:18:21 +0200 | [diff] [blame] | 164 | * Don't show advice for people who explicitly set |
Matthieu Moy | b55e677 | 2012-04-24 09:50:03 +0200 | [diff] [blame] | 165 | * push.default. |
| 166 | */ |
| 167 | if (push_default == PUSH_DEFAULT_UNSPECIFIED) |
| 168 | advice_maybe = _("\n" |
| 169 | "To choose either option permanently, " |
| 170 | "see push.default in 'git help config'."); |
| 171 | die(_("The upstream branch of your current branch does not match\n" |
| 172 | "the name of your current branch. To push to the upstream branch\n" |
| 173 | "on the remote, use\n" |
| 174 | "\n" |
| 175 | " git push %s HEAD:%s\n" |
| 176 | "\n" |
| 177 | "To push to the branch of the same name on the remote, use\n" |
| 178 | "\n" |
Ævar Arnfjörð Bjarmason | 8247166 | 2018-11-13 20:39:09 +0000 | [diff] [blame] | 179 | " git push %s HEAD\n" |
Matthieu Moy | b55e677 | 2012-04-24 09:50:03 +0200 | [diff] [blame] | 180 | "%s"), |
| 181 | remote->name, short_upstream, |
Ævar Arnfjörð Bjarmason | 8247166 | 2018-11-13 20:39:09 +0000 | [diff] [blame] | 182 | remote->name, advice_maybe); |
Matthieu Moy | b55e677 | 2012-04-24 09:50:03 +0200 | [diff] [blame] | 183 | } |
| 184 | |
Ramkumar Ramachandra | 35ee69c | 2013-05-30 00:51:49 +0530 | [diff] [blame] | 185 | static const char message_detached_head_die[] = |
| 186 | N_("You are not currently on a branch.\n" |
| 187 | "To push the history leading to the current (detached HEAD)\n" |
| 188 | "state now, use\n" |
| 189 | "\n" |
| 190 | " git push %s HEAD:<name-of-remote-branch>\n"); |
| 191 | |
Ramkumar Ramachandra | ed2b182 | 2013-06-19 16:41:41 +0530 | [diff] [blame] | 192 | static void setup_push_upstream(struct remote *remote, struct branch *branch, |
Jeff King | 00a6fa0 | 2014-11-26 22:43:06 -0500 | [diff] [blame] | 193 | int triangular, int simple) |
Finn Arne Gangstad | 5215374 | 2009-03-16 16:42:51 +0100 | [diff] [blame] | 194 | { |
| 195 | struct strbuf refspec = STRBUF_INIT; |
Ramkumar Ramachandra | ed2b182 | 2013-06-19 16:41:41 +0530 | [diff] [blame] | 196 | |
Finn Arne Gangstad | 5215374 | 2009-03-16 16:42:51 +0100 | [diff] [blame] | 197 | if (!branch) |
Ramkumar Ramachandra | 35ee69c | 2013-05-30 00:51:49 +0530 | [diff] [blame] | 198 | die(_(message_detached_head_die), remote->name); |
Junio C Hamano | 135dade | 2012-03-30 16:07:12 -0700 | [diff] [blame] | 199 | if (!branch->merge_nr || !branch->merge || !branch->remote_name) |
Junio C Hamano | 6c80cd2 | 2011-04-01 17:55:55 -0700 | [diff] [blame] | 200 | die(_("The current branch %s has no upstream branch.\n" |
Matthieu Moy | ec8460b | 2011-03-02 21:12:10 +0100 | [diff] [blame] | 201 | "To push the current branch and set the remote as upstream, use\n" |
| 202 | "\n" |
Junio C Hamano | 6c80cd2 | 2011-04-01 17:55:55 -0700 | [diff] [blame] | 203 | " git push --set-upstream %s %s\n"), |
Matthieu Moy | ec8460b | 2011-03-02 21:12:10 +0100 | [diff] [blame] | 204 | branch->name, |
| 205 | remote->name, |
Finn Arne Gangstad | 5215374 | 2009-03-16 16:42:51 +0100 | [diff] [blame] | 206 | branch->name); |
| 207 | if (branch->merge_nr != 1) |
Junio C Hamano | 6c80cd2 | 2011-04-01 17:55:55 -0700 | [diff] [blame] | 208 | die(_("The current branch %s has multiple upstream branches, " |
Ævar Arnfjörð Bjarmason | 8352d29 | 2011-02-22 23:42:11 +0000 | [diff] [blame] | 209 | "refusing to push."), branch->name); |
Ramkumar Ramachandra | ed2b182 | 2013-06-19 16:41:41 +0530 | [diff] [blame] | 210 | if (triangular) |
Junio C Hamano | 135dade | 2012-03-30 16:07:12 -0700 | [diff] [blame] | 211 | die(_("You are pushing to remote '%s', which is not the upstream of\n" |
| 212 | "your current branch '%s', without telling me what to push\n" |
| 213 | "to update which remote branch."), |
| 214 | remote->name, branch->name); |
Ramkumar Ramachandra | ed2b182 | 2013-06-19 16:41:41 +0530 | [diff] [blame] | 215 | |
Jeff King | 00a6fa0 | 2014-11-26 22:43:06 -0500 | [diff] [blame] | 216 | if (simple) { |
Ramkumar Ramachandra | ed2b182 | 2013-06-19 16:41:41 +0530 | [diff] [blame] | 217 | /* Additional safety */ |
| 218 | if (strcmp(branch->refname, branch->merge[0]->src)) |
| 219 | die_push_simple(branch, remote); |
| 220 | } |
Junio C Hamano | 135dade | 2012-03-30 16:07:12 -0700 | [diff] [blame] | 221 | |
Junio C Hamano | eef2bda | 2016-10-28 12:25:30 -0700 | [diff] [blame] | 222 | strbuf_addf(&refspec, "%s:%s", branch->refname, branch->merge[0]->src); |
Brandon Williams | aa40289 | 2018-05-16 15:58:16 -0700 | [diff] [blame] | 223 | refspec_append(&rs, refspec.buf); |
Finn Arne Gangstad | 5215374 | 2009-03-16 16:42:51 +0100 | [diff] [blame] | 224 | } |
| 225 | |
Ramkumar Ramachandra | ed2b182 | 2013-06-19 16:41:41 +0530 | [diff] [blame] | 226 | static void setup_push_current(struct remote *remote, struct branch *branch) |
| 227 | { |
Junio C Hamano | eef2bda | 2016-10-28 12:25:30 -0700 | [diff] [blame] | 228 | struct strbuf refspec = STRBUF_INIT; |
| 229 | |
Ramkumar Ramachandra | ed2b182 | 2013-06-19 16:41:41 +0530 | [diff] [blame] | 230 | if (!branch) |
| 231 | die(_(message_detached_head_die), remote->name); |
Junio C Hamano | eef2bda | 2016-10-28 12:25:30 -0700 | [diff] [blame] | 232 | strbuf_addf(&refspec, "%s:%s", branch->refname, branch->refname); |
Brandon Williams | aa40289 | 2018-05-16 15:58:16 -0700 | [diff] [blame] | 233 | refspec_append(&rs, refspec.buf); |
Ramkumar Ramachandra | ed2b182 | 2013-06-19 16:41:41 +0530 | [diff] [blame] | 234 | } |
| 235 | |
Ramkumar Ramachandra | ed2b182 | 2013-06-19 16:41:41 +0530 | [diff] [blame] | 236 | static int is_workflow_triangular(struct remote *remote) |
| 237 | { |
| 238 | struct remote *fetch_remote = remote_get(NULL); |
| 239 | return (fetch_remote && fetch_remote != remote); |
| 240 | } |
| 241 | |
Matthieu Moy | ec8460b | 2011-03-02 21:12:10 +0100 | [diff] [blame] | 242 | static void setup_default_push_refspecs(struct remote *remote) |
Finn Arne Gangstad | 5215374 | 2009-03-16 16:42:51 +0100 | [diff] [blame] | 243 | { |
Ramkumar Ramachandra | ed2b182 | 2013-06-19 16:41:41 +0530 | [diff] [blame] | 244 | struct branch *branch = branch_get(NULL); |
| 245 | int triangular = is_workflow_triangular(remote); |
Ramkumar Ramachandra | 7b2ecd8 | 2013-05-30 00:51:50 +0530 | [diff] [blame] | 246 | |
Finn Arne Gangstad | 5215374 | 2009-03-16 16:42:51 +0100 | [diff] [blame] | 247 | switch (push_default) { |
Junio C Hamano | bba0fd2 | 2009-07-18 17:19:47 -0700 | [diff] [blame] | 248 | default: |
Finn Arne Gangstad | 5215374 | 2009-03-16 16:42:51 +0100 | [diff] [blame] | 249 | case PUSH_DEFAULT_MATCHING: |
Brandon Williams | aa40289 | 2018-05-16 15:58:16 -0700 | [diff] [blame] | 250 | refspec_append(&rs, ":"); |
Finn Arne Gangstad | 5215374 | 2009-03-16 16:42:51 +0100 | [diff] [blame] | 251 | break; |
| 252 | |
Junio C Hamano | b2ed944 | 2013-01-04 16:02:29 -0800 | [diff] [blame] | 253 | case PUSH_DEFAULT_UNSPECIFIED: |
Matthieu Moy | b55e677 | 2012-04-24 09:50:03 +0200 | [diff] [blame] | 254 | case PUSH_DEFAULT_SIMPLE: |
Ramkumar Ramachandra | ed2b182 | 2013-06-19 16:41:41 +0530 | [diff] [blame] | 255 | if (triangular) |
| 256 | setup_push_current(remote, branch); |
| 257 | else |
Jeff King | 00a6fa0 | 2014-11-26 22:43:06 -0500 | [diff] [blame] | 258 | setup_push_upstream(remote, branch, triangular, 1); |
Matthieu Moy | b55e677 | 2012-04-24 09:50:03 +0200 | [diff] [blame] | 259 | break; |
| 260 | |
Johan Herland | 53c4031 | 2011-02-16 01:54:24 +0100 | [diff] [blame] | 261 | case PUSH_DEFAULT_UPSTREAM: |
Jeff King | 00a6fa0 | 2014-11-26 22:43:06 -0500 | [diff] [blame] | 262 | setup_push_upstream(remote, branch, triangular, 0); |
Finn Arne Gangstad | 5215374 | 2009-03-16 16:42:51 +0100 | [diff] [blame] | 263 | break; |
| 264 | |
| 265 | case PUSH_DEFAULT_CURRENT: |
Ramkumar Ramachandra | ed2b182 | 2013-06-19 16:41:41 +0530 | [diff] [blame] | 266 | setup_push_current(remote, branch); |
Finn Arne Gangstad | 5215374 | 2009-03-16 16:42:51 +0100 | [diff] [blame] | 267 | break; |
| 268 | |
| 269 | case PUSH_DEFAULT_NOTHING: |
Ævar Arnfjörð Bjarmason | 8352d29 | 2011-02-22 23:42:11 +0000 | [diff] [blame] | 270 | die(_("You didn't specify any refspecs to push, and " |
| 271 | "push.default is \"nothing\".")); |
Finn Arne Gangstad | 5215374 | 2009-03-16 16:42:51 +0100 | [diff] [blame] | 272 | break; |
| 273 | } |
| 274 | } |
| 275 | |
Christopher Tiwald | f25950f | 2012-03-20 00:31:33 -0400 | [diff] [blame] | 276 | static const char message_advice_pull_before_push[] = |
| 277 | N_("Updates were rejected because the tip of your current branch is behind\n" |
John Keeping | fc6c4e9 | 2013-07-07 20:02:14 +0100 | [diff] [blame] | 278 | "its remote counterpart. Integrate the remote changes (e.g.\n" |
| 279 | "'git pull ...') before pushing again.\n" |
Christopher Tiwald | f25950f | 2012-03-20 00:31:33 -0400 | [diff] [blame] | 280 | "See the 'Note about fast-forwards' in 'git push --help' for details."); |
| 281 | |
Christopher Tiwald | f25950f | 2012-03-20 00:31:33 -0400 | [diff] [blame] | 282 | static const char message_advice_checkout_pull_push[] = |
| 283 | N_("Updates were rejected because a pushed branch tip is behind its remote\n" |
John Keeping | fc6c4e9 | 2013-07-07 20:02:14 +0100 | [diff] [blame] | 284 | "counterpart. Check out this branch and integrate the remote changes\n" |
| 285 | "(e.g. 'git pull ...') before pushing again.\n" |
Christopher Tiwald | f25950f | 2012-03-20 00:31:33 -0400 | [diff] [blame] | 286 | "See the 'Note about fast-forwards' in 'git push --help' for details."); |
| 287 | |
Junio C Hamano | 75e5c0d | 2013-01-23 13:55:30 -0800 | [diff] [blame] | 288 | static const char message_advice_ref_fetch_first[] = |
| 289 | N_("Updates were rejected because the remote contains work that you do\n" |
| 290 | "not have locally. This is usually caused by another repository pushing\n" |
John Keeping | fc6c4e9 | 2013-07-07 20:02:14 +0100 | [diff] [blame] | 291 | "to the same ref. You may want to first integrate the remote changes\n" |
| 292 | "(e.g., 'git pull ...') before pushing again.\n" |
Junio C Hamano | 75e5c0d | 2013-01-23 13:55:30 -0800 | [diff] [blame] | 293 | "See the 'Note about fast-forwards' in 'git push --help' for details."); |
| 294 | |
Chris Rorvick | b24e604 | 2012-11-29 19:41:34 -0600 | [diff] [blame] | 295 | static const char message_advice_ref_already_exists[] = |
Junio C Hamano | b4cf8db | 2013-01-24 21:09:00 -0800 | [diff] [blame] | 296 | N_("Updates were rejected because the tag already exists in the remote."); |
Chris Rorvick | b24e604 | 2012-11-29 19:41:34 -0600 | [diff] [blame] | 297 | |
Junio C Hamano | 75e5c0d | 2013-01-23 13:55:30 -0800 | [diff] [blame] | 298 | static const char message_advice_ref_needs_force[] = |
| 299 | N_("You cannot update a remote ref that points at a non-commit object,\n" |
| 300 | "or update a remote ref to make it point at a non-commit object,\n" |
| 301 | "without using the '--force' option.\n"); |
Christopher Tiwald | f25950f | 2012-03-20 00:31:33 -0400 | [diff] [blame] | 302 | |
| 303 | static void advise_pull_before_push(void) |
| 304 | { |
Chris Rorvick | 1184564 | 2012-12-02 21:27:50 -0600 | [diff] [blame] | 305 | if (!advice_push_non_ff_current || !advice_push_update_rejected) |
Christopher Tiwald | f25950f | 2012-03-20 00:31:33 -0400 | [diff] [blame] | 306 | return; |
| 307 | advise(_(message_advice_pull_before_push)); |
| 308 | } |
| 309 | |
Christopher Tiwald | f25950f | 2012-03-20 00:31:33 -0400 | [diff] [blame] | 310 | static void advise_checkout_pull_push(void) |
| 311 | { |
Chris Rorvick | 1184564 | 2012-12-02 21:27:50 -0600 | [diff] [blame] | 312 | if (!advice_push_non_ff_matching || !advice_push_update_rejected) |
Christopher Tiwald | f25950f | 2012-03-20 00:31:33 -0400 | [diff] [blame] | 313 | return; |
| 314 | advise(_(message_advice_checkout_pull_push)); |
| 315 | } |
| 316 | |
Chris Rorvick | b24e604 | 2012-11-29 19:41:34 -0600 | [diff] [blame] | 317 | static void advise_ref_already_exists(void) |
| 318 | { |
Chris Rorvick | b450568 | 2012-12-02 21:27:51 -0600 | [diff] [blame] | 319 | if (!advice_push_already_exists || !advice_push_update_rejected) |
| 320 | return; |
Chris Rorvick | b24e604 | 2012-11-29 19:41:34 -0600 | [diff] [blame] | 321 | advise(_(message_advice_ref_already_exists)); |
| 322 | } |
| 323 | |
Junio C Hamano | 75e5c0d | 2013-01-23 13:55:30 -0800 | [diff] [blame] | 324 | static void advise_ref_fetch_first(void) |
| 325 | { |
| 326 | if (!advice_push_fetch_first || !advice_push_update_rejected) |
| 327 | return; |
| 328 | advise(_(message_advice_ref_fetch_first)); |
| 329 | } |
| 330 | |
| 331 | static void advise_ref_needs_force(void) |
| 332 | { |
| 333 | if (!advice_push_needs_force || !advice_push_update_rejected) |
| 334 | return; |
| 335 | advise(_(message_advice_ref_needs_force)); |
| 336 | } |
| 337 | |
Brandon Williams | aa40289 | 2018-05-16 15:58:16 -0700 | [diff] [blame] | 338 | static int push_with_options(struct transport *transport, struct refspec *rs, |
| 339 | int flags) |
Daniel Barkalow | fb0cc87 | 2009-11-18 02:42:22 +0100 | [diff] [blame] | 340 | { |
| 341 | int err; |
Chris Rorvick | 10643d4 | 2012-11-29 19:41:33 -0600 | [diff] [blame] | 342 | unsigned int reject_reasons; |
Tay Ray Chuan | 8afd8dc | 2010-02-24 20:50:24 +0800 | [diff] [blame] | 343 | |
Tay Ray Chuan | 7838106 | 2010-02-24 20:50:27 +0800 | [diff] [blame] | 344 | transport_set_verbosity(transport, verbosity, progress); |
Eric Wong | c915f11 | 2016-02-03 04:09:14 +0000 | [diff] [blame] | 345 | transport->family = family; |
Tay Ray Chuan | 8afd8dc | 2010-02-24 20:50:24 +0800 | [diff] [blame] | 346 | |
Daniel Barkalow | fb0cc87 | 2009-11-18 02:42:22 +0100 | [diff] [blame] | 347 | if (receivepack) |
| 348 | transport_set_option(transport, |
| 349 | TRANS_OPT_RECEIVEPACK, receivepack); |
Nguyễn Thái Ngọc Duy | f7c815c | 2013-08-12 20:55:55 +0700 | [diff] [blame] | 350 | transport_set_option(transport, TRANS_OPT_THIN, thin ? "yes" : NULL); |
Daniel Barkalow | fb0cc87 | 2009-11-18 02:42:22 +0100 | [diff] [blame] | 351 | |
Junio C Hamano | 91048a9 | 2013-07-09 11:01:06 -0700 | [diff] [blame] | 352 | if (!is_empty_cas(&cas)) { |
| 353 | if (!transport->smart_options) |
| 354 | die("underlying transport does not support --%s option", |
| 355 | CAS_OPT_NAME); |
| 356 | transport->smart_options->cas = &cas; |
| 357 | } |
| 358 | |
Tay Ray Chuan | 8afd8dc | 2010-02-24 20:50:24 +0800 | [diff] [blame] | 359 | if (verbosity > 0) |
Ævar Arnfjörð Bjarmason | 8352d29 | 2011-02-22 23:42:11 +0000 | [diff] [blame] | 360 | fprintf(stderr, _("Pushing to %s\n"), transport->url); |
Josh Steadmon | 25e4b80 | 2019-10-02 16:49:29 -0700 | [diff] [blame] | 361 | trace2_region_enter("push", "transport_push", the_repository); |
Nguyễn Thái Ngọc Duy | 6c6d5d0 | 2018-11-10 06:48:55 +0100 | [diff] [blame] | 362 | err = transport_push(the_repository, transport, |
| 363 | rs, flags, &reject_reasons); |
Josh Steadmon | 25e4b80 | 2019-10-02 16:49:29 -0700 | [diff] [blame] | 364 | trace2_region_leave("push", "transport_push", the_repository); |
Ryan Dammrose | 960786e | 2018-04-21 12:10:00 +0200 | [diff] [blame] | 365 | if (err != 0) { |
| 366 | fprintf(stderr, "%s", push_get_color(PUSH_COLOR_ERROR)); |
Ævar Arnfjörð Bjarmason | 8352d29 | 2011-02-22 23:42:11 +0000 | [diff] [blame] | 367 | error(_("failed to push some refs to '%s'"), transport->url); |
Ryan Dammrose | 960786e | 2018-04-21 12:10:00 +0200 | [diff] [blame] | 368 | fprintf(stderr, "%s", push_get_color(PUSH_COLOR_RESET)); |
| 369 | } |
Tay Ray Chuan | 53970b9 | 2009-12-04 07:31:44 +0800 | [diff] [blame] | 370 | |
Daniel Barkalow | fb0cc87 | 2009-11-18 02:42:22 +0100 | [diff] [blame] | 371 | err |= transport_disconnect(transport); |
Daniel Barkalow | fb0cc87 | 2009-11-18 02:42:22 +0100 | [diff] [blame] | 372 | if (!err) |
| 373 | return 0; |
| 374 | |
Chris Rorvick | 10643d4 | 2012-11-29 19:41:33 -0600 | [diff] [blame] | 375 | if (reject_reasons & REJECT_NON_FF_HEAD) { |
Christopher Tiwald | f25950f | 2012-03-20 00:31:33 -0400 | [diff] [blame] | 376 | advise_pull_before_push(); |
Chris Rorvick | 10643d4 | 2012-11-29 19:41:33 -0600 | [diff] [blame] | 377 | } else if (reject_reasons & REJECT_NON_FF_OTHER) { |
Junio C Hamano | b2ed944 | 2013-01-04 16:02:29 -0800 | [diff] [blame] | 378 | advise_checkout_pull_push(); |
Chris Rorvick | b24e604 | 2012-11-29 19:41:34 -0600 | [diff] [blame] | 379 | } else if (reject_reasons & REJECT_ALREADY_EXISTS) { |
| 380 | advise_ref_already_exists(); |
Junio C Hamano | 75e5c0d | 2013-01-23 13:55:30 -0800 | [diff] [blame] | 381 | } else if (reject_reasons & REJECT_FETCH_FIRST) { |
| 382 | advise_ref_fetch_first(); |
| 383 | } else if (reject_reasons & REJECT_NEEDS_FORCE) { |
| 384 | advise_ref_needs_force(); |
Daniel Barkalow | fb0cc87 | 2009-11-18 02:42:22 +0100 | [diff] [blame] | 385 | } |
| 386 | |
| 387 | return 1; |
| 388 | } |
| 389 | |
Stefan Beller | f6a4e61 | 2016-07-14 14:49:47 -0700 | [diff] [blame] | 390 | static int do_push(const char *repo, int flags, |
Thomas Gummerer | 8e4c8af | 2019-09-02 19:08:28 +0100 | [diff] [blame] | 391 | const struct string_list *push_options, |
| 392 | struct remote *remote) |
Linus Torvalds | 755225d | 2006-04-29 21:22:49 -0700 | [diff] [blame] | 393 | { |
Daniel Barkalow | 5751f49 | 2007-05-12 11:45:53 -0400 | [diff] [blame] | 394 | int i, errs; |
Michael J Gruber | 2034623 | 2009-06-09 18:01:34 +0200 | [diff] [blame] | 395 | const char **url; |
| 396 | int url_nr; |
Brandon Williams | aa40289 | 2018-05-16 15:58:16 -0700 | [diff] [blame] | 397 | struct refspec *push_refspec = &rs; |
Linus Torvalds | 755225d | 2006-04-29 21:22:49 -0700 | [diff] [blame] | 398 | |
Stefan Beller | f6a4e61 | 2016-07-14 14:49:47 -0700 | [diff] [blame] | 399 | if (push_options->nr) |
| 400 | flags |= TRANSPORT_PUSH_OPTIONS; |
| 401 | |
Brandon Williams | aa40289 | 2018-05-16 15:58:16 -0700 | [diff] [blame] | 402 | if (!push_refspec->nr && !(flags & TRANSPORT_PUSH_ALL)) { |
| 403 | if (remote->push.nr) { |
| 404 | push_refspec = &remote->push; |
Finn Arne Gangstad | 5215374 | 2009-03-16 16:42:51 +0100 | [diff] [blame] | 405 | } else if (!(flags & TRANSPORT_PUSH_MIRROR)) |
Matthieu Moy | ec8460b | 2011-03-02 21:12:10 +0100 | [diff] [blame] | 406 | setup_default_push_refspecs(remote); |
Daniel Barkalow | 5751f49 | 2007-05-12 11:45:53 -0400 | [diff] [blame] | 407 | } |
Junio C Hamano | fd1d1b0 | 2007-04-06 23:04:53 -0700 | [diff] [blame] | 408 | errs = 0; |
Junio C Hamano | 135dade | 2012-03-30 16:07:12 -0700 | [diff] [blame] | 409 | url_nr = push_url_of_remote(remote, &url); |
Daniel Barkalow | fb0cc87 | 2009-11-18 02:42:22 +0100 | [diff] [blame] | 410 | if (url_nr) { |
| 411 | for (i = 0; i < url_nr; i++) { |
| 412 | struct transport *transport = |
| 413 | transport_get(remote, url[i]); |
Stefan Beller | f6a4e61 | 2016-07-14 14:49:47 -0700 | [diff] [blame] | 414 | if (flags & TRANSPORT_PUSH_OPTIONS) |
| 415 | transport->push_options = push_options; |
Brandon Williams | aa40289 | 2018-05-16 15:58:16 -0700 | [diff] [blame] | 416 | if (push_with_options(transport, push_refspec, flags)) |
Daniel Barkalow | fb0cc87 | 2009-11-18 02:42:22 +0100 | [diff] [blame] | 417 | errs++; |
Matthieu Moy | 07436e4 | 2009-08-08 09:51:08 +0200 | [diff] [blame] | 418 | } |
Daniel Barkalow | fb0cc87 | 2009-11-18 02:42:22 +0100 | [diff] [blame] | 419 | } else { |
| 420 | struct transport *transport = |
| 421 | transport_get(remote, NULL); |
Stefan Beller | f6a4e61 | 2016-07-14 14:49:47 -0700 | [diff] [blame] | 422 | if (flags & TRANSPORT_PUSH_OPTIONS) |
| 423 | transport->push_options = push_options; |
Brandon Williams | aa40289 | 2018-05-16 15:58:16 -0700 | [diff] [blame] | 424 | if (push_with_options(transport, push_refspec, flags)) |
Daniel Barkalow | fb0cc87 | 2009-11-18 02:42:22 +0100 | [diff] [blame] | 425 | errs++; |
Linus Torvalds | 755225d | 2006-04-29 21:22:49 -0700 | [diff] [blame] | 426 | } |
Junio C Hamano | fd1d1b0 | 2007-04-06 23:04:53 -0700 | [diff] [blame] | 427 | return !!errs; |
Linus Torvalds | 755225d | 2006-04-29 21:22:49 -0700 | [diff] [blame] | 428 | } |
| 429 | |
Fredrik Gustafsson | d2b17b3 | 2011-08-20 00:08:47 +0200 | [diff] [blame] | 430 | static int option_parse_recurse_submodules(const struct option *opt, |
| 431 | const char *arg, int unset) |
| 432 | { |
Mike Crowe | b33a15b | 2015-11-17 11:05:56 +0000 | [diff] [blame] | 433 | int *recurse_submodules = opt->value; |
Heiko Voigt | eb21c73 | 2012-03-29 09:21:24 +0200 | [diff] [blame] | 434 | |
Mike Crowe | b33a15b | 2015-11-17 11:05:56 +0000 | [diff] [blame] | 435 | if (unset) |
| 436 | *recurse_submodules = RECURSE_SUBMODULES_OFF; |
| 437 | else if (arg) |
| 438 | *recurse_submodules = parse_push_recurse_submodules_arg(opt->long_name, arg); |
| 439 | else |
| 440 | die("%s missing parameter", opt->long_name); |
Fredrik Gustafsson | d2b17b3 | 2011-08-20 00:08:47 +0200 | [diff] [blame] | 441 | |
| 442 | return 0; |
| 443 | } |
| 444 | |
Dave Borowitz | 68c757f | 2015-08-19 11:26:47 -0400 | [diff] [blame] | 445 | static void set_push_cert_flags(int *flags, int v) |
| 446 | { |
| 447 | switch (v) { |
| 448 | case SEND_PACK_PUSH_CERT_NEVER: |
| 449 | *flags &= ~(TRANSPORT_PUSH_CERT_ALWAYS | TRANSPORT_PUSH_CERT_IF_ASKED); |
| 450 | break; |
| 451 | case SEND_PACK_PUSH_CERT_ALWAYS: |
| 452 | *flags |= TRANSPORT_PUSH_CERT_ALWAYS; |
| 453 | *flags &= ~TRANSPORT_PUSH_CERT_IF_ASKED; |
| 454 | break; |
| 455 | case SEND_PACK_PUSH_CERT_IF_ASKED: |
| 456 | *flags |= TRANSPORT_PUSH_CERT_IF_ASKED; |
| 457 | *flags &= ~TRANSPORT_PUSH_CERT_ALWAYS; |
| 458 | break; |
| 459 | } |
| 460 | } |
| 461 | |
| 462 | |
Michael J Gruber | b945901 | 2014-10-22 16:57:49 +0200 | [diff] [blame] | 463 | static int git_push_config(const char *k, const char *v, void *cb) |
| 464 | { |
Ryan Dammrose | 960786e | 2018-04-21 12:10:00 +0200 | [diff] [blame] | 465 | const char *slot_name; |
Dave Olszewski | a8bc269 | 2015-02-16 01:16:19 -0500 | [diff] [blame] | 466 | int *flags = cb; |
Michael J Gruber | b945901 | 2014-10-22 16:57:49 +0200 | [diff] [blame] | 467 | int status; |
| 468 | |
| 469 | status = git_gpg_config(k, v, NULL); |
| 470 | if (status) |
| 471 | return status; |
Dave Olszewski | a8bc269 | 2015-02-16 01:16:19 -0500 | [diff] [blame] | 472 | |
| 473 | if (!strcmp(k, "push.followtags")) { |
| 474 | if (git_config_bool(k, v)) |
| 475 | *flags |= TRANSPORT_PUSH_FOLLOW_TAGS; |
| 476 | else |
| 477 | *flags &= ~TRANSPORT_PUSH_FOLLOW_TAGS; |
| 478 | return 0; |
Dave Borowitz | 68c757f | 2015-08-19 11:26:47 -0400 | [diff] [blame] | 479 | } else if (!strcmp(k, "push.gpgsign")) { |
| 480 | const char *value; |
| 481 | if (!git_config_get_value("push.gpgsign", &value)) { |
Martin Ågren | 8957661 | 2017-08-07 20:20:49 +0200 | [diff] [blame] | 482 | switch (git_parse_maybe_bool(value)) { |
Dave Borowitz | 68c757f | 2015-08-19 11:26:47 -0400 | [diff] [blame] | 483 | case 0: |
| 484 | set_push_cert_flags(flags, SEND_PACK_PUSH_CERT_NEVER); |
| 485 | break; |
| 486 | case 1: |
| 487 | set_push_cert_flags(flags, SEND_PACK_PUSH_CERT_ALWAYS); |
| 488 | break; |
| 489 | default: |
| 490 | if (value && !strcasecmp(value, "if-asked")) |
| 491 | set_push_cert_flags(flags, SEND_PACK_PUSH_CERT_IF_ASKED); |
| 492 | else |
| 493 | return error("Invalid value for '%s'", k); |
| 494 | } |
| 495 | } |
Mike Crowe | b33a15b | 2015-11-17 11:05:56 +0000 | [diff] [blame] | 496 | } else if (!strcmp(k, "push.recursesubmodules")) { |
| 497 | const char *value; |
| 498 | if (!git_config_get_value("push.recursesubmodules", &value)) |
| 499 | recurse_submodules = parse_push_recurse_submodules_arg(k, value); |
Stefan Beller | 4e53d6a | 2017-05-31 17:30:49 -0700 | [diff] [blame] | 500 | } else if (!strcmp(k, "submodule.recurse")) { |
| 501 | int val = git_config_bool(k, v) ? |
| 502 | RECURSE_SUBMODULES_ON_DEMAND : RECURSE_SUBMODULES_OFF; |
| 503 | recurse_submodules = val; |
Marius Paliga | d805275 | 2017-10-23 13:44:49 +0200 | [diff] [blame] | 504 | } else if (!strcmp(k, "push.pushoption")) { |
| 505 | if (!v) |
| 506 | return config_error_nonbool(k); |
| 507 | else |
| 508 | if (!*v) |
| 509 | string_list_clear(&push_options_config, 0); |
| 510 | else |
| 511 | string_list_append(&push_options_config, v); |
| 512 | return 0; |
Ryan Dammrose | 960786e | 2018-04-21 12:10:00 +0200 | [diff] [blame] | 513 | } else if (!strcmp(k, "color.push")) { |
| 514 | push_use_color = git_config_colorbool(k, v); |
| 515 | return 0; |
| 516 | } else if (skip_prefix(k, "color.push.", &slot_name)) { |
| 517 | int slot = parse_push_color_slot(slot_name); |
| 518 | if (slot < 0) |
| 519 | return 0; |
| 520 | if (!v) |
| 521 | return config_error_nonbool(k); |
| 522 | return color_parse(v, push_colors[slot]); |
Dave Olszewski | a8bc269 | 2015-02-16 01:16:19 -0500 | [diff] [blame] | 523 | } |
| 524 | |
Jeff King | 06038cd | 2015-02-16 00:46:30 -0500 | [diff] [blame] | 525 | return git_default_config(k, v, NULL); |
Michael J Gruber | b945901 | 2014-10-22 16:57:49 +0200 | [diff] [blame] | 526 | } |
| 527 | |
Linus Torvalds | a633fca | 2006-07-28 22:44:25 -0700 | [diff] [blame] | 528 | int cmd_push(int argc, const char **argv, const char *prefix) |
Linus Torvalds | 755225d | 2006-04-29 21:22:49 -0700 | [diff] [blame] | 529 | { |
Daniel Barkalow | 9b28851 | 2007-09-10 23:03:04 -0400 | [diff] [blame] | 530 | int flags = 0; |
Daniel Barkalow | 378c483 | 2007-11-04 22:35:37 -0500 | [diff] [blame] | 531 | int tags = 0; |
Dave Borowitz | 3026109 | 2015-08-19 11:26:46 -0400 | [diff] [blame] | 532 | int push_cert = -1; |
Paolo Bonzini | 84bb2df | 2008-04-17 13:17:20 +0200 | [diff] [blame] | 533 | int rc; |
Daniel Barkalow | 5751f49 | 2007-05-12 11:45:53 -0400 | [diff] [blame] | 534 | const char *repo = NULL; /* default repository */ |
Marius Paliga | d805275 | 2017-10-23 13:44:49 +0200 | [diff] [blame] | 535 | struct string_list push_options_cmdline = STRING_LIST_INIT_DUP; |
| 536 | struct string_list *push_options; |
Brandon Williams | 54cc8ac | 2017-03-31 16:56:22 -0700 | [diff] [blame] | 537 | const struct string_list_item *item; |
Thomas Gummerer | 8e4c8af | 2019-09-02 19:08:28 +0100 | [diff] [blame] | 538 | struct remote *remote; |
Stefan Beller | f6a4e61 | 2016-07-14 14:49:47 -0700 | [diff] [blame] | 539 | |
Daniel Barkalow | 378c483 | 2007-11-04 22:35:37 -0500 | [diff] [blame] | 540 | struct option options[] = { |
Tay Ray Chuan | 8afd8dc | 2010-02-24 20:50:24 +0800 | [diff] [blame] | 541 | OPT__VERBOSITY(&verbosity), |
Nguyễn Thái Ngọc Duy | 78dafaa | 2012-08-20 19:32:33 +0700 | [diff] [blame] | 542 | OPT_STRING( 0 , "repo", &repo, N_("repository"), N_("repository")), |
| 543 | OPT_BIT( 0 , "all", &flags, N_("push all refs"), TRANSPORT_PUSH_ALL), |
| 544 | OPT_BIT( 0 , "mirror", &flags, N_("mirror all refs"), |
Michele Ballabio | c29c1b4 | 2008-07-20 14:02:20 +0200 | [diff] [blame] | 545 | (TRANSPORT_PUSH_MIRROR|TRANSPORT_PUSH_FORCE)), |
Patrick Steinhardt | 38a2559 | 2015-12-14 16:23:04 +0100 | [diff] [blame] | 546 | OPT_BOOL('d', "delete", &deleterefs, N_("delete refs")), |
Stefan Beller | d5d09d4 | 2013-08-03 13:51:19 +0200 | [diff] [blame] | 547 | OPT_BOOL( 0 , "tags", &tags, N_("push tags (can't be used with --all or --mirror)")), |
Nguyễn Thái Ngọc Duy | 78dafaa | 2012-08-20 19:32:33 +0700 | [diff] [blame] | 548 | OPT_BIT('n' , "dry-run", &flags, N_("dry run"), TRANSPORT_PUSH_DRY_RUN), |
| 549 | OPT_BIT( 0, "porcelain", &flags, N_("machine-readable output"), TRANSPORT_PUSH_PORCELAIN), |
| 550 | OPT_BIT('f', "force", &flags, N_("force updates"), TRANSPORT_PUSH_FORCE), |
Junio C Hamano | 28f5d17 | 2013-07-08 15:34:36 -0700 | [diff] [blame] | 551 | { OPTION_CALLBACK, |
Ævar Arnfjörð Bjarmason | c67318e | 2018-08-02 00:31:33 +0200 | [diff] [blame] | 552 | 0, CAS_OPT_NAME, &cas, N_("<refname>:<expect>"), |
Junio C Hamano | 28f5d17 | 2013-07-08 15:34:36 -0700 | [diff] [blame] | 553 | N_("require old value of ref to be at this value"), |
Ævar Arnfjörð Bjarmason | c67318e | 2018-08-02 00:31:33 +0200 | [diff] [blame] | 554 | PARSE_OPT_OPTARG | PARSE_OPT_LITERAL_ARGHELP, parseopt_push_cas_option }, |
René Scharfe | bbc072f | 2018-08-19 19:34:48 +0200 | [diff] [blame] | 555 | { OPTION_CALLBACK, 0, "recurse-submodules", &recurse_submodules, "(check|on-demand|no)", |
Nguyễn Thái Ngọc Duy | f63cf8c | 2012-08-20 19:32:55 +0700 | [diff] [blame] | 556 | N_("control recursive pushing of submodules"), |
Fredrik Gustafsson | d2b17b3 | 2011-08-20 00:08:47 +0200 | [diff] [blame] | 557 | PARSE_OPT_OPTARG, option_parse_recurse_submodules }, |
Nguyễn Thái Ngọc Duy | f1e1bdd | 2018-02-09 18:02:10 +0700 | [diff] [blame] | 558 | OPT_BOOL_F( 0 , "thin", &thin, N_("use thin pack"), PARSE_OPT_NOCOMPLETE), |
Nguyễn Thái Ngọc Duy | 78dafaa | 2012-08-20 19:32:33 +0700 | [diff] [blame] | 559 | OPT_STRING( 0 , "receive-pack", &receivepack, "receive-pack", N_("receive pack program")), |
| 560 | OPT_STRING( 0 , "exec", &receivepack, "receive-pack", N_("receive pack program")), |
| 561 | OPT_BIT('u', "set-upstream", &flags, N_("set upstream for git pull/status"), |
Ilari Liusvaara | e9fcd1e | 2010-01-16 23:45:31 +0200 | [diff] [blame] | 562 | TRANSPORT_PUSH_SET_UPSTREAM), |
Nguyễn Thái Ngọc Duy | 78dafaa | 2012-08-20 19:32:33 +0700 | [diff] [blame] | 563 | OPT_BOOL(0, "progress", &progress, N_("force progress reporting")), |
| 564 | OPT_BIT(0, "prune", &flags, N_("prune locally removed refs"), |
Felipe Contreras | 6ddba5e | 2012-02-23 00:43:41 +0200 | [diff] [blame] | 565 | TRANSPORT_PUSH_PRUNE), |
Aaron Schrab | ec55559 | 2013-01-13 00:17:03 -0500 | [diff] [blame] | 566 | OPT_BIT(0, "no-verify", &flags, N_("bypass pre-push hook"), TRANSPORT_PUSH_NO_HOOK), |
Junio C Hamano | c2aba15 | 2013-03-04 12:09:50 -0800 | [diff] [blame] | 567 | OPT_BIT(0, "follow-tags", &flags, N_("push missing but relevant tags"), |
| 568 | TRANSPORT_PUSH_FOLLOW_TAGS), |
Dave Borowitz | 3026109 | 2015-08-19 11:26:46 -0400 | [diff] [blame] | 569 | { OPTION_CALLBACK, |
René Scharfe | bbc072f | 2018-08-19 19:34:48 +0200 | [diff] [blame] | 570 | 0, "signed", &push_cert, "(yes|no|if-asked)", N_("GPG sign the push"), |
Dave Borowitz | 3026109 | 2015-08-19 11:26:46 -0400 | [diff] [blame] | 571 | PARSE_OPT_OPTARG, option_parse_push_signed }, |
Jeff King | d16c33b | 2015-02-16 01:12:04 -0500 | [diff] [blame] | 572 | OPT_BIT(0, "atomic", &flags, N_("request atomic transaction on remote side"), TRANSPORT_PUSH_ATOMIC), |
Marius Paliga | d805275 | 2017-10-23 13:44:49 +0200 | [diff] [blame] | 573 | OPT_STRING_LIST('o', "push-option", &push_options_cmdline, N_("server-specific"), N_("option to transmit")), |
Eric Wong | c915f11 | 2016-02-03 04:09:14 +0000 | [diff] [blame] | 574 | OPT_SET_INT('4', "ipv4", &family, N_("use IPv4 addresses only"), |
| 575 | TRANSPORT_FAMILY_IPV4), |
| 576 | OPT_SET_INT('6', "ipv6", &family, N_("use IPv6 addresses only"), |
| 577 | TRANSPORT_FAMILY_IPV6), |
Daniel Barkalow | 378c483 | 2007-11-04 22:35:37 -0500 | [diff] [blame] | 578 | OPT_END() |
| 579 | }; |
Linus Torvalds | 755225d | 2006-04-29 21:22:49 -0700 | [diff] [blame] | 580 | |
Jeff King | bbc30f9 | 2011-02-24 09:30:19 -0500 | [diff] [blame] | 581 | packet_trace_identity("push"); |
Jeff King | 06c21e18 | 2015-02-16 01:13:25 -0500 | [diff] [blame] | 582 | git_config(git_push_config, &flags); |
Stephen Boyd | 3778292 | 2009-05-23 11:53:12 -0700 | [diff] [blame] | 583 | argc = parse_options(argc, argv, prefix, options, push_usage, 0); |
Marius Paliga | d805275 | 2017-10-23 13:44:49 +0200 | [diff] [blame] | 584 | push_options = (push_options_cmdline.nr |
| 585 | ? &push_options_cmdline |
| 586 | : &push_options_config); |
Dave Borowitz | 68c757f | 2015-08-19 11:26:47 -0400 | [diff] [blame] | 587 | set_push_cert_flags(&flags, push_cert); |
Daniel Barkalow | 378c483 | 2007-11-04 22:35:37 -0500 | [diff] [blame] | 588 | |
Jan Krüger | f517f1f | 2009-12-30 20:57:42 +0100 | [diff] [blame] | 589 | if (deleterefs && (tags || (flags & (TRANSPORT_PUSH_ALL | TRANSPORT_PUSH_MIRROR)))) |
Ævar Arnfjörð Bjarmason | 8352d29 | 2011-02-22 23:42:11 +0000 | [diff] [blame] | 590 | die(_("--delete is incompatible with --all, --mirror and --tags")); |
Jan Krüger | f517f1f | 2009-12-30 20:57:42 +0100 | [diff] [blame] | 591 | if (deleterefs && argc < 2) |
Ævar Arnfjörð Bjarmason | 8352d29 | 2011-02-22 23:42:11 +0000 | [diff] [blame] | 592 | die(_("--delete doesn't make sense without any refs")); |
Jan Krüger | f517f1f | 2009-12-30 20:57:42 +0100 | [diff] [blame] | 593 | |
Mike Crowe | b33a15b | 2015-11-17 11:05:56 +0000 | [diff] [blame] | 594 | if (recurse_submodules == RECURSE_SUBMODULES_CHECK) |
| 595 | flags |= TRANSPORT_RECURSE_SUBMODULES_CHECK; |
| 596 | else if (recurse_submodules == RECURSE_SUBMODULES_ON_DEMAND) |
| 597 | flags |= TRANSPORT_RECURSE_SUBMODULES_ON_DEMAND; |
Brandon Williams | 225e8bf | 2016-12-19 10:25:33 -0800 | [diff] [blame] | 598 | else if (recurse_submodules == RECURSE_SUBMODULES_ONLY) |
| 599 | flags |= TRANSPORT_RECURSE_SUBMODULES_ONLY; |
Mike Crowe | b33a15b | 2015-11-17 11:05:56 +0000 | [diff] [blame] | 600 | |
Daniel Barkalow | 378c483 | 2007-11-04 22:35:37 -0500 | [diff] [blame] | 601 | if (tags) |
Brandon Williams | aa40289 | 2018-05-16 15:58:16 -0700 | [diff] [blame] | 602 | refspec_append(&rs, "refs/tags/*"); |
Daniel Barkalow | 378c483 | 2007-11-04 22:35:37 -0500 | [diff] [blame] | 603 | |
| 604 | if (argc > 0) { |
| 605 | repo = argv[0]; |
Junio C Hamano | ca02465 | 2013-12-03 15:41:15 -0800 | [diff] [blame] | 606 | set_refspecs(argv + 1, argc - 1, repo); |
Linus Torvalds | 755225d | 2006-04-29 21:22:49 -0700 | [diff] [blame] | 607 | } |
Daniel Barkalow | 8558fd9 | 2007-05-25 01:20:56 -0400 | [diff] [blame] | 608 | |
Thomas Gummerer | 8e4c8af | 2019-09-02 19:08:28 +0100 | [diff] [blame] | 609 | remote = pushremote_get(repo); |
| 610 | if (!remote) { |
| 611 | if (repo) |
| 612 | die(_("bad repository '%s'"), repo); |
| 613 | die(_("No configured push destination.\n" |
| 614 | "Either specify the URL from the command-line or configure a remote repository using\n" |
| 615 | "\n" |
| 616 | " git remote add <name> <url>\n" |
| 617 | "\n" |
| 618 | "and then push using the remote name\n" |
| 619 | "\n" |
| 620 | " git push <name>\n")); |
| 621 | } |
| 622 | |
| 623 | if (remote->mirror) |
| 624 | flags |= (TRANSPORT_PUSH_MIRROR|TRANSPORT_PUSH_FORCE); |
| 625 | |
| 626 | if (flags & TRANSPORT_PUSH_ALL) { |
| 627 | if (tags) |
| 628 | die(_("--all and --tags are incompatible")); |
| 629 | if (argc >= 2) |
| 630 | die(_("--all can't be combined with refspecs")); |
| 631 | } |
| 632 | if (flags & TRANSPORT_PUSH_MIRROR) { |
| 633 | if (tags) |
| 634 | die(_("--mirror and --tags are incompatible")); |
| 635 | if (argc >= 2) |
| 636 | die(_("--mirror can't be combined with refspecs")); |
| 637 | } |
| 638 | if ((flags & TRANSPORT_PUSH_ALL) && (flags & TRANSPORT_PUSH_MIRROR)) |
| 639 | die(_("--all and --mirror are incompatible")); |
| 640 | |
Marius Paliga | d805275 | 2017-10-23 13:44:49 +0200 | [diff] [blame] | 641 | for_each_string_list_item(item, push_options) |
Stefan Beller | f6a4e61 | 2016-07-14 14:49:47 -0700 | [diff] [blame] | 642 | if (strchr(item->string, '\n')) |
| 643 | die(_("push options must not have new line characters")); |
| 644 | |
Thomas Gummerer | 8e4c8af | 2019-09-02 19:08:28 +0100 | [diff] [blame] | 645 | rc = do_push(repo, flags, push_options, remote); |
Marius Paliga | d805275 | 2017-10-23 13:44:49 +0200 | [diff] [blame] | 646 | string_list_clear(&push_options_cmdline, 0); |
| 647 | string_list_clear(&push_options_config, 0); |
Paolo Bonzini | 84bb2df | 2008-04-17 13:17:20 +0200 | [diff] [blame] | 648 | if (rc == -1) |
Andy Whitcroft | 94c89ba | 2007-11-09 23:32:25 +0000 | [diff] [blame] | 649 | usage_with_options(push_usage, options); |
Paolo Bonzini | 84bb2df | 2008-04-17 13:17:20 +0200 | [diff] [blame] | 650 | else |
| 651 | return rc; |
Linus Torvalds | 755225d | 2006-04-29 21:22:49 -0700 | [diff] [blame] | 652 | } |