From 71509c4d7fc4042754af746fddd5d292df7a6e82 Mon Sep 17 00:00:00 2001 From: huanghai Date: Fri, 26 Apr 2019 21:57:45 +0800 Subject: [PATCH 1/4] fix: modify the parameters for the sander.readFile function (#448) --- @commitlint/read/src/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/@commitlint/read/src/index.js b/@commitlint/read/src/index.js index 9323a34a48..63594ac664 100644 --- a/@commitlint/read/src/index.js +++ b/@commitlint/read/src/index.js @@ -59,7 +59,7 @@ async function getEditFilePath(top, edit) { if (dotgitStats.isDirectory()) { editFilePath = path.join(top, '.git/COMMIT_EDITMSG'); } else { - const gitFile = await sander.readFile(dotgitPath, 'utf8'); + const gitFile = await sander.readFile(dotgitPath, { encoding: 'utf-8' }); const relativeGitPath = gitFile.replace('gitdir: ', '').replace('\n', ''); editFilePath = path.resolve(top, relativeGitPath, 'COMMIT_EDITMSG'); } From 5fb8f526fdb21607a38d294f1dfcf356988480b9 Mon Sep 17 00:00:00 2001 From: huanghai4 Date: Sun, 28 Apr 2019 13:23:26 +0800 Subject: [PATCH 2/4] fix: modify the parameters for the sander.readFile function (#448) - prettier lint fix --- @commitlint/read/src/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/@commitlint/read/src/index.js b/@commitlint/read/src/index.js index 63594ac664..b9ae72e0b4 100644 --- a/@commitlint/read/src/index.js +++ b/@commitlint/read/src/index.js @@ -59,7 +59,7 @@ async function getEditFilePath(top, edit) { if (dotgitStats.isDirectory()) { editFilePath = path.join(top, '.git/COMMIT_EDITMSG'); } else { - const gitFile = await sander.readFile(dotgitPath, { encoding: 'utf-8' }); + const gitFile = await sander.readFile(dotgitPath, {encoding: 'utf-8'}); const relativeGitPath = gitFile.replace('gitdir: ', '').replace('\n', ''); editFilePath = path.resolve(top, relativeGitPath, 'COMMIT_EDITMSG'); } From 2a0a6361120e5438256169aba1e095ceedac0982 Mon Sep 17 00:00:00 2001 From: huanghai4 Date: Wed, 11 Sep 2019 16:28:57 +0800 Subject: [PATCH 3/4] fix: do NOT specify the .git to be a directory in case of the git submodule not able to work properly --- @commitlint/top-level/src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/@commitlint/top-level/src/index.ts b/@commitlint/top-level/src/index.ts index 6984e899a7..3ee41a9a97 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 up('.git', {cwd}); if (typeof found !== 'string') { return found; From de9ccd67dbb0119f66ddacbc7c5f18ea9f8711c6 Mon Sep 17 00:00:00 2001 From: huanghai4 Date: Wed, 9 Oct 2019 13:08:05 +0800 Subject: [PATCH 4/4] 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 3ee41a9a97..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}); + 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; +}