Skip to content

Commit 774ca82

Browse files
committed
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.
1 parent e38b172 commit 774ca82

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

flit/vcs/__init__.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import subprocess
12
from pathlib import Path
23

34
from . import hg
@@ -7,7 +8,14 @@ def identify_vcs(directory: Path):
78
directory = directory.resolve()
89
for p in [directory] + list(directory.parents):
910
if (p / '.git').is_dir():
10-
return git
11+
check_ignore = subprocess.run(
12+
['git', 'check-ignore', '.'],
13+
cwd=str(directory),
14+
stderr=subprocess.DEVNULL,
15+
stdout=subprocess.DEVNULL,
16+
).returncode
17+
if check_ignore != 0:
18+
return git
1119
if (p / '.hg').is_dir():
1220
return hg
1321

0 commit comments

Comments
 (0)