package gitpb import ( "strings" "time" "go.wit.com/log" timestamppb "google.golang.org/protobuf/types/known/timestamppb" ) // does a fast check with os.Stat() // if the mtimes changed, does a full repo.Reload() func (repo *Repo) ReloadCheck() error { if !repo.DidRepoChange() { return nil } // f.configSave = true err := repo.Reload() return err } // TODO: clean this up more, but it is working now more or less func (repo *Repo) Reload() error { // log.Info("in reload", repo.FullPath) repo.Tags = new(GitTags) repo.reloadGitTags() repo.GoDeps = new(GoDeps) if repo.GoInfo == nil { repo.GoInfo = new(GoInfo) } repo.ParseGoSum() // also sets GoPrimitive repo.reloadVersions() repo.setRepoType() // this is probably a good place & time to store these repo.reloadMtimes() repo.CheckDirty() repo.setRepoState() if repo.GitConfig == nil { if err := repo.updateGitConfig(); err != nil { return err } } // LastUpdate should always be the newest time repo.Times.LastUpdate = timestamppb.New(time.Now()) return nil } func (repo *Repo) SetDevelBranchName(bname string) { repo.DevelBranchName = bname } func (repo *Repo) SetUserBranchName(bname string) { repo.UserBranchName = bname } // updates LastTag by age func (repo *Repo) setLastTag() { repo.LastTag = repo.FindLastTag() } func (repo *Repo) setCurrentBranchName() { repo.CurrentBranchName = "" r, err := repo.RunQuiet([]string{"git", "branch", "--show-current"}) output := strings.Join(r.Stdout, "\n") if err != nil { log.Log(WARN, "GetCurrentBranchName() not in a git repo?", err, repo.GetGoPath()) log.Log(WARN, "GetCurrentBranchName() output might have worked anyway:", output) } repo.CurrentBranchName = strings.TrimSpace(output) } // always spawns 'git' and always should spawn 'git' func (repo *Repo) setCurrentBranchVersion() { repo.CurrentBranchVersion = "" if repo == nil { log.Info("repo.GetCurrentBranchVersion() repo == nil") return } r, err := repo.RunQuiet([]string{"git", "describe", "--tags", "--always"}) output := strings.Join(r.Stdout, "\n") if err != nil { log.Log(WARN, "GetCurrentBranchVersion() not in a git repo?", err, repo.GetGoPath()) log.Log(WARN, "GetCurrentBranchVersion() output might have worked anyway:", output) } repo.CurrentBranchVersion = strings.TrimSpace(output) }