-
Notifications
You must be signed in to change notification settings - Fork 13
/
git.arc
68 lines (57 loc) · 1.86 KB
/
git.arc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
(use strings parsimonious-urlencode path ret cwd system-code)
(= ar-cachedir* (racket-path->string (racket-expand-user-path "~/.ar-cache")))
(= git-cachedir* (path ar-cachedir* "git"))
(def filenamize (hack)
(let hack string.hack
(parsimonious-urlencode
(subst "_" "/"
(subst "__" "_" hack)))))
(def parse-git-spec (spec)
(zap string spec)
(and (begins spec "git://")
(iflet p (pos [in _ #\: #\!] spec 6)
(with (repo (cut spec 0 p)
rest (cut spec p))
(if (begins rest "!")
(iflet p (pos #\: rest)
(obj repo repo
revision (cut rest 1 p)
file (cut rest (+ 1 p)))
(obj repo repo
revision (cut rest 1)))
(obj repo repo
file (cut rest 1))))
(obj repo spec))))
(def git-spec (spec)
(if (isa spec 'table)
spec
(or (parse-git-spec spec)
(err "unable to parse git spec" spec))))
(def git-revision (git)
(zap git-spec git)
(or git!revision "master"))
(def git-dir (git)
(path (filenamize (cut git!repo 6))
(filenamize (git-revision git))))
(def gitcmd args
(w/stdout stderr
(apply check-system "/usr/bin/git" args)))
(def git-repo (git)
(zap git-spec git)
(ret gitdir (path git-cachedir* (git-dir git))
(unless (dir-exists gitdir)
(let dir (dirpart gitdir)
(ensure-dir dir)
(w/cwd dir
(gitcmd "clone" "--no-checkout" git!repo (filepart gitdir)))
(w/cwd gitdir
(gitcmd "checkout" "-q" (git-revision git)))))))
(def git-filepath (git)
(zap git-spec git)
(path (git-repo git) git!file))
(def git-pull (git)
(w/cwd (git-repo git)
(gitcmd "pull")))
(def git-loc (git)
(zap git-spec git)
(string "git://" git!repo (aif git!revision (+ "!" it))))