Skip to content

Fix regression when using --last flag #3982

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = {
rules: {
'subject-empty': [2, 'never'],
'type-empty': [2, 'never'],
'type-enum': [2, 'always', [
'test'
]]
}
};
10 changes: 10 additions & 0 deletions @commitlint/cli/src/cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,16 @@ test('should produce last commit and success output with --verbose flag', async
expect(actual.stderr).toEqual('');
});

test('regression test for running with --last flag', async () => {
const cwd = await gitBootstrap('fixtures/last-flag-regression');
await execa('git', ['add', 'commitlint.config.js'], {cwd});
await execa('git', ['commit', '-m', '"test: this should work"'], {cwd});
const actual = await cli(['--last', '--verbose'], {cwd})();
expect(actual.stdout).toContain('0 problems, 0 warnings');
expect(actual.stdout).toContain('test: this should work');
expect(actual.stderr).toEqual('');
});

test('should produce no output with --quiet flag', async () => {
const cwd = await gitBootstrap('fixtures/default');
const actual = await cli(['--quiet'], {cwd})('foo: bar');
Expand Down
10 changes: 7 additions & 3 deletions @commitlint/read/src/read.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,16 @@ export default async function getCommitMessages(
}

if (last) {
const executeGitCommand = await execa('git', [
const gitCommandResult = await execa('git', [
'log',
'-1',
'--pretty=format:"%B"',
'--pretty=format:%B',
]);
return [executeGitCommand.stdout];
let output = gitCommandResult.stdout;
// strip output of extra quotation marks ("")
if (output[0] == '"' && output[output.length - 1] == '"')
output = output.slice(1, -1);
return [output];
}

let gitOptions: GitOptions = {from, to};
Expand Down