Skip to content

Commit 3005efa

Browse files
loveulvuloveulvu
andauthored
fix: recognize linguist language aliases (#39135)
Co-authored-by: loveulvu <ax9inl@google.com>
1 parent e21c377 commit 3005efa

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

modules/git/languagestats/language_stats_get.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,10 @@ func GetLanguageStats(ctx context.Context, repo *git.Repository, commitID string
114114
if hasLanguage := attrs.GetLanguage(); hasLanguage.Value() != "" {
115115
language := hasLanguage.Value()
116116

117+
if canonicalLanguage, ok := enry.GetLanguageByAlias(language); ok {
118+
language = canonicalLanguage
119+
}
120+
117121
// group languages, such as Pug -> HTML; SCSS -> CSS
118122
group := enry.GetLanguageGroup(language)
119123
if len(group) != 0 {

tests/integration/linguist_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,17 @@ func TestLinguist(t *testing.T) {
225225
},
226226
ExpectedLanguageOrder: []string{"YAML"},
227227
},
228+
// case 15: linguist-language alias should resolve to its canonical language
229+
{
230+
GitAttributesContent: "*.cpp linguist-language=golang",
231+
FilesToAdd: []*files_service.ChangeRepoFile{
232+
{
233+
TreePath: "cplusplus.cpp",
234+
ContentReader: strings.NewReader(cppContent),
235+
},
236+
},
237+
ExpectedLanguageOrder: []string{"Go"},
238+
},
228239
}
229240

230241
for i, c := range cases {

0 commit comments

Comments
 (0)