diff options
Diffstat (limited to 'Annex/Version.hs')
-rw-r--r-- | Annex/Version.hs | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/Annex/Version.hs b/Annex/Version.hs new file mode 100644 index 000000000..e501dbf2e --- /dev/null +++ b/Annex/Version.hs @@ -0,0 +1,46 @@ +{- git-annex repository versioning + - + - Copyright 2010 Joey Hess <joey@kitenet.net> + - + - Licensed under the GNU GPL version 3 or higher. + -} + +module Annex.Version where + +import Annex.Common +import qualified Git +import Config + +type Version = String + +defaultVersion :: Version +defaultVersion = "3" + +supportedVersions :: [Version] +supportedVersions = [defaultVersion] + +upgradableVersions :: [Version] +upgradableVersions = ["0", "1", "2"] + +versionField :: String +versionField = "annex.version" + +getVersion :: Annex (Maybe Version) +getVersion = do + g <- gitRepo + let v = Git.configGet g versionField "" + if not $ null v + then return $ Just v + else return Nothing + +setVersion :: Annex () +setVersion = setConfig versionField defaultVersion + +checkVersion :: Version -> Annex () +checkVersion v + | v `elem` supportedVersions = return () + | v `elem` upgradableVersions = err "Upgrade this repository: git-annex upgrade" + | otherwise = err "Upgrade git-annex." + where + err msg = error $ "Repository version " ++ v ++ + " is not supported. " ++ msg |