-
Notifications
You must be signed in to change notification settings - Fork 696
Expand file tree
/
Copy pathworker_checkout.js
More file actions
51 lines (46 loc) · 1.17 KB
/
worker_checkout.js
File metadata and controls
51 lines (46 loc) · 1.17 KB
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
const {
isMainThread,
parentPort,
workerData
} = require("worker_threads");
const assert = require("assert");
const NodeGit = require("../../");
const loopingCheckoutHead = require("./loop_checkout.js");
if (isMainThread) {
throw new Error("Must be run via worker thread");
}
parentPort.postMessage("init");
const { clonePath, url } = workerData;
const cloneOpts = {
fetchOpts: {
callbacks: {
certificateCheck: () => 0
}
}
};
let repository;
let filterName = "psuedo_filter";
let applyCallbackResult = 1;
return NodeGit.Clone(url, clonePath, cloneOpts)
.then(function(_repository) {
repository = _repository;
assert.ok(repository instanceof NodeGit.Repository);
return NodeGit.FilterRegistry.register(filterName, {
apply: function() {
applyCallbackResult = 0;
},
check: function() {
return NodeGit.Error.CODE.OK;
}
}, 0);
})
.then(function(result) {
assert.strictEqual(result, NodeGit.Error.CODE.OK);
return loopingCheckoutHead(clonePath, repository, 0);
}).then(function() {
assert.strictEqual(applyCallbackResult, 0);
parentPort.postMessage("success");
})
.catch((err) => {
parentPort.postMessage("failure");
});