Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

  • Loading branch information...
commit 9aada19bb68d7836a799e821f0d8ea7b2e84445a 1 parent 273c1f8
@meenie authored
Showing with 22 additions and 1 deletion.
  1. +8 −0 README.md
  2. +14 −1 tasks/bump.js
View
8 README.md
@@ -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
15 tasks/bump.js
@@ -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 Owner
meenie added a note

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ if (err) {
+ grunt.fatal('Can not add files:\n ' + stderr);
+ }
+ grunt.log.ok('Files added.');

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 Owner
meenie added a note

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ 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);
}
@joshua703

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

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

@meenie

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

Please sign in to comment.
Something went wrong with that request. Please try again.