I want to prevent users from pushing to my repository when their usernames aren't set correctly. In practice I'd like this:
foreach commit in pushed_stuff:
if not commit.username in some_list:
reject push
The hook pre-receive
seems appropriate but how do I extract the username from each commit object that is received? update
seems to get the object names but from my understanding that happens when it's already in my repository (just before the ref has moved).
EDIT: This isn't meant to be some security mechanism to only allow certain people to push to me. I trust everyone, but sometimes people mess up and forget to configure their .gitconfig
.
UPDATE: I had a problem with VonC's suggestion. When using pre-receive, if someone pushes a new branch the <old-value>
is "000000000". So if he had made several commits to that new branch and he tries to push it, doing git rev-list ... $new only gives me one commit. But maybe other commits before it have had a bad username that I want to reject. I couldn't find a way to tell git to give me all the new commits. When the branch already exists doing git rev-list ... $old..$new does the job.