Skip to content

prek install -f fails when global core.hooksPath is set #2426

Description

@lxl66566

When git's core.hooksPath is configured globally, running prek install -f inside a repository produces the following error:

❯ prek install -f
error: Refusing to install hooks because core.hooksPath is configured outside this repository.

note: Git will execute hooks from the configured global/system hooks directory, not from this repository's hooks directory.

The -f (force) flag does not override this check.

Why do we need to install the hook? Because even if core.hooksPath is set, the local hook can still be executed via the global hook, such as the following pre-commit script:

#!/usr/bin/env bash

LOCAL_HOOK=".git/hooks/pre-commit"

if [ -f "$LOCAL_HOOK" ] && [ -x "$LOCAL_HOOK" ]; then
    "$LOCAL_HOOK" "$@"
    exit "$?"
fi

exit 0

The expected behavior is that -f would bypass the error and proceed with the installation, and simply emit a warning about the global hooksPath interfering.

Alternatively, if you made prek install (without -f) emit a warning about core.hooksPath instead of throwing an error, I would be even happier.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions