Add some more tests and fix some issues.

This commit is contained in:
Andre Cruz
2013-04-24 19:00:50 +01:00
parent dc67e8bbde
commit 3f7bd98174
7 changed files with 139 additions and 53 deletions

View File

@@ -19,19 +19,7 @@ mout.object.mixIn(GitFsResolver, GitResolver);
// -----------------
GitFsResolver.prototype._resolveSelf = function () {
return this._findResolution()
.then(this._readJson.bind(this, this._source))
.then(this._copy.bind(this))
.then(this._checkout.bind(this))
.then(this._cleanup.bind(this));
};
// -----------------
GitFsResolver.prototype._copy = function (meta) {
var ignore = meta.ignore;
GitFsResolver.prototype._copy = function () {
// Copy folder permissions
return Q.nfcall(fs.stat, this._source)
.then(function (stat) {
@@ -39,10 +27,7 @@ GitFsResolver.prototype._copy = function (meta) {
}.bind(this))
// Copy folder contents
.then(function () {
return Q.nfcall(ncp, this._source, this._tempDir, {
// Don't copy ignored files
filter: ignore && ignore.length ? this._createIgnoreFilter(ignore) : null
});
return Q.nfcall(ncp, this._source, this._tempDir);
}.bind(this));
};
@@ -50,8 +35,12 @@ GitFsResolver.prototype._copy = function (meta) {
GitFsResolver.prototype._checkout = function () {
var resolution = this._resolution;
// Checkout resolution
return cmd('git', ['checkout', '-f', resolution.tag || resolution.branch || resolution.commit], { cwd: this._tempDir })
// The checkout process could be similar to the GitRemoteResolver by prepending file:// to the source
// But from my performance measures, it's faster to copy the folder and just checkout in there
// Copy files to the temporary directory first
return this._copy()
.then(cmd.bind(cmd, 'git', ['checkout', '-f', resolution.tag || resolution.branch || resolution.commit], { cwd: this._tempDir }))
// Cleanup unstagged files
.then(cmd.bind(cmd, 'git', ['clean', '-f', '-d'], { cwd: this._tempDir }));
};
@@ -67,7 +56,10 @@ GitFsResolver.fetchRefs = function (source) {
return cmd('git', ['show-ref', '--tags', '--heads'], { cwd : source })
.then(function (stdout) {
// Make them an array
var refs = stdout.toString().trim().split('\n');
var refs = stdout.toString()
.trim() // Trim trailing and leading spaces
.replace(/[\t ]+/g, ' ') // Standardize spaces (some git versions make tabs, other spaces)
.split(/\r?\n/); // Split lines into an array
this._refs = this._refs || {};
return this._refs[source] = refs;

View File

@@ -40,7 +40,10 @@ GitRemoteResolver.fetchRefs = function (source) {
return cmd('git', ['ls-remote', '--tags', '--heads', source])
.then(function (stdout) {
// Make them an array
var refs = stdout.toString().trim().split('\n');
var refs = stdout.toString()
.trim() // Trim trailing and leading spaces
.replace(/[\t ]+/g, ' ') // Standardize spaces (some git versions make tabs, other spaces)
.split(/\r?\n/); // Split lines into an array
this._refs = this._refs || {};
return this._refs[source] = refs;

View File

@@ -23,8 +23,13 @@ util.inherits(GitResolver, Resolver);
GitResolver.prototype._resolveSelf = function () {
return this._findResolution()
.then(this._checkout.bind(this))
.then(this._cleanup.bind(this));
.then(function () {
return this._checkout()
// Always run cleanup after checkout to ensure that .git is removed!
// If it's not removed, problems might arrise when the "tmp" module attemps
// to delete the temporary folder
.fin(this._cleanup.bind(this));
}.bind(this));
};
GitResolver.prototype.hasNew = function (canonicalPkg) {