git.iko.soy/typeable/gitrev
on 33b104f help sign in
2 files changed+7−40
since splitsnapshots
unifiedsplit
gitrev.cabal+1−1 src/Development/GitRev.hs+6−39
gitrev.cabal+1−1
@@ -1,5 +1,5 @@
11name: gitrev
2−version: 1.3.1
2+version: 1.3.0
33synopsis: Compile git revision info into Haskell projects
44homepage: https://github.com/acfoltzer/gitrev
55license: BSD3
src/Development/GitRev.hs+6−39
@@ -32,15 +32,7 @@
3232-- > % cabal exec runhaskell Example.hs
3333-- > Example.hs: [panic master@2ae047ba5e4a6f0f3e705a43615363ac006099c1 (Mon Jan 11 11:50:59 2016 -0800) (14 commits in HEAD) (uncommitted files present)] oh no!
3434
35−module Development.GitRev
36− ( gitBranch
37− , gitCommitCount
38− , gitCommitDate
39− , gitDescribe
40− , gitDirty
41− , gitDirtyTracked
42− , gitHash
43− ) where
35+module Development.GitRev (gitHash, gitBranch, gitDirty, gitCommitCount, gitCommitDate) where
4436
4537import Control.Exception
4638import Control.Monad
@@ -66,7 +58,7 @@ runGit args def useIdx = do
6658 if gitFound
6759 then do
6860 -- a lot of bookkeeping to record the right dependencies
69− pwd <- runIO getDotGit
61+ pwd <- runIO getGitDirectory
7062 let hd = pwd </> ".git" </> "HEAD"
7163 index = pwd </> ".git" </> "index"
7264 packedRefs = pwd </> ".git" </> "packed-refs"
@@ -97,11 +89,11 @@ runGit args def useIdx = do
9789 ExitFailure _ -> return def
9890 else return def
9991
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
10193-- submodule.
102−getDotGit :: IO FilePath
103−getDotGit = do
104− pwd <- getGitRoot
94+getGitDirectory :: IO FilePath
95+getGitDirectory = do
96+ pwd <- getCurrentDirectory
10597 let dotGit = pwd </> ".git"
10698 oops = return dotGit -- it's gonna fail, that's fine
10799 isDir <- doesDirectoryExist dotGit
@@ -117,16 +109,6 @@ getDotGit = do
117109 else oops
118110 _ -> oops
119111
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−
130112-- | Type to flag if the git index is used or not in a call to runGit
131113data IndexUsed = IdxUsed -- ^ The git index is used
132114 | IdxNotUsed -- ^ The git index is /not/ used
@@ -145,12 +127,6 @@ gitBranch :: ExpQ
145127gitBranch =
146128 stringE =<< runGit ["rev-parse", "--abbrev-ref", "HEAD"] "UNKNOWN" IdxNotUsed
147129
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−
154130-- | Return @True@ if there are non-committed files present in the
155131-- repository
156132gitDirty :: ExpQ
@@ -160,15 +136,6 @@ gitDirty = do
160136 "" -> conE falseName
161137 _ -> conE trueName
162138
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−
172139-- | Return the number of commits in the current head
173140gitCommitCount :: ExpQ
174141gitCommitCount =