]> dgit.raspbian.org Git - git-annex.git/commitdiff
reject batch options combined with non-batch options
authorJoey Hess <joeyh@joeyh.name>
Wed, 26 Jan 2022 16:59:55 +0000 (12:59 -0400)
committerJoey Hess <joeyh@joeyh.name>
Wed, 26 Jan 2022 17:00:19 +0000 (13:00 -0400)
Reject combinations of --batch (or --batch-keys) with options like --all or
--key or with filenames.

Most commands ignored the non-batch items when batch mode was enabled.

For some reason, addurl and dropkey both processed first the specified
non-batch items, followed by entering batch mode. Changed them to also
error out, for consistency.

Sponsored-by: Dartmouth College's Datalad project
19 files changed:
CHANGELOG
CmdLine/Batch.hs
Command/Add.hs
Command/AddUrl.hs
Command/Copy.hs
Command/Drop.hs
Command/DropKey.hs
Command/Find.hs
Command/FromKey.hs
Command/Get.hs
Command/Info.hs
Command/MetaData.hs
Command/Move.hs
Command/ReKey.hs
Command/RegisterUrl.hs
Command/RmUrl.hs
Command/SetPresentKey.hs
Command/Whereis.hs
doc/bugs/should_error_on_whereis_--batch-keys_--all.mdwn

index c6468a020a080fcebef61216a7d451978ead0730..04e0e32fae1b66eb0c99adf35c79c65cd3fcd71f 100644 (file)
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -26,6 +26,8 @@ git-annex (10.20220121) UNRELEASED; urgency=medium
   * adb: Added ignorefinderror configuration parameter.
   * Avoid crashing when run in a bare git repo that somehow contains an
     index file.
+  * Reject combinations of --batch (or --batch-keys) with options like
+    --all or --key or with filenames.
 
  -- Joey Hess <id@joeyh.name>  Mon, 03 Jan 2022 14:01:14 -0400
 
index 15fd89710e0638b26282dfce001ba2515207be1b..80c901ecca2fb374c1cb5b2b8f71c16077902b78 100644 (file)
@@ -77,8 +77,9 @@ batchable handler parser paramdesc = batchseeker <$> batchparser
        
        batchseeker (opts, NoBatch, params) =
                mapM_ (\p -> go NoBatch opts (SeekInput [p], p)) params
-       batchseeker (opts, batchmode@(Batch fmt), _) = 
-               batchInput fmt (pure . Right) (go batchmode opts)
+       batchseeker (opts, batchmode@(Batch fmt), params) = 
+               batchOnly Nothing params $
+                       batchInput fmt (pure . Right) (go batchmode opts)
 
        go batchmode opts (si, p) =
                unlessM (handler opts si p) $
@@ -209,3 +210,8 @@ batchAnnexed fmt seeker keyaction = do
                , providedMimeEncoding = Nothing
                , providedLinkType = Nothing
                }
+
+batchOnly :: Maybe KeyOptions -> CmdParams -> Annex () -> Annex ()
+batchOnly Nothing [] a = a
+batchOnly _ _ _ = giveup "Cannot combine batch option with file or key options"
+
index 4da6f7354f9ecb27b0696863102080e220e7ab4f..57ee51b5a2b3eda2ed4c79bb08e2eddf955d3f3e 100644 (file)
@@ -95,7 +95,8 @@ seek o = startConcurrency commandStages $ do
                Batch fmt
                        | updateOnly o ->
                                giveup "--update --batch is not supported"
-                       | otherwise -> batchFiles fmt gofile
+                       | otherwise -> batchOnly Nothing (addThese o) $
+                               batchFiles fmt gofile
                NoBatch -> do
                        -- Avoid git ls-files complaining about files that
                        -- are not known to git yet, since this will add
index 30443e649b958bb0b0b960eb622e4dac09f97915..9c35b01e51fc991d81f45d4c959fbdb082eaadb1 100644 (file)
@@ -119,10 +119,10 @@ seek o = startConcurrency commandStages $ do
                        then void $ commandAction $
                                startWeb addunlockedmatcher o' si u
                        else checkUrl addunlockedmatcher r o' si u
-       forM_ (addUrls o) (\u -> go (SeekInput [u], (o, u)))
        case batchOption o of
-               Batch fmt -> batchInput fmt (pure . parseBatchInput o) go
-               NoBatch -> noop
+               Batch fmt -> batchOnly Nothing (addUrls o) $
+                       batchInput fmt (pure . parseBatchInput o) go
+               NoBatch -> forM_ (addUrls o) (\u -> go (SeekInput [u], (o, u)))
 
 parseBatchInput :: AddUrlOptions -> String -> Either String (AddUrlOptions, URLString)
 parseBatchInput o s
index a6ddf4f80f43e1532b7a9385f2c165ba452f493b..9e18cf7e2d1c9c2e36567418dabc9db2ae25e870 100644 (file)
@@ -51,7 +51,8 @@ seek o = startConcurrency commandStages $ do
                        (commandAction . keyaction)
                        (withFilesInGitAnnex ww seeker)
                        =<< workTreeItems ww (copyFiles o)
