2024-12-03 00:35:33 -06:00
|
|
|
package forgepb
|
|
|
|
|
|
|
|
import (
|
2024-12-13 16:18:03 -06:00
|
|
|
"errors"
|
|
|
|
|
|
|
|
"go.wit.com/lib/protobuf/gitpb"
|
2024-12-03 00:35:33 -06:00
|
|
|
"go.wit.com/log"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (f *Forge) GitPull() bool {
|
2024-12-06 01:50:03 -06:00
|
|
|
f.Repos.RillGitPull(5, 5)
|
|
|
|
/*
|
2024-12-03 00:35:33 -06:00
|
|
|
|
2024-12-06 01:50:03 -06:00
|
|
|
var localonly int
|
|
|
|
var badmap int
|
|
|
|
|
|
|
|
log.Log(FORGEPBWARN, "running git pull everywhere")
|
|
|
|
var failed int = 0
|
2024-12-11 19:31:37 -06:00
|
|
|
for all.Scan() {
|
|
|
|
repo := all.Next()
|
2024-12-06 01:50:03 -06:00
|
|
|
if out, err := repo.GitPull(); err == nil {
|
|
|
|
log.Log(FORGEPBWARN, "Ran git pull ok", repo.GetGoPath(), out)
|
|
|
|
} else {
|
|
|
|
failed += 1
|
|
|
|
// repo.DumpTags()
|
|
|
|
if errors.Is(repostatus.ErrorGitPullOnLocal, err) {
|
|
|
|
localonly += 1
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
badmap += 1
|
|
|
|
log.Log(FORGEPBWARN, "bad unknown git error", repo.GetGoPath(), out, err)
|
2024-12-03 00:35:33 -06:00
|
|
|
}
|
|
|
|
}
|
2024-12-06 01:50:03 -06:00
|
|
|
log.Log(FORGEPBWARN, "Ran git pull in all repos. failure count =", failed)
|
|
|
|
log.Log(FORGEPBWARN, "Ran git pull in all repos. bad errors =", badmap)
|
|
|
|
if localonly != 0 {
|
|
|
|
log.Log(FORGEPBWARN, "Ran git pull in all repos. ignored local only branches =", localonly)
|
|
|
|
}
|
|
|
|
*/
|
2024-12-03 00:35:33 -06:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *Forge) CheckoutDevel() bool {
|
|
|
|
log.Log(FORGEPBWARN, "running git checkout devel everwhere")
|
|
|
|
var failed int = 0
|
|
|
|
var count int = 0
|
2024-12-17 06:37:00 -06:00
|
|
|
all := f.Repos.SortByFullPath()
|
2024-12-11 19:31:37 -06:00
|
|
|
for all.Scan() {
|
|
|
|
repo := all.Next()
|
2024-12-03 00:35:33 -06:00
|
|
|
count += 1
|
|
|
|
if repo.CheckoutDevel() {
|
|
|
|
// checkout ok
|
|
|
|
} else {
|
2024-12-13 16:18:03 -06:00
|
|
|
dname := repo.GetDevelBranchName()
|
|
|
|
if err := f.makeBranch(repo, dname); err != nil {
|
2024-12-17 06:37:00 -06:00
|
|
|
log.Info(repo.GetGoPath(), "can not make devel branch", dname)
|
2024-12-13 16:18:03 -06:00
|
|
|
failed += 1
|
|
|
|
}
|
2024-12-03 00:35:33 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
log.Log(FORGEPBWARN, "Ran git checkout in", count, "repos. failure count =", failed)
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2024-12-13 16:18:03 -06:00
|
|
|
func (f *Forge) MakeDevelBranch(repo *gitpb.Repo) error {
|
|
|
|
dname := repo.GetDevelBranchName()
|
|
|
|
if dname == "" {
|
|
|
|
dname = f.configDevelBranchName(repo)
|
|
|
|
}
|
|
|
|
if err := f.makeBranch(repo, dname); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
repo.DevelBranchName = dname
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *Forge) MakeUserBranch(repo *gitpb.Repo) error {
|
|
|
|
uname := repo.GetUserBranchName()
|
|
|
|
if uname == "" {
|
|
|
|
uname = f.configUserBranchName(repo)
|
|
|
|
}
|
|
|
|
if err := f.makeBranch(repo, uname); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
repo.UserBranchName = uname
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *Forge) makeBranch(repo *gitpb.Repo, bname string) error {
|
|
|
|
if repo.IsLocalBranch(bname) {
|
|
|
|
// branch already exists in refs/heads/
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
if repo.IsBranch(bname) {
|
|
|
|
// branch already exists refs/remotes/
|
|
|
|
return nil
|
|
|
|
} else {
|
|
|
|
log.Info("makeBranch() says", bname, "does not exist")
|
|
|
|
loop := repo.Tags.All()
|
|
|
|
for loop.Scan() {
|
|
|
|
t := loop.Next()
|
|
|
|
log.Info("LocalTagExists() tag:", t.Refname)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mname := repo.GetMasterBranchName()
|
|
|
|
cname := repo.GetCurrentBranchName()
|
|
|
|
if mname != cname {
|
|
|
|
return errors.New("can only make branches from master branch")
|
|
|
|
}
|
|
|
|
cmd := []string{"git", "branch", bname}
|
|
|
|
if err := repo.StrictRun(cmd); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2024-12-03 00:35:33 -06:00
|
|
|
func (f *Forge) CheckoutMaster() bool {
|
|
|
|
log.Log(FORGEPBWARN, "running git checkout master everwhere")
|
|
|
|
var failed int = 0
|
|
|
|
var count int = 0
|
2024-12-17 06:37:00 -06:00
|
|
|
all := f.Repos.SortByFullPath()
|
2024-12-11 19:31:37 -06:00
|
|
|
for all.Scan() {
|
|
|
|
repo := all.Next()
|
2024-12-03 00:35:33 -06:00
|
|
|
count += 1
|
|
|
|
if repo.CheckoutMaster() {
|
|
|
|
// checkout ok
|
|
|
|
} else {
|
|
|
|
failed += 1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
log.Log(FORGEPBWARN, "Ran git checkout in", count, "repos. failure count =", failed)
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *Forge) CheckoutUser() bool {
|
2024-12-15 08:48:06 -06:00
|
|
|
log.Log(FORGEPBWARN, "running git checkout user everwhere")
|
2024-12-03 00:35:33 -06:00
|
|
|
var failed int = 0
|
|
|
|
var count int = 0
|
2024-12-17 06:37:00 -06:00
|
|
|
all := f.Repos.SortByFullPath()
|
2024-12-11 19:31:37 -06:00
|
|
|
for all.Scan() {
|
|
|
|
repo := all.Next()
|
2024-12-03 00:35:33 -06:00
|
|
|
count += 1
|
|
|
|
if repo.CheckoutUser() {
|
|
|
|
// checkout ok
|
|
|
|
} else {
|
|
|
|
failed += 1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
log.Log(FORGEPBWARN, "Ran git checkout in", count, "repos. failure count =", failed)
|
|
|
|
return true
|
|
|
|
}
|