Skip to content

Commit

Permalink
Add ref option.
Browse files Browse the repository at this point in the history
  • Loading branch information
Simen Brekken committed Oct 16, 2013
1 parent 2818a9d commit d2bdb08
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
7 changes: 7 additions & 0 deletions README.md
Expand Up @@ -27,6 +27,7 @@ grunt.initConfig({
revision: {
options: {
property: 'meta.revision',
ref: 'HEAD',
short: true
}
},
Expand All @@ -41,6 +42,12 @@ Default value: `'meta.revision'`

What configuration property to write the revision to.

#### options.ref
Type: `String`
Default value: `'HEAD'`

What ref to read the revision from.

#### options.short
Type: `Boolean`
Default value: `true`
Expand Down
5 changes: 3 additions & 2 deletions tasks/revision.js
Expand Up @@ -12,14 +12,15 @@ module.exports = function(grunt) {
grunt.registerTask('revision', 'Retrieves the current git revision', function(property) {
var options = this.options({
property: 'meta.revision',
ref: 'HEAD',
short: true
});

var done = this.async();

grunt.util.spawn({
cmd: 'git',
args: ['rev-parse', options.short && '--short', 'HEAD'].filter(Boolean)
args: ['rev-parse', options.short && '--short', options.ref].filter(Boolean)
}, function(err, result) {
if (err) {
grunt.log.error(err);
Expand All @@ -30,7 +31,7 @@ module.exports = function(grunt) {
var revision = result.toString();

grunt.config(options.property, revision);
grunt.log.writeln('Found Git revision "' + revision + '"');
grunt.log.writeln(options.ref + ' at revision ' + revision);

done(true);
});
Expand Down

0 comments on commit d2bdb08

Please sign in to comment.