This commit is contained in:
Joey Hess 2011-08-17 18:52:58 -04:00
parent 9e763954ae
commit 0c53ccc675

32
Init.hs
View file

@ -29,14 +29,11 @@ initialize = do
prepUUID prepUUID
Branch.create Branch.create
setVersion setVersion
g <- Annex.gitRepo gitPreCommitHookWrite
unless (Git.repoIsLocalBare g) $
gitPreCommitHookWrite g
uninitialize :: Annex () uninitialize :: Annex ()
uninitialize = do uninitialize = do
g <- Annex.gitRepo gitPreCommitHookUnWrite
gitPreCommitHookUnWrite g
{- Will automatically initialize if there is already a git-annex {- Will automatically initialize if there is already a git-annex
branch from somewhere. Otherwise, require a manual init branch from somewhere. Otherwise, require a manual init
@ -52,8 +49,9 @@ ensureInitialized = getVersion >>= maybe needsinit checkVersion
else error "First run: git-annex init" else error "First run: git-annex init"
{- set up a git pre-commit hook, if one is not already present -} {- set up a git pre-commit hook, if one is not already present -}
gitPreCommitHookWrite :: Git.Repo -> Annex () gitPreCommitHookWrite :: Annex ()
gitPreCommitHookWrite repo = do gitPreCommitHookWrite = unlessBare $ do
hook <- preCommitHook
exists <- liftIO $ doesFileExist hook exists <- liftIO $ doesFileExist hook
if exists if exists
then warning $ "pre-commit hook (" ++ hook ++ ") already exists, not configuring" then warning $ "pre-commit hook (" ++ hook ++ ") already exists, not configuring"
@ -61,12 +59,10 @@ gitPreCommitHookWrite repo = do
viaTmp writeFile hook preCommitScript viaTmp writeFile hook preCommitScript
p <- getPermissions hook p <- getPermissions hook
setPermissions hook $ p {executable = True} setPermissions hook $ p {executable = True}
where
hook = preCommitHook repo
gitPreCommitHookUnWrite :: Git.Repo -> Annex () gitPreCommitHookUnWrite :: Annex ()
gitPreCommitHookUnWrite repo = do gitPreCommitHookUnWrite = unlessBare $ do
let hook = preCommitHook repo hook <- preCommitHook
whenM (liftIO $ doesFileExist hook) $ do whenM (liftIO $ doesFileExist hook) $ do
c <- liftIO $ readFile hook c <- liftIO $ readFile hook
if c == preCommitScript if c == preCommitScript
@ -75,9 +71,15 @@ gitPreCommitHookUnWrite repo = do
") contents modified; not deleting." ++ ") contents modified; not deleting." ++
" Edit it to remove call to git annex." " Edit it to remove call to git annex."
preCommitHook :: Git.Repo -> FilePath unlessBare :: Annex () -> Annex ()
preCommitHook repo = unlessBare a = do
Git.workTree repo ++ "/" ++ Git.gitDir repo ++ "/hooks/pre-commit" 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 :: String
preCommitScript = preCommitScript =