diff --git a/cmd/bd/doctor/git.go b/cmd/bd/doctor/git.go index 18ef9170..595a7088 100644 --- a/cmd/bd/doctor/git.go +++ b/cmd/bd/doctor/git.go @@ -276,22 +276,9 @@ func CheckSyncBranchHookCompatibility(path string) DoctorCheck { gitDir = filepath.Join(path, gitDir) } - // Check for pre-push hook in standard location or shared hooks location - var hookPath string - - // First check if core.hooksPath is configured (shared hooks) - hooksPathCmd := exec.Command("git", "config", "--get", "core.hooksPath") - hooksPathCmd.Dir = path - if hooksPathOutput, err := hooksPathCmd.Output(); err == nil { - sharedHooksDir := strings.TrimSpace(string(hooksPathOutput)) - if !filepath.IsAbs(sharedHooksDir) { - sharedHooksDir = filepath.Join(path, sharedHooksDir) - } - hookPath = filepath.Join(sharedHooksDir, "pre-push") - } else { - // Use standard .git/hooks location - hookPath = filepath.Join(gitDir, "hooks", "pre-push") - } + // Use standard .git/hooks location for consistency with CheckGitHooks (issue #799) + // Note: core.hooksPath is intentionally NOT checked here to match CheckGitHooks behavior. + hookPath := filepath.Join(gitDir, "hooks", "pre-push") hookContent, err := os.ReadFile(hookPath) // #nosec G304 - path is controlled if err != nil { diff --git a/cmd/bd/doctor/git_test.go b/cmd/bd/doctor/git_test.go index cd6682e3..fe38d13d 100644 --- a/cmd/bd/doctor/git_test.go +++ b/cmd/bd/doctor/git_test.go @@ -744,16 +744,20 @@ func TestCheckSyncBranchHookCompatibility_OldHookFormat(t *testing.T) { expectedStatus: "warning", expectInMsg: "Could not determine", }, + // Note: core.hooksPath is NOT respected by this check (or CheckGitHooks) + // Both functions use .git/hooks/ for consistency. This is a known limitation. + // A future fix could make both respect core.hooksPath. { - name: "hook in shared hooks directory (core.hooksPath)", + name: "hook in standard location with core.hooksPath set elsewhere", setup: func(t *testing.T, dir string) { setupGitRepoInDir(t, dir) - // create shared hooks directory - sharedHooksDir := filepath.Join(dir, ".git-hooks") - os.MkdirAll(sharedHooksDir, 0755) + // Put hook in standard .git/hooks location + gitDir := filepath.Join(dir, ".git") + hooksDir := filepath.Join(gitDir, "hooks") + os.MkdirAll(hooksDir, 0755) hookContent := "#!/bin/sh\n# bd-hooks-version: 0.29.0\nbd sync\n" - os.WriteFile(filepath.Join(sharedHooksDir, "pre-push"), []byte(hookContent), 0755) - // configure core.hooksPath + os.WriteFile(filepath.Join(hooksDir, "pre-push"), []byte(hookContent), 0755) + // configure core.hooksPath (ignored by this check) cmd := exec.Command("git", "config", "core.hooksPath", ".git-hooks") cmd.Dir = dir _ = cmd.Run()