diff options
Diffstat (limited to 'Config.hs')
-rw-r--r-- | Config.hs | 18 |
1 files changed, 11 insertions, 7 deletions
@@ -18,10 +18,16 @@ import Config.Cost type UnqualifiedConfigKey = String data ConfigKey = ConfigKey String +instance Show ConfigKey where + show (ConfigKey s) = s + {- Looks up a setting in git config. -} getConfig :: ConfigKey -> String -> Annex String getConfig (ConfigKey key) def = fromRepo $ Git.Config.get key def +getConfigMaybe :: ConfigKey -> Annex (Maybe String) +getConfigMaybe (ConfigKey key) = fromRepo $ Git.Config.getMaybe key + {- Changes a git config setting in both internal state and .git/config -} setConfig :: ConfigKey -> String -> Annex () setConfig (ConfigKey key) value = do @@ -30,8 +36,11 @@ setConfig (ConfigKey key) value = do {- Unsets a git config setting. (Leaves it in state currently.) -} unsetConfig :: ConfigKey -> Annex () -unsetConfig (ConfigKey key) = inRepo $ Git.Command.run - [Param "config", Param "--unset", Param key] +unsetConfig ck@(ConfigKey key) = ifM (isJust <$> getConfigMaybe ck) + ( inRepo $ Git.Command.run + [Param "config", Param "--unset", Param key] + , noop -- avoid unsetting something not set; that would fail + ) {- A per-remote config setting in git config. -} remoteConfig :: Git.Repo -> UnqualifiedConfigKey -> ConfigKey @@ -62,11 +71,6 @@ getNumCopies Nothing = annexNumCopies <$> Annex.getGitConfig isDirect :: Annex Bool isDirect = annexDirect <$> Annex.getGitConfig -setDirect :: Bool -> Annex () -setDirect b = do - setConfig (annexConfig "direct") (Git.Config.boolConfig b) - Annex.changeGitConfig $ \c -> c { annexDirect = b } - crippledFileSystem :: Annex Bool crippledFileSystem = annexCrippledFileSystem <$> Annex.getGitConfig |