summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorValery Sizov <valery@gitlab.com>2016-09-13 17:17:27 +0300
committerValery Sizov <valery@gitlab.com>2016-09-13 17:21:43 +0300
commitcc7600498876c2451e2af4c7f95cb830e55f7432 (patch)
treeda11c2c2df1330f92ba55d1b276812093490ad6b
parentc6d8af599dc797ec8ba7874380abad393b439c9e (diff)
downloadgitlab-shell-fix_hook_env.tar.gz
Fix: Allow Git Hooks to be executed in another Ruby env when committing from the web UIfix_hook_env
-rw-r--r--CHANGELOG3
-rw-r--r--lib/gitlab_custom_hook.rb15
2 files changed, 15 insertions, 3 deletions
diff --git a/CHANGELOG b/CHANGELOG
index bce8783..fefa733 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,3 +1,6 @@
+v3.5.1
+ - Clear environment variables before running hooks
+
v3.5.0
- Add option to recover 2FA via SSH
diff --git a/lib/gitlab_custom_hook.rb b/lib/gitlab_custom_hook.rb
index fe6cff3..daca345 100644
--- a/lib/gitlab_custom_hook.rb
+++ b/lib/gitlab_custom_hook.rb
@@ -1,4 +1,5 @@
require 'open3'
+require 'bundler'
class GitlabCustomHook
def pre_receive(changes, repo_path)
@@ -11,7 +12,7 @@ class GitlabCustomHook
def post_receive(changes, repo_path)
hook = hook_file('post-receive', repo_path)
return true if hook.nil?
-
+
call_receive_hook(hook, changes)
end
@@ -19,7 +20,9 @@ class GitlabCustomHook
hook = hook_file('update', repo_path)
return true if hook.nil?
- system(hook, ref_name, old_value, new_value)
+ Bundler.with_clean_env do
+ system(hook, ref_name, old_value, new_value)
+ end
end
private
@@ -28,7 +31,13 @@ class GitlabCustomHook
# Prepare the hook subprocess. Attach a pipe to its stdin, and merge
# both its stdout and stderr into our own stdout.
stdin_reader, stdin_writer = IO.pipe
- hook_pid = spawn(hook, in: stdin_reader, err: :out)
+
+ hook_pid = nil
+
+ Bundler.with_clean_env do
+ hook_pid = spawn(hook, in: stdin_reader, err: :out)
+ end
+
stdin_reader.close
# Submit changes to the hook via its stdin.