Support user.useConfigOnly git config
When it's set and git cannot determine user.name or user.email, this will result in git-annex init failing when committing to create the git-annex branch. Other git-annex commands that commit can also fail. Sponsored-by: Jack Hill on Patreon
This commit is contained in:
parent
66eb63dd82
commit
e91bf784cd
2 changed files with 23 additions and 7 deletions
|
@ -7,7 +7,11 @@
|
||||||
|
|
||||||
{-# LANGUAGE OverloadedStrings #-}
|
{-# LANGUAGE OverloadedStrings #-}
|
||||||
|
|
||||||
module Annex.Environment where
|
module Annex.Environment (
|
||||||
|
checkEnvironment,
|
||||||
|
checkEnvironmentIO,
|
||||||
|
ensureCommit,
|
||||||
|
) where
|
||||||
|
|
||||||
import Annex.Common
|
import Annex.Common
|
||||||
import qualified Annex
|
import qualified Annex
|
||||||
|
@ -15,6 +19,8 @@ import Utility.UserInfo
|
||||||
import qualified Git.Config
|
import qualified Git.Config
|
||||||
import Utility.Env.Set
|
import Utility.Env.Set
|
||||||
|
|
||||||
|
import Control.Exception
|
||||||
|
|
||||||
{- Checks that the system's environment allows git to function.
|
{- Checks that the system's environment allows git to function.
|
||||||
- Git requires a GECOS username, or suitable git configuration, or
|
- Git requires a GECOS username, or suitable git configuration, or
|
||||||
- environment variables.
|
- environment variables.
|
||||||
|
@ -29,7 +35,8 @@ checkEnvironment :: Annex ()
|
||||||
checkEnvironment = do
|
checkEnvironment = do
|
||||||
gitusername <- fromRepo $ Git.Config.getMaybe "user.name"
|
gitusername <- fromRepo $ Git.Config.getMaybe "user.name"
|
||||||
when (isNothing gitusername || gitusername == Just "") $
|
when (isNothing gitusername || gitusername == Just "") $
|
||||||
liftIO checkEnvironmentIO
|
unlessM userConfigOnly $
|
||||||
|
liftIO checkEnvironmentIO
|
||||||
|
|
||||||
checkEnvironmentIO :: IO ()
|
checkEnvironmentIO :: IO ()
|
||||||
checkEnvironmentIO = whenM (isNothing <$> myUserGecos) $ do
|
checkEnvironmentIO = whenM (isNothing <$> myUserGecos) $ do
|
||||||
|
@ -46,8 +53,16 @@ checkEnvironmentIO = whenM (isNothing <$> myUserGecos) $ do
|
||||||
ensureCommit :: Annex a -> Annex a
|
ensureCommit :: Annex a -> Annex a
|
||||||
ensureCommit a = either retry return =<< tryNonAsync a
|
ensureCommit a = either retry return =<< tryNonAsync a
|
||||||
where
|
where
|
||||||
retry _ = do
|
retry e = ifM userConfigOnly
|
||||||
name <- liftIO $ either (const "unknown") id <$> myUserName
|
( liftIO (throwIO e)
|
||||||
Annex.addGitConfigOverride ("user.name=" ++ name)
|
, do
|
||||||
Annex.addGitConfigOverride ("user.email=" ++ name)
|
name <- liftIO $ either (const "unknown") id <$> myUserName
|
||||||
a
|
Annex.addGitConfigOverride ("user.name=" ++ name)
|
||||||
|
Annex.addGitConfigOverride ("user.email=" ++ name)
|
||||||
|
a
|
||||||
|
)
|
||||||
|
|
||||||
|
userConfigOnly :: Annex Bool
|
||||||
|
userConfigOnly = do
|
||||||
|
v <- fromRepo $ Git.Config.getMaybe "user.useconfigonly"
|
||||||
|
return (fromMaybe False (Git.Config.isTrueFalse' =<< v))
|
||||||
|
|
|
@ -7,6 +7,7 @@ git-annex (10.20230330) UNRELEASED; urgency=medium
|
||||||
of --unlock-present and --hide-missing adjusted branches.
|
of --unlock-present and --hide-missing adjusted branches.
|
||||||
* Avoid setting user.name and user.email in the git config
|
* Avoid setting user.name and user.email in the git config
|
||||||
when git is unable to detect them.
|
when git is unable to detect them.
|
||||||
|
* Support user.useConfigOnly git config.
|
||||||
|
|
||||||
-- Joey Hess <id@joeyh.name> Fri, 31 Mar 2023 12:48:54 -0400
|
-- Joey Hess <id@joeyh.name> Fri, 31 Mar 2023 12:48:54 -0400
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue