简体   繁体   English

如何在该应用程序中显示rails应用程序的git分支?

[英]How can I show the git branch of a rails app within that app?

I've got a couple of different branches of a rails app running in a development environment on the same server (on separate databases, obv), and I'd like to make it very clear what branch is being shown when I hit the app through the web. 我在同一台服务器(在不同的数据库,obv)上的开发环境中运行了一个rails应用程序的几个不同分支,我想清楚地说明当我点击应用程序时显示的分支是什么通过网络。

Any ideas, short of running git-branch or git-symbolic-ref HEAD in backticks and parsing the output? 任何想法,缺少在反引号中运行git-branchgit-symbolic-ref HEAD并解析输出?

Check out Grit , it allows you to read a Git repository using Ruby. 查看Grit ,它允许您使用Ruby读取Git存储库。

repository = Grit::Repo.new(RAILS_ROOT)
repository.head.name # => "master"

Actually, as you suggested, shelling out is the right thing to do. 实际上,正如你的建议,炮轰是正确的。

If you're afraid somehow git might not be available to the app, you might try reading the file .git/HEAD . 如果您害怕应用程序可能无法使用git ,您可以尝试阅读.git/HEAD文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM