gitrev 1.2.0 → 1.3.0
raw patch · 2 files changed
+32/−5 lines, 2 filesdep +base-compatPVP ok
version bump matches the API change (PVP)
Dependencies added: base-compat
API changes (from Hackage documentation)
Files
- gitrev.cabal +4/−1
- src/Development/GitRev.hs +28/−4
gitrev.cabal view
@@ -1,5 +1,5 @@ name: gitrev-version: 1.2.0+version: 1.3.0 synopsis: Compile git revision info into Haskell projects homepage: https://github.com/acfoltzer/gitrev license: BSD3@@ -9,6 +9,7 @@ category: Development build-type: Simple cabal-version: >=1.10+tested-with: GHC == 7.6.3, GHC == 7.8.4, GHC == 7.10.3, GHC == 8.0.2 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. source-repository head@@ -17,10 +18,12 @@ library build-depends: base >= 4.6 && < 5,+ base-compat >= 0.6.0, directory, filepath, template-haskell, process hs-source-dirs: src+ ghc-options: -Wall default-language: Haskell2010 exposed-modules: Development.GitRev
src/Development/GitRev.hs view
@@ -1,3 +1,6 @@+{-# LANGUAGE LambdaCase #-}+{-# LANGUAGE MultiWayIf #-}+ -- | -- Module : $Header$ -- Copyright : (c) 2015 Adam C. Foltzer@@ -31,7 +34,6 @@ module Development.GitRev (gitHash, gitBranch, gitDirty, gitCommitCount, gitCommitDate) where -import Control.Applicative import Control.Exception import Control.Monad import Data.Maybe@@ -42,6 +44,9 @@ import System.FilePath import System.Process +import Prelude ()+import Prelude.Compat+ -- | 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.@@ -53,7 +58,7 @@ if gitFound then do -- a lot of bookkeeping to record the right dependencies- pwd <- runIO getCurrentDirectory+ pwd <- runIO getGitDirectory let hd = pwd </> ".git" </> "HEAD" index = pwd </> ".git" </> "index" packedRefs = pwd </> ".git" </> "packed-refs"@@ -61,8 +66,7 @@ when hdExists $ do -- the HEAD file either contains the hash of a detached head -- or a pointer to the file that contains the hash of the head- hdRef <- runIO $ readFile hd- case splitAt 5 hdRef of+ splitAt 5 `fmap` runIO (readFile hd) >>= \case -- pointer to ref ("ref: ", relRef) -> do let ref = pwd </> ".git" </> relRef@@ -84,6 +88,26 @@ ExitSuccess -> return (takeWhile (/= '\n') out) ExitFailure _ -> return def else return def++-- | Determine where our git directory is, in case we're in a+-- submodule.+getGitDirectory :: IO FilePath+getGitDirectory = do+ pwd <- getCurrentDirectory+ let dotGit = pwd </> ".git"+ oops = return dotGit -- it's gonna fail, that's fine+ isDir <- doesDirectoryExist dotGit+ isFile <- doesFileExist dotGit+ if | isDir -> return dotGit+ | not isFile -> oops+ | isFile ->+ splitAt 8 `fmap` readFile dotGit >>= \case+ ("gitdir: ", relDir) -> do+ isRelDir <- doesDirectoryExist relDir+ if isRelDir+ then return relDir+ else oops+ _ -> oops -- | Type to flag if the git index is used or not in a call to runGit data IndexUsed = IdxUsed -- ^ The git index is used