Merge branch 'jk/messages-with-excess-lf-fix'
[git/gitster.git] / send-pack.c
blob5d0c23772addb46480916fd0a0902b8f8c06ae6c
1 #define USE_THE_REPOSITORY_VARIABLE
3 #include "git-compat-util.h"
4 #include "config.h"
5 #include "commit.h"
6 #include "date.h"
7 #include "gettext.h"
8 #include "hex.h"
9 #include "object-store-ll.h"
10 #include "pkt-line.h"
11 #include "sideband.h"
12 #include "run-command.h"
13 #include "remote.h"
14 #include "connect.h"
15 #include "send-pack.h"
16 #include "transport.h"
17 #include "version.h"
18 #include "oid-array.h"
19 #include "gpg-interface.h"
20 #include "shallow.h"
21 #include "parse-options.h"
22 #include "trace2.h"
23 #include "write-or-die.h"
25 int option_parse_push_signed(const struct option *opt,
26 const char *arg, int unset)
28 if (unset) {
29 *(int *)(opt->value) = SEND_PACK_PUSH_CERT_NEVER;
30 return 0;
32 switch (git_parse_maybe_bool(arg)) {
33 case 1:
34 *(int *)(opt->value) = SEND_PACK_PUSH_CERT_ALWAYS;
35 return 0;
36 case 0:
37 *(int *)(opt->value) = SEND_PACK_PUSH_CERT_NEVER;
38 return 0;
40 if (!strcasecmp("if-asked", arg)) {
41 *(int *)(opt->value) = SEND_PACK_PUSH_CERT_IF_ASKED;
42 return 0;
44 die("bad %s argument: %s", opt->long_name, arg);
47 static void feed_object(const struct object_id *oid, FILE *fh, int negative)
49 if (negative &&
50 !repo_has_object_file_with_flags(the_repository, oid,
51 OBJECT_INFO_SKIP_FETCH_OBJECT |
52 OBJECT_INFO_QUICK))
53 return;
55 if (negative)
56 putc('^', fh);
57 fputs(oid_to_hex(oid), fh);
58 putc('\n', fh);
62 * Make a pack stream and spit it out into file descriptor fd
64 static int pack_objects(int fd, struct ref *refs, struct oid_array *advertised,
65 struct oid_array *negotiated,
66 struct send_pack_args *args)
69 * The child becomes pack-objects --revs; we feed
70 * the revision parameters to it via its stdin and
71 * let its stdout go back to the other end.
73 struct child_process po = CHILD_PROCESS_INIT;
74 FILE *po_in;
75 int i;
76 int rc;
78 trace2_region_enter("send_pack", "pack_objects", the_repository);
79 strvec_push(&po.args, "pack-objects");
80 strvec_push(&po.args, "--all-progress-implied");
81 strvec_push(&po.args, "--revs");
82 strvec_push(&po.args, "--stdout");
83 if (args->use_thin_pack)
84 strvec_push(&po.args, "--thin");
85 if (args->use_ofs_delta)
86 strvec_push(&po.args, "--delta-base-offset");
87 if (args->quiet || !args->progress)
88 strvec_push(&po.args, "-q");
89 if (args->progress)
90 strvec_push(&po.args, "--progress");
91 if (is_repository_shallow(the_repository))
92 strvec_push(&po.args, "--shallow");
93 if (args->disable_bitmaps)
94 strvec_push(&po.args, "--no-use-bitmap-index");
95 po.in = -1;
96 po.out = args->stateless_rpc ? -1 : fd;
97 po.git_cmd = 1;
98 po.clean_on_exit = 1;
99 if (start_command(&po))
100 die_errno("git pack-objects failed");
103 * We feed the pack-objects we just spawned with revision
104 * parameters by writing to the pipe.
106 po_in = xfdopen(po.in, "w");
107 for (i = 0; i < advertised->nr; i++)
108 feed_object(&advertised->oid[i], po_in, 1);
109 for (i = 0; i < negotiated->nr; i++)
110 feed_object(&negotiated->oid[i], po_in, 1);
112 while (refs) {
113 if (!is_null_oid(&refs->old_oid))
114 feed_object(&refs->old_oid, po_in, 1);
115 if (!is_null_oid(&refs->new_oid))
116 feed_object(&refs->new_oid, po_in, 0);
117 refs = refs->next;
120 fflush(po_in);
121 if (ferror(po_in))
122 die_errno("error writing to pack-objects");
123 fclose(po_in);
125 if (args->stateless_rpc) {
126 char *buf = xmalloc(LARGE_PACKET_MAX);
127 while (1) {
128 ssize_t n = xread(po.out, buf, LARGE_PACKET_MAX);
129 if (n <= 0)
130 break;
131 send_sideband(fd, -1, buf, n, LARGE_PACKET_MAX);
133 free(buf);
134 close(po.out);
135 po.out = -1;
138 rc = finish_command(&po);
139 if (rc) {
141 * For a normal non-zero exit, we assume pack-objects wrote
142 * something useful to stderr. For death by signal, though,
143 * we should mention it to the user. The exception is SIGPIPE
144 * (141), because that's a normal occurrence if the remote end
145 * hangs up (and we'll report that by trying to read the unpack
146 * status).
148 if (rc > 128 && rc != 141)
149 error("pack-objects died of signal %d", rc - 128);
150 trace2_region_leave("send_pack", "pack_objects", the_repository);
151 return -1;
153 trace2_region_leave("send_pack", "pack_objects", the_repository);
154 return 0;
157 static int receive_unpack_status(struct packet_reader *reader)
159 if (packet_reader_read(reader) != PACKET_READ_NORMAL)
160 return error(_("unexpected flush packet while reading remote unpack status"));
161 if (!skip_prefix(reader->line, "unpack ", &reader->line))
162 return error(_("unable to parse remote unpack status: %s"), reader->line);
163 if (strcmp(reader->line, "ok"))
164 return error(_("remote unpack failed: %s"), reader->line);
165 return 0;
168 static int receive_status(struct packet_reader *reader, struct ref *refs)
170 struct ref *hint;
171 int ret;
172 struct ref_push_report *report = NULL;
173 int new_report = 0;
174 int once = 0;
176 trace2_region_enter("send_pack", "receive_status", the_repository);
177 hint = NULL;
178 ret = receive_unpack_status(reader);
179 while (1) {
180 struct object_id old_oid, new_oid;
181 const char *head;
182 const char *refname;
183 char *p;
184 if (packet_reader_read(reader) != PACKET_READ_NORMAL)
185 break;
186 head = reader->line;
187 p = strchr(head, ' ');
188 if (!p) {
189 error("invalid status line from remote: %s", reader->line);
190 ret = -1;
191 break;
193 *p++ = '\0';
195 if (!strcmp(head, "option")) {
196 const char *key, *val;
198 if (!hint || !(report || new_report)) {
199 if (!once++)
200 error("'option' without a matching 'ok/ng' directive");
201 ret = -1;
202 continue;
204 if (new_report) {
205 if (!hint->report) {
206 CALLOC_ARRAY(hint->report, 1);
207 report = hint->report;
208 } else {
209 report = hint->report;
210 while (report->next)
211 report = report->next;
212 CALLOC_ARRAY(report->next, 1);
213 report = report->next;
215 new_report = 0;
217 key = p;
218 p = strchr(key, ' ');
219 if (p)
220 *p++ = '\0';
221 val = p;
222 if (!strcmp(key, "refname"))
223 report->ref_name = xstrdup_or_null(val);
224 else if (!strcmp(key, "old-oid") && val &&
225 !parse_oid_hex(val, &old_oid, &val))
226 report->old_oid = oiddup(&old_oid);
227 else if (!strcmp(key, "new-oid") && val &&
228 !parse_oid_hex(val, &new_oid, &val))
229 report->new_oid = oiddup(&new_oid);
230 else if (!strcmp(key, "forced-update"))
231 report->forced_update = 1;
232 continue;
235 report = NULL;
236 new_report = 0;
237 if (strcmp(head, "ok") && strcmp(head, "ng")) {
238 error("invalid ref status from remote: %s", head);
239 ret = -1;
240 break;
242 refname = p;
243 p = strchr(refname, ' ');
244 if (p)
245 *p++ = '\0';
246 /* first try searching at our hint, falling back to all refs */
247 if (hint)
248 hint = find_ref_by_name(hint, refname);
249 if (!hint)
250 hint = find_ref_by_name(refs, refname);
251 if (!hint) {
252 warning("remote reported status on unknown ref: %s",
253 refname);
254 continue;
256 if (hint->status != REF_STATUS_EXPECTING_REPORT &&
257 hint->status != REF_STATUS_OK &&
258 hint->status != REF_STATUS_REMOTE_REJECT) {
259 warning("remote reported status on unexpected ref: %s",
260 refname);
261 continue;
263 if (!strcmp(head, "ng")) {
264 hint->status = REF_STATUS_REMOTE_REJECT;
265 if (p)
266 hint->remote_status = xstrdup(p);
267 else
268 hint->remote_status = xstrdup("failed");
269 } else {
270 hint->status = REF_STATUS_OK;
271 hint->remote_status = xstrdup_or_null(p);
272 new_report = 1;
275 trace2_region_leave("send_pack", "receive_status", the_repository);
276 return ret;
279 static int sideband_demux(int in UNUSED, int out, void *data)
281 int *fd = data, ret;
282 if (async_with_fork())
283 close(fd[1]);
284 ret = recv_sideband("send-pack", fd[0], out);
285 close(out);
286 return ret;
289 static int advertise_shallow_grafts_cb(const struct commit_graft *graft, void *cb)
291 struct strbuf *sb = cb;
292 if (graft->nr_parent == -1)
293 packet_buf_write(sb, "shallow %s\n", oid_to_hex(&graft->oid));
294 return 0;
297 static void advertise_shallow_grafts_buf(struct strbuf *sb)
299 if (!is_repository_shallow(the_repository))
300 return;
301 for_each_commit_graft(advertise_shallow_grafts_cb, sb);
304 #define CHECK_REF_NO_PUSH -1
305 #define CHECK_REF_STATUS_REJECTED -2
306 #define CHECK_REF_UPTODATE -3
307 static int check_to_send_update(const struct ref *ref, const struct send_pack_args *args)
309 if (!ref->peer_ref && !args->send_mirror)
310 return CHECK_REF_NO_PUSH;
312 /* Check for statuses set by set_ref_status_for_push() */
313 switch (ref->status) {
314 case REF_STATUS_REJECT_NONFASTFORWARD:
315 case REF_STATUS_REJECT_ALREADY_EXISTS:
316 case REF_STATUS_REJECT_FETCH_FIRST:
317 case REF_STATUS_REJECT_NEEDS_FORCE:
318 case REF_STATUS_REJECT_STALE:
319 case REF_STATUS_REJECT_REMOTE_UPDATED:
320 case REF_STATUS_REJECT_NODELETE:
321 return CHECK_REF_STATUS_REJECTED;
322 case REF_STATUS_UPTODATE:
323 return CHECK_REF_UPTODATE;
325 default:
326 case REF_STATUS_EXPECTING_REPORT:
327 /* already passed checks on the local side */
328 case REF_STATUS_OK:
329 /* of course this is OK */
330 return 0;
335 * the beginning of the next line, or the end of buffer.
337 * NEEDSWORK: perhaps move this to git-compat-util.h or somewhere and
338 * convert many similar uses found by "git grep -A4 memchr".
340 static const char *next_line(const char *line, size_t len)
342 const char *nl = memchr(line, '\n', len);
343 if (!nl)
344 return line + len; /* incomplete line */
345 return nl + 1;
348 static int generate_push_cert(struct strbuf *req_buf,
349 const struct ref *remote_refs,
350 struct send_pack_args *args,
351 const char *cap_string,
352 const char *push_cert_nonce)
354 const struct ref *ref;
355 struct string_list_item *item;
356 char *signing_key_id = xstrdup(get_signing_key_id());
357 const char *cp, *np;
358 struct strbuf cert = STRBUF_INIT;
359 int update_seen = 0;
361 strbuf_addstr(&cert, "certificate version 0.1\n");
362 strbuf_addf(&cert, "pusher %s ", signing_key_id);
363 datestamp(&cert);
364 strbuf_addch(&cert, '\n');
365 if (args->url && *args->url) {
366 char *anon_url = transport_anonymize_url(args->url);
367 strbuf_addf(&cert, "pushee %s\n", anon_url);
368 free(anon_url);
370 if (push_cert_nonce[0])
371 strbuf_addf(&cert, "nonce %s\n", push_cert_nonce);
372 if (args->push_options)
373 for_each_string_list_item(item, args->push_options)
374 strbuf_addf(&cert, "push-option %s\n", item->string);
375 strbuf_addstr(&cert, "\n");
377 for (ref = remote_refs; ref; ref = ref->next) {
378 if (check_to_send_update(ref, args) < 0)
379 continue;
380 update_seen = 1;
381 strbuf_addf(&cert, "%s %s %s\n",
382 oid_to_hex(&ref->old_oid),
383 oid_to_hex(&ref->new_oid),
384 ref->name);
386 if (!update_seen)
387 goto free_return;
389 if (sign_buffer(&cert, &cert, get_signing_key()))
390 die(_("failed to sign the push certificate"));
392 packet_buf_write(req_buf, "push-cert%c%s", 0, cap_string);
393 for (cp = cert.buf; cp < cert.buf + cert.len; cp = np) {
394 np = next_line(cp, cert.buf + cert.len - cp);
395 packet_buf_write(req_buf,
396 "%.*s", (int)(np - cp), cp);
398 packet_buf_write(req_buf, "push-cert-end\n");
400 free_return:
401 free(signing_key_id);
402 strbuf_release(&cert);
403 return update_seen;
406 #define NONCE_LEN_LIMIT 256
408 static void reject_invalid_nonce(const char *nonce, int len)
410 int i = 0;
412 if (NONCE_LEN_LIMIT <= len)
413 die("the receiving end asked to sign an invalid nonce <%.*s>",
414 len, nonce);
416 for (i = 0; i < len; i++) {
417 int ch = nonce[i] & 0xFF;
418 if (isalnum(ch) ||
419 ch == '-' || ch == '.' ||
420 ch == '/' || ch == '+' ||
421 ch == '=' || ch == '_')
422 continue;
423 die("the receiving end asked to sign an invalid nonce <%.*s>",
424 len, nonce);
428 static void get_commons_through_negotiation(const char *url,
429 const struct ref *remote_refs,
430 struct oid_array *commons)
432 struct child_process child = CHILD_PROCESS_INIT;
433 const struct ref *ref;
434 int len = the_hash_algo->hexsz + 1; /* hash + NL */
435 int nr_negotiation_tip = 0;
437 child.git_cmd = 1;
438 child.no_stdin = 1;
439 child.out = -1;
440 strvec_pushl(&child.args, "fetch", "--negotiate-only", NULL);
441 for (ref = remote_refs; ref; ref = ref->next) {
442 if (!is_null_oid(&ref->new_oid)) {
443 strvec_pushf(&child.args, "--negotiation-tip=%s",
444 oid_to_hex(&ref->new_oid));
445 nr_negotiation_tip++;
448 strvec_push(&child.args, url);
450 if (!nr_negotiation_tip) {
451 child_process_clear(&child);
452 return;
455 if (start_command(&child))
456 die(_("send-pack: unable to fork off fetch subprocess"));
458 do {
459 char hex_hash[GIT_MAX_HEXSZ + 1];
460 int read_len = read_in_full(child.out, hex_hash, len);
461 struct object_id oid;
462 const char *end;
464 if (!read_len)
465 break;
466 if (read_len != len)
467 die("invalid length read %d", read_len);
468 if (parse_oid_hex(hex_hash, &oid, &end) || *end != '\n')
469 die("invalid hash");
470 oid_array_append(commons, &oid);
471 } while (1);
473 if (finish_command(&child)) {
475 * The information that push negotiation provides is useful but
476 * not mandatory.
478 warning(_("push negotiation failed; proceeding anyway with push"));
482 int send_pack(struct send_pack_args *args,
483 int fd[], struct child_process *conn,
484 struct ref *remote_refs,
485 struct oid_array *extra_have)
487 struct oid_array commons = OID_ARRAY_INIT;
488 int in = fd[0];
489 int out = fd[1];
490 struct strbuf req_buf = STRBUF_INIT;
491 struct strbuf cap_buf = STRBUF_INIT;
492 struct ref *ref;
493 int need_pack_data = 0;
494 int allow_deleting_refs = 0;
495 int status_report = 0;
496 int use_sideband = 0;
497 int quiet_supported = 0;
498 int agent_supported = 0;
499 int advertise_sid = 0;
500 int push_negotiate = 0;
501 int use_atomic = 0;
502 int atomic_supported = 0;
503 int use_push_options = 0;
504 int push_options_supported = 0;
505 int object_format_supported = 0;
506 unsigned cmds_sent = 0;
507 int ret;
508 struct async demux;
509 const char *push_cert_nonce = NULL;
510 struct packet_reader reader;
511 int use_bitmaps;
513 if (!remote_refs) {
514 fprintf(stderr, "No refs in common and none specified; doing nothing.\n"
515 "Perhaps you should specify a branch.\n");
516 return 0;
519 git_config_get_bool("push.negotiate", &push_negotiate);
520 if (push_negotiate) {
521 trace2_region_enter("send_pack", "push_negotiate", the_repository);
522 get_commons_through_negotiation(args->url, remote_refs, &commons);
523 trace2_region_leave("send_pack", "push_negotiate", the_repository);
526 if (!git_config_get_bool("push.usebitmaps", &use_bitmaps))
527 args->disable_bitmaps = !use_bitmaps;
529 git_config_get_bool("transfer.advertisesid", &advertise_sid);
531 /* Does the other end support the reporting? */
532 if (server_supports("report-status-v2"))
533 status_report = 2;
534 else if (server_supports("report-status"))
535 status_report = 1;
536 if (server_supports("delete-refs"))
537 allow_deleting_refs = 1;
538 if (server_supports("ofs-delta"))
539 args->use_ofs_delta = 1;
540 if (server_supports("side-band-64k"))
541 use_sideband = 1;
542 if (server_supports("quiet"))
543 quiet_supported = 1;
544 if (server_supports("agent"))
545 agent_supported = 1;
546 if (!server_supports("session-id"))
547 advertise_sid = 0;
548 if (server_supports("no-thin"))
549 args->use_thin_pack = 0;
550 if (server_supports("atomic"))
551 atomic_supported = 1;
552 if (server_supports("push-options"))
553 push_options_supported = 1;
555 if (!server_supports_hash(the_hash_algo->name, &object_format_supported))
556 die(_("the receiving end does not support this repository's hash algorithm"));
558 if (args->push_cert != SEND_PACK_PUSH_CERT_NEVER) {
559 size_t len;
560 push_cert_nonce = server_feature_value("push-cert", &len);
561 if (push_cert_nonce) {
562 reject_invalid_nonce(push_cert_nonce, len);
563 push_cert_nonce = xmemdupz(push_cert_nonce, len);
564 } else if (args->push_cert == SEND_PACK_PUSH_CERT_ALWAYS) {
565 die(_("the receiving end does not support --signed push"));
566 } else if (args->push_cert == SEND_PACK_PUSH_CERT_IF_ASKED) {
567 warning(_("not sending a push certificate since the"
568 " receiving end does not support --signed"
569 " push"));
573 if (args->atomic && !atomic_supported)
574 die(_("the receiving end does not support --atomic push"));
576 use_atomic = atomic_supported && args->atomic;
578 if (args->push_options && !push_options_supported)
579 die(_("the receiving end does not support push options"));
581 use_push_options = push_options_supported && args->push_options;
583 if (status_report == 1)
584 strbuf_addstr(&cap_buf, " report-status");
585 else if (status_report == 2)
586 strbuf_addstr(&cap_buf, " report-status-v2");
587 if (use_sideband)
588 strbuf_addstr(&cap_buf, " side-band-64k");
589 if (quiet_supported && (args->quiet || !args->progress))
590 strbuf_addstr(&cap_buf, " quiet");
591 if (use_atomic)
592 strbuf_addstr(&cap_buf, " atomic");
593 if (use_push_options)
594 strbuf_addstr(&cap_buf, " push-options");
595 if (object_format_supported)
596 strbuf_addf(&cap_buf, " object-format=%s", the_hash_algo->name);
597 if (agent_supported)
598 strbuf_addf(&cap_buf, " agent=%s", git_user_agent_sanitized());
599 if (advertise_sid)
600 strbuf_addf(&cap_buf, " session-id=%s", trace2_session_id());
603 * NEEDSWORK: why does delete-refs have to be so specific to
604 * send-pack machinery that set_ref_status_for_push() cannot
605 * set this bit for us???
607 for (ref = remote_refs; ref; ref = ref->next)
608 if (ref->deletion && !allow_deleting_refs)
609 ref->status = REF_STATUS_REJECT_NODELETE;
612 * Clear the status for each ref and see if we need to send
613 * the pack data.
615 for (ref = remote_refs; ref; ref = ref->next) {
616 switch (check_to_send_update(ref, args)) {
617 case 0: /* no error */
618 break;
619 case CHECK_REF_STATUS_REJECTED:
621 * When we know the server would reject a ref update if
622 * we were to send it and we're trying to send the refs
623 * atomically, abort the whole operation.
625 if (use_atomic) {
626 strbuf_release(&req_buf);
627 strbuf_release(&cap_buf);
628 reject_atomic_push(remote_refs, args->send_mirror);
629 error("atomic push failed for ref %s. status: %d",
630 ref->name, ref->status);
631 return args->porcelain ? 0 : -1;
633 /* else fallthrough */
634 default:
635 continue;
637 if (!ref->deletion)
638 need_pack_data = 1;
640 if (args->dry_run || !status_report)
641 ref->status = REF_STATUS_OK;
642 else
643 ref->status = REF_STATUS_EXPECTING_REPORT;
646 if (!args->dry_run)
647 advertise_shallow_grafts_buf(&req_buf);
650 * Finally, tell the other end!
652 if (!args->dry_run && push_cert_nonce) {
653 cmds_sent = generate_push_cert(&req_buf, remote_refs, args,
654 cap_buf.buf, push_cert_nonce);
655 trace2_printf("Generated push certificate");
656 } else if (!args->dry_run) {
657 for (ref = remote_refs; ref; ref = ref->next) {
658 char *old_hex, *new_hex;
660 if (check_to_send_update(ref, args) < 0)
661 continue;
663 old_hex = oid_to_hex(&ref->old_oid);
664 new_hex = oid_to_hex(&ref->new_oid);
665 if (!cmds_sent) {
666 packet_buf_write(&req_buf,
667 "%s %s %s%c%s",
668 old_hex, new_hex, ref->name, 0,
669 cap_buf.buf);
670 cmds_sent = 1;
671 } else {
672 packet_buf_write(&req_buf, "%s %s %s",
673 old_hex, new_hex, ref->name);
678 if (use_push_options) {
679 struct string_list_item *item;
681 packet_buf_flush(&req_buf);
682 for_each_string_list_item(item, args->push_options)
683 packet_buf_write(&req_buf, "%s", item->string);
686 if (args->stateless_rpc) {
687 if (!args->dry_run && (cmds_sent || is_repository_shallow(the_repository))) {
688 packet_buf_flush(&req_buf);
689 send_sideband(out, -1, req_buf.buf, req_buf.len, LARGE_PACKET_MAX);
691 } else {
692 write_or_die(out, req_buf.buf, req_buf.len);
693 packet_flush(out);
695 strbuf_release(&req_buf);
696 strbuf_release(&cap_buf);
698 if (use_sideband && cmds_sent) {
699 memset(&demux, 0, sizeof(demux));
700 demux.proc = sideband_demux;
701 demux.data = fd;
702 demux.out = -1;
703 demux.isolate_sigpipe = 1;
704 if (start_async(&demux))
705 die("send-pack: unable to fork off sideband demultiplexer");
706 in = demux.out;
709 packet_reader_init(&reader, in, NULL, 0,
710 PACKET_READ_CHOMP_NEWLINE |
711 PACKET_READ_DIE_ON_ERR_PACKET);
713 if (need_pack_data && cmds_sent) {
714 if (pack_objects(out, remote_refs, extra_have, &commons, args) < 0) {
715 if (args->stateless_rpc)
716 close(out);
717 if (git_connection_is_socket(conn))
718 shutdown(fd[0], SHUT_WR);
721 * Do not even bother with the return value; we know we
722 * are failing, and just want the error() side effects,
723 * as well as marking refs with their remote status (if
724 * we get one).
726 if (status_report)
727 receive_status(&reader, remote_refs);
729 if (use_sideband) {
730 close(demux.out);
731 finish_async(&demux);
733 fd[1] = -1;
734 return -1;
736 if (!args->stateless_rpc)
737 /* Closed by pack_objects() via start_command() */
738 fd[1] = -1;
740 if (args->stateless_rpc && cmds_sent)
741 packet_flush(out);
743 if (status_report && cmds_sent)
744 ret = receive_status(&reader, remote_refs);
745 else
746 ret = 0;
747 if (args->stateless_rpc)
748 packet_flush(out);
750 if (use_sideband && cmds_sent) {
751 close(demux.out);
752 if (finish_async(&demux)) {
753 error("error in sideband demultiplexer");
754 ret = -1;
758 if (ret < 0)
759 return ret;
761 if (args->porcelain)
762 return 0;
764 for (ref = remote_refs; ref; ref = ref->next) {
765 switch (ref->status) {
766 case REF_STATUS_NONE:
767 case REF_STATUS_UPTODATE:
768 case REF_STATUS_OK:
769 break;
770 default:
771 return -1;
774 return 0;