packages feed

gitcache 0.1 → 0.2

raw patch · 3 files changed

+40/−18 lines, 3 files

Files

README.md view
@@ -1,9 +1,16 @@ gitcache ======= -[![Build Status](https://travis-ci.org/vincenthz/hs-gitcache.png?branch=master)](https://travis-ci.org/vincenthz/hs-gitcache)+[![Build Status](https://travis-ci.org/vincenthz/gitcache.png?branch=master)](https://travis-ci.org/vincenthz/gitcache) [![BSD](http://b.repl.ca/v1/license-BSD-blue.png)](http://en.wikipedia.org/wiki/BSD_licenses) [![Haskell](http://b.repl.ca/v1/language-haskell-lightgrey.png)](http://haskell.org)   Documentation: [gitcache on hackage](http://hackage.haskell.org/package/gitcache)+++INSTALL+-------++1) make sure you have ghc and cabal available on your system, then+2) cabal install gitcache
gitcache.cabal view
@@ -1,7 +1,8 @@ Name:                gitcache-Version:             0.1+Version:             0.2 Synopsis:            Simple git utility to use and manage clone cache-Description:         +Description:+    Manage cache of git repository for faster cloning and offline working License:             BSD3 License-file:        LICENSE Copyright:           Vincent Hanquez <vincent@snarc.org>@@ -10,14 +11,14 @@ Category:            Tools Stability:           experimental Build-Type:          Simple-Homepage:            https://github.com/vincenthz/hs-gitcache-Bug-Reports:         https://github.com/vincenthz/hs-gitcache/issues+Homepage:            https://github.com/vincenthz/gitcache+Bug-Reports:         https://github.com/vincenthz/gitcache/issues Cabal-Version:       >=1.10 extra-source-files:  README.md  source-repository head   type: git-  location: https://github.com/vincenthz/hs-gitcache+  location: https://github.com/vincenthz/gitcache  Executable           gitcache   Main-Is:           gitcache.hs
src/gitcache.hs view
@@ -42,23 +42,28 @@     withSetDirectory repoDir $         rawSystemEC "git" [ "fetch", "--all" ] +data CloneOpt = CloneLocally | CloneInCache+    deriving (Show,Eq)+ cloneRepo inDir destName url =     withSetDirectory inDir $         rawSystemEC "git" [ "clone", "--mirror", url, destName ] -cloneUrl gitCacheDir url pushUrl = do+cloneUrl gitCacheDir cloneOpt url pushUrl = do     let destName = urlToHash url         destDir  = gitCacheDir </> destName     clonedAlready <- doesDirectoryExist destDir     if clonedAlready         then updateRepo destDir         else cloneRepo gitCacheDir destName url-    -- and clone locally and replace the origin url-    rawSystemEC "git" [ "clone", destDir, urlToName url ]-    withSetDirectory (urlToName url) $ do-        rawSystemEC "git" [ "remote", "set-url", "origin", url ]-        maybe (return ()) (\purl -> rawSystemEC "git" [ "remote", "set-url", "origin", "--push", purl]) pushUrl +    when (cloneOpt == CloneLocally) $ do+        -- and clone locally and replace the origin url+        rawSystemEC "git" [ "clone", destDir, urlToName url ]+        withSetDirectory (urlToName url) $ do+            rawSystemEC "git" [ "remote", "set-url", "origin", url ]+            maybe (return ()) (\purl -> rawSystemEC "git" [ "remote", "set-url", "origin", "--push", purl]) pushUrl+ getRepoUrl gitCacheDir repoDir =     getOriginUrl . lines <$> readFile (gitCacheDir </> repoDir </> "config")   where@@ -87,16 +92,23 @@      getGitCacheDir = flip (</>) ".gitcache" <$> getEnv "HOME" +commandClone gitCacheDir cloneOpt args =+    case args of+        "github":user:repo:[] -> do+            cloneUrl gitCacheDir cloneOpt+                     ("https://github.com/" ++ user ++ "/" ++ repo)+                     (Just ("git@github.com:" ++ user ++ "/" ++ repo))+        url:[] -> do+            cloneUrl gitCacheDir cloneOpt url Nothing+        _ ->+            error "clone options not known"+ main = do     args <- getArgs     gitCacheDir <- initialization     case args of-        "clone":"github":user:repo:[] -> do-            cloneUrl gitCacheDir-                     ("https://github.com/" ++ user ++ "/" ++ repo)-                     (Just ("git@github.com:" ++ user ++ "/" ++ repo))-        "clone":url:[] ->-            cloneUrl gitCacheDir url Nothing+        "clone":cargs -> commandClone gitCacheDir CloneLocally cargs+        "cache":cargs -> commandClone gitCacheDir CloneInCache cargs         "list":[]    -> do             repos <- listCacheRepos gitCacheDir             mapM_ (showRepoUrl gitCacheDir) repos@@ -112,6 +124,8 @@             mapM_ putStrLn                 [ "  clone <url>"                 , "  clone github <user> <repo>"+                , "  cache <url>"+                , "  cache github <user> <repo>"                 , "  list"                 , "  update"                 ]