git.iko.soy/typeable/gitrev
on master help sign in
add count of commits in HEAD
8184c27Adam C. Foltzer
Example.hs+3−1
@@ -5,7 +5,9 @@ import Development.GitRev
5panic :: String -> a
5panic :: String -> a
6panic msg = error panicMsg
6panic msg = error panicMsg
7 where panicMsg =
7 where panicMsg =
8− concat [ "[panic ", $(gitBranch), "@", $(gitHash), dirty, "] ", msg ]
8+ concat [ "[panic ", $(gitBranch), "@", $(gitHash)
9+ , " (", $(gitCommitCount), " commits in HEAD)"
10+ , dirty, "] ", msg ]
9 dirty | $(gitDirty) = " (uncommitted files present)"
11 dirty | $(gitDirty) = " (uncommitted files present)"
10 | otherwise = ""
12 | otherwise = ""
11
13
gitrev.cabal+3−2
@@ -1,5 +1,5 @@
1name: gitrev
1name: gitrev
2−version: 1.0.0
2+version: 1.1.0
3synopsis: Compile git revision info into Haskell projects
3synopsis: Compile git revision info into Haskell projects
4homepage: https://github.com/acfoltzer/gitrev
4homepage: https://github.com/acfoltzer/gitrev
5license: BSD3
5license: BSD3
@@ -9,13 +9,14 @@ maintainer: acfoltzer@galois.com
9category: Development
9category: Development
10build-type: Simple
10build-type: Simple
11cabal-version: >=1.10
11cabal-version: >=1.10
12+description: 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.
12
13
13source-repository head
14source-repository head
14 type: git
15 type: git
15 location: https://github.com/acfoltzer/gitrev.git
16 location: https://github.com/acfoltzer/gitrev.git
16
17
17library
18library
18− build-depends: base >= 4.7,
19+ build-depends: base >= 4.7 && < 5,
19 directory,
20 directory,
20 filepath,
21 filepath,
21 template-haskell,
22 template-haskell,
src/Development/GitRev.hs+10−3
@@ -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 = ""
23-- >
25-- >
24-- > main = panic "oh no!"
26-- > main = panic "oh no!"
25--
27--
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!
28
30
29−module Development.GitRev (gitHash, gitBranch, gitDirty) where
31+module Development.GitRev (gitHash, gitBranch, gitDirty, gitCommitCount) where
30
32
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"
108+
109+-- | Return the number of commits in the current head
110+gitCommitCount :: ExpQ
111+gitCommitCount =
112+ stringE =<< runGit ["rev-list", "HEAD", "--count"] "UNKNOWN"