doCheckout() shared between GUI and command line

This commit is contained in:
Jeff Carr 2025-02-09 02:22:22 -06:00
parent d7d2e0ba1b
commit 5171aca31f
3 changed files with 108 additions and 38 deletions

View File

@ -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
}

View File

@ -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)

View File

@ -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
}