Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent matching bogus parent git directories #687

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion flit/vcs/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
import subprocess
from pathlib import Path

from . import hg
from . import git

def git_validate_ignore(directory: Path) -> bool:
check_ignore = subprocess.run(
['git', 'check-ignore', '.'],
cwd=str(directory),
stderr=subprocess.DEVNULL,
stdout=subprocess.DEVNULL,
).returncode
if check_ignore == 0:
return False
return True

def identify_vcs(directory: Path):
directory = directory.resolve()
for p in [directory] + list(directory.parents):
if (p / '.git').is_dir():
if (p / '.git').is_dir() and git_validate_ignore(directory):
return git
if (p / '.hg').is_dir():
return hg
Expand Down
4 changes: 3 additions & 1 deletion tests/test_sdist.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import ast
from os.path import join as pjoin
from pathlib import Path
from unittest.mock import patch
import pytest
from shutil import which, copy, copytree
import sys
Expand Down Expand Up @@ -81,7 +82,8 @@ def test_get_files_list_git(copy_sample):

builder = sdist.SdistBuilder.from_ini_path(td / 'pyproject.toml')
with MockCommand('git', LIST_FILES_GIT):
files = builder.select_files()
with patch('flit.vcs.git_validate_ignore', return_value=True):
files = builder.select_files()

assert set(files) == {
'foo', pjoin('dir1', 'bar'), pjoin('dir1', 'subdir', 'qux'),
Expand Down