MCPcopy Create free account
hub / github.com/github/gh-aw / parseDefaultBranchFromLsRemote

Function parseDefaultBranchFromLsRemote

pkg/cli/add_interactive_git.go:343–358  ·  view source on GitHub ↗

parseDefaultBranchFromLsRemote extracts the default branch name from the output of `git ls-remote --symref origin HEAD`. Example output: ref: refs/heads/main abc123 abc123 HEAD Returns "" if the branch cannot be determined.

(output string)

Source from the content-addressed store, hash-verified

341//
342// Returns "" if the branch cannot be determined.
343func parseDefaultBranchFromLsRemote(output string) string {
344 for line := range strings.SplitSeq(output, "\n") {
345 if !strings.HasPrefix(line, "ref: refs/heads/") {
346 continue
347 }
348 // line is e.g. "ref: refs/heads/main\tabc123"
349 // Split on tab first to isolate the symref part from the hash.
350 tabParts := strings.SplitN(line, "\t", 2)
351 ref := strings.TrimPrefix(tabParts[0], "ref: refs/heads/")
352 ref = strings.TrimSpace(ref)
353 if ref != "" {
354 return ref
355 }
356 }
357 return ""
358}

Calls

no outgoing calls