From eda8b58d9f2e85f1bae92ce3b70f279b89031046 Mon Sep 17 00:00:00 2001 From: Anirudh Oppiliappan Date: Tue, 13 Dec 2022 09:58:40 +0530 Subject: git: find main branch from config --- git/git.go | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'git/git.go') diff --git a/git/git.go b/git/git.go index a34d679..3756840 100644 --- a/git/git.go +++ b/git/git.go @@ -110,3 +110,13 @@ func (g *GitRepo) Branches() ([]*plumbing.Reference, error) { return branches, nil } + +func (g *GitRepo) FindMainBranch(branches []string) (string, error) { + for _, b := range branches { + _, err := g.r.ResolveRevision(plumbing.Revision(b)) + if err == nil { + return b, nil + } + } + return "", fmt.Errorf("unable to find main branch") +} -- cgit