From 192e2bd367494bf66746c8971896a2d9cb84fc92 Mon Sep 17 00:00:00 2001 From: Paco Guzman Date: Thu, 15 Sep 2016 15:45:10 +0200 Subject: Enable GIT_TRACE/GIT_TRACE_PACKET/GIT_TRACE_PERFORMANCE by providing the git_trace_log_file config key MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The value of the variable if present must be a writable absolute path. If it’s not the case we log a proper message and not enable tracing to not throw output to the users. --- lib/gitlab_config.rb | 4 ++++ lib/gitlab_shell.rb | 26 ++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) (limited to 'lib') diff --git a/lib/gitlab_config.rb b/lib/gitlab_config.rb index beaf173..781c706 100644 --- a/lib/gitlab_config.rb +++ b/lib/gitlab_config.rb @@ -50,4 +50,8 @@ class GitlabConfig def git_annex_enabled? @config['git_annex_enabled'] ||= false end + + def git_trace_log_file + @config['git_trace_log_file'] + end end diff --git a/lib/gitlab_shell.rb b/lib/gitlab_shell.rb index 971b22f..f72ce74 100644 --- a/lib/gitlab_shell.rb +++ b/lib/gitlab_shell.rb @@ -1,4 +1,5 @@ require 'shellwords' +require 'pathname' require_relative 'gitlab_net' @@ -150,6 +151,14 @@ class GitlabShell env.merge!({ 'GIT_ANNEX_SHELL_LIMITED' => '1' }) end + if git_trace_available? + env.merge!({ + 'GIT_TRACE' => @config.git_trace_log_file, + 'GIT_TRACE_PACKET' => @config.git_trace_log_file, + 'GIT_TRACE_PERFORMANCE' => @config.git_trace_log_file, + }) + end + Kernel::exec(env, *args, unsetenv_others: true) end @@ -232,6 +241,23 @@ class GitlabShell end end + def git_trace_available? + return false unless @config.git_trace_log_file + + if Pathname(@config.git_trace_log_file).relative? + $logger.warn "gitlab-shell: is configured to trace git commands with #{@config.git_trace_log_file.inspect} but an absolute path needs to be provided" + return false + end + + begin + File.open(@config.git_trace_log_file, 'a') { nil } + return true + rescue => ex + $logger.warn "gitlab-shell: is configured to trace git commands with #{@config.git_trace_log_file.inspect} but it's not possible to write in that path #{ex.message}" + return false + end + end + def repo_path=(repo_path) raise ArgumentError, "Repository path not provided. Please make sure you're using GitLab v8.10 or later." unless repo_path raise InvalidRepositoryPathError if File.absolute_path(repo_path) != repo_path -- cgit v1.2.1