]> source.dussan.org Git - redmine.git/commitdiff
scm: mercurial: add new method 'hg' to wrap shellout (#4455).
authorToshi MARUYAMA <marutosijp2@yahoo.co.jp>
Tue, 15 Feb 2011 07:04:29 +0000 (07:04 +0000)
committerToshi MARUYAMA <marutosijp2@yahoo.co.jp>
Tue, 15 Feb 2011 07:04:29 +0000 (07:04 +0000)
Contributed by Yuya Nishihara.

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4830 e93f8b46-1217-0410-a6f0-8f06a7374b81

lib/redmine/scm/adapters/mercurial_adapter.rb

index 58e9a269a01bfddcd21c228406f05f9174d21c30..ea022c3394ad9abbfbe83c0b5cfd9f583a25ca5e 100644 (file)
@@ -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