lookupkey: Added --ref option
Sponsored-by: Joshua Antonishen on Patreon
This commit is contained in:
parent
7be8950138
commit
a18e40bdd7
4 changed files with 46 additions and 10 deletions
|
@ -11,6 +11,7 @@ git-annex (10.20230829) UNRELEASED; urgency=medium
|
|||
filenames that confuse adb shell commands.
|
||||
* push: When on an adjusted branch, propagate changes to parent branch
|
||||
before updating export remotes.
|
||||
* lookupkey: Added --ref option.
|
||||
|
||||
-- Joey Hess <id@joeyh.name> Mon, 28 Aug 2023 13:10:17 -0400
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ module Command.LookupKey where
|
|||
import Command
|
||||
import Annex.CatFile
|
||||
import qualified Git.LsFiles
|
||||
import Git.Types
|
||||
import Utility.Terminal
|
||||
import Utility.SafeOutput
|
||||
|
||||
|
@ -18,18 +19,33 @@ cmd = notBareRepo $ noCommit $ noMessages $
|
|||
command "lookupkey" SectionPlumbing
|
||||
"looks up key used for file"
|
||||
(paramRepeating paramFile)
|
||||
(batchable run (pure ()))
|
||||
(batchable run optParser)
|
||||
|
||||
run :: () -> SeekInput -> String -> Annex Bool
|
||||
run _ _ file = seekSingleGitFile file >>= \case
|
||||
Nothing -> return False
|
||||
Just file' -> catKeyFile file' >>= \case
|
||||
Just k -> do
|
||||
IsTerminal isterminal <- liftIO $ checkIsTerminal stdout
|
||||
let sk = serializeKey k
|
||||
liftIO $ putStrLn $ if isterminal then safeOutput sk else sk
|
||||
return True
|
||||
data LookupKeyOptions = LookupKeyOptions
|
||||
{ refOption :: Bool
|
||||
}
|
||||
|
||||
optParser :: Parser LookupKeyOptions
|
||||
optParser = LookupKeyOptions
|
||||
<$> switch
|
||||
( long "ref"
|
||||
<> help "look up key used by git ref to file"
|
||||
)
|
||||
|
||||
run :: LookupKeyOptions -> SeekInput -> String -> Annex Bool
|
||||
run o _ file
|
||||
| refOption o = catKey (Ref (toRawFilePath file)) >>= display
|
||||
| otherwise = seekSingleGitFile file >>= \case
|
||||
Nothing -> return False
|
||||
Just file' -> catKeyFile file' >>= display
|
||||
|
||||
display :: Maybe Key -> Annex Bool
|
||||
display (Just k) = do
|
||||
IsTerminal isterminal <- liftIO $ checkIsTerminal stdout
|
||||
let sk = serializeKey k
|
||||
liftIO $ putStrLn $ if isterminal then safeOutput sk else sk
|
||||
return True
|
||||
display Nothing = return False
|
||||
|
||||
-- To support absolute filenames, pass through git ls-files.
|
||||
-- But, this plumbing command does not recurse through directories.
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
[[!comment format=mdwn
|
||||
username="joey"
|
||||
subject="""Re: get file by branch and path in bare repository"""
|
||||
date="2023-09-12T16:46:55Z"
|
||||
content="""
|
||||
--branch is limited to a treeish, so not a single file.
|
||||
|
||||
You can use `git-annex lookupkey --ref` to look up the key used by a ref to
|
||||
a file, and then pass that to `git-annex get --key`
|
||||
|
||||
(That's a new feature I added due to you asking this question.)
|
||||
"""]]
|
|
@ -15,6 +15,13 @@ nothing is output, and it exits nonzero.
|
|||
|
||||
# OPTIONS
|
||||
|
||||
* `--ref`
|
||||
|
||||
Rather than looking for the specified files in the index, interpet them
|
||||
as git refs. For example to find the key used for somefile in tag v1.0:
|
||||
|
||||
git-annex lookupkey v1.0:somefile
|
||||
|
||||
* `--batch`
|
||||
|
||||
Enable batch mode, in which a line containing the filename is read from
|
||||
|
|
Loading…
Reference in a new issue