Skip to content

Commit fb3c69c

Browse files
committed
fix: do not ask questions if the commit message already exists
1 parent d1b6bae commit fb3c69c

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

src/index.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,18 +64,32 @@ function runInteractive(): void {
6464
const options = promptCommand.opts();
6565
const config = parseConfigFile(options.config);
6666

67+
const orig = options.file
68+
? readFileSync(options.file, { encoding: 'utf-8' })
69+
: '';
70+
71+
if (
72+
orig
73+
.split('\n')
74+
.filter(s => !s.startsWith('#'))
75+
.join('\n')
76+
.trim() !== ''
77+
) {
78+
process.exitCode = 0;
79+
return;
80+
}
81+
6782
createCommitMessage(config)
6883
.then(msg => {
6984
const rendered = renderMessage(msg, config);
7085
if (options.file) {
71-
let orig = readFileSync(options.file, { encoding: 'utf-8' })
86+
const comments = orig
7287
.split('\n')
7388
.filter(s => s.startsWith('#'))
7489
.join('\n');
75-
7690
return promises.writeFile(
7791
options.file,
78-
rendered + '\n\n' + orig,
92+
rendered + '\n\n' + comments,
7993
{
8094
encoding: 'utf-8',
8195
}

0 commit comments

Comments
 (0)