Skip to content

Commit

Permalink
feat(cli): commit hash validation
Browse files Browse the repository at this point in the history
  • Loading branch information
Mersho committed Feb 12, 2024
1 parent 2ad881f commit bccc623
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion @commitlint/cli/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down

0 comments on commit bccc623

Please sign in to comment.