예제 #1
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
예제 #2
0
파일: run.py 프로젝트: vtitor/pre-commit
def run(runner, store, args, environ=os.environ):
    no_stash = args.all_files or bool(args.files)

    # Check if we have unresolved merge conflict files and fail fast.
    if _has_unmerged_paths():
        logger.error('Unmerged files.  Resolve before committing.')
        return 1
    if bool(args.source) != bool(args.origin):
        logger.error('Specify both --origin and --source.')
        return 1
    if _has_unstaged_config(runner) and not no_stash:
        logger.error(
            'Your pre-commit configuration is unstaged.\n'
            '`git add {}` to fix this.'.format(runner.config_file), )
        return 1

    # Expose origin / source as environment variables for hooks to consume
    if args.origin and args.source:
        environ['PRE_COMMIT_ORIGIN'] = args.origin
        environ['PRE_COMMIT_SOURCE'] = args.source

    if no_stash:
        ctx = noop_context()
    else:
        ctx = staged_files_only(store.directory)

    with ctx:
        repo_hooks = []
        for repo in repositories(runner.config, store):
            for _, hook in repo.hooks:
                if ((not args.hook or hook['id'] == args.hook)
                        and not hook['stages']
                        or args.hook_stage in hook['stages']):
                    repo_hooks.append((repo, hook))

        if args.hook and not repo_hooks:
            output.write_line('No hook with id `{}`'.format(args.hook))
            return 1

        for repo in {repo for repo, _ in repo_hooks}:
            repo.require_installed()

        return _run_hooks(runner.config, repo_hooks, args, environ)
예제 #3
0
def install_hooks(runner, store):
    for repository in repositories(runner.config, store):
        repository.require_installed()