diff --git a/Makefile b/Makefile index 3e3f646..f9613a9 100644 --- a/Makefile +++ b/Makefile @@ -24,6 +24,7 @@ redomod: rm -f go.* GO111MODULE= go mod init GO111MODULE= go mod tidy + go mod edit -go=1.20 clean: rm -f *.pb.go diff --git a/scanGoSrc.go b/scanGoSrc.go index 312c77c..e0fba71 100644 --- a/scanGoSrc.go +++ b/scanGoSrc.go @@ -2,6 +2,7 @@ package forgepb import ( "os" + "os/user" "path/filepath" "strings" @@ -26,7 +27,31 @@ func (f *Forge) ScanGoSrc() (bool, error) { } 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") + } } else { log.Log(FORGEPBWARN, "ScanGoSrc() bad:", dir) } @@ -57,6 +82,16 @@ func gitDirectories(srcDir string) ([]string, error) { return all, err } +// IsGitDir checks if a .git directory exists inside the given directory +func IsGitDir(dir string) bool { + gitDir := filepath.Join(dir, ".git") + info, err := os.Stat(gitDir) + if os.IsNotExist(err) { + return false + } + return info.IsDir() +} + /* // rill is awesome. long live rill func rillAddDirs(gopaths []string) { @@ -81,61 +116,3 @@ func rillAddDirs(gopaths []string) { fmt.Println("Error:", err) } */ - -// IsGitDir checks if a .git directory exists inside the given directory -func IsGitDir(dir string) bool { - gitDir := filepath.Join(dir, ".git") - info, err := os.Stat(gitDir) - if os.IsNotExist(err) { - return false - } - return info.IsDir() -} - -// attempt's to guess at what master is. -// TODO: fix this properly -func (repo *Repo) guessMainWorkingName() { - if repo.IsBranch("guimaster") { - return - } - if repo.IsBranch("master") { - return - } - if rs.TagExists("main") { - return - } - - // figure out what to do here - rs.mainWorkingName.SetText("FIXME") - rs.mainBranchVersion.SetLabel("FIXME") -} - -func (rs *RepoStatus) guessDevelWorkingName() { - if rs.TagExists("guidevel") { - rs.develWorkingName.SetValue("guidevel") - rs.develBranchVersion.SetLabel("guidevel") - return - } - if rs.TagExists("devel") { - rs.develWorkingName.SetValue("devel") - rs.develBranchVersion.SetLabel("devel") - return - } - - // figure out what to do here - rs.develWorkingName.SetValue("develFIXME") - rs.develBranchVersion.SetLabel("develFIXME") -} - -func (rs *RepoStatus) setUserWorkingName() { - usr, _ := user.Current() - uname := usr.Username - if rs.TagExists(uname) { - rs.userWorkingName.SetValue(uname) - rs.userBranchVersion.SetLabel(uname) - return - } - rs.userWorkingName.SetValue("need to create " + uname) - rs.userBranchVersion.SetLabel("need to create " + uname) -} -