forge/doClean.go

60 lines
1.2 KiB
Go

package main
import (
"fmt"
"go.wit.com/lib/protobuf/gitpb"
"go.wit.com/log"
)
var ErrorReposHasLocalBranches error = fmt.Errorf("repo still has local branches")
func doClean() error {
if err := IsEverythingOnMaster(); err != nil {
log.Info("Not all repos are on the master branch")
// return err
}
all := me.forge.Repos.SortByFullPath()
for all.Scan() {
repo := all.Next()
if repo.GetCurrentBranchName() != repo.GetMasterBranchName() {
continue
}
if err := doCleanRepo(repo); err != nil {
badRepoExit(repo, err)
}
}
log.Info("All repos on the master branch are clean")
return nil
}
// removes all local branches
func doCleanRepo(repo *gitpb.Repo) error {
var hasLocal bool
log.Info("Cleaning:", repo.GetGoPath())
if repo.GitConfig == nil {
return fmt.Errorf("GitConfig == nil")
}
for _, l := range repo.GitConfig.Local {
log.Info("\tlocal branch name:", l.Name)
}
for name, b := range repo.GitConfig.Branches {
log.Info("\tlocal branch name:", name, b.Merge, b.Remote)
if name == repo.GetMasterBranchName() {
continue
}
hasLocal = true
}
if hasLocal {
return ErrorReposHasLocalBranches
}
return nil
}
func verifyLocalBranchIsMerged(repo *gitpb.Repo, branch *gitpb.GitBranch) error {
return nil
}