.noannex file
A top-level .noannex file will prevent git-annex init from being used in a repository. This is useful for repositories that have a policy reason not to use git-annex. The content of the file will be displayed to the user who tries to run git-annex init. This also affects git annex reinit and initialization via the webapp. It does not affect automatic inits, when there's a sibling git-annex branch already. This commit was supported by the NSF-funded DataLad project.
This commit is contained in:
parent
95ec530324
commit
3cc94c1667
10 changed files with 41 additions and 12 deletions
|
@ -8,6 +8,7 @@
|
||||||
{-# LANGUAGE CPP #-}
|
{-# LANGUAGE CPP #-}
|
||||||
|
|
||||||
module Annex.Init (
|
module Annex.Init (
|
||||||
|
AutoInit(..),
|
||||||
ensureInitialized,
|
ensureInitialized,
|
||||||
isInitialized,
|
isInitialized,
|
||||||
initialize,
|
initialize,
|
||||||
|
@ -48,6 +49,23 @@ import System.Posix.User
|
||||||
import qualified Utility.LockFile.Posix as Posix
|
import qualified Utility.LockFile.Posix as Posix
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
newtype AutoInit = AutoInit Bool
|
||||||
|
|
||||||
|
checkCanInitialize :: AutoInit -> Annex a -> Annex a
|
||||||
|
checkCanInitialize (AutoInit True) a = a
|
||||||
|
checkCanInitialize (AutoInit False) a = fromRepo Git.repoWorkTree >>= \case
|
||||||
|
Nothing -> a
|
||||||
|
Just wt -> liftIO (catchMaybeIO (readFile (wt </> ".noannex"))) >>= \case
|
||||||
|
Nothing -> a
|
||||||
|
Just noannexmsg -> ifM (Annex.getState Annex.force)
|
||||||
|
( a
|
||||||
|
, do
|
||||||
|
warning "Initialization prevented by .noannex file (use --force to override)"
|
||||||
|
unless (null noannexmsg) $
|
||||||
|
warning noannexmsg
|
||||||
|
giveup "Not initialized."
|
||||||
|
)
|
||||||
|
|
||||||
genDescription :: Maybe String -> Annex String
|
genDescription :: Maybe String -> Annex String
|
||||||
genDescription (Just d) = return d
|
genDescription (Just d) = return d
|
||||||
genDescription Nothing = do
|
genDescription Nothing = do
|
||||||
|
@ -59,8 +77,8 @@ genDescription Nothing = do
|
||||||
Right username -> [username, at, hostname, ":", reldir]
|
Right username -> [username, at, hostname, ":", reldir]
|
||||||
Left _ -> [hostname, ":", reldir]
|
Left _ -> [hostname, ":", reldir]
|
||||||
|
|
||||||
initialize :: Maybe String -> Maybe Version -> Annex ()
|
initialize :: AutoInit -> Maybe String -> Maybe Version -> Annex ()
|
||||||
initialize mdescription mversion = do
|
initialize ai mdescription mversion = checkCanInitialize ai $ do
|
||||||
{- Has to come before any commits are made as the shared
|
{- Has to come before any commits are made as the shared
|
||||||
- clone heuristic expects no local objects. -}
|
- clone heuristic expects no local objects. -}
|
||||||
sharedclone <- checkSharedClone
|
sharedclone <- checkSharedClone
|
||||||
|
@ -70,7 +88,7 @@ initialize mdescription mversion = do
|
||||||
ensureCommit $ Annex.Branch.create
|
ensureCommit $ Annex.Branch.create
|
||||||
|
|
||||||
prepUUID
|
prepUUID
|
||||||
initialize' mversion
|
initialize' (AutoInit True) mversion
|
||||||
|
|
||||||
initSharedClone sharedclone
|
initSharedClone sharedclone
|
||||||
|
|
||||||
|
@ -79,8 +97,8 @@ initialize mdescription mversion = do
|
||||||
|
|
||||||
-- Everything except for uuid setup, shared clone setup, and initial
|
-- Everything except for uuid setup, shared clone setup, and initial
|
||||||
-- description.
|
-- description.
|
||||||
initialize' :: Maybe Version -> Annex ()
|
initialize' :: AutoInit -> Maybe Version -> Annex ()
|
||||||
initialize' mversion = do
|
initialize' ai mversion = checkCanInitialize ai $ do
|
||||||
checkLockSupport
|
checkLockSupport
|
||||||
checkFifoSupport
|
checkFifoSupport
|
||||||
checkCrippledFileSystem
|
checkCrippledFileSystem
|
||||||
|
@ -131,7 +149,7 @@ ensureInitialized :: Annex ()
|
||||||
ensureInitialized = getVersion >>= maybe needsinit checkUpgrade
|
ensureInitialized = getVersion >>= maybe needsinit checkUpgrade
|
||||||
where
|
where
|
||||||
needsinit = ifM Annex.Branch.hasSibling
|
needsinit = ifM Annex.Branch.hasSibling
|
||||||
( initialize Nothing Nothing
|
( initialize (AutoInit True) Nothing Nothing
|
||||||
, giveup "First run: git-annex init"
|
, giveup "First run: git-annex init"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -76,7 +76,7 @@ initRepo False _ dir desc mgroup = inDir dir $ do
|
||||||
|
|
||||||
initRepo' :: Maybe String -> Maybe StandardGroup -> Annex ()
|
initRepo' :: Maybe String -> Maybe StandardGroup -> Annex ()
|
||||||
initRepo' desc mgroup = unlessM isInitialized $ do
|
initRepo' desc mgroup = unlessM isInitialized $ do
|
||||||
initialize desc Nothing
|
initialize (AutoInit False) desc Nothing
|
||||||
u <- getUUID
|
u <- getUUID
|
||||||
maybe noop (defaultStandardGroup u) mgroup
|
maybe noop (defaultStandardGroup u) mgroup
|
||||||
{- Ensure branch gets committed right away so it is
|
{- Ensure branch gets committed right away so it is
|
||||||
|
|
|
@ -16,6 +16,10 @@ git-annex (6.20171125) UNRELEASED; urgency=medium
|
||||||
(Previous try had a bug.)
|
(Previous try had a bug.)
|
||||||
* lookupkey: Support being given an absolute filename to a file
|
* lookupkey: Support being given an absolute filename to a file
|
||||||
within the current git repository.
|
within the current git repository.
|
||||||
|
* A top-level .noannex file will prevent git-annex init from being used
|
||||||
|
in a repository. This is useful for repositories that have a policy
|
||||||
|
reason not to use git-annex. The content of the file will be displayed
|
||||||
|
to the user who tries to run git-annex init.
|
||||||
|
|
||||||
-- Joey Hess <id@joeyh.name> Tue, 28 Nov 2017 13:48:44 -0400
|
-- Joey Hess <id@joeyh.name> Tue, 28 Nov 2017 13:48:44 -0400
|
||||||
|
|
||||||
|
|
|
@ -45,7 +45,7 @@ findOrGenUUID = do
|
||||||
else ifM (Annex.Branch.hasSibling <||> (isJust <$> Fields.getField Fields.autoInit))
|
else ifM (Annex.Branch.hasSibling <||> (isJust <$> Fields.getField Fields.autoInit))
|
||||||
( do
|
( do
|
||||||
liftIO checkNotReadOnly
|
liftIO checkNotReadOnly
|
||||||
initialize Nothing Nothing
|
initialize (AutoInit True) Nothing Nothing
|
||||||
getUUID
|
getUUID
|
||||||
, return NoUUID
|
, return NoUUID
|
||||||
)
|
)
|
||||||
|
|
|
@ -45,7 +45,7 @@ start os = do
|
||||||
|
|
||||||
perform :: InitOptions -> CommandPerform
|
perform :: InitOptions -> CommandPerform
|
||||||
perform os = do
|
perform os = do
|
||||||
initialize
|
initialize (AutoInit False)
|
||||||
(if null (initDesc os) then Nothing else Just (initDesc os))
|
(if null (initDesc os) then Nothing else Just (initDesc os))
|
||||||
(initVersion os)
|
(initVersion os)
|
||||||
Annex.SpecialRemote.autoEnable
|
Annex.SpecialRemote.autoEnable
|
||||||
|
|
|
@ -36,6 +36,6 @@ perform s = do
|
||||||
then return $ toUUID s
|
then return $ toUUID s
|
||||||
else Remote.nameToUUID s
|
else Remote.nameToUUID s
|
||||||
storeUUID u
|
storeUUID u
|
||||||
initialize' Nothing
|
initialize' (AutoInit False) Nothing
|
||||||
Annex.SpecialRemote.autoEnable
|
Annex.SpecialRemote.autoEnable
|
||||||
next $ return True
|
next $ return True
|
||||||
|
|
|
@ -25,6 +25,6 @@ start :: CommandStart
|
||||||
start = do
|
start = do
|
||||||
showStart' "upgrade" Nothing
|
showStart' "upgrade" Nothing
|
||||||
whenM (isNothing <$> getVersion) $ do
|
whenM (isNothing <$> getVersion) $ do
|
||||||
initialize Nothing Nothing
|
initialize (AutoInit False) Nothing Nothing
|
||||||
r <- upgrade False latestVersion
|
r <- upgrade False latestVersion
|
||||||
next $ next $ return r
|
next $ next $ return r
|
||||||
|
|
2
Test.hs
2
Test.hs
|
@ -1810,7 +1810,7 @@ intmpclonerepoInDirect a = intmpclonerepo $
|
||||||
)
|
)
|
||||||
where
|
where
|
||||||
isdirect = annexeval $ do
|
isdirect = annexeval $ do
|
||||||
Annex.Init.initialize Nothing Nothing
|
Annex.Init.initialize (Annex.Init.AutoInit False) Nothing Nothing
|
||||||
Config.isDirect
|
Config.isDirect
|
||||||
|
|
||||||
checkRepo :: Types.Annex a -> FilePath -> IO a
|
checkRepo :: Types.Annex a -> FilePath -> IO a
|
||||||
|
|
|
@ -23,6 +23,11 @@ mark it as dead (see [[git-annex-dead]](1)).
|
||||||
|
|
||||||
This command is entirely safe, although usually pointless, to run inside an
|
This command is entirely safe, although usually pointless, to run inside an
|
||||||
already initialized git-annex repository.
|
already initialized git-annex repository.
|
||||||
|
|
||||||
|
A top-level `.noannex` file will prevent git-annex init from being used
|
||||||
|
in a repository. This is useful for repositories that have a policy
|
||||||
|
reason not to use git-annex. The content of the file will be displayed
|
||||||
|
to the user who tries to run git-annex init.
|
||||||
|
|
||||||
# OPTIONS
|
# OPTIONS
|
||||||
|
|
||||||
|
|
|
@ -6,3 +6,5 @@ annoying. --[[Joey]]
|
||||||
This could be a git configuration setting, or it could be something
|
This could be a git configuration setting, or it could be something
|
||||||
checked into the repo. Either might make sense depending on the scope
|
checked into the repo. Either might make sense depending on the scope
|
||||||
in which one wants to prevent the accidental init.
|
in which one wants to prevent the accidental init.
|
||||||
|
|
||||||
|
> [[done]] using .noannex file. --[[Joey]]
|
||||||
|
|
Loading…
Reference in a new issue