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 all commits
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
12 changes: 10 additions & 2 deletions src/Stack2nix.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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 ()
Expand Down
27 changes: 21 additions & 6 deletions src/Stack2nix/External/VCS/Git.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
1 change: 1 addition & 0 deletions src/Stack2nix/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ data Args = Args
, argUri :: String
, argIndent :: Bool
, 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 @@ -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
Expand Down