gitrev 1.1.0 → 1.2.0
raw patch · 2 files changed
+24/−13 lines, 2 filesdep ~basePVP ok
version bump matches the API change (PVP)
Dependency ranges changed: base
API changes (from Hackage documentation)
+ Development.GitRev: gitCommitDate :: ExpQ
+ Development.GitRev: instance GHC.Classes.Eq Development.GitRev.IndexUsed
Files
- gitrev.cabal +2/−2
- src/Development/GitRev.hs +22/−11
gitrev.cabal view
@@ -1,5 +1,5 @@ name: gitrev-version: 1.1.0+version: 1.2.0 synopsis: Compile git revision info into Haskell projects homepage: https://github.com/acfoltzer/gitrev license: BSD3@@ -16,7 +16,7 @@ location: https://github.com/acfoltzer/gitrev.git library- build-depends: base >= 4.7 && < 5,+ build-depends: base >= 4.6 && < 5, directory, filepath, template-haskell,
src/Development/GitRev.hs view
@@ -18,6 +18,7 @@ -- > panic msg = error panicMsg -- > where panicMsg = -- > concat [ "[panic ", $(gitBranch), "@", $(gitHash)+-- > , " (", $(gitCommitDate), ")" -- > , " (", $(gitCommitCount), " commits in HEAD)" -- > , dirty, "] ", msg ] -- > dirty | $(gitDirty) = " (uncommitted files present)"@@ -26,9 +27,9 @@ -- > main = panic "oh no!" -- -- > % cabal exec runhaskell Example.hs--- > Example.hs: [panic master@2702e69355c978805064543489c351b61ac6760b (6 commits in HEAD) (uncommitted files present)] oh no!+-- > Example.hs: [panic master@2ae047ba5e4a6f0f3e705a43615363ac006099c1 (Mon Jan 11 11:50:59 2016 -0800) (14 commits in HEAD) (uncommitted files present)] oh no! -module Development.GitRev (gitHash, gitBranch, gitDirty, gitCommitCount) where+module Development.GitRev (gitHash, gitBranch, gitDirty, gitCommitCount, gitCommitDate) where import Control.Applicative import Control.Exception@@ -44,8 +45,8 @@ -- | Run git with the given arguments and no stdin, returning the -- stdout output. If git isn't available or something goes wrong, -- return the second argument.-runGit :: [String] -> String -> Q String-runGit args def = do+runGit :: [String] -> String -> IndexUsed -> Q String+runGit args def useIdx = do let oops :: SomeException -> IO (ExitCode, String, String) oops _e = return (ExitFailure 1, def, "") gitFound <- runIO $ isJust <$> findExecutable "git"@@ -71,7 +72,7 @@ _hash -> addDependentFile hd -- add the index if it exists to set the dirty flag indexExists <- runIO $ doesFileExist index- when indexExists $ addDependentFile index+ when (indexExists && useIdx == IdxUsed) $ addDependentFile index -- if the refs have been packed, the info we're looking for -- might be in that file rather than the one-file-per-ref case -- handled above@@ -84,29 +85,39 @@ ExitFailure _ -> return def else return def +-- | Type to flag if the git index is used or not in a call to runGit+data IndexUsed = IdxUsed -- ^ The git index is used+ | IdxNotUsed -- ^ The git index is /not/ used+ deriving (Eq)+ -- | Return the hash of the current git commit, or @UNKNOWN@ if not in -- a git repository gitHash :: ExpQ gitHash =- stringE =<< runGit ["rev-parse", "HEAD"] "UNKNOWN"+ stringE =<< runGit ["rev-parse", "HEAD"] "UNKNOWN" IdxNotUsed -- | 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" gitBranch :: ExpQ gitBranch =- stringE =<< runGit ["rev-parse", "--abbrev-ref", "HEAD"] "UNKNOWN"+ stringE =<< runGit ["rev-parse", "--abbrev-ref", "HEAD"] "UNKNOWN" IdxNotUsed -- | Return @True@ if there are non-committed files present in the -- repository gitDirty :: ExpQ gitDirty = do- output <- runGit ["status", "--porcelain"] ""+ output <- runGit ["status", "--porcelain"] "" IdxUsed case output of- "" -> conE $ mkName "Prelude.False"- _ -> conE $ mkName "Prelude.True"+ "" -> conE falseName+ _ -> conE trueName -- | Return the number of commits in the current head gitCommitCount :: ExpQ gitCommitCount =- stringE =<< runGit ["rev-list", "HEAD", "--count"] "UNKNOWN"+ stringE =<< runGit ["rev-list", "HEAD", "--count"] "UNKNOWN" IdxNotUsed++-- | Return the commit date of the current head+gitCommitDate :: ExpQ+gitCommitDate =+ stringE =<< runGit ["log", "HEAD", "-1", "--format=%cd"] "UNKNOWN" IdxNotUsed