-               Batch fmt -> batchAnnexed fmt seeker keyaction
+               Batch fmt -> batchOnly (keyOptions o) (copyFiles o) $
+                       batchAnnexed fmt seeker keyaction
   where
        ww = WarnUnmatchLsFiles
        
index a9a4314cac0566cdfd53e837bf744c35bc1e8220..b5774b999f285b1c1da103197061380acef5d11a 100644 (file)
@@ -71,7 +71,8 @@ seek o = startConcurrency commandStages $ do
                        (commandAction . startKeys o from)
                        (withFilesInGitAnnex ww seeker)
                        =<< workTreeItems ww (dropFiles o)
-               Batch fmt -> batchAnnexed fmt seeker (startKeys o from)
+               Batch fmt -> batchOnly (keyOptions o) (dropFiles o) $
+                       batchAnnexed fmt seeker (startKeys o from)
   where
        ww = WarnUnmatchLsFiles
 
index 580c6f1c22dfb0475b29b151fda5c0a7fed2aefc..86248b0cc0abda2374e8e86e5bab43de105ad8c5 100644 (file)
@@ -33,11 +33,11 @@ seek :: DropKeyOptions -> CommandSeek
 seek o = do
        unlessM (Annex.getState Annex.force) $
                giveup "dropkey can cause data loss; use --force if you're sure you want to do this"
-       withKeys (commandAction . start) (toDrop o)
        case batchOption o of
-               Batch fmt -> batchInput fmt (pure . parsekey) $
-                       batchCommandAction . start
-               NoBatch -> noop
+               NoBatch -> withKeys (commandAction . start) (toDrop o)
+               Batch fmt -> batchOnly Nothing (toDrop o) $
+                       batchInput fmt (pure . parsekey) $
+                               batchCommandAction . start
   where
        parsekey = maybe (Left "bad key") Right . deserializeKey
 
index 0a5544e437727381d6f6fe4bb28eda9c6168fa75..271543d1e6bef271c305f6da43948ce4b16079ca 100644 (file)
@@ -70,7 +70,8 @@ seek o = do
                        (commandAction . startKeys o)
                        (withFilesInGitAnnex ww seeker)
                        =<< workTreeItems ww (findThese o)
-               Batch fmt -> batchAnnexedFiles fmt seeker
+               Batch fmt -> batchOnly (keyOptions o) (findThese o) $
+                       batchAnnexedFiles fmt seeker
   where
        ww = WarnUnmatchLsFiles
 
index e4591a184f303c8a5179183881583ee806cb3a25..22eafcefe53734c2188d132fe2e1744b1eb63280 100644 (file)
@@ -41,7 +41,8 @@ seek :: FromKeyOptions -> CommandSeek
 seek o = do
        matcher <- addUnlockedMatcher
        case (batchOption o, keyFilePairs o) of
-               (Batch fmt, _) -> seekBatch matcher fmt
+               (Batch fmt, _) -> batchOnly Nothing (keyFilePairs o) $
+                       seekBatch matcher fmt
                -- older way of enabling batch input, does not support BatchNull
                (NoBatch, []) -> seekBatch matcher (BatchFormat BatchLine (BatchKeys False))
                (NoBatch, ps) -> do
index eef40c4eb349c5db28c799a6da71e1825f9478df..c3faf308d4708f9fafaba9015ade01d7283fae0c 100644 (file)
@@ -49,7 +49,8 @@ seek o = startConcurrency downloadStages $ do
                        (commandAction . startKeys from)
                        (withFilesInGitAnnex ww seeker)
                        =<< workTreeItems ww (getFiles o)
-               Batch fmt -> batchAnnexed fmt seeker (startKeys from)
+               Batch fmt -> batchOnly (keyOptions o) (getFiles o) $
+                       batchAnnexed fmt seeker (startKeys from)
   where
        ww = WarnUnmatchLsFiles
 
index 8f9f243a0b8c9bd85cd79a5b75aaf145e1c01535..6594498e3a5471c313301e077772217a5fdfd132 100644 (file)
@@ -119,7 +119,8 @@ optParser desc = InfoOptions
 seek :: InfoOptions -> CommandSeek
 seek o = case batchOption o of
        NoBatch -> withWords (commandAction . start o) (infoFor o)
-       Batch fmt -> batchInput fmt (pure . Right) (itemInfo o)
+       Batch fmt -> batchOnly Nothing (infoFor o) $
+               batchInput fmt (pure . Right) (itemInfo o)
 
 start :: InfoOptions -> [String] -> CommandStart
 start o [] = do
index 2ab6e37ee4b61bf75e7455766eb7e7b2064bdb41..cd48734b98ade9fec096798aab9997c0d251140f 100644 (file)
@@ -93,8 +93,9 @@ seek o = case batchOption o of
        Batch fmt -> withMessageState $ \s -> case outputType s of
                JSONOutput _ -> ifM limited
                        ( giveup "combining --batch with file matching options is not currently supported"
-                       , batchInput fmt parseJSONInput 
-                               (commandAction . batchCommandStart . startBatch)
+                       , batchOnly (keyOptions o) (forFiles o) $
+                               batchInput fmt parseJSONInput 
+                                       (commandAction . batchCommandStart . startBatch)
                        )
                _ -> giveup "--batch is currently only supported in --json mode"
 
