Skip to content

Conversation

@itxshakil
Copy link

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 --dirty mode.

This dramatically improves performance for large projects and makes Rector more convenient to use during active development.


🚀 What This PR Adds

✔ New CLI flag: --dirty

vendor/bin/rector process --dirty

When enabled, Rector will:

  • Run git status --porcelain

  • Collect files marked as:

    • modified (M)
    • added (A)
    • untracked (??)
  • 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:

“Only modify or inspect files that have uncommitted changes according to Git.”

This massively reduces Rector execution time during iterative refactoring.


🧠 Implementation Overview

1. Added GitDirtyFileFetcher service

Responsible 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 --dirty and enables dirty mode in the configuration.


🧹 No Breaking Changes

  • Defaults remain unchanged
  • Git is only executed when --dirty is used
  • Behavior is fully opt-in

✔️ Summary

This PR brings a much-requested developer experience improvement to Rector.
Teams using Rector heavily — especially in large repositories — will benefit from:

  • Faster iteration cycles
  • Less noise
  • A more “incremental refactoring” workflow

@github-actions
Copy link
Contributor

This repository content is generated by rectorphp/rector-src. Please open pull request to rectorphp/rector-src.

@github-actions github-actions bot closed this Nov 21, 2025
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