add 'forge sync'

This commit is contained in:
Jeff Carr 2025-04-20 20:41:24 -05:00
parent 06cf0f7d84
commit 52c9fece43
4 changed files with 89 additions and 1 deletions

View File

@ -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 {
}

View File

@ -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)

73
doSync.go Normal file
View File

@ -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
}

View File

@ -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)