From 9d09693ef5cecc8a5fa5ea8c503b1ac8677bda39 Mon Sep 17 00:00:00 2001 From: huanghai21 Date: Tue, 22 Oct 2019 07:13:04 +0800 Subject: [PATCH] fix(top-level): support git submodules (#784) * fix: modify the parameters for the sander.readFile function (#448) * fix: modify the parameters for the sander.readFile function (#448) - prettier lint fix * fix: do NOT specify the .git to be a directory in case of the git submodule not able to work properly * fix: add a new function 'searchDotGit' to make sure we can find a correct .git path which can be file or directory (#784) --- @commitlint/top-level/src/index.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) 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; +}