summaryrefslogtreecommitdiffstats
path: root/git
diff options
context:
space:
mode:
authorLibravatar Anirudh Oppiliappan <x@icyphox.sh>2022-12-13 09:58:40 +0530
committerLibravatar Anirudh Oppiliappan <x@icyphox.sh>2022-12-13 09:58:40 +0530
commiteda8b58d9f2e85f1bae92ce3b70f279b89031046 (patch)
tree8b365320501fbbcac08f7abb9087eaef9c9b2711 /git
parent551c6637250172c5a2ca05070c011b1d72bb7d02 (diff)
downloadlegit-eda8b58d9f2e85f1bae92ce3b70f279b89031046.tar.gz
legit-eda8b58d9f2e85f1bae92ce3b70f279b89031046.tar.bz2
legit-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")
+}