89b2542d3c
Added annex.skipunknown git config, that can be set to false to change the behavior of commands like `git annex get foo*`, to not skip over files/dirs that are not checked into git and are explicitly listed in the command line. Significant complexity was needed to handle git-annex add, which uses some git ls-files calls, but needs to not use --error-unmatch because of course the files are not known to git. annex.skipunknown is planned to change to default to false in a git-annex release in early 2022. There's a todo for that.
40 lines
1.1 KiB
Haskell
40 lines
1.1 KiB
Haskell
{- git-annex command
|
|
-
|
|
- Copyright 2013-2017 Joey Hess <id@joeyh.name>
|
|
-
|
|
- Licensed under the GNU AGPL version 3 or higher.
|
|
-}
|
|
|
|
module Command.LookupKey where
|
|
|
|
import Command
|
|
import Annex.CatFile
|
|
import qualified Git.LsFiles
|
|
|
|
cmd :: Command
|
|
cmd = notBareRepo $ noCommit $ noMessages $
|
|
command "lookupkey" SectionPlumbing
|
|
"looks up key used for file"
|
|
(paramRepeating paramFile)
|
|
(batchable run (pure ()))
|
|
|
|
run :: () -> String -> Annex Bool
|
|
run _ file = seekSingleGitFile file >>= \case
|
|
Nothing -> return False
|
|
Just file' -> catKeyFile file' >>= \case
|
|
Just k -> do
|
|
liftIO $ putStrLn $ serializeKey k
|
|
return True
|
|
Nothing -> return False
|
|
|
|
-- To support absolute filenames, pass through git ls-files.
|
|
-- But, this plumbing command does not recurse through directories.
|
|
seekSingleGitFile :: FilePath -> Annex (Maybe RawFilePath)
|
|
seekSingleGitFile file = do
|
|
(l, cleanup) <- inRepo (Git.LsFiles.inRepo [] [toRawFilePath file])
|
|
r <- case l of
|
|
(f:[]) | takeFileName (fromRawFilePath f) == takeFileName file ->
|
|
return (Just f)
|
|
_ -> return Nothing
|
|
void $ liftIO cleanup
|
|
return r
|