summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-04-20 20:41:24 -0500
committerJeff Carr <[email protected]>2025-04-20 20:41:24 -0500
commit52c9fece43e5845ed795887eab073c88d70420e0 (patch)
treebc9d8f574c74c959222a4aa6a7b0545a828ce45c
parent06cf0f7d844192eacbaeec60e3cc12c9a7968469 (diff)
add 'forge sync'v0.22.115
-rw-r--r--argv.go6
-rw-r--r--argvAutoshell.go4
-rw-r--r--doSync.go73
-rw-r--r--main.go7
4 files changed, 89 insertions, 1 deletions
diff --git a/argv.go b/argv.go
index aeae447..4551c76 100644
--- a/argv.go
+++ b/argv.go
@@ -24,6 +24,7 @@ type args struct {
List *FindCmd `arg:"subcommand:list" help:"print a table of the current repos"`
Patch *PatchCmd `arg:"subcommand:patch" help:"make patchsets"`
GitPull *FindCmd `arg:"subcommand:pull" help:"run 'git pull'"`
+ Sync *SyncCmd `arg:"subcommand:sync" help:"sync repos with upstream"`
URL string `arg:"--connect" help:"forge url"`
All bool `arg:"--all" help:"git commit --all"`
Build string `arg:"--build" help:"build a repo"`
@@ -91,6 +92,11 @@ type CheckoutCmd struct {
Master *FindCmd `arg:"subcommand:master" help:"git checkout master"`
}
+type SyncCmd struct {
+ Clean *EmptyCmd `arg:"subcommand:clean" help:"sync everything to upstream master"`
+ User *EmptyCmd `arg:"subcommand:user" help:"sync everything to user"`
+}
+
type DirtyCmd struct {
}
diff --git a/argvAutoshell.go b/argvAutoshell.go
index 3b8c98d..e9dbd9e 100644
--- a/argvAutoshell.go
+++ b/argvAutoshell.go
@@ -51,6 +51,8 @@ func (args) doBashAuto() {
fmt.Println("--force")
case "devel":
fmt.Println("--force")
+ case "sync":
+ fmt.Println("clean user --force")
case "master":
fmt.Println("")
case "verify":
@@ -58,7 +60,7 @@ func (args) doBashAuto() {
default:
if argv.BashAuto[0] == ARGNAME {
// list the subcommands here
- fmt.Println("--bash list checkout clean commit config dirty fetch patch pull")
+ fmt.Println("--bash list checkout clean commit config dirty fetch patch pull sync")
}
}
os.Exit(0)
diff --git a/doSync.go b/doSync.go
new file mode 100644
index 0000000..a6bb284
--- /dev/null
+++ b/doSync.go
@@ -0,0 +1,73 @@
+// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
+// Use of this source code is governed by the GPL 3.0
+
+package main
+
+import (
+ "fmt"
+ "time"
+
+ "go.wit.com/lib/gui/shell"
+ "go.wit.com/lib/protobuf/forgepb"
+ "go.wit.com/log"
+)
+
+// trys to figure out if there is still something to update
+
+func doSync() error {
+ if argv.Sync.Clean != nil {
+ return doSyncClean()
+ }
+ if argv.Sync.User != nil {
+ return doSyncUser()
+ }
+
+ return fmt.Errorf("nothing to do")
+}
+
+func doSyncClean() error {
+ me.argvCheckoutMaster = true
+ me.forge.Config.Mode = forgepb.ForgeMode_MASTER
+ me.forge.Config.ConfigSave()
+
+ if err := doCheckoutShared(); err != nil {
+ return err
+ }
+
+ if _, _, _, err := IsEverythingOnMaster(); err != nil {
+ log.Info("Not all repos are on the master branch")
+ return err
+ }
+
+ if err := doCleanUser(); err != nil {
+ badExit(err)
+ }
+
+ if err := doCleanDevel(); err != nil {
+ badExit(err)
+ }
+
+ now := time.Now()
+ pullcount := me.forge.RillFuncError(rillPull)
+ count := me.forge.RillReload()
+ if count != 0 {
+ me.forge.ConfigSave()
+ }
+
+ total, count, nope, _ := IsEverythingOnMaster()
+ log.Printf("Master branch check. %d total repos. (%d git pulled) (%d not on master branch) (%s) git pull total=%d\n", total, count, nope, shell.FormatDuration(time.Since(now)), pullcount)
+
+ return nil
+}
+
+func doSyncUser() error {
+ me.argvCheckoutUser = true
+ me.forge.Config.Mode = forgepb.ForgeMode_USER
+ me.forge.Config.ConfigSave()
+
+ if err := doCheckoutShared(); err != nil {
+ return err
+ }
+
+ return nil
+}
diff --git a/main.go b/main.go
index 6e63f12..2cf2ed9 100644
--- a/main.go
+++ b/main.go
@@ -91,6 +91,13 @@ func main() {
okExit("")
}
+ if argv.Sync != nil {
+ if err := doSync(); err != nil {
+ badExit(err)
+ }
+ okExit("")
+ }
+
if argv.Build != "" {
if err := doBuild(); err != nil {
badExit(err)