diff options
Diffstat (limited to 'doCheckout.go')
| -rw-r--r-- | doCheckout.go | 188 |
1 files changed, 149 insertions, 39 deletions
diff --git a/doCheckout.go b/doCheckout.go index a314d25..4f9aeda 100644 --- a/doCheckout.go +++ b/doCheckout.go @@ -1,41 +1,76 @@ package main import ( + "fmt" + "go.wit.com/lib/protobuf/forgepb" "go.wit.com/lib/protobuf/gitpb" "go.wit.com/log" ) -func IsEverythingOnDevel() bool { - me.found = new(gitpb.Repos) - all := me.forge.Repos.SortByFullPath() +var ErrorNotAllReposOnMaster error = fmt.Errorf("not all repos on are on the master branch") +var ErrorNotAllReposOnDevel error = fmt.Errorf("not all repos on are on the devel branch") +var ErrorNotAllReposOnUser error = fmt.Errorf("not all repos on are on the user branch") + +func IsEverythingOnMaster() error { + var total int + var count int + + // first make sure every repo is on the master branch + all := me.forge.Repos.All() + for all.Scan() { + repo := all.Next() + total += 1 + if repo.GetMasterBranchName() == repo.GetCurrentBranchName() { + count += 1 + } + } + log.Printf("Master branch check. %d total repos. %d repos on the master branch\n", total, count) + if total != count { + // log.Info(ErrorNotAllReposOnMaster) + return ErrorNotAllReposOnMaster + } + return nil +} + +func IsEverythingOnDevel() error { + var total int + var count int + + // first make sure every repo is on the master branch + all := me.forge.Repos.All() for all.Scan() { repo := all.Next() - if repo.GetCurrentBranchName() != repo.GetDevelBranchName() { - // log.Info(repo.GetFullPath(), repo.GetCurrentBranchName(), repo.GetDevelBranchName()) - // add this to the list of "found" repos - me.found.AppendByGoPath(repo) + total += 1 + if repo.GetDevelBranchName() == repo.GetCurrentBranchName() { + count += 1 } } - if len(me.found.Repos) == 0 { - return true + log.Printf("Devel branch check. %d total repos. %d repos on the devel branch\n", total, count) + if total != count { + return ErrorNotAllReposOnDevel } - return false + return nil } -func IsEverythingOnUser() bool { - me.found = new(gitpb.Repos) - all := me.forge.Repos.SortByFullPath() +func IsEverythingOnUser() error { + var total int + var count int + + // first make sure every repo is on the master branch + all := me.forge.Repos.All() for all.Scan() { repo := all.Next() - if repo.GetCurrentBranchName() != repo.GetUserBranchName() { - me.found.AppendByGoPath(repo) + total += 1 + if repo.GetUserBranchName() == repo.GetUserBranchName() { + count += 1 } } - if len(me.found.Repos) == 0 { - return true + log.Printf("User branch check. %d total repos. %d repos on the user branch\n", total, count) + if total != count { + return ErrorNotAllReposOnUser } - return false + return nil } func doGitReset() { @@ -55,6 +90,7 @@ func doGitReset() { } } +/* func checkoutBranches(repo *gitpb.Repo) error { dname := repo.GetDevelBranchName() if dname == "" { @@ -73,34 +109,108 @@ func checkoutBranches(repo *gitpb.Repo) error { } return nil } +*/ + +func doAllCheckoutUser() error { + me.forge.CheckoutUser() + // me.forge = forgepb.Init() + count := me.forge.RillReload() + log.Info("CHECKOUT USER COUNT", count) + if count != 0 { + me.forge.ConfigSave() + } + if err := IsEverythingOnUser(); err != nil { + return err + } + return nil +} -func doAllCheckoutDevel() bool { +func doAllCheckoutDevel() error { me.forge.CheckoutDevel() - me.forge = forgepb.Init() - if !IsEverythingOnDevel() { - log.Info("switching to devel branch failed") - me.forge.PrintHumanTable(me.found) - badExit(nil) - return false + // me.forge = forgepb.Init() + count := me.forge.RillReload() + log.Info("CHECKOUT DEVEL COUNT", count) + if count != 0 { + me.forge.ConfigSave() + } + if err := IsEverythingOnDevel(); err != nil { + return err + } + return nil +} + +func rillCheckoutMaster(repo *gitpb.Repo) error { + if repo.GetUserVersion() != repo.GetDevelVersion() { + // don't switch braches if the user branch has uncommitted patches + return nil } - return true + if repo.GetCurrentBranchName() == repo.GetMasterBranchName() { + // repo is already on master + return nil + } + repo.CheckoutMaster() + return nil } -func doAllCheckoutUser() bool { - me.forge.CheckoutUser() - me.forge = forgepb.Init() - if !IsEverythingOnUser() { - log.Info("switching to user branch failed") +// trys to figure out if there is still something to update +// todo: redo this logic as it is terrible + +func doAllCheckoutMaster() error { + me.forge.RillFuncError(rillCheckoutMaster) + count := me.forge.RillReload() + log.Info("CHECKOUT MASTER COUNT", count) + if count != 0 { + me.forge.ConfigSave() + } + + if err := IsEverythingOnMaster(); err != nil { + // display all repos not on master + me.found = new(gitpb.Repos) + all := me.forge.Repos.SortByFullPath() + for all.Scan() { + repo := all.Next() + if repo.GetCurrentBranchName() != repo.GetMasterBranchName() { + me.found.AppendByGoPath(repo) + } + } me.forge.PrintHumanTable(me.found) - return false + log.Printf("There are %d repos that are NOT on the master branch\n", me.found.Len()) + return err } - return true + return nil } -func doCheckoutMaster() { - me.forge.CheckoutMaster() - me.forge = forgepb.Init() - me.found = new(gitpb.Repos) - argv.Checkout.Master.findRepos() - me.forge.PrintHumanTable(me.found) +// 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 { + me.forge.CheckoutUserForce() + } else { + me.forge.CheckoutUser() + } + me.forge = forgepb.Init() + me.found = new(gitpb.Repos) + argv.Checkout.User.findRepos() + me.forge.PrintHumanTable(me.found) + if err := IsEverythingOnUser(); err != nil { + badExit(err) + } + okExit("") + } + + if argv.Checkout.Devel != nil { + me.forge.CheckoutDevel() + me.forge = forgepb.Init() + me.found = new(gitpb.Repos) + argv.Checkout.Devel.findRepos() + me.forge.PrintHumanTable(me.found) + okExit("") + } + + if argv.Checkout.Master != nil { + doAllCheckoutMaster() + } + return nil } |
