2024-12-05 14:17:50 -06:00
|
|
|
package main
|
|
|
|
|
2024-12-06 01:48:17 -06:00
|
|
|
import (
|
2025-01-18 23:25:55 -06:00
|
|
|
"fmt"
|
|
|
|
|
2025-01-05 06:14:06 -06:00
|
|
|
"go.wit.com/lib/protobuf/forgepb"
|
2024-12-06 01:48:17 -06:00
|
|
|
"go.wit.com/lib/protobuf/gitpb"
|
|
|
|
"go.wit.com/log"
|
|
|
|
)
|
2024-12-05 14:17:50 -06:00
|
|
|
|
2025-01-18 23:25:55 -06:00
|
|
|
var ErrorNotAllReposOnMaster error = fmt.Errorf("not all repos on are on the master branch")
|
|
|
|
var ErrorNotAllReposOnDevel error = fmt.Errorf("not all repos on are on the devel branch")
|
|
|
|
var ErrorNotAllReposOnUser error = fmt.Errorf("not all repos on are on the user branch")
|
|
|
|
|
|
|
|
func IsEverythingOnMaster() error {
|
|
|
|
var total int
|
|
|
|
var count int
|
|
|
|
|
|
|
|
// first make sure every repo is on the master branch
|
|
|
|
all := me.forge.Repos.All()
|
|
|
|
for all.Scan() {
|
|
|
|
repo := all.Next()
|
|
|
|
total += 1
|
|
|
|
if repo.GetMasterBranchName() == repo.GetCurrentBranchName() {
|
|
|
|
count += 1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
log.Printf("Master branch check. %d total repos. %d repos on the master branch\n", total, count)
|
|
|
|
if total != count {
|
|
|
|
// log.Info(ErrorNotAllReposOnMaster)
|
|
|
|
return ErrorNotAllReposOnMaster
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func IsEverythingOnDevel() error {
|
|
|
|
var total int
|
|
|
|
var count int
|
|
|
|
|
|
|
|
// first make sure every repo is on the master branch
|
|
|
|
all := me.forge.Repos.All()
|
2025-01-05 05:48:02 -06:00
|
|
|
for all.Scan() {
|
|
|
|
repo := all.Next()
|
2025-01-18 23:25:55 -06:00
|
|
|
total += 1
|
|
|
|
if repo.GetDevelBranchName() == repo.GetCurrentBranchName() {
|
|
|
|
count += 1
|
2025-01-05 05:48:02 -06:00
|
|
|
}
|
|
|
|
}
|
2025-01-18 23:25:55 -06:00
|
|
|
log.Printf("Devel branch check. %d total repos. %d repos on the devel branch\n", total, count)
|
|
|
|
if total != count {
|
|
|
|
return ErrorNotAllReposOnDevel
|
2025-01-05 06:14:06 -06:00
|
|
|
}
|
2025-01-18 23:25:55 -06:00
|
|
|
return nil
|
2025-01-05 06:14:06 -06:00
|
|
|
}
|
|
|
|
|
2025-01-18 23:25:55 -06:00
|
|
|
func IsEverythingOnUser() error {
|
|
|
|
var total int
|
|
|
|
var count int
|
|
|
|
|
|
|
|
// first make sure every repo is on the master branch
|
|
|
|
all := me.forge.Repos.All()
|
2025-01-05 06:14:06 -06:00
|
|
|
for all.Scan() {
|
|
|
|
repo := all.Next()
|
2025-01-18 23:25:55 -06:00
|
|
|
total += 1
|
|
|
|
if repo.GetUserBranchName() == repo.GetUserBranchName() {
|
|
|
|
count += 1
|
2025-01-05 06:14:06 -06:00
|
|
|
}
|
|
|
|
}
|
2025-01-18 23:25:55 -06:00
|
|
|
log.Printf("User branch check. %d total repos. %d repos on the user branch\n", total, count)
|
|
|
|
if total != count {
|
|
|
|
return ErrorNotAllReposOnUser
|
2025-01-05 06:14:06 -06:00
|
|
|
}
|
2025-01-18 23:25:55 -06:00
|
|
|
return nil
|
2025-01-05 05:48:02 -06:00
|
|
|
}
|
|
|
|
|
2024-12-13 17:13:07 -06:00
|
|
|
func doGitReset() {
|
2024-12-17 06:36:00 -06:00
|
|
|
all := me.found.SortByFullPath()
|
2024-12-13 17:13:07 -06:00
|
|
|
for all.Scan() {
|
|
|
|
repo := all.Next()
|
2024-12-17 06:36:00 -06:00
|
|
|
if me.forge.Config.IsReadOnly(repo.GetGoPath()) {
|
|
|
|
// log.Info("is readonly", repo.GetGoPath())
|
2024-12-13 17:13:07 -06:00
|
|
|
if repo.CheckDirty() {
|
2024-12-17 06:36:00 -06:00
|
|
|
log.Info("is readonly and dirty", repo.GetGoPath())
|
2024-12-13 17:13:07 -06:00
|
|
|
cmd := []string{"git", "reset", "--hard"}
|
|
|
|
repo.RunRealtime(cmd)
|
|
|
|
}
|
|
|
|
} else {
|
2024-12-17 06:36:00 -06:00
|
|
|
// log.Info("is not readonly", repo.GetGoPath())
|
2024-12-13 17:13:07 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-12-05 14:17:50 -06:00
|
|
|
|
2025-01-18 23:25:55 -06:00
|
|
|
/*
|
2024-12-13 16:17:36 -06:00
|
|
|
func checkoutBranches(repo *gitpb.Repo) error {
|
|
|
|
dname := repo.GetDevelBranchName()
|
|
|
|
if dname == "" {
|
|
|
|
if err := me.forge.MakeDevelBranch(repo); err != nil {
|
2024-12-17 06:36:00 -06:00
|
|
|
log.Info("verify() no devel branch name", repo.GetGoPath())
|
2024-12-13 16:17:36 -06:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
configSave = true
|
|
|
|
}
|
|
|
|
if repo.GetUserBranchName() == "" {
|
|
|
|
if err := me.forge.MakeUserBranch(repo); err != nil {
|
2024-12-17 06:36:00 -06:00
|
|
|
log.Info("verify() no devel branch name", repo.GetGoPath())
|
2024-12-13 16:17:36 -06:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
configSave = true
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
2025-01-18 23:25:55 -06:00
|
|
|
*/
|
|
|
|
|
|
|
|
func doAllCheckoutUser() error {
|
|
|
|
me.forge.CheckoutUser()
|
|
|
|
// me.forge = forgepb.Init()
|
|
|
|
count := me.forge.RillReload()
|
|
|
|
log.Info("CHECKOUT USER COUNT", count)
|
|
|
|
if count != 0 {
|
|
|
|
me.forge.ConfigSave()
|
|
|
|
}
|
|
|
|
if err := IsEverythingOnUser(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
2025-01-05 06:14:06 -06:00
|
|
|
|
2025-01-18 23:25:55 -06:00
|
|
|
func doAllCheckoutDevel() error {
|
2025-01-05 06:14:06 -06:00
|
|
|
me.forge.CheckoutDevel()
|
2025-01-18 23:25:55 -06:00
|
|
|
// me.forge = forgepb.Init()
|
|
|
|
count := me.forge.RillReload()
|
|
|
|
log.Info("CHECKOUT DEVEL COUNT", count)
|
|
|
|
if count != 0 {
|
|
|
|
me.forge.ConfigSave()
|
|
|
|
}
|
|
|
|
if err := IsEverythingOnDevel(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func rillCheckoutMaster(repo *gitpb.Repo) error {
|
|
|
|
if repo.GetUserVersion() != repo.GetDevelVersion() {
|
|
|
|
// don't switch braches if the user branch has uncommitted patches
|
|
|
|
return nil
|
2025-01-05 06:14:06 -06:00
|
|
|
}
|
2025-01-19 03:39:35 -06:00
|
|
|
if repo.GetDevelVersion() != repo.GetMasterVersion() {
|
|
|
|
// don't switch braches if the devel branch does not match master (needs merge)
|
|
|
|
return nil
|
|
|
|
}
|
2025-01-18 23:25:55 -06:00
|
|
|
if repo.GetCurrentBranchName() == repo.GetMasterBranchName() {
|
|
|
|
// repo is already on master
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
repo.CheckoutMaster()
|
|
|
|
return nil
|
2025-01-05 06:14:06 -06:00
|
|
|
}
|
|
|
|
|
2025-01-18 23:25:55 -06:00
|
|
|
// trys to figure out if there is still something to update
|
|
|
|
// todo: redo this logic as it is terrible
|
|
|
|
|
|
|
|
func doAllCheckoutMaster() error {
|
|
|
|
me.forge.RillFuncError(rillCheckoutMaster)
|
|
|
|
count := me.forge.RillReload()
|
|
|
|
if count != 0 {
|
|
|
|
me.forge.ConfigSave()
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := IsEverythingOnMaster(); err != nil {
|
|
|
|
// display all repos not on master
|
|
|
|
me.found = new(gitpb.Repos)
|
|
|
|
all := me.forge.Repos.SortByFullPath()
|
|
|
|
for all.Scan() {
|
|
|
|
repo := all.Next()
|
|
|
|
if repo.GetCurrentBranchName() != repo.GetMasterBranchName() {
|
|
|
|
me.found.AppendByGoPath(repo)
|
|
|
|
}
|
|
|
|
}
|
2025-01-08 00:51:53 -06:00
|
|
|
me.forge.PrintHumanTable(me.found)
|
2025-01-18 23:25:55 -06:00
|
|
|
log.Printf("There are %d repos that are NOT on the master branch\n", me.found.Len())
|
|
|
|
return err
|
2025-01-05 06:14:06 -06:00
|
|
|
}
|
2025-01-18 23:25:55 -06:00
|
|
|
return nil
|
2025-01-05 06:14:06 -06:00
|
|
|
}
|
2025-01-18 07:47:34 -06:00
|
|
|
|
2025-01-18 23:25:55 -06:00
|
|
|
// trys to figure out if there is still something to update
|
|
|
|
// todo: redo this logic as it is terrible
|
|
|
|
|
|
|
|
func doCheckout() error {
|
|
|
|
if argv.Checkout.User != nil {
|
|
|
|
if argv.Force {
|
|
|
|
me.forge.CheckoutUserForce()
|
|
|
|
} else {
|
|
|
|
me.forge.CheckoutUser()
|
|
|
|
}
|
|
|
|
me.forge = forgepb.Init()
|
|
|
|
me.found = new(gitpb.Repos)
|
|
|
|
argv.Checkout.User.findRepos()
|
|
|
|
me.forge.PrintHumanTable(me.found)
|
|
|
|
if err := IsEverythingOnUser(); err != nil {
|
|
|
|
badExit(err)
|
|
|
|
}
|
|
|
|
okExit("")
|
|
|
|
}
|
|
|
|
|
|
|
|
if argv.Checkout.Devel != nil {
|
|
|
|
me.forge.CheckoutDevel()
|
|
|
|
me.forge = forgepb.Init()
|
|
|
|
me.found = new(gitpb.Repos)
|
|
|
|
argv.Checkout.Devel.findRepos()
|
|
|
|
me.forge.PrintHumanTable(me.found)
|
|
|
|
okExit("")
|
|
|
|
}
|
|
|
|
|
|
|
|
if argv.Checkout.Master != nil {
|
|
|
|
doAllCheckoutMaster()
|
|
|
|
}
|
|
|
|
return nil
|
2025-01-18 07:47:34 -06:00
|
|
|
}
|