Skip to content

Commit

Permalink
Fix gitignore matching for root directory (#626)
Browse files Browse the repository at this point in the history
Was representing the relative root of the repo as `./.` which, if the
.gitignore file matched `.*`, caused the whole directory to be ignored.
  • Loading branch information
michaelkedar authored Nov 1, 2023
1 parent 5a02f6c commit 130254c
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pkg/osvscanner/osvscanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,10 @@ func (m *gitIgnoreMatcher) match(absPath string, isDir bool) (bool, error) {
return false, err
}
// must prepend "." to paths because of how gitignore.ReadPatterns interprets paths
pathInGitSep := append([]string{"."}, strings.Split(pathInGit, string(filepath.Separator))...)
pathInGitSep := []string{"."}
if pathInGit != "." { // don't make the path "./."
pathInGitSep = append(pathInGitSep, strings.Split(pathInGit, string(filepath.Separator))...)
}

return m.matcher.Match(pathInGitSep, isDir), nil
}
Expand Down

0 comments on commit 130254c

Please sign in to comment.