views:

2045

answers:

4

Browsing through the git documentation, I can't see anything analogous to SVN's commit hooks or the "propset" features that can, say, update a version number or copyright notice within a file whenever it is committed to the repository.

Are git users expected to write external scripts for this sort of functionality (which doesn't seem out of the question) or have I just missed something obvious?

Edit : Just to be clear, I'm more interested in, e.g.,

svn propset svn:keywords "Author Date Id Revision" expl3.dtx

where a string like this:

$Id: expl3.dtx 780 2008-08-30 12:32:34Z morten $

is kept up-to-date with the relevant info whenever a commit occurs.

+1  A: 

Perhaps the most common SVN property, 'svn:ignore' is done through the .gitignore file, rather than metadata. I'm afraid I don't have anything more helpful for the other kinds of metadata.

James A. Rosen
+3  A: 

Quoting from the Git FAQ:

Does git have keyword expansion?

Not recommended. Keyword expansion causes all sorts of strange problems and isn't really useful anyway, especially within the context of an SCM. Outside git you may perform keyword expansion using a script. The Linux kernel export script does this to set the EXTRA_VERSION variable in the Makefile.

See gitattributes(5) if you really want to do this. If your translation is not reversible (eg SCCS keyword expansion) this may be problematic.

Jordi Bunster
+1  A: 

Git does have pre-commit and post-commit hooks, they are located inside each .git/hooks directory. Just modify the files and chmod them to make them executable.

georg
+2  A: 

I wrote up a fairly complete answer to this elsewhere, with code showing how to do it. A summary:

  1. You probably don't want to do this. Using git describe is a reasonable alternative.
  2. If you do need to do this, $Id$ and $Format$ are fairly easy.
  3. Anything more advanced will require using gitattributes and a custom filter. I provide an example implementation of $Date$.

Solutions based on hook functions are generally not helpful, because they make your working copy dirty.

emk