pre-init config and hook
Added annex.pre-init-command git config and pre-init-annex hook that is run before git-annex repository initialization. This can block initialization. Or it can preform pre-initialization configuration or tweaking. I left stdio connected while it's running, so it could also be used for interactive prompting conceivably, although that would want to use /dev/tty anyway probably in order to not pollute the stdout of a command when automatic initialization is done. Sponsored-by: Dartmouth College's OpenNeuro project
This commit is contained in:
parent
9e95556d69
commit
42d55bc57c
9 changed files with 87 additions and 19 deletions
|
@ -1,6 +1,6 @@
|
|||
{- git-annex repository initialization
|
||||
-
|
||||
- Copyright 2011-2024 Joey Hess <id@joeyh.name>
|
||||
- Copyright 2011-2025 Joey Hess <id@joeyh.name>
|
||||
-
|
||||
- Licensed under the GNU AGPL version 3 or higher.
|
||||
-}
|
||||
|
@ -74,17 +74,29 @@ data InitializeAllowed = InitializeAllowed
|
|||
|
||||
checkInitializeAllowed :: (InitializeAllowed -> Annex a) -> Annex a
|
||||
checkInitializeAllowed a = guardSafeToUseRepo $ noAnnexFileContent' >>= \case
|
||||
Nothing -> do
|
||||
checkSqliteWorks
|
||||
a InitializeAllowed
|
||||
Nothing -> runAnnexHook' preInitAnnexHook annexPreInitCommand >>= \case
|
||||
Nothing -> do
|
||||
checkSqliteWorks
|
||||
a InitializeAllowed
|
||||
Just failedcommanddesc -> do
|
||||
initpreventedby failedcommanddesc
|
||||
notinitialized
|
||||
Just noannexmsg -> do
|
||||
warning "Initialization prevented by .noannex file (remove the file to override)"
|
||||
initpreventedby ".noannex file (remove the file to override)"
|
||||
unless (null noannexmsg) $
|
||||
warning (UnquotedString noannexmsg)
|
||||
giveup "Not initialized."
|
||||
notinitialized
|
||||
where
|
||||
initpreventedby r = warning $ UnquotedString $
|
||||
"Initialization prevented by " ++ r
|
||||
notinitialized = giveup "Not initialized."
|
||||
|
||||
initializeAllowed :: Annex Bool
|
||||
initializeAllowed = isNothing <$> noAnnexFileContent'
|
||||
initializeAllowed = noAnnexFileContent' >>= \case
|
||||
Nothing -> runAnnexHook' preInitAnnexHook annexPreInitCommand >>= \case
|
||||
Nothing -> return True
|
||||
Just _ -> return False
|
||||
Just _ -> return False
|
||||
|
||||
noAnnexFileContent' :: Annex (Maybe String)
|
||||
noAnnexFileContent' = inRepo $
|
||||
|
@ -268,7 +280,7 @@ autoInitialize' check startupannex remotelist =
|
|||
getInitializedVersion >>= maybe needsinit checkUpgrade
|
||||
where
|
||||
needsinit =
|
||||
whenM (initializeAllowed <&&> check) $ do
|
||||
whenM (check <&&> initializeAllowed) $ do
|
||||
initialize startupannex Nothing Nothing
|
||||
autoEnableSpecialRemotes remotelist
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue