grunt-checkbranch
Advanced tools
Comparing version 0.2.2 to 0.3.0
@@ -31,7 +31,2 @@ /* | ||
// Configuration to be run (and then tested). | ||
checkbranch: { | ||
// @todo | ||
}, | ||
// Unit tests. | ||
@@ -38,0 +33,0 @@ buster: { |
{ | ||
"name": "grunt-checkbranch", | ||
"description": "Check that we are on a correct Git branch before proceeding.", | ||
"version": "0.2.2", | ||
"version": "0.3.0", | ||
"homepage": "https://github.com/dymonaz/grunt-checkbranch", | ||
@@ -32,8 +32,8 @@ "author": { | ||
"devDependencies": { | ||
"grunt-contrib-jshint": "~0.6.0", | ||
"grunt-contrib-jshint": "~0.8.0", | ||
"grunt-contrib-clean": "~0.5.0", | ||
"grunt": "~0.4.1", | ||
"grunt-release": "~0.5.1", | ||
"grunt-release": "~0.7.0", | ||
"buster": "~0.7.6", | ||
"grunt-buster": "~0.2.2" | ||
"grunt-buster": "~0.3.1" | ||
}, | ||
@@ -40,0 +40,0 @@ "peerDependencies": { |
@@ -28,8 +28,13 @@ # grunt-checkbranch | ||
In the example above, the `deploy` task will only be executed, if you project is currently on the `develop` branch - otherwise the run will result in a fatal error. | ||
In the example above, the `deploy` task will only be executed, if your project is currently on the `develop` branch - otherwise the run will result in a fatal error. | ||
You may override this behavior, if `--no-checkbranch` is passed via command line. You can disable `--no-checkbranch` (i.e. force the check) by setting a second param for the task, e.g. `checkbranch:master:true`. | ||
You may override this behavior by passing `--no-checkbranch` via command line. You can disable `--no-checkbranch` (i.e. force the check) by setting a second param for the task, e.g. `checkbranch:master:true`. | ||
You may also negate the test, i.e. exclude a specific branch by prepending an exclamation mark, e.g. `"checkbranch:!develop"`. | ||
## Release History | ||
### 0.3.0 (2014-02-24) | ||
* Added support for negating a branch, i.e. "run everywhere except X" (thx @Pleochism) | ||
### 0.2.2 (2013-09-29) | ||
@@ -36,0 +41,0 @@ * Added tests |
@@ -23,4 +23,9 @@ /* | ||
expectedBranch = expectedBranch || "master"; | ||
var negate = false; | ||
if(expectedBranch[0] === "!") { | ||
negate = true; | ||
expectedBranch = expectedBranch.slice(1); | ||
} | ||
grunt.log.writeln("Expecting to be on '" + expectedBranch + "' branch."); | ||
grunt.log.writeln("Expecting to " + (negate ? "not" : "") + " be on '" + expectedBranch + "' branch."); | ||
@@ -33,5 +38,8 @@ var branchOutput = shell.exec("git rev-parse --abbrev-ref HEAD", {silent: true}); | ||
var branch = branchOutput.output.trim(); | ||
if (branch !== expectedBranch) { | ||
if (!negate && branch !== expectedBranch) { | ||
grunt.fail.fatal("Only '"+expectedBranch+"' branch is allowed, and you're on '" + branch + "' branch."); | ||
} | ||
else if(negate && branch === expectedBranch) { | ||
grunt.fail.fatal("Anything except '"+expectedBranch+"' branch is allowed, and you're on '" + branch + "' branch."); | ||
} | ||
@@ -38,0 +46,0 @@ }); |
@@ -49,2 +49,22 @@ var buster = require('buster'); | ||
"should proceed when directory differs from negated match": function () { | ||
shell.pushd('tmp'); | ||
shell.exec("git checkout -b develop2"); | ||
shell.popd(); | ||
var output = execGrunt("checkbranch:!develop"); | ||
expect(output.output).toMatch(GRUNT_SUCCESS); | ||
expect(output.code).toEqual(0, "Incorrect grunt output code"); | ||
}, | ||
"should not proceed when directory equals negated match": function () { | ||
shell.pushd('tmp'); | ||
shell.exec("git checkout -b develop"); | ||
shell.popd(); | ||
var output = execGrunt("checkbranch:!develop"); | ||
expect(output.output).toMatch(GRUNT_FATAL); | ||
expect(output.code).toEqual(1, "Incorrect grunt output code"); | ||
}, | ||
"should default to 'master'": function () { | ||
@@ -51,0 +71,0 @@ var output = execGrunt("checkbranch"); |
9911
168
45