mirror of
https://github.com/kirill-markin/repo-to-text.git
synced 2025-12-06 03:22:23 -08:00
gitignore-import-and-ignore setting
This commit is contained in:
parent
b6bcdeca03
commit
72ac64ceb6
2 changed files with 18 additions and 12 deletions
|
|
@ -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:
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
||||||
|
repo_settings_path = os.path.join(path, '.repo-to-text-settings.yaml')
|
||||||
|
if os.path.exists(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:
|
||||||
|
settings = yaml.safe_load(f)
|
||||||
|
use_gitignore = settings.get('gitignore-import-and-ignore', True)
|
||||||
|
if 'ignore-content' in settings:
|
||||||
|
content_ignore_spec = pathspec.PathSpec.from_lines('gitwildmatch', settings['ignore-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')
|
gitignore_path = os.path.join(path, '.gitignore')
|
||||||
if os.path.exists(gitignore_path):
|
if os.path.exists(gitignore_path):
|
||||||
logging.debug(f'Loading .gitignore from path: {gitignore_path}')
|
logging.debug(f'Loading .gitignore from path: {gitignore_path}')
|
||||||
with open(gitignore_path, 'r') as f:
|
with open(gitignore_path, 'r') as f:
|
||||||
gitignore_spec = pathspec.PathSpec.from_lines('gitwildmatch', f)
|
gitignore_spec = pathspec.PathSpec.from_lines('gitwildmatch', f)
|
||||||
|
|
||||||
repo_settings_path = os.path.join(path, '.repo-to-text-settings.yaml')
|
|
||||||
if os.path.exists(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:
|
|
||||||
ignore_data = yaml.safe_load(f)
|
|
||||||
if 'ignore-content' in ignore_data:
|
|
||||||
content_ignore_spec = pathspec.PathSpec.from_lines('gitwildmatch', ignore_data['ignore-content'])
|
|
||||||
if 'ignore-tree-and-content' in ignore_data:
|
|
||||||
tree_and_content_ignore_spec = pathspec.PathSpec.from_lines('gitwildmatch', ignore_data['ignore-tree-and-content'])
|
|
||||||
|
|
||||||
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
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue