summaryrefslogtreecommitdiff
path: root/reloadTags.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-09-26 23:44:19 -0500
committerJeff Carr <[email protected]>2025-09-26 23:44:19 -0500
commit3718ebe168dc7c4ce553bdc9b4e19b4b7bfe0d33 (patch)
treef51269dfba05952f6ead1f0e604470c0fab4e3c2 /reloadTags.go
parent5cfc8d38505a1f17c14cebef8f8e1b393f799dda (diff)
add Tags.Master & Tags.Develv0.0.140
Diffstat (limited to 'reloadTags.go')
-rw-r--r--reloadTags.go51
1 files changed, 42 insertions, 9 deletions
diff --git a/reloadTags.go b/reloadTags.go
index 3665567..810d616 100644
--- a/reloadTags.go
+++ b/reloadTags.go
@@ -1,6 +1,7 @@
package gitpb
import (
+ "os"
"path/filepath"
"slices"
"strings"
@@ -60,6 +61,7 @@ func (repo *Repo) reloadGitTags() error {
var subject string
var ctime *timestamppb.Timestamp
var atime *timestamppb.Timestamp
+ var newest time.Time
for i, line := range lines {
var parts []string
@@ -72,10 +74,16 @@ func (repo *Repo) reloadGitTags() error {
hash = parts[0]
if parts[1] != "" {
tmp := getGitDateStamp(parts[1])
+ if newest.Before(tmp) {
+ newest = tmp // track the newest time
+ }
ctime = timestamppb.New(tmp)
}
if parts[2] != "" {
tmp := getGitDateStamp(parts[2])
+ if newest.Before(tmp) {
+ newest = tmp // track the newest time
+ }
atime = timestamppb.New(tmp)
}
refname = parts[3]
@@ -100,16 +108,24 @@ func (repo *Repo) reloadGitTags() error {
// git log -1 --format="%H %aI %cI %an %ae %cn %ce"
// also set the repo.NewestCommit
- cmd = []string{"git", "log", "-1", "--format=%cd"}
- result = shell.PathRunQuiet(repo.FullPath, cmd)
- if result.Error != nil {
- log.Warn("git for-each-ref error:", result.Error)
- return result.Error
+ /*
+ cmd = []string{"git", "log", "-1", "--format=%cd"}
+ result = shell.PathRunQuiet(repo.FullPath, cmd)
+ if result.Error != nil {
+ log.Warn("git for-each-ref error:", result.Error)
+ return result.Error
+ }
+ newest := strings.Join(result.Stdout, "\n")
+ newest = strings.TrimSpace(newest)
+ tmp := getGitDateStamp(newest)
+ */
+ repo.Times.NewestCommit = timestamppb.New(newest)
+
+ if repo.GetMasterBranchName() == "" {
+ if err := repo.findHEAD(); err != nil {
+ log.Info(repo.FullPath, "master branch blank", err)
+ }
}
- newest := strings.Join(result.Stdout, "\n")
- newest = strings.TrimSpace(newest)
- tmp := getGitDateStamp(newest)
- repo.Times.NewestCommit = timestamppb.New(tmp)
return nil
}
@@ -221,3 +237,20 @@ func (repo *Repo) IsOnlyLocalTag(taggy string) bool {
// we couldn't find the local tag anywhere remote, so it's probably only local
return true
}
+
+func (repo *Repo) findHEAD() error {
+ headfile := filepath.Join(repo.GetFullPath(), ".git/refs/remotes/origin/HEAD")
+ data, err := os.ReadFile(headfile)
+ if err != nil {
+ return err
+ }
+ s := string(data)
+ if !strings.HasPrefix(s, "ref: ") {
+ return log.Errorf("HEAD doesn't start with 'ref:'")
+ }
+ fields := strings.Fields(s)
+ _, bname := filepath.Split(fields[1])
+
+ repo.SetMasterBranchName(bname)
+ return nil
+}