]>
Commit | Line | Data |
---|---|---|
c2e86add | 1 | #include "builtin.h" |
2a9c3fe8 | 2 | #include "commit.h" |
584c6cc9 | 3 | #include "refs.h" |
f3a3214e | 4 | #include "pkt-line.h" |
de1a2fdd | 5 | #include "sideband.h" |
38b1c662 | 6 | #include "run-command.h" |
6b62816c | 7 | #include "remote.h" |
47a59185 | 8 | #include "connect.h" |
96249c04 | 9 | #include "send-pack.h" |
de1a2fdd | 10 | #include "quote.h" |
f1863d0d | 11 | #include "transport.h" |
ff5effdf | 12 | #include "version.h" |
13eb4626 | 13 | #include "sha1-array.h" |
61221472 | 14 | |
2a245013 | 15 | static const char send_pack_usage[] = |
1b1dd23f | 16 | "git send-pack [--all | --mirror] [--dry-run] [--force] [--receive-pack=<git-receive-pack>] [--verbose] [--thin] [<host>:]<directory> [<ref>...]\n" |
18bd8821 | 17 | " --all and explicit <ref> specification are mutually exclusive."; |
96249c04 | 18 | |
6828f72f | 19 | static struct send_pack_args args; |
61221472 | 20 | |
de1a2fdd SP |
21 | static void print_helper_status(struct ref *ref) |
22 | { | |
23 | struct strbuf buf = STRBUF_INIT; | |
24 | ||
25 | for (; ref; ref = ref->next) { | |
26 | const char *msg = NULL; | |
27 | const char *res; | |
28 | ||
29 | switch(ref->status) { | |
30 | case REF_STATUS_NONE: | |
31 | res = "error"; | |
32 | msg = "no match"; | |
33 | break; | |
34 | ||
35 | case REF_STATUS_OK: | |
36 | res = "ok"; | |
37 | break; | |
38 | ||
39 | case REF_STATUS_UPTODATE: | |
40 | res = "ok"; | |
41 | msg = "up to date"; | |
42 | break; | |
43 | ||
44 | case REF_STATUS_REJECT_NONFASTFORWARD: | |
45 | res = "error"; | |
46 | msg = "non-fast forward"; | |
dbfeddb1 CR |
47 | break; |
48 | ||
75e5c0dc JH |
49 | case REF_STATUS_REJECT_FETCH_FIRST: |
50 | res = "error"; | |
51 | msg = "fetch first"; | |
52 | break; | |
53 | ||
54 | case REF_STATUS_REJECT_NEEDS_FORCE: | |
55 | res = "error"; | |
56 | msg = "needs force"; | |
57 | break; | |
58 | ||
631b5ef2 JH |
59 | case REF_STATUS_REJECT_STALE: |
60 | res = "error"; | |
61 | msg = "stale info"; | |
62 | break; | |
63 | ||
dbfeddb1 CR |
64 | case REF_STATUS_REJECT_ALREADY_EXISTS: |
65 | res = "error"; | |
66 | msg = "already exists"; | |
de1a2fdd SP |
67 | break; |
68 | ||
69 | case REF_STATUS_REJECT_NODELETE: | |
70 | case REF_STATUS_REMOTE_REJECT: | |
71 | res = "error"; | |
72 | break; | |
73 | ||
74 | case REF_STATUS_EXPECTING_REPORT: | |
75 | default: | |
76 | continue; | |
77 | } | |
78 | ||
79 | strbuf_reset(&buf); | |
80 | strbuf_addf(&buf, "%s %s", res, ref->name); | |
81 | if (ref->remote_status) | |
82 | msg = ref->remote_status; | |
83 | if (msg) { | |
84 | strbuf_addch(&buf, ' '); | |
85 | quote_two_c_style(&buf, "", msg, 0); | |
86 | } | |
87 | strbuf_addch(&buf, '\n'); | |
88 | ||
cdf4fb8e | 89 | write_or_die(1, buf.buf, buf.len); |
de1a2fdd SP |
90 | } |
91 | strbuf_release(&buf); | |
92 | } | |
93 | ||
96249c04 | 94 | int cmd_send_pack(int argc, const char **argv, const char *prefix) |
61221472 | 95 | { |
64fcef2d DB |
96 | int i, nr_refspecs = 0; |
97 | const char **refspecs = NULL; | |
96249c04 | 98 | const char *remote_name = NULL; |
b516968f | 99 | struct remote *remote = NULL; |
96249c04 | 100 | const char *dest = NULL; |
64fcef2d DB |
101 | int fd[2]; |
102 | struct child_process *conn; | |
13eb4626 | 103 | struct sha1_array extra_have = SHA1_ARRAY_INIT; |
b016918b | 104 | struct sha1_array shallow = SHA1_ARRAY_INIT; |
6d2bf96e | 105 | struct ref *remote_refs, *local_refs; |
64fcef2d | 106 | int ret; |
de1a2fdd | 107 | int helper_status = 0; |
64fcef2d DB |
108 | int send_all = 0; |
109 | const char *receivepack = "git-receive-pack"; | |
110 | int flags; | |
10643d4e | 111 | unsigned int reject_reasons; |
391b1f20 | 112 | int progress = -1; |
28f5d176 | 113 | struct push_cas_option cas = {0}; |
84a9b58c | 114 | |
61221472 | 115 | argv++; |
d089391c | 116 | for (i = 1; i < argc; i++, argv++) { |
96249c04 | 117 | const char *arg = *argv; |
61221472 LT |
118 | |
119 | if (*arg == '-') { | |
59556548 | 120 | if (starts_with(arg, "--receive-pack=")) { |
64fcef2d | 121 | receivepack = arg + 15; |
d23842fd UKK |
122 | continue; |
123 | } | |
59556548 | 124 | if (starts_with(arg, "--exec=")) { |
64fcef2d | 125 | receivepack = arg + 7; |
61221472 LT |
126 | continue; |
127 | } | |
59556548 | 128 | if (starts_with(arg, "--remote=")) { |
b516968f DB |
129 | remote_name = arg + 9; |
130 | continue; | |
131 | } | |
d089391c | 132 | if (!strcmp(arg, "--all")) { |
64fcef2d | 133 | send_all = 1; |
d089391c LT |
134 | continue; |
135 | } | |
a63103ae | 136 | if (!strcmp(arg, "--dry-run")) { |
96249c04 | 137 | args.dry_run = 1; |
a63103ae BE |
138 | continue; |
139 | } | |
28b9d6e5 AW |
140 | if (!strcmp(arg, "--mirror")) { |
141 | args.send_mirror = 1; | |
142 | continue; | |
143 | } | |
2a9c3fe8 | 144 | if (!strcmp(arg, "--force")) { |
96249c04 | 145 | args.force_update = 1; |
2a9c3fe8 LT |
146 | continue; |
147 | } | |
c207e34f CB |
148 | if (!strcmp(arg, "--quiet")) { |
149 | args.quiet = 1; | |
150 | continue; | |
151 | } | |
41f93a2c | 152 | if (!strcmp(arg, "--verbose")) { |
96249c04 | 153 | args.verbose = 1; |
41f93a2c LT |
154 | continue; |
155 | } | |
391b1f20 JK |
156 | if (!strcmp(arg, "--progress")) { |
157 | progress = 1; | |
158 | continue; | |
159 | } | |
160 | if (!strcmp(arg, "--no-progress")) { | |
161 | progress = 0; | |
162 | continue; | |
163 | } | |
2245be3e | 164 | if (!strcmp(arg, "--thin")) { |
96249c04 | 165 | args.use_thin_pack = 1; |
2245be3e JH |
166 | continue; |
167 | } | |
de1a2fdd SP |
168 | if (!strcmp(arg, "--stateless-rpc")) { |
169 | args.stateless_rpc = 1; | |
170 | continue; | |
171 | } | |
172 | if (!strcmp(arg, "--helper-status")) { | |
173 | helper_status = 1; | |
174 | continue; | |
175 | } | |
28f5d176 JH |
176 | if (!strcmp(arg, "--" CAS_OPT_NAME)) { |
177 | if (parse_push_cas_option(&cas, NULL, 0) < 0) | |
178 | exit(1); | |
179 | continue; | |
180 | } | |
181 | if (!strcmp(arg, "--no-" CAS_OPT_NAME)) { | |
182 | if (parse_push_cas_option(&cas, NULL, 1) < 0) | |
183 | exit(1); | |
184 | continue; | |
185 | } | |
59556548 | 186 | if (starts_with(arg, "--" CAS_OPT_NAME "=")) { |
28f5d176 | 187 | if (parse_push_cas_option(&cas, |
77aa9348 | 188 | strchr(arg, '=') + 1, 0) < 0) |
28f5d176 JH |
189 | exit(1); |
190 | continue; | |
191 | } | |
61221472 LT |
192 | usage(send_pack_usage); |
193 | } | |
d089391c LT |
194 | if (!dest) { |
195 | dest = arg; | |
196 | continue; | |
197 | } | |
64fcef2d DB |
198 | refspecs = (const char **) argv; |
199 | nr_refspecs = argc - i; | |
61221472 LT |
200 | break; |
201 | } | |
202 | if (!dest) | |
203 | usage(send_pack_usage); | |
28b9d6e5 AW |
204 | /* |
205 | * --all and --mirror are incompatible; neither makes sense | |
206 | * with any refspecs. | |
207 | */ | |
64fcef2d DB |
208 | if ((refspecs && (send_all || args.send_mirror)) || |
209 | (send_all && args.send_mirror)) | |
0bc3cdfc | 210 | usage(send_pack_usage); |
37adac76 | 211 | |
b516968f DB |
212 | if (remote_name) { |
213 | remote = remote_get(remote_name); | |
28b91f8a | 214 | if (!remote_has_url(remote, dest)) { |
b516968f DB |
215 | die("Destination %s is not a uri for %s", |
216 | dest, remote_name); | |
217 | } | |
218 | } | |
219 | ||
391b1f20 JK |
220 | if (progress == -1) |
221 | progress = !args.quiet && isatty(2); | |
222 | args.progress = progress; | |
8d32e60d | 223 | |
de1a2fdd SP |
224 | if (args.stateless_rpc) { |
225 | conn = NULL; | |
226 | fd[0] = 0; | |
227 | fd[1] = 1; | |
228 | } else { | |
5a277f3f | 229 | conn = git_connect(fd, dest, receivepack, |
de1a2fdd SP |
230 | args.verbose ? CONNECT_VERBOSE : 0); |
231 | } | |
96249c04 | 232 | |
b016918b NTND |
233 | get_remote_heads(fd[0], NULL, 0, &remote_refs, REF_NORMAL, |
234 | &extra_have, &shallow); | |
64fcef2d | 235 | |
f1863d0d | 236 | transport_verify_remote_names(nr_refspecs, refspecs); |
64fcef2d DB |
237 | |
238 | local_refs = get_local_heads(); | |
96249c04 | 239 | |
64fcef2d DB |
240 | flags = MATCH_REFS_NONE; |
241 | ||
242 | if (send_all) | |
243 | flags |= MATCH_REFS_ALL; | |
244 | if (args.send_mirror) | |
245 | flags |= MATCH_REFS_MIRROR; | |
246 | ||
247 | /* match them up */ | |
29753cdd | 248 | if (match_push_refs(local_refs, &remote_refs, nr_refspecs, refspecs, flags)) |
64fcef2d | 249 | return -1; |
96249c04 | 250 | |
91048a95 JH |
251 | if (!is_empty_cas(&cas)) |
252 | apply_push_cas(&cas, remote, remote_refs); | |
253 | ||
20e8b465 TRC |
254 | set_ref_status_for_push(remote_refs, args.send_mirror, |
255 | args.force_update); | |
256 | ||
64fcef2d | 257 | ret = send_pack(&args, fd, conn, remote_refs, &extra_have); |
96249c04 | 258 | |
de1a2fdd SP |
259 | if (helper_status) |
260 | print_helper_status(remote_refs); | |
261 | ||
64fcef2d | 262 | close(fd[1]); |
7f8e9828 | 263 | close(fd[0]); |
64fcef2d | 264 | |
98158e9c | 265 | ret |= finish_connect(conn); |
64fcef2d | 266 | |
de1a2fdd | 267 | if (!helper_status) |
10643d4e | 268 | transport_print_push_status(dest, remote_refs, args.verbose, 0, &reject_reasons); |
64fcef2d DB |
269 | |
270 | if (!args.dry_run && remote) { | |
271 | struct ref *ref; | |
272 | for (ref = remote_refs; ref; ref = ref->next) | |
f1863d0d | 273 | transport_update_tracking_ref(remote, ref, args.verbose); |
64fcef2d DB |
274 | } |
275 | ||
f1863d0d | 276 | if (!ret && !transport_refs_pushed(remote_refs)) |
64fcef2d DB |
277 | fprintf(stderr, "Everything up-to-date\n"); |
278 | ||
279 | return ret; | |
61221472 | 280 | } |