summaryrefslogtreecommitdiff
path: root/Annex
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2017-12-13 14:34:32 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2017-12-13 14:34:32 -0400
commit667617a1f2c39f338cbbcb7cab861472b5d7e438 (patch)
tree98acb4bc30370126c803936f7d374fa8093d84e8 /Annex
parent859c133f46931fc0f8e2d2b5a027d33dab2cec75 (diff)
.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.
Diffstat (limited to 'Annex')
-rw-r--r--Annex/Init.hs30
-rw-r--r--Annex/MakeRepo.hs2
2 files changed, 25 insertions, 7 deletions
diff --git a/Annex/Init.hs b/Annex/Init.hs
index 0754d1f96..1d4093ff5 100644
--- a/Annex/Init.hs
+++ b/Annex/Init.hs
@@ -8,6 +8,7 @@
{-# LANGUAGE CPP #-}
module Annex.Init (
+ AutoInit(..),
ensureInitialized,
isInitialized,
initialize,
@@ -48,6 +49,23 @@ import System.Posix.User
import qualified Utility.LockFile.Posix as Posix
#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 (Just d) = return d
genDescription Nothing = do
@@ -59,8 +77,8 @@ genDescription Nothing = do
Right username -> [username, at, hostname, ":", reldir]
Left _ -> [hostname, ":", reldir]
-initialize :: Maybe String -> Maybe Version -> Annex ()
-initialize mdescription mversion = do
+initialize :: AutoInit -> Maybe String -> Maybe Version -> Annex ()
+initialize ai mdescription mversion = checkCanInitialize ai $ do
{- Has to come before any commits are made as the shared
- clone heuristic expects no local objects. -}
sharedclone <- checkSharedClone
@@ -70,7 +88,7 @@ initialize mdescription mversion = do
ensureCommit $ Annex.Branch.create
prepUUID
- initialize' mversion
+ initialize' (AutoInit True) mversion
initSharedClone sharedclone
@@ -79,8 +97,8 @@ initialize mdescription mversion = do
-- Everything except for uuid setup, shared clone setup, and initial
-- description.
-initialize' :: Maybe Version -> Annex ()
-initialize' mversion = do
+initialize' :: AutoInit -> Maybe Version -> Annex ()
+initialize' ai mversion = checkCanInitialize ai $ do
checkLockSupport
checkFifoSupport
checkCrippledFileSystem
@@ -131,7 +149,7 @@ ensureInitialized :: Annex ()
ensureInitialized = getVersion >>= maybe needsinit checkUpgrade
where
needsinit = ifM Annex.Branch.hasSibling
- ( initialize Nothing Nothing
+ ( initialize (AutoInit True) Nothing Nothing
, giveup "First run: git-annex init"
)
diff --git a/Annex/MakeRepo.hs b/Annex/MakeRepo.hs
index e03196664..ac25c013d 100644
--- a/Annex/MakeRepo.hs
+++ b/Annex/MakeRepo.hs
@@ -76,7 +76,7 @@ initRepo False _ dir desc mgroup = inDir dir $ do
initRepo' :: Maybe String -> Maybe StandardGroup -> Annex ()
initRepo' desc mgroup = unlessM isInitialized $ do
- initialize desc Nothing
+ initialize (AutoInit False) desc Nothing
u <- getUUID
maybe noop (defaultStandardGroup u) mgroup
{- Ensure branch gets committed right away so it is