reject batch options combined with non-batch options
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
This commit is contained in:
parent
56a12eb84c
commit
835c50966a
19 changed files with 50 additions and 27 deletions
|
@ -26,6 +26,8 @@ git-annex (10.20220121) UNRELEASED; urgency=medium
|
||||||
* adb: Added ignorefinderror configuration parameter.
|
* adb: Added ignorefinderror configuration parameter.
|
||||||
* Avoid crashing when run in a bare git repo that somehow contains an
|
* Avoid crashing when run in a bare git repo that somehow contains an
|
||||||
index file.
|
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
|
-- Joey Hess <id@joeyh.name> Mon, 03 Jan 2022 14:01:14 -0400
|
||||||
|
|
||||||
|
|
|
@ -77,8 +77,9 @@ batchable handler parser paramdesc = batchseeker <$> batchparser
|
||||||
|
|
||||||
batchseeker (opts, NoBatch, params) =
|
batchseeker (opts, NoBatch, params) =
|
||||||
mapM_ (\p -> go NoBatch opts (SeekInput [p], p)) params
|
mapM_ (\p -> go NoBatch opts (SeekInput [p], p)) params
|
||||||
batchseeker (opts, batchmode@(Batch fmt), _) =
|
batchseeker (opts, batchmode@(Batch fmt), params) =
|
||||||
batchInput fmt (pure . Right) (go batchmode opts)
|
batchOnly Nothing params $
|
||||||
|
batchInput fmt (pure . Right) (go batchmode opts)
|
||||||
|
|
||||||
go batchmode opts (si, p) =
|
go batchmode opts (si, p) =
|
||||||
unlessM (handler opts si p) $
|
unlessM (handler opts si p) $
|
||||||
|
@ -209,3 +210,8 @@ batchAnnexed fmt seeker keyaction = do
|
||||||
, providedMimeEncoding = Nothing
|
, providedMimeEncoding = Nothing
|
||||||
, providedLinkType = Nothing
|
, providedLinkType = Nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
|
batchOnly :: Maybe KeyOptions -> CmdParams -> Annex () -> Annex ()
|
||||||
|
batchOnly Nothing [] a = a
|
||||||
|
batchOnly _ _ _ = giveup "Cannot combine batch option with file or key options"
|
||||||
|
|
||||||
|
|
|
@ -95,7 +95,8 @@ seek o = startConcurrency commandStages $ do
|
||||||
Batch fmt
|
Batch fmt
|
||||||
| updateOnly o ->
|
| updateOnly o ->
|
||||||
giveup "--update --batch is not supported"
|
giveup "--update --batch is not supported"
|
||||||
| otherwise -> batchFiles fmt gofile
|
| otherwise -> batchOnly Nothing (addThese o) $
|
||||||
|
batchFiles fmt gofile
|
||||||
NoBatch -> do
|
NoBatch -> do
|
||||||
-- Avoid git ls-files complaining about files that
|
-- Avoid git ls-files complaining about files that
|
||||||
-- are not known to git yet, since this will add
|
-- are not known to git yet, since this will add
|
||||||
|
|
|
@ -119,10 +119,10 @@ seek o = startConcurrency commandStages $ do
|
||||||
then void $ commandAction $
|
then void $ commandAction $
|
||||||
startWeb addunlockedmatcher o' si u
|
startWeb addunlockedmatcher o' si u
|
||||||
else checkUrl addunlockedmatcher r o' si u
|
else checkUrl addunlockedmatcher r o' si u
|
||||||
forM_ (addUrls o) (\u -> go (SeekInput [u], (o, u)))
|
|
||||||
case batchOption o of
|
case batchOption o of
|
||||||
Batch fmt -> batchInput fmt (pure . parseBatchInput o) go
|
Batch fmt -> batchOnly Nothing (addUrls o) $
|
||||||
NoBatch -> noop
|
batchInput fmt (pure . parseBatchInput o) go
|
||||||
|
NoBatch -> forM_ (addUrls o) (\u -> go (SeekInput [u], (o, u)))
|
||||||
|
|
||||||
parseBatchInput :: AddUrlOptions -> String -> Either String (AddUrlOptions, URLString)
|
parseBatchInput :: AddUrlOptions -> String -> Either String (AddUrlOptions, URLString)
|
||||||
parseBatchInput o s
|
parseBatchInput o s
|
||||||
|
|
|
@ -51,7 +51,8 @@ seek o = startConcurrency commandStages $ do
|
||||||
(commandAction . keyaction)
|
(commandAction . keyaction)
|
||||||
(withFilesInGitAnnex ww seeker)
|
(withFilesInGitAnnex ww seeker)
|
||||||
=<< workTreeItems ww (copyFiles o)
|
=<< workTreeItems ww (copyFiles o)
|
||||||
Batch fmt -> batchAnnexed fmt seeker keyaction
|
Batch fmt -> batchOnly (keyOptions o) (copyFiles o) $
|
||||||
|
batchAnnexed fmt seeker keyaction
|
||||||
where
|
where
|
||||||
ww = WarnUnmatchLsFiles
|
ww = WarnUnmatchLsFiles
|
||||||
|
|
||||||
|
|
|
@ -71,7 +71,8 @@ seek o = startConcurrency commandStages $ do
|
||||||
(commandAction . startKeys o from)
|
(commandAction . startKeys o from)
|
||||||
(withFilesInGitAnnex ww seeker)
|
(withFilesInGitAnnex ww seeker)
|
||||||
=<< workTreeItems ww (dropFiles o)
|
=<< 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
|
where
|
||||||
ww = WarnUnmatchLsFiles
|
ww = WarnUnmatchLsFiles
|
||||||
|
|
||||||
|
|
|
@ -33,11 +33,11 @@ seek :: DropKeyOptions -> CommandSeek
|
||||||
seek o = do
|
seek o = do
|
||||||
unlessM (Annex.getState Annex.force) $
|
unlessM (Annex.getState Annex.force) $
|
||||||
giveup "dropkey can cause data loss; use --force if you're sure you want to do this"
|
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
|
case batchOption o of
|
||||||
Batch fmt -> batchInput fmt (pure . parsekey) $
|
NoBatch -> withKeys (commandAction . start) (toDrop o)
|
||||||
batchCommandAction . start
|
Batch fmt -> batchOnly Nothing (toDrop o) $
|
||||||
NoBatch -> noop
|
batchInput fmt (pure . parsekey) $
|
||||||
|
batchCommandAction . start
|
||||||
where
|
where
|
||||||
parsekey = maybe (Left "bad key") Right . deserializeKey
|
parsekey = maybe (Left "bad key") Right . deserializeKey
|
||||||
|
|
||||||
|
|
|
@ -70,7 +70,8 @@ seek o = do
|
||||||
(commandAction . startKeys o)
|
(commandAction . startKeys o)
|
||||||
(withFilesInGitAnnex ww seeker)
|
(withFilesInGitAnnex ww seeker)
|
||||||
=<< workTreeItems ww (findThese o)
|
=<< workTreeItems ww (findThese o)
|
||||||
Batch fmt -> batchAnnexedFiles fmt seeker
|
Batch fmt -> batchOnly (keyOptions o) (findThese o) $
|
||||||
|
batchAnnexedFiles fmt seeker
|
||||||
where
|
where
|
||||||
ww = WarnUnmatchLsFiles
|
ww = WarnUnmatchLsFiles
|
||||||
|
|
||||||
|
|
|
@ -41,7 +41,8 @@ seek :: FromKeyOptions -> CommandSeek
|
||||||
seek o = do
|
seek o = do
|
||||||
matcher <- addUnlockedMatcher
|
matcher <- addUnlockedMatcher
|
||||||
case (batchOption o, keyFilePairs o) of
|
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
|
-- older way of enabling batch input, does not support BatchNull
|
||||||
(NoBatch, []) -> seekBatch matcher (BatchFormat BatchLine (BatchKeys False))
|
(NoBatch, []) -> seekBatch matcher (BatchFormat BatchLine (BatchKeys False))
|
||||||
(NoBatch, ps) -> do
|
(NoBatch, ps) -> do
|
||||||
|
|
|
@ -49,7 +49,8 @@ seek o = startConcurrency downloadStages $ do
|
||||||
(commandAction . startKeys from)
|
(commandAction . startKeys from)
|
||||||
(withFilesInGitAnnex ww seeker)
|
(withFilesInGitAnnex ww seeker)
|
||||||
=<< workTreeItems ww (getFiles o)
|
=<< workTreeItems ww (getFiles o)
|
||||||
Batch fmt -> batchAnnexed fmt seeker (startKeys from)
|
Batch fmt -> batchOnly (keyOptions o) (getFiles o) $
|
||||||
|
batchAnnexed fmt seeker (startKeys from)
|
||||||
where
|
where
|
||||||
ww = WarnUnmatchLsFiles
|
ww = WarnUnmatchLsFiles
|
||||||
|
|
||||||
|
|
|
@ -119,7 +119,8 @@ optParser desc = InfoOptions
|
||||||
seek :: InfoOptions -> CommandSeek
|
seek :: InfoOptions -> CommandSeek
|
||||||
seek o = case batchOption o of
|
seek o = case batchOption o of
|
||||||
NoBatch -> withWords (commandAction . start o) (infoFor o)
|
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 :: InfoOptions -> [String] -> CommandStart
|
||||||
start o [] = do
|
start o [] = do
|
||||||
|
|
|
@ -93,8 +93,9 @@ seek o = case batchOption o of
|
||||||
Batch fmt -> withMessageState $ \s -> case outputType s of
|
Batch fmt -> withMessageState $ \s -> case outputType s of
|
||||||
JSONOutput _ -> ifM limited
|
JSONOutput _ -> ifM limited
|
||||||
( giveup "combining --batch with file matching options is not currently supported"
|
( giveup "combining --batch with file matching options is not currently supported"
|
||||||
, batchInput fmt parseJSONInput
|
, batchOnly (keyOptions o) (forFiles o) $
|
||||||
(commandAction . batchCommandStart . startBatch)
|
batchInput fmt parseJSONInput
|
||||||
|
(commandAction . batchCommandStart . startBatch)
|
||||||
)
|
)
|
||||||
_ -> giveup "--batch is currently only supported in --json mode"
|
_ -> giveup "--batch is currently only supported in --json mode"
|
||||||
|
|
||||||
|
|
|
@ -64,7 +64,8 @@ seek o = startConcurrency stages $ do
|
||||||
(commandAction . keyaction)
|
(commandAction . keyaction)
|
||||||
(withFilesInGitAnnex ww seeker)
|
(withFilesInGitAnnex ww seeker)
|
||||||
=<< workTreeItems ww (moveFiles o)
|
=<< workTreeItems ww (moveFiles o)
|
||||||
Batch fmt -> batchAnnexed fmt seeker keyaction
|
Batch fmt -> batchOnly (keyOptions o) (moveFiles o) $
|
||||||
|
batchAnnexed fmt seeker keyaction
|
||||||
where
|
where
|
||||||
seeker = AnnexedFileSeeker
|
seeker = AnnexedFileSeeker
|
||||||
{ startAction = start (fromToOptions o) (removeWhen o)
|
{ startAction = start (fromToOptions o) (removeWhen o)
|
||||||
|
|
|
@ -50,8 +50,9 @@ batchParser s = case separate (== ' ') (reverse s) of
|
||||||
|
|
||||||
seek :: ReKeyOptions -> CommandSeek
|
seek :: ReKeyOptions -> CommandSeek
|
||||||
seek o = case batchOption o of
|
seek o = case batchOption o of
|
||||||
Batch fmt -> batchInput fmt batchParser
|
Batch fmt -> batchOnly Nothing (reKeyThese o) $
|
||||||
(batchCommandAction . uncurry start)
|
batchInput fmt batchParser
|
||||||
|
(batchCommandAction . uncurry start)
|
||||||
NoBatch -> withPairs
|
NoBatch -> withPairs
|
||||||
(\(si, p) -> commandAction (start si (parsekey p)))
|
(\(si, p) -> commandAction (start si (parsekey p)))
|
||||||
(reKeyThese o)
|
(reKeyThese o)
|
||||||
|
|
|
@ -32,7 +32,7 @@ optParser desc = RegisterUrlOptions
|
||||||
|
|
||||||
seek :: RegisterUrlOptions -> CommandSeek
|
seek :: RegisterUrlOptions -> CommandSeek
|
||||||
seek o = case (batchOption o, keyUrlPairs o) of
|
seek o = case (batchOption o, keyUrlPairs o) of
|
||||||
(Batch (BatchFormat sep _), _) ->
|
(Batch (BatchFormat sep _), _) -> batchOnly Nothing (keyUrlPairs o) $
|
||||||
commandAction $ startMass setUrlPresent sep
|
commandAction $ startMass setUrlPresent sep
|
||||||
-- older way of enabling batch input, does not support BatchNull
|
-- older way of enabling batch input, does not support BatchNull
|
||||||
(NoBatch, []) -> commandAction $ startMass setUrlPresent BatchLine
|
(NoBatch, []) -> commandAction $ startMass setUrlPresent BatchLine
|
||||||
|
|
|
@ -29,7 +29,8 @@ optParser desc = RmUrlOptions
|
||||||
|
|
||||||
seek :: RmUrlOptions -> CommandSeek
|
seek :: RmUrlOptions -> CommandSeek
|
||||||
seek o = case batchOption o of
|
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)
|
NoBatch -> withPairs (commandAction . start) (rmThese o)
|
||||||
|
|
||||||
-- Split on the last space, since a FilePath can contain whitespace,
|
-- Split on the last space, since a FilePath can contain whitespace,
|
||||||
|
|
|
@ -30,9 +30,10 @@ optParser desc = SetPresentKeyOptions
|
||||||
|
|
||||||
seek :: SetPresentKeyOptions -> CommandSeek
|
seek :: SetPresentKeyOptions -> CommandSeek
|
||||||
seek o = case batchOption o of
|
seek o = case batchOption o of
|
||||||
Batch fmt -> batchInput fmt
|
Batch fmt -> batchOnly Nothing (params o) $
|
||||||
(pure . parseKeyStatus . words)
|
batchInput fmt
|
||||||
(batchCommandAction . uncurry start)
|
(pure . parseKeyStatus . words)
|
||||||
|
(batchCommandAction . uncurry start)
|
||||||
NoBatch -> either giveup (commandAction . start (SeekInput (params o)))
|
NoBatch -> either giveup (commandAction . start (SeekInput (params o)))
|
||||||
(parseKeyStatus $ params o)
|
(parseKeyStatus $ params o)
|
||||||
|
|
||||||
|
|
|
@ -62,7 +62,8 @@ seek o = do
|
||||||
(commandAction . startKeys o m)
|
(commandAction . startKeys o m)
|
||||||
(withFilesInGitAnnex ww seeker)
|
(withFilesInGitAnnex ww seeker)
|
||||||
=<< workTreeItems ww (whereisFiles o)
|
=<< 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
|
where
|
||||||
ww = WarnUnmatchLsFiles
|
ww = WarnUnmatchLsFiles
|
||||||
|
|
||||||
|
|
|
@ -21,3 +21,5 @@ MD5E-s5663237--4608ffbd6b78ce3a325eb338fa556589.nii.gz
|
||||||
### What version of git-annex are you using? On what operating system?
|
### What version of git-annex are you using? On what operating system?
|
||||||
|
|
||||||
`8.20211231+git140-gc3817495f-1~ndall+1`
|
`8.20211231+git140-gc3817495f-1~ndall+1`
|
||||||
|
|
||||||
|
> [[fixed|done]] --[[Joey]]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue