There is a bug in the install script when the gitRoot is not the same as the projectRoot. My Project looks like:
- .git
- npm_project_1
- npm_project_2
- package.json
- <- executing
npx simple-git-hooks here
result:
- .git
- npm_project_1
- npm_project_2
expectation:
- .git
- npm_project_1
- npm_project_2
To fix this you should get the gitRoot in the _getHooksDirPath:
function _getHooksDirPath(projectRoot) {
const gitRoot = getGitProjectRoot(projectRoot)
if (!gitRoot) {
console.info('[INFO] No `.git` root folder found, skipping')
return
}
const defaultHooksDirPath = path.join(gitRoot, 'hooks')
try {
const customHooksDirPath = execSync('git config core.hooksPath', {
cwd: projectRoot,
encoding: 'utf8'
}).trim()
if (!customHooksDirPath) {
return defaultHooksDirPath
}
return path.isAbsolute(customHooksDirPath)
? customHooksDirPath
: path.resolve(projectRoot, customHooksDirPath)
} catch {
return defaultHooksDirPath
}
}
and skipping in _setHook and _removeHook
const hookDirectory = _getHooksDirPath(projectRoot)
if (!hookDirectory) {
console.info('[INFO] No hooks folder found, skipping')
return
}
and the path to the npm project must be set into the hook call:
from
to
npm run git:pre-commit --prefix ./npm_project_2
There is a bug in the install script when the gitRoot is not the same as the projectRoot. My Project looks like:
npx simple-git-hookshereresult:
expectation:
To fix this you should get the gitRoot in the
_getHooksDirPath:and skipping in
_setHookand_removeHookand the path to the npm project must be set into the hook call:
from
to