1# Copyright 2024 The Pigweed Authors 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); you may not 4# use this file except in compliance with the License. You may obtain a copy of 5# the License at 6# 7# https://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12# License for the specific language governing permissions and limitations under 13# the License. 14""" 15Helpful commands for working with the repo tool. 16See https://gerrit.googlesource.com/git-repo/ for more info! 17""" 18 19import subprocess 20 21from typing import List 22from pathlib import Path 23from pw_presubmit.tools import log_run 24 25 26def list_all_git_repos() -> List[Path]: 27 """Query repo tool and return a list of git repos in the current project. 28 29 Returns: 30 List of "Path"s which were found. 31 """ 32 repos = ( 33 log_run( 34 ['repo', 'forall', '-c', 'git', 'rev-parse', '--show-toplevel'], 35 stdout=subprocess.PIPE, 36 stderr=subprocess.DEVNULL, 37 check=True, 38 ignore_dry_run=True, 39 ) 40 .stdout.decode() 41 .strip() 42 ) 43 44 return [Path(line) for line in repos.splitlines()] 45