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