From 253a5498ae923d3652769bed52fbde562ae72beb Mon Sep 17 00:00:00 2001 From: James Hilliard Date: Fri, 26 Jul 2024 03:15:53 -0600 Subject: [PATCH] Prevent matching bogus parent gitignores If our project root directory is matched by an exclude pattern we should assume the pattern is invalid as our project root is likely in an ignored build directory of another project. --- backend/src/hatchling/builders/config.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/backend/src/hatchling/builders/config.py b/backend/src/hatchling/builders/config.py index da4a9f9b9..d5b6b27dc 100644 --- a/backend/src/hatchling/builders/config.py +++ b/backend/src/hatchling/builders/config.py @@ -883,6 +883,11 @@ def load_vcs_exclusion_patterns(self) -> list[str]: if glob_mode: patterns.append(line) + # validate project root is not excluded by vcs + exclude_spec = pathspec.GitIgnoreSpec.from_lines(patterns) + if exclude_spec.match_file(self.root): + return [] + return patterns def normalize_build_directory(self, build_directory: str) -> str: