Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRubén Dávila <ruben@gitlab.com>2015-11-26 03:20:40 +0300
committerRubén Dávila <ruben@gitlab.com>2015-12-03 17:39:15 +0300
commit5145706c82613d64462fe736850d09799224cd77 (patch)
tree81744d6a01be18d3c89c6cb726f8496777b99e4e /app/services/git_hooks_service.rb
parentb5103a83a8574936721250997e75ab9a6855d00a (diff)
Run custom Git hooks when creating or deleting branches through the UI. #1156
Diffstat (limited to 'app/services/git_hooks_service.rb')
-rw-r--r--app/services/git_hooks_service.rb32
1 files changed, 32 insertions, 0 deletions
diff --git a/app/services/git_hooks_service.rb b/app/services/git_hooks_service.rb
new file mode 100644
index 00000000000..53f1fdef796
--- /dev/null
+++ b/app/services/git_hooks_service.rb
@@ -0,0 +1,32 @@
+class GitHooksService
+ PreReceiveError = Class.new(StandardError)
+
+ def execute(user, repo_path, oldrev, newrev, ref)
+ @repo_path = repo_path
+ @user = Gitlab::ShellEnv.gl_id(user)
+ @oldrev = oldrev
+ @newrev = newrev
+ @ref = ref
+
+ pre_status = run_hook('pre-receive')
+
+ if pre_status
+ yield
+
+ run_hook('post-receive')
+ end
+ end
+
+ private
+
+ def run_hook(name)
+ hook = Gitlab::Git::Hook.new(name, @repo_path)
+ status = hook.trigger(@user, @oldrev, @newrev, @ref)
+
+ if !status && (name != 'post-receive')
+ raise PreReceiveError.new("Git operation was rejected by #{name} hook")
+ end
+
+ status
+ end
+end