convert notBareRepo to a CommandCheck

This avoids some small overhead by only running the check once per command;
it also ensures that, even if the command doesn't find anything to run on,
it still fails to run when in a bare repo.
This commit is contained in:
Joey Hess 2012-12-29 14:45:19 -04:00
parent e2788a5d15
commit e872c3f648
10 changed files with 26 additions and 28 deletions

View file

@ -14,6 +14,7 @@ import Common.Annex
import Types.Command
import Init
import Config
import qualified Git
commonChecks :: [CommandCheck]
commonChecks = [repoExists]
@ -25,6 +26,10 @@ notDirect :: Command -> Command
notDirect = addCheck $ whenM isDirect $
error "You cannot run this subcommand in a direct mode repository."
notBareRepo :: Command -> Command
notBareRepo = addCheck $ whenM (fromRepo Git.repoIsLocalBare) $
error "You cannot run this subcommand in a bare repository."
dontCheck :: CommandCheck -> Command -> Command
dontCheck check cmd = mutateCheck cmd $ \c -> filter (/= check) c