-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheckout-versions.ts
51 lines (44 loc) · 1.26 KB
/
checkout-versions.ts
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
import { ensureDir } from "@std/fs";
import * as ai from "@hongminhee/aitertools";
import { getVersionList } from "./lib/versions.ts";
let versions = await getVersionList();
await ensureDir("versions");
let dirs = await ai.toArray(
ai.map(
(e: Deno.DirEntry) => e.name,
ai.filter((e: Deno.DirEntry) => e.isDirectory, Deno.readDir("versions")),
),
);
console.info("found %d version dirs: %o", dirs.length, dirs);
let seen: Set<string> = new Set();
for (let v of versions) {
seen.add(v.label);
if (dirs.includes(v.label)) {
console.info("version %s already checked out", v.label);
continue;
}
let cmd = new Deno.Command("git", {
args: ["worktree", "add", `versions/${v.label}`, v.branch],
});
let proc = cmd.spawn();
let res = await proc.output();
if (res.code != 0) {
console.error("git worktree failed with status %d", res.code);
Deno.exit(3);
}
}
for (let dir of dirs) {
if (seen.has(dir)) {
continue;
}
console.info("removing unused tree %s", dir);
let cmd = new Deno.Command("git", {
args: ["worktree", "remove", `versions/${dir}`],
});
let proc = cmd.spawn();
let res = await proc.output();
if (res.code != 0) {
console.error("git worktree failed with status %d", res.code);
Deno.exit(3);
}
}