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