summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-01-18 23:25:55 -0600
committerJeff Carr <[email protected]>2025-01-18 23:25:55 -0600
commit39f72d20344c5bbe05b83a13eee9c0d7b54f7e78 (patch)
treebba755911c142fb357804a006dc11183063c2b37
parentcbbd43f7b59cee14ed3c83d1da33a04cf8e73bbc (diff)
better git checkout
-rw-r--r--argv.go1
-rw-r--r--doCheckout.go188
-rw-r--r--doClean.go26
-rw-r--r--doDirty.go2
-rw-r--r--doExamine.go6
-rw-r--r--exit.go6
-rw-r--r--find.go15
-rw-r--r--main.go35
-rw-r--r--windowMain.go22
-rw-r--r--windowPatches.go2
10 files changed, 215 insertions, 88 deletions
diff --git a/argv.go b/argv.go
index 0bd593e..6856a6e 100644
--- a/argv.go
+++ b/argv.go
@@ -92,6 +92,7 @@ type FindCmd struct {
Favorites bool `arg:"--favorites" help:"your repos configured as favorites"`
Private bool `arg:"--private" help:"your private repos from your .config/forge/"`
Dirty bool `arg:"--dirty" help:"only use dirty git repos"`
+ User bool `arg:"--user" help:"show repos on the user branch"`
// ReadOnly bool `arg:"--readonly" help:"include read-only repos"`
}
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
}
diff --git a/doClean.go b/doClean.go
index 11e4b7e..bc665a6 100644
--- a/doClean.go
+++ b/doClean.go
@@ -7,18 +7,31 @@ import (
"go.wit.com/log"
)
+var ErrorReposHasLocalBranches error = fmt.Errorf("repo still has local branches")
+
func doClean() error {
+ if err := IsEverythingOnMaster(); err != nil {
+ log.Info("Not all repos are on the master branch")
+ // return err
+ }
+
all := me.forge.Repos.SortByFullPath()
for all.Scan() {
repo := all.Next()
+ if repo.GetCurrentBranchName() != repo.GetMasterBranchName() {
+ continue
+ }
if err := doCleanRepo(repo); err != nil {
- badExit(err)
+ badRepoExit(repo, err)
}
}
+ log.Info("All repos on the master branch are clean")
return nil
}
+// removes all local branches
func doCleanRepo(repo *gitpb.Repo) error {
+ var hasLocal bool
log.Info("Cleaning:", repo.GetGoPath())
if repo.GitConfig == nil {
return fmt.Errorf("GitConfig == nil")
@@ -30,6 +43,17 @@ func doCleanRepo(repo *gitpb.Repo) error {
for name, b := range repo.GitConfig.Branches {
log.Info("\tlocal branch name:", name, b.Merge, b.Remote)
+ if name == repo.GetMasterBranchName() {
+ continue
+ }
+ hasLocal = true
}
+ if hasLocal {
+ return ErrorReposHasLocalBranches
+ }
+ return nil
+}
+
+func verifyLocalBranchIsMerged(repo *gitpb.Repo, branch *gitpb.GitBranch) error {
return nil
}
diff --git a/doDirty.go b/doDirty.go
index f81d176..296d852 100644
--- a/doDirty.go
+++ b/doDirty.go
@@ -49,7 +49,7 @@ func doCheckDirtyAndConfigSave() {
*/
// this might work?
now := time.Now()
- me.forge.RillFuncError(20, 10, doCheckDirty)
+ me.forge.RillFuncError(doCheckDirty)
end := straightCheckDirty()
log.Printf("dirty check (%d dirty repos) (%d total repos) took:%s\n", end, me.found.Len(), shell.FormatDuration(time.Since(now)))
diff --git a/doExamine.go b/doExamine.go
index 8cac9d8..8a4ca75 100644
--- a/doExamine.go
+++ b/doExamine.go
@@ -12,7 +12,7 @@ import (
"go.wit.com/log"
)
-func doExamine() bool {
+func doExamine() error {
me.found = new(gitpb.Repos)
all := me.forge.Repos.SortByFullPath()
for all.Scan() {
@@ -28,7 +28,7 @@ func doExamine() bool {
}
}
if len(me.found.Repos) == 0 {
- return true
+ return nil
}
// slices.Reverse(me.found.Repos)
slices.SortFunc(me.found.Repos, func(a, b *gitpb.Repo) int {
@@ -63,7 +63,7 @@ func doExamine() bool {
me.found.AppendByGoPath(repo)
}
me.forge.PrintHumanTableDirty(me.found)
- return false
+ return nil
}
func isNormal(repo *gitpb.Repo) bool {
diff --git a/exit.go b/exit.go
index e80df8a..fac574b 100644
--- a/exit.go
+++ b/exit.go
@@ -3,6 +3,7 @@ package main
import (
"os"
+ "go.wit.com/lib/protobuf/gitpb"
"go.wit.com/log"
)
@@ -21,3 +22,8 @@ func badExit(err error) {
log.Info("forge failed: ", err, me.forge.GetGoSrc())
os.Exit(-1)
}
+
+func badRepoExit(repo *gitpb.Repo, err error) {
+ log.Printf("forge failed on %s with %v", repo.GetGoPath(), err)
+ os.Exit(-1)
+}
diff --git a/find.go b/find.go
index 905176b..2c21e85 100644
--- a/find.go
+++ b/find.go
@@ -42,6 +42,11 @@ func (f *FindCmd) findRepos() {
return
}
+ if f.User {
+ findUser()
+ return
+ }
+
findAll()
}
@@ -98,3 +103,13 @@ func findAll() {
me.found.AppendByGoPath(repo)
}
}
+
+func findUser() {
+ all := me.forge.Repos.SortByFullPath()
+ for all.Scan() {
+ repo := all.Next()
+ if repo.GetCurrentBranchName() == repo.GetUserBranchName() {
+ me.found.AppendByGoPath(repo)
+ }
+ }
+}
diff --git a/main.go b/main.go
index 395a318..53a96a7 100644
--- a/main.go
+++ b/main.go
@@ -88,37 +88,16 @@ func main() {
}
if argv.Checkout != nil {
- 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)
- 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 {
- doCheckoutMaster()
+ if err := doCheckout(); err != nil {
+ badExit(err)
}
- log.Info("make 'user' the default here?")
okExit("")
}
if argv.Clean != nil {
- doClean()
+ if err := doClean(); err != nil {
+ badExit(err)
+ }
okExit("")
}
@@ -128,7 +107,9 @@ func main() {
}
if argv.Examine != nil {
- doExamine()
+ if err := doExamine(); err != nil {
+ badExit(err)
+ }
okExit("")
}
diff --git a/windowMain.go b/windowMain.go
index c17f766..814287a 100644
--- a/windowMain.go
+++ b/windowMain.go
@@ -85,31 +85,21 @@ func globalBuildOptions(vbox *gui.Node) {
targetName := me.newBranch.String()
log.Warn("setting all branches to", targetName)
if targetName == "devel" {
- if !doAllCheckoutDevel() {
- okExit("")
+ if err := doAllCheckoutDevel(); err != nil {
+ log.Info("switching to devel branches failed")
}
return
}
if targetName == "master" {
- log.Info("Don't know how to set", targetName, "yet")
+ if err := doAllCheckoutMaster(); err != nil {
+ log.Info("switching to master branches failed")
+ }
return
}
// just assume user
- if targetName == "jcarr" {
- if doAllCheckoutUser() {
- return
- }
+ if err := doAllCheckoutUser(); err != nil {
log.Info("switching to user branches failed")
- return
}
- /*
- loop := me.repos.View.ReposSortByName()
- for loop.Scan() {
- repo := loop.Repo()
- repo.Status.CheckoutBranch(targetName)
- repo.Scan()
- }
- */
})
me.newBranch = grid.NewCombobox()
me.newBranch.AddText("master")
diff --git a/windowPatches.go b/windowPatches.go
index b137454..916ab66 100644
--- a/windowPatches.go
+++ b/windowPatches.go
@@ -104,7 +104,7 @@ func submitPatchesBox(box *gui.Node) *patchSummary {
if err != nil {
return
}
- if !IsEverythingOnDevel() {
+ if err := IsEverythingOnDevel(); err != nil {
log.Info("You can only apply patches to the devel branch")
return
}