Created
September 13, 2012 11:49
-
-
Save tkawachi/3713816 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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