Skip to content

Commit c691610

Browse files
committed
feat: edit flag now accepts the path to the commit file
Closes conventional-changelog#40.
1 parent 97ccf2b commit c691610

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

@commitlint/core/src/read.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ async function getCommitMessages(settings) {
1919
const {cwd, from, to, edit} = settings;
2020

2121
if (edit) {
22-
return getEditCommit(cwd);
22+
return getEditCommit(cwd, edit);
2323
}
2424

2525
if (await isShallow(cwd)) {
@@ -57,15 +57,19 @@ async function isShallow(cwd) {
5757
}
5858

5959
// Get recently edited commit message
60-
// (cwd: string) => Promise<Array<String>>
61-
async function getEditCommit(cwd) {
60+
// (cwd: string, edit: any) => Promise<Array<String>>
61+
async function getEditCommit(cwd, edit) {
6262
const top = await toplevel(cwd);
6363

6464
if (typeof top !== 'string') {
6565
throw new TypeError(`Could not find git root from ${cwd}`);
6666
}
6767

68-
const editFilePath = path.join(top, '.git/COMMIT_EDITMSG');
68+
const editFilePath =
69+
typeof edit === 'string'
70+
? path.resolve(top, edit)
71+
: path.join(top, '.git/COMMIT_EDITMSG');
72+
6973
const editFile = await sander.readFile(editFilePath);
7074
return [`${editFile.toString('utf-8')}\n`];
7175
}

@commitlint/core/src/read.test.js

+10
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@ import * as sander from '@marionebl/sander';
66
import pkg from '../package';
77
import read from './read';
88

9+
test('get edit commit message specified by the `edit` flag', async t => {
10+
const cwd = await git.bootstrap();
11+
12+
await sander.writeFile(cwd, 'commit-msg-file', 'foo');
13+
14+
const expected = ['foo\n'];
15+
const actual = await read({edit: 'commit-msg-file', cwd});
16+
t.deepEqual(actual, expected);
17+
});
18+
919
test('get edit commit message from git root', async t => {
1020
const cwd = await git.bootstrap();
1121

0 commit comments

Comments
 (0)