Limit grunt tasks to specific git branches
Ever accidentally run a grunt deployment task, forgetting that you're actually in a half-working feature branch? Had a colleague ask for help, only to discovery (much later) that they deployed to staging with uncommitted local changes?
This plugin runs a few quick sanity checks to help avoid these problems. It will:
- Allow you to configure a grunt task that will cause grunt to quit if a configured set of checks don't pass
- Optionally check for uncommitted local changes
- Optionally check to ensure there are no local revisions that need to be pushed to the remote
- Optionally check that your local repo is not behind the remote
This plugin requires Grunt
If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:
npm install grunt-gitcheck --save-dev
In your project's Gruntfile, add a section named
gitcheck to the data object passed into
gruntinitConfiggitcheck:options:branchChecking: trueenforceUncommittedChanges: trueenforceUpdates: trueproduction:branches: 'production'staging:options:branchChecking: false'v0.2.0':branches: 'nextrelease' 'newfeature';
options.branchChecking set to
true, the task will look for a configured array of allowed
branches below), and throw an error if you're not currently working in one of the
With this option set to
true, the task will check to see if you have any local changes that haven't
been committed, and throws an error if you do.
This causes the task to check against the origin to see if your local repo is ahead (you have local revs that have not been pushed) or behind (there are revs at the origin you have not pulled).
true, the task will check against this list of branch names - if
working in a branch not listed in the array when the task is called, an error will be thrown.
gruntinitConfiggitcheck:production:branches: 'master's3:options:cacheTTL: 0headers:CacheControl: 300gzip: falsestaging:options:bucket: 'staging.mybucket.com'cwd: 'dist/'src: '**'production:options:bucket: 'www.mybucket.com'gzip: truecwd: 'dist/'src: '**';gruntregisterTask'deploy'if !targetgruntfailfatal'Deploy where?';var tasks = 's3:' + target;if gruntconfigget'gitcheck.' + targettasksunshift'gitcheck:' + target;grunttaskruntasks;;
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.
0.1.0 Initial release