From cb7c844e774b1a7d64db54327fa27c8c9f702d2e Mon Sep 17 00:00:00 2001 From: Simeon Simeonov Date: Thu, 11 Feb 2021 20:26:55 +0100 Subject: Add the -l option and list untracked and staged files in addition to modified --- pygitchecker.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'pygitchecker.py') diff --git a/pygitchecker.py b/pygitchecker.py index 469dcdf..b9041c1 100755 --- a/pygitchecker.py +++ b/pygitchecker.py @@ -21,9 +21,7 @@ def eprint(*arg, **kwargs): def is_git_repo(abspath): - """ - True of abspath points to a git repo, False otherwise - """ + """True of abspath points to a git repo, False otherwise""" if not os.path.isdir(abspath): return False try: @@ -76,8 +74,13 @@ def fetch_git_files(args): """Fetches new and modified .py-files using git""" try: repo = git.Repo(args.repo_path) - return [mfile.a_path for mfile in repo.index.diff(None) - if mfile.a_path.lower().endswith('.py')] + modified_files = {mfile.a_path for mfile in repo.index.diff(None) + if mfile.a_path.lower().endswith('.py')} + staged_files = {sfile.a_path for sfile in repo.index.diff('HEAD') + if sfile.a_path.lower().endswith('.py')} + untracked_files = set( + filter(lambda f: f.lower().endswith('.py'), repo.untracked_files)) + return list(modified_files | staged_files | untracked_files) except git.InvalidGitRepositoryError: eprint(f'{args.repo_path} is not a valid git repository') sys.exit(1) @@ -154,6 +157,11 @@ def main(inargs=None): action='store_true', dest='full_search', help='Consider repos that contain untracked files (used with -m)') + parser.add_argument( + '-l', '--list-only', + action='store_true', + dest='list_only', + help='Only lists the target files without performing any checks') parser.add_argument( '-m', '--modifications-only', action='store_true', @@ -206,6 +214,9 @@ def main(inargs=None): eprint(f'Unable to parse {args.config_file}: {e}') sys.exit(errno.EIO) for target_file in selected_files: + if args.list_only: + print(target_file) + continue if args.verbose: print(f'Validating {target_file}:') validate_python_file(target_file, config_dict.get('tests'), args) -- cgit v1.3