// Copyright 2017-2025 WIT.COM Inc. All rights reserved. // Use of this source code is governed by the GPL 3.0 package main import ( "go.wit.com/lib/protobuf/gitpb" ) // this populates a slice of protobuf records representing each git repo // var found []*gitpb.Repo // // so, it makes a subset of repos that are then used performing actions on // // by default, it adds every repo func doFind() *gitpb.Repos { if argv.List == nil { return findAll() } if argv.List.Mine { return findMine() } if argv.List.Dirty { return findDirty() } return findAll() } func (f *FindCmd) findRepos() *gitpb.Repos { if f == nil { return findMine() } if f.All { return findAll() } if f.Private { return findPrivate() } if f.Mine { return findMine() } if f.Favorites { return findFavorites() } if f.Dirty { return findDirty() } if f.User { return findUser() } return findAll() } func findPrivate() *gitpb.Repos { found := gitpb.NewRepos() for repo := range me.forge.Repos.IterByFullPath() { if me.forge.Config.IsPrivate(repo.GetGoPath()) { found.AppendByGoPath(repo) } } return found } // finds repos that are writable func findMine() *gitpb.Repos { found := gitpb.NewRepos() // log.Printf("get mine %s\n", me.forge.GetGoSrc()) for repo := range me.forge.Repos.IterByFullPath() { if me.forge.Config.IsWritable(repo.GetGoPath()) { found.AppendByGoPath(repo) } } return found } // finds repos the user has marked as favorites in the forge .config func findFavorites() *gitpb.Repos { found := gitpb.NewRepos() // log.Printf("get favorites %s\n", me.forge.GetGoSrc()) for repo := range me.forge.Repos.IterByFullPath() { if me.forge.Config.IsFavorite(repo.GetGoPath()) { found.AppendByGoPath(repo) } } return found } // finds repos that git is reporting as dirty func findDirty() *gitpb.Repos { found := gitpb.NewRepos() for repo := range me.forge.Repos.IterByFullPath() { if repo.IsDirty() { found.AppendByGoPath(repo) } } return found } func findAll() *gitpb.Repos { found := gitpb.NewRepos() for repo := range me.forge.Repos.IterByFullPath() { found.AppendByGoPath(repo) } return found } func findUser() *gitpb.Repos { found := gitpb.NewRepos() for repo := range me.forge.Repos.IterByFullPath() { if repo.GetCurrentBranchName() == repo.GetUserBranchName() { found.AppendByGoPath(repo) } } return found } func findPublishable() *gitpb.Repos { found := gitpb.NewRepos() for repo := range me.forge.Repos.IterByFullPath() { if repo.GetTargetVersion() == "" { continue } found.AppendByGoPath(repo) } return found } func findReposWithPatches() *gitpb.Repos { found := gitpb.NewRepos() for repo := range me.forge.Repos.IterByFullPath() { if repo.GetTargetVersion() != "" { // add everything that has a target version set found.AppendByGoPath(repo) continue } if repo.IsDirty() { // always add dirty branches found.AppendByGoPath(repo) continue } if repo.GetUserVersion() == "" || repo.GetUserVersion() == "uerr" { // skip anything without a user branch continue } if repo.GetUserVersion() != repo.GetDevelVersion() { found.AppendByGoPath(repo) continue } // this is an old test to see if the current 'last tag' is accurate and should be removed if me.forge.Config.IsReadOnly(repo.GetGoPath()) { continue } if repo.GetLastTag() != repo.GetMasterVersion() { found.AppendByGoPath(repo) repo.FindLastTag() continue } } return found }