diff options
Diffstat (limited to 'gitConfig.go')
| -rw-r--r-- | gitConfig.go | 120 |
1 files changed, 104 insertions, 16 deletions
diff --git a/gitConfig.go b/gitConfig.go index 67e6179..cccad74 100644 --- a/gitConfig.go +++ b/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) } |
