Skip to content

Commit 09f84a2

Browse files
author
Adam C. Foltzer
committedJan 11, 2016
Merge PR acfoltzer#6
2 parents a49c7b8 + 2f71b53 commit 09f84a2

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed
 

‎src/Development/GitRev.hs

+12-7
Original file line numberDiff line numberDiff line change
@@ -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,32 +84,37 @@ 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
8994
gitHash :: ExpQ
9095
gitHash =
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"
96101
gitBranch :: ExpQ
97102
gitBranch =
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
102107
gitDirty :: ExpQ
103108
gitDirty = 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"
108113

109114
-- | Return the number of commits in the current head
110115
gitCommitCount :: ExpQ
111116
gitCommitCount =
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
115120
gitCommitDate :: ExpQ

0 commit comments

Comments
 (0)
Please sign in to comment.