-
-
Notifications
You must be signed in to change notification settings - Fork 37
/
git.cue
67 lines (54 loc) · 1.01 KB
/
git.cue
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
package hof
import (
"path"
"strings"
)
RepoRoot: {
@task(os.Exec)
cmd: ["bash", "-c", "git rev-parse --show-toplevel"]
stdout: string
out: strings.TrimSpace(stdout)
}
GitDiff: {
@task(os.Exec)
ref: string | *""
cmd: ["bash", "-c", "git diff \(ref) --name-only"]
stdout: string
out: strings.TrimSpace(stdout)
files: strings.Split(out, "\n")
}
ShouldI: {
globs: [...string]
files: [...string]
match: [
for _, f in files
for _, g in globs
if path.Match(g, f, "unix") || strings.HasPrefix(f,g)
{ "\(f) -> \(g)" }
]
yes: bool | *false
if len(match) > 0 {
yes: true
}
}
shouldi_test: F={
@flow(shouldi.test)
globs: [...string] | *["*cue"]
_g: string @tag(globs)
if _g != _|_ {
globs: strings.Split(_g, ",")
}
diff: GitDiff
_shouldi: ShouldI & { files: diff.files }
print: {
@task(os.Stdout)
shouldi: _shouldi & { globs: F.globs }
if shouldi.yes {
text: "yes\n"
}
if !shouldi.yes {
text: "no\n"
}
@print()
}
}