This is clearly a pure git issue.
This will be easy to debug if you, well, debug the issue. Even printfs in your hook will help you figure out what is going wrong. You will see which command is failing and as long as you have some good git knowledge (which you must because you're running a git server) you will have an "aha" moment about why the command is not working.
New branches in git are surprisingly hard to deal with. A new ref could be pushing zero, one, or more new-to-this-repo commits. For instance, when I want to iterate over new commits, I have to jump through some hoops to properly account for a new branch as follows. (And I'm explicitly ignoring merges.)
zero="0000000000000000000000000000000000000000"
if [ "$oldrev" = "$zero" ]; then
# New branch, examine all commits. Could be none, one, or more.
# newrev must be _before_ the --not. Or you have to add another --not later
cmd=$(git rev-list --first-parent $newrev --not --branches=*)
else
commitcount=$(git rev-list --first-parent $oldrev..$newrev )
fi
<run $cmd and iterate through commits>
Stephen