Skip to content

Commit

Permalink
Display git revision on every page
Browse files Browse the repository at this point in the history
  • Loading branch information
bryanstearns committed Mar 20, 2012
1 parent 2678efb commit db11b19
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/views/layouts/application.html.erb
Expand Up @@ -7,6 +7,7 @@
<%= csrf_meta_tags %>
</head>
<body>
<div style="float: right; color: #ccc;"><%= SOURCE_REVISION_DETAILS %></div>

<%= yield %>

Expand Down
38 changes: 38 additions & 0 deletions config/initializers/ascertain_revision.rb
@@ -0,0 +1,38 @@

# "Ascertain" the revision we're running (so named so it'll come before
# the cache initializer, which uses this info).

def determine_revision
# Note the revision number we're running, and a
# more-informative string containing it.
revision_path = File.dirname(__FILE__) + "/../../REVISION"
begin
digits = 8
if File.exist? revision_path
mod_date = File.mtime(revision_path)
full_number = File.read(revision_path).strip
number = full_number[0...digits]
extra = mod_date.strftime("%H:%M %a, %b %d %Y").gsub(" 0"," ")
else
if File.exist?(".git")
full_number = `git log -1`.split(" ")[1]
number = full_number[0...digits]
extra = `git branch`.split("\n").grep(/^\*/)[0].split(' ')[-1]
else
# We don't use --xml anymore, because CentOS's svn doesn't have it.
number = `svn info`.grep(%r"^Revision: ")[0].split(" ")[1]
extra = ''
end
end
rescue
number = '???'
extra = ''
end
details = "#{Rails.env} #{number} #{extra} #{Socket.gethostname}"
return full_number, number, details
end

FULL_SOURCE_REVISION_NUMBER, SOURCE_REVISION_NUMBER, SOURCE_REVISION_DETAILS = determine_revision

# Add this to the environment too, so it'll be visible in Hoptoad
ENV["SOURCE_REVISION_DETAILS"] = SOURCE_REVISION_DETAILS

0 comments on commit db11b19

Please sign in to comment.