slways set current version in new repos

detect v1 repos that don't have a version set
This commit is contained in:
Joey Hess 2011-03-16 02:15:54 -04:00
parent e227c210ec
commit a4d0250298
2 changed files with 17 additions and 11 deletions

View file

@ -17,8 +17,7 @@ upgrade :: Annex Bool
upgrade = do upgrade = do
version <- getVersion version <- getVersion
case version of case version of
Just "0" -> Upgrade.V0.upgrade "0" -> Upgrade.V0.upgrade
Just "1" -> Upgrade.V1.upgrade "1" -> Upgrade.V1.upgrade
Nothing -> return True -- repo not initted yet, no version v | v == currentVersion -> return True
Just v | v == currentVersion -> return True _ -> error "this version of git-annex is too old for this git repository!"
Just _ -> error "this version of git-annex is too old for this git repository!"

View file

@ -21,21 +21,28 @@ currentVersion = "2"
versionField :: String versionField :: String
versionField = "annex.version" versionField = "annex.version"
getVersion :: Annex (Maybe String) getVersion :: Annex String
getVersion = do getVersion = do
g <- Annex.gitRepo g <- Annex.gitRepo
let v = Git.configGet g versionField "" let v = Git.configGet g versionField ""
if not $ null v if not $ null v
then return $ Just v then return v
else do else do
-- version 0 was not recorded in .git/config; -- version 0 was not recorded in .git/config;
-- such a repo should have an gitAnnexDir but no -- such a repo should have an gitAnnexDir but no
-- gitAnnexObjectDir -- gitAnnexObjectDir.
--
-- version 1 may not be recorded if the user
-- forgot to init. Such a repo should have a
-- gitAnnexObjectDir already.
d <- liftIO $ doesDirectoryExist $ gitAnnexDir g d <- liftIO $ doesDirectoryExist $ gitAnnexDir g
o <- liftIO $ doesDirectoryExist $ gitAnnexObjectDir g o <- liftIO $ doesDirectoryExist $ gitAnnexObjectDir g
if d && not o case (d, o) of
then return $ Just "0" (True, False) -> return "0"
else return Nothing -- no version yet (True, True) -> return "1"
_ -> do
setVersion
return currentVersion
setVersion :: Annex () setVersion :: Annex ()
setVersion = Annex.setConfig versionField currentVersion setVersion = Annex.setConfig versionField currentVersion