예제 #1
0
def check_useless_excludes(config_file):
    config = load_config(config_file)
    files = git.get_all_files()
    retv = 0

    exclude = config['exclude']
    if not exclude_matches_any(files, '', exclude):
        print(
            'The global exclude pattern {!r} does not match any files'.format(
                exclude), )
        retv = 1

    for repo in config['repos']:
        for hook in repo['hooks']:
            # Not actually a manifest dict, but this more accurately reflects
            # the defaults applied during runtime
            hook = apply_defaults(hook, MANIFEST_HOOK_DICT)
            include, exclude = hook['files'], hook['exclude']
            if not exclude_matches_any(files, include, exclude):
                print(
                    'The exclude pattern {!r} for {} does not match any files'.
                    format(exclude, hook['id']), )
                retv = 1

    return retv
예제 #2
0
def check_useless_excludes(config_file: str) -> int:
    config = load_config(config_file)
    filenames = git.get_all_files()
    classifier = Classifier.from_config(
        filenames,
        config["files"],
        config["exclude"],
    )
    retv = 0

    exclude = config["exclude"]
    if not exclude_matches_any(filenames, "", exclude):
        print(
            f"The global exclude pattern {exclude!r} does not match any files",
        )
        retv = 1

    for repo in config["repos"]:
        for hook in repo["hooks"]:
            # Not actually a manifest dict, but this more accurately reflects
            # the defaults applied during runtime
            hook = apply_defaults(hook, MANIFEST_HOOK_DICT)
            names = classifier.filenames
            types, exclude_types = hook["types"], hook["exclude_types"]
            names = classifier.by_types(names, types, exclude_types)
            include, exclude = hook["files"], hook["exclude"]
            if not exclude_matches_any(names, include, exclude):
                print(
                    f'The exclude pattern {exclude!r} for {hook["id"]} does '
                    f"not match any files", )
                retv = 1

    return retv
def check_useless_excludes(config_file):
    config = load_config(config_file)
    classifier = Classifier(git.get_all_files())
    retv = 0

    exclude = config['exclude']
    if not exclude_matches_any(classifier.filenames, '', exclude):
        print(
            'The global exclude pattern {!r} does not match any files'
            .format(exclude),
        )
        retv = 1

    for repo in config['repos']:
        for hook in repo['hooks']:
            # Not actually a manifest dict, but this more accurately reflects
            # the defaults applied during runtime
            hook = apply_defaults(hook, MANIFEST_HOOK_DICT)
            names = classifier.filenames
            types, exclude_types = hook['types'], hook['exclude_types']
            names = classifier.by_types(names, types, exclude_types)
            include, exclude = hook['files'], hook['exclude']
            if not exclude_matches_any(names, include, exclude):
                print(
                    'The exclude pattern {!r} for {} does not match any files'
                    .format(exclude, hook['id']),
                )
                retv = 1

    return retv
예제 #4
0
def check_all_hooks_match_files(config_file):
    classifier = Classifier(git.get_all_files())
    retv = 0

    for hook in all_hooks(load_config(config_file), Store()):
        if hook.always_run or hook.language == 'fail':
            continue
        elif not classifier.filenames_for_hook(hook):
            print('{} does not apply to this repository'.format(hook.id))
            retv = 1

    return retv
예제 #5
0
def check_all_hooks_match_files(config_file: str) -> int:
    classifier = Classifier(git.get_all_files())
    retv = 0

    for hook in all_hooks(load_config(config_file), Store()):
        if hook.always_run or hook.language == 'fail':
            continue
        elif not classifier.filenames_for_hook(hook):
            print(f'{hook.id} does not apply to this repository')
            retv = 1

    return retv
예제 #6
0
def _all_filenames(args):
    if args.origin and args.source:
        return git.get_changed_files(args.origin, args.source)
    elif args.hook_stage in {'prepare-commit-msg', 'commit-msg'}:
        return (args.commit_msg_filename,)
    elif args.files:
        return args.files
    elif args.all_files:
        return git.get_all_files()
    elif git.is_in_merge_conflict():
        return git.get_conflicted_files()
    else:
        return git.get_staged_files()
예제 #7
0
파일: run.py 프로젝트: tpriyanshu90/motiBot
def _all_filenames(args):
    if args.origin and args.source:
        return git.get_changed_files(args.origin, args.source)
    elif args.hook_stage == 'commit-msg':
        return (args.commit_msg_filename, )
    elif args.files:
        return args.files
    elif args.all_files:
        return git.get_all_files()
    elif git.is_in_merge_conflict():
        return git.get_conflicted_files()
    else:
        return git.get_staged_files()
예제 #8
0
def _all_filenames(args: argparse.Namespace) -> Collection[str]:
    if args.origin and args.source:
        return git.get_changed_files(args.origin, args.source)
    elif args.hook_stage in {'prepare-commit-msg', 'commit-msg'}:
        return (args.commit_msg_filename, )
    elif args.files:
        return args.files
    elif args.all_files:
        return git.get_all_files()
    elif git.is_in_merge_conflict():
        return git.get_conflicted_files()
    else:
        return git.get_staged_files()
