Skip to content

Instantly share code, notes, and snippets.

@tkawachi
Created September 13, 2012 11:49
Show Gist options
  • Select an option

  • Save tkawachi/3713816 to your computer and use it in GitHub Desktop.

Select an option

Save tkawachi/3713816 to your computer and use it in GitHub Desktop.
# coding: UTF-8
class GitUtil
class << self
# Current source code revision
def revision
rev = capistrano_revision
rev = command_revision unless rev
rev.try(:chomp)
end
private
def capistrano_revision
begin
revision_file = "#{Rails.root}/REVISION"
return File.read(revision_file) if File.exists? revision_file
rescue IOError => e
Rails.logger.info(e)
end
nil
end
def command_revision
rev = `cd '#{Rails.root}' && git rev-list --max-count=1 HEAD`
$? == 0 ? rev : nil
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment