lots more moved to using the protobuf

This commit is contained in:
Jeff Carr 2024-12-03 00:34:55 -06:00
parent d5c394d3c3
commit 283bd90e91
9 changed files with 327 additions and 469 deletions

57
deps.go
View File

@ -1,57 +0,0 @@
package repostatus
import (
"bufio"
"os"
"path/filepath"
"strings"
"go.wit.com/log"
)
func (rs *RepoStatus) GetGoDeps() GoConfig {
tmp := filepath.Join(rs.realPath.String(), "go.sum")
gosum, err := os.Open(tmp)
if err != nil {
log.Log(REPO, "\tmissing go.sum", rs.realPath.String())
return nil
}
defer gosum.Close()
var deps GoConfig
deps = make(GoConfig)
scanner := bufio.NewScanner(gosum)
log.Log(REPO, "\tgosum:", tmp)
for scanner.Scan() {
line := strings.TrimSpace(scanner.Text())
parts := strings.Split(line, " ")
if len(parts) == 3 {
godep := strings.TrimSpace(parts[0])
version := strings.TrimSpace(parts[1])
if strings.HasSuffix(version, "/go.mod") {
version = strings.TrimSuffix(version, "/go.mod")
}
currentversion, ok := deps[godep]
if ok {
if currentversion != version {
log.Log(REPO, "\tREPO:", rs.String(), rs.realPath.String())
log.Log(REPO, "\t version mismatch:", godep, version, currentversion)
}
} else {
deps[godep] = version
log.Log(REPO, "\t", godep, "=", version)
}
} else {
log.Log(REPO, "\t INVALID:", parts)
return nil
}
}
if err := scanner.Err(); err != nil {
return nil
}
return deps
}

586
git.go
View File

@ -44,6 +44,7 @@ func (rs *RepoStatus) Age() time.Duration {
var ErrorMissingGitConfig error = errors.New("missing .git/config")
var ErrorGitPullOnLocal error = errors.New("git pull on local only branch")
/*
func (rs *RepoStatus) GitPull() (string, error) {
currentName := rs.GetCurrentBranchName()
if rs.IsOnlyLocalTag(currentName) {
@ -64,286 +65,8 @@ func (rs *RepoStatus) GitPull() (string, error) {
}
return output, r.Error
}
/*
// this isn't right
func (rs *RepoStatus) LastTagAge() (time.Time, string) {
return time.Now(), rs.lasttag.String()
}
*/
func (rs *RepoStatus) GetLastTagVersion() string {
return rs.lasttag.String()
}
// stores the current branch name
func (rs *RepoStatus) checkCurrentBranchName() string {
currentname := rs.currentBranch.String()
out := run(rs.realPath.String(), "git", "branch --show-current")
if currentname == out {
// nothing changed
return currentname
}
rs.currentBranch.SetValue(out)
if currentname == "" {
return out // don't note if there was nothing before
}
rs.NoteChange("current branch has changed from " + currentname + " to " + out)
return out
}
func (rs *RepoStatus) gitDescribeByHash(hash string) (string, error) {
if hash == "" {
return "", errors.New("hash was blank")
}
r := shell.PathRunLog(rs.Path(), []string{"git", "describe", "--tags", "--always", hash}, INFO)
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
}
return out, r.Error
}
func (rs *RepoStatus) gitDescribeByName(name string) (string, error) {
name = strings.TrimSpace(name)
if name == "" {
// git will return the current tag
r := shell.PathRunLog(rs.Path(), []string{"git", "describe", "--tags", "--always"}, INFO)
output := strings.Join(r.Stdout, "\n")
if r.Error != nil {
log.Warn("gitDescribeByName() not in a git repo?", r.Error, rs.Path())
}
return strings.TrimSpace(output), r.Error
}
if !rs.LocalTagExists(name) {
// tag does not exist
return "", errors.New("gitDescribeByName() git fatal: Not a valid object name")
}
cmd := []string{"git", "describe", "--tags", "--always", name}
r := shell.PathRunLog(rs.Path(), cmd, INFO)
output := strings.Join(r.Stdout, "\n")
if r.Error != nil {
log.Warn("cmd =", cmd)
log.Warn("err =", r.Error)
log.Warn("not in a git repo or bad tag?", rs.Path())
}
return strings.TrimSpace(output), r.Error
}
// todo: don't run git every time?
func (rs *RepoStatus) checkCurrentBranchVersion() string {
out, _ := rs.gitDescribeByName("")
log.Log(REPO, "checkCurrentBranchVersion()", out)
rs.currentVersion.SetValue(out)
return out
}
// this should get the most recent tag
func (rs *RepoStatus) setLastTagVersion() {
hash := run(rs.realPath.String(), "git", "rev-list --tags --max-count=1")
log.Log(REPO, "getLastTagVersion()", hash)
name, _ := rs.gitDescribeByHash(hash)
rs.lasttag.SetText(name)
return
}
func (rs *RepoStatus) populateTags() {
tmp := rs.realPath.String() + "/.git/refs/tags"
log.Log(REPO, "populateTags() path =", tmp)
for _, tag := range listFiles(tmp) {
if rs.tags[tag] == "" {
log.Log(REPO, "populateTags() Adding new tag", tag)
// rs.tagsDrop.AddText(tag)
rs.tags[tag] = "origin"
}
}
// rs.tagsDrop.SetText(rs.lasttagrev)
}
func (rs *RepoStatus) getBranches() []string {
var all []string
var heads []string
var remotes []string
heads = listFiles(rs.realPath.String() + "/.git/refs/heads")
remotes = listFiles(rs.realPath.String() + "/.git/refs/remotes")
all = heads
all = append(all, remotes...)
for _, branch := range all {
log.Log(REPO, "getBranches()", branch)
}
return all
}
// returns quickly based on the last time it was checked
func (rs *RepoStatus) IsDirty() bool {
if rs.dirtyLabel.String() == "no" {
return false
}
return true
}
// return the list of dirty files (but ignores go.mod & go.sum)
func (rs *RepoStatus) DirtyList() []string {
var all []string
for _, line := range strings.Split(rs.dirtyList, "\n") {
line = strings.TrimSpace(line)
parts := strings.Split(line, " ")
if len(parts) != 2 {
continue
}
if parts[1] == "go.mod" {
continue
}
if parts[1] == "go.sum" {
continue
}
all = append(all, parts[1])
}
return all
}
func (rs *RepoStatus) CheckDirty() bool {
var start string = rs.dirtyLabel.String()
cmd := []string{"git", "status", "--porcelain"}
r := shell.PathRunLog(rs.Path(), cmd, INFO)
out := strings.Join(r.Stdout, "\n")
if r.Error != nil {
log.Warn("CheckDirty() status cmd =", cmd)
log.Warn("CheckDirty() status out =", out)
log.Warn("CheckDirty() status err =", r.Error)
log.Error(r.Error, "CheckDirty() git status error")
rs.dirtyLabel.SetValue("error")
if start != "error" {
rs.NoteChange("git status is in error " + fmt.Sprint(r.Error))
}
return true
}
rs.dirtyList = out
// last := out[strings.LastIndex(out, "\n")+1:]
// if last == "nothing to commit, working tree clean" {
if len(rs.DirtyList()) == 0 {
log.Log(REPO, "CheckDirty() no", rs.realPath.String())
rs.dirtyLabel.SetValue("no")
if start == "" {
// don't record a change as this is the initial run
return false
}
if start != "no" {
log.Log(REPOWARN, "is no longer dirty")
rs.NoteChange("is no longer dirty")
}
return false
}
rs.dirtyLabel.SetValue("dirty")
if start == "" {
// don't record a change as this is the initial run
return false
}
if start != "dirty" {
log.Log(REPOWARN, "is now dirty")
rs.NoteChange("is now dirty")
}
return true
}
func (rs *RepoStatus) CheckoutBranch(bname string) bool {
if rs.CheckDirty() {
log.Log(REPO, rs.realPath.String(), "is dirty")
log.Info(bname, "is dirty", rs.Path())
return false
}
if !rs.TagExists(bname) {
// tag does not exist
log.Log(REPO, "repo does not have branch", bname, rs.Path())
return false
}
cName := rs.GetCurrentBranchName()
if cName == bname {
// already on branch
return true
}
cmd := []string{"git", "checkout", bname}
r := rs.Run(cmd)
if r.Error != nil {
log.Log(REPO, "git checkout error:", r.Error)
return false
}
rs.checkCurrentBranchName()
rs.checkCurrentBranchVersion()
return true
}
func (rs *RepoStatus) CheckoutMaster() bool {
if rs.CheckDirty() {
log.Log(REPO, rs.realPath.String(), "is dirty")
return false
}
mName := rs.GetMasterBranchName()
if rs.CheckoutBranch(mName) {
return true
}
return true
}
func (rs *RepoStatus) CheckoutDevel() bool {
devel := rs.develWorkingName.String()
// user := rs.userWorkingName.String()
if devel == "" {
return false
}
if rs.CheckDirty() {
log.Log(REPO, rs.realPath.String(), "is dirty")
return false
}
log.Log(REPO, "checkoutBranch", devel)
rs.checkoutBranch("devel", devel)
// log.Log(REPO, "checkoutBranch", user)
// rs.checkoutBranch("user", user)
return true
}
func (rs *RepoStatus) CheckoutUser() bool {
bName := rs.GetUserBranchName()
if bName == "" {
return false
}
if rs.CheckDirty() {
log.Log(REPO, rs.realPath.String(), "is dirty")
return false
}
if !rs.BranchExists(bName) {
return false
}
cmd := []string{"git", "checkout", bName}
r := rs.Run(cmd)
if r.Error != nil {
log.Log(REPO, "git checkout error:", r.Error)
}
realname := rs.GetCurrentBranchName()
realversion := rs.GetCurrentBranchVersion()
log.Log(REPO, rs.realPath.String(), "realname =", realname, "realversion =", realversion)
if realname != bName {
log.Log(REPO, "git checkout failed", rs.realPath.String(), bName, "!=", realname)
return false
}
rs.userBranchVersion.SetValue(realversion)
return true
}
func (rs *RepoStatus) checkoutBranch(level string, branch string) {
if rs.CheckDirty() {
log.Log(REPO, "checkoutBranch() checkDirty() == true for repo", rs.realPath.String(), "looking for branch:", branch)
@ -367,33 +90,6 @@ func (rs *RepoStatus) checkoutBranch(level string, branch string) {
}
}
// attempt's to guess at what master is.
// TODO: fix this properly
func (rs *RepoStatus) guessMainWorkingName() {
if !rs.Ready() {
return
}
if rs.TagExists("guimaster") {
rs.mainWorkingName.SetText("guimaster")
rs.mainBranchVersion.SetLabel("guimaster")
return
}
if rs.TagExists("master") {
rs.mainWorkingName.SetText("master")
rs.mainBranchVersion.SetLabel("master")
return
}
if rs.TagExists("main") {
rs.mainWorkingName.SetText("main")
rs.mainBranchVersion.SetLabel("main")
return
}
// figure out what to do here
rs.mainWorkingName.SetText("FIXME")
rs.mainBranchVersion.SetLabel("FIXME")
}
func (rs *RepoStatus) guessDevelWorkingName() {
if rs.TagExists("guidevel") {
rs.develWorkingName.SetValue("guidevel")
@ -591,3 +287,283 @@ func (rs *RepoStatus) CheckBranches() bool {
}
return perfect
}
/*
// this isn't right
func (rs *RepoStatus) LastTagAge() (time.Time, string) {
return time.Now(), rs.lasttag.String()
}
*/
func (rs *RepoStatus) GetLastTagVersion() string {
return rs.lasttag.String()
}
// stores the current branch name
func (rs *RepoStatus) checkCurrentBranchName() string {
currentname := rs.currentBranch.String()
out := run(rs.realPath.String(), "git", "branch --show-current")
if currentname == out {
// nothing changed
return currentname
}
rs.currentBranch.SetValue(out)
if currentname == "" {
return out // don't note if there was nothing before
}
rs.NoteChange("current branch has changed from " + currentname + " to " + out)
return out
}
func (rs *RepoStatus) gitDescribeByHash(hash string) (string, error) {
if hash == "" {
return "", errors.New("hash was blank")
}
r := shell.PathRunLog(rs.Path(), []string{"git", "describe", "--tags", "--always", hash}, INFO)
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
}
return out, r.Error
}
func (rs *RepoStatus) gitDescribeByName(name string) (string, error) {
name = strings.TrimSpace(name)
if name == "" {
// git will return the current tag
r := shell.PathRunLog(rs.Path(), []string{"git", "describe", "--tags", "--always"}, INFO)
output := strings.Join(r.Stdout, "\n")
if r.Error != nil {
log.Warn("gitDescribeByName() not in a git repo?", r.Error, rs.Path())
}
return strings.TrimSpace(output), r.Error
}
if !rs.LocalTagExists(name) {
// tag does not exist
return "", errors.New("gitDescribeByName() git fatal: Not a valid object name")
}
cmd := []string{"git", "describe", "--tags", "--always", name}
r := shell.PathRunLog(rs.Path(), cmd, INFO)
output := strings.Join(r.Stdout, "\n")
if r.Error != nil {
log.Warn("cmd =", cmd)
log.Warn("err =", r.Error)
log.Warn("not in a git repo or bad tag?", rs.Path())
}
return strings.TrimSpace(output), r.Error
}
// todo: don't run git every time?
func (rs *RepoStatus) checkCurrentBranchVersion() string {
out, _ := rs.gitDescribeByName("")
log.Log(REPO, "checkCurrentBranchVersion()", out)
rs.currentVersion.SetValue(out)
return out
}
// this should get the most recent tag
func (rs *RepoStatus) setLastTagVersion() {
hash := run(rs.realPath.String(), "git", "rev-list --tags --max-count=1")
log.Log(REPO, "getLastTagVersion()", hash)
name, _ := rs.gitDescribeByHash(hash)
rs.lasttag.SetText(name)
return
}
func (rs *RepoStatus) populateTags() {
tmp := rs.realPath.String() + "/.git/refs/tags"
log.Log(REPO, "populateTags() path =", tmp)
for _, tag := range listFiles(tmp) {
if rs.tags[tag] == "" {
log.Log(REPO, "populateTags() Adding new tag", tag)
// rs.tagsDrop.AddText(tag)
rs.tags[tag] = "origin"
}
}
// rs.tagsDrop.SetText(rs.lasttagrev)
}
func (rs *RepoStatus) getBranches() []string {
var all []string
var heads []string
var remotes []string
heads = listFiles(rs.realPath.String() + "/.git/refs/heads")
remotes = listFiles(rs.realPath.String() + "/.git/refs/remotes")
all = heads
all = append(all, remotes...)
for _, branch := range all {
log.Log(REPO, "getBranches()", branch)
}
return all
}
// returns quickly based on the last time it was checked
func (rs *RepoStatus) IsDirty() bool {
if rs.dirtyLabel.String() == "no" {
return false
}
return true
}
// return the list of dirty files (but ignores go.mod & go.sum)
func (rs *RepoStatus) DirtyList() []string {
var all []string
for _, line := range strings.Split(rs.dirtyList, "\n") {
line = strings.TrimSpace(line)
parts := strings.Split(line, " ")
if len(parts) != 2 {
continue
}
if parts[1] == "go.mod" {
continue
}
if parts[1] == "go.sum" {
continue
}
all = append(all, parts[1])
}
return all
}
func (rs *RepoStatus) CheckDirty() bool {
var start string = rs.dirtyLabel.String()
cmd := []string{"git", "status", "--porcelain"}
r := shell.PathRunLog(rs.Path(), cmd, INFO)
out := strings.Join(r.Stdout, "\n")
if r.Error != nil {
log.Warn("CheckDirty() status cmd =", cmd)
log.Warn("CheckDirty() status out =", out)
log.Warn("CheckDirty() status err =", r.Error)
log.Error(r.Error, "CheckDirty() git status error")
rs.dirtyLabel.SetValue("error")
if start != "error" {
rs.NoteChange("git status is in error " + fmt.Sprint(r.Error))
}
return true
}
rs.dirtyList = out
// last := out[strings.LastIndex(out, "\n")+1:]
// if last == "nothing to commit, working tree clean" {
if len(rs.DirtyList()) == 0 {
log.Log(REPO, "CheckDirty() no", rs.realPath.String())
rs.dirtyLabel.SetValue("no")
if start == "" {
// don't record a change as this is the initial run
return false
}
if start != "no" {
log.Log(REPOWARN, "is no longer dirty")
rs.NoteChange("is no longer dirty")
}
return false
}
rs.dirtyLabel.SetValue("dirty")
if start == "" {
// don't record a change as this is the initial run
return false
}
if start != "dirty" {
log.Log(REPOWARN, "is now dirty")
rs.NoteChange("is now dirty")
}
return true
}
func (rs *RepoStatus) CheckoutBranch(bname string) bool {
if rs.CheckDirty() {
log.Log(REPO, rs.realPath.String(), "is dirty")
log.Info(bname, "is dirty", rs.Path())
return false
}
if !rs.TagExists(bname) {
// tag does not exist
log.Log(REPO, "repo does not have branch", bname, rs.Path())
return false
}
cName := rs.GetCurrentBranchName()
if cName == bname {
// already on branch
return true
}
cmd := []string{"git", "checkout", bname}
r := rs.Run(cmd)
if r.Error != nil {
log.Log(REPO, "git checkout error:", r.Error)
return false
}
rs.checkCurrentBranchName()
rs.checkCurrentBranchVersion()
return true
}
func (rs *RepoStatus) CheckoutMaster() bool {
if rs.CheckDirty() {
log.Log(REPO, rs.realPath.String(), "is dirty")
return false
}
mName := rs.GetMasterBranchName()
if rs.CheckoutBranch(mName) {
return true
}
return true
}
func (rs *RepoStatus) CheckoutDevel() bool {
devel := rs.develWorkingName.String()
// user := rs.userWorkingName.String()
if devel == "" {
return false
}
if rs.CheckDirty() {
log.Log(REPO, rs.realPath.String(), "is dirty")
return false
}
log.Log(REPO, "checkoutBranch", devel)
rs.checkoutBranch("devel", devel)
// log.Log(REPO, "checkoutBranch", user)
// rs.checkoutBranch("user", user)
return true
}
func (rs *RepoStatus) CheckoutUser() bool {
bName := rs.GetUserBranchName()
if bName == "" {
return false
}
if rs.CheckDirty() {
log.Log(REPO, rs.realPath.String(), "is dirty")
return false
}
if !rs.BranchExists(bName) {
return false
}
cmd := []string{"git", "checkout", bName}
r := rs.Run(cmd)
if r.Error != nil {
log.Log(REPO, "git checkout error:", r.Error)
}
realname := rs.GetCurrentBranchName()
realversion := rs.GetCurrentBranchVersion()
log.Log(REPO, rs.realPath.String(), "realname =", realname, "realversion =", realversion)
if realname != bName {
log.Log(REPO, "git checkout failed", rs.realPath.String(), bName, "!=", realname)
return false
}
rs.userBranchVersion.SetValue(realversion)
return true
}

View File

@ -2,6 +2,7 @@ package repostatus
import (
"bufio"
"io/ioutil"
"os"
"path/filepath"
"strings"
@ -32,7 +33,7 @@ type GitConfig struct {
versions map[string]string
}
type GoConfig map[string]string
// type GoConfig map[string]string
func ListGitDirectories() []string {
var all []string
@ -253,11 +254,13 @@ func (rs *RepoStatus) processBranch(branch string) {
hash, ok := rs.gitConfig.hashes[branch]
filename := fullpath + "/.git/refs/heads/" + branch
log.Log(INFO, " hash: need to open", filename)
newhash, err := readFileToString(filename)
data, err := ioutil.ReadFile(filename)
if err != nil {
log.Log(WARN, "hash: read failed", filename, rs.String())
return
}
newhash := strings.TrimSpace(string(data))
log.Log(INFO, " hash:", newhash)
rs.gitConfig.hashes[branch] = newhash
if ok {

View File

@ -3,48 +3,10 @@ package repostatus
// does processing on the go.mod and go.sum files
import (
"bufio"
"errors"
"os"
"path/filepath"
"strings"
"go.wit.com/log"
)
// Detect a 'Primative' package. Sets the isPrimative flag
// will return true if the repo is truly not dependent on _anything_ else
// like spew or lib/widget
// it assumes go mod ran init and tidy ran without error
func (rs *RepoStatus) isPrimativeGoMod() (bool, error) {
// go mod init & go mod tidy ran without errors
log.Log(REPO, "isPrimativeGoMod()", rs.realPath.String())
tmp := filepath.Join(rs.realPath.String(), "go.mod")
gomod, err := os.Open(tmp)
if err != nil {
log.Log(REPO, "missing go.mod", rs.realPath.String())
rs.goConfig = nil
return false, err
}
defer gomod.Close()
scanner := bufio.NewScanner(gomod)
for scanner.Scan() {
line := strings.TrimSpace(scanner.Text())
parts := strings.Split(line, " ")
log.Log(REPO, " gomod:", parts)
if len(parts) >= 1 {
log.Log(REPO, " gomod: part[0] =", parts[0])
if parts[0] == "require" {
log.Log(REPO, " should return false here")
return false, errors.New("go.mod file is not primative")
}
}
}
return true, nil
}
/*
// readGoMod reads and parses the go.sum file
// saves the config information in *Repo.goConfig
@ -105,6 +67,7 @@ func (rs *RepoStatus) parseGoSum() (bool, error) {
func (rs *RepoStatus) GoConfig() map[string]string {
return rs.goConfig
}
*/
// for now, even check cmd.Exit
func (rs *RepoStatus) strictRun(cmd []string) (bool, error) {

View File

@ -40,7 +40,7 @@ func (rs *RepoStatus) drawGitCommands(box *gui.Node) {
newgrid.NextRow()
newgrid.NewButton("git pull", func() {
rs.GitPull()
rs.pb.GitPull()
})
newgrid.NextRow()

41
new.go
View File

@ -2,7 +2,6 @@ package repostatus
import (
"os"
"strings"
"go.wit.com/lib/gadgets"
"go.wit.com/lib/protobuf/gitpb"
@ -41,10 +40,6 @@ func SetWorkPath(path string) {
// it's doesn't need to be displayed so it'll work fine even in an embedded space
func NewRepoStatusWindow(repo *gitpb.Repo) (*RepoStatus, error) {
path := repo.GoPath
goSrcDir := os.Getenv("FORGE_GOSRC")
realpath := repo.FullPath
isGoLang := true
if windowMap[path] == nil {
log.Log(INFO, "NewRepoStatusWindow() adding new", path)
} else {
@ -56,6 +51,9 @@ func NewRepoStatusWindow(repo *gitpb.Repo) (*RepoStatus, error) {
rs := &RepoStatus{
ready: false,
}
rs.pb = repo
// realpath := repo.FullPath
// isGoLang := true
rs.tags = make(map[string]string)
rs.window = gadgets.RawBasicWindow("GO Repo Details " + path)
@ -83,34 +81,33 @@ func NewRepoStatusWindow(repo *gitpb.Repo) (*RepoStatus, error) {
// save ~/go/src & the whole path strings
rs.path.SetValue(path)
rs.goSrcPath.SetValue(goSrcDir)
rs.realPath.SetValue(realpath)
rs.goSrcPath.SetValue(os.Getenv("FORGE_GOSRC"))
rs.realPath.SetValue(rs.pb.GetFullPath())
// add all the tags
rs.makeTagBox(box2)
rs.readGitConfig()
rs.readOnly.SetValue("true")
// ignore everything else for now
// todo: move this logic to cfgfile.go
if strings.HasPrefix(path, "go.wit.com") {
rs.readOnly.SetValue("false")
}
if strings.HasPrefix(path, "git.wit.org") {
if rs.pb.GetReadOnly() {
rs.readOnly.SetValue("true")
} else {
rs.readOnly.SetValue("false")
}
rs.mainWorkingName.SetText(rs.pb.GetMasterBranchName())
rs.mainBranchVersion.SetLabel(rs.pb.GetMasterBranchName())
// tries 'master', 'main', etc.
rs.guessMainWorkingName()
// tries 'devel', etc
rs.guessDevelWorkingName()
// sets this to os.Username
rs.setUserWorkingName()
rs.develWorkingName.SetText(rs.pb.GetDevelBranchName())
rs.develBranchVersion.SetLabel(rs.pb.GetDevelBranchName())
if isGoLang {
rs.userWorkingName.SetText(rs.pb.GetUserBranchName())
rs.userBranchVersion.SetLabel(rs.pb.GetUserBranchName())
if rs.pb.GoPath == "" {
// not golang repo
} else {
rs.isGoLang.SetText("true")
rs.goPath.SetText(path)
rs.goPath.SetText(rs.pb.GoPath)
}
windowMap[path] = rs
return rs, nil

View File

@ -3,6 +3,7 @@ package repostatus
import (
"go.wit.com/gui"
"go.wit.com/lib/gadgets"
"go.wit.com/lib/protobuf/gitpb"
)
type RepoStatus struct {
@ -12,6 +13,8 @@ type RepoStatus struct {
tags map[string]string
InitOk bool // it takes a second or so to init these
pb *gitpb.Repo // the protobuf
// used to temporarily tell the automation tools to
// try to ignore this repo's changes and state
// specifically when doing formal releases, sometimes
@ -72,7 +75,7 @@ type RepoStatus struct {
speedActual *gadgets.OneLiner
gitConfig *GitConfig
goConfig GoConfig
// goConfig GoConfig
switchBranchB *gui.Node
targetBranch *gui.Node

View File

@ -4,13 +4,11 @@ import (
"errors"
"path/filepath"
"regexp"
"slices"
"strings"
"sync"
"time"
"go.wit.com/gui"
"go.wit.com/lib/gui/shell"
"go.wit.com/log"
)
@ -88,49 +86,24 @@ func (rs *RepoStatus) makeTagBox(box *gui.Node) error {
grid.NewLabel("ref")
grid.NewLabel("date")
grid.NewLabel("release subject")
// works like a typerwriter
grid.NextRow()
grid.NextRow() // works like a typerwriter newline
// git tag --list --sort=taggerdate
// git for-each-ref --sort=taggerdate --format '%(tag) %(*objectname) %(taggerdate)'
// git rev-parse HEAD
// if last tag == HEAD, then remove it
loop := rs.pb.Tags.SortByAge()
for loop.Scan() {
tag := loop.Next()
tags := []string{"%(objectname)", "%(creatordate)", "%(*authordate)", "%(refname)", "%(subject)"}
format := strings.Join(tags, "_,,,_")
cmd := []string{"git", "for-each-ref", "--sort=taggerdate", "--format", format}
// log.Info("RUNNING:", strings.Join(cmd, " "))
r := shell.PathRunQuiet(rs.Path(), cmd)
if r.Error != nil {
log.Warn("git for-each-ref error:", r.Error)
return r.Error
}
lines := r.Stdout
// reverse the git order
slices.Reverse(lines)
tagB.tags = make([]*Tag, 0)
for i, line := range lines {
var parts []string
parts = make([]string, 0)
parts = strings.Split(line, "_,,,_")
if len(parts) != 5 {
log.Info("tag error:", i, parts)
continue
}
// log.Info("found tag:", i, parts)
rTag := new(Tag)
rTag.tag = grid.NewLabel(parts[3])
rTag.ref = grid.NewEntrybox(parts[0])
rTag.tag = grid.NewLabel(tag.GetRefname())
rTag.ref = grid.NewEntrybox(tag.GetHash())
_, stamp, dur := getGitDateStamp(parts[1])
rTag.date = grid.NewLabel(stamp)
ctime := tag.GetAuthordate().AsTime()
dur := getDurationStamp(ctime)
rTag.date = grid.NewLabel(ctime.Format("YYYY/MM/DD"))
rTag.duration = grid.NewLabel(dur)
rTag.subject = grid.NewLabel(parts[4])
rTag.subject = grid.NewLabel(tag.GetSubject())
rTag.deleteB = grid.NewButton("delete", func() {
tagversion := parts[0]
tagversion := tag.GetRefname()
log.Info("remove tag", tagversion)
var all [][]string
all = append(all, []string{"git", "tag", "--delete", tagversion})
@ -147,8 +120,6 @@ func (rs *RepoStatus) makeTagBox(box *gui.Node) error {
// works like a typerwriter
grid.NextRow()
}
// reverse the git order
// slices.Reverse(rtags.tags)
return nil
}

View File

@ -2,12 +2,10 @@ package repostatus
import (
"fmt"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
"regexp"
"strconv"
"strings"
"time"
@ -179,6 +177,7 @@ func Exists(file string) bool {
return true
}
/*
func readFileToString(filename string) (string, error) {
data, err := ioutil.ReadFile(filename)
if err != nil {
@ -217,6 +216,7 @@ func getRawDateStamp(raw string) (time.Time, string, string) {
gitTagDate := time.Unix(i, 0)
return gitTagDate, gitTagDate.UTC().Format("2006/01/02 15:04:05 UTC"), getDurationStamp(gitTagDate)
}
*/
func getDurationStamp(t time.Time) string {
@ -376,6 +376,7 @@ func (rs *RepoStatus) DoAll(all [][]string) bool {
return true
}
/*
func ScanGitDirectories(srcDir string) []string {
var all []string
err := filepath.Walk(srcDir, func(path string, info os.FileInfo, err error) error {
@ -398,3 +399,4 @@ func ScanGitDirectories(srcDir string) []string {
return all
}
*/