summaryrefslogtreecommitdiff
path: root/Git/Env.hs
diff options
context:
space:
mode:
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