From 5171aca31fc459b238e8a751375d14d3b8184bc0 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sun, 9 Feb 2025 02:22:22 -0600 Subject: [PATCH] doCheckout() shared between GUI and command line --- doCheckout.go | 63 ++++++++++++++++++++++++++-------------- doGui.go | 79 ++++++++++++++++++++++++++++++++++++++++----------- structs.go | 4 +++ 3 files changed, 108 insertions(+), 38 deletions(-) diff --git a/doCheckout.go b/doCheckout.go index c77c336..0d50f22 100644 --- a/doCheckout.go +++ b/doCheckout.go @@ -250,40 +250,59 @@ func doAllCheckoutMaster() error { return nil } +// shared this with the GUI and the command line? +func doCheckoutShared() error { + if me.argvCheckoutUser { + if argv.Force { + // make the user directories + if err := makeUserBranches(); err != nil { + return err + } + return nil + } + // this uses rill and is super fast + doAllCheckoutUser() + return nil + } + + if me.argvCheckoutDevel { + if argv.Force { + // make the devel directories + if err := makeDevelBranches(); err != nil { + return err + } + return nil + } + // this uses rill and is super fast + doAllCheckoutDevel() + return nil + } + + if me.argvCheckoutMaster { + doAllCheckoutMaster() + } + return nil +} + // trys to figure out if there is still something to update // todo: redo this logic as it is terrible func doCheckout() error { if argv.Checkout.User != nil { - if argv.Force { - // make the user directories - if err := makeUserBranches(); err != nil { - badExit(err) - } - okExit("make user branches done") - } - // this uses rill and is super fast - doAllCheckoutUser() - okExit("") + me.argvCheckoutUser = true } if argv.Checkout.Devel != nil { - if argv.Force { - // make the devel directories - if err := makeDevelBranches(); err != nil { - badExit(err) - } - okExit("make devel branches done") - } - // this uses rill and is super fast - doAllCheckoutDevel() - okExit("") + me.argvCheckoutDevel = true } if argv.Checkout.Master != nil { - doAllCheckoutMaster() - okExit("") + me.argvCheckoutMaster = true } + if err := doCheckoutShared(); err != nil { + badExit(err) + } + okExit("git checkout done") return nil } diff --git a/doGui.go b/doGui.go index 4b73077..88baa94 100644 --- a/doGui.go +++ b/doGui.go @@ -112,30 +112,77 @@ func drawWindow(win *gadgets.BasicWindow) { log.Info("reposWin == nil") reposWin.Hide() } - targetName := me.newBranch.String() - log.Warn("setting all branches to", targetName) - if targetName == "devel" { - if err := doAllCheckoutDevel(); err != nil { - log.Info("switching to devel branches failed") + + if me.autoCreateBranches.Checked() { + argv.Force = true + } else { + argv.Force = false + } + if err := doCheckoutShared(); err != nil { + badExit(err) + } + /* + targetName := me.newBranch.String() + log.Warn("setting all branches to", targetName) + log.Info("auto create branches =", createBranches) + if targetName == "devel" { + now := time.Now() + if err := doAllCheckoutDevel(); err != nil { + } + total, count, nope, _ := IsEverythingOnDevel() + log.Printf("Devel branch check. %d total repos. (%d ok) (%d not on devel branch) (%s)\n", total, count, nope, shell.FormatDuration(time.Since(now))) + if nope != 0 { + log.Info("switching to devel branches failed") + log.Info("auto create branches =", createBranches) + if createBranches { + } else { + log.Info("You should enable the 'auto create branches' checkbox") + } + } + return } - return - } - if targetName == "master" { - if err := doAllCheckoutMaster(); err != nil { - log.Info("switching to master branches failed") + if targetName == "master" { + if err := doAllCheckoutMaster(); err != nil { + log.Info("switching to master branches failed") + } + return } - return - } - // just assume user - if err := doAllCheckoutUser(); err != nil { - log.Info("switching to user branches failed") - } + now := time.Now() + // just assume user + if err := doAllCheckoutUser(); err != nil { + } + total, count, nope, err := IsEverythingOnUser() + log.Printf("User branch check. %d total repos. (%d ok) (%d not on user branch) (%s)\n", total, count, nope, shell.FormatDuration(time.Since(now))) + if err != nil { + log.Info("switching to user branches failed") + log.Info("auto create branches =", createBranches) + if createBranches { + } else { + log.Info("You should enable the 'auto create branches' checkbox") + } + } + */ }) me.newBranch = grid.NewDropdown() me.newBranch.AddText("master") me.newBranch.AddText("devel") me.newBranch.AddText(usr.Username) me.newBranch.SetText(usr.Username) + me.argvCheckoutUser = true + me.newBranch.Custom = func() { + // toggle global values shared by the command line and the gui for doCheckout() + me.argvCheckoutUser = false + me.argvCheckoutDevel = false + me.argvCheckoutMaster = false + switch me.newBranch.String() { + case "master": + me.argvCheckoutMaster = true + case "devel": + me.argvCheckoutDevel = true + default: + me.argvCheckoutUser = true + } + } // checking this will automatically make the branches off of devel me.autoCreateBranches = grid.NewCheckbox("auto create branches").SetChecked(true) diff --git a/structs.go b/structs.go index 53136ee..8bfe557 100644 --- a/structs.go +++ b/structs.go @@ -72,4 +72,8 @@ type mainType struct { // the repositories to them newBranch *gui.Node setBranchB *gui.Node + + argvCheckoutUser bool // shared between the GUI and the command line tools + argvCheckoutDevel bool // shared between the GUI and the command line tools + argvCheckoutMaster bool // shared between the GUI and the command line tools }