diff options
Diffstat (limited to 'repoNew.go')
| -rw-r--r-- | repoNew.go | 76 |
1 files changed, 42 insertions, 34 deletions
@@ -2,7 +2,6 @@ package forgepb import ( "fmt" - "os/user" "path/filepath" "strings" @@ -44,68 +43,77 @@ func (f *Forge) ValidGoVersion(ver string) (bool, error) { return true, nil } -func (f *Forge) VerifyBranchNames(newr *gitpb.Repo) { - // log.Info("init worked for", newr.GoPath) +// this is still in flux +func (f *Forge) VerifyBranchNames(repo *gitpb.Repo) { + // log.Info("init worked for", repo.GoPath) - if newr.GetMasterBranchName() == "" { + if repo.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") + if repo.IsBranch("guimaster") { + repo.SetMasterBranchName("guimaster") + } else if repo.IsBranch("master") { + repo.SetMasterBranchName("master") + } else if repo.IsBranch("main") { + repo.SetMasterBranchName("main") } else { // todo, figure out the name from git - newr.SetMasterBranchName("master") - if newr.CheckoutMaster() { + repo.SetMasterBranchName("master") + if repo.CheckoutMaster() { } else { cmd := []string{"git", "branch", "master"} - newr.Run(cmd) + repo.Run(cmd) } } } - if newr.GetDevelBranchName() == "" { - if newr.IsBranch("guidevel") { - newr.SetDevelBranchName("guidevel") - } else if newr.IsBranch("devel") { - newr.SetDevelBranchName("devel") + if repo.GetDevelBranchName() == "" { + if repo.IsBranch("guidevel") { + repo.SetDevelBranchName("guidevel") + } else if repo.IsBranch("devel") { + repo.SetDevelBranchName("devel") } else { // forcing for now. todo: warn users - newr.SetDevelBranchName("devel") - if newr.CheckoutDevel() { + repo.SetDevelBranchName("devel") + if repo.CheckoutDevel() { } else { cmd := []string{"git", "branch", "devel"} - newr.Run(cmd) + repo.Run(cmd) } } } - if newr.GetUserBranchName() == "" { - usr, _ := user.Current() - uname := usr.Username - if newr.IsBranch(uname) { - newr.SetUserBranchName(uname) + if repo.GetUserBranchName() == "" { + uname := f.configUserBranchName(repo) + if repo.IsBranch(uname) { + repo.SetUserBranchName(uname) } else { // forcing for now. todo: warn users - newr.SetUserBranchName(uname) - if newr.CheckoutUser() { + repo.SetUserBranchName(uname) + if repo.CheckoutUser() { } else { cmd := []string{"git", "branch", uname} - newr.Run(cmd) + repo.Run(cmd) } } } } -// todo: check the forge config +// what name should be used for the user branch? func (f *Forge) configUserBranchName(repo *gitpb.Repo) string { - if repo.GetUserBranchName() != "" { - return repo.GetUserBranchName() + // look in the repo record for the username + uname := repo.GetUserBranchName() + if uname != "" { + return uname + } + + // query the the forge config for a custom User Branch Name + uname = f.Config.FindUserBranch(repo.GetGoPath()) + if uname != "" { + return uname } - usr, _ := user.Current() - uname := usr.Username + + // use the os.Username + uname = f.Config.Username return uname } |
