From b34caae965babca30edb12c6320abb3e6df61236 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Mon, 25 Nov 2024 02:46:07 -0600 Subject: [PATCH] skip git checkout when IsReadOnly(repo) --- checkout.go | 34 +++++++++++++++++++++++++++++ main.go | 2 ++ rebuildAutotypist.go | 40 ++++++++++++++++++++++++++-------- standardMachineInit.go | 49 ++++++++++++++++++++++++++++++++++++++++++ structs.go | 11 ++++++++++ 5 files changed, 127 insertions(+), 9 deletions(-) create mode 100644 checkout.go create mode 100644 standardMachineInit.go diff --git a/checkout.go b/checkout.go new file mode 100644 index 0000000..3b18b89 --- /dev/null +++ b/checkout.go @@ -0,0 +1,34 @@ +package main + +/* + this parses the command line arguements + this enables command line options from other packages like 'gui' and 'log' +*/ + +import ( + "go.wit.com/log" +) + +// okay +func checkoutDevel() bool { + log.Info("running git checkout devel everwhere") + var failed int = 0 + var count int = 0 + loop := me.repos.View.ReposSortByName() + for loop.Scan() { + repo := loop.Repo() + count += 1 + + // don't switch branches on readonly repos + if me.forge.IsReadOnly(repo.GoPath()) { + continue + } + if repo.Status.CheckoutDevel() { + // checkout ok + } else { + failed += 1 + } + } + log.Info("Ran git checkout in", count, "repos. failure count =", failed) + return true +} diff --git a/main.go b/main.go index c4f50be..30d7730 100644 --- a/main.go +++ b/main.go @@ -18,6 +18,8 @@ var myargv argv func main() { me = new(autoType) + standardMachineInit() + log.DaemonMode(false) me.myGui = gui.New() if !myargv.GitPull { diff --git a/rebuildAutotypist.go b/rebuildAutotypist.go index 10dcaa4..beed13f 100644 --- a/rebuildAutotypist.go +++ b/rebuildAutotypist.go @@ -3,6 +3,7 @@ package main import ( "path/filepath" "strings" + "github.com/go-cmd/cmd" "go.wit.com/lib/gui/shell" @@ -16,16 +17,34 @@ import ( func attemptAutoRebuild() bool { gosrc := me.goSrcPwd.String() - if r, ok := quickCmd(gosrc, []string{"go-clone", "--recursive", "go.wit.com/apps/autotypist"}); !ok { return buildDied(r) } - if r, ok := quickCmd(gosrc, []string{"go-clone", "--recursive", "go.wit.com/toolkits/debian"}); !ok { return buildDied(r) } - if r, ok := quickCmd(gosrc, []string{"go-clone", "--recursive", "go.wit.com/toolkits/tree"}); !ok { return buildDied(r) } - if r, ok := quickCmd(gosrc, []string{"go-clone", "--recursive", "go.wit.com/toolkits/nocui"}); !ok { return buildDied(r) } - if r, ok := quickCmd(gosrc, []string{"go-clone", "--recursive", "go.wit.com/toolkits/gocui"}); !ok { return buildDied(r) } - if r, ok := quickCmd(gosrc, []string{"go-clone", "--recursive", "go.wit.com/toolkits/andlabs"}); !ok { return buildDied(r) } + if r, ok := quickCmd(gosrc, []string{"go-clone", "--recursive", "go.wit.com/apps/autotypist"}); !ok { + return buildDied(r) + } + if r, ok := quickCmd(gosrc, []string{"go-clone", "--recursive", "go.wit.com/toolkits/debian"}); !ok { + return buildDied(r) + } + if r, ok := quickCmd(gosrc, []string{"go-clone", "--recursive", "go.wit.com/toolkits/tree"}); !ok { + return buildDied(r) + } + if r, ok := quickCmd(gosrc, []string{"go-clone", "--recursive", "go.wit.com/toolkits/nocui"}); !ok { + return buildDied(r) + } + if r, ok := quickCmd(gosrc, []string{"go-clone", "--recursive", "go.wit.com/toolkits/gocui"}); !ok { + return buildDied(r) + } + if r, ok := quickCmd(gosrc, []string{"go-clone", "--recursive", "go.wit.com/toolkits/andlabs"}); !ok { + return buildDied(r) + } - if r, ok := quickCmd(filepath.Join(gosrc, "go.wit.com/toolkits/nocui/"), []string{"make"}); !ok { return buildDied(r) } - if r, ok := quickCmd(filepath.Join(gosrc, "go.wit.com/toolkits/gocui/"), []string{"make"}); !ok { return buildDied(r) } - if r, ok := quickCmd(filepath.Join(gosrc, "go.wit.com/toolkits/andlabs/"), []string{"make"}); !ok { return buildDied(r) } + if r, ok := quickCmd(filepath.Join(gosrc, "go.wit.com/toolkits/nocui/"), []string{"make"}); !ok { + return buildDied(r) + } + if r, ok := quickCmd(filepath.Join(gosrc, "go.wit.com/toolkits/gocui/"), []string{"make"}); !ok { + return buildDied(r) + } + if r, ok := quickCmd(filepath.Join(gosrc, "go.wit.com/toolkits/andlabs/"), []string{"make"}); !ok { + return buildDied(r) + } // build the protobuf files // TODO: verify the right protoc-gen-go exists @@ -33,7 +52,10 @@ func attemptAutoRebuild() bool { log.Warn("missing /usr/bin/protc-gen-go. apt install protoc-gen-go") return false } + quickCmd(filepath.Join(gosrc, "go.wit.com/lib/protobuf/forgepb/"), []string{"make"}) quickCmd(filepath.Join(gosrc, "go.wit.com/lib/protobuf/virtbuf/"), []string{"make"}) + quickCmd(filepath.Join(gosrc, "go.wit.com/lib/protobuf/zoopb/"), []string{"make"}) + quickCmd(filepath.Join(gosrc, "go.wit.com/apps/autotypist/"), []string{"make", "build"}) return true } diff --git a/standardMachineInit.go b/standardMachineInit.go new file mode 100644 index 0000000..26ca1a7 --- /dev/null +++ b/standardMachineInit.go @@ -0,0 +1,49 @@ +package main + +import ( + "os" + + "go.wit.com/lib/protobuf/forgepb" + "go.wit.com/log" +) + +// does a standard forgepb & zoopb init + +func standardMachineInit() { + var err error + // load the ~/.config/forge/ config + if err = me.forge.ConfigLoad(); err != nil { + log.Warn("forgepb.ConfigLoad() failed", err) + os.Exit(-1) + } + + me.forge.PrintTable() + + // load the ~/.config/forge/ machine file from zoopb + if err = me.machine.ConfigLoad(); err != nil { + log.Warn("zoopb.ConfigLoad() failed", err) + os.Exit(-1) + } + me.machine.InitWit() + + // list all packages from mirrors.wit.com + /* + loop := me.machine.Wit.SortByName() + for loop.Scan() { + p := loop.Package() + log.Info("package:", p.Name, p.Version, p.PkgName) + } + */ + + // use ~/go/src unless we find a go.work file in a parent directory + if me.goSrcPath, err = forgepb.FindGoSrc(); err != nil { + log.Info(err) + os.Exit(-1) + } + + // this ENV value is used by the repolist and repostatus packages + if me.goSrcPath != "" { + os.Setenv("REPO_WORK_PATH", me.goSrcPath) + + } +} diff --git a/structs.go b/structs.go index 5d6b62e..6599f48 100644 --- a/structs.go +++ b/structs.go @@ -3,6 +3,8 @@ package main import ( "go.wit.com/gui" "go.wit.com/lib/gadgets" + "go.wit.com/lib/protobuf/forgepb" + "go.wit.com/lib/protobuf/zoopb" ) var me *autoType @@ -17,6 +19,15 @@ func (b *autoType) Enable() { // this app's variables type autoType struct { + // your customized repo preferences and settings + forge forgepb.Repos + + // where your ~/go/src is + goSrcPath string + + // use zookeeper to get the list of installed packages + machine zoopb.Machine + // allrepos map[string]*repo myGui *gui.Node