mirror of
https://github.com/go-gitea/gitea
synced 2026-02-03 10:00:37 +00:00
Fixes: https://github.com/go-gitea/gitea/issues/22618 `go-enry`'s `IsVendor` function marks git paths (`.gitignore`, `.gitattributes`, `.gitmodules`), github/gitea paths (`.github/`, `.gitea/`) as "vendored" for GitHub Linguist language statistics. This causes these files to incorrectly display the "Vendored" tag in diff views. Override `go-enry`'s detection for these specific cases while preserving its behavior for actual vendor directories. --------- Signed-off-by: silverwind <me@silverwind.io> Signed-off-by: wxiaoguang <wxiaoguang@gmail.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: silverwind <115237+silverwind@users.noreply.github.com> Co-authored-by: silverwind <me@silverwind.io> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
32 lines
751 B
Go
32 lines
751 B
Go
// Copyright 2021 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package analyze
|
|
|
|
import (
|
|
"path"
|
|
"strings"
|
|
|
|
"github.com/go-enry/go-enry/v2"
|
|
)
|
|
|
|
// IsVendor returns whether the path is a vendor path.
|
|
// It uses go-enry's IsVendor function but overrides its detection for certain
|
|
// special cases that shouldn't be marked as vendored in the diff view.
|
|
func IsVendor(treePath string) bool {
|
|
if !enry.IsVendor(treePath) {
|
|
return false
|
|
}
|
|
|
|
// Override detection for single files
|
|
basename := path.Base(treePath)
|
|
switch basename {
|
|
case ".gitignore", ".gitattributes", ".gitmodules":
|
|
return false
|
|
}
|
|
if strings.HasPrefix(treePath, ".github/") || strings.HasPrefix(treePath, ".gitea/") {
|
|
return false
|
|
}
|
|
return true
|
|
}
|