add typeChangedFiles

This commit is contained in:
Joey Hess 2010-11-10 14:01:41 -04:00
parent d0886a9ac7
commit 81524d19a7

View file

@ -39,6 +39,7 @@ module GitRepo (
checkAttr,
decodeGitFile,
encodeGitFile,
typeChangedFiles,
prop_idempotent_deencode
) where
@ -58,6 +59,7 @@ import Data.Char
import Data.Word (Word8)
import Codec.Binary.UTF8.String (encode)
import Text.Printf
import Data.List
import Utility
@ -227,20 +229,31 @@ hPipeRead repo params = assertLocal repo $ do
- are checked into git at that location. -}
inRepo :: Repo -> FilePath -> IO [FilePath]
inRepo repo l = pipeNullSplit repo
["ls-files", "--cached", "--exclude-standard", "-z", l]
["ls-files", "--cached", "--exclude-standard", "-z", "--", l]
{- Passed a location, recursively scans for all files that are not checked
- into git, and not gitignored. -}
notInRepo :: Repo -> FilePath -> IO [FilePath]
notInRepo repo l = pipeNullSplit repo
["ls-files", "--others", "--exclude-standard", "-z", l]
["ls-files", "--others", "--exclude-standard", "-z", "--", l]
{- Passed a location, returns a list of the files, staged for
- commit, that are being added, moved, or changed (but not deleted). -}
stagedFiles :: Repo -> FilePath -> IO [FilePath]
stagedFiles repo l = pipeNullSplit repo
["diff", "--cached", "--name-only", "--diff-filter=ACMRT", "-z",
"HEAD", l]
["diff", "--cached", "--name-only", "--diff-filter=ACMRT", "-z",
"--", l]
{- Passed a location, returns a list of the files whose type has changed. -}
typeChangedFiles :: Repo -> FilePath -> IO [FilePath]
typeChangedFiles repo l = do
changed <- pipeNullSplit repo $ start ++ end
changedCached <- pipeNullSplit repo $ start ++ ["--cached"] ++ end
-- a file can be found twice by the above, so nub
return $ nub $ changed ++ changedCached
where
start = ["diff", "--name-only", "--diff-filter=T", "-z"]
end = ["--", l]
{- Reads null terminated output of a git command (as enabled by the -z
- parameter), and splits it into a list of files. -}