I am running a gitlab git server.
Most of my users are running 1 of 3 versions of git.
git 1.7.1 (centos users)
git 1.7.9 (everyone else)
git 1.8.4 (mac users)
Some users have accidentally been committing and pushing code as the root user. I need to block commits from those users.
My pre-commit hook looks like this:
#!/bin/bash
if [[ $GIT_AUTHOR_NAME == 'root' ]]
then
echo "If you commit as root, you're gonna have a bad time";
echo "Set 'git config user.name' and try again";
exit 1;
fi
This works as a pre-commit hook on 1.7.9 and 1.8.x but not 1.7.1
According to this blog, pre receive and post receive hooks do not have any of the environment variables that I am looking for ( GIT_AUTHOR_NAME, GIT_AUTHOR_EMAIL, GIT_AUTHOR_DATE, GIT_COMMITTER_NAME, GIT_COMMITTER_EMAIL, GIT_COMMITTER_DATE, EMAIL
).
Is there any way to modify this pre-commit hook to block root users on older versions of git?
http://longair.net/blog/2011/04/09/missing-git-hooks-documentation/