scm: git: add new method 'scm_cmd' to wrap shellout.

Refer Mercurial adapter r4830.

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4886 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Toshi MARUYAMA 2011-02-20 01:33:30 +00:00
parent 915107a0ec
commit 1c5cd49cd2
1 changed files with 19 additions and 3 deletions

View File

@ -24,6 +24,9 @@ module Redmine
# Git executable name
GIT_BIN = Redmine::Configuration['scm_git_command'] || "git"
# raised if scm command exited with error, e.g. unknown revision.
class ScmCommandAborted < CommandFailed; end
class << self
def client_command
@@bin ||= GIT_BIN
@ -300,6 +303,19 @@ module Redmine
identifier[0,8]
end
end
def scm_cmd(*args, &block)
repo_path = root_url || url
full_args = [GIT_BIN, '--git-dir', repo_path]
full_args += args
full_args << '--no-color'
ret = shellout(full_args.map { |e| shell_quote e.to_s }.join(' '), &block)
if $? && $?.exitstatus != 0
raise ScmCommandAborted, "git exited with non-zero status: #{$?.exitstatus}"
end
ret
end
private :scm_cmd
end
end
end