summaryrefslogtreecommitdiff
path: root/Annex
diff options
context:
space:
mode:
Diffstat (limited to 'Annex')
-rw-r--r--Annex/Environment.hs31
1 files changed, 31 insertions, 0 deletions
diff --git a/Annex/Environment.hs b/Annex/Environment.hs
new file mode 100644
index 000000000..357ad6958
--- /dev/null
+++ b/Annex/Environment.hs
@@ -0,0 +1,31 @@
+{- git-annex environment
+ -
+ - Copyright 2012 Joey Hess <joey@kitenet.net>
+ -
+ - Licensed under the GNU GPL version 3 or higher.
+ -}
+
+module Annex.Environment where
+
+import Common.Annex
+import Utility.UserInfo
+import qualified Git.Config
+
+import System.Posix.Env
+
+{- Checks that the system's environment allows git to function.
+ - Git requires a GECOS username, or suitable git configuration, or
+ - environment variables. -}
+checkEnvironment :: Annex ()
+checkEnvironment = do
+ gitusername <- fromRepo $ Git.Config.getMaybe "user.name"
+ when (gitusername == Nothing || gitusername == Just "") $
+ liftIO checkEnvironmentIO
+
+checkEnvironmentIO :: IO ()
+checkEnvironmentIO = do
+ whenM (null <$> myUserGecos) $ do
+ username <- myUserName
+ -- existing environment is not overwritten
+ setEnv "GIT_AUTHOR_NAME" username False
+ setEnv "GIT_COMMITTER_NAME" username False