diff --git a/README.md b/README.md index b8641c7..81a52c1 100644 --- a/README.md +++ b/README.md @@ -99,6 +99,12 @@ Default value: `false` When `true`, the task will commit the changes with the `--no-verify` flag. +#### options.force +Type: `Boolean` +Default value: `false` + +When `true`, files will be added with the --force flag. This allows adding otherwise ignored files. + #### options.noStatus Type: `Boolean` Default value: `false` diff --git a/lib/command_commit.js b/lib/command_commit.js index 64bd8c4..d475c1b 100644 --- a/lib/command_commit.js +++ b/lib/command_commit.js @@ -7,7 +7,8 @@ module.exports = function (task, exec, done) { message: 'Commit', ignoreEmpty: false, noVerify: false, - noStatus: false + noStatus: false, + force: false }); var args = ['commit', '-m', options.message]; @@ -21,12 +22,21 @@ module.exports = function (task, exec, done) { args.push(done); + var argsAdd = ['add']; + if (options.force) { + argsAdd.push('--force'); + } + function addFiles(files, cb) { async.forEachSeries(files.src, addFile, cb); } function addFile(file, cb) { - exec('add', file, cb); + + var localArgs = argsAdd.slice(); // create a copy + localArgs.push(file); + localArgs.push(cb); + exec.apply(null, localArgs); } function checkStaged(cb) { diff --git a/test/commit_test.js b/test/commit_test.js index c25cb4d..3db6ba9 100644 --- a/test/commit_test.js +++ b/test/commit_test.js @@ -39,6 +39,24 @@ describe('commit', function () { .run(done); }); + it('should add files with the force flag', function (done) { + var options = { + force: true + }; + + var files = [ + 'test.txt', + 'test2.txt' + ]; + + new Test(command, options, files) + .expect(['add', '--force', 'test.txt']) + .expect(['add', '--force', 'test2.txt']) + .expect(['diff', '--cached', '--exit-code'], [null, 'diff', 1]) + .expect(['commit', '-m', 'Commit']) + .run(done); + }); + it('should not fail when there are no unstaged changes', function (done) { var options = { ignoreEmpty: false