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
|
|
|
-
|
2019-03-13 19:48:14 +00:00
|
|
|
- Licensed under the GNU AGPL version 3 or higher.
|
2013-01-06 17:34:08 +00:00
|
|
|
-}
|
|
|
|
|
2019-11-27 20:54:11 +00:00
|
|
|
{-# LANGUAGE OverloadedStrings #-}
|
|
|
|
|
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
|
2017-12-31 20:08:31 +00:00
|
|
|
import Utility.Env.Set
|
2013-08-04 17:54:09 +00:00
|
|
|
|
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
|
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-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
|
2019-12-02 14:57:09 +00:00
|
|
|
setConfig "user.name" name
|
|
|
|
setConfig "user.email" name
|
2013-07-05 16:24:28 +00:00
|
|
|
a
|