summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2011-10-27 18:56:54 -0400
committerGravatar Joey Hess <joey@kitenet.net>2011-10-27 18:56:54 -0400
commitb955238ec7464b12c793d543fc51308c8b213e08 (patch)
treea8953c64f6933fe233993b29f2a64cf45a850e48
parentc879eb873ec2fda1ec7d76c0de27d9ace57ba6e7 (diff)
Fail if --from or --to is passed to commands that do not support them.
-rw-r--r--Command.hs32
-rw-r--r--Command/Add.hs2
-rw-r--r--Command/AddUrl.hs2
-rw-r--r--Command/ConfigList.hs2
-rw-r--r--Command/Describe.hs2
-rw-r--r--Command/Drop.hs2
-rw-r--r--Command/DropKey.hs2
-rw-r--r--Command/DropUnused.hs4
-rw-r--r--Command/Find.hs2
-rw-r--r--Command/Fix.hs2
-rw-r--r--Command/FromKey.hs2
-rw-r--r--Command/Fsck.hs2
-rw-r--r--Command/Get.hs2
-rw-r--r--Command/InAnnex.hs2
-rw-r--r--Command/Init.hs2
-rw-r--r--Command/InitRemote.hs2
-rw-r--r--Command/Lock.hs2
-rw-r--r--Command/Map.hs2
-rw-r--r--Command/Merge.hs2
-rw-r--r--Command/Migrate.hs2
-rw-r--r--Command/PreCommit.hs2
-rw-r--r--Command/RecvKey.hs2
-rw-r--r--Command/Semitrust.hs2
-rw-r--r--Command/SendKey.hs2
-rw-r--r--Command/SetKey.hs2
-rw-r--r--Command/Status.hs2
-rw-r--r--Command/Trust.hs2
-rw-r--r--Command/Unannex.hs2
-rw-r--r--Command/Uninit.hs3
-rw-r--r--Command/Unlock.hs2
-rw-r--r--Command/Untrust.hs2
-rw-r--r--Command/Unused.hs2
-rw-r--r--Command/Upgrade.hs2
-rw-r--r--Command/Version.hs2
-rw-r--r--Command/Whereis.hs2
-rw-r--r--debian/changelog1
36 files changed, 58 insertions, 46 deletions
diff --git a/Command.hs b/Command.hs
index d19dad260..5690118c4 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 255e787b7..33b636bed 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 8deb79541..72e29ff60 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 35a939b38..645d1523c 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 9184ede9c..cd5da302e 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 7309c2acd..02f44915c 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 9e3554856..3e666b9ab 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 019fab076..1236fb823 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 5b13c742a..291904ec0 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 5e58f0733..090558d52 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 30243964e..a3e96b20d 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 0098a822d..d025095b1 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 d9596c3fe..21ff73bc4 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 b4db849c9..7a5735b74 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 06bdf4ad5..664643200 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 8f97199b7..cea1acc8d 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 bf3b12559..8f0bd78eb 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 6fbc6930b..05cc9d794 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 2b7162946..33d4c8ffc 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 e3956c5aa..ac8f042ba 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 50bc2662e..5dac4f533 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 9dc436a68..3415de526 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 f6a2f639c..4f61531ff 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 e8ba3ae79..5118a009b 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 51f344f20..a60f53997 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 155e53ee2..df79d4a7f 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 1af458630..17b689c34 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 cdaa790c0..76100c8c3 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 60e86cc03..b2046ec41 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 c89b61de7..be1d05298 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 7d65c1af9..5a2505a10 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 5cef829d6..d2b45ed6b 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 77d15c930..9ca3c8d2b 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 dae9a31d3..905a48a51 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 71b3ad96b..06a894fd3 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 dd72fc296..d100bd4e8 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 <joeyh@debian.org> Thu, 27 Oct 2011 13:58:53 -0400