Skip to content
This repository has been archived by the owner on Jan 3, 2024. It is now read-only.

Add gitDiff #20

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/Development/GitRev.hs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ module Development.GitRev
, gitCommitCount
, gitCommitDate
, gitDescribe
, gitDiff
, gitDirty
, gitDirtyTracked
, gitHash
Expand All @@ -59,7 +60,10 @@ import Prelude.Compat
-- stdout output. If git isn't available or something goes wrong,
-- return the second argument.
runGit :: [String] -> String -> IndexUsed -> Q String
runGit args def useIdx = do
runGit = runGitPostprocess (takeWhile (/= '\n'))

runGitPostprocess :: (String -> String) -> [String] -> String -> IndexUsed -> Q String
runGitPostprocess postProcess args def useIdx = do
let oops :: SomeException -> IO (ExitCode, String, String)
oops _e = return (ExitFailure 1, def, "")
gitFound <- runIO $ isJust <$> findExecutable "git"
Expand Down Expand Up @@ -93,7 +97,7 @@ runGit args def useIdx = do
runIO $ do
(code, out, _err) <- readProcessWithExitCode "git" args "" `catch` oops
case code of
ExitSuccess -> return (takeWhile (/= '\n') out)
ExitSuccess -> return (postProcess out)
ExitFailure _ -> return def
else return def

Expand Down Expand Up @@ -178,3 +182,8 @@ gitCommitCount =
gitCommitDate :: ExpQ
gitCommitDate =
stringE =<< runGit ["log", "HEAD", "-1", "--format=%cd"] "UNKNOWN" IdxNotUsed

-- | Return the diff of the working copy with HEAD
gitDiff :: ExpQ
gitDiff =
stringE =<< runGitPostprocess id ["diff", "HEAD"] "UNKNOWN" IdxNotUsed