// Copyright 2017-2025 WIT.COM Inc. All rights reserved. // Use of this source code is governed by the GPL 3.0 package main // checks that repos are in a "normal" state import ( "errors" "fmt" "path/filepath" "strings" "time" "go.wit.com/lib/config" "go.wit.com/lib/fhelp" "go.wit.com/lib/gui/shell" "go.wit.com/lib/protobuf/forgepb" "go.wit.com/lib/protobuf/gitpb" "go.wit.com/log" ) func doNormal() bool { me.forge.CheckDirtyQuiet() var count int stats := me.forge.RillRepos(checkNormalRepoState) for path, stat := range stats { dur := stat.End.Sub(stat.Start) if dur > 10*time.Second { log.Infof("%s checkNormalRepoState() took a long time (%s)\n", path, shell.FormatDuration(dur)) } if stat.Err == nil { continue } repo := me.forge.Repos.FindByFullPath(path) if stat.Err == ErrorLocalDevelBranch { if me.forge.Config.Mode == forgepb.ForgeMode_NORMAL { bname := repo.GetDevelBranchName() s := fmt.Sprintf("repair the %s branch on %s", bname, repo.FullPath) if fhelp.QuestionUser(s) { // todo, check to make sure we aren't on this branch repo.RunVerbose([]string{"git", "branch", "-D", bname}) repo.RunVerbose([]string{"git", "checkout", bname}) } } } if stat.Err == ErrorLocalMasterBranch { if me.forge.Config.Mode == forgepb.ForgeMode_NORMAL { bname := repo.GetMasterBranchName() s := fmt.Sprintf("repair the %s branch on %s", bname, repo.FullPath) if fhelp.QuestionUser(s) { // todo, check to make sure we aren't on this branch repo.RunVerbose([]string{"git", "branch", "-D", bname}) repo.RunVerbose([]string{"git", "checkout", bname}) } } } // log.Infof("%-60s, %-60s %v %s\n", stat.Start, stat.End.String(), dur, path) // log.Infof("%-30v %s %v\n", dur, path, stat.Err) // log.Info("got path", path, stat.Err) count += 1 } if count > 0 { log.Info("Some repos are not in a 'normal' state. error count =", count) log.Info("TODO: list the repos here. forge patch repos?") showWorkRepos() config.SetChanged("repos", true) return false } return true } var ErrorLocalDevelBranch error = errors.New("devel branch problem") var ErrorLocalMasterBranch error = errors.New("master branch problem") // 99% of the time, the repos during development should be on your user branch. // error out if it's not // this checks to see if a devel and user branch exist // this needs to run each time in case repos were added manually by the user // this also verifies that func checkNormalRepoState(repo *gitpb.Repo) error { var err error tmp := filepath.Join(me.forge.Config.ReposDir, repo.GetNamespace()) if tmp != repo.FullPath { log.Infof("%s != %s\n", repo.FullPath, tmp) if strings.HasPrefix(repo.FullPath, me.forge.Config.ReposDir) { tmp = strings.TrimPrefix(repo.FullPath, me.forge.Config.ReposDir) tmp = strings.Trim(tmp, "/") repo.Namespace = tmp err = log.Errorf("namespace set to filepath") } } else { // log.Infof("%s == %s\n", repo.FullPath, tmp) } tmp = strings.Trim(repo.Namespace, "/") if tmp != repo.Namespace { err = log.Errorf("junk in ns %s", repo.Namespace) repo.Namespace = tmp } if repo.GetMasterBranchName() == "" { me.forge.VerifyBranchNames(repo) log.Info("ABNORMAL: master branch name was blank in", repo.GetFullPath()) } if repo.GetMasterBranchName() == "" { me.forge.VerifyBranchNames(repo) err = log.Errorf("master branch name blank") } if repo.GetDevelBranchName() == "" { me.forge.VerifyBranchNames(repo) err = log.Errorf("devel branch name blank") } if repo.GetUserBranchName() == "" { me.forge.VerifyBranchNames(repo) err = log.Errorf("user branch name blank") } if repo.GetGoPath() == repo.GetNamespace() { // log.Info(repo.FullPath, "gopath == namespace", repo.GetGoPath(), repo.GetNamespace()) } else { log.Info(repo.FullPath, "gopath != namespace", repo.GetGoPath(), repo.GetNamespace()) } repo.MakeLocalDevelBranch() if !repo.VerifyRemoteAndLocalBranches(repo.GetDevelBranchName()) { return ErrorLocalDevelBranch /* bname := repo.GetDevelBranchName() s := fmt.Sprintf("repair the %s branch on %s", bname, repo.FullPath) if fhelp.QuestionUser(s) { repo.RunVerbose([]string{"git", "branch", "-D", bname}) repo.RunVerbose([]string{"git", "checkout", bname}) } */ } if !repo.VerifyRemoteAndLocalBranches(repo.GetMasterBranchName()) { return ErrorLocalMasterBranch /* bname := repo.GetMasterBranchName() s := fmt.Sprintf("repair the %s branch on %s", bname, repo.FullPath) if fhelp.QuestionUser(s) { repo.RunVerbose([]string{"git", "branch", "-D", bname}) repo.RunVerbose([]string{"git", "checkout", bname}) } */ } if repo.GetCurrentBranchName() != repo.GetUserBranchName() { log.Infof("changing to user(%s) branch: %s\n", repo.GetUserBranchName(), repo.FullPath) repo.CheckoutUser() repo.ReloadCheck() err = log.Errorf("now on user branch") } if me.forge.Config.IsReadOnly(repo.GetGoPath()) != repo.GetReadOnly() { repo.ReadOnly = me.forge.Config.IsReadOnly(repo.GetGoPath()) log.Info("damnit", repo.FullPath) err = log.Errorf("readonly bit wrong") } return err }