diff options
author | Toshi MARUYAMA <marutosijp2@yahoo.co.jp> | 2011-02-15 07:04:29 +0000 |
---|---|---|
committer | Toshi MARUYAMA <marutosijp2@yahoo.co.jp> | 2011-02-15 07:04:29 +0000 |
commit | a9429df880f588f4df05c736afa18ca668a0c6ec (patch) | |
tree | a106b6ce5968c12d46bd2a42ef9a36178863a2f1 /lib/redmine/scm | |
parent | 4f1b1d9242284f8cd6ea7b7705fdca3c85b40222 (diff) | |
download | redmine-a9429df880f588f4df05c736afa18ca668a0c6ec.tar.gz redmine-a9429df880f588f4df05c736afa18ca668a0c6ec.zip |
scm: mercurial: add new method 'hg' to wrap shellout (#4455).
Contributed by Yuya Nishihara.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4830 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'lib/redmine/scm')
-rw-r--r-- | lib/redmine/scm/adapters/mercurial_adapter.rb | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/lib/redmine/scm/adapters/mercurial_adapter.rb b/lib/redmine/scm/adapters/mercurial_adapter.rb index 58e9a269a..ea022c339 100644 --- a/lib/redmine/scm/adapters/mercurial_adapter.rb +++ b/lib/redmine/scm/adapters/mercurial_adapter.rb @@ -29,6 +29,9 @@ module Redmine TEMPLATE_NAME = "hg-template" TEMPLATE_EXTENSION = "tmpl" + # raised if hg command exited with error, e.g. unknown revision. + class HgCommandAborted < CommandFailed; end + class << self def client_command @@bin ||= HG_BIN @@ -226,6 +229,20 @@ module Redmine end end + # Runs 'hg' command with the given args + def hg(*args, &block) + full_args = [HG_BIN, '--cwd', url, '--encoding', 'utf-8'] + full_args << '--config' << "extensions.redminehelper=#{HG_HELPER_EXT}" + full_args << '--config' << 'diff.git=false' + full_args += args + ret = shellout(full_args.map { |e| shell_quote e.to_s }.join(' '), &block) + if $? && $?.exitstatus != 0 + raise HgCommandAborted, "hg exited with non-zero status: #{$?.exitstatus}" + end + ret + end + private :hg + # Returns correct revision identifier def hgrev(identifier, sq=false) rev = identifier.blank? ? 'tip' : identifier.to_s |