forgepb/repoNew.go

88 lines
2.0 KiB
Go
Raw Normal View History

2024-11-30 01:31:54 -06:00
package forgepb
2024-11-30 12:45:07 -06:00
import (
"os/user"
"go.wit.com/lib/protobuf/gitpb"
)
2024-11-30 01:31:54 -06:00
2024-12-01 22:36:36 -06:00
/*
2024-11-30 01:31:54 -06:00
func (f *Forge) NewGoPath(gopath string) (*gitpb.Repo, error) {
2024-11-30 12:45:07 -06:00
newr, err := f.Repos.NewGoPath(f.goSrc, gopath)
if err != nil {
log.Log(FORGEPBWARN, "init failed", err)
2024-12-01 22:36:36 -06:00
return nil, err
2024-11-30 12:45:07 -06:00
}
log.Info("init worked for", newr.GoPath)
// try to guess what the 'master' branch is
if newr.IsBranch("guimaster") {
newr.SetMasterBranchName("guimaster")
} else if newr.IsBranch("master") {
newr.SetMasterBranchName("master")
} else if newr.IsBranch("main") {
newr.SetMasterBranchName("main")
} else {
newr.SetMasterBranchName("masterFIXME")
}
if newr.IsBranch("guidevel") {
newr.SetDevelBranchName("guidevel")
} else if newr.IsBranch("devel") {
newr.SetDevelBranchName("devel")
} else {
newr.SetDevelBranchName("develFIXME")
}
usr, _ := user.Current()
uname := usr.Username
if newr.IsBranch(uname) {
newr.SetUserBranchName(uname)
} else {
newr.SetUserBranchName(uname + "FIXME")
}
2024-12-01 10:44:29 -06:00
f.Repos.ConfigSave()
2024-12-01 22:36:36 -06:00
return newr, err
2024-11-30 01:31:54 -06:00
}
2024-12-01 22:36:36 -06:00
*/
2024-12-01 12:53:08 -06:00
func (f *Forge) VerifyBranchNames(newr *gitpb.Repo) {
// log.Info("init worked for", newr.GoPath)
if newr.GetMasterBranchName() == "" {
// try to guess what the 'master' branch is
if newr.IsBranch("guimaster") {
newr.SetMasterBranchName("guimaster")
} else if newr.IsBranch("master") {
newr.SetMasterBranchName("master")
} else if newr.IsBranch("main") {
newr.SetMasterBranchName("main")
} else {
newr.SetMasterBranchName("masterFIXME")
}
}
if f.IsReadOnly(newr.GoPath) {
return
}
if newr.GetDevelBranchName() == "" {
if newr.IsBranch("guidevel") {
newr.SetDevelBranchName("guidevel")
} else if newr.IsBranch("devel") {
newr.SetDevelBranchName("devel")
} else {
newr.SetDevelBranchName("develFIXME")
}
}
if newr.GetUserBranchName() == "" {
usr, _ := user.Current()
uname := usr.Username
if newr.IsBranch(uname) {
newr.SetUserBranchName(uname)
} else {
newr.SetUserBranchName(uname + "FIXME")
}
}
}