@@ -15,7 +15,6 @@ import Distribution.Pretty (prettyShow)
1515import Distribution.Types.PackageId
1616import Distribution.Types.PackageName (unPackageName )
1717import Foliage.FetchURL (fetchURL )
18- import Foliage.GitClone (gitClone )
1918import Foliage.Meta
2019import Foliage.UpdateCabalFile (rewritePackageVersion )
2120import GHC.Generics
@@ -70,8 +69,8 @@ addPrepareSourceRule inputDir cacheDir = addBuiltinRule noLint noIdentity run
7069 tarballPath <- fetchURL uri
7170 extractFromTarball tarballPath mSubdir srcDir
7271 GitHubSource repo rev mSubdir -> do
73- workDir <- gitClone repo rev
74- let packageDir = maybe workDir (workDir </> ) mSubdir
72+ workingCopy <- gitCheckout cacheDir repo rev
73+ let packageDir = maybe workingCopy (workingCopy </> ) mSubdir
7574 copyDirectoryContents packageDir srcDir
7675
7776 let patchesDir = inputDir </> unPackageName pkgName </> prettyShow pkgVersion </> " patches"
@@ -120,6 +119,20 @@ addPrepareSourceRule inputDir cacheDir = addBuiltinRule noLint noIdentity run
120119
121120 copyDirectoryContents srcDir outDir
122121
122+ gitCheckout :: FilePath -> GitHubRepo -> GitHubRev -> Action FilePath
123+ gitCheckout cacheDir repo rev = do
124+ alreadyCloned <- doesDirectoryExist path
125+ if alreadyCloned
126+ then command_ [Cwd path] " git" [" fetch" ]
127+ else command_ [] " git" [" clone" , " --recursive" , url, path]
128+ command_ [Cwd path] " git" [" checkout" , show rev]
129+ command_ [Cwd path] " git" [" submodule" , " update" ]
130+ pure path
131+ where
132+ path = cacheDir </> " git" </> show repo
133+
134+ url = " https://github.com/" <> show repo <> " .git"
135+
123136copyDirectoryContents :: FilePath -> FilePath -> Action ()
124137copyDirectoryContents source destination =
125138 cmd_
0 commit comments