Generate version file by hooks

2 messages, 2 authors, 2016-06-15 · open the first message on its own page

Generate version file by hooks

From: Björn Hendriks <hidden>
Date: 2016-06-15 22:46:24

Hello,

I'd like to put the SHA1 of the current commit into a source file so that my 
program can further process it -- put it into a log file for example.

My idea is to write a script which reads the SHA1 of the current commit with 
the call

git log -1 --pretty=format:"%H"

(git-describe is not suitable for me) and then generates the wanted source 
file.  To avoid accidentally committing that file I will put its name 
into .git/info/exclude.

I already put the call to my experimental generator script into the hooks 
post-checkout and post-commit, so it will be called if I do a commit or a 
checkout of another branch.

My problem is, that my script won't be called if I do a git-pull, a git-reset 
or a git-merge without conflicts resulting in workfiles of a new commit.  
Maybe there are more git calls which change the current commit I haven't 
thought of yet?

So my question: How to make git call my script automatically in all cases 
where git changes the currently checked out commit?

Maybe there are different solutions to put the current SHA1 into a source 
file?

Of course I know that it's still possible to change the working files without 
git's notice resulting in an inconsistent commit SHA1.  But before doing any 
test runs I normally check with git-status that all files are in a committed 
state but that won't reveal if my generated version file is not up to date.

I use git version 1.5.4.3 and would like to stick to it for some reason if 
possible.

Thanks for your help
Björn

Re: Generate version file by hooks

From: Santi Béjar <hidden>
Date: 2016-06-15 22:46:24

2009/3/17 Björn Hendriks [off-list ref]:
Hello,

I'd like to put the SHA1 of the current commit into a source file so that my
program can further process it -- put it into a log file for example.
You can look at what is done in git itself with the version number.
There is a GIT-VERSION-GEN that generates a GIT-VERSION-FILE with the
version number (it only updates the file if the version number has
changed). Then in the makefile you specify how to create it and which
programs depend on the GIT-VERSION-FILE:

GIT-VERSION-FILE: .FORCE-GIT-VERSION-FILE
        @$(SHELL_PATH) ./GIT-VERSION-GEN
-include GIT-VERSION-FILE

program: GIT-VERSION-FILE

HTH,
Santi
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help