Skip to content

Added dry-run, tree view, and global catignore support for better dev… - #3

Merged
TheOnliestMattastic merged 6 commits into
mainfrom
update
May 22, 2026
Merged

Added dry-run, tree view, and global catignore support for better dev…#3
TheOnliestMattastic merged 6 commits into
mainfrom
update

Conversation

@TheOnliestMattastic

Copy link
Copy Markdown
Owner

…elopment experience.

@qodo-code-review

Copy link
Copy Markdown
Contributor

Review Summary by Qodo

Add dry-run, tree view, and global catignore support

✨ Enhancement

Grey Divider

Walkthroughs

Description
• Added -WhatIf switch for dry-run mode to preview bundled files
• Added -IncludeTree switch to display directory tree structure
• Implemented global catignore support via ~/.catignore file
• Enhanced catignore to merge global and local patterns with deduplication
• Added environment variable override for catignore path in testing
• Added verbose logging for file processing operations
Diagram
flowchart LR
  A["User Parameters"] -->|WhatIf| B["Dry-run Mode"]
  A -->|IncludeTree| C["Directory Tree Output"]
  A -->|CatIgnore| D["Pattern Matching"]
  E["Global ~/.catignore"] -->|Merge| D
  F["Local catignore"] -->|Merge| D
  G["Environment Variable"] -->|Override| D
  D -->|Filter| H["File List"]
  B -->|Preview| H
  C -->|Include| I["Final Output"]
  H -->|Process| I

Loading

File Changes

1. src/PowerCat/PowerCat.psm1 ✨ Enhancement +53/-9

Add dry-run, tree view, and global catignore features

• Added $WhatIf and $IncludeTree parameters to function signature
• Implemented global catignore loading from ~/.catignore with environment variable override
 support
• Enhanced catignore pattern merging to combine global, local, and environment-based patterns with
 deduplication
• Added dry-run logic to display files without processing when -WhatIf is used
• Added directory tree generation and output when -IncludeTree is specified
• Added verbose logging for file processing operations

src/PowerCat/PowerCat.psm1


2. tests/PowerCat.Tests.ps1 🧪 Tests +66/-1

Add tests for dry-run and catignore features

• Added new test context "DX features (Dry-run and Verbose)" with three test cases
• Tests verify -WhatIf lists files without producing content output
• Tests verify -Verbose outputs processing information
• Tests verify -IncludeTree displays directory tree structure
• Added new test context "Configuration and Context" for catignore merging
• Tests verify global and local catignore patterns are merged correctly
• Tests verify environment variable override for catignore path works as expected

tests/PowerCat.Tests.ps1


Grey Divider

Qodo Logo

@qodo-code-review

qodo-code-review Bot commented May 22, 2026

Copy link
Copy Markdown
Contributor

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider


Remediation recommended

1. Catignore path separator mismatch ✓ Resolved 🐞 Bug ≡ Correctness
Description
Catignore matching compares $relativePath (derived from $file.FullName) directly to patterns
with -like, without normalizing path separators. On Windows, relative paths typically contain \,
so patterns written with / (common for ignore files) won’t match and intended ignores can be
silently skipped.
Code

src/PowerCat/PowerCat.psm1[R346-351]

Evidence
$relativePath is constructed from $file.FullName and then used with -like against raw
patterns; there’s no step that normalizes internal separators before matching, so patterns that
include directory separators are OS-sensitive.

src/PowerCat/PowerCat.psm1[339-352]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
Ignore matching uses `if ($relativePath -like $pattern -or $file.Name -like $pattern)` but `$relativePath` is taken from `$file.FullName` and can contain platform-specific separators.

