make devel and user branches
This commit is contained in:
parent
4a2568fea3
commit
b715fdd11a
|
@ -1,6 +1,9 @@
|
|||
package forgepb
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"go.wit.com/lib/protobuf/gitpb"
|
||||
"go.wit.com/log"
|
||||
)
|
||||
|
||||
|
@ -48,13 +51,69 @@ func (f *Forge) CheckoutDevel() bool {
|
|||
if repo.CheckoutDevel() {
|
||||
// checkout ok
|
||||
} else {
|
||||
failed += 1
|
||||
dname := repo.GetDevelBranchName()
|
||||
if err := f.makeBranch(repo, dname); err != nil {
|
||||
log.Info(repo.GoPath, "can not make devel branch", dname)
|
||||
failed += 1
|
||||
}
|
||||
}
|
||||
}
|
||||
log.Log(FORGEPBWARN, "Ran git checkout in", count, "repos. failure count =", failed)
|
||||
return true
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
func (f *Forge) CheckoutMaster() bool {
|
||||
log.Log(FORGEPBWARN, "running git checkout master everwhere")
|
||||
var failed int = 0
|
||||
|
|
24
repoNew.go
24
repoNew.go
|
@ -74,3 +74,27 @@ func (f *Forge) VerifyBranchNames(newr *gitpb.Repo) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// todo: check the forge config
|
||||
func (f *Forge) configUserBranchName(repo *gitpb.Repo) string {
|
||||
if repo.GetUserBranchName() != "" {
|
||||
return repo.GetUserBranchName()
|
||||
}
|
||||
usr, _ := user.Current()
|
||||
uname := usr.Username
|
||||
return uname
|
||||
}
|
||||
|
||||
// todo: check the forge config
|
||||
func (f *Forge) configDevelBranchName(repo *gitpb.Repo) string {
|
||||
if repo.GetDevelBranchName() != "" {
|
||||
return repo.GetDevelBranchName()
|
||||
}
|
||||
if repo.IsBranch("guidevel") {
|
||||
return "guidevel"
|
||||
}
|
||||
if repo.IsBranch("devel") {
|
||||
return "devel"
|
||||
}
|
||||
return "devel"
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue