Skip to content

Add flag to clone a git repository recursive #95

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/Stack2nix.hs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ stack2nix args@Args{..} = do

tryGit :: FilePath -> IO ()
tryGit tmpDir = do
void $ git $ OutsideRepo $ Clone argUri tmpDir
let externalCmd = if argGitRecursive
then CloneRecursive argUri tmpDir
else Clone argUri tmpDir
void $ git $ OutsideRepo externalCmd
case argRev of
Just r -> void $ git $ InsideRepo tmpDir (Checkout r)
Nothing -> return mempty
Expand Down
14 changes: 11 additions & 3 deletions src/Stack2nix/External/VCS/Git.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,17 @@ module Stack2nix.External.VCS.Git
import Stack2nix.External.Util (failHard, runCmd, runCmdFrom)
import System.Exit (ExitCode (..))

data Command = OutsideRepo ExternalCmd
| InsideRepo FilePath InternalCmd
data ExternalCmd = Clone String FilePath
data Command
= OutsideRepo ExternalCmd
| InsideRepo FilePath InternalCmd

data ExternalCmd
= Clone RepoUri FilePath
| CloneRecursive RepoUri FilePath

data InternalCmd = Checkout CommitRef

type RepoUri = String
type CommitRef = String

exe :: String
Expand All @@ -24,6 +30,8 @@ git (InsideRepo dir cmd) = runInternal dir cmd
runExternal :: ExternalCmd -> IO (ExitCode, String, String)
runExternal (Clone uri dir) =
runCmd exe ["clone", uri, dir] >>= failHard
runExternal (CloneRecursive uri dir) =
runCmd exe ["clone", uri, "--recursive", dir] >>= failHard

runInternal :: FilePath -> InternalCmd -> IO (ExitCode, String, String)
runInternal repoDir (Checkout ref) =
Expand Down
1 change: 1 addition & 0 deletions src/Stack2nix/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ data Args = Args
, argPlatform :: Platform
, argUri :: String
, argVerbose :: Bool
, argGitRecursive :: Bool
}
deriving (Show)
1 change: 1 addition & 0 deletions stack2nix/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ args = Args
<*> option (readP platformReader) (long "platform" <> help "target platform to use when invoking stack or cabal2nix" <> value buildPlatform <> showDefaultWith display)
<*> strArgument (metavar "URI")
<*> switch (long "verbose" <> help "verbose output")
<*> switch (long "git-recursive" <> help "clone external git reposity w/ all submodules")
where
-- | A parser for the date. Hackage updates happen maybe once or twice a month.
-- Example: parseTime defaultTimeLocale "%FT%T%QZ" "2017-11-20T12:18:35Z" :: Maybe UTCTime
Expand Down