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

feat: add support for git submodules #469

Merged
merged 2 commits into from
Jan 27, 2019
Merged
Changes from 1 commit
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
26 changes: 22 additions & 4 deletions @commitlint/read/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,29 @@ async function getEditCommit(cwd, edit) {
throw new TypeError(`Could not find git root from ${cwd}`);
}

const editFilePath =
typeof edit === 'string'
? path.resolve(top, edit)
: path.join(top, '.git/COMMIT_EDITMSG');
const editFilePath = await getEditFilePath(top, edit);

const editFile = await sander.readFile(editFilePath);
return [`${editFile.toString('utf-8')}\n`];
}

// Get path to recently edited commit message file
// (top: string, edit: any) => Promise<String>
async function getEditFilePath(top, edit) {
let editFilePath;
if (typeof edit === 'string') {
editFilePath = path.resolve(top, edit);
} else {
const dotgitPath = path.join(top, '.git');
const dotgitStats = sander.lstatSync(dotgitPath);
if (dotgitStats.isDirectory()) {
editFilePath = path.join(top, '.git/COMMIT_EDITMSG');
} else {
const gitFile = await sander.readFile(dotgitPath, 'utf8');
const relativeGitPath = gitFile.replace('gitdir: ', '').replace('\n', '');
editFilePath = path.join(top, relativeGitPath, 'COMMIT_EDITMSG');
}
}

return editFilePath;
}