views:

43

answers:

3

Hi Everyone,

I have a few Rails applications and I use Git as the version control system. I use either GitHub or Beanstalk as the repository hosts.

What I am trying to is quite simple in theory. Somehow show the latest commit ID number (hash?) in the footer of the web application. So that when I am looking at the web application I can check that it's committed and deployed correctly.

I can imagine there are two methods to tackle this. The first would be a possible feature of Git that allows the output of the commit ID. The second would be a post-commit web hook (both Beanstalk and GitHub allow this).

Has anyone ever found a way to do this, or something similar?

Thanks,

Danny

+2  A: 

I believe what you'll end up wanting to do is, as a part of your "build" process (deployment, your case?), store the output of git rev-parse HEAD or git describe HEAD (better, assuming you tag releases) in a file. Your app can then display the contents of the file. The commit hash can't ever actually be part of any tracked content (the hash of the commit depends on the tracked content). Of course, if your app is running out of a repo, you could simply run the command from the app, but it's a lot more elegant to just do it once.

This is the approach taken by git itself, by the way. It has a teeny shell script which basically dumps git describe output to GIT-VERSION-FILE, which is then compiled in to provide the version information.

Hopefully I haven't misunderstood your situation - I'm a little confused by you saying "a possible feature of Git that allows the output of the commit ID". This is a very basic capability of git.

Jefromi
"Hopefully I haven't misunderstood your situation - I'm a little confused by you saying "a possible feature of Git that allows the output of the commit ID". This is a very basic capability of git."I don't think you have misunderstood - it's the way I have explained it...overcomplicated as always!I was hoping there would be a way of having a piece of code in my view that just outputs the current build version. The simplest way I could think of was the GIT HEAD value.
dannymcc
A: 

First, the answer to your question, run the following command in your ruby script:

`git log -n1 | head -1`.split.last

Second: What do you mean you use beanstalk as your repository host? Isn't beanstalk a queueing server?

Faisal
BeanstalkApp is a competitor to GitHub: http://beanstalkapp.com/
dannymcc
aah, though you were referring to beanstalkd: http://kr.github.com/beanstalkd/
Faisal
Use `git rev-parse HEAD`, not `git log -n1 | ...`
Jakub Narębski
+2  A: 
Jakub Narębski