refactored and generalized pre-command sanity checking

This commit is contained in:
Joey Hess 2011-10-27 16:31:35 -04:00
parent 66194684ac
commit 5b74b130a3
38 changed files with 73 additions and 67 deletions

View file

@ -19,18 +19,15 @@ import qualified Annex.Branch
import Annex.Content
command :: [Command]
command = [repoCommand "uninit" paramPaths seek
command = [Command "uninit" paramPaths check seek
"de-initialize git-annex and clean out repository"]
seek :: [CommandSeek]
seek = [withNothing startCheck, withFilesInGit startUnannex, withNothing start]
startCheck :: CommandStart
startCheck = do
check :: Annex ()
check = do
needsRepo
b <- current_branch
when (b == Annex.Branch.name) $ error $
"cannot uninit when the " ++ b ++ " branch is checked out"
stop
where
current_branch = do
g <- gitRepo
@ -38,6 +35,9 @@ startCheck = do
Git.pipeRead g [Params "rev-parse --abbrev-ref HEAD"]
return $ head $ lines $ B.unpack b
seek :: [CommandSeek]
seek = [withFilesInGit startUnannex, withNothing start]
startUnannex :: FilePath -> CommandStart
startUnannex file = do
-- Force fast mode before running unannex. This way, if multiple