コード例 #1
0
 def repositories(self):
     """Returns a tuple of the configured repositories."""
     config = load_config(self.config_file_path)
     repositories = tuple(Repository.create(x, self.store) for x in config)
     for repository in repositories:
         repository.require_installed()
     return repositories
コード例 #2
0
ファイル: runner.py プロジェクト: akramhussein/pre-commit
 def repositories(self):
     """Returns a tuple of the configured repositories."""
     config = load_config(self.config_file_path)
     repositories = tuple(Repository.create(x, self.store) for x in config)
     for repository in repositories:
         repository.require_installed()
     return repositories
コード例 #3
0
def test_autoupdate_local_hooks(tempdir_factory):
    git_path = git_dir(tempdir_factory)
    config = config_with_local_hooks()
    path = add_config_to_repo(git_path, config)
    runner = Runner(path, C.CONFIG_FILE)
    assert autoupdate(runner, tags_only=False) == 0
    new_config_writen = load_config(runner.config_file_path)
    assert len(new_config_writen) == 1
    assert new_config_writen[0] == config
コード例 #4
0
ファイル: autoupdate_test.py プロジェクト: rolka/pre-commit
def test_autoupdate_local_hooks(tmpdir_factory):
    git_path = git_dir(tmpdir_factory)
    config = config_with_local_hooks()
    path = add_config_to_repo(git_path, config)
    runner = Runner(path)
    assert autoupdate(runner) == 0
    new_config_writen = load_config(runner.config_file_path)
    assert len(new_config_writen) == 1
    assert new_config_writen[0] == config
コード例 #5
0
def autoupdate(runner):
    """Auto-update the pre-commit config to the latest versions of repos."""
    # Set up our logging handler
    logger.addHandler(LoggingHandler(False))
    logger.setLevel(logging.WARNING)

    retv = 0
    output_configs = []
    changed = False

    input_configs = load_config(
        runner.config_file_path,
        load_strategy=ordered_load,
    )

    for repo_config in input_configs:
        if is_local_hooks(repo_config):
            output_configs.append(repo_config)
            continue
        sys.stdout.write('Updating {0}...'.format(repo_config['repo']))
        sys.stdout.flush()
        try:
            new_repo_config = _update_repository(repo_config, runner)
        except RepositoryCannotBeUpdatedError as error:
            print(error.args[0])
            output_configs.append(repo_config)
            retv = 1
            continue

        if new_repo_config['sha'] != repo_config['sha']:
            changed = True
            print(
                'updating {0} -> {1}.'.format(
                    repo_config['sha'], new_repo_config['sha'],
                )
            )
            output_configs.append(new_repo_config)
        else:
            print('already up to date.')
            output_configs.append(repo_config)

    if changed:
        with open(runner.config_file_path, 'w') as config_file:
            config_file.write(
                ordered_dump(
                    remove_defaults(output_configs, CONFIG_JSON_SCHEMA),
                    **C.YAML_DUMP_KWARGS
                )
            )

    return retv
コード例 #6
0
def autoupdate(runner):
    """Auto-update the pre-commit config to the latest versions of repos."""
    # Set up our logging handler
    logger.addHandler(LoggingHandler(False))
    logger.setLevel(logging.WARNING)

    retv = 0
    output_configs = []
    changed = False

    input_configs = load_config(
        runner.config_file_path,
        load_strategy=ordered_load,
    )

    for repo_config in input_configs:
        if is_local_hooks(repo_config):
            output_configs.append(repo_config)
            continue
        sys.stdout.write('Updating {}...'.format(repo_config['repo']))
        sys.stdout.flush()
        try:
            new_repo_config = _update_repository(repo_config, runner)
        except RepositoryCannotBeUpdatedError as error:
            print(error.args[0])
            output_configs.append(repo_config)
            retv = 1
            continue

        if new_repo_config['sha'] != repo_config['sha']:
            changed = True
            print(
                'updating {} -> {}.'.format(
                    repo_config['sha'], new_repo_config['sha'],
                )
            )
            output_configs.append(new_repo_config)
        else:
            print('already up to date.')
            output_configs.append(repo_config)

    if changed:
        with open(runner.config_file_path, 'w') as config_file:
            config_file.write(
                ordered_dump(
                    remove_defaults(output_configs, CONFIG_JSON_SCHEMA),
                    **C.YAML_DUMP_KWARGS
                )
            )

    return retv
コード例 #7
0
ファイル: autoupdate_test.py プロジェクト: rolka/pre-commit
def test_autoupdate_local_hooks_with_out_of_date_repo(
        out_of_date_repo, in_tmpdir, mock_out_store_directory
):
    stale_config = make_config_from_repo(
        out_of_date_repo.path, sha=out_of_date_repo.original_sha, check=False,
    )
    local_config = config_with_local_hooks()
    config = [local_config, stale_config]
    write_config('.', config)
    runner = Runner('.')
    assert autoupdate(runner) == 0
    new_config_writen = load_config(runner.config_file_path)
    assert len(new_config_writen) == 2
    assert new_config_writen[0] == local_config
コード例 #8
0
def test_autoupdate_local_hooks_with_out_of_date_repo(
        out_of_date_repo, in_tmpdir, mock_out_store_directory):
    stale_config = make_config_from_repo(
        out_of_date_repo.path,
        sha=out_of_date_repo.original_sha,
        check=False,
    )
    local_config = config_with_local_hooks()
    config = [local_config, stale_config]
    write_config('.', config)
    runner = Runner('.', C.CONFIG_FILE)
    assert autoupdate(runner, tags_only=False) == 0
    new_config_writen = load_config(runner.config_file_path)
    assert len(new_config_writen) == 2
    assert new_config_writen[0] == local_config
コード例 #9
0
def autoupdate(runner, tags_only):
    """Auto-update the pre-commit config to the latest versions of repos."""
    retv = 0
    output_configs = []
    changed = False

    input_configs = load_config(
        runner.config_file_path,
        load_strategy=ordered_load,
    )

    for repo_config in input_configs:
        if is_local_hooks(repo_config):
            output_configs.append(repo_config)
            continue
        output.write('Updating {}...'.format(repo_config['repo']))
        try:
            new_repo_config = _update_repo(repo_config, runner, tags_only)
        except RepositoryCannotBeUpdatedError as error:
            output.write_line(error.args[0])
            output_configs.append(repo_config)
            retv = 1
            continue

        if new_repo_config['sha'] != repo_config['sha']:
            changed = True
            output.write_line('updating {} -> {}.'.format(
                repo_config['sha'],
                new_repo_config['sha'],
            ))
            output_configs.append(new_repo_config)
        else:
            output.write_line('already up to date.')
            output_configs.append(repo_config)

    if changed:
        with open(runner.config_file_path, 'w') as config_file:
            config_file.write(
                ordered_dump(
                    remove_defaults(output_configs, CONFIG_JSON_SCHEMA),
                    **C.YAML_DUMP_KWARGS))

    return retv