git.iko.soy/typeable/gitrev
on master help sign in
Merge PR #6
09f84a2Adam C. Foltzer
src/Development/GitRev.hs+12−7
@@ -44,8 +44,8 @@ import System.Process
44-- | Run git with the given arguments and no stdin, returning the
44-- | Run git with the given arguments and no stdin, returning the
45-- stdout output. If git isn't available or something goes wrong,
45-- stdout output. If git isn't available or something goes wrong,
46-- return the second argument.
46-- return the second argument.
47−runGit :: [String] -> String -> Q String
47+runGit :: [String] -> String -> IndexUsed -> Q String
48−runGit args def = do
48+runGit args def useIdx = do
49 let oops :: SomeException -> IO (ExitCode, String, String)
49 let oops :: SomeException -> IO (ExitCode, String, String)
50 oops _e = return (ExitFailure 1, def, "")
50 oops _e = return (ExitFailure 1, def, "")
51 gitFound <- runIO $ isJust <$> findExecutable "git"
51 gitFound <- runIO $ isJust <$> findExecutable "git"
@@ -71,7 +71,7 @@ runGit args def = do
71 _hash -> addDependentFile hd
71 _hash -> addDependentFile hd
72 -- add the index if it exists to set the dirty flag
72 -- add the index if it exists to set the dirty flag
73 indexExists <- runIO $ doesFileExist index
73 indexExists <- runIO $ doesFileExist index
74− when indexExists $ addDependentFile index
74+ when (indexExists && useIdx == IdxUsed) $ addDependentFile index
75 -- if the refs have been packed, the info we're looking for
75 -- if the refs have been packed, the info we're looking for
76 -- might be in that file rather than the one-file-per-ref case
76 -- might be in that file rather than the one-file-per-ref case
77 -- handled above
77 -- handled above
@@ -84,24 +84,29 @@ runGit args def = do
84 ExitFailure _ -> return def
84 ExitFailure _ -> return def
85 else return def
85 else return def
86
86
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+
87-- | Return the hash of the current git commit, or @UNKNOWN@ if not in
92-- | Return the hash of the current git commit, or @UNKNOWN@ if not in
88-- a git repository
93-- a git repository
89gitHash :: ExpQ
94gitHash :: ExpQ
90gitHash =
95gitHash =
91− stringE =<< runGit ["rev-parse", "HEAD"] "UNKNOWN"
96+ stringE =<< runGit ["rev-parse", "HEAD"] "UNKNOWN" IdxNotUsed
92
97
93-- | Return the branch (or tag) name of the current git commit, or @UNKNOWN@
98-- | Return the branch (or tag) name of the current git commit, or @UNKNOWN@
94-- if not in a git repository. For detached heads, this will just be
99-- if not in a git repository. For detached heads, this will just be
95-- "HEAD"
100-- "HEAD"
96gitBranch :: ExpQ
101gitBranch :: ExpQ
97gitBranch =
102gitBranch =
98− stringE =<< runGit ["rev-parse", "--abbrev-ref", "HEAD"] "UNKNOWN"
103+ stringE =<< runGit ["rev-parse", "--abbrev-ref", "HEAD"] "UNKNOWN" IdxNotUsed
99
104
100-- | Return @True@ if there are non-committed files present in the
105-- | Return @True@ if there are non-committed files present in the
101-- repository
106-- repository
102gitDirty :: ExpQ
107gitDirty :: ExpQ
103gitDirty = do
108gitDirty = do
104− output <- runGit ["status", "--porcelain"] ""
109+ output <- runGit ["status", "--porcelain"] "" IdxUsed
105 case output of
110 case output of
106 "" -> conE $ mkName "Prelude.False"
111 "" -> conE $ mkName "Prelude.False"
107 _ -> conE $ mkName "Prelude.True"
112 _ -> conE $ mkName "Prelude.True"
@@ -109,7 +114,7 @@ gitDirty = do
109-- | Return the number of commits in the current head
114-- | Return the number of commits in the current head
110gitCommitCount :: ExpQ
115gitCommitCount :: ExpQ
111gitCommitCount =
116gitCommitCount =
112− stringE =<< runGit ["rev-list", "HEAD", "--count"] "UNKNOWN"
117+ stringE =<< runGit ["rev-list", "HEAD", "--count"] "UNKNOWN" IdxNotUsed
113
118
114-- | Return the commit date of the current head
119-- | Return the commit date of the current head
115gitCommitDate :: ExpQ
120gitCommitDate :: ExpQ