Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/top level #784

Merged
merged 5 commits into from
Oct 21, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion @commitlint/top-level/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,21 @@ 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;
}

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;
}