From 2574ec733a812a747b3e4075f8affc862453034f Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Fri, 13 Dec 2024 16:18:25 -0600 Subject: [PATCH] IsLocalBranch() --- currentVersions.go | 22 ++++++++++++++++++++++ shell.go | 19 ++++++++++++++++++- 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/currentVersions.go b/currentVersions.go index 9026149..beecc4f 100644 --- a/currentVersions.go +++ b/currentVersions.go @@ -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) { diff --git a/shell.go b/shell.go index 8215d46..efb682d 100644 --- a/shell.go +++ b/shell.go @@ -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 {