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.
|
// creates the actual widgets.
|
||||||
// it's assumed you are always passing in a box
|
// 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() {
|
if !rs.Ready() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// display the status of the git repository
|
// display the status of the git repository
|
||||||
rs.drawGitStatus(goSrcPath, realPath)
|
rs.drawGitStatus()
|
||||||
|
|
||||||
// display the git branches and options
|
// display the git branches and options
|
||||||
rs.drawGitBranches()
|
rs.drawGitBranches()
|
||||||
|
@ -107,30 +107,21 @@ func (rs *RepoStatus) drawGitBranches() {
|
||||||
log.Log(WARN, " ", name, "remote:", branch.remote, "merge", branch.merge)
|
log.Log(WARN, " ", name, "remote:", branch.remote, "merge", branch.merge)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
newgrid.NewButton("check go.sum", func() {
|
newgrid.NewButton("check go.sum", func() {
|
||||||
if rs.ReadGoMod() {
|
rs.CheckGoSum()
|
||||||
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) drawGitStatus(goSrcPath string, realPath string) {
|
func (rs *RepoStatus) drawGitStatus() {
|
||||||
rs.gitStatusGroup = rs.window.Box().NewGroup("What GO Knows It Has")
|
rs.gitStatusGroup = rs.window.Box().NewGroup("What GO Knows It Has")
|
||||||
newgrid := rs.gitStatusGroup.NewGrid("gridnuts", 2, 2)
|
newgrid := rs.gitStatusGroup.NewGrid("gridnuts", 2, 2)
|
||||||
newgrid.Margin()
|
newgrid.Margin()
|
||||||
newgrid.Pad()
|
newgrid.Pad()
|
||||||
|
|
||||||
rs.path = gadgets.NewOneLiner(newgrid, "path")
|
rs.path = gadgets.NewOneLiner(newgrid, "path")
|
||||||
rs.goSrcPath = gadgets.NewOneLiner(newgrid, goSrcPath)
|
rs.goSrcPath = gadgets.NewOneLiner(newgrid, "~/go/src")
|
||||||
rs.realPath = gadgets.NewOneLiner(newgrid, realPath)
|
rs.realPath = gadgets.NewOneLiner(newgrid, "full path")
|
||||||
rs.realPath.Hide()
|
rs.realPath.Hide()
|
||||||
rs.mainWorkingName = gadgets.NewOneLiner(newgrid, "main working branch")
|
rs.mainWorkingName = gadgets.NewOneLiner(newgrid, "main working branch")
|
||||||
rs.mainWorkingName.SetValue("???")
|
rs.mainWorkingName.SetValue("???")
|
||||||
|
@ -149,11 +140,8 @@ func (rs *RepoStatus) drawGitStatus(goSrcPath string, realPath string) {
|
||||||
rs.tagsDrop.AddText(line)
|
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.dirtyLabel = gadgets.NewOneLiner(newgrid, "dirty")
|
||||||
|
rs.readOnly = gadgets.NewOneLiner(newgrid, "read only")
|
||||||
|
|
||||||
rs.speed = gadgets.NewOneLiner(newgrid, "refresh speed =")
|
rs.speed = gadgets.NewOneLiner(newgrid, "refresh speed =")
|
||||||
rs.speedActual = gadgets.NewOneLiner(newgrid, "speed actual =")
|
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 {
|
func (rs *RepoStatus) getLastTagVersion() string {
|
||||||
out := run(rs.realPath.String(), "git", "rev-list --tags --max-count=1")
|
out := run(rs.realPath.String(), "git", "rev-list --tags --max-count=1")
|
||||||
log.Log(INFO, "getLastTagVersion()", out)
|
log.Log(INFO, "getLastTagVersion()", out)
|
||||||
rs.lasttagrev = out
|
// rs.lasttagrev = out
|
||||||
|
|
||||||
lastreal := "describe --tags " + out
|
lastreal := "describe --tags " + out
|
||||||
// out = run(r.path, "git", "describe --tags c871d5ecf051a7dc4e3a77157cdbc0a457eb9ae1")
|
// 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"
|
core map[string]string // map[origin] = "https:/git.wit.org/gui/gadgets"
|
||||||
remotes map[string]*remote // 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
|
branches map[string]*branch // map[guimaster] = origin guimaster
|
||||||
|
hashes map[string]string
|
||||||
|
versions map[string]string
|
||||||
}
|
}
|
||||||
|
|
||||||
type GoConfig 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
|
// readGitConfig reads and parses the .git/config file
|
||||||
func readGitConfig(filePath string) (*GitConfig, error) {
|
func (rs *RepoStatus) readGitConfig() error {
|
||||||
file, err := os.Open(filePath)
|
filename := filepath.Join(rs.realPath.String(), "/.git/config")
|
||||||
|
file, err := os.Open(filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil
|
||||||
}
|
}
|
||||||
defer file.Close()
|
defer file.Close()
|
||||||
|
|
||||||
var currentSection string = ""
|
var currentSection string = ""
|
||||||
var currentName string = ""
|
var currentName string = ""
|
||||||
|
|
||||||
config := new(GitConfig)
|
rs.gitConfig = new(GitConfig)
|
||||||
config.core = make(map[string]string)
|
rs.gitConfig.core = make(map[string]string)
|
||||||
config.remotes = make(map[string]*remote)
|
rs.gitConfig.remotes = make(map[string]*remote)
|
||||||
config.branches = make(map[string]*branch)
|
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)
|
scanner := bufio.NewScanner(file)
|
||||||
for scanner.Scan() {
|
for scanner.Scan() {
|
||||||
|
@ -123,12 +128,12 @@ func readGitConfig(filePath string) (*GitConfig, error) {
|
||||||
|
|
||||||
switch currentSection {
|
switch currentSection {
|
||||||
case "core":
|
case "core":
|
||||||
config.core[key] = value
|
rs.gitConfig.core[key] = value
|
||||||
case "remote":
|
case "remote":
|
||||||
test, ok := config.remotes[currentName]
|
test, ok := rs.gitConfig.remotes[currentName]
|
||||||
if !ok {
|
if !ok {
|
||||||
test = new(remote)
|
test = new(remote)
|
||||||
config.remotes[currentName] = test
|
rs.gitConfig.remotes[currentName] = test
|
||||||
}
|
}
|
||||||
log.Log(INFO, "switch currentSection", currentSection, currentName)
|
log.Log(INFO, "switch currentSection", currentSection, currentName)
|
||||||
switch key {
|
switch key {
|
||||||
|
@ -154,16 +159,17 @@ func readGitConfig(filePath string) (*GitConfig, error) {
|
||||||
log.Log(WARN, "error unknown remote:", currentSection, currentName, "key", key, "value", value)
|
log.Log(WARN, "error unknown remote:", currentSection, currentName, "key", key, "value", value)
|
||||||
}
|
}
|
||||||
case "branch":
|
case "branch":
|
||||||
test, ok := config.branches[currentName]
|
test, ok := rs.gitConfig.branches[currentName]
|
||||||
if !ok {
|
if !ok {
|
||||||
test = new(branch)
|
test = new(branch)
|
||||||
config.branches[currentName] = test
|
rs.gitConfig.branches[currentName] = test
|
||||||
|
rs.processBranch(currentName)
|
||||||
}
|
}
|
||||||
switch key {
|
switch key {
|
||||||
case "remote":
|
case "remote":
|
||||||
config.branches[currentName].remote = value
|
rs.gitConfig.branches[currentName].remote = value
|
||||||
case "merge":
|
case "merge":
|
||||||
config.branches[currentName].merge = value
|
rs.gitConfig.branches[currentName].merge = value
|
||||||
default:
|
default:
|
||||||
log.Log(WARN, "error unknown remote:", currentSection, currentName, key, value)
|
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 {
|
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)
|
// readGoMod reads and parses the go.sum file (TODO: do the go.mod file)
|
||||||
|
@ -250,6 +256,7 @@ func ScanGoSrc() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func ScanGitConfig() {
|
func ScanGitConfig() {
|
||||||
|
/*
|
||||||
for i, path := range listGitDirectories() {
|
for i, path := range listGitDirectories() {
|
||||||
filename := filepath.Join(path, ".git/config")
|
filename := filepath.Join(path, ".git/config")
|
||||||
_, err := readGitConfig(filename)
|
_, err := readGitConfig(filename)
|
||||||
|
@ -258,4 +265,85 @@ func ScanGitConfig() {
|
||||||
log.Log(WARN, "Error reading .git/config:", err)
|
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 (
|
import (
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"go.wit.com/gui"
|
"go.wit.com/gui"
|
||||||
"go.wit.com/lib/gadgets"
|
"go.wit.com/lib/gadgets"
|
||||||
|
@ -33,26 +34,33 @@ func NewRepoStatusWindow(path string) *RepoStatus {
|
||||||
}
|
}
|
||||||
|
|
||||||
goSrcDir := filepath.Join(homeDir, "go/src")
|
goSrcDir := filepath.Join(homeDir, "go/src")
|
||||||
|
|
||||||
realpath := filepath.Join(goSrcDir, path)
|
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 {
|
if err != nil {
|
||||||
log.Log(WARN, "Error reading .git/config:", err)
|
log.Log(WARN, "Error reading:", filename, err)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
rs := New(gui.TreeRoot(), path)
|
rs := New(gui.TreeRoot(), path)
|
||||||
rs.draw(goSrcDir, realpath)
|
rs.draw()
|
||||||
|
|
||||||
// save ~/go/src & the whole path strings
|
// save ~/go/src & the whole path strings
|
||||||
|
rs.path.SetValue(path)
|
||||||
rs.goSrcPath.SetValue(goSrcDir)
|
rs.goSrcPath.SetValue(goSrcDir)
|
||||||
rs.realPath.SetValue(realpath)
|
rs.realPath.SetValue(realpath)
|
||||||
|
|
||||||
// save .git/config
|
rs.readGitConfig()
|
||||||
rs.gitConfig = gitConfig
|
|
||||||
|
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
|
windowMap[path] = rs
|
||||||
|
|
||||||
|
|
|
@ -10,18 +10,16 @@ type RepoStatus struct {
|
||||||
hidden bool
|
hidden bool
|
||||||
changed bool
|
changed bool
|
||||||
|
|
||||||
// repopath string
|
// lasttagrev string
|
||||||
lasttagrev string
|
|
||||||
tags map[string]string
|
tags map[string]string
|
||||||
|
|
||||||
parent *gui.Node
|
parent *gui.Node
|
||||||
|
|
||||||
window *gadgets.BasicWindow
|
window *gadgets.BasicWindow
|
||||||
// group *gui.Node
|
|
||||||
// grid *gui.Node
|
|
||||||
|
|
||||||
// status *gadgets.OneLiner
|
|
||||||
dirtyLabel *gadgets.OneLiner
|
dirtyLabel *gadgets.OneLiner
|
||||||
|
readOnly *gadgets.OneLiner
|
||||||
|
|
||||||
path *gadgets.OneLiner
|
path *gadgets.OneLiner
|
||||||
goSrcPath *gadgets.OneLiner
|
goSrcPath *gadgets.OneLiner
|
||||||
realPath *gadgets.OneLiner
|
realPath *gadgets.OneLiner
|
||||||
|
|
9
unix.go
9
unix.go
|
@ -3,6 +3,7 @@ package repostatus
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"os/user"
|
"os/user"
|
||||||
|
@ -203,3 +204,11 @@ func VerifyLocalGoRepo(gorepo string) bool {
|
||||||
log.Log(INFO, "go directory:", gitDir)
|
log.Log(INFO, "go directory:", gitDir)
|
||||||
return IsDirectory(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