summaryrefslogtreecommitdiff
path: root/Annex/Environment.hs
blob: fd757ee2c90dbe7960d70f75cc292c8f18e8043f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
{- git-annex environment
 -
 - Copyright 2012, 2013 Joey Hess <joey@kitenet.net>
 -
 - Licensed under the GNU GPL version 3 or higher.
 -}

{-# LANGUAGE CPP #-}

module Annex.Environment where

import Common.Annex
#ifndef __WINDOWS__
import Utility.UserInfo
#endif
import qualified Git.Config

#ifndef __WINDOWS__
import System.Posix.Env
#endif
import Network.BSD

{- 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 =
#ifdef __WINDOWS__
	noop
#else
	whenM (null <$> myUserGecos) $ do
		username <- myUserName
		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
#endif