Skip to content

Commit 7c5b5eb

Browse files
committed
Make gitCheckout just an Action, no additional rule
This avoids some boiler plate and works just the same.
1 parent 8b39c30 commit 7c5b5eb

File tree

5 files changed

+20
-63
lines changed

5 files changed

+20
-63
lines changed

app/Foliage/CmdBuild.hs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import Distribution.Package
2323
import Distribution.Pretty (prettyShow)
2424
import Distribution.Version
2525
import Foliage.FetchURL (addFetchURLRule)
26-
import Foliage.GitClone (addGitCloneRule)
2726
import Foliage.HackageSecurity hiding (ToJSON, toJSON)
2827
import Foliage.Meta
2928
import Foliage.Meta.Aeson ()
@@ -43,7 +42,6 @@ cmdBuild buildOptions = do
4342
shake opts $
4443
do
4544
addFetchURLRule cacheDir
46-
addGitCloneRule cacheDir
4745
addPrepareSourceRule (buildOptsInputDir buildOptions) cacheDir
4846
addPrepareSdistRule outputDirRoot
4947
phony "buildAction" (buildAction buildOptions)

app/Foliage/GitClone.hs

Lines changed: 0 additions & 57 deletions
This file was deleted.

app/Foliage/PrepareSource.hs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import Distribution.Pretty (prettyShow)
1515
import Distribution.Types.PackageId
1616
import Distribution.Types.PackageName (unPackageName)
1717
import Foliage.FetchURL (fetchURL)
18-
import Foliage.GitClone (gitClone)
1918
import Foliage.Meta
2019
import Foliage.UpdateCabalFile (rewritePackageVersion)
2120
import 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+
123136
copyDirectoryContents :: FilePath -> FilePath -> Action ()
124137
copyDirectoryContents source destination =
125138
cmd_

foliage.cabal

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ executable foliage
2727
Foliage.CmdCreateKeys
2828
Foliage.CmdImportIndex
2929
Foliage.FetchURL
30-
Foliage.GitClone
3130
Foliage.HackageSecurity
3231
Foliage.Meta
3332
Foliage.Meta.Aeson

tests/Tests.hs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ main = do
4040
inTemporaryDirectoryWithFixture "tests/fixtures/git-submodule" $ do
4141
step "Building repository"
4242
callCommand "foliage build"
43+
44+
doesFileExist "_cache/git/cardano-scaling/foliage-test-with-submodule/README.md" @? "Missing working copy"
45+
doesFileExist "_cache/foliage-test-with-submodule/1.0.0/README.md" @? "Missing packaged version"
46+
doesFileExist "_cache/foliage-test-with-submodule/1.1.0/README.md" @? "Missing packaged version"
4347
, ---
4448
testCaseSteps "accepts --no-signatures" $ \step ->
4549
inTemporaryDirectoryWithFixture "tests/fixtures/simple" $ do

0 commit comments

Comments
 (0)