forgepb/repoNew.go

77 lines
1.7 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-03 00:35:33 -06:00
func (f *Forge) NewGoPathRepo(gopath string) (*gitpb.Repo, error) {
repo, err := f.Repos.NewGoPath(f.GetGoSrc(), gopath, "")
2024-11-30 12:45:07 -06:00
if err != nil {
2024-12-01 22:36:36 -06:00
return nil, err
2024-11-30 12:45:07 -06:00
}
2024-12-03 00:35:33 -06:00
f.VerifyBranchNames(repo)
repo.ParseGoSum()
return repo, nil
2024-11-30 01:31:54 -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 {
2024-12-03 01:57:31 -06:00
// todo, figure out the name from git
newr.SetMasterBranchName("master")
if newr.CheckoutMaster() {
} else {
cmd := []string{"git", "branch", "master"}
newr.Run(cmd)
}
2024-12-01 12:53:08 -06:00
}
}
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 {
2024-12-03 01:57:31 -06:00
// forcing for now. todo: warn users
newr.SetDevelBranchName("devel")
if newr.CheckoutDevel() {
} else {
cmd := []string{"git", "branch", "devel"}
newr.Run(cmd)
}
2024-12-01 12:53:08 -06:00
}
}
if newr.GetUserBranchName() == "" {
usr, _ := user.Current()
uname := usr.Username
if newr.IsBranch(uname) {
newr.SetUserBranchName(uname)
} else {
2024-12-03 01:57:31 -06:00
// forcing for now. todo: warn users
newr.SetUserBranchName(uname)
if newr.CheckoutUser() {
} else {
cmd := []string{"git", "branch", uname}
newr.Run(cmd)
}
2024-12-01 12:53:08 -06:00
}
}
}