diff --git a/@commitlint/top-level/src/index.ts b/@commitlint/top-level/src/index.ts index 6984e899a7..1ea308ea39 100644 --- a/@commitlint/top-level/src/index.ts +++ b/@commitlint/top-level/src/index.ts @@ -14,7 +14,7 @@ export default toplevel; * Find the next git root */ async function toplevel(cwd: string) { - const found = await up('.git', {cwd, type: 'directory'}); + const found = await searchDotGit(cwd); if (typeof found !== 'string') { return found; @@ -22,3 +22,13 @@ async function toplevel(cwd: string) { return path.join(found, '..'); } + +/** + * Search .git, the '.git' can be a file(submodule), also can be a directory(normal) + */ +async function searchDotGit(cwd: string) { + const foundFile = await up('.git', {cwd, type: 'file'}); + const foundDir = await up('.git', {cwd, type: 'directory'}); + + return foundFile || foundDir; +}