12

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.

dotancohen
  • 30,064
  • 36
  • 138
  • 197

1 Answers1

13

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 "$@"
}
Leon
  • 31,443
  • 4
  • 72
  • 97
  • Thank you Leon! I now understand the reasoning for the lack of a git-status hook, and the Bash function idea is terrific. – dotancohen Jan 25 '17 at 09:46