2010-11-02 23:04:24 +00:00
|
|
|
{- git-annex command
|
|
|
|
-
|
2020-05-27 15:54:39 +00:00
|
|
|
- Copyright 2010-2020 Joey Hess <id@joeyh.name>
|
2010-11-02 23:04:24 +00:00
|
|
|
-
|
2019-03-13 19:48:14 +00:00
|
|
|
- Licensed under the GNU AGPL version 3 or higher.
|
2010-11-02 23:04:24 +00:00
|
|
|
-}
|
|
|
|
|
|
|
|
module Command.Init where
|
|
|
|
|
|
|
|
import Command
|
2014-01-26 20:36:31 +00:00
|
|
|
import Annex.Init
|
2015-12-15 21:17:13 +00:00
|
|
|
import Annex.Version
|
2018-10-25 21:23:53 +00:00
|
|
|
import Types.RepoVersion
|
2015-09-14 18:49:48 +00:00
|
|
|
import qualified Annex.SpecialRemote
|
2018-10-26 15:44:05 +00:00
|
|
|
|
2020-02-28 16:57:55 +00:00
|
|
|
import Control.Monad.Fail as Fail (MonadFail(..))
|
2018-10-26 15:44:05 +00:00
|
|
|
import qualified Data.Map as M
|
2010-12-30 19:06:26 +00:00
|
|
|
|
2015-07-08 16:33:27 +00:00
|
|
|
cmd :: Command
|
|
|
|
cmd = dontCheck repoExists $
|
2015-07-08 19:08:02 +00:00
|
|
|
command "init" SectionSetup "initialize git-annex"
|
2015-12-15 21:17:13 +00:00
|
|
|
paramDesc (seek <$$> optParser)
|
2010-11-02 23:04:24 +00:00
|
|
|
|
2015-12-15 21:17:13 +00:00
|
|
|
data InitOptions = InitOptions
|
|
|
|
{ initDesc :: String
|
2018-10-25 21:23:53 +00:00
|
|
|
, initVersion :: Maybe RepoVersion
|
2020-05-27 15:54:39 +00:00
|
|
|
, autoEnableOnly :: Bool
|
2015-12-15 21:17:13 +00:00
|
|
|
}
|
2010-11-11 22:54:52 +00:00
|
|
|
|
2015-12-15 21:17:13 +00:00
|
|
|
optParser :: CmdParamsDesc -> Parser InitOptions
|
|
|
|
optParser desc = InitOptions
|
|
|
|
<$> (unwords <$> cmdParams desc)
|
2018-10-25 21:23:53 +00:00
|
|
|
<*> optional (option (str >>= parseRepoVersion)
|
2015-12-15 21:17:13 +00:00
|
|
|
( long "version" <> metavar paramValue
|
|
|
|
<> help "Override default annex.version"
|
|
|
|
))
|
2020-05-27 15:54:39 +00:00
|
|
|
<*> switch
|
|
|
|
( long "autoenable"
|
|
|
|
<> help "only enable special remotes configured with autoenable=true"
|
|
|
|
)
|
2010-11-02 23:04:24 +00:00
|
|
|
|
2020-02-28 10:56:48 +00:00
|
|
|
parseRepoVersion :: MonadFail m => String -> m RepoVersion
|
2018-10-25 21:23:53 +00:00
|
|
|
parseRepoVersion s = case RepoVersion <$> readish s of
|
2020-02-28 10:56:48 +00:00
|
|
|
Nothing -> Fail.fail $ "version parse error"
|
2018-10-25 21:23:53 +00:00
|
|
|
Just v
|
|
|
|
| v `elem` supportedVersions -> return v
|
2018-10-26 15:44:05 +00:00
|
|
|
| otherwise -> case M.lookup v autoUpgradeableVersions of
|
|
|
|
Just v' -> return v'
|
2020-02-28 10:56:48 +00:00
|
|
|
Nothing -> Fail.fail $ s ++ " is not a currently supported repository version"
|
2015-12-15 21:17:13 +00:00
|
|
|
|
|
|
|
seek :: InitOptions -> CommandSeek
|
|
|
|
seek = commandAction . start
|
|
|
|
|
|
|
|
start :: InitOptions -> CommandStart
|
2020-05-27 15:54:39 +00:00
|
|
|
start os
|
2020-09-14 20:49:33 +00:00
|
|
|
| autoEnableOnly os =
|
|
|
|
starting "init" (ActionItemOther (Just "autoenable")) si $
|
|
|
|
performAutoEnableOnly
|
|
|
|
| otherwise =
|
|
|
|
starting "init" (ActionItemOther (Just $ initDesc os)) si $
|
|
|
|
perform os
|
|
|
|
where
|
|
|
|
si = SeekInput []
|
2015-12-15 21:17:13 +00:00
|
|
|
|
|
|
|
perform :: InitOptions -> CommandPerform
|
|
|
|
perform os = do
|
2019-08-08 18:12:46 +00:00
|
|
|
case initVersion os of
|
|
|
|
Nothing -> noop
|
|
|
|
Just wantversion -> getVersion >>= \case
|
|
|
|
Just v | v /= wantversion ->
|
|
|
|
giveup $ "This repository is already a initialized with version " ++ show (fromRepoVersion v) ++ ", not changing to requested version."
|
|
|
|
_ -> noop
|
2021-07-30 22:36:03 +00:00
|
|
|
initialize False
|
2015-12-15 21:17:13 +00:00
|
|
|
(if null (initDesc os) then Nothing else Just (initDesc os))
|
|
|
|
(initVersion os)
|
2015-09-14 18:49:48 +00:00
|
|
|
Annex.SpecialRemote.autoEnable
|
2011-06-22 20:03:26 +00:00
|
|
|
next $ return True
|
2020-05-27 15:54:39 +00:00
|
|
|
|
|
|
|
performAutoEnableOnly :: CommandPerform
|
|
|
|
performAutoEnableOnly = do
|
|
|
|
Annex.SpecialRemote.autoEnable
|
|
|
|
next $ return True
|