Skip to content

Commit

Permalink
Add support for 'one user' mode (fix #526)
Browse files Browse the repository at this point in the history
  • Loading branch information
root committed Dec 30, 2016
1 parent af0d817 commit aa52075
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 5 deletions.
8 changes: 6 additions & 2 deletions lib/redmine_git_hosting/commands/git.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 = []
Expand Down
8 changes: 7 additions & 1 deletion lib/redmine_git_hosting/commands/gitolite.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion lib/redmine_git_hosting/commands/sudo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
5 changes: 5 additions & 0 deletions lib/redmine_git_hosting/config/gitolite_base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/redmine_git_hosting/config/gitolite_config_tests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit aa52075

Please sign in to comment.