Repository navigation
Conversation
…ree (mufeedvh#111) - Change `include_in_tree` condition in `crates/code2prompt-core/src/path.rs` from `path.is_dir() || entry_match` to `config.full_directory_tree || (path.is_file() && entry_match)` so directories whose files are all excluded via `--exclude` are not rendered as empty branches in `<directory_tree>` unless `--full-directory-tree` is enabled (Fixes mufeedvh#111) - Add regression test `test_excluded_files_prune_empty_directories_from_tree` in `crates/code2prompt-core/tests/path_test.rs` Signed-off-by: Napat (Tan) Phasundhiae <tanfasantia@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Resolves #111.
Root Cause
In
crates/code2prompt-core/src/path.rs,traverse_directoryadded entries to the visualtreewheneverif path.is_dir() || entry_matchheld (L139). Becauseignore::WalkBuilderyields directory entries before visiting their children—and user--excludeglob patterns (such as--exclude "*.txt"or--exclude "**/subfolder/*") match file paths rather than the parent directory path itself—every traversed directory was unconditionally inserted intotreeeven when all files inside it were excluded.Fix
if path.is_dir() || entry_matchwithlet include_in_tree = config.full_directory_tree || (path.is_file() && entry_match);.termtree::Treebuilds parent directory chains automatically viacur.split('/')whenever a matched file is added, non-empty directories continue to render identically, while directories with zero matched files are pruned unless--full-directory-treeis explicitly enabled.test_excluded_files_prune_empty_directories_from_treeincrates/code2prompt-core/tests/path_test.rs(cargo test -p code2prompt_core --test path_test->9/9 PASS).Fixes #111