### Issue Context
The code already trims both `\` and `/` from the start, but does not normalize separators inside the rest of the path, so directory-based patterns can fail depending on OS.

### Fix Focus Areas
- src/PowerCat/PowerCat.psm1[339-352]

### Suggested fix
- Normalize `$relativePath` to a single separator (e.g., replace `\` with `/`) before matching.
- Normalize `$pattern` similarly (or match using both variants).
- Consider clearly documenting whether catignore patterns should use `/`, `\`, or both.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


2. Tree scan always recurses ✓ Resolved 🐞 Bug ≡ Correctness
Description
When -IncludeTree is set, Invoke-PowerCat always runs a full recursive Get-ChildItem scan, even if
-Recurse was not requested for bundling. This can print a tree that includes files/directories that
were not eligible for inclusion and doubles filesystem traversal cost.
Code

src/PowerCat/PowerCat.psm1[R413-415]

Evidence
Bundled file enumeration only adds Recurse when $Recurse is true, but the tree generation path
always uses Get-ChildItem -Recurse, making the tree output inconsistent and causing an extra
recursive scan.

src/PowerCat/PowerCat.psm1[319-326]
src/PowerCat/PowerCat.psm1[411-425]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
`-IncludeTree` currently performs `Get-ChildItem -Recurse` unconditionally, which can (a) show deeper paths than the bundle selection (which only recurses when `-Recurse` is set) and (b) incur a second full directory traversal.

### Issue Context
File selection respects `$Recurse` by conditionally adding `Recurse = $true` to the `Get-ChildItem` parameters, but tree generation always recurses and doesn’t reuse the already-computed `$Files`.

### Fix Focus Areas
- src/PowerCat/PowerCat.psm1[319-326]
- src/PowerCat/PowerCat.psm1[411-425]

### Suggested fix
- Build the tree from the same enumeration semantics as bundling:
 - If `-Recurse` is not set, don’t use `-Recurse` for the tree.
 - Consider reusing the already enumerated `$Files` (and optionally their directory parents) to avoid a second full scan, or at least use the same `@getChildItemParams` logic.
- If intended behavior is “tree always recursive”, rename/document it explicitly and/or add a separate switch (e.g., `-TreeRecurse`).

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


3. Duplicate relative path computed ✓ Resolved 🐞 Bug ⚙ Maintainability
Description
The filter block computes $sourceDirPath and $relativePath twice per file, increasing per-file
overhead and making future edits error-prone. This duplication is unnecessary because the first
computed values are not modified before reuse.
Code

src/PowerCat/PowerCat.psm1[R345-347]

Evidence
The current code shows two identical assignments to $sourceDirPath and $relativePath within the
same Where-Object block, meaning each file pays this cost twice.

src/PowerCat/PowerCat.psm1[336-347]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
Inside the `$Files = $Files | Where-Object { ... }` filter, `$sourceDirPath` and `$relativePath` are assigned twice.

### Issue Context
The first assignment happens at the top of the `Where-Object` script block, and then the PR adds the same calculation again just before the catignore loop.

### Fix Focus Areas
- src/PowerCat/PowerCat.psm1[336-347]

### Suggested fix
- Keep a single computation of `$sourceDirPath`/`$relativePath` within the filter block and delete the redundant re-assignment.
- (Optional) Compute `$sourceDirPath` once outside the `Where-Object` to avoid recalculating it for every file.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


View more (1)
4. Env var not restored ✓ Resolved 🐞 Bug ☼ Reliability
Description
The new test overwrites $env:CATIGNORE_PATH and then sets it to $null in finally, which
permanently clobbers any pre-existing value for the remainder of the test run. This breaks test
isolation and can cause unrelated tests or local runs to behave differently.
Code

tests/PowerCat.Tests.ps1[R549-561]

Evidence
The test sets $env:CATIGNORE_PATH and later unconditionally nulls it out, with no preservation of
prior state.

tests/PowerCat.Tests.ps1[535-561]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
The test sets `$env:CATIGNORE_PATH` but does not preserve a previous value; it unconditionally clears it to `$null` in `finally`.

### Issue Context
Environment variables are process-global for the test session; changing them without restoring previous state can impact other tests.

### Fix Focus Areas
- tests/PowerCat.Tests.ps1[548-561]

### Suggested fix
- Capture the old value before overwriting:
 - `$old = $env:CATIGNORE_PATH`
- In `finally`, restore it:
 - `$env:CATIGNORE_PATH = $old`
- (Optional) If you want to truly remove it when it was originally unset, restore to `$null` only when `$old` was `$null`.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Advisory comments

5. Help omits new switches ✓ Resolved 🐞 Bug ⚙ Maintainability
Description
Comment-based help in PowerCat.psm1 documents parameters only through Stats and does not describe
the new -WhatIf and -IncludeTree switches. This makes Get-Help Invoke-PowerCat incomplete and
increases the chance of misuse.
Code

src/PowerCat/PowerCat.psm1[R195-197]

Evidence
The help section lists parameters up to Stats, while the param block includes WhatIf and
IncludeTree, so help output will not mention these new flags.

src/PowerCat/PowerCat.psm1[1-67]
src/PowerCat/PowerCat.psm1[192-198]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
The module’s comment-based help doesn’t include `.PARAMETER WhatIf` / `.PARAMETER IncludeTree` (or the global catignore behavior), even though the parameters exist.

### Issue Context
Users rely on `Get-Help Invoke-PowerCat -Full` for discoverability; missing entries effectively hides the feature.

### Fix Focus Areas
- src/PowerCat/PowerCat.psm1[1-67]
- src/PowerCat/PowerCat.psm1[192-198]

### Suggested fix
- Add `.PARAMETER WhatIf` explaining dry-run behavior (what is printed and that no bundling happens).
- Add `.PARAMETER IncludeTree` explaining scope (recursive vs not) and whether it respects catignore/extension filters.
- Add a brief note about global/user ignore sources (`$HOME/.catignore` and `CATIGNORE_PATH`).

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Qodo Logo

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request enhances the PowerCat module by introducing -WhatIf and -IncludeTree switches, adding verbose logging, and improving the .catignore logic to support global and environment-variable-based ignore files. The review feedback identifies redundant path calculations, suggests using Write-Host for dry-run output to avoid polluting the success stream, and points out that the directory tree generation should respect the user's recursion preference.

Comment thread src/PowerCat/PowerCat.psm1 Outdated
Comment on lines +394 to +397
Write-Output "Dry run: The following files would be bundled:"
foreach ($file in $Files) {
Write-Output $file.FullName
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using Write-Output for dry-run status messages sends them to the success stream. This can pollute the output if the function is used in a pipeline or if the result is captured in a variable. It is better to use Write-Host or Write-Information for these messages so they don't pollute the data output.

    Write-Host "Dry run: The following files would be bundled:"
    foreach ($file in $Files) {
      Write-Host $file.FullName
    }

Comment thread src/PowerCat/PowerCat.psm1 Outdated
@TheOnliestMattastic
TheOnliestMattastic merged commit 2a528ed into main May 22, 2026
2 checks passed
@TheOnliestMattastic
TheOnliestMattastic deleted the update branch May 22, 2026 01:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant