Skip to content

Instantly share code, notes, and snippets.

@havvg
Created March 21, 2015 13:25
Show Gist options
  • Save havvg/972893026c9aed4a15bf to your computer and use it in GitHub Desktop.
Save havvg/972893026c9aed4a15bf to your computer and use it in GitHub Desktop.
apply PHP-CS-Fixer on all changed files in the staging area
[alias]
fix-staged = "!git diff-index --cached --name-status HEAD | grep -ve '^D' | cut -f2 | xargs -n1 php-cs-fixer fix"
@havvg
Copy link
Author

havvg commented Apr 27, 2015

For separate commits of unrelated CS fixes:

[alias]
    cs-head = "!git diff-tree --no-commit-id --name-only -r HEAD | xargs -n1 php-cs-fixer fix"

@hannesvdvreken
Copy link

Sure, but that would reformat the entire file. Legacy projects often come with large controller classes, if you know what I mean ;-)

The first one would be useful for a pre-commit hook, right? The second as an after commit script.

Good suggestion though! Certainly useful! A pre-commit hook is also an option.

@havvg
Copy link
Author

havvg commented Apr 27, 2015

I'm using them in conjunction with those two:

[alias]
    ls-staged = diff-index --cached --name-only HEAD

    co-staged = !git ls-staged | xargs git co
    up-staged = "!f() { git ls-staged; }; git add -p `f`"

I apply the fixer on the staged, use the update patch workflow to only stage the fixes on my work. Afterwards I can use cs-head to apply all other fixes to the files I just change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment