summaryrefslogtreecommitdiff
path: root/doCheckout.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-01-08 05:47:33 -0600
committerJeff Carr <[email protected]>2025-01-08 05:47:33 -0600
commite27e1716d77f4d4f09d89285707895724e7a3838 (patch)
tree9f1335c970c8c2fa049308427194520ec50218c7 /doCheckout.go
parent9d97b946168f7b285c9b725c93f1ef69b73ef785 (diff)
better filenames
Diffstat (limited to 'doCheckout.go')
-rw-r--r--doCheckout.go148
1 files changed, 148 insertions, 0 deletions
diff --git a/doCheckout.go b/doCheckout.go
new file mode 100644
index 0000000..eb48c04
--- /dev/null
+++ b/doCheckout.go
@@ -0,0 +1,148 @@
+package main
+
+import (
+ "time"
+
+ "go.wit.com/lib/gui/shell"
+ "go.wit.com/lib/protobuf/forgepb"
+ "go.wit.com/lib/protobuf/gitpb"
+ "go.wit.com/log"
+)
+
+func doGitPull() {
+ allerr := me.found.RillGitPull(40, 5)
+
+ all := me.found.SortByFullPath()
+ for all.Scan() {
+ repo := all.Next()
+ result := allerr[repo]
+ if result.Error == gitpb.ErrorGitPullOnDirty {
+ log.Info("skip git pull. repo is dirty", repo.GetGoPath())
+ continue
+ }
+ if result.Error == gitpb.ErrorGitPullOnLocal {
+ log.Info("skip git pull. local branch ", repo.GetGoPath())
+ continue
+ }
+ if result.Exit == 0 {
+ continue
+ }
+
+ log.Info("git pull error:", repo.GetGoPath(), result.Error)
+ log.Info("git pull error:", repo.GetGoPath(), result.Stdout)
+ }
+
+}
+
+func doCheckDirtyAndConfigSave() {
+ var count int
+ now := time.Now()
+ all := me.found.SortByFullPath()
+ for all.Scan() {
+ repo := all.Next()
+ dirty := repo.IsDirty()
+ if repo.CheckDirty() {
+ count += 1
+ me.found.AppendUniqueGoPath(repo)
+ if !dirty {
+ configSave = true
+ }
+ } else {
+ if dirty {
+ configSave = true
+ }
+ }
+ }
+ log.Printf("dirty check %d took:%s\n", count, shell.FormatDuration(time.Since(now)))
+ me.forge.SetConfigSave(configSave)
+}
+
+func IsEverythingOnDevel() bool {
+ me.found = new(gitpb.Repos)
+ all := me.forge.Repos.SortByFullPath()
+ for all.Scan() {
+ repo := all.Next()
+ if repo.GetCurrentBranchName() != repo.GetDevelBranchName() {
+ // log.Info(repo.GetFullPath(), repo.GetCurrentBranchName(), repo.GetDevelBranchName())
+ me.found.AppendUniqueGoPath(repo)
+ }
+ }
+ if len(me.found.Repos) == 0 {
+ return true
+ }
+ return false
+}
+
+func IsEverythingOnUser() bool {
+ me.found = new(gitpb.Repos)
+ all := me.forge.Repos.SortByFullPath()
+ for all.Scan() {
+ repo := all.Next()
+ if repo.GetCurrentBranchName() != repo.GetUserBranchName() {
+ me.found.AppendUniqueGoPath(repo)
+ }
+ }
+ if len(me.found.Repos) == 0 {
+ return true
+ }
+ return false
+}
+
+func doGitReset() {
+ all := me.found.SortByFullPath()
+ for all.Scan() {
+ repo := all.Next()
+ if me.forge.Config.IsReadOnly(repo.GetGoPath()) {
+ // log.Info("is readonly", repo.GetGoPath())
+ if repo.CheckDirty() {
+ log.Info("is readonly and dirty", repo.GetGoPath())
+ cmd := []string{"git", "reset", "--hard"}
+ repo.RunRealtime(cmd)
+ }
+ } else {
+ // log.Info("is not readonly", repo.GetGoPath())
+ }
+ }
+}
+
+func checkoutBranches(repo *gitpb.Repo) error {
+ dname := repo.GetDevelBranchName()
+ if dname == "" {
+ if err := me.forge.MakeDevelBranch(repo); err != nil {
+ log.Info("verify() no devel branch name", repo.GetGoPath())
+ return err
+ }
+ configSave = true
+ }
+ if repo.GetUserBranchName() == "" {
+ if err := me.forge.MakeUserBranch(repo); err != nil {
+ log.Info("verify() no devel branch name", repo.GetGoPath())
+ return err
+ }
+ configSave = true
+ }
+ return nil
+}
+
+func doAllCheckoutDevel() bool {
+ 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
+ }
+ return true
+}
+
+func doAllCheckoutUser() bool {
+ me.forge.CheckoutUser()
+ me.forge = forgepb.Init()
+ if !IsEverythingOnUser() {
+ log.Info("switching to user branch failed")
+ me.forge.PrintHumanTable(me.found)
+ return false
+ }
+ return true
+}