git-annex/Command/Trust.hs

55 lines
1.6 KiB
Haskell
Raw Normal View History

2010-12-28 21:44:55 +00:00
{- git-annex command
-
- Copyright 2010-2023 Joey Hess <id@joeyh.name>
2010-12-28 21:44:55 +00:00
-
- Licensed under the GNU AGPL version 3 or higher.
2010-12-28 21:44:55 +00:00
-}
module Command.Trust where
import Command
import qualified Remote
import qualified Annex
import Types.TrustLevel
2011-10-15 20:21:08 +00:00
import Logs.Trust
2014-02-20 19:12:35 +00:00
import Logs.Group
import qualified Data.Set as S
2010-12-28 21:44:55 +00:00
cmd :: Command
cmd = withAnnexOptions [jsonOptions] $
command "trust" SectionSetup "trust a repository"
(paramRepeating paramRepository) (withParams seek)
seek :: CmdParams -> CommandSeek
2014-02-20 19:12:35 +00:00
seek = trustCommand "trust" Trusted
2010-12-28 21:44:55 +00:00
trustCommand :: String -> TrustLevel -> CmdParams -> CommandSeek
trustCommand _ _ [] = giveup "no repository name specified"
trustCommand c level ps = withStrings (commandAction . start) ps
2014-02-20 19:12:35 +00:00
where
start name = do
2014-02-20 19:12:35 +00:00
u <- Remote.nameToUUID name
let si = SeekInput [name]
starting c (ActionItemUUID u (UnquotedString name)) si (perform name u)
perform name uuid = do
when (level >= Trusted) $
unlessM (Annex.getRead Annex.force) $
giveup $ trustedNeedsForce name
2014-02-20 19:12:35 +00:00
trustSet uuid level
when (level == DeadTrusted) $
groupSet uuid S.empty
l <- lookupTrust uuid
when (l /= level) $
warning $ UnquotedString $ "This remote's trust level is overridden to " ++ showTrustLevel l ++ "."
2014-02-20 19:12:35 +00:00
next $ return True
trustedNeedsForce :: String -> String
trustedNeedsForce name = unwords
[ "Trusting a repository can lead to data loss."
, "If you're sure you know what you're doing, use --force to"
, "make this take effect."
, "If you choose to do so, bear in mind that any time you drop"
, "content from " ++ name ++ ", you will risk losing data."
]