Monorepo for Tangled tangled.org

knotserver/git: refactor FindMainBranch to use `git rev-parse`

Signed-off-by: oppiliappan <me@oppi.li>

oppi.li 19a0c4cb 0950f59c

verified
Changed files
+3 -6
knotserver
git
+3 -6
knotserver/git/git.go
··· 316 316 } 317 317 318 318 func (g *GitRepo) FindMainBranch() (string, error) { 319 - ref, err := g.r.Head() 319 + output, err := g.revParse("--abbrev-ref", "HEAD") 320 320 if err != nil { 321 - return "", fmt.Errorf("unable to find main branch: %w", err) 322 - } 323 - if ref.Name().IsBranch() { 324 - return strings.TrimPrefix(string(ref.Name()), "refs/heads/"), nil 321 + return "", fmt.Errorf("failed to find main branch: %w", err) 325 322 } 326 323 327 - return "", fmt.Errorf("unable to find main branch: %w", err) 324 + return strings.TrimSpace(string(output)), nil 328 325 } 329 326 330 327 // WriteTar writes itself from a tree into a binary tar file format.