Skip to content

Commit beec696

Browse files
committed
Make skips work properly
1 parent d42fe69 commit beec696

File tree

2 files changed

+24
-11
lines changed

2 files changed

+24
-11
lines changed

internal/hooks/validate_skip.go

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"io"
88
"path/filepath"
99

10+
"github.com/Veraticus/cc-tools/internal/shared"
1011
"github.com/Veraticus/cc-tools/internal/skipregistry"
1112
)
1213

@@ -101,31 +102,43 @@ func checkSkipsFromInput(ctx context.Context, stdinData []byte, debug bool, stde
101102
}
102103

103104
// Get directory from file path
104-
dir := filepath.Dir(filePath)
105+
fileDir := filepath.Dir(filePath)
106+
107+
// Find the project root - same as we do for discovering lint/test commands
108+
projectRoot, err := shared.FindProjectRoot(fileDir, nil)
109+
if err != nil {
110+
if debug {
111+
_, _ = fmt.Fprintf(stderr, "Failed to find project root: %v\n", err)
112+
}
113+
// If we can't find project root, check the file's directory as fallback
114+
projectRoot = fileDir
115+
}
105116

106117
// Convert to absolute path
107-
absDir, err := filepath.Abs(dir)
118+
absProjectRoot, err := filepath.Abs(projectRoot)
108119
if err != nil {
109120
if debug {
110121
_, _ = fmt.Fprintf(stderr, "Failed to get absolute path: %v\n", err)
111122
}
112123
return false, false
113124
}
114125

115-
// Check skip registry
126+
// Check skip registry for the project root
116127
storage := skipregistry.DefaultStorage()
117128
registry := skipregistry.NewRegistry(storage)
118129

119-
skipLint, _ := registry.IsSkipped(ctx, skipregistry.DirectoryPath(absDir), skipregistry.SkipTypeLint)
120-
skipTest, _ := registry.IsSkipped(ctx, skipregistry.DirectoryPath(absDir), skipregistry.SkipTypeTest)
130+
skipLint, _ := registry.IsSkipped(ctx, skipregistry.DirectoryPath(absProjectRoot), skipregistry.SkipTypeLint)
131+
skipTest, _ := registry.IsSkipped(ctx, skipregistry.DirectoryPath(absProjectRoot), skipregistry.SkipTypeTest)
121132

122133
if debug {
123-
_, _ = fmt.Fprintf(stderr, "Checking skips for directory: %s\n", absDir)
134+
_, _ = fmt.Fprintf(stderr, "File: %s\n", filePath)
135+
_, _ = fmt.Fprintf(stderr, "Project root: %s\n", absProjectRoot)
136+
_, _ = fmt.Fprintf(stderr, "Checking skips for project root: %s\n", absProjectRoot)
124137
if skipLint {
125-
_, _ = fmt.Fprintf(stderr, "Skipping lint for directory: %s\n", absDir)
138+
_, _ = fmt.Fprintf(stderr, "Skipping lint for project: %s\n", absProjectRoot)
126139
}
127140
if skipTest {
128-
_, _ = fmt.Fprintf(stderr, "Skipping test for directory: %s\n", absDir)
141+
_, _ = fmt.Fprintf(stderr, "Skipping test for project: %s\n", absProjectRoot)
129142
}
130143
}
131144

internal/hooks/validate_skip_integration_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func TestValidateWithSkipCheck_RealIntegration(t *testing.T) {
5555
debug: true,
5656
wantExitCode: 2, // Shows validation pass message even with skips
5757
wantInStderr: []string{
58-
"Checking skips for directory",
58+
"Checking skips for project root",
5959
},
6060
},
6161
}
@@ -130,7 +130,7 @@ func TestCheckSkipsFromInput_Unit(t *testing.T) {
130130
}`,
131131
debug: true,
132132
wantLogs: []string{
133-
"Checking skips for directory: /tmp",
133+
"Checking skips for project root: /tmp",
134134
},
135135
},
136136
{
@@ -162,7 +162,7 @@ func TestCheckSkipsFromInput_Unit(t *testing.T) {
162162
}`,
163163
debug: true,
164164
wantLogs: []string{
165-
"Checking skips for directory: /home/user/project/src",
165+
"Checking skips for project root: /home/user/project/src",
166166
},
167167
},
168168
}

0 commit comments

Comments
 (0)