Skip to content

Fix --ignore flag not suppressing --erase targets#119

Merged
bittner merged 5 commits into
mainfrom
copilot/fix-ignore-flag-override-erase
Mar 30, 2026
Merged

Fix --ignore flag not suppressing --erase targets#119
bittner merged 5 commits into
mainfrom
copilot/fix-ignore-flag-override-erase

Conversation

Copilot AI commented Mar 30, 2026

Copy link
Copy Markdown
Contributor

--ignore had no effect on paths targeted by --erase: glob results were processed for deletion without consulting Runner.ignore, so ignored directories were deleted anyway.

Changes

  • pyclean/erase.py: Added _path_is_ignored(path, ignore_patterns) that checks a path and all its ancestors against ignore patterns (delegating to the existing should_ignore from traversal.py). Applied this filter to glob results in delete_filesystem_objects before any deletion occurs.

Example

# Before: allure-results/ was deleted despite -i flag
# After: allure-results/ and its contents are skipped entirely
pyclean . --erase 'allure-results/**/*' allure-results -i allure-results -nyv

Copilot AI linked an issue Mar 30, 2026 that may be closed by this pull request
Copilot AI changed the title [WIP] Fix ignore flag to override erase flag targets Fix --ignore flag not suppressing --erase targets Mar 30, 2026
Copilot AI requested a review from bittner March 30, 2026 11:17
Comment thread pyclean/erase.py Outdated
Copilot AI requested a review from bittner March 30, 2026 11:23
Comment thread pyclean/erase.py Outdated

@bittner bittner left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Make sure linting, formatting and tests pass.

…-function call in erase.py

Agent-Logs-Url: https://github.com/bittner/pyclean/sessions/6eb036ae-d200-4616-bb20-7d471ee1178c

Co-authored-by: bittner <665072+bittner@users.noreply.github.com>

Copilot AI commented Mar 30, 2026

Copy link
Copy Markdown
Contributor Author

Make sure linting, formatting and tests pass.

Fixed in 8f54073. Lint, format, and all 100 tests pass. The lazy import that was causing PLC0415 has been resolved by extracting normalize, should_ignore, and path_is_ignored into a new pyclean/ignore.py module, breaking the circular dependency cleanly.

@bittner bittner marked this pull request as ready for review March 30, 2026 12:02
@bittner bittner merged commit 9eefae2 into main Mar 30, 2026
34 checks passed
@bittner bittner deleted the copilot/fix-ignore-flag-override-erase branch March 30, 2026 12:08
bittner added a commit that referenced this pull request May 23, 2026
- Default `remove_freeform_targets`'s `explicit_ignore_patterns` to `[]`
  internally so production callers (`main.py`) and tests both exercise the
  same path. The `None`-fallback in `delete_filesystem_objects` remains for
  direct debris call sites only.
- Update the #119 regression test to pass `explicit_ignore_patterns=['foo']`
  so it exercises the production wiring instead of the `Runner.ignore`
  fallback.
- Add a regression test for case 3 of issue #122's precedence table —
  `pyclean DIR --erase '**/*' --ignore DIR` is a no-op.
- Trim the hardcoded default ignore list to the patterns that actually
  matter in the two new erase tests (`.tox`, `keep.txt`).
- Document the erase/ignore interaction in `remove_freeform_targets`'s
  docstring and in the README `--erase` section.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.

Ignore flag should override erase flag targets

2 participants