Skip to content

Commit 904bb51

Browse files
wesmclaude
andcommitted
Use cross-platform path checks in GetHooksPath test
- Normalize path with filepath.Clean before suffix comparison - Use filepath.Rel instead of strings.HasPrefix for containment check Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 4c3d8c6 commit 904bb51

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

internal/git/git_test.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,16 @@ func TestGetHooksPath(t *testing.T) {
2929
t.Errorf("hooks path should be absolute, got: %s", hooksPath)
3030
}
3131

32-
// Should end with .git/hooks (or .git\hooks on Windows)
32+
// Should end with .git/hooks (normalize for cross-platform)
33+
cleanPath := filepath.Clean(hooksPath)
3334
expectedSuffix := filepath.Join(".git", "hooks")
34-
if !strings.HasSuffix(hooksPath, expectedSuffix) {
35-
t.Errorf("hooks path should end with %s, got: %s", expectedSuffix, hooksPath)
35+
if !strings.HasSuffix(cleanPath, expectedSuffix) {
36+
t.Errorf("hooks path should end with %s, got: %s", expectedSuffix, cleanPath)
3637
}
3738

38-
// Should be under tmpDir
39-
if !strings.HasPrefix(hooksPath, tmpDir) {
39+
// Should be under tmpDir (use filepath.Rel for robust check)
40+
rel, err := filepath.Rel(tmpDir, hooksPath)
41+
if err != nil || strings.HasPrefix(rel, ".."+string(filepath.Separator)) || rel == ".." {
4042
t.Errorf("hooks path should be under %s, got: %s", tmpDir, hooksPath)
4143
}
4244
})

0 commit comments

Comments
 (0)