summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2011-03-16 02:15:54 -0400
committerGravatar Joey Hess <joey@kitenet.net>2011-03-16 02:16:25 -0400
commita4d0250298a503c7d9093e6dd1618ff5b07b19e5 (patch)
treeb47ca090446bae9c713eda47ba0425c8eb89390c
parente227c210ec817eca6b4409cb4cc893f791d51c00 (diff)
slways set current version in new repos
detect v1 repos that don't have a version set
-rw-r--r--Upgrade.hs9
-rw-r--r--Version.hs19
2 files changed, 17 insertions, 11 deletions
diff --git a/Upgrade.hs b/Upgrade.hs
index a15258204..76dd156f8 100644
--- a/Upgrade.hs
+++ b/Upgrade.hs
@@ -17,8 +17,7 @@ upgrade :: Annex Bool
upgrade = do
version <- getVersion
case version of
- Just "0" -> Upgrade.V0.upgrade
- Just "1" -> Upgrade.V1.upgrade
- Nothing -> return True -- repo not initted yet, no version
- Just v | v == currentVersion -> return True
- Just _ -> error "this version of git-annex is too old for this git repository!"
+ "0" -> Upgrade.V0.upgrade
+ "1" -> Upgrade.V1.upgrade
+ v | v == currentVersion -> return True
+ _ -> error "this version of git-annex is too old for this git repository!"
diff --git a/Version.hs b/Version.hs
index 7fdbd1a49..5f414e93b 100644
--- a/Version.hs
+++ b/Version.hs
@@ -21,21 +21,28 @@ currentVersion = "2"
versionField :: String
versionField = "annex.version"
-getVersion :: Annex (Maybe String)
+getVersion :: Annex String
getVersion = do
g <- Annex.gitRepo
let v = Git.configGet g versionField ""
if not $ null v
- then return $ Just v
+ then return v
else do
-- version 0 was not recorded in .git/config;
-- 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
o <- liftIO $ doesDirectoryExist $ gitAnnexObjectDir g
- if d && not o
- then return $ Just "0"
- else return Nothing -- no version yet
+ case (d, o) of
+ (True, False) -> return "0"
+ (True, True) -> return "1"
+ _ -> do
+ setVersion
+ return currentVersion
setVersion :: Annex ()
setVersion = Annex.setConfig versionField currentVersion