add catCommit, with commit object parser

This commit is contained in:
Joey Hess 2016-02-25 14:59:35 -04:00
parent be2e9427ad
commit 1f91d1d0b7
Failed to extract signature
3 changed files with 77 additions and 1 deletions

View file

@ -10,6 +10,7 @@
module Git.Env where
import Git
import Git.Types
import Utility.Env
{- Adjusts the gitEnv of a Repo. Copies the system environment if the repo
@ -36,3 +37,18 @@ adjustGitEnv g adj = do
addGitEnv :: Repo -> String -> String -> IO Repo
addGitEnv g var val = adjustGitEnv g (addEntry var val)
{- Use with any action that makes a commit to set metadata. -}
commitWithMetaData :: CommitMetaData -> CommitMetaData -> (Repo -> IO a) -> Repo -> IO a
commitWithMetaData authormetadata committermetadata a g =
a =<< adjustGitEnv g adj
where
adj = mkadj "AUTHOR" authormetadata
. mkadj "COMMITTER" committermetadata
mkadj p md = go "NAME" commitName
. go "EMAIL" commitEmail
. go "DATE" commitDate
where
go s getv = case getv md of
Nothing -> id
Just v -> addEntry ("GIT_" ++ p ++ "_" ++ s) v