gitbashhook

git pre-status or post-status hook


I would like to run a linter on git status, however there seems to be no pre-status nor post-status hook. How could one add a hook to git? The fine docs are suspiciously silent on the matter!

I'm currently wrapping my linter and git status in a Bash script, but I would prefer a solution which supports my muscle-memory-macro git status. I'm running CentOS 7.3 with KDE 4 if it matters.


Solution

  • Git hooks are for operations that (are going to) modify the repository or the working tree. Since git status is a read-only operation there is no hook for it.

    I'm currently wrapping my linter and git status in a Bash script, but I would prefer a solution which supports my muscle-memory-macro git status.

    You can wrap your git command into the following function that will not require to adjust your muscle memory:

    git()
    {
        if [[ $# -ge 1 && "$1" == "status" ]]
        then
            echo Your git-status pre-hook should be here
        fi
    
        command git "$@"
    }