aboutsummaryrefslogtreecommitdiff
path: root/Annex/Environment.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2013-04-22 15:36:34 -0400
committerGravatar Joey Hess <joey@kitenet.net>2013-04-22 15:36:34 -0400
commit6c5360cbdf20821a97a0f109ea114e4772b001e6 (patch)
tree030a5613938276edb57e18a09063bfe4c4ed4905 /Annex/Environment.hs
parent8655ea7f8e853b7de4defbca2655b741362ecd21 (diff)
Detect systems that have no user name set in GECOS, and also don't have user.name set in git config, and put in a workaround so that commits to the git-annex branch (and the assistant) will still succeed despite git not liking the system configuration.
Diffstat (limited to 'Annex/Environment.hs')
-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