Skip to content

Commit bf6d2db

Browse files
committed
feat(commit): allow override options passed to git commit
1 parent 1b11570 commit bf6d2db

File tree

2 files changed

+54
-4
lines changed

2 files changed

+54
-4
lines changed

src/commitizen/commit.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ export default commit;
99
function commit(sh, inquirer, repoPath, prompter, options, done) {
1010

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

1414
// Commit the user input -- side effect that we'll test
15-
gitCommit(sh, repoPath, template, options, function() {
15+
gitCommit(sh, repoPath, template, { ...options, ...overrideOptions }, function() {
1616
done(template);
1717
});
1818
});

test/tests/commit.js

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,56 @@ describe('commit', function() {
133133
});
134134

135135
});
136+
137+
it('should allow to override options passed to gulp-git', function(done) {
138+
139+
this.timeout(config.maxTimeout); // this could take a while
140+
141+
// SETUP
142+
143+
let dummyCommitMessage = `sip sip sippin on some sizzurp`;
144+
let author = `A U Thor <[email protected]>`;
145+
146+
// Describe a repo and some files to add and commit
147+
let repoConfig = {
148+
path: config.paths.endUserRepo,
149+
files: {
150+
dummyfile: {
151+
contents: `duck-duck-goose`,
152+
filename: `mydummyfile.txt`,
153+
},
154+
gitignore: {
155+
contents: `node_modules/`,
156+
filename: `.gitignore`
157+
}
158+
}
159+
};
160+
161+
// Describe an adapter
162+
let adapterConfig = {
163+
path: path.join(repoConfig.path, '/node_modules/cz-jira-smart-commit'),
164+
npmName: 'cz-jira-smart-commit'
165+
};
166+
167+
let options = {
168+
args: `--author="${author}" --no-edit`
169+
};
170+
171+
// Quick setup the repos, adapter, and grab a simple prompter
172+
let prompter = quickPrompterSetup(sh, repoConfig, adapterConfig, dummyCommitMessage, options);
173+
// TEST
174+
175+
// Pass in inquirer but it never gets used since we've mocked out a different
176+
// version of prompter.
177+
commitizenCommit(sh, inquirer, repoConfig.path, prompter, {disableAppendPaths:true, quiet:true, emitData:true}, function() {
178+
log(repoConfig.path, function(logOutput) {
179+
expect(logOutput).to.have.string(author);
180+
expect(logOutput).to.have.string(dummyCommitMessage);
181+
done();
182+
});
183+
});
184+
185+
});
136186

137187
});
138188

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

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

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

166216
gitInit(sh, repoConfig.path);

0 commit comments

Comments
 (0)