diff options
author | Joey Hess <joey@kitenet.net> | 2010-11-14 14:44:24 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2010-11-14 14:44:24 -0400 |
commit | 0e55d6a907a39c3b7239268261edc2d5b5f55caf (patch) | |
tree | f296a331d44c0ecbafcbfa3a417c7516543ed6f5 /Command/Init.hs | |
parent | 10f30cf6383167e72ced5c6138ee6857b3fd63eb (diff) |
move stuff out of Core
Diffstat (limited to 'Command/Init.hs')
-rw-r--r-- | Command/Init.hs | 40 |
1 files changed, 39 insertions, 1 deletions
diff --git a/Command/Init.hs b/Command/Init.hs index 8110948a4..c928647a5 100644 --- a/Command/Init.hs +++ b/Command/Init.hs @@ -9,14 +9,15 @@ module Command.Init where import Control.Monad.State (liftIO) import Control.Monad (when) +import System.Directory import Command import qualified Annex -import Core import qualified GitRepo as Git import UUID import Version import Messages +import Locations seek :: [SubCmdSeek] seek = [withString start] @@ -46,3 +47,40 @@ cleanup = do liftIO $ Git.run g ["add", logfile] liftIO $ Git.run g ["commit", "-m", "git annex init", logfile] return True + +{- configure git to use union merge driver on state files, if it is not + - already -} +gitAttributes :: Git.Repo -> IO () +gitAttributes repo = do + exists <- doesFileExist attributes + if (not exists) + then do + writeFile attributes $ attrLine ++ "\n" + commit + else do + content <- readFile attributes + when (all (/= attrLine) (lines content)) $ do + appendFile attributes $ attrLine ++ "\n" + commit + where + attrLine = stateLoc ++ "*.log merge=union" + attributes = Git.attributes repo + commit = do + Git.run repo ["add", attributes] + Git.run repo ["commit", "-m", "git-annex setup", + attributes] + +{- set up a git pre-commit hook, if one is not already present -} +gitPreCommitHook :: Git.Repo -> IO () +gitPreCommitHook repo = do + let hook = Git.workTree repo ++ "/" ++ Git.gitDir repo ++ + "/hooks/pre-commit" + exists <- doesFileExist hook + if (exists) + then putStrLn $ "pre-commit hook (" ++ hook ++ ") already exists, not configuring" + else do + writeFile hook $ "#!/bin/sh\n" ++ + "# automatically configured by git-annex\n" ++ + "git annex pre-commit .\n" + p <- getPermissions hook + setPermissions hook $ p {executable = True} |