summaryrefslogtreecommitdiff
path: root/reload.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2024-12-17 01:15:31 -0600
committerJeff Carr <[email protected]>2024-12-17 01:15:31 -0600
commit4bc95ad2684cb42159229b8198aa8a2377f80aa1 (patch)
tree57c4b95880302bfd3a34d0cc3eec6ab79f1d0993 /reload.go
parentc53da5a9a1da1b29db24d4e1ce2b294514d99ac2 (diff)
keep isolating use of os.Exec("git")
Diffstat (limited to 'reload.go')
-rw-r--r--reload.go68
1 files changed, 67 insertions, 1 deletions
diff --git a/reload.go b/reload.go
index 7a8c212..7c910d3 100644
--- a/reload.go
+++ b/reload.go
@@ -1,14 +1,27 @@
package gitpb
+import (
+ "strings"
+
+ "go.wit.com/log"
+)
+
func (repo *Repo) Reload() error {
repo.Tags = new(GitTags)
- repo.UpdateGitTags()
+ repo.reloadGitTags()
+
repo.GoDeps = new(GoDeps)
repo.ParseGoSum()
if repo.GoInfo != nil {
repo.ReloadGo()
}
+
+ repo.setLastTag()
+ repo.setCurrentBranchName()
+
+ // everything has been checked, now save the mtime's
+ repo.RepoChanged()
return nil
}
@@ -37,3 +50,56 @@ func (repo *Repo) SetDevelBranchName(bname string) {
func (repo *Repo) SetUserBranchName(bname string) {
repo.UserBranchName = bname
}
+
+// updates LastTag // todo, get this from the protobuf
+func (repo *Repo) setLastTag() {
+ cmd := []string{"git", "rev-list", "--tags", "--max-count=1"}
+ result := repo.RunQuiet(cmd)
+ // log.Info("getLastTagVersion()", result.Stdout)
+
+ if len(result.Stdout) != 1 {
+ log.Log(GITPBWARN, "git LastTag() error:", result.Stdout)
+ repo.LastTag = ""
+ return
+ }
+
+ hash := result.Stdout[0]
+
+ cmd = []string{"git", "describe", "--tags", "--always", hash}
+ result = repo.RunQuiet(cmd)
+
+ if len(result.Stdout) != 1 {
+ log.Log(GITPBWARN, "git LastTag() error:", result.Stdout)
+ repo.LastTag = ""
+ return
+ }
+
+ repo.LastTag = result.Stdout[0]
+}
+
+func (repo *Repo) setCurrentBranchName() {
+ repo.CurrentBranchName = ""
+ r := repo.RunQuiet([]string{"git", "branch", "--show-current"})
+ output := strings.Join(r.Stdout, "\n")
+ if r.Error != nil {
+ log.Log(GITPBWARN, "GetCurrentBranchName() not in a git repo?", r.Error, repo.GoPath)
+ log.Log(GITPBWARN, "GetCurrentBranchName() output might have worked anyway:", output)
+ }
+ repo.CurrentBranchName = strings.TrimSpace(output)
+}
+
+// always spawns 'git' and always should spawn 'git'
+func (repo *Repo) setCurrentBranchVersion() {
+ repo.CurrentBranchVersion = ""
+ if repo == nil {
+ log.Info("repo.GetCurrentBranchVersion() repo == nil")
+ return
+ }
+ r := repo.RunQuiet([]string{"git", "describe", "--tags", "--always"})
+ output := strings.Join(r.Stdout, "\n")
+ if r.Error != nil {
+ log.Log(GITPBWARN, "GetCurrentBranchVersion() not in a git repo?", r.Error, repo.GoPath)
+ log.Log(GITPBWARN, "GetCurrentBranchVersion() output might have worked anyway:", output)
+ }
+ repo.CurrentBranchVersion = strings.TrimSpace(output)
+}