Skip to content

Commit 2e4ab55

Browse files
committed
chore: more debug console
1 parent 2f7188c commit 2e4ab55

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

bin/cli.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ cli
2626
console.log('[DEBUG] Working directory:', process.cwd())
2727
}
2828

29-
setHooksFromConfig(process.cwd())
29+
console.log('setHooksFromConfig', { configFile: configPath })
30+
31+
setHooksFromConfig(process.cwd(), { configFile: configPath })
3032
console.log('[INFO] Successfully set all git hooks')
3133
}
3234
catch (err) {

src/git-hooks.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,25 +194,35 @@ export function setHooksFromConfig(projectRootPath: string = process.cwd(), opti
194194
if (!config || Object.keys(config).length === 0)
195195
throw new Error('[ERROR] Config was not found! Please add `.git-hooks.config.{ts,js,mjs,cjs,mts,cts,json}` or `git-hooks.config.{ts,js,mjs,cjs,mts,cts,json}` or the `git-hooks` entry in package.json.\r\nCheck README for details')
196196

197+
198+
console.log('setHooksFromConfig config', config)
197199
// Only validate hook names that aren't options
198200
const hookKeys = Object.keys(config).filter(key => key !== 'preserveUnused' && key !== 'verbose')
201+
202+
console.log('hookKeys', hookKeys)
199203
const isValidConfig = hookKeys.every(key => VALID_GIT_HOOKS.includes(key as typeof VALID_GIT_HOOKS[number]))
200204

205+
console.log('isValidConfig', isValidConfig)
206+
201207
if (!isValidConfig)
202208
throw new Error('[ERROR] Config was not in correct format. Please check git hooks or options name')
203209

204210
const preserveUnused = Array.isArray(config.preserveUnused) ? config.preserveUnused : config.preserveUnused ? VALID_GIT_HOOKS : []
205211

206212
for (const hook of VALID_GIT_HOOKS) {
213+
console.log('hook', hook)
207214
if (Object.prototype.hasOwnProperty.call(config, hook)) {
215+
console.log('hook in config')
208216
if (!config[hook])
209217
throw new Error(`[ERROR] Command for ${hook} is not set`)
210218

211219
console.log(`Hook ${hook}: `, config[hook])
212220
_setHook(hook, config[hook], projectRootPath)
213221
}
214-
else if (!preserveUnused.includes(hook))
222+
else if (!preserveUnused.includes(hook)) {
223+
console.log('Remove hook', hook)
215224
_removeHook(hook, projectRootPath)
225+
}
216226
}
217227
}
218228

0 commit comments

Comments
 (0)