Skip to content

Commit

Permalink
Ignore bower.json version in bower version
Browse files Browse the repository at this point in the history
Fixes bower#2139.

Make `bower version` operate solely on git tags, ignoring the version
field in bower.json (if it exists).
  • Loading branch information
hdgarrood committed Apr 2, 2016
1 parent c0c2858 commit 3fbca6d
Showing 1 changed file with 31 additions and 15 deletions.
46 changes: 31 additions & 15 deletions lib/commands/version.js
Expand Up @@ -21,22 +21,20 @@ function version(logger, versionArg, options, config) {
function bump(project, versionArg, message) {
var cwd = project._config.cwd || process.cwd();
var newVersion;
var doGitCommit = false;

return checkGit(cwd)
.then(function (hasGit) {
doGitCommit = hasGit;
if (!hasGit) {
throw createError('This directory does not appear to be a git repository', 'ENOTGITREPOSITORY');
}
})
.then(project.getJson.bind(project))
.then(function (json) {
newVersion = getNewVersion(json.version, versionArg);
json.version = newVersion;
.then(function(/*json (ignored)*/) {
return currentGitVersion(cwd);
})
.then(project.saveJson.bind(project))
.then(function () {
if (doGitCommit) {
return gitCommitAndTag(cwd, newVersion, message);
}
.then(function (currentVersion) {
newVersion = getNewVersion(currentVersion, versionArg);
return gitCommitAndTag(cwd, newVersion, message);
})
.then(function () {
console.log('v' + newVersion);
Expand Down Expand Up @@ -104,15 +102,33 @@ function gitCommitAndTag(cwd, newVersion, message) {
var tag = 'v' + newVersion;
message = message || tag;
message = message.replace(/%s/g, newVersion);
return Q.nfcall(execFile, 'git', ['add', 'bower.json'], {env: process.env, cwd: cwd})
return Q.nfcall(execFile, 'git', ['commit', '-m', message, '--allow-empty'], {env: process.env, cwd: cwd})
.then(function () {
return Q.nfcall(execFile, 'git', ['commit', '-m', message], {env: process.env, cwd: cwd});
})
.then(function () {
return Q.nfcall(execFile, 'git', ['tag', tag, '-am', message], {env: process.env, cwd: cwd});
Q.nfcall(execFile, 'git', ['tag', tag, '-am', message], {env: process.env, cwd: cwd});
});
}

function currentGitVersion(cwd) {
return Q.nfcall(execFile, 'git', ['tag'], {env: process.env, cwd: cwd})
.then(function(res) {
var versions = res[0]
.split(/\r?\n/)
.map(stripV)
.filter(semver.valid)
.sort(semver.compare);

return versions[versions.length - 1] || '0.0.0';
});
}

function stripV(s) {
if (s[0] === 'v') {
return s.slice(1);
} else {
return s;
}
}

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

version.readOptions = function (argv) {
Expand Down

0 comments on commit 3fbca6d

Please sign in to comment.