index 781bdb6138877682485feb2b4ea12e63398032d9..31f6d05a79a107265fac88990f3c4b244bee72fb 100644 (file)
@@ -64,7 +64,8 @@ seek o = startConcurrency stages $ do
                        (commandAction . keyaction)
                        (withFilesInGitAnnex ww seeker)
                        =<< workTreeItems ww (moveFiles o)
-               Batch fmt -> batchAnnexed fmt seeker keyaction
+               Batch fmt -> batchOnly (keyOptions o) (moveFiles o) $
+                       batchAnnexed fmt seeker keyaction
   where
        seeker = AnnexedFileSeeker
                { startAction = start (fromToOptions o) (removeWhen o)
index ab2f9fa2411866f892fa80ae3752890d48ea8908..d00cad566f75ae87af39c428ba88e1480e6c8ceb 100644 (file)
@@ -50,8 +50,9 @@ batchParser s = case separate (== ' ') (reverse s) of
 
 seek :: ReKeyOptions -> CommandSeek
 seek o = case batchOption o of
-       Batch fmt -> batchInput fmt batchParser
-               (batchCommandAction . uncurry start)
+       Batch fmt -> batchOnly Nothing (reKeyThese o) $
+               batchInput fmt batchParser
+                       (batchCommandAction . uncurry start)
        NoBatch -> withPairs 
                (\(si, p) -> commandAction (start si (parsekey p))) 
                (reKeyThese o)
index 1ec953d02bd4f29ea7c2c2025c7fcbb3369cb717..f42272957208a06b32d1ec7baf650af219035c6b 100644 (file)
@@ -32,7 +32,7 @@ optParser desc = RegisterUrlOptions
 
 seek :: RegisterUrlOptions -> CommandSeek
 seek o = case (batchOption o, keyUrlPairs o) of
-       (Batch (BatchFormat sep _), _) ->
+       (Batch (BatchFormat sep _), _) -> batchOnly Nothing (keyUrlPairs o) $
                commandAction $ startMass setUrlPresent sep
        -- older way of enabling batch input, does not support BatchNull
        (NoBatch, []) -> commandAction $ startMass setUrlPresent BatchLine
index bd854f64a0fac61b7f19077fa404d39e1e8945e5..93443b227ac6961b928eda4933ff827039da9abd 100644 (file)
@@ -29,7 +29,8 @@ optParser desc = RmUrlOptions
 
 seek :: RmUrlOptions -> CommandSeek
 seek o = case batchOption o of
-       Batch fmt -> batchInput fmt batchParser (batchCommandAction . start)
+       Batch fmt -> batchOnly Nothing (rmThese o) $
+               batchInput fmt batchParser (batchCommandAction . start)
        NoBatch -> withPairs (commandAction . start) (rmThese o)
 
 -- Split on the last space, since a FilePath can contain whitespace,
index 50749886e60ba6396d5b9493c56b31d993e0882a..839d23cec7221a851f0ccb2404811e7de7368064 100644 (file)
@@ -30,9 +30,10 @@ optParser desc = SetPresentKeyOptions
 
 seek :: SetPresentKeyOptions -> CommandSeek
 seek o = case batchOption o of
-       Batch fmt -> batchInput fmt
-               (pure . parseKeyStatus . words)
-               (batchCommandAction . uncurry start)
+       Batch fmt -> batchOnly Nothing (params o) $
+               batchInput fmt
+                       (pure . parseKeyStatus . words)
+                       (batchCommandAction . uncurry start)
        NoBatch -> either giveup (commandAction . start (SeekInput (params o)))
                (parseKeyStatus $ params o)
 
index 58f26db1f1ba3f4547643142cb1534569d94719b..d3efb7465818a38ea5062499f2c4bd8744ca3046 100644 (file)
@@ -62,7 +62,8 @@ seek o = do
                                (commandAction . startKeys o m)
                                (withFilesInGitAnnex ww seeker)
                                =<< workTreeItems ww (whereisFiles o)
-               Batch fmt -> batchAnnexed fmt seeker (startKeys o m)
+               Batch fmt -> batchOnly (keyOptions o) (whereisFiles o) $
+                       batchAnnexed fmt seeker (startKeys o m)
   where
        ww = WarnUnmatchLsFiles
 
index 09d403bbce1d9ecf635504b63b6a38f0345cd6a6..0ee8f21ebbe1ed416470d5a3fb6e1744654f0774 100644 (file)
@@ -21,3 +21,5 @@ MD5E-s5663237--4608ffbd6b78ce3a325eb338fa556589.nii.gz
 ### What version of git-annex are you using? On what operating system?
 
 `8.20211231+git140-gc3817495f-1~ndall+1`
+
+> [[fixed|done]] --[[Joey]]