aboutsummaryrefslogtreecommitdiff
path: root/git
diff options
context:
space:
mode:
authorAnirudh Oppiliappan <x@icyphox.sh>2022-12-13 09:58:40 +0530
committerAnirudh Oppiliappan <x@icyphox.sh>2022-12-13 09:58:40 +0530
commiteda8b58d9f2e85f1bae92ce3b70f279b89031046 (patch)
tree8b365320501fbbcac08f7abb9087eaef9c9b2711 /git
parentdeps: bump go-git (diff)
downloadlegitrx-eda8b58d9f2e85f1bae92ce3b70f279b89031046.tar.gz
legitrx-eda8b58d9f2e85f1bae92ce3b70f279b89031046.tar.zst
legitrx-eda8b58d9f2e85f1bae92ce3b70f279b89031046.zip
git: find main branch from config
Diffstat (limited to 'git')
-rw-r--r--git/git.go10
1 files changed, 10 insertions, 0 deletions
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")
+}