module SimpleCmd.Git (
git,
git_,
gitBranch,
isGitDir,
rwGitDir) where
import Data.List (isPrefixOf)
import System.Directory (doesDirectoryExist, getCurrentDirectory)
import System.FilePath ((</>))
import SimpleCmd (cmd, cmd_, egrep_, removePrefix)
#if (defined(MIN_VERSION_base) && MIN_VERSION_base(4,8,2))
#else
import Control.Applicative ((<$>))
#endif
git :: String -> [String] -> IO String
git c args =
cmd "git" (c:args)
git_ :: String -> [String] -> IO ()
git_ c args =
cmd_ "git" (c:args)
isGitDir :: FilePath -> IO Bool
isGitDir dir = doesDirectoryExist (dir </> ".git")
gitBranch :: IO String
gitBranch =
removePrefix "* " . head . filter (isPrefixOf "* ") . lines <$> cmd "git" ["branch"]
rwGitDir :: IO Bool
rwGitDir = do
gitDir <- getCurrentDirectory >>= isGitDir
if gitDir
then egrep_ "url = (ssh://|git@)" ".git/config"
else return False