Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-01-10 19:44:38 -06:00
parent 348f01091c
commit 0d23f7271a
3 changed files with 95 additions and 34 deletions

49
git.go
View File

@ -38,14 +38,20 @@ func (r *repo) getBranch() {
}
func (r *repo) checkDirty() bool {
if r.path == "" {
log.Warn("disable spaceholders")
r.cButton.Disable()
r.pButton.Disable()
return false
}
out := run(r.path, "git", "diff-index HEAD")
if out == "" {
r.dirtyLabel.SetText("")
r.pButton.Disable()
r.pButton.SetText("scan")
return false
} else {
r.dirtyLabel.SetText("dirty")
r.pButton.Enable()
r.pButton.SetText("scan")
return true
}
@ -83,7 +89,7 @@ func (r *repo) populateTags() {
for _, tag := range r.tags {
r.tagsDrop.AddText(tag)
}
r.tagsDrop.SetText(r.lasttag)
// r.tagsDrop.SetText(r.lasttag)
}
func (r *repo) scan() {
@ -91,9 +97,42 @@ func (r *repo) scan() {
r.getLastTagVersion()
r.getCurrentBranchName()
r.getCurrentBranchVersion()
r.checkDirty()
r.populateTags()
if r.checkDirty() {
return
}
r.checkoutBranch("master")
r.checkoutBranch("devel")
r.checkoutBranch("jcarr")
lasttag := r.lastLabel.GetText()
master := r.masterVersion.GetText()
devel := r.develVersion.GetText()
jcarr := r.jcarrVersion.GetText()
log.Warn("")
log.Warn("lasttag =", lasttag)
log.Warn("master =", master)
log.Warn("devel =", devel)
log.Warn("jcarr =", jcarr)
r.dirtyLabel.SetText("garbage")
if devel != master {
log.Warn("devel version != master version", devel, "vs", master)
r.dirtyLabel.SetText("merge")
return
}
if lasttag != master {
log.Warn("last tag rev != master version", lasttag, "vs", master)
r.dirtyLabel.SetText("merge")
return
}
if lasttag == jcarr {
log.Warn("last tag rev == jcarr version", lasttag, "vs", jcarr)
r.dirtyLabel.SetText("GOOD")
return
}
}
func checkrepos() {

43
main.go
View File

@ -43,13 +43,8 @@ type repo struct {
func main() {
myGui = gui.New().Default()
helloworld()
repoworld()
checkrepos()
for _, r := range allrepos {
r.checkoutBranch("master")
r.checkoutBranch("devel")
r.checkoutBranch("jcarr")
}
gui.Watchdog()
}
@ -70,6 +65,7 @@ func addRepo(grid *gui.Node, path string) *repo {
newRepo.cButton = grid.NewButton("status", func () {
log.Println("repo status for", newRepo.path)
newRepo.scan()
if newRepo.status == nil {
newRepo.status = repostatus.New(myGui, newRepo.path)
newRepo.status.InitWindow()
@ -80,23 +76,27 @@ func addRepo(grid *gui.Node, path string) *repo {
newRepo.status.Toggle()
})
newRepo.pButton = grid.NewButton("push", func () {
log.Println("push")
newRepo.scan()
})
if path == "" { return newRepo }
if path == "" {
newRepo.cButton.Hide()
newRepo.pButton.Hide()
return newRepo
}
allrepos = append(allrepos, newRepo)
return newRepo
}
// This creates a window
func helloworld() {
win := gadgets.NewBasicWindow(myGui, "helloworld golang wit/gui window")
func repoworld() {
win := gadgets.NewBasicWindow(myGui, "git autotypist. it types faster than you can.")
box := win.Box().NewBox("bw vbox", false)
box2 := win.Box().NewBox("bw vbox", false)
group := box.NewGroup("test")
group := box.NewGroup("go repositories (read from ~/.config/myrepolist)")
grid := group.NewGrid("test", 11, 1)
grid.NewLabel("go repo")
grid.NewLabel("")
grid.NewLabel("branch")
grid.NewLabel("last tag")
grid.NewLabel("Version")
@ -104,7 +104,7 @@ func helloworld() {
grid.NewLabel("master")
grid.NewLabel("devel")
grid.NewLabel("jcarr")
grid.NewLabel("is dirty?")
grid.NewLabel("Status")
grid.NewLabel("commit")
grid.NewLabel("push to")
@ -125,21 +125,6 @@ func helloworld() {
}
mystatus.Toggle()
})
box2.NewButton("checkout jcarr (all repos)", func () {
for _, r := range allrepos {
r.checkoutBranch("jcarr")
}
})
box2.NewButton("checkout devel (all repos)", func () {
for _, r := range allrepos {
r.checkoutBranch("devel")
}
})
box2.NewButton("checkout master (all repos)", func () {
for _, r := range allrepos {
r.checkoutBranch("master")
}
})
box2.NewButton("hello", func () {
log.Println("world")
hellosmart()
@ -151,7 +136,7 @@ func hellosmart() {
win := smartwindow.New()
win.SetParent(myGui)
win.InitWindow()
win.Title("helloworld golang wit/gui window")
win.Title("hellosmart test")
win.Vertical()
win.SetDraw(smartDraw)
win.Make()

37
unix.go
View File

@ -57,3 +57,40 @@ func listFiles(directory string) []string {
return files
}
func runCmd(path string, cmdline string) (bool, string) {
parts := strings.Split(cmdline, " ")
if len(parts) == 0 {
log.Warn("command line was empty")
return false, ""
}
if parts[0] == "" {
log.Warn("command line was empty")
return false, ""
}
thing := parts[0]
parts = parts[1:]
log.Warn("path =", path, "thing =", thing, "cmdline =", parts)
return false, ""
// Create the command
cmd := exec.Command(thing, parts...)
// Set the working directory
cmd.Dir = fullpath(path)
// Execute the command
output, err := cmd.CombinedOutput()
if err != nil {
log.Error(err)
log.Warn("output was", output)
log.Warn("cmd exited with error", err)
return false, string(output)
}
tmp := string(output)
tmp = strings.TrimSpace(tmp)
// Print the output
return true, tmp
}