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?

To people that doesn't use capistrano, a prettier one:

On config/initializers/git_info.rb:

GIT_BRANCH = `git symbolic-ref HEAD 2>/dev/null | cut -d"/" -f 3`
GIT_COMMIT = `git log --pretty=format:'%h' -n 1`
GIT_COMMIT_TIMESTAMP = `git log --pretty=format:'%ct' -n 1`

The second one gives the sha in prettier form (ex: 4df21c0).

The third one returns the UNIX TIMESTAMP, that I format using Time/DateTime later.

Need Your Help

Resharper force line break before dot

c# asp.net resharper

How do you force line breaks before the dot?

Copy a file without using the windows file cache

c# windows winapi filesystems file-copying

Anybody know of a way to copy a file from path A to path B and suppressing the Windows file system cache?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.