Skip to content

Commit

Permalink
fix(wizard): wizard if there is no commit message format
Browse files Browse the repository at this point in the history
  • Loading branch information
bahmutov committed Dec 13, 2015
1 parent 164ac22 commit 1d5b1ce
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
17 changes: 16 additions & 1 deletion bin/commit-wizard.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const pkgPath = join(process.cwd(), 'package.json');
const pkg = require(pkgPath);
const preGit = require('pre-git');
const git = require('ggit');
const chalk = require('chalk');
const log = require('debug')('pre-git');
la(check.fn(log), 'missing debug log', log);

Expand All @@ -20,7 +21,8 @@ const config = pkg.config &&
pkg.config['pre-git'];

const wizard = preGit.wizard();
la(check.object(wizard), 'could not get commit message wizard', wizard);
la(check.maybe.object(wizard),
'could not get commit message wizard', wizard);

function getPreCommitCommands(config) {
if (!config) {
Expand Down Expand Up @@ -63,6 +65,15 @@ function guideUserMock() {
}

function guideUser() {
if (!wizard) {
console.error(chalk.yellow('You have not set the commit message format'));
console.error('This wizard does not know what to ask you');
console.error('Maybe try setting up "simple" commit message format');
console.error('See',
chalk.underline('https://github.com/bahmutov/pre-git#validating-commit-message'));
return Promise.reject(new Error('Missing commit format name'));
}

const inquirer = require('inquirer');

return new Promise(function (resolve, reject) {
Expand Down Expand Up @@ -92,6 +103,10 @@ function firstLine(str) {
}

function isValidMessage(message) {
if (!wizard) {
return message;
}

la(check.unemptyString(message), 'missing message');

const first = firstLine(message);
Expand Down
2 changes: 1 addition & 1 deletion src/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ function setupMessageValidation(pkg) {

var changedPackage;
var config = targetPackage.config['pre-git'];
if (commitMessageCommandIsEmpty(targetPackage)) {
if (!config && commitMessageCommandIsEmpty(targetPackage)) {
console.log('setting up commit message helpers');

config[hookLabel] = 'simple';
Expand Down

0 comments on commit 1d5b1ce

Please sign in to comment.