gitignore-import-and-ignore setting

This commit is contained in:
Kirill Markin 2024-06-09 09:53:27 +02:00
parent b6bcdeca03
commit 72ac64ceb6
2 changed files with 18 additions and 12 deletions

View file

@ -1,6 +1,10 @@
# Details: https://github.com/kirill-markin/repo-to-text # Details: https://github.com/kirill-markin/repo-to-text
# Syntax: gitignore rules # Syntax: gitignore rules
# Ignore files and directories for all sections from gitignore file
# Default: True
gitignore-import-and-ignore: True
# Ignore files and directories for tree # Ignore files and directories for tree
# and "Contents of ..." sections # and "Contents of ..." sections
ignore-tree-and-content: ignore-tree-and-content:

View file

@ -38,26 +38,28 @@ def load_ignore_specs(path='.'):
gitignore_spec = None gitignore_spec = None
content_ignore_spec = None content_ignore_spec = None
tree_and_content_ignore_spec = None tree_and_content_ignore_spec = None
use_gitignore = True
gitignore_path = os.path.join(path, '.gitignore')
if os.path.exists(gitignore_path):
logging.debug(f'Loading .gitignore from path: {gitignore_path}')
with open(gitignore_path, 'r') as f:
gitignore_spec = pathspec.PathSpec.from_lines('gitwildmatch', f)
repo_settings_path = os.path.join(path, '.repo-to-text-settings.yaml') repo_settings_path = os.path.join(path, '.repo-to-text-settings.yaml')
if os.path.exists(repo_settings_path): if os.path.exists(repo_settings_path):
logging.debug(f'Loading .repo-to-text-settings.yaml from path: {repo_settings_path}') logging.debug(f'Loading .repo-to-text-settings.yaml from path: {repo_settings_path}')
with open(repo_settings_path, 'r') as f: with open(repo_settings_path, 'r') as f:
ignore_data = yaml.safe_load(f) settings = yaml.safe_load(f)
if 'ignore-content' in ignore_data: use_gitignore = settings.get('gitignore-import-and-ignore', True)
content_ignore_spec = pathspec.PathSpec.from_lines('gitwildmatch', ignore_data['ignore-content']) if 'ignore-content' in settings:
if 'ignore-tree-and-content' in ignore_data: content_ignore_spec = pathspec.PathSpec.from_lines('gitwildmatch', settings['ignore-content'])
tree_and_content_ignore_spec = pathspec.PathSpec.from_lines('gitwildmatch', ignore_data['ignore-tree-and-content']) if 'ignore-tree-and-content' in settings:
tree_and_content_ignore_spec = pathspec.PathSpec.from_lines('gitwildmatch', settings['ignore-tree-and-content'])
if use_gitignore:
gitignore_path = os.path.join(path, '.gitignore')
if os.path.exists(gitignore_path):
logging.debug(f'Loading .gitignore from path: {gitignore_path}')
with open(gitignore_path, 'r') as f:
gitignore_spec = pathspec.PathSpec.from_lines('gitwildmatch', f)
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):
return ( return (
is_ignored_path(file_path) or is_ignored_path(file_path) or