package gitpb import ( "path/filepath" "strings" "go.wit.com/log" ) func (repo *Repo) DevelHash() string { brname := repo.GetDevelBranchName() refname := "refs/heads/" + brname all := repo.Tags.All() for all.Scan() { tag := all.Next() // log.Info("repo tag", tag.GetHash(), tag.GetRefname()) if tag.GetRefname() == refname { return tag.GetHash() } } return "" } func (repo *Repo) GetLocalHash(brname string) string { refname := "refs/heads/" + brname all := repo.Tags.All() for all.Scan() { tag := all.Next() // log.Info("repo tag", tag.GetHash(), tag.GetRefname()) if tag.GetRefname() == refname { return strings.TrimSpace(tag.GetHash()) } } return "" } func (repo *Repo) GetRemoteHash(brname string) string { refname := "refs/remotes/origin/" + brname all := repo.Tags.All() for all.Scan() { tag := all.Next() // log.Info("repo tag", tag.GetHash(), tag.GetRefname()) if tag.GetRefname() == refname { return strings.TrimSpace(tag.GetHash()) } } return "" } // this is the correct way. uses 'git show-ref' func (repo *Repo) IsBranchRemote(brname string) bool { if repo.Tags == nil { return false } brname = "refs/remotes/origin/" + brname ref := repo.Tags.FindByRefname(brname) if ref == nil { // log.Info("did not found refname!!!!!!!!", brname) return false } // log.Info("found refname!!!!!!!!") return true } // this is the correct way. uses 'git show-ref' func (repo *Repo) IsDevelRemote() bool { if repo.Tags == nil { return false } devname := repo.GetDevelBranchName() refname := "refs/remotes/origin/" + devname ref := repo.Tags.FindByRefname(refname) if ref == nil { // log.Info("did not found refname!!!!!!!!", refname) return false } // log.Info("found refname!!!!!!!!") return true } // find a branch namm // will find "master" or "devel" // will also find "v0.1.1" // or will find "patches-from-foo" // will return *any* match on any git branch because it doesn't // matter much here yet // eventually this will be worked out by forge in some future code that hasn't been made yet func (repo *Repo) IsBranch(findname string) bool { loop := repo.Tags.All() for loop.Scan() { t := loop.Next() // log.Info("LocalTagExists() tag:", t.Refname) tagname := t.Refname if strings.HasPrefix(tagname, "refs/remotes") { continue } path, filename := filepath.Split(tagname) log.Log(INFO, "gitpb.IsBranch() tag:", path, filename, "from", repo.GetGoPath()) if filename == findname { log.Log(INFO, "gitpb.IsBranch() found tag:", path, filename, "from", repo.GetGoPath()) return true } } log.Log(INFO, "did not find tag:", findname, "in", repo.GetGoPath()) return false } func (repo *Repo) IsLocalBranch(findname string) bool { loop := repo.Tags.All() for loop.Scan() { t := loop.Next() if !strings.HasPrefix(t.Refname, "refs/heads") { // log.Info("LocalTagExists() skip tag:", t.Refname) continue } // log.Info("LocalTagExists() check tag:", t.Refname) path, filename := filepath.Split(t.Refname) log.Log(INFO, "gitpb.IsBranch() tag:", path, filename, "from", repo.GetGoPath()) if filename == findname { log.Log(INFO, "gitpb.IsBranch() found tag:", path, filename, "from", repo.GetGoPath()) return true } } log.Log(INFO, "did not find tag:", findname, "in", repo.GetGoPath()) return false } // finds the newest tag. used for deciding if master needs to be published func (repo *Repo) FindLastTag() string { var newest *GitTag all := repo.Tags.All() for all.Scan() { tag := all.Next() if !strings.HasPrefix(tag.GetRefname(), "refs/tags/") { continue } if newest == nil { newest = tag continue } cur := newest.Creatordate.AsTime() if cur.Before(tag.Creatordate.AsTime()) { newest = tag } // newtag := strings.TrimPrefix(tag.GetRefname(), "refs/tags/") // log.Info("repo tag", tag.GetHash(), tag.Creatordate.AsTime(), tag.GetRefname(), newtag) } if newest == nil { return "" } // log.Info("repo newest tag", newest.GetHash(), newest.Creatordate.AsTime(), newest.GetRefname()) newtag := strings.TrimPrefix(newest.GetRefname(), "refs/tags/") return newtag }