3 | import public Pack.Core.Git.Consts
5 | import Pack.Core.Types
11 | gitTmpDir : TmpDir => (pkg : PkgName) -> Path Abs
12 | gitTmpDir pkg = tmpDir <//> pkg
16 | gitCacheDir : (pd : PackDirs) => (url : URL) -> Path Abs
17 | gitCacheDir url = pd.cache <//> "git" <//> url
19 | parameters {auto has : HasIO io}
22 | cloneRemote : (url : URL) -> (dest : Path Abs) -> EitherT PackErr io ()
23 | cloneRemote url dest = sys ["git", "clone", "--depth", "1", "-q", url, dest]
28 | -> {auto _ : TmpDir}
31 | -> EitherT PackErr io ()
32 | cloneShared url pkg =
33 | let cache := gitCacheDir url
34 | tmp := gitTmpDir pkg
35 | in sys ["git", "clone", "--shared", "-q", cache, tmp]
38 | fetch : (commit : Commit) -> EitherT PackErr io ()
39 | fetch commit = sys ["git", "fetch", "-q", "origin", commit]
43 | checkout : (commit : Commit) -> EitherT PackErr io ()
44 | checkout commit = sys ["git", "checkout", "-q", commit]
48 | gitLatest : (url : URL) -> (branch : Branch) -> EitherT PackErr io Commit
50 | MkCommit . fst . break isSpace <$> sysRun ["git", "ls-remote", url, b]
57 | -> {auto _ : PackDirs}
60 | -> (commit : Commit)
61 | -> (forceFetch : Bool)
62 | -> (act : Path Abs -> EitherT PackErr io a)
63 | -> EitherT PackErr io a
64 | withGit pkg url commit forceFetch act =
65 | let cache := gitCacheDir url
66 | tmp := gitTmpDir pkg
70 | | True => case forceFetch of
71 | False => inDir tmp act
72 | True => inDir tmp (\d => fetch commit >> checkout commit >> act d)
75 | when !(missing cache) $
do
77 | cloneRemote url cache
80 | inDir cache $
\_ => fetch commit
85 | inDir tmp (\d => fetch commit >> checkout commit >> act d)