Add --dirty option to process only Git-dirty files in Rector #9506
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.
This PR introduces a new CLI option,
--dirty, that allows Rector to process only the files that have uncommitted changes according to Git, similar to Laravel Pint’s--dirtymode.This dramatically improves performance for large projects and makes Rector more convenient to use during active development.
🚀 What This PR Adds
✔ New CLI flag:
--dirtyWhen enabled, Rector will:
Run
git status --porcelainCollect files marked as:
Filter to existing files only
Pass only those files to the standard Rector pipeline
❤️ Inspired by Laravel Pint
Just like Pint, the purpose is to:
This massively reduces Rector execution time during iterative refactoring.
🧠 Implementation Overview
1. Added
GitDirtyFileFetcherserviceResponsible for executing the git porcelain command and extracting changed file paths.
A custom callable can be injected for testing (to avoid executing real git).
2. ProcessCommand updated
Recognizes
--dirtyand enables dirty mode in the configuration.🧹 No Breaking Changes
--dirtyis used✔️ Summary
This PR brings a much-requested developer experience improvement to Rector.
Teams using Rector heavily — especially in large repositories — will benefit from: