HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Modulegitrev-1.3.1Haskell2010

Development.GitRev

Some handy Template Haskell splices for including the current git hash and branch in the code of your project. Useful for including in panic messages, --version output, or diagnostic info for more informative bug reports.

{-# LANGUAGE TemplateHaskell #-}
import Development.GitRev

panic :: String -> a
panic msg = error panicMsg
  where panicMsg =
          concat [ "[panic ", $(gitBranch), "@", $(gitHash)
                 , " (", $(gitCommitDate), ")"
                 , " (", $(gitCommitCount), " commits in HEAD)"
                 , dirty, "] ", msg ]
        dirty | $(gitDirty) = " (uncommitted files present)"
              | otherwise   = ""

main = panic "oh no!"
% cabal exec runhaskell Example.hs
Example.hs: [panic master@2ae047ba5e4a6f0f3e705a43615363ac006099c1 (Mon Jan 11 11:50:59 2016 -0800) (14 commits in HEAD) (uncommitted files present)] oh no!
  • 7 values
  • Packagegitrev-1.3.1
  • Exports7
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceGitRev.hs
valuegitBranch :: ExpQ
#

Return the branch (or tag) name of the current git commit, or UNKNOWN if not in a git repository. For detached heads, this will just be HEAD

valuegitDescribe :: ExpQ
#

Return the long git description for the current git commit, or UNKNOWN if not in a git repository.

valuegitDirty :: ExpQ
#

Return True if there are non-committed files present in the repository

valuegitDirtyTracked :: ExpQ
#

Return True if there are non-commited changes to tracked files present in the repository

valuegitHash :: ExpQ
#

Return the hash of the current git commit, or UNKNOWN if not in a git repository