summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2011-08-17 18:52:58 -0400
committerGravatar Joey Hess <joey@kitenet.net>2011-08-17 18:52:58 -0400
commit0c53ccc675b52d4995b3406d5814116605fe6ec7 (patch)
tree75cf810643a0ab5499a347df1ae73bc5d04413f5
parent9e763954ae96201ce577cb51f904bf7756597f14 (diff)
tweak
-rw-r--r--Init.hs32
1 files changed, 17 insertions, 15 deletions
diff --git a/Init.hs b/Init.hs
index a11a7c51c..4708701fa 100644
--- a/Init.hs
+++ b/Init.hs
@@ -29,14 +29,11 @@ initialize = do
prepUUID
Branch.create
setVersion
- g <- Annex.gitRepo
- unless (Git.repoIsLocalBare g) $
- gitPreCommitHookWrite g
+ gitPreCommitHookWrite
uninitialize :: Annex ()
uninitialize = do
- g <- Annex.gitRepo
- gitPreCommitHookUnWrite g
+ gitPreCommitHookUnWrite
{- Will automatically initialize if there is already a git-annex
branch from somewhere. Otherwise, require a manual init
@@ -52,8 +49,9 @@ ensureInitialized = getVersion >>= maybe needsinit checkVersion
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
+gitPreCommitHookWrite :: Annex ()
+gitPreCommitHookWrite = unlessBare $ do
+ hook <- preCommitHook
exists <- liftIO $ doesFileExist hook
if exists
then warning $ "pre-commit hook (" ++ hook ++ ") already exists, not configuring"
@@ -61,12 +59,10 @@ gitPreCommitHookWrite repo = do
viaTmp writeFile hook preCommitScript
p <- getPermissions hook
setPermissions hook $ p {executable = True}
- where
- hook = preCommitHook repo
-gitPreCommitHookUnWrite :: Git.Repo -> Annex ()
-gitPreCommitHookUnWrite repo = do
- let hook = preCommitHook repo
+gitPreCommitHookUnWrite :: Annex ()
+gitPreCommitHookUnWrite = unlessBare $ do
+ hook <- preCommitHook
whenM (liftIO $ doesFileExist hook) $ do
c <- liftIO $ readFile hook
if c == preCommitScript
@@ -75,9 +71,15 @@ gitPreCommitHookUnWrite repo = do
") contents modified; not deleting." ++
" Edit it to remove call to git annex."
-preCommitHook :: Git.Repo -> FilePath
-preCommitHook repo =
- Git.workTree repo ++ "/" ++ Git.gitDir repo ++ "/hooks/pre-commit"
+unlessBare :: Annex () -> Annex ()
+unlessBare a = do
+ g <- Annex.gitRepo
+ unless (Git.repoIsLocalBare g) a
+
+preCommitHook :: Annex FilePath
+preCommitHook = do
+ g <- Annex.gitRepo
+ return $ Git.workTree g ++ "/" ++ Git.gitDir g ++ "/hooks/pre-commit"
preCommitScript :: String
preCommitScript =