Skip to content

Commit

Permalink
fix(commit): allow quotes in commit message
Browse files Browse the repository at this point in the history
Fixes an issue in which quotes in the description were not escaped and would cause cz to fail.
  • Loading branch information
Patrick McElhaney authored and Patrick McElhaney committed Mar 30, 2016
1 parent c514f56 commit e7c299b
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/git/commit.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@ function commit(sh, repoPath, message, options, done) {

var alreadyEnded = false;
let dedentedMessage = dedent(message);
let escapedMessage = dedentedMessage.replace(/"/g, '\\"');
let operatingSystemNormalizedMessage;
// On windows we must use an array in gulp-git instead of a string because
// command line parsing works differently
if(os.platform()=="win32") {
operatingSystemNormalizedMessage = dedentedMessage.split(/\r?\n/);
operatingSystemNormalizedMessage = escapedMessage.split(/\r?\n/);
} else {
operatingSystemNormalizedMessage = dedentedMessage;
operatingSystemNormalizedMessage = escapedMessage;
}

// Get a gulp stream based off the config
Expand Down
45 changes: 45 additions & 0 deletions test/tests/commit.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,51 @@ describe('commit', function() {

});

it('should commit message with quotes', function(done) {

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

// SETUP

let dummyCommitMessage = `sip sip sippin' on some "sizzurp"`;

// 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'
};

// Quick setup the repos, adapter, and grab a simple prompter
let prompter = quickPrompterSetup(sh, repoConfig, adapterConfig, dummyCommitMessage);
// 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(dummyCommitMessage);
done();
});
});

});


it('should commit multiline messages', function(done) {

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

0 comments on commit e7c299b

Please sign in to comment.