From 4b2aaa0e9df6a432566e6baa6947021af87882fc Mon Sep 17 00:00:00 2001 From: Santiago Burbano Date: Thu, 3 Jul 2014 23:53:42 -0500 Subject: [PATCH 1/2] Added 'force' option to command_commit --- README.md | 6 ++++++ lib/command_commit.js | 14 ++++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) 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..fd3e44f 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(0); + argsAdd.push(file); + argsAdd.push(cb); + exec.apply(null, argsAdd); } function checkStaged(cb) { From 2aab4e939a6d24bcba53c412ec9fca623bf7fc87 Mon Sep 17 00:00:00 2001 From: Santiago Burbano Date: Fri, 4 Jul 2014 09:22:51 -0500 Subject: [PATCH 2/2] fixed Added 'force' option to command_commit. Added test for commit 'force' option --- lib/command_commit.js | 8 ++++---- test/commit_test.js | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/lib/command_commit.js b/lib/command_commit.js index fd3e44f..d475c1b 100644 --- a/lib/command_commit.js +++ b/lib/command_commit.js @@ -33,10 +33,10 @@ module.exports = function (task, exec, done) { function addFile(file, cb) { - var localArgs = argsAdd.slice(0); - argsAdd.push(file); - argsAdd.push(cb); - exec.apply(null, argsAdd); + 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