module Hish.VCS
(
VCS (..)
, Git (..)
, Darcs (..)
) where
import Text.Regex.TDFA ((=~))
import qualified Data.String.Utils as S (replace)
import qualified Data.List as DL (lines)
class VCS a where
vcsAhead :: a -> String -> Maybe String
vcsBehind :: a -> String -> Maybe String
vcsCleanliness :: a -> String -> Maybe String
vcsCurrentBranch :: a -> String -> Maybe String
data Git = Git
instance VCS Git where
vcsAhead _ s =
case (s =~ "ahead [0-9]+" :: String) of
[] -> Nothing
ahead -> Just $ S.replace "ahead " "" ahead
vcsBehind _ s =
case (s =~ "behind [0-9]+" :: String) of
[] -> Nothing
behind -> Just $ S.replace "behind " "" behind
vcsCleanliness _ s = let body = tail $ DL.lines s in
case body of
[] -> Just "#"
_ -> let (index,tree) = unzip $ map ((\ (a:b:_)->(a,b)).take 2) body in
if ("" == (filter (/='?') tree))
then Just "?"
else Just "*"
vcsCurrentBranch _ = Just
. drop 2
. head
. filter ((=='*').head)
. lines
data Darcs = Darcs
instance VCS Darcs where
vcsAhead _ s = return "a"
vcsBehind _ s = return "b"
vcsCleanliness _ s = return "?"