From b955238ec7464b12c793d543fc51308c8b213e08 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 27 Oct 2011 18:56:54 -0400 Subject: [PATCH] Fail if --from or --to is passed to commands that do not support them. --- Command.hs | 32 ++++++++++++++++++++++---------- Command/Add.hs | 2 +- Command/AddUrl.hs | 2 +- Command/ConfigList.hs | 2 +- Command/Describe.hs | 2 +- Command/Drop.hs | 2 +- Command/DropKey.hs | 2 +- Command/DropUnused.hs | 4 ++-- Command/Find.hs | 2 +- Command/Fix.hs | 2 +- Command/FromKey.hs | 2 +- Command/Fsck.hs | 2 +- Command/Get.hs | 2 +- Command/InAnnex.hs | 2 +- Command/Init.hs | 2 +- Command/InitRemote.hs | 2 +- Command/Lock.hs | 2 +- Command/Map.hs | 2 +- Command/Merge.hs | 2 +- Command/Migrate.hs | 2 +- Command/PreCommit.hs | 2 +- Command/RecvKey.hs | 2 +- Command/Semitrust.hs | 2 +- Command/SendKey.hs | 2 +- Command/SetKey.hs | 2 +- Command/Status.hs | 2 +- Command/Trust.hs | 2 +- Command/Unannex.hs | 2 +- Command/Uninit.hs | 3 +-- Command/Unlock.hs | 2 +- Command/Untrust.hs | 2 +- Command/Unused.hs | 2 +- Command/Upgrade.hs | 2 +- Command/Version.hs | 2 +- Command/Whereis.hs | 2 +- debian/changelog | 1 + 36 files changed, 58 insertions(+), 46 deletions(-) diff --git a/Command.hs b/Command.hs index d19dad2601..5690118c40 100644 --- a/Command.hs +++ b/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" diff --git a/Command/Add.hs b/Command/Add.hs index 255e787b74..33b636bed7 100644 --- a/Command/Add.hs +++ b/Command/Add.hs @@ -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] diff --git a/Command/AddUrl.hs b/Command/AddUrl.hs index 8deb79541f..72e29ff60e 100644 --- a/Command/AddUrl.hs +++ b/Command/AddUrl.hs @@ -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] diff --git a/Command/ConfigList.hs b/Command/ConfigList.hs index 35a939b38f..645d1523ca 100644 --- a/Command/ConfigList.hs +++ b/Command/ConfigList.hs @@ -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] diff --git a/Command/Describe.hs b/Command/Describe.hs index 9184ede9cf..cd5da302e9 100644 --- a/Command/Describe.hs +++ b/Command/Describe.hs @@ -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] diff --git a/Command/Drop.hs b/Command/Drop.hs index 7309c2acdb..02f44915ce 100644 --- a/Command/Drop.hs +++ b/Command/Drop.hs @@ -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] diff --git a/Command/DropKey.hs b/Command/DropKey.hs index 9e35548569..3e666b9aba 100644 --- a/Command/DropKey.hs +++ b/Command/DropKey.hs @@ -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] diff --git a/Command/DropUnused.hs b/Command/DropUnused.hs index 019fab0769..1236fb8230 100644 --- a/Command/DropUnused.hs +++ b/Command/DropUnused.hs @@ -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] diff --git a/Command/Find.hs b/Command/Find.hs index 5b13c742ad..291904ec03 100644 --- a/Command/Find.hs +++ b/Command/Find.hs @@ -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] diff --git a/Command/Fix.hs b/Command/Fix.hs index 5e58f07332..090558d521 100644 --- a/Command/Fix.hs +++ b/Command/Fix.hs @@ -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] diff --git a/Command/FromKey.hs b/Command/FromKey.hs index 30243964e5..a3e96b20da 100644 --- a/Command/FromKey.hs +++ b/Command/FromKey.hs @@ -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] diff --git a/Command/Fsck.hs b/Command/Fsck.hs index 0098a822db..d025095b1b 100644 --- a/Command/Fsck.hs +++ b/Command/Fsck.hs @@ -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] diff --git a/Command/Get.hs b/Command/Get.hs index d9596c3fe8..21ff73bc4e 100644 --- a/Command/Get.hs +++ b/Command/Get.hs @@ -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] diff --git a/Command/InAnnex.hs b/Command/InAnnex.hs index b4db849c9b..7a5735b742 100644 --- a/Command/InAnnex.hs +++ b/Command/InAnnex.hs @@ -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] diff --git a/Command/Init.hs b/Command/Init.hs index 06bdf4ad56..6646432002 100644 --- a/Command/Init.hs +++ b/Command/Init.hs @@ -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] diff --git a/Command/InitRemote.hs b/Command/InitRemote.hs index 8f97199b77..cea1acc8d8 100644 --- a/Command/InitRemote.hs +++ b/Command/InitRemote.hs @@ -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] diff --git a/Command/Lock.hs b/Command/Lock.hs index bf3b125592..8f0bd78ebe 100644 --- a/Command/Lock.hs +++ b/Command/Lock.hs @@ -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] diff --git a/Command/Map.hs b/Command/Map.hs index 6fbc6930ba..05cc9d794c 100644 --- a/Command/Map.hs +++ b/Command/Map.hs @@ -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] diff --git a/Command/Merge.hs b/Command/Merge.hs index 2b7162946a..33d4c8ffc5 100644 --- a/Command/Merge.hs +++ b/Command/Merge.hs @@ -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] diff --git a/Command/Migrate.hs b/Command/Migrate.hs index e3956c5aa7..ac8f042ba2 100644 --- a/Command/Migrate.hs +++ b/Command/Migrate.hs @@ -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] diff --git a/Command/PreCommit.hs b/Command/PreCommit.hs index 50bc2662e1..5dac4f5339 100644 --- a/Command/PreCommit.hs +++ b/Command/PreCommit.hs @@ -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. diff --git a/Command/RecvKey.hs b/Command/RecvKey.hs index 9dc436a681..3415de526e 100644 --- a/Command/RecvKey.hs +++ b/Command/RecvKey.hs @@ -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] diff --git a/Command/Semitrust.hs b/Command/Semitrust.hs index f6a2f639c7..4f61531ff0 100644 --- a/Command/Semitrust.hs +++ b/Command/Semitrust.hs @@ -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] diff --git a/Command/SendKey.hs b/Command/SendKey.hs index e8ba3ae79c..5118a009b4 100644 --- a/Command/SendKey.hs +++ b/Command/SendKey.hs @@ -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] diff --git a/Command/SetKey.hs b/Command/SetKey.hs index 51f344f20f..a60f539973 100644 --- a/Command/SetKey.hs +++ b/Command/SetKey.hs @@ -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] diff --git a/Command/Status.hs b/Command/Status.hs index 155e53ee2c..df79d4a7fe 100644 --- a/Command/Status.hs +++ b/Command/Status.hs @@ -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] diff --git a/Command/Trust.hs b/Command/Trust.hs index 1af458630f..17b689c345 100644 --- a/Command/Trust.hs +++ b/Command/Trust.hs @@ -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] diff --git a/Command/Unannex.hs b/Command/Unannex.hs index cdaa790c0f..76100c8c3c 100644 --- a/Command/Unannex.hs +++ b/Command/Unannex.hs @@ -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] diff --git a/Command/Uninit.hs b/Command/Uninit.hs index 60e86cc039..b2046ec414 100644 --- a/Command/Uninit.hs +++ b/Command/Uninit.hs @@ -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" diff --git a/Command/Unlock.hs b/Command/Unlock.hs index c89b61de70..be1d052984 100644 --- a/Command/Unlock.hs +++ b/Command/Unlock.hs @@ -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] diff --git a/Command/Untrust.hs b/Command/Untrust.hs index 7d65c1af95..5a2505a10f 100644 --- a/Command/Untrust.hs +++ b/Command/Untrust.hs @@ -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] diff --git a/Command/Unused.hs b/Command/Unused.hs index 5cef829d6e..d2b45ed6b7 100644 --- a/Command/Unused.hs +++ b/Command/Unused.hs @@ -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] diff --git a/Command/Upgrade.hs b/Command/Upgrade.hs index 77d15c9306..9ca3c8d2be 100644 --- a/Command/Upgrade.hs +++ b/Command/Upgrade.hs @@ -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] diff --git a/Command/Version.hs b/Command/Version.hs index dae9a31d3b..905a48a51e 100644 --- a/Command/Version.hs +++ b/Command/Version.hs @@ -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] diff --git a/Command/Whereis.hs b/Command/Whereis.hs index 71b3ad96b1..06a894fd3f 100644 --- a/Command/Whereis.hs +++ b/Command/Whereis.hs @@ -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] diff --git a/debian/changelog b/debian/changelog index dd72fc296d..d100bd4e85 100644 --- a/debian/changelog +++ b/debian/changelog @@ -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 Thu, 27 Oct 2011 13:58:53 -0400