// 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 me.found []*gitpb.Repo // // so, it makes a subset of repos that are then used performing actions on // // by default, it adds every repo func (f *FindCmd) findRepos() *gitpb.Repos { if f == nil { findMine() return me.found } if f.All { findAll() return me.found } if f.Private { findPrivate() return me.found } if f.Mine { findMine() return me.found } if f.Favorites { findFavorites() return me.found } if f.Dirty { return findDirty() } if f.User { findUser() return me.found } findAll() return me.found } func findPrivate() { all := me.forge.Repos.SortByFullPath() for all.Scan() { repo := all.Next() if me.forge.Config.IsPrivate(repo.GetGoPath()) { me.found.AppendByGoPath(repo) } } } // finds repos that are writable func findMine() { // log.Printf("get mine %s\n", me.forge.GetGoSrc()) all := me.forge.Repos.SortByFullPath() for all.Scan() { repo := all.Next() if me.forge.Config.IsWritable(repo.GetGoPath()) { me.found.AppendByGoPath(repo) } } } // finds repos the user has marked as favorites in the forge .config func findFavorites() { // log.Printf("get favorites %s\n", me.forge.GetGoSrc()) all := me.forge.Repos.SortByFullPath() for all.Scan() { repo := all.Next() if me.forge.Config.IsFavorite(repo.GetGoPath()) { me.found.AppendByGoPath(repo) } } } // finds repos that git is reporting as dirty func findDirty() *gitpb.Repos { found := gitpb.NewRepos() all := me.forge.Repos.SortByFullPath() for all.Scan() { var repo *gitpb.Repo repo = all.Next() if repo.IsDirty() { found.AppendByGoPath(repo) } } return found } func findAll() { all := me.forge.Repos.SortByFullPath() for all.Scan() { repo := all.Next() me.found.AppendByGoPath(repo) } } func findUser() { all := me.forge.Repos.SortByFullPath() for all.Scan() { repo := all.Next() if repo.GetCurrentBranchName() == repo.GetUserBranchName() { me.found.AppendByGoPath(repo) } } } func findPublishable() { all := me.forge.Repos.SortByFullPath() for all.Scan() { repo := all.Next() if repo.GetTargetVersion() == "" { continue } me.found.AppendByGoPath(repo) } } func findReposWithPatches() { all := me.forge.Repos.SortByFullPath() for all.Scan() { repo := all.Next() if repo.GetTargetVersion() != "" { // add everything that has a target version set me.found.AppendByGoPath(repo) continue } if repo.IsDirty() { // always add dirty branches me.found.AppendByGoPath(repo) continue } if repo.GetUserVersion() == "" || repo.GetUserVersion() == "uerr" { // skip anything without a user branch continue } if repo.GetUserVersion() != repo.GetDevelVersion() { me.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() { me.found.AppendByGoPath(repo) repo.FindLastTag() continue } } }