summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimeon Simeonov2021-02-11 20:26:55 +0100
committerSimeon Simeonov2021-02-11 20:26:55 +0100
commitcb7c844e774b1a7d64db54327fa27c8c9f702d2e (patch)
tree6c9e0cdc9bebb2947d05e02a348fd87f4a65fbf7
parent8e5b86d0461466a6960fa4874a4f9286e63a9653 (diff)
Add the -l option and list untracked and staged files in addition to modified
-rwxr-xr-xpygitchecker.py21
1 files changed, 16 insertions, 5 deletions
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):
21 21
22 22
23def is_git_repo(abspath): 23def is_git_repo(abspath):
24 """ 24 """True of abspath points to a git repo, False otherwise"""
25 True of abspath points to a git repo, False otherwise
26 """
27 if not os.path.isdir(abspath): 25 if not os.path.isdir(abspath):
28 return False 26 return False
29 try: 27 try:
@@ -76,8 +74,13 @@ def fetch_git_files(args):
76 """Fetches new and modified .py-files using git""" 74 """Fetches new and modified .py-files using git"""
77 try: 75 try:
78 repo = git.Repo(args.repo_path) 76 repo = git.Repo(args.repo_path)
79 return [mfile.a_path for mfile in repo.index.diff(None) 77 modified_files = {mfile.a_path for mfile in repo.index.diff(None)
80 if mfile.a_path.lower().endswith('.py')] 78 if mfile.a_path.lower().endswith('.py')}
79 staged_files = {sfile.a_path for sfile in repo.index.diff('HEAD')
80 if sfile.a_path.lower().endswith('.py')}
81 untracked_files = set(
82 filter(lambda f: f.lower().endswith('.py'), repo.untracked_files))
83 return list(modified_files | staged_files | untracked_files)
81 except git.InvalidGitRepositoryError: 84 except git.InvalidGitRepositoryError:
82 eprint(f'{args.repo_path} is not a valid git repository') 85 eprint(f'{args.repo_path} is not a valid git repository')
83 sys.exit(1) 86 sys.exit(1)
@@ -155,6 +158,11 @@ def main(inargs=None):
155 dest='full_search', 158 dest='full_search',
156 help='Consider repos that contain untracked files (used with -m)') 159 help='Consider repos that contain untracked files (used with -m)')
157 parser.add_argument( 160 parser.add_argument(
161 '-l', '--list-only',
162 action='store_true',
163 dest='list_only',
164 help='Only lists the target files without performing any checks')
165 parser.add_argument(
158 '-m', '--modifications-only', 166 '-m', '--modifications-only',
159 action='store_true', 167 action='store_true',
160 dest='mod_only', 168 dest='mod_only',
@@ -206,6 +214,9 @@ def main(inargs=None):
206 eprint(f'Unable to parse {args.config_file}: {e}') 214 eprint(f'Unable to parse {args.config_file}: {e}')
207 sys.exit(errno.EIO) 215 sys.exit(errno.EIO)
208 for target_file in selected_files: 216 for target_file in selected_files:
217 if args.list_only:
218 print(target_file)
219 continue
209 if args.verbose: 220 if args.verbose:
210 print(f'Validating {target_file}:') 221 print(f'Validating {target_file}:')
211 validate_python_file(target_file, config_dict.get('tests'), args) 222 validate_python_file(target_file, config_dict.get('tests'), args)