Because the "update" hook has been removed in GitLab version 7.4 here a new
and better reject hook replacing the pre-receive:
#!/opt/gitlab/embedded/bin/ruby
# @backup
# Fix the PATH so that gitlab-shell can find git-upload-pack and friends.
ENV['PATH'] = '/opt/gitlab/bin:/opt/gitlab/embedded/bin:' + ENV['PATH']
#!/usr/bin/env ruby
# This file was placed here by GitLab. It makes sure that your pushed
commits
# will be processed properly.
# You can add your own hooks to this file, but be careful when updating
gitlab-shell!
refs = ARGF.read
key_id = ENV['GL_ID']
repo_path = Dir.pwd
# get sha references
temp = refs.split(" ")
shaold = temp[0]
shanew = temp[1]
require '/opt/gitlab/embedded/service/gitlab-shell/lib/gitlab_access'
# read the remote user which is pushing
# distinguish between key-id (ssh access) and user-id (http access)
user = {}
if key_id =~ /\Akey\-\d+\Z/
# discover the user though its ssh key using GitLab shell function
require '/opt/gitlab/embedded/service/gitlab-shell/lib/gitlab_net'
api = GitlabNet.new
user = api.discover(key_id)
elsif key_id =~ /\Auser\-\d+\Z/
# read user data directly from database table
dbid = key_id.gsub("user-", "")
temp = `psql -h localhost -At -d gitlab -c "select name from users where
id=#{dbid};"`
temp = temp.encode('UTF-8', :invalid => :replace).strip
user["name"] = temp
temp = `psql -h localhost -At -d gitlab -c "select username from users
where id=#{dbid};"`
temp = temp.encode('UTF-8', :invalid => :replace).strip
user["username"] = temp
else
puts "Unknown GL_ID response: " + key_id
exit 1
end
## cn = committers name from SHA reference
cn = `git log #{shanew} --pretty=format:%cn --max-count=1`
puts "Remote account is " + user['name'] + " (" + user['username'] + ")"
if (user["username"] != cn) && (user["name"] != cn)
puts "Rejected push because the committers name '#{cn}' does not match
the remote account"
puts "Use 'git config user.name <your-account-name>' to set things right"
exit 1
end
if GitlabAccess.new(repo_path, key_id, refs).exec
exit 0
else
exit 1
end
--
You received this message because you are subscribed to the Google Groups
"GitLab" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/gitlabhq/823f6aea-5fec-46ce-840c-9f31905d01c9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.