2010-11-02 23:04:24 +00:00
|
|
|
{- git-annex command
|
|
|
|
-
|
|
|
|
- Copyright 2010 Joey Hess <joey@kitenet.net>
|
|
|
|
-
|
|
|
|
- Licensed under the GNU GPL version 3 or higher.
|
|
|
|
-}
|
|
|
|
|
|
|
|
module Command.Init where
|
|
|
|
|
|
|
|
import Control.Monad.State (liftIO)
|
2011-06-22 22:32:41 +00:00
|
|
|
import Control.Monad (when, unless)
|
2010-11-14 18:44:24 +00:00
|
|
|
import System.Directory
|
2010-11-02 23:04:24 +00:00
|
|
|
|
|
|
|
import Command
|
|
|
|
import qualified Annex
|
2011-06-30 17:16:57 +00:00
|
|
|
import qualified Git
|
2011-06-22 20:03:26 +00:00
|
|
|
import qualified Branch
|
2010-11-02 23:04:24 +00:00
|
|
|
import UUID
|
2010-11-08 20:40:28 +00:00
|
|
|
import Version
|
2010-11-08 19:15:21 +00:00
|
|
|
import Messages
|
2010-12-03 04:33:41 +00:00
|
|
|
import Types
|
2011-01-28 16:35:51 +00:00
|
|
|
import Utility
|
2010-12-30 19:06:26 +00:00
|
|
|
|
|
|
|
command :: [Command]
|
2011-06-22 22:07:45 +00:00
|
|
|
command = [standaloneCommand "init" paramDesc seek
|
2010-12-30 19:06:26 +00:00
|
|
|
"initialize git-annex with repository description"]
|
2010-11-02 23:04:24 +00:00
|
|
|
|
2010-12-30 18:19:16 +00:00
|
|
|
seek :: [CommandSeek]
|
2011-05-16 16:25:54 +00:00
|
|
|
seek = [withWords start]
|
2010-11-11 22:54:52 +00:00
|
|
|
|
2011-05-16 16:25:54 +00:00
|
|
|
start :: CommandStartWords
|
|
|
|
start ws = do
|
2010-11-22 21:51:55 +00:00
|
|
|
when (null description) $
|
|
|
|
error "please specify a description of this repository\n"
|
2010-11-02 23:04:24 +00:00
|
|
|
showStart "init" description
|
2011-05-15 06:02:46 +00:00
|
|
|
next $ perform description
|
2011-05-16 16:25:54 +00:00
|
|
|
where
|
|
|
|
description = unwords ws
|
2010-11-02 23:04:24 +00:00
|
|
|
|
2010-12-30 18:19:16 +00:00
|
|
|
perform :: String -> CommandPerform
|
2010-11-02 23:04:24 +00:00
|
|
|
perform description = do
|
2011-06-22 20:03:26 +00:00
|
|
|
Branch.create
|
2010-11-02 23:04:24 +00:00
|
|
|
g <- Annex.gitRepo
|
|
|
|
u <- getUUID g
|
2010-11-08 20:40:28 +00:00
|
|
|
setVersion
|
2011-06-22 20:03:26 +00:00
|
|
|
describeUUID u description
|
2011-06-22 22:32:41 +00:00
|
|
|
unless (Git.repoIsLocalBare g) $
|
|
|
|
gitPreCommitHookWrite g
|
2011-06-22 20:03:26 +00:00
|
|
|
next $ return True
|
2010-12-03 04:33:41 +00:00
|
|
|
|
2010-11-14 18:44:24 +00:00
|
|
|
{- set up a git pre-commit hook, if one is not already present -}
|
2010-12-03 04:33:41 +00:00
|
|
|
gitPreCommitHookWrite :: Git.Repo -> Annex ()
|
|
|
|
gitPreCommitHookWrite repo = do
|
|
|
|
exists <- liftIO $ doesFileExist hook
|
2010-11-22 21:51:55 +00:00
|
|
|
if exists
|
2010-12-03 04:33:41 +00:00
|
|
|
then warning $ "pre-commit hook (" ++ hook ++ ") already exists, not configuring"
|
|
|
|
else liftIO $ do
|
2011-06-30 04:42:09 +00:00
|
|
|
viaTmp writeFile hook preCommitScript
|
2010-11-14 18:44:24 +00:00
|
|
|
p <- getPermissions hook
|
|
|
|
setPermissions hook $ p {executable = True}
|
2010-12-03 04:33:41 +00:00
|
|
|
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"
|