2024-01-09 15:34:53 -06:00
|
|
|
package repostatus
|
|
|
|
|
2024-01-18 00:57:43 -06:00
|
|
|
import (
|
2024-01-23 10:52:17 -06:00
|
|
|
"os"
|
|
|
|
"path/filepath"
|
2024-01-23 22:47:39 -06:00
|
|
|
"strings"
|
2024-01-23 10:52:17 -06:00
|
|
|
|
2024-01-18 00:57:43 -06:00
|
|
|
"go.wit.com/lib/gadgets"
|
|
|
|
"go.wit.com/log"
|
2024-01-09 15:34:53 -06:00
|
|
|
)
|
|
|
|
|
2024-01-21 03:18:07 -06:00
|
|
|
var windowMap map[string]*RepoStatus
|
|
|
|
|
2024-02-15 22:50:50 -06:00
|
|
|
func init() {
|
|
|
|
windowMap = make(map[string]*RepoStatus)
|
|
|
|
}
|
|
|
|
|
2024-01-21 03:18:07 -06:00
|
|
|
func ListAll() {
|
|
|
|
for path, rs := range windowMap {
|
|
|
|
log.Warn(rs.GetMasterVersion(), path)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-14 15:18:39 -06:00
|
|
|
// returns the object for the path
|
|
|
|
func FindPath(path string) *RepoStatus {
|
|
|
|
if windowMap[path] == nil {
|
|
|
|
log.Log(INFO, "FindPath() not initialized yet", path)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return windowMap[path]
|
|
|
|
}
|
|
|
|
|
2024-01-21 03:18:07 -06:00
|
|
|
func NewRepoStatusWindow(path string) *RepoStatus {
|
|
|
|
if windowMap[path] == nil {
|
2024-01-23 10:52:17 -06:00
|
|
|
log.Log(INFO, "NewRepoStatusWindow() adding new", path)
|
2024-01-21 03:18:07 -06:00
|
|
|
} else {
|
|
|
|
log.Warn("This already exists yet for path", path)
|
|
|
|
log.Warn("should return windowMap[path] here")
|
2024-01-23 10:52:17 -06:00
|
|
|
return windowMap[path]
|
|
|
|
}
|
|
|
|
|
2024-02-15 22:50:50 -06:00
|
|
|
var realpath string
|
|
|
|
|
2024-01-23 10:52:17 -06:00
|
|
|
homeDir, err := os.UserHomeDir()
|
|
|
|
if err != nil {
|
|
|
|
log.Log(WARN, "Error getting home directory:", err)
|
|
|
|
return nil
|
2024-01-21 03:18:07 -06:00
|
|
|
}
|
2024-01-23 10:52:17 -06:00
|
|
|
goSrcDir := filepath.Join(homeDir, "go/src")
|
|
|
|
|
2024-02-15 22:50:50 -06:00
|
|
|
// allow arbitrary paths, otherwise, assume the repo is in ~/go/src
|
|
|
|
if strings.HasPrefix(path, "/") {
|
|
|
|
realpath = path
|
|
|
|
} else if strings.HasPrefix(path, "~") {
|
|
|
|
// TODO: example this to homedir
|
|
|
|
tmp := strings.TrimPrefix(path, "~")
|
|
|
|
realpath = filepath.Join(homeDir, tmp)
|
|
|
|
} else {
|
|
|
|
realpath = filepath.Join(goSrcDir, path)
|
|
|
|
}
|
|
|
|
|
|
|
|
filename := filepath.Join(realpath, ".git/config")
|
2024-01-23 22:47:39 -06:00
|
|
|
|
|
|
|
_, err = os.Open(filename)
|
2024-01-23 10:52:17 -06:00
|
|
|
if err != nil {
|
2024-01-25 02:23:56 -06:00
|
|
|
log.Log(WARN, "Error reading .git/config:", filename, err)
|
|
|
|
log.Log(WARN, "TODO: find .git/config in parent directory")
|
|
|
|
// return nil
|
2024-01-23 10:52:17 -06:00
|
|
|
}
|
|
|
|
|
2024-02-14 02:35:47 -06:00
|
|
|
rs := &RepoStatus{
|
2024-02-14 15:18:39 -06:00
|
|
|
ready: false,
|
2024-02-14 02:35:47 -06:00
|
|
|
}
|
|
|
|
rs.tags = make(map[string]string)
|
|
|
|
rs.window = gadgets.RawBasicWindow("GO Repo Details " + path)
|
|
|
|
rs.window.Horizontal()
|
|
|
|
rs.window.Make()
|
2024-02-15 22:50:50 -06:00
|
|
|
basebox := rs.window.Box()
|
|
|
|
group := basebox.NewGroup("stuff")
|
|
|
|
primarybox := group.Box()
|
|
|
|
primarybox.Horizontal()
|
|
|
|
box2 := group.Box()
|
2024-02-14 02:35:47 -06:00
|
|
|
rs.ready = true
|
|
|
|
rs.window.Custom = func() {
|
|
|
|
rs.Hide()
|
|
|
|
log.Warn("repostatus user closed the window()")
|
|
|
|
}
|
2024-02-15 22:50:50 -06:00
|
|
|
|
|
|
|
// display the status of the git repository
|
|
|
|
rs.drawGitStatus(primarybox)
|
|
|
|
|
|
|
|
// display the git branches and options
|
|
|
|
rs.makeBranchesBox(primarybox)
|
|
|
|
|
|
|
|
// show standard git commit and merge controls
|
|
|
|
rs.drawGitCommands(primarybox)
|
2024-01-23 10:52:17 -06:00
|
|
|
|
|
|
|
// save ~/go/src & the whole path strings
|
2024-01-23 22:47:39 -06:00
|
|
|
rs.path.SetValue(path)
|
2024-01-23 10:52:17 -06:00
|
|
|
rs.goSrcPath.SetValue(goSrcDir)
|
|
|
|
rs.realPath.SetValue(realpath)
|
|
|
|
|
2024-02-15 22:50:50 -06:00
|
|
|
// add all the tags
|
|
|
|
rs.makeTagBox(box2)
|
|
|
|
|
2024-01-23 22:47:39 -06:00
|
|
|
rs.readGitConfig()
|
|
|
|
|
|
|
|
rs.readOnly.SetValue("true")
|
2024-02-14 02:35:47 -06:00
|
|
|
// ignore everything else for now
|
2024-01-23 22:47:39 -06:00
|
|
|
if strings.HasPrefix(path, "go.wit.com") {
|
|
|
|
rs.readOnly.SetValue("false")
|
|
|
|
}
|
|
|
|
if strings.HasPrefix(path, "git.wit.org") {
|
|
|
|
rs.readOnly.SetValue("false")
|
|
|
|
}
|
2024-01-23 10:52:17 -06:00
|
|
|
|
2024-01-21 03:18:07 -06:00
|
|
|
windowMap[path] = rs
|
2024-01-11 15:56:50 -06:00
|
|
|
return rs
|
2024-01-09 15:34:53 -06:00
|
|
|
}
|