mirror of
https://github.com/go-gitea/gitea.git
synced 2026-08-27 18:53:52 +00:00
fix: recognize linguist language aliases (#39135)
Co-authored-by: loveulvu <ax9inl@google.com>
This commit is contained in:
@@ -114,6 +114,10 @@ func GetLanguageStats(ctx context.Context, repo *git.Repository, commitID string
|
||||
if hasLanguage := attrs.GetLanguage(); hasLanguage.Value() != "" {
|
||||
language := hasLanguage.Value()
|
||||
|
||||
if canonicalLanguage, ok := enry.GetLanguageByAlias(language); ok {
|
||||
language = canonicalLanguage
|
||||
}
|
||||
|
||||
// group languages, such as Pug -> HTML; SCSS -> CSS
|
||||
group := enry.GetLanguageGroup(language)
|
||||
if len(group) != 0 {
|
||||
|
||||
@@ -225,6 +225,17 @@ func TestLinguist(t *testing.T) {
|
||||
},
|
||||
ExpectedLanguageOrder: []string{"YAML"},
|
||||
},
|
||||
// case 15: linguist-language alias should resolve to its canonical language
|
||||
{
|
||||
GitAttributesContent: "*.cpp linguist-language=golang",
|
||||
FilesToAdd: []*files_service.ChangeRepoFile{
|
||||
{
|
||||
TreePath: "cplusplus.cpp",
|
||||
ContentReader: strings.NewReader(cppContent),
|
||||
},
|
||||
},
|
||||
ExpectedLanguageOrder: []string{"Go"},
|
||||
},
|
||||
}
|
||||
|
||||
for i, c := range cases {
|
||||
|
||||
Reference in New Issue
Block a user