diff --git a/lib/resolve/Resolver.js b/lib/resolve/Resolver.js index e25dc17a..7a30da61 100644 --- a/lib/resolve/Resolver.js +++ b/lib/resolve/Resolver.js @@ -151,7 +151,7 @@ Resolver.prototype._applyPkgMeta = function (meta) { var filter = this._createIgnoreFilter(meta.ignore), promises = []; - // Foreach file that passes the ignore filter, + // For each file that passes the ignore filter, // rimraf it files.forEach(function (file) { if (filter(file)) { diff --git a/lib/resolve/Worker.js b/lib/resolve/Worker.js index a841837c..1115f8dd 100644 --- a/lib/resolve/Worker.js +++ b/lib/resolve/Worker.js @@ -78,7 +78,7 @@ Worker.prototype._processEntry = function (entry) { // If there is a free slot for every tag if (allFree) { - // Foreach type + // For each type entry.types.forEach(function (type) { // Remove entry from the queue mout.array.remove(this._queue[type], entry); @@ -104,7 +104,7 @@ Worker.prototype._processEntry = function (entry) { Worker.prototype._onResolve = function (entry, ok, result) { - // Resolve/reject the deferred based on sucess/error of the promise + // Resolve/reject the deferred based on success/error of the promise if (ok) { entry.deferred.resolve(result); } else { diff --git a/lib/resolve/resolvers/GitFsResolver.js b/lib/resolve/resolvers/GitFsResolver.js index 39bbceb1..5cd60dee 100644 --- a/lib/resolve/resolvers/GitFsResolver.js +++ b/lib/resolve/resolvers/GitFsResolver.js @@ -9,8 +9,6 @@ var path = require('path'); var GitFsResolver = function (source, options) { // Ensure absolute path - // TODO: should sources that arrive here be already absolute - // or is ok to do this here? source = path.resolve(source); GitResolver.call(this, source, options); @@ -52,8 +50,6 @@ GitFsResolver.prototype._copy = function (meta) { GitFsResolver.prototype._checkout = function () { var resolution = this._resolution; - console.log(resolution); - // Checkout resolution return cmd('git', ['checkout', '-f', resolution.tag || resolution.branch || resolution.commit], { cwd: this._tempDir }) // Cleanup unstagged files diff --git a/lib/resolve/resolvers/GitRemoteResolver.js b/lib/resolve/resolvers/GitRemoteResolver.js index d8dffd8a..d5d896ce 100644 --- a/lib/resolve/resolvers/GitRemoteResolver.js +++ b/lib/resolve/resolvers/GitRemoteResolver.js @@ -17,10 +17,8 @@ GitRemoteResolver.prototype._checkout = function () { var branch, resolution = this._resolution; - console.log(resolution); - - // If resolution is a commit, we need to clone the entire repo and checkit out - // Because a commit is not a nammed ref, there's no better solution + // If resolution is a commit, we need to clone the entire repo and check it out + // Because a commit is not a named ref, there's no better solution if (resolution.type === 'commit') { return cmd('git', ['clone', this._source, this._tempDir]) .then(cmd.bind(cmd, 'git', ['checkout', resolution.commit], { cwd: this._tempDir })); diff --git a/lib/resolve/resolvers/GitResolver.js b/lib/resolve/resolvers/GitResolver.js index be5ee65b..99e1def0 100644 --- a/lib/resolve/resolvers/GitResolver.js +++ b/lib/resolve/resolvers/GitResolver.js @@ -166,7 +166,7 @@ GitResolver.fetchVersions = function (source) { .then(function (refs) { var versions = []; - // Foreach line in the refs, match only the tags + // For each line in the refs, match only the tags refs.forEach(function (line) { var match = line.match(/^([a-f0-9]{40})\s+refs\/tags\/(\S+)/), tag, @@ -202,7 +202,7 @@ GitResolver.fetchHeads = function (source) { this._heads = this._heads || {}; var heads = this._heads[source] = this._heads[source] || {}; - // Foreach line in the refs, extract only the heads + // For each line in the refs, extract only the heads // Organize them in an object where keys are branches and values // the commit hashes refs.forEach(function (line) { diff --git a/test/assets/downloader.js b/test/assets/downloader.js index 43bf8cad..60c64888 100644 --- a/test/assets/downloader.js +++ b/test/assets/downloader.js @@ -4,19 +4,50 @@ var cmd = require('../../lib/util/cmd'); var githubTestPackage = path.join(__dirname, 'github-test-package'); +function fetchBranch(branch, dir) { + return cmd('git', ['checkout', '-b', branch, 'origin/' + branch], { cwd: dir }) + .then(null, function (err) { + if (/already exists/i.test(err.details)) { + return cmd('git', ['checkout', branch], { cwd: dir }) + .then(function () { + return cmd('git', ['pull', 'origin', branch], { cwd: dir }); + }); + } + }); +} + +function updateBranches() { + console.log('Updating "test-package" branches..'); + + return fetchBranch('master', githubTestPackage) + .then(function () { + return fetchBranch('some-branch', githubTestPackage); + }) + .then(function () { + console.log('Successfully updated "test-package" branches\n'); + }); +} + if (!fs.existsSync(githubTestPackage)) { - console.log('Cloning "test-package"'); + console.log('Cloning "test-package"..'); cmd('git', ['clone', 'git://github.com/bower/test-package.git', githubTestPackage]) .then(function () { console.log('Successfully downloaded "test-package"'); + return updateBranches(); + }) + .then(function () { + return updateBranches(); }) .done(); } else { - console.log('Updating "test-package"'); + console.log('Fetching "test-package"..'); cmd('git', ['fetch', '--prune'], { cwd: githubTestPackage }) .then(function () { - console.log('Successfully updated "test-package"'); - }); -} \ No newline at end of file + console.log('Successfully fetched "test-package"'); + return updateBranches(); + }) + .done(); +} + diff --git a/test/resolve/resolvers/gitFsResolver.js b/test/resolve/resolvers/gitFsResolver.js index a6d37843..0b2ba152 100644 --- a/test/resolve/resolvers/gitFsResolver.js +++ b/test/resolve/resolvers/gitFsResolver.js @@ -13,6 +13,23 @@ describe('GitFsResolver', function () { delete GitFsResolver._refs; } + describe('.constructor', function () { + it('should guess the name from the path', function () { + var resolver = new GitFsResolver(testPackage); + + expect(resolver.getName()).to.equal('github-test-package'); + }); + + it('should make paths absolute and normalized', function () { + var resolver = new GitFsResolver(path.relative(process.cwd(), testPackage)); + + expect(resolver.getSource()).to.equal(testPackage); + + resolver = new GitFsResolver(testPackage + '/something/..'); + expect(resolver.getSource()).to.equal(testPackage); + }); + }); + describe('.resolve', function () { it('should checkout correctly if resolution is a branch', function (next) { var resolver = new GitFsResolver(testPackage, { target: 'some-branch' }); diff --git a/test/test.js b/test/test.js index 0eea77e1..63928b22 100644 --- a/test/test.js +++ b/test/test.js @@ -1,7 +1,5 @@ -var path = require('path'); var GitRemoteResolver = require('../lib/resolve/resolvers/GitRemoteResolver'); var GitFsResolver = require('../lib/resolve/resolvers/GitFsResolver'); -var fetchBranch = require('./util/fetchBranch'); function testGitRemoteResolver() { var dejavuResolver = new GitRemoteResolver('git://github.com/IndigoUnited/dejavu.git', { @@ -56,19 +54,6 @@ if (process.argv[1] && !/mocha/.test(process.argv[1])) { // It messes with the mocha uncaughtException event to caught errors process.removeAllListeners('uncaughtException'); - // Ensure that our "fake" remote repository has all - // the necessary branches being tracked - before(function (next) { - var dir = path.join(__dirname, 'assets/github-test-package'); - - return fetchBranch('master', dir) - .then(function () { - return fetchBranch('some-branch', dir); - }) - .then(next.bind(next, null)) - .done(); - }); - require('./resolve/resolver'); require('./resolve/resolvers/gitResolver'); require('./resolve/resolvers/gitFsResolver'); diff --git a/test/util/fetchBranch.js b/test/util/fetchBranch.js deleted file mode 100644 index def2962a..00000000 --- a/test/util/fetchBranch.js +++ /dev/null @@ -1,15 +0,0 @@ -var cmd = require('../../lib/util/cmd'); - -function fetchBranch(branch, dir) { - return cmd('git', ['checkout', '-b', branch, 'origin/' + branch], { cwd: dir }) - .then(null, function (err) { - if (/already exists/i.test(err.details)) { - return cmd('git', ['checkout', branch], { cwd: dir }) - .then(function () { - return cmd('git', ['pull', 'origin', branch], { cwd: dir }); - }); - } - }); -} - -module.exports = fetchBranch; \ No newline at end of file