Skip to content

Commit

Permalink
Fix ignore list
Browse files Browse the repository at this point in the history
Files inside a .git/ folder were being removed
even with FREEZER_DESTINATION_IGNORE set.
  • Loading branch information
Siecje committed Feb 5, 2024
1 parent c122a40 commit a76b4b3
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 11 deletions.
2 changes: 1 addition & 1 deletion docs/index.rst
Expand Up @@ -266,7 +266,7 @@ are accepted:
As in ``.gitignore`` files,
patterns apply to the whole path if they contain a slash ``/``,
to each slash-separated part otherwise.
For example, this could be set to ``['.git*']``
For example, this could be set to ``['*.git*']``
if the destination is a git repository.

.. versionadded:: 0.10
Expand Down
24 changes: 14 additions & 10 deletions flask_frozen/__init__.py
Expand Up @@ -428,16 +428,20 @@ def walk_directory(root, ignore=()):
"""
for dir, dirs, filenames in os.walk(root):
for filename in filenames:
path = str((Path(dir) / filename).relative_to(root))
if os.sep != '/':
path = path.replace(os.sep, '/')
for pattern in ignore:
if fnmatch(path if '/' in pattern else filename, pattern):
break
else:
# See https://github.com/SimonSapin/Frozen-Flask/issues/5
yield normalize('NFC', path)
for pattern in ignore:
if fnmatch(dir, pattern):
break
else:
for filename in filenames:
path = str((Path(dir) / filename).relative_to(root))
if os.sep != '/':
path = path.replace(os.sep, '/')
for pattern in ignore:
if fnmatch(path if '/' in pattern else filename, pattern):
break
else:
# See https://github.com/SimonSapin/Frozen-Flask/issues/5
yield normalize('NFC', path)


@contextmanager
Expand Down
14 changes: 14 additions & 0 deletions tests/test_frozen_flask.py
Expand Up @@ -45,6 +45,20 @@ def test_walk_directory():
assert {
filename for filename in walk_directory(directory)
if not filename.endswith(('.pyc', '.pyo', '.css'))} == paths

git_dir = directory / '.git'
git_dir.mkdir()
git_file = git_dir / 'keep'
with git_file.open('w') as keep_file:
keep_file.write('keep')
try:
found = set(
walk_directory(directory, ('*.git', '*.pyc', '*.pyo', '*.css'))
)
assert found == paths
finally:
git_file.unlink()
git_dir.rmdir()


def test_warnings_share_common_superclass():
Expand Down

0 comments on commit a76b4b3

Please sign in to comment.