diff --git a/CmdLine.hs b/CmdLine.hs index a683be5c53..caf7279463 100644 --- a/CmdLine.hs +++ b/CmdLine.hs @@ -28,6 +28,7 @@ import qualified Command.Fsck import qualified Command.Unlock import qualified Command.Lock import qualified Command.PreCommit +import qualified Command.Find subCmds :: [SubCommand] subCmds = @@ -61,6 +62,8 @@ subCmds = "fix up symlinks to point to annexed content" , SubCommand "fsck" maybepath Command.Fsck.seek "check for problems" + , SubCommand "find" maybepath Command.Find.seek + "lists available files" ] where path = "PATH ..." diff --git a/Command.hs b/Command.hs index 40a21cacc8..60d82d09fb 100644 --- a/Command.hs +++ b/Command.hs @@ -158,6 +158,13 @@ withAll w a params = do w a [Git.workTree g] else w a params +{- Provides a default parameter to a with search. -} +withDefault :: String-> SubCmdSeekStrings -> SubCmdSeekStrings +withDefault d w a params = do + if null params + then w a [d] + else w a params + {- filter out files from the state directory -} notState :: FilePath -> Bool notState f = stateLoc /= take (length stateLoc) f diff --git a/Command/Find.hs b/Command/Find.hs new file mode 100644 index 0000000000..db0589feae --- /dev/null +++ b/Command/Find.hs @@ -0,0 +1,24 @@ +{- git-annex command + - + - Copyright 2010 Joey Hess + - + - Licensed under the GNU GPL version 3 or higher. + -} + +module Command.Find where + +import Control.Monad (when) +import Control.Monad.State (liftIO) + +import Command +import Core + +seek :: [SubCmdSeek] +seek = [withDefault "." withFilesInGit start] + +{- Output a list of files. -} +start :: SubCmdStartString +start file = isAnnexed file $ \(key, _) -> do + exists <- inAnnex key + when (exists) $ liftIO $ putStrLn file + return Nothing diff --git a/debian/changelog b/debian/changelog index 64973557ff..07eceae6cd 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +git-annex (0.07) UNRELEASED; urgency=low + + * find: New subcommand. + + -- Joey Hess Sun, 14 Nov 2010 12:34:49 -0400 + git-annex (0.06) unstable; urgency=low * fsck: Check if annex.numcopies is satisfied. diff --git a/doc/git-annex.mdwn b/doc/git-annex.mdwn index 61a5962f1f..c496ca0d8c 100644 --- a/doc/git-annex.mdwn +++ b/doc/git-annex.mdwn @@ -166,6 +166,13 @@ Many git-annex subcommands will stage changes for later `git commit` by you. With parameters, only the specified files are checked. +* find [path ...] + + Outputs a list of annexed files whose content is currently present. + + With no parameters, defaults to finding all files in the current directory + and its subdirectories. + # OPTIONS * --force