From 8e8439a5191e8768edebdcf27668157b70c0ebf7 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Wed, 27 Jun 2012 09:27:59 -0400 Subject: add ls-files --unmerged support --- Git/LsFiles.hs | 27 ++++++++++++++++++++++++++- Git/Types.hs | 6 ++++++ 2 files changed, 32 insertions(+), 1 deletion(-) (limited to 'Git') diff --git a/Git/LsFiles.hs b/Git/LsFiles.hs index 06d4b9f44..540503a28 100644 --- a/Git/LsFiles.hs +++ b/Git/LsFiles.hs @@ -1,6 +1,6 @@ {- git ls-files interface - - - Copyright 2010 Joey Hess + - Copyright 2010,2012 Joey Hess - - Licensed under the GNU GPL version 3 or higher. -} @@ -18,6 +18,8 @@ module Git.LsFiles ( import Common import Git import Git.Command +import Git.Types +import Git.Sha {- Scans for files that are checked into git at the specified locations. -} inRepo :: [FilePath] -> Repo -> IO [FilePath] @@ -75,3 +77,26 @@ typeChanged' ps l repo = do where prefix = [Params "diff --name-only --diff-filter=T -z"] suffix = Param "--" : map File l + +data Unmerged = Unmerged + { unmergedFile :: FilePath + , unmergedBlobType :: BlobType + , unmergedSha :: Sha + } + +{- Returns a list of the files in the specified locations that have + - unresolved merge conflicts. Each unmerged file will have duplicates + - in the list for each unmerged version (typically two). -} +unmerged :: [FilePath] -> Repo -> IO [Unmerged] +unmerged l repo = catMaybes . map parse <$> list repo + where + list = pipeNullSplit $ Params "ls-files --unmerged -z --" : map File l + parse s + | null file || length ws < 2 = Nothing + | otherwise = do + blobtype <- readBlobType (ws !! 0) + sha <- extractSha (ws !! 1) + return $ Unmerged file blobtype sha + where + (metadata, file) = separate (== '\t') s + ws = words metadata diff --git a/Git/Types.hs b/Git/Types.hs index 1df6e343b..e8cdbb442 100644 --- a/Git/Types.hs +++ b/Git/Types.hs @@ -71,3 +71,9 @@ instance Show BlobType where show FileBlob = "100644" show ExecutableBlob = "100755" show SymlinkBlob = "120000" + +readBlobType :: String -> Maybe BlobType +readBlobType "100644" = Just FileBlob +readBlobType "100755" = Just ExecutableBlob +readBlobType "120000" = Just SymlinkBlob +readBlobType _ = Nothing -- cgit v1.2.3