Skip to content

Commit cc575fa

Browse files
ericcornelissenmarionebl
authored andcommitted
feat: add support for git submodules
No test included in this commit as this would require an update to @commitlint/test to support submodules.
1 parent 058e83a commit cc575fa

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

@commitlint/read/src/index.js

+22-4
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,29 @@ async function getEditCommit(cwd, edit) {
4141
throw new TypeError(`Could not find git root from ${cwd}`);
4242
}
4343

44-
const editFilePath =
45-
typeof edit === 'string'
46-
? path.resolve(top, edit)
47-
: path.join(top, '.git/COMMIT_EDITMSG');
44+
const editFilePath = await getEditFilePath(top, edit);
4845

4946
const editFile = await sander.readFile(editFilePath);
5047
return [`${editFile.toString('utf-8')}\n`];
5148
}
49+
50+
// Get path to recently edited commit message file
51+
// (top: string, edit: any) => Promise<String>
52+
async function getEditFilePath(top, edit) {
53+
let editFilePath;
54+
if (typeof edit === 'string') {
55+
editFilePath = path.resolve(top, edit);
56+
} else {
57+
const dotgitPath = path.join(top, '.git');
58+
const dotgitStats = sander.lstatSync(dotgitPath);
59+
if (dotgitStats.isDirectory()) {
60+
editFilePath = path.join(top, '.git/COMMIT_EDITMSG');
61+
} else {
62+
const gitFile = await sander.readFile(dotgitPath, 'utf8');
63+
const relativeGitPath = gitFile.replace('gitdir: ', '').replace('\n', '');
64+
editFilePath = path.join(top, relativeGitPath, 'COMMIT_EDITMSG');
65+
}
66+
}
67+
68+
return editFilePath;
69+
}

0 commit comments

Comments
 (0)