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)
| 341 | // |
| 342 | // Returns "" if the branch cannot be determined. |
| 343 | func 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 | } |
no outgoing calls