From 66194684acaf8dc5c72e5a163465b42050cf9212 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 27 Oct 2011 15:47:11 -0400 Subject: uninit: Add guard against being run with the git-annex branch checked out. --- Command/Uninit.hs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'Command') diff --git a/Command/Uninit.hs b/Command/Uninit.hs index 7b3b4fe32..8214c4208 100644 --- a/Command/Uninit.hs +++ b/Command/Uninit.hs @@ -7,6 +7,8 @@ module Command.Uninit where +import qualified Data.ByteString.Lazy.Char8 as B + import Common.Annex import Command import qualified Git @@ -21,7 +23,20 @@ command = [repoCommand "uninit" paramPaths seek "de-initialize git-annex and clean out repository"] seek :: [CommandSeek] -seek = [withFilesInGit startUnannex, withNothing start] +seek = [withNothing startCheck, withFilesInGit startUnannex, withNothing start] + +startCheck :: CommandStart +startCheck = do + 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 + b <- liftIO $ + Git.pipeRead g [Params "rev-parse --abbrev-ref HEAD"] + return $ head $ lines $ B.unpack b startUnannex :: FilePath -> CommandStart startUnannex file = do -- cgit v1.2.3