зеркало из https://github.com/Azure/draft-classic.git
use filepath.Rel for portability
This commit is contained in:
Родитель
2a348d11d8
Коммит
55e0ddea10
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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",
|
||||
|
|
Загрузка…
Ссылка в новой задаче