diff --git a/Annex/Init.hs b/Annex/Init.hs index 614c307a0b..c05263c7df 100644 --- a/Annex/Init.hs +++ b/Annex/Init.hs @@ -65,8 +65,8 @@ import qualified System.FilePath.ByteString as P import Control.Concurrent.Async #endif -checkCanInitialize :: Annex a -> Annex a -checkCanInitialize a = canInitialize' >>= \case +checkInitializeAllowed :: Annex a -> Annex a +checkInitializeAllowed a = noAnnexFileContent' >>= \case Nothing -> a Just noannexmsg -> do warning "Initialization prevented by .noannex file (remove the file to override)" @@ -74,11 +74,12 @@ checkCanInitialize a = canInitialize' >>= \case warning noannexmsg giveup "Not initialized." -canInitialize :: Annex Bool -canInitialize = isNothing <$> canInitialize' +initializeAllowed :: Annex Bool +initializeAllowed = isNothing <$> noAnnexFileContent' -canInitialize' :: Annex (Maybe String) -canInitialize' = inRepo (noAnnexFileContent . fmap fromRawFilePath . Git.repoWorkTree) +noAnnexFileContent' :: Annex (Maybe String) +noAnnexFileContent' = inRepo $ + noAnnexFileContent . fmap fromRawFilePath . Git.repoWorkTree genDescription :: Maybe String -> Annex UUIDDesc genDescription (Just d) = return $ UUIDDesc $ encodeBS d @@ -94,7 +95,7 @@ genDescription Nothing = do Left _ -> [hostname, ":", reldir] initialize :: Maybe String -> Maybe RepoVersion -> Annex () -initialize mdescription mversion = checkCanInitialize $ do +initialize mdescription mversion = checkInitializeAllowed $ do {- Has to come before any commits are made as the shared - clone heuristic expects no local objects. -} sharedclone <- checkSharedClone @@ -117,7 +118,7 @@ initialize mdescription mversion = checkCanInitialize $ do -- Everything except for uuid setup, shared clone setup, and initial -- description. initialize' :: Maybe RepoVersion -> Annex () -initialize' mversion = checkCanInitialize $ do +initialize' mversion = checkInitializeAllowed $ do checkLockSupport checkFifoSupport checkCrippledFileSystem @@ -168,21 +169,26 @@ uninitialize = do ensureInitialized :: Annex () ensureInitialized = getVersion >>= maybe needsinit checkUpgrade where - needsinit = ifM Annex.Branch.hasSibling + needsinit = ifM autoInitializeAllowed ( do initialize Nothing Nothing autoEnableSpecialRemotes , giveup "First run: git-annex init" ) -{- Initialize if it can do so automatically. +{- Check if auto-initialize is allowed. -} +autoInitializeAllowed :: Annex Bool +autoInitializeAllowed = Annex.Branch.hasSibling + +{- Initialize if it can do so automatically. Avoids failing if it cannot. - - Checks repository version and handles upgrades too. -} autoInitialize :: Annex () autoInitialize = getVersion >>= maybe needsinit checkUpgrade where - needsinit = whenM (canInitialize <&&> Annex.Branch.hasSibling) $ do + needsinit = + whenM (initializeAllowed <&&> autoInitializeAllowed) $ do initialize Nothing Nothing autoEnableSpecialRemotes diff --git a/Config/Files.hs b/Config/Files.hs index c53ca646a4..83e4eda085 100644 --- a/Config/Files.hs +++ b/Config/Files.hs @@ -29,7 +29,7 @@ programFile :: IO FilePath programFile = userConfigFile "program" {- A .noannex file in a git repository prevents git-annex from - - initializing that repository.. The content of the file is returned. -} + - initializing that repository. The content of the file is returned. -} noAnnexFileContent :: Maybe FilePath -> IO (Maybe String) noAnnexFileContent repoworktree = case repoworktree of Nothing -> return Nothing