From 774ca82f3ad64da1acd6941c18c479244e441095 Mon Sep 17 00:00:00 2001 From: James Hilliard Date: Fri, 26 Jul 2024 11:17:00 -0600 Subject: [PATCH] Prevent matching bogus parent git directories If our current directory is not tracked by git we should assume that the project does not use git as the vcs as any match will be a false positive. --- flit/vcs/__init__.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/flit/vcs/__init__.py b/flit/vcs/__init__.py index a3e92b39..fe364e52 100644 --- a/flit/vcs/__init__.py +++ b/flit/vcs/__init__.py @@ -1,3 +1,4 @@ +import subprocess from pathlib import Path from . import hg @@ -7,7 +8,14 @@ def identify_vcs(directory: Path): directory = directory.resolve() for p in [directory] + list(directory.parents): if (p / '.git').is_dir(): - return git + check_ignore = subprocess.run( + ['git', 'check-ignore', '.'], + cwd=str(directory), + stderr=subprocess.DEVNULL, + stdout=subprocess.DEVNULL, + ).returncode + if check_ignore != 0: + return git if (p / '.hg').is_dir(): return hg