Skip to content

Commit

Permalink
feat(commit): allow override options passed to git commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Guria committed Jan 10, 2016
1 parent 1b11570 commit bf6d2db
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/commitizen/commit.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ export default commit;
function commit(sh, inquirer, repoPath, prompter, options, done) {

// Get user input -- side effect that is hard to test
prompter(inquirer, function(template) {
prompter(inquirer, function(template, overrideOptions) {

// Commit the user input -- side effect that we'll test
gitCommit(sh, repoPath, template, options, function() {
gitCommit(sh, repoPath, template, { ...options, ...overrideOptions }, function() {
done(template);
});
});
Expand Down
54 changes: 52 additions & 2 deletions test/tests/commit.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,56 @@ describe('commit', function() {
});

});

it('should allow to override options passed to gulp-git', function(done) {

this.timeout(config.maxTimeout); // this could take a while

// SETUP

let dummyCommitMessage = `sip sip sippin on some sizzurp`;
let author = `A U Thor <author@example.com>`;

// Describe a repo and some files to add and commit
let repoConfig = {
path: config.paths.endUserRepo,
files: {
dummyfile: {
contents: `duck-duck-goose`,
filename: `mydummyfile.txt`,
},
gitignore: {
contents: `node_modules/`,
filename: `.gitignore`
}
}
};

// Describe an adapter
let adapterConfig = {
path: path.join(repoConfig.path, '/node_modules/cz-jira-smart-commit'),
npmName: 'cz-jira-smart-commit'
};

let options = {
args: `--author="${author}" --no-edit`
};

// Quick setup the repos, adapter, and grab a simple prompter
let prompter = quickPrompterSetup(sh, repoConfig, adapterConfig, dummyCommitMessage, options);
// TEST

// Pass in inquirer but it never gets used since we've mocked out a different
// version of prompter.
commitizenCommit(sh, inquirer, repoConfig.path, prompter, {disableAppendPaths:true, quiet:true, emitData:true}, function() {
log(repoConfig.path, function(logOutput) {
expect(logOutput).to.have.string(author);
expect(logOutput).to.have.string(dummyCommitMessage);
done();
});
});

});

});

Expand All @@ -151,7 +201,7 @@ after(function() {
* This is just a helper for testing. NOTE that prompter
* prompter is overriden for testing purposes.
*/
function quickPrompterSetup(sh, repoConfig, adapterConfig, commitMessage) {
function quickPrompterSetup(sh, repoConfig, adapterConfig, commitMessage, options={}) {

commitizenInit(sh, repoConfig.path, adapterConfig.npmName);

Expand All @@ -160,7 +210,7 @@ function quickPrompterSetup(sh, repoConfig, adapterConfig, commitMessage) {
// we'll provide prompter. We'd normally use:
// let prompter = getPrompter(adapterConfig.path);
let prompter = function(cz, commit) {
commit(commitMessage);
commit(commitMessage, options);
}

gitInit(sh, repoConfig.path);
Expand Down

0 comments on commit bf6d2db

Please sign in to comment.