From 74f7c93a6d6e46a417153bdb7b45ad4710bc5228 Mon Sep 17 00:00:00 2001 From: Andre Cruz Date: Mon, 15 Apr 2013 14:20:40 +0100 Subject: [PATCH] Remove fetch origin in the GitFsResolver. --- lib/resolve/resolvers/GitFsResolver.js | 25 +++++-------------------- lib/resolve/resolvers/GitResolver.js | 16 ++++++---------- test/test.js | 12 +++--------- 3 files changed, 14 insertions(+), 39 deletions(-) diff --git a/lib/resolve/resolvers/GitFsResolver.js b/lib/resolve/resolvers/GitFsResolver.js index 34d3539e..8c635631 100644 --- a/lib/resolve/resolvers/GitFsResolver.js +++ b/lib/resolve/resolvers/GitFsResolver.js @@ -22,11 +22,11 @@ mout.object.mixIn(GitFsResolver, GitResolver); // ----------------- GitFsResolver.prototype._resolveSelf = function () { - this._sourcePath = this._tempDir; - - return this._copy() - .then(this._fetch.bind(this)) - .then(GitResolver.prototype._resolveSelf.bind(this)); + return this._findResolution() + .then(this._copy.bind(this)) + .then(function () { + return this._checkout(this._resolution); + }.bind(this)); }; // ----------------- @@ -45,21 +45,6 @@ GitFsResolver.prototype._copy = function () { }.bind(this)); }; -GitFsResolver.prototype._fetch = function () { - var dir = this._tempDir; - - // Check if there is at least one remote - return cmd('git', ['remote'], { cwd: dir }) - .then(function (stdout) { - var hasRemote = !!stdout.trim().length; - - // If so, do a fetch to grab the new tags and refs - if (hasRemote) { - return cmd('git', ['fetch']); - } - }); -}; - // Override the checkout function to work with the local copy GitFsResolver.prototype._checkout = function (resolution) { var dir = this._tempDir; diff --git a/lib/resolve/resolvers/GitResolver.js b/lib/resolve/resolvers/GitResolver.js index 35873c78..48e0e77e 100644 --- a/lib/resolve/resolvers/GitResolver.js +++ b/lib/resolve/resolvers/GitResolver.js @@ -7,11 +7,6 @@ var createError = require('../../util/createError'); var GitResolver = function (source, options) { Resolver.call(this, source, options); - - // Set the source path to be the same as the original source by default - // The source path is the real location of the repository since it - // can be infered from the source or simply a different one - this._sourcePath = this._source; }; util.inherits(GitResolver, Resolver); @@ -59,7 +54,7 @@ GitResolver.prototype._findResolution = function (target) { // Target is a range/version if (semver.valid(target) != null || semver.validRange(target) != null) { - return self.fetchVersions(this._sourcePath) + return self.fetchVersions(this._source) .then(function (versions) { // If there are no tags and target is *, // fallback to the latest commit on master @@ -80,18 +75,19 @@ GitResolver.prototype._findResolution = function (target) { }); } - return { type: 'tag', tag: version }; + return this._resolution = { type: 'tag', tag: version }; }.bind(this)); } // Target is a commit, so it's a stale target (not a moving target) // There's nothing to do in this case if ((/^[a-f0-9]{40}$/).test(target)) { - return Q.resolve({ type: 'commit', commit: target }); + this._resolution = { type: 'commit', commit: target }; + return Q.resolve(this._resolution); } // Otherwise, assume target is a branch - return self.fetchHeads(this._sourcePath) + return self.fetchHeads(this._source) .then(function (heads) { if (!heads[target]) { branches = Object.keys(heads); @@ -102,7 +98,7 @@ GitResolver.prototype._findResolution = function (target) { }); } - return { type: 'branch', branch: target, commit: heads[target] }; + return this._resolution = { type: 'branch', branch: target, commit: heads[target] }; }.bind(this)); }; diff --git a/test/test.js b/test/test.js index b232ab1c..1e9a0f19 100644 --- a/test/test.js +++ b/test/test.js @@ -12,12 +12,10 @@ function testGitRemoteResolver() { return dejavuResolver.resolve() .then(function () { console.log('ok!'); - }, function (err) { - console.log('failed to resolve', err); }); } -function testGitLocalResolver() { +function testGitFsResolver() { var bowerResolver = new GitFsResolver('.', { name: 'bower', target: 'rewrite' @@ -26,8 +24,6 @@ function testGitLocalResolver() { return bowerResolver.resolve() .then(function () { console.log('ok!'); - }, function (err) { - console.log('failed to resolve', err); }); } @@ -42,16 +38,14 @@ function testGitRemoteResolverNoTags() { return spoonResolver.resolve() .then(function () { console.log('ok!'); - }, function (err) { - console.log('failed to resolve', err); }); } if (process.argv[1] && !/mocha/.test(process.argv[1])) { testGitRemoteResolver() - .then(testGitLocalResolver) + .then(testGitFsResolver) .then(testGitRemoteResolverNoTags); - //testGitLocalResolver(); + //testGitFsResolver(); //testGitRemoteResolverNoTags(); } \ No newline at end of file