MCPcopy Create free account
hub / github.com/git/git / remote_default_branch

Function remote_default_branch

scalar.c:341–390  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

339}
340
341static 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
392static int delete_enlistment(struct strbuf *enlistment)
393{

Callers 1

cmd_cloneFunction · 0.85

Calls 10

strvec_pushlFunction · 0.85
pipe_commandFunction · 0.85
strip_suffix_memFunction · 0.85
xstrndupFunction · 0.85
strbuf_releaseFunction · 0.85
errorFunction · 0.85
warningFunction · 0.85
child_process_initFunction · 0.85
strbuf_trimFunction · 0.85
strbuf_detachFunction · 0.85

Tested by

no test coverage detected