Skip to content

Commit

Permalink
Add vcs exclude patterns before other patterns.
Browse files Browse the repository at this point in the history
Whitelists are possible in the vcs configuration.
These whitelists would override any configured
exclusions.
Configured exclusion should take precedence over
vcs configuration.

Issue #1276
  • Loading branch information
Wim-De-Clercq committed Feb 23, 2024
1 parent a5f62c2 commit 04b63f6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
6 changes: 3 additions & 3 deletions backend/src/hatchling/builders/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,9 @@ def exclude_spec(self) -> pathspec.GitIgnoreSpec | None:

all_exclude_patterns = self.default_global_exclude()

if not self.ignore_vcs:
all_exclude_patterns.extend(self.load_vcs_exclusion_patterns())

exclude_patterns = exclude_config.get('exclude', self.default_exclude())
if not isinstance(exclude_patterns, list):
message = f'Field `{exclude_location}` must be an array of strings'
Expand All @@ -207,9 +210,6 @@ def exclude_spec(self) -> pathspec.GitIgnoreSpec | None:

all_exclude_patterns.append(exclude_pattern)

if not self.ignore_vcs:
all_exclude_patterns.extend(self.load_vcs_exclusion_patterns())

if all_exclude_patterns:
self.__exclude_spec = pathspec.GitIgnoreSpec.from_lines(all_exclude_patterns)

Expand Down
11 changes: 11 additions & 0 deletions tests/backend/builders/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -1854,6 +1854,17 @@ def test_ignore_vcs_git(self, temp_dir, separator, platform):
assert builder.config.exclude_spec.match_file(f'foo{separator}file.py')
assert not builder.config.exclude_spec.match_file(f'bar{separator}file.py')

def test_vcs_git_exclude_whitelisted_file(self, temp_dir):
with temp_dir.as_cwd():
config = {'tool': {'hatch': {'build': {'exclude': ['foo/bar']}}}}
builder = MockBuilder(str(temp_dir), config=config)

vcs_ignore_file = temp_dir / '.gitignore'
vcs_ignore_file.write_text('foo/*\n!foo/bar')

assert builder.config.path_is_excluded('foo/deb') is True
assert builder.config.path_is_excluded('foo/bar') is True

@pytest.mark.parametrize('separator', ['/', '\\'])
def test_vcs_mercurial(self, temp_dir, separator, platform):
if separator == '\\' and not platform.windows:
Expand Down

0 comments on commit 04b63f6

Please sign in to comment.