2013-04-22 19:36:34 +00:00
|
|
|
{- git-annex environment
|
2013-01-06 17:34:08 +00:00
|
|
|
-
|
2015-01-21 16:50:09 +00:00
|
|
|
- Copyright 2012, 2013 Joey Hess <id@joeyh.name>
|
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
|
|
|
|
2016-01-20 20:36:33 +00:00
|
|
|
import Annex.Common
|
2013-01-06 17:34:08 +00:00
|
|
|
import Utility.UserInfo
|
|
|
|
import qualified Git.Config
|
2013-07-05 16:24:28 +00:00
|
|
|
import Config
|
2013-08-04 17:54:09 +00:00
|
|
|
import Utility.Env
|
|
|
|
|
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
|
2013-07-05 16:24:28 +00:00
|
|
|
- environment variables.
|
|
|
|
-
|
|
|
|
- Git also requires the system have a hostname containing a dot.
|
|
|
|
- Otherwise, it tries various methods to find a FQDN, and will fail if it
|
|
|
|
- does not. To avoid replicating that code here, which would break if its
|
|
|
|
- methods change, this function does not check the hostname is valid.
|
|
|
|
- Instead, code that commits can use ensureCommit.
|
|
|
|
-}
|
2013-01-06 17:34:08 +00:00
|
|
|
checkEnvironment :: Annex ()
|
|
|
|
checkEnvironment = do
|
|
|
|
gitusername <- fromRepo $ Git.Config.getMaybe "user.name"
|
2013-09-25 07:09:06 +00:00
|
|
|
when (isNothing gitusername || gitusername == Just "") $
|
2013-04-22 19:36:34 +00:00
|
|
|
liftIO checkEnvironmentIO
|
|
|
|
|
|
|
|
checkEnvironmentIO :: IO ()
|
2014-10-31 20:14:12 +00:00
|
|
|
checkEnvironmentIO = whenM (isNothing <$> myUserGecos) $ do
|
2016-06-08 19:04:15 +00:00
|
|
|
username <- either (const "unknown") id <$> myUserName
|
2014-10-16 00:33:52 +00:00
|
|
|
ensureEnv "GIT_AUTHOR_NAME" username
|
|
|
|
ensureEnv "GIT_COMMITTER_NAME" username
|
2013-05-03 18:08:26 +00:00
|
|
|
where
|
|
|
|
#ifndef __ANDROID__
|
2014-10-09 18:53:13 +00:00
|
|
|
-- existing environment is not overwritten
|
2014-10-16 00:33:52 +00:00
|
|
|
ensureEnv var val = setEnv var val False
|
2013-05-03 18:08:26 +00:00
|
|
|
#else
|
|
|
|
-- Environment setting is broken on Android, so this is dealt with
|
|
|
|
-- in runshell instead.
|
|
|
|
ensureEnv _ _ = noop
|
|
|
|
#endif
|
2013-07-05 16:24:28 +00:00
|
|
|
|
|
|
|
{- Runs an action that commits to the repository, and if it fails,
|
2014-04-20 18:17:57 +00:00
|
|
|
- sets user.email and user.name to a dummy value and tries the action again. -}
|
2013-07-05 16:24:28 +00:00
|
|
|
ensureCommit :: Annex a -> Annex a
|
unify exception handling into Utility.Exception
Removed old extensible-exceptions, only needed for very old ghc.
Made webdav use Utility.Exception, to work after some changes in DAV's
exception handling.
Removed Annex.Exception. Mostly this was trivial, but note that
tryAnnex is replaced with tryNonAsync and catchAnnex replaced with
catchNonAsync. In theory that could be a behavior change, since the former
caught all exceptions, and the latter don't catch async exceptions.
However, in practice, nothing in the Annex monad uses async exceptions.
Grepping for throwTo and killThread only find stuff in the assistant,
which does not seem related.
Command.Add.undo is changed to accept a SomeException, and things
that use it for rollback now catch non-async exceptions, rather than
only IOExceptions.
2014-08-08 01:55:44 +00:00
|
|
|
ensureCommit a = either retry return =<< tryNonAsync a
|
2013-07-05 16:24:28 +00:00
|
|
|
where
|
2014-10-09 18:53:13 +00:00
|
|
|
retry _ = do
|
2016-06-08 19:04:15 +00:00
|
|
|
name <- liftIO $ either (const "unknown") id <$> myUserName
|
2014-04-20 18:17:57 +00:00
|
|
|
setConfig (ConfigKey "user.name") name
|
|
|
|
setConfig (ConfigKey "user.email") name
|
2013-07-05 16:24:28 +00:00
|
|
|
a
|