Search code examples
gitgitosis

Git/gitosis: How to check validity of user name and email?


I have installed git and gitosis and I need to add a check that the user name is valid when something is pushed into the repository.

I reckon the pre-receive hook is the correct hook to place this, but I'm unable to find the real user name and email address which gitosis enters into the repository (the ones set by git config user.name and git config user.email) from environment variables. LOGNAME and USER are both 'git'. How does gitosis detect this info and can I find it in the pre-receive hook as well?


Solution

  • Hmm, from what I gather from githooks(5) the pre-receive hook gets fed the updated refs on stdin.

    #!/bin/sh
    
    while read old new name; do
        email=$(git log -1 --pretty=format:%ae $new)
        # check email
    done
    

    You would need to check the email addresses (there can be more than one line of data) and exit the script accordingly, i.e. exit 0 for success and e.g. exit 1 for failure.