2013-04-22 19:36:34 +00:00
|
|
|
{- git-annex environment
|
2013-01-06 17:34:08 +00:00
|
|
|
-
|
2013-05-03 15:52:04 +00:00
|
|
|
- Copyright 2012, 2013 Joey Hess <joey@kitenet.net>
|
2013-01-06 17:34:08 +00:00
|
|
|
-
|
|
|
|
- Licensed under the GNU GPL version 3 or higher.
|
|
|
|
-}
|
|
|
|
|
2013-05-03 18:08:26 +00:00
|
|
|
{-# LANGUAGE CPP #-}
|
|
|
|
|
2013-04-22 19:36:34 +00:00
|
|
|
module Annex.Environment where
|
2013-01-06 17:34:08 +00:00
|
|
|
|
2013-04-22 19:36:34 +00:00
|
|
|
import Common.Annex
|
2013-05-11 20:03:00 +00:00
|
|
|
#ifndef __WINDOWS__
|
2013-01-06 17:34:08 +00:00
|
|
|
import Utility.UserInfo
|
2013-05-11 20:03:00 +00:00
|
|
|
#endif
|
2013-01-06 17:34:08 +00:00
|
|
|
import qualified Git.Config
|
|
|
|
|
2013-05-11 20:03:00 +00:00
|
|
|
#ifndef __WINDOWS__
|
2013-01-06 17:34:08 +00:00
|
|
|
import System.Posix.Env
|
2013-05-10 21:29:59 +00:00
|
|
|
#endif
|
2013-05-03 15:52:04 +00:00
|
|
|
import Network.BSD
|
2013-01-06 17:34:08 +00:00
|
|
|
|
|
|
|
{- 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"
|
2013-04-22 19:36:34 +00:00
|
|
|
when (gitusername == Nothing || gitusername == Just "") $
|
|
|
|
liftIO checkEnvironmentIO
|
|
|
|
|
|
|
|
checkEnvironmentIO :: IO ()
|
2013-05-11 20:03:00 +00:00
|
|
|
checkEnvironmentIO =
|
|
|
|
#ifdef __WINDOWS__
|
|
|
|
noop
|
|
|
|
#else
|
2013-04-22 19:36:34 +00:00
|
|
|
whenM (null <$> myUserGecos) $ do
|
|
|
|
username <- myUserName
|
2013-05-03 18:08:26 +00:00
|
|
|
ensureEnv "GIT_AUTHOR_NAME" username
|
|
|
|
ensureEnv "GIT_COMMITTER_NAME" username
|
|
|
|
where
|
|
|
|
#ifndef __ANDROID__
|
|
|
|
-- existing environment is not overwritten
|
|
|
|
ensureEnv var val = setEnv var val False
|
|
|
|
#else
|
|
|
|
-- Environment setting is broken on Android, so this is dealt with
|
|
|
|
-- in runshell instead.
|
|
|
|
ensureEnv _ _ = noop
|
|
|
|
#endif
|
2013-05-11 20:03:00 +00:00
|
|
|
#endif
|