From 660255c8a3e3dba84b17ccc93cad0602e779f23d Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Fri, 17 Jan 2025 11:00:06 -0600 Subject: add ExamineBranches() --- reloadBranches.go | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) (limited to 'reloadBranches.go') diff --git a/reloadBranches.go b/reloadBranches.go index a2c6024..26937ab 100644 --- a/reloadBranches.go +++ b/reloadBranches.go @@ -9,6 +9,7 @@ import ( "go.wit.com/lib/gui/shell" "go.wit.com/log" + timestamppb "google.golang.org/protobuf/types/known/timestamppb" ) // TODO: make this report the error somewhere @@ -116,3 +117,57 @@ func ListFiles(directory string) []string { return files } + +func (repo *Repo) ExamineBranches() *GitTag { + var hashCheck string + all := repo.GetBranches() + path := filepath.Join(repo.FullPath, ".git/refs/") + for _, b := range all { + parts := strings.Split(b, "/") + rdir := "heads" + if len(parts) == 2 { + rdir = "remotes" + } + fullfile := filepath.Join(path, rdir, b) + + // check if the ref name is "HEAD". if so, skip + runeCount := utf8.RuneCountInString(fullfile) + // Convert the string to a slice of runes + runes := []rune(fullfile) + // Slice the last 4 runes + lastFour := runes[runeCount-4:] + if string(lastFour) == "HEAD" { + // assume HEAD is always a valid branch + // log.Info("skip HEAD. always valid branch name", fullfile) + continue + } + + content, _ := ioutil.ReadFile(fullfile) + hash := strings.TrimSpace(string(content)) + if hashCheck == "" { + hashCheck = hash + } + var cmd []string + cmd = append(cmd, "git", "show", "-s", "--format=%cI", hash) + r := shell.PathRunLog(repo.GetFullPath(), cmd, INFO) + if r.Error != nil { + log.Log(WARN, "CheckBranches() git show error:", r.Error) + } + // git show -s --format=%ci will give you the time + // log.Log(REPO, fullfile) + if hash == hashCheck { + // log.Info("notsure why this git show is here", hash) + } else { + // log.Printf("UNKNOWN BRANCH %-50s %s %s %s\n", repo.GetFullPath(), r.Stdout, cmd, b) + tag := new(GitTag) + tag.Refname = b + tag.Hash = hash + if len(r.Stdout) > 0 { + tagtime := parseDateRFC3339(r.Stdout[0]) + tag.Creatordate = timestamppb.New(tagtime) + } + return tag + } + } + return nil +} -- cgit v1.2.3