diff --git a/find/find.go b/find/find.go index 0d0fd19..1f11cee 100644 --- a/find/find.go +++ b/find/find.go @@ -34,38 +34,46 @@ func shouldFilter(conf *config.Config, match *file.Change) bool { return false } -func checkHidden(conf *config.Config, path string) (bool, error) { - if !conf.IncludeHidden { - isHidden, err := checkIfHidden(filepath.Base(path), "") - if err != nil { - return false, err - } +// skipFileIfHidden checks if a file is hidden, and if so, returns a boolean +// confirming whether it should be skipped or not. +func skipFileIfHidden( + path string, + filesAndDirPaths []string, + includeHidden bool, +) (bool, error) { + if includeHidden { + return false, nil + } - if isHidden { - // Ensure that explicitly included file arguments are not affected - entryAbsPath, err := filepath.Abs(path) - if err != nil { - return false, err - } + isHidden, err := checkIfHidden(filepath.Base(path), "") + if err != nil { + return false, err + } - shouldSkip := true + if !isHidden { + return false, nil + } - for _, pathArg := range conf.FilesAndDirPaths { - argAbsPath, err := filepath.Abs(pathArg) - if err != nil { - return false, err - } + entryAbsPath, err := filepath.Abs(path) + if err != nil { + return false, err + } - if strings.EqualFold(entryAbsPath, argAbsPath) { - shouldSkip = false - } - } + skipFile := true - return shouldSkip, nil + // Ensure that explicitly included file arguments are not affected + for _, pathArg := range filesAndDirPaths { + argAbsPath, err := filepath.Abs(pathArg) + if err != nil { + return false, err + } + + if strings.EqualFold(entryAbsPath, argAbsPath) { + skipFile = false } } - return false, nil + return skipFile, nil } // isMaxDepth reports whether the configured max depth has been reached. @@ -145,7 +153,11 @@ func searchPaths(conf *config.Config) ([]*file.Change, error) { return nil } - skipHidden, herr := checkHidden(conf, currentPath) + skipHidden, herr := skipFileIfHidden( + currentPath, + conf.FilesAndDirPaths, + conf.IncludeHidden, + ) if herr != nil { return herr } @@ -158,10 +170,6 @@ func searchPaths(conf *config.Config) ([]*file.Change, error) { return nil } - if currentPath == ".git" { - return fs.SkipDir - } - if isMaxDepth(rootPath, currentPath, maxDepth) { return fs.SkipDir }