IsLocalBranch()

This commit is contained in:
Jeff Carr 2024-12-13 16:18:25 -06:00
parent d7a90a71ab
commit 2574ec733a
2 changed files with 40 additions and 1 deletions

View File

@ -211,6 +211,28 @@ func (repo *Repo) IsBranch(findname string) bool {
return false
}
// todo: redo this and above. both are messed up. ignore for now until things are stable
func (repo *Repo) IsLocalBranch(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/heads") {
continue
}
path, filename := filepath.Split(tagname)
log.Log(GITPB, "gitpb.IsBranch() tag:", path, filename, "from", repo.GoPath)
if filename == findname {
log.Log(GITPB, "gitpb.IsBranch() found tag:", path, filename, "from", repo.GoPath)
return true
}
}
log.Log(GITPB, "did not find tag:", findname, "in", repo.GoPath)
return false
}
func trimNonNumericFromStart(s string) string {
for i, r := range s {
if unicode.IsDigit(r) {

View File

@ -79,12 +79,29 @@ func (repo *Repo) Exists(filename string) bool {
}
func (repo *Repo) IsValid() bool {
if !repo.IsDirectory() {
if repo == nil {
return false
}
if !repo.IsGitDirectory() {
return false
}
return true
}
func (repo *Repo) ReadFile(fname string) ([]byte, error) {
fullname := filepath.Join(repo.FullPath, fname)
return os.ReadFile(fullname)
}
func (repo *Repo) IsGitDirectory() bool {
gitdir := filepath.Join(repo.FullPath, ".git")
info, err := os.Stat(gitdir)
if err != nil {
return false
}
return info.IsDir()
}
func (repo *Repo) IsDirectory() bool {
info, err := os.Stat(repo.FullPath)
if err != nil {