send-pack.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681
  1. #include "builtin.h"
  2. #include "config.h"
  3. #include "commit.h"
  4. #include "refs.h"
  5. #include "object-store.h"
  6. #include "pkt-line.h"
  7. #include "sideband.h"
  8. #include "run-command.h"
  9. #include "remote.h"
  10. #include "connect.h"
  11. #include "send-pack.h"
  12. #include "quote.h"
  13. #include "transport.h"
  14. #include "version.h"
  15. #include "oid-array.h"
  16. #include "gpg-interface.h"
  17. #include "cache.h"
  18. #include "shallow.h"
  19. int option_parse_push_signed(const struct option *opt,
  20. const char *arg, int unset)
  21. {
  22. if (unset) {
  23. *(int *)(opt->value) = SEND_PACK_PUSH_CERT_NEVER;
  24. return 0;
  25. }
  26. switch (git_parse_maybe_bool(arg)) {
  27. case 1:
  28. *(int *)(opt->value) = SEND_PACK_PUSH_CERT_ALWAYS;
  29. return 0;
  30. case 0:
  31. *(int *)(opt->value) = SEND_PACK_PUSH_CERT_NEVER;
  32. return 0;
  33. }
  34. if (!strcasecmp("if-asked", arg)) {
  35. *(int *)(opt->value) = SEND_PACK_PUSH_CERT_IF_ASKED;
  36. return 0;
  37. }
  38. die("bad %s argument: %s", opt->long_name, arg);
  39. }
  40. static void feed_object(const struct object_id *oid, FILE *fh, int negative)
  41. {
  42. if (negative &&
  43. !has_object_file_with_flags(oid,
  44. OBJECT_INFO_SKIP_FETCH_OBJECT |
  45. OBJECT_INFO_QUICK))
  46. return;
  47. if (negative)
  48. putc('^', fh);
  49. fputs(oid_to_hex(oid), fh);
  50. putc('\n', fh);
  51. }
  52. /*
  53. * Make a pack stream and spit it out into file descriptor fd
  54. */
  55. static int pack_objects(int fd, struct ref *refs, struct oid_array *extra, struct send_pack_args *args)
  56. {
  57. /*
  58. * The child becomes pack-objects --revs; we feed
  59. * the revision parameters to it via its stdin and
  60. * let its stdout go back to the other end.
  61. */
  62. struct child_process po = CHILD_PROCESS_INIT;
  63. FILE *po_in;
  64. int i;
  65. int rc;
  66. strvec_push(&po.args, "pack-objects");
  67. strvec_push(&po.args, "--all-progress-implied");
  68. strvec_push(&po.args, "--revs");
  69. strvec_push(&po.args, "--stdout");
  70. if (args->use_thin_pack)
  71. strvec_push(&po.args, "--thin");
  72. if (args->use_ofs_delta)
  73. strvec_push(&po.args, "--delta-base-offset");
  74. if (args->quiet || !args->progress)
  75. strvec_push(&po.args, "-q");
  76. if (args->progress)
  77. strvec_push(&po.args, "--progress");
  78. if (is_repository_shallow(the_repository))
  79. strvec_push(&po.args, "--shallow");
  80. po.in = -1;
  81. po.out = args->stateless_rpc ? -1 : fd;
  82. po.git_cmd = 1;
  83. if (start_command(&po))
  84. die_errno("git pack-objects failed");
  85. /*
  86. * We feed the pack-objects we just spawned with revision
  87. * parameters by writing to the pipe.
  88. */
  89. po_in = xfdopen(po.in, "w");
  90. for (i = 0; i < extra->nr; i++)
  91. feed_object(&extra->oid[i], po_in, 1);
  92. while (refs) {
  93. if (!is_null_oid(&refs->old_oid))
  94. feed_object(&refs->old_oid, po_in, 1);
  95. if (!is_null_oid(&refs->new_oid))
  96. feed_object(&refs->new_oid, po_in, 0);
  97. refs = refs->next;
  98. }
  99. fflush(po_in);
  100. if (ferror(po_in))
  101. die_errno("error writing to pack-objects");
  102. fclose(po_in);
  103. if (args->stateless_rpc) {
  104. char *buf = xmalloc(LARGE_PACKET_MAX);
  105. while (1) {
  106. ssize_t n = xread(po.out, buf, LARGE_PACKET_MAX);
  107. if (n <= 0)
  108. break;
  109. send_sideband(fd, -1, buf, n, LARGE_PACKET_MAX);
  110. }
  111. free(buf);
  112. close(po.out);
  113. po.out = -1;
  114. }
  115. rc = finish_command(&po);
  116. if (rc) {
  117. /*
  118. * For a normal non-zero exit, we assume pack-objects wrote
  119. * something useful to stderr. For death by signal, though,
  120. * we should mention it to the user. The exception is SIGPIPE
  121. * (141), because that's a normal occurrence if the remote end
  122. * hangs up (and we'll report that by trying to read the unpack
  123. * status).
  124. */
  125. if (rc > 128 && rc != 141)
  126. error("pack-objects died of signal %d", rc - 128);
  127. return -1;
  128. }
  129. return 0;
  130. }
  131. static int receive_unpack_status(struct packet_reader *reader)
  132. {
  133. if (packet_reader_read(reader) != PACKET_READ_NORMAL)
  134. return error(_("unexpected flush packet while reading remote unpack status"));
  135. if (!skip_prefix(reader->line, "unpack ", &reader->line))
  136. return error(_("unable to parse remote unpack status: %s"), reader->line);
  137. if (strcmp(reader->line, "ok"))
  138. return error(_("remote unpack failed: %s"), reader->line);
  139. return 0;
  140. }
  141. static int receive_status(struct packet_reader *reader, struct ref *refs)
  142. {
  143. struct ref *hint;
  144. int ret;
  145. struct ref_push_report *report = NULL;
  146. int new_report = 0;
  147. int once = 0;
  148. hint = NULL;
  149. ret = receive_unpack_status(reader);
  150. while (1) {
  151. struct object_id old_oid, new_oid;
  152. const char *head;
  153. const char *refname;
  154. char *p;
  155. if (packet_reader_read(reader) != PACKET_READ_NORMAL)
  156. break;
  157. head = reader->line;
  158. p = strchr(head, ' ');
  159. if (!p) {
  160. error("invalid status line from remote: %s", reader->line);
  161. ret = -1;
  162. break;
  163. }
  164. *p++ = '\0';
  165. if (!strcmp(head, "option")) {
  166. const char *key, *val;
  167. if (!hint || !(report || new_report)) {
  168. if (!once++)
  169. error("'option' without a matching 'ok/ng' directive");
  170. ret = -1;
  171. continue;
  172. }
  173. if (new_report) {
  174. if (!hint->report) {
  175. hint->report = xcalloc(1, sizeof(struct ref_push_report));
  176. report = hint->report;
  177. } else {
  178. report = hint->report;
  179. while (report->next)
  180. report = report->next;
  181. report->next = xcalloc(1, sizeof(struct ref_push_report));
  182. report = report->next;
  183. }
  184. new_report = 0;
  185. }
  186. key = p;
  187. p = strchr(key, ' ');
  188. if (p)
  189. *p++ = '\0';
  190. val = p;
  191. if (!strcmp(key, "refname"))
  192. report->ref_name = xstrdup_or_null(val);
  193. else if (!strcmp(key, "old-oid") && val &&
  194. !parse_oid_hex(val, &old_oid, &val))
  195. report->old_oid = oiddup(&old_oid);
  196. else if (!strcmp(key, "new-oid") && val &&
  197. !parse_oid_hex(val, &new_oid, &val))
  198. report->new_oid = oiddup(&new_oid);
  199. else if (!strcmp(key, "forced-update"))
  200. report->forced_update = 1;
  201. continue;
  202. }
  203. report = NULL;
  204. new_report = 0;
  205. if (strcmp(head, "ok") && strcmp(head, "ng")) {
  206. error("invalid ref status from remote: %s", head);
  207. ret = -1;
  208. break;
  209. }
  210. refname = p;
  211. p = strchr(refname, ' ');
  212. if (p)
  213. *p++ = '\0';
  214. /* first try searching at our hint, falling back to all refs */
  215. if (hint)
  216. hint = find_ref_by_name(hint, refname);
  217. if (!hint)
  218. hint = find_ref_by_name(refs, refname);
  219. if (!hint) {
  220. warning("remote reported status on unknown ref: %s",
  221. refname);
  222. continue;
  223. }
  224. if (hint->status != REF_STATUS_EXPECTING_REPORT &&
  225. hint->status != REF_STATUS_OK &&
  226. hint->status != REF_STATUS_REMOTE_REJECT) {
  227. warning("remote reported status on unexpected ref: %s",
  228. refname);
  229. continue;
  230. }
  231. if (!strcmp(head, "ng")) {
  232. hint->status = REF_STATUS_REMOTE_REJECT;
  233. if (p)
  234. hint->remote_status = xstrdup(p);
  235. else
  236. hint->remote_status = "failed";
  237. } else {
  238. hint->status = REF_STATUS_OK;
  239. hint->remote_status = xstrdup_or_null(p);
  240. new_report = 1;
  241. }
  242. }
  243. return ret;
  244. }
  245. static int sideband_demux(int in, int out, void *data)
  246. {
  247. int *fd = data, ret;
  248. if (async_with_fork())
  249. close(fd[1]);
  250. ret = recv_sideband("send-pack", fd[0], out);
  251. close(out);
  252. return ret;
  253. }
  254. static int advertise_shallow_grafts_cb(const struct commit_graft *graft, void *cb)
  255. {
  256. struct strbuf *sb = cb;
  257. if (graft->nr_parent == -1)
  258. packet_buf_write(sb, "shallow %s\n", oid_to_hex(&graft->oid));
  259. return 0;
  260. }
  261. static void advertise_shallow_grafts_buf(struct strbuf *sb)
  262. {
  263. if (!is_repository_shallow(the_repository))
  264. return;
  265. for_each_commit_graft(advertise_shallow_grafts_cb, sb);
  266. }
  267. #define CHECK_REF_NO_PUSH -1
  268. #define CHECK_REF_STATUS_REJECTED -2
  269. #define CHECK_REF_UPTODATE -3
  270. static int check_to_send_update(const struct ref *ref, const struct send_pack_args *args)
  271. {
  272. if (!ref->peer_ref && !args->send_mirror)
  273. return CHECK_REF_NO_PUSH;
  274. /* Check for statuses set by set_ref_status_for_push() */
  275. switch (ref->status) {
  276. case REF_STATUS_REJECT_NONFASTFORWARD:
  277. case REF_STATUS_REJECT_ALREADY_EXISTS:
  278. case REF_STATUS_REJECT_FETCH_FIRST:
  279. case REF_STATUS_REJECT_NEEDS_FORCE:
  280. case REF_STATUS_REJECT_STALE:
  281. case REF_STATUS_REJECT_NODELETE:
  282. return CHECK_REF_STATUS_REJECTED;
  283. case REF_STATUS_UPTODATE:
  284. return CHECK_REF_UPTODATE;
  285. default:
  286. case REF_STATUS_EXPECTING_REPORT:
  287. /* already passed checks on the local side */
  288. case REF_STATUS_OK:
  289. /* of course this is OK */
  290. return 0;
  291. }
  292. }
  293. /*
  294. * the beginning of the next line, or the end of buffer.
  295. *
  296. * NEEDSWORK: perhaps move this to git-compat-util.h or somewhere and
  297. * convert many similar uses found by "git grep -A4 memchr".
  298. */
  299. static const char *next_line(const char *line, size_t len)
  300. {
  301. const char *nl = memchr(line, '\n', len);
  302. if (!nl)
  303. return line + len; /* incomplete line */
  304. return nl + 1;
  305. }
  306. static int generate_push_cert(struct strbuf *req_buf,
  307. const struct ref *remote_refs,
  308. struct send_pack_args *args,
  309. const char *cap_string,
  310. const char *push_cert_nonce)
  311. {
  312. const struct ref *ref;
  313. struct string_list_item *item;
  314. char *signing_key = xstrdup(get_signing_key());
  315. const char *cp, *np;
  316. struct strbuf cert = STRBUF_INIT;
  317. int update_seen = 0;
  318. strbuf_addstr(&cert, "certificate version 0.1\n");
  319. strbuf_addf(&cert, "pusher %s ", signing_key);
  320. datestamp(&cert);
  321. strbuf_addch(&cert, '\n');
  322. if (args->url && *args->url) {
  323. char *anon_url = transport_anonymize_url(args->url);
  324. strbuf_addf(&cert, "pushee %s\n", anon_url);
  325. free(anon_url);
  326. }
  327. if (push_cert_nonce[0])
  328. strbuf_addf(&cert, "nonce %s\n", push_cert_nonce);
  329. if (args->push_options)
  330. for_each_string_list_item(item, args->push_options)
  331. strbuf_addf(&cert, "push-option %s\n", item->string);
  332. strbuf_addstr(&cert, "\n");
  333. for (ref = remote_refs; ref; ref = ref->next) {
  334. if (check_to_send_update(ref, args) < 0)
  335. continue;
  336. update_seen = 1;
  337. strbuf_addf(&cert, "%s %s %s\n",
  338. oid_to_hex(&ref->old_oid),
  339. oid_to_hex(&ref->new_oid),
  340. ref->name);
  341. }
  342. if (!update_seen)
  343. goto free_return;
  344. if (sign_buffer(&cert, &cert, signing_key))
  345. die(_("failed to sign the push certificate"));
  346. packet_buf_write(req_buf, "push-cert%c%s", 0, cap_string);
  347. for (cp = cert.buf; cp < cert.buf + cert.len; cp = np) {
  348. np = next_line(cp, cert.buf + cert.len - cp);
  349. packet_buf_write(req_buf,
  350. "%.*s", (int)(np - cp), cp);
  351. }
  352. packet_buf_write(req_buf, "push-cert-end\n");
  353. free_return:
  354. free(signing_key);
  355. strbuf_release(&cert);
  356. return update_seen;
  357. }
  358. #define NONCE_LEN_LIMIT 256
  359. static void reject_invalid_nonce(const char *nonce, int len)
  360. {
  361. int i = 0;
  362. if (NONCE_LEN_LIMIT <= len)
  363. die("the receiving end asked to sign an invalid nonce <%.*s>",
  364. len, nonce);
  365. for (i = 0; i < len; i++) {
  366. int ch = nonce[i] & 0xFF;
  367. if (isalnum(ch) ||
  368. ch == '-' || ch == '.' ||
  369. ch == '/' || ch == '+' ||
  370. ch == '=' || ch == '_')
  371. continue;
  372. die("the receiving end asked to sign an invalid nonce <%.*s>",
  373. len, nonce);
  374. }
  375. }
  376. int send_pack(struct send_pack_args *args,
  377. int fd[], struct child_process *conn,
  378. struct ref *remote_refs,
  379. struct oid_array *extra_have)
  380. {
  381. int in = fd[0];
  382. int out = fd[1];
  383. struct strbuf req_buf = STRBUF_INIT;
  384. struct strbuf cap_buf = STRBUF_INIT;
  385. struct ref *ref;
  386. int need_pack_data = 0;
  387. int allow_deleting_refs = 0;
  388. int status_report = 0;
  389. int use_sideband = 0;
  390. int quiet_supported = 0;
  391. int agent_supported = 0;
  392. int use_atomic = 0;
  393. int atomic_supported = 0;
  394. int use_push_options = 0;
  395. int push_options_supported = 0;
  396. int object_format_supported = 0;
  397. unsigned cmds_sent = 0;
  398. int ret;
  399. struct async demux;
  400. const char *push_cert_nonce = NULL;
  401. struct packet_reader reader;
  402. /* Does the other end support the reporting? */
  403. if (server_supports("report-status-v2"))
  404. status_report = 2;
  405. else if (server_supports("report-status"))
  406. status_report = 1;
  407. if (server_supports("delete-refs"))
  408. allow_deleting_refs = 1;
  409. if (server_supports("ofs-delta"))
  410. args->use_ofs_delta = 1;
  411. if (server_supports("side-band-64k"))
  412. use_sideband = 1;
  413. if (server_supports("quiet"))
  414. quiet_supported = 1;
  415. if (server_supports("agent"))
  416. agent_supported = 1;
  417. if (server_supports("no-thin"))
  418. args->use_thin_pack = 0;
  419. if (server_supports("atomic"))
  420. atomic_supported = 1;
  421. if (server_supports("push-options"))
  422. push_options_supported = 1;
  423. if (!server_supports_hash(the_hash_algo->name, &object_format_supported))
  424. die(_("the receiving end does not support this repository's hash algorithm"));
  425. if (args->push_cert != SEND_PACK_PUSH_CERT_NEVER) {
  426. int len;
  427. push_cert_nonce = server_feature_value("push-cert", &len);
  428. if (push_cert_nonce) {
  429. reject_invalid_nonce(push_cert_nonce, len);
  430. push_cert_nonce = xmemdupz(push_cert_nonce, len);
  431. } else if (args->push_cert == SEND_PACK_PUSH_CERT_ALWAYS) {
  432. die(_("the receiving end does not support --signed push"));
  433. } else if (args->push_cert == SEND_PACK_PUSH_CERT_IF_ASKED) {
  434. warning(_("not sending a push certificate since the"
  435. " receiving end does not support --signed"
  436. " push"));
  437. }
  438. }
  439. if (!remote_refs) {
  440. fprintf(stderr, "No refs in common and none specified; doing nothing.\n"
  441. "Perhaps you should specify a branch.\n");
  442. return 0;
  443. }
  444. if (args->atomic && !atomic_supported)
  445. die(_("the receiving end does not support --atomic push"));
  446. use_atomic = atomic_supported && args->atomic;
  447. if (args->push_options && !push_options_supported)
  448. die(_("the receiving end does not support push options"));
  449. use_push_options = push_options_supported && args->push_options;
  450. if (status_report == 1)
  451. strbuf_addstr(&cap_buf, " report-status");
  452. else if (status_report == 2)
  453. strbuf_addstr(&cap_buf, " report-status-v2");
  454. if (use_sideband)
  455. strbuf_addstr(&cap_buf, " side-band-64k");
  456. if (quiet_supported && (args->quiet || !args->progress))
  457. strbuf_addstr(&cap_buf, " quiet");
  458. if (use_atomic)
  459. strbuf_addstr(&cap_buf, " atomic");
  460. if (use_push_options)
  461. strbuf_addstr(&cap_buf, " push-options");
  462. if (object_format_supported)
  463. strbuf_addf(&cap_buf, " object-format=%s", the_hash_algo->name);
  464. if (agent_supported)
  465. strbuf_addf(&cap_buf, " agent=%s", git_user_agent_sanitized());
  466. /*
  467. * NEEDSWORK: why does delete-refs have to be so specific to
  468. * send-pack machinery that set_ref_status_for_push() cannot
  469. * set this bit for us???
  470. */
  471. for (ref = remote_refs; ref; ref = ref->next)
  472. if (ref->deletion && !allow_deleting_refs)
  473. ref->status = REF_STATUS_REJECT_NODELETE;
  474. /*
  475. * Clear the status for each ref and see if we need to send
  476. * the pack data.
  477. */
  478. for (ref = remote_refs; ref; ref = ref->next) {
  479. switch (check_to_send_update(ref, args)) {
  480. case 0: /* no error */
  481. break;
  482. case CHECK_REF_STATUS_REJECTED:
  483. /*
  484. * When we know the server would reject a ref update if
  485. * we were to send it and we're trying to send the refs
  486. * atomically, abort the whole operation.
  487. */
  488. if (use_atomic) {
  489. strbuf_release(&req_buf);
  490. strbuf_release(&cap_buf);
  491. reject_atomic_push(remote_refs, args->send_mirror);
  492. error("atomic push failed for ref %s. status: %d\n",
  493. ref->name, ref->status);
  494. return args->porcelain ? 0 : -1;
  495. }
  496. /* else fallthrough */
  497. default:
  498. continue;
  499. }
  500. if (!ref->deletion)
  501. need_pack_data = 1;
  502. if (args->dry_run || !status_report)
  503. ref->status = REF_STATUS_OK;
  504. else
  505. ref->status = REF_STATUS_EXPECTING_REPORT;
  506. }
  507. if (!args->dry_run)
  508. advertise_shallow_grafts_buf(&req_buf);
  509. /*
  510. * Finally, tell the other end!
  511. */
  512. if (!args->dry_run && push_cert_nonce)
  513. cmds_sent = generate_push_cert(&req_buf, remote_refs, args,
  514. cap_buf.buf, push_cert_nonce);
  515. else if (!args->dry_run)
  516. for (ref = remote_refs; ref; ref = ref->next) {
  517. char *old_hex, *new_hex;
  518. if (check_to_send_update(ref, args) < 0)
  519. continue;
  520. old_hex = oid_to_hex(&ref->old_oid);
  521. new_hex = oid_to_hex(&ref->new_oid);
  522. if (!cmds_sent) {
  523. packet_buf_write(&req_buf,
  524. "%s %s %s%c%s",
  525. old_hex, new_hex, ref->name, 0,
  526. cap_buf.buf);
  527. cmds_sent = 1;
  528. } else {
  529. packet_buf_write(&req_buf, "%s %s %s",
  530. old_hex, new_hex, ref->name);
  531. }
  532. }
  533. if (use_push_options) {
  534. struct string_list_item *item;
  535. packet_buf_flush(&req_buf);
  536. for_each_string_list_item(item, args->push_options)
  537. packet_buf_write(&req_buf, "%s", item->string);
  538. }
  539. if (args->stateless_rpc) {
  540. if (!args->dry_run && (cmds_sent || is_repository_shallow(the_repository))) {
  541. packet_buf_flush(&req_buf);
  542. send_sideband(out, -1, req_buf.buf, req_buf.len, LARGE_PACKET_MAX);
  543. }
  544. } else {
  545. write_or_die(out, req_buf.buf, req_buf.len);
  546. packet_flush(out);
  547. }
  548. strbuf_release(&req_buf);
  549. strbuf_release(&cap_buf);
  550. if (use_sideband && cmds_sent) {
  551. memset(&demux, 0, sizeof(demux));
  552. demux.proc = sideband_demux;
  553. demux.data = fd;
  554. demux.out = -1;
  555. demux.isolate_sigpipe = 1;
  556. if (start_async(&demux))
  557. die("send-pack: unable to fork off sideband demultiplexer");
  558. in = demux.out;
  559. }
  560. packet_reader_init(&reader, in, NULL, 0,
  561. PACKET_READ_CHOMP_NEWLINE |
  562. PACKET_READ_DIE_ON_ERR_PACKET);
  563. if (need_pack_data && cmds_sent) {
  564. if (pack_objects(out, remote_refs, extra_have, args) < 0) {
  565. if (args->stateless_rpc)
  566. close(out);
  567. if (git_connection_is_socket(conn))
  568. shutdown(fd[0], SHUT_WR);
  569. /*
  570. * Do not even bother with the return value; we know we
  571. * are failing, and just want the error() side effects,
  572. * as well as marking refs with their remote status (if
  573. * we get one).
  574. */
  575. if (status_report)
  576. receive_status(&reader, remote_refs);
  577. if (use_sideband) {
  578. close(demux.out);
  579. finish_async(&demux);
  580. }
  581. fd[1] = -1;
  582. return -1;
  583. }
  584. if (!args->stateless_rpc)
  585. /* Closed by pack_objects() via start_command() */
  586. fd[1] = -1;
  587. }
  588. if (args->stateless_rpc && cmds_sent)
  589. packet_flush(out);
  590. if (status_report && cmds_sent)
  591. ret = receive_status(&reader, remote_refs);
  592. else
  593. ret = 0;
  594. if (args->stateless_rpc)
  595. packet_flush(out);
  596. if (use_sideband && cmds_sent) {
  597. close(demux.out);
  598. if (finish_async(&demux)) {
  599. error("error in sideband demultiplexer");
  600. ret = -1;
  601. }
  602. }
  603. if (ret < 0)
  604. return ret;
  605. if (args->porcelain)
  606. return 0;
  607. for (ref = remote_refs; ref; ref = ref->next) {
  608. switch (ref->status) {
  609. case REF_STATUS_NONE:
  610. case REF_STATUS_UPTODATE:
  611. case REF_STATUS_OK:
  612. break;
  613. default:
  614. return -1;
  615. }
  616. }
  617. return 0;
  618. }