2024-01-23 10:52:17 -06:00
|
|
|
package repostatus
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bufio"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"go.wit.com/log"
|
|
|
|
)
|
|
|
|
|
|
|
|
// GitConfig represents the parsed .git/config data
|
|
|
|
// type GitConfig map[string]map[string]string
|
|
|
|
|
|
|
|
type remote struct {
|
|
|
|
url string
|
|
|
|
fetch string
|
|
|
|
}
|
|
|
|
|
|
|
|
type branch struct {
|
|
|
|
remote string
|
|
|
|
merge string
|
|
|
|
}
|
|
|
|
|
|
|
|
type GitConfig struct {
|
|
|
|
core map[string]string // map[origin] = "https:/git.wit.org/gui/gadgets"
|
|
|
|
remotes map[string]*remote // map[origin] = "https:/git.wit.org/gui/gadgets"
|
|
|
|
branches map[string]*branch // map[guimaster] = origin guimaster
|
2024-01-23 22:47:39 -06:00
|
|
|
hashes map[string]string
|
|
|
|
versions map[string]string
|
2024-01-23 10:52:17 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
type GoConfig map[string]string
|
|
|
|
|
2024-01-25 01:30:01 -06:00
|
|
|
func ListGitDirectories() []string {
|
2024-01-23 10:52:17 -06:00
|
|
|
var all []string
|
|
|
|
homeDir, err := os.UserHomeDir()
|
|
|
|
if err != nil {
|
|
|
|
log.Log(WARN, "Error getting home directory:", err)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
srcDir := filepath.Join(homeDir, "go/src")
|
|
|
|
|
|
|
|
err = filepath.Walk(srcDir, func(path string, info os.FileInfo, err error) error {
|
|
|
|
if err != nil {
|
|
|
|
log.Log(WARN, "Error accessing path:", path, err)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if the current path is a directory and has a .git subdirectory
|
|
|
|
if info.IsDir() && isGitDir(path) {
|
|
|
|
all = append(all, path)
|
|
|
|
// fmt.Println(path)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
log.Log(WARN, "Error walking the path:", srcDir, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return all
|
|
|
|
}
|
|
|
|
|
|
|
|
// isGitDir checks if a .git directory exists inside the given directory
|
|
|
|
func isGitDir(dir string) bool {
|
|
|
|
gitDir := filepath.Join(dir, ".git")
|
|
|
|
info, err := os.Stat(gitDir)
|
|
|
|
if os.IsNotExist(err) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return info.IsDir()
|
|
|
|
}
|
|
|
|
|
|
|
|
// readGitConfig reads and parses the .git/config file
|
2024-01-23 22:47:39 -06:00
|
|
|
func (rs *RepoStatus) readGitConfig() error {
|
|
|
|
filename := filepath.Join(rs.realPath.String(), "/.git/config")
|
|
|
|
file, err := os.Open(filename)
|
2024-01-23 10:52:17 -06:00
|
|
|
if err != nil {
|
2024-01-25 02:23:56 -06:00
|
|
|
filename = filepath.Join(rs.realPath.String(), "../.git/config")
|
|
|
|
log.Log(WARN, "readGitConfig() trying up one directory instead", filename)
|
|
|
|
file, err = os.Open(filename)
|
|
|
|
if err != nil {
|
|
|
|
panic("couldn't open .git/config")
|
|
|
|
return nil
|
|
|
|
}
|
2024-01-23 10:52:17 -06:00
|
|
|
}
|
|
|
|
defer file.Close()
|
|
|
|
|
|
|
|
var currentSection string = ""
|
|
|
|
var currentName string = ""
|
|
|
|
|
2024-01-23 22:47:39 -06:00
|
|
|
rs.gitConfig = new(GitConfig)
|
|
|
|
rs.gitConfig.core = make(map[string]string)
|
|
|
|
rs.gitConfig.remotes = make(map[string]*remote)
|
|
|
|
rs.gitConfig.branches = make(map[string]*branch)
|
|
|
|
rs.gitConfig.versions = make(map[string]string)
|
|
|
|
rs.gitConfig.hashes = make(map[string]string)
|
2024-01-23 10:52:17 -06:00
|
|
|
|
|
|
|
scanner := bufio.NewScanner(file)
|
|
|
|
for scanner.Scan() {
|
|
|
|
line := strings.TrimSpace(scanner.Text())
|
|
|
|
|
|
|
|
// Skip empty lines and comments
|
|
|
|
if line == "" || strings.HasPrefix(line, "#") || strings.HasPrefix(line, ";") {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check for section headers
|
|
|
|
if strings.HasPrefix(line, "[") && strings.HasSuffix(line, "]") {
|
|
|
|
line = strings.Trim(line, "[]")
|
|
|
|
parts := strings.Split(line, " ")
|
|
|
|
currentSection = parts[0]
|
|
|
|
|
|
|
|
if len(parts) == 2 {
|
|
|
|
line = strings.Trim(line, "[]")
|
2024-01-23 15:20:54 -06:00
|
|
|
currentName = strings.Trim(parts[1], "\"")
|
2024-01-23 10:52:17 -06:00
|
|
|
}
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
partsNew := strings.SplitN(line, "=", 2)
|
|
|
|
if len(partsNew) != 2 {
|
|
|
|
log.Log(WARN, "error on config section:", currentSection, "line:", line)
|
|
|
|
}
|
|
|
|
|
|
|
|
key := strings.TrimSpace(partsNew[0])
|
2024-01-23 15:20:54 -06:00
|
|
|
key = strings.TrimSuffix(key, "\"")
|
|
|
|
|
2024-01-23 10:52:17 -06:00
|
|
|
value := strings.TrimSpace(partsNew[1])
|
2024-01-23 15:20:54 -06:00
|
|
|
value = strings.TrimSuffix(value, "\"")
|
2024-01-23 10:52:17 -06:00
|
|
|
|
|
|
|
switch currentSection {
|
|
|
|
case "core":
|
2024-01-23 22:47:39 -06:00
|
|
|
rs.gitConfig.core[key] = value
|
2024-01-23 10:52:17 -06:00
|
|
|
case "remote":
|
2024-01-23 22:47:39 -06:00
|
|
|
test, ok := rs.gitConfig.remotes[currentName]
|
2024-01-23 10:52:17 -06:00
|
|
|
if !ok {
|
|
|
|
test = new(remote)
|
2024-01-23 22:47:39 -06:00
|
|
|
rs.gitConfig.remotes[currentName] = test
|
2024-01-23 10:52:17 -06:00
|
|
|
}
|
|
|
|
log.Log(INFO, "switch currentSection", currentSection, currentName)
|
|
|
|
switch key {
|
|
|
|
case "url":
|
|
|
|
if test.url == value {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if test.url == "" {
|
|
|
|
test.url = value
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
log.Log(WARN, "error url mismatch", test.url, value)
|
|
|
|
case "fetch":
|
|
|
|
if test.fetch == value {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if test.fetch == "" {
|
|
|
|
test.fetch = value
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
log.Log(WARN, "error fetch mismatch", test.fetch, value)
|
|
|
|
default:
|
|
|
|
log.Log(WARN, "error unknown remote:", currentSection, currentName, "key", key, "value", value)
|
|
|
|
}
|
|
|
|
case "branch":
|
2024-01-23 22:47:39 -06:00
|
|
|
test, ok := rs.gitConfig.branches[currentName]
|
2024-01-23 10:52:17 -06:00
|
|
|
if !ok {
|
|
|
|
test = new(branch)
|
2024-01-23 22:47:39 -06:00
|
|
|
rs.gitConfig.branches[currentName] = test
|
|
|
|
rs.processBranch(currentName)
|
2024-01-23 10:52:17 -06:00
|
|
|
}
|
|
|
|
switch key {
|
|
|
|
case "remote":
|
2024-01-23 22:47:39 -06:00
|
|
|
rs.gitConfig.branches[currentName].remote = value
|
2024-01-23 10:52:17 -06:00
|
|
|
case "merge":
|
2024-01-23 22:47:39 -06:00
|
|
|
rs.gitConfig.branches[currentName].merge = value
|
2024-01-23 10:52:17 -06:00
|
|
|
default:
|
|
|
|
log.Log(WARN, "error unknown remote:", currentSection, currentName, key, value)
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
log.Log(WARN, "error unknown currentSection", currentSection, "line:", line)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := scanner.Err(); err != nil {
|
2024-01-23 22:47:39 -06:00
|
|
|
return err
|
2024-01-23 10:52:17 -06:00
|
|
|
}
|
|
|
|
|
2024-01-23 22:47:39 -06:00
|
|
|
return nil
|
2024-01-23 10:52:17 -06:00
|
|
|
}
|
|
|
|
|
2024-01-24 16:24:58 -06:00
|
|
|
// 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")
|
2024-01-23 10:52:17 -06:00
|
|
|
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()
|
|
|
|
|
2024-01-24 16:24:58 -06:00
|
|
|
scanner := bufio.NewScanner(gomod)
|
|
|
|
for scanner.Scan() {
|
|
|
|
line := strings.TrimSpace(scanner.Text())
|
|
|
|
|
|
|
|
parts := strings.Split(line, " ")
|
2024-01-26 11:53:22 -06:00
|
|
|
log.Log(INFO, " gomod:", parts)
|
2024-01-24 16:24:58 -06:00
|
|
|
if len(parts) >= 1 {
|
2024-01-26 11:53:22 -06:00
|
|
|
log.Log(INFO, " gomod: part[0] =", parts[0])
|
2024-01-24 16:24:58 -06:00
|
|
|
if parts[0] == "require" {
|
2024-01-26 11:53:22 -06:00
|
|
|
log.Log(INFO, " should return false here")
|
2024-01-24 16:24:58 -06:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2024-02-05 19:01:50 -06:00
|
|
|
func (rs *RepoStatus) GitLsFiles() (bool, string) {
|
|
|
|
err, output := rs.RunCmd([]string{"git", "ls-files"})
|
|
|
|
if err != nil {
|
|
|
|
log.Warn("git ls-files failed err =", err)
|
|
|
|
log.Warn("git ls-files failed output =", output)
|
|
|
|
return false, output
|
|
|
|
}
|
|
|
|
return true, output
|
|
|
|
}
|
|
|
|
|
2024-01-24 16:24:58 -06:00
|
|
|
// 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")
|
2024-01-23 10:52:17 -06:00
|
|
|
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 {
|
2024-01-23 15:39:53 -06:00
|
|
|
log.Log(WARN, "REPO:", rs.String(), rs.realPath.String())
|
|
|
|
log.Log(WARN, " version mismatch:", godep, version, currentversion)
|
2024-01-23 10:52:17 -06:00
|
|
|
}
|
|
|
|
} 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
|
|
|
|
}
|
2024-01-23 15:20:54 -06:00
|
|
|
|
|
|
|
func ScanGoSrc() {
|
|
|
|
log.Log(WARN, "Scanning all go.sum files")
|
|
|
|
for path, rs := range windowMap {
|
|
|
|
if rs.ReadGoMod() {
|
|
|
|
// everything is ok
|
|
|
|
} else {
|
|
|
|
log.Log(WARN, "failed reading go.sum repo:", path)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func ScanGitConfig() {
|
2024-01-23 22:47:39 -06:00
|
|
|
/*
|
2024-01-24 16:24:58 -06:00
|
|
|
for i, path := range listGitDirectories() {
|
|
|
|
filename := filepath.Join(path, ".git/config")
|
|
|
|
_, err := readGitConfig(filename)
|
|
|
|
if err != nil {
|
|
|
|
log.Log(WARN, "repo =", i, path)
|
|
|
|
log.Log(WARN, "Error reading .git/config:", err)
|
|
|
|
}
|
2024-01-23 15:20:54 -06:00
|
|
|
}
|
2024-01-23 22:47:39 -06:00
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
|
|
|
func (rs *RepoStatus) ScanGoSrc() {
|
|
|
|
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())
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Log(WARN, "go.sum:", rs.realPath.String())
|
|
|
|
for depname, version := range rs.goConfig {
|
|
|
|
log.Log(WARN, " ", depname, version)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-26 09:34:13 -06:00
|
|
|
// check if it is safe to remake the go.sum & go.mod files
|
|
|
|
func (rs *RepoStatus) CheckSafeGoSumRemake() (bool, []string) {
|
2024-01-31 16:38:31 -06:00
|
|
|
myGoSumS := rs.goSumStatus.String()
|
2024-01-26 09:34:13 -06:00
|
|
|
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)
|
2024-01-31 04:07:49 -06:00
|
|
|
username := deprs.mainWorkingName.String()
|
2024-01-26 09:34:13 -06:00
|
|
|
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 {
|
2024-01-31 16:38:31 -06:00
|
|
|
log.Log(WARN, " USER VERSIONS MATCH", version, userversion, goSumS)
|
|
|
|
clean = append(clean, deprs.String())
|
2024-01-26 09:34:13 -06:00
|
|
|
} else {
|
2024-01-31 16:38:31 -06:00
|
|
|
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)
|
|
|
|
/*
|
2024-02-06 04:02:46 -06:00
|
|
|
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" {
|
|
|
|
}
|
2024-01-31 16:38:31 -06:00
|
|
|
}
|
|
|
|
*/
|
2024-01-26 09:34:13 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} 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
|
|
|
|
}
|
|
|
|
|
2024-01-25 01:30:01 -06:00
|
|
|
func (rs *RepoStatus) CheckGoSum() (bool, string) {
|
2024-01-23 22:47:39 -06:00
|
|
|
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())
|
2024-01-25 01:30:01 -06:00
|
|
|
return false, ""
|
2024-01-23 22:47:39 -06:00
|
|
|
}
|
|
|
|
log.Log(WARN, "go.sum:", rs.realPath.String())
|
|
|
|
for depname, version := range rs.goConfig {
|
2024-01-25 01:30:01 -06:00
|
|
|
if strings.HasSuffix(depname, "/v2") {
|
|
|
|
log.Log(WARN, " FOUND /v2 wierd golang stuff. instead, look for:", depname)
|
|
|
|
depname = strings.TrimSuffix(depname, "/v2")
|
|
|
|
}
|
2024-01-23 22:47:39 -06:00
|
|
|
log.Log(WARN, " ", depname, version)
|
2024-01-26 09:34:13 -06:00
|
|
|
deprs, ok := windowMap[depname]
|
2024-01-23 22:47:39 -06:00
|
|
|
if ok {
|
2024-01-26 09:34:13 -06:00
|
|
|
if deprs.CheckDirty() {
|
|
|
|
log.Log(WARN, " IS DIRTY", deprs.String())
|
2024-01-25 01:30:01 -06:00
|
|
|
return false, ""
|
2024-01-23 22:47:39 -06:00
|
|
|
}
|
2024-01-26 09:34:13 -06:00
|
|
|
if deprs.readOnly.String() == "true" {
|
|
|
|
log.Log(WARN, " SKIPPING Read Only", deprs.String())
|
2024-01-23 22:47:39 -06:00
|
|
|
} else {
|
2024-01-26 09:34:13 -06:00
|
|
|
log.Log(WARN, " FOUND", deprs.String(), deprs.goSumStatus.String())
|
2024-01-31 04:07:49 -06:00
|
|
|
username := deprs.mainWorkingName.String()
|
2024-01-26 09:34:13 -06:00
|
|
|
userhash, _ := deprs.gitConfig.hashes[username]
|
|
|
|
userversion, _ := deprs.gitConfig.versions[userhash]
|
2024-01-25 01:30:01 -06:00
|
|
|
log.Log(WARN, " username :"+username, userhash)
|
|
|
|
log.Log(WARN, " username :"+username, userversion)
|
|
|
|
if version == userversion {
|
|
|
|
log.Log(WARN, " USER VERSIONS MATCH", version, userversion)
|
2024-01-26 09:34:13 -06:00
|
|
|
if deprs.goSumStatus.String() == "BAD" {
|
2024-01-26 02:41:14 -06:00
|
|
|
log.Log(WARN, " USER VERSION IS BAD!! return false")
|
|
|
|
return false, ""
|
|
|
|
}
|
2024-01-25 01:30:01 -06:00
|
|
|
} else {
|
|
|
|
log.Log(WARN, " USER VERSIONS MISMATCH", version, userversion)
|
|
|
|
return false, ""
|
|
|
|
}
|
2024-01-23 22:47:39 -06:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
log.Log(WARN, " NOT FOUND", depname)
|
2024-01-25 01:30:01 -06:00
|
|
|
if strings.HasSuffix(depname, "/v2") {
|
|
|
|
log.Log(WARN, " FOUND /v2 wierd golang stuff. instead, look for:", depname)
|
|
|
|
}
|
2024-01-25 23:19:51 -06:00
|
|
|
// 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")
|
2024-01-23 22:47:39 -06:00
|
|
|
}
|
|
|
|
}
|
2024-01-26 02:02:56 -06:00
|
|
|
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)
|
|
|
|
}
|
2024-01-25 01:30:01 -06:00
|
|
|
return true, ""
|
2024-01-23 22:47:39 -06:00
|
|
|
}
|
|
|
|
|
2024-02-01 13:30:01 -06:00
|
|
|
func (rs *RepoStatus) MakeRedomod() bool {
|
2024-01-24 16:24:58 -06:00
|
|
|
var err error
|
|
|
|
var b bool
|
|
|
|
var output string
|
|
|
|
var worked bool = true
|
2024-01-26 11:53:22 -06:00
|
|
|
if rs.ReadOnly() {
|
|
|
|
log.Log(WARN, "will not go mod redo read only repos", rs.String())
|
2024-02-01 13:30:01 -06:00
|
|
|
return false
|
2024-01-26 11:53:22 -06:00
|
|
|
}
|
2024-01-24 16:24:58 -06:00
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
2024-02-01 13:30:01 -06:00
|
|
|
return worked
|
2024-01-24 16:24:58 -06:00
|
|
|
}
|
|
|
|
|
2024-01-25 01:30:01 -06:00
|
|
|
func (rs *RepoStatus) ReadOnly() bool {
|
|
|
|
if rs.readOnly.String() == "true" {
|
|
|
|
return true
|
|
|
|
} else {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-23 22:47:39 -06:00
|
|
|
func (rs *RepoStatus) processBranch(branch string) {
|
|
|
|
fullpath := rs.realPath.String()
|
|
|
|
log.Log(WARN, " ", branch)
|
|
|
|
hash, ok := rs.gitConfig.hashes[branch]
|
|
|
|
filename := fullpath + "/.git/refs/heads/" + branch
|
|
|
|
log.Log(WARN, " hash: need to open", filename)
|
|
|
|
newhash, err := readFileToString(filename)
|
|
|
|
if err != nil {
|
|
|
|
log.Log(WARN, " hash: read failed", filename)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
log.Log(WARN, " hash:", newhash)
|
|
|
|
rs.gitConfig.hashes[branch] = newhash
|
|
|
|
if ok {
|
|
|
|
if hash != newhash {
|
|
|
|
log.Log(WARN, " hash changed!!!!!!!!!", hash)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var cmd []string
|
|
|
|
cmd = append(cmd, "git", "describe", "--tags", newhash)
|
|
|
|
_, _, output := RunCmd(rs.realPath.String(), cmd)
|
|
|
|
output = strings.TrimSpace(output)
|
|
|
|
rs.gitConfig.versions[newhash] = output
|
|
|
|
log.Log(WARN, " hash: version", output)
|
2024-01-23 15:20:54 -06:00
|
|
|
}
|