2024-01-09 15:34:53 -06:00
|
|
|
package repostatus
|
|
|
|
|
|
|
|
import (
|
2024-02-16 17:55:13 -06:00
|
|
|
"errors"
|
2024-01-11 23:24:09 -06:00
|
|
|
"strings"
|
2024-01-18 16:20:11 -06:00
|
|
|
|
2024-11-13 10:33:25 -06:00
|
|
|
"go.wit.com/lib/gui/shell"
|
2025-01-07 18:24:17 -06:00
|
|
|
"go.wit.com/lib/protobuf/gitpb"
|
2024-11-15 09:12:47 -06:00
|
|
|
"go.wit.com/log"
|
2024-01-09 15:34:53 -06:00
|
|
|
)
|
|
|
|
|
2025-01-07 04:58:05 -06:00
|
|
|
// remove this everything
|
|
|
|
func (rs *RepoStatus) Path() string {
|
|
|
|
return rs.realPath.String()
|
2024-02-22 17:19:29 -06:00
|
|
|
}
|
2024-12-03 00:34:55 -06:00
|
|
|
|
|
|
|
func (rs *RepoStatus) GitState() string {
|
|
|
|
return rs.gitState.String()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (rs *RepoStatus) GetStatus() string {
|
|
|
|
return rs.gitState.String()
|
|
|
|
}
|
|
|
|
|
2024-01-13 20:30:33 -06:00
|
|
|
func (rs *RepoStatus) GetLastTagVersion() string {
|
2024-01-17 03:59:13 -06:00
|
|
|
return rs.lasttag.String()
|
2024-01-13 20:30:33 -06:00
|
|
|
}
|
|
|
|
|
2025-01-07 04:58:05 -06:00
|
|
|
func (rs *RepoStatus) displayCurrentBranchName() string {
|
|
|
|
out := rs.pb.GetCurrentBranchName()
|
|
|
|
rs.currentBranch.SetValue(out)
|
|
|
|
return out
|
|
|
|
}
|
|
|
|
|
2024-02-16 17:55:13 -06:00
|
|
|
// stores the current branch name
|
|
|
|
func (rs *RepoStatus) checkCurrentBranchName() string {
|
|
|
|
currentname := rs.currentBranch.String()
|
2025-01-07 18:18:38 -06:00
|
|
|
out := rs.pb.GetCurrentBranchName()
|
2024-02-16 17:55:13 -06:00
|
|
|
if currentname == out {
|
|
|
|
// nothing changed
|
|
|
|
return currentname
|
|
|
|
}
|
2024-01-19 12:36:52 -06:00
|
|
|
rs.currentBranch.SetValue(out)
|
2024-02-16 17:55:13 -06:00
|
|
|
if currentname == "" {
|
|
|
|
return out // don't note if there was nothing before
|
|
|
|
}
|
|
|
|
rs.NoteChange("current branch has changed from " + currentname + " to " + out)
|
2024-01-09 15:34:53 -06:00
|
|
|
return out
|
|
|
|
}
|
|
|
|
|
2024-02-16 17:55:13 -06:00
|
|
|
func (rs *RepoStatus) gitDescribeByHash(hash string) (string, error) {
|
|
|
|
if hash == "" {
|
|
|
|
return "", errors.New("hash was blank")
|
|
|
|
}
|
2025-01-07 04:58:05 -06:00
|
|
|
r := shell.PathRunLog(rs.realPath.String(), []string{"git", "describe", "--tags", "--always", hash}, INFO)
|
2024-11-08 06:43:33 -06:00
|
|
|
out := strings.Join(r.Stdout, "\n")
|
|
|
|
if r.Error != nil {
|
|
|
|
log.Warn("not in a git repo or bad hash?", r.Error, rs.Path())
|
|
|
|
return out, r.Error
|
2024-02-16 17:55:13 -06:00
|
|
|
}
|
2024-11-08 06:43:33 -06:00
|
|
|
return out, r.Error
|
2024-02-16 17:55:13 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func (rs *RepoStatus) gitDescribeByName(name string) (string, error) {
|
2024-02-16 11:41:29 -06:00
|
|
|
name = strings.TrimSpace(name)
|
|
|
|
|
|
|
|
if name == "" {
|
|
|
|
// git will return the current tag
|
2024-11-13 10:33:25 -06:00
|
|
|
r := shell.PathRunLog(rs.Path(), []string{"git", "describe", "--tags", "--always"}, INFO)
|
2024-11-08 06:43:33 -06:00
|
|
|
output := strings.Join(r.Stdout, "\n")
|
|
|
|
if r.Error != nil {
|
|
|
|
log.Warn("gitDescribeByName() not in a git repo?", r.Error, rs.Path())
|
2024-02-16 11:41:29 -06:00
|
|
|
}
|
2024-11-08 06:43:33 -06:00
|
|
|
return strings.TrimSpace(output), r.Error
|
2024-02-16 11:41:29 -06:00
|
|
|
}
|
2024-02-16 17:55:13 -06:00
|
|
|
if !rs.LocalTagExists(name) {
|
|
|
|
// tag does not exist
|
2024-11-08 06:43:33 -06:00
|
|
|
return "", errors.New("gitDescribeByName() git fatal: Not a valid object name")
|
2024-02-16 17:55:13 -06:00
|
|
|
}
|
|
|
|
cmd := []string{"git", "describe", "--tags", "--always", name}
|
2024-11-13 10:33:25 -06:00
|
|
|
r := shell.PathRunLog(rs.Path(), cmd, INFO)
|
2024-11-08 06:43:33 -06:00
|
|
|
output := strings.Join(r.Stdout, "\n")
|
|
|
|
if r.Error != nil {
|
2024-02-16 17:55:13 -06:00
|
|
|
log.Warn("cmd =", cmd)
|
2024-11-08 06:43:33 -06:00
|
|
|
log.Warn("err =", r.Error)
|
2024-02-16 17:55:13 -06:00
|
|
|
log.Warn("not in a git repo or bad tag?", rs.Path())
|
2024-02-16 11:41:29 -06:00
|
|
|
}
|
2024-11-08 06:43:33 -06:00
|
|
|
|
|
|
|
return strings.TrimSpace(output), r.Error
|
2024-02-16 11:41:29 -06:00
|
|
|
}
|
|
|
|
|
2024-01-09 15:34:53 -06:00
|
|
|
func (rs *RepoStatus) populateTags() {
|
2024-01-23 15:20:54 -06:00
|
|
|
tmp := rs.realPath.String() + "/.git/refs/tags"
|
2024-02-24 05:37:53 -06:00
|
|
|
log.Log(REPO, "populateTags() path =", tmp)
|
2025-01-07 18:24:17 -06:00
|
|
|
for _, tag := range gitpb.ListFiles(tmp) {
|
2024-01-09 15:34:53 -06:00
|
|
|
if rs.tags[tag] == "" {
|
2024-02-24 05:37:53 -06:00
|
|
|
log.Log(REPO, "populateTags() Adding new tag", tag)
|
2024-02-14 00:09:58 -06:00
|
|
|
// rs.tagsDrop.AddText(tag)
|
2024-01-09 15:34:53 -06:00
|
|
|
rs.tags[tag] = "origin"
|
|
|
|
}
|
|
|
|
}
|
2024-01-17 03:59:13 -06:00
|
|
|
// rs.tagsDrop.SetText(rs.lasttagrev)
|
2024-01-09 15:34:53 -06:00
|
|
|
}
|