mirror of
https://github.com/kirill-markin/repo-to-text.git
synced 2025-12-06 03:22:23 -08:00
allows wildcards and pattern ignores for specific files
This commit is contained in:
parent
1cf311bcf9
commit
4642e3fd09
2 changed files with 32 additions and 2 deletions
16
README.md
16
README.md
|
|
@ -116,6 +116,22 @@ You can copy this file from the [existing example in the project](https://github
|
||||||
|
|
||||||
Using these settings, you can control which files and directories are included or excluded from the final text file.
|
Using these settings, you can control which files and directories are included or excluded from the final text file.
|
||||||
|
|
||||||
|
### Wildcards and Inclusions
|
||||||
|
|
||||||
|
Using Wildcard Patterns
|
||||||
|
|
||||||
|
- `*.ext`: Matches any file ending with .ext in any directory.
|
||||||
|
- `dir/*.ext`: Matches files ending with .ext in the specified directory dir/.
|
||||||
|
- `**/*.ext`: Matches files ending with .ext in any subdirectory (recursive).
|
||||||
|
|
||||||
|
If you want to include certain files that would otherwise be ignored, use the ! pattern:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
ignore-tree-and-content:
|
||||||
|
- "*.txt"
|
||||||
|
- "!README.txt"
|
||||||
|
```
|
||||||
|
|
||||||
## gitignore Rule to Ignore generated files
|
## gitignore Rule to Ignore generated files
|
||||||
|
|
||||||
To ignore the generated text files, add the following lines to your `.gitignore` file:
|
To ignore the generated text files, add the following lines to your `.gitignore` file:
|
||||||
|
|
|
||||||
|
|
@ -100,6 +100,17 @@ def load_ignore_specs(path='.'):
|
||||||
return gitignore_spec, content_ignore_spec, tree_and_content_ignore_spec
|
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):
|
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 = (
|
result = (
|
||||||
is_ignored_path(file_path) or
|
is_ignored_path(file_path) or
|
||||||
(gitignore_spec and gitignore_spec.match_file(relative_path)) or
|
(gitignore_spec and gitignore_spec.match_file(relative_path)) or
|
||||||
|
|
@ -107,8 +118,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
|
(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_')
|
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
|
return result
|
||||||
|
|
||||||
def is_ignored_path(file_path: str) -> bool:
|
def is_ignored_path(file_path: str) -> bool:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue