Skip to content

Commit f1f6071

Browse files
committed
Allow to fetch a specific git ref
1 parent e16ad1c commit f1f6071

File tree

3 files changed

+19
-13
lines changed

3 files changed

+19
-13
lines changed

src/MicroCabal/Env.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ data Env = Env {
2222
backend :: Backend, -- which compiler to use, default is MHS
2323
targets :: [Target], -- only build/install these
2424
gitRepo :: Maybe String, -- use git repo for package
25+
gitRef :: Maybe String, -- use git ref when cloning 'gitRepo'
2526
subDir :: Maybe String -- subdirectory of git repo
2627
}
2728

src/MicroCabal/Main.hs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ setupEnv = do
4646
let cdir = fromMaybe (home </> ".mcabal") cdirm
4747
env = Env{ cabalDir = cdir, distDir = "dist-mcabal", verbose = 0, depth = 0, eflags = [],
4848
backend = error "backend undefined", recursive = False, targets = [TgtLib, TgtFor, TgtExe],
49-
gitRepo = Nothing, dryRun = False, useNightly = True, subDir = Nothing }
49+
gitRepo = Nothing, gitRef = Nothing, dryRun = False, useNightly = True, subDir = Nothing }
5050
be <- mhsBackend env
5151
return env{ backend = be }
5252

@@ -228,7 +228,7 @@ cmdFetch env [pkg] = do
228228
-- Doing a git fetch.
229229
-- With --git we will always fetch, blowing away the old repo.
230230
message env 1 $ "Fetching from git repo " ++ repo
231-
gitClone env pdir (URL repo)
231+
gitClone env pdir (URL repo) (GitRef <$> gitRef env)
232232
cmdFetch _ _ = usage
233233

234234
-----------------------------------------
@@ -385,6 +385,7 @@ addMissing sects = sects
385385

386386
decodeGit :: (Env -> [String] -> IO ()) -> Env -> [String] -> IO ()
387387
decodeGit io env (arg:args) | repo@(Just _) <- stripPrefix "--git=" arg = decodeGit io (env{ gitRepo = repo }) args
388+
decodeGit io env (arg:args) | ref@(Just _) <- stripPrefix "--git-ref=" arg = decodeGit io (env{ gitRef = ref }) args
388389
decodeGit io env (arg:args) | dir@(Just _) <- stripPrefix "--dir=" arg = decodeGit io (env{ subDir = dir }) args
389390
decodeGit io env args = io env args
390391

@@ -473,14 +474,14 @@ installCFiles env glob (Section _ _ flds) = do
473474
cmdHelp :: Env -> [String] -> IO ()
474475
cmdHelp _ _ = putStrLn "\
475476
\Available commands:\n\
476-
\ mcabal [FLAGS] build [--git=URL [--dir=DIR]] [PKG] build in current directory, or the package PKG\n\
477-
\ mcabal [FLAGS] test build and run tests in current directory\n\
478-
\ mcabal [FLAGS] clean clean in the current directory\n\
479-
\ mcabal [FLAGS] fetch [--git=URL [--dir=DIR]] PKG fetch files for package PKG\n\
480-
\ mcabal [FLAGS] help show this message\n\
481-
\ mcabal [FLAGS] install [--git=URL [--dir=DIR]] [PKG] build and install in current directory, or the package PKG\n\
482-
\ mcabal [FLAGS] parse FILE just parse a Cabal file (for debugging)\n\
483-
\ mcabal [FLAGS] update retrieve new set of consistent packages from Stackage\n\
477+
\ mcabal [FLAGS] build [--git=URL [--gitRef=REF] [--dir=DIR]] [PKG] build in current directory, or the package PKG\n\
478+
\ mcabal [FLAGS] test build and run tests in current directory\n\
479+
\ mcabal [FLAGS] clean clean in the current directory\n\
480+
\ mcabal [FLAGS] fetch [--git=URL [--dir=DIR]] PKG fetch files for package PKG\n\
481+
\ mcabal [FLAGS] help show this message\n\
482+
\ mcabal [FLAGS] install [--git=URL [--dir=DIR]] [PKG] build and install in current directory, or the package PKG\n\
483+
\ mcabal [FLAGS] parse FILE just parse a Cabal file (for debugging)\n\
484+
\ mcabal [FLAGS] update retrieve new set of consistent packages from Stackage\n\
484485
\\n\
485486
\Flags:\n\
486487
\ --version show version\n\

src/MicroCabal/Unix.hs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module MicroCabal.Unix(
22
cmd, tryCmd, cmdOut, tryCmdOut,
33
mkdir,
4-
wget, URL(..),
4+
wget, URL(..), GitRef(..),
55
gitClone,
66
tarx,
77
rmrf,
@@ -21,6 +21,8 @@ import MicroCabal.Env
2121

2222
newtype URL = URL String
2323

24+
newtype GitRef = GitRef String
25+
2426
cmd :: Env -> String -> IO ()
2527
cmd env s = do
2628
message env 2 $ "cmd: " ++ s
@@ -111,8 +113,10 @@ preserveCurrentDirectory io = do
111113
setCurrentDirectory cwd
112114
return a
113115

114-
gitClone :: Env -> FilePath -> URL -> IO ()
115-
gitClone env dir (URL repo) =
116+
gitClone :: Env -> FilePath -> URL -> Maybe GitRef -> IO ()
117+
gitClone env dir (URL repo) (Just (GitRef ref)) =
118+
cmd env $ "git clone --depth 1 --branch " ++ ref ++ " --quiet " ++ repo ++ " " ++ dir
119+
gitClone env dir (URL repo) Nothing =
116120
cmd env $ "git clone --depth 1 --quiet " ++ repo ++ " " ++ dir
117121

118122
-----

0 commit comments

Comments
 (0)