Exemplo n.º 1
0
def install(client, force):
    """Install Git hooks."""
    warning_messages = []
    for hook in HOOKS:
        hook_path = Path(get_hook_path(hook, client.repo.git_dir))
        if hook_path.exists():
            if not force:
                warning_messages.append(
                    'Hook already exists. Skipping {0}'.format(str(hook_path))
                )
                continue
            else:
                hook_path.unlink()

        # Make sure the hooks directory exists.
        hook_path.parent.mkdir(parents=True, exist_ok=True)

        Path(hook_path).write_bytes(
            pkg_resources.resource_string(
                'renku.data', '{hook}.sh'.format(hook=hook)
            )
        )
        hook_path.chmod(hook_path.stat().st_mode | stat.S_IEXEC)

    return warning_messages
Exemplo n.º 2
0
def uninstall(client):
    """Uninstall Git hooks."""
    from git.index.fun import hook_path as get_hook_path

    for hook in HOOKS:
        hook_path = Path(get_hook_path(hook, client.repo.git_dir))
        if hook_path.exists():
            hook_path.unlink()
Exemplo n.º 3
0
def install(client, force):
    """Install Git hooks."""
    import pkg_resources
    from git.index.fun import hook_path as get_hook_path

    for hook in HOOKS:
        hook_path = Path(get_hook_path(hook, client.repo.git_dir))
        if hook_path.exists():
            if not force:
                click.echo("Hook already exists. Skipping {0}".format(
                    str(hook_path)),
                           err=True)
                continue
            else:
                hook_path.unlink()

        # Make sure the hooks directory exists.
        hook_path.parent.mkdir(parents=True, exist_ok=True)

        Path(hook_path).write_bytes(
            pkg_resources.resource_string('renku.data',
                                          '{hook}.sh'.format(hook=hook)))
        hook_path.chmod(hook_path.stat().st_mode | stat.S_IEXEC)
Exemplo n.º 4
0
def check_git_hooks_installed(client):
    """Checks if all necessary hooks are installed."""
    for hook in HOOKS:
        hook_path = Path(get_hook_path(hook, client.repo.git_dir))
        if not hook_path.exists():
            message = WARNING + 'Git hooks are not installed. ' \
                'Use "renku githooks install" to install them. \n'
            return False, message

        with hook_path.open() as file_:
            actual_hook = _extract_renku_hook(file_)
        with StringIO(_read_resource(hook)) as file_:
            expected_hook = _extract_renku_hook(file_)

        if not expected_hook:
            message = WARNING + 'Cannot check for existence of Git hooks.\n'
            return False, message

        if actual_hook != expected_hook:
            message = WARNING + 'Git hooks are outdated or not installed.\n' \
                '  (use "renku githooks install --force" to update them) \n'
            return False, message

    return True, None