diff options
author | Toshi MARUYAMA <marutosijp2@yahoo.co.jp> | 2011-02-20 01:33:30 +0000 |
---|---|---|
committer | Toshi MARUYAMA <marutosijp2@yahoo.co.jp> | 2011-02-20 01:33:30 +0000 |
commit | 1c5cd49cd276eb1c1a2792d5d443da6e3531a69b (patch) | |
tree | a816bc93a98172440bf76a4ad83a17aae99c7484 /lib | |
parent | 915107a0ec04a0703bdb381061eeb83d38fe38a7 (diff) | |
download | redmine-1c5cd49cd276eb1c1a2792d5d443da6e3531a69b.tar.gz redmine-1c5cd49cd276eb1c1a2792d5d443da6e3531a69b.zip |
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
Diffstat (limited to 'lib')
-rw-r--r-- | lib/redmine/scm/adapters/git_adapter.rb | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/lib/redmine/scm/adapters/git_adapter.rb b/lib/redmine/scm/adapters/git_adapter.rb index f6a9b0d7c..d23fc2240 100644 --- a/lib/redmine/scm/adapters/git_adapter.rb +++ b/lib/redmine/scm/adapters/git_adapter.rb @@ -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 @@ -82,9 +85,9 @@ module Redmine end def default_branch - branches.include?('master') ? 'master' : branches.first + branches.include?('master') ? 'master' : branches.first end - + def entries(path=nil, identifier=nil) path ||= '' entries = Entries.new @@ -279,7 +282,7 @@ module Redmine end blame end - + def cat(path, identifier=nil) if identifier.nil? identifier = 'HEAD' @@ -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 |