summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2015-08-17 09:18:43 +0000
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2015-08-17 09:18:43 +0000
commitbbe0e58aebbb804cb884662be9e7f0f40db9eacd (patch)
treeca9ff02ae7fdb421d8fa0e7e6ca98a0b2d9a0233 /lib
parent69c193e78a14e34d1c67527df821886a38c2e5d8 (diff)
parente02cff19ed158637bd0199f954f6b40d431e45a4 (diff)
downloadgitlab-ce-bbe0e58aebbb804cb884662be9e7f0f40db9eacd.tar.gz
Merge branch 'pre-receive-wo-satellites' into 'remove-satellites'
Add support of pre-receive hooks without satellites Implement commit transaction with pre-receive and post-receive hooks for web editor and merge Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> See merge request !1154
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/git/hook.rb59
1 files changed, 59 insertions, 0 deletions
diff --git a/lib/gitlab/git/hook.rb b/lib/gitlab/git/hook.rb
new file mode 100644
index 00000000000..dd393fe09d2
--- /dev/null
+++ b/lib/gitlab/git/hook.rb
@@ -0,0 +1,59 @@
+module Gitlab
+ module Git
+ class Hook
+ attr_reader :name, :repo_path, :path
+
+ def initialize(name, repo_path)
+ @name = name
+ @repo_path = repo_path
+ @path = File.join(repo_path.strip, 'hooks', name)
+ end
+
+ def exists?
+ File.exist?(path)
+ end
+
+ def trigger(gl_id, oldrev, newrev, ref)
+ return true unless exists?
+
+ changes = [oldrev, newrev, ref].join(" ")
+
+ # function will return true if succesful
+ exit_status = false
+
+ vars = {
+ 'GL_ID' => gl_id,
+ 'PWD' => repo_path
+ }
+
+ options = {
+ chdir: repo_path
+ }
+
+ Open3.popen2(vars, path, options) do |stdin, _, wait_thr|
+ exit_status = true
+ stdin.sync = true
+
+ # in git, pre- and post- receive hooks may just exit without
+ # reading stdin. We catch the exception to avoid a broken pipe
+ # warning
+ begin
+ # inject all the changes as stdin to the hook
+ changes.lines do |line|
+ stdin.puts line
+ end
+ rescue Errno::EPIPE
+ end
+
+ stdin.close
+
+ unless wait_thr.value == 0
+ exit_status = false
+ end
+ end
+
+ exit_status
+ end
+ end
+ end
+end