From 3e121808a270a103161821fbf87e458842251fb6 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 is 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: