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:

#!/bin/bash

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