Switch from git-node to nodegit (temporary)

dependabot/npm_and_yarn/BuildServer/eslint-7.2.0
Inga 🏳‍🌈 10 years ago
parent ff0f0e7a31
commit 9e2fa91600
  1. 79
      BuildServer/lib/git-loader.js
  2. 2
      BuildServer/package.json

@ -1,6 +1,6 @@
"use strict"; "use strict";
var git = require('git-node'), var nodegit = require('nodegit'),
async = require('async'), async = require('async'),
fs = require('fs'), fs = require('fs'),
fse = require('fs-extra'), fse = require('fs-extra'),
@ -26,70 +26,71 @@ options = {
module.exports = function (options, globalCallback) { module.exports = function (options, globalCallback) {
var url = options.remote, var url = options.remote,
remote = git.remote(url),
path = options.local + "/" + options.hash, path = options.local + "/" + options.hash,
repo = git.repo(path),
exported = options.exported, exported = options.exported,
opts = {
want: options.branch/*,
onProgress: function (progress) {
process.stderr.write(progress);
}*/
},
done = function () { done = function () {
globalCallback(); globalCallback();
}; };
removedirs(path);
mkdirs(path); mkdirs(path);
//console.log("Cloning %s to %s", url, path); if (url.substr(0, 8) == "https://") {
url = "git://" + url.substr(8);
}
repo.fetch(remote, opts, function (err) { console.log("Cloning %s to %s", url, path);
nodegit.Repo.clone(url, path, null /*new nodegit.CloneOptions({"checkout_branch": options.branch})*/, function (err, repo) {
if (err) { if (err) {
return globalCallback(err); return globalCallback(err);
} }
//console.log("Done fetching");
removedirs(exported);
mkdirs(exported);
var q = async.queue(function (task, callback) { var q = async.queue(function (task, callback) {
//console.log("Going to write file " + task.path + " (" + task.buffer.length + " bytes)"); //console.log("Going to write file " + task.path + " (" + task.buffer.length + " bytes)");
fs.writeFile(exported + "/" + task.path, task.buffer, function (err, result) { task.entry.getBlob(function (err, blob) {
//console.log("Done writing file " + task.path); if (err) {
callback(err, result); return callback(err);
}
fs.writeFile(exported + "/" + task.path, blob.content(), function (err, result) {
//console.log("Done writing file " + task.path);
callback(err, result);
});
}); });
}, 10); }, 10);
repo.treeWalk(options.hash, function (err, tree) { repo.getCommit(options.hash, function (err, commit) {
if (err) { if (err) {
return globalCallback(err); return globalCallback(err);
} }
var onEntry = function (err, entry) { removedirs(exported);
mkdirs(exported);
commit.getTree(function (err, tree) {
if (err) { if (err) {
return globalCallback(err); return globalCallback(err);
} }
if (!entry) { tree.walk(false)
if (q.length() === 0) { .on('entry', function (entry) {
process.nextTick(done); if (entry.isTree()) {
} else { mkdirs(exported + "/" + entry.path());
q.drain = done; } else if (entry.isFile()) {
} q.push({path: entry.path(), entry: entry });
return; }
} })
//console.log(" %s %s (%s)", entry.hash, entry.path, entry.type); .on('end', function () {
if (entry.type === "tree") { if (q.length() === 0) {
mkdirs(exported + "/" + entry.path); process.nextTick(done);
} else if (entry.type === "blob") { } else {
q.push({path: entry.path, buffer: entry.body }); q.drain = done;
} }
return tree.read(onEntry); return;
}; })
.start();
tree.read(onEntry); });
}); });
}); });
}; };

@ -10,7 +10,7 @@
"jade": "*", "jade": "*",
"async": "~0.2.9", "async": "~0.2.9",
"fs-extra": "~0.8.1", "fs-extra": "~0.8.1",
"git-node": "~0.1.1", "nodegit": "~0.1.4",
"github": "~0.2.0", "github": "~0.2.0",
"glob": "~3.2.7", "glob": "~3.2.7",
"nodemailer": "~0.6.0", "nodemailer": "~0.6.0",

Loading…
Cancel
Save