예제 #9
0
파일: run.py 프로젝트: ejazs/showcase
def _all_filenames(args: argparse.Namespace) -> Collection[str]:
    if args.hook_stage == 'post-checkout':  # no files for post-checkout
        return ()
    elif args.hook_stage in {'prepare-commit-msg', 'commit-msg'}:
        return (args.commit_msg_filename, )
    elif args.from_ref and args.to_ref:
        return git.get_changed_files(args.from_ref, args.to_ref)
    elif args.files:
        return args.files
    elif args.all_files:
        return git.get_all_files()
    elif git.is_in_merge_conflict():
        return git.get_conflicted_files()
    else:
        return git.get_staged_files()
예제 #10
0
def check_all_hooks_match_files(config_file):
    files = git.get_all_files()
    retv = 0

    for hook in all_hooks(load_config(config_file), Store()):
        if hook.always_run or hook.language == 'fail':
            continue
        include, exclude = hook.files, hook.exclude
        filtered = _filter_by_include_exclude(files, include, exclude)
        types, exclude_types = hook.types, hook.exclude_types
        filtered = _filter_by_types(filtered, types, exclude_types)
        if not filtered:
            print('{} does not apply to this repository'.format(hook.id))
            retv = 1

    return retv
예제 #11
0
def _all_filenames(args: argparse.Namespace) -> Collection[str]:
    # these hooks do not operate on files
    if args.hook_stage in {"post-checkout", "post-commit"}:
        return ()
    elif args.hook_stage in {"prepare-commit-msg", "commit-msg"}:
        return (args.commit_msg_filename,)
    elif args.from_ref and args.to_ref:
        return git.get_changed_files(args.from_ref, args.to_ref)
    elif args.files:
        return args.files
    elif args.all_files:
        return git.get_all_files()
    elif git.is_in_merge_conflict():
        return git.get_conflicted_files()
    else:
        return git.get_staged_files()
예제 #12
0
def check_all_hooks_match_files(config_file):
    files = git.get_all_files()
    retv = 0

    for repo in repositories(load_config(config_file), Store()):
        for hook_id, hook in repo.hooks:
            if hook['always_run'] or hook['language'] == 'fail':
                continue
            include, exclude = hook['files'], hook['exclude']
            filtered = _filter_by_include_exclude(files, include, exclude)
            types, exclude_types = hook['types'], hook['exclude_types']
            filtered = _filter_by_types(filtered, types, exclude_types)
            if not filtered:
                print('{} does not apply to this repository'.format(hook_id))
                retv = 1

    return retv
예제 #13
0
def check_all_hooks_match_files(config_file: str) -> int:
    config = load_config(config_file)
    classifier = Classifier.from_config(
        git.get_all_files(),
        config["files"],
        config["exclude"],
    )
    retv = 0

    for hook in all_hooks(config, Store()):
        if hook.always_run or hook.language == "fail":
            continue
        elif not classifier.filenames_for_hook(hook):
            print(f"{hook.id} does not apply to this repository")
            retv = 1

    return retv
예제 #14
0
def check_all_hooks_match_files(config_file):
    runner = Runner.create(config_file)
    files = git.get_all_files()
    retv = 0

    for repo in runner.repositories:
        for hook_id, hook in repo.hooks:
            if hook['always_run']:
                continue
            include, exclude = hook['files'], hook['exclude']
            filtered = _filter_by_include_exclude(files, include, exclude)
            types, exclude_types = hook['types'], hook['exclude_types']
            filtered = _filter_by_types(filtered, types, exclude_types)
            if not filtered:
                print('{} does not apply to this repository'.format(hook_id))
                retv = 1

    return retv
예제 #15
0
def check_useless_excludes(config_file: str) -> int:
    config = load_config(config_file)
    filenames = git.get_all_files()
    classifier = Classifier.from_config(
        filenames,
        config['files'],
        config['exclude'],
    )
    retv = 0

    exclude = config['exclude']
    if not exclude_matches_any(filenames, '', exclude):
        print(
            f'The global exclude pattern {exclude!r} does not match any files',
        )
        retv = 1

    for repo in config['repos']:
        for hook in repo['hooks']:
            # the default of manifest hooks is `types: [file]` but we may
            # be configuring a symlink hook while there's a broken symlink
            hook.setdefault('types', [])
            # Not actually a manifest dict, but this more accurately reflects
            # the defaults applied during runtime
            hook = apply_defaults(hook, MANIFEST_HOOK_DICT)
            names = classifier.filenames
            types = hook['types']
            types_or = hook['types_or']
            exclude_types = hook['exclude_types']
            names = classifier.by_types(names, types, types_or, exclude_types)
            include, exclude = hook['files'], hook['exclude']
            if not exclude_matches_any(names, include, exclude):
                print(
                    f'The exclude pattern {exclude!r} for {hook["id"]} does '
                    f'not match any files', )
                retv = 1

    return retv
예제 #16
0
def test_all_files_non_ascii(non_ascii_repo):
    ret = git.get_all_files()
    assert ret == ['интервью']
예제 #17
0
def test_all_files_non_ascii(non_ascii_repo):
    ret = git.get_all_files()
    assert ret == ['интервью']