[#748] Use SCM commands to detect the revision

This commit is contained in:
Holger Just 2011-12-15 22:02:10 +01:00
parent b2998c3972
commit 611889f3f7
2 changed files with 10 additions and 3 deletions

View File

@ -38,7 +38,14 @@ module ChiliProject
end end
def self.revision def self.revision
`git --git-dir="#{Rails.root.join('.git')}" rev-parse --short=9 HEAD`.chomp if File.directory? Rails.root.join('.git') @revision ||= begin
git = Redmine::Scm::Adapters::GitAdapter
git_dir = Rails.root.join('.git')
if File.directory? git_dir
git.send(:shellout, "#{git.sq_bin} --git-dir='#{git_dir}' rev-parse --short=9 HEAD") { |io| io.read }.to_s.chomp
end
end
end end
REVISION = self.revision REVISION = self.revision

View File

@ -19,10 +19,10 @@ module Redmine
module Adapters module Adapters
class GitAdapter < AbstractAdapter class GitAdapter < AbstractAdapter
SCM_GIT_REPORT_LAST_COMMIT = true SCM_GIT_REPORT_LAST_COMMIT = true unless defined?(SCM_GIT_REPORT_LAST_COMMIT)
# Git executable name # Git executable name
GIT_BIN = Redmine::Configuration['scm_git_command'] || "git" GIT_BIN = Redmine::Configuration['scm_git_command'] || "git" unless defined?(GIT_BIN)
# raised if scm command exited with error, e.g. unknown revision. # raised if scm command exited with error, e.g. unknown revision.
class ScmCommandAborted < CommandFailed; end class ScmCommandAborted < CommandFailed; end