summaryrefslogtreecommitdiff
path: root/reloadBranches.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-01-17 11:00:06 -0600
committerJeff Carr <[email protected]>2025-01-17 11:00:06 -0600
commit660255c8a3e3dba84b17ccc93cad0602e779f23d (patch)
tree558cb93d9fd95b7e415a5eda975eec6dedfed40b /reloadBranches.go
parent0773f20d00380690911f2b146e80b9630d90aef9 (diff)
add ExamineBranches()
Diffstat (limited to 'reloadBranches.go')
-rw-r--r--reloadBranches.go55
1 files changed, 55 insertions, 0 deletions
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 <hash> 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
+}