git-annex/Command/Init.hs
Joey Hess 3cc94c1667
.noannex file
A top-level .noannex file will prevent git-annex init from being used in a
repository. This is useful for repositories that have a policy reason not
to use git-annex. The content of the file will be displayed to the user who
tries to run git-annex init.

This also affects git annex reinit and initialization via the webapp.
It does not affect automatic inits, when there's a sibling git-annex branch
already.

This commit was supported by the NSF-funded DataLad project.
2017-12-13 14:34:32 -04:00

52 lines
1.3 KiB
Haskell

{- git-annex command
-
- Copyright 2010 Joey Hess <id@joeyh.name>
-
- Licensed under the GNU GPL version 3 or higher.
-}
module Command.Init where
import Command
import Annex.Init
import Annex.Version
import qualified Annex.SpecialRemote
cmd :: Command
cmd = dontCheck repoExists $
command "init" SectionSetup "initialize git-annex"
paramDesc (seek <$$> optParser)
data InitOptions = InitOptions
{ initDesc :: String
, initVersion :: Maybe Version
}
optParser :: CmdParamsDesc -> Parser InitOptions
optParser desc = InitOptions
<$> (unwords <$> cmdParams desc)
<*> optional (option (str >>= parseVersion)
( long "version" <> metavar paramValue
<> help "Override default annex.version"
))
parseVersion :: Monad m => String -> m Version
parseVersion v
| v `elem` supportedVersions = return v
| otherwise = fail $ v ++ " is not a currently supported repository version"
seek :: InitOptions -> CommandSeek
seek = commandAction . start
start :: InitOptions -> CommandStart
start os = do
showStart' "init" (Just $ initDesc os)
next $ perform os
perform :: InitOptions -> CommandPerform
perform os = do
initialize (AutoInit False)
(if null (initDesc os) then Nothing else Just (initDesc os))
(initVersion os)
Annex.SpecialRemote.autoEnable
next $ return True