feat: add prek support as pre-commit alternative (#1040)
prek (https://prek.j178.dev) is a faster Rust-based alternative to pre-commit that uses the same .pre-commit-config.yaml config files. Changes: - Add prek detection pattern in hookManagerPatterns (before pre-commit to ensure correct detection since prek hooks may contain 'pre-commit') - Handle prek in checkManagerBdIntegration using same config parser - Update init_git_hooks.go to recognize prek-installed hooks - Rename isPreCommit field to isPreCommitFramework for clarity - Use regex pattern matching all pre-commit/prek signatures consistently - Add test cases for prek run and prek hook-impl signatures Co-authored-by: Ismar Iljazovic <ismar@gmail.com>
This commit is contained in:
@@ -27,6 +27,8 @@ type hookManagerConfig struct {
|
||||
|
||||
// hookManagerConfigs defines external hook managers in priority order.
|
||||
// See https://lefthook.dev/configuration/ for lefthook config options.
|
||||
// Note: prek (https://prek.j178.dev) uses the same config files as pre-commit
|
||||
// but is a faster Rust-based alternative. We detect both from the same config.
|
||||
var hookManagerConfigs = []hookManagerConfig{
|
||||
{"lefthook", []string{
|
||||
// YAML variants
|
||||
@@ -38,6 +40,7 @@ var hookManagerConfigs = []hookManagerConfig{
|
||||
"lefthook.json", ".lefthook.json", ".config/lefthook.json",
|
||||
}},
|
||||
{"husky", []string{".husky"}},
|
||||
// pre-commit and prek share the same config files; we detect which is active from git hooks
|
||||
{"pre-commit", []string{".pre-commit-config.yaml", ".pre-commit-config.yml"}},
|
||||
{"overcommit", []string{".overcommit.yml"}},
|
||||
{"yorkie", []string{".yorkie"}},
|
||||
@@ -92,9 +95,12 @@ type hookManagerPattern struct {
|
||||
}
|
||||
|
||||
// hookManagerPatterns identifies which hook manager installed a git hook (in priority order).
|
||||
// Note: prek must come before pre-commit since prek hooks may also contain "pre-commit" in paths.
|
||||
var hookManagerPatterns = []hookManagerPattern{
|
||||
{"lefthook", regexp.MustCompile(`(?i)lefthook`)},
|
||||
{"husky", regexp.MustCompile(`(?i)(\.husky|husky\.sh)`)},
|
||||
// prek (https://prek.j178.dev) - faster Rust-based pre-commit alternative
|
||||
{"prek", regexp.MustCompile(`(?i)(prek\s+run|prek\s+hook-impl)`)},
|
||||
{"pre-commit", regexp.MustCompile(`(?i)(pre-commit\s+run|\.pre-commit-config|INSTALL_PYTHON|PRE_COMMIT)`)},
|
||||
{"simple-git-hooks", regexp.MustCompile(`(?i)simple-git-hooks`)},
|
||||
}
|
||||
@@ -470,8 +476,13 @@ func checkManagerBdIntegration(name, path string) *HookIntegrationStatus {
|
||||
return CheckLefthookBdIntegration(path)
|
||||
case "husky":
|
||||
return CheckHuskyBdIntegration(path)
|
||||
case "pre-commit":
|
||||
return CheckPrecommitBdIntegration(path)
|
||||
case "pre-commit", "prek":
|
||||
// prek uses the same config format as pre-commit
|
||||
status := CheckPrecommitBdIntegration(path)
|
||||
if status != nil {
|
||||
status.Manager = name // Use the actual detected manager name
|
||||
}
|
||||
return status
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user