diff --git a/src/Stack2nix.hs b/src/Stack2nix.hs index 655aa92..d24bc07 100644 --- a/src/Stack2nix.hs +++ b/src/Stack2nix.hs @@ -53,9 +53,17 @@ 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) + Just rev -> + let internalCmd = if argGitRecursive + then CheckoutRecursive rev + else Checkout rev + in + void . git $ InsideRepo tmpDir internalCmd Nothing -> return mempty handleStackConfig :: Maybe String -> FilePath -> IO () diff --git a/src/Stack2nix/External/VCS/Git.hs b/src/Stack2nix/External/VCS/Git.hs index 639bd79..8fff28e 100644 --- a/src/Stack2nix/External/VCS/Git.hs +++ b/src/Stack2nix/External/VCS/Git.hs @@ -6,11 +6,19 @@ 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 InternalCmd = Checkout CommitRef +data Command + = OutsideRepo ExternalCmd + | InsideRepo FilePath InternalCmd +data ExternalCmd + = Clone RepoUri FilePath + | CloneRecursive RepoUri FilePath + +data InternalCmd + = Checkout CommitRef + | CheckoutRecursive CommitRef + +type RepoUri = String type CommitRef = String exe :: String @@ -24,7 +32,14 @@ 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", "--recurse-submodules", uri, dir] >>= failHard runInternal :: FilePath -> InternalCmd -> IO (ExitCode, String, String) -runInternal repoDir (Checkout ref) = - runCmdFrom repoDir exe ["checkout", ref] >>= failHard +runInternal repoDir (Checkout ref) = + runCmdFrom repoDir exe ["checkout", ref] >>= failHard +runInternal repoDir (CheckoutRecursive ref) = do + checkoutCmd <- runCmdFrom repoDir exe ["checkout", ref] + _ <- failHard checkoutCmd + submoduleCmd <- runCmdFrom repoDir exe ["submodule", "update", "--init", "--recursive"] + failHard submoduleCmd diff --git a/src/Stack2nix/Types.hs b/src/Stack2nix/Types.hs index 6bbec87..7a32580 100644 --- a/src/Stack2nix/Types.hs +++ b/src/Stack2nix/Types.hs @@ -16,5 +16,6 @@ data Args = Args , argUri :: String , argIndent :: Bool , argVerbose :: Bool + , argGitRecursive :: Bool } deriving (Show) diff --git a/stack2nix/Main.hs b/stack2nix/Main.hs index 0b4b012..0a9dd0a 100644 --- a/stack2nix/Main.hs +++ b/stack2nix/Main.hs @@ -26,6 +26,7 @@ args = Args <*> strArgument (metavar "URI") <*> flag True False (long "no-indent" <> help "disable indentation and place one item per line") <*> 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