Skip to content

Commit f91d539

Browse files
Fix regression when using --last flag (#3982)
* 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
1 parent 64dbb46 commit f91d539

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module.exports = {
2+
rules: {
3+
'subject-empty': [2, 'never'],
4+
'type-empty': [2, 'never'],
5+
'type-enum': [2, 'always', [
6+
'test'
7+
]]
8+
}
9+
};

@commitlint/cli/src/cli.test.ts

+10
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,16 @@ test('should produce last commit and success output with --verbose flag', async
6262
expect(actual.stderr).toEqual('');
6363
});
6464

65+
test('regression test for running with --last flag', async () => {
66+
const cwd = await gitBootstrap('fixtures/last-flag-regression');
67+
await execa('git', ['add', 'commitlint.config.js'], {cwd});
68+
await execa('git', ['commit', '-m', '"test: this should work"'], {cwd});
69+
const actual = await cli(['--last', '--verbose'], {cwd})();
70+
expect(actual.stdout).toContain('0 problems, 0 warnings');
71+
expect(actual.stdout).toContain('test: this should work');
72+
expect(actual.stderr).toEqual('');
73+
});
74+
6575
test('should produce no output with --quiet flag', async () => {
6676
const cwd = await gitBootstrap('fixtures/default');
6777
const actual = await cli(['--quiet'], {cwd})('foo: bar');

@commitlint/read/src/read.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,16 @@ export default async function getCommitMessages(
2626
}
2727

2828
if (last) {
29-
const executeGitCommand = await execa('git', [
29+
const gitCommandResult = await execa('git', [
3030
'log',
3131
'-1',
32-
'--pretty=format:"%B"',
32+
'--pretty=format:%B',
3333
]);
34-
return [executeGitCommand.stdout];
34+
let output = gitCommandResult.stdout;
35+
// strip output of extra quotation marks ("")
36+
if (output[0] == '"' && output[output.length - 1] == '"')
37+
output = output.slice(1, -1);
38+
return [output];
3539
}
3640

3741
let gitOptions: GitOptions = {from, to};

0 commit comments

Comments
 (0)