Skip to content

Commit 682ee6f

Browse files
committed
fix: observe working directory with --last option
1 parent 722d8ff commit 682ee6f

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

@commitlint/read/src/read.test.ts

+12
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,15 @@ test('get edit commit message while skipping first commit', async () => {
7272
const actual = await read({from: 'HEAD~2', cwd, gitLogArgs: '--skip 1'});
7373
expect(actual).toEqual(expected);
7474
});
75+
76+
test('should only read the last commit', async () => {
77+
const cwd: string = await git.bootstrap();
78+
79+
await execa('git', ['commit', '--allow-empty', '-m', 'commit Z'], {cwd});
80+
await execa('git', ['commit', '--allow-empty', '-m', 'commit Y'], {cwd});
81+
await execa('git', ['commit', '--allow-empty', '-m', 'commit X'], {cwd});
82+
83+
const result = await read({cwd, last: true});
84+
85+
expect(result).toEqual(['commit X']);
86+
});

@commitlint/read/src/read.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ export default async function getCommitMessages(
2626
}
2727

2828
if (last) {
29-
const gitCommandResult = await execa('git', [
30-
'log',
31-
'-1',
32-
'--pretty=format:%B',
33-
]);
29+
const gitCommandResult = await execa(
30+
'git',
31+
['log', '-1', '--pretty=format:%B'],
32+
{cwd}
33+
);
3434
let output = gitCommandResult.stdout;
3535
// strip output of extra quotation marks ("")
3636
if (output[0] == '"' && output[output.length - 1] == '"')

0 commit comments

Comments
 (0)