Skip to content

Instantly share code, notes, and snippets.

@pixmin
Created October 31, 2019 14:20
Show Gist options
  • Save pixmin/23d9941e256eaa70e373831c85dd15db to your computer and use it in GitHub Desktop.
Save pixmin/23d9941e256eaa70e373831c85dd15db to your computer and use it in GitHub Desktop.
git filter-branch psr2
#!/bin/bash
# This script with loop through every commit in the current branch
# and run every php file through phpcbf (standard PSR2)
# -f to force if there is already a back up (previous filter-branch run)
# -d path to a tmpfs mount point
# PSR2 Coding Standard
# Only PHP files that have been added or modified
# Excluding root folders: vendor, libs and dist
# Output to /dev/null
# return true to keep filter-branch running
git filter-branch -f -d /dev/shm/foo --tree-filter '\
/usr/bin/phpcbf -n -q --standard=PSR2 $( \
git show $GIT_COMMIT --name-status | \
egrep ^[AM] | \
grep .php | \
cut -f2 | \
egrep -v ^vendor/ | \
egrep -v ^libs/ | \
egrep -v ^dist/ \
) 1>&2 2>/dev/null ; true \
'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment