git.iko.soy/typeable/gitrev
on 33b104f help sign in
gitrev.cabal+1−1
since splitsnapshots
unifiedsplit
@@ -1,5 +1,5 @@
1name: gitrev
1name: gitrev
2−version: 1.3.1
2+version: 1.3.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
src/Development/GitRev.hs+6−39
@@ -32,15 +32,7 @@
32-- > % cabal exec runhaskell Example.hs
32-- > % cabal exec runhaskell Example.hs
33-- > Example.hs: [panic master@2ae047ba5e4a6f0f3e705a43615363ac006099c1 (Mon Jan 11 11:50:59 2016 -0800) (14 commits in HEAD) (uncommitted files present)] oh no!
33-- > Example.hs: [panic master@2ae047ba5e4a6f0f3e705a43615363ac006099c1 (Mon Jan 11 11:50:59 2016 -0800) (14 commits in HEAD) (uncommitted files present)] oh no!
34
34
35−module Development.GitRev
35+module Development.GitRev (gitHash, gitBranch, gitDirty, gitCommitCount, gitCommitDate) where
36− ( gitBranch
37− , gitCommitCount
38− , gitCommitDate
39− , gitDescribe
40− , gitDirty
41− , gitDirtyTracked
42− , gitHash
43− ) where
44
36
45import Control.Exception
37import Control.Exception
46import Control.Monad
38import Control.Monad
@@ -66,7 +58,7 @@ runGit args def useIdx = do
66 if gitFound
58 if gitFound
67 then do
59 then do
68 -- a lot of bookkeeping to record the right dependencies
60 -- a lot of bookkeeping to record the right dependencies
69− pwd <- runIO getDotGit
61+ pwd <- runIO getGitDirectory
70 let hd = pwd </> ".git" </> "HEAD"
62 let hd = pwd </> ".git" </> "HEAD"
71 index = pwd </> ".git" </> "index"
63 index = pwd </> ".git" </> "index"
72 packedRefs = pwd </> ".git" </> "packed-refs"
64 packedRefs = pwd </> ".git" </> "packed-refs"
@@ -97,11 +89,11 @@ runGit args def useIdx = do
97 ExitFailure _ -> return def
89 ExitFailure _ -> return def
98 else return def
90 else return def
99
91
100−-- | Determine where our @.git@ directory is, in case we're in a
92+-- | Determine where our git directory is, in case we're in a
101-- submodule.
93-- submodule.
102−getDotGit :: IO FilePath
94+getGitDirectory :: IO FilePath
103−getDotGit = do
95+getGitDirectory = do
104− pwd <- getGitRoot
96+ pwd <- getCurrentDirectory
105 let dotGit = pwd </> ".git"
97 let dotGit = pwd </> ".git"
106 oops = return dotGit -- it's gonna fail, that's fine
98 oops = return dotGit -- it's gonna fail, that's fine
107 isDir <- doesDirectoryExist dotGit
99 isDir <- doesDirectoryExist dotGit
@@ -117,16 +109,6 @@ getDotGit = do
117 else oops
109 else oops
118 _ -> oops
110 _ -> oops
119
111
120−-- | Get the root directory of the Git repo.
121−getGitRoot :: IO FilePath
122−getGitRoot = do
123− pwd <- getCurrentDirectory
124− (code, out, _) <-
125− readProcessWithExitCode "git" ["rev-parse", "--show-toplevel"] ""
126− case code of
127− ExitSuccess -> return $ takeWhile (/= '\n') out
128− ExitFailure _ -> return pwd -- later steps will fail, that's fine
129−
130-- | Type to flag if the git index is used or not in a call to runGit
112-- | Type to flag if the git index is used or not in a call to runGit
131data IndexUsed = IdxUsed -- ^ The git index is used
113data IndexUsed = IdxUsed -- ^ The git index is used
132 | IdxNotUsed -- ^ The git index is /not/ used
114 | IdxNotUsed -- ^ The git index is /not/ used
@@ -145,12 +127,6 @@ gitBranch :: ExpQ
145gitBranch =
127gitBranch =
146 stringE =<< runGit ["rev-parse", "--abbrev-ref", "HEAD"] "UNKNOWN" IdxNotUsed
128 stringE =<< runGit ["rev-parse", "--abbrev-ref", "HEAD"] "UNKNOWN" IdxNotUsed
147
129
148−-- | Return the long git description for the current git commit, or
149−-- @UNKNOWN@ if not in a git repository.
150−gitDescribe :: ExpQ
151−gitDescribe =
152− stringE =<< runGit ["describe", "--long", "--always"] "UNKNOWN" IdxNotUsed
153−
154-- | Return @True@ if there are non-committed files present in the
130-- | Return @True@ if there are non-committed files present in the
155-- repository
131-- repository
156gitDirty :: ExpQ
132gitDirty :: ExpQ
@@ -160,15 +136,6 @@ gitDirty = do
160 "" -> conE falseName
136 "" -> conE falseName
161 _ -> conE trueName
137 _ -> conE trueName
162
138
163−-- | Return @True@ if there are non-commited changes to tracked files
164−-- present in the repository
165−gitDirtyTracked :: ExpQ
166−gitDirtyTracked = do
167− output <- runGit ["status", "--porcelain","--untracked-files=no"] "" IdxUsed
168− case output of
169− "" -> conE falseName
170− _ -> conE trueName
171−
172-- | Return the number of commits in the current head
139-- | Return the number of commits in the current head
173gitCommitCount :: ExpQ
140gitCommitCount :: ExpQ
174gitCommitCount =
141gitCommitCount =