Skip to content

Commit 3c1a9eb

Browse files
committed
feat(cli): commit hash validation
Fixes conventional-changelog#3376
1 parent 2ad881f commit 3c1a9eb

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

@commitlint/cli/src/cli.ts

+16-1
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,9 @@ function checkFromStdin(input: (string | number)[], flags: CliFlags): boolean {
352352
}
353353

354354
function checkFromRepository(flags: CliFlags): boolean {
355-
return checkFromHistory(flags) || checkFromEdit(flags);
355+
return (
356+
(checkFromHistory(flags) && checkFlagsValue(flags)) || checkFromEdit(flags)
357+
);
356358
}
357359

358360
function checkFromEdit(flags: CliFlags): boolean {
@@ -367,6 +369,19 @@ function checkFromHistory(flags: CliFlags): boolean {
367369
);
368370
}
369371

372+
function checkFlagsValue(flags: CliFlags): boolean {
373+
if (flags.from === flags.to) {
374+
const err = new CliError(
375+
'Please use a different commit hash for --from and --to, not the same. (Or use the --last flag for analyzing just the last commit.)',
376+
pkg.name
377+
);
378+
yargs.showHelp('log');
379+
console.log(err.message);
380+
throw err;
381+
}
382+
return true;
383+
}
384+
370385
function normalizeFlags(flags: CliFlags): CliFlags {
371386
const edit = getEditValue(flags);
372387
return {

0 commit comments

Comments
 (0)