-
Notifications
You must be signed in to change notification settings - Fork 53
Open
Description
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
- package.json
- npm_project_2
- package.json
- <- executing
npx simple-git-hooks
here
result:
- .git
- npm_project_1
- package.json
- npm_project_2
- .git
- hooks
- pre-commit
- hooks
- package.json
- .git
expectation:
- .git
- hooks
- pre-commit
- hooks
- npm_project_1
- package.json
- npm_project_2
- package.json
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
npm run git:pre-commit
to
npm run git:pre-commit --prefix ./npm_project_2
Metadata
Metadata
Assignees
Labels
No labels