Created
July 13, 2013 11:04
-
-
Save fujimura/5990335 to your computer and use it in GitHub Desktop.
Clone git repo in temporary directory and do `ls-files`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Control.Exception (bracket_) | |
import System.Directory | |
import System.Exit (ExitCode) | |
import System.IO.Temp (withSystemTempDirectory) | |
import System.Process (system) | |
inTemporaryDirectory :: String -> IO a -> IO a | |
inTemporaryDirectory name cb = | |
withSystemTempDirectory name $ flip inDirectory cb | |
inDirectory :: FilePath -> IO a -> IO a | |
inDirectory path cb = do | |
pwd <- getCurrentDirectory | |
bracket_ (setCurrentDirectory path) (setCurrentDirectory pwd) cb | |
cloneRepo :: String -> IO ExitCode | |
cloneRepo repoUrl = do | |
system $ "git clone --no-checkout --depth=1 --quiet " ++ repoUrl ++ " ./" | |
system "git checkout HEAD --quiet" | |
main :: IO () | |
main = | |
inTemporaryDirectory "boilerplate" $ do | |
cloneRepo "git@github.com:fujimura/wai-hspec-example.git" | |
system "git ls-files" | |
return () |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment