I needed to test if a script is called by git as a hook or not.

I found out, that for the pre-receive script the environment variable GIT_PUSH_OPTION_COUNT is set. So we can take that to our advantage:


if [ -z "$GIT_PUSH_OPTION_COUNT" ]; then
    echo "Does not seems to be a git hook"
    echo "I think I'm a git hook"