Skip to content

Commit

Permalink
First stab at allowing branch, tag or SHA
Browse files Browse the repository at this point in the history
This could be a half-measure for purescript#33. This does not prevent usage of
master, but it arguably does behave how you'd expect: it always keeps
whatever reference you're using as a package set up to date, and
happens to also allow you to use a SHA in addition to a revision. I'm
going to give this a spin, but if we later wanted to disallow
branches, we could probably cobble together a git command that would
tell us if a tree-ish or whatever they call it is a branch or not.
  • Loading branch information
MichaelXavier committed Jun 13, 2017
1 parent f59ea9a commit e761abb
Showing 1 changed file with 28 additions and 16 deletions.
44 changes: 28 additions & 16 deletions app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -114,20 +114,34 @@ cloneShallow
:: Text
-- ^ repo
-> Text
-- ^ branch/tag
-- ^ branch/tag/SHA
-> Turtle.FilePath
-- ^ target directory
-> IO ExitCode
cloneShallow from ref into =
proc "git"
[ "clone"
, "-q"
, "-c", "advice.detachedHead=false"
, "--depth", "1"
, "-b", ref
, from
, pathToTextUnsafe into
] empty .||. exit (ExitFailure 1)
-> IO ()
cloneShallow from ref into = do
gitExists <- testdir (into </> ".git")
unless gitExists $ void $ do
proc "git"
[ "clone"
, "-q"
, "-c", "advice.detachedHead=false"
, "--depth", "1"
, from
, pathToTextUnsafe into
] empty .||. exit (ExitFailure 1)
inGitRepo $ proc "git"
[ "fetch"
, "-q"
, "--tags"
] empty .||. exit (ExitFailure 1)
inGitRepo $ proc "git"
[ "reset"
, "-q"
, "--hard"
, ref
] empty .||. exit (ExitFailure 1)
where
inGitRepo m = (view (pushd into >> m))

listRemoteTags
:: Text
Expand All @@ -144,8 +158,7 @@ listRemoteTags from = let gitProc = inproc "git"
getPackageSet :: PackageConfig -> IO ()
getPackageSet PackageConfig{ source, set } = do
let pkgDir = ".psc-package" </> fromText set </> ".set"
exists <- testdir pkgDir
unless exists . void $ cloneShallow source set pkgDir
void $ cloneShallow source set pkgDir

readPackageSet :: PackageConfig -> IO PackageSet
readPackageSet PackageConfig{ set } = do
Expand All @@ -170,8 +183,7 @@ installOrUpdate :: Text -> PackageName -> PackageInfo -> IO Turtle.FilePath
installOrUpdate set pkgName PackageInfo{ repo, version } = do
echoT ("Updating " <> runPackageName pkgName)
let pkgDir = ".psc-package" </> fromText set </> fromText (runPackageName pkgName) </> fromText version
exists <- testdir pkgDir
unless exists . void $ cloneShallow repo version pkgDir
void $ cloneShallow repo version pkgDir
pure pkgDir

getTransitiveDeps :: PackageSet -> [PackageName] -> IO [(PackageName, PackageInfo)]
Expand Down

0 comments on commit e761abb

Please sign in to comment.