From 0f77bc130c944ae3a027de49d63fe15efdea4a0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Fri, 27 Mar 2026 15:00:04 +0100 Subject: [PATCH] Limit locating ignore files to both kind of repositories --- backend/src/hatchling/builders/config.py | 4 ++-- backend/src/hatchling/utils/fs.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/backend/src/hatchling/builders/config.py b/backend/src/hatchling/builders/config.py index f33ba4ef7..8a95220db 100644 --- a/backend/src/hatchling/builders/config.py +++ b/backend/src/hatchling/builders/config.py @@ -752,11 +752,11 @@ def get_distribution_path(self, relative_path: str) -> str: def vcs_exclusion_files(self) -> dict[str, list[str]]: exclusion_files: dict[str, list[str]] = {"git": [], "hg": []} - local_gitignore = locate_file(self.root, ".gitignore", boundary=".git") + local_gitignore = locate_file(self.root, ".gitignore", boundaries=[".git", ".hg"]) if local_gitignore is not None: exclusion_files["git"].append(local_gitignore) - local_hgignore = locate_file(self.root, ".hgignore", boundary=".hg") + local_hgignore = locate_file(self.root, ".hgignore", boundaries=[".git", ".hg"]) if local_hgignore is not None: exclusion_files["hg"].append(local_hgignore) diff --git a/backend/src/hatchling/utils/fs.py b/backend/src/hatchling/utils/fs.py index d7413006c..b0a0b7467 100644 --- a/backend/src/hatchling/utils/fs.py +++ b/backend/src/hatchling/utils/fs.py @@ -3,13 +3,13 @@ import os -def locate_file(root: str, file_name: str, *, boundary: str | None = None) -> str | None: +def locate_file(root: str, file_name: str, *, boundaries: list[str] | None = None) -> str | None: while True: file_path = os.path.join(root, file_name) if os.path.isfile(file_path): return file_path - if boundary is not None and os.path.exists(os.path.join(root, boundary)): + if boundaries is not None and any(os.path.exists(os.path.join(root, boundary)) for boundary in boundaries): return None new_root = os.path.dirname(root)