mirror of
https://github.com/kirill-markin/repo-to-text.git
synced 2025-12-06 03:22:23 -08:00
fixes ignoring subdirectories paths in the yaml
This commit is contained in:
parent
18b4b0bcd3
commit
1cf311bcf9
1 changed files with 30 additions and 9 deletions
|
|
@ -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}')
|
||||
result = subprocess.run(['tree', '-a', '-f', '--noreport', path], stdout=subprocess.PIPE)
|
||||
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:
|
||||
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')
|
||||
filtered_lines = []
|
||||
|
||||
for line in tree_output.splitlines():
|
||||
stripped_line = line.strip()
|
||||
if stripped_line:
|
||||
# Extract the path by removing the leading tree branch symbols
|
||||
full_path = stripped_line.split(maxsplit=1)[-1]
|
||||
relative_path = os.path.relpath(full_path, path)
|
||||
if not should_ignore_file(full_path, relative_path, gitignore_spec, None, tree_and_content_ignore_spec):
|
||||
filtered_lines.append(line.replace('./', '', 1))
|
||||
# Find the index where the path starts (look for './' or absolute path)
|
||||
idx = line.find('./')
|
||||
if idx == -1:
|
||||
idx = line.find(path)
|
||||
if idx != -1:
|
||||
full_path = line[idx:].strip()
|
||||
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)
|
||||
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')
|
||||
return filtered_tree_output
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue