mirror of
https://github.com/bower/bower.git
synced 2026-04-24 03:00:19 -04:00
Fallback to latest commit on master if the repo has no tags and target is *.
This commit is contained in:
@@ -51,21 +51,29 @@ GitResolver.fetchRefs = function (source) {};
|
||||
|
||||
// -----------------
|
||||
|
||||
GitResolver.prototype._findResolution = function () {
|
||||
GitResolver.prototype._findResolution = function (target) {
|
||||
var branches,
|
||||
self = this.constructor;
|
||||
|
||||
target = target || this._target;
|
||||
|
||||
// Target is a range/version
|
||||
if (semver.valid(this._target) || semver.validRange(this._target)) {
|
||||
if (semver.valid(target) != null || semver.validRange(target) != null) {
|
||||
return self.fetchVersions(this._sourcePath)
|
||||
.then(function (versions) {
|
||||
// If there are no tags and target is *,
|
||||
// fallback to the latest commit on master
|
||||
if (!versions.length && target === '*') {
|
||||
return this._findResolution('master');
|
||||
}
|
||||
|
||||
// Find the highest one that satifies the target
|
||||
var version = mout.array.find(versions, function (version) {
|
||||
return semver.satisfies(version, this._target);
|
||||
return semver.satisfies(version, target);
|
||||
}, this);
|
||||
|
||||
if (!version) {
|
||||
throw createError('No tag found that was able to satisfy "' + this._target + '"', 'ENORESTARGET', {
|
||||
throw createError('No tag found that was able to satisfy "' + target + '"', 'ENORESTARGET', {
|
||||
details: !versions.length ?
|
||||
'No tags found in "' + this._source + '"' :
|
||||
'Available tags in "' + this._source + '" are: ' + versions.join(', ')
|
||||
@@ -78,23 +86,23 @@ GitResolver.prototype._findResolution = function () {
|
||||
|
||||
// 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(this._target)) {
|
||||
return Q.resolve({ type: 'commit', commit: this._target });
|
||||
if ((/^[a-f0-9]{40}$/).test(target)) {
|
||||
return Q.resolve({ type: 'commit', commit: target });
|
||||
}
|
||||
|
||||
// Otherwise, assume target is a branch
|
||||
return self.fetchHeads(this._sourcePath)
|
||||
.then(function (heads) {
|
||||
if (!heads[this._target]) {
|
||||
if (!heads[target]) {
|
||||
branches = Object.keys(heads);
|
||||
throw createError('Branch "' + this._target + '" does not exist', 'ENORESTARGET', {
|
||||
throw createError('Branch "' + target + '" does not exist', 'ENORESTARGET', {
|
||||
details: !branches.length ?
|
||||
'No branches found in "' + this._source + '"' :
|
||||
'Available branches in "' + this._source + '" are: ' + branches.join(', ')
|
||||
});
|
||||
}
|
||||
|
||||
return { type: 'branch', branch: this._target, commit: heads[this._target] };
|
||||
return { type: 'branch', branch: target, commit: heads[target] };
|
||||
}.bind(this));
|
||||
};
|
||||
|
||||
|
||||
20
test/test.js
20
test/test.js
@@ -31,9 +31,27 @@ function testGitLocalResolver() {
|
||||
});
|
||||
}
|
||||
|
||||
function testGitRemoteResolverNoTags() {
|
||||
var spoonResolver = new GitRemoteResolver('git://github.com/IndigoUnited/spoon.js.git', {
|
||||
name: 'spoonjs',
|
||||
//target: '7d07190ca6fb7ffa63642526537e0c314cbaab12'
|
||||
//target: 'master'
|
||||
target: '*'
|
||||
});
|
||||
|
||||
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(testGitLocalResolver)
|
||||
.then(testGitRemoteResolverNoTags);
|
||||
|
||||
//testGitLocalResolver();
|
||||
//testGitRemoteResolverNoTags();
|
||||
}
|
||||
Reference in New Issue
Block a user