diff options
author | Paco Guzman <pacoguzmanp@gmail.com> | 2016-09-15 15:45:10 +0200 |
---|---|---|
committer | Paco Guzman <pacoguzmanp@gmail.com> | 2016-09-27 12:37:36 +0200 |
commit | 192e2bd367494bf66746c8971896a2d9cb84fc92 (patch) | |
tree | c3a252d71cab51e47d4f1a03c40abe0a1851f6f2 /lib | |
parent | b71ca5da9fde4fa8457af146bd090ec7caa28d60 (diff) | |
download | gitlab-shell-59-git-tracing.tar.gz |
Enable GIT_TRACE/GIT_TRACE_PACKET/GIT_TRACE_PERFORMANCE by providing the git_trace_log_file config key59-git-tracing
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.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab_config.rb | 4 | ||||
-rw-r--r-- | lib/gitlab_shell.rb | 26 |
2 files changed, 30 insertions, 0 deletions
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 |