@@ -17,16 +17,18 @@
17-- > panic :: String -> a
17-- > panic :: String -> a
18-- > panic msg = error panicMsg
18-- > panic msg = error panicMsg
19-- > where panicMsg =
19-- > where panicMsg =
20−-- > concat [ "[panic ", $(gitBranch), "@", $(gitHash), dirty, "] ", msg ]
20+-- > concat [ "[panic ", $(gitBranch), "@", $(gitHash)
21+-- > , " (", $(gitCommitCount), " commits in HEAD)"
22+-- > , dirty, "] ", msg ]
21-- > dirty | $(gitDirty) = " (uncommitted files present)"
23-- > dirty | $(gitDirty) = " (uncommitted files present)"
22-- > | otherwise = ""
24-- > | otherwise = ""
24-- > main = panic "oh no!"
26-- > main = panic "oh no!"
26-- > % cabal exec runhaskell Example.hs
28-- > % cabal exec runhaskell Example.hs
27−-- > Example.hs: [panic master@4a0a592c37ad908889bd2a7a411923a903ed05a3 (uncommitted files present)] oh no!
29+-- > Example.hs: [panic master@2702e69355c978805064543489c351b61ac6760b (6 commits in HEAD) (uncommitted files present)] oh no!
29−module Development.GitRev (gitHash, gitBranch, gitDirty) where
31+module Development.GitRev (gitHash, gitBranch, gitDirty, gitCommitCount) where
31import Control.Applicative
33import Control.Applicative
32import Control.Exception
34import Control.Exception
@@ -103,3 +105,8 @@ gitDirty = do
103 case output of
105 case output of
104 "" -> conE $ mkName "Prelude.False"
106 "" -> conE $ mkName "Prelude.False"
105 _ -> conE $ mkName "Prelude.True"
107 _ -> conE $ mkName "Prelude.True"
109+-- | Return the number of commits in the current head
110+gitCommitCount :: ExpQ
112+ stringE =<< runGit ["rev-list", "HEAD", "--count"] "UNKNOWN"