detect go.sum is clean
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
edf74e160e
commit
7c82f918aa
28
draw.go
28
draw.go
|
@ -11,13 +11,13 @@ import (
|
|||
|
||||
// creates the actual widgets.
|
||||
// it's assumed you are always passing in a box
|
||||
func (rs *RepoStatus) draw(goSrcPath string, realPath string) {
|
||||
func (rs *RepoStatus) draw() {
|
||||
if !rs.Ready() {
|
||||
return
|
||||
}
|
||||
|
||||
// display the status of the git repository
|
||||
rs.drawGitStatus(goSrcPath, realPath)
|
||||
rs.drawGitStatus()
|
||||
|
||||
// display the git branches and options
|
||||
rs.drawGitBranches()
|
||||
|
@ -107,30 +107,21 @@ func (rs *RepoStatus) drawGitBranches() {
|
|||
log.Log(WARN, " ", name, "remote:", branch.remote, "merge", branch.merge)
|
||||
}
|
||||
})
|
||||
|
||||
newgrid.NewButton("check go.sum", func() {
|
||||
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)
|
||||
}
|
||||
|
||||
rs.CheckGoSum()
|
||||
})
|
||||
}
|
||||
|
||||
func (rs *RepoStatus) drawGitStatus(goSrcPath string, realPath string) {
|
||||
func (rs *RepoStatus) drawGitStatus() {
|
||||
rs.gitStatusGroup = rs.window.Box().NewGroup("What GO Knows It Has")
|
||||
newgrid := rs.gitStatusGroup.NewGrid("gridnuts", 2, 2)
|
||||
newgrid.Margin()
|
||||
newgrid.Pad()
|
||||
|
||||
rs.path = gadgets.NewOneLiner(newgrid, "path")
|
||||
rs.goSrcPath = gadgets.NewOneLiner(newgrid, goSrcPath)
|
||||
rs.realPath = gadgets.NewOneLiner(newgrid, realPath)
|
||||
rs.goSrcPath = gadgets.NewOneLiner(newgrid, "~/go/src")
|
||||
rs.realPath = gadgets.NewOneLiner(newgrid, "full path")
|
||||
rs.realPath.Hide()
|
||||
rs.mainWorkingName = gadgets.NewOneLiner(newgrid, "main working branch")
|
||||
rs.mainWorkingName.SetValue("???")
|
||||
|
@ -149,11 +140,8 @@ func (rs *RepoStatus) drawGitStatus(goSrcPath string, realPath string) {
|
|||
rs.tagsDrop.AddText(line)
|
||||
}
|
||||
|
||||
// rs.masterBranchVersion = gadgets.NewOneLiner(newgrid, "master")
|
||||
// rs.develBranchVersion = gadgets.NewOneLiner(newgrid, "devel")
|
||||
// rs.userBranchVersion = gadgets.NewOneLiner(newgrid, "user")
|
||||
|
||||
rs.dirtyLabel = gadgets.NewOneLiner(newgrid, "dirty")
|
||||
rs.readOnly = gadgets.NewOneLiner(newgrid, "read only")
|
||||
|
||||
rs.speed = gadgets.NewOneLiner(newgrid, "refresh speed =")
|
||||
rs.speedActual = gadgets.NewOneLiner(newgrid, "speed actual =")
|
||||
|
|
2
git.go
2
git.go
|
@ -48,7 +48,7 @@ func (rs *RepoStatus) getCurrentBranchVersion() string {
|
|||
func (rs *RepoStatus) getLastTagVersion() string {
|
||||
out := run(rs.realPath.String(), "git", "rev-list --tags --max-count=1")
|
||||
log.Log(INFO, "getLastTagVersion()", out)
|
||||
rs.lasttagrev = out
|
||||
// rs.lasttagrev = out
|
||||
|
||||
lastreal := "describe --tags " + out
|
||||
// out = run(r.path, "git", "describe --tags c871d5ecf051a7dc4e3a77157cdbc0a457eb9ae1")
|
||||
|
|
120
gitConfig.go
120
gitConfig.go
|
@ -26,6 +26,8 @@ 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
|
||||
hashes map[string]string
|
||||
versions map[string]string
|
||||
}
|
||||
|
||||
type GoConfig map[string]string
|
||||
|
@ -73,20 +75,23 @@ func isGitDir(dir string) bool {
|
|||
}
|
||||
|
||||
// readGitConfig reads and parses the .git/config file
|
||||
func readGitConfig(filePath string) (*GitConfig, error) {
|
||||
file, err := os.Open(filePath)
|
||||
func (rs *RepoStatus) readGitConfig() error {
|
||||
filename := filepath.Join(rs.realPath.String(), "/.git/config")
|
||||
file, err := os.Open(filename)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
var currentSection string = ""
|
||||
var currentName string = ""
|
||||
|
||||
config := new(GitConfig)
|
||||
config.core = make(map[string]string)
|
||||
config.remotes = make(map[string]*remote)
|
||||
config.branches = make(map[string]*branch)
|
||||
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)
|
||||
|
||||
scanner := bufio.NewScanner(file)
|
||||
for scanner.Scan() {
|
||||
|
@ -123,12 +128,12 @@ func readGitConfig(filePath string) (*GitConfig, error) {
|
|||
|
||||
switch currentSection {
|
||||
case "core":
|
||||
config.core[key] = value
|
||||
rs.gitConfig.core[key] = value
|
||||
case "remote":
|
||||
test, ok := config.remotes[currentName]
|
||||
test, ok := rs.gitConfig.remotes[currentName]
|
||||
if !ok {
|
||||
test = new(remote)
|
||||
config.remotes[currentName] = test
|
||||
rs.gitConfig.remotes[currentName] = test
|
||||
}
|
||||
log.Log(INFO, "switch currentSection", currentSection, currentName)
|
||||
switch key {
|
||||
|
@ -154,16 +159,17 @@ func readGitConfig(filePath string) (*GitConfig, error) {
|
|||
log.Log(WARN, "error unknown remote:", currentSection, currentName, "key", key, "value", value)
|
||||
}
|
||||
case "branch":
|
||||
test, ok := config.branches[currentName]
|
||||
test, ok := rs.gitConfig.branches[currentName]
|
||||
if !ok {
|
||||
test = new(branch)
|
||||
config.branches[currentName] = test
|
||||
rs.gitConfig.branches[currentName] = test
|
||||
rs.processBranch(currentName)
|
||||
}
|
||||
switch key {
|
||||
case "remote":
|
||||
config.branches[currentName].remote = value
|
||||
rs.gitConfig.branches[currentName].remote = value
|
||||
case "merge":
|
||||
config.branches[currentName].merge = value
|
||||
rs.gitConfig.branches[currentName].merge = value
|
||||
default:
|
||||
log.Log(WARN, "error unknown remote:", currentSection, currentName, key, value)
|
||||
}
|
||||
|
@ -173,10 +179,10 @@ func readGitConfig(filePath string) (*GitConfig, error) {
|
|||
}
|
||||
|
||||
if err := scanner.Err(); err != nil {
|
||||
return nil, err
|
||||
return err
|
||||
}
|
||||
|
||||
return config, nil
|
||||
return nil
|
||||
}
|
||||
|
||||
// readGoMod reads and parses the go.sum file (TODO: do the go.mod file)
|
||||
|
@ -250,6 +256,7 @@ func ScanGoSrc() {
|
|||
}
|
||||
|
||||
func ScanGitConfig() {
|
||||
/*
|
||||
for i, path := range listGitDirectories() {
|
||||
filename := filepath.Join(path, ".git/config")
|
||||
_, err := readGitConfig(filename)
|
||||
|
@ -258,4 +265,85 @@ func ScanGitConfig() {
|
|||
log.Log(WARN, "Error reading .git/config:", err)
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
func (rs *RepoStatus) CheckGoSum() bool {
|
||||
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 {
|
||||
log.Log(WARN, " ", depname, version)
|
||||
newrs, ok := windowMap[depname]
|
||||
if ok {
|
||||
if newrs.CheckDirty() {
|
||||
log.Log(WARN, " IS DIRTY", newrs.String())
|
||||
return false
|
||||
}
|
||||
log.Log(WARN, " FOUND", newrs.String())
|
||||
/*
|
||||
for branch, _ := range rs.gitConfig.branches {
|
||||
log.Log(WARN, " ", branch)
|
||||
}
|
||||
*/
|
||||
userhash, _ := newrs.gitConfig.hashes["jcarr"]
|
||||
userversion, _ := newrs.gitConfig.versions[userhash]
|
||||
log.Log(WARN, " jcarr", userhash)
|
||||
log.Log(WARN, " jcarr", userversion)
|
||||
if version == userversion {
|
||||
log.Log(WARN, " USER VERSIONS MATCH", version, userversion)
|
||||
} else {
|
||||
log.Log(WARN, " USER VERSIONS MISMATCH", version, userversion)
|
||||
return false
|
||||
}
|
||||
} else {
|
||||
log.Log(WARN, " NOT FOUND", depname)
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
|
24
new.go
24
new.go
|
@ -3,6 +3,7 @@ package repostatus
|
|||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"go.wit.com/gui"
|
||||
"go.wit.com/lib/gadgets"
|
||||
|
@ -33,26 +34,33 @@ func NewRepoStatusWindow(path string) *RepoStatus {
|
|||
}
|
||||
|
||||
goSrcDir := filepath.Join(homeDir, "go/src")
|
||||
|
||||
realpath := filepath.Join(goSrcDir, path)
|
||||
filename := filepath.Join(realpath, ".git/config")
|
||||
gitConfig, err := readGitConfig(filename)
|
||||
|
||||
// if the .git/config file fails to load, just nil out man
|
||||
filename := filepath.Join(goSrcDir, path, ".git/config")
|
||||
|
||||
_, err = os.Open(filename)
|
||||
if err != nil {
|
||||
log.Log(WARN, "Error reading .git/config:", err)
|
||||
log.Log(WARN, "Error reading:", filename, err)
|
||||
return nil
|
||||
}
|
||||
|
||||
rs := New(gui.TreeRoot(), path)
|
||||
rs.draw(goSrcDir, realpath)
|
||||
rs.draw()
|
||||
|
||||
// save ~/go/src & the whole path strings
|
||||
rs.path.SetValue(path)
|
||||
rs.goSrcPath.SetValue(goSrcDir)
|
||||
rs.realPath.SetValue(realpath)
|
||||
|
||||
// save .git/config
|
||||
rs.gitConfig = gitConfig
|
||||
rs.readGitConfig()
|
||||
|
||||
rs.readOnly.SetValue("true")
|
||||
if strings.HasPrefix(path, "go.wit.com") {
|
||||
rs.readOnly.SetValue("false")
|
||||
}
|
||||
if strings.HasPrefix(path, "git.wit.org") {
|
||||
rs.readOnly.SetValue("false")
|
||||
}
|
||||
|
||||
windowMap[path] = rs
|
||||
|
||||
|
|
16
structs.go
16
structs.go
|
@ -10,21 +10,19 @@ type RepoStatus struct {
|
|||
hidden bool
|
||||
changed bool
|
||||
|
||||
// repopath string
|
||||
lasttagrev string
|
||||
tags map[string]string
|
||||
// lasttagrev string
|
||||
tags map[string]string
|
||||
|
||||
parent *gui.Node
|
||||
|
||||
window *gadgets.BasicWindow
|
||||
// group *gui.Node
|
||||
// grid *gui.Node
|
||||
|
||||
// status *gadgets.OneLiner
|
||||
dirtyLabel *gadgets.OneLiner
|
||||
path *gadgets.OneLiner
|
||||
goSrcPath *gadgets.OneLiner
|
||||
realPath *gadgets.OneLiner
|
||||
readOnly *gadgets.OneLiner
|
||||
|
||||
path *gadgets.OneLiner
|
||||
goSrcPath *gadgets.OneLiner
|
||||
realPath *gadgets.OneLiner
|
||||
|
||||
currentBranch *gadgets.OneLiner
|
||||
currentVersion *gadgets.OneLiner
|
||||
|
|
9
unix.go
9
unix.go
|
@ -3,6 +3,7 @@ package repostatus
|
|||
|
||||
import (
|
||||
"errors"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/exec"
|
||||
"os/user"
|
||||
|
@ -203,3 +204,11 @@ func VerifyLocalGoRepo(gorepo string) bool {
|
|||
log.Log(INFO, "go directory:", gitDir)
|
||||
return IsDirectory(gitDir)
|
||||
}
|
||||
|
||||
func readFileToString(filename string) (string, error) {
|
||||
data, err := ioutil.ReadFile(filename)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return strings.TrimSpace(string(data)), nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue