Skip to content

Commit

Permalink
Merge pull request #756 from bower/meaningful-proxy-error
Browse files Browse the repository at this point in the history
Add additional message for proxy users about https//.insteadOf git://, fixes #250.
  • Loading branch information
satazor committed Aug 16, 2013
2 parents 47094ef + 17f72f0 commit 7621a71
Showing 1 changed file with 34 additions and 3 deletions.
37 changes: 34 additions & 3 deletions lib/core/resolvers/GitRemoteResolver.js
Expand Up @@ -72,12 +72,29 @@ GitRemoteResolver.prototype._checkout = function () {
}, 8000);

return promise
// Add additional proxy information to the error if necessary
.fail(function (err) {
that._suggestProxyWorkaround(err);
throw err;
})
// Clear timer at the end
.fin(function () {
clearTimeout(timer);
});
};

GitRemoteResolver.prototype._findResolution = function (target) {
var that = this;

// Override this function to include a meaningful message related to proxies
// if necessary
return GitResolver.prototype._findResolution.call(this, target)
.fail(function (err) {
that._suggestProxyWorkaround(err);
throw err;
});
};

// ------------------------------

GitRemoteResolver.prototype._slowClone = function (resolution) {
Expand Down Expand Up @@ -124,10 +141,21 @@ GitRemoteResolver.prototype._fastClone = function (resolution) {
});
};

// ------------------------------
GitRemoteResolver.prototype._suggestProxyWorkaround = function (err) {
if ((this._config.proxy || this._config.httpsProxy) &&
mout.string.startsWith(this._source, 'git://') &&
err.code === 'ECMDERR' && err.details
) {
err.details = err.details.trim();
err.details += '\n\nWhen under a proxy, you must configure git to use https:// instead of git://.';
err.details += '\nYou can configure it for every endpoint or for this specific host as follows:';
err.details += '\ngit config --global url."https://".insteadOf git://';
err.details += '\ngit config --global url."https://' + this._host + '".insteadOf git://' + this._host;
err.details += 'Ignore this suggestion if you already have this configured.';
}
};

// Store hosts that do not support shallow clones here
GitRemoteResolver._noShallow = new LRU({ max: 50, maxAge: 5 * 60 * 1000 });
// ------------------------------

// Grab refs remotely
GitRemoteResolver.refs = function (source) {
Expand Down Expand Up @@ -162,4 +190,7 @@ GitRemoteResolver.refs = function (source) {
return value;
};

// Store hosts that do not support shallow clones here
GitRemoteResolver._noShallow = new LRU({ max: 50, maxAge: 5 * 60 * 1000 });

module.exports = GitRemoteResolver;

0 comments on commit 7621a71

Please sign in to comment.