From c2165341d2ccf09a50e239b3e2902b4c4426d088 Mon Sep 17 00:00:00 2001 From: jonathanmetzman <31354670+jonathanmetzman@users.noreply.github.com> Date: Fri, 18 Dec 2020 10:43:22 -0800 Subject: [presubmit] Support option to run on all files (#4870) --- infra/presubmit.py | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) (limited to 'infra') diff --git a/infra/presubmit.py b/infra/presubmit.py index b85af5bef..3a616aca0 100755 --- a/infra/presubmit.py +++ b/infra/presubmit.py @@ -351,6 +351,13 @@ def run_tests(): return not result.failures and not result.errors +def get_all_files(): + """Returns a list of absolute paths of files in this repo.""" + get_all_files_command = ['git', 'ls-files'] + output = subprocess.check_output(get_all_files_command).decode().splitlines() + return [os.path.abspath(path) for path in output if os.path.isfile(path)] + + def main(): """Check changes on a branch for common issues before submitting.""" # Get program arguments. @@ -358,30 +365,38 @@ def main(): parser.add_argument('command', choices=['format', 'lint', 'license', 'infra-tests'], nargs='?') + parser.add_argument('--all-files', + action='store_true', + help='Run presubmit check(s) on all files', + default=False) args = parser.parse_args() - changed_files = get_changed_files() + if args.all_files: + relevant_files = get_all_files() + else: + relevant_files = get_changed_files() os.chdir(_SRC_ROOT) # Do one specific check if the user asked for it. if args.command == 'format': - success = yapf(changed_files, False) + success = yapf(relevant_files, False) return bool_to_returncode(success) if args.command == 'lint': - success = lint(changed_files) + success = lint(relevant_files) return bool_to_returncode(success) if args.command == 'license': - success = check_license(changed_files) + success = check_license(relevant_files) return bool_to_returncode(success) if args.command == 'infra-tests': - return bool_to_returncode(run_tests()) + success = run_tests() + return bool_to_returncode(success) # Do all the checks (but no tests). - success = do_checks(changed_files) + success = do_checks(relevant_files) return bool_to_returncode(success) -- cgit v1.2.3