diff --git a/pkg/linguist/linguist.go b/pkg/linguist/linguist.go index ac35110..7890a82 100644 --- a/pkg/linguist/linguist.go +++ b/pkg/linguist/linguist.go @@ -134,9 +134,14 @@ func initLinguistAttributes(dir string) error { isIgnored = func(filename string) bool { for _, p := range ignore { - if m, _ := filepath.Match(p, strings.TrimPrefix(filename, dir+string(filepath.Separator))); m { + cleanPath, err := filepath.Rel(dir, filename) + if err != nil { + log.Debugf("could not get relative path: %v", err) + return false + } + if m, _ := filepath.Match(p, cleanPath); m { for _, e := range except { - if m, _ := filepath.Match(e, strings.TrimPrefix(filename, dir+string(filepath.Separator))); m { + if m, _ := filepath.Match(e, cleanPath); m { return false } } @@ -147,7 +152,12 @@ func initLinguistAttributes(dir string) error { } isDetectedInGitAttributes = func(filename string) string { for p, lang := range detected { - if m, _ := filepath.Match(p, strings.TrimPrefix(filename, dir+string(filepath.Separator))); m { + cleanPath, err := filepath.Rel(dir, filename) + if err != nil { + log.Debugf("could not get relative path: %v", err) + return "" + } + if m, _ := filepath.Match(p, cleanPath); m { return lang } } diff --git a/pkg/linguist/linguist_test.go b/pkg/linguist/linguist_test.go index 5b3012f..27d1d34 100644 --- a/pkg/linguist/linguist_test.go +++ b/pkg/linguist/linguist_test.go @@ -56,6 +56,16 @@ func TestGitAttributes(t *testing.T) { } } +func TestIsIgnored(t *testing.T) { + path := filepath.Join("testdata", "app-documentation") + // populate isIgnored + ProcessDir(path) + ignorePath := filepath.Join(path, "docs") + if !isIgnored(ignorePath) { + t.Errorf("expected dir '%s' to be ignored", ignorePath) + } +} + func TestGetAlias(t *testing.T) { testcases := map[string]string{ "maven pom": "Java",