Skip to content

Commit

Permalink
Add tests for supporting git submodules and fix issues
Browse files Browse the repository at this point in the history
The `RepoRecipe` type now takes a type level argument which tells the arbitrary
instance whether to allow submodules in the recipe or not.
  • Loading branch information
akshaymankar committed Sep 13, 2021
1 parent a666f2e commit 30f716e
Show file tree
Hide file tree
Showing 2 changed files with 198 additions and 77 deletions.
20 changes: 15 additions & 5 deletions cabal-install/src/Distribution/Client/VCS.hs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ import qualified Data.Char as Char
import qualified Data.List as List
import qualified Data.Map as Map
import System.FilePath
( takeDirectory )
( takeDirectory, (</>) )
import System.Directory
( doesDirectoryExist
, removeDirectoryRecursive
Expand Down Expand Up @@ -386,11 +386,12 @@ vcsGit =
vcsCloneRepo verbosity prog repo srcuri destdir =
[ programInvocation prog cloneArgs ]
-- And if there's a tag, we have to do that in a second step:
++ [ (programInvocation prog (resetArgs tag)) {
progInvokeCwd = Just destdir
}
| tag <- maybeToList (srpTag repo) ]
++ [ git (resetArgs tag) | tag <- maybeToList (srpTag repo) ]
++ [ git (["submodule", "sync", "--recursive"] ++ verboseArg)
, git (["submodule", "update", "--init", "--force", "--recursive"] ++ verboseArg)
]
where
git args = (programInvocation prog args) {progInvokeCwd = Just destdir}
cloneArgs = ["clone", srcuri, destdir]
++ branchArgs ++ verboseArg
branchArgs = case srpBranch repo of
Expand Down Expand Up @@ -419,6 +420,15 @@ vcsGit =
if exists
then git localDir ["fetch"]
else git (takeDirectory localDir) cloneArgs
-- Before trying to checkout other commits, all submodules must be
-- de-initialised and the .git/modules directory must be deleted. This
-- is needed because sometimes `git submodule sync` does not actually
-- update the submodule source URL. Detailed description here:
-- https://git.coop/-/snippets/85
git localDir ["submodule", "deinit", "--force", "--all"]
let gitModulesDir = localDir </> ".git" </> "modules"
gitModulesExists <- doesDirectoryExist gitModulesDir
when gitModulesExists $ removeDirectoryRecursive gitModulesDir
git localDir resetArgs
git localDir ["submodule", "sync", "--recursive"]
git localDir ["submodule", "update", "--force", "--init", "--recursive"]
Expand Down
Loading

0 comments on commit 30f716e

Please sign in to comment.