Rails 3应用程序,如何获得GIT版本和更新网站? [英] Rails 3 app, How to get GIT version and update website?
问题描述
我正在使用capistrano部署我的rails 3应用程序,并且我想要获取git版本(和日期信息)并更新我的网站页脚。
我可以这样做吗?
基于David的指导,我通过创建初始化程序git_info.rb解决了这个问题。将这个文件放在你的Rails初始化器目录中。
git_info.rb的内容是:
pre> GIT_BRANCH =`git status | sed -n 1p`.split().last
GIT_COMMIT =`git log | sed -n 1p`.split().last
然后在您的页脚中,您可以使用这个输出(HAML语法):
#rev_info
=分支:#{GIT_BRANCH} | commit:#{ GIT_COMMIT}
您可能希望将#rev_info的字体颜色设置为与背景颜色相同,所以文本只有在用光标突出显示时才是可见的。
我刚刚尝试了这一点,并且在开发模式下工作时,用部署post capistrano部署编写。 Capistrano必须在部署时创建自己的本地分支,称为部署?
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):
#rev_info
= "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?
这篇关于Rails 3应用程序,如何获得GIT版本和更新网站?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!