(
    hook_dir_path: str,
    force: bool,
    local_hook_support: bool,
    hook_type: str,
    append: bool,
)
return 0
Create hook directory (if needed) and pre-commit/pre-push file.
Create hook directory (if needed) and pre-commit/pre-push file.
Create hook directory ( if needed ) and pre - commit / pre - push file .
def create_hook(
    hook_dir_path: str,
    force: bool,
    local_hook_support: bool,
    hook_type: str,
    append: bool,
) -> int:
    """Create hook directory (if needed) and pre-commit/pre-push file."""
    os.makedirs(hook_dir_path, exist_ok=True)
    hook_path = f"{hook_dir_path}/{hook_type}"

    if os.path.isdir(hook_path):
        raise click.ClickException(f"{hook_path} is a directory.")

    if os.path.isfile(hook_path) and not (force or append):
        raise click.ClickException(
            f"{hook_path} already exists."
            " Use --force to override or --append to add to current script"
        )

    local_hook_str = ""
    if local_hook_support:
        local_hook_str = f"""
if [[ -f .git/hooks/{hook_type} ]]; then
    if ! .git/hooks/{hook_type} $@; then
        echo 'Local {hook_type} hook failed, please see output above'
        exit 1
    fi
fi
"""

    mode = "a" if os.path.exists(hook_path) and append else "w"

    with open(hook_path, mode) as f:
        if mode == "w":
            f.write("#!/bin/bash\n")

        f.write(f"\n{local_hook_str}\nggshield scan {hook_type}\n")
        os.chmod(hook_path, 0o700)

    click.echo(
        f"{hook_type} successfully added in"
        f" {click.style(hook_path, fg='yellow', bold=True)}"
    )

    return 0
def create_hook ( hook_dir_path : str , force : bool , local_hook_support : bool , hook_type : str , append : bool , ) -> int : os . makedirs ( hook_dir_path , exist_ok = True ) hook_path = f"{hook_dir_path}/{hook_type}" if os . path . isdir ( hook_path ) : raise click . ClickException ( f"{hook_path} is a directory." ) if os . path . isfile ( hook_path ) and not ( force or append ) : raise click . ClickException ( f"{hook_path} already exists." " Use --force to override or --append to add to current script" ) local_hook_str = "" if local_hook_support : local_hook_str = f"""
if [[ -f .git/hooks/{hook_type} ]]; then
    if ! .git/hooks/{hook_type} $@; then
        echo 'Local {hook_type} hook failed, please see output above'
        exit 1
    fi
fi
""" mode = "a" if os . path . exists ( hook_path ) and append else "w" with open ( hook_path , mode ) as f : if mode == "w" : f . write ( "#!/bin/bash\n" ) f . write ( f"\n{local_hook_str}\nggshield scan {hook_type}\n" ) os . chmod ( hook_path , 0o700 ) click . echo ( f"{hook_type} successfully added in" f" {click.style(hook_path, fg='yellow', bold=True)}" ) return 0