diff --git a/repoNew.go b/repoNew.go index a152dc1..17adeb2 100644 --- a/repoNew.go +++ b/repoNew.go @@ -2,6 +2,7 @@ package forgepb import ( "fmt" + "os" "path/filepath" "strings" @@ -48,12 +49,22 @@ func (f *Forge) ValidGoVersion(ver string) (bool, error) { func (f *Forge) findMasterBranch(repo *gitpb.Repo) { // check the forge config first if bname := f.Config.FindMasterBranch(repo.GetGoPath()); bname != "" { - log.Info("FOUND CONFIG NAME", bname) - log.Info("FOUND CONFIG NAME", bname) - log.Info("FOUND CONFIG NAME", bname) + log.Info("Using master branch name from forge config:", bname) repo.SetMasterBranchName(bname) return } + // todo: fix this after .git parsing is better or libgit2 is being used + headfile := filepath.Join(repo.GetFullPath(), ".git/refs/remotes/origin/HEAD") + if data, err := os.ReadFile(headfile); err == nil { + s := string(data) + if strings.HasPrefix(s, "ref: ") { + fields := strings.Fields(s) + _, bname := filepath.Split(fields[1]) + log.Info("Using master branch name from .git/ HEAD:", bname) + repo.SetMasterBranchName(bname) + return + } + } // try to guess what the 'master' branch is if repo.IsBranch("master") {