diff --git a/Annex/Init.hs b/Annex/Init.hs index 2eb76c2bca..ca57337a7b 100644 --- a/Annex/Init.hs +++ b/Annex/Init.hs @@ -141,12 +141,7 @@ uninitialize = do - Checks repository version and handles upgrades too. -} ensureInitialized :: Annex () -ensureInitialized = ifM isDirect - ( unlessM (catchBoolIO $ upgrade True defaultVersion) $ do - g <- Annex.gitRepo - giveup $ "Upgrading direct mode repository " ++ Git.repoDescribe g ++ " failed, and direct mode is no longer supported." - , getVersion >>= maybe needsinit checkUpgrade - ) +ensureInitialized = getVersion >>= maybe needsinit checkUpgrade where needsinit = ifM Annex.Branch.hasSibling ( initialize Nothing Nothing diff --git a/CHANGELOG b/CHANGELOG index d77fe1f7bb..e039b2c47b 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -4,6 +4,8 @@ git-annex (7.20190826) UNRELEASED; urgency=medium * Automatically upgrade v5 repositories to v7. * Automatically convert direct mode repositories to v7 with adjusted unlocked branches and set annex.thin. + * Added annex.autoupgraderepository configuration that can be set to false + to prevent any automatic repository upgrades. * Refuse to upgrade direct mode repositories when git is older than 2.22, which fixed a memory leak that could cause an OOM during the upgrade. * assistant: When creating a new repository, no longer use direct diff --git a/Command/Upgrade.hs b/Command/Upgrade.hs index 00e972ae5d..ead0c4b867 100644 --- a/Command/Upgrade.hs +++ b/Command/Upgrade.hs @@ -13,9 +13,13 @@ import Annex.Version import Annex.Init cmd :: Command -cmd = dontCheck repoExists $ -- because an old version may not seem to exist - noDaemonRunning $ -- avoid upgrading repo out from under daemon - command "upgrade" SectionMaintenance "upgrade repository layout" +cmd = dontCheck repoExists $ + -- ^ because an old version may not seem to exist + -- and also, this avoids automatic silent upgrades before + -- this command can start up. + noDaemonRunning $ + -- ^ avoid upgrading repo out from under daemon + command "upgrade" SectionMaintenance "upgrade repository" paramNothing (withParams seek) seek :: CmdParams -> CommandSeek diff --git a/Types/GitConfig.hs b/Types/GitConfig.hs index 7976f08e9f..9e37bc1f3a 100644 --- a/Types/GitConfig.hs +++ b/Types/GitConfig.hs @@ -103,6 +103,7 @@ data GitConfig = GitConfig , annexMaxExtensionLength :: Maybe Int , annexJobs :: Concurrency , annexCacheCreds :: Bool + , annexAutoUpgradeRepository :: Bool , coreSymlinks :: Bool , coreSharedRepository :: SharedRepository , receiveDenyCurrentBranch :: DenyCurrentBranch @@ -182,6 +183,7 @@ extractGitConfig r = GitConfig , annexJobs = fromMaybe NonConcurrent $ parseConcurrency =<< getmaybe (annex "jobs") , annexCacheCreds = getbool (annex "cachecreds") True + , annexAutoUpgradeRepository = getbool (annex "autoupgraderepository") True , coreSymlinks = getbool "core.symlinks" True , coreSharedRepository = getSharedRepository r , receiveDenyCurrentBranch = getDenyCurrentBranch r diff --git a/Upgrade.hs b/Upgrade.hs index 353572574a..981710de47 100644 --- a/Upgrade.hs +++ b/Upgrade.hs @@ -1,6 +1,6 @@ {- git-annex upgrade support - - - Copyright 2010, 2013 Joey Hess + - Copyright 2010-2019 Joey Hess - - Licensed under the GNU AGPL version 3 or higher. -} @@ -10,6 +10,8 @@ module Upgrade where import Annex.Common +import qualified Annex +import qualified Git import Annex.Version import Types.RepoVersion #ifndef mingw32_HOST_OS @@ -36,14 +38,23 @@ needsUpgrade v err "Upgrade this repository: git-annex upgrade" | otherwise -> err "Upgrade git-annex." - Just newv -> ifM (upgrade True newv) - ( ok - , err "Automatic upgrade failed!" + Just newv -> ifM (annexAutoUpgradeRepository <$> Annex.getGitConfig) + ( tryNonAsync (upgrade True newv) >>= \case + Right True -> ok + Right False -> "Automatic upgrade failed!" + Left err -> "Automatic upgrade exception! " ++ show err + , err "Automatic upgrade is disabled by annex.autoupgraderepository configuration. To upgrade this repository: git-annex upgrade" ) where - err msg = return $ Just $ "Repository version " ++ - show (fromRepoVersion v) ++ - " is not supported. " ++ msg + err msg = do + g <- Annex.gitRepo + p <- liftIO $ absPath $ Git.repoPath g + return $ Just $ unwords + [ "Repository", p + , "is at unsupported version" + , show (fromRepoVersion v) ++ "." + , msg + ] ok = return Nothing upgrade :: Bool -> RepoVersion -> Annex Bool @@ -74,3 +85,4 @@ upgrade automatic destversion = do up (RepoVersion 5) = Upgrade.V5.upgrade automatic up (RepoVersion 6) = Upgrade.V6.upgrade automatic up _ = return True + diff --git a/doc/git-annex-upgrade.mdwn b/doc/git-annex-upgrade.mdwn index 07b319cc11..c27fedd642 100644 --- a/doc/git-annex-upgrade.mdwn +++ b/doc/git-annex-upgrade.mdwn @@ -1,6 +1,6 @@ # NAME -git-annex upgrade - upgrade repository layout +git-annex upgrade - upgrade repository # SYNOPSIS @@ -8,13 +8,16 @@ git annex upgrade # DESCRIPTION -Upgrades the repository to current layout. +Upgrades the repository. Each git-annex repository has an annex.version in its git configuration, -that indicates the repository version. If git-annex changes to a new -layout, you must upgrade the repository before git-annex can be used in it. +that indicates the repository version. When an old repository version +becomes deprecated, git-annex will automatically upgrade it +(unless annex.autoupgraderepository is set to false). To manually upgrade, +you can use this command. -To see version information, run `git annex version`. +Sometimes there's a newer repository version that is not the default yet, +and then you can use this command to upgrade to it. Currently, git-annex supports upgrades all the way back to version 0, which was only used by its author. It's expected that git-annex will always diff --git a/doc/git-annex.mdwn b/doc/git-annex.mdwn index 33c6ee26b9..121e0d9477 100644 --- a/doc/git-annex.mdwn +++ b/doc/git-annex.mdwn @@ -383,7 +383,7 @@ subdirectories). * `upgrade` - Upgrades the repository to current layout. + Upgrades the repository. See [[git-annex-upgrade]](1) for details. @@ -1066,7 +1066,19 @@ Like other git commands, git-annex is configured via `.git/config`. * `annex.version` - Automatically maintained, and used to automate upgrades between versions. + The current version of the git-annex repository. This is + maintained by git-annex and should never be manually changed. + +* `annex.autoupgraderepository` + + When an old git-annex repository version has become deprecated, + git-annex will normally automatically upgrade the repository to + the new version. + + If this is set to false, git-annex won't automatically upgrade the + repository. Instead it will exit with an error message. You can run + `git annex upgrade` yourself when you are ready to upgrade the + repository. * `annex.crippledfilesystem`