@@ -40,6 +40,8 @@ import (
4040 "golang.org/x/sync/errgroup"
4141)
4242
43+ const currentDir = "./"
44+
4345// Check checks the license headers of the specified paths/globs.
4446func Check (config * ConfigHeader , result * Result ) error {
4547 fileList , err := listFiles (config )
@@ -67,13 +69,13 @@ func Check(config *ConfigHeader, result *Result) error {
6769func listFiles (config * ConfigHeader ) ([]string , error ) {
6870 var fileList []string
6971
70- repo , err := git .PlainOpen ("./" )
72+ repo , err := git .PlainOpen (currentDir )
7173
7274 if err != nil { // we're not in a Git workspace, fallback to glob paths
7375 var localFileList []string
7476 for _ , pattern := range config .Paths {
7577 if pattern == "." {
76- pattern = "./"
78+ pattern = currentDir
7779 }
7880 files , err := doublestar .Glob (pattern )
7981 if err != nil {
@@ -156,12 +158,32 @@ func listFiles(config *ConfigHeader) ([]string, error) {
156158func MatchPaths (file string , patterns []string ) bool {
157159 for _ , pattern := range patterns {
158160 if pattern == "." {
159- pattern = "./"
161+ pattern = currentDir
160162 }
161163 matched , err := doublestar .Match (pattern , file )
162164 if err == nil && matched {
163165 return true
164166 }
167+ // Fallback for directory patterns (e.g., "pkg/header/" or "pkg/header")
168+ // to behave consistently with tryMatchPatten in config.go.
169+ // Ensure that pattern ends with a path separator so it clearly denotes a directory.
170+ if strings .HasSuffix (pattern , "/" ) ||
171+ strings .HasSuffix (pattern , string (os .PathSeparator )) {
172+ dirPattern := strings .TrimRight (pattern , "/" )
173+ // Match if file's directory name equals pattern (exact directory match)
174+ if stat , err := os .Stat (file ); err == nil {
175+ if stat .Name () == dirPattern {
176+ return true
177+ }
178+ }
179+ // Match if file is under the directory (prefix match)
180+ // Normalize both paths to use '/' so prefix matching is consistent across platforms.
181+ normalizedDir := strings .ReplaceAll (pattern , "\\ " , "/" )
182+ normalizedFile := strings .ReplaceAll (file , "\\ " , "/" )
183+ if strings .HasPrefix (normalizedFile , normalizedDir ) {
184+ return true
185+ }
186+ }
165187 }
166188 return false
167189}
0 commit comments