git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Generate version file by hooks
@ 2009-03-17 15:26 Björn Hendriks
  2009-03-17 15:43 ` Santi Béjar
  0 siblings, 1 reply; 5+ messages in thread
From: Björn Hendriks @ 2009-03-17 15:26 UTC (permalink / raw)
  To: git


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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Generate version file by hooks
@ 2009-03-17 15:42 John Dlugosz
  2009-03-17 16:40 ` Björn Hendriks
  0 siblings, 1 reply; 5+ messages in thread
From: John Dlugosz @ 2009-03-17 15:42 UTC (permalink / raw)
  To: git; +Cc: bjoern01

=== Re: ===
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.
=== end ===

Isn't that what the existing file HEAD is for?  Possibly with a level of
indirection.  So use 
	git rev-parse HEAD
any time you need that SHA1 value.  The HEAD is always updated, since
that _is_ what defines the "current" commit.

--John
(please excuse the footer; it's not my idea)

TradeStation Group, Inc. is a publicly-traded holding company (NASDAQ GS: TRAD) of three operating subsidiaries, TradeStation Securities, Inc. (Member NYSE, FINRA, SIPC and NFA), TradeStation Technologies, Inc., a trading software and subscription company, and TradeStation Europe Limited, a United Kingdom, FSA-authorized introducing brokerage firm. None of these companies provides trading or investment advice, recommendations or endorsements of any kind. The information transmitted is intended only for the person or entity to which it is addressed and may contain confidential and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited.
  If you received this in error, please contact the sender and delete the material from any computer.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Generate version file by hooks
  2009-03-17 15:26 Björn Hendriks
@ 2009-03-17 15:43 ` Santi Béjar
  0 siblings, 0 replies; 5+ messages in thread
From: Santi Béjar @ 2009-03-17 15:43 UTC (permalink / raw)
  To: Björn Hendriks; +Cc: git

2009/3/17 Björn Hendriks <bjoern01@nurfuerspam.de>:
>
> 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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Generate version file by hooks
  2009-03-17 15:42 Generate version file by hooks John Dlugosz
@ 2009-03-17 16:40 ` Björn Hendriks
  2009-03-17 16:54   ` Johannes Sixt
  0 siblings, 1 reply; 5+ messages in thread
From: Björn Hendriks @ 2009-03-17 16:40 UTC (permalink / raw)
  To: git; +Cc: John Dlugosz, Santi Béjar


Hi John, hi Santi,

thanks for your help.

On Dienstag 17 März 2009 16:42:01 John Dlugosz wrote:
> Isn't that what the existing file HEAD is for?  Possibly with a level of
> indirection.  So use
> 	git rev-parse HEAD
> any time you need that SHA1 value.  The HEAD is always updated, since
> that _is_ what defines the "current" commit.

That might be a good alternative to my call of git-log which I was not 
absolutely sure if it works under all circumstances.

In fact my problem is not to find out the SHA1 of the last commit in a script 
but to have that script called automatically each time git changes the 
commit. My idea was to use the git hooks for that, but as I explained I 
couldn't find hooks for all cases in which a commit changes.

I need git to do that because my application is a Matlab-project which I 
normally do not compile -- although there is a Matlab-compiler to get a 
standalone application, but within the Matlab environment you don't need to 
compile. It would be the same with my little bash-helper-scripts I manage 
also with the great assistance of git.

But now -- as I think of it -- I might as well put a script call into the 
Matlab-code to get the last SHA1 and find a different solution for the rare 
cases in which I really compile the Matlab-code.

Thanks
Björn

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Generate version file by hooks
  2009-03-17 16:40 ` Björn Hendriks
@ 2009-03-17 16:54   ` Johannes Sixt
  0 siblings, 0 replies; 5+ messages in thread
From: Johannes Sixt @ 2009-03-17 16:54 UTC (permalink / raw)
  To: Björn Hendriks; +Cc: git, John Dlugosz, Santi Béjar

Björn Hendriks schrieb:
> In fact my problem is not to find out the SHA1 of the last commit in a script 
> but to have that script called automatically each time git changes the 
> commit. My idea was to use the git hooks for that, but as I explained I 
> couldn't find hooks for all cases in which a commit changes.

In fact there are so many situations where the current commit changes. You
won't find enough hooks to catch all cases.

You better modify your build system to look for the current commit when it
is needed. That is *much* safer.

-- Hannes

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2009-03-17 16:56 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-03-17 15:42 Generate version file by hooks John Dlugosz
2009-03-17 16:40 ` Björn Hendriks
2009-03-17 16:54   ` Johannes Sixt
  -- strict thread matches above, loose matches on Subject: below --
2009-03-17 15:26 Björn Hendriks
2009-03-17 15:43 ` Santi Béjar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).