Skip to content

Commit 79114d1

Browse files
committed
only remove some hooks that are not in preserveUnused
1 parent 0433a04 commit 79114d1

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

simple-git-hooks.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,9 +210,19 @@ function _setHook(hook, command, projectRoot=process.cwd()) {
210210
/**
211211
* Deletes all git hooks
212212
* @param {string} projectRoot
213+
* @param {string[]} [argv]
213214
*/
214-
function removeHooks(projectRoot=process.cwd()) {
215-
for (let configEntry of VALID_GIT_HOOKS) {
215+
function removeHooks(projectRoot = process.cwd(), argv = process.argv) {
216+
const customConfigPath = _getCustomConfigPath(argv)
217+
const config = _getConfig(projectRoot, customConfigPath)
218+
219+
if (!config) {
220+
throw ('[ERROR] Config was not found! Please add `.simple-git-hooks.js` or `simple-git-hooks.js` or `.simple-git-hooks.json` or `simple-git-hooks.json` or `simple-git-hooks` entry in package.json.\r\nCheck README for details')
221+
}
222+
223+
const preserveUnused = Array.isArray(config.preserveUnused) ? config.preserveUnused : []
224+
const needRemoveHooks = VALID_GIT_HOOKS.filter(hook => !preserveUnused.includes(hook))
225+
for (let configEntry of needRemoveHooks) {
216226
_removeHook(configEntry, projectRoot)
217227
}
218228
}

0 commit comments

Comments
 (0)