From 25e4ab7e811185bf9f44875f49e2e111ecb39831 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Mon, 1 Mar 2021 16:10:42 -0400 Subject: [PATCH] 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. --- CHANGELOG | 6 +++++ CmdLine/Seek.hs | 25 +++++++++++++------ Limit.hs | 6 +++-- ..._3f1980c96f795c30886b3decba69819d._comment | 10 ++++++++ 4 files changed, 37 insertions(+), 10 deletions(-) create mode 100644 doc/bugs/find_--branch__58___no_results_with_--__123__un__44____125__locked/comment_2_3f1980c96f795c30886b3decba69819d._comment diff --git a/CHANGELOG b/CHANGELOG index c3debfd120..c1beb91d1e 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -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 Wed, 24 Feb 2021 13:18:38 -0400 diff --git a/CmdLine/Seek.hs b/CmdLine/Seek.hs index 46ec0f67c4..f6e9dee556 100644 --- a/CmdLine/Seek.hs +++ b/CmdLine/Seek.hs @@ -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 diff --git a/Limit.hs b/Limit.hs index 649c1c2c27..145b57291e 100644 --- a/Limit.hs +++ b/Limit.hs @@ -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) diff --git a/doc/bugs/find_--branch__58___no_results_with_--__123__un__44____125__locked/comment_2_3f1980c96f795c30886b3decba69819d._comment b/doc/bugs/find_--branch__58___no_results_with_--__123__un__44____125__locked/comment_2_3f1980c96f795c30886b3decba69819d._comment new file mode 100644 index 0000000000..5a10b2d539 --- /dev/null +++ b/doc/bugs/find_--branch__58___no_results_with_--__123__un__44____125__locked/comment_2_3f1980c96f795c30886b3decba69819d._comment @@ -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. +"""]]