Prevent combinations of options such as --all with --include

Previously such nonsensical combinations always treated the matching option
as if it didn't match.

For now, made find --branch refuse matching options that need a
filename, because one is not provided to them in a way they'll use.
There's an open bug report to support it, but making it error out is
better than the old behavior of not finding what it was asked to.

Also, made --mimetype combined with eg --all work, by looking at the
object file when operating on keys.
This commit is contained in:
Joey Hess 2021-03-01 16:10:42 -04:00
parent 7a089f05b2
commit 25e4ab7e81
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
4 changed files with 37 additions and 10 deletions

View file

@ -4,6 +4,12 @@ git-annex (8.20210224) UNRELEASED; urgency=medium
* registerurl: Allow it to be used in a bare repository.
* Windows: Correct the path to the html help file for 64 bit build.
* uninit: Fix a small bug that left a lock file in .git/annex
* Prevent combinations of options such as --all with --include.
* Fixed handling of --mimetype or --mimeencoding combined with
options like --all or --unused.
Also, made --mimetype combined with eg --all work, by looking at the
object file when operating on keys.
-- Joey Hess <id@joeyh.name> Wed, 24 Feb 2021 13:18:38 -0400

View file

@ -217,21 +217,30 @@ withKeyOptions' ko auto mkkeyaction fallbackaction worktreeitems = do
giveup "Cannot use --auto in a bare repository"
case (noworktreeitems, ko) of
(True, Nothing)
| bare -> noauto runallkeys
| bare -> nofilename $ noauto runallkeys
| otherwise -> fallbackaction worktreeitems
(False, Nothing) -> fallbackaction worktreeitems
(True, Just WantAllKeys) -> noauto runallkeys
(True, Just WantUnusedKeys) -> noauto $ runkeyaction unusedKeys'
(True, Just WantFailedTransfers) -> noauto runfailedtransfers
(True, Just (WantSpecificKey k)) -> noauto $ runkeyaction (return [k])
(True, Just WantIncompleteKeys) -> noauto $ runkeyaction incompletekeys
(True, Just (WantBranchKeys bs)) -> noauto $ runbranchkeys bs
(True, Just WantAllKeys) -> nofilename $ noauto runallkeys
(True, Just WantUnusedKeys) -> nofilename $ noauto $ runkeyaction unusedKeys'
(True, Just WantFailedTransfers) -> nofilename $ noauto runfailedtransfers
(True, Just (WantSpecificKey k)) -> nofilename $ noauto $ runkeyaction (return [k])
(True, Just WantIncompleteKeys) -> nofilename $ noauto $ runkeyaction incompletekeys
(True, Just (WantBranchKeys bs)) -> nofilename $ noauto $ runbranchkeys bs
(False, Just _) -> giveup "Can only specify one of file names, --all, --branch, --unused, --failed, --key, or --incomplete"
where
noauto a
| auto = giveup "Cannot use --auto with --all or --branch or --unused or --key or --incomplete"
| otherwise = a
nofilename a = ifM (Limit.introspect matchNeedsFileName)
( do
bare <- fromRepo Git.repoIsLocalBare
if bare
then giveup "Cannot use options that match on file names in a bare repository."
else giveup "Cannot use --all or --unused or --key or --incomplete with options that match on file names."
, a
)
noworktreeitems = case worktreeitems of
WorkTreeItems [] -> True
WorkTreeItems _ -> False

View file

@ -159,14 +159,16 @@ matchMagic
matchMagic _limitname querymagic selectprovidedinfo selectuserprovidedinfo (Just magic) glob =
Right $ MatchFiles
{ matchAction = const go
, matchNeedsFileName = True
, matchNeedsFileName = False
, matchNeedsFileContent = True
, matchNeedsKey = False
, matchNeedsLocationLog = False
}
where
cglob = compileGlob glob CaseSensative (GlobFilePath False) -- memoized
go (MatchingKey _ _) = pure False
go (MatchingKey k _) = withObjectLoc k $ \obj ->
maybe False (matchGlob cglob)
<$> querymagic magic (fromRawFilePath obj)
go (MatchingFile fi) = case contentFile fi of
Just f -> catchBoolIO $
maybe False (matchGlob cglob)

View file

@ -0,0 +1,10 @@
[[!comment format=mdwn
username="joey"
subject="""comment 2"""
date="2021-03-01T19:50:36Z"
content="""
I've guarded against all the other bad combos mentioned.
find --branch --unlocked/--locked will be rejected now due to that change,
but can be implemented later the way I discussed above.
"""]]