summaryrefslogtreecommitdiff
path: root/Command/Init.hs
diff options
context:
space:
mode:
Diffstat (limited to 'Command/Init.hs')
-rw-r--r--Command/Init.hs41
1 files changed, 26 insertions, 15 deletions
diff --git a/Command/Init.hs b/Command/Init.hs
index eb5c58696..e19849ba3 100644
--- a/Command/Init.hs
+++ b/Command/Init.hs
@@ -18,6 +18,7 @@ import UUID
import Version
import Messages
import Locations
+import Types
seek :: [SubCmdSeek]
seek = [withString start]
@@ -36,8 +37,8 @@ perform description = do
u <- getUUID g
describeUUID u description
setVersion
- liftIO $ gitAttributes g
- liftIO $ gitPreCommitHook g
+ liftIO $ gitAttributesWrite g
+ gitPreCommitHookWrite g
return $ Just cleanup
cleanup :: SubCmdCleanup
@@ -50,8 +51,8 @@ cleanup = do
{- configure git to use union merge driver on state files, if it is not
- already -}
-gitAttributes :: Git.Repo -> IO ()
-gitAttributes repo = do
+gitAttributesWrite :: Git.Repo -> IO ()
+gitAttributesWrite repo = do
exists <- doesFileExist attributes
if not exists
then do
@@ -63,24 +64,34 @@ gitAttributes repo = 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]
+attrLine :: String
+attrLine = stateLoc ++ "*.log merge=union"
+
{- 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
+gitPreCommitHookWrite :: Git.Repo -> Annex ()
+gitPreCommitHookWrite repo = do
+ exists <- liftIO $ 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"
+ then warning $ "pre-commit hook (" ++ hook ++ ") already exists, not configuring"
+ else liftIO $ do
+ writeFile hook preCommitScript
p <- getPermissions hook
setPermissions hook $ p {executable = True}
+ where
+ hook = preCommitHook repo
+
+preCommitHook :: Git.Repo -> FilePath
+preCommitHook repo =
+ Git.workTree repo ++ "/" ++ Git.gitDir repo ++ "/hooks/pre-commit"
+
+preCommitScript :: String
+preCommitScript =
+ "#!/bin/sh\n" ++
+ "# automatically configured by git-annex\n" ++
+ "git annex pre-commit .\n"