Skip to content

Commit

Permalink
Fix: Allow Git Hooks to be executed in another Ruby env when committi…
Browse files Browse the repository at this point in the history
…ng from the web UI
  • Loading branch information
vsizov committed Sep 13, 2016
1 parent c6d8af5 commit cc76004
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
v3.5.1
- Clear environment variables before running hooks

v3.5.0
- Add option to recover 2FA via SSH

Expand Down
15 changes: 12 additions & 3 deletions lib/gitlab_custom_hook.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'open3'
require 'bundler'

class GitlabCustomHook
def pre_receive(changes, repo_path)
Expand All @@ -11,15 +12,17 @@ def pre_receive(changes, repo_path)
def post_receive(changes, repo_path)
hook = hook_file('post-receive', repo_path)
return true if hook.nil?

call_receive_hook(hook, changes)
end

def update(ref_name, old_value, new_value, repo_path)
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
Expand All @@ -28,7 +31,13 @@ def call_receive_hook(hook, changes)
# 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.
Expand Down

0 comments on commit cc76004

Please sign in to comment.