diff --git a/globalBuildOptions.go b/globalBuildOptions.go index 5658b02..3d89174 100644 --- a/globalBuildOptions.go +++ b/globalBuildOptions.go @@ -10,51 +10,8 @@ import ( "go.wit.com/gui" "go.wit.com/lib/gadgets" "go.wit.com/lib/gui/repolist" - "go.wit.com/lib/gui/repostatus" ) -func doesExist(path string) bool { - if _, err := os.Stat(path); err != nil { - if os.IsNotExist(err) { - return false - } - } - return true -} - -// only errors on bad errors -func quickCmd(fullpath string, cmd []string) bool { - var err error - var b bool - var output string - - // if me.autoWorkingPwd.String() != fullpath { - // me.autoWorkingPwd.SetValue(fullpath) - // } - - if me.autoDryRun.Checked() { - log.Warn("RUN --dry-run", fullpath, cmd) - return false - } else { - log.Warn("RUN:", fullpath, cmd) - } - - err, b, output = repostatus.RunCmd(fullpath, cmd) - if err != nil { - log.Warn("cmd =", cmd) - log.Warn("err =", err) - log.Warn("b =", b) - log.Warn("output =", string(output)) - return false - } else if !b { - log.Warn("b =", b) - log.Warn("output =", string(output)) - return true - } - log.Warn("output = ", string(output)) - return true -} - func globalBuildOptions(vbox *gui.Node) { group1 := vbox.NewGroup("Global Build Options") grid := group1.NewGrid("buildOptions", 0, 0) @@ -80,10 +37,17 @@ func globalBuildOptions(vbox *gui.Node) { // checking this will automatically make the branches off of devel grid.NextRow() me.autoCreateBranches = grid.NewCheckbox("create if missing").SetChecked(true) + me.autoCreateBranches.Custom = func() { + if me.autoCreateBranches.Checked() { + os.Setenv("AUTOTYPIST_CREATE_BRANCHES", "on") + } else { + os.Unsetenv("AUTOTYPIST_CREATE_BRANCHES") + } + } grid.NextRow() grid.NewButton("git checkout default", func() { - me.repos.View.ArgCheckoutUser() + me.repos.View.ArgCheckoutMaster() }) grid.NewLabel("master,main,etc.") // set the order of these in the config file grid.NextRow() @@ -99,58 +63,76 @@ func globalBuildOptions(vbox *gui.Node) { }) grid.NewLabel(usr.Username) grid.NextRow() - // select the branch you want to test, build and develop against + + // select the branches you want to test, build and develop against + // let's call this the 'mode' ? // 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 - me.setBranchB = grid.NewButton("set current branch to:", func() { - targetName := me.newBranch.String() - log.Warn("setting all branches to", targetName) - var count int - for _, repo := range repolist.AllRepos() { - 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 + grid.NewButton("set working mode:", func() { + me.Disable() + targetMode := me.newMode.String() + log.Warn("setting all branches to", targetMode) + if me.autoCreateBranches.Checked() { + os.Setenv("AUTOTYPIST_CREATE_BRANCHES", "on") + } else { + os.Unsetenv("AUTOTYPIST_CREATE_BRANCHES") + } + switch me.newMode.String() { + case "master": + me.repos.View.ArgCheckoutMaster() + case "devel": + me.repos.View.ArgCheckoutDevel() + case "user": + me.repos.View.ArgCheckoutUser() + } + me.Enable() + /* + var count int + for _, repo := range repolist.AllRepos() { + if repo.ReadOnly() { continue } - log.Info("couldn't set", repo.Status.Path(), "branch to", targetName) - log.Info("but branch exists so something went wrong") - 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) + } + repo.Scan() + count += 1 } - 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) - } - repo.Scan() - count += 1 - } - log.Info("set", count, "branches to", targetName) + */ }) - me.newBranch = grid.NewDropdown() - me.newBranch.AddText("master") - me.newBranch.AddText("devel") - me.newBranch.AddText(usr.Username) - me.newBranch.SetText(usr.Username) + me.newMode = grid.NewDropdown() + me.newMode.AddText("git default") + me.newMode.AddText("devel") + me.newMode.AddText("user") + me.newMode.SetText("user") grid.NextRow() - me.setBranchB = grid.NewButton("git fetch master & devel", func() { + grid.NewButton("git fetch master & devel", func() { me.Disable() defer me.Enable() log.Warn("updating all master branches") diff --git a/globalDisplayOptions.go b/globalDisplayOptions.go index 6fa4021..83a69d9 100644 --- a/globalDisplayOptions.go +++ b/globalDisplayOptions.go @@ -1,48 +1,15 @@ package main import ( + "os" + "go.wit.com/gui" "go.wit.com/lib/debugger" "go.wit.com/lib/gui/gowit" "go.wit.com/lib/gui/logsettings" - "go.wit.com/lib/gui/repolist" "go.wit.com/log" ) -func hideFunction(r *repolist.RepoRow) { - if r.Status.IsDirty() { - r.Show() - return - } - if me.autoHideReadOnly.Checked() { - if r.Status.ReadOnly() { - r.Hide() - return - } - } - if me.autoHidePerfect.Checked() { - if r.IsPerfect() { - r.Hide() - return - } - } - r.Show() -} - -func hideFunction2(repo *repolist.RepoRow) { - if me.autoHideReadOnly.Checked() { - if repo.Status.ReadOnly() { - return - } - } - if me.autoHidePerfect.Checked() { - if repo.IsPerfect() { - return - } - } - repo.Show() -} - func globalDisplayOptions(vbox *gui.Node) { group1 := vbox.NewGroup("Global Display Options") @@ -57,20 +24,31 @@ func globalDisplayOptions(vbox *gui.Node) { me.autoHideReadOnly = group1.NewCheckbox("Hide read-only repos").SetChecked(true) me.autoHideReadOnly.Custom = func() { - me.repos.View.RegisterHideFunction(hideFunction) - me.repos.View.ScanRepositories() + if me.autoHideReadOnly.Checked() { + os.Setenv("AUTOTYPIST_READONLY", "hide") + } else { + os.Unsetenv("AUTOTYPIST_READONLY") + } } me.autoHidePerfect = group1.NewCheckbox("Hide Perfectly clean repos").SetChecked(true) me.autoHidePerfect.Custom = func() { - me.repos.View.RegisterHideFunction(hideFunction) - me.repos.View.ScanRepositories() + if me.autoHideReadOnly.Checked() { + os.Setenv("AUTOTYPIST_CLEAN", "hide") + } else { + os.Unsetenv("AUTOTYPIST_CLEAN") + } } scanbox := group1.Box().Horizontal() me.autoScanReposCB = scanbox.NewCheckbox("auto scan").SetChecked(true) me.autoScanReposCB.Custom = func() { - me.repos.View.SetAutoScan(me.autoScanReposCB.Checked()) + if me.autoScanReposCB.Checked() { + os.Setenv("REPO_AUTO_SCAN", "true") + } else { + os.Unsetenv("REPO_AUTO_SCAN") + } } + os.Setenv("REPO_AUTO_SCAN", "true") scanbox.NewButton("scan now", func() { log.Info("re-scanning repos now") i, s := me.repos.View.ScanRepositories() @@ -111,15 +89,3 @@ func debuggerBox(vbox *gui.Node) { debugger.DebugWindow() }) } - -func hidePerfect() { - for _, repo := range repolist.AllRepos() { - if repo.IsPerfect() { - if repo.Hidden() { - continue - } - repo.Hide() - // return - } - } -} diff --git a/hideFunction.go b/hideFunction.go new file mode 100644 index 0000000..9115026 --- /dev/null +++ b/hideFunction.go @@ -0,0 +1,47 @@ +package main + +import ( + "os" + + "go.wit.com/lib/gui/repolist" +) + +// like tcl/tk, use ENV variables to set display preferences +func hideFunction(r *repolist.RepoRow) { + // always show dirty repos + if r.Status.IsDirty() { + r.Show() + return + } + + // hide read-only repos + if os.Getenv("AUTOTYPIST_READONLY") == "hide" { + if r.Status.ReadOnly() { + r.Hide() + return + } + } + + // show repos with mismatched mode + // this means, if you are in "devel" mode, show all the repos that + // might be stuck on the wrong branch, like 'master' or '' + if os.Getenv("AUTOTYPIST_MODE") != "" { + if !r.Status.IsCorrectMode(os.Getenv("AUTOTYPIST_MODE")) { + r.Show() + return + } + } + + // hide perfectly clean repos + if os.Getenv("AUTOTYPIST_CLEAN") == "hide" { + if r.IsPerfect() { + r.Hide() + return + } + } + + // show everything else. often this will be "unconforming" repos + // if you what those repos ignored, add these to the config file + // as read-only=true + r.Show() +} diff --git a/main.go b/main.go index ff5ad7c..d660ce3 100644 --- a/main.go +++ b/main.go @@ -52,7 +52,6 @@ func main() { // setup the autoscan functions me.repos.View.RegisterHideFunction(hideFunction) - me.repos.View.SetAutoScan(me.autoScanReposCB.Checked()) // processing is done. update the repo summary box // me.summary.Update() diff --git a/shell.go b/shell.go new file mode 100644 index 0000000..3d0b211 --- /dev/null +++ b/shell.go @@ -0,0 +1,40 @@ +package main + +import ( + "go.wit.com/log" + + "go.wit.com/lib/gui/repostatus" +) + +// only errors on bad errors +func quickCmd(fullpath string, cmd []string) bool { + var err error + var b bool + var output string + + // if me.autoWorkingPwd.String() != fullpath { + // me.autoWorkingPwd.SetValue(fullpath) + // } + + if me.autoDryRun.Checked() { + log.Warn("RUN --dry-run", fullpath, cmd) + return false + } else { + log.Warn("RUN:", fullpath, cmd) + } + + err, b, output = repostatus.RunCmd(fullpath, cmd) + if err != nil { + log.Warn("cmd =", cmd) + log.Warn("err =", err) + log.Warn("b =", b) + log.Warn("output =", string(output)) + return false + } else if !b { + log.Warn("b =", b) + log.Warn("output =", string(output)) + return true + } + log.Warn("output = ", string(output)) + return true +} diff --git a/structs.go b/structs.go index 227f88b..5d6b62e 100644 --- a/structs.go +++ b/structs.go @@ -77,8 +77,7 @@ type autoType struct { // when switch to user or devel branches, autocreate them autoCreateBranches *gui.Node - // these hold the branches that the user can switch all - // the repositories to them - newBranch *gui.Node - setBranchB *gui.Node + // make a concept called a 'mode' that means which branches + // are you working from: "master"? "devel"? ? + newMode *gui.Node }