forked from nodegit/nodegit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathworker.js
More file actions
38 lines (34 loc) · 957 Bytes
/
worker.js
File metadata and controls
38 lines (34 loc) · 957 Bytes
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
const {
isMainThread,
parentPort,
workerData
} = require("worker_threads");
const assert = require("assert");
const NodeGit = require("../../");
if (isMainThread) {
throw new Error("Must be run via worker thread");
}
parentPort.postMessage("init");
const { clonePath, url } = workerData;
const opts = {
fetchOpts: {
callbacks: {
certificateCheck: () => 0
}
}
};
let repository;
return NodeGit.Clone(url, clonePath, opts).then((_repository) => {
repository = _repository;
assert.ok(repository instanceof NodeGit.Repository);
return repository.index();
}).then((index) => {
assert.ok(index instanceof NodeGit.Index);
return repository.getRemoteNames();
}).then((remotes) => {
assert.ok(Array.isArray(remotes));
return repository.getCurrentBranch();
}).then((branch) => {
assert.ok(branch instanceof NodeGit.Reference);
parentPort.postMessage("success");
}).catch(() => parentPort.postMessage("failure"));