ttulka
ttulka

Reputation: 10882

Git server-side hook - committer name

On a Git server 1.8.1.4 with Gitlab 7.7.2 in the server-side hook file pre-receive (ruby) I can get the name of the user from the server database by the push commit into the server via SSH:

$GIT_AUTHOR_NAME['name']

I'd like to check the this user's name with the name of the committer. I have tried to user the variable $GIT_COMMITTER_NAME, but I got the 'nil' value.

How to get the committer name set before the push by the client's command?

git config user.name "Joe Doe"

The same question for the email address ('user.email').

Thank you!

Upvotes: 1

Views: 776

Answers (1)

ttulka
ttulka

Reputation: 10882

My solution:

#!/usr/bin/env ruby
# pre-receive

refs = ARGF.read
key_id  = ENV['GL_ID']
...
# get the user
user = GitlabNet.new.discover(key_id)
author_name = user['name']

committer_name = `git show --pretty=oneline --pretty=format:%an #{newrev} | head -n1`.strip

if author_name != committer_name
    print "Name of the committer must be '" + author_name + "' but found '" + committer_name + "'.\n"
    exit 1
end
...

The newrev is SHA of the current commit, the value is taken from refs.

Upvotes: 2

Related Questions