diff --git a/lib/redmine_git_hosting/commands/git.rb b/lib/redmine_git_hosting/commands/git.rb index 21e9d548ab5..4d7dfa72246 100644 --- a/lib/redmine_git_hosting/commands/git.rb +++ b/lib/redmine_git_hosting/commands/git.rb @@ -13,7 +13,11 @@ module Git # Send Git command with Sudo # def sudo_git(*params) - cmd = sudo_git_cmd.concat(params) + if RedmineGitHosting::Config.gitolite_use_sudo? + cmd = sudo_git_cmd.concat(params) + else + cmd = ['git'].concat(params) + end capture(cmd) end @@ -67,7 +71,7 @@ def sudo_set_git_global_param(namespace, key, value) # Return a hash with global config parameters. def sudo_get_git_global_params(namespace) begin - params = sudo_git('config', '-f', '.gitconfig', '--get-regexp', namespace).split("\n") + params = sudo_git('config', '--get-regexp', namespace).split("\n") rescue RedmineGitHosting::Error::GitoliteCommandException => e logger.error("Problems to retrieve Gitolite hook parameters in Gitolite config 'namespace : #{namespace}'") params = [] diff --git a/lib/redmine_git_hosting/commands/gitolite.rb b/lib/redmine_git_hosting/commands/gitolite.rb index 43f4a5d68c8..1c77aaac623 100644 --- a/lib/redmine_git_hosting/commands/gitolite.rb +++ b/lib/redmine_git_hosting/commands/gitolite.rb @@ -46,8 +46,14 @@ def sudo_repository_empty?(repo_path) def sudo_git_objects_count(repo_path) + if RedmineGitHosting::Config.gitolite_use_sudo? + cmd = ['eval', 'find', repo_path, '-type', 'f', '|', 'wc', '-l'] + else + cmd = ['bash', '-c', "find #{repo_path} -type f | wc -l"] + end + begin - sudo_capture('eval', 'find', repo_path, '-type', 'f', '|', 'wc', '-l') + sudo_capture(*cmd) rescue RedmineGitHosting::Error::GitoliteCommandException => e logger.error("Can't retrieve Git objects count : #{e.output}") 0 diff --git a/lib/redmine_git_hosting/commands/sudo.rb b/lib/redmine_git_hosting/commands/sudo.rb index 032e0b65120..2dbccfbc8ff 100644 --- a/lib/redmine_git_hosting/commands/sudo.rb +++ b/lib/redmine_git_hosting/commands/sudo.rb @@ -168,7 +168,11 @@ def sudo_pipe_data(stdin) # Return the Sudo command with basic args. # def sudo - ['sudo', *sudo_shell_params] + if RedmineGitHosting::Config.gitolite_use_sudo? + ['sudo', *sudo_shell_params] + else + [] + end end diff --git a/lib/redmine_git_hosting/config/gitolite_base.rb b/lib/redmine_git_hosting/config/gitolite_base.rb index af2a8a21484..82a0bc0fc33 100644 --- a/lib/redmine_git_hosting/config/gitolite_base.rb +++ b/lib/redmine_git_hosting/config/gitolite_base.rb @@ -18,6 +18,11 @@ def redmine_user end + def gitolite_use_sudo? + redmine_user != gitolite_user + end + + def gitolite_home_dir @gitolite_home_dir ||= Etc.getpwnam(gitolite_user).dir rescue nil end diff --git a/lib/redmine_git_hosting/config/gitolite_config_tests.rb b/lib/redmine_git_hosting/config/gitolite_config_tests.rb index 0bb12970325..c0b94052684 100644 --- a/lib/redmine_git_hosting/config/gitolite_config_tests.rb +++ b/lib/redmine_git_hosting/config/gitolite_config_tests.rb @@ -66,7 +66,7 @@ def temp_dir_writeable?(opts = {}) ## SUDO TEST1 def can_redmine_sudo_to_gitolite_user? - return true if gitolite_user == redmine_user + return true unless gitolite_use_sudo? file_logger.info("Testing if Redmine user '#{redmine_user}' can sudo to Gitolite user '#{gitolite_user}'...") result = execute_sudo_test(gitolite_user) do RedmineGitHosting::Commands.sudo_capture('whoami')