Merge pull request #16 from himwho/main

allows wildcards and pattern ignores for specific files
This commit is contained in:
Kirill Markin 2024-12-16 00:53:26 +01:00 committed by GitHub
commit 6a434e5174
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 32 additions and 2 deletions

View file

@ -104,6 +104,17 @@ def load_ignore_specs(path='.', cli_ignore_patterns=None):
return gitignore_spec, content_ignore_spec, tree_and_content_ignore_spec
def should_ignore_file(file_path, relative_path, gitignore_spec, content_ignore_spec, tree_and_content_ignore_spec):
# Normalize relative_path to use forward slashes
relative_path = relative_path.replace(os.sep, '/')
# Remove leading './' if present
if relative_path.startswith('./'):
relative_path = relative_path[2:]
# Append '/' to directories to match patterns ending with '/'
if os.path.isdir(file_path):
relative_path += '/'
result = (
is_ignored_path(file_path) or
(gitignore_spec and gitignore_spec.match_file(relative_path)) or
@ -111,8 +122,11 @@ def should_ignore_file(file_path, relative_path, gitignore_spec, content_ignore_
(tree_and_content_ignore_spec and tree_and_content_ignore_spec.match_file(relative_path)) or
os.path.basename(file_path).startswith('repo-to-text_')
)
logging.debug(f'Checking if file should be ignored: {file_path}, relative path: {relative_path}, result: {result}')
logging.debug(f'Checking if file should be ignored:')
logging.debug(f' file_path: {file_path}')
logging.debug(f' relative_path: {relative_path}')
logging.debug(f' Result: {result}')
return result
def is_ignored_path(file_path: str) -> bool: