git.iko.soy/typeable/gitrev
on master help sign in
Merge PR #6
commit09f84a2b09a50f05ca80abedf54ddda35a778ca3 authorAdam C. Foltzer <acfoltzer@galois.com> dateMon 11 Jan 2016, 11:49 (11 years ago) parenta49c7b82f71b53
1 file changed+12−7
src/Development/GitRev.hs+12−7
src/Development/GitRev.hs+12−7
@@ -44,8 +44,8 @@ import System.Process
4444-- | Run git with the given arguments and no stdin, returning the
4545-- stdout output. If git isn't available or something goes wrong,
4646-- return the second argument.
47−runGit :: [String] -> String -> Q String
48−runGit args def = do
47+runGit :: [String] -> String -> IndexUsed -> Q String
48+runGit args def useIdx = do
4949 let oops :: SomeException -> IO (ExitCode, String, String)
5050 oops _e = return (ExitFailure 1, def, "")
5151 gitFound <- runIO $ isJust <$> findExecutable "git"
@@ -71,7 +71,7 @@ runGit args def = do
7171 _hash -> addDependentFile hd
7272 -- add the index if it exists to set the dirty flag
7373 indexExists <- runIO $ doesFileExist index
74− when indexExists $ addDependentFile index
74+ when (indexExists && useIdx == IdxUsed) $ addDependentFile index
7575 -- if the refs have been packed, the info we're looking for
7676 -- might be in that file rather than the one-file-per-ref case
7777 -- handled above
@@ -84,24 +84,29 @@ runGit args def = do
8484 ExitFailure _ -> return def
8585 else return def
8686
87+-- | Type to flag if the git index is used or not in a call to runGit
88+data IndexUsed = IdxUsed -- ^ The git index is used
89+ | IdxNotUsed -- ^ The git index is /not/ used
90+ deriving (Eq)
91+
8792-- | Return the hash of the current git commit, or @UNKNOWN@ if not in
8893-- a git repository
8994gitHash :: ExpQ
9095gitHash =
91− stringE =<< runGit ["rev-parse", "HEAD"] "UNKNOWN"
96+ stringE =<< runGit ["rev-parse", "HEAD"] "UNKNOWN" IdxNotUsed
9297
9398-- | Return the branch (or tag) name of the current git commit, or @UNKNOWN@
9499-- if not in a git repository. For detached heads, this will just be
95100-- "HEAD"
96101gitBranch :: ExpQ
97102gitBranch =
98− stringE =<< runGit ["rev-parse", "--abbrev-ref", "HEAD"] "UNKNOWN"
103+ stringE =<< runGit ["rev-parse", "--abbrev-ref", "HEAD"] "UNKNOWN" IdxNotUsed
99104
100105-- | Return @True@ if there are non-committed files present in the
101106-- repository
102107gitDirty :: ExpQ
103108gitDirty = do
104− output <- runGit ["status", "--porcelain"] ""
109+ output <- runGit ["status", "--porcelain"] "" IdxUsed
105110 case output of
106111 "" -> conE $ mkName "Prelude.False"
107112 _ -> conE $ mkName "Prelude.True"
@@ -109,7 +114,7 @@ gitDirty = do
109114-- | Return the number of commits in the current head
110115gitCommitCount :: ExpQ
111116gitCommitCount =
112− stringE =<< runGit ["rev-list", "HEAD", "--count"] "UNKNOWN"
117+ stringE =<< runGit ["rev-list", "HEAD", "--count"] "UNKNOWN" IdxNotUsed
113118
114119-- | Return the commit date of the current head
115120gitCommitDate :: ExpQ