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?
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?
Often one does not deploy into a git repository, but into a release which does not contain any repository information:
Capistrano stores a revision file with each successful deployment which is the git commit sha. This file is called
REVISION
and can be found in the root of the deployment directory.In config/initializers of your Rails app, create a file: deploy_version.rb with something like:
Or if sure that outside of deployment there is always a git repository one can replace the last assignment with
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:
Then in your footer, you can use this output (HAML syntax):
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?
Long time ago I did this for subversion:
in an initializer I put a global
and in the application layout:
with git you could change the global to something like:
Now thinking about it, it may be better to:
I'm not sure, it's just an idea.
To people that doesn't use capistrano, a prettier one:
On config/initializers/git_info.rb:
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.