aboutsummaryrefslogtreecommitdiff
path: root/Git/Env.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2016-02-25 14:59:35 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2016-02-25 15:14:47 -0400
commit063e26fb58d6f835b9325e280f322eb5788ca660 (patch)
tree433d5bbabf0eeba0ab0e2afd8c9a7994bdb5863d /Git/Env.hs
parentc5df5fd4fa172782fee20f966b04c3793df140a1 (diff)
add catCommit, with commit object parser
Diffstat (limited to 'Git/Env.hs')
-rw-r--r--Git/Env.hs16
1 files changed, 16 insertions, 0 deletions
diff --git a/Git/Env.hs b/Git/Env.hs
index 35a4eb04d..0173513a7 100644
--- a/Git/Env.hs
+++ b/Git/Env.hs
@@ -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