Skip to content

Instantly share code, notes, and snippets.

@mhaley
Created September 30, 2009 17:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mhaley/198268 to your computer and use it in GitHub Desktop.
Save mhaley/198268 to your computer and use it in GitHub Desktop.
# Call +git+ and obtain the current commit SHA1 and commit date. Store these values
# in +APP_VERSION_COMMIT_ID+ and +APP_VERSION_COMMIT_DATE+. Then define
# +APP_VERSION+ to be a string of the two.
git_cmd = 'git show --pretty=format:"%H|%ci" --quiet'
commit_id = nil
commit_date = nil
begin
unless RAILS_ENV=='test'
commit_id, commit_date = IO.popen(git_cmd) {|f|
log_entry = f.gets
log_entry.split("|") unless log_entry.nil?
}
else
commit_id, commit_date = '',''
end
rescue Errno::ENOENT # git not installed
commit_id = 'Unknown'
commit_date = ''
end
unless defined?(::APP_VERSION)
APP_VERSION_COMMIT_ID = commit_id
APP_VERSION_COMMIT_DATE = commit_date
APP_VERSION = "#{commit_id} #{commit_date}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment