diff --git a/@commitlint/cli/src/cli.ts b/@commitlint/cli/src/cli.ts index ed34a75e18..8a8ec6f35f 100644 --- a/@commitlint/cli/src/cli.ts +++ b/@commitlint/cli/src/cli.ts @@ -352,7 +352,10 @@ function checkFromStdin(input: (string | number)[], flags: CliFlags): boolean { } function checkFromRepository(flags: CliFlags): boolean { - return checkFromHistory(flags) || checkFromEdit(flags); + return ( + (checkFromHistory(flags) && checkHistoryValue(flags)) || + checkFromEdit(flags) + ); } function checkFromEdit(flags: CliFlags): boolean { @@ -367,6 +370,19 @@ function checkFromHistory(flags: CliFlags): boolean { ); } +function checkHistoryValue(flags: CliFlags): boolean { + if (flags.from === flags.to) { + const err = new CliError( + 'Please use a different commit hash for --from and --to, not the same. (Or use the --last flag for analyzing just the last commit.)', + pkg.name + ); + yargs.showHelp('log'); + console.log(err.message); + throw err; + } + return true; +} + function normalizeFlags(flags: CliFlags): CliFlags { const edit = getEditValue(flags); return {