Permalink
Browse files

Adding option to add untracked files before a commit is performed.

  • Loading branch information...
1 parent 273c1f8 commit 9aada19bb68d7836a799e821f0d8ea7b2e84445a Cody Lundquist committed Jul 24, 2014
Showing with 22 additions and 1 deletion.
  1. +8 −0 README.md
  2. +14 −1 tasks/bump.js
View
@@ -29,6 +29,7 @@ grunt.initConfig({
commit: true,
commitMessage: 'Release v%VERSION%',
commitFiles: ['package.json'],
+ addUntrackedFiles: false,
createTag: true,
tagName: 'v%VERSION%',
tagMessage: 'Version %VERSION%',
@@ -79,6 +80,13 @@ Default value: `['package.json']`
An array of files that you want to commit. You can use `['-a']` to commit all files.
+#### options.addUntrackedFiles
+Type: `Boolean`
+Default value: `false`
+
+Stages all files (untracked as well) listed in `options.commitFiles`.
+**Note:** This will not work if using `['-a']` for `options.commitFiles`.
+
#### options.createTag
Type: `Boolean`
Default value: `true`
View
@@ -28,6 +28,7 @@ module.exports = function(grunt) {
commit: true,
commitMessage: 'Release v%VERSION%',
commitFiles: ['package.json'], // '-a' for all files
+ addUntrackedFiles: false,
createTag: true,
tagName: 'v%VERSION%',
tagMessage: 'Version %VERSION%',
@@ -72,6 +73,7 @@ module.exports = function(grunt) {
var globalVersion; // when bumping multiple files
var gitVersion; // when bumping using `git describe`
var VERSION_REGEXP = /([\'|\"]?version[\'|\"]?[ ]*:[ ]*[\'|\"]?)([\d||A-a|.|-]*)([\'|\"]?)/i;
+ var filesToCommit = opts.commitFiles.join(' ');
// GET VERSION FROM GIT
@@ -139,11 +141,22 @@ module.exports = function(grunt) {
});
+ // ADD UNTRACKED FILES
+ runIf(opts.addUntrackedFiles && filesToCommit.trim() !== '-a', function() {
+ exec('git add ' + opts.commitFiles.join(' '), function(err, stdout, stderr) {
@meenie

meenie Jul 24, 2014

Owner

Also, I forgot to swap out opts.commitFiles.join(' ') for filesToCommit :).

+ if (err) {
+ grunt.fatal('Can not add files:\n ' + stderr);
+ }
+ grunt.log.ok('Files added.');
@joshua703

joshua703 Jul 24, 2014

Would it be helpful to log which files were added (e.g. git ls-files ./dist --exclude-standard --others)? I could imagine a situation where people start adding .DS_STORE or *.swp etc, unknowingly.

@meenie

meenie Jul 24, 2014

Owner

That's a very good point :). I'll add this in so it reports which new files have been added. Thanks @joshua703 👍

+ next();
+ });
+ });
+
// COMMIT
runIf(opts.commit, function() {
var commitMessage = opts.commitMessage.replace('%VERSION%', globalVersion);
- exec('git commit ' + opts.commitFiles.join(' ') + ' -m "' + commitMessage + '"', function(err, stdout, stderr) {
+ exec('git commit ' + filesToCommit + ' -m "' + commitMessage + '"', function(err, stdout, stderr) {
if (err) {
grunt.fatal('Can not create the commit:\n ' + stderr);
}

0 comments on commit 9aada19

Please sign in to comment.