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:
Ismar
2026-01-13 02:29:57 +01:00
committed by GitHub
parent a8f7c21a74
commit d931f81427
4 changed files with 53 additions and 26 deletions

View File

@@ -24,12 +24,12 @@ func TestDetectExistingHooks(t *testing.T) {
hooksDir := filepath.Join(gitDirPath, "hooks")
tests := []struct {
name string
setupHook string
hookContent string
wantExists bool
wantIsBdHook bool
wantIsPreCommit bool
name string
setupHook string
hookContent string
wantExists bool
wantIsBdHook bool
wantIsPreCommitFramework bool
}{
{
name: "no hook",
@@ -44,11 +44,11 @@ func TestDetectExistingHooks(t *testing.T) {
wantIsBdHook: true,
},
{
name: "pre-commit framework hook",
setupHook: "pre-commit",
hookContent: "#!/bin/sh\n# pre-commit framework\npre-commit run",
wantExists: true,
wantIsPreCommit: true,
name: "pre-commit framework hook",
setupHook: "pre-commit",
hookContent: "#!/bin/sh\n# pre-commit framework\npre-commit run",
wantExists: true,
wantIsPreCommitFramework: true,
},
{
name: "custom hook",
@@ -90,8 +90,8 @@ func TestDetectExistingHooks(t *testing.T) {
if found.isBdHook != tt.wantIsBdHook {
t.Errorf("isBdHook = %v, want %v", found.isBdHook, tt.wantIsBdHook)
}
if found.isPreCommit != tt.wantIsPreCommit {
t.Errorf("isPreCommit = %v, want %v", found.isPreCommit, tt.wantIsPreCommit)
if found.isPreCommitFramework != tt.wantIsPreCommitFramework {
t.Errorf("isPreCommitFramework = %v, want %v", found.isPreCommitFramework, tt.wantIsPreCommitFramework)
}
})
}