Hey,

I created a small package: http://hackage.haskell.org/package/vcs-revision , repo http://github.com/jkff/vcs-revision

It can be used like this:
{-# LANGUAGE TemplateHaskell #-}
 import Distribution.VcsRevision.Git
 import Language.Haskell.TH.Syntax

 showMyGitVersion :: String
 showMyGitVersion = $(do
   v <- qRunIO getRevision
   lift $ case v of
     Nothing           -> "<none>"
     Just (hash,True)  -> hash ++ " (with local modifications)"
     Just (hash,False) -> hash)

On Wed, Feb 22, 2012 at 2:26 PM, Herbert Valerio Riedel <hvr@gnu.org> wrote:
Hi,

Eugene Kirpichov <ekirpichov@gmail.com> writes:

> I'd like my program to print something like "this is $program 1.0.4 git
> 45fea6b" when invoked with --version, or at least just the 1.0.4 part.

Here's some proof-of-concept code we use slightly modified in production
here for over a year now successfully:

 https://gist.github.com/656738

The primary goal was to have a reliable version number (allowing to find
the exact corresponding git-commit in the source-code repository), and
to be able to detect when that version number is unreliable (there's
nothing more annoying than wasting time debugging the wrong
source-code...).

The idea is to dynamically infer and overwrite cabal's version when
building from the git repository, and have it accessible via the cabal's
auto-generated "Paths_<pkg-name>" module Data.Version...

...and when creating a source-dist, via "runghc Setup.hs sdist" the
current dynamic git-version string is embedded into the generated
.tar.gz's .cabal file, so that the source-distribution is just a plain
simple .cabal project (that could be uploaded to hackage)

hth,
hvr
--



--
Eugene Kirpichov
Principal Engineer, Mirantis Inc. http://www.mirantis.com/
Editor, http://fprog.ru/