Rails 3应用程序,如何获得GIT版本和更新网站? [英] Rails 3 app, How to get GIT version and update website?

查看:92
本文介绍了Rails 3应用程序,如何获得GIT版本和更新网站?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