Fix handing of autocorrection when running outside a git repository.

Old behavior was to take the first fuzzy match. Now, it checks the globa
git config, and runs the normal fuzzy handling, including failing to run a
semi-random command by default.
This commit is contained in:
Joey Hess 2014-08-23 16:51:33 -07:00
parent 6f80bacbf5
commit 4405650828
3 changed files with 10 additions and 6 deletions

View file

@ -26,6 +26,7 @@ import Common.Annex
import qualified Annex
import qualified Git
import qualified Git.AutoCorrect
import qualified Git.Config
import Annex.Content
import Annex.Environment
import Command
@ -44,7 +45,8 @@ dispatch fuzzyok allargs allcmds commonoptions fields header getgitrepo = do
state <- Annex.new g
Annex.eval state $ do
checkEnvironment
checkfuzzy
when fuzzy $
inRepo $ autocorrect . Just
forM_ fields $ uncurry Annex.setField
when (cmdnomessages cmd) $
Annex.setOutput QuietOutput
@ -54,13 +56,14 @@ dispatch fuzzyok allargs allcmds commonoptions fields header getgitrepo = do
startup
performCommandAction cmd params
shutdown $ cmdnocommit cmd
go _flags params (Left e) =
go _flags params (Left e) = do
when fuzzy $
autocorrect =<< Git.Config.global
maybe (throw e) (\a -> a params) (cmdnorepo cmd)
err msg = msg ++ "\n\n" ++ usage header allcmds
cmd = Prelude.head cmds
(fuzzy, cmds, name, args) = findCmd fuzzyok allargs allcmds err
checkfuzzy = when fuzzy $
inRepo $ Git.AutoCorrect.prepare name cmdname cmds
autocorrect = Git.AutoCorrect.prepare name cmdname cmds
{- Parses command line params far enough to find the Command to run, and
- returns the remaining params.