def get_filenames(args, include_expr, exclude_expr): if args.origin and args.source: getter = git.get_files_matching( lambda: get_changed_files(args.origin, args.source), ) elif args.files: getter = git.get_files_matching(lambda: args.files) elif args.all_files: getter = git.get_all_files_matching elif git.is_in_merge_conflict(): getter = git.get_conflicted_files_matching else: getter = git.get_staged_files_matching return getter(include_expr, exclude_expr)
def _run_single_hook(runner, repository, hook, args, write, skips=set()): if args.origin and args.source: get_filenames = git.get_files_matching( lambda: get_changed_files(args.origin, args.source), ) elif args.files: get_filenames = git.get_files_matching(lambda: args.files) elif args.all_files: get_filenames = git.get_all_files_matching elif git.is_in_merge_conflict(): get_filenames = git.get_conflicted_files_matching else: get_filenames = git.get_staged_files_matching filenames = get_filenames(hook['files'], hook['exclude']) if hook['id'] in skips: _print_user_skipped(hook, write, args) return 0 elif not filenames: _print_no_files_skipped(hook, write, args) return 0 # Print the hook and the dots first in case the hook takes hella long to # run. write(get_hook_message(_hook_msg_start(hook, args.verbose), end_len=6)) sys.stdout.flush() retcode, stdout, stderr = repository.run_hook(hook, filenames) if retcode != hook['expected_return_value']: retcode = 1 print_color = color.RED pass_fail = 'Failed' else: retcode = 0 print_color = color.GREEN pass_fail = 'Passed' write(color.format_color(pass_fail, print_color, args.color) + '\n') if (stdout or stderr) and (retcode or args.verbose): write('hookid: {0}\n'.format(hook['id'])) write('\n') for output in (stdout, stderr): if output.strip(): write(output.strip() + '\n') write('\n') return retcode
def get_files_matching_func(): def get_filenames(): return ( '.pre-commit-hooks.yaml', 'pre_commit/main.py', 'pre_commit/git.py', 'im_a_file_that_doesnt_exist.py', ) return git.get_files_matching(get_filenames)
def get_files_matching_func(): def get_filenames(): return ( 'pre_commit/main.py', 'pre_commit/git.py', 'im_a_file_that_doesnt_exist.py', 'hooks.yaml', ) return git.get_files_matching(get_filenames)
def get_files_matching_func(): def get_filenames(): return ( 'pre_commit/main.py', 'pre_commit/git.py', 'im_a_file_that_doesnt_exist.py', 'testing/test_symlink', 'hooks.yaml', ) return git.get_files_matching(get_filenames)
def get_files_matching_func(): def get_filenames(): return ( '.pre-commit-hooks.yaml', 'pre_commit/main.py', 'pre_commit/git.py', 'im_a_file_that_doesnt_exist.py', 'testing/test_symlink', ) return git.get_files_matching(get_filenames)
def get_files_matching_func(): def get_filenames(): return ( "pre_commit/main.py", "pre_commit/git.py", "im_a_file_that_doesnt_exist.py", "testing/test_symlink", "hooks.yaml", ) return git.get_files_matching(get_filenames)
def test_matches_broken_symlink(tmpdir): # pragma: no cover (non-windwos) with tmpdir.as_cwd(): os.symlink('does-not-exist', 'link') func = git.get_files_matching(lambda: ('link', )) assert func('', '^$') == {'link'}