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)"
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
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
-- 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
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