Skip to content

Commit

Permalink
Fix regression when using --last flag (#3982)
Browse files Browse the repository at this point in the history
* test(cli): add regression test for --last flag

Added regression test for running with --last flag. See [1].

[1] #3981

* fix(cli): fixed regression when using --last flag

Fixed regression when using --last flag.

Fixes #3981
  • Loading branch information
webwarrior-ws committed Mar 19, 2024
1 parent 64dbb46 commit f91d539
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
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

0 comments on commit f91d539

Please sign in to comment.