| 339 | } |
| 340 | |
| 341 | static char *remote_default_branch(const char *url) |
| 342 | { |
| 343 | struct child_process cp = CHILD_PROCESS_INIT; |
| 344 | struct strbuf out = STRBUF_INIT; |
| 345 | |
| 346 | cp.git_cmd = 1; |
| 347 | strvec_pushl(&cp.args, "ls-remote", "--symref", url, "HEAD", NULL); |
| 348 | if (!pipe_command(&cp, NULL, 0, &out, 0, NULL, 0)) { |
| 349 | const char *line = out.buf; |
| 350 | |
| 351 | while (*line) { |
| 352 | const char *eol = strchrnul(line, '\n'), *p; |
| 353 | size_t len = eol - line; |
| 354 | char *branch; |
| 355 | |
| 356 | if (!skip_prefix(line, "ref: ", &p) || |
| 357 | !strip_suffix_mem(line, &len, "\tHEAD")) { |
| 358 | line = eol + (*eol == '\n'); |
| 359 | continue; |
| 360 | } |
| 361 | |
| 362 | eol = line + len; |
| 363 | if (skip_prefix(p, "refs/heads/", &p)) { |
| 364 | branch = xstrndup(p, eol - p); |
| 365 | strbuf_release(&out); |
| 366 | return branch; |
| 367 | } |
| 368 | |
| 369 | error(_("remote HEAD is not a branch: '%.*s'"), |
| 370 | (int)(eol - p), p); |
| 371 | strbuf_release(&out); |
| 372 | return NULL; |
| 373 | } |
| 374 | } |
| 375 | warning(_("failed to get default branch name from remote; " |
| 376 | "using local default")); |
| 377 | strbuf_reset(&out); |
| 378 | |
| 379 | child_process_init(&cp); |
| 380 | cp.git_cmd = 1; |
| 381 | strvec_pushl(&cp.args, "symbolic-ref", "--short", "HEAD", NULL); |
| 382 | if (!pipe_command(&cp, NULL, 0, &out, 0, NULL, 0)) { |
| 383 | strbuf_trim(&out); |
| 384 | return strbuf_detach(&out, NULL); |
| 385 | } |
| 386 | |
| 387 | strbuf_release(&out); |
| 388 | error(_("failed to get default branch name")); |
| 389 | return NULL; |
| 390 | } |
| 391 | |
| 392 | static int delete_enlistment(struct strbuf *enlistment) |
| 393 | { |
no test coverage detected