summaryrefslogtreecommitdiff
path: root/Init.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2011-08-17 14:36:20 -0400
committerGravatar Joey Hess <joey@kitenet.net>2011-08-17 14:44:31 -0400
commit32f27cc3e839a3c243641b953fd4bd0f15dda08a (patch)
tree818a65122d2aedd805e475332fe7769c42f70379 /Init.hs
parentcf33eff684de5193379e99745d83c80fd2fb09c0 (diff)
when reading configs of local repos, first initializeSafe
This auto-generates a uuid if the local repo does not already have one.
Diffstat (limited to 'Init.hs')
-rw-r--r--Init.hs17
1 files changed, 16 insertions, 1 deletions
diff --git a/Init.hs b/Init.hs
index 41256a953..36d3ed0fa 100644
--- a/Init.hs
+++ b/Init.hs
@@ -5,7 +5,11 @@
- Licensed under the GNU GPL version 3 or higher.
-}
-module Init (initialize, uninitialize) where
+module Init (
+ initialize,
+ initializeSafe,
+ uninitialize
+) where
import Control.Monad.State (liftIO)
import Control.Monad (unless)
@@ -34,6 +38,17 @@ uninitialize = do
g <- Annex.gitRepo
gitPreCommitHookUnWrite g
+{- Call to automatically initialize if there is already a git-annex
+ branch from somewhere. Otherwise, require a manual init
+ to avoid git-annex accidentially being run in git
+ repos that did not intend to use it. -}
+initializeSafe :: Annex ()
+initializeSafe = do
+ annexed <- Branch.hasSomeBranch
+ if annexed
+ then initialize
+ else error "First run: git-annex init"
+
{- set up a git pre-commit hook, if one is not already present -}
gitPreCommitHookWrite :: Git.Repo -> Annex ()
gitPreCommitHookWrite repo = do