2024-01-16 04:46:17 -06:00
|
|
|
package main
|
|
|
|
|
2024-01-18 00:58:14 -06:00
|
|
|
import (
|
2024-01-16 04:46:17 -06:00
|
|
|
"os"
|
2024-01-30 17:22:46 -06:00
|
|
|
"os/user"
|
2024-01-26 14:21:05 -06:00
|
|
|
"path/filepath"
|
2024-01-16 04:46:17 -06:00
|
|
|
|
|
|
|
"go.wit.com/log"
|
|
|
|
|
2024-01-18 05:03:04 -06:00
|
|
|
"go.wit.com/gui"
|
2024-01-18 00:58:14 -06:00
|
|
|
"go.wit.com/lib/gadgets"
|
2024-02-17 08:38:44 -06:00
|
|
|
"go.wit.com/lib/gui/repolist"
|
2024-01-18 14:46:20 -06:00
|
|
|
"go.wit.com/lib/gui/repostatus"
|
2024-01-16 04:46:17 -06:00
|
|
|
)
|
|
|
|
|
|
|
|
func doesExist(path string) bool {
|
|
|
|
if _, err := os.Stat(path); err != nil {
|
|
|
|
if os.IsNotExist(err) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2024-01-18 13:46:25 -06:00
|
|
|
// only errors on bad errors
|
|
|
|
func quickCmd(fullpath string, cmd []string) bool {
|
|
|
|
var err error
|
|
|
|
var b bool
|
|
|
|
var output string
|
|
|
|
|
2024-02-13 12:54:32 -06:00
|
|
|
// if me.autoWorkingPwd.String() != fullpath {
|
|
|
|
// me.autoWorkingPwd.SetValue(fullpath)
|
|
|
|
// }
|
2024-01-25 13:09:33 -06:00
|
|
|
|
2024-01-23 11:22:33 -06:00
|
|
|
if me.autoDryRun.Checked() {
|
2024-01-25 13:09:33 -06:00
|
|
|
log.Warn("RUN --dry-run", fullpath, cmd)
|
2024-01-18 16:21:43 -06:00
|
|
|
return false
|
2024-01-25 13:09:33 -06:00
|
|
|
} else {
|
|
|
|
log.Warn("RUN:", fullpath, cmd)
|
2024-01-18 16:21:43 -06:00
|
|
|
}
|
|
|
|
|
2024-01-18 14:46:20 -06:00
|
|
|
err, b, output = repostatus.RunCmd(fullpath, cmd)
|
2024-01-18 13:46:25 -06:00
|
|
|
if err != nil {
|
2024-01-27 14:40:17 -06:00
|
|
|
log.Warn("cmd =", cmd)
|
|
|
|
log.Warn("err =", err)
|
|
|
|
log.Warn("b =", b)
|
|
|
|
log.Warn("output =", string(output))
|
2024-01-18 13:46:25 -06:00
|
|
|
return false
|
2024-01-18 14:46:20 -06:00
|
|
|
} else if !b {
|
2024-01-18 14:21:02 -06:00
|
|
|
log.Warn("b =", b)
|
|
|
|
log.Warn("output =", string(output))
|
2024-01-18 13:46:25 -06:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
log.Warn("output = ", string(output))
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2024-02-12 15:24:35 -06:00
|
|
|
func globalBuildOptions(vbox *gui.Node) {
|
2024-01-20 17:17:48 -06:00
|
|
|
group1 := vbox.NewGroup("Global Build Options")
|
2024-02-16 17:55:53 -06:00
|
|
|
grid := group1.NewGrid("buildOptions", 0, 0)
|
2024-01-16 04:46:17 -06:00
|
|
|
|
2024-02-13 09:18:04 -06:00
|
|
|
// me.autoWorkingPwd = gadgets.NewOneLiner(grid, "working directory (pwd)")
|
2024-01-30 23:38:46 -06:00
|
|
|
me.userHomePwd = gadgets.NewOneLiner(grid, "user home")
|
2024-02-16 17:55:53 -06:00
|
|
|
grid.NextRow()
|
2024-01-30 23:38:46 -06:00
|
|
|
me.goSrcPwd = gadgets.NewOneLiner(grid, "go src home")
|
2024-02-16 17:55:53 -06:00
|
|
|
grid.NextRow()
|
2024-01-30 23:38:46 -06:00
|
|
|
|
|
|
|
usr, _ := user.Current()
|
|
|
|
homeDir, err := os.UserHomeDir()
|
|
|
|
if err != nil {
|
|
|
|
log.Warn("Error getting home directory:", err)
|
|
|
|
homeDir = "/home/autotypist"
|
|
|
|
}
|
|
|
|
me.userHomePwd.SetText(homeDir)
|
|
|
|
srcDir := filepath.Join(homeDir, "go/src")
|
|
|
|
me.goSrcPwd.SetText(srcDir)
|
|
|
|
|
2024-01-16 04:46:17 -06:00
|
|
|
// select the branch you want to test, build and develop against
|
|
|
|
// this lets you select your user branch, but, when you are happy
|
|
|
|
// you can merge everything into the devel branch and make sure it actually
|
|
|
|
// works. Then, when that is good, merge and version everything in master
|
2024-02-16 17:55:53 -06:00
|
|
|
me.setBranchB = grid.NewButton("set current branch to:", func() {
|
|
|
|
targetName := me.newBranch.String()
|
|
|
|
log.Warn("setting all branches to", targetName)
|
2024-02-22 05:24:02 -06:00
|
|
|
var count int
|
2024-02-17 08:38:44 -06:00
|
|
|
for _, repo := range repolist.AllRepos() {
|
2024-02-22 05:24:02 -06:00
|
|
|
if repo.ReadOnly() {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if targetName == repo.Status.GetCurrentBranchName() {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if repo.Status.BranchExists(targetName) {
|
|
|
|
ok := repo.Status.CheckoutBranch(targetName)
|
|
|
|
if ok {
|
|
|
|
// checkout went fine
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
log.Info("couldn't set", repo.Status.Path(), "branch to", targetName)
|
|
|
|
log.Info("but branch exists so something went wrong")
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if ! me.autoCreateBranches.Checked() {
|
|
|
|
log.Info("not auto creating branch", targetName)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
// branch doesn't exist. make it
|
|
|
|
// todo: make this branch from 'devel' branch if it exists
|
|
|
|
log.Info("should make the", targetName, "branch here!")
|
|
|
|
if me.autoCreateBranches.Checked() {
|
|
|
|
log.Info("going to make the branch!")
|
|
|
|
repo.Status.RunCmd([]string{"git", "branch", targetName})
|
|
|
|
repo.Status.RunCmd([]string{"git", "checkout", targetName})
|
|
|
|
} else {
|
|
|
|
log.Info("not auto creating branch", targetName)
|
|
|
|
}
|
2024-02-17 08:38:44 -06:00
|
|
|
repo.Scan()
|
2024-02-22 05:24:02 -06:00
|
|
|
count += 1
|
2024-01-31 00:19:21 -06:00
|
|
|
}
|
2024-02-22 05:24:02 -06:00
|
|
|
log.Info("set", count, "branches to", targetName)
|
2024-01-20 17:17:48 -06:00
|
|
|
})
|
2024-02-16 17:55:53 -06:00
|
|
|
me.newBranch = grid.NewCombobox()
|
|
|
|
me.newBranch.AddText("master")
|
|
|
|
me.newBranch.AddText("devel")
|
|
|
|
me.newBranch.AddText(usr.Username)
|
|
|
|
me.newBranch.SetText(usr.Username)
|
|
|
|
|
|
|
|
// checking this will automatically make the branches off of devel
|
|
|
|
me.autoCreateBranches = grid.NewCheckbox("create if missing").SetChecked(true)
|
|
|
|
grid.NextRow()
|
2024-01-16 04:46:17 -06:00
|
|
|
}
|
2024-02-20 10:58:58 -06:00
|
|
|
|
|
|
|
// this code isn't ready yet
|
|
|
|
/*
|
|
|
|
s.gitPullB = grid.NewButton("git pull", func() {
|
|
|
|
me.Disable()
|
|
|
|
defer me.Enable()
|
|
|
|
for _, repo := range repolist.AllRepos() {
|
|
|
|
// gitcmd := []string{"git", "fetch", "origin"}
|
2024-02-22 05:24:02 -06:00
|
|
|
itcmd := []string{"git", "pull"}
|
2024-02-20 10:58:58 -06:00
|
|
|
err, output := repo.RunCmd(gitcmd)
|
|
|
|
log.Info("output =", output)
|
|
|
|
if err == nil {
|
|
|
|
log.Info("git fetch worked", repo.Name())
|
|
|
|
} else {
|
|
|
|
log.Info("git fetch failed", repo.Name())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
gitPullB.SetText("GOOD")
|
|
|
|
// update the stats
|
|
|
|
// s.Update()
|
|
|
|
})
|
|
|
|
|
|
|
|
s.gitPushB = grid.NewButton("git push", func() {
|
|
|
|
me.Disable()
|
|
|
|
defer me.Enable()
|
|
|
|
for _, repo := range repolist.AllRepos() {
|
|
|
|
gitcmd := []string{"git", "push"}
|
|
|
|
err, output := repo.RunCmd(gitcmd)
|
|
|
|
log.Info("output =", output)
|
|
|
|
if err == nil {
|
|
|
|
log.Info("git push worked", repo.Name())
|
|
|
|
} else {
|
|
|
|
log.Info("git push failed", repo.Name())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
s.gitPushB.SetText("GOOD")
|
|
|
|
// update the stats
|
|
|
|
s.Update()
|
|
|
|
})
|
|
|
|
|
|
|
|
s.checkB = s.grid.NewButton("Check repos are working", func() {
|
|
|
|
me.Disable()
|
|
|
|
defer me.Enable()
|
|
|
|
for _, repo := range repolist.AllRepos() {
|
|
|
|
if repo.GitURL() != "" {
|
|
|
|
log.Info("repo already checked. do they match?")
|
|
|
|
log.Info("go.wit.com =", repo.GoURL())
|
|
|
|
log.Info("localurl =", repo.Path())
|
|
|
|
} else {
|
|
|
|
ok, giturl := gowit.CheckRegistered(repo)
|
|
|
|
if ok {
|
|
|
|
log.Info("is url correct?", repo.Path(), "vs", giturl)
|
|
|
|
repo.giturl = giturl
|
|
|
|
if giturl != repo.Path() {
|
|
|
|
log.Info("repo check failed", repo.String())
|
|
|
|
s.unknownOL.SetText(repo.String())
|
|
|
|
s.unknownOL.Show()
|
|
|
|
s.unknownSubmitB.Show()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
log.Info("repo check failed", repo.String())
|
|
|
|
repo.giturl = "look in .git/config"
|
|
|
|
s.unknownOL.SetText(repo.String())
|
|
|
|
s.unknownOL.Show()
|
|
|
|
s.unknownSubmitB.Show()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
s.checkB.SetText("GOOD")
|
|
|
|
})
|
|
|
|
*/
|