summaryrefslogtreecommitdiff
path: root/CmdLine.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2011-08-17 14:14:43 -0400
committerGravatar Joey Hess <joey@kitenet.net>2011-08-17 14:44:31 -0400
commit56f6923ccbc6fb1932137b53458a4cece47e69b0 (patch)
treea2c9a949f2c6c5163551a76f4012e7606e3c1463 /CmdLine.hs
parent3b5f7221305ba6e768711d8326a01b78fb1e4f79 (diff)
Now "git annex init" only has to be run once
when a git repository is first being created. Clones will automatically notice that git-annex is in use and automatically perform a basic initalization. It's still recommended to run "git annex init" in any clones, to describe them.
Diffstat (limited to 'CmdLine.hs')
-rw-r--r--CmdLine.hs22
1 files changed, 17 insertions, 5 deletions
diff --git a/CmdLine.hs b/CmdLine.hs
index c33c49785..ff1758f0d 100644
--- a/CmdLine.hs
+++ b/CmdLine.hs
@@ -19,13 +19,14 @@ import Control.Monad (when)
import qualified Annex
import qualified AnnexQueue
import qualified Git
+import qualified Branch
import Content
import Types
import Command
import Version
import Options
import Messages
-import UUID
+import Init
{- Runs the passed command line. -}
dispatch :: [String] -> [Command] -> [Option] -> String -> Git.Repo -> IO ()
@@ -45,7 +46,7 @@ parseCmd argv header cmds options = do
[] -> error $ "unknown command" ++ usagemsg
[command] -> do
_ <- sequence flags
- when (cmdusesrepo command) checkVersion
+ checkCmdEnviron command
prepCommand command (drop 1 params)
_ -> error "internal error: multiple matching commands"
where
@@ -57,6 +58,19 @@ parseCmd argv header cmds options = do
lookupCmd cmd = filter (\c -> cmd == cmdname c) cmds
usagemsg = "\n\n" ++ usage header cmds options
+{- Checks that the command can be run in the current environment. -}
+checkCmdEnviron :: Command -> Annex ()
+checkCmdEnviron command = do
+ when (cmdusesrepo command) $ checkVersion $ do
+ {- Automatically initialize if there is already a git-annex
+ branch from somewhere. Otherwise, require a manual init
+ to avoid git-annex accidentially being run in git
+ repos that did not intend to use it. -}
+ annexed <- Branch.hasSomeBranch
+ if annexed
+ then initialize
+ else error "First run: git-annex init"
+
{- Usage message with lists of commands and options. -}
usage :: String -> [Command] -> [Option] -> String
usage header cmds options =
@@ -95,9 +109,7 @@ tryRun' errnum _ [] = when (errnum > 0) $ error $ show errnum ++ " failed"
{- Actions to perform each time ran. -}
startup :: Annex Bool
-startup = do
- prepUUID
- return True
+startup = return True
{- Cleanup actions. -}
shutdown :: Annex Bool