summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRémy Coutable <remy@rymai.me>2016-09-27 14:29:51 +0000
committerRémy Coutable <remy@rymai.me>2016-09-27 14:29:51 +0000
commit0b4fd0af16555b2bdc28f6b18781d72226c5d56c (patch)
treec3a252d71cab51e47d4f1a03c40abe0a1851f6f2 /lib
parentb71ca5da9fde4fa8457af146bd090ec7caa28d60 (diff)
parent192e2bd367494bf66746c8971896a2d9cb84fc92 (diff)
downloadgitlab-shell-3.6.2.tar.gz
Merge branch '59-git-tracing' into 'master' v3.6.2
Enable GIT_TRACE_PERFORMANCE through a config variable. The value of the variable must an absolute path needs to exist so we’re able to check if we can write in that file. Because in the case we cannot write we’ll throw a warning to the output of the users. ```sh ~/dev/gitlab/local/pacoguzman/gitlab-ce (master=)$ git push origin master warning: could not open '/wadus' for tracing: Permission denied Everything up-to-date ``` Closes #59 See merge request !91
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab_config.rb4
-rw-r--r--lib/gitlab_shell.rb26
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