{"thread":{"id":"18349","subject":"Generate version file by hooks","startedAt":"2009-03-17T15:26:00Z","lastAt":"2009-03-17T15:43:31Z","messageCount":2,"participants":["Björn Hendriks","Santi Béjar"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"108236","messageId":"200903171626.01102.bjoern01@nurfuerspam.de","threadId":"18349","inReplyTo":null,"subject":"Generate version file by hooks","fromName":"Björn Hendriks","fromEmail":"bjoern01@nurfuerspam.de","sentAt":"2009-03-17T15:26:00Z","receivedAt":"2009-03-17T15:26:00Z","isPatch":false,"sender":{"key":"bjoern01@nurfuerspam.de","avatar":null},"body":"\nHello,\n\nI'd like to put the SHA1 of the current commit into a source file so that my \nprogram can further process it -- put it into a log file for example.\n\nMy idea is to write a script which reads the SHA1 of the current commit with \nthe call\n\ngit log -1 --pretty=format:\"%H\"\n\n(git-describe is not suitable for me) and then generates the wanted source \nfile.  To avoid accidentally committing that file I will put its name \ninto .git/info/exclude.\n\nI already put the call to my experimental generator script into the hooks \npost-checkout and post-commit, so it will be called if I do a commit or a \ncheckout of another branch.\n\nMy problem is, that my script won't be called if I do a git-pull, a git-reset \nor a git-merge without conflicts resulting in workfiles of a new commit.  \nMaybe there are more git calls which change the current commit I haven't \nthought of yet?\n\nSo my question: How to make git call my script automatically in all cases \nwhere git changes the currently checked out commit?\n\nMaybe there are different solutions to put the current SHA1 into a source \nfile?\n\nOf course I know that it's still possible to change the working files without \ngit's notice resulting in an inconsistent commit SHA1.  But before doing any \ntest runs I normally check with git-status that all files are in a committed \nstate but that won't reveal if my generated version file is not up to date.\n\nI use git version 1.5.4.3 and would like to stick to it for some reason if \npossible.\n\nThanks for your help\nBjörn\n"},{"id":"108241","messageId":"adf1fd3d0903170843r3649eb53tf8b22240bbc20e33@mail.gmail.com","threadId":"18349","inReplyTo":"200903171626.01102.bjoern01@nurfuerspam.de","subject":"Re: Generate version file by hooks","fromName":"Santi Béjar","fromEmail":"santi@agolina.net","sentAt":"2009-03-17T15:43:31Z","receivedAt":"2009-03-17T15:43:31Z","isPatch":false,"sender":{"key":"santi@agolina.net","avatar":null},"body":"2009/3/17 Björn Hendriks <bjoern01@nurfuerspam.de>:\n>\n> Hello,\n>\n> I'd like to put the SHA1 of the current commit into a source file so that my\n> program can further process it -- put it into a log file for example.\n\nYou can look at what is done in git itself with the version number.\nThere is a GIT-VERSION-GEN that generates a GIT-VERSION-FILE with the\nversion number (it only updates the file if the version number has\nchanged). Then in the makefile you specify how to create it and which\nprograms depend on the GIT-VERSION-FILE:\n\nGIT-VERSION-FILE: .FORCE-GIT-VERSION-FILE\n        @$(SHELL_PATH) ./GIT-VERSION-GEN\n-include GIT-VERSION-FILE\n\nprogram: GIT-VERSION-FILE\n\nHTH,\nSanti\n"}]}