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.
The pre-commit hook is run first, before you even type in a commit message. It's used to inspect the snapshot that's about to be committed, to see if you've forgotten something, to make sure tests run, or to examine whatever you need to inspect in the code.
The post-commit hook is called immediately after the commit-msg hook. It can't change the outcome of the git commit operation, so it's used primarily for notification purposes. The script takes no parameters and its exit status does not affect the commit in any way.
No. Hooks are per-repository and are never pushed.
Open a terminal window by using option + T in GitKraken Client. Once the terminal windows is open, change directory to . git/hooks . Then use the command chmod +x pre-commit to make the pre-commit file executable.
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-macrogit 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 "$@"
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With