Blankman Blankman - 7 days ago 6x
Git Question

Rails 3 app, How to get GIT version and update website?

I am deploying my rails 3 app using capistrano, and I want to get the git version (and date information) and update my website's footer with this.

How can I do this?


Based on David's direction, I solved this by creating an initializer "git_info.rb". Place this file in your Rails initializers directory

The contents of the git_info.rb are:

GIT_BRANCH = `git status | sed -n 1p`.split(" ").last
GIT_COMMIT = `git log | sed -n 1p`.split(" ").last

Then in your footer, you can use this output (HAML syntax):

  = "branch: #{GIT_BRANCH} | commit: #{GIT_COMMIT}"

You may want to set the font color of #rev_info the same as the background color, so the text is visible only when you highlight it with your cursor.

I just tried this, and while it works in development mode, it seems like the branch gets over-written with "deploy" post capistrano deploy. Capistrano must be creating it's own local branch called "deploy" on deploy?