(ctx: click.Context, prepush_args: List[str])
scan as a pre-push git hook.
scan as a pre-push git hook.
scan as a pre - push git hook .
def prepush_cmd(ctx: click.Context, prepush_args: List[str]) -> int:  # pragma: no cover
    """
    scan as a pre-push git hook.
    """
    config = ctx.obj["config"]

    local_commit, remote_commit = collect_from_precommit_env()
    if local_commit is None or remote_commit is None:
        local_commit, remote_commit = collect_from_stdin()

    if local_commit == EMPTY_SHA:
        click.echo("Deletion event or nothing to scan.")
        return 0

    if remote_commit == EMPTY_SHA:
        click.echo(
            f"New tree event. Scanning last {config.max_commits_for_hook} commits."
        )
        before = EMPTY_TREE
        after = local_commit
        cmd_range = (
            f"--max-count={config.max_commits_for_hook+1} {EMPTY_TREE} {local_commit}"
        )
    else:
        before = remote_commit
        after = local_commit
        cmd_range = f"--max-count={config.max_commits_for_hook+1} {remote_commit}...{local_commit}"  # noqa

    commit_list = get_list_commit_SHA(cmd_range)

    if not commit_list:
        click.echo(
            "Unable to get commit range.\n"
            f"  before: {before}\n"
            f"  after: {after}\n"
            "Skipping pre-push hook\n"
        )
        return 0

    if len(commit_list) > config.max_commits_for_hook:
        click.echo(
            f"Too many commits. Scanning last {config.max_commits_for_hook} commits\n"
        )
        commit_list = commit_list[-config.max_commits_for_hook :]

    if config.verbose:
        click.echo(f"Commits to scan: {len(commit_list)}")

    try:
        check_git_dir()
        return scan_commit_range(
            client=ctx.obj["client"],
            cache=ctx.obj["cache"],
            commit_list=commit_list,
            output_handler=ctx.obj["output_handler"],
            verbose=config.verbose,
            exclusion_regexes=ctx.obj["exclusion_regexes"],
            matches_ignore=config.matches_ignore,
            all_policies=config.all_policies,
            scan_id=" ".join(commit_list),
            mode_header=SupportedScanMode.PRE_PUSH.value,
            banlisted_detectors=config.banlisted_detectors,
        )
    except Exception as error:
        return handle_exception(error, config.verbose)
def prepush_cmd ( ctx : click . Context , prepush_args : List [ str ] ) -> int : # pragma: no cover config = ctx . obj [ "config" ] local_commit , remote_commit = collect_from_precommit_env ( ) if local_commit is None or remote_commit is None : local_commit , remote_commit = collect_from_stdin ( ) if local_commit == EMPTY_SHA : click . echo ( "Deletion event or nothing to scan." ) return 0 if remote_commit == EMPTY_SHA : click . echo ( f"New tree event. Scanning last {config.max_commits_for_hook} commits." ) before = EMPTY_TREE after = local_commit cmd_range = ( f"--max-count={config.max_commits_for_hook+1} {EMPTY_TREE} {local_commit}" ) else : before = remote_commit after = local_commit cmd_range = f"--max-count={config.max_commits_for_hook+1} {remote_commit}...{local_commit}" # noqa commit_list = get_list_commit_SHA ( cmd_range ) if not commit_list : click . echo ( "Unable to get commit range.\n" f"  before: {before}\n" f"  after: {after}\n" "Skipping pre-push hook\n" ) return 0 if len ( commit_list ) > config . max_commits_for_hook : click . echo ( f"Too many commits. Scanning last {config.max_commits_for_hook} commits\n" ) commit_list = commit_list [ - config . max_commits_for_hook : ] if config . verbose : click . echo ( f"Commits to scan: {len(commit_list)}" ) try : check_git_dir ( ) return scan_commit_range ( client = ctx . obj [ "client" ] , cache = ctx . obj [ "cache" ] , commit_list = commit_list , output_handler = ctx . obj [ "output_handler" ] , verbose = config . verbose , exclusion_regexes = ctx . obj [ "exclusion_regexes" ] , matches_ignore = config . matches_ignore , all_policies = config . all_policies , scan_id = " " . join ( commit_list ) , mode_header = SupportedScanMode . PRE_PUSH . value , banlisted_detectors = config . banlisted_detectors , ) except Exception as error : return handle_exception ( error , config . verbose )