git-annex/Command/Config.hs
Joey Hess e53070c1ff
inheritable annex.securehashesonly
* init: When annex.securehashesonly has been set with git-annex config,
  copy that value to the annex.securehashesonly git config.
* config --set: As well as setting value in git-annex branch,
  set local gitconfig. This is needed especially for
  annex.securehashesonly, which is read only from local gitconfig and not
  the git-annex branch.

doc/todo/sha1_collision_embedding_in_git-annex_keys.mdwn has the
rationalle for doing it this way. There's no perfect solution; this
seems to be the least-bad one.

This commit was supported by the NSF-funded DataLad project.
2017-02-27 16:08:23 -04:00

71 lines
1.5 KiB
Haskell

{- git-annex command
-
- Copyright 2017 Joey Hess <id@joeyh.name>
-
- Licensed under the GNU GPL version 3 or higher.
-}
module Command.Config where
import Command
import Logs.Config
import Config
cmd :: Command
cmd = noMessages $ command "config" SectionSetup
"configuration stored in git-annex branch"
paramNothing (seek <$$> optParser)
data Action
= SetConfig ConfigName ConfigValue
| GetConfig ConfigName
| UnsetConfig ConfigName
type Name = String
type Value = String
optParser :: CmdParamsDesc -> Parser Action
optParser _ = setconfig <|> getconfig <|> unsetconfig
where
setconfig = SetConfig
<$> strOption
( long "set"
<> help "set configuration"
<> metavar paramName
)
<*> strArgument
( metavar paramValue
)
getconfig = GetConfig <$> strOption
( long "get"
<> help "get configuration"
<> metavar paramName
)
unsetconfig = UnsetConfig <$> strOption
( long "unset"
<> help "unset configuration"
<> metavar paramName
)
seek :: Action -> CommandSeek
seek (SetConfig name val) = commandAction $ do
allowMessages
showStart name val
next $ next $ do
setGlobalConfig name val
setConfig (ConfigKey name) val
return True
seek (UnsetConfig name) = commandAction $ do
allowMessages
showStart name "unset"
next $ next $ do
unsetGlobalConfig name
unsetConfig (ConfigKey name)
return True
seek (GetConfig name) = commandAction $ do
mv <- getGlobalConfig name
case mv of
Nothing -> stop
Just v -> do
liftIO $ putStrLn v
stop