From 584d8ef75fc0c794d8ee4f7f39605eca737907bc Mon Sep 17 00:00:00 2001 From: Copilot <198982749+Copilot@users.noreply.github.com> Date: Sun, 1 Feb 2026 10:35:51 +0000 Subject: [PATCH] Fix incorrect vendored detections (#36508) 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 Signed-off-by: wxiaoguang 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 Co-authored-by: wxiaoguang --- AGENTS.md | 7 +++++-- modules/analyze/vendor.go | 24 +++++++++++++++++++++--- modules/analyze/vendor_test.go | 9 +++++++++ 3 files changed, 35 insertions(+), 5 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index eda1abeeeb..f4414bfc8c 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -1,7 +1,10 @@ # Instructions for agents - Use `make help` to find available development targets -- Before committing go code changes, run `make fmt` +- Use the latest Golang stable release when working on Go code +- Use the latest Node.js LTS release when working on TypeScript code +- Before committing `.go` changes, run `make fmt` to format, and run `make lint-go` to lint +- Before committing `.ts` changes, run `make lint-js` to lint - Before committing `go.mod` changes, run `make tidy` - Before committing new `.go` files, add the current year into the copyright header -- Before committing files, removed any trailing whitespace +- Before committing any files, remove all trailing whitespace from source code lines diff --git a/modules/analyze/vendor.go b/modules/analyze/vendor.go index adcca923dd..f3e75f535f 100644 --- a/modules/analyze/vendor.go +++ b/modules/analyze/vendor.go @@ -4,10 +4,28 @@ package analyze import ( + "path" + "strings" + "github.com/go-enry/go-enry/v2" ) -// IsVendor returns whether or not path is a vendor path. -func IsVendor(path string) bool { - return enry.IsVendor(path) +// 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 } diff --git a/modules/analyze/vendor_test.go b/modules/analyze/vendor_test.go index 02a51d4c8f..6efb825de6 100644 --- a/modules/analyze/vendor_test.go +++ b/modules/analyze/vendor_test.go @@ -14,6 +14,7 @@ func TestIsVendor(t *testing.T) { path string want bool }{ + // Original go-enry test cases {"cache/", true}, {"random/cache/", true}, {"cache", false}, @@ -34,6 +35,14 @@ func TestIsVendor(t *testing.T) { {"a/docs/_build/", true}, {"a/dasdocs/_build-vsdoc.js", true}, {"a/dasdocs/_build-vsdoc.j", false}, + + // Override: Git/GitHub/Gitea-related paths should NOT be detected as vendored + {".gitignore", false}, + {".gitattributes", false}, + {".gitmodules", false}, + {"src/.gitignore", false}, + {".github/workflows/ci.yml", false}, + {".gitea/workflows/ci.yml", false}, } for _, tt := range tests { t.Run(tt.path, func(t *testing.T) {