Fail if --from or --to is passed to commands that do not support them.
This commit is contained in:
parent
c879eb873e
commit
b955238ec7
36 changed files with 58 additions and 46 deletions
32
Command.hs
32
Command.hs
|
@ -22,8 +22,8 @@ import Init
|
|||
|
||||
{- A command runs in these stages.
|
||||
-
|
||||
- a. The check stage is run once and should error out if anything
|
||||
- prevents the command from running. -}
|
||||
- a. The check stage runs checks, that error out if
|
||||
- anything prevents the command from running. -}
|
||||
type CommandCheck = Annex ()
|
||||
{- b. The seek stage takes the parameters passed to the command,
|
||||
- looks through the repo to find the ones that are relevant
|
||||
|
@ -58,14 +58,6 @@ next a = return $ Just a
|
|||
stop :: Annex (Maybe a)
|
||||
stop = return Nothing
|
||||
|
||||
needsNothing :: CommandCheck
|
||||
needsNothing = return ()
|
||||
|
||||
{- Most commands will check this, as they need to be run in an initialized
|
||||
- repo. -}
|
||||
needsRepo :: CommandCheck
|
||||
needsRepo = ensureInitialized
|
||||
|
||||
{- Checks that the command can be run in the current environment. -}
|
||||
checkCommand :: Command -> Annex ()
|
||||
checkCommand Command { cmdcheck = check } = check
|
||||
|
@ -239,3 +231,23 @@ autoCopies key vs numcopiesattr a = do
|
|||
(_, have) <- trustPartition UnTrusted =<< keyLocations key
|
||||
if length have `vs` needed then a else stop
|
||||
else a
|
||||
|
||||
{- Checks -}
|
||||
defaultChecks :: CommandCheck
|
||||
defaultChecks = noFrom >> noTo >> needsRepo
|
||||
|
||||
noChecks :: CommandCheck
|
||||
noChecks = return ()
|
||||
|
||||
needsRepo :: CommandCheck
|
||||
needsRepo = ensureInitialized
|
||||
|
||||
noFrom :: CommandCheck
|
||||
noFrom = do
|
||||
v <- Annex.getState Annex.fromremote
|
||||
unless (v == Nothing) $ error "cannot use --from with this command"
|
||||
|
||||
noTo :: CommandCheck
|
||||
noTo = do
|
||||
v <- Annex.getState Annex.toremote
|
||||
unless (v == Nothing) $ error "cannot use --to with this command"
|
||||
|
|
|
@ -19,7 +19,7 @@ import Utility.Touch
|
|||
import Backend
|
||||
|
||||
command :: [Command]
|
||||
command = [Command "add" paramPaths needsRepo seek "add files to annex"]
|
||||
command = [Command "add" paramPaths defaultChecks seek "add files to annex"]
|
||||
|
||||
{- Add acts on both files not checked into git yet, and unlocked files. -}
|
||||
seek :: [CommandSeek]
|
||||
|
|
|
@ -20,7 +20,7 @@ import Annex.Content
|
|||
import Logs.Web
|
||||
|
||||
command :: [Command]
|
||||
command = [Command "addurl" (paramRepeating paramUrl) needsRepo seek
|
||||
command = [Command "addurl" (paramRepeating paramUrl) defaultChecks seek
|
||||
"add urls to annex"]
|
||||
|
||||
seek :: [CommandSeek]
|
||||
|
|
|
@ -12,7 +12,7 @@ import Command
|
|||
import Annex.UUID
|
||||
|
||||
command :: [Command]
|
||||
command = [Command "configlist" paramNothing needsRepo seek
|
||||
command = [Command "configlist" paramNothing defaultChecks seek
|
||||
"outputs relevant git configuration"]
|
||||
|
||||
seek :: [CommandSeek]
|
||||
|
|
|
@ -13,7 +13,7 @@ import qualified Remote
|
|||
import Logs.UUID
|
||||
|
||||
command :: [Command]
|
||||
command = [Command "describe" (paramPair paramRemote paramDesc) needsRepo seek
|
||||
command = [Command "describe" (paramPair paramRemote paramDesc) defaultChecks seek
|
||||
"change description of a repository"]
|
||||
|
||||
seek :: [CommandSeek]
|
||||
|
|
|
@ -17,7 +17,7 @@ import Annex.Content
|
|||
import Config
|
||||
|
||||
command :: [Command]
|
||||
command = [Command "drop" paramPaths needsRepo seek
|
||||
command = [Command "drop" paramPaths defaultChecks seek
|
||||
"indicate content of files not currently wanted"]
|
||||
|
||||
seek :: [CommandSeek]
|
||||
|
|
|
@ -14,7 +14,7 @@ import Logs.Location
|
|||
import Annex.Content
|
||||
|
||||
command :: [Command]
|
||||
command = [Command "dropkey" (paramRepeating paramKey) needsRepo seek
|
||||
command = [Command "dropkey" (paramRepeating paramKey) defaultChecks seek
|
||||
"drops annexed content for specified keys"]
|
||||
|
||||
seek :: [CommandSeek]
|
||||
|
|
|
@ -21,8 +21,8 @@ import Types.Key
|
|||
type UnusedMap = M.Map String Key
|
||||
|
||||
command :: [Command]
|
||||
command = [Command "dropunused" (paramRepeating paramNumber) needsRepo seek
|
||||
"drop unused file content"]
|
||||
command = [Command "dropunused" (paramRepeating paramNumber) (noTo >> needsRepo)
|
||||
seek "drop unused file content"]
|
||||
|
||||
seek :: [CommandSeek]
|
||||
seek = [withUnusedMaps]
|
||||
|
|
|
@ -13,7 +13,7 @@ import Annex.Content
|
|||
import Limit
|
||||
|
||||
command :: [Command]
|
||||
command = [Command "find" paramPaths needsRepo seek "lists available files"]
|
||||
command = [Command "find" paramPaths defaultChecks seek "lists available files"]
|
||||
|
||||
seek :: [CommandSeek]
|
||||
seek = [withFilesInGit start]
|
||||
|
|
|
@ -13,7 +13,7 @@ import qualified Annex.Queue
|
|||
import Annex.Content
|
||||
|
||||
command :: [Command]
|
||||
command = [Command "fix" paramPaths needsRepo seek
|
||||
command = [Command "fix" paramPaths defaultChecks seek
|
||||
"fix up symlinks to point to annexed content"]
|
||||
|
||||
seek :: [CommandSeek]
|
||||
|
|
|
@ -14,7 +14,7 @@ import Annex.Content
|
|||
import Types.Key
|
||||
|
||||
command :: [Command]
|
||||
command = [Command "fromkey" paramPath needsRepo seek
|
||||
command = [Command "fromkey" paramPath defaultChecks seek
|
||||
"adds a file using a specific key"]
|
||||
|
||||
seek :: [CommandSeek]
|
||||
|
|
|
@ -21,7 +21,7 @@ import Utility.FileMode
|
|||
import Config
|
||||
|
||||
command :: [Command]
|
||||
command = [Command "fsck" paramPaths needsRepo seek "check for problems"]
|
||||
command = [Command "fsck" paramPaths defaultChecks seek "check for problems"]
|
||||
|
||||
seek :: [CommandSeek]
|
||||
seek = [withNumCopies start]
|
||||
|
|
|
@ -15,7 +15,7 @@ import Annex.Content
|
|||
import qualified Command.Move
|
||||
|
||||
command :: [Command]
|
||||
command = [Command "get" paramPaths needsRepo seek
|
||||
command = [Command "get" paramPaths (noTo >> needsRepo) seek
|
||||
"make content of annexed files available"]
|
||||
|
||||
seek :: [CommandSeek]
|
||||
|
|
|
@ -12,7 +12,7 @@ import Command
|
|||
import Annex.Content
|
||||
|
||||
command :: [Command]
|
||||
command = [Command "inannex" (paramRepeating paramKey) needsRepo seek
|
||||
command = [Command "inannex" (paramRepeating paramKey) defaultChecks seek
|
||||
"checks if keys are present in the annex"]
|
||||
|
||||
seek :: [CommandSeek]
|
||||
|
|
|
@ -14,7 +14,7 @@ import Logs.UUID
|
|||
import Init
|
||||
|
||||
command :: [Command]
|
||||
command = [Command "init" paramDesc needsNothing seek "initialize git-annex"]
|
||||
command = [Command "init" paramDesc noChecks seek "initialize git-annex"]
|
||||
|
||||
seek :: [CommandSeek]
|
||||
seek = [withWords start]
|
||||
|
|
|
@ -19,7 +19,7 @@ import Annex.UUID
|
|||
command :: [Command]
|
||||
command = [Command "initremote"
|
||||
(paramPair paramName $ paramOptional $ paramRepeating paramKeyValue)
|
||||
needsRepo seek "sets up a special (non-git) remote"]
|
||||
defaultChecks seek "sets up a special (non-git) remote"]
|
||||
|
||||
seek :: [CommandSeek]
|
||||
seek = [withWords start]
|
||||
|
|
|
@ -13,7 +13,7 @@ import qualified Annex.Queue
|
|||
import Backend
|
||||
|
||||
command :: [Command]
|
||||
command = [Command "lock" paramPaths needsRepo seek "undo unlock command"]
|
||||
command = [Command "lock" paramPaths defaultChecks seek "undo unlock command"]
|
||||
|
||||
seek :: [CommandSeek]
|
||||
seek = [withFilesUnlocked start, withFilesUnlockedToBeCommitted start]
|
||||
|
|
|
@ -23,7 +23,7 @@ import qualified Utility.Dot as Dot
|
|||
data Link = Link Git.Repo Git.Repo
|
||||
|
||||
command :: [Command]
|
||||
command = [Command "map" paramNothing needsNothing seek
|
||||
command = [Command "map" paramNothing noChecks seek
|
||||
"generate map of repositories"]
|
||||
|
||||
seek :: [CommandSeek]
|
||||
|
|
|
@ -12,7 +12,7 @@ import Command
|
|||
import qualified Annex.Branch
|
||||
|
||||
command :: [Command]
|
||||
command = [Command "merge" paramNothing needsRepo seek
|
||||
command = [Command "merge" paramNothing defaultChecks seek
|
||||
"auto-merge remote changes into git-annex branch"]
|
||||
|
||||
seek :: [CommandSeek]
|
||||
|
|
|
@ -17,7 +17,7 @@ import Backend
|
|||
import Logs.Web
|
||||
|
||||
command :: [Command]
|
||||
command = [Command "migrate" paramPaths needsRepo seek
|
||||
command = [Command "migrate" paramPaths defaultChecks seek
|
||||
"switch data to different backend"]
|
||||
|
||||
seek :: [CommandSeek]
|
||||
|
|
|
@ -13,7 +13,7 @@ import qualified Command.Fix
|
|||
import Backend
|
||||
|
||||
command :: [Command]
|
||||
command = [Command "pre-commit" paramPaths needsRepo seek
|
||||
command = [Command "pre-commit" paramPaths defaultChecks seek
|
||||
"run by git pre-commit hook"]
|
||||
|
||||
{- The pre-commit hook needs to fix symlinks to all files being committed.
|
||||
|
|
|
@ -14,7 +14,7 @@ import Annex.Content
|
|||
import Utility.RsyncFile
|
||||
|
||||
command :: [Command]
|
||||
command = [Command "recvkey" paramKey needsRepo seek
|
||||
command = [Command "recvkey" paramKey defaultChecks seek
|
||||
"runs rsync in server mode to receive content"]
|
||||
|
||||
seek :: [CommandSeek]
|
||||
|
|
|
@ -13,7 +13,7 @@ import qualified Remote
|
|||
import Logs.Trust
|
||||
|
||||
command :: [Command]
|
||||
command = [Command "semitrust" (paramRepeating paramRemote) needsRepo seek
|
||||
command = [Command "semitrust" (paramRepeating paramRemote) defaultChecks seek
|
||||
"return repository to default trust level"]
|
||||
|
||||
seek :: [CommandSeek]
|
||||
|
|
|
@ -13,7 +13,7 @@ import Annex.Content
|
|||
import Utility.RsyncFile
|
||||
|
||||
command :: [Command]
|
||||
command = [Command "sendkey" paramKey needsRepo seek
|
||||
command = [Command "sendkey" paramKey defaultChecks seek
|
||||
"runs rsync in server mode to send content"]
|
||||
|
||||
seek :: [CommandSeek]
|
||||
|
|
|
@ -13,7 +13,7 @@ import Logs.Location
|
|||
import Annex.Content
|
||||
|
||||
command :: [Command]
|
||||
command = [Command "setkey" paramPath needsRepo seek
|
||||
command = [Command "setkey" paramPath defaultChecks seek
|
||||
"sets annexed content for a key using a temp file"]
|
||||
|
||||
seek :: [CommandSeek]
|
||||
|
|
|
@ -39,7 +39,7 @@ data StatInfo = StatInfo
|
|||
type StatState = StateT StatInfo Annex
|
||||
|
||||
command :: [Command]
|
||||
command = [Command "status" paramNothing needsRepo seek
|
||||
command = [Command "status" paramNothing defaultChecks seek
|
||||
"shows status information about the annex"]
|
||||
|
||||
seek :: [CommandSeek]
|
||||
|
|
|
@ -13,7 +13,7 @@ import qualified Remote
|
|||
import Logs.Trust
|
||||
|
||||
command :: [Command]
|
||||
command = [Command "trust" (paramRepeating paramRemote) needsRepo seek
|
||||
command = [Command "trust" (paramRepeating paramRemote) defaultChecks seek
|
||||
"trust a repository"]
|
||||
|
||||
seek :: [CommandSeek]
|
||||
|
|
|
@ -19,7 +19,7 @@ import qualified Git
|
|||
import qualified Git.LsFiles as LsFiles
|
||||
|
||||
command :: [Command]
|
||||
command = [Command "unannex" paramPaths needsRepo seek
|
||||
command = [Command "unannex" paramPaths defaultChecks seek
|
||||
"undo accidential add command"]
|
||||
|
||||
seek :: [CommandSeek]
|
||||
|
|
|
@ -19,12 +19,11 @@ import qualified Annex.Branch
|
|||
import Annex.Content
|
||||
|
||||
command :: [Command]
|
||||
command = [Command "uninit" paramPaths check seek
|
||||
command = [Command "uninit" paramPaths (check >> defaultChecks) seek
|
||||
"de-initialize git-annex and clean out repository"]
|
||||
|
||||
check :: Annex ()
|
||||
check = do
|
||||
needsRepo
|
||||
b <- current_branch
|
||||
when (b == Annex.Branch.name) $ error $
|
||||
"cannot uninit when the " ++ b ++ " branch is checked out"
|
||||
|
|
|
@ -19,7 +19,7 @@ command =
|
|||
, c "edit" "same as unlock"
|
||||
]
|
||||
where
|
||||
c n = Command n paramPaths needsRepo seek
|
||||
c n = Command n paramPaths defaultChecks seek
|
||||
|
||||
seek :: [CommandSeek]
|
||||
seek = [withFilesInGit start]
|
||||
|
|
|
@ -13,7 +13,7 @@ import qualified Remote
|
|||
import Logs.Trust
|
||||
|
||||
command :: [Command]
|
||||
command = [Command "untrust" (paramRepeating paramRemote) needsRepo seek
|
||||
command = [Command "untrust" (paramRepeating paramRemote) defaultChecks seek
|
||||
"do not trust a repository"]
|
||||
|
||||
seek :: [CommandSeek]
|
||||
|
|
|
@ -28,7 +28,7 @@ import qualified Annex.Branch
|
|||
import Annex.CatFile
|
||||
|
||||
command :: [Command]
|
||||
command = [Command "unused" paramNothing needsRepo seek
|
||||
command = [Command "unused" paramNothing (noTo >> needsRepo) seek
|
||||
"look for unused file content"]
|
||||
|
||||
seek :: [CommandSeek]
|
||||
|
|
|
@ -13,7 +13,7 @@ import Upgrade
|
|||
import Annex.Version
|
||||
|
||||
command :: [Command]
|
||||
command = [Command "upgrade" paramNothing needsNothing seek
|
||||
command = [Command "upgrade" paramNothing noChecks seek
|
||||
"upgrade repository layout"]
|
||||
|
||||
seek :: [CommandSeek]
|
||||
|
|
|
@ -13,7 +13,7 @@ import qualified Build.SysConfig as SysConfig
|
|||
import Annex.Version
|
||||
|
||||
command :: [Command]
|
||||
command = [Command "version" paramNothing needsNothing seek "show version info"]
|
||||
command = [Command "version" paramNothing noChecks seek "show version info"]
|
||||
|
||||
seek :: [CommandSeek]
|
||||
seek = [withNothing start]
|
||||
|
|
|
@ -14,7 +14,7 @@ import Remote
|
|||
import Logs.Trust
|
||||
|
||||
command :: [Command]
|
||||
command = [Command "whereis" paramPaths needsRepo seek
|
||||
command = [Command "whereis" paramPaths defaultChecks seek
|
||||
"lists repositories that have file content"]
|
||||
|
||||
seek :: [CommandSeek]
|
||||
|
|
1
debian/changelog
vendored
1
debian/changelog
vendored
|
@ -4,6 +4,7 @@ git-annex (3.20111026) UNRELEASED; urgency=low
|
|||
* copy --to: Fixed leak when copying many files to a remote on the same
|
||||
host.
|
||||
* uninit: Add guard against being run with the git-annex branch checked out.
|
||||
* Fail if --from or --to is passed to commands that do not support them.
|
||||
|
||||
-- Joey Hess <joeyh@debian.org> Thu, 27 Oct 2011 13:58:53 -0400
|
||||
|
||||
|
|
Loading…
Reference in a new issue