Skip to content

Commit

Permalink
fix(grunt): Make getVersion() work on travis
Browse files Browse the repository at this point in the history
  • Loading branch information
c0bra committed Dec 20, 2013
1 parent 84de806 commit 129f28b
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions lib/grunt/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,28 @@ var util = module.exports = {
getVersion: function() {
// Get the current git tag
// var version = shell.exec('git describe', {silent:true}).output.trim();
var version = shell.exec('git rev-list --all --max-count=1 | xargs git describe', {silent:true}).output.trim();

// Clean up the tag
// Try to get a tag for the current version
var out = shell.exec('git rev-list --all --max-count=1 | xargs git describe', {silent:true});

var version;

// If there's a tag on this commit, use it
if (out.code == 0) {
version = out.output.trim();
}
// ...otherwise, get the most recent stable tag
else {
version = shell.exec('git rev-list --tags --max-count=1 | xargs git describe', {silent:true}).output.trim();

// Append the commit hash suffix
var hash = shell.exec('git describe --always', {silent:true}).output.trim();
version = version + '-' + hash;
}

// Clean up the tag (git describe --long comes out as: v1.0.0-123-a78fda, need to remove the middle part though with the above commands we should not have the build number)
var tag = version.replace(/-\d+-/, '-');

tag = semver.clean(tag);

return tag;
Expand Down

0 comments on commit 129f28b

Please sign in to comment.