git-annex/Command/Init.hs
Joey Hess 944c51ba26 improve version checking for v3
Do not set annex.version whenever any command is run. Just do it in init.
This ensures that, if a repo has annex.version=3, it has a git-annex
branch, so we don't have to run a command every time to check for the
branch.

Remove the old ad-hoc logic for v0 and v1, to simplify version checking.
2011-06-22 18:07:45 -04:00

71 lines
1.7 KiB
Haskell

{- 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)
import Control.Monad (when)
import System.Directory
import Command
import qualified Annex
import qualified GitRepo as Git
import qualified Branch
import UUID
import Version
import Messages
import Types
import Utility
command :: [Command]
command = [standaloneCommand "init" paramDesc seek
"initialize git-annex with repository description"]
seek :: [CommandSeek]
seek = [withWords start]
start :: CommandStartWords
start ws = do
when (null description) $
error "please specify a description of this repository\n"
showStart "init" description
next $ perform description
where
description = unwords ws
perform :: String -> CommandPerform
perform description = do
Branch.create
g <- Annex.gitRepo
u <- getUUID g
setVersion
describeUUID u description
gitPreCommitHookWrite g
next $ return True
{- set up a git pre-commit hook, if one is not already present -}
gitPreCommitHookWrite :: Git.Repo -> Annex ()
gitPreCommitHookWrite repo = do
exists <- liftIO $ doesFileExist hook
if exists
then warning $ "pre-commit hook (" ++ hook ++ ") already exists, not configuring"
else liftIO $ do
safeWriteFile 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"