Rails 3 app, How to get GIT version and update website?

前端 未结 4 1980
别那么骄傲
别那么骄傲 2021-02-08 17:59

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?

4条回答
  •  时光取名叫无心
    2021-02-08 18:53

    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?

提交回复
热议问题