forge/doNormal.go

73 lines
1.9 KiB
Go

// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
// Use of this source code is governed by the GPL 3.0
package main
// checks that repos are in a "normal" state
import (
"time"
"go.wit.com/lib/protobuf/gitpb"
"go.wit.com/log"
)
func doNormal() bool {
doCheckDirtyAndConfigSave()
var count int
stats := me.forge.RillRepos(checkNormalRepoState)
for path, stat := range stats {
dur := stat.End.Sub(stat.Start)
if dur > 10*time.Second {
log.Infof("%-30v %s checkNormalRepoState() took a long time\n", dur, path)
}
if stat.Err == nil {
continue
}
// log.Infof("%-60s, %-60s %v %s\n", stat.Start, stat.End.String(), dur, path)
log.Infof("%-30v %s %v\n", dur, path, stat.Err)
// log.Info("got path", path, stat.Err)
count += 1
}
if count > 0 {
log.Info("Some repos are not in a 'normal' state. error count =", count)
return false
}
return true
}
// 99% of the time, the repos during development should be on your user branch.
// error out if it's not
// this checks to see if a devel and user branch exist
// this needs to run each time in case repos were added manually by the user
// this also verifies that
func checkNormalRepoState(repo *gitpb.Repo) error {
if repo.GetMasterBranchName() == "" {
me.forge.VerifyBranchNames(repo)
configSave = true
// log.Info("ABNORMAL: master branch name was blank in", repo.GetFullPath())
}
if repo.GetMasterBranchName() == "" {
return log.Errorf("master branch name blank")
}
if repo.GetDevelBranchName() == "" {
return log.Errorf("devel branch name blank")
}
if repo.GetUserBranchName() == "" {
return log.Errorf("user branch name blank")
}
if _, err := repo.MakeLocalDevelBranch(); err != nil {
return err
}
if repo.GetCurrentBranchName() != repo.GetUserBranchName() {
configSave = true
if err := repo.CheckoutUser(); err != nil {
return err
}
_, err := me.forge.ReAdd(repo)
return err
}
return nil
}