cabalg 0.2.3 → 0.2.4
raw patch · 5 files changed
+69/−19 lines, 5 filesdep +cabalg
Dependencies added: cabalg
Files
- cabalg.cabal +27/−3
- src/Git.hs +7/−3
- src/Main.hs +1/−13
- src/System/Directory/NonExistent.hs +19/−0
- test/Test.hs +15/−0
cabalg.cabal view
@@ -1,5 +1,5 @@ name: cabalg-version: 0.2.3+version: 0.2.4 synopsis: alias for cabal install from given git repo license: MIT license-file: LICENSE@@ -34,12 +34,12 @@ . Please notice, that '--single-branch' flag comes with git-1.7.10 (<https://lkml.org/lkml/2012/3/28/418>) and later, so you probably want to have it. .- It's supposed to be Windows-compatible.+ It's supposed to be Windows-compatible (not sure about the tests) executable cabalg main-is: Main.hs hs-source-dirs: src- other-modules: Git+ other-modules: Git System.Directory.NonExistent ghc-options: -Wall default-language: Haskell2010 @@ -49,6 +49,30 @@ , directory , filepath +library+ hs-source-dirs: src+ exposed-modules: System.Directory.NonExistent+ other-modules: Git+ ghc-options: -Wall+ default-language: Haskell2010+ build-depends:+ base >= 4 && < 5+ , process+ , directory+ , filepath+ source-repository head type: git location: https://github.com/dmalikov/cabalg++test-suite test+ type: exitcode-stdio-1.0+ hs-source-dirs: test+ main-is: Test.hs+ default-language: Haskell2010+ build-depends:+ base >= 4 && < 5+ , cabalg+ , directory+ , process+
src/Git.hs view
@@ -1,7 +1,8 @@ module Git where import Control.Monad-import System.FilePath+import System.Directory+import System.FilePath() import System.Process -- | git clone "master" branch@@ -17,12 +18,15 @@ , url , dir] [] --- | git clone and checkout in particular revision (could be much slower than 'clone')+-- | git clone and checkout particular revision (could be much slower than 'clone') cloneRevision :: String -- | url -> String -- | revision -> FilePath -- | directory where repository will be cloned to -> IO () cloneRevision url revision dir = do void $ readProcess "git" [ "clone", url, dir ] []- void $ readProcess "git" [ "--git-dir", dir </> ".git", "checkout", revision, "--force", "--quiet" ] []+ currentDir <- getCurrentDirectory+ setCurrentDirectory dir+ void $ readProcess "git" [ "checkout", revision, "--force", "--quiet" ] []+ setCurrentDirectory currentDir
src/Main.hs view
@@ -9,6 +9,7 @@ import System.Process import Git+import System.Directory.NonExistent main :: IO ()@@ -50,19 +51,6 @@ go acc (x:xs) | x == c = go [] xs | otherwise = go (acc ++ [x]) xs go acc [] = acc--createNonExistentDirectory :: FilePath -> String -> IO FilePath-createNonExistentDirectory currentDir dirname = do- newDir <- generateNonExistentDirectory dirname Nothing- createDirectory newDir- return newDir- where- generateNonExistentDirectory :: FilePath -> Maybe Int -> IO FilePath- generateNonExistentDirectory d suffix = let fullDirName = currentDir </> d ++ maybe "" show suffix in do- exist <- doesDirectoryExist fullDirName- if exist- then generateNonExistentDirectory d $ return $ maybe 1 (+ 1) suffix- else return fullDirName findCabalFile :: FilePath -> IO (Maybe FilePath) findCabalFile path = ((path </>) `fmap`) `fmap` find (".cabal" `isSuffixOf`) `fmap` getDirectoryContents path
+ src/System/Directory/NonExistent.hs view
@@ -0,0 +1,19 @@+module System.Directory.NonExistent where++import System.FilePath+import System.Directory++-- | create non existent directory appending a number to the end of the name+createNonExistentDirectory :: FilePath -> String -> IO FilePath+createNonExistentDirectory currentDir dirname = do+ newDir <- generateNonExistentDirectory dirname Nothing+ createDirectory newDir+ return newDir+ where+ generateNonExistentDirectory :: FilePath -> Maybe Int -> IO FilePath+ generateNonExistentDirectory d suffix = let fullDirName = currentDir </> d ++ maybe "" show suffix in do+ exist <- doesDirectoryExist fullDirName+ if exist+ then generateNonExistentDirectory d $ return $ maybe 1 (+ 1) suffix+ else return fullDirName+
+ test/Test.hs view
@@ -0,0 +1,15 @@+module Main where++import Control.Monad+import System.Directory+import System.Process++import System.Directory.NonExistent++main :: IO ()+main = do+ currentDir <- getCurrentDirectory+ tmpDir <- createNonExistentDirectory currentDir "cabalgtest"+ setCurrentDirectory tmpDir+ void $ readProcess "cabalg" ["https://github.com/dmalikov/dotfiles@master", "https://github.com/biegunka/biegunka@develop"] []+ setCurrentDirectory currentDir