forked from taisukef/deno-git-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGitProxy.js
64 lines (59 loc) · 1.39 KB
/
GitProxy.js
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
export default class GitProxy {
static async service(service, advertise, gitpath, data) {
const cmd = ['git'];
if (service) {
cmd.push(service.substring(4));
}
cmd.push("--stateless-rpc");
if (advertise) {
cmd.push("--advertise-refs");
}
cmd.push(gitpath);
const p = Deno.run({
cmd,
stdin: "piped",
stdout: "piped",
stderr: "piped",
});
if (data) {
//await p.stdin.writeAll(data);
await Deno.writeAll(p.stdin, data);
await p.stdin.close();
}
const output = await p.output();
const error = await p.stderrOutput();
const errorStr = new TextDecoder().decode(error);
p.close();
//console.log("stdout", new TextDecoder().decode(output));
if (errorStr) {
console.log("stderr", errorStr)
}
return output;
}
static async init(gitpath, bare = true) {
const basedir = gitpath.substring(0, gitpath.lastIndexOf("/"));
try {
Deno.mkdirSync(basedir);
} catch (e) {
}
const cmd = ["git"];
cmd.push("init");
if (bare) {
cmd.push("--bare");
}
cmd.push(gitpath + ".git");
const p = Deno.run({
cmd,
stdout: "piped",
stderr: "piped",
});
const output = await p.output();
const outStr = new TextDecoder().decode(output);
const error = await p.stderrOutput();
const errorStr = new TextDecoder().decode(error);
p.close();
//console.log("stdout", outStr);
//console.log("stderr", errorStr);
}
}
export { GitProxy };