fixes ignoring subdirectories paths in the yaml

This commit is contained in:
Dylan Marcus 2024-10-22 01:11:15 -04:00
parent 18b4b0bcd3
commit 1cf311bcf9

View file

@ -30,7 +30,7 @@ def get_tree_structure(path='.', gitignore_spec=None, tree_and_content_ignore_sp
logging.debug(f'Generating tree structure for path: {path}') logging.debug(f'Generating tree structure for path: {path}')
result = subprocess.run(['tree', '-a', '-f', '--noreport', path], stdout=subprocess.PIPE) result = subprocess.run(['tree', '-a', '-f', '--noreport', path], stdout=subprocess.PIPE)
tree_output = result.stdout.decode('utf-8') tree_output = result.stdout.decode('utf-8')
logging.debug(f'Tree output generated: {tree_output}') logging.debug(f'Tree output generated:\n{tree_output}')
if not gitignore_spec and not tree_and_content_ignore_spec: if not gitignore_spec and not tree_and_content_ignore_spec:
logging.debug('No .gitignore or ignore-tree-and-content specification found') logging.debug('No .gitignore or ignore-tree-and-content specification found')
@ -38,17 +38,38 @@ def get_tree_structure(path='.', gitignore_spec=None, tree_and_content_ignore_sp
logging.debug('Filtering tree output based on .gitignore and ignore-tree-and-content specification') logging.debug('Filtering tree output based on .gitignore and ignore-tree-and-content specification')
filtered_lines = [] filtered_lines = []
for line in tree_output.splitlines(): for line in tree_output.splitlines():
stripped_line = line.strip() # Find the index where the path starts (look for './' or absolute path)
if stripped_line: idx = line.find('./')
# Extract the path by removing the leading tree branch symbols if idx == -1:
full_path = stripped_line.split(maxsplit=1)[-1] idx = line.find(path)
relative_path = os.path.relpath(full_path, path) if idx != -1:
if not should_ignore_file(full_path, relative_path, gitignore_spec, None, tree_and_content_ignore_spec): full_path = line[idx:].strip()
filtered_lines.append(line.replace('./', '', 1)) else:
# If neither './' nor the absolute path is found, skip the line
continue
# Skip the root directory '.'
if full_path == '.':
continue
# Normalize paths
relative_path = os.path.relpath(full_path, path)
relative_path = relative_path.replace(os.sep, '/')
if os.path.isdir(full_path):
relative_path += '/'
# Check if the file should be ignored
if not should_ignore_file(full_path, relative_path, gitignore_spec, None, tree_and_content_ignore_spec):
# Remove './' from display output for clarity
display_line = line.replace('./', '', 1)
filtered_lines.append(display_line)
else:
logging.debug(f'Ignored: {relative_path}')
filtered_tree_output = '\n'.join(filtered_lines) filtered_tree_output = '\n'.join(filtered_lines)
logging.debug(f'Filtered tree structure: {filtered_tree_output}') logging.debug(f'Filtered tree structure:\n{filtered_tree_output}')
logging.debug('Tree structure filtering complete') logging.debug('Tree structure filtering complete')
return filtered_tree_output return filtered_tree_output