trying to improve older code
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
d7e391fed0
commit
73d711ad2b
20
git.go
20
git.go
|
@ -332,6 +332,14 @@ func (rs *RepoStatus) GetStatus() string {
|
|||
}
|
||||
|
||||
// TODO: make this report the error somewhere
|
||||
// This is supposed to check all the branches to make sure
|
||||
// the are the same. that was originally what this was for
|
||||
// now I think it's jsut probably dumb old code that doesn't
|
||||
// need to be here
|
||||
|
||||
// actually, this is to attempt to verify absolutely everything
|
||||
// is pushed upstream before doing a rm -rf ~/go/src
|
||||
// TODO: revisit this code in the autotypist later
|
||||
func (rs *RepoStatus) CheckBranches() bool {
|
||||
var hashCheck string
|
||||
var perfect bool = true
|
||||
|
@ -363,17 +371,21 @@ func (rs *RepoStatus) CheckBranches() bool {
|
|||
}
|
||||
var cmd []string
|
||||
cmd = append(cmd, "git", "show", "-s", "--format=%ci", hash)
|
||||
_, _, output := RunCmd(rs.realPath.String(), cmd)
|
||||
err, output := rs.RunCmd(cmd)
|
||||
if err != nil {
|
||||
// log.Log(WARN, "cmd failed", cmd, "err =", err, "in", rs.String())
|
||||
}
|
||||
// git show -s --format=%ci <hash> will give you the time
|
||||
// log.Log(INFO, fullfile)
|
||||
if hash == hashCheck {
|
||||
log.Log(INFO, hash, output, b)
|
||||
} else {
|
||||
log.Warn("UNKNOWN BRANCHES IN THIS REPO")
|
||||
// log.Log(WARN, rs.String(), hash, output, b)
|
||||
// log.Log(WARN, "UNKNOWN BRANCHES IN THIS REPO", cmd)
|
||||
rs.versionCmdOutput.SetText("UNKNOWN BRANCHES")
|
||||
perfect = false
|
||||
parts := strings.Split(b, "/")
|
||||
log.Warn("git push", parts)
|
||||
// parts := strings.Split(b, "/")
|
||||
// log.Warn("git push", parts)
|
||||
}
|
||||
}
|
||||
return perfect
|
||||
|
|
282
gitConfig.go
282
gitConfig.go
|
@ -203,37 +203,6 @@ func (rs *RepoStatus) GitURL() string {
|
|||
return ""
|
||||
}
|
||||
|
||||
// this checks to see if the repo is truly not dependent on _anything_ else
|
||||
// like spew or lib/widget
|
||||
func (rs *RepoStatus) CheckPrimativeGoMod() bool {
|
||||
log.Log(WARN, "CheckPrimativeGoMod()", rs.realPath.String())
|
||||
tmp := filepath.Join(rs.realPath.String(), "go.mod")
|
||||
gomod, err := os.Open(tmp)
|
||||
if err != nil {
|
||||
log.Log(WARN, "missing go.mod", rs.realPath.String())
|
||||
rs.goConfig = nil
|
||||
return false
|
||||
}
|
||||
defer gomod.Close()
|
||||
|
||||
scanner := bufio.NewScanner(gomod)
|
||||
for scanner.Scan() {
|
||||
line := strings.TrimSpace(scanner.Text())
|
||||
|
||||
parts := strings.Split(line, " ")
|
||||
log.Log(INFO, " gomod:", parts)
|
||||
if len(parts) >= 1 {
|
||||
log.Log(INFO, " gomod: part[0] =", parts[0])
|
||||
if parts[0] == "require" {
|
||||
log.Log(INFO, " should return false here")
|
||||
return false
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func (rs *RepoStatus) GitLsFiles() (bool, string) {
|
||||
err, output := rs.RunCmd([]string{"git", "ls-files"})
|
||||
if err != nil {
|
||||
|
@ -244,61 +213,6 @@ func (rs *RepoStatus) GitLsFiles() (bool, string) {
|
|||
return true, output
|
||||
}
|
||||
|
||||
// readGoMod reads and parses the go.sum file (TODO: do the go.mod file)
|
||||
func (rs *RepoStatus) ReadGoMod() bool {
|
||||
if rs.CheckPrimativeGoMod() {
|
||||
log.Info("PRIMATIVE repo:", rs.String())
|
||||
return true
|
||||
}
|
||||
|
||||
tmp := filepath.Join(rs.realPath.String(), "go.sum")
|
||||
gosum, err := os.Open(tmp)
|
||||
if err != nil {
|
||||
log.Log(WARN, "missing go.sum", rs.realPath.String())
|
||||
rs.goConfig = nil
|
||||
return false
|
||||
}
|
||||
defer gosum.Close()
|
||||
|
||||
var deps GoConfig
|
||||
deps = make(GoConfig)
|
||||
|
||||
scanner := bufio.NewScanner(gosum)
|
||||
log.Log(INFO, "gosum:", 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(WARN, "REPO:", rs.String(), rs.realPath.String())
|
||||
log.Log(WARN, " version mismatch:", godep, version, currentversion)
|
||||
}
|
||||
} else {
|
||||
deps[godep] = version
|
||||
log.Log(INFO, "\t", godep, "=", version)
|
||||
}
|
||||
} else {
|
||||
log.Log(WARN, "\t INVALID:", parts)
|
||||
}
|
||||
}
|
||||
|
||||
if err := scanner.Err(); err != nil {
|
||||
rs.goConfig = nil
|
||||
return false
|
||||
}
|
||||
|
||||
rs.goConfig = deps
|
||||
return true
|
||||
}
|
||||
|
||||
func ScanGoSrc() {
|
||||
log.Log(WARN, "Scanning all go.sum files")
|
||||
for path, rs := range windowMap {
|
||||
|
@ -336,190 +250,6 @@ func (rs *RepoStatus) ScanGoSrc() {
|
|||
}
|
||||
}
|
||||
|
||||
// check if it is safe to remake the go.sum & go.mod files
|
||||
func (rs *RepoStatus) CheckSafeGoSumRemake() (bool, []string) {
|
||||
myGoSumS := rs.goSumStatus.String()
|
||||
if rs.ReadGoMod() {
|
||||
log.Log(INFO, "parsed go.mod", rs.realPath.String())
|
||||
} else {
|
||||
log.Log(WARN, "Something went wrong parsing go.mod", rs.realPath.String())
|
||||
return false, nil
|
||||
}
|
||||
log.Log(WARN, "go.sum:", rs.realPath.String())
|
||||
var clean []string
|
||||
for depname, version := range rs.goConfig {
|
||||
if strings.HasSuffix(depname, "/v2") {
|
||||
log.Log(WARN, " FOUND /v2 wierd golang stuff. instead, look for:", depname)
|
||||
depname = strings.TrimSuffix(depname, "/v2")
|
||||
}
|
||||
log.Log(WARN, " ", depname, version)
|
||||
deprs, ok := windowMap[depname]
|
||||
if ok {
|
||||
if deprs.CheckDirty() {
|
||||
log.Log(WARN, " IS DIRTY", deprs.String())
|
||||
clean = append(clean, deprs.String())
|
||||
}
|
||||
if deprs.readOnly.String() == "true" {
|
||||
log.Log(WARN, " SKIPPING Read Only", deprs.String())
|
||||
} else {
|
||||
goSumS := deprs.goSumStatus.String()
|
||||
log.Log(WARN, " FOUND", deprs.String(), goSumS)
|
||||
username := deprs.mainWorkingName.String()
|
||||
userhash, _ := deprs.gitConfig.hashes[username]
|
||||
userversion, _ := deprs.gitConfig.versions[userhash]
|
||||
log.Log(WARN, " username :"+username, userhash)
|
||||
log.Log(WARN, " username :"+username, userversion)
|
||||
if version == userversion {
|
||||
log.Log(WARN, " USER VERSIONS MATCH", version, userversion, goSumS)
|
||||
clean = append(clean, deprs.String())
|
||||
} else {
|
||||
os.Unsetenv("GO111MODULE")
|
||||
log.Log(WARN, " USER VERSIONS MISMATCH", version, userversion, myGoSumS)
|
||||
log.Log(WARN, " IGNORE UNCHANGED REPO. RUNNING 'go get'", depname, userversion)
|
||||
err, output := rs.RunCmd([]string{"go", "get", depname + "@" + userversion})
|
||||
log.Log(WARN, " go get", depname, err, output)
|
||||
/*
|
||||
switch goSumS {
|
||||
case "SAFE":
|
||||
log.Log(WARN, " USER VERSIONS MISMATCH", version, userversion)
|
||||
log.Log(WARN, " IGNORE SAFE REPO")
|
||||
err, output := rs.RunCmd([]string{"go", "get", depname + "@" + userversion})
|
||||
log.Log(WARN, " go get", depname, err, output)
|
||||
case "CLEAN":
|
||||
log.Log(WARN, " USER VERSIONS MISMATCH", version, userversion)
|
||||
log.Log(WARN, " IGNORE CLEAN REPO")
|
||||
case "PRIMATIVE":
|
||||
log.Log(WARN, " USER VERSIONS MISMATCH", version, userversion)
|
||||
log.Log(WARN, " IGNORE PRIMATIVE REPO")
|
||||
err, output := rs.RunCmd([]string{"go", "get", depname + "@" + userversion})
|
||||
log.Log(WARN, " go get", depname, err, output)
|
||||
default:
|
||||
log.Log(WARN, " USER VERSIONS MISMATCH default", version, userversion)
|
||||
clean = append(clean, deprs.String())
|
||||
if myGoSumS == "UNCHANGED" {
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
} else {
|
||||
log.Log(WARN, " NOT FOUND", depname)
|
||||
// only fail on our stuff
|
||||
if strings.HasPrefix(depname, "go.wit.com") {
|
||||
// log.Log(WARN, " go get -v", depname)
|
||||
// rs.RunCmd([]string{"go", "get", "-v", depname})
|
||||
return false, clean
|
||||
}
|
||||
log.Log(WARN, " NOT FOUND BUT IGNORING FOR NOW")
|
||||
}
|
||||
}
|
||||
if len(clean) == 0 {
|
||||
return true, nil
|
||||
}
|
||||
return false, clean
|
||||
}
|
||||
|
||||
func (rs *RepoStatus) CheckGoSum() (bool, string) {
|
||||
if rs.ReadGoMod() {
|
||||
log.Log(INFO, "parsed go.mod", rs.realPath.String())
|
||||
} else {
|
||||
log.Log(WARN, "Something went wrong parsing go.mod", rs.realPath.String())
|
||||
return false, ""
|
||||
}
|
||||
log.Log(WARN, "go.sum:", rs.realPath.String())
|
||||
for depname, version := range rs.goConfig {
|
||||
if strings.HasSuffix(depname, "/v2") {
|
||||
log.Log(WARN, " FOUND /v2 wierd golang stuff. instead, look for:", depname)
|
||||
depname = strings.TrimSuffix(depname, "/v2")
|
||||
}
|
||||
log.Log(WARN, " ", depname, version)
|
||||
deprs, ok := windowMap[depname]
|
||||
if ok {
|
||||
if deprs.CheckDirty() {
|
||||
log.Log(WARN, " IS DIRTY", deprs.String())
|
||||
return false, ""
|
||||
}
|
||||
if deprs.readOnly.String() == "true" {
|
||||
log.Log(WARN, " SKIPPING Read Only", deprs.String())
|
||||
} else {
|
||||
log.Log(WARN, " FOUND", deprs.String(), deprs.goSumStatus.String())
|
||||
username := deprs.mainWorkingName.String()
|
||||
userhash, _ := deprs.gitConfig.hashes[username]
|
||||
userversion, _ := deprs.gitConfig.versions[userhash]
|
||||
log.Log(WARN, " username :"+username, userhash)
|
||||
log.Log(WARN, " username :"+username, userversion)
|
||||
if version == userversion {
|
||||
log.Log(WARN, " USER VERSIONS MATCH", version, userversion)
|
||||
if deprs.goSumStatus.String() == "BAD" {
|
||||
log.Log(WARN, " USER VERSION IS BAD!! return false")
|
||||
return false, ""
|
||||
}
|
||||
} else {
|
||||
log.Log(WARN, " USER VERSIONS MISMATCH", version, userversion)
|
||||
return false, ""
|
||||
}
|
||||
}
|
||||
} else {
|
||||
log.Log(WARN, " NOT FOUND", depname)
|
||||
if strings.HasSuffix(depname, "/v2") {
|
||||
log.Log(WARN, " FOUND /v2 wierd golang stuff. instead, look for:", depname)
|
||||
}
|
||||
// only fail on our stuff
|
||||
if strings.HasPrefix(depname, "go.wit.com") {
|
||||
// log.Log(WARN, " go get -v", depname)
|
||||
// rs.RunCmd([]string{"go", "get", "-v", depname})
|
||||
return false, depname
|
||||
}
|
||||
log.Log(WARN, " NOT FOUND BUT IGNORING FOR NOW")
|
||||
}
|
||||
}
|
||||
err, output := rs.RunCmd([]string{"git", "branch", "--remotes"})
|
||||
if err == nil {
|
||||
lines := strings.Split(output, "\n")
|
||||
for i, s := range lines {
|
||||
log.Log(WARN, "add line", i, s)
|
||||
}
|
||||
} else {
|
||||
log.Log(WARN, "git branch --remotes failed", err)
|
||||
}
|
||||
return true, ""
|
||||
}
|
||||
|
||||
func (rs *RepoStatus) MakeRedomod() bool {
|
||||
var err error
|
||||
var b bool
|
||||
var output string
|
||||
var worked bool = true
|
||||
if rs.ReadOnly() {
|
||||
log.Log(WARN, "will not go mod redo read only repos", rs.String())
|
||||
return false
|
||||
}
|
||||
|
||||
os.Unsetenv("GO111MODULE")
|
||||
path := rs.realPath.String()
|
||||
err, b, output = RunCmd(path, []string{"rm", "-f", "go.mod", "go.sum"})
|
||||
if err != nil {
|
||||
worked = false
|
||||
log.Log(WARN, "rm failed", err, b, output)
|
||||
}
|
||||
err, b, output = RunCmd(path, []string{"go", "mod", "init"})
|
||||
if err != nil {
|
||||
worked = false
|
||||
log.Log(WARN, "go mod init failed", err, b, output)
|
||||
}
|
||||
err, b, output = RunCmd(path, []string{"go", "mod", "tidy"})
|
||||
if err != nil {
|
||||
worked = false
|
||||
log.Log(WARN, "go mod tidy failed", err, b, output)
|
||||
}
|
||||
if worked {
|
||||
log.Log(WARN, "MakeRedomod() worked", path)
|
||||
} else {
|
||||
log.Log(WARN, "MakeRedomod() failed", path)
|
||||
}
|
||||
return worked
|
||||
}
|
||||
|
||||
func (rs *RepoStatus) ReadOnly() bool {
|
||||
if rs.readOnly.String() == "true" {
|
||||
return true
|
||||
|
@ -530,20 +260,20 @@ func (rs *RepoStatus) ReadOnly() bool {
|
|||
|
||||
func (rs *RepoStatus) processBranch(branch string) {
|
||||
fullpath := rs.realPath.String()
|
||||
log.Log(WARN, " ", branch)
|
||||
log.Log(INFO, " ", branch)
|
||||
hash, ok := rs.gitConfig.hashes[branch]
|
||||
filename := fullpath + "/.git/refs/heads/" + branch
|
||||
log.Log(WARN, " hash: need to open", filename)
|
||||
log.Log(INFO, " hash: need to open", filename)
|
||||
newhash, err := readFileToString(filename)
|
||||
if err != nil {
|
||||
log.Log(WARN, " hash: read failed", filename)
|
||||
log.Log(WARN, "hash: read failed", filename, rs.String())
|
||||
return
|
||||
}
|
||||
log.Log(WARN, " hash:", newhash)
|
||||
log.Log(INFO, " hash:", newhash)
|
||||
rs.gitConfig.hashes[branch] = newhash
|
||||
if ok {
|
||||
if hash != newhash {
|
||||
log.Log(WARN, " hash changed!!!!!!!!!", hash)
|
||||
log.Log(WARN, "hash changed", hash, rs.String())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -552,5 +282,5 @@ func (rs *RepoStatus) processBranch(branch string) {
|
|||
_, _, output := RunCmd(rs.realPath.String(), cmd)
|
||||
output = strings.TrimSpace(output)
|
||||
rs.gitConfig.versions[newhash] = output
|
||||
log.Log(WARN, " hash: version", output)
|
||||
log.Log(INFO, " hash: version", output)
|
||||
}
|
||||
|
|
|
@ -13,6 +13,10 @@ func (rs *RepoStatus) drawGitCommands() {
|
|||
rs.Update()
|
||||
})
|
||||
|
||||
newgrid.NewButton("UpdateCurrent()", func() {
|
||||
rs.Update()
|
||||
})
|
||||
|
||||
newgrid.NewButton("CheckDirty()", func() {
|
||||
if rs.CheckDirty() {
|
||||
log.Log(WARN, "is dirty")
|
||||
|
|
35
new.go
35
new.go
|
@ -5,7 +5,6 @@ import (
|
|||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"go.wit.com/gui"
|
||||
"go.wit.com/lib/gadgets"
|
||||
"go.wit.com/log"
|
||||
)
|
||||
|
@ -45,7 +44,18 @@ func NewRepoStatusWindow(path string) *RepoStatus {
|
|||
// return nil
|
||||
}
|
||||
|
||||
rs := New(gui.TreeRoot(), path)
|
||||
rs := &RepoStatus{
|
||||
ready: false,
|
||||
}
|
||||
rs.tags = make(map[string]string)
|
||||
rs.window = gadgets.RawBasicWindow("GO Repo Details " + path)
|
||||
rs.window.Horizontal()
|
||||
rs.window.Make()
|
||||
rs.ready = true
|
||||
rs.window.Custom = func() {
|
||||
rs.Hide()
|
||||
log.Warn("repostatus user closed the window()")
|
||||
}
|
||||
rs.draw()
|
||||
|
||||
// save ~/go/src & the whole path strings
|
||||
|
@ -56,6 +66,7 @@ func NewRepoStatusWindow(path string) *RepoStatus {
|
|||
rs.readGitConfig()
|
||||
|
||||
rs.readOnly.SetValue("true")
|
||||
// ignore everything else for now
|
||||
if strings.HasPrefix(path, "go.wit.com") {
|
||||
rs.readOnly.SetValue("false")
|
||||
}
|
||||
|
@ -63,26 +74,6 @@ func NewRepoStatusWindow(path string) *RepoStatus {
|
|||
rs.readOnly.SetValue("false")
|
||||
}
|
||||
|
||||
windowMap[path] = rs
|
||||
|
||||
// todo check if a window already exists for this path
|
||||
return rs
|
||||
}
|
||||
|
||||
func New(p *gui.Node, path string) *RepoStatus {
|
||||
rs := &RepoStatus{
|
||||
ready: false,
|
||||
parent: p,
|
||||
}
|
||||
rs.tags = make(map[string]string)
|
||||
rs.window = gadgets.NewBasicWindow(p, "GO Repo Details "+path)
|
||||
rs.window.Horizontal()
|
||||
rs.window.Make()
|
||||
rs.ready = true
|
||||
rs.window.Custom = func() {
|
||||
rs.Hide()
|
||||
log.Warn("repostatus user closed the window()")
|
||||
}
|
||||
windowMap[path] = rs
|
||||
return rs
|
||||
}
|
||||
|
|
|
@ -0,0 +1,287 @@
|
|||
package repostatus
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"go.wit.com/log"
|
||||
)
|
||||
|
||||
// this checks to see if the repo is truly not dependent on _anything_ else
|
||||
// like spew or lib/widget
|
||||
func (rs *RepoStatus) CheckPrimativeGoMod() bool {
|
||||
log.Log(WARN, "CheckPrimativeGoMod()", rs.realPath.String())
|
||||
tmp := filepath.Join(rs.realPath.String(), "go.mod")
|
||||
gomod, err := os.Open(tmp)
|
||||
if err != nil {
|
||||
log.Log(WARN, "missing go.mod", rs.realPath.String())
|
||||
rs.goConfig = nil
|
||||
return false
|
||||
}
|
||||
defer gomod.Close()
|
||||
|
||||
scanner := bufio.NewScanner(gomod)
|
||||
for scanner.Scan() {
|
||||
line := strings.TrimSpace(scanner.Text())
|
||||
|
||||
parts := strings.Split(line, " ")
|
||||
log.Log(INFO, " gomod:", parts)
|
||||
if len(parts) >= 1 {
|
||||
log.Log(INFO, " gomod: part[0] =", parts[0])
|
||||
if parts[0] == "require" {
|
||||
log.Log(INFO, " should return false here")
|
||||
return false
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// readGoMod reads and parses the go.sum file (TODO: do the go.mod file)
|
||||
func (rs *RepoStatus) ReadGoMod() bool {
|
||||
if rs.CheckPrimativeGoMod() {
|
||||
log.Info("PRIMATIVE repo:", rs.String())
|
||||
return true
|
||||
}
|
||||
|
||||
tmp := filepath.Join(rs.realPath.String(), "go.sum")
|
||||
gosum, err := os.Open(tmp)
|
||||
if err != nil {
|
||||
log.Log(WARN, "missing go.sum", rs.realPath.String())
|
||||
rs.goConfig = nil
|
||||
return false
|
||||
}
|
||||
defer gosum.Close()
|
||||
|
||||
var deps GoConfig
|
||||
deps = make(GoConfig)
|
||||
|
||||
scanner := bufio.NewScanner(gosum)
|
||||
log.Log(INFO, "gosum:", 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 {
|
||||
// ignore these warnings for now
|
||||
depname := rs.String()
|
||||
if strings.HasPrefix(depname, "go.wit.com") {
|
||||
log.Log(INFO, "REPO:", rs.realPath.String())
|
||||
log.Log(INFO, " version mismatch:", godep, version, currentversion)
|
||||
} else {
|
||||
log.Log(INFO, "REPO:", rs.realPath.String())
|
||||
log.Log(INFO, " version mismatch:", godep, version, currentversion)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
deps[godep] = version
|
||||
log.Log(INFO, "\t", godep, "=", version)
|
||||
}
|
||||
} else {
|
||||
log.Log(WARN, "\t INVALID:", parts)
|
||||
}
|
||||
}
|
||||
|
||||
if err := scanner.Err(); err != nil {
|
||||
rs.goConfig = nil
|
||||
return false
|
||||
}
|
||||
|
||||
rs.goConfig = deps
|
||||
return true
|
||||
}
|
||||
|
||||
// check if it is safe to remake the go.sum & go.mod files
|
||||
func (rs *RepoStatus) CheckSafeGoSumRemake() (bool, []string) {
|
||||
myGoSumS := rs.goSumStatus.String()
|
||||
if rs.ReadGoMod() {
|
||||
log.Log(INFO, "parsed go.mod", rs.realPath.String())
|
||||
} else {
|
||||
log.Log(WARN, "Something went wrong parsing go.mod", rs.realPath.String())
|
||||
return false, nil
|
||||
}
|
||||
log.Log(WARN, "go.sum:", rs.realPath.String())
|
||||
var clean []string
|
||||
for depname, version := range rs.goConfig {
|
||||
if strings.HasSuffix(depname, "/v2") {
|
||||
log.Log(WARN, " FOUND /v2 wierd golang stuff. instead, look for:", depname)
|
||||
depname = strings.TrimSuffix(depname, "/v2")
|
||||
}
|
||||
log.Log(WARN, " ", depname, version)
|
||||
deprs, ok := windowMap[depname]
|
||||
if ok {
|
||||
if deprs.CheckDirty() {
|
||||
log.Log(WARN, " IS DIRTY", deprs.String())
|
||||
clean = append(clean, deprs.String())
|
||||
}
|
||||
if deprs.readOnly.String() == "true" {
|
||||
log.Log(WARN, " SKIPPING Read Only", deprs.String())
|
||||
} else {
|
||||
goSumS := deprs.goSumStatus.String()
|
||||
log.Log(WARN, " FOUND", deprs.String(), goSumS)
|
||||
username := deprs.mainWorkingName.String()
|
||||
userhash, _ := deprs.gitConfig.hashes[username]
|
||||
userversion, _ := deprs.gitConfig.versions[userhash]
|
||||
log.Log(WARN, " username :"+username, userhash)
|
||||
log.Log(WARN, " username :"+username, userversion)
|
||||
if version == userversion {
|
||||
log.Log(WARN, " USER VERSIONS MATCH", version, userversion, goSumS)
|
||||
clean = append(clean, deprs.String())
|
||||
} else {
|
||||
os.Unsetenv("GO111MODULE")
|
||||
log.Log(WARN, " USER VERSIONS MISMATCH", version, userversion, myGoSumS)
|
||||
log.Log(WARN, " IGNORE UNCHANGED REPO. RUNNING 'go get'", depname, userversion)
|
||||
err, output := rs.RunCmd([]string{"go", "get", depname + "@" + userversion})
|
||||
log.Log(WARN, " go get", depname, err, output)
|
||||
/*
|
||||
switch goSumS {
|
||||
case "SAFE":
|
||||
log.Log(WARN, " USER VERSIONS MISMATCH", version, userversion)
|
||||
log.Log(WARN, " IGNORE SAFE REPO")
|
||||
err, output := rs.RunCmd([]string{"go", "get", depname + "@" + userversion})
|
||||
log.Log(WARN, " go get", depname, err, output)
|
||||
case "CLEAN":
|
||||
log.Log(WARN, " USER VERSIONS MISMATCH", version, userversion)
|
||||
log.Log(WARN, " IGNORE CLEAN REPO")
|
||||
case "PRIMATIVE":
|
||||
log.Log(WARN, " USER VERSIONS MISMATCH", version, userversion)
|
||||
log.Log(WARN, " IGNORE PRIMATIVE REPO")
|
||||
err, output := rs.RunCmd([]string{"go", "get", depname + "@" + userversion})
|
||||
log.Log(WARN, " go get", depname, err, output)
|
||||
default:
|
||||
log.Log(WARN, " USER VERSIONS MISMATCH default", version, userversion)
|
||||
clean = append(clean, deprs.String())
|
||||
if myGoSumS == "UNCHANGED" {
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// log.Log(WARN, " NOT FOUND", depname)
|
||||
// only fail on our stuff
|
||||
if strings.HasPrefix(depname, "go.wit.com") {
|
||||
log.Log(WARN, " go get -v", depname)
|
||||
// rs.RunCmd([]string{"go", "get", "-v", depname})
|
||||
return false, clean
|
||||
}
|
||||
// log.Log(WARN, " NOT FOUND BUT IGNORING FOR NOW")
|
||||
}
|
||||
}
|
||||
if len(clean) == 0 {
|
||||
return true, nil
|
||||
}
|
||||
return false, clean
|
||||
}
|
||||
|
||||
func (rs *RepoStatus) CheckGoSum() (bool, string) {
|
||||
if rs.ReadGoMod() {
|
||||
log.Log(INFO, "parsed go.mod", rs.realPath.String())
|
||||
} else {
|
||||
log.Log(WARN, "Something went wrong parsing go.mod", rs.realPath.String())
|
||||
return false, ""
|
||||
}
|
||||
log.Log(WARN, "go.sum:", rs.realPath.String())
|
||||
for depname, version := range rs.goConfig {
|
||||
if strings.HasSuffix(depname, "/v2") {
|
||||
log.Log(WARN, " FOUND /v2 wierd golang stuff. instead, look for:", depname)
|
||||
depname = strings.TrimSuffix(depname, "/v2")
|
||||
}
|
||||
log.Log(WARN, " ", depname, version)
|
||||
deprs, ok := windowMap[depname]
|
||||
if ok {
|
||||
if deprs.CheckDirty() {
|
||||
log.Log(WARN, " IS DIRTY", deprs.String())
|
||||
return false, ""
|
||||
}
|
||||
if deprs.readOnly.String() == "true" {
|
||||
log.Log(WARN, " SKIPPING Read Only", deprs.String())
|
||||
} else {
|
||||
log.Log(WARN, " FOUND", deprs.String(), deprs.goSumStatus.String())
|
||||
username := deprs.mainWorkingName.String()
|
||||
userhash, _ := deprs.gitConfig.hashes[username]
|
||||
userversion, _ := deprs.gitConfig.versions[userhash]
|
||||
log.Log(WARN, " username :"+username, userhash)
|
||||
log.Log(WARN, " username :"+username, userversion)
|
||||
if version == userversion {
|
||||
log.Log(WARN, " USER VERSIONS MATCH", version, userversion)
|
||||
if deprs.goSumStatus.String() == "BAD" {
|
||||
log.Log(WARN, " USER VERSION IS BAD!! return false")
|
||||
return false, ""
|
||||
}
|
||||
} else {
|
||||
log.Log(WARN, " USER VERSIONS MISMATCH", version, userversion)
|
||||
return false, ""
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// log.Log(WARN, " NOT FOUND", depname)
|
||||
if strings.HasSuffix(depname, "/v2") {
|
||||
log.Log(WARN, " FOUND /v2 wierd golang stuff. instead, look for:", depname)
|
||||
}
|
||||
// only fail on our stuff
|
||||
if strings.HasPrefix(depname, "go.wit.com") {
|
||||
log.Log(WARN, " go get -v", depname)
|
||||
// rs.RunCmd([]string{"go", "get", "-v", depname})
|
||||
return false, depname
|
||||
}
|
||||
// log.Log(WARN, " NOT FOUND BUT IGNORING FOR NOW")
|
||||
}
|
||||
}
|
||||
err, output := rs.RunCmd([]string{"git", "branch", "--remotes"})
|
||||
if err == nil {
|
||||
lines := strings.Split(output, "\n")
|
||||
for i, s := range lines {
|
||||
log.Log(WARN, "add line", i, s)
|
||||
}
|
||||
} else {
|
||||
log.Log(WARN, "git branch --remotes failed", err)
|
||||
}
|
||||
return true, ""
|
||||
}
|
||||
|
||||
func (rs *RepoStatus) MakeRedomod() bool {
|
||||
var err error
|
||||
var b bool
|
||||
var output string
|
||||
var worked bool = true
|
||||
if rs.ReadOnly() {
|
||||
log.Log(WARN, "will not go mod redo read only repos", rs.String())
|
||||
return false
|
||||
}
|
||||
|
||||
os.Unsetenv("GO111MODULE")
|
||||
path := rs.realPath.String()
|
||||
err, b, output = RunCmd(path, []string{"rm", "-f", "go.mod", "go.sum"})
|
||||
if err != nil {
|
||||
worked = false
|
||||
log.Log(WARN, "rm failed", err, b, output)
|
||||
}
|
||||
err, b, output = RunCmd(path, []string{"go", "mod", "init"})
|
||||
if err != nil {
|
||||
worked = false
|
||||
log.Log(WARN, "go mod init failed", err, b, output)
|
||||
}
|
||||
err, b, output = RunCmd(path, []string{"go", "mod", "tidy"})
|
||||
if err != nil {
|
||||
worked = false
|
||||
log.Log(WARN, "go mod tidy failed", err, b, output)
|
||||
}
|
||||
if worked {
|
||||
log.Log(WARN, "MakeRedomod() worked", path)
|
||||
} else {
|
||||
log.Log(WARN, "MakeRedomod() failed", path)
|
||||
}
|
||||
return worked
|
||||
}
|
|
@ -9,11 +9,8 @@ type RepoStatus struct {
|
|||
ready bool
|
||||
changed bool
|
||||
|
||||
// lasttagrev string
|
||||
tags map[string]string
|
||||
|
||||
parent *gui.Node
|
||||
|
||||
window *gadgets.BasicWindow
|
||||
|
||||
// a window to manage your .git tags
|
||||
|
@ -29,7 +26,6 @@ type RepoStatus struct {
|
|||
|
||||
currentBranch *gadgets.OneLiner
|
||||
currentVersion *gadgets.OneLiner
|
||||
// tagsDrop *gadgets.BasicDropdown
|
||||
|
||||
lasttag *gadgets.OneLiner
|
||||
masterBranchVersion *gadgets.OneLiner
|
||||
|
@ -44,7 +40,6 @@ type RepoStatus struct {
|
|||
mainMergeB *gui.Node
|
||||
releaseVersion *gui.Node
|
||||
|
||||
// vgroup *gui.Node
|
||||
minor *gadgets.BasicCombobox
|
||||
major *gadgets.BasicCombobox
|
||||
revision *gadgets.BasicCombobox
|
||||
|
@ -60,10 +55,6 @@ type RepoStatus struct {
|
|||
gitStatusGroup *gui.Node
|
||||
gitCommandsGroup *gui.Node
|
||||
|
||||
// masterDrop *gadgets.BasicDropdown
|
||||
// develDrop *gadgets.BasicDropdown
|
||||
// userDrop *gadgets.BasicDropdown
|
||||
|
||||
showBranchesButton *gui.Node
|
||||
checkBranchesButton *gui.Node
|
||||
|
||||
|
|
Loading…
Reference in New Issue