(context: Context, block: bool)
Configures Bento to automatically run on commits.

    Autorun is configured only for you; it does not affect
    other contributors to this project.

    Autorun is only configured for the project from which this
    command is run.

    By default, Bento will block commits if it finds an issue.
    To prevent autorun from blocking commits, run:

        $ bento enable autorun --no-block
Configures Bento to automatically run on commits.
Configures Bento to automatically run on commits .
def install_autorun(context: Context, block: bool) -> None:
    """
    Configures Bento to automatically run on commits.

    Autorun is configured only for you; it does not affect
    other contributors to this project.

    Autorun is only configured for the project from which this
    command is run.

    By default, Bento will block commits if it finds an issue.
    To prevent autorun from blocking commits, run:

        $ bento enable autorun --no-block

    """
    import git  # import inside def for performance

    # Get hook path
    repo = bento.git.repo(context.base_path)
    if repo is None:
        raise NotAGitRepoException()

    _configure_block(context, block)

    hook_path = Path(git.index.fun.hook_path("pre-commit", repo.git_dir))

    if _is_bento_precommit(hook_path):
        _notify_install(context, block)

    else:
        legacy_hook_path = Path(f"{hook_path}.pre-bento")
        if hook_path.exists():
            # If pre-commit hook already exists move it over
            if legacy_hook_path.exists():
                raise ExistingGitHookException(str(hook_path))
            else:
                # Check that
                shutil.move(str(hook_path), str(legacy_hook_path))

        # Ensure .git/hooks directory exists
        # note that we can (and should) assume .git dir exists since
        # project must be a git project at this point in the code
        hook_path.parent.mkdir(exist_ok=True)

        # Copy pre-commit script template to hook_path
        template_location = os.path.join(
            os.path.dirname(__file__), "../configs/pre-commit.template"
        )
        shutil.copyfile(template_location, hook_path)

        # Make file executable
        original_mode = hook_path.stat().st_mode
        os.chmod(hook_path, original_mode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH)

        _notify_install(context, block)
def install_autorun ( context : Context , block : bool ) -> None : import git # import inside def for performance # Get hook path repo = bento . git . repo ( context . base_path ) if repo is None : raise NotAGitRepoException ( ) _configure_block ( context , block ) hook_path = Path ( git . index . fun . hook_path ( "pre-commit" , repo . git_dir ) ) if _is_bento_precommit ( hook_path ) : _notify_install ( context , block ) else : legacy_hook_path = Path ( f"{hook_path}.pre-bento" ) if hook_path . exists ( ) : # If pre-commit hook already exists move it over if legacy_hook_path . exists ( ) : raise ExistingGitHookException ( str ( hook_path ) ) else : # Check that shutil . move ( str ( hook_path ) , str ( legacy_hook_path ) ) # Ensure .git/hooks directory exists # note that we can (and should) assume .git dir exists since # project must be a git project at this point in the code hook_path . parent . mkdir ( exist_ok = True ) # Copy pre-commit script template to hook_path template_location = os . path . join ( os . path . dirname ( __file__ ) , "../configs/pre-commit.template" ) shutil . copyfile ( template_location , hook_path ) # Make file executable original_mode = hook_path . stat ( ) . st_mode os . chmod ( hook_path , original_mode | stat . S_IXUSR | stat . S_IXGRP | stat . S_IXOTH ) _notify_install ( context , block )