From bf7412e48e47c31fe70046285c6109f6a2bb23c5 Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Tue, 6 Feb 2018 19:17:22 +0000 Subject: Merge branch 'dm-git-hook-popen' into 'master' Only set cwd on the newly spawned process, instead of the current one See merge request gitlab-org/gitlab-ce!16958 --- lib/gitlab/git/hook.rb | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/lib/gitlab/git/hook.rb b/lib/gitlab/git/hook.rb index e29a1f7afa1..24f027d8da4 100644 --- a/lib/gitlab/git/hook.rb +++ b/lib/gitlab/git/hook.rb @@ -82,14 +82,20 @@ module Gitlab end def call_update_hook(gl_id, gl_username, oldrev, newrev, ref) - Dir.chdir(repo_path) do - env = { - 'GL_ID' => gl_id, - 'GL_USERNAME' => gl_username - } - stdout, stderr, status = Open3.capture3(env, path, ref, oldrev, newrev) - [status.success?, (stderr.presence || stdout).gsub(/\R/, "
").html_safe] - end + env = { + 'GL_ID' => gl_id, + 'GL_USERNAME' => gl_username, + 'PWD' => repo_path + } + + options = { + chdir: repo_path + } + + args = [ref, oldrev, newrev] + + stdout, stderr, status = Open3.capture3(env, path, *args, options) + [status.success?, (stderr.presence || stdout).gsub(/\R/, "
").html_safe] end def retrieve_error_message(stderr, stdout) -- cgit v1.2.1