Skip to content

Commit

Permalink
Prevent matching bogus parent git directories
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jameshilliard committed Jul 26, 2024
1 parent e38b172 commit 774ca82
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion flit/vcs/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import subprocess
from pathlib import Path

from . import hg
Expand All @@ -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

Expand Down

0 comments on commit 774ca82

Please sign in to comment.