Commit 49db8b79 authored by Valery Sizov's avatar Valery Sizov Committed by Robert Speicher

Merge branch 'upload_hook' into 'master'

Fire update hook from GitLab

https://gitlab.com/gitlab-org/gitlab-ce/issues/3069

See merge request !1882
parent 45f15602
......@@ -6,6 +6,7 @@ v 8.2.2
- Fix Error 500 when viewing user's personal projects from admin page (Stan Hu)
- Fix: Raw private snippets access workflow
- Prevent "413 Request entity too large" errors when pushing large files with LFS
- Ensure GitLab fires custom update hooks after commit via UI
v 8.2.1
- Forcefully update builds that didn't want to update with state machine
......
......@@ -571,9 +571,13 @@ class Repository
# Run GitLab pre-receive hook
pre_receive_hook = Gitlab::Git::Hook.new('pre-receive', path_to_repo)
status = pre_receive_hook.trigger(gl_id, oldrev, newrev, ref)
pre_receive_hook_status = pre_receive_hook.trigger(gl_id, oldrev, newrev, ref)
if status
# Run GitLab update hook
update_hook = Gitlab::Git::Hook.new('update', path_to_repo)
update_hook_status = update_hook.trigger(gl_id, oldrev, newrev, ref)
if pre_receive_hook_status && update_hook_status
if was_empty
# Create branch
rugged.references.create(ref, newrev)
......@@ -596,7 +600,7 @@ class Repository
# Remove tmp ref and return error to user
rugged.references.delete(tmp_ref)
raise PreReceiveError.new('Commit was rejected by pre-receive hook')
raise PreReceiveError.new('Commit was rejected by git hook')
end
end
......
......@@ -16,6 +16,17 @@ module Gitlab
def trigger(gl_id, oldrev, newrev, ref)
return true unless exists?
case name
when "pre-receive", "post-receive"
call_receive_hook(gl_id, oldrev, newrev, ref)
when "update"
call_update_hook(gl_id, oldrev, newrev, ref)
end
end
private
def call_receive_hook(gl_id, oldrev, newrev, ref)
changes = [oldrev, newrev, ref].join(" ")
# function will return true if succesful
......@@ -54,6 +65,12 @@ module Gitlab
exit_status
end
def call_update_hook(gl_id, oldrev, newrev, ref)
Dir.chdir(repo_path) do
system({ 'GL_ID' => gl_id }, path, ref, oldrev, newrev)
end
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment