summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-10-04 16:19:44 -0500
committerJeff Carr <[email protected]>2025-10-04 16:19:44 -0500
commit2f925f6215c1feb8093a6c1811c85fa9a611ee91 (patch)
treead6b2f1325f6aa410ddbe4c789c630cebd3c6f68
parenta0e1da677e8c9a54064228c472292498d0fac62e (diff)
start default behavior functions
-rw-r--r--defaultBehavior.go72
-rw-r--r--doCheckout.go5
-rw-r--r--doMerge.go1
-rw-r--r--main.go20
4 files changed, 90 insertions, 8 deletions
diff --git a/defaultBehavior.go b/defaultBehavior.go
new file mode 100644
index 0000000..c215aa2
--- /dev/null
+++ b/defaultBehavior.go
@@ -0,0 +1,72 @@
+// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
+// Use of this source code is governed by the GPL 3.0
+
+package main
+
+import (
+ "go.wit.com/log"
+)
+
+func defaultBehavior() error {
+ // always run dirty first
+ me.forge.CheckDirtyQuiet()
+
+ // if no option is given to patch, list out the
+ // repos that have patches ready in them
+ found := findReposWithPatches()
+ if found.Len() == 0 {
+ log.Info("you currently have no repos with patches")
+ return log.Errorf("no repos to publish")
+ }
+ // check if any are dirty
+ for repo := range found.IterAll() {
+ if repo.CheckDirty() {
+ return log.Errorf("%s repo is dirty", repo.FullPath)
+ }
+ }
+ // check the hashes
+ for repo := range found.IterAll() {
+ if err := hashesMatch(repo); err != nil {
+ return err
+ }
+ }
+ // move them all the the master branch
+ var bad bool
+ for repo := range found.IterAll() {
+ if repo.GetCurrentBranchName() != repo.GetMasterBranchName() {
+ repo.CheckoutMaster()
+ bad = true
+ }
+ }
+ if bad {
+ return log.Errorf("some repos had to be switched to the master branch")
+ }
+ if !argv.Force {
+ return log.Errorf("notsure. it might be safe to publish(?)")
+ }
+ return nil
+}
+
+func defaultBehaviorMaster() error {
+ // always run dirty first
+ me.forge.CheckDirtyQuiet()
+
+ // if no option is given to patch, list out the
+ // repos that have patches ready in them
+ found := findReposWithPatches()
+ if found.Len() == 0 {
+ log.Info("you currently have no repos with patches")
+ return nil
+ }
+ // warn about dirty repos not in master branches
+ for repo := range found.IterAll() {
+ if repo.CheckDirty() {
+ if repo.GetCurrentBranchName() != repo.GetUserBranchName() {
+ repo.State = "DIRTY REPO NOT IN USER BRANCH"
+ }
+ // return log.Errorf("%s repo is dirty", repo.FullPath)
+ }
+ }
+ me.forge.PrintDefaultTB(found)
+ return nil
+}
diff --git a/doCheckout.go b/doCheckout.go
index c6d4798..7dffed7 100644
--- a/doCheckout.go
+++ b/doCheckout.go
@@ -21,6 +21,7 @@ func didRepoChangeDir(repo *gitpb.Repo) error {
func doCheckout() error {
if argv.Checkout.User != nil {
+ setForgeMode(forgepb.ForgeMode_USER)
start := time.Now()
err := me.forge.DoAllCheckoutUser(argv.Force)
dur := time.Since(start)
@@ -32,7 +33,7 @@ func doCheckout() error {
}
if argv.Checkout.Devel != nil {
- // setForgeMode(forgepb.ForgeMode_DEVEL)
+ setForgeMode(forgepb.ForgeMode_DEVEL)
if err := me.forge.DoAllCheckoutDevelNew(argv.Force); err != nil {
badExit(err)
}
@@ -40,7 +41,7 @@ func doCheckout() error {
}
if argv.Checkout.Master != nil {
- setForgeMode(forgepb.ForgeMode_MASTER) // disable "normal" mode if set
+ setForgeMode(forgepb.ForgeMode_MASTER)
err := me.forge.DoAllCheckoutMaster()
count := me.forge.RillReload()
diff --git a/doMerge.go b/doMerge.go
index f0f18b2..b09fd74 100644
--- a/doMerge.go
+++ b/doMerge.go
@@ -116,7 +116,6 @@ func safeToPublish() error {
repo.CheckoutMaster()
bad = true
}
- return log.Errorf("%s todo: check if repo is completely merged", repo.FullPath)
}
if bad {
return log.Errorf("some repos had to be switched to the master branch")
diff --git a/main.go b/main.go
index 7c90520..9ec860d 100644
--- a/main.go
+++ b/main.go
@@ -50,7 +50,7 @@ func main() {
me.forge = forgepb.Init() // init forge.pb
me.forge.ScanRepoDir() // looks for new dirs, checks existing repos for changes
if me.forge.Config.Mode != forgepb.ForgeMode_NORMAL {
- me.forge.Config.DumpENV()
+ me.forge.Config.DumpPB()
}
// first find the repos or gopaths to operate on
@@ -192,7 +192,10 @@ func main() {
doGui() // start making our forge GUI
debug() // sits here forever
}
- if me.forge.Config.Mode == forgepb.ForgeMode_NORMAL {
+
+ // DEFAULT BEHAVIOR CHANGES BETWEEN MODES
+ if me.forge.Config.Mode == forgepb.ForgeMode_NORMAL || me.forge.Config.Mode == forgepb.ForgeMode_USER {
+ // PROBABLY YOU ARE WRITING CODE
// got to the end with nothing to do (?)
if showWorkRepos() {
// found some repos at least
@@ -202,11 +205,18 @@ func main() {
// nothing different between user and master branch version. not common
log.Info("All of your git repositories appear to be in perfect shape")
}
- } else {
- found := findAll()
- me.forge.PrintDefaultTB(found)
okExit("")
}
+
+ if me.forge.Config.Mode == forgepb.ForgeMode_MASTER {
+ // PROBABLY YOU ARE PUBLISHING / MERGING CODE
+ defaultBehaviorMaster()
+ okExit("")
+ }
+
+ // PROBABLY A NEW USER
+ found := findAll()
+ me.forge.PrintDefaultTB(found)
okExit("")
}