Skip to content

Commit

Permalink
Add confirmation message when no previous commits are found - fixes #242
Browse files Browse the repository at this point in the history
 (#245)
  • Loading branch information
SamVerschueren authored and sindresorhus committed Feb 22, 2018
1 parent d0499c6 commit 370ef63
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion lib/ui.js
Expand Up @@ -31,6 +31,10 @@ function printCommitLog(repositoryUrl) {
return execa.stdout('git', ['rev-list', `--tags`, '--max-count=1'])
.then(latestHash => execa.stdout('git', ['log', '--format=%s %h', `${latestHash}..HEAD`]))
.then(result => {
if (!result) {
return false;
}

const history = result.split('\n')
.map(commit => {
const commitParts = commit.match(/^(.+)\s([a-f\d]{7})$/);
Expand All @@ -43,6 +47,8 @@ function printCommitLog(repositoryUrl) {
.join('\n');

console.log(`${chalk.bold('Commits:')}\n${history}\n`);

return true;
});
}

Expand Down Expand Up @@ -145,6 +151,22 @@ module.exports = options => {
];

return printCommitLog(repositoryUrl)
.then(() => inquirer.prompt(prompts))
.then(hasCommits => {
if (!hasCommits) {
return inquirer.prompt([{
type: 'confirm',
name: 'confirm',
message: 'No commits found since previous release, continue?',
default: false
}]);
}
})
.then(answers => {
if (answers && !answers.confirm) {
return answers;
}

return inquirer.prompt(prompts);
})
.then(answers => Object.assign({}, options, answers));
};

0 comments on commit 370ef63

Please sign in to comment.