@@ -15,6 +15,7 @@ import Distribution.Pretty (prettyShow)
1515import Distribution.Types.PackageId
1616import Distribution.Types.PackageName (unPackageName )
1717import Foliage.FetchURL (fetchURL )
18+ import Foliage.GitClone (gitClone )
1819import Foliage.Meta
1920import Foliage.UpdateCabalFile (rewritePackageVersion )
2021import GHC.Generics
@@ -69,9 +70,8 @@ addPrepareSourceRule inputDir cacheDir = addBuiltinRule noLint noIdentity run
6970 tarballPath <- fetchURL uri
7071 extractFromTarball tarballPath mSubdir srcDir
7172 GitHubSource repo rev mSubdir -> do
72- workingCopy <- gitCheckout cacheDir repo rev
73- let packageDir = maybe workingCopy (workingCopy </> ) mSubdir
74- copyDirectoryContents packageDir srcDir
73+ repoDir <- gitClone repo
74+ copyGitWorktree repoDir rev mSubdir srcDir
7575
7676 let patchesDir = inputDir </> unPackageName pkgName </> prettyShow pkgVersion </> " patches"
7777 hasPatches <- doesDirectoryExist patchesDir
@@ -119,20 +119,16 @@ addPrepareSourceRule inputDir cacheDir = addBuiltinRule noLint noIdentity run
119119
120120 copyDirectoryContents srcDir outDir
121121
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"
122+ -- | Copy package source from a git repository using 'git worktree'.
123+ copyGitWorktree :: FilePath -> GitHubRev -> Maybe FilePath -> FilePath -> Action ()
124+ copyGitWorktree repoDir rev mSubdir outDir = do
125+ withTempDir $ \ tmpDir -> do
126+ command_ [Cwd repoDir] " git" [" worktree" , " add" , tmpDir, show rev]
127+ command_ [Cwd tmpDir] " git" [" submodule" , " update" , " --init" ]
128+ let packageDir = maybe tmpDir (tmpDir </> ) mSubdir
129+ copyDirectoryContents packageDir outDir
135130
131+ -- | Copy all contents from one directory to another.
136132copyDirectoryContents :: FilePath -> FilePath -> Action ()
137133copyDirectoryContents source destination =
138134 cmd_
0 commit comments