Skip to content

Commit

Permalink
feat: add support for git submodules
Browse files Browse the repository at this point in the history
No test included in this commit as this would require an update to
@commitlint/test to support submodules.
  • Loading branch information
ericcornelissen authored and marionebl committed Jan 27, 2019
1 parent 058e83a commit cc575fa
Showing 1 changed file with 22 additions and 4 deletions.
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;
}

0 comments on commit cc575fa

Please sign in to